owenloop 0.4.0 → 0.4.1
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/CHANGELOG.md +19 -0
- package/README.md +48 -2
- package/dist/add.d.ts +12 -40
- package/dist/add.js +11 -176
- package/dist/cli.d.ts +51 -2
- package/dist/cli.js +959 -325
- package/dist/credentials.d.ts +274 -0
- package/dist/credentials.js +695 -0
- package/dist/defs.js +23 -0
- package/dist/engine.js +15 -6
- package/dist/hub.d.ts +133 -0
- package/dist/hub.js +172 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/lock.d.ts +80 -0
- package/dist/lock.js +217 -0
- package/dist/mcp/serve.d.ts +84 -0
- package/dist/mcp/serve.js +565 -0
- package/dist/mcp/server.d.ts +135 -0
- package/dist/mcp/server.js +330 -0
- package/dist/model.d.ts +59 -4
- package/dist/model.js +148 -21
- package/dist/owenwork.d.ts +57 -0
- package/dist/owenwork.js +84 -0
- package/dist/types.d.ts +48 -6
- package/dist/util.d.ts +24 -0
- package/dist/util.js +25 -0
- package/docs/authoring.md +9 -0
- package/docs/cli.md +337 -4
- package/docs/design.md +86 -12
- package/docs/embedding.md +29 -5
- package/package.json +1 -1
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential WRITE + OAuth refresh library surface.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `src/cli.ts` (where these were module-private) so external
|
|
5
|
+
* consumers — a future `owenloop mcp` stdio server, an `owenwork join` command —
|
|
6
|
+
* can store credentials and keep an OAuth access token fresh without depending
|
|
7
|
+
* on the CLI module. The exported `storeCredential` / `deleteCredential` /
|
|
8
|
+
* `ensureFreshOAuth` are re-imported by `cli.ts`, so every existing subcommand
|
|
9
|
+
* keeps its exact behavior.
|
|
10
|
+
*
|
|
11
|
+
* **Concurrency safety (the reason this module exists):** the refresh-and-persist
|
|
12
|
+
* critical section is serialized by a lockfile next to the store
|
|
13
|
+
* (`~/.config/owenloop/credentials.lock`, via `src/lock.ts`). Multiple long-lived
|
|
14
|
+
* processes sharing one slot (the `mcp` server case) would otherwise race a
|
|
15
|
+
* refresh — both read the old refresh token, both rotate it server-side, and the
|
|
16
|
+
* loser persists a now-dead token, causing a silent logout an hour later. The
|
|
17
|
+
* lock turns "two refreshes race" into "the second process adopts the first's
|
|
18
|
+
* result": acquire → re-read the slot → adopt-or-refresh → persist → release.
|
|
19
|
+
*
|
|
20
|
+
* This module imports ONLY `hub.ts` (store internals), `util.ts` (`CliError`,
|
|
21
|
+
* `nowMs`), and `lock.ts` (node-builtin-only) — never `cli.ts`. That keeps the
|
|
22
|
+
* package barrel (`src/index.ts`) free of the CLI/add/untar runtime closure and
|
|
23
|
+
* avoids an import cycle.
|
|
24
|
+
*/
|
|
25
|
+
import { join } from 'node:path';
|
|
26
|
+
import { asMintAgentTokenOk, asRekeyAgentTokenOk, configDir, credentialBackend, credentialFilePath, credentialSlot, externalCredentialCommand, keychainServiceFor, readCredentialFile, readStoredCredential, resolveEndpoint, resolveKeychain, writeCredentialFile, } from "./hub.js";
|
|
27
|
+
import { CliError, nowMs } from "./util.js";
|
|
28
|
+
import { acquireFileLock, FileLockTimeoutError, releaseFileLock } from "./lock.js";
|
|
29
|
+
/**
|
|
30
|
+
* Freshness window shared by `ensureFreshOAuth`'s cheap pre-lock check and the
|
|
31
|
+
* adopt decision under the lock: a stored token more than this far from expiry
|
|
32
|
+
* is treated as fresh (either "no refresh needed" or "another process already
|
|
33
|
+
* refreshed — adopt it").
|
|
34
|
+
*/
|
|
35
|
+
const FRESH_WINDOW_MS = 60_000;
|
|
36
|
+
// ---- the refresh/store lockfile --------------------------------------------
|
|
37
|
+
/** The credential lock path — sibling of `credentials.json` in the config dir. */
|
|
38
|
+
function credLockPath(env) {
|
|
39
|
+
return join(configDir(env), 'credentials.lock');
|
|
40
|
+
}
|
|
41
|
+
/** A positive-number env override, else the default (test knobs, same pattern as `OWENLOOP_HUB_TIMEOUT_MS`). */
|
|
42
|
+
function envNum(env, key, fallback) {
|
|
43
|
+
const n = Number(env[key]);
|
|
44
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Lock timings for the credential lock. Defaults 45s wait / 30s stale / 100ms
|
|
48
|
+
* poll; each overridable via `OWENLOOP_CRED_LOCK_{WAIT,STALE,POLL}_MS`. The 30s
|
|
49
|
+
* TTL is safe even against a slow live holder (a worst-case refresh — discovery
|
|
50
|
+
* + token POST, each budgeted `HUB_TIMEOUT_MS` = 30s — can exceed it) because
|
|
51
|
+
* `lockIsStale` never age-reclaims a lock whose recorded pid is alive; age only
|
|
52
|
+
* governs an abandoned/unparseable lockfile.
|
|
53
|
+
*/
|
|
54
|
+
function credLockOpts(env) {
|
|
55
|
+
return {
|
|
56
|
+
waitMs: envNum(env, 'OWENLOOP_CRED_LOCK_WAIT_MS', 45_000),
|
|
57
|
+
staleMs: envNum(env, 'OWENLOOP_CRED_LOCK_STALE_MS', 30_000),
|
|
58
|
+
pollMs: envNum(env, 'OWENLOOP_CRED_LOCK_POLL_MS', 100),
|
|
59
|
+
label: 'owenloop credential operation',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Acquire the credential lock, mapping a clean acquire timeout to a loud
|
|
64
|
+
* `CliError` — never falling through to an unlocked refresh (that would silently
|
|
65
|
+
* reintroduce the double-refresh race). A real filesystem error from the
|
|
66
|
+
* exclusive create (EACCES/EROFS) is NOT a timeout and propagates untouched. No
|
|
67
|
+
* token value ever appears in the message (the lock payload is pid/host/
|
|
68
|
+
* startedAt/token-only, and this message names neither the credential nor a
|
|
69
|
+
* token).
|
|
70
|
+
*/
|
|
71
|
+
async function acquireCredLock(io) {
|
|
72
|
+
try {
|
|
73
|
+
return await acquireFileLock(credLockPath(io.env), credLockOpts(io.env));
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
if (e instanceof FileLockTimeoutError) {
|
|
77
|
+
const who = e.holderPid !== undefined ? `pid ${e.holderPid}` : 'another process';
|
|
78
|
+
throw new CliError(`another owenloop process is using the credential store (${who}) — holds ${e.lockPath}; ` +
|
|
79
|
+
`timed out waiting after ${Math.round(e.waitMs / 1000)}s`);
|
|
80
|
+
}
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// ---- credential store writes -----------------------------------------------
|
|
85
|
+
/**
|
|
86
|
+
* Store body WITHOUT the lock — the caller holds it. Private on purpose: the
|
|
87
|
+
* exported `storeCredential` wraps this in the lock, and `refreshOAuth`'s locked
|
|
88
|
+
* section calls this directly (calling the exported wrapper from inside the lock
|
|
89
|
+
* would deadlock — it would poll against its own held lock until `waitMs`).
|
|
90
|
+
*
|
|
91
|
+
* Stores in the chosen backend ONLY; returns which one. A failed keychain write
|
|
92
|
+
* is a hard error (REL-6), never a silent fall-through to the file — the escape
|
|
93
|
+
* hatch is `OWENLOOP_NO_KEYCHAIN=1`. The file backend MERGES into the origin's
|
|
94
|
+
* slot map: writing `agent:ci` must leave a `human` credential for the same
|
|
95
|
+
* origin intact. The external-command backstop throw stays here even though the
|
|
96
|
+
* exported wrapper checks it before locking — an unreachable-but-honest guard.
|
|
97
|
+
*/
|
|
98
|
+
function storeCredentialUnlocked(io, origin, slot, cred) {
|
|
99
|
+
const account = credentialSlot(slot);
|
|
100
|
+
const backend = credentialBackend(io.env, io.keychain);
|
|
101
|
+
if (backend.kind === 'external') {
|
|
102
|
+
// Writing to a store that reads will never consult is exactly the
|
|
103
|
+
// "half-working setup hands back a stale key" failure the external command
|
|
104
|
+
// exists to prevent, so refuse loudly instead.
|
|
105
|
+
throw new CliError('an external credential command is configured (OWENLOOP_CREDENTIAL_COMMAND), so it — not the ' +
|
|
106
|
+
'local store — supplies credentials for this hub; unset it to use `owenloop login`');
|
|
107
|
+
}
|
|
108
|
+
if (backend.kind === 'keychain') {
|
|
109
|
+
try {
|
|
110
|
+
backend.kc.set(keychainServiceFor(origin), account, JSON.stringify(cred));
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
throw new CliError(`could not write the credential to the OS keychain: ${e.message}. ` +
|
|
114
|
+
'Fix the keychain, or set OWENLOOP_NO_KEYCHAIN=1 to use the 0600 file store');
|
|
115
|
+
}
|
|
116
|
+
return 'keychain';
|
|
117
|
+
}
|
|
118
|
+
const path = credentialFilePath(io.env);
|
|
119
|
+
const file = readCredentialFile(path);
|
|
120
|
+
file.hubs[origin] = { ...file.hubs[origin], [account]: cred };
|
|
121
|
+
writeCredentialFile(path, file);
|
|
122
|
+
return 'file';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Store a credential for `origin` in `slot`, in the chosen backend ONLY;
|
|
126
|
+
* returns which one. Serialized by the credential lock so a plain write from
|
|
127
|
+
* `login` / `agent new` can never interleave with a refresh-and-persist.
|
|
128
|
+
*
|
|
129
|
+
* The external-command refusal runs BEFORE acquiring the lock: in that mode the
|
|
130
|
+
* command (not the local store) is authoritative, so a write is refused with no
|
|
131
|
+
* lockfile/config-dir side effect at all.
|
|
132
|
+
*
|
|
133
|
+
* Async because gaining the lock made it so — acceptable because this function
|
|
134
|
+
* was module-private before this change; the NEW public API is born async.
|
|
135
|
+
*/
|
|
136
|
+
export async function storeCredential(io, origin, slot, cred) {
|
|
137
|
+
if (externalCredentialCommand(io.env) !== undefined) {
|
|
138
|
+
throw new CliError('an external credential command is configured (OWENLOOP_CREDENTIAL_COMMAND), so it — not the ' +
|
|
139
|
+
'local store — supplies credentials for this hub; unset it to use `owenloop login`');
|
|
140
|
+
}
|
|
141
|
+
const handle = await acquireCredLock(io);
|
|
142
|
+
try {
|
|
143
|
+
return storeCredentialUnlocked(io, origin, slot, cred);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
releaseFileLock(handle);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Delete body WITHOUT the lock — the caller holds it. Deletes the stored
|
|
151
|
+
* credential for `(origin, slot)` from BOTH backends (a defensive dual-clear, so
|
|
152
|
+
* a live refresh token can never be stranded in the store that wasn't the
|
|
153
|
+
* currently-chosen one). Returns whether anything was removed. Only the NAMED
|
|
154
|
+
* slot is removed.
|
|
155
|
+
*/
|
|
156
|
+
function deleteCredentialUnlocked(io, origin, slot) {
|
|
157
|
+
const account = credentialSlot(slot);
|
|
158
|
+
let removed = false;
|
|
159
|
+
const kc = resolveKeychain(io.env, io.keychain);
|
|
160
|
+
const service = keychainServiceFor(origin);
|
|
161
|
+
if (kc && kc.get(service, account) !== null) {
|
|
162
|
+
kc.delete(service, account);
|
|
163
|
+
removed = true;
|
|
164
|
+
}
|
|
165
|
+
const path = credentialFilePath(io.env);
|
|
166
|
+
const file = readCredentialFile(path);
|
|
167
|
+
const slots = file.hubs[origin];
|
|
168
|
+
if (slots !== undefined && slots[account] !== undefined) {
|
|
169
|
+
delete slots[account];
|
|
170
|
+
// Drop the origin key once its last slot is gone, so the file never keeps
|
|
171
|
+
// an empty husk that a later read would have to special-case.
|
|
172
|
+
if (Object.keys(slots).length === 0)
|
|
173
|
+
delete file.hubs[origin];
|
|
174
|
+
writeCredentialFile(path, file);
|
|
175
|
+
removed = true;
|
|
176
|
+
}
|
|
177
|
+
return removed;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Delete the stored credential for `(origin, slot)` from BOTH backends, under
|
|
181
|
+
* the credential lock so a logout can never interleave with a concurrent
|
|
182
|
+
* refresh-and-persist. Returns whether anything was removed. Async for the same
|
|
183
|
+
* born-with-the-lock reason as `storeCredential`.
|
|
184
|
+
*/
|
|
185
|
+
export async function deleteCredential(io, origin, slot) {
|
|
186
|
+
const handle = await acquireCredLock(io);
|
|
187
|
+
try {
|
|
188
|
+
return deleteCredentialUnlocked(io, origin, slot);
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
releaseFileLock(handle);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// ---- HTTP helpers (hub/auth calls) -----------------------------------------
|
|
195
|
+
/** The Bearer value for an authenticated request. Never logged. */
|
|
196
|
+
export function authHeader(cred) {
|
|
197
|
+
return `Bearer ${cred.accessToken}`;
|
|
198
|
+
}
|
|
199
|
+
// Request deadline for EVERY hub/auth call — OAuth discovery, DCR, code
|
|
200
|
+
// exchange, token refresh, whoami, workflow list, and push (REL-7). These are
|
|
201
|
+
// all small JSON round-trips, so one budget fits them all;
|
|
202
|
+
// OWENLOOP_HUB_TIMEOUT_MS overrides it (a test knob, consistent with
|
|
203
|
+
// OWENLOOP_LOGIN_TIMEOUT_MS and the project's other OWENLOOP_* test-only knobs).
|
|
204
|
+
const HUB_TIMEOUT_MS = 30_000;
|
|
205
|
+
function hubTimeoutMs(io) {
|
|
206
|
+
const override = Number(io.env.OWENLOOP_HUB_TIMEOUT_MS);
|
|
207
|
+
return Number.isFinite(override) && override > 0 ? override : HUB_TIMEOUT_MS;
|
|
208
|
+
}
|
|
209
|
+
// Cap on any hub/auth JSON RESPONSE body (OAuth discovery, DCR, code exchange,
|
|
210
|
+
// token refresh, whoami, the workflow list, create_workflow). Hub responses are
|
|
211
|
+
// small round-trips — the largest realistic body is a workflows summary list,
|
|
212
|
+
// far below 8 MiB. This is a RESPONSE cap; the hub's 32MB figure (the 413 path)
|
|
213
|
+
// is a REQUEST cap and responses never echo YAML. OWENLOOP_HUB_MAX_RESPONSE_BYTES
|
|
214
|
+
// overrides it (a test-only knob, consistent with OWENLOOP_HUB_TIMEOUT_MS).
|
|
215
|
+
const HUB_MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
216
|
+
export function hubMaxResponseBytes(io) {
|
|
217
|
+
const override = Number(io.env.OWENLOOP_HUB_MAX_RESPONSE_BYTES);
|
|
218
|
+
return Number.isFinite(override) && override > 0 ? override : HUB_MAX_RESPONSE_BYTES;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Read a `Response` body into memory with a hard byte cap, streaming so an
|
|
222
|
+
* oversized body is rejected without first buffering the whole thing. Also used
|
|
223
|
+
* by the `add` tarball/sha fetches in `cli.ts` (which import it back), hence the
|
|
224
|
+
* `export`. `label` names the request in the error and is origin+path or
|
|
225
|
+
* `owner/repo@sha` only — never a token. Counting post-decode bytes (what lands
|
|
226
|
+
* in memory) is deliberate: the cap protects memory, not wire bytes.
|
|
227
|
+
*
|
|
228
|
+
* `res.body === null` (empty/no-body response) yields empty bytes, so callers
|
|
229
|
+
* behave exactly as they did under `arrayBuffer()`. An absent, malformed, or
|
|
230
|
+
* multi-valued `Content-Length` skips the header check — the counting path is
|
|
231
|
+
* the real guard (GitHub codeload tarballs are typically chunked, no header). A
|
|
232
|
+
* `TimeoutError`/`AbortError` from `read()` (the abort signal fired mid-body)
|
|
233
|
+
* propagates untouched, so each call site's existing timeout mapping still
|
|
234
|
+
* fires exactly as it did for `arrayBuffer()` rejections. `cancel()` may reject
|
|
235
|
+
* on an already-errored stream — swallowed; the cap `CliError` is the story.
|
|
236
|
+
*/
|
|
237
|
+
export async function readBodyBounded(res, cap, label) {
|
|
238
|
+
const declared = Number(res.headers.get('content-length'));
|
|
239
|
+
if (Number.isFinite(declared) && declared > cap) {
|
|
240
|
+
await res.body?.cancel().catch(() => { });
|
|
241
|
+
throw new CliError(`response body for ${label} exceeds the ${cap}-byte cap (declared Content-Length ${declared})`);
|
|
242
|
+
}
|
|
243
|
+
if (res.body === null)
|
|
244
|
+
return new Uint8Array(0);
|
|
245
|
+
const reader = res.body.getReader();
|
|
246
|
+
const chunks = [];
|
|
247
|
+
let total = 0;
|
|
248
|
+
for (;;) {
|
|
249
|
+
const { done, value } = await reader.read();
|
|
250
|
+
if (done)
|
|
251
|
+
break;
|
|
252
|
+
if (value === undefined)
|
|
253
|
+
continue;
|
|
254
|
+
total += value.byteLength;
|
|
255
|
+
chunks.push(value);
|
|
256
|
+
if (total > cap) {
|
|
257
|
+
await reader.cancel().catch(() => { });
|
|
258
|
+
throw new CliError(`response body for ${label} exceeds the ${cap}-byte cap`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const out = new Uint8Array(total);
|
|
262
|
+
let offset = 0;
|
|
263
|
+
for (const chunk of chunks) {
|
|
264
|
+
out.set(chunk, offset);
|
|
265
|
+
offset += chunk.byteLength;
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* `fetch` wrapper putting a deadline on every hub/auth call (REL-7). The abort
|
|
271
|
+
* signal is threaded into `fetch` AND the body is read (via `readBodyBounded`,
|
|
272
|
+
* which caps the response size — see HUB_MAX_RESPONSE_BYTES) inside the same
|
|
273
|
+
* try, so the deadline covers a stalled BODY read too — the exact undici
|
|
274
|
+
* behavior the two `add` fetches document (`AbortSignal.timeout` ties the
|
|
275
|
+
* signal to the body stream). The returned `Response` re-exposes the read
|
|
276
|
+
* body, so every call site's `res.json()` / `res.status` /
|
|
277
|
+
* `res.headers.get(...)` usage is byte-for-byte unchanged. A
|
|
278
|
+
* `TimeoutError`/`AbortError` becomes a clear `CliError` (naming the request,
|
|
279
|
+
* which is origin+path only — never a token); anything else is rethrown
|
|
280
|
+
* untouched.
|
|
281
|
+
*
|
|
282
|
+
* `redirect: 'error'` is forced on every call — after the `...init` spread, so
|
|
283
|
+
* no caller can override it — to close the redirect gap `resolveEndpoint`
|
|
284
|
+
* (SEC-4) cannot see: same-origin validation covers only the INITIAL URL, but a
|
|
285
|
+
* validated endpoint answering 307/308 would re-send the POST body (refresh
|
|
286
|
+
* token, PKCE verifier, auth code, workflow YAML) to a foreign origin — undici
|
|
287
|
+
* strips the Authorization header on a cross-origin redirect but RESENDS the
|
|
288
|
+
* body. The hub protocol has no redirects, so any 3xx is a hard, loud failure
|
|
289
|
+
* mapped to a `CliError` (again naming origin+path only, never a token).
|
|
290
|
+
*/
|
|
291
|
+
export async function hubFetch(io, url, init) {
|
|
292
|
+
const fetchFn = io.fetch ?? globalThis.fetch;
|
|
293
|
+
const ms = hubTimeoutMs(io);
|
|
294
|
+
const method = (init?.method ?? 'GET').toUpperCase();
|
|
295
|
+
try {
|
|
296
|
+
const res = await fetchFn(url, { ...init, signal: AbortSignal.timeout(ms), redirect: 'error' });
|
|
297
|
+
// 204/304 carry no body — reading one would be a spec violation.
|
|
298
|
+
if (res.status === 204 || res.status === 304) {
|
|
299
|
+
return new Response(null, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
300
|
+
}
|
|
301
|
+
const body = await readBodyBounded(res, hubMaxResponseBytes(io), `${method} ${url}`);
|
|
302
|
+
return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
303
|
+
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
const err = e;
|
|
306
|
+
if (err.name === 'TimeoutError' || err.name === 'AbortError') {
|
|
307
|
+
throw new CliError(`hub did not respond within ${ms / 1000}s (${method} ${url})`);
|
|
308
|
+
}
|
|
309
|
+
// `redirect: 'error'` makes undici reject a 3xx with a TypeError whose
|
|
310
|
+
// cause message is 'unexpected redirect' (verified on Node 22.22.3 and 26).
|
|
311
|
+
// Substring-match for slack against undici wording drift — if it ever stops
|
|
312
|
+
// matching, the raw TypeError still surfaces (fail-closed, just less pretty).
|
|
313
|
+
const cause = String(err.cause?.message ?? '');
|
|
314
|
+
if (err.name === 'TypeError' && cause.includes('unexpected redirect')) {
|
|
315
|
+
throw new CliError(`hub responded with a redirect — refusing to follow it (${method} ${url}); redirects are not part of the hub protocol`);
|
|
316
|
+
}
|
|
317
|
+
throw e;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
export async function discoverMetadata(io, origin) {
|
|
321
|
+
const res = await hubFetch(io, resolveEndpoint(origin, '/.well-known/oauth-authorization-server'), {
|
|
322
|
+
headers: { Accept: 'application/json' },
|
|
323
|
+
});
|
|
324
|
+
if (!res.ok) {
|
|
325
|
+
throw new CliError(`could not read OAuth metadata from ${origin} (HTTP ${res.status})`);
|
|
326
|
+
}
|
|
327
|
+
return (await res.json());
|
|
328
|
+
}
|
|
329
|
+
export async function discoverTokenEndpoint(io, origin) {
|
|
330
|
+
const meta = await discoverMetadata(io, origin);
|
|
331
|
+
if (!meta.token_endpoint)
|
|
332
|
+
throw new CliError(`hub ${origin} advertises no token_endpoint`);
|
|
333
|
+
return resolveEndpoint(origin, meta.token_endpoint);
|
|
334
|
+
}
|
|
335
|
+
// ---- OAuth refresh ---------------------------------------------------------
|
|
336
|
+
/**
|
|
337
|
+
* Ensure an `oauth` credential's access token is fresh: if it expires within
|
|
338
|
+
* 60s, refresh once (grant_type=refresh_token) and persist the new token. No-op
|
|
339
|
+
* for `agent`/`oauth-pasted` credentials (they don't refresh). Returns the
|
|
340
|
+
* possibly-updated credential.
|
|
341
|
+
*
|
|
342
|
+
* The `expiresAt - nowMs() > FRESH_WINDOW_MS` fast path is the cheap first check
|
|
343
|
+
* of a double-checked pattern: it returns WITHOUT locking; the re-read under the
|
|
344
|
+
* lock inside `refreshOAuth` is the second check.
|
|
345
|
+
*
|
|
346
|
+
* `slot` is the slot the credential was READ from — a refreshed token must be
|
|
347
|
+
* written back to that same slot, never to a default one.
|
|
348
|
+
*/
|
|
349
|
+
export async function ensureFreshOAuth(io, origin, slot, cred, persist = true) {
|
|
350
|
+
if (cred.kind !== 'oauth')
|
|
351
|
+
return cred;
|
|
352
|
+
if (cred.expiresAt - nowMs() > FRESH_WINDOW_MS)
|
|
353
|
+
return cred;
|
|
354
|
+
return refreshOAuth(io, origin, slot, cred, persist);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Perform ONE HTTP refresh (grant_type=refresh_token) using `input` and return
|
|
358
|
+
* the freshly minted oauth credential. Does NOT touch the store or the lock —
|
|
359
|
+
* the caller decides whether/where to persist. A rotating refresh token echoes
|
|
360
|
+
* the new one; a server that omits it keeps `input.refreshToken`.
|
|
361
|
+
*/
|
|
362
|
+
async function performRefresh(io, origin, input) {
|
|
363
|
+
const tokenEndpoint = await discoverTokenEndpoint(io, origin);
|
|
364
|
+
const body = new URLSearchParams({
|
|
365
|
+
grant_type: 'refresh_token',
|
|
366
|
+
refresh_token: input.refreshToken,
|
|
367
|
+
client_id: input.clientId,
|
|
368
|
+
});
|
|
369
|
+
const res = await hubFetch(io, tokenEndpoint, {
|
|
370
|
+
method: 'POST',
|
|
371
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
372
|
+
body: body.toString(),
|
|
373
|
+
});
|
|
374
|
+
if (!res.ok) {
|
|
375
|
+
throw new CliError('credential expired and refresh failed — run `owenloop login`');
|
|
376
|
+
}
|
|
377
|
+
const json = (await res.json());
|
|
378
|
+
if (typeof json.access_token !== 'string') {
|
|
379
|
+
throw new CliError('credential expired and refresh returned no access token — run `owenloop login`');
|
|
380
|
+
}
|
|
381
|
+
const expiresIn = typeof json.expires_in === 'number' ? json.expires_in : 3600;
|
|
382
|
+
return {
|
|
383
|
+
kind: 'oauth',
|
|
384
|
+
accessToken: json.access_token,
|
|
385
|
+
refreshToken: typeof json.refresh_token === 'string' ? json.refresh_token : input.refreshToken,
|
|
386
|
+
expiresAt: nowMs() + expiresIn * 1000,
|
|
387
|
+
clientId: input.clientId,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Refresh an `oauth` credential's access token.
|
|
392
|
+
*
|
|
393
|
+
* `persist` defaults to true — the normal case is refreshing an ALREADY stored,
|
|
394
|
+
* trusted credential (push/connect), where persisting immediately matters
|
|
395
|
+
* because refresh tokens can be single-use/rotating: losing the new one to a
|
|
396
|
+
* later crash would strand the user. `verifyCredential`'s login-time use passes
|
|
397
|
+
* `persist: false` — a not-yet-stored credential must never be written to
|
|
398
|
+
* disk/keychain before it is proven to work end to end.
|
|
399
|
+
*
|
|
400
|
+
* Two paths:
|
|
401
|
+
*
|
|
402
|
+
* - **Unlocked** (`persist: false`, i.e. login-time verify; OR an external
|
|
403
|
+
* credential command is configured): byte-for-byte the pre-lock behavior —
|
|
404
|
+
* refresh over HTTP, do NOT touch the store, do NOT lock, do NOT adopt.
|
|
405
|
+
* `persist: false` must never adopt a stored credential: the caller is
|
|
406
|
+
* verifying a specific not-yet-stored token, and handing back some other slot
|
|
407
|
+
* occupant would verify the WRONG credential. In external-command mode
|
|
408
|
+
* owenloop owns none of the credential lifecycle, so it neither locks nor
|
|
409
|
+
* persists (matching the old `persist && externalCredentialCommand ===
|
|
410
|
+
* undefined` gate).
|
|
411
|
+
*
|
|
412
|
+
* - **Locked** (`persist: true` and no external command): acquire the credential
|
|
413
|
+
* lock, RE-READ the slot, then decide:
|
|
414
|
+
* * stored is oauth AND its accessToken differs from ours AND it is fresh
|
|
415
|
+
* (> `FRESH_WINDOW_MS` from expiry) → another process already refreshed;
|
|
416
|
+
* adopt its credential with ZERO network calls and ZERO writes.
|
|
417
|
+
* * stored is oauth AND differs from ours but is NOT fresh → refresh using
|
|
418
|
+
* STORED as input (its refreshToken is the newest link in the rotation
|
|
419
|
+
* chain; ours is provably older), persist, return.
|
|
420
|
+
* * otherwise (stored same token, absent, or non-oauth) → refresh using
|
|
421
|
+
* `cred`, persist, return.
|
|
422
|
+
* Release the lock in `finally`.
|
|
423
|
+
*
|
|
424
|
+
* The `accessToken !== cred.accessToken` guard (not freshness alone) exists
|
|
425
|
+
* because `authedGet` calls this on a 401 with a token that may not be near
|
|
426
|
+
* expiry: freshness-only adoption would hand the caller back its own
|
|
427
|
+
* just-rejected token and turn a recoverable 401 into a hard failure.
|
|
428
|
+
* Token-differs ⇒ someone else moved the chain; token-same ⇒ we are first,
|
|
429
|
+
* refresh for real. The locked-section persist calls `storeCredentialUnlocked`
|
|
430
|
+
* (not the exported wrapper) — it already holds the lock.
|
|
431
|
+
*/
|
|
432
|
+
export async function refreshOAuth(io, origin, slot, cred, persist = true) {
|
|
433
|
+
// Unlocked path: never touch the store, never lock, never adopt.
|
|
434
|
+
if (!persist || externalCredentialCommand(io.env) !== undefined) {
|
|
435
|
+
return performRefresh(io, origin, cred);
|
|
436
|
+
}
|
|
437
|
+
// Locked path: acquire → re-read → adopt-or-refresh → persist → release.
|
|
438
|
+
const handle = await acquireCredLock(io);
|
|
439
|
+
try {
|
|
440
|
+
const stored = readStoredCredential(origin, { ...slot, env: io.env, keychain: io.keychain });
|
|
441
|
+
if (stored && stored.kind === 'oauth' && stored.accessToken !== cred.accessToken) {
|
|
442
|
+
// Another process moved the rotation chain since we read `cred`.
|
|
443
|
+
if (stored.expiresAt - nowMs() > FRESH_WINDOW_MS) {
|
|
444
|
+
// Already fresh — adopt it. Return the STORED object (its rotated
|
|
445
|
+
// refreshToken included) with zero network and zero writes.
|
|
446
|
+
return stored;
|
|
447
|
+
}
|
|
448
|
+
// Differs but not fresh — refresh using STORED (the newer refresh token).
|
|
449
|
+
const refreshed = await performRefresh(io, origin, stored);
|
|
450
|
+
storeCredentialUnlocked(io, origin, slot, refreshed);
|
|
451
|
+
return refreshed;
|
|
452
|
+
}
|
|
453
|
+
// Stored same token, absent, or non-oauth → we are first: refresh using ours.
|
|
454
|
+
const refreshed = await performRefresh(io, origin, cred);
|
|
455
|
+
storeCredentialUnlocked(io, origin, slot, refreshed);
|
|
456
|
+
return refreshed;
|
|
457
|
+
}
|
|
458
|
+
finally {
|
|
459
|
+
releaseFileLock(handle);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Mint a new agent identity on `origin` as the human `cred` and persist the
|
|
464
|
+
* returned `olp_` token to slot `agent:<name>`. CLI-free (no `Args`, no exit
|
|
465
|
+
* codes — the caller maps failures to exit codes) so both `owenloop agent new`
|
|
466
|
+
* (O3) and `owenloop mcp`'s `create_agent` (O2) can reuse it.
|
|
467
|
+
*
|
|
468
|
+
* **The token NEVER leaves this function.** It flows exactly one hop —
|
|
469
|
+
* `asMintAgentTokenOk(body).token` → `storeCredential` — and is never returned,
|
|
470
|
+
* thrown, logged, or embedded in any message (identity model §6). The returned
|
|
471
|
+
* `MintAgentResult` structurally omits it. The hub's 4xx `message` (e.g. H1's
|
|
472
|
+
* `agent name already taken: "…"`) is surfaced verbatim via `CliError`; a
|
|
473
|
+
* malformed 2xx names the offending FIELD only, never a value.
|
|
474
|
+
*
|
|
475
|
+
* Order is load-bearing (PR #69 lesson): the client-side name check and the
|
|
476
|
+
* external-command refusal both run BEFORE any network call. Refusing only at
|
|
477
|
+
* `storeCredential` time would mint a server-side token that can never be stored
|
|
478
|
+
* locally — permanently burning the agent name (re-running refuses "taken").
|
|
479
|
+
*
|
|
480
|
+
* @param humanSlot the slot `cred` was read from (always `{principal:'human'}`
|
|
481
|
+
* today; explicit for symmetry with the store/refresh signatures).
|
|
482
|
+
* @param params.scopes defaults to `['work']` — the H3 route REQUIRES a
|
|
483
|
+
* non-empty `scopes`; an empty list is server-refused.
|
|
484
|
+
* @param params.pools omitted when absent so the server defaults to the minter's
|
|
485
|
+
* personal pool (`pools: []` is server-refused with `pool_invalid`).
|
|
486
|
+
*/
|
|
487
|
+
export async function mintAgentCredential(io, origin, humanSlot, cred, params) {
|
|
488
|
+
// 1. Validate the agent name before any I/O. The client regex is byte-identical
|
|
489
|
+
// to the server's, so this can never mask a server-side "invalid name" —
|
|
490
|
+
// only "taken" is left to the server. Throws on an invalid name.
|
|
491
|
+
credentialSlot({ principal: 'agent', account: params.name });
|
|
492
|
+
// 2. Refuse an external-command setup BEFORE the network call. In that mode the
|
|
493
|
+
// command — not the local store — is authoritative, so a minted token could
|
|
494
|
+
// never be stored; minting first would burn the name. Same wording as
|
|
495
|
+
// `storeCredential`'s refusal.
|
|
496
|
+
if (externalCredentialCommand(io.env) !== undefined) {
|
|
497
|
+
throw new CliError('an external credential command is configured (OWENLOOP_CREDENTIAL_COMMAND), so it — not the ' +
|
|
498
|
+
'local store — supplies credentials for this hub; unset it to use `owenloop login`');
|
|
499
|
+
}
|
|
500
|
+
// 3. Freshen the human oauth bearer (persist=true: a rotated refresh token must
|
|
501
|
+
// land in the store). No-op for oauth-pasted / agent kinds.
|
|
502
|
+
let current = await ensureFreshOAuth(io, origin, humanSlot, cred);
|
|
503
|
+
const scopes = params.scopes ?? ['work'];
|
|
504
|
+
const doPost = (bearer) => hubFetch(io, resolveEndpoint(origin, '/api/mint_agent_token'), {
|
|
505
|
+
method: 'POST',
|
|
506
|
+
headers: {
|
|
507
|
+
Authorization: authHeader(bearer),
|
|
508
|
+
'Content-Type': 'application/json',
|
|
509
|
+
Accept: 'application/json',
|
|
510
|
+
},
|
|
511
|
+
// `pools` omitted entirely when absent (server default = personal pool);
|
|
512
|
+
// never sent as `[]` (server-refused).
|
|
513
|
+
body: JSON.stringify({
|
|
514
|
+
name: params.name,
|
|
515
|
+
scopes,
|
|
516
|
+
...(params.pools !== undefined ? { pools: params.pools } : {}),
|
|
517
|
+
}),
|
|
518
|
+
});
|
|
519
|
+
// 4 + 5. POST; on a 401 with an oauth credential, refresh once and retry once —
|
|
520
|
+
// the exact `authedGet`/`dispatchPush` pattern.
|
|
521
|
+
let res = await doPost(current);
|
|
522
|
+
if (res.status === 401 && current.kind === 'oauth') {
|
|
523
|
+
current = await refreshOAuth(io, origin, humanSlot, current);
|
|
524
|
+
res = await doPost(current);
|
|
525
|
+
}
|
|
526
|
+
if (res.status === 401) {
|
|
527
|
+
// A second 401 (or a non-oauth credential the hub rejected) is a hard
|
|
528
|
+
// "credential rejected" — the human slot never holds an agent kind, so the
|
|
529
|
+
// agent-token wording cannot apply here.
|
|
530
|
+
throw new CliError('credential rejected by the hub — run `owenloop login`');
|
|
531
|
+
}
|
|
532
|
+
// 6. Any other non-2xx: surface the hub's typed `message` VERBATIM (this is how
|
|
533
|
+
// H1's `agent name already taken: "…"`, `pool_invalid`, `bad_request`, and
|
|
534
|
+
// `forbidden` all surface uniformly). Never include raw body text.
|
|
535
|
+
if (!res.ok) {
|
|
536
|
+
let message;
|
|
537
|
+
try {
|
|
538
|
+
const errBody = (await res.json());
|
|
539
|
+
if (typeof errBody === 'object' && errBody !== null) {
|
|
540
|
+
const m = errBody.message;
|
|
541
|
+
if (typeof m === 'string' && m !== '')
|
|
542
|
+
message = m;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
catch {
|
|
546
|
+
// Non-JSON body — fall through to the generic status message.
|
|
547
|
+
}
|
|
548
|
+
throw new CliError(message ?? `hub ${origin} rejected the mint (HTTP ${res.status})`);
|
|
549
|
+
}
|
|
550
|
+
// 7. Narrow the 2xx body through the whitelisting guard. A malformed body could
|
|
551
|
+
// still carry the plaintext in `text`, so the guard's message names the
|
|
552
|
+
// FIELD only — rewrapped as a CliError to carry it verbatim.
|
|
553
|
+
// `res.json()` itself is wrapped too: on a 200 whose body is NOT valid JSON,
|
|
554
|
+
// V8's SyntaxError message embeds a verbatim snippet of the raw body — which
|
|
555
|
+
// on THIS endpoint is the plaintext token. The thrown CliError message is a
|
|
556
|
+
// FIXED string (never the parse-error message) so no body text can leak (§6).
|
|
557
|
+
let body;
|
|
558
|
+
try {
|
|
559
|
+
body = (await res.json());
|
|
560
|
+
}
|
|
561
|
+
catch {
|
|
562
|
+
throw new CliError('mint_agent_token: malformed success response — body is not valid JSON');
|
|
563
|
+
}
|
|
564
|
+
let ok;
|
|
565
|
+
try {
|
|
566
|
+
ok = asMintAgentTokenOk(body);
|
|
567
|
+
}
|
|
568
|
+
catch (e) {
|
|
569
|
+
throw new CliError(e.message);
|
|
570
|
+
}
|
|
571
|
+
// 8. Store the token — its only hop out of this function. On a keychain write
|
|
572
|
+
// failure the token was ALREADY minted server-side and is now unrecoverable
|
|
573
|
+
// locally; report that honestly. NEVER print the token as a fallback (§6).
|
|
574
|
+
let storage;
|
|
575
|
+
try {
|
|
576
|
+
storage = await storeCredential(io, origin, { principal: 'agent', account: params.name }, { kind: 'agent', accessToken: ok.token });
|
|
577
|
+
}
|
|
578
|
+
catch (e) {
|
|
579
|
+
throw new CliError(`the agent token was minted but could not be stored locally: ${e.message}. ` +
|
|
580
|
+
`The agent '${params.name}' now exists on the hub — recover via the console (Reconnect/re-key) ` +
|
|
581
|
+
`once storage works; re-running \`agent new ${params.name}\` will refuse the taken name`);
|
|
582
|
+
}
|
|
583
|
+
// 9. Return non-secret handles only — no token field exists to leak.
|
|
584
|
+
return { id: ok.id, agentId: ok.agentId, pools: ok.pools, storage };
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Re-key an EXISTING agent identity on `origin` as the human `cred`: the hub
|
|
588
|
+
* mints a fresh `olp_` token for `agentId`, REVOKES the identity's current
|
|
589
|
+
* token(s), and this function persists the new token into the SAME
|
|
590
|
+
* `agent:<name>` slot — overwriting the old one. Sibling of
|
|
591
|
+
* `mintAgentCredential` with the identical §6 discipline; the only shape
|
|
592
|
+
* differences are the endpoint (`/api/rekey_agent_token`), the request body
|
|
593
|
+
* (`{agentId}` — no name/scopes/pools; rekey preserves pools), and the response
|
|
594
|
+
* guard (`asRekeyAgentTokenOk` — no `pools` field).
|
|
595
|
+
*
|
|
596
|
+
* **The token NEVER leaves this function.** It flows exactly one hop —
|
|
597
|
+
* `asRekeyAgentTokenOk(body).token` → `storeCredential` — and is never returned,
|
|
598
|
+
* thrown, logged, or embedded in any message. The returned `RekeyAgentResult`
|
|
599
|
+
* structurally omits it.
|
|
600
|
+
*
|
|
601
|
+
* **Irreversibility (why the caller must gate this behind a hard auth step):**
|
|
602
|
+
* a successful rekey has ALREADY revoked the old token server-side by the time
|
|
603
|
+
* this function returns. If the local `storeCredential` then fails, the old
|
|
604
|
+
* installation is disconnected AND the new token is unrecoverable locally — the
|
|
605
|
+
* error says exactly that and points at console Reconnect; it never prints the
|
|
606
|
+
* token as a fallback.
|
|
607
|
+
*
|
|
608
|
+
* @param humanSlot the slot `cred` was read from (always `{principal:'human'}`).
|
|
609
|
+
* @param params.agentId the identity to rekey (resolved by the caller from the
|
|
610
|
+
* `agent_identities` listing by NAME — names are org-unique).
|
|
611
|
+
* @param params.name the agent account name — the local slot `agent:<name>` the
|
|
612
|
+
* new token is written to. Validated before any I/O.
|
|
613
|
+
*/
|
|
614
|
+
export async function rekeyAgentCredential(io, origin, humanSlot, cred, params) {
|
|
615
|
+
// 1. Validate the agent name (the local slot target) before any I/O — same
|
|
616
|
+
// byte-identical client regex as mint.
|
|
617
|
+
credentialSlot({ principal: 'agent', account: params.name });
|
|
618
|
+
// 2. Refuse an external-command setup BEFORE the network call — same reason as
|
|
619
|
+
// mint: the rekey would revoke the old token server-side, but the new one
|
|
620
|
+
// could never be stored, stranding the install.
|
|
621
|
+
if (externalCredentialCommand(io.env) !== undefined) {
|
|
622
|
+
throw new CliError('an external credential command is configured (OWENLOOP_CREDENTIAL_COMMAND), so it — not the ' +
|
|
623
|
+
'local store — supplies credentials for this hub; unset it to use `owenloop login`');
|
|
624
|
+
}
|
|
625
|
+
// 3. Freshen the human oauth bearer (persist=true). No-op for non-oauth kinds.
|
|
626
|
+
let current = await ensureFreshOAuth(io, origin, humanSlot, cred);
|
|
627
|
+
const doPost = (bearer) => hubFetch(io, resolveEndpoint(origin, '/api/rekey_agent_token'), {
|
|
628
|
+
method: 'POST',
|
|
629
|
+
headers: {
|
|
630
|
+
Authorization: authHeader(bearer),
|
|
631
|
+
'Content-Type': 'application/json',
|
|
632
|
+
Accept: 'application/json',
|
|
633
|
+
},
|
|
634
|
+
body: JSON.stringify({ agentId: params.agentId }),
|
|
635
|
+
});
|
|
636
|
+
// 4 + 5. POST; on a 401 with an oauth credential, refresh once and retry once.
|
|
637
|
+
let res = await doPost(current);
|
|
638
|
+
if (res.status === 401 && current.kind === 'oauth') {
|
|
639
|
+
current = await refreshOAuth(io, origin, humanSlot, current);
|
|
640
|
+
res = await doPost(current);
|
|
641
|
+
}
|
|
642
|
+
if (res.status === 401) {
|
|
643
|
+
throw new CliError('credential rejected by the hub — run `owenloop login`');
|
|
644
|
+
}
|
|
645
|
+
// 6. Any other non-2xx: surface the hub's typed `message` VERBATIM (e.g. an
|
|
646
|
+
// unknown agentId, or a `forbidden` for a non-admin human). Never raw body.
|
|
647
|
+
if (!res.ok) {
|
|
648
|
+
let message;
|
|
649
|
+
try {
|
|
650
|
+
const errBody = (await res.json());
|
|
651
|
+
if (typeof errBody === 'object' && errBody !== null) {
|
|
652
|
+
const m = errBody.message;
|
|
653
|
+
if (typeof m === 'string' && m !== '')
|
|
654
|
+
message = m;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
catch {
|
|
658
|
+
// Non-JSON body — fall through to the generic status message.
|
|
659
|
+
}
|
|
660
|
+
throw new CliError(message ?? `hub ${origin} rejected the rekey (HTTP ${res.status})`);
|
|
661
|
+
}
|
|
662
|
+
// 7. Narrow the 2xx body. Same double-wrap as mint: the raw body carries the
|
|
663
|
+
// plaintext in `text`, and V8's SyntaxError embeds body snippets, so BOTH
|
|
664
|
+
// the JSON-parse failure and the guard failure throw FIXED/field-only
|
|
665
|
+
// strings — never body text.
|
|
666
|
+
let body;
|
|
667
|
+
try {
|
|
668
|
+
body = (await res.json());
|
|
669
|
+
}
|
|
670
|
+
catch {
|
|
671
|
+
throw new CliError('rekey_agent_token: malformed success response — body is not valid JSON');
|
|
672
|
+
}
|
|
673
|
+
let ok;
|
|
674
|
+
try {
|
|
675
|
+
ok = asRekeyAgentTokenOk(body);
|
|
676
|
+
}
|
|
677
|
+
catch (e) {
|
|
678
|
+
throw new CliError(e.message);
|
|
679
|
+
}
|
|
680
|
+
// 8. Store the new token — its only hop. On a store failure the old token is
|
|
681
|
+
// ALREADY revoked server-side (the previous installation is disconnected)
|
|
682
|
+
// and the new one is now unrecoverable locally; say so honestly and point
|
|
683
|
+
// at console Reconnect. NEVER print the token as a fallback (§6).
|
|
684
|
+
let storage;
|
|
685
|
+
try {
|
|
686
|
+
storage = await storeCredential(io, origin, { principal: 'agent', account: params.name }, { kind: 'agent', accessToken: ok.token });
|
|
687
|
+
}
|
|
688
|
+
catch (e) {
|
|
689
|
+
throw new CliError(`the agent token was re-keyed but the new token could not be stored locally: ${e.message}. ` +
|
|
690
|
+
`The old token for '${params.name}' is already revoked (any other running copy is now disconnected); ` +
|
|
691
|
+
`recover via the console (Reconnect) — the new token cannot be recovered from here`);
|
|
692
|
+
}
|
|
693
|
+
// 9. Return non-secret handles only — no token field exists to leak.
|
|
694
|
+
return { id: ok.id, agentId: ok.agentId, revokedTokenIds: ok.revokedTokenIds, scopes: ok.scopes, storage };
|
|
695
|
+
}
|