@clavis.nexus/setup 1.0.1 → 1.0.2
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/README.md +6 -0
- package/dist/cli.js +228 -149
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +201 -142
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +215 -145
- package/dist/mcp.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,6 +41,8 @@ export CLAVIS_ID_ORIGIN=https://id.clavis.nexus
|
|
|
41
41
|
export CLAVIS_DEVELOPERS_ORIGIN=https://developers.clavis.nexus
|
|
42
42
|
|
|
43
43
|
clavis login
|
|
44
|
+
# ブラウザで Passkey 後、developers /setup/login に出る JSON を貼る
|
|
45
|
+
# (非対話: clavis login --bridge-json-file ./bridge.json)
|
|
44
46
|
clavis status
|
|
45
47
|
clavis org-anchor-plan example.com "Example Org"
|
|
46
48
|
# Passkey → org-anchor-finish → DNS 掲載 → org-verify-anchor
|
|
@@ -58,6 +60,10 @@ clavis emit-env --app <appId>
|
|
|
58
60
|
|
|
59
61
|
セッションは `~/.config/clavis/session.json` です(`CLAVIS_SESSION_PATH` で変更できます)。
|
|
60
62
|
|
|
63
|
+
### ログイン(貼り付け)
|
|
64
|
+
|
|
65
|
+
ブラウザから localhost へトークンを POST しません。`clavis login` は developers `/developers/setup/login?state=…` を開き、画面の JSON(`state` + `accessToken`)を stdin または `--bridge-json` / `--bridge-json-file` で受け取ります。MCP の `clavis_login` は初回でブラウザを開き、2 回目に `bridge_json` を渡します。
|
|
66
|
+
|
|
61
67
|
### この CLI が扱う範囲
|
|
62
68
|
|
|
63
69
|
- `clavis status` が返すのは、Org・App・ホスト確認・用途の申告と、署名のカードの状態です。WASM と台帳の購読は developers で確認します。
|
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import { execFile } from 'child_process';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import { readFile, mkdir, writeFile, chmod, unlink } from 'fs/promises';
|
|
5
|
-
import { dirname, join } from 'path';
|
|
5
|
+
import path, { dirname, join } from 'path';
|
|
6
6
|
import { homedir } from 'os';
|
|
7
7
|
import { generateKeyPair, exportJWK, createRemoteJWKSet, jwtVerify } from 'jose';
|
|
8
|
-
import {
|
|
8
|
+
import { createInterface } from 'readline/promises';
|
|
9
|
+
import { stdin, stdout } from 'process';
|
|
9
10
|
import { randomBytes } from 'crypto';
|
|
10
11
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
11
12
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
@@ -127,12 +128,12 @@ var init_canonical_json = __esm({
|
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
// src/digests.ts
|
|
130
|
-
async function computeOrgPolicyBootstrapDigest(
|
|
131
|
+
async function computeOrgPolicyBootstrapDigest(input2) {
|
|
131
132
|
return sha256Base64Url(
|
|
132
133
|
canonicalStringify({
|
|
133
|
-
org_id:
|
|
134
|
-
primary_domain:
|
|
135
|
-
owner_sub:
|
|
134
|
+
org_id: input2.org_id.trim(),
|
|
135
|
+
primary_domain: input2.primary_domain.trim().toLowerCase(),
|
|
136
|
+
owner_sub: input2.owner_sub.trim()
|
|
136
137
|
})
|
|
137
138
|
);
|
|
138
139
|
}
|
|
@@ -143,21 +144,21 @@ async function computePayloadCommitmentHex(payload) {
|
|
|
143
144
|
}
|
|
144
145
|
return sha256HexUtf8(canonicalStringify(o));
|
|
145
146
|
}
|
|
146
|
-
async function computeOrgAppRegisterDigest(
|
|
147
|
+
async function computeOrgAppRegisterDigest(input2) {
|
|
147
148
|
return sha256Base64Url(
|
|
148
149
|
canonicalStringify({
|
|
149
|
-
payload_hash:
|
|
150
|
-
proposer_sub:
|
|
150
|
+
payload_hash: input2.payload_hash.trim().toLowerCase(),
|
|
151
|
+
proposer_sub: input2.proposer_sub.trim()
|
|
151
152
|
})
|
|
152
153
|
);
|
|
153
154
|
}
|
|
154
|
-
async function computeOrgAppVerifyHostDigest(
|
|
155
|
+
async function computeOrgAppVerifyHostDigest(input2) {
|
|
155
156
|
return sha256Base64Url(
|
|
156
157
|
canonicalStringify({
|
|
157
|
-
app_id:
|
|
158
|
-
host:
|
|
159
|
-
nonce:
|
|
160
|
-
org_id:
|
|
158
|
+
app_id: input2.app_id.trim(),
|
|
159
|
+
host: input2.host.trim().toLowerCase(),
|
|
160
|
+
nonce: input2.nonce.trim(),
|
|
161
|
+
org_id: input2.org_id.trim()
|
|
161
162
|
})
|
|
162
163
|
);
|
|
163
164
|
}
|
|
@@ -170,13 +171,13 @@ async function computeOrgAppDeclarationHash(declaration) {
|
|
|
170
171
|
})
|
|
171
172
|
);
|
|
172
173
|
}
|
|
173
|
-
async function computeOrgAppDeclarationDigest(
|
|
174
|
+
async function computeOrgAppDeclarationDigest(input2) {
|
|
174
175
|
return sha256Base64Url(
|
|
175
176
|
canonicalStringify({
|
|
176
|
-
org_id:
|
|
177
|
-
app_id:
|
|
178
|
-
declaration_hash:
|
|
179
|
-
actor_sub:
|
|
177
|
+
org_id: input2.org_id.trim(),
|
|
178
|
+
app_id: input2.app_id.trim(),
|
|
179
|
+
declaration_hash: input2.declaration_hash.trim(),
|
|
180
|
+
actor_sub: input2.actor_sub.trim()
|
|
180
181
|
})
|
|
181
182
|
);
|
|
182
183
|
}
|
|
@@ -273,8 +274,8 @@ var init_ceremony = __esm({
|
|
|
273
274
|
});
|
|
274
275
|
|
|
275
276
|
// src/org-api.ts
|
|
276
|
-
async function apiJson(apiOrigin,
|
|
277
|
-
const res = await fetch(`${apiOrigin.replace(/\/+$/, "")}${
|
|
277
|
+
async function apiJson(apiOrigin, path2, opts) {
|
|
278
|
+
const res = await fetch(`${apiOrigin.replace(/\/+$/, "")}${path2}`, {
|
|
278
279
|
method: opts.method ?? "GET",
|
|
279
280
|
headers: {
|
|
280
281
|
Accept: "application/json",
|
|
@@ -428,25 +429,25 @@ function appEnvFilePath(appId) {
|
|
|
428
429
|
const base = process.env.CLAVIS_OPERATE_KEYS_DIR?.trim() || join(homedir(), ".config", "clavis", "apps");
|
|
429
430
|
return join(base, app, "app.env");
|
|
430
431
|
}
|
|
431
|
-
async function restrictFileMode(
|
|
432
|
+
async function restrictFileMode(path2) {
|
|
432
433
|
try {
|
|
433
|
-
await chmod(
|
|
434
|
+
await chmod(path2, 384);
|
|
434
435
|
} catch (e) {
|
|
435
436
|
console.warn(
|
|
436
|
-
`clavis: could not set mode 0600 on ${
|
|
437
|
+
`clavis: could not set mode 0600 on ${path2}: ${e instanceof Error ? e.message : e}`
|
|
437
438
|
);
|
|
438
439
|
}
|
|
439
440
|
}
|
|
440
441
|
async function saveOperatePrivateJwk(appId, jwkJson) {
|
|
441
|
-
const
|
|
442
|
-
await mkdir(dirname(
|
|
443
|
-
await writeFile(
|
|
444
|
-
await restrictFileMode(
|
|
442
|
+
const path2 = operatePrivateJwkPath(appId);
|
|
443
|
+
await mkdir(dirname(path2), { recursive: true });
|
|
444
|
+
await writeFile(path2, jwkJson.trim(), "utf8");
|
|
445
|
+
await restrictFileMode(path2);
|
|
445
446
|
try {
|
|
446
|
-
await chmod(dirname(
|
|
447
|
+
await chmod(dirname(path2), 448);
|
|
447
448
|
} catch {
|
|
448
449
|
}
|
|
449
|
-
return
|
|
450
|
+
return path2;
|
|
450
451
|
}
|
|
451
452
|
async function readOperatePrivateJwk(appId) {
|
|
452
453
|
try {
|
|
@@ -457,12 +458,12 @@ async function readOperatePrivateJwk(appId) {
|
|
|
457
458
|
}
|
|
458
459
|
}
|
|
459
460
|
async function writeAppEnvFile(appId, contents) {
|
|
460
|
-
const
|
|
461
|
-
await mkdir(dirname(
|
|
462
|
-
await writeFile(
|
|
461
|
+
const path2 = appEnvFilePath(appId);
|
|
462
|
+
await mkdir(dirname(path2), { recursive: true });
|
|
463
|
+
await writeFile(path2, contents.endsWith("\n") ? contents : `${contents}
|
|
463
464
|
`, "utf8");
|
|
464
|
-
await restrictFileMode(
|
|
465
|
-
return
|
|
465
|
+
await restrictFileMode(path2);
|
|
466
|
+
return path2;
|
|
466
467
|
}
|
|
467
468
|
var init_operate_key_store = __esm({
|
|
468
469
|
"src/operate-key-store.ts"() {
|
|
@@ -562,9 +563,9 @@ function originsFromEnv(overrides) {
|
|
|
562
563
|
developersOrigin: overrides?.developersOrigin ?? process.env.CLAVIS_DEVELOPERS_ORIGIN?.trim() ?? DEFAULT_ORIGINS.developersOrigin
|
|
563
564
|
};
|
|
564
565
|
}
|
|
565
|
-
async function loadSession(
|
|
566
|
+
async function loadSession(path2 = defaultSessionPath()) {
|
|
566
567
|
try {
|
|
567
|
-
const raw = await readFile(
|
|
568
|
+
const raw = await readFile(path2, "utf8");
|
|
568
569
|
const parsed = JSON.parse(raw);
|
|
569
570
|
if (parsed?.v !== 1 || typeof parsed.session?.accessToken !== "string") return null;
|
|
570
571
|
if (parsed.session.expiresAt && parsed.session.expiresAt * 1e3 < Date.now()) return null;
|
|
@@ -573,21 +574,21 @@ async function loadSession(path = defaultSessionPath()) {
|
|
|
573
574
|
return null;
|
|
574
575
|
}
|
|
575
576
|
}
|
|
576
|
-
async function saveSession(session, origins,
|
|
577
|
-
await mkdir(dirname(
|
|
577
|
+
async function saveSession(session, origins, path2 = defaultSessionPath()) {
|
|
578
|
+
await mkdir(dirname(path2), { recursive: true });
|
|
578
579
|
const body = { v: 1, origins, session, savedAt: Date.now() };
|
|
579
|
-
await writeFile(
|
|
580
|
+
await writeFile(path2, JSON.stringify(body, null, 2), "utf8");
|
|
580
581
|
try {
|
|
581
|
-
await chmod(
|
|
582
|
+
await chmod(path2, 384);
|
|
582
583
|
} catch (e) {
|
|
583
584
|
console.warn(
|
|
584
|
-
`clavis: could not set session file mode 0600 (${
|
|
585
|
+
`clavis: could not set session file mode 0600 (${path2}): ${e instanceof Error ? e.message : e}`
|
|
585
586
|
);
|
|
586
587
|
}
|
|
587
588
|
}
|
|
588
|
-
async function clearSession(
|
|
589
|
+
async function clearSession(path2 = defaultSessionPath()) {
|
|
589
590
|
try {
|
|
590
|
-
await unlink(
|
|
591
|
+
await unlink(path2);
|
|
591
592
|
} catch {
|
|
592
593
|
}
|
|
593
594
|
}
|
|
@@ -596,29 +597,9 @@ var init_session_store = __esm({
|
|
|
596
597
|
init_types();
|
|
597
598
|
}
|
|
598
599
|
});
|
|
599
|
-
function
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
let total = 0;
|
|
603
|
-
req.on("data", (c) => {
|
|
604
|
-
const buf = Buffer.isBuffer(c) ? c : Buffer.from(c);
|
|
605
|
-
total += buf.length;
|
|
606
|
-
if (total > MAX_CALLBACK_BODY_BYTES) {
|
|
607
|
-
reject(new Error("callback body too large"));
|
|
608
|
-
req.destroy();
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
chunks.push(buf);
|
|
612
|
-
});
|
|
613
|
-
req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
614
|
-
req.on("error", reject);
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
function cors(res, developersOrigin) {
|
|
618
|
-
res.setHeader("Access-Control-Allow-Origin", developersOrigin);
|
|
619
|
-
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
620
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
621
|
-
res.setHeader("Vary", "Origin");
|
|
600
|
+
function pendingLoginPath(sessionPath) {
|
|
601
|
+
const base = sessionPath ? path.dirname(sessionPath) : path.dirname(defaultSessionPath());
|
|
602
|
+
return path.join(base, "login-pending.json");
|
|
622
603
|
}
|
|
623
604
|
function subFromJwt(accessToken) {
|
|
624
605
|
try {
|
|
@@ -631,96 +612,159 @@ function subFromJwt(accessToken) {
|
|
|
631
612
|
return void 0;
|
|
632
613
|
}
|
|
633
614
|
}
|
|
615
|
+
function loginBridgeUrl(developersOrigin, state) {
|
|
616
|
+
const bridge = new URL("/developers/setup/login", developersOrigin);
|
|
617
|
+
bridge.searchParams.set("state", state);
|
|
618
|
+
return bridge.toString();
|
|
619
|
+
}
|
|
620
|
+
async function writePending(pendingPath, pending) {
|
|
621
|
+
await mkdir(path.dirname(pendingPath), { recursive: true, mode: 448 });
|
|
622
|
+
await writeFile(pendingPath, `${JSON.stringify(pending, null, 2)}
|
|
623
|
+
`, { mode: 384 });
|
|
624
|
+
}
|
|
625
|
+
async function readPending(pendingPath) {
|
|
626
|
+
try {
|
|
627
|
+
const raw = await readFile(pendingPath, "utf8");
|
|
628
|
+
const parsed = JSON.parse(raw);
|
|
629
|
+
if (parsed?.v !== 1 || typeof parsed.state !== "string" || !parsed.state) return null;
|
|
630
|
+
return parsed;
|
|
631
|
+
} catch {
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async function clearPending(pendingPath) {
|
|
636
|
+
try {
|
|
637
|
+
await unlink(pendingPath);
|
|
638
|
+
} catch {
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function parseBridgePayload(raw) {
|
|
642
|
+
const trimmed = raw.trim();
|
|
643
|
+
if (!trimmed) throw new Error("empty_bridge_json");
|
|
644
|
+
if (trimmed.length > MAX_BRIDGE_JSON_CHARS) throw new Error("bridge_json_too_large");
|
|
645
|
+
const body = JSON.parse(trimmed);
|
|
646
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
647
|
+
throw new Error("bridge_json_not_object");
|
|
648
|
+
}
|
|
649
|
+
return body;
|
|
650
|
+
}
|
|
651
|
+
async function sessionFromBridge(args) {
|
|
652
|
+
const body = parseBridgePayload(args.raw);
|
|
653
|
+
if (body.state !== args.expectedState || typeof body.accessToken !== "string" || !body.accessToken) {
|
|
654
|
+
throw new Error("invalid_bridge_json");
|
|
655
|
+
}
|
|
656
|
+
await verifyDevelopersAccessToken(body.accessToken, args.apiOrigin);
|
|
657
|
+
const sub = typeof body.sub === "string" ? body.sub : subFromJwt(body.accessToken);
|
|
658
|
+
return {
|
|
659
|
+
accessToken: body.accessToken,
|
|
660
|
+
...sub ? { sub } : {},
|
|
661
|
+
...typeof body.expiresAt === "number" ? { expiresAt: body.expiresAt } : {}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
async function readBridgeJsonFromStdin() {
|
|
665
|
+
if (!stdin.isTTY) {
|
|
666
|
+
const chunks = [];
|
|
667
|
+
for await (const chunk of stdin) {
|
|
668
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
669
|
+
}
|
|
670
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
671
|
+
}
|
|
672
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
673
|
+
try {
|
|
674
|
+
stdout.write(
|
|
675
|
+
"Paste the JSON shown on developers /setup/login, then press Enter.\n(End with a blank line if the paste spans multiple lines.)\n"
|
|
676
|
+
);
|
|
677
|
+
const lines = [];
|
|
678
|
+
for (; ; ) {
|
|
679
|
+
const line = await rl.question("");
|
|
680
|
+
if (line.trim() === "" && lines.length > 0) break;
|
|
681
|
+
lines.push(line);
|
|
682
|
+
const joined = lines.join("\n").trim();
|
|
683
|
+
if (joined.startsWith("{") && joined.endsWith("}")) break;
|
|
684
|
+
}
|
|
685
|
+
return lines.join("\n");
|
|
686
|
+
} finally {
|
|
687
|
+
rl.close();
|
|
688
|
+
}
|
|
689
|
+
}
|
|
634
690
|
async function loginWithBrowser(args) {
|
|
635
|
-
const
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
try {
|
|
651
|
-
const raw = await readBody(req);
|
|
652
|
-
const body = JSON.parse(raw);
|
|
653
|
-
if (body.state !== state || typeof body.accessToken !== "string" || !body.accessToken) {
|
|
654
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
655
|
-
res.end(JSON.stringify({ ok: false, error: "invalid_callback" }));
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
try {
|
|
659
|
-
await verifyDevelopersAccessToken(body.accessToken, args.origins.apiOrigin);
|
|
660
|
-
} catch {
|
|
661
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
662
|
-
res.end(JSON.stringify({ ok: false, error: "invalid_token" }));
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
const sub = typeof body.sub === "string" ? body.sub : subFromJwt(body.accessToken);
|
|
666
|
-
const next = {
|
|
667
|
-
accessToken: body.accessToken,
|
|
668
|
-
...sub ? { sub } : {},
|
|
669
|
-
...typeof body.expiresAt === "number" ? { expiresAt: body.expiresAt } : {}
|
|
670
|
-
};
|
|
671
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
672
|
-
res.end(JSON.stringify({ ok: true }));
|
|
673
|
-
server.close();
|
|
674
|
-
resolve(next);
|
|
675
|
-
} catch (e) {
|
|
676
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
677
|
-
res.end(JSON.stringify({ ok: false }));
|
|
678
|
-
server.close();
|
|
679
|
-
reject(e);
|
|
680
|
-
}
|
|
691
|
+
const pendingPath = pendingLoginPath(args.sessionPath);
|
|
692
|
+
const openFlag = args.open !== false;
|
|
693
|
+
if (args.bridgeJson?.trim()) {
|
|
694
|
+
const pending = await readPending(pendingPath);
|
|
695
|
+
if (!pending) {
|
|
696
|
+
throw new Error("no_pending_login \u2014 run login again to open the browser first");
|
|
697
|
+
}
|
|
698
|
+
if (pending.apiOrigin !== args.origins.apiOrigin || pending.developersOrigin !== args.origins.developersOrigin) {
|
|
699
|
+
await clearPending(pendingPath);
|
|
700
|
+
throw new Error("pending_login_origin_mismatch \u2014 run login again");
|
|
701
|
+
}
|
|
702
|
+
const session2 = await sessionFromBridge({
|
|
703
|
+
raw: args.bridgeJson,
|
|
704
|
+
expectedState: pending.state,
|
|
705
|
+
apiOrigin: args.origins.apiOrigin
|
|
681
706
|
});
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
707
|
+
await saveSession(session2, args.origins, args.sessionPath);
|
|
708
|
+
await clearPending(pendingPath);
|
|
709
|
+
return {
|
|
710
|
+
session: session2,
|
|
711
|
+
human: {
|
|
712
|
+
needs_human: "login",
|
|
713
|
+
message: "Session stored.",
|
|
714
|
+
open_url: loginBridgeUrl(args.origins.developersOrigin, pending.state)
|
|
687
715
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
}
|
|
704
|
-
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
const state = randomBytes(16).toString("hex");
|
|
719
|
+
const openUrl = loginBridgeUrl(args.origins.developersOrigin, state);
|
|
720
|
+
await writePending(pendingPath, {
|
|
721
|
+
v: 1,
|
|
722
|
+
state,
|
|
723
|
+
createdAt: Date.now(),
|
|
724
|
+
developersOrigin: args.origins.developersOrigin,
|
|
725
|
+
apiOrigin: args.origins.apiOrigin
|
|
726
|
+
});
|
|
727
|
+
if (openFlag) {
|
|
728
|
+
try {
|
|
729
|
+
await openBrowser(assertOriginBrowserUrl(openUrl, args.origins.developersOrigin));
|
|
730
|
+
} catch {
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if (args.deferPaste) {
|
|
734
|
+
return {
|
|
735
|
+
pending: true,
|
|
736
|
+
human: {
|
|
737
|
+
needs_human: "login",
|
|
738
|
+
message: "Complete Passkey in the browser, copy the JSON on the page, then call login again with bridge_json.",
|
|
739
|
+
open_url: openUrl
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
const raw = await readBridgeJsonFromStdin();
|
|
744
|
+
const session = await sessionFromBridge({
|
|
745
|
+
raw,
|
|
746
|
+
expectedState: state,
|
|
747
|
+
apiOrigin: args.origins.apiOrigin
|
|
705
748
|
});
|
|
706
|
-
await saveSession(session, args.origins);
|
|
749
|
+
await saveSession(session, args.origins, args.sessionPath);
|
|
750
|
+
await clearPending(pendingPath);
|
|
707
751
|
return {
|
|
708
752
|
session,
|
|
709
753
|
human: {
|
|
710
754
|
needs_human: "login",
|
|
711
|
-
message: "
|
|
712
|
-
open_url:
|
|
755
|
+
message: "Session stored. You can close the browser tab.",
|
|
756
|
+
open_url: openUrl
|
|
713
757
|
}
|
|
714
758
|
};
|
|
715
759
|
}
|
|
716
|
-
var
|
|
760
|
+
var MAX_BRIDGE_JSON_CHARS;
|
|
717
761
|
var init_login = __esm({
|
|
718
762
|
"src/login.ts"() {
|
|
719
763
|
init_browser();
|
|
720
764
|
init_safe_browser_url();
|
|
721
765
|
init_access_token_verify();
|
|
722
766
|
init_session_store();
|
|
723
|
-
|
|
767
|
+
MAX_BRIDGE_JSON_CHARS = 16384;
|
|
724
768
|
}
|
|
725
769
|
});
|
|
726
770
|
|
|
@@ -866,9 +910,24 @@ function createSetupClient(options = {}) {
|
|
|
866
910
|
const s = await loadSession(sessionPath);
|
|
867
911
|
return s?.session ?? null;
|
|
868
912
|
},
|
|
869
|
-
async login() {
|
|
870
|
-
const
|
|
871
|
-
|
|
913
|
+
async login(opts) {
|
|
914
|
+
const bridgeJson = opts?.bridgeJson?.trim();
|
|
915
|
+
const deferPaste = !bridgeJson && !process.stdin.isTTY;
|
|
916
|
+
const out = await loginWithBrowser({
|
|
917
|
+
origins,
|
|
918
|
+
open: openBrowserFlag,
|
|
919
|
+
...bridgeJson ? { bridgeJson } : {},
|
|
920
|
+
...deferPaste ? { deferPaste: true } : {},
|
|
921
|
+
sessionPath
|
|
922
|
+
});
|
|
923
|
+
if (out.pending || !out.session) {
|
|
924
|
+
return {
|
|
925
|
+
ok: false,
|
|
926
|
+
error: "login_pending_paste",
|
|
927
|
+
human: out.human
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
return { ok: true, data: { sub: out.session.sub } };
|
|
872
931
|
},
|
|
873
932
|
async logout() {
|
|
874
933
|
await clearSession(sessionPath);
|
|
@@ -1246,7 +1305,9 @@ async function dispatch(client, name, args) {
|
|
|
1246
1305
|
case "clavis_setup_status":
|
|
1247
1306
|
return client.status();
|
|
1248
1307
|
case "clavis_login":
|
|
1249
|
-
return client.login(
|
|
1308
|
+
return client.login(
|
|
1309
|
+
args.bridge_json ? { bridgeJson: String(args.bridge_json) } : void 0
|
|
1310
|
+
);
|
|
1250
1311
|
case "clavis_org_anchor_plan":
|
|
1251
1312
|
return client.orgAnchorPlan(String(args.domain), args.name ? String(args.name) : void 0);
|
|
1252
1313
|
case "clavis_org_anchor_finish":
|
|
@@ -1339,8 +1400,17 @@ var init_mcp = __esm({
|
|
|
1339
1400
|
},
|
|
1340
1401
|
{
|
|
1341
1402
|
name: "clavis_login",
|
|
1342
|
-
description: "
|
|
1343
|
-
inputSchema: {
|
|
1403
|
+
description: "Start or finish developers Passkey login. First call opens the browser; after the human pastes the page JSON, call again with bridge_json.",
|
|
1404
|
+
inputSchema: {
|
|
1405
|
+
type: "object",
|
|
1406
|
+
properties: {
|
|
1407
|
+
bridge_json: {
|
|
1408
|
+
type: "string",
|
|
1409
|
+
description: "JSON shown on developers /setup/login after Passkey (state + accessToken)."
|
|
1410
|
+
}
|
|
1411
|
+
},
|
|
1412
|
+
additionalProperties: false
|
|
1413
|
+
}
|
|
1344
1414
|
},
|
|
1345
1415
|
{
|
|
1346
1416
|
name: "clavis_org_anchor_plan",
|
|
@@ -1501,7 +1571,7 @@ function printJson(value) {
|
|
|
1501
1571
|
}
|
|
1502
1572
|
function usage() {
|
|
1503
1573
|
console.error(`Usage:
|
|
1504
|
-
clavis login
|
|
1574
|
+
clavis login [--bridge-json '<json>' | --bridge-json-file <path>]
|
|
1505
1575
|
clavis logout
|
|
1506
1576
|
clavis status
|
|
1507
1577
|
clavis mcp
|
|
@@ -1516,6 +1586,7 @@ function usage() {
|
|
|
1516
1586
|
clavis declaration-set --org O --app A --end-users TEXT --use signature=OP
|
|
1517
1587
|
clavis emit-env --app A [--operate-jwk '{"kty":"..."}']
|
|
1518
1588
|
|
|
1589
|
+
login: opens developers /setup/login, then paste the JSON from the page (or pass --bridge-json).
|
|
1519
1590
|
Secrets stay in ~/.config/clavis/apps/<appId>/ (mode 0600). Command output includes the file path. emit-env needs CLAVIS_MASTER_PUBLIC_JWK_JSON set to the master public JWK from /.well-known/jwks.json.
|
|
1520
1591
|
declaration-set replaces the App's current declaration. Pass every use to keep. status reports the signature card. WASM and ledger subscription are on developers.
|
|
1521
1592
|
|
|
@@ -1546,9 +1617,17 @@ async function main() {
|
|
|
1546
1617
|
await runMcpServer2();
|
|
1547
1618
|
return;
|
|
1548
1619
|
}
|
|
1549
|
-
case "login":
|
|
1550
|
-
|
|
1620
|
+
case "login": {
|
|
1621
|
+
const fromFlag = flag(rest, "--bridge-json");
|
|
1622
|
+
const fromFile = flag(rest, "--bridge-json-file");
|
|
1623
|
+
let bridgeJson = fromFlag;
|
|
1624
|
+
if (fromFile) {
|
|
1625
|
+
const { readFile: readFile4 } = await import('fs/promises');
|
|
1626
|
+
bridgeJson = await readFile4(fromFile, "utf8");
|
|
1627
|
+
}
|
|
1628
|
+
printJson(await client.login(bridgeJson ? { bridgeJson } : void 0));
|
|
1551
1629
|
return;
|
|
1630
|
+
}
|
|
1552
1631
|
case "logout":
|
|
1553
1632
|
printJson(await client.logout());
|
|
1554
1633
|
return;
|