kenso 0.1.175 → 0.1.176
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 +6 -0
- package/dist/kenso.js +181 -30
- package/dist/operations.index.json +1 -1
- package/dist/operations.json +1 -1
- package/docs/auth.md +2 -0
- package/docs/reference.md +4 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in the kenso CLI, newest first, by the day it changed. A new version publishes after every change.
|
|
4
4
|
|
|
5
|
+
## 2026-11-23
|
|
6
|
+
|
|
7
|
+
- keep a matching saved apiUrl on login, and record the sandbox key's origin
|
|
8
|
+
- logout and --dry-run keep the saved key to its issued-for origin
|
|
9
|
+
- refuse dot-segment route values and bind the saved key to its origin
|
|
10
|
+
|
|
5
11
|
## 2026-11-22
|
|
6
12
|
|
|
7
13
|
- restore a deleted person or deal within 30 days, and undo a bulk delete of people or deals
|
package/dist/kenso.js
CHANGED
|
@@ -386,6 +386,79 @@ var init_folder = __esm({
|
|
|
386
386
|
}
|
|
387
387
|
});
|
|
388
388
|
|
|
389
|
+
// src/core/endpoint.ts
|
|
390
|
+
function originOf(url) {
|
|
391
|
+
try {
|
|
392
|
+
return new URL(url).origin;
|
|
393
|
+
} catch {
|
|
394
|
+
return void 0;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function checkEndpoint(url, variable) {
|
|
398
|
+
let parsed2;
|
|
399
|
+
try {
|
|
400
|
+
parsed2 = new URL(url);
|
|
401
|
+
} catch {
|
|
402
|
+
throw usageError(`${variable} is not a URL.`, { field: variable, hint: `Set ${variable} to an https URL, or unset it.` });
|
|
403
|
+
}
|
|
404
|
+
if (parsed2.protocol === "https:" || parsed2.protocol === "http:" && LOOPBACK_HOSTS.has(parsed2.hostname)) return parsed2;
|
|
405
|
+
throw new KensoError({
|
|
406
|
+
code: "insecure_url",
|
|
407
|
+
message: `${parsed2.protocol === "http:" ? parsed2.origin : `A ${parsed2.protocol} URL`} is refused: the API key goes only over https (plain http only to localhost or 127.0.0.1).`,
|
|
408
|
+
exitCode: ExitCode.Usage,
|
|
409
|
+
field: variable,
|
|
410
|
+
hint: `Set ${variable} to an https URL, or unset it (it may also come from the profile's saved apiUrl).`
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function otherOriginWarning(origin, expected, variable) {
|
|
414
|
+
return `Using ${origin}, not ${expected} (${variable === "KENSO_API_URL" ? "KENSO_API_URL or the profile's apiUrl" : variable}): the API key goes there.`;
|
|
415
|
+
}
|
|
416
|
+
function keyOriginError(keyOrigin, origin, variable) {
|
|
417
|
+
return new KensoError({
|
|
418
|
+
code: "key_origin_mismatch",
|
|
419
|
+
message: `The saved API key was issued for ${keyOrigin}, so it is not sent to ${origin}.`,
|
|
420
|
+
exitCode: ExitCode.Auth,
|
|
421
|
+
field: variable,
|
|
422
|
+
hint: variable === "KENSO_API_URL" ? `Set KENSO_API_URL to ${keyOrigin} (or unset it if that is the default), or log in on ${origin} with kenso auth login (--profile <name> keeps the saved key; --save-api-url saves the URL too).` : `Unset KENSO_MCP_URL to use the Kenso MCP, or pass a key for ${origin} in KENSO_API_KEY.`,
|
|
423
|
+
next: "kenso auth login"
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function checkApiSend(url, keyOrigin, warned, warn) {
|
|
427
|
+
const { origin } = new URL(url);
|
|
428
|
+
if (keyOrigin !== void 0 && origin !== keyOrigin) throw keyOriginError(keyOrigin, origin, "KENSO_API_URL");
|
|
429
|
+
if (origin !== DEFAULT_API_ORIGIN && !warned.origin) {
|
|
430
|
+
warned.origin = true;
|
|
431
|
+
warn?.(otherOriginWarning(origin, DEFAULT_API_ORIGIN, "KENSO_API_URL"));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function isDotSegment(segment) {
|
|
435
|
+
const dots = segment.replace(/%2e/gi, ".");
|
|
436
|
+
return dots === "." || dots === "..";
|
|
437
|
+
}
|
|
438
|
+
function checkPath(path) {
|
|
439
|
+
const route = (path.split(/[?#]/, 1)[0] ?? "").replace(/[\t\n\r]/g, "");
|
|
440
|
+
if (route.split(/[\\/]/).some(isDotSegment)) {
|
|
441
|
+
throw new KensoError({
|
|
442
|
+
code: "path_not_kept",
|
|
443
|
+
message: `The request path ${route} has a . or .. segment, which would send the request to another route.`,
|
|
444
|
+
exitCode: ExitCode.Usage,
|
|
445
|
+
field: "path",
|
|
446
|
+
hint: "No Kenso id or key is . or ..: check the value that filled the path."
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
var DEFAULT_API_ORIGIN, DEFAULT_MCP_ORIGIN, LOOPBACK_HOSTS;
|
|
451
|
+
var init_endpoint = __esm({
|
|
452
|
+
"src/core/endpoint.ts"() {
|
|
453
|
+
"use strict";
|
|
454
|
+
init_errors();
|
|
455
|
+
init_exit_codes();
|
|
456
|
+
DEFAULT_API_ORIGIN = "https://api.ken.so";
|
|
457
|
+
DEFAULT_MCP_ORIGIN = "https://mcp.ken.so";
|
|
458
|
+
LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
389
462
|
// src/core/config.ts
|
|
390
463
|
import { chmodSync, existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, renameSync as renameSync2, rmSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
391
464
|
import { homedir as homedir2 } from "node:os";
|
|
@@ -489,6 +562,9 @@ function clearCache(env = process.env) {
|
|
|
489
562
|
const dir3 = join2(configDir(env), "cache");
|
|
490
563
|
if (existsSync2(dir3)) rmSync(dir3, { recursive: true, force: true });
|
|
491
564
|
}
|
|
565
|
+
function profileKeyOrigin(profile) {
|
|
566
|
+
return profile.keyOrigin ?? originOf(profile.apiUrl ?? DEFAULT_API_URL) ?? DEFAULT_API_ORIGIN;
|
|
567
|
+
}
|
|
492
568
|
function nonEmpty(value) {
|
|
493
569
|
const trimmed = value?.trim();
|
|
494
570
|
return trimmed ? trimmed : void 0;
|
|
@@ -509,11 +585,13 @@ function resolveAuth(flags, env = process.env, cwd = process.cwd()) {
|
|
|
509
585
|
const workspaceId = flagWorkspace ?? envWorkspace ?? folderWorkspace ?? profile.workspaceId;
|
|
510
586
|
const workspaceSource = flagWorkspace ? "flag" : envWorkspace ? "env" : folderWorkspace ? "folder" : profile.workspaceId ? "profile" : "none";
|
|
511
587
|
const apiUrl = (nonEmpty(env.KENSO_API_URL) ?? profile.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
588
|
+
const keyOrigin = source === "profile" ? profileKeyOrigin(profile) : void 0;
|
|
512
589
|
return {
|
|
513
590
|
apiKey,
|
|
514
591
|
workspaceId,
|
|
515
592
|
workspaceSource,
|
|
516
593
|
apiUrl,
|
|
594
|
+
...keyOrigin !== void 0 ? { keyOrigin } : {},
|
|
517
595
|
profileName,
|
|
518
596
|
source,
|
|
519
597
|
...folder ? { folderFile: folder.path } : {},
|
|
@@ -521,6 +599,11 @@ function resolveAuth(flags, env = process.env, cwd = process.cwd()) {
|
|
|
521
599
|
...skipped ? { folderFileSkipped: skipped } : {}
|
|
522
600
|
};
|
|
523
601
|
}
|
|
602
|
+
function apiUrlToSave(auth, env, saveEnvUrl, profileName) {
|
|
603
|
+
if (auth.apiUrl === DEFAULT_API_URL) return void 0;
|
|
604
|
+
if (nonEmpty(env.KENSO_API_URL) === void 0 || saveEnvUrl) return auth.apiUrl;
|
|
605
|
+
return readConfig(env).profiles[profileName]?.apiUrl?.replace(/\/+$/, "") === auth.apiUrl ? auth.apiUrl : void 0;
|
|
606
|
+
}
|
|
524
607
|
function folderProfileNotice(auth) {
|
|
525
608
|
return auth.profileFromFolder ? `${auth.folderFile} chooses profile ${auth.profileName} here; pass --profile for another.` : void 0;
|
|
526
609
|
}
|
|
@@ -537,10 +620,11 @@ var init_config = __esm({
|
|
|
537
620
|
init_errors();
|
|
538
621
|
init_exit_codes();
|
|
539
622
|
init_folder();
|
|
623
|
+
init_endpoint();
|
|
540
624
|
DEFAULT_API_URL = "https://api.ken.so";
|
|
541
625
|
DEFAULT_PROFILE = "default";
|
|
542
626
|
CONFIG_FILE = "config.json";
|
|
543
|
-
PROFILE_KEYS = ["apiKey", "workspaceId", "apiUrl", "email", "keyId"];
|
|
627
|
+
PROFILE_KEYS = ["apiKey", "workspaceId", "apiUrl", "keyOrigin", "email", "keyId"];
|
|
544
628
|
}
|
|
545
629
|
});
|
|
546
630
|
|
|
@@ -630,6 +714,7 @@ var KEN_VERSION, REQUEST_TIMEOUT_MS, TRANSIENT_STATUSES, MAX_TRANSIENT_RETRIES,
|
|
|
630
714
|
var init_http = __esm({
|
|
631
715
|
"src/core/http.ts"() {
|
|
632
716
|
"use strict";
|
|
717
|
+
init_endpoint();
|
|
633
718
|
init_errors();
|
|
634
719
|
init_exit_codes();
|
|
635
720
|
init_redact();
|
|
@@ -647,16 +732,23 @@ var init_http = __esm({
|
|
|
647
732
|
sleep;
|
|
648
733
|
rateLimitBudgetMs;
|
|
649
734
|
rateLimitWaitedMs = 0;
|
|
650
|
-
|
|
735
|
+
/** Shared with the withApiKey copy, so the other-origin warning prints once per command. */
|
|
736
|
+
warned;
|
|
737
|
+
constructor(opts, warned = { origin: false }) {
|
|
651
738
|
this.opts = { ...opts, apiUrl: opts.apiUrl.replace(/\/+$/, "") };
|
|
739
|
+
this.warned = warned;
|
|
652
740
|
this.workspaceId = opts.workspaceId;
|
|
653
741
|
this.fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
654
742
|
this.sleep = opts.sleep;
|
|
655
743
|
this.rateLimitBudgetMs = opts.maxRateLimitWaitMs ?? DEFAULT_RATE_LIMIT_BUDGET_MS;
|
|
656
744
|
}
|
|
657
|
-
/** The same client with another credential: kenso work run --token-stdin sets the run token this way. */
|
|
745
|
+
/** The same client with another credential (not a saved key): kenso work run --token-stdin sets the run token this way. */
|
|
658
746
|
withApiKey(apiKey) {
|
|
659
|
-
return new _KensoClient({ ...this.opts, apiKey });
|
|
747
|
+
return new _KensoClient({ ...this.opts, apiKey, keyOrigin: void 0 }, this.warned);
|
|
748
|
+
}
|
|
749
|
+
/** What --dry-run prints: the URL, after the checks a send makes. */
|
|
750
|
+
urlFor(req) {
|
|
751
|
+
return this.sendUrl(req);
|
|
660
752
|
}
|
|
661
753
|
/** Sends one API call. Throws KensoError on a non-2xx answer after retries. */
|
|
662
754
|
async request(req) {
|
|
@@ -664,7 +756,7 @@ var init_http = __esm({
|
|
|
664
756
|
if (req.method === "GET" && (req.body !== void 0 || req.form !== void 0)) {
|
|
665
757
|
throw usageError("A GET request cannot carry a body.", { field: "data", hint: "Send the values in the query string, or use another method." });
|
|
666
758
|
}
|
|
667
|
-
const url = this.
|
|
759
|
+
const url = this.sendUrl(req);
|
|
668
760
|
const headers = this.buildHeaders(req);
|
|
669
761
|
const body2 = req.form ?? (req.body !== void 0 ? JSON.stringify(req.body) : void 0);
|
|
670
762
|
const mayRetryTransient = req.method !== "POST" || req.retrySafe === true;
|
|
@@ -776,7 +868,7 @@ var init_http = __esm({
|
|
|
776
868
|
*/
|
|
777
869
|
async openStream(req, signal) {
|
|
778
870
|
if (!req.anonymous && !this.opts.apiKey) throw noApiKeyError();
|
|
779
|
-
const url = this.
|
|
871
|
+
const url = this.sendUrl(req);
|
|
780
872
|
const headers = this.buildHeaders({ ...req, headers: { Accept: "text/event-stream", ...req.headers } });
|
|
781
873
|
const connect = new AbortController();
|
|
782
874
|
const timer = setTimeout(() => connect.abort(new DOMException("No answer in time.", "TimeoutError")), REQUEST_TIMEOUT_MS);
|
|
@@ -831,7 +923,16 @@ var init_http = __esm({
|
|
|
831
923
|
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
832
924
|
}
|
|
833
925
|
}
|
|
926
|
+
/** The URL to send `req` to, after checkApiSend. */
|
|
927
|
+
sendUrl(req) {
|
|
928
|
+
const url = this.buildUrl(req.path, req.query);
|
|
929
|
+
checkApiSend(url, req.keyOrigin ?? (req.anonymous ? void 0 : this.opts.keyOrigin), this.warned, this.opts.onWarning);
|
|
930
|
+
return url;
|
|
931
|
+
}
|
|
932
|
+
/** Refuses an insecure API URL (DEV-13403) and a path the URL would resolve to another route (DEV-13401). */
|
|
834
933
|
buildUrl(path, query) {
|
|
934
|
+
checkEndpoint(this.opts.apiUrl, "KENSO_API_URL");
|
|
935
|
+
checkPath(path);
|
|
835
936
|
const url = new URL(this.opts.apiUrl + (path.startsWith("/") ? path : `/${path}`));
|
|
836
937
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
837
938
|
if (value === void 0) continue;
|
|
@@ -3429,7 +3530,7 @@ var VERSION;
|
|
|
3429
3530
|
var init_version = __esm({
|
|
3430
3531
|
"src/core/version.ts"() {
|
|
3431
3532
|
"use strict";
|
|
3432
|
-
VERSION = true ? "0.1.
|
|
3533
|
+
VERSION = true ? "0.1.176" : "0.0.0-dev";
|
|
3433
3534
|
}
|
|
3434
3535
|
});
|
|
3435
3536
|
|
|
@@ -3451,6 +3552,8 @@ function createContext(flags, env = process.env, overrides2) {
|
|
|
3451
3552
|
const client = new KensoClient({
|
|
3452
3553
|
apiKey: auth.apiKey,
|
|
3453
3554
|
apiUrl: auth.apiUrl,
|
|
3555
|
+
keyOrigin: auth.keyOrigin,
|
|
3556
|
+
onWarning: (message) => output.warn(message),
|
|
3454
3557
|
workspaceId: auth.workspaceId,
|
|
3455
3558
|
agent,
|
|
3456
3559
|
version: VERSION,
|
|
@@ -7702,8 +7805,13 @@ function buildRequest(op, values) {
|
|
|
7702
7805
|
}
|
|
7703
7806
|
const path = op.path.replace(/\{([^}]+)\}/g, (_, name) => {
|
|
7704
7807
|
const value = values[name];
|
|
7705
|
-
|
|
7706
|
-
|
|
7808
|
+
const flag = op.routeParams.find((p) => p.name === name)?.flag ?? name;
|
|
7809
|
+
if (isBlank(value)) throw missing(op, flag);
|
|
7810
|
+
const text4 = String(value);
|
|
7811
|
+
if (text4 === "." || text4 === "..") {
|
|
7812
|
+
throw usageError(`--${flag} cannot be "${text4}": in the path it would send ${commandOf(op)} to another route.`, { field: flag });
|
|
7813
|
+
}
|
|
7814
|
+
return encodeURIComponent(text4);
|
|
7707
7815
|
});
|
|
7708
7816
|
const query = {};
|
|
7709
7817
|
for (const name of queryNames) {
|
|
@@ -7867,9 +7975,9 @@ function sameCommand(ctx, op, flags) {
|
|
|
7867
7975
|
for (const [name, value] of globals) if (value !== void 0) parts2.push(flagWithValue(name, value));
|
|
7868
7976
|
return parts2.join(" ");
|
|
7869
7977
|
}
|
|
7870
|
-
function describeRequest(req, op) {
|
|
7978
|
+
function describeRequest(ctx, req, op) {
|
|
7871
7979
|
const secrets = new Set(secretParams(op).map((s) => s.name));
|
|
7872
|
-
const out = { method: req.method, path: req.path };
|
|
7980
|
+
const out = { method: req.method, path: req.path, url: ctx.client.urlFor(req) };
|
|
7873
7981
|
if (req.query) out.query = req.query;
|
|
7874
7982
|
if (req.body !== void 0) out.body = maskSecrets(req.body, secrets);
|
|
7875
7983
|
if (req.form) out.form = describeForm(req.form, secrets);
|
|
@@ -8002,7 +8110,7 @@ async function runOperation(ctx, op, flags) {
|
|
|
8002
8110
|
const req = lean ? buildRequest(op, { ...values, ...lean }) : plain2;
|
|
8003
8111
|
if (ctx.flags.dryRun) {
|
|
8004
8112
|
const cost = op.effect === "spend" ? await spendCost(ctx, op, [req]) : {};
|
|
8005
|
-
ctx.output.object({ dryRun: true, operationId: op.id, request: describeRequest(req, op), ...cost });
|
|
8113
|
+
ctx.output.object({ dryRun: true, operationId: op.id, request: describeRequest(ctx, req, op), ...cost });
|
|
8006
8114
|
return ExitCode.Ok;
|
|
8007
8115
|
}
|
|
8008
8116
|
if (isDestructive(op)) await confirmDestructive(ctx, `${commandOf(op)} sends ${req.method} ${req.path}`, `${sameCommand(ctx, op, flags)} --yes`);
|
|
@@ -9772,6 +9880,7 @@ var init_client = __esm({
|
|
|
9772
9880
|
"use strict";
|
|
9773
9881
|
init_errors();
|
|
9774
9882
|
init_exit_codes();
|
|
9883
|
+
init_endpoint();
|
|
9775
9884
|
init_redact();
|
|
9776
9885
|
DEFAULT_MCP_URL = "https://mcp.ken.so/mcp";
|
|
9777
9886
|
MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
@@ -9784,6 +9893,7 @@ var init_client = __esm({
|
|
|
9784
9893
|
nextId = 1;
|
|
9785
9894
|
initialized = false;
|
|
9786
9895
|
constructor(opts) {
|
|
9896
|
+
checkEndpoint(opts.url, "KENSO_MCP_URL");
|
|
9787
9897
|
this.opts = opts;
|
|
9788
9898
|
this.fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
9789
9899
|
}
|
|
@@ -9936,7 +10046,7 @@ var init_agents = __esm({
|
|
|
9936
10046
|
var auth_default;
|
|
9937
10047
|
var init_auth = __esm({
|
|
9938
10048
|
"docs/auth.md"() {
|
|
9939
|
-
auth_default = '# Authentication\n\nThe CLI calls the Kenso API with a Kenso API key (`kenso_live_` plus 49 characters, or an older key: `ken_` plus 43 characters). It sends the key as `Authorization: Bearer <key>` and never prints it, logs it or puts it in an error.\n\n`kenso login`, `kenso logout` and `kenso whoami` are the same commands as `kenso auth login`, `kenso auth logout` and `kenso auth status`.\n\n## Log in with an API key\n\n1. In app.ken.so, go to Settings > API keys and create a key.\n2. Pipe it to `kenso auth login --with-key`. The key is read from stdin, never from a flag, so it stays out of your shell history and process list.\n\n```bash\necho $KEY | kenso auth login --with-key\nkenso auth login --with-key --profile client-a --workspace 1234 < key.txt\n```\n\nThe CLI checks the key with `GET /v1/me`, then saves it to `~/.kenso/config.json` (file mode 0600, folder mode 0700). It prints:\n\n```json\n{"profile":"default","email":"you@acme.io","workspaceId":"1234","workspaceCount":1}\n```\n\nA developer sandbox does not count here unless every workspace is one: a key whose user has one workspace and a sandbox saves that workspace. When the key reaches several workspaces and you did not pass `--workspace`, no workspace is saved and the output carries `"next":"kenso workspace list --search <name>"`. A key in the wrong format exits 2 (`invalid_key_format`). A key Kenso rejects exits 3.\n\n## Browser login\n\n```bash\nkenso auth login\nkenso auth login --no-browser --device-name "build box"\n```\n\nBrowser login is available to every workspace. The CLI prints a link and a code on stderr. You open the link, sign in to app.ken.so, check that the code matches the one in your terminal, pick the workspace to start in and approve. The CLI then saves a new API key to the profile and prints:\n\n```json\n{"profile":"default","email":"you@acme.io","workspaceId":"1234","keyExpiresAt":"2027-02-02T06:26:59Z"}\n```\n\nThe key is the same kind you create in the app. It is named `Kenso CLI - <device name>` (`--device-name`, else `kenso-cli on <hostname>`), lasts 90 days, and shows in your API key list at Settings > API keys, where you can revoke it. The CLI opens the browser itself only when no coding agent is detected and the machine has a display. An agent prints the link and asks you to open it. The login expires after 10 minutes (`login_expired`, exit 3), and a denied login exits 3 with `access_denied`. If the API answers that browser login is off (`browser_login_unavailable`, exit 3, `"next":"kenso auth login --with-key"`), log in with an API key as above.\n\n## Hand a login to a person (agents)\n\nAn agent that should not sit in a 10-minute wait starts the login, hands the link and code to its person, and collects the key once the person has approved:\n\n```bash\nkenso login --no-wait\nkenso auth wait\nkenso auth wait --timeout 2m\n```\n\n`kenso login --no-wait` (or `kenso auth login --no-wait`) starts a browser login, opens no browser and returns at once:\n\n```json\n{"verificationUrl":"https://app.ken.so/cli/login?code=WXYZ-2345","userCode":"WXYZ-2345","expiresAt":"2026-11-21T10:10:00.000Z","next":"kenso auth wait"}\n```\n\nIt saves the login in `~/.kenso/pending-login.json` (file mode 0600). The file holds the login\'s poll id, which can pick up the key, so the CLI never prints it and removes the file when the login ends. Running `kenso login --no-wait` again while that login is pending for the same profile and API URL, with more than a minute left, prints the same link and code and starts nothing new; `kenso login` without the flag reuses it too and waits for it. A waiting `kenso login` that is stopped leaves the file behind, so `kenso auth wait` can still collect the login.\n\n`kenso auth wait` polls only the API the login was started on, saves the key to the profile the login was started for, and prints what `kenso auth login` prints. By default it waits until the code expires; `--timeout` stops it sooner, after at least one poll, so `--timeout 0` checks once. `--workspace <id>` saves that workspace instead of the one the person approved. The pending login keeps no workspace, so `kenso login --no-wait --workspace <id>` is refused (exit 2): give the workspace to `kenso auth wait`. If the pending login is for another profile whose API differs, `kenso auth wait` answers `no_pending_login` with `next` set to `kenso auth wait --profile <name>`.\n\n| Outcome | Exit | Code | `next` | Pending file |\n|---|---|---|---|---|\n| Approved | 0 | - | - | removed |\n| No pending login, or one started on another API URL | 2 | `no_pending_login` | `kenso login --no-wait` | kept |\n| Denied in the browser | 3 | `login_denied` | `kenso login --no-wait` | removed |\n| The code expired | 3 | `login_expired` | `kenso login --no-wait` | removed |\n| `--timeout` passed first | 3 | `login_pending` | `kenso auth wait` | kept |\n\n## The workspace line\n\nUnder a coding agent, a command that is not a read prints one line on stderr before it runs, its `--dry-run` included: the workspace it acts in and where that came from.\n\n```text\nworkspace: 1234 (--workspace)\nworkspace: 1234 (KENSO_WORKSPACE_ID)\nworkspace: 1234 (kenso.json)\nworkspace: 1234 (profile client-a)\nworkspace: none set (the API picks the key\'s only workspace or answers workspace_required)\n```\n\nRead commands, the login and logout commands, and commands that bring their own credential print no line. The line costs no request.\n\n## CI, scripts and agents: use the environment\n\nYou do not need to log in on a machine that has the key in its environment:\n\n```bash\nexport KENSO_API_KEY=kenso_live_...\nexport KENSO_WORKSPACE_ID=1234\nkenso auth status\n```\n\n`KENSO_API_KEY` wins over any saved profile. Store it as a secret in your CI or agent platform, never in a file in the repo.\n\n## Workspaces\n\nA key reaches every workspace its user belongs to. Each command runs in one workspace, picked in this order:\n\n1. `--workspace <id>` on the command\n2. `KENSO_WORKSPACE_ID`\n3. `workspaceId` in a `kenso.json` in this folder or a folder above it, up to the repository root or your home folder (see [kenso.json](workflows.md#kensojson))\n4. the workspace saved in the profile (`kenso workspace use`)\n\n```bash\nkenso workspace list --search acme\nkenso workspace use 1234\nkenso campaigns list --workspace 5678\n```\n\n`workspace list` prints one page and says on stderr when there are more: add `--all` for every page. A command that needs a workspace when none is picked fails with `workspace_required` (exit 2) and `"next":"kenso workspace list --search <name>"`.\n\n## Workspace-owned keys\n\nA workspace admin can create a key the workspace owns: it keeps working when the admin leaves and acts with exactly the permissions of its template (`admin`, `editor` or `viewer`). Workspace keys are on for every workspace. The command is in beta: `kenso --help` and `kenso workspace --help` list it, marked beta, once the CLI has read the workspace\'s features from `GET /v1/me`. When it cannot read them (no key, or the lookup fails or takes more than 1.5 seconds), help hides the command and names it on its "Beta, hidden" line instead; `--all-commands` shows it. It runs when typed either way.\n\n```bash\nkenso workspace keys create --name "Zapier sync" --template editor --expires-in-days 90\n```\n\nNo API key may create a workspace key, the one the CLI logs in with included. The command prints the API\'s refusal (`forbidden`) with `"next":"A workspace admin can create it in the app: Settings > API keys > Workspace keys"` and exits 3, without retrying. A member who is not a workspace admin gets a 403 too (`permission_denied`), with the same next step. An admin creates the key there; the secret is shown once.\n\n## Profiles\n\nA profile holds a key, a workspace, an optional API URL and the email. Use one per client or per key:\n\n```bash\nkenso auth login --with-key --profile client-a < client-a-key.txt\nkenso campaigns list --profile client-a\nKENSO_PROFILE=client-a kenso auth status\n```\n\nThe profile is `--profile`, else `KENSO_PROFILE`, else the active one (the last one you logged in to).\n\n## Check the setup\n\n```bash\nkenso auth status\nkenso doctor\n```\n\n`auth status` prints who the key belongs to and when it expires, and warns on stderr when that is within 14 days:\n\n```json\n{"email":"you@acme.io","workspaceCount":3,"activeWorkspace":{"id":"1234","name":"Acme"},"keyExpiresAt":"2027-01-31T00:00:00Z","keySource":"profile","profile":"default"}\n```\n\n`doctor` prints the version, Node, the config folder, the profile, the key source, the API URL, the workspace and the detected agent, then seven checks: `node_version`, `config_permissions`, `api_reachable`, `key_valid`, `skill_installed`, `skill_current` and `mcp_registered`. A failed check carries the `next` command that fixes it, and the top-level `next` is the first of those; when every check passes, `starters` lists four requests to start with. It exits 0 when the first four checks pass, 3 when the key is missing or rejected, else 1.\n\n## Log out\n\n```bash\nkenso auth logout\nkenso auth logout --profile client-a\nkenso auth logout --keep-key\n```\n\nThis removes the profile and its key from this machine. When browser login made the key, logout revokes it first, so it stops working everywhere; `--keep-key` leaves it valid. If the revoke fails (no network, or the key was already revoked), logout warns and still removes the profile. A key you saved with `--with-key` was made by you in the app, so logout leaves it valid: revoke it at Settings > API keys. The output adds `revoked: true` or `false`.\n\n## Where things live\n\n| What | Default | Override |\n|---|---|---|\n| Config file with profiles and keys | `~/.kenso/config.json` | `KENSO_CONFIG_DIR` |\n| Pending browser login (`kenso login --no-wait`) | `~/.kenso/pending-login.json` | follows `KENSO_CONFIG_DIR` |\n| Run folders | `~/.kenso/runs/` | `KENSO_RUNS_DIR` |\n| Cached workspace features (1 hour) | `~/.kenso/cache/` | follows `KENSO_CONFIG_DIR` |\n| Last update check (once every 7 days) | `~/.kenso/update-check.json` | follows `KENSO_CONFIG_DIR`; `KENSO_NO_UPDATE_NOTIFIER=1` turns the check off |\n| API | `https://api.ken.so` | `KENSO_API_URL` |\n| MCP (for `kenso mcp`) | `https://mcp.ken.so/mcp` | `KENSO_MCP_URL` |\n\n`--verbose` prints each request line to stderr with the key redacted.\n';
|
|
10049
|
+
auth_default = '# Authentication\n\nThe CLI calls the Kenso API with a Kenso API key (`kenso_live_` plus 49 characters, or an older key: `ken_` plus 43 characters). It sends the key as `Authorization: Bearer <key>` and never prints it, logs it or puts it in an error.\n\n`kenso login`, `kenso logout` and `kenso whoami` are the same commands as `kenso auth login`, `kenso auth logout` and `kenso auth status`.\n\n## Log in with an API key\n\n1. In app.ken.so, go to Settings > API keys and create a key.\n2. Pipe it to `kenso auth login --with-key`. The key is read from stdin, never from a flag, so it stays out of your shell history and process list.\n\n```bash\necho $KEY | kenso auth login --with-key\nkenso auth login --with-key --profile client-a --workspace 1234 < key.txt\n```\n\nThe CLI checks the key with `GET /v1/me`, then saves it to `~/.kenso/config.json` (file mode 0600, folder mode 0700). It prints:\n\n```json\n{"profile":"default","email":"you@acme.io","workspaceId":"1234","workspaceCount":1}\n```\n\nA developer sandbox does not count here unless every workspace is one: a key whose user has one workspace and a sandbox saves that workspace. When the key reaches several workspaces and you did not pass `--workspace`, no workspace is saved and the output carries `"next":"kenso workspace list --search <name>"`. A key in the wrong format exits 2 (`invalid_key_format`). A key Kenso rejects exits 3.\n\n## Browser login\n\n```bash\nkenso auth login\nkenso auth login --no-browser --device-name "build box"\n```\n\nBrowser login is available to every workspace. The CLI prints a link and a code on stderr. You open the link, sign in to app.ken.so, check that the code matches the one in your terminal, pick the workspace to start in and approve. The CLI then saves a new API key to the profile and prints:\n\n```json\n{"profile":"default","email":"you@acme.io","workspaceId":"1234","keyExpiresAt":"2027-02-02T06:26:59Z"}\n```\n\nThe key is the same kind you create in the app. It is named `Kenso CLI - <device name>` (`--device-name`, else `kenso-cli on <hostname>`), lasts 90 days, and shows in your API key list at Settings > API keys, where you can revoke it. The CLI opens the browser itself only when no coding agent is detected and the machine has a display. An agent prints the link and asks you to open it. The login expires after 10 minutes (`login_expired`, exit 3), and a denied login exits 3 with `access_denied`. If the API answers that browser login is off (`browser_login_unavailable`, exit 3, `"next":"kenso auth login --with-key"`), log in with an API key as above.\n\n## Hand a login to a person (agents)\n\nAn agent that should not sit in a 10-minute wait starts the login, hands the link and code to its person, and collects the key once the person has approved:\n\n```bash\nkenso login --no-wait\nkenso auth wait\nkenso auth wait --timeout 2m\n```\n\n`kenso login --no-wait` (or `kenso auth login --no-wait`) starts a browser login, opens no browser and returns at once:\n\n```json\n{"verificationUrl":"https://app.ken.so/cli/login?code=WXYZ-2345","userCode":"WXYZ-2345","expiresAt":"2026-11-21T10:10:00.000Z","next":"kenso auth wait"}\n```\n\nIt saves the login in `~/.kenso/pending-login.json` (file mode 0600). The file holds the login\'s poll id, which can pick up the key, so the CLI never prints it and removes the file when the login ends. Running `kenso login --no-wait` again while that login is pending for the same profile and API URL, with more than a minute left, prints the same link and code and starts nothing new; `kenso login` without the flag reuses it too and waits for it. A waiting `kenso login` that is stopped leaves the file behind, so `kenso auth wait` can still collect the login.\n\n`kenso auth wait` polls only the API the login was started on, saves the key to the profile the login was started for, and prints what `kenso auth login` prints. By default it waits until the code expires; `--timeout` stops it sooner, after at least one poll, so `--timeout 0` checks once. `--workspace <id>` saves that workspace instead of the one the person approved. The pending login keeps no workspace, so `kenso login --no-wait --workspace <id>` is refused (exit 2): give the workspace to `kenso auth wait`. If the pending login is for another profile whose API differs, `kenso auth wait` answers `no_pending_login` with `next` set to `kenso auth wait --profile <name>`.\n\n| Outcome | Exit | Code | `next` | Pending file |\n|---|---|---|---|---|\n| Approved | 0 | - | - | removed |\n| No pending login, or one started on another API URL | 2 | `no_pending_login` | `kenso login --no-wait` | kept |\n| Denied in the browser | 3 | `login_denied` | `kenso login --no-wait` | removed |\n| The code expired | 3 | `login_expired` | `kenso login --no-wait` | removed |\n| `--timeout` passed first | 3 | `login_pending` | `kenso auth wait` | kept |\n\n## The workspace line\n\nUnder a coding agent, a command that is not a read prints one line on stderr before it runs, its `--dry-run` included: the workspace it acts in and where that came from.\n\n```text\nworkspace: 1234 (--workspace)\nworkspace: 1234 (KENSO_WORKSPACE_ID)\nworkspace: 1234 (kenso.json)\nworkspace: 1234 (profile client-a)\nworkspace: none set (the API picks the key\'s only workspace or answers workspace_required)\n```\n\nRead commands, the login and logout commands, and commands that bring their own credential print no line. The line costs no request.\n\n## CI, scripts and agents: use the environment\n\nYou do not need to log in on a machine that has the key in its environment:\n\n```bash\nexport KENSO_API_KEY=kenso_live_...\nexport KENSO_WORKSPACE_ID=1234\nkenso auth status\n```\n\n`KENSO_API_KEY` wins over any saved profile. Store it as a secret in your CI or agent platform, never in a file in the repo.\n\n## Workspaces\n\nA key reaches every workspace its user belongs to. Each command runs in one workspace, picked in this order:\n\n1. `--workspace <id>` on the command\n2. `KENSO_WORKSPACE_ID`\n3. `workspaceId` in a `kenso.json` in this folder or a folder above it, up to the repository root or your home folder (see [kenso.json](workflows.md#kensojson))\n4. the workspace saved in the profile (`kenso workspace use`)\n\n```bash\nkenso workspace list --search acme\nkenso workspace use 1234\nkenso campaigns list --workspace 5678\n```\n\n`workspace list` prints one page and says on stderr when there are more: add `--all` for every page. A command that needs a workspace when none is picked fails with `workspace_required` (exit 2) and `"next":"kenso workspace list --search <name>"`.\n\n## Workspace-owned keys\n\nA workspace admin can create a key the workspace owns: it keeps working when the admin leaves and acts with exactly the permissions of its template (`admin`, `editor` or `viewer`). Workspace keys are on for every workspace. The command is in beta: `kenso --help` and `kenso workspace --help` list it, marked beta, once the CLI has read the workspace\'s features from `GET /v1/me`. When it cannot read them (no key, or the lookup fails or takes more than 1.5 seconds), help hides the command and names it on its "Beta, hidden" line instead; `--all-commands` shows it. It runs when typed either way.\n\n```bash\nkenso workspace keys create --name "Zapier sync" --template editor --expires-in-days 90\n```\n\nNo API key may create a workspace key, the one the CLI logs in with included. The command prints the API\'s refusal (`forbidden`) with `"next":"A workspace admin can create it in the app: Settings > API keys > Workspace keys"` and exits 3, without retrying. A member who is not a workspace admin gets a 403 too (`permission_denied`), with the same next step. An admin creates the key there; the secret is shown once.\n\n## Profiles\n\nA profile holds a key, a workspace, an optional API URL and the email. Use one per client or per key:\n\n```bash\nkenso auth login --with-key --profile client-a < client-a-key.txt\nkenso campaigns list --profile client-a\nKENSO_PROFILE=client-a kenso auth status\n```\n\nThe profile is `--profile`, else `KENSO_PROFILE`, else the active one (the last one you logged in to).\n\n## Check the setup\n\n```bash\nkenso auth status\nkenso doctor\n```\n\n`auth status` prints who the key belongs to and when it expires, and warns on stderr when that is within 14 days:\n\n```json\n{"email":"you@acme.io","workspaceCount":3,"activeWorkspace":{"id":"1234","name":"Acme"},"keyExpiresAt":"2027-01-31T00:00:00Z","keySource":"profile","profile":"default"}\n```\n\n`doctor` prints the version, Node, the config folder, the profile, the key source, the API URL, the workspace and the detected agent, then seven checks: `node_version`, `config_permissions`, `api_reachable`, `key_valid`, `skill_installed`, `skill_current` and `mcp_registered`. A failed check carries the `next` command that fixes it, and the top-level `next` is the first of those; when every check passes, `starters` lists four requests to start with. It exits 0 when the first four checks pass, 3 when the key is missing or rejected, else 1.\n\n## Log out\n\n```bash\nkenso auth logout\nkenso auth logout --profile client-a\nkenso auth logout --keep-key\n```\n\nThis removes the profile and its key from this machine. When browser login made the key, logout revokes it first, so it stops working everywhere; `--keep-key` leaves it valid. If the revoke fails (no network, or the key was already revoked), logout warns and still removes the profile. A key you saved with `--with-key` was made by you in the app, so logout leaves it valid: revoke it at Settings > API keys. The output adds `revoked: true` or `false`.\n\n## Where things live\n\n| What | Default | Override |\n|---|---|---|\n| Config file with profiles and keys | `~/.kenso/config.json` | `KENSO_CONFIG_DIR` |\n| Pending browser login (`kenso login --no-wait`) | `~/.kenso/pending-login.json` | follows `KENSO_CONFIG_DIR` |\n| Run folders | `~/.kenso/runs/` | `KENSO_RUNS_DIR` |\n| Cached workspace features (1 hour) | `~/.kenso/cache/` | follows `KENSO_CONFIG_DIR` |\n| Last update check (once every 7 days) | `~/.kenso/update-check.json` | follows `KENSO_CONFIG_DIR`; `KENSO_NO_UPDATE_NOTIFIER=1` turns the check off |\n| API | `https://api.ken.so` | `KENSO_API_URL` |\n| MCP (for `kenso mcp`) | `https://mcp.ken.so/mcp` | `KENSO_MCP_URL` |\n\nAnother API or MCP gets a warning on stderr before the key goes there, and it must be https (plain http only to `localhost` or `127.0.0.1`, `insecure_url`, exit 2). A saved key goes only to the API it was saved for (`key_origin_mismatch`, exit 3, names it): a key from `kenso auth login` run with `KENSO_API_URL` set works on that API only while the variable is set, unless you log in with `--save-api-url`, which saves the URL in the profile. A key saved for `https://api.ken.so` goes to no MCP but `https://mcp.ken.so`. `kenso auth status` prints the `apiUrl` it used.\n\n`--verbose` prints each request line to stderr with the key redacted.\n';
|
|
9940
10050
|
}
|
|
9941
10051
|
});
|
|
9942
10052
|
|
|
@@ -11110,7 +11220,7 @@ async function browserLogin(ctx, opts, overrides2) {
|
|
|
11110
11220
|
openBrowser(pending.verificationUrl, deps);
|
|
11111
11221
|
}
|
|
11112
11222
|
const picked = await collect(ctx, deps, pending, { retry: RETRY_LOGIN, deniedCode: "access_denied" });
|
|
11113
|
-
return saveLogin(ctx, { profile: opts.profile,
|
|
11223
|
+
return saveLogin(ctx, { profile: opts.profile, workspace: opts.workspace, saveApiUrl: opts.saveApiUrl === true }, picked);
|
|
11114
11224
|
}
|
|
11115
11225
|
async function waitForPendingLogin(ctx, opts, overrides2) {
|
|
11116
11226
|
const deps = { ...defaultDeps, ...overrides2 };
|
|
@@ -11132,7 +11242,7 @@ async function waitForPendingLogin(ctx, opts, overrides2) {
|
|
|
11132
11242
|
ctx.output.info(`Waiting for the person to approve ${pending.verificationUrl} (code ${pending.userCode}) until ${pending.expiresAt}.`);
|
|
11133
11243
|
const stopAtMs = opts.timeoutMs !== void 0 ? deps.now() + opts.timeoutMs : void 0;
|
|
11134
11244
|
const picked = await collect(ctx, deps, pending, { retry: NO_WAIT_RETRY, deniedCode: "login_denied", stopAtMs });
|
|
11135
|
-
return saveLogin(ctx, { profile: pending.profile,
|
|
11245
|
+
return saveLogin(ctx, { profile: pending.profile, workspace: opts.workspace, saveApiUrl: opts.saveApiUrl === true }, picked);
|
|
11136
11246
|
}
|
|
11137
11247
|
async function collect(ctx, deps, pending, opts) {
|
|
11138
11248
|
try {
|
|
@@ -11147,6 +11257,12 @@ async function collect(ctx, deps, pending, opts) {
|
|
|
11147
11257
|
function forget(ctx, pending) {
|
|
11148
11258
|
if (readPendingLogin(ctx.env)?.loginId === pending.loginId) removePendingLogin(ctx.env);
|
|
11149
11259
|
}
|
|
11260
|
+
function warnUnsavedApiUrl(ctx, savedApiUrl) {
|
|
11261
|
+
if (savedApiUrl !== void 0 || ctx.auth.apiUrl === DEFAULT_API_URL) return;
|
|
11262
|
+
ctx.output.warn(
|
|
11263
|
+
`The key was saved for ${ctx.auth.apiUrl}, but the URL was not: later commands reach that API only while KENSO_API_URL is set. Log in with --save-api-url to save it in the profile.`
|
|
11264
|
+
);
|
|
11265
|
+
}
|
|
11150
11266
|
function saveLogin(ctx, target2, picked) {
|
|
11151
11267
|
const workspaceId = target2.workspace ?? (picked.workspaceId !== void 0 ? String(picked.workspaceId) : void 0);
|
|
11152
11268
|
if (target2.workspace !== void 0 && picked.workspaceId !== void 0 && target2.workspace !== String(picked.workspaceId)) {
|
|
@@ -11154,6 +11270,7 @@ function saveLogin(ctx, target2, picked) {
|
|
|
11154
11270
|
`The key was approved for workspace ${String(picked.workspaceId)}, but --workspace ${target2.workspace} was saved. The key reaches every workspace you belong to, so this works only if you are a member of it.`
|
|
11155
11271
|
);
|
|
11156
11272
|
}
|
|
11273
|
+
const apiUrl = apiUrlToSave(ctx.auth, ctx.env, target2.saveApiUrl, target2.profile);
|
|
11157
11274
|
writeProfile(
|
|
11158
11275
|
target2.profile,
|
|
11159
11276
|
{
|
|
@@ -11161,11 +11278,13 @@ function saveLogin(ctx, target2, picked) {
|
|
|
11161
11278
|
workspaceId,
|
|
11162
11279
|
email: picked.email,
|
|
11163
11280
|
keyId: picked.apiKeyId !== void 0 ? String(picked.apiKeyId) : void 0,
|
|
11164
|
-
apiUrl
|
|
11281
|
+
apiUrl,
|
|
11282
|
+
keyOrigin: originOf(ctx.auth.apiUrl)
|
|
11165
11283
|
},
|
|
11166
11284
|
{ activate: true, env: ctx.env }
|
|
11167
11285
|
);
|
|
11168
11286
|
clearCache(ctx.env);
|
|
11287
|
+
warnUnsavedApiUrl(ctx, apiUrl);
|
|
11169
11288
|
if (ctx.auth.source === "env") {
|
|
11170
11289
|
ctx.output.warn("KENSO_API_KEY is set and wins over the saved profile. Unset it to use the saved key.");
|
|
11171
11290
|
}
|
|
@@ -11234,6 +11353,7 @@ var init_browser_login = __esm({
|
|
|
11234
11353
|
init_config();
|
|
11235
11354
|
init_errors();
|
|
11236
11355
|
init_exit_codes();
|
|
11356
|
+
init_endpoint();
|
|
11237
11357
|
init_http();
|
|
11238
11358
|
init_pending_login();
|
|
11239
11359
|
MAX_DEVICE_NAME = 100;
|
|
@@ -11307,6 +11427,7 @@ var init_login = __esm({
|
|
|
11307
11427
|
init_config();
|
|
11308
11428
|
init_errors();
|
|
11309
11429
|
init_exit_codes();
|
|
11430
|
+
init_endpoint();
|
|
11310
11431
|
init_http();
|
|
11311
11432
|
init_input();
|
|
11312
11433
|
init_browser_login();
|
|
@@ -11322,9 +11443,10 @@ var init_login = __esm({
|
|
|
11322
11443
|
when: "before the first command on a machine, or after an unauthorized error: a person approves the sign-in in the browser",
|
|
11323
11444
|
next: "kenso workspace use <workspaceId>, then kenso doctor"
|
|
11324
11445
|
},
|
|
11325
|
-
description: "With --with-key, reads one API key from stdin, checks it with GET /v1/me and saves it to the profile (--profile, KENSO_PROFILE, the folder's kenso.json or the active one) in ~/.kenso/config.json with mode 0600. The workspace is --workspace when the key can reach it, else the key's only workspace (a developer sandbox counts only when every workspace is one). The key is never a flag value: to use a key from an environment variable, pipe the variable in as the first example shows (an empty or malformed key is refused, exit 2, without printing it). Without --with-key it starts a browser login and waits up to 10 minutes for the approval. --no-wait prints {verificationUrl, userCode, expiresAt, next} and returns at once, for an agent to hand the link to its person; kenso auth wait then collects the key. While that login is pending, another login for the same profile and API reuses it.",
|
|
11446
|
+
description: "With --with-key, reads one API key from stdin, checks it with GET /v1/me and saves it to the profile (--profile, KENSO_PROFILE, the folder's kenso.json or the active one) in ~/.kenso/config.json with mode 0600. The workspace is --workspace when the key can reach it, else the key's only workspace (a developer sandbox counts only when every workspace is one). The key is never a flag value: to use a key from an environment variable, pipe the variable in as the first example shows (an empty or malformed key is refused, exit 2, without printing it). Without --with-key it starts a browser login and waits up to 10 minutes for the approval. --no-wait prints {verificationUrl, userCode, expiresAt, next} and returns at once, for an agent to hand the link to its person; kenso auth wait then collects the key. While that login is pending, another login for the same profile and API reuses it. The key is saved for the API it was checked on and is sent to no other. A KENSO_API_URL other than https://api.ken.so is saved in the profile only with --save-api-url; without it, later commands reach that API only while KENSO_API_URL is set.",
|
|
11326
11447
|
flags: {
|
|
11327
11448
|
"with-key": { type: "boolean", description: "Read the API key from stdin" },
|
|
11449
|
+
"save-api-url": { type: "boolean", description: "Save KENSO_API_URL in the profile, so later commands use that API without the variable" },
|
|
11328
11450
|
"device-name": { type: "string", description: "Name this machine on the browser sign-in page" },
|
|
11329
11451
|
"no-browser": { type: "boolean", description: "Print the sign-in link instead of opening a browser" },
|
|
11330
11452
|
"no-wait": { type: "boolean", description: "Start the browser login, print the link and code, and return at once (collect it with kenso auth wait)" }
|
|
@@ -11341,7 +11463,8 @@ var init_login = __esm({
|
|
|
11341
11463
|
deviceName: typeof flags["device-name"] === "string" ? flags["device-name"] : void 0,
|
|
11342
11464
|
noBrowser: flags["no-browser"] === true,
|
|
11343
11465
|
workspace: ctx.flags.workspace,
|
|
11344
|
-
noWait: flags["no-wait"] === true
|
|
11466
|
+
noWait: flags["no-wait"] === true,
|
|
11467
|
+
saveApiUrl: flags["save-api-url"] === true
|
|
11345
11468
|
});
|
|
11346
11469
|
}
|
|
11347
11470
|
const stdin = ctx.stdin ?? process.stdin;
|
|
@@ -11400,17 +11523,20 @@ var init_login = __esm({
|
|
|
11400
11523
|
const counted = ids2.length > 1 ? await withoutSandboxes(ctx, key, ids2) : ids2;
|
|
11401
11524
|
if (counted.length === 1) workspaceId = counted[0];
|
|
11402
11525
|
}
|
|
11526
|
+
const apiUrl = apiUrlToSave(ctx.auth, ctx.env, flags["save-api-url"] === true, profile);
|
|
11403
11527
|
writeProfile(
|
|
11404
11528
|
profile,
|
|
11405
11529
|
{
|
|
11406
11530
|
apiKey: key,
|
|
11407
11531
|
workspaceId,
|
|
11408
|
-
apiUrl
|
|
11532
|
+
apiUrl,
|
|
11533
|
+
keyOrigin: originOf(ctx.auth.apiUrl),
|
|
11409
11534
|
email: me.email
|
|
11410
11535
|
},
|
|
11411
11536
|
{ activate: true, env: ctx.env }
|
|
11412
11537
|
);
|
|
11413
11538
|
clearCache(ctx.env);
|
|
11539
|
+
warnUnsavedApiUrl(ctx, apiUrl);
|
|
11414
11540
|
if (ctx.auth.source === "env") {
|
|
11415
11541
|
ctx.output.warn("KENSO_API_KEY is set and wins over the saved profile. Unset it to use the saved key.");
|
|
11416
11542
|
}
|
|
@@ -11432,19 +11558,21 @@ var logout_exports = {};
|
|
|
11432
11558
|
__export(logout_exports, {
|
|
11433
11559
|
default: () => logout_default
|
|
11434
11560
|
});
|
|
11435
|
-
async function revoke(ctx,
|
|
11436
|
-
const auth = { Authorization: `Bearer ${apiKey}` };
|
|
11561
|
+
async function revoke(ctx, profile) {
|
|
11562
|
+
const auth = { Authorization: `Bearer ${profile.apiKey}` };
|
|
11563
|
+
const keyOrigin = profileKeyOrigin(profile);
|
|
11437
11564
|
try {
|
|
11438
|
-
let workspaceId =
|
|
11565
|
+
let workspaceId = profile.workspaceId;
|
|
11439
11566
|
if (!workspaceId) {
|
|
11440
|
-
const me = await ctx.client.request({ method: "GET", path: "/v1/me", anonymous: true, noWorkspace: true, headers: auth, signal: ctx.signal });
|
|
11567
|
+
const me = await ctx.client.request({ method: "GET", path: "/v1/me", anonymous: true, keyOrigin, noWorkspace: true, headers: auth, signal: ctx.signal });
|
|
11441
11568
|
const first = unwrap(me.body)?.workspaces?.[0]?.id;
|
|
11442
11569
|
workspaceId = first !== void 0 ? String(first) : void 0;
|
|
11443
11570
|
}
|
|
11444
11571
|
await ctx.client.request({
|
|
11445
11572
|
method: "DELETE",
|
|
11446
|
-
path: `/v1/api-keys/${encodeURIComponent(keyId)}`,
|
|
11573
|
+
path: `/v1/api-keys/${encodeURIComponent(profile.keyId)}`,
|
|
11447
11574
|
anonymous: true,
|
|
11575
|
+
keyOrigin,
|
|
11448
11576
|
noWorkspace: true,
|
|
11449
11577
|
headers: workspaceId ? { ...auth, "X-Ken-Workspace-Id": workspaceId } : auth,
|
|
11450
11578
|
signal: ctx.signal
|
|
@@ -11452,6 +11580,15 @@ async function revoke(ctx, apiKey, keyId, savedWorkspaceId) {
|
|
|
11452
11580
|
return true;
|
|
11453
11581
|
} catch (err) {
|
|
11454
11582
|
if (err instanceof KensoError && err.exitCode === ExitCode.Interrupted) throw err;
|
|
11583
|
+
if (err instanceof KensoError && err.code === "key_origin_mismatch") {
|
|
11584
|
+
throw new KensoError({
|
|
11585
|
+
code: err.code,
|
|
11586
|
+
message: `${err.message} Nothing was removed.`,
|
|
11587
|
+
exitCode: err.exitCode,
|
|
11588
|
+
field: err.field,
|
|
11589
|
+
hint: `Set KENSO_API_URL to ${keyOrigin} (or unset it if that is the default) and log out again, or pass --keep-key to remove the profile without revoking the key.`
|
|
11590
|
+
});
|
|
11591
|
+
}
|
|
11455
11592
|
const why = err instanceof Error ? err.message : String(err);
|
|
11456
11593
|
ctx.output.warn(`Could not revoke the key (${why}). The profile is removed anyway; revoke the key at Settings > API keys.`);
|
|
11457
11594
|
return false;
|
|
@@ -11474,7 +11611,7 @@ var init_logout = __esm({
|
|
|
11474
11611
|
when: "this machine should stop using a saved profile: it removes the profile and revokes the key browser login made",
|
|
11475
11612
|
next: "kenso auth login to sign in again"
|
|
11476
11613
|
},
|
|
11477
|
-
description: "Removes the profile (--profile, KENSO_PROFILE, the folder's kenso.json or the active one) from ~/.kenso/config.json. When browser login made its key, it revokes that key first (--keep-key keeps it valid); if the revoke fails it warns and still removes the profile. A key saved with --with-key stays valid: revoke it at Settings > API keys.",
|
|
11614
|
+
description: "Removes the profile (--profile, KENSO_PROFILE, the folder's kenso.json or the active one) from ~/.kenso/config.json. When browser login made its key, it revokes that key first (--keep-key keeps it valid); if the revoke fails it warns and still removes the profile, but on an API other than the one the key was issued for it sends nothing and removes nothing (key_origin_mismatch, exit 3). A key saved with --with-key stays valid: revoke it at Settings > API keys.",
|
|
11478
11615
|
flags: {
|
|
11479
11616
|
"keep-key": { type: "boolean", description: "Remove the profile but leave its key valid" }
|
|
11480
11617
|
},
|
|
@@ -11486,7 +11623,7 @@ var init_logout = __esm({
|
|
|
11486
11623
|
if (notice) ctx.output.warn(notice);
|
|
11487
11624
|
const profile = readConfig(ctx.env).profiles[name];
|
|
11488
11625
|
const removed = profile !== void 0;
|
|
11489
|
-
const revoked = profile?.apiKey && profile.keyId && flags["keep-key"] !== true ? await revoke(ctx, profile.apiKey, profile.keyId
|
|
11626
|
+
const revoked = profile?.apiKey && profile.keyId && flags["keep-key"] !== true ? await revoke(ctx, { ...profile, apiKey: profile.apiKey, keyId: profile.keyId }) : false;
|
|
11490
11627
|
if (removed) removeProfile(name, ctx.env);
|
|
11491
11628
|
clearCache(ctx.env);
|
|
11492
11629
|
if (ctx.auth.source === "env") ctx.output.warn("KENSO_API_KEY is still set, so commands keep using that key.");
|
|
@@ -11519,7 +11656,7 @@ var init_status = __esm({
|
|
|
11519
11656
|
action: "status",
|
|
11520
11657
|
summary: "Show the key's user, workspace and expiry",
|
|
11521
11658
|
effect: "read",
|
|
11522
|
-
description: `Reads GET /v1/me for the email and workspaces, and GET /v1/api-keys for the key's expiry. Warns on stderr when the key expires within ${EXPIRY_WARNING_DAYS} days. A sandbox test key (kenso_test_) adds keyKind "test" and the sandbox it works in. workspaceSource says where the workspace came from: flag (--workspace), env (KENSO_WORKSPACE_ID), folder (a kenso.json, named in folderFile), profile or none.`,
|
|
11659
|
+
description: `Reads GET /v1/me for the email and workspaces, and GET /v1/api-keys for the key's expiry. Warns on stderr when the key expires within ${EXPIRY_WARNING_DAYS} days. A sandbox test key (kenso_test_) adds keyKind "test" and the sandbox it works in. apiUrl is the API the key was sent to. workspaceSource says where the workspace came from: flag (--workspace), env (KENSO_WORKSPACE_ID), folder (a kenso.json, named in folderFile), profile or none.`,
|
|
11523
11660
|
flags: {},
|
|
11524
11661
|
examples: ["kenso auth status", "kenso auth status --profile client-a"],
|
|
11525
11662
|
operationIds: ["me.get", "api-keys.list"],
|
|
@@ -11585,6 +11722,8 @@ var init_status = __esm({
|
|
|
11585
11722
|
activeWorkspace,
|
|
11586
11723
|
keyExpiresAt,
|
|
11587
11724
|
keySource: ctx.auth.source,
|
|
11725
|
+
// The API the key went to (KENSO_API_URL, the profile's apiUrl or the default), so a redirect cannot hide (DEV-13403).
|
|
11726
|
+
apiUrl: ctx.auth.apiUrl,
|
|
11588
11727
|
...staff ? { isSuperAdmin: true } : {},
|
|
11589
11728
|
profile: ctx.auth.profileName,
|
|
11590
11729
|
workspaceSource: ctx.auth.workspaceSource,
|
|
@@ -11621,6 +11760,7 @@ var init_wait2 = __esm({
|
|
|
11621
11760
|
effect: "read",
|
|
11622
11761
|
doc: { when: "After kenso login --no-wait, once you have handed the link and code to the person", next: "kenso whoami" },
|
|
11623
11762
|
flags: {
|
|
11763
|
+
"save-api-url": { type: "boolean", description: "Save KENSO_API_URL in the profile, so later commands use that API without the variable" },
|
|
11624
11764
|
timeout: { type: "string", description: "Stop waiting after this long: 90s, 10m, 1h or a number of seconds; it always polls once, so 0 checks once (default: until the code expires)" }
|
|
11625
11765
|
},
|
|
11626
11766
|
examples: ["kenso auth wait", "kenso auth wait --timeout 2m"],
|
|
@@ -11631,7 +11771,7 @@ var init_wait2 = __esm({
|
|
|
11631
11771
|
if (text4 !== void 0 && timeoutMs2 === void 0) {
|
|
11632
11772
|
throw usageError(`--timeout takes 90s, 10m, 1h or a number of seconds (got "${text4}").`, { field: "timeout", next: "kenso auth wait --help" });
|
|
11633
11773
|
}
|
|
11634
|
-
return waitForPendingLogin(ctx, { timeoutMs: timeoutMs2, workspace: ctx.flags.workspace });
|
|
11774
|
+
return waitForPendingLogin(ctx, { timeoutMs: timeoutMs2, workspace: ctx.flags.workspace, saveApiUrl: flags["save-api-url"] === true });
|
|
11635
11775
|
}
|
|
11636
11776
|
};
|
|
11637
11777
|
wait_default2 = command12;
|
|
@@ -16223,6 +16363,13 @@ var init_logs = __esm({
|
|
|
16223
16363
|
function mcpUrl(ctx) {
|
|
16224
16364
|
return ctx.env.KENSO_MCP_URL?.trim() || DEFAULT_MCP_URL;
|
|
16225
16365
|
}
|
|
16366
|
+
function keyMcpUrl(ctx) {
|
|
16367
|
+
const url = mcpUrl(ctx);
|
|
16368
|
+
const { origin } = checkEndpoint(url, "KENSO_MCP_URL");
|
|
16369
|
+
if (ctx.auth.keyOrigin === DEFAULT_API_ORIGIN && origin !== DEFAULT_MCP_ORIGIN) throw keyOriginError(ctx.auth.keyOrigin, origin, "KENSO_MCP_URL");
|
|
16370
|
+
if (origin !== DEFAULT_MCP_ORIGIN) ctx.output.warn(otherOriginWarning(origin, DEFAULT_MCP_ORIGIN, "KENSO_MCP_URL"));
|
|
16371
|
+
return url;
|
|
16372
|
+
}
|
|
16226
16373
|
function mcpClient(ctx) {
|
|
16227
16374
|
const apiKey = ctx.auth.apiKey;
|
|
16228
16375
|
if (!apiKey) {
|
|
@@ -16234,7 +16381,7 @@ function mcpClient(ctx) {
|
|
|
16234
16381
|
next: "kenso auth login"
|
|
16235
16382
|
});
|
|
16236
16383
|
}
|
|
16237
|
-
const url =
|
|
16384
|
+
const url = keyMcpUrl(ctx);
|
|
16238
16385
|
return new McpClient({
|
|
16239
16386
|
url,
|
|
16240
16387
|
apiKey,
|
|
@@ -16254,6 +16401,7 @@ var init_connect4 = __esm({
|
|
|
16254
16401
|
"use strict";
|
|
16255
16402
|
init_errors();
|
|
16256
16403
|
init_exit_codes();
|
|
16404
|
+
init_endpoint();
|
|
16257
16405
|
init_client();
|
|
16258
16406
|
}
|
|
16259
16407
|
});
|
|
@@ -17775,8 +17923,10 @@ function saveTestKey(ctx, sandboxId, key) {
|
|
|
17775
17923
|
{
|
|
17776
17924
|
apiKey: key.secret,
|
|
17777
17925
|
workspaceId: sandboxId,
|
|
17778
|
-
// The API
|
|
17926
|
+
// The API that issued the test key, the only one it works on (DEV-13403). Unlike a login, a sandbox profile
|
|
17927
|
+
// saves a non-default KENSO_API_URL without --save-api-url: the key is useless anywhere else.
|
|
17779
17928
|
apiUrl: ctx.auth.apiUrl !== DEFAULT_API_URL ? ctx.auth.apiUrl : void 0,
|
|
17929
|
+
keyOrigin: originOf(ctx.auth.apiUrl),
|
|
17780
17930
|
email: current.email,
|
|
17781
17931
|
keyId: key.id
|
|
17782
17932
|
},
|
|
@@ -17806,6 +17956,7 @@ var init_shared = __esm({
|
|
|
17806
17956
|
init_config();
|
|
17807
17957
|
init_errors();
|
|
17808
17958
|
init_exit_codes();
|
|
17959
|
+
init_endpoint();
|
|
17809
17960
|
SANDBOX_PROFILE = "sandbox";
|
|
17810
17961
|
SANDBOX_GATES = { all: ["developer_sandboxes"] };
|
|
17811
17962
|
SANDBOX_ID_POSITIONAL = { name: "sandboxId", description: "The sandbox id (default: your one sandbox)" };
|