@mnemom/mnemom 0.17.36 → 0.17.38-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/agent-run.d.ts +11 -0
- package/dist/commands/agent-run.js +37 -0
- package/dist/commands/agent-share-render.d.ts +5 -5
- package/dist/commands/agent-share-render.js +9 -7
- package/dist/commands/agent-share-test-issuer.d.ts +1 -1
- package/dist/commands/agent-share-test-issuer.js +1 -1
- package/dist/commands/agent.d.ts +8 -1
- package/dist/commands/agent.js +14 -3
- package/dist/commands/scan.d.ts +15 -2
- package/dist/commands/scan.js +48 -3
- package/dist/host/commands.js +4 -1
- package/dist/host/owner.d.ts +2 -0
- package/dist/host/verbs.d.ts +16 -1
- package/dist/host/verbs.js +45 -3
- package/dist/index.js +1 -1
- package/dist/lib/commit-report.d.ts +7 -13
- package/dist/lib/commit-report.js +12 -5
- package/dist/lib/conduct-receipt.d.ts +8 -3
- package/dist/lib/conduct-receipt.js +29 -7
- package/dist/lib/experimental.d.ts +1 -1
- package/dist/lib/experimental.js +1 -12
- package/dist/lib/runner/executor-client.d.ts +5 -0
- package/dist/lib/runner/executor-client.js +8 -0
- package/dist/lib/runner/job.d.ts +37 -0
- package/dist/lib/runner/job.js +74 -1
- package/dist/lib/runner/phases.d.ts +7 -2
- package/dist/lib/runner/phases.js +7 -2
- package/dist/lib/runner/proxy.d.ts +26 -2
- package/dist/lib/runner/proxy.js +33 -1
- package/dist/lib/runner/record-commit.d.ts +16 -0
- package/dist/lib/runner/record-commit.js +7 -0
- package/dist/lib/scan/spend/anthropic-usage.d.ts +20 -1
- package/dist/lib/scan/spend/anthropic-usage.js +32 -7
- package/dist/lib/scan/spend/anthropic-wif.d.ts +42 -0
- package/dist/lib/scan/spend/anthropic-wif.js +153 -0
- package/dist/vendor/durable-contract/index.js +6 -3
- package/dist/vendor/shared/durable-contract/cli-surface.js +2 -2
- package/dist/vendor/shared/durable-contract/codes.js +4 -1
- package/package.json +2 -5
- package/node_modules/@mnemom/aip-verifier/LICENSE +0 -190
- package/node_modules/@mnemom/aip-verifier/dist/claim-lint-CVITIRcU.d.cts +0 -478
- package/node_modules/@mnemom/aip-verifier/dist/claim-lint-CVITIRcU.d.ts +0 -478
- package/node_modules/@mnemom/aip-verifier/dist/index.cjs +0 -971
- package/node_modules/@mnemom/aip-verifier/dist/index.cjs.map +0 -1
- package/node_modules/@mnemom/aip-verifier/dist/index.d.cts +0 -330
- package/node_modules/@mnemom/aip-verifier/dist/index.d.ts +0 -330
- package/node_modules/@mnemom/aip-verifier/dist/index.js +0 -933
- package/node_modules/@mnemom/aip-verifier/dist/index.js.map +0 -1
- package/node_modules/@mnemom/aip-verifier/dist/render-lines.cjs +0 -879
- package/node_modules/@mnemom/aip-verifier/dist/render-lines.cjs.map +0 -1
- package/node_modules/@mnemom/aip-verifier/dist/render-lines.d.cts +0 -96
- package/node_modules/@mnemom/aip-verifier/dist/render-lines.d.ts +0 -96
- package/node_modules/@mnemom/aip-verifier/dist/render-lines.js +0 -875
- package/node_modules/@mnemom/aip-verifier/dist/render-lines.js.map +0 -1
- package/node_modules/@mnemom/aip-verifier/package.json +0 -86
- package/node_modules/@noble/ed25519/LICENSE +0 -21
- package/node_modules/@noble/ed25519/README.md +0 -371
- package/node_modules/@noble/ed25519/index.d.ts +0 -391
- package/node_modules/@noble/ed25519/index.js +0 -933
- package/node_modules/@noble/ed25519/index.ts +0 -1134
- package/node_modules/@noble/ed25519/package.json +0 -54
- package/node_modules/@noble/hashes/LICENSE +0 -21
- package/node_modules/@noble/hashes/README.md +0 -478
- package/node_modules/@noble/hashes/_blake.d.ts +0 -20
- package/node_modules/@noble/hashes/_blake.js +0 -59
- package/node_modules/@noble/hashes/_md.d.ts +0 -95
- package/node_modules/@noble/hashes/_md.js +0 -209
- package/node_modules/@noble/hashes/_u64.d.ts +0 -36
- package/node_modules/@noble/hashes/_u64.js +0 -77
- package/node_modules/@noble/hashes/argon2.d.ts +0 -148
- package/node_modules/@noble/hashes/argon2.js +0 -577
- package/node_modules/@noble/hashes/blake1.d.ts +0 -162
- package/node_modules/@noble/hashes/blake1.js +0 -630
- package/node_modules/@noble/hashes/blake2.d.ts +0 -203
- package/node_modules/@noble/hashes/blake2.js +0 -573
- package/node_modules/@noble/hashes/blake3.d.ts +0 -68
- package/node_modules/@noble/hashes/blake3.js +0 -310
- package/node_modules/@noble/hashes/eskdf.d.ts +0 -91
- package/node_modules/@noble/hashes/eskdf.js +0 -225
- package/node_modules/@noble/hashes/hkdf.d.ts +0 -70
- package/node_modules/@noble/hashes/hkdf.js +0 -152
- package/node_modules/@noble/hashes/hmac.d.ts +0 -50
- package/node_modules/@noble/hashes/hmac.js +0 -93
- package/node_modules/@noble/hashes/index.d.ts +0 -1
- package/node_modules/@noble/hashes/index.js +0 -34
- package/node_modules/@noble/hashes/legacy.d.ts +0 -107
- package/node_modules/@noble/hashes/legacy.js +0 -348
- package/node_modules/@noble/hashes/package.json +0 -91
- package/node_modules/@noble/hashes/pbkdf2.d.ts +0 -66
- package/node_modules/@noble/hashes/pbkdf2.js +0 -176
- package/node_modules/@noble/hashes/scrypt.d.ts +0 -98
- package/node_modules/@noble/hashes/scrypt.js +0 -304
- package/node_modules/@noble/hashes/sha2.d.ts +0 -176
- package/node_modules/@noble/hashes/sha2.js +0 -446
- package/node_modules/@noble/hashes/sha3-addons.d.ts +0 -533
- package/node_modules/@noble/hashes/sha3-addons.js +0 -973
- package/node_modules/@noble/hashes/sha3.d.ts +0 -208
- package/node_modules/@noble/hashes/sha3.js +0 -475
- package/node_modules/@noble/hashes/src/_blake.ts +0 -67
- package/node_modules/@noble/hashes/src/_md.ts +0 -227
- package/node_modules/@noble/hashes/src/_u64.ts +0 -111
- package/node_modules/@noble/hashes/src/argon2.ts +0 -693
- package/node_modules/@noble/hashes/src/blake1.ts +0 -677
- package/node_modules/@noble/hashes/src/blake2.ts +0 -648
- package/node_modules/@noble/hashes/src/blake3.ts +0 -344
- package/node_modules/@noble/hashes/src/eskdf.ts +0 -265
- package/node_modules/@noble/hashes/src/hkdf.ts +0 -161
- package/node_modules/@noble/hashes/src/hmac.ts +0 -130
- package/node_modules/@noble/hashes/src/index.ts +0 -33
- package/node_modules/@noble/hashes/src/legacy.ts +0 -361
- package/node_modules/@noble/hashes/src/pbkdf2.ts +0 -219
- package/node_modules/@noble/hashes/src/scrypt.ts +0 -375
- package/node_modules/@noble/hashes/src/sha2.ts +0 -486
- package/node_modules/@noble/hashes/src/sha3-addons.ts +0 -1157
- package/node_modules/@noble/hashes/src/sha3.ts +0 -525
- package/node_modules/@noble/hashes/src/utils.ts +0 -978
- package/node_modules/@noble/hashes/src/webcrypto.ts +0 -283
- package/node_modules/@noble/hashes/utils.d.ts +0 -560
- package/node_modules/@noble/hashes/utils.js +0 -687
- package/node_modules/@noble/hashes/webcrypto.d.ts +0 -121
- package/node_modules/@noble/hashes/webcrypto.js +0 -228
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// MNE-9298 Tier 1: the CTO's own Anthropic Admin key, used LOCALLY, to read measured usage. Port of
|
|
2
2
|
// mnemom-api src/org-scan/usage/usage-client.ts (two read-only GETs: usage_report/messages grouped by
|
|
3
|
-
// context_window, and cost_report) with the server-only parts (egress allowlist
|
|
3
|
+
// context_window, and cost_report) with the server-only parts (egress allowlist) dropped.
|
|
4
|
+
//
|
|
5
|
+
// MNE-9706: the reads take either credential, as the server's credential-source.ts does: the pasted Admin
|
|
6
|
+
// key (x-api-key) or a short-lived WIF access token (Authorization: Bearer, see anthropic-wif.ts). Either
|
|
7
|
+
// one is sent ONLY to the two report paths below; walk() refuses any other path (the fence, design T18:
|
|
8
|
+
// Anthropic's WIF scope for these reports is org:admin, so the fence has to live here).
|
|
4
9
|
//
|
|
5
10
|
// The key is held in memory for the length of the two reads. It is never stored, logged, written to disk,
|
|
6
11
|
// echoed, put in argv, a URL or an error message, and is sent only to api.anthropic.com (a constant, not
|
|
@@ -11,6 +16,13 @@ export const ADMIN_KEY_ENV = "ANTHROPIC_ADMIN_KEY";
|
|
|
11
16
|
const ANTHROPIC_VERSION = "2023-06-01";
|
|
12
17
|
const USAGE_PATH = "/v1/organizations/usage_report/messages";
|
|
13
18
|
const COST_PATH = "/v1/organizations/cost_report";
|
|
19
|
+
/** The only paths a usage credential is ever sent to (design T18: fenced to report endpoints). */
|
|
20
|
+
export const REPORT_PATHS = [USAGE_PATH, COST_PATH];
|
|
21
|
+
/** The fence, as one exported check so it is directly testable. Throws AnthropicUsageError for any other path. */
|
|
22
|
+
export function assertReportPath(path) {
|
|
23
|
+
if (!REPORT_PATHS.includes(path))
|
|
24
|
+
throw new AnthropicUsageError("malformed");
|
|
25
|
+
}
|
|
14
26
|
export const DEFAULT_MAX_PAGES = 20;
|
|
15
27
|
/** One shared deadline for a request including its retries (not N x timeout). */
|
|
16
28
|
export const DEFAULT_TIMEOUT_MS = 15_000;
|
|
@@ -22,6 +34,7 @@ export const isAdminKeyShape = (k) => typeof k === "string" && ADMIN_KEY_RE.test
|
|
|
22
34
|
const FAILURE_TEXT = {
|
|
23
35
|
key_invalid: "The Anthropic admin key is not an Admin API key (it should start with sk-ant-admin).",
|
|
24
36
|
key_refused: "Anthropic refused the admin key (401/403).",
|
|
37
|
+
token_refused: "Anthropic refused the workload identity token for the usage reports (401/403). The federation rule needs scope org:admin.",
|
|
25
38
|
rate_limited: "Anthropic rate limit reached.",
|
|
26
39
|
timeout: "Anthropic did not answer in time.",
|
|
27
40
|
network: "Anthropic was unreachable.",
|
|
@@ -96,14 +109,14 @@ function retryWait(res, attempt) {
|
|
|
96
109
|
return Number.isFinite(ra) && ra > 0 ? ra * 1000 : backoff(attempt);
|
|
97
110
|
}
|
|
98
111
|
class Reader {
|
|
99
|
-
|
|
112
|
+
auth;
|
|
100
113
|
fetchImpl;
|
|
101
114
|
sleep;
|
|
102
115
|
maxPages;
|
|
103
116
|
timeoutMs;
|
|
104
117
|
maxRetries;
|
|
105
|
-
constructor(
|
|
106
|
-
this.
|
|
118
|
+
constructor(auth, deps) {
|
|
119
|
+
this.auth = auth;
|
|
107
120
|
this.fetchImpl = deps.fetchImpl ?? ((...a) => fetch(...a));
|
|
108
121
|
this.sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
109
122
|
this.maxPages = deps.maxPages ?? DEFAULT_MAX_PAGES;
|
|
@@ -111,6 +124,8 @@ class Reader {
|
|
|
111
124
|
this.maxRetries = deps.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
112
125
|
}
|
|
113
126
|
async walk(path, base, parse, callMaxPages) {
|
|
127
|
+
// The fence: the credential goes to the two report paths and nowhere else.
|
|
128
|
+
assertReportPath(path);
|
|
114
129
|
const ceiling = typeof callMaxPages === "number" && Number.isFinite(callMaxPages) && callMaxPages >= 1
|
|
115
130
|
? Math.min(this.maxPages, Math.floor(callMaxPages))
|
|
116
131
|
: this.maxPages;
|
|
@@ -154,7 +169,7 @@ class Reader {
|
|
|
154
169
|
res = await this.fetchImpl(url, {
|
|
155
170
|
method: "GET",
|
|
156
171
|
headers: {
|
|
157
|
-
|
|
172
|
+
[this.auth.header]: this.auth.value,
|
|
158
173
|
"anthropic-version": ANTHROPIC_VERSION,
|
|
159
174
|
accept: "application/json",
|
|
160
175
|
},
|
|
@@ -185,7 +200,7 @@ class Reader {
|
|
|
185
200
|
}
|
|
186
201
|
await res.body?.cancel().catch(() => { });
|
|
187
202
|
if (res.status === 401 || res.status === 403)
|
|
188
|
-
throw new AnthropicUsageError("key_refused");
|
|
203
|
+
throw new AnthropicUsageError(this.auth.header === "x-api-key" ? "key_refused" : "token_refused");
|
|
189
204
|
const retryable = res.status === 429 || res.status >= 500;
|
|
190
205
|
const wait = retryable ? retryWait(res, attempt + 1) : 0;
|
|
191
206
|
if (retryable &&
|
|
@@ -209,11 +224,21 @@ export async function fetchMeasuredUsage(key, period, deps = {}) {
|
|
|
209
224
|
const k = key?.trim();
|
|
210
225
|
if (!k || !isAdminKeyShape(k))
|
|
211
226
|
throw new AnthropicUsageError("key_invalid");
|
|
227
|
+
return fetchMeasuredUsageWithAuth({ header: "x-api-key", value: k }, period, deps);
|
|
228
|
+
}
|
|
229
|
+
/** A WIF access token as the bearer for the two report reads. Printable ASCII only, else key_invalid. */
|
|
230
|
+
export function bearerAuth(token) {
|
|
231
|
+
if (!/^[\x21-\x7e]{8,4096}$/.test(token))
|
|
232
|
+
throw new AnthropicUsageError("key_invalid");
|
|
233
|
+
return { header: "authorization", value: `Bearer ${token}` };
|
|
234
|
+
}
|
|
235
|
+
/** The two reads with an already-resolved credential (pasted key or WIF bearer). Throws AnthropicUsageError only. */
|
|
236
|
+
export async function fetchMeasuredUsageWithAuth(auth, period, deps = {}) {
|
|
212
237
|
if (!validDay(period.start) || !validDay(period.end))
|
|
213
238
|
throw new AnthropicUsageError("malformed");
|
|
214
239
|
const startingAt = alignStartingAt(`${period.start}T00:00:00Z`);
|
|
215
240
|
const endingAt = new Date(Date.parse(`${period.end}T00:00:00Z`) + DAY_MS).toISOString();
|
|
216
|
-
const reader = new Reader(
|
|
241
|
+
const reader = new Reader(auth, deps);
|
|
217
242
|
const up = new URLSearchParams({
|
|
218
243
|
starting_at: startingAt,
|
|
219
244
|
ending_at: endingAt,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const WIF_EXCHANGE_URL = "https://api.anthropic.com/v1/oauth/token";
|
|
2
|
+
export declare const WIF_ENV: {
|
|
3
|
+
readonly rule: "ANTHROPIC_FEDERATION_RULE_ID";
|
|
4
|
+
readonly org: "ANTHROPIC_ORGANIZATION_ID";
|
|
5
|
+
readonly serviceAccount: "ANTHROPIC_SERVICE_ACCOUNT_ID";
|
|
6
|
+
readonly workspace: "ANTHROPIC_WORKSPACE_ID";
|
|
7
|
+
};
|
|
8
|
+
/** Same ceiling the server held a WIF token to (credential-source.ts MAX_WIF_TOKEN_LIFETIME_MS). */
|
|
9
|
+
export declare const MAX_WIF_TOKEN_LIFETIME_MS = 300000;
|
|
10
|
+
export interface WifConfig {
|
|
11
|
+
federationRuleId: string;
|
|
12
|
+
organizationId: string;
|
|
13
|
+
serviceAccountId: string;
|
|
14
|
+
workspaceId?: string;
|
|
15
|
+
}
|
|
16
|
+
export type WifFailure = "config_invalid" | "assertion_unavailable" | "assertion_refused" | "exchange_refused" | "exchange_failed";
|
|
17
|
+
export declare const wifFailureText: (r: WifFailure) => string;
|
|
18
|
+
export declare const WIF_FALLBACK_NOTE = "Falling back to the pasted Anthropic Admin key.";
|
|
19
|
+
/** Carries only a reason tag; its message is the fixed sentence. */
|
|
20
|
+
export declare class WifError extends Error {
|
|
21
|
+
readonly reason: WifFailure;
|
|
22
|
+
constructor(reason: WifFailure);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads the WIF ids from env. None of the three required ids set: null (WIF is not set up, no message).
|
|
26
|
+
* Some set, or any malformed: WifError("config_invalid"), so a half-done setup is said out loud.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readWifConfig(env: NodeJS.ProcessEnv): WifConfig | null;
|
|
29
|
+
export interface WifDeps {
|
|
30
|
+
/** Step 1 seam: returns the assertion for the org. Defaults to the mnemom-api route with the CLI's auth. */
|
|
31
|
+
mintAssertion?: (orgId: string) => Promise<unknown>;
|
|
32
|
+
/** Step 2 seam: the fetch used ONLY for the Anthropic exchange. */
|
|
33
|
+
fetchImpl?: typeof fetch;
|
|
34
|
+
now?: () => number;
|
|
35
|
+
}
|
|
36
|
+
export interface WifAccessToken {
|
|
37
|
+
accessToken: string;
|
|
38
|
+
/** Epoch ms, clamped to MAX_WIF_TOKEN_LIFETIME_MS from receipt. */
|
|
39
|
+
expiresAt: number;
|
|
40
|
+
}
|
|
41
|
+
/** Steps 1 and 2. Throws WifError only. */
|
|
42
|
+
export declare function obtainWifAccessToken(orgId: string, cfg: WifConfig, deps?: WifDeps): Promise<WifAccessToken>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// MNE-9706 (S2.6, design T18): read the Anthropic Console through workload identity federation (WIF).
|
|
2
|
+
//
|
|
3
|
+
// Three steps, all from this machine:
|
|
4
|
+
// 1. Ask mnemom-api for a short-lived OIDC identity token (the "assertion") for the org, with the user's
|
|
5
|
+
// own CLI sign-in: POST /v1/orgs/{org_id}/scan/wif-assertion. Its sub is `mnemom:org:<org_id>`.
|
|
6
|
+
// 2. Exchange it DIRECTLY at Anthropic (POST https://api.anthropic.com/v1/oauth/token, RFC 7523
|
|
7
|
+
// jwt-bearer) for a short-lived access token. Mnemom never sees that token.
|
|
8
|
+
// 3. Hand the token to the usage reader, which sends it only to the two report paths (the fence).
|
|
9
|
+
//
|
|
10
|
+
// The customer's Console holds the federation issuer, service account and rule. The CLI needs only their
|
|
11
|
+
// non-secret ids, read from Anthropic's own variable names (ANTHROPIC_FEDERATION_RULE_ID,
|
|
12
|
+
// ANTHROPIC_ORGANIZATION_ID, ANTHROPIC_SERVICE_ACCOUNT_ID, optional ANTHROPIC_WORKSPACE_ID).
|
|
13
|
+
//
|
|
14
|
+
// The assertion and the access token live in memory for one scan and are never logged, stored, printed,
|
|
15
|
+
// put in argv, a URL or an error message. Every failure is a fixed sentence (WifFailure), so the caller can
|
|
16
|
+
// fall back to the pasted Admin key with a clear message.
|
|
17
|
+
import { MnemomApiError, postApi } from "../../api.js";
|
|
18
|
+
import { ANTHROPIC_ADMIN_ORIGIN } from "./anthropic-usage.js";
|
|
19
|
+
export const WIF_EXCHANGE_URL = `${ANTHROPIC_ADMIN_ORIGIN}/v1/oauth/token`;
|
|
20
|
+
export const WIF_ENV = {
|
|
21
|
+
rule: "ANTHROPIC_FEDERATION_RULE_ID",
|
|
22
|
+
org: "ANTHROPIC_ORGANIZATION_ID",
|
|
23
|
+
serviceAccount: "ANTHROPIC_SERVICE_ACCOUNT_ID",
|
|
24
|
+
workspace: "ANTHROPIC_WORKSPACE_ID",
|
|
25
|
+
};
|
|
26
|
+
/** Same ceiling the server held a WIF token to (credential-source.ts MAX_WIF_TOKEN_LIFETIME_MS). */
|
|
27
|
+
export const MAX_WIF_TOKEN_LIFETIME_MS = 300_000;
|
|
28
|
+
const EXCHANGE_TIMEOUT_MS = 15_000;
|
|
29
|
+
const WIF_TEXT = {
|
|
30
|
+
config_invalid: "The Anthropic workload identity settings are incomplete or malformed (federation rule, organization and service account ids).",
|
|
31
|
+
assertion_unavailable: "Mnemom could not issue a workload identity token for this org right now.",
|
|
32
|
+
assertion_refused: "Mnemom did not issue a workload identity token (sign in as an owner or admin of an org with Org Scan on).",
|
|
33
|
+
exchange_refused: "Anthropic refused the workload identity token. Check the federation rule in your Anthropic Console (its issuer, subject and scope org:admin).",
|
|
34
|
+
exchange_failed: "Anthropic's token exchange could not be completed.",
|
|
35
|
+
};
|
|
36
|
+
export const wifFailureText = (r) => WIF_TEXT[r];
|
|
37
|
+
export const WIF_FALLBACK_NOTE = "Falling back to the pasted Anthropic Admin key.";
|
|
38
|
+
/** Carries only a reason tag; its message is the fixed sentence. */
|
|
39
|
+
export class WifError extends Error {
|
|
40
|
+
reason;
|
|
41
|
+
constructor(reason) {
|
|
42
|
+
super(WIF_TEXT[reason]);
|
|
43
|
+
this.reason = reason;
|
|
44
|
+
this.name = "WifError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const RULE_RE = /^fdrl_[A-Za-z0-9]{1,128}$/;
|
|
48
|
+
const SVAC_RE = /^svac_[A-Za-z0-9]{1,128}$/;
|
|
49
|
+
const WRKSPC_RE = /^wrkspc_[A-Za-z0-9]{1,128}$/;
|
|
50
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
51
|
+
/**
|
|
52
|
+
* Reads the WIF ids from env. None of the three required ids set: null (WIF is not set up, no message).
|
|
53
|
+
* Some set, or any malformed: WifError("config_invalid"), so a half-done setup is said out loud.
|
|
54
|
+
*/
|
|
55
|
+
export function readWifConfig(env) {
|
|
56
|
+
const get = (k) => {
|
|
57
|
+
const v = env[k]?.trim();
|
|
58
|
+
return v ? v : undefined;
|
|
59
|
+
};
|
|
60
|
+
const rule = get(WIF_ENV.rule);
|
|
61
|
+
const org = get(WIF_ENV.org);
|
|
62
|
+
const svac = get(WIF_ENV.serviceAccount);
|
|
63
|
+
const ws = get(WIF_ENV.workspace);
|
|
64
|
+
if (!rule && !org && !svac)
|
|
65
|
+
return null;
|
|
66
|
+
if (!rule || !org || !svac)
|
|
67
|
+
throw new WifError("config_invalid");
|
|
68
|
+
if (!RULE_RE.test(rule) || !UUID_RE.test(org) || !SVAC_RE.test(svac))
|
|
69
|
+
throw new WifError("config_invalid");
|
|
70
|
+
if (ws !== undefined && !WRKSPC_RE.test(ws))
|
|
71
|
+
throw new WifError("config_invalid");
|
|
72
|
+
return {
|
|
73
|
+
federationRuleId: rule,
|
|
74
|
+
organizationId: org,
|
|
75
|
+
serviceAccountId: svac,
|
|
76
|
+
...(ws ? { workspaceId: ws } : {}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const JWT_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
80
|
+
async function defaultMint(orgId) {
|
|
81
|
+
return postApi(`/v1/orgs/${encodeURIComponent(orgId)}/scan/wif-assertion`, {});
|
|
82
|
+
}
|
|
83
|
+
/** Steps 1 and 2. Throws WifError only. */
|
|
84
|
+
export async function obtainWifAccessToken(orgId, cfg, deps = {}) {
|
|
85
|
+
const now = deps.now ?? Date.now;
|
|
86
|
+
let assertion;
|
|
87
|
+
try {
|
|
88
|
+
const body = await (deps.mintAssertion ?? defaultMint)(orgId);
|
|
89
|
+
const a = body && typeof body === "object" ? body.assertion : undefined;
|
|
90
|
+
if (typeof a !== "string" || a.length > 16_384 || !JWT_RE.test(a))
|
|
91
|
+
throw new WifError("assertion_unavailable");
|
|
92
|
+
assertion = a;
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
if (e instanceof WifError)
|
|
96
|
+
throw e;
|
|
97
|
+
const status = e instanceof MnemomApiError ? e.effectiveStatus : 0;
|
|
98
|
+
// 401/403 is "not you"; 404 is the dark route (Org Scan off for this org). Both: no token for you.
|
|
99
|
+
throw new WifError(status === 401 || status === 403 || status === 404
|
|
100
|
+
? "assertion_refused"
|
|
101
|
+
: "assertion_unavailable");
|
|
102
|
+
}
|
|
103
|
+
const fetchImpl = deps.fetchImpl ?? ((...a) => fetch(...a));
|
|
104
|
+
let res;
|
|
105
|
+
try {
|
|
106
|
+
res = await fetchImpl(WIF_EXCHANGE_URL, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
109
|
+
body: JSON.stringify({
|
|
110
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
111
|
+
assertion,
|
|
112
|
+
federation_rule_id: cfg.federationRuleId,
|
|
113
|
+
organization_id: cfg.organizationId,
|
|
114
|
+
service_account_id: cfg.serviceAccountId,
|
|
115
|
+
...(cfg.workspaceId ? { workspace_id: cfg.workspaceId } : {}),
|
|
116
|
+
}),
|
|
117
|
+
// A redirect would carry the assertion elsewhere: refuse to follow one.
|
|
118
|
+
redirect: "error",
|
|
119
|
+
signal: AbortSignal.timeout(EXCHANGE_TIMEOUT_MS),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Never surface the thrown value: it can carry the request.
|
|
124
|
+
throw new WifError("exchange_failed");
|
|
125
|
+
}
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
await res.body?.cancel().catch(() => { });
|
|
128
|
+
throw new WifError(res.status === 400 || res.status === 401 || res.status === 403
|
|
129
|
+
? "exchange_refused"
|
|
130
|
+
: "exchange_failed");
|
|
131
|
+
}
|
|
132
|
+
let json;
|
|
133
|
+
try {
|
|
134
|
+
json = await res.json();
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
throw new WifError("exchange_failed");
|
|
138
|
+
}
|
|
139
|
+
const b = json && typeof json === "object" ? json : {};
|
|
140
|
+
const token = b.access_token;
|
|
141
|
+
if (typeof token !== "string" || !/^[\x21-\x7e]{8,4096}$/.test(token))
|
|
142
|
+
throw new WifError("exchange_failed");
|
|
143
|
+
if (b.token_type !== undefined && String(b.token_type).toLowerCase() !== "bearer")
|
|
144
|
+
throw new WifError("exchange_failed");
|
|
145
|
+
const secs = typeof b.expires_in === "number" && Number.isFinite(b.expires_in) && b.expires_in > 0
|
|
146
|
+
? b.expires_in
|
|
147
|
+
: 300;
|
|
148
|
+
const t = now();
|
|
149
|
+
return {
|
|
150
|
+
accessToken: token,
|
|
151
|
+
expiresAt: Math.min(t + secs * 1000, t + MAX_WIF_TOKEN_LIFETIME_MS),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -1196,7 +1196,10 @@ var DURABLE_CODES = {
|
|
|
1196
1196
|
// ---- api executor enrollment start, POST ROUTES.exec_enroll (C04-R02, R03; wave-0 fix 3b) ----
|
|
1197
1197
|
// Names kept verbatim from C04-R03. A machine principal keeps 403 machine_principal_refused
|
|
1198
1198
|
// (C04-R02); a non-starter approver gets durable_approval_not_eligible (ruling 1.13). Device-poll
|
|
1199
|
-
// errors are not codes here: see ENROLL_POLL_ERRORS.
|
|
1199
|
+
// errors are not codes here: see ENROLL_POLL_ERRORS. Ruling 34.03.4: a host start naming an org_id
|
|
1200
|
+
// the caller is not a member of is also durable_approval_not_eligible (403, no approval row). A
|
|
1201
|
+
// malformed or refused org_id is the api's plain 400 invalid_scope, which is not a durable code;
|
|
1202
|
+
// an api from before 34.03.4 answers it to any org_id on a host start (34.03.2 (1)).
|
|
1200
1203
|
/** The caller lacks the entitlement durable.locked. */
|
|
1201
1204
|
not_entitled: { status: 403, surfaces: ["api"], fields: [] },
|
|
1202
1205
|
/** The declared kind is not in durable.executors (M1 allows 'host' only). */
|
|
@@ -1643,8 +1646,8 @@ var M1_CLI_SURFACE = Object.freeze([
|
|
|
1643
1646
|
entry(["agent", "done"], ["--json"]),
|
|
1644
1647
|
// BACKBONE C2 (`mnemom agent host` replaces `mnemom host`, amendment 2; design-v3 row 7).
|
|
1645
1648
|
entry(["agent", "host"]),
|
|
1646
|
-
// BACKBONE C2 enroll (device step).
|
|
1647
|
-
entry(["agent", "host", "enroll"]),
|
|
1649
|
+
// BACKBONE C2 enroll (device step); --org: ruling 34.03.4 (a host joins an org its user belongs to).
|
|
1650
|
+
entry(["agent", "host", "enroll"], ["--org"]),
|
|
1648
1651
|
// BACKBONE C2 install/status/uninstall; --json: C04 (`mnemom agent host install --json`),
|
|
1649
1652
|
// ruling 32.31.
|
|
1650
1653
|
entry(["agent", "host", "install"], ["--json"]),
|
|
@@ -36,8 +36,8 @@ export const M1_CLI_SURFACE = Object.freeze([
|
|
|
36
36
|
entry(["agent", "done"], ["--json"]),
|
|
37
37
|
// BACKBONE C2 (`mnemom agent host` replaces `mnemom host`, amendment 2; design-v3 row 7).
|
|
38
38
|
entry(["agent", "host"]),
|
|
39
|
-
// BACKBONE C2 enroll (device step).
|
|
40
|
-
entry(["agent", "host", "enroll"]),
|
|
39
|
+
// BACKBONE C2 enroll (device step); --org: ruling 34.03.4 (a host joins an org its user belongs to).
|
|
40
|
+
entry(["agent", "host", "enroll"], ["--org"]),
|
|
41
41
|
// BACKBONE C2 install/status/uninstall; --json: C04 (`mnemom agent host install --json`),
|
|
42
42
|
// ruling 32.31.
|
|
43
43
|
entry(["agent", "host", "install"], ["--json"]),
|
|
@@ -157,7 +157,10 @@ export const DURABLE_CODES = {
|
|
|
157
157
|
// ---- api executor enrollment start, POST ROUTES.exec_enroll (C04-R02, R03; wave-0 fix 3b) ----
|
|
158
158
|
// Names kept verbatim from C04-R03. A machine principal keeps 403 machine_principal_refused
|
|
159
159
|
// (C04-R02); a non-starter approver gets durable_approval_not_eligible (ruling 1.13). Device-poll
|
|
160
|
-
// errors are not codes here: see ENROLL_POLL_ERRORS.
|
|
160
|
+
// errors are not codes here: see ENROLL_POLL_ERRORS. Ruling 34.03.4: a host start naming an org_id
|
|
161
|
+
// the caller is not a member of is also durable_approval_not_eligible (403, no approval row). A
|
|
162
|
+
// malformed or refused org_id is the api's plain 400 invalid_scope, which is not a durable code;
|
|
163
|
+
// an api from before 34.03.4 answers it to any org_id on a host start (34.03.2 (1)).
|
|
161
164
|
/** The caller lacks the entitlement durable.locked. */
|
|
162
165
|
not_entitled: { status: 403, surfaces: ["api"], fields: [] },
|
|
163
166
|
/** The declared kind is not in durable.executors (M1 allows 'host' only). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mnemom/mnemom",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.38-next.0",
|
|
4
4
|
"description": "Transparent AI agent tracing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"test": "vitest"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@mnemom/aip-verifier": "file:vendor/mnemom-aip-verifier-0.6.0.tgz",
|
|
22
21
|
"@mnemom/policy-engine": "^0.3.0",
|
|
22
|
+
"@mnemom/verify": "0.6.2",
|
|
23
23
|
"chalk": "^5.3.0",
|
|
24
24
|
"commander": "^12.0.0",
|
|
25
25
|
"js-yaml": "^4.3.2",
|
|
@@ -34,9 +34,6 @@
|
|
|
34
34
|
"typescript": "^6.0.3",
|
|
35
35
|
"vitest": "^4.1.12"
|
|
36
36
|
},
|
|
37
|
-
"bundleDependencies": [
|
|
38
|
-
"@mnemom/aip-verifier"
|
|
39
|
-
],
|
|
40
37
|
"files": [
|
|
41
38
|
"dist",
|
|
42
39
|
"!dist/__tests__",
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding any notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
Copyright 2026 Mnemon
|
|
179
|
-
|
|
180
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
-
you may not use this file except in compliance with the License.
|
|
182
|
-
You may obtain a copy of the License at
|
|
183
|
-
|
|
184
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
-
|
|
186
|
-
Unless required by applicable law or agreed to in writing, software
|
|
187
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
-
See the License for the specific language governing permissions and
|
|
190
|
-
limitations under the License.
|