@remembrance-ai/mcp-server 0.2.13 → 0.2.14
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/server.js +1046 -509
- package/package.json +2 -2
- package/server.json +2 -2
package/dist/server.js
CHANGED
|
@@ -4820,8 +4820,8 @@ function parseSurfaceReleases(value) {
|
|
|
4820
4820
|
);
|
|
4821
4821
|
}
|
|
4822
4822
|
function isCanonicalIsoTimestamp(value) {
|
|
4823
|
-
const
|
|
4824
|
-
return Number.isFinite(
|
|
4823
|
+
const timestamp3 = Date.parse(value);
|
|
4824
|
+
return Number.isFinite(timestamp3) && new Date(timestamp3).toISOString() === value;
|
|
4825
4825
|
}
|
|
4826
4826
|
|
|
4827
4827
|
// ../core/src/client-health-alerts.ts
|
|
@@ -5438,18 +5438,18 @@ function issueCodes(value) {
|
|
|
5438
5438
|
)
|
|
5439
5439
|
].sort();
|
|
5440
5440
|
}
|
|
5441
|
-
function pass(
|
|
5442
|
-
return { id, status: "pass", summary, remediation: null };
|
|
5441
|
+
function pass(id2, summary) {
|
|
5442
|
+
return { id: id2, status: "pass", summary, remediation: null };
|
|
5443
5443
|
}
|
|
5444
|
-
function info(
|
|
5445
|
-
return { id, status: "info", summary, remediation: null };
|
|
5444
|
+
function info(id2, summary) {
|
|
5445
|
+
return { id: id2, status: "info", summary, remediation: null };
|
|
5446
5446
|
}
|
|
5447
|
-
function notApplicable(
|
|
5448
|
-
return { id, status: "not_applicable", summary, remediation: null };
|
|
5447
|
+
function notApplicable(id2, summary) {
|
|
5448
|
+
return { id: id2, status: "not_applicable", summary, remediation: null };
|
|
5449
5449
|
}
|
|
5450
|
-
function warning(
|
|
5450
|
+
function warning(id2, summary, code, action, issueCodesValue, automatic = false, command) {
|
|
5451
5451
|
return {
|
|
5452
|
-
id,
|
|
5452
|
+
id: id2,
|
|
5453
5453
|
status: "warning",
|
|
5454
5454
|
summary,
|
|
5455
5455
|
...issueCodesValue && issueCodesValue.length > 0 ? { issue_codes: issueCodesValue } : {},
|
|
@@ -5461,9 +5461,9 @@ function warning(id, summary, code, action, issueCodesValue, automatic = false,
|
|
|
5461
5461
|
}
|
|
5462
5462
|
};
|
|
5463
5463
|
}
|
|
5464
|
-
function fail(
|
|
5464
|
+
function fail(id2, summary, code, action, command) {
|
|
5465
5465
|
return {
|
|
5466
|
-
id,
|
|
5466
|
+
id: id2,
|
|
5467
5467
|
status: "fail",
|
|
5468
5468
|
summary,
|
|
5469
5469
|
remediation: {
|
|
@@ -8447,21 +8447,21 @@ function privateLessonLegacyLimitPolicyDigest(input) {
|
|
|
8447
8447
|
});
|
|
8448
8448
|
}
|
|
8449
8449
|
var profileQueryValue = (profile) => `${profile.redaction_version}:${profile.redactor_digest}`;
|
|
8450
|
-
function privateLessonPolicyQuery(
|
|
8450
|
+
function privateLessonPolicyQuery(request2) {
|
|
8451
8451
|
const params = new URLSearchParams();
|
|
8452
|
-
for (const profile of
|
|
8452
|
+
for (const profile of request2.supported_redactor_profiles ?? []) {
|
|
8453
8453
|
params.append("supported_redactor_profile", profileQueryValue(profile));
|
|
8454
8454
|
}
|
|
8455
|
-
if (
|
|
8455
|
+
if (request2.required_redactor_profile) {
|
|
8456
8456
|
params.set(
|
|
8457
8457
|
"required_redactor_profile",
|
|
8458
|
-
profileQueryValue(
|
|
8458
|
+
profileQueryValue(request2.required_redactor_profile)
|
|
8459
8459
|
);
|
|
8460
8460
|
}
|
|
8461
|
-
if (
|
|
8461
|
+
if (request2.supported_max_payload_bytes !== void 0) {
|
|
8462
8462
|
params.set(
|
|
8463
8463
|
"supported_max_payload_bytes",
|
|
8464
|
-
String(
|
|
8464
|
+
String(request2.supported_max_payload_bytes)
|
|
8465
8465
|
);
|
|
8466
8466
|
}
|
|
8467
8467
|
return params.toString();
|
|
@@ -8473,16 +8473,16 @@ function privateLessonSignaturePayload(purpose, canonicalPayload) {
|
|
|
8473
8473
|
payload: canonicalPayload
|
|
8474
8474
|
});
|
|
8475
8475
|
}
|
|
8476
|
-
function assertPlatformEnvelopeSignature(
|
|
8477
|
-
const canonical = canonicalJson(
|
|
8478
|
-
if (canonical !==
|
|
8476
|
+
function assertPlatformEnvelopeSignature(envelope2, purpose, keySet, subject) {
|
|
8477
|
+
const canonical = canonicalJson(envelope2.payload);
|
|
8478
|
+
if (canonical !== envelope2.canonical_payload) {
|
|
8479
8479
|
throw new Error(`${subject} signed payload is not canonical.`);
|
|
8480
8480
|
}
|
|
8481
8481
|
const keys = privateLessonVerificationKeySetSchema.parse(keySet);
|
|
8482
|
-
const jwk = keys.keys.find((key) => key.kid ===
|
|
8482
|
+
const jwk = keys.keys.find((key) => key.kid === envelope2.key_id);
|
|
8483
8483
|
if (!jwk) {
|
|
8484
8484
|
throw new Error(
|
|
8485
|
-
`${subject} verification key is unavailable: ${
|
|
8485
|
+
`${subject} verification key is unavailable: ${envelope2.key_id}`
|
|
8486
8486
|
);
|
|
8487
8487
|
}
|
|
8488
8488
|
const signatureValid = verify(
|
|
@@ -8492,23 +8492,23 @@ function assertPlatformEnvelopeSignature(envelope, purpose, keySet, subject) {
|
|
|
8492
8492
|
key: { kty: "OKP", crv: "Ed25519", x: jwk.x },
|
|
8493
8493
|
format: "jwk"
|
|
8494
8494
|
}),
|
|
8495
|
-
Buffer.from(
|
|
8495
|
+
Buffer.from(envelope2.signature, "base64url")
|
|
8496
8496
|
);
|
|
8497
8497
|
if (!signatureValid) {
|
|
8498
8498
|
throw new Error(`${subject} signature is invalid.`);
|
|
8499
8499
|
}
|
|
8500
8500
|
}
|
|
8501
8501
|
function verifyPrivateSkillCapabilityEnvelope(args) {
|
|
8502
|
-
const
|
|
8502
|
+
const envelope2 = signedPrivateSkillCapabilitySchema.parse(args.envelope);
|
|
8503
8503
|
assertPlatformEnvelopeSignature(
|
|
8504
|
-
|
|
8504
|
+
envelope2,
|
|
8505
8505
|
"remembrance-private-skill-capability",
|
|
8506
8506
|
args.keySet,
|
|
8507
8507
|
"Private skill capability"
|
|
8508
8508
|
);
|
|
8509
8509
|
const now = (args.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
8510
|
-
const issuedAt = Date.parse(
|
|
8511
|
-
const expiresAt = Date.parse(
|
|
8510
|
+
const issuedAt = Date.parse(envelope2.payload.issued_at);
|
|
8511
|
+
const expiresAt = Date.parse(envelope2.payload.expires_at);
|
|
8512
8512
|
if (expiresAt <= issuedAt) {
|
|
8513
8513
|
throw new Error("Private skill capability validity window is invalid.");
|
|
8514
8514
|
}
|
|
@@ -8521,7 +8521,7 @@ function verifyPrivateSkillCapabilityEnvelope(args) {
|
|
|
8521
8521
|
if (issuedAt > now + PRIVATE_SKILL_CAPABILITY_CLOCK_SKEW_MS) {
|
|
8522
8522
|
throw new Error("Private skill capability is not active yet.");
|
|
8523
8523
|
}
|
|
8524
|
-
return
|
|
8524
|
+
return envelope2;
|
|
8525
8525
|
}
|
|
8526
8526
|
function verifyPrivateLessonSignedEnvelope(args) {
|
|
8527
8527
|
if (args.kind !== "policy" && args.policyFloor !== void 0) {
|
|
@@ -8534,15 +8534,15 @@ function verifyPrivateLessonSignedEnvelope(args) {
|
|
|
8534
8534
|
privateLessonRedactorProfile(profile.version, profile.digest);
|
|
8535
8535
|
}
|
|
8536
8536
|
const schema = args.kind === "policy" ? signedPrivateLessonPolicySchema : args.kind === "receipt" ? signedPrivateLessonReceiptSchema : signedPrivateLessonHoldReceiptSchema;
|
|
8537
|
-
const
|
|
8537
|
+
const envelope2 = schema.parse(args.envelope);
|
|
8538
8538
|
assertPlatformEnvelopeSignature(
|
|
8539
|
-
|
|
8539
|
+
envelope2,
|
|
8540
8540
|
args.kind === "policy" ? "remembrance-private-lesson-policy" : args.kind === "receipt" ? "remembrance-private-lesson-receipt" : "remembrance-private-lesson-hold-receipt",
|
|
8541
8541
|
args.keySet,
|
|
8542
8542
|
"Private lesson"
|
|
8543
8543
|
);
|
|
8544
8544
|
if (args.kind === "policy") {
|
|
8545
|
-
const policy =
|
|
8545
|
+
const policy = envelope2;
|
|
8546
8546
|
privateLessonRedactorProfile(
|
|
8547
8547
|
policy.payload.redaction_version,
|
|
8548
8548
|
policy.payload.redactor_digest
|
|
@@ -8572,21 +8572,21 @@ function verifyPrivateLessonSignedEnvelope(args) {
|
|
|
8572
8572
|
}
|
|
8573
8573
|
} else {
|
|
8574
8574
|
privateLessonRedactorProfile(
|
|
8575
|
-
|
|
8576
|
-
|
|
8575
|
+
envelope2.payload.redaction_version,
|
|
8576
|
+
envelope2.payload.redactor_digest
|
|
8577
8577
|
);
|
|
8578
8578
|
}
|
|
8579
|
-
return
|
|
8579
|
+
return envelope2;
|
|
8580
8580
|
}
|
|
8581
8581
|
function privateLessonSignedEnvelopeProfileFields(input) {
|
|
8582
8582
|
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
8583
8583
|
return { version: void 0, digest: void 0 };
|
|
8584
8584
|
}
|
|
8585
|
-
const
|
|
8586
|
-
if (!
|
|
8585
|
+
const envelope2 = input;
|
|
8586
|
+
if (!envelope2.payload || typeof envelope2.payload !== "object" || Array.isArray(envelope2.payload)) {
|
|
8587
8587
|
return { version: void 0, digest: void 0 };
|
|
8588
8588
|
}
|
|
8589
|
-
const payload =
|
|
8589
|
+
const payload = envelope2.payload;
|
|
8590
8590
|
return {
|
|
8591
8591
|
version: payload.redaction_version,
|
|
8592
8592
|
digest: payload.redactor_digest
|
|
@@ -11127,7 +11127,7 @@ function analyzeStructuredPrivateKeys(graph, mark, markRange, metrics) {
|
|
|
11127
11127
|
metrics
|
|
11128
11128
|
);
|
|
11129
11129
|
const markerEvents = [...exactEvents, ...fragmentedEvents].map(
|
|
11130
|
-
(event,
|
|
11130
|
+
(event, id2) => ({ ...event, id: id2 })
|
|
11131
11131
|
);
|
|
11132
11132
|
const hasStructuredMarker = markerEvents.length > 0;
|
|
11133
11133
|
const markerTokenIds = /* @__PURE__ */ new Set();
|
|
@@ -15081,7 +15081,7 @@ function recordRawCompleteSourceFrames(tokens, assessment, metrics) {
|
|
|
15081
15081
|
const tokenIds = tokens.slice(first, last + 1).map((token) => token.id);
|
|
15082
15082
|
const existing = byFirst.get(tokenIds[0]) ?? [];
|
|
15083
15083
|
if (existing.some(
|
|
15084
|
-
(frame) => frame.claim.encoding === claim.encoding && frame.claim.bitOffset === claim.bitOffset && frame.tokenIds.length === tokenIds.length && frame.tokenIds.every((
|
|
15084
|
+
(frame) => frame.claim.encoding === claim.encoding && frame.claim.bitOffset === claim.bitOffset && frame.tokenIds.length === tokenIds.length && frame.tokenIds.every((id2, index) => id2 === tokenIds[index])
|
|
15085
15085
|
))
|
|
15086
15086
|
continue;
|
|
15087
15087
|
existing.push({
|
|
@@ -15127,7 +15127,7 @@ function rawCompleteClaimsForTokens(tokens, metrics) {
|
|
|
15127
15127
|
for (const [index, token] of tokens.entries()) {
|
|
15128
15128
|
for (const frame of byFirst.get(token.id) ?? []) {
|
|
15129
15129
|
metrics.ownershipSteps += frame.tokenIds.length;
|
|
15130
|
-
if (frame.tokenIds.every((
|
|
15130
|
+
if (frame.tokenIds.every((id2, next) => tokens[index + next]?.id === id2)) {
|
|
15131
15131
|
claims.push({
|
|
15132
15132
|
...frame.claim,
|
|
15133
15133
|
start: offset,
|
|
@@ -17067,9 +17067,9 @@ function structuredMixedEncodedTokenStreams(graph, metrics) {
|
|
|
17067
17067
|
if (propertyTokenIds.size === 0 && semanticPropertyTokenIds.size === 0)
|
|
17068
17068
|
return [];
|
|
17069
17069
|
const pairedPropertyTokenIds = /* @__PURE__ */ new Set();
|
|
17070
|
-
for (const
|
|
17070
|
+
for (const id2 of propertyTokenIds) {
|
|
17071
17071
|
metrics.encodedTokensVisited += 1;
|
|
17072
|
-
if (graph.tokens[
|
|
17072
|
+
if (graph.tokens[id2].edge.valueToken) pairedPropertyTokenIds.add(id2);
|
|
17073
17073
|
}
|
|
17074
17074
|
const projections = [
|
|
17075
17075
|
...pairedPropertyTokenIds.size > 0 ? [
|
|
@@ -18840,10 +18840,10 @@ function rsaPrivateExponentRecoversFactor2(modulus, exponent, privateExponent, m
|
|
|
18840
18840
|
}
|
|
18841
18841
|
var rsaArithmeticMeters = /* @__PURE__ */ new WeakMap();
|
|
18842
18842
|
function rsaArithmeticMeter(metrics, modulus) {
|
|
18843
|
-
const
|
|
18844
|
-
let meter = rsaArithmeticMeters.get(
|
|
18843
|
+
const request2 = currentRedactionRequest();
|
|
18844
|
+
let meter = rsaArithmeticMeters.get(request2 ?? metrics);
|
|
18845
18845
|
if (!meter) {
|
|
18846
|
-
const limit =
|
|
18846
|
+
const limit = request2 ? MAX_REQUEST_RSA_ARITHMETIC_WORK : MAX_RSA_ARITHMETIC_WORK;
|
|
18847
18847
|
let spent = 0;
|
|
18848
18848
|
meter = {
|
|
18849
18849
|
weight: 0,
|
|
@@ -18870,7 +18870,7 @@ function rsaArithmeticMeter(metrics, modulus) {
|
|
|
18870
18870
|
this.analysis.rsaExponentProofCacheHits = hits;
|
|
18871
18871
|
}
|
|
18872
18872
|
};
|
|
18873
|
-
rsaArithmeticMeters.set(
|
|
18873
|
+
rsaArithmeticMeters.set(request2 ?? metrics, meter);
|
|
18874
18874
|
}
|
|
18875
18875
|
meter.analysis = metrics;
|
|
18876
18876
|
meter.weight = 2 * (Math.ceil(modulus.toString(16).length / 16) + 16) ** 2;
|
|
@@ -19389,8 +19389,8 @@ function pairMarkerEvents(begins, ends, metrics) {
|
|
|
19389
19389
|
function buildEnvelopeCandidateIndex(componentGraph, runsByContainer, metrics) {
|
|
19390
19390
|
const summaries = Array.from(
|
|
19391
19391
|
{ length: componentGraph.components.length },
|
|
19392
|
-
(_,
|
|
19393
|
-
id,
|
|
19392
|
+
(_, id2) => ({
|
|
19393
|
+
id: id2,
|
|
19394
19394
|
directTokens: [],
|
|
19395
19395
|
directRuns: [],
|
|
19396
19396
|
childSummaries: [],
|
|
@@ -23236,16 +23236,16 @@ function remembranceMcpFailureRetryable(status) {
|
|
|
23236
23236
|
if (status === 408 || status === 425 || status === 429) return true;
|
|
23237
23237
|
return status >= 500 && status <= 599;
|
|
23238
23238
|
}
|
|
23239
|
-
function remembranceMcpFailureDelivery(
|
|
23240
|
-
if (!isRecord2(
|
|
23241
|
-
if (
|
|
23242
|
-
if (bodyField(
|
|
23239
|
+
function remembranceMcpFailureDelivery(envelope2, operation) {
|
|
23240
|
+
if (!isRecord2(envelope2)) return UNKNOWN_DELIVERY;
|
|
23241
|
+
if (envelope2.redirect_rejected === true) return UNKNOWN_DELIVERY;
|
|
23242
|
+
if (bodyField(envelope2, "delivery") === REMEMBRANCE_API_NOT_DELIVERED_DECLARATION) {
|
|
23243
23243
|
return { delivery: "not_delivered", basis: "server_delivery_declaration" };
|
|
23244
23244
|
}
|
|
23245
|
-
if (typeof
|
|
23245
|
+
if (typeof envelope2.status === "number" && isRemembranceDocumentedPreWriteRefusal(
|
|
23246
23246
|
operation,
|
|
23247
|
-
|
|
23248
|
-
bodyField(
|
|
23247
|
+
envelope2.status,
|
|
23248
|
+
bodyField(envelope2, "code")
|
|
23249
23249
|
)) {
|
|
23250
23250
|
return { delivery: "not_delivered", basis: "documented_refusal_code" };
|
|
23251
23251
|
}
|
|
@@ -23271,26 +23271,26 @@ function statusClassCode(status) {
|
|
|
23271
23271
|
if (status >= 300 && status < 400) return "remembrance_api_redirect_refused";
|
|
23272
23272
|
return "remembrance_api_request_failed";
|
|
23273
23273
|
}
|
|
23274
|
-
function bodyField(
|
|
23275
|
-
const body =
|
|
23274
|
+
function bodyField(envelope2, key) {
|
|
23275
|
+
const body = envelope2.body;
|
|
23276
23276
|
if (!isRecord2(body)) return void 0;
|
|
23277
23277
|
if (body[key] !== void 0) return body[key];
|
|
23278
23278
|
const details = body.details;
|
|
23279
23279
|
return isRecord2(details) ? details[key] : void 0;
|
|
23280
23280
|
}
|
|
23281
|
-
function sanitizedFailureCode(
|
|
23282
|
-
const candidate = bodyField(
|
|
23281
|
+
function sanitizedFailureCode(envelope2) {
|
|
23282
|
+
const candidate = bodyField(envelope2, "code");
|
|
23283
23283
|
if (typeof candidate === "string" && SAFE_FAILURE_CODE.test(candidate)) {
|
|
23284
23284
|
return candidate;
|
|
23285
23285
|
}
|
|
23286
|
-
const status =
|
|
23287
|
-
if (
|
|
23286
|
+
const status = envelope2.status;
|
|
23287
|
+
if (envelope2.redirect_rejected === true && status >= 200) {
|
|
23288
23288
|
return "remembrance_api_redirect_refused";
|
|
23289
23289
|
}
|
|
23290
23290
|
return statusClassCode(status);
|
|
23291
23291
|
}
|
|
23292
|
-
function retryAfterSeconds(
|
|
23293
|
-
const raw =
|
|
23292
|
+
function retryAfterSeconds(envelope2) {
|
|
23293
|
+
const raw = envelope2.retry_after;
|
|
23294
23294
|
const seconds = typeof raw === "string" ? Number(raw) : raw;
|
|
23295
23295
|
return typeof seconds === "number" && Number.isFinite(seconds) && seconds >= 0 && seconds <= 86400 ? Math.trunc(seconds) : null;
|
|
23296
23296
|
}
|
|
@@ -23696,8 +23696,8 @@ function shapeRemembranceQueryResultForAgents(result) {
|
|
|
23696
23696
|
return body === result.body ? result : { ...result, body };
|
|
23697
23697
|
}
|
|
23698
23698
|
function remembranceMcpToolCallResult(result, toolName) {
|
|
23699
|
-
const
|
|
23700
|
-
if (!
|
|
23699
|
+
const failure2 = remembranceMcpToolFailure(result, toolName);
|
|
23700
|
+
if (!failure2) {
|
|
23701
23701
|
const shaped = toolName === "query_skills" ? shapeRemembranceQueryResultForAgents(result) : result;
|
|
23702
23702
|
return { content: [{ type: "text", text: JSON.stringify(shaped) }] };
|
|
23703
23703
|
}
|
|
@@ -23707,7 +23707,7 @@ function remembranceMcpToolCallResult(result, toolName) {
|
|
|
23707
23707
|
type: "text",
|
|
23708
23708
|
text: JSON.stringify({
|
|
23709
23709
|
...result,
|
|
23710
|
-
tool_error:
|
|
23710
|
+
tool_error: failure2
|
|
23711
23711
|
})
|
|
23712
23712
|
}
|
|
23713
23713
|
],
|
|
@@ -23767,13 +23767,13 @@ var organizationSkillHandoffBundleSchema = external_exports.object({
|
|
|
23767
23767
|
}
|
|
23768
23768
|
});
|
|
23769
23769
|
function buildOrganizationSkillHandoffBundle(input, createdAt = /* @__PURE__ */ new Date()) {
|
|
23770
|
-
const
|
|
23770
|
+
const request2 = organizationSkillHandoffRequestSchema.parse(input);
|
|
23771
23771
|
const fingerprint = createIdempotencyKey({
|
|
23772
23772
|
kind: ORGANIZATION_SKILL_HANDOFF_KIND,
|
|
23773
|
-
idempotency_key:
|
|
23774
|
-
source_runtime:
|
|
23775
|
-
handoff_reason:
|
|
23776
|
-
skills:
|
|
23773
|
+
idempotency_key: request2.idempotency_key ?? null,
|
|
23774
|
+
source_runtime: request2.source_runtime,
|
|
23775
|
+
handoff_reason: request2.handoff_reason,
|
|
23776
|
+
skills: request2.skills
|
|
23777
23777
|
});
|
|
23778
23778
|
return organizationSkillHandoffBundleSchema.parse({
|
|
23779
23779
|
schema_version: ORGANIZATION_SKILL_HANDOFF_SCHEMA_VERSION,
|
|
@@ -23781,9 +23781,9 @@ function buildOrganizationSkillHandoffBundle(input, createdAt = /* @__PURE__ */
|
|
|
23781
23781
|
bundle_id: `handoff_${fingerprint.slice(0, 24)}`,
|
|
23782
23782
|
created_at: createdAt.toISOString(),
|
|
23783
23783
|
destination: "active_organization_private_review",
|
|
23784
|
-
source_runtime:
|
|
23785
|
-
handoff_reason:
|
|
23786
|
-
skills:
|
|
23784
|
+
source_runtime: request2.source_runtime,
|
|
23785
|
+
handoff_reason: request2.handoff_reason,
|
|
23786
|
+
skills: request2.skills
|
|
23787
23787
|
});
|
|
23788
23788
|
}
|
|
23789
23789
|
|
|
@@ -23858,7 +23858,8 @@ var remembrance_mcp_consent_lanes_default = {
|
|
|
23858
23858
|
submit_suggestion: "skill_suggestion",
|
|
23859
23859
|
submit_resource: "resource_submission",
|
|
23860
23860
|
submit_resource_review: "resource_review",
|
|
23861
|
-
repair_review_draft: "admin_review_repair"
|
|
23861
|
+
repair_review_draft: "admin_review_repair",
|
|
23862
|
+
admin_write: "admin_control"
|
|
23862
23863
|
};
|
|
23863
23864
|
|
|
23864
23865
|
// ../core/src/remembrance-mcp-policy.ts
|
|
@@ -23903,6 +23904,18 @@ var REMEMBRANCE_MCP_OPTIONAL_ADMIN_REVIEW_TOOLS = Object.freeze([
|
|
|
23903
23904
|
"get_review_comparison",
|
|
23904
23905
|
"repair_review_draft"
|
|
23905
23906
|
]);
|
|
23907
|
+
var REMEMBRANCE_MCP_HOSTED_ADMIN_CONTROL_TOOLS = Object.freeze([
|
|
23908
|
+
"get_admin_capabilities",
|
|
23909
|
+
"admin_read",
|
|
23910
|
+
"admin_write"
|
|
23911
|
+
]);
|
|
23912
|
+
var REMEMBRANCE_MCP_ADMIN_CONTROL_TOOLS = Object.freeze([
|
|
23913
|
+
...REMEMBRANCE_MCP_HOSTED_ADMIN_CONTROL_TOOLS,
|
|
23914
|
+
"begin_admin_login",
|
|
23915
|
+
"complete_admin_login",
|
|
23916
|
+
"get_admin_session",
|
|
23917
|
+
"end_admin_session"
|
|
23918
|
+
]);
|
|
23906
23919
|
var REMEMBRANCE_MCP_LOCAL_ONLY_TOOLS = Object.freeze([
|
|
23907
23920
|
"bootstrap_agent_identity",
|
|
23908
23921
|
"acknowledge_feedback_denial",
|
|
@@ -23943,6 +23956,7 @@ var REMEMBRANCE_MCP_ALL_TOOLS = Object.freeze([
|
|
|
23943
23956
|
...REMEMBRANCE_MCP_RECOMMENDED_ORG_TOOLS,
|
|
23944
23957
|
...REMEMBRANCE_MCP_OPTIONAL_SHARED_CONTRIBUTION_TOOLS,
|
|
23945
23958
|
...REMEMBRANCE_MCP_OPTIONAL_ADMIN_REVIEW_TOOLS,
|
|
23959
|
+
...REMEMBRANCE_MCP_ADMIN_CONTROL_TOOLS,
|
|
23946
23960
|
...REMEMBRANCE_MCP_LOCAL_ONLY_TOOLS
|
|
23947
23961
|
]);
|
|
23948
23962
|
var REMEMBRANCE_MCP_BOUNDED_WRITE_POLICY_MAX_BYTES_BY_PAYLOAD_CLASS = Object.freeze({
|
|
@@ -23950,6 +23964,9 @@ var REMEMBRANCE_MCP_BOUNDED_WRITE_POLICY_MAX_BYTES_BY_PAYLOAD_CLASS = Object.fre
|
|
|
23950
23964
|
bounded_metadata: 384 * 1024
|
|
23951
23965
|
});
|
|
23952
23966
|
var REMEMBRANCE_MCP_BOUNDED_WRITE_MAX_BYTES_BY_TOOL = Object.freeze({
|
|
23967
|
+
begin_admin_login: 1026,
|
|
23968
|
+
complete_admin_login: 1026,
|
|
23969
|
+
end_admin_session: 1026,
|
|
23953
23970
|
invoke_skill: 354323,
|
|
23954
23971
|
record_preference: 13443,
|
|
23955
23972
|
submit_preference_compatibility_feedback: 5487,
|
|
@@ -24026,6 +24043,13 @@ function freezeMcpToolSecurityManifest(manifest) {
|
|
|
24026
24043
|
return Object.freeze(manifest);
|
|
24027
24044
|
}
|
|
24028
24045
|
var REMEMBRANCE_MCP_TOOL_SECURITY = freezeMcpToolSecurityManifest({
|
|
24046
|
+
get_admin_capabilities: read(),
|
|
24047
|
+
admin_read: read(),
|
|
24048
|
+
admin_write: content("admin_write", "broad_content"),
|
|
24049
|
+
begin_admin_login: bounded("bounded_metadata"),
|
|
24050
|
+
complete_admin_login: bounded("bounded_metadata"),
|
|
24051
|
+
get_admin_session: local(),
|
|
24052
|
+
end_admin_session: bounded("bounded_metadata"),
|
|
24029
24053
|
get_connection_status: read(),
|
|
24030
24054
|
run_connection_doctor: read(),
|
|
24031
24055
|
query_skills: read(),
|
|
@@ -24548,7 +24572,9 @@ var targetTypes = external_exports.enum([
|
|
|
24548
24572
|
"resource",
|
|
24549
24573
|
"resource_review",
|
|
24550
24574
|
"skill_idea",
|
|
24551
|
-
"suggestion"
|
|
24575
|
+
"suggestion",
|
|
24576
|
+
"skill_version",
|
|
24577
|
+
"verify_request"
|
|
24552
24578
|
]);
|
|
24553
24579
|
var reviewDecisionPreviewSelectorSchema = external_exports.object({
|
|
24554
24580
|
action: adminReviewActionValueSchema.nullable().default(null),
|
|
@@ -24600,13 +24626,13 @@ var consumedBaselineSchema = external_exports.object({
|
|
|
24600
24626
|
}).strict();
|
|
24601
24627
|
var reviewDecisionSnapshotSchema = external_exports.object({
|
|
24602
24628
|
schema_version: external_exports.literal("admin-review-decision-snapshot-v1"),
|
|
24603
|
-
org_id:
|
|
24629
|
+
org_id: nullableIdentifier,
|
|
24604
24630
|
public_skill_access_policy: external_exports.enum(["allow", "org_only"]),
|
|
24605
24631
|
selected_route: reviewDecisionPreviewSelectorSchema,
|
|
24606
24632
|
actor: external_exports.object({
|
|
24607
24633
|
type: identifier,
|
|
24608
24634
|
id: identifier,
|
|
24609
|
-
org_id:
|
|
24635
|
+
org_id: nullableIdentifier,
|
|
24610
24636
|
api_key_id: nullableIdentifier,
|
|
24611
24637
|
token_id: nullableIdentifier
|
|
24612
24638
|
}).strict(),
|
|
@@ -24629,7 +24655,7 @@ var reviewDecisionSnapshotSchema = external_exports.object({
|
|
|
24629
24655
|
payload_ref: nullableIdentifier,
|
|
24630
24656
|
superseded_by_submission_id: nullableIdentifier,
|
|
24631
24657
|
disposition_job_id: nullableIdentifier
|
|
24632
|
-
}).strict(),
|
|
24658
|
+
}).strict().nullable(),
|
|
24633
24659
|
private_payload: external_exports.object({
|
|
24634
24660
|
id: identifier,
|
|
24635
24661
|
updated_at: timestamp,
|
|
@@ -24657,6 +24683,14 @@ var reviewDecisionSnapshotSchema = external_exports.object({
|
|
|
24657
24683
|
target_digest: identifier,
|
|
24658
24684
|
inline_job_digest: identifier.nullable()
|
|
24659
24685
|
}).strict().optional(),
|
|
24686
|
+
public_source_binding: external_exports.object({
|
|
24687
|
+
schema_version: external_exports.literal("public-review-source-v1"),
|
|
24688
|
+
job_digest: identifier,
|
|
24689
|
+
target_digest: identifier,
|
|
24690
|
+
payload_digest: nullableIdentifier,
|
|
24691
|
+
current_skill_digest: nullableIdentifier,
|
|
24692
|
+
target_kind: external_exports.enum(["skill_version", "verification_job", "job_only"]).optional()
|
|
24693
|
+
}).strict().optional(),
|
|
24660
24694
|
current_skill: external_exports.object({
|
|
24661
24695
|
slug: identifier,
|
|
24662
24696
|
overlay: overlayRevisionSchema.nullable(),
|
|
@@ -24699,10 +24733,10 @@ var reviewReferenceComparisonSchema = external_exports.object({
|
|
|
24699
24733
|
parent_skill: reviewReferenceSkillSchema.nullable(),
|
|
24700
24734
|
current_skill: reviewReferenceSkillSchema.nullable()
|
|
24701
24735
|
}).strict();
|
|
24702
|
-
function reviewWorkflowResponseBound(tool, body,
|
|
24736
|
+
function reviewWorkflowResponseBound(tool, body, request2) {
|
|
24703
24737
|
if (tool === "get_review_comparison") {
|
|
24704
24738
|
const parsed2 = reviewReferenceComparisonSchema.safeParse(body);
|
|
24705
|
-
return parsed2.success && parsed2.data.job_id ===
|
|
24739
|
+
return parsed2.success && parsed2.data.job_id === request2.job_id;
|
|
24706
24740
|
}
|
|
24707
24741
|
if (tool !== "repair_review_draft") return false;
|
|
24708
24742
|
const parsed = external_exports.object({
|
|
@@ -24737,7 +24771,7 @@ function reviewWorkflowResponseBound(tool, body, request) {
|
|
|
24737
24771
|
}).strict().safeParse(body);
|
|
24738
24772
|
if (!parsed.success) return false;
|
|
24739
24773
|
const receipt = parsed.data;
|
|
24740
|
-
if (receipt.request_id !==
|
|
24774
|
+
if (receipt.request_id !== request2.request_id || receipt.original_job_id !== request2.job_id || receipt.replacement.job_id === receipt.original_job_id || receipt.next_action.query.job_id !== receipt.replacement.job_id) return false;
|
|
24741
24775
|
if (receipt.replayed) return receipt.verification === null && receipt.dispatch_state === "existing_persisted_job";
|
|
24742
24776
|
const verification = receipt.verification;
|
|
24743
24777
|
return verification !== null && verification.verification_job.id === receipt.replacement.job_id && verification.verification_job.status === receipt.verification_status && (verification.queue.queued ? receipt.dispatch_state === "queued" && verification.queue.queueJobId === receipt.replacement.job_id : receipt.dispatch_state === "mongo_poll_fallback" && verification.queue.queueJobId === null);
|
|
@@ -24800,6 +24834,21 @@ var privateSkillReviewRepairRequestSchema = external_exports.preprocess((value,
|
|
|
24800
24834
|
return value;
|
|
24801
24835
|
}, privateSkillReviewRepairRequest);
|
|
24802
24836
|
|
|
24837
|
+
// ../core/src/admin-control.ts
|
|
24838
|
+
var adminControlOperationNameSchema = external_exports.string().min(3).max(128).regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/);
|
|
24839
|
+
var envelope = {
|
|
24840
|
+
operation: adminControlOperationNameSchema,
|
|
24841
|
+
org_id: external_exports.string().regex(/^org_[a-f0-9]{18}$/).optional(),
|
|
24842
|
+
input: external_exports.record(external_exports.unknown())
|
|
24843
|
+
};
|
|
24844
|
+
var adminControlReadRequestSchema = external_exports.object(envelope).strict();
|
|
24845
|
+
var adminControlWriteRequestSchema = external_exports.object({
|
|
24846
|
+
...envelope,
|
|
24847
|
+
request_id: external_exports.string().regex(/^acreq_[a-f0-9]{32}$/)
|
|
24848
|
+
}).strict();
|
|
24849
|
+
var ADMIN_CONTROL_MAX_BODY_BYTES = 262144;
|
|
24850
|
+
var ADMIN_CONTROL_MAX_RESPONSE_BYTES = 1048576;
|
|
24851
|
+
|
|
24803
24852
|
// ../core/src/seed.ts
|
|
24804
24853
|
var feedbackUrl = publicSkillDeliveryDefaults().feedback_url;
|
|
24805
24854
|
var jsonItems = (values, indent) => values.map((value) => `${indent}${JSON.stringify(value)}`).join(",\n");
|
|
@@ -27510,9 +27559,9 @@ function privateSkillPermanentRefusalGuidance(draft) {
|
|
|
27510
27559
|
// src/server.ts
|
|
27511
27560
|
import { existsSync as existsSync6 } from "node:fs";
|
|
27512
27561
|
import { mkdir as mkdir5, writeFile as writeFile2 } from "node:fs/promises";
|
|
27513
|
-
import { dirname as
|
|
27562
|
+
import { dirname as dirname11 } from "node:path";
|
|
27514
27563
|
import {
|
|
27515
|
-
createHash as
|
|
27564
|
+
createHash as createHash10,
|
|
27516
27565
|
createHmac,
|
|
27517
27566
|
createPrivateKey as createPrivateKey2,
|
|
27518
27567
|
generateKeyPairSync,
|
|
@@ -29140,6 +29189,35 @@ function toolArgumentMessage(error) {
|
|
|
29140
29189
|
return error instanceof ZodError ? messages2.get(error) : void 0;
|
|
29141
29190
|
}
|
|
29142
29191
|
|
|
29192
|
+
// src/admin-control-tools.ts
|
|
29193
|
+
var ADMIN_CONTROL_TOOL_DESCRIPTIONS = {
|
|
29194
|
+
get_admin_capabilities: "Read current authorized administrative operations and their input schemas. Pass org_id to discover organization controls using a browser-approved global session. Uses a separate admin session when present, otherwise the configured organization key. Never grants query tools administrative authority. Hosted MCP requires an explicit x-remembrance-admin-token for global administration; browser login tools are local-only.",
|
|
29195
|
+
admin_read: "Execute one read-only administrative operation returned by get_admin_capabilities. Select org_id only when authorized. The server validates the exact operation input and current tenant permissions. No arbitrary URL or repository method is accepted.",
|
|
29196
|
+
admin_write: "Execute one explicitly requested administrative mutation returned by get_admin_capabilities. Requires operation-specific input and a request_id of acreq_ plus 32 lowercase hexadecimal characters. Preserve the same request_id for the same logical attempt after timeout or unknown delivery; use a new ID only for an intentionally separate action. Never retries automatically. This is not persistent approval for future writes. One-time API keys and member-link credentials are stored in a preflighted local private vault and never returned in tool output; hosted MCP refuses those operations before mutation and requires local MCP or a REST client with secure secret delivery.",
|
|
29197
|
+
begin_admin_login: "Begin a local browser-approved administrative session. Returns only a confirmation URL, public code and expiry. Open the URL and ask the administrator to compare and approve the code. Credentials stay in a separate mode-0600 local store; no browser cookie or organization key is exchanged for an admin token.",
|
|
29198
|
+
complete_admin_login: "Check a pending local admin login once after browser approval. Honors the returned polling interval; never loops or retries automatically. Stores the admin token privately and never returns it. This is a device-style PKCE exchange, not MCP HTTP OAuth conformance.",
|
|
29199
|
+
get_admin_session: "Inspect local admin login status without network access. Never returns credentials and never claims server validity was checked. Use get_admin_capabilities for a fresh authorization check.",
|
|
29200
|
+
end_admin_session: "Revoke the separate local administrative session and remove it only after confirmed revocation. A pending login is cancelled locally. Unknown revocation keeps the credential for a bounded retry; ordinary organization credentials are unchanged."
|
|
29201
|
+
};
|
|
29202
|
+
var ADMIN_CONTROL_TOOL_NAMES = Object.freeze(Object.keys(ADMIN_CONTROL_TOOL_DESCRIPTIONS));
|
|
29203
|
+
var adminSessionToolInputSchema = external_exports.object({}).strict();
|
|
29204
|
+
var adminCapabilitiesToolInputSchema = external_exports.object({ org_id: adminControlReadRequestSchema.shape.org_id }).strict();
|
|
29205
|
+
function assertAdminControlPayloadBounds(name, payload) {
|
|
29206
|
+
if (!ADMIN_CONTROL_TOOL_NAMES.includes(name)) return;
|
|
29207
|
+
let serialized;
|
|
29208
|
+
try {
|
|
29209
|
+
serialized = JSON.stringify(payload);
|
|
29210
|
+
} catch {
|
|
29211
|
+
}
|
|
29212
|
+
if (serialized === void 0 || Buffer.byteLength(serialized, "utf8") > ADMIN_CONTROL_MAX_BODY_BYTES) {
|
|
29213
|
+
throw new external_exports.ZodError([{
|
|
29214
|
+
code: external_exports.ZodIssueCode.custom,
|
|
29215
|
+
path: [],
|
|
29216
|
+
message: "Administrative arguments must be JSON-serializable and at most 262144 bytes."
|
|
29217
|
+
}]);
|
|
29218
|
+
}
|
|
29219
|
+
}
|
|
29220
|
+
|
|
29143
29221
|
// src/tool-definitions.ts
|
|
29144
29222
|
var PRIVATE_EGRESS_TOOL_LANES = Object.freeze(
|
|
29145
29223
|
Object.fromEntries(Object.entries(REMEMBRANCE_MCP_CONSENT_LANES))
|
|
@@ -29299,6 +29377,52 @@ var remembranceToolSchema = remembrancePayloadSchema.extend({
|
|
|
29299
29377
|
)
|
|
29300
29378
|
});
|
|
29301
29379
|
var declaredToolDefinitions = [
|
|
29380
|
+
readTool(
|
|
29381
|
+
"get_admin_capabilities",
|
|
29382
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.get_admin_capabilities,
|
|
29383
|
+
"/api/v1/admin/control",
|
|
29384
|
+
adminCapabilitiesToolInputSchema,
|
|
29385
|
+
"GET"
|
|
29386
|
+
),
|
|
29387
|
+
readTool(
|
|
29388
|
+
"admin_read",
|
|
29389
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.admin_read,
|
|
29390
|
+
"/api/v1/admin/control/read",
|
|
29391
|
+
adminControlReadRequestSchema
|
|
29392
|
+
),
|
|
29393
|
+
contentWriteTool(
|
|
29394
|
+
"admin_write",
|
|
29395
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.admin_write,
|
|
29396
|
+
"/api/v1/admin/control/write",
|
|
29397
|
+
adminControlWriteRequestSchema
|
|
29398
|
+
),
|
|
29399
|
+
localNetworkTool(
|
|
29400
|
+
"begin_admin_login",
|
|
29401
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.begin_admin_login,
|
|
29402
|
+
"begin_admin_login",
|
|
29403
|
+
adminSessionToolInputSchema,
|
|
29404
|
+
"bounded_write"
|
|
29405
|
+
),
|
|
29406
|
+
localNetworkTool(
|
|
29407
|
+
"complete_admin_login",
|
|
29408
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.complete_admin_login,
|
|
29409
|
+
"complete_admin_login",
|
|
29410
|
+
adminSessionToolInputSchema,
|
|
29411
|
+
"bounded_write"
|
|
29412
|
+
),
|
|
29413
|
+
localTool(
|
|
29414
|
+
"get_admin_session",
|
|
29415
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.get_admin_session,
|
|
29416
|
+
"get_admin_session",
|
|
29417
|
+
adminSessionToolInputSchema
|
|
29418
|
+
),
|
|
29419
|
+
localNetworkTool(
|
|
29420
|
+
"end_admin_session",
|
|
29421
|
+
ADMIN_CONTROL_TOOL_DESCRIPTIONS.end_admin_session,
|
|
29422
|
+
"end_admin_session",
|
|
29423
|
+
adminSessionToolInputSchema,
|
|
29424
|
+
"bounded_write"
|
|
29425
|
+
),
|
|
29302
29426
|
readTool(
|
|
29303
29427
|
"get_review_comparison",
|
|
29304
29428
|
REVIEW_COMPARISON_TOOL_DESCRIPTION,
|
|
@@ -29873,10 +29997,10 @@ function canonicalToolDefinitionForDispatch(definition) {
|
|
|
29873
29997
|
}
|
|
29874
29998
|
function parseToolArguments(definition, value) {
|
|
29875
29999
|
const runtime = canonicalRuntimeForDefinition(definition);
|
|
29876
|
-
return parseWithArgumentDiagnostics(
|
|
29877
|
-
runtime.definition.
|
|
29878
|
-
|
|
29879
|
-
);
|
|
30000
|
+
return parseWithArgumentDiagnostics(runtime.definition.inputSchema, () => {
|
|
30001
|
+
assertAdminControlPayloadBounds(runtime.definition.name, value);
|
|
30002
|
+
return runtime.parseInput(value);
|
|
30003
|
+
});
|
|
29880
30004
|
}
|
|
29881
30005
|
function parseToolNetworkArguments(definition, value) {
|
|
29882
30006
|
return canonicalRuntimeForDefinition(definition).parseNetwork(value);
|
|
@@ -30061,12 +30185,12 @@ function validateServedToolDefinition(definition) {
|
|
|
30061
30185
|
canonicalToolDefinitionForDispatch(definition);
|
|
30062
30186
|
}
|
|
30063
30187
|
function annotationsForTool(name) {
|
|
30064
|
-
const readOnly = name === "get_review_comparison" || name === "list_skills" || name === "get_effective_preferences" || name === "get_value_proof" || name === "run_connection_doctor" || name === "get_private_lesson_policy" || name === "inspect_private_lesson_outbox" || name === "inspect_private_learning_outbox" || name === "get_pending_action_payload";
|
|
30188
|
+
const readOnly = name === "get_admin_capabilities" || name === "admin_read" || name === "get_admin_session" || name === "get_review_comparison" || name === "list_skills" || name === "get_effective_preferences" || name === "get_value_proof" || name === "run_connection_doctor" || name === "get_private_lesson_policy" || name === "inspect_private_lesson_outbox" || name === "inspect_private_learning_outbox" || name === "get_pending_action_payload";
|
|
30065
30189
|
const openWorld = name === "submit_feedback" || name === "submit_remembrance" || name === "propose_skill_idea" || name === "submit_suggestion" || name === "submit_resource" || name === "submit_resource_review";
|
|
30066
30190
|
return {
|
|
30067
30191
|
readOnlyHint: readOnly,
|
|
30068
30192
|
openWorldHint: openWorld,
|
|
30069
|
-
destructiveHint: name === "delete_private_lesson_candidate" || name === "delete_private_skill_candidate",
|
|
30193
|
+
destructiveHint: name === "admin_write" || name === "end_admin_session" || name === "delete_private_lesson_candidate" || name === "delete_private_skill_candidate",
|
|
30070
30194
|
...readOnly || name === "queue_private_skill_import" || name === "acknowledge_feedback_denial" || name === "decline_pending_action" || name === "submit_private_lesson_candidate" || name === "retry_private_lesson_candidate" || name === "submit_private_skill_candidate" || name === "retry_private_skill_candidate" || name === "repair_review_draft" ? { idempotentHint: true } : {}
|
|
30071
30195
|
};
|
|
30072
30196
|
}
|
|
@@ -30348,21 +30472,21 @@ function base64urlOfLength(value, bytes) {
|
|
|
30348
30472
|
return typeof value === "string" && BASE64URL.test(value) && Buffer.from(value, "base64url").length === bytes;
|
|
30349
30473
|
}
|
|
30350
30474
|
function openResupplyEnvelope(obligation, key) {
|
|
30351
|
-
const
|
|
30475
|
+
const envelope2 = normalizeResupplyEnvelope(
|
|
30352
30476
|
obligation?.local_resupply_envelope
|
|
30353
30477
|
);
|
|
30354
|
-
if (!
|
|
30478
|
+
if (!envelope2) throw new ResupplyError("envelope_invalid");
|
|
30355
30479
|
let text;
|
|
30356
30480
|
try {
|
|
30357
30481
|
const decipher = createDecipheriv(
|
|
30358
30482
|
"aes-256-gcm",
|
|
30359
30483
|
key,
|
|
30360
|
-
Buffer.from(
|
|
30484
|
+
Buffer.from(envelope2.nonce, "base64url")
|
|
30361
30485
|
);
|
|
30362
30486
|
decipher.setAAD(envelopeAad(obligation));
|
|
30363
|
-
decipher.setAuthTag(Buffer.from(
|
|
30487
|
+
decipher.setAuthTag(Buffer.from(envelope2.auth_tag, "base64url"));
|
|
30364
30488
|
text = Buffer.concat([
|
|
30365
|
-
decipher.update(Buffer.from(
|
|
30489
|
+
decipher.update(Buffer.from(envelope2.ciphertext, "base64url")),
|
|
30366
30490
|
decipher.final()
|
|
30367
30491
|
]).toString("utf8");
|
|
30368
30492
|
} catch {
|
|
@@ -30529,25 +30653,25 @@ function withoutPayload(status, input, extra) {
|
|
|
30529
30653
|
};
|
|
30530
30654
|
}
|
|
30531
30655
|
async function readPendingActionPayload(input, env, { readKey }) {
|
|
30532
|
-
const
|
|
30656
|
+
const request2 = {
|
|
30533
30657
|
action_id: String(input?.action_id ?? ""),
|
|
30534
30658
|
ledger: String(input?.ledger ?? "")
|
|
30535
30659
|
};
|
|
30536
|
-
const notFound = withoutPayload("not_found",
|
|
30660
|
+
const notFound = withoutPayload("not_found", request2, {
|
|
30537
30661
|
guidance: "No pending action with this action_id is retained in this ledger. It may be closed, owned by another session or agent, or never recorded; do not guess its payload."
|
|
30538
30662
|
});
|
|
30539
|
-
if (!HEX16.test(
|
|
30663
|
+
if (!HEX16.test(request2.action_id) || !HEX16.test(request2.ledger)) {
|
|
30540
30664
|
return notFound;
|
|
30541
30665
|
}
|
|
30542
30666
|
let record4 = null;
|
|
30543
30667
|
for (const directory of [
|
|
30544
|
-
...retainedRootsUsable(env) ? [join(retainedLedgerRoot(env), `${
|
|
30545
|
-
join(usageDirectory(env), `${
|
|
30668
|
+
...retainedRootsUsable(env) ? [join(retainedLedgerRoot(env), `${request2.ledger}.obligations`)] : [],
|
|
30669
|
+
join(usageDirectory(env), `${request2.ledger}.obligations`)
|
|
30546
30670
|
]) {
|
|
30547
30671
|
try {
|
|
30548
30672
|
assertPrivateDirectory(directory);
|
|
30549
30673
|
for (const name of readdirSync(directory).sort().slice(0, LEDGER_ENTRY_LIMIT)) {
|
|
30550
|
-
if (!name.startsWith(
|
|
30674
|
+
if (!name.startsWith(request2.action_id) || !/^[a-f0-9]{32}\.json$/u.test(name)) {
|
|
30551
30675
|
continue;
|
|
30552
30676
|
}
|
|
30553
30677
|
try {
|
|
@@ -30583,9 +30707,9 @@ async function readPendingActionPayload(input, env, { readKey }) {
|
|
|
30583
30707
|
};
|
|
30584
30708
|
let payload = null;
|
|
30585
30709
|
if (record4.local_resupply_envelope) {
|
|
30586
|
-
const
|
|
30587
|
-
if (!
|
|
30588
|
-
return withoutPayload("refused",
|
|
30710
|
+
const envelope2 = normalizeResupplyEnvelope(record4.local_resupply_envelope);
|
|
30711
|
+
if (!envelope2) {
|
|
30712
|
+
return withoutPayload("refused", request2, {
|
|
30589
30713
|
...described,
|
|
30590
30714
|
reason: "envelope_invalid",
|
|
30591
30715
|
guidance: guidance.envelope_invalid
|
|
@@ -30593,9 +30717,9 @@ async function readPendingActionPayload(input, env, { readKey }) {
|
|
|
30593
30717
|
}
|
|
30594
30718
|
let key;
|
|
30595
30719
|
try {
|
|
30596
|
-
key = await readKey(
|
|
30720
|
+
key = await readKey(envelope2.key_source);
|
|
30597
30721
|
} catch (error) {
|
|
30598
|
-
return withoutPayload("unavailable",
|
|
30722
|
+
return withoutPayload("unavailable", request2, {
|
|
30599
30723
|
...described,
|
|
30600
30724
|
reason: localKeyReason(error),
|
|
30601
30725
|
// The outbox's own content-free recovery, when the reader gives one.
|
|
@@ -30605,11 +30729,11 @@ async function readPendingActionPayload(input, env, { readKey }) {
|
|
|
30605
30729
|
}
|
|
30606
30730
|
try {
|
|
30607
30731
|
payload = openResupplyEnvelope(
|
|
30608
|
-
{ ...record4, local_resupply_envelope:
|
|
30732
|
+
{ ...record4, local_resupply_envelope: envelope2 },
|
|
30609
30733
|
key
|
|
30610
30734
|
);
|
|
30611
30735
|
} catch (error) {
|
|
30612
|
-
return withoutPayload("refused",
|
|
30736
|
+
return withoutPayload("refused", request2, {
|
|
30613
30737
|
...described,
|
|
30614
30738
|
reason: error?.code ?? "decryption_failed",
|
|
30615
30739
|
guidance: guidance.refused
|
|
@@ -30617,7 +30741,7 @@ async function readPendingActionPayload(input, env, { readKey }) {
|
|
|
30617
30741
|
}
|
|
30618
30742
|
} else if (!preference && record4.local_resupply_payload && typeof record4.local_resupply_payload === "object" && !Array.isArray(record4.local_resupply_payload)) {
|
|
30619
30743
|
if (resupplyPayloadDigest(record4.local_resupply_payload) !== record4.payload_digest || record4.id !== `remembrance_followup:${record4.payload_digest}`) {
|
|
30620
|
-
return withoutPayload("refused",
|
|
30744
|
+
return withoutPayload("refused", request2, {
|
|
30621
30745
|
...described,
|
|
30622
30746
|
reason: "digest_mismatch",
|
|
30623
30747
|
guidance: guidance.refused
|
|
@@ -30625,7 +30749,7 @@ async function readPendingActionPayload(input, env, { readKey }) {
|
|
|
30625
30749
|
}
|
|
30626
30750
|
payload = record4.local_resupply_payload;
|
|
30627
30751
|
} else {
|
|
30628
|
-
return withoutPayload("not_retained",
|
|
30752
|
+
return withoutPayload("not_retained", request2, {
|
|
30629
30753
|
...described,
|
|
30630
30754
|
reason: record4.local_resupply_payload_omitted === "too_large" || record4.local_resupply_payload_omitted === "key_unavailable" ? record4.local_resupply_payload_omitted : "not_retained",
|
|
30631
30755
|
guidance: guidance.not_retained
|
|
@@ -30633,8 +30757,8 @@ async function readPendingActionPayload(input, env, { readKey }) {
|
|
|
30633
30757
|
}
|
|
30634
30758
|
return {
|
|
30635
30759
|
status: "retrieved",
|
|
30636
|
-
action_id:
|
|
30637
|
-
ledger:
|
|
30760
|
+
action_id: request2.action_id,
|
|
30761
|
+
ledger: request2.ledger,
|
|
30638
30762
|
...described,
|
|
30639
30763
|
payload_bytes: Buffer.byteLength(JSON.stringify(payload), "utf8"),
|
|
30640
30764
|
[preference ? "arguments" : "payload"]: payload,
|
|
@@ -30756,8 +30880,8 @@ function inventoryRetainedKeyConsumers(env, { limits = INVENTORY_LIMITS, lanes,
|
|
|
30756
30880
|
unretained.kinds.add(String(record4.kind));
|
|
30757
30881
|
}
|
|
30758
30882
|
if (record4.local_resupply_envelope == null) return;
|
|
30759
|
-
const
|
|
30760
|
-
if (!
|
|
30883
|
+
const envelope2 = normalizeResupplyEnvelope(record4.local_resupply_envelope);
|
|
30884
|
+
if (!envelope2 || !RETAINED_KINDS.has(record4.kind) || !consumer(record4.kind, envelope2.key_source)) {
|
|
30761
30885
|
leftFile(area, "unclassified");
|
|
30762
30886
|
}
|
|
30763
30887
|
};
|
|
@@ -31033,6 +31157,12 @@ function readSecureLocalText(path, options) {
|
|
|
31033
31157
|
function secureLocalFileMode(path) {
|
|
31034
31158
|
return lstatSync2(path).mode;
|
|
31035
31159
|
}
|
|
31160
|
+
function assertSecurePrivateLocalDirectory(path) {
|
|
31161
|
+
assertSecureParentDirectory(path);
|
|
31162
|
+
if (isPosix() && (lstatSync2(path).mode & 63) !== 0) {
|
|
31163
|
+
throw new Error("Local credential directory permissions are not private.");
|
|
31164
|
+
}
|
|
31165
|
+
}
|
|
31036
31166
|
function listSecureLocalDirectory(path) {
|
|
31037
31167
|
assertSecureDirectory(path);
|
|
31038
31168
|
const directory = opendirSync(path);
|
|
@@ -31656,8 +31786,8 @@ async function withCaptureLearningDiagnostics(operation) {
|
|
|
31656
31786
|
try {
|
|
31657
31787
|
return await operation();
|
|
31658
31788
|
} catch (error) {
|
|
31659
|
-
const
|
|
31660
|
-
failures.set(
|
|
31789
|
+
const failure2 = error !== null && (typeof error === "object" || typeof error === "function") ? error : new Error("Private learning capture failed.");
|
|
31790
|
+
failures.set(failure2, {
|
|
31661
31791
|
...diagnostic(context),
|
|
31662
31792
|
...preparationConstraintDiagnostic(context, error),
|
|
31663
31793
|
...error instanceof CaptureLearningReplayError ? {
|
|
@@ -31665,7 +31795,7 @@ async function withCaptureLearningDiagnostics(operation) {
|
|
|
31665
31795
|
recovery: context.replacement_of ? "Inspect the original held draft and the selected replacement. Repeat only the exact same lesson and replacement_of through its existing recovery lane; do not create an unrelated capture." : "Inspect the outcome for this capture_id. It must not be reused for a different lesson or destination, and a submitted or explicitly deleted capture is never recreated."
|
|
31666
31796
|
} : {}
|
|
31667
31797
|
});
|
|
31668
|
-
throw
|
|
31798
|
+
throw failure2;
|
|
31669
31799
|
}
|
|
31670
31800
|
});
|
|
31671
31801
|
}
|
|
@@ -32147,11 +32277,11 @@ async function retireReplacedPrivateLessonUnlocked(directory, draftId, replaceme
|
|
|
32147
32277
|
}
|
|
32148
32278
|
try {
|
|
32149
32279
|
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
32150
|
-
const
|
|
32280
|
+
const envelope2 = parseEnvelope(
|
|
32151
32281
|
await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
32152
32282
|
draftId
|
|
32153
32283
|
);
|
|
32154
|
-
if (
|
|
32284
|
+
if (envelope2.state === "submitted") return;
|
|
32155
32285
|
} catch {
|
|
32156
32286
|
return;
|
|
32157
32287
|
}
|
|
@@ -32203,7 +32333,7 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
32203
32333
|
throw new Error("Private lesson draft was already submitted.");
|
|
32204
32334
|
}
|
|
32205
32335
|
let draft;
|
|
32206
|
-
let
|
|
32336
|
+
let envelope2;
|
|
32207
32337
|
try {
|
|
32208
32338
|
const path = draftPath(outbox.directory, draftId);
|
|
32209
32339
|
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
@@ -32211,8 +32341,8 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
32211
32341
|
path,
|
|
32212
32342
|
PRIVATE_LESSON_DRAFT_MAX_BYTES
|
|
32213
32343
|
);
|
|
32214
|
-
|
|
32215
|
-
draft = await decryptDraft(
|
|
32344
|
+
envelope2 = parseEnvelope(serialized, draftId);
|
|
32345
|
+
draft = await decryptDraft(envelope2, outbox.encryption, true);
|
|
32216
32346
|
} catch (error) {
|
|
32217
32347
|
throw selectedPrivateLessonError(draftId, error);
|
|
32218
32348
|
}
|
|
@@ -32236,7 +32366,7 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
32236
32366
|
);
|
|
32237
32367
|
}
|
|
32238
32368
|
const reconciled = reconcileStoredDraft(draft, now);
|
|
32239
|
-
if (reconciled !== draft || staleSafetyRecheckHint(
|
|
32369
|
+
if (reconciled !== draft || staleSafetyRecheckHint(envelope2, reconciled)) {
|
|
32240
32370
|
await writeDraft(reconciled, outbox, true, void 0, true);
|
|
32241
32371
|
}
|
|
32242
32372
|
return reconciled;
|
|
@@ -32409,8 +32539,8 @@ async function recoverOwnerAttestedLegacyPrivateLessonDestination(input, options
|
|
|
32409
32539
|
const path = draftPath(outbox.directory, input.draft_id);
|
|
32410
32540
|
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
32411
32541
|
const serialized = await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
32412
|
-
const
|
|
32413
|
-
const current = await decryptDraft(
|
|
32542
|
+
const envelope2 = parseEnvelope(serialized, input.draft_id);
|
|
32543
|
+
const current = await decryptDraft(envelope2, outbox.encryption);
|
|
32414
32544
|
if (!ownerAttestedLegacyPrivateLessonRecoveryEligible(current) || current.payload_digest !== input.expected_payload_digest) {
|
|
32415
32545
|
throw new Error("Selected draft does not match the owner-attested legacy recovery scope.");
|
|
32416
32546
|
}
|
|
@@ -32425,8 +32555,8 @@ async function recoverOwnerAttestedLegacyPrivateLessonDestination(input, options
|
|
|
32425
32555
|
updated_at: now
|
|
32426
32556
|
};
|
|
32427
32557
|
const encryption = {
|
|
32428
|
-
key: await readPrivateLessonOutboxKey(outbox.encryption,
|
|
32429
|
-
source:
|
|
32558
|
+
key: await readPrivateLessonOutboxKey(outbox.encryption, envelope2.encryption.key_source),
|
|
32559
|
+
source: envelope2.encryption.key_source
|
|
32430
32560
|
};
|
|
32431
32561
|
if (!input.dry_run) await writeDraft(next, { ...outbox, encryption }, true);
|
|
32432
32562
|
return {
|
|
@@ -32486,11 +32616,11 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
32486
32616
|
let current;
|
|
32487
32617
|
try {
|
|
32488
32618
|
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
32489
|
-
const
|
|
32619
|
+
const envelope2 = parseEnvelope(
|
|
32490
32620
|
await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
32491
32621
|
draftId
|
|
32492
32622
|
);
|
|
32493
|
-
current = await decryptDraft(
|
|
32623
|
+
current = await decryptDraft(envelope2, outbox.encryption, true);
|
|
32494
32624
|
} catch (error) {
|
|
32495
32625
|
throw selectedPrivateLessonError(draftId, error);
|
|
32496
32626
|
}
|
|
@@ -32644,9 +32774,9 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
32644
32774
|
replacedRecords += 1;
|
|
32645
32775
|
continue;
|
|
32646
32776
|
}
|
|
32647
|
-
let
|
|
32777
|
+
let envelope2;
|
|
32648
32778
|
try {
|
|
32649
|
-
|
|
32779
|
+
envelope2 = parseEnvelope(
|
|
32650
32780
|
await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
32651
32781
|
name.slice(0, -".lesson.json".length)
|
|
32652
32782
|
);
|
|
@@ -32654,8 +32784,8 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
32654
32784
|
corruptFiles += 1;
|
|
32655
32785
|
continue;
|
|
32656
32786
|
}
|
|
32657
|
-
counts[
|
|
32658
|
-
if (
|
|
32787
|
+
counts[envelope2.state] += 1;
|
|
32788
|
+
if (envelope2.state === "superseded_redactor") {
|
|
32659
32789
|
terminalBytes += metadata.size;
|
|
32660
32790
|
try {
|
|
32661
32791
|
const draft = await readPrivateLessonDraft(
|
|
@@ -32821,7 +32951,7 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
32821
32951
|
}
|
|
32822
32952
|
continue;
|
|
32823
32953
|
}
|
|
32824
|
-
let
|
|
32954
|
+
let envelope2;
|
|
32825
32955
|
let serialized;
|
|
32826
32956
|
try {
|
|
32827
32957
|
serialized = await readPrivateLessonCanonicalText(
|
|
@@ -32837,7 +32967,7 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
32837
32967
|
continue;
|
|
32838
32968
|
}
|
|
32839
32969
|
try {
|
|
32840
|
-
|
|
32970
|
+
envelope2 = parseEnvelope(serialized, draftId);
|
|
32841
32971
|
} catch {
|
|
32842
32972
|
recoveryItems.push(
|
|
32843
32973
|
privateLessonRecoveryItem(draftId, "invalid_canonical_entry")
|
|
@@ -32845,10 +32975,10 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
32845
32975
|
corruptFiles += 1;
|
|
32846
32976
|
continue;
|
|
32847
32977
|
}
|
|
32848
|
-
counts[
|
|
32978
|
+
counts[envelope2.state] += 1;
|
|
32849
32979
|
let decrypted;
|
|
32850
32980
|
try {
|
|
32851
|
-
decrypted = await decryptDraft(
|
|
32981
|
+
decrypted = await decryptDraft(envelope2, outbox.encryption, true);
|
|
32852
32982
|
} catch (error) {
|
|
32853
32983
|
if (isPrivateOutboxKeyAccessError(error)) {
|
|
32854
32984
|
recoveryItems.push(
|
|
@@ -32871,7 +33001,7 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
32871
33001
|
decrypted
|
|
32872
33002
|
);
|
|
32873
33003
|
if (replacement) {
|
|
32874
|
-
counts[
|
|
33004
|
+
counts[envelope2.state] -= 1;
|
|
32875
33005
|
replacedRecords += 1;
|
|
32876
33006
|
await retireReplacedPrivateLessonUnlocked(
|
|
32877
33007
|
outbox.directory,
|
|
@@ -32883,8 +33013,8 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
32883
33013
|
continue;
|
|
32884
33014
|
}
|
|
32885
33015
|
const draft = reconcileStoredDraft(decrypted, now);
|
|
32886
|
-
if (draft !== decrypted || staleSafetyRecheckHint(
|
|
32887
|
-
counts[
|
|
33016
|
+
if (draft !== decrypted || staleSafetyRecheckHint(envelope2, draft)) {
|
|
33017
|
+
counts[envelope2.state] -= 1;
|
|
32888
33018
|
counts[draft.state] += 1;
|
|
32889
33019
|
await writeDraftUnlocked(draft, outbox, true, void 0, true);
|
|
32890
33020
|
}
|
|
@@ -33099,9 +33229,9 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
33099
33229
|
continue;
|
|
33100
33230
|
}
|
|
33101
33231
|
if (!name.endsWith(".lesson.json")) continue;
|
|
33102
|
-
let
|
|
33232
|
+
let envelope2;
|
|
33103
33233
|
try {
|
|
33104
|
-
|
|
33234
|
+
envelope2 = parseEnvelope(
|
|
33105
33235
|
await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
33106
33236
|
name.slice(0, -".lesson.json".length)
|
|
33107
33237
|
);
|
|
@@ -33109,8 +33239,8 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
33109
33239
|
corruptFiles += 1;
|
|
33110
33240
|
continue;
|
|
33111
33241
|
}
|
|
33112
|
-
counts[
|
|
33113
|
-
if (
|
|
33242
|
+
counts[envelope2.state] += 1;
|
|
33243
|
+
if (envelope2.state === "superseded_redactor") {
|
|
33114
33244
|
terminalBytes += entry.size;
|
|
33115
33245
|
}
|
|
33116
33246
|
}
|
|
@@ -33551,7 +33681,7 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
33551
33681
|
const cipher = createCipheriv2("aes-256-gcm", outbox.encryption.key, nonce);
|
|
33552
33682
|
cipher.setAAD(aad);
|
|
33553
33683
|
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
33554
|
-
const
|
|
33684
|
+
const envelope2 = {
|
|
33555
33685
|
version: "private-lesson-outbox-envelope-v1",
|
|
33556
33686
|
draft_id: validated.draft_id,
|
|
33557
33687
|
state: validated.state,
|
|
@@ -33572,7 +33702,7 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
33572
33702
|
auth_tag: cipher.getAuthTag().toString("base64url")
|
|
33573
33703
|
}
|
|
33574
33704
|
};
|
|
33575
|
-
const serialized = `${JSON.stringify(
|
|
33705
|
+
const serialized = `${JSON.stringify(envelope2)}
|
|
33576
33706
|
`;
|
|
33577
33707
|
const serializedBytes = Buffer.byteLength(serialized, "utf8");
|
|
33578
33708
|
if (!replace && await retainedPrivateLessonOutboxBytes(outbox.directory) + serializedBytes > outbox.ceilingBytes) {
|
|
@@ -33615,41 +33745,41 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
33615
33745
|
markCaptureLearningPersisted(validated.draft_id);
|
|
33616
33746
|
}
|
|
33617
33747
|
}
|
|
33618
|
-
async function decryptDraft(
|
|
33748
|
+
async function decryptDraft(envelope2, encryption, allowUnsupportedProfile = false) {
|
|
33619
33749
|
const aadFields = {
|
|
33620
|
-
version:
|
|
33621
|
-
draft_id:
|
|
33622
|
-
state:
|
|
33623
|
-
payload_digest:
|
|
33624
|
-
hold_telemetry_status:
|
|
33625
|
-
next_retry_at:
|
|
33626
|
-
terminal_reason:
|
|
33627
|
-
...Object.hasOwn(
|
|
33628
|
-
...Object.hasOwn(
|
|
33750
|
+
version: envelope2.version,
|
|
33751
|
+
draft_id: envelope2.draft_id,
|
|
33752
|
+
state: envelope2.state,
|
|
33753
|
+
payload_digest: envelope2.payload_digest,
|
|
33754
|
+
hold_telemetry_status: envelope2.hold_telemetry_status,
|
|
33755
|
+
next_retry_at: envelope2.next_retry_at,
|
|
33756
|
+
terminal_reason: envelope2.terminal_reason,
|
|
33757
|
+
...Object.hasOwn(envelope2, "last_error_code") ? { last_error_code: envelope2.last_error_code ?? null } : {},
|
|
33758
|
+
...Object.hasOwn(envelope2, "destination_binding") ? { destination_binding: envelope2.destination_binding ?? null } : {}
|
|
33629
33759
|
};
|
|
33630
33760
|
const aad = Buffer.from(canonicalJson(aadFields), "utf8");
|
|
33631
33761
|
const key = await readPrivateLessonOutboxKey(
|
|
33632
33762
|
encryption,
|
|
33633
|
-
|
|
33763
|
+
envelope2.encryption.key_source
|
|
33634
33764
|
);
|
|
33635
33765
|
const decipher = createDecipheriv2(
|
|
33636
33766
|
"aes-256-gcm",
|
|
33637
33767
|
key,
|
|
33638
|
-
Buffer.from(
|
|
33768
|
+
Buffer.from(envelope2.encryption.nonce, "base64url")
|
|
33639
33769
|
);
|
|
33640
33770
|
decipher.setAAD(aad);
|
|
33641
|
-
decipher.setAuthTag(Buffer.from(
|
|
33771
|
+
decipher.setAuthTag(Buffer.from(envelope2.encryption.auth_tag, "base64url"));
|
|
33642
33772
|
let plaintext;
|
|
33643
33773
|
try {
|
|
33644
33774
|
plaintext = Buffer.concat([
|
|
33645
|
-
decipher.update(Buffer.from(
|
|
33775
|
+
decipher.update(Buffer.from(envelope2.encryption.ciphertext, "base64url")),
|
|
33646
33776
|
decipher.final()
|
|
33647
33777
|
]).toString("utf8");
|
|
33648
33778
|
} catch {
|
|
33649
|
-
throw new PrivateOutboxDecryptionError("private_lesson",
|
|
33779
|
+
throw new PrivateOutboxDecryptionError("private_lesson", envelope2.draft_id);
|
|
33650
33780
|
}
|
|
33651
33781
|
const draft = validateDraft(JSON.parse(plaintext), allowUnsupportedProfile);
|
|
33652
|
-
if (draft.draft_id !==
|
|
33782
|
+
if (draft.draft_id !== envelope2.draft_id || draft.state !== envelope2.state || draft.payload_digest !== envelope2.payload_digest || draft.hold_telemetry_status !== envelope2.hold_telemetry_status || draft.next_retry_at !== envelope2.next_retry_at || Object.hasOwn(envelope2, "last_error_code") && draft.last_error_code !== (envelope2.last_error_code ?? null) || Object.hasOwn(envelope2, "destination_binding") && canonicalJson(draft.destination_binding) !== canonicalJson(envelope2.destination_binding ?? null) || draft.terminal_reason !== envelope2.terminal_reason) {
|
|
33653
33783
|
throw new Error(
|
|
33654
33784
|
"Private lesson outbox envelope does not match its payload."
|
|
33655
33785
|
);
|
|
@@ -33742,8 +33872,8 @@ function validateDraft(value, allowUnsupportedProfile = false) {
|
|
|
33742
33872
|
destination_binding: destinationBinding
|
|
33743
33873
|
};
|
|
33744
33874
|
}
|
|
33745
|
-
function staleSafetyRecheckHint(
|
|
33746
|
-
return (
|
|
33875
|
+
function staleSafetyRecheckHint(envelope2, draft) {
|
|
33876
|
+
return (envelope2.safety_recheck ?? null) !== privateLessonSafetyRecheck(draft);
|
|
33747
33877
|
}
|
|
33748
33878
|
function reconcileStoredDraft(draft, now) {
|
|
33749
33879
|
return normalizeLegacyHeldSafetyDraft(
|
|
@@ -34284,8 +34414,8 @@ async function reconcilePrivateLessonTemporaryWrites(directory, encryption) {
|
|
|
34284
34414
|
const raw = JSON.parse(value);
|
|
34285
34415
|
draftId = String(raw.draft_id ?? "");
|
|
34286
34416
|
assertDraftId(draftId);
|
|
34287
|
-
const
|
|
34288
|
-
await decryptDraft(
|
|
34417
|
+
const envelope2 = parseEnvelope(value, draftId);
|
|
34418
|
+
await decryptDraft(envelope2, encryption, true);
|
|
34289
34419
|
} catch (error) {
|
|
34290
34420
|
if (isPrivateOutboxKeyAccessError(error)) {
|
|
34291
34421
|
if (draftId) unresolved.set(draftId, error);
|
|
@@ -34399,11 +34529,11 @@ async function validatePrivateLessonCanonicalPath(path, name, encryption) {
|
|
|
34399
34529
|
);
|
|
34400
34530
|
return null;
|
|
34401
34531
|
}
|
|
34402
|
-
const
|
|
34532
|
+
const envelope2 = parseEnvelope(
|
|
34403
34533
|
await readPrivateLessonCanonicalText(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
34404
34534
|
draftId
|
|
34405
34535
|
);
|
|
34406
|
-
return await decryptDraft(
|
|
34536
|
+
return await decryptDraft(envelope2, encryption, true);
|
|
34407
34537
|
}
|
|
34408
34538
|
async function readPrivateLessonCanonicalText(path, maxBytes) {
|
|
34409
34539
|
try {
|
|
@@ -47221,7 +47351,7 @@ var require_timestamp = __commonJS({
|
|
|
47221
47351
|
resolve: (str) => parseSexagesimal(str, false),
|
|
47222
47352
|
stringify: stringifySexagesimal
|
|
47223
47353
|
};
|
|
47224
|
-
var
|
|
47354
|
+
var timestamp3 = {
|
|
47225
47355
|
identify: (value) => value instanceof Date,
|
|
47226
47356
|
default: true,
|
|
47227
47357
|
tag: "tag:yaml.org,2002:timestamp",
|
|
@@ -47230,7 +47360,7 @@ var require_timestamp = __commonJS({
|
|
|
47230
47360
|
// assumed to be 00:00:00Z (start of day, UTC).
|
|
47231
47361
|
test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
|
|
47232
47362
|
resolve(str) {
|
|
47233
|
-
const match = str.match(
|
|
47363
|
+
const match = str.match(timestamp3.test);
|
|
47234
47364
|
if (!match)
|
|
47235
47365
|
throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
|
|
47236
47366
|
const [, year, month, day, hour, minute, second] = match.map(Number);
|
|
@@ -47249,7 +47379,7 @@ var require_timestamp = __commonJS({
|
|
|
47249
47379
|
};
|
|
47250
47380
|
exports.floatTime = floatTime;
|
|
47251
47381
|
exports.intTime = intTime;
|
|
47252
|
-
exports.timestamp =
|
|
47382
|
+
exports.timestamp = timestamp3;
|
|
47253
47383
|
}
|
|
47254
47384
|
});
|
|
47255
47385
|
var require_schema3 = __commonJS({
|
|
@@ -47267,7 +47397,7 @@ var require_schema3 = __commonJS({
|
|
|
47267
47397
|
var omap = require_omap();
|
|
47268
47398
|
var pairs = require_pairs();
|
|
47269
47399
|
var set = require_set();
|
|
47270
|
-
var
|
|
47400
|
+
var timestamp3 = require_timestamp();
|
|
47271
47401
|
var schema = [
|
|
47272
47402
|
map.map,
|
|
47273
47403
|
seq.seq,
|
|
@@ -47287,9 +47417,9 @@ var require_schema3 = __commonJS({
|
|
|
47287
47417
|
omap.omap,
|
|
47288
47418
|
pairs.pairs,
|
|
47289
47419
|
set.set,
|
|
47290
|
-
|
|
47291
|
-
|
|
47292
|
-
|
|
47420
|
+
timestamp3.intTime,
|
|
47421
|
+
timestamp3.floatTime,
|
|
47422
|
+
timestamp3.timestamp
|
|
47293
47423
|
];
|
|
47294
47424
|
exports.schema = schema;
|
|
47295
47425
|
}
|
|
@@ -47312,7 +47442,7 @@ var require_tags = __commonJS({
|
|
|
47312
47442
|
var pairs = require_pairs();
|
|
47313
47443
|
var schema$2 = require_schema3();
|
|
47314
47444
|
var set = require_set();
|
|
47315
|
-
var
|
|
47445
|
+
var timestamp3 = require_timestamp();
|
|
47316
47446
|
var schemas = /* @__PURE__ */ new Map([
|
|
47317
47447
|
["core", schema.schema],
|
|
47318
47448
|
["failsafe", [map.map, seq.seq, string.string]],
|
|
@@ -47326,11 +47456,11 @@ var require_tags = __commonJS({
|
|
|
47326
47456
|
float: float.float,
|
|
47327
47457
|
floatExp: float.floatExp,
|
|
47328
47458
|
floatNaN: float.floatNaN,
|
|
47329
|
-
floatTime:
|
|
47459
|
+
floatTime: timestamp3.floatTime,
|
|
47330
47460
|
int: int.int,
|
|
47331
47461
|
intHex: int.intHex,
|
|
47332
47462
|
intOct: int.intOct,
|
|
47333
|
-
intTime:
|
|
47463
|
+
intTime: timestamp3.intTime,
|
|
47334
47464
|
map: map.map,
|
|
47335
47465
|
merge: merge.merge,
|
|
47336
47466
|
null: _null.nullTag,
|
|
@@ -47338,7 +47468,7 @@ var require_tags = __commonJS({
|
|
|
47338
47468
|
pairs: pairs.pairs,
|
|
47339
47469
|
seq: seq.seq,
|
|
47340
47470
|
set: set.set,
|
|
47341
|
-
timestamp:
|
|
47471
|
+
timestamp: timestamp3.timestamp
|
|
47342
47472
|
};
|
|
47343
47473
|
var coreKnownTags = {
|
|
47344
47474
|
"tag:yaml.org,2002:binary": binary.binary,
|
|
@@ -47346,7 +47476,7 @@ var require_tags = __commonJS({
|
|
|
47346
47476
|
"tag:yaml.org,2002:omap": omap.omap,
|
|
47347
47477
|
"tag:yaml.org,2002:pairs": pairs.pairs,
|
|
47348
47478
|
"tag:yaml.org,2002:set": set.set,
|
|
47349
|
-
"tag:yaml.org,2002:timestamp":
|
|
47479
|
+
"tag:yaml.org,2002:timestamp": timestamp3.timestamp
|
|
47350
47480
|
};
|
|
47351
47481
|
function getTags(customTags, schemaName, addMergeTag) {
|
|
47352
47482
|
const schemaTags = schemas.get(schemaName);
|
|
@@ -51507,24 +51637,24 @@ function rsa(b, t, f) {
|
|
|
51507
51637
|
function algorithmId(b, t) {
|
|
51508
51638
|
if (!t?.complete || t.tag !== 48) return;
|
|
51509
51639
|
const f = fields(b, t, 2);
|
|
51510
|
-
const
|
|
51511
|
-
if (!f || !
|
|
51512
|
-
for (let p =
|
|
51513
|
-
if ((p ===
|
|
51640
|
+
const id2 = f?.[0];
|
|
51641
|
+
if (!f || !id2 || !hex(b, id2) || b[id2.end - 1] & 128) return;
|
|
51642
|
+
for (let p = id2.body; p < id2.end; p++) {
|
|
51643
|
+
if ((p === id2.body || !(b[p - 1] & 128)) && b[p] === 128) return;
|
|
51514
51644
|
}
|
|
51515
|
-
return hex(b,
|
|
51645
|
+
return hex(b, id2);
|
|
51516
51646
|
}
|
|
51517
51647
|
function algorithm(b, t) {
|
|
51518
51648
|
if (!t?.complete || t.tag !== 48) return;
|
|
51519
51649
|
const f = fields(b, t, 2);
|
|
51520
51650
|
if (!f) return;
|
|
51521
|
-
const
|
|
51522
|
-
if (
|
|
51651
|
+
const id2 = hex(b, f[0]);
|
|
51652
|
+
if (id2 === OID.rsa && (f.length === 1 || f[1]?.tag === 5 && f[1].body === f[1].end))
|
|
51523
51653
|
return { name: "rsa" };
|
|
51524
|
-
if (
|
|
51654
|
+
if (id2 === OID.ed && f.length === 1) return { name: "ed25519" };
|
|
51525
51655
|
const curve = hex(b, f[1]);
|
|
51526
|
-
if (
|
|
51527
|
-
if (
|
|
51656
|
+
if (id2 === OID.ec && curve) return { name: "ec", curve };
|
|
51657
|
+
if (id2 === OID.ec && f[1]?.tag === 48)
|
|
51528
51658
|
return { name: "ec", curve: "explicit" };
|
|
51529
51659
|
}
|
|
51530
51660
|
function sec1(b, t, f, inheritedCurve) {
|
|
@@ -51570,10 +51700,10 @@ function encryptedAlgorithm(b, t) {
|
|
|
51570
51700
|
const f = fields(b, t, 2);
|
|
51571
51701
|
if (!f || f.length !== 2 || f[1]?.tag !== 48 || !f[1].complete)
|
|
51572
51702
|
return false;
|
|
51573
|
-
const
|
|
51703
|
+
const id2 = hex(b, f[0]);
|
|
51574
51704
|
const params = fields(b, f[1], 2);
|
|
51575
51705
|
if (!params || params.length !== 2) return false;
|
|
51576
|
-
if (
|
|
51706
|
+
if (id2 === OID.pbes2) {
|
|
51577
51707
|
const kdf = params[0]?.tag === 48 && fields(b, params[0], 2);
|
|
51578
51708
|
const cipher = params[1]?.tag === 48 && fields(b, params[1], 2);
|
|
51579
51709
|
if (!kdf || kdf.length !== 2 || !cipher || cipher.length !== 2 || hex(b, kdf[0]) !== "2a864886f70d01050c" || kdf[1]?.tag !== 48)
|
|
@@ -51596,11 +51726,11 @@ function encryptedAlgorithm(b, t) {
|
|
|
51596
51726
|
const ivSize = /^6086480165030401(02|16|2a)$/.test(cipherId) ? 16 : cipherId === "2a864886f70d0307" ? 8 : 0;
|
|
51597
51727
|
return next === derivation.length && ivSize > 0 && cipher[1]?.tag === 4 && cipher[1].end - cipher[1].body === ivSize;
|
|
51598
51728
|
}
|
|
51599
|
-
return /^2a864886f70d010c010[1-6]$/.test(
|
|
51729
|
+
return /^2a864886f70d010c010[1-6]$/.test(id2) && params[0]?.tag === 4 && params[0].end > params[0].body && (integer(b, params[1]) ?? 0n) > 0n;
|
|
51600
51730
|
}
|
|
51601
51731
|
function encryptedPkcs8(b, t, f) {
|
|
51602
|
-
const
|
|
51603
|
-
if (f.length !== 2 || !encryptedAlgorithm(b, f[0]) &&
|
|
51732
|
+
const id2 = algorithmId(b, f[0]);
|
|
51733
|
+
if (f.length !== 2 || !encryptedAlgorithm(b, f[0]) && id2 !== OID.pbes2 && !/^2a864886f70d010c010[1-6]$/.test(id2 ?? "") || f[1]?.tag !== 4 || f[1].body >= Math.min(f[1].end, b.length))
|
|
51604
51734
|
return;
|
|
51605
51735
|
return { kind: "encrypted", format: "pkcs8-encrypted", complete: t.complete };
|
|
51606
51736
|
}
|
|
@@ -51616,10 +51746,10 @@ function pkcs8(b, t, f) {
|
|
|
51616
51746
|
return;
|
|
51617
51747
|
}
|
|
51618
51748
|
if (next !== f.length) return;
|
|
51619
|
-
const
|
|
51749
|
+
const id2 = algorithmId(b, f[1]);
|
|
51620
51750
|
const alg = algorithm(b, f[1]);
|
|
51621
51751
|
const octets2 = f[2];
|
|
51622
|
-
if (
|
|
51752
|
+
if (id2 === OID.pss && octets2.body < Math.min(octets2.end, b.length)) {
|
|
51623
51753
|
return {
|
|
51624
51754
|
kind: "private",
|
|
51625
51755
|
format: "pkcs8-rsa-pss",
|
|
@@ -51630,9 +51760,9 @@ function pkcs8(b, t, f) {
|
|
|
51630
51760
|
const inner = tlv(b, octets2.body, Math.min(octets2.end, b.length));
|
|
51631
51761
|
if (!inner || inner.end !== octets2.end) return;
|
|
51632
51762
|
if (!alg) {
|
|
51633
|
-
const seedSize =
|
|
51763
|
+
const seedSize = id2 === "2b656e" ? 32 : id2 === "2b656f" ? 56 : id2 === "2b6571" ? 57 : 0;
|
|
51634
51764
|
const knownSeed = seedSize && inner.tag === 4 && inner.end - inner.body === seedSize && inner.body < b.length;
|
|
51635
|
-
const dsa =
|
|
51765
|
+
const dsa = id2 === "2a8648ce380401" && (integer(b, inner) ?? 0n) > 0n;
|
|
51636
51766
|
if (knownSeed || dsa)
|
|
51637
51767
|
return {
|
|
51638
51768
|
kind: "private",
|
|
@@ -51785,14 +51915,14 @@ function safeContents(b, t, out, depth, callbacks) {
|
|
|
51785
51915
|
if (!f || f.length < 2 || f[2] && f[2].tag !== 49) return false;
|
|
51786
51916
|
const value = wrapped(b, f[1], 160, true);
|
|
51787
51917
|
if (!value) return false;
|
|
51788
|
-
const
|
|
51789
|
-
if (
|
|
51918
|
+
const id2 = hex(b, f[0]);
|
|
51919
|
+
if (id2 === OID.safeBag) {
|
|
51790
51920
|
if (!safeContents(b, value, out, depth + 1, callbacks)) return false;
|
|
51791
|
-
} else if (
|
|
51921
|
+
} else if (id2 === OID.keyBag || id2 === OID.shroudedBag) {
|
|
51792
51922
|
const children = value.tag === 48 && fields(b, value);
|
|
51793
|
-
let evidence = children && (
|
|
51923
|
+
let evidence = children && (id2 === OID.keyBag ? pkcs8(b, value, children) : encryptedPkcs8(b, value, children));
|
|
51794
51924
|
if (!evidence && children) {
|
|
51795
|
-
const offset =
|
|
51925
|
+
const offset = id2 === OID.keyBag ? 1 : 0;
|
|
51796
51926
|
const version = offset ? integer(b, children[0]) : 0n;
|
|
51797
51927
|
const payload = children[offset + 1];
|
|
51798
51928
|
if ((version === 0n || version === 1n) && algorithmId(b, children[offset]) && payload?.tag === 4 && payload.body < Math.min(payload.end, b.length)) {
|
|
@@ -51808,7 +51938,7 @@ function safeContents(b, t, out, depth, callbacks) {
|
|
|
51808
51938
|
if (evidence.kind === "private") out.private = true;
|
|
51809
51939
|
else out.encrypted = true;
|
|
51810
51940
|
out.editable &&= evidence.complete && evidence.editable !== false;
|
|
51811
|
-
} else if (
|
|
51941
|
+
} else if (id2 === OID.certBag) {
|
|
51812
51942
|
const cert = value.tag === 48 && fields(b, value, 2);
|
|
51813
51943
|
const octets2 = cert && wrapped(b, cert[1], 160);
|
|
51814
51944
|
const der = octets2 && wrapped(b, octets2, 4);
|
|
@@ -55823,8 +55953,8 @@ var DFA = class DFA2 {
|
|
|
55823
55953
|
const matches = /* @__PURE__ */ new Set();
|
|
55824
55954
|
const checkMatch = (state, currentPos) => {
|
|
55825
55955
|
if (state.isMatch) if (anchor === RE2Flags.ANCHOR_BOTH) {
|
|
55826
|
-
if (currentPos === endPos) state.matchIDs.forEach((
|
|
55827
|
-
} else state.matchIDs.forEach((
|
|
55956
|
+
if (currentPos === endPos) state.matchIDs.forEach((id2) => matches.add(id2));
|
|
55957
|
+
} else state.matchIDs.forEach((id2) => matches.add(id2));
|
|
55828
55958
|
};
|
|
55829
55959
|
checkMatch(currentState, pos);
|
|
55830
55960
|
let i = pos;
|
|
@@ -57131,12 +57261,12 @@ var Compiler = class Compiler2 {
|
|
|
57131
57261
|
return f;
|
|
57132
57262
|
}
|
|
57133
57263
|
lookBehind(a, lb) {
|
|
57134
|
-
const
|
|
57135
|
-
this.prog.getInst(
|
|
57264
|
+
const id2 = this.newInst(Inst.LB_WRITE);
|
|
57265
|
+
this.prog.getInst(id2.i).arg = lb;
|
|
57136
57266
|
const any = this.rune(Compiler2.ANY_RUNE(), 0);
|
|
57137
57267
|
const dotStar = this.star(any, true);
|
|
57138
57268
|
const lbAutomaton = this.cat(dotStar, a);
|
|
57139
|
-
this.prog.patch(lbAutomaton.out,
|
|
57269
|
+
this.prog.patch(lbAutomaton.out, id2.i);
|
|
57140
57270
|
const checkId = this.newInst(Inst.LB_CHECK);
|
|
57141
57271
|
this.prog.getInst(checkId.i).arg = lb;
|
|
57142
57272
|
this.prog.lbStarts.push(lbAutomaton.i);
|
|
@@ -63174,7 +63304,7 @@ function parsePrivateSkillInspectionDecision(value) {
|
|
|
63174
63304
|
});
|
|
63175
63305
|
}
|
|
63176
63306
|
function inspectPrivateSkillCandidate(candidate) {
|
|
63177
|
-
const
|
|
63307
|
+
const failure2 = (reason, stage, projectionBodyLength) => ({
|
|
63178
63308
|
status: "invalid",
|
|
63179
63309
|
error_code: reason === "source_projection_invalid" ? reason : "local_inspection_failure",
|
|
63180
63310
|
decision: {
|
|
@@ -63188,13 +63318,13 @@ function inspectPrivateSkillCandidate(candidate) {
|
|
|
63188
63318
|
try {
|
|
63189
63319
|
const result = inspectBoundedPrivateLearningRoot(candidate);
|
|
63190
63320
|
if (!record3(result) || result.inspector_digest !== PRIVATE_LEARNING_INSPECTOR_DIGEST)
|
|
63191
|
-
return
|
|
63321
|
+
return failure2("inspector_contract_invalid", "original");
|
|
63192
63322
|
if (result.status === "incomplete" && result.outcome === "operational_failure") {
|
|
63193
63323
|
const reason = reasons.includes(result.reason) ? result.reason : "inspection_internal_failure";
|
|
63194
63324
|
const stage = ["original", "candidate", "recovery_context"].includes(
|
|
63195
63325
|
String(result.failure_stage)
|
|
63196
63326
|
) ? result.failure_stage : "original";
|
|
63197
|
-
return
|
|
63327
|
+
return failure2(reason, stage);
|
|
63198
63328
|
}
|
|
63199
63329
|
if (result.status === "incomplete" && result.outcome === "positive_recovery_need" && (result.reason === "ambiguous_source_ownership" || result.reason === "encrypted_private_container" || result.reason === "declared_private_format_unverified")) {
|
|
63200
63330
|
return {
|
|
@@ -63217,11 +63347,11 @@ function inspectPrivateSkillCandidate(candidate) {
|
|
|
63217
63347
|
};
|
|
63218
63348
|
}
|
|
63219
63349
|
if (result.status !== "complete" || result.outcome !== "unchanged" && result.outcome !== "redacted" || typeof result.sensitiveMaterial !== "boolean" || typeof result.sensitiveObjectKeyMaterial !== "boolean")
|
|
63220
|
-
return
|
|
63350
|
+
return failure2("inspector_contract_invalid", "original");
|
|
63221
63351
|
const projected = privateSkillCaptureSchema.safeParse(result.redacted);
|
|
63222
63352
|
if (!projected.success) {
|
|
63223
63353
|
const body = record3(result.redacted) ? result.redacted.proposed_skill_md : void 0;
|
|
63224
|
-
return
|
|
63354
|
+
return failure2(
|
|
63225
63355
|
"source_projection_invalid",
|
|
63226
63356
|
"candidate",
|
|
63227
63357
|
typeof body === "string" && isOnlySkillBodyTooLong(projected.error) ? body.trim().length : void 0
|
|
@@ -63229,7 +63359,7 @@ function inspectPrivateSkillCandidate(candidate) {
|
|
|
63229
63359
|
}
|
|
63230
63360
|
const changed = canonicalJson(candidate) !== canonicalJson(projected.data);
|
|
63231
63361
|
if (changed !== (result.outcome === "redacted") || changed !== result.sensitiveMaterial || !changed && result.sensitiveObjectKeyMaterial)
|
|
63232
|
-
return
|
|
63362
|
+
return failure2("inspector_contract_invalid", "candidate");
|
|
63233
63363
|
return {
|
|
63234
63364
|
status: "complete",
|
|
63235
63365
|
candidate: projected.data,
|
|
@@ -63241,7 +63371,7 @@ function inspectPrivateSkillCandidate(candidate) {
|
|
|
63241
63371
|
}
|
|
63242
63372
|
};
|
|
63243
63373
|
} catch {
|
|
63244
|
-
return
|
|
63374
|
+
return failure2("inspection_internal_failure", "original");
|
|
63245
63375
|
}
|
|
63246
63376
|
}
|
|
63247
63377
|
|
|
@@ -65294,7 +65424,7 @@ async function recordPrivateSkillDeliveryResolution(draftId, rawResolution, opti
|
|
|
65294
65424
|
}
|
|
65295
65425
|
async function recordPrivateSkillDeliveryResolutionRouteUnavailable(draftId, rawRequest, options = {}) {
|
|
65296
65426
|
assertPrivateSkillDraftId(draftId);
|
|
65297
|
-
const
|
|
65427
|
+
const request2 = privateSkillDeliveryResolveRequestSchema.parse(rawRequest);
|
|
65298
65428
|
return withPrivateSkillDraftLock(draftId, async () => {
|
|
65299
65429
|
const outbox = await readyPrivateSkillOutbox(options);
|
|
65300
65430
|
return withPrivateSkillOutboxLock(outbox.directory, async () => {
|
|
@@ -65304,7 +65434,7 @@ async function recordPrivateSkillDeliveryResolutionRouteUnavailable(draftId, raw
|
|
|
65304
65434
|
outbox.encryption
|
|
65305
65435
|
);
|
|
65306
65436
|
const pending = current.delivery_resolution;
|
|
65307
|
-
if (!pending ||
|
|
65437
|
+
if (!pending || request2.idempotency_key !== pending.idempotency_key || request2.candidate_digest !== pending.candidate_digest) {
|
|
65308
65438
|
throw new Error("Private skill delivery resolution binding changed.");
|
|
65309
65439
|
}
|
|
65310
65440
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
@@ -65816,7 +65946,7 @@ async function writePrivateSkillDraft(draft, directory, encryption, env = proces
|
|
|
65816
65946
|
cipher.update(canonicalJson(parsed), "utf8"),
|
|
65817
65947
|
cipher.final()
|
|
65818
65948
|
]);
|
|
65819
|
-
const
|
|
65949
|
+
const envelope2 = {
|
|
65820
65950
|
...metadata,
|
|
65821
65951
|
encryption: {
|
|
65822
65952
|
algorithm: "aes-256-gcm",
|
|
@@ -65826,7 +65956,7 @@ async function writePrivateSkillDraft(draft, directory, encryption, env = proces
|
|
|
65826
65956
|
auth_tag: cipher.getAuthTag().toString("base64url")
|
|
65827
65957
|
}
|
|
65828
65958
|
};
|
|
65829
|
-
const encoded = `${canonicalJson(
|
|
65959
|
+
const encoded = `${canonicalJson(envelope2)}
|
|
65830
65960
|
`;
|
|
65831
65961
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
65832
65962
|
const reserve = parsed.native_authority_state && !withdrawal ? PRIVATE_SKILL_NATIVE_WITHDRAWAL_RESERVE_BYTES : 0;
|
|
@@ -65860,46 +65990,46 @@ async function writePrivateSkillDraft(draft, directory, encryption, env = proces
|
|
|
65860
65990
|
await atomicWritePrivateText(path, encoded, beforePublish);
|
|
65861
65991
|
}
|
|
65862
65992
|
async function readPrivateSkillDraftFrom(path, encryption) {
|
|
65863
|
-
const
|
|
65993
|
+
const envelope2 = parseEnvelope2(
|
|
65864
65994
|
readSecureLocalText(path, { maxBytes: PRIVATE_SKILL_DRAFT_MAX_BYTES })
|
|
65865
65995
|
);
|
|
65866
|
-
const metadata = envelopeMetadataFromEnvelope(
|
|
65996
|
+
const metadata = envelopeMetadataFromEnvelope(envelope2);
|
|
65867
65997
|
const key = await readPrivateLessonOutboxKey(
|
|
65868
65998
|
encryption,
|
|
65869
|
-
|
|
65999
|
+
envelope2.encryption.key_source
|
|
65870
66000
|
);
|
|
65871
66001
|
const decipher = createDecipheriv3(
|
|
65872
66002
|
"aes-256-gcm",
|
|
65873
66003
|
key,
|
|
65874
|
-
Buffer.from(
|
|
66004
|
+
Buffer.from(envelope2.encryption.nonce, "base64url")
|
|
65875
66005
|
);
|
|
65876
66006
|
decipher.setAAD(Buffer.from(canonicalJson(metadata)));
|
|
65877
|
-
decipher.setAuthTag(Buffer.from(
|
|
66007
|
+
decipher.setAuthTag(Buffer.from(envelope2.encryption.auth_tag, "base64url"));
|
|
65878
66008
|
let plaintext;
|
|
65879
66009
|
try {
|
|
65880
66010
|
plaintext = Buffer.concat([
|
|
65881
|
-
decipher.update(Buffer.from(
|
|
66011
|
+
decipher.update(Buffer.from(envelope2.encryption.ciphertext, "base64url")),
|
|
65882
66012
|
decipher.final()
|
|
65883
66013
|
]).toString("utf8");
|
|
65884
66014
|
} catch {
|
|
65885
|
-
throw new PrivateOutboxDecryptionError("private_skill",
|
|
66015
|
+
throw new PrivateOutboxDecryptionError("private_skill", envelope2.draft_id);
|
|
65886
66016
|
}
|
|
65887
66017
|
const parsed = validatePrivateSkillDraft(JSON.parse(plaintext));
|
|
65888
|
-
if (
|
|
66018
|
+
if (envelope2.version === "private-skill-outbox-envelope-v2" !== Boolean(parsed.native_authority_state))
|
|
65889
66019
|
throw new Error("Private skill native authority envelope is invalid.");
|
|
65890
|
-
if (parsed.draft_id !==
|
|
66020
|
+
if (parsed.draft_id !== envelope2.draft_id || parsed.state !== envelope2.state || parsed.candidate_digest !== envelope2.candidate_digest || parsed.next_retry_at !== envelope2.next_retry_at || parsed.created_at !== envelope2.created_at || parsed.updated_at !== envelope2.updated_at) {
|
|
65891
66021
|
throw new Error(
|
|
65892
66022
|
"Private skill outbox metadata does not match its payload."
|
|
65893
66023
|
);
|
|
65894
66024
|
}
|
|
65895
|
-
if (hasEnvelopeReformulationMetadata(
|
|
66025
|
+
if (hasEnvelopeReformulationMetadata(envelope2) && (envelope2.reformulation_available !== privateSkillReformulationAvailable(
|
|
65896
66026
|
parsed,
|
|
65897
|
-
|
|
65898
|
-
) ||
|
|
66027
|
+
envelope2.inspector_digest ?? PRIVATE_LEARNING_INSPECTOR_DIGEST
|
|
66028
|
+
) || envelope2.reformulation_reason !== parsed.reformulation_reason || envelope2.reformulation_attempt_count !== parsed.reformulation_attempts.length || envelope2.recovery_epoch_attempt_count !== void 0 && envelope2.recovery_epoch_attempt_count !== privateSkillCurrentEpochAttemptCount(parsed) || envelope2.inspector_digest !== void 0 && envelope2.inspector_digest !== (parsed.inspection?.inspector_digest ?? null) || envelope2.native_context_pending !== void 0 && envelope2.native_context_pending !== hasPendingNativeContext(parsed) || envelope2.next_action !== void 0 && canonicalJson(envelope2.next_action) !== canonicalJson(
|
|
65899
66029
|
privateSkillRecoveryTransition(
|
|
65900
66030
|
parsed,
|
|
65901
66031
|
false,
|
|
65902
|
-
|
|
66032
|
+
envelope2.inspector_digest ?? PRIVATE_LEARNING_INSPECTOR_DIGEST
|
|
65903
66033
|
).next_action
|
|
65904
66034
|
))) {
|
|
65905
66035
|
throw new Error(
|
|
@@ -66676,27 +66806,27 @@ function privateSkillInspectorRefreshAllowed(draft) {
|
|
|
66676
66806
|
}
|
|
66677
66807
|
return draft.inspection.outcome === "positive_recovery_need" || draft.inspection.outcome === "operational_failure" || draft.last_error_code === "submission_reinspection_source_projection_drift" || draft.last_error_code === "inspector_refresh_new_lineage_required";
|
|
66678
66808
|
}
|
|
66679
|
-
function envelopeMetadataFromEnvelope(
|
|
66809
|
+
function envelopeMetadataFromEnvelope(envelope2) {
|
|
66680
66810
|
const base2 = {
|
|
66681
|
-
version:
|
|
66682
|
-
draft_id:
|
|
66683
|
-
state:
|
|
66684
|
-
candidate_digest:
|
|
66685
|
-
next_retry_at:
|
|
66686
|
-
created_at:
|
|
66687
|
-
updated_at:
|
|
66811
|
+
version: envelope2.version,
|
|
66812
|
+
draft_id: envelope2.draft_id,
|
|
66813
|
+
state: envelope2.state,
|
|
66814
|
+
candidate_digest: envelope2.candidate_digest,
|
|
66815
|
+
next_retry_at: envelope2.next_retry_at,
|
|
66816
|
+
created_at: envelope2.created_at,
|
|
66817
|
+
updated_at: envelope2.updated_at
|
|
66688
66818
|
};
|
|
66689
|
-
return hasEnvelopeReformulationMetadata(
|
|
66819
|
+
return hasEnvelopeReformulationMetadata(envelope2) ? {
|
|
66690
66820
|
...base2,
|
|
66691
|
-
reformulation_available:
|
|
66692
|
-
reformulation_reason:
|
|
66693
|
-
reformulation_attempt_count:
|
|
66694
|
-
...
|
|
66695
|
-
recovery_epoch_attempt_count:
|
|
66821
|
+
reformulation_available: envelope2.reformulation_available,
|
|
66822
|
+
reformulation_reason: envelope2.reformulation_reason,
|
|
66823
|
+
reformulation_attempt_count: envelope2.reformulation_attempt_count,
|
|
66824
|
+
...envelope2.recovery_epoch_attempt_count === void 0 ? {} : {
|
|
66825
|
+
recovery_epoch_attempt_count: envelope2.recovery_epoch_attempt_count
|
|
66696
66826
|
},
|
|
66697
|
-
...
|
|
66698
|
-
...
|
|
66699
|
-
...
|
|
66827
|
+
...envelope2.inspector_digest === void 0 ? {} : { inspector_digest: envelope2.inspector_digest },
|
|
66828
|
+
...envelope2.native_context_pending === void 0 ? {} : { native_context_pending: envelope2.native_context_pending },
|
|
66829
|
+
...envelope2.next_action === void 0 ? {} : { next_action: envelope2.next_action }
|
|
66700
66830
|
} : base2;
|
|
66701
66831
|
}
|
|
66702
66832
|
function parseEnvelope2(value) {
|
|
@@ -66704,14 +66834,14 @@ function parseEnvelope2(value) {
|
|
|
66704
66834
|
if (!isRecord4(parsed) || !isRecord4(parsed.encryption)) {
|
|
66705
66835
|
throw new Error("Private skill outbox envelope is invalid.");
|
|
66706
66836
|
}
|
|
66707
|
-
const
|
|
66837
|
+
const envelope2 = parsed;
|
|
66708
66838
|
if (![
|
|
66709
66839
|
"private-skill-outbox-envelope-v1",
|
|
66710
66840
|
"private-skill-outbox-envelope-v2"
|
|
66711
|
-
].includes(
|
|
66841
|
+
].includes(envelope2.version) || envelope2.encryption.algorithm !== "aes-256-gcm" || !/^[A-Za-z0-9_-]{16}$/u.test(envelope2.encryption.nonce) || !/^[A-Za-z0-9_-]{16,}$/u.test(envelope2.encryption.ciphertext) || !/^[A-Za-z0-9_-]{20,32}$/u.test(envelope2.encryption.auth_tag)) {
|
|
66712
66842
|
throw new Error("Private skill outbox envelope is invalid.");
|
|
66713
66843
|
}
|
|
66714
|
-
assertPrivateSkillDraftId(
|
|
66844
|
+
assertPrivateSkillDraftId(envelope2.draft_id);
|
|
66715
66845
|
const recoveryKeys = [
|
|
66716
66846
|
"reformulation_available",
|
|
66717
66847
|
"reformulation_reason",
|
|
@@ -66722,12 +66852,12 @@ function parseEnvelope2(value) {
|
|
|
66722
66852
|
throw new Error("Private skill outbox recovery metadata is invalid.");
|
|
66723
66853
|
}
|
|
66724
66854
|
if (recoveryKeyCount === recoveryKeys.length) {
|
|
66725
|
-
const epochCount =
|
|
66726
|
-
if (typeof
|
|
66855
|
+
const epochCount = envelope2.recovery_epoch_attempt_count ?? envelope2.reformulation_attempt_count;
|
|
66856
|
+
if (typeof envelope2.reformulation_available !== "boolean" || !isPrivateSkillRecoveryReasonOrNull(envelope2.reformulation_reason) || !Number.isSafeInteger(envelope2.reformulation_attempt_count) || Number(envelope2.reformulation_attempt_count) < 0 || Number(envelope2.reformulation_attempt_count) > PRIVATE_SKILL_REFORMULATION_RECORD_MAX || !Number.isSafeInteger(epochCount) || Number(epochCount) < 0 || Number(epochCount) > PRIVATE_SKILL_REFORMULATION_MAX_ATTEMPTS || envelope2.inspector_digest !== void 0 && envelope2.inspector_digest !== null && !/^sha256:[a-f0-9]{64}$/u.test(envelope2.inspector_digest) || envelope2.native_context_pending !== void 0 && typeof envelope2.native_context_pending !== "boolean" || !isPrivateSkillRecoveryActionOrNull(envelope2.next_action) || envelope2.next_action !== void 0 && envelope2.next_action !== null && (envelope2.next_action.draft_updated_at !== envelope2.updated_at || envelope2.next_action.inspector_digest !== (envelope2.inspector_digest ?? null)) || envelope2.reformulation_available && (!isPrivateSkillRecoveryReason(envelope2.reformulation_reason) || Number(epochCount) >= PRIVATE_SKILL_REFORMULATION_MAX_ATTEMPTS)) {
|
|
66727
66857
|
throw new Error("Private skill outbox recovery metadata is invalid.");
|
|
66728
66858
|
}
|
|
66729
66859
|
}
|
|
66730
|
-
return
|
|
66860
|
+
return envelope2;
|
|
66731
66861
|
}
|
|
66732
66862
|
function isPrivateSkillRecoveryActionOrNull(value) {
|
|
66733
66863
|
if (value === void 0 || value === null) return true;
|
|
@@ -66743,8 +66873,8 @@ function isPrivateSkillRecoveryActionOrNull(value) {
|
|
|
66743
66873
|
"capture_native_context"
|
|
66744
66874
|
].includes(String(value.kind)) && typeof value.candidate_digest === "string" && /^sha256:[a-f0-9]{64}$/u.test(value.candidate_digest) && (value.inspector_digest === null || typeof value.inspector_digest === "string" && /^sha256:[a-f0-9]{64}$/u.test(value.inspector_digest)) && typeof value.draft_updated_at === "string" && Number.isFinite(Date.parse(value.draft_updated_at));
|
|
66745
66875
|
}
|
|
66746
|
-
function hasEnvelopeReformulationMetadata(
|
|
66747
|
-
return
|
|
66876
|
+
function hasEnvelopeReformulationMetadata(envelope2) {
|
|
66877
|
+
return envelope2.reformulation_available !== void 0 && envelope2.reformulation_reason !== void 0 && envelope2.reformulation_attempt_count !== void 0;
|
|
66748
66878
|
}
|
|
66749
66879
|
function parseSubmittedRecord2(value) {
|
|
66750
66880
|
const parsed = JSON.parse(value);
|
|
@@ -67798,17 +67928,17 @@ var LOCAL_ONLY_HANDLERS = Object.freeze({
|
|
|
67798
67928
|
context.privateLessonDestination
|
|
67799
67929
|
),
|
|
67800
67930
|
delete_private_lesson_candidate: (payload, context) => {
|
|
67801
|
-
const
|
|
67931
|
+
const request2 = payload;
|
|
67802
67932
|
return context.persistence.deletePrivateLessonDraft(
|
|
67803
|
-
|
|
67804
|
-
|
|
67933
|
+
request2.draft_id,
|
|
67934
|
+
request2.confirm
|
|
67805
67935
|
);
|
|
67806
67936
|
},
|
|
67807
67937
|
delete_private_skill_candidate: (payload, context) => {
|
|
67808
|
-
const
|
|
67938
|
+
const request2 = payload;
|
|
67809
67939
|
return context.persistence.deletePrivateSkillDraft(
|
|
67810
|
-
|
|
67811
|
-
|
|
67940
|
+
request2.draft_id,
|
|
67941
|
+
request2.confirm
|
|
67812
67942
|
);
|
|
67813
67943
|
}
|
|
67814
67944
|
});
|
|
@@ -68969,131 +69099,139 @@ function createLocalPersistenceCapabilities(dependencies = {}) {
|
|
|
68969
69099
|
});
|
|
68970
69100
|
}
|
|
68971
69101
|
|
|
68972
|
-
//
|
|
68973
|
-
import {
|
|
68974
|
-
|
|
68975
|
-
|
|
68976
|
-
|
|
68977
|
-
|
|
69102
|
+
// src/admin-control-client.ts
|
|
69103
|
+
import { createHash as createHash9, randomBytes as randomBytes11 } from "node:crypto";
|
|
69104
|
+
import { unlinkSync as unlinkSync3 } from "node:fs";
|
|
69105
|
+
import { dirname as dirname9 } from "node:path";
|
|
69106
|
+
|
|
69107
|
+
// src/admin-control-session-store.ts
|
|
69108
|
+
import { createHash as createHash6, randomBytes as randomBytes8 } from "node:crypto";
|
|
69109
|
+
import { mkdirSync as mkdirSync2, renameSync as renameSync2, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
69110
|
+
import { dirname as dirname6, join as join8 } from "node:path";
|
|
69111
|
+
|
|
69112
|
+
// src/local-config-path.ts
|
|
69113
|
+
import { homedir as homedir6 } from "node:os";
|
|
69114
|
+
import { join as join7 } from "node:path";
|
|
69115
|
+
function remembranceConfigPath(env = process.env, homeDirectory = homedir6()) {
|
|
69116
|
+
const configRoot = env.REMEMBRANCE_PLUGIN_HOST?.trim().toLowerCase() === "openclaw" ? join7(homeDirectory, ".config") : env.XDG_CONFIG_HOME ?? join7(homeDirectory, ".config");
|
|
69117
|
+
return join7(configRoot, "remembrance", "config.json");
|
|
68978
69118
|
}
|
|
68979
69119
|
|
|
68980
|
-
// src/
|
|
68981
|
-
|
|
68982
|
-
|
|
68983
|
-
|
|
68984
|
-
|
|
68985
|
-
|
|
68986
|
-
|
|
68987
|
-
|
|
68988
|
-
|
|
68989
|
-
|
|
68990
|
-
|
|
69120
|
+
// src/admin-control-session-store.ts
|
|
69121
|
+
var id = external_exports.string().regex(/^aar_[A-Za-z0-9_-]{32}$/);
|
|
69122
|
+
var timestamp2 = external_exports.string().datetime();
|
|
69123
|
+
var pendingSchema = external_exports.object({
|
|
69124
|
+
state: external_exports.literal("pending"),
|
|
69125
|
+
base_url: external_exports.string(),
|
|
69126
|
+
request_id: id,
|
|
69127
|
+
device_secret: external_exports.string().regex(/^adev_[A-Za-z0-9_-]{43}$/),
|
|
69128
|
+
code_verifier: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
69129
|
+
verification_uri: external_exports.string().url(),
|
|
69130
|
+
user_code: external_exports.string().regex(/^[A-F0-9]{8}$/),
|
|
69131
|
+
expires_at: timestamp2,
|
|
69132
|
+
interval: external_exports.number().int().min(3).max(60),
|
|
69133
|
+
next_poll_at: timestamp2
|
|
69134
|
+
}).strict();
|
|
69135
|
+
var activeSchema = external_exports.object({
|
|
69136
|
+
state: external_exports.literal("active"),
|
|
69137
|
+
base_url: external_exports.string(),
|
|
69138
|
+
session_id: id,
|
|
69139
|
+
access_token: external_exports.string().regex(/^radmin_[A-Za-z0-9_-]{43}$/),
|
|
69140
|
+
expires_at: timestamp2
|
|
69141
|
+
}).strict();
|
|
69142
|
+
var stateSchema = external_exports.discriminatedUnion("state", [pendingSchema, activeSchema]);
|
|
69143
|
+
function storePath(baseUrl) {
|
|
69144
|
+
const digest3 = createHash6("sha256").update(baseUrl).digest("hex");
|
|
69145
|
+
return join8(dirname6(remembranceConfigPath()), "admin-sessions", `${digest3}.json`);
|
|
69146
|
+
}
|
|
69147
|
+
function secureDirectory(path) {
|
|
69148
|
+
mkdirSync2(path, { recursive: true, mode: 448 });
|
|
69149
|
+
assertSecurePrivateLocalDirectory(path);
|
|
69150
|
+
}
|
|
69151
|
+
function readState(baseUrl) {
|
|
69152
|
+
try {
|
|
69153
|
+
const state = stateSchema.parse(JSON.parse(readSecureLocalText(storePath(baseUrl), { maxBytes: 8192 })));
|
|
69154
|
+
if (state.base_url !== baseUrl) throw new Error();
|
|
69155
|
+
if (state.state === "pending") {
|
|
69156
|
+
const expectedUri = new URL("/admin/authorize-agent", baseUrl);
|
|
69157
|
+
expectedUri.searchParams.set("request_id", state.request_id);
|
|
69158
|
+
if (state.verification_uri !== expectedUri.toString()) throw new Error();
|
|
68991
69159
|
}
|
|
69160
|
+
return state;
|
|
69161
|
+
} catch (error) {
|
|
69162
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
|
|
69163
|
+
throw new Error("Administrative credential storage is unavailable. Restore its private permissions before continuing.");
|
|
69164
|
+
}
|
|
69165
|
+
}
|
|
69166
|
+
function saveState(state) {
|
|
69167
|
+
const path = storePath(state.base_url);
|
|
69168
|
+
const temporary = `${path}.${randomBytes8(8).toString("hex")}.tmp`;
|
|
69169
|
+
try {
|
|
69170
|
+
writeFileSync2(temporary, JSON.stringify(state), { flag: "wx", mode: 384 });
|
|
69171
|
+
renameSync2(temporary, path);
|
|
69172
|
+
} finally {
|
|
68992
69173
|
try {
|
|
68993
|
-
|
|
68994
|
-
return { ready: false, refusal: {
|
|
68995
|
-
status: "held",
|
|
68996
|
-
code: "review_repair_wire_inspection_hold",
|
|
68997
|
-
delivery: "not_delivered",
|
|
68998
|
-
candidate_sent: false,
|
|
68999
|
-
candidate_stored: false,
|
|
69000
|
-
original_disposition: "unchanged",
|
|
69001
|
-
next_action: "Retain the original. Read a fresh normal content-free review snapshot; do not send suspected secrets, rewrite the held request, or use another transport."
|
|
69002
|
-
} };
|
|
69003
|
-
}
|
|
69174
|
+
unlinkSync(temporary);
|
|
69004
69175
|
} catch {
|
|
69005
|
-
return { ready: false, refusal: {
|
|
69006
|
-
status: "held",
|
|
69007
|
-
code: "review_repair_wire_inspection_failure",
|
|
69008
|
-
delivery: "not_delivered",
|
|
69009
|
-
candidate_sent: false,
|
|
69010
|
-
candidate_stored: false,
|
|
69011
|
-
original_disposition: "unchanged",
|
|
69012
|
-
next_action: "Retain the original. Correct the local inspection failure before retrying; do not reformulate around an operational failure."
|
|
69013
|
-
} };
|
|
69014
69176
|
}
|
|
69015
|
-
return { ready: true, request };
|
|
69016
69177
|
}
|
|
69017
|
-
const reason = inspection.status === "complete" ? "authored_capture_changed_by_inspection" : inspection.status === "incomplete" ? inspection.reason : inspection.error_code;
|
|
69018
|
-
return { ready: false, refusal: {
|
|
69019
|
-
status: "held",
|
|
69020
|
-
code: "review_repair_local_inspection_hold",
|
|
69021
|
-
delivery: "not_delivered",
|
|
69022
|
-
candidate_sent: false,
|
|
69023
|
-
candidate_stored: false,
|
|
69024
|
-
original_disposition: "unchanged",
|
|
69025
|
-
reason_code: reason,
|
|
69026
|
-
inspection: inspection.decision,
|
|
69027
|
-
next_action: inspection.status === "invalid" ? "Retain the original. Correct the local inspection failure before retrying the same unchanged request; do not reformulate around an operational failure or use another transport." : "Retain the original. Prepare a complete safe replacement from authenticated task context and inspect it again. Do not recover suspected secrets, invent missing instructions, or bypass a host denial."
|
|
69028
|
-
} };
|
|
69029
69178
|
}
|
|
69030
|
-
|
|
69031
|
-
|
|
69032
|
-
|
|
69033
|
-
|
|
69034
|
-
|
|
69035
|
-
|
|
69036
|
-
|
|
69037
|
-
|
|
69038
|
-
|
|
69039
|
-
|
|
69040
|
-
|
|
69179
|
+
function publicState(state) {
|
|
69180
|
+
if (!state) return { status: "not_authenticated", server_validity_checked: false };
|
|
69181
|
+
const expired = Date.parse(state.expires_at) <= Date.now();
|
|
69182
|
+
return {
|
|
69183
|
+
status: expired ? "expired" : state.state === "active" ? "authenticated_locally" : "authorization_pending",
|
|
69184
|
+
expires_at: state.expires_at,
|
|
69185
|
+
server_validity_checked: false,
|
|
69186
|
+
...state.state === "pending" && !expired ? {
|
|
69187
|
+
verification_uri: state.verification_uri,
|
|
69188
|
+
user_code: state.user_code,
|
|
69189
|
+
interval: state.interval,
|
|
69190
|
+
next_poll_at: state.next_poll_at
|
|
69191
|
+
} : {}
|
|
69041
69192
|
};
|
|
69042
|
-
guardedFetches.add(guardedFetch);
|
|
69043
|
-
globalThis.fetch = guardedFetch;
|
|
69044
69193
|
}
|
|
69045
|
-
|
|
69046
|
-
|
|
69047
|
-
|
|
69048
|
-
|
|
69049
|
-
|
|
69050
|
-
|
|
69051
|
-
|
|
69052
|
-
|
|
69053
|
-
|
|
69054
|
-
}
|
|
69055
|
-
function assertRemembranceNetworkEgressAllowed(capability) {
|
|
69056
|
-
const authority = networkExecutionAuthority.getStore();
|
|
69057
|
-
if (authority?.networkBehavior === "local_only") {
|
|
69058
|
-
throw new Error(
|
|
69059
|
-
`Local-only tool attempted network egress through ${capability}: ${authority.toolName}.`
|
|
69060
|
-
);
|
|
69194
|
+
function getLocalAdminSession(baseUrl) {
|
|
69195
|
+
try {
|
|
69196
|
+
return { ok: true, ...publicState(readState(baseUrl)) };
|
|
69197
|
+
} catch {
|
|
69198
|
+
return { ok: false, status: 0, server_validity_checked: false, body: {
|
|
69199
|
+
code: "admin_local_storage_unavailable",
|
|
69200
|
+
error: "Administrative credential storage is unavailable.",
|
|
69201
|
+
delivery: "not_delivered"
|
|
69202
|
+
} };
|
|
69061
69203
|
}
|
|
69062
69204
|
}
|
|
69063
|
-
|
|
69064
|
-
|
|
69065
|
-
|
|
69066
|
-
|
|
69067
|
-
|
|
69068
|
-
return delegate.call(globalThis, input, init);
|
|
69069
|
-
};
|
|
69070
|
-
return Object.freeze({ request });
|
|
69071
|
-
}
|
|
69205
|
+
|
|
69206
|
+
// src/admin-control-vault.ts
|
|
69207
|
+
import { createHash as createHash8, randomBytes as randomBytes10 } from "node:crypto";
|
|
69208
|
+
import { mkdirSync as mkdirSync4, renameSync as renameSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
69209
|
+
import { dirname as dirname8, join as join13 } from "node:path";
|
|
69072
69210
|
|
|
69073
69211
|
// src/connection-status.ts
|
|
69074
69212
|
import {
|
|
69075
69213
|
chmodSync as chmodSync2,
|
|
69076
69214
|
existsSync as existsSync5,
|
|
69077
69215
|
lstatSync as lstatSync4,
|
|
69078
|
-
mkdirSync as
|
|
69079
|
-
renameSync as
|
|
69216
|
+
mkdirSync as mkdirSync3,
|
|
69217
|
+
renameSync as renameSync3,
|
|
69080
69218
|
rmSync as rmSync2,
|
|
69081
|
-
writeFileSync as
|
|
69219
|
+
writeFileSync as writeFileSync3
|
|
69082
69220
|
} from "node:fs";
|
|
69083
|
-
import { createHash as
|
|
69221
|
+
import { createHash as createHash7, randomBytes as randomBytes9 } from "node:crypto";
|
|
69084
69222
|
import { isIP } from "node:net";
|
|
69085
|
-
import { homedir as
|
|
69086
|
-
import { join as
|
|
69223
|
+
import { homedir as homedir10 } from "node:os";
|
|
69224
|
+
import { join as join12 } from "node:path";
|
|
69087
69225
|
|
|
69088
69226
|
// src/codex-hook-approval.ts
|
|
69089
|
-
import { homedir as
|
|
69090
|
-
import { basename as basename2, dirname as
|
|
69227
|
+
import { homedir as homedir8 } from "node:os";
|
|
69228
|
+
import { basename as basename2, dirname as dirname7, join as join10 } from "node:path";
|
|
69091
69229
|
import { fileURLToPath } from "node:url";
|
|
69092
69230
|
|
|
69093
69231
|
// src/codex-managed-hooks.ts
|
|
69094
69232
|
import { readFileSync, statSync } from "node:fs";
|
|
69095
|
-
import { homedir as
|
|
69096
|
-
import { join as
|
|
69233
|
+
import { homedir as homedir7, userInfo as userInfo3 } from "node:os";
|
|
69234
|
+
import { join as join9 } from "node:path";
|
|
69097
69235
|
var SETTING = "allow_managed_hooks_only";
|
|
69098
69236
|
var PREFERENCE_FILE = "com.openai.codex.plist";
|
|
69099
69237
|
var PREFERENCE_KEY = "requirements_toml_base64";
|
|
@@ -69102,27 +69240,27 @@ var MAX_SOURCE_BYTES = 1024 * 1024;
|
|
|
69102
69240
|
function codexManagedPolicySources(env, platform = process.platform) {
|
|
69103
69241
|
const root = env.REMEMBRANCE_CODEX_MANAGED_POLICY_ROOT ? String(env.REMEMBRANCE_CODEX_MANAGED_POLICY_ROOT) : "/";
|
|
69104
69242
|
return {
|
|
69105
|
-
requirementsFile: platform === "win32" ? null :
|
|
69243
|
+
requirementsFile: platform === "win32" ? null : join9(root, "etc", "codex", "requirements.toml"),
|
|
69106
69244
|
// Forced (MDM) values for this user, then for the device, then the
|
|
69107
69245
|
// user's and the machine's own preferences. The ByHost and global
|
|
69108
69246
|
// domains are not read.
|
|
69109
69247
|
preferenceFiles: platform === "darwin" ? [
|
|
69110
|
-
|
|
69248
|
+
join9(
|
|
69111
69249
|
root,
|
|
69112
69250
|
"Library",
|
|
69113
69251
|
"Managed Preferences",
|
|
69114
69252
|
userInfo3().username,
|
|
69115
69253
|
PREFERENCE_FILE
|
|
69116
69254
|
),
|
|
69117
|
-
|
|
69118
|
-
|
|
69119
|
-
|
|
69255
|
+
join9(root, "Library", "Managed Preferences", PREFERENCE_FILE),
|
|
69256
|
+
join9(root, homedir7(), "Library", "Preferences", PREFERENCE_FILE),
|
|
69257
|
+
join9(root, "Library", "Preferences", PREFERENCE_FILE)
|
|
69120
69258
|
] : []
|
|
69121
69259
|
};
|
|
69122
69260
|
}
|
|
69123
69261
|
function codexRunsOnlyManagedHooks(codexHome, sources) {
|
|
69124
69262
|
const settings = /* @__PURE__ */ new Set([
|
|
69125
|
-
cloudSetting(
|
|
69263
|
+
cloudSetting(join9(codexHome, CLOUD_CACHE)),
|
|
69126
69264
|
preferenceSetting(sources.preferenceFiles),
|
|
69127
69265
|
sources.requirementsFile === null ? void 0 : fileSetting(sources.requirementsFile)
|
|
69128
69266
|
]);
|
|
@@ -69393,19 +69531,19 @@ function readCodexHookApproval(options = {}) {
|
|
|
69393
69531
|
if (host.trim().toLowerCase() !== "codex") return null;
|
|
69394
69532
|
const unknown = { status: "unknown" };
|
|
69395
69533
|
try {
|
|
69396
|
-
const root = options.pluginRoot ??
|
|
69397
|
-
let codexHome =
|
|
69534
|
+
const root = options.pluginRoot ?? dirname7(dirname7(fileURLToPath(import.meta.url)));
|
|
69535
|
+
let codexHome = dirname7(root);
|
|
69398
69536
|
for (const name of CACHE_LAYOUT) {
|
|
69399
69537
|
if (basename2(codexHome) !== name) return unknown;
|
|
69400
|
-
codexHome =
|
|
69538
|
+
codexHome = dirname7(codexHome);
|
|
69401
69539
|
}
|
|
69402
69540
|
const hooksFile = readBounded(
|
|
69403
|
-
|
|
69541
|
+
join10(root, "hooks", "hooks.json"),
|
|
69404
69542
|
MAX_HOOKS_BYTES
|
|
69405
69543
|
);
|
|
69406
69544
|
const hooks = hooksFile && expectedHooks(hooksFile.toString("utf8"));
|
|
69407
69545
|
const trusted = trustedHashes(
|
|
69408
|
-
readBounded(
|
|
69546
|
+
readBounded(join10(codexHome, "config.toml"), MAX_CONFIG_BYTES)?.toString(
|
|
69409
69547
|
"utf8"
|
|
69410
69548
|
) ?? ""
|
|
69411
69549
|
);
|
|
@@ -69507,10 +69645,10 @@ function tablePath(text) {
|
|
|
69507
69645
|
}
|
|
69508
69646
|
}
|
|
69509
69647
|
function sessionStartObserved(env, version) {
|
|
69510
|
-
const directory = env.REMEMBRANCE_PLUGIN_HEALTH_DIR ? String(env.REMEMBRANCE_PLUGIN_HEALTH_DIR) :
|
|
69648
|
+
const directory = env.REMEMBRANCE_PLUGIN_HEALTH_DIR ? String(env.REMEMBRANCE_PLUGIN_HEALTH_DIR) : join10(homedir8(), ".cache", "remembrance", "plugin-health");
|
|
69511
69649
|
try {
|
|
69512
69650
|
const marker = JSON.parse(
|
|
69513
|
-
String(readBounded(
|
|
69651
|
+
String(readBounded(join10(directory, "codex.json"), MAX_MARKER_BYTES))
|
|
69514
69652
|
);
|
|
69515
69653
|
return isRecord7(marker) && marker.plugin_version === version && isRecord7(marker.components) && Number.isFinite(Date.parse(String(marker.components.session_start)));
|
|
69516
69654
|
} catch {
|
|
@@ -69530,8 +69668,8 @@ function isRecord7(value) {
|
|
|
69530
69668
|
// src/local-agent-identity.ts
|
|
69531
69669
|
import { createPrivateKey, createPublicKey as createPublicKey4 } from "node:crypto";
|
|
69532
69670
|
import { existsSync as existsSync4 } from "node:fs";
|
|
69533
|
-
import { homedir as
|
|
69534
|
-
import { join as
|
|
69671
|
+
import { homedir as homedir9 } from "node:os";
|
|
69672
|
+
import { join as join11 } from "node:path";
|
|
69535
69673
|
var nodeFileSystem = {
|
|
69536
69674
|
exists: existsSync4,
|
|
69537
69675
|
read: (path, maxBytes = MAX_LOCAL_IDENTITY_BYTES) => readSecureLocalText(path, {
|
|
@@ -69546,11 +69684,11 @@ var supportedProviders = /* @__PURE__ */ new Set([
|
|
|
69546
69684
|
"cursor",
|
|
69547
69685
|
"claude_code"
|
|
69548
69686
|
]);
|
|
69549
|
-
function localAgentIdentityPath(env = process.env, homeDirectory =
|
|
69687
|
+
function localAgentIdentityPath(env = process.env, homeDirectory = homedir9()) {
|
|
69550
69688
|
const explicit = env.REMEMBRANCE_AGENT_KEY_PATH?.trim();
|
|
69551
69689
|
if (explicit) return explicit;
|
|
69552
|
-
return
|
|
69553
|
-
env.XDG_CONFIG_HOME ??
|
|
69690
|
+
return join11(
|
|
69691
|
+
env.XDG_CONFIG_HOME ?? join11(homeDirectory, ".config"),
|
|
69554
69692
|
"remembrance",
|
|
69555
69693
|
"agent-key.json"
|
|
69556
69694
|
);
|
|
@@ -69730,15 +69868,15 @@ function recordConnectionDoctorLifecycleProbe(options = {}) {
|
|
|
69730
69868
|
const env = options.env ?? process.env;
|
|
69731
69869
|
const rawSurface = String(env.REMEMBRANCE_PLUGIN_HOST ?? "").trim().toLowerCase();
|
|
69732
69870
|
if (!isPluginHostSurface(rawSurface)) return false;
|
|
69733
|
-
const healthDir = env.REMEMBRANCE_PLUGIN_HEALTH_DIR ? String(env.REMEMBRANCE_PLUGIN_HEALTH_DIR) :
|
|
69734
|
-
options.homeDirectory ??
|
|
69871
|
+
const healthDir = env.REMEMBRANCE_PLUGIN_HEALTH_DIR ? String(env.REMEMBRANCE_PLUGIN_HEALTH_DIR) : join12(
|
|
69872
|
+
options.homeDirectory ?? homedir10(),
|
|
69735
69873
|
".cache",
|
|
69736
69874
|
"remembrance",
|
|
69737
69875
|
"plugin-health"
|
|
69738
69876
|
);
|
|
69739
|
-
const path =
|
|
69877
|
+
const path = join12(healthDir, `${rawSurface}.json`);
|
|
69740
69878
|
if (!existsSync5(path)) return false;
|
|
69741
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
69879
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes9(6).toString("hex")}.tmp`;
|
|
69742
69880
|
try {
|
|
69743
69881
|
const parsed = JSON.parse(
|
|
69744
69882
|
readSecureLocalText(path, {
|
|
@@ -69748,13 +69886,13 @@ function recordConnectionDoctorLifecycleProbe(options = {}) {
|
|
|
69748
69886
|
if (!isRecord9(parsed) || parsed.surface !== rawSurface) return false;
|
|
69749
69887
|
const components = isRecord9(parsed.components) ? parsed.components : {};
|
|
69750
69888
|
if (typeof components.session_start !== "string") return false;
|
|
69751
|
-
|
|
69889
|
+
mkdirSync3(healthDir, { recursive: true, mode: 448 });
|
|
69752
69890
|
const directoryMetadata = lstatSync4(healthDir);
|
|
69753
69891
|
if (directoryMetadata.isSymbolicLink() || !directoryMetadata.isDirectory()) {
|
|
69754
69892
|
return false;
|
|
69755
69893
|
}
|
|
69756
69894
|
chmodSync2(healthDir, 448);
|
|
69757
|
-
|
|
69895
|
+
writeFileSync3(
|
|
69758
69896
|
temporaryPath,
|
|
69759
69897
|
`${JSON.stringify({
|
|
69760
69898
|
...parsed,
|
|
@@ -69766,7 +69904,7 @@ function recordConnectionDoctorLifecycleProbe(options = {}) {
|
|
|
69766
69904
|
`,
|
|
69767
69905
|
{ mode: 384, flag: "wx" }
|
|
69768
69906
|
);
|
|
69769
|
-
|
|
69907
|
+
renameSync3(temporaryPath, path);
|
|
69770
69908
|
chmodSync2(path, 384);
|
|
69771
69909
|
return true;
|
|
69772
69910
|
} catch {
|
|
@@ -69777,10 +69915,6 @@ function recordConnectionDoctorLifecycleProbe(options = {}) {
|
|
|
69777
69915
|
return false;
|
|
69778
69916
|
}
|
|
69779
69917
|
}
|
|
69780
|
-
function remembranceConfigPath(env = process.env, homeDirectory = homedir9()) {
|
|
69781
|
-
const configRoot = env.REMEMBRANCE_PLUGIN_HOST?.trim().toLowerCase() === "openclaw" ? join10(homeDirectory, ".config") : env.XDG_CONFIG_HOME ?? join10(homeDirectory, ".config");
|
|
69782
|
-
return join10(configRoot, "remembrance", "config.json");
|
|
69783
|
-
}
|
|
69784
69918
|
function resolveApiCredential(env = process.env, fileSystem = nodeFileSystem2) {
|
|
69785
69919
|
return resolveApiAccess(env, fileSystem).credential;
|
|
69786
69920
|
}
|
|
@@ -70015,7 +70149,7 @@ function localHostPolicyStatus(options) {
|
|
|
70015
70149
|
explanation: "This host does not expose a reliable failed-tool or permission event to the plugin."
|
|
70016
70150
|
};
|
|
70017
70151
|
}
|
|
70018
|
-
const directory = env.REMEMBRANCE_PLUGIN_ALERT_DIR ? String(env.REMEMBRANCE_PLUGIN_ALERT_DIR) :
|
|
70152
|
+
const directory = env.REMEMBRANCE_PLUGIN_ALERT_DIR ? String(env.REMEMBRANCE_PLUGIN_ALERT_DIR) : join12(homedir10(), ".cache", "remembrance", "plugin-alerts");
|
|
70019
70153
|
const names = fileSystem.list ? (() => {
|
|
70020
70154
|
try {
|
|
70021
70155
|
return fileSystem.list?.(directory) ?? [];
|
|
@@ -70033,7 +70167,7 @@ function localHostPolicyStatus(options) {
|
|
|
70033
70167
|
const sessionHash = name.split(".")[1];
|
|
70034
70168
|
const parsed = JSON.parse(
|
|
70035
70169
|
fileSystem.read(
|
|
70036
|
-
|
|
70170
|
+
join12(directory, name),
|
|
70037
70171
|
MAX_LOCAL_LIFECYCLE_MARKER_BYTES
|
|
70038
70172
|
)
|
|
70039
70173
|
);
|
|
@@ -70097,13 +70231,13 @@ function localPluginLifecycleHealth(options) {
|
|
|
70097
70231
|
}
|
|
70098
70232
|
const surface = rawSurface;
|
|
70099
70233
|
const host = agentHostBySurface(surface);
|
|
70100
|
-
const healthDir = env.REMEMBRANCE_PLUGIN_HEALTH_DIR ? String(env.REMEMBRANCE_PLUGIN_HEALTH_DIR) :
|
|
70234
|
+
const healthDir = env.REMEMBRANCE_PLUGIN_HEALTH_DIR ? String(env.REMEMBRANCE_PLUGIN_HEALTH_DIR) : join12(homedir10(), ".cache", "remembrance", "plugin-health");
|
|
70101
70235
|
const paths = lifecycleMarkerPaths(surface, healthDir, fileSystem);
|
|
70102
70236
|
if (paths.length === 0) {
|
|
70103
70237
|
return missingPluginLifecycleHealth(surface);
|
|
70104
70238
|
}
|
|
70105
70239
|
const nowMs = (options.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
70106
|
-
const genericPath =
|
|
70240
|
+
const genericPath = join12(healthDir, `${surface}.json`);
|
|
70107
70241
|
const markerEntries = [];
|
|
70108
70242
|
for (const path of paths) {
|
|
70109
70243
|
try {
|
|
@@ -70381,7 +70515,7 @@ function apiDestinationStatus(baseUrl, source) {
|
|
|
70381
70515
|
return {
|
|
70382
70516
|
kind: normalized2 === "https://remembrance.dev" ? "remembrance_cloud" : "custom",
|
|
70383
70517
|
source,
|
|
70384
|
-
fingerprint:
|
|
70518
|
+
fingerprint: createHash7("sha256").update(normalized2, "utf8").digest("hex").slice(0, 16)
|
|
70385
70519
|
};
|
|
70386
70520
|
}
|
|
70387
70521
|
function missingPluginLifecycleHealth(surface) {
|
|
@@ -70413,7 +70547,7 @@ function emptyPluginComponents() {
|
|
|
70413
70547
|
);
|
|
70414
70548
|
}
|
|
70415
70549
|
function lifecycleMarkerPaths(surface, healthDir, fileSystem) {
|
|
70416
|
-
const legacyPath =
|
|
70550
|
+
const legacyPath = join12(healthDir, `${surface}.json`);
|
|
70417
70551
|
const paths = fileSystem.exists(legacyPath) ? [legacyPath] : [];
|
|
70418
70552
|
const listed = fileSystem.list ? (() => {
|
|
70419
70553
|
try {
|
|
@@ -70424,7 +70558,7 @@ function lifecycleMarkerPaths(surface, healthDir, fileSystem) {
|
|
|
70424
70558
|
})() : [];
|
|
70425
70559
|
const sessionPaths = listed.filter(
|
|
70426
70560
|
(name) => name.startsWith(`${surface}.`) && name.endsWith(".json") && /^[a-z_]+\.[a-f0-9]{24}\.json$/.test(name)
|
|
70427
|
-
).slice(0, MAX_LOCAL_LIFECYCLE_MARKERS - paths.length).map((name) =>
|
|
70561
|
+
).slice(0, MAX_LOCAL_LIFECYCLE_MARKERS - paths.length).map((name) => join12(healthDir, name));
|
|
70428
70562
|
paths.push(...sessionPaths);
|
|
70429
70563
|
return [...new Set(paths)].slice(0, MAX_LOCAL_LIFECYCLE_MARKERS);
|
|
70430
70564
|
}
|
|
@@ -70526,6 +70660,402 @@ function isRecord9(value) {
|
|
|
70526
70660
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
70527
70661
|
}
|
|
70528
70662
|
|
|
70663
|
+
// src/admin-control-vault.ts
|
|
70664
|
+
var ADMIN_CREDENTIAL_ISSUANCE_OPERATIONS = Object.freeze(["api_keys.create", "agents.member_link.create"]);
|
|
70665
|
+
var recordSchema = external_exports.object({
|
|
70666
|
+
version: external_exports.literal("admin-credential-vault-v1"),
|
|
70667
|
+
base_url: external_exports.string(),
|
|
70668
|
+
operation: external_exports.enum(["api_keys.create", "agents.member_link.create"]),
|
|
70669
|
+
org_id: external_exports.string().regex(/^org_[a-f0-9]{18}$/).optional(),
|
|
70670
|
+
request_id: external_exports.string().regex(/^acreq_[a-f0-9]{32}$/),
|
|
70671
|
+
request_digest: external_exports.string().regex(/^[a-f0-9]{64}$/),
|
|
70672
|
+
state: external_exports.enum(["pending", "not_delivered", "stored"]),
|
|
70673
|
+
created_at: external_exports.string().datetime(),
|
|
70674
|
+
secret: external_exports.string().min(1).max(4096).optional(),
|
|
70675
|
+
key_id: external_exports.string().regex(/^key_[a-f0-9]{18}$/).optional(),
|
|
70676
|
+
expires_at: external_exports.string().datetime().optional()
|
|
70677
|
+
}).strict();
|
|
70678
|
+
function pathFor(baseUrl, requestId) {
|
|
70679
|
+
const destination = createHash8("sha256").update(baseUrl).digest("hex");
|
|
70680
|
+
return join13(dirname8(remembranceConfigPath()), "admin-credential-vault", destination, `${requestId}.json`);
|
|
70681
|
+
}
|
|
70682
|
+
function privateDirectory(path) {
|
|
70683
|
+
mkdirSync4(path, { recursive: true, mode: 448 });
|
|
70684
|
+
assertSecurePrivateLocalDirectory(path);
|
|
70685
|
+
}
|
|
70686
|
+
function prepareAdminCredentialDelivery(baseUrl, payload) {
|
|
70687
|
+
if (!ADMIN_CREDENTIAL_ISSUANCE_OPERATIONS.includes(String(payload.operation))) return null;
|
|
70688
|
+
const requestId = external_exports.string().regex(/^acreq_[a-f0-9]{32}$/).parse(payload.request_id);
|
|
70689
|
+
const path = pathFor(baseUrl, requestId);
|
|
70690
|
+
privateDirectory(dirname8(dirname8(path)));
|
|
70691
|
+
privateDirectory(dirname8(path));
|
|
70692
|
+
const digest3 = createHash8("sha256").update(canonicalJson(payload)).digest("hex");
|
|
70693
|
+
try {
|
|
70694
|
+
const existing = recordSchema.parse(JSON.parse(readSecureLocalText(path, { maxBytes: 16384 })));
|
|
70695
|
+
if (existing.base_url !== baseUrl || existing.request_digest !== digest3 || existing.request_id !== requestId || existing.operation !== payload.operation) throw Error("Credential delivery identity conflict.");
|
|
70696
|
+
if (existing.state === "stored" && !existing.secret) throw Error("Stored credential is unavailable.");
|
|
70697
|
+
return { path, record: existing, readyToIssue: existing.state === "not_delivered" };
|
|
70698
|
+
} catch (error) {
|
|
70699
|
+
if (!(error && typeof error === "object" && "code" in error && error.code === "ENOENT")) throw error;
|
|
70700
|
+
}
|
|
70701
|
+
const record4 = recordSchema.parse({
|
|
70702
|
+
version: "admin-credential-vault-v1",
|
|
70703
|
+
base_url: baseUrl,
|
|
70704
|
+
operation: payload.operation,
|
|
70705
|
+
request_id: requestId,
|
|
70706
|
+
request_digest: digest3,
|
|
70707
|
+
state: "pending",
|
|
70708
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
70709
|
+
...payload.org_id ? { org_id: payload.org_id } : {}
|
|
70710
|
+
});
|
|
70711
|
+
writeFileSync4(path, JSON.stringify(record4), { mode: 384, flag: "wx" });
|
|
70712
|
+
return { path, record: record4, readyToIssue: true };
|
|
70713
|
+
}
|
|
70714
|
+
function save(delivery, record4) {
|
|
70715
|
+
const temporary = `${delivery.path}.${randomBytes10(8).toString("hex")}.tmp`;
|
|
70716
|
+
try {
|
|
70717
|
+
writeFileSync4(temporary, JSON.stringify(recordSchema.parse(record4)), { mode: 384, flag: "wx" });
|
|
70718
|
+
renameSync4(temporary, delivery.path);
|
|
70719
|
+
delivery.record = record4;
|
|
70720
|
+
} finally {
|
|
70721
|
+
try {
|
|
70722
|
+
unlinkSync2(temporary);
|
|
70723
|
+
} catch {
|
|
70724
|
+
}
|
|
70725
|
+
}
|
|
70726
|
+
}
|
|
70727
|
+
function adminCredentialDeliveryReceipt(delivery) {
|
|
70728
|
+
return {
|
|
70729
|
+
request_id: delivery.record.request_id,
|
|
70730
|
+
operation: delivery.record.operation,
|
|
70731
|
+
one_time_secret_stored: true,
|
|
70732
|
+
vault_reference: delivery.path,
|
|
70733
|
+
...delivery.record.key_id ? { key_id: delivery.record.key_id } : {},
|
|
70734
|
+
...delivery.record.expires_at ? { expires_at: delivery.record.expires_at } : {},
|
|
70735
|
+
instruction: "The one-time credential is in a separate mode-0600 local vault. Configure its intended client using local secret handling; never print it, copy it into chat, or replace the current organization credential implicitly."
|
|
70736
|
+
};
|
|
70737
|
+
}
|
|
70738
|
+
function adminCredentialUnknownReceipt(delivery) {
|
|
70739
|
+
return { ok: false, status: 0, body: {
|
|
70740
|
+
code: "admin_credential_delivery_unknown",
|
|
70741
|
+
delivery: "unknown",
|
|
70742
|
+
request_id: delivery.record.request_id,
|
|
70743
|
+
operation: delivery.record.operation,
|
|
70744
|
+
retry_automatically: false,
|
|
70745
|
+
next_action: { tool: "admin_read", arguments: {
|
|
70746
|
+
operation: "admin.operations.status",
|
|
70747
|
+
...delivery.record.org_id ? { org_id: delivery.record.org_id } : {},
|
|
70748
|
+
input: { request_id: delivery.record.request_id }
|
|
70749
|
+
} },
|
|
70750
|
+
instruction: delivery.record.operation === "api_keys.create" ? "Do not mint a replacement under a new request_id. Read this exact operation receipt, then inspect api_keys.list. If issuance succeeded but delivery was lost, explicitly revoke its issued key ID before requesting another. This vault reservation contains no recoverable secret yet." : "Do not mint a replacement under a new request_id. Read this exact operation receipt. An undelivered member-link credential expires automatically; confirm the existing link has expired before requesting another. This vault reservation contains no recoverable secret yet."
|
|
70751
|
+
} };
|
|
70752
|
+
}
|
|
70753
|
+
function markAdminCredentialNotDelivered(delivery) {
|
|
70754
|
+
save(delivery, { ...delivery.record, state: "not_delivered" });
|
|
70755
|
+
}
|
|
70756
|
+
function reserveAdminCredentialRetry(delivery) {
|
|
70757
|
+
save(delivery, { ...delivery.record, state: "pending" });
|
|
70758
|
+
}
|
|
70759
|
+
function storeIssuedAdminCredential(delivery, body) {
|
|
70760
|
+
const envelope2 = body && typeof body === "object" ? body : {};
|
|
70761
|
+
if (envelope2.operation !== delivery.record.operation || envelope2.request_id !== delivery.record.request_id || !envelope2.result || typeof envelope2.result !== "object") return false;
|
|
70762
|
+
const result = envelope2.result;
|
|
70763
|
+
const secret = delivery.record.operation === "api_keys.create" ? result.api_key : result.token;
|
|
70764
|
+
const grammar = delivery.record.operation === "api_keys.create" ? /^rem_[A-Za-z0-9_-]{43}$/ : /^mlink_[A-Za-z0-9_-]{43}$/;
|
|
70765
|
+
if (typeof secret !== "string" || !grammar.test(secret)) return false;
|
|
70766
|
+
const key = result.key && typeof result.key === "object" ? result.key : {};
|
|
70767
|
+
save(delivery, {
|
|
70768
|
+
...delivery.record,
|
|
70769
|
+
state: "stored",
|
|
70770
|
+
secret,
|
|
70771
|
+
...typeof key.id === "string" && /^key_[a-f0-9]{18}$/.test(key.id) ? { key_id: key.id } : {},
|
|
70772
|
+
...external_exports.string().datetime().safeParse(result.expires_at).success ? { expires_at: result.expires_at } : {}
|
|
70773
|
+
});
|
|
70774
|
+
return true;
|
|
70775
|
+
}
|
|
70776
|
+
|
|
70777
|
+
// src/admin-control-client.ts
|
|
70778
|
+
var MAX_RESPONSE_BYTES = ADMIN_CONTROL_MAX_RESPONSE_BYTES;
|
|
70779
|
+
function failure(code, status, delivery = "unknown", requestId) {
|
|
70780
|
+
return { ok: false, status, body: {
|
|
70781
|
+
code,
|
|
70782
|
+
error: "Administrative operation unavailable.",
|
|
70783
|
+
delivery,
|
|
70784
|
+
...requestId ? { request_id: requestId } : {},
|
|
70785
|
+
retry_automatically: false,
|
|
70786
|
+
...code === "admin_session_unauthorized" || code === "admin_authorization_exchange_failed" ? { next_action: "Call end_admin_session, then begin_admin_login for fresh browser approval. Never replace ordinary organization credentials." } : code === "admin_session_expired" || code === "admin_authentication_required" ? { next_action: "Call begin_admin_login for browser approval, or configure an authorized organization admin key separately." } : code === "admin_credential_vault_unavailable" ? { next_action: "No credential issuance was sent. Restore user-owned, private and writable local vault storage, or inspect this request_id's existing vault reservation. Never change a reserved request's input or silently mint a replacement." } : {}
|
|
70787
|
+
} };
|
|
70788
|
+
}
|
|
70789
|
+
async function readJson(response) {
|
|
70790
|
+
if (!response.body) throw new Error();
|
|
70791
|
+
const reader = response.body.getReader();
|
|
70792
|
+
const chunks = [];
|
|
70793
|
+
let bytes = 0;
|
|
70794
|
+
try {
|
|
70795
|
+
for (; ; ) {
|
|
70796
|
+
const next = await reader.read();
|
|
70797
|
+
if (next.done) break;
|
|
70798
|
+
bytes += next.value.byteLength;
|
|
70799
|
+
if (bytes > MAX_RESPONSE_BYTES) throw new Error();
|
|
70800
|
+
chunks.push(next.value);
|
|
70801
|
+
}
|
|
70802
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
70803
|
+
} finally {
|
|
70804
|
+
await reader.cancel().catch(() => {
|
|
70805
|
+
});
|
|
70806
|
+
reader.releaseLock();
|
|
70807
|
+
}
|
|
70808
|
+
}
|
|
70809
|
+
async function request(transport, baseUrl, path, method, payload, credential, requestId) {
|
|
70810
|
+
const controller = new AbortController();
|
|
70811
|
+
const timer = setTimeout(() => controller.abort(), 3e4);
|
|
70812
|
+
try {
|
|
70813
|
+
const headers = { "content-type": "application/json" };
|
|
70814
|
+
if (credential?.adminToken) headers["x-remembrance-admin-token"] = credential.adminToken;
|
|
70815
|
+
else if (credential?.apiKey) headers["x-remembrance-api-key"] = credential.apiKey;
|
|
70816
|
+
if (requestId) headers["Idempotency-Key"] = requestId;
|
|
70817
|
+
const response = await transport.request(`${baseUrl}${path}`, {
|
|
70818
|
+
method,
|
|
70819
|
+
headers,
|
|
70820
|
+
redirect: "manual",
|
|
70821
|
+
signal: controller.signal,
|
|
70822
|
+
...payload !== void 0 ? { body: JSON.stringify(payload) } : {}
|
|
70823
|
+
});
|
|
70824
|
+
if (response.status >= 300 && response.status < 400) return { response, body: null, redirect: true };
|
|
70825
|
+
return { response, body: await readJson(response), redirect: false };
|
|
70826
|
+
} finally {
|
|
70827
|
+
clearTimeout(timer);
|
|
70828
|
+
}
|
|
70829
|
+
}
|
|
70830
|
+
async function callAdminControlTool(name, payload, access, transport) {
|
|
70831
|
+
const baseUrl = access.configuration.baseUrl;
|
|
70832
|
+
const requestId = name === "admin_write" ? String(payload.request_id) : void 0;
|
|
70833
|
+
let reservedDelivery = null;
|
|
70834
|
+
if (access.configuration.source.startsWith("unusable_")) return failure("admin_destination_unavailable", 0, "not_delivered", requestId);
|
|
70835
|
+
try {
|
|
70836
|
+
secureDirectory(dirname9(storePath(baseUrl)));
|
|
70837
|
+
return await withPrivateOutboxLock(dirname9(storePath(baseUrl)), "admin-session", async () => {
|
|
70838
|
+
const state = readState(baseUrl);
|
|
70839
|
+
if (name === "begin_admin_login") {
|
|
70840
|
+
if (state && Date.parse(state.expires_at) > Date.now()) return { ok: true, ...publicState(state) };
|
|
70841
|
+
const verifier = randomBytes11(32).toString("base64url");
|
|
70842
|
+
const result2 = await request(transport, baseUrl, "/api/v1/admin/agent-sessions/authorize", "POST", {
|
|
70843
|
+
code_challenge: createHash9("sha256").update(verifier).digest("base64url"),
|
|
70844
|
+
code_challenge_method: "S256"
|
|
70845
|
+
});
|
|
70846
|
+
if (!result2.response.ok || result2.redirect) return failure("admin_authorization_unavailable", result2.response.status);
|
|
70847
|
+
const started = pendingSchema.omit({ state: true, base_url: true, code_verifier: true, next_poll_at: true }).parse(result2.body);
|
|
70848
|
+
const expectedUri = new URL("/admin/authorize-agent", baseUrl);
|
|
70849
|
+
expectedUri.searchParams.set("request_id", started.request_id);
|
|
70850
|
+
if (started.verification_uri !== expectedUri.toString() || Date.parse(started.expires_at) <= Date.now())
|
|
70851
|
+
return failure("admin_authorization_destination_invalid", 0, "not_delivered");
|
|
70852
|
+
const pending = {
|
|
70853
|
+
...started,
|
|
70854
|
+
state: "pending",
|
|
70855
|
+
base_url: baseUrl,
|
|
70856
|
+
code_verifier: verifier,
|
|
70857
|
+
next_poll_at: new Date(Date.now() + started.interval * 1e3).toISOString()
|
|
70858
|
+
};
|
|
70859
|
+
saveState(pending);
|
|
70860
|
+
return { ok: true, ...publicState(pending) };
|
|
70861
|
+
}
|
|
70862
|
+
if (name === "complete_admin_login") {
|
|
70863
|
+
if (!state || state.state !== "pending") return { ok: Boolean(state), ...publicState(state) };
|
|
70864
|
+
if (Date.parse(state.expires_at) <= Date.now()) return { ok: false, ...publicState(state) };
|
|
70865
|
+
if (Date.parse(state.next_poll_at) > Date.now()) return { ok: true, ...publicState(state) };
|
|
70866
|
+
saveState({ ...state, next_poll_at: new Date(Date.now() + state.interval * 1e3).toISOString() });
|
|
70867
|
+
const result2 = await request(transport, baseUrl, "/api/v1/admin/agent-sessions/token", "POST", {
|
|
70868
|
+
request_id: state.request_id,
|
|
70869
|
+
device_secret: state.device_secret,
|
|
70870
|
+
code_verifier: state.code_verifier
|
|
70871
|
+
});
|
|
70872
|
+
if (result2.response.status === 409 && result2.body && typeof result2.body === "object" && "code" in result2.body && result2.body.code === "authorization_pending")
|
|
70873
|
+
return { ok: true, ...publicState(readState(baseUrl)) };
|
|
70874
|
+
if (!result2.response.ok || result2.redirect) return failure("admin_authorization_exchange_failed", result2.response.status);
|
|
70875
|
+
const issued2 = external_exports.object({ access_token: activeSchema.shape.access_token, token_type: external_exports.literal("Bearer"), expires_at: timestamp2, session_id: id }).strict().parse(result2.body);
|
|
70876
|
+
if (issued2.session_id !== state.request_id || Date.parse(issued2.expires_at) <= Date.now()) return failure("admin_authorization_response_invalid", 0);
|
|
70877
|
+
const active = { state: "active", base_url: baseUrl, access_token: issued2.access_token, session_id: issued2.session_id, expires_at: issued2.expires_at };
|
|
70878
|
+
saveState(active);
|
|
70879
|
+
return { ok: true, ...publicState(active) };
|
|
70880
|
+
}
|
|
70881
|
+
if (name === "end_admin_session") {
|
|
70882
|
+
let revocationConfirmed = false;
|
|
70883
|
+
let sessionAlreadyInvalid = false;
|
|
70884
|
+
if (state?.state === "active") {
|
|
70885
|
+
const result2 = await request(transport, baseUrl, "/api/v1/admin/agent-sessions/current", "DELETE", void 0, { adminToken: state.access_token });
|
|
70886
|
+
const body = result2.body && typeof result2.body === "object" ? result2.body : {};
|
|
70887
|
+
revocationConfirmed = result2.response.ok && body.revoked === true;
|
|
70888
|
+
sessionAlreadyInvalid = result2.response.status === 401 && body.code === "admin_session_invalid" && body.delivery === "not_delivered";
|
|
70889
|
+
if (!revocationConfirmed && !sessionAlreadyInvalid)
|
|
70890
|
+
return failure("admin_revocation_outcome_unknown", result2.response.status);
|
|
70891
|
+
}
|
|
70892
|
+
if (state) unlinkSync3(storePath(baseUrl));
|
|
70893
|
+
return {
|
|
70894
|
+
ok: true,
|
|
70895
|
+
status: "signed_out",
|
|
70896
|
+
server_revocation_confirmed: revocationConfirmed,
|
|
70897
|
+
...sessionAlreadyInvalid ? { server_session_already_invalid: true } : {}
|
|
70898
|
+
};
|
|
70899
|
+
}
|
|
70900
|
+
if (state && state.state === "active" && Date.parse(state.expires_at) <= Date.now())
|
|
70901
|
+
return failure("admin_session_expired", 401, "not_delivered", requestId);
|
|
70902
|
+
const adminToken = state?.state === "active" ? state.access_token : void 0;
|
|
70903
|
+
if (!adminToken && (!access.credential.apiKey || access.credential.source.startsWith("unusable_")))
|
|
70904
|
+
return failure("admin_authentication_required", 401, "not_delivered", requestId);
|
|
70905
|
+
let delivery = null;
|
|
70906
|
+
try {
|
|
70907
|
+
delivery = name === "admin_write" ? prepareAdminCredentialDelivery(baseUrl, payload) : null;
|
|
70908
|
+
} catch {
|
|
70909
|
+
return failure("admin_credential_vault_unavailable", 0, "not_delivered", requestId);
|
|
70910
|
+
}
|
|
70911
|
+
reservedDelivery = delivery;
|
|
70912
|
+
if (delivery?.record.state === "stored") return { ok: true, status: 200, body: adminCredentialDeliveryReceipt(delivery) };
|
|
70913
|
+
if (delivery && !delivery.readyToIssue) return adminCredentialUnknownReceipt(delivery);
|
|
70914
|
+
if (delivery?.record.state === "not_delivered") reserveAdminCredentialRetry(delivery);
|
|
70915
|
+
const path = name === "get_admin_capabilities" ? `/api/v1/admin/control${payload.org_id ? `?org_id=${encodeURIComponent(String(payload.org_id))}` : ""}` : `/api/v1/admin/control/${name === "admin_read" ? "read" : "write"}`;
|
|
70916
|
+
const result = await request(
|
|
70917
|
+
transport,
|
|
70918
|
+
baseUrl,
|
|
70919
|
+
path,
|
|
70920
|
+
name === "get_admin_capabilities" ? "GET" : "POST",
|
|
70921
|
+
name === "get_admin_capabilities" ? void 0 : payload,
|
|
70922
|
+
{ adminToken, apiKey: adminToken ? void 0 : access.credential.apiKey },
|
|
70923
|
+
requestId
|
|
70924
|
+
);
|
|
70925
|
+
if (!result.response.ok || result.redirect) {
|
|
70926
|
+
const record4 = result.body && typeof result.body === "object" ? result.body : {};
|
|
70927
|
+
if (delivery && record4.delivery === "not_delivered") markAdminCredentialNotDelivered(delivery);
|
|
70928
|
+
return failure(
|
|
70929
|
+
result.response.status === 401 ? "admin_session_unauthorized" : "admin_operation_failed",
|
|
70930
|
+
result.response.status,
|
|
70931
|
+
record4.delivery === "not_delivered" ? "not_delivered" : "unknown",
|
|
70932
|
+
requestId
|
|
70933
|
+
);
|
|
70934
|
+
}
|
|
70935
|
+
const serialized = JSON.stringify(result.body);
|
|
70936
|
+
const secrets = [
|
|
70937
|
+
...access.credential.apiKey ? [access.credential.apiKey] : [],
|
|
70938
|
+
...state?.state === "active" ? [state.access_token] : state?.state === "pending" ? [state.code_verifier, state.device_secret] : []
|
|
70939
|
+
];
|
|
70940
|
+
if (secrets.some((secret) => serialized.includes(secret))) return failure("admin_response_invalid", result.response.status, "unknown", requestId);
|
|
70941
|
+
if (delivery) {
|
|
70942
|
+
if (!storeIssuedAdminCredential(delivery, result.body)) return adminCredentialUnknownReceipt(delivery);
|
|
70943
|
+
return { ok: true, status: result.response.status, body: adminCredentialDeliveryReceipt(delivery) };
|
|
70944
|
+
}
|
|
70945
|
+
return {
|
|
70946
|
+
ok: true,
|
|
70947
|
+
status: result.response.status,
|
|
70948
|
+
body: result.body,
|
|
70949
|
+
...name === "get_admin_capabilities" ? { server_validity_checked: true } : {}
|
|
70950
|
+
};
|
|
70951
|
+
}, { waitMs: 1e3 });
|
|
70952
|
+
} catch {
|
|
70953
|
+
if (reservedDelivery) return adminCredentialUnknownReceipt(reservedDelivery);
|
|
70954
|
+
return failure("admin_operation_unavailable", 0, "unknown", requestId);
|
|
70955
|
+
}
|
|
70956
|
+
}
|
|
70957
|
+
|
|
70958
|
+
// ../core/src/redaction-request-budget.ts
|
|
70959
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
70960
|
+
var requests = new AsyncLocalStorage3();
|
|
70961
|
+
trackRedactionRequests(() => requests.getStore());
|
|
70962
|
+
function withRedactionRequestBudget(run) {
|
|
70963
|
+
return requests.getStore() ? run() : requests.run({}, run);
|
|
70964
|
+
}
|
|
70965
|
+
|
|
70966
|
+
// src/review-repair-inspection.ts
|
|
70967
|
+
function inspectReviewRepairForTransport(value) {
|
|
70968
|
+
const request2 = privateSkillReviewRepairRequestSchema.parse(value);
|
|
70969
|
+
const inspection = inspectPrivateSkillCandidate(request2.capture);
|
|
70970
|
+
if (inspection.status === "complete" && inspection.decision.outcome === "unchanged") {
|
|
70971
|
+
const values = [];
|
|
70972
|
+
const pending = [request2.expected_review_snapshot];
|
|
70973
|
+
while (pending.length) {
|
|
70974
|
+
const entry = pending.pop();
|
|
70975
|
+
if (entry !== null && typeof entry === "object") pending.push(...Object.values(entry));
|
|
70976
|
+
else values.push(entry);
|
|
70977
|
+
}
|
|
70978
|
+
try {
|
|
70979
|
+
if (canonicalJson(withRedactionRequestBudget(() => redactPayload(values))) !== canonicalJson(values)) {
|
|
70980
|
+
return { ready: false, refusal: {
|
|
70981
|
+
status: "held",
|
|
70982
|
+
code: "review_repair_wire_inspection_hold",
|
|
70983
|
+
delivery: "not_delivered",
|
|
70984
|
+
candidate_sent: false,
|
|
70985
|
+
candidate_stored: false,
|
|
70986
|
+
original_disposition: "unchanged",
|
|
70987
|
+
next_action: "Retain the original. Read a fresh normal content-free review snapshot; do not send suspected secrets, rewrite the held request, or use another transport."
|
|
70988
|
+
} };
|
|
70989
|
+
}
|
|
70990
|
+
} catch {
|
|
70991
|
+
return { ready: false, refusal: {
|
|
70992
|
+
status: "held",
|
|
70993
|
+
code: "review_repair_wire_inspection_failure",
|
|
70994
|
+
delivery: "not_delivered",
|
|
70995
|
+
candidate_sent: false,
|
|
70996
|
+
candidate_stored: false,
|
|
70997
|
+
original_disposition: "unchanged",
|
|
70998
|
+
next_action: "Retain the original. Correct the local inspection failure before retrying; do not reformulate around an operational failure."
|
|
70999
|
+
} };
|
|
71000
|
+
}
|
|
71001
|
+
return { ready: true, request: request2 };
|
|
71002
|
+
}
|
|
71003
|
+
const reason = inspection.status === "complete" ? "authored_capture_changed_by_inspection" : inspection.status === "incomplete" ? inspection.reason : inspection.error_code;
|
|
71004
|
+
return { ready: false, refusal: {
|
|
71005
|
+
status: "held",
|
|
71006
|
+
code: "review_repair_local_inspection_hold",
|
|
71007
|
+
delivery: "not_delivered",
|
|
71008
|
+
candidate_sent: false,
|
|
71009
|
+
candidate_stored: false,
|
|
71010
|
+
original_disposition: "unchanged",
|
|
71011
|
+
reason_code: reason,
|
|
71012
|
+
inspection: inspection.decision,
|
|
71013
|
+
next_action: inspection.status === "invalid" ? "Retain the original. Correct the local inspection failure before retrying the same unchanged request; do not reformulate around an operational failure or use another transport." : "Retain the original. Prepare a complete safe replacement from authenticated task context and inspect it again. Do not recover suspected secrets, invent missing instructions, or bypass a host denial."
|
|
71014
|
+
} };
|
|
71015
|
+
}
|
|
71016
|
+
|
|
71017
|
+
// src/network-transport.ts
|
|
71018
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
71019
|
+
var networkExecutionAuthority = new AsyncLocalStorage4();
|
|
71020
|
+
var guardedFetches = /* @__PURE__ */ new WeakSet();
|
|
71021
|
+
function installRuntimeFetchGuard() {
|
|
71022
|
+
const delegate = globalThis.fetch;
|
|
71023
|
+
if (typeof delegate !== "function" || guardedFetches.has(delegate)) return;
|
|
71024
|
+
const guardedFetch = (input, init) => {
|
|
71025
|
+
assertRemembranceNetworkEgressAllowed("ambient fetch");
|
|
71026
|
+
return delegate.call(globalThis, input, init);
|
|
71027
|
+
};
|
|
71028
|
+
guardedFetches.add(guardedFetch);
|
|
71029
|
+
globalThis.fetch = guardedFetch;
|
|
71030
|
+
}
|
|
71031
|
+
installRuntimeFetchGuard();
|
|
71032
|
+
async function runWithRemembranceNetworkExecution(authority, operation) {
|
|
71033
|
+
const effectiveAuthority = restrictNetworkExecutionAuthority(authority);
|
|
71034
|
+
installRuntimeFetchGuard();
|
|
71035
|
+
return networkExecutionAuthority.run(effectiveAuthority, operation);
|
|
71036
|
+
}
|
|
71037
|
+
function restrictNetworkExecutionAuthority(requested) {
|
|
71038
|
+
const parent = networkExecutionAuthority.getStore();
|
|
71039
|
+
return parent?.networkBehavior === "local_only" ? parent : requested;
|
|
71040
|
+
}
|
|
71041
|
+
function assertRemembranceNetworkEgressAllowed(capability) {
|
|
71042
|
+
const authority = networkExecutionAuthority.getStore();
|
|
71043
|
+
if (authority?.networkBehavior === "local_only") {
|
|
71044
|
+
throw new Error(
|
|
71045
|
+
`Local-only tool attempted network egress through ${capability}: ${authority.toolName}.`
|
|
71046
|
+
);
|
|
71047
|
+
}
|
|
71048
|
+
}
|
|
71049
|
+
function createRemembranceNetworkTransport(fetchImpl) {
|
|
71050
|
+
assertRemembranceNetworkEgressAllowed("transport construction");
|
|
71051
|
+
const delegate = fetchImpl ?? globalThis.fetch;
|
|
71052
|
+
const request2 = (input, init) => {
|
|
71053
|
+
assertRemembranceNetworkEgressAllowed("transport request");
|
|
71054
|
+
return delegate.call(globalThis, input, init);
|
|
71055
|
+
};
|
|
71056
|
+
return Object.freeze({ request: request2 });
|
|
71057
|
+
}
|
|
71058
|
+
|
|
70529
71059
|
// src/private-skill-native-context-cli.ts
|
|
70530
71060
|
var MAX_NATIVE_EVENT_BYTES = 512 * 1024;
|
|
70531
71061
|
async function runPrivateSkillNativeContextCli(input = process.stdin, output = process.stdout) {
|
|
@@ -70666,7 +71196,7 @@ async function checkClientUpdate(input) {
|
|
|
70666
71196
|
// src/installed-client-version.ts
|
|
70667
71197
|
import { lstat as lstat4, readdir as readdir3, readFile as readFile2 } from "node:fs/promises";
|
|
70668
71198
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
70669
|
-
import { basename as basename3, dirname as
|
|
71199
|
+
import { basename as basename3, dirname as dirname10, join as join14 } from "node:path";
|
|
70670
71200
|
var MAX_MANIFEST_BYTES2 = 16 * 1024;
|
|
70671
71201
|
var MAX_ANCESTORS = 5;
|
|
70672
71202
|
var MAX_VERSION_SIBLINGS = 64;
|
|
@@ -70689,7 +71219,7 @@ async function detectInstalledClientVersion(input) {
|
|
|
70689
71219
|
} catch {
|
|
70690
71220
|
return unavailable3(input.runningVersion);
|
|
70691
71221
|
}
|
|
70692
|
-
const roots = ancestorDirectories(
|
|
71222
|
+
const roots = ancestorDirectories(dirname10(bundlePath));
|
|
70693
71223
|
const discovered = /* @__PURE__ */ new Set();
|
|
70694
71224
|
let versionedRoot = null;
|
|
70695
71225
|
for (const root of roots) {
|
|
@@ -70700,9 +71230,9 @@ async function detectInstalledClientVersion(input) {
|
|
|
70700
71230
|
break;
|
|
70701
71231
|
}
|
|
70702
71232
|
if (versionedRoot) {
|
|
70703
|
-
const parent =
|
|
71233
|
+
const parent = dirname10(versionedRoot);
|
|
70704
71234
|
for (const name of await boundedSafeDirectoryNames(parent)) {
|
|
70705
|
-
const siblingRoot =
|
|
71235
|
+
const siblingRoot = join14(parent, name);
|
|
70706
71236
|
const version = await readRemembranceVersion(siblingRoot, input.surface);
|
|
70707
71237
|
if (version === name) discovered.add(version);
|
|
70708
71238
|
}
|
|
@@ -70724,7 +71254,7 @@ function ancestorDirectories(start) {
|
|
|
70724
71254
|
let current = start;
|
|
70725
71255
|
for (let index = 0; index < MAX_ANCESTORS; index += 1) {
|
|
70726
71256
|
roots.push(current);
|
|
70727
|
-
const parent =
|
|
71257
|
+
const parent = dirname10(current);
|
|
70728
71258
|
if (parent === current) break;
|
|
70729
71259
|
current = parent;
|
|
70730
71260
|
}
|
|
@@ -70732,7 +71262,7 @@ function ancestorDirectories(start) {
|
|
|
70732
71262
|
}
|
|
70733
71263
|
async function readRemembranceVersion(root, surface) {
|
|
70734
71264
|
for (const relative of SURFACE_MANIFESTS[surface]) {
|
|
70735
|
-
const manifest = await readBoundedRegularJson(
|
|
71265
|
+
const manifest = await readBoundedRegularJson(join14(root, relative));
|
|
70736
71266
|
if (!manifest || !isRemembranceManifest(manifest)) continue;
|
|
70737
71267
|
const version = manifest.version;
|
|
70738
71268
|
if (typeof version === "string" && parseStableClientVersion(version)) {
|
|
@@ -70783,15 +71313,15 @@ function isRecord10(value) {
|
|
|
70783
71313
|
// src/legacy-lesson-destination-recovery.ts
|
|
70784
71314
|
var CONTRACT_VERSION = "private-lesson-legacy-destination-recovery-v1";
|
|
70785
71315
|
var DIGEST4 = /^sha256:[a-f0-9]{64}$/u;
|
|
70786
|
-
async function legacyLessonDestinationRecovery(draft, destination,
|
|
71316
|
+
async function legacyLessonDestinationRecovery(draft, destination, request2, dependencies) {
|
|
70787
71317
|
const alreadyRecovered = isRecoveredForDestination(draft, destination);
|
|
70788
71318
|
if (!ownerAttestedLegacyPrivateLessonRecoveryEligible(draft) && !alreadyRecovered) {
|
|
70789
71319
|
return refused(draft, "private_lesson_destination_recovery_ineligible");
|
|
70790
71320
|
}
|
|
70791
|
-
if (
|
|
71321
|
+
if (request2.action === "approve" && !validApproval(request2)) {
|
|
70792
71322
|
return refused(draft, "private_lesson_destination_recovery_approval_required");
|
|
70793
71323
|
}
|
|
70794
|
-
if (
|
|
71324
|
+
if (request2.action === "approve" && (request2.expected_payload_digest !== draft.payload_digest || canonicalJson(request2.expected_destination) !== canonicalJson(destination))) {
|
|
70795
71325
|
return refused(draft, "private_lesson_destination_recovery_review_stale");
|
|
70796
71326
|
}
|
|
70797
71327
|
let audience;
|
|
@@ -70805,7 +71335,7 @@ async function legacyLessonDestinationRecovery(draft, destination, request, depe
|
|
|
70805
71335
|
return refused(draft, "private_lesson_destination_recovery_review_stale");
|
|
70806
71336
|
}
|
|
70807
71337
|
const plan = recoveryPlan(draft, destination, audience);
|
|
70808
|
-
if (
|
|
71338
|
+
if (request2.action === "review") {
|
|
70809
71339
|
if (alreadyRecovered) return recovered(draft, plan, "already_recovered");
|
|
70810
71340
|
return {
|
|
70811
71341
|
...base(draft),
|
|
@@ -70836,7 +71366,7 @@ async function legacyLessonDestinationRecovery(draft, destination, request, depe
|
|
|
70836
71366
|
}
|
|
70837
71367
|
};
|
|
70838
71368
|
}
|
|
70839
|
-
if (
|
|
71369
|
+
if (request2.review_id !== plan.review_id || request2.organization_audience_hash !== audience) {
|
|
70840
71370
|
return refused(draft, "private_lesson_destination_recovery_review_stale");
|
|
70841
71371
|
}
|
|
70842
71372
|
if (alreadyRecovered) {
|
|
@@ -70849,7 +71379,7 @@ async function legacyLessonDestinationRecovery(draft, destination, request, depe
|
|
|
70849
71379
|
destination,
|
|
70850
71380
|
organization_audience_hash: audience,
|
|
70851
71381
|
owner_attested_single_organization: true,
|
|
70852
|
-
owner_attestation_sha256:
|
|
71382
|
+
owner_attestation_sha256: request2.owner_attestation_sha256
|
|
70853
71383
|
});
|
|
70854
71384
|
return {
|
|
70855
71385
|
...recovered(draft, plan, "destination_recovered"),
|
|
@@ -70878,7 +71408,7 @@ async function legacyLessonDestinationRecovery(draft, destination, request, depe
|
|
|
70878
71408
|
tool: "retry_private_lesson_candidate",
|
|
70879
71409
|
arguments: {
|
|
70880
71410
|
draft_id: draft.draft_id,
|
|
70881
|
-
legacy_destination_recovery:
|
|
71411
|
+
legacy_destination_recovery: request2
|
|
70882
71412
|
}
|
|
70883
71413
|
}
|
|
70884
71414
|
};
|
|
@@ -70887,8 +71417,8 @@ async function legacyLessonDestinationRecovery(draft, destination, request, depe
|
|
|
70887
71417
|
function isRecoveredForDestination(draft, destination) {
|
|
70888
71418
|
return draft.attested_organization_audience_hash !== void 0 && draft.destination_binding !== null && canonicalJson(draft.destination_binding) === canonicalJson(destination) && draft.last_error_code !== "private_lesson_destination_attestation_mismatch" && draft.state !== "submitted" && draft.state !== "superseded_redactor";
|
|
70889
71419
|
}
|
|
70890
|
-
function validApproval(
|
|
70891
|
-
return
|
|
71420
|
+
function validApproval(request2) {
|
|
71421
|
+
return request2.owner_attested_single_organization === true && request2.all_outbox_readers_updated === true && DIGEST4.test(request2.review_id) && DIGEST4.test(request2.expected_payload_digest) && DIGEST4.test(request2.owner_attestation_sha256) && DIGEST4.test(request2.organization_audience_hash);
|
|
70892
71422
|
}
|
|
70893
71423
|
function recoveryPlan(draft, destination, audience) {
|
|
70894
71424
|
const fields2 = {
|
|
@@ -70958,7 +71488,7 @@ function inspectPrivateLearningOutbox2(input, dependencies = {}) {
|
|
|
70958
71488
|
}
|
|
70959
71489
|
var MAX_REMOTE_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
70960
71490
|
var DOCTOR_PROBE_TIMEOUT_MS = 7500;
|
|
70961
|
-
var SERVER_VERSION = true ? "0.2.
|
|
71491
|
+
var SERVER_VERSION = true ? "0.2.14" : "0.0.0-dev";
|
|
70962
71492
|
var tools2 = toolDefinitions;
|
|
70963
71493
|
var doctorCliRequested = process.argv[2] === "doctor";
|
|
70964
71494
|
var nativeContextCliRequested = process.argv[2] === "--native-context";
|
|
@@ -70993,7 +71523,7 @@ var PRINCIPAL_SESSION_AWAITED_TOOLS = /* @__PURE__ */ new Set([
|
|
|
70993
71523
|
"report_task_outcome"
|
|
70994
71524
|
]);
|
|
70995
71525
|
function apiAccessKey(access) {
|
|
70996
|
-
return
|
|
71526
|
+
return createHash10("sha256").update(
|
|
70997
71527
|
[
|
|
70998
71528
|
access.configuration.baseUrl,
|
|
70999
71529
|
access.credential.source,
|
|
@@ -71090,16 +71620,16 @@ function readJsonRpcMessages(buffer) {
|
|
|
71090
71620
|
}
|
|
71091
71621
|
}
|
|
71092
71622
|
}
|
|
71093
|
-
async function handleRequest(
|
|
71094
|
-
const response = await dispatchJsonRpcRequest(
|
|
71623
|
+
async function handleRequest(request2) {
|
|
71624
|
+
const response = await dispatchJsonRpcRequest(request2);
|
|
71095
71625
|
if (!response) {
|
|
71096
71626
|
return;
|
|
71097
71627
|
}
|
|
71098
71628
|
writeResponse(response.id, response.result, response.error);
|
|
71099
71629
|
}
|
|
71100
|
-
async function dispatchJsonRpcRequest(
|
|
71101
|
-
if (
|
|
71102
|
-
connectedClientInfo = normalizedMcpClientInfo(
|
|
71630
|
+
async function dispatchJsonRpcRequest(request2) {
|
|
71631
|
+
if (request2.method === "initialize") {
|
|
71632
|
+
connectedClientInfo = normalizedMcpClientInfo(request2.params?.clientInfo);
|
|
71103
71633
|
const access = resolveApiAccess();
|
|
71104
71634
|
const transport = createRemembranceNetworkTransport();
|
|
71105
71635
|
warmPrincipalSession(access, transport);
|
|
@@ -71118,7 +71648,7 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71118
71648
|
hookApproval.status === "pending_approval" ? CODEX_HOOKS_PENDING_APPROVAL_NOTICE : hookApproval.status === "managed_hooks_disabled" ? CODEX_MANAGED_HOOKS_ONLY_NOTICE : CODEX_HOOK_TRUST_UNREADABLE_NOTICE
|
|
71119
71649
|
) : withUpdate;
|
|
71120
71650
|
return {
|
|
71121
|
-
id:
|
|
71651
|
+
id: request2.id,
|
|
71122
71652
|
result: {
|
|
71123
71653
|
protocolVersion: "2024-11-05",
|
|
71124
71654
|
capabilities: { tools: {}, resources: {} },
|
|
@@ -71130,10 +71660,10 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71130
71660
|
}
|
|
71131
71661
|
};
|
|
71132
71662
|
}
|
|
71133
|
-
if (
|
|
71663
|
+
if (request2.method === "tools/list") {
|
|
71134
71664
|
const visibleTools = visibleLocalTools(resolveApiAccess());
|
|
71135
71665
|
return {
|
|
71136
|
-
id:
|
|
71666
|
+
id: request2.id,
|
|
71137
71667
|
result: {
|
|
71138
71668
|
tools: visibleTools.map(
|
|
71139
71669
|
({ name, description, inputSchema, annotations }) => withRemembranceMcpToolMeta({
|
|
@@ -71146,19 +71676,19 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71146
71676
|
}
|
|
71147
71677
|
};
|
|
71148
71678
|
}
|
|
71149
|
-
if (
|
|
71679
|
+
if (request2.method === "resources/list") {
|
|
71150
71680
|
try {
|
|
71151
71681
|
return {
|
|
71152
|
-
id:
|
|
71153
|
-
result: await listSkillResources(
|
|
71682
|
+
id: request2.id,
|
|
71683
|
+
result: await listSkillResources(request2.params?.cursor)
|
|
71154
71684
|
};
|
|
71155
71685
|
} catch (error) {
|
|
71156
|
-
return { id:
|
|
71686
|
+
return { id: request2.id, error: jsonRpcErrorForToolError(error) };
|
|
71157
71687
|
}
|
|
71158
71688
|
}
|
|
71159
|
-
if (
|
|
71689
|
+
if (request2.method === "resources/templates/list") {
|
|
71160
71690
|
return {
|
|
71161
|
-
id:
|
|
71691
|
+
id: request2.id,
|
|
71162
71692
|
result: {
|
|
71163
71693
|
resourceTemplates: [
|
|
71164
71694
|
{
|
|
@@ -71171,18 +71701,18 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71171
71701
|
}
|
|
71172
71702
|
};
|
|
71173
71703
|
}
|
|
71174
|
-
if (
|
|
71704
|
+
if (request2.method === "resources/read") {
|
|
71175
71705
|
try {
|
|
71176
71706
|
return {
|
|
71177
|
-
id:
|
|
71178
|
-
result: await readSkillResource(
|
|
71707
|
+
id: request2.id,
|
|
71708
|
+
result: await readSkillResource(request2.params?.uri)
|
|
71179
71709
|
};
|
|
71180
71710
|
} catch (error) {
|
|
71181
|
-
return { id:
|
|
71711
|
+
return { id: request2.id, error: jsonRpcErrorForToolError(error) };
|
|
71182
71712
|
}
|
|
71183
71713
|
}
|
|
71184
|
-
if (
|
|
71185
|
-
const name = String(
|
|
71714
|
+
if (request2.method === "tools/call") {
|
|
71715
|
+
const name = String(request2.params?.name ?? "");
|
|
71186
71716
|
const access = resolveApiAccess();
|
|
71187
71717
|
const definition = visibleLocalTools(access).find(
|
|
71188
71718
|
(item) => item.name === name
|
|
@@ -71190,7 +71720,7 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71190
71720
|
if (!definition) {
|
|
71191
71721
|
if (privateCaptureModeEnabled(access) && isReplacedRoutineLearningTool(name)) {
|
|
71192
71722
|
return {
|
|
71193
|
-
id:
|
|
71723
|
+
id: request2.id,
|
|
71194
71724
|
error: {
|
|
71195
71725
|
code: -32602,
|
|
71196
71726
|
message: "This learning tool was replaced by capture_learning in private capture mode.",
|
|
@@ -71202,18 +71732,18 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71202
71732
|
};
|
|
71203
71733
|
}
|
|
71204
71734
|
return {
|
|
71205
|
-
id:
|
|
71735
|
+
id: request2.id,
|
|
71206
71736
|
error: { code: -32602, message: `Unknown tool: ${name}` }
|
|
71207
71737
|
};
|
|
71208
71738
|
}
|
|
71209
71739
|
try {
|
|
71210
71740
|
const execute = async () => {
|
|
71211
|
-
const result2 = await callTool(definition,
|
|
71741
|
+
const result2 = await callTool(definition, request2.params?.arguments);
|
|
71212
71742
|
markCaptureLearningStage("response");
|
|
71213
71743
|
return remembranceMcpToolCallResult(result2, definition.name);
|
|
71214
71744
|
};
|
|
71215
71745
|
const result = name === "capture_learning" ? await withCaptureLearningDiagnostics(execute) : await execute();
|
|
71216
|
-
return { id:
|
|
71746
|
+
return { id: request2.id, result };
|
|
71217
71747
|
} catch (error) {
|
|
71218
71748
|
const capture2 = captureLearningDiagnostic(error);
|
|
71219
71749
|
if (capture2) {
|
|
@@ -71237,17 +71767,17 @@ async function dispatchJsonRpcRequest(request) {
|
|
|
71237
71767
|
}
|
|
71238
71768
|
}
|
|
71239
71769
|
return {
|
|
71240
|
-
id:
|
|
71770
|
+
id: request2.id,
|
|
71241
71771
|
error: jsonRpcErrorForToolError(error)
|
|
71242
71772
|
};
|
|
71243
71773
|
}
|
|
71244
71774
|
}
|
|
71245
|
-
if (
|
|
71775
|
+
if (request2.id !== void 0) {
|
|
71246
71776
|
return {
|
|
71247
|
-
id:
|
|
71777
|
+
id: request2.id,
|
|
71248
71778
|
error: {
|
|
71249
71779
|
code: -32601,
|
|
71250
|
-
message: `Method not found: ${
|
|
71780
|
+
message: `Method not found: ${request2.method ?? "unknown"}`
|
|
71251
71781
|
}
|
|
71252
71782
|
};
|
|
71253
71783
|
}
|
|
@@ -71326,6 +71856,10 @@ async function callToolWithinExecution(runtimeDefinition, rawArguments, dependen
|
|
|
71326
71856
|
const payload = dependencies.testSchemaOverride ? dependencies.testSchemaOverride.parse(rawPayload) : parseToolArguments(runtimeDefinition, rawPayload);
|
|
71327
71857
|
assertToolPayloadBoundary(runtimeDefinition, payload, { sizeCheck: false });
|
|
71328
71858
|
const access = resolveApiAccess();
|
|
71859
|
+
if (runtimeDefinition.name === "get_admin_session") {
|
|
71860
|
+
if (access.configuration.source.startsWith("unusable_")) return { ok: false, status: "destination_unavailable", server_validity_checked: false };
|
|
71861
|
+
return getLocalAdminSession(access.configuration.baseUrl);
|
|
71862
|
+
}
|
|
71329
71863
|
if (runtimeDefinition.executionNetworkBehavior === "local_only") {
|
|
71330
71864
|
if (!runtimeDefinition.local || !LOCAL_ONLY_HANDLER_NAMES.includes(
|
|
71331
71865
|
runtimeDefinition.local
|
|
@@ -71356,6 +71890,9 @@ async function callToolWithinExecution(runtimeDefinition, rawArguments, dependen
|
|
|
71356
71890
|
);
|
|
71357
71891
|
}
|
|
71358
71892
|
async function callNetworkToolWithinExecution(definition, payload, access, transport) {
|
|
71893
|
+
if (ADMIN_CONTROL_TOOL_NAMES.includes(definition.name)) {
|
|
71894
|
+
return callAdminControlTool(definition.name, payload, access, transport);
|
|
71895
|
+
}
|
|
71359
71896
|
if (definition.name === "repair_review_draft") {
|
|
71360
71897
|
const inspection = inspectReviewRepairForTransport(payload);
|
|
71361
71898
|
if (!inspection.ready) return inspection.refusal;
|
|
@@ -71646,11 +72183,11 @@ function retryAfterDelayMs(value, nowMs = Date.now()) {
|
|
|
71646
72183
|
Number(trimmed) * 1e3
|
|
71647
72184
|
);
|
|
71648
72185
|
}
|
|
71649
|
-
const
|
|
71650
|
-
if (!Number.isFinite(
|
|
72186
|
+
const timestamp3 = Date.parse(trimmed);
|
|
72187
|
+
if (!Number.isFinite(timestamp3)) return null;
|
|
71651
72188
|
return Math.min(
|
|
71652
72189
|
PRIVATE_LEARNING_MAX_RETRY_DELAY_MS,
|
|
71653
|
-
Math.max(0,
|
|
72190
|
+
Math.max(0, timestamp3 - nowMs)
|
|
71654
72191
|
);
|
|
71655
72192
|
}
|
|
71656
72193
|
function privateLessonDestinationForAccess(access) {
|
|
@@ -71669,17 +72206,17 @@ function privateLessonDestinationForAccess(access) {
|
|
|
71669
72206
|
)
|
|
71670
72207
|
});
|
|
71671
72208
|
}
|
|
71672
|
-
async function getLocalPrivateLessonPolicy(access, transport,
|
|
72209
|
+
async function getLocalPrivateLessonPolicy(access, transport, request2 = {
|
|
71673
72210
|
supported_redactor_profiles: []
|
|
71674
72211
|
}) {
|
|
71675
72212
|
const verified = await fetchVerifiedPrivateLessonPolicy(
|
|
71676
72213
|
access,
|
|
71677
72214
|
transport,
|
|
71678
|
-
|
|
71679
|
-
|
|
72215
|
+
request2.required_redactor_profile,
|
|
72216
|
+
request2.supported_redactor_profiles,
|
|
71680
72217
|
// Like the hosted tool, ask for the larger limit only when the caller
|
|
71681
72218
|
// does; submission asks for it only for a lesson over the legacy limit.
|
|
71682
|
-
|
|
72219
|
+
request2.supported_max_payload_bytes
|
|
71683
72220
|
);
|
|
71684
72221
|
const outbox = await privateLessonOutboxSummary();
|
|
71685
72222
|
return {
|
|
@@ -71795,16 +72332,16 @@ async function deliverPrivateSkillDraft(draftId, access, mode, transport) {
|
|
|
71795
72332
|
);
|
|
71796
72333
|
verifiedAudience = verified.policy.payload.organization_audience_hash;
|
|
71797
72334
|
} catch (error) {
|
|
71798
|
-
const
|
|
72335
|
+
const failure2 = privateSkillDestinationProofFailure(error);
|
|
71799
72336
|
draft = await persistPrivateSkillDestinationProofFailure(
|
|
71800
72337
|
draft,
|
|
71801
|
-
|
|
72338
|
+
failure2,
|
|
71802
72339
|
destination
|
|
71803
72340
|
);
|
|
71804
72341
|
return privateSkillDraftActionResult2(draft, {
|
|
71805
72342
|
status: "not_submitted",
|
|
71806
|
-
action_required:
|
|
71807
|
-
next_action:
|
|
72343
|
+
action_required: failure2.action_required,
|
|
72344
|
+
next_action: failure2.state === "retry_scheduled" ? {
|
|
71808
72345
|
tool: "retry_private_skill_candidate",
|
|
71809
72346
|
arguments: { draft_id: draft.draft_id }
|
|
71810
72347
|
} : null,
|
|
@@ -72051,15 +72588,15 @@ function privateSkillDestinationProofFailure(error) {
|
|
|
72051
72588
|
action_required: "Local destination-proof validation failed unexpectedly. The frozen candidate remains encrypted and no candidate content was sent; it will not be retried automatically."
|
|
72052
72589
|
};
|
|
72053
72590
|
}
|
|
72054
|
-
async function persistPrivateSkillDestinationProofFailure(draft,
|
|
72591
|
+
async function persistPrivateSkillDestinationProofFailure(draft, failure2, destination) {
|
|
72055
72592
|
return updatePrivateSkillDraft(draft.draft_id, (current) => ({
|
|
72056
72593
|
...current,
|
|
72057
|
-
state:
|
|
72058
|
-
destination_rejection:
|
|
72059
|
-
next_retry_at:
|
|
72594
|
+
state: failure2.state,
|
|
72595
|
+
destination_rejection: failure2.state === "held_validation" ? destination : null,
|
|
72596
|
+
next_retry_at: failure2.state === "retry_scheduled" ? new Date(
|
|
72060
72597
|
Date.now() + privateSkillRetryDelayMs(current.attempts)
|
|
72061
72598
|
).toISOString() : null,
|
|
72062
|
-
last_error_code:
|
|
72599
|
+
last_error_code: failure2.error_code,
|
|
72063
72600
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
72064
72601
|
}));
|
|
72065
72602
|
}
|
|
@@ -72075,13 +72612,13 @@ async function holdPrivateSkillDestination(draft, errorCode) {
|
|
|
72075
72612
|
async function persistPrivateSkillFailure(draft, result, destinationBodyLimit) {
|
|
72076
72613
|
return updatePrivateSkillDraft(draft.draft_id, (current) => {
|
|
72077
72614
|
const attempts = current.attempts;
|
|
72078
|
-
const
|
|
72079
|
-
if (
|
|
72615
|
+
const failure2 = remembranceMcpToolFailure(result, "propose_private_skill");
|
|
72616
|
+
if (failure2 && failure2.http_status >= 500 && failure2.http_status <= 599 && !failure2.retryable) {
|
|
72080
72617
|
return {
|
|
72081
72618
|
...current,
|
|
72082
72619
|
state: "held_validation",
|
|
72083
72620
|
next_retry_at: null,
|
|
72084
|
-
last_error_code:
|
|
72621
|
+
last_error_code: failure2.code === PRIVATE_SKILL_CONFIGURATION_REFUSAL ? PRIVATE_SKILL_CONFIGURATION_REFUSAL : PRIVATE_SKILL_PERMANENT_SERVICE_REFUSAL,
|
|
72085
72622
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
72086
72623
|
};
|
|
72087
72624
|
}
|
|
@@ -72232,7 +72769,7 @@ async function fetchPrivateSkillDestinationCapability(access, transport) {
|
|
|
72232
72769
|
} finally {
|
|
72233
72770
|
clearTimeout(timeout);
|
|
72234
72771
|
}
|
|
72235
|
-
const
|
|
72772
|
+
const envelope2 = isRecord11(body) ? body.capability : void 0;
|
|
72236
72773
|
for (const refreshKeys of [false, true]) {
|
|
72237
72774
|
try {
|
|
72238
72775
|
const keySet = await fetchValueProofKeySet(
|
|
@@ -72242,10 +72779,10 @@ async function fetchPrivateSkillDestinationCapability(access, transport) {
|
|
|
72242
72779
|
);
|
|
72243
72780
|
return {
|
|
72244
72781
|
status: "verified",
|
|
72245
|
-
capability: verifyPrivateSkillCapabilityEnvelope({ envelope, keySet }).payload
|
|
72782
|
+
capability: verifyPrivateSkillCapabilityEnvelope({ envelope: envelope2, keySet }).payload
|
|
72246
72783
|
};
|
|
72247
72784
|
} catch {
|
|
72248
|
-
if (!isRecord11(
|
|
72785
|
+
if (!isRecord11(envelope2)) break;
|
|
72249
72786
|
}
|
|
72250
72787
|
}
|
|
72251
72788
|
return { status: "unverified", retry_after_ms: null };
|
|
@@ -72920,8 +73457,8 @@ function privateLessonRetryGate(draft) {
|
|
|
72920
73457
|
}
|
|
72921
73458
|
function retryDue(nextRetryAt) {
|
|
72922
73459
|
if (!nextRetryAt) return true;
|
|
72923
|
-
const
|
|
72924
|
-
return !Number.isFinite(
|
|
73460
|
+
const timestamp3 = Date.parse(nextRetryAt);
|
|
73461
|
+
return !Number.isFinite(timestamp3) || timestamp3 <= Date.now();
|
|
72925
73462
|
}
|
|
72926
73463
|
async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolicyRefresh, transport) {
|
|
72927
73464
|
let draft = initialDraft;
|
|
@@ -73192,7 +73729,7 @@ async function fetchVerifiedPrivateLessonPolicy(access, transport, requiredProfi
|
|
|
73192
73729
|
});
|
|
73193
73730
|
return { policy: verified, body };
|
|
73194
73731
|
}
|
|
73195
|
-
async function verifyPrivateLessonEnvelopeWithKeyRefresh(
|
|
73732
|
+
async function verifyPrivateLessonEnvelopeWithKeyRefresh(envelope2, kind, access, transport) {
|
|
73196
73733
|
let keySet;
|
|
73197
73734
|
try {
|
|
73198
73735
|
keySet = await fetchValueProofKeySet(false, access, transport);
|
|
@@ -73207,7 +73744,7 @@ async function verifyPrivateLessonEnvelopeWithKeyRefresh(envelope, kind, access,
|
|
|
73207
73744
|
);
|
|
73208
73745
|
}
|
|
73209
73746
|
try {
|
|
73210
|
-
return verifyPrivateLessonEnvelope(
|
|
73747
|
+
return verifyPrivateLessonEnvelope(envelope2, kind, keySet);
|
|
73211
73748
|
} catch (error) {
|
|
73212
73749
|
rethrowPrivateLessonProfileVerificationError(error, kind);
|
|
73213
73750
|
let refreshedKeySet;
|
|
@@ -73224,11 +73761,11 @@ async function verifyPrivateLessonEnvelopeWithKeyRefresh(envelope, kind, access,
|
|
|
73224
73761
|
);
|
|
73225
73762
|
}
|
|
73226
73763
|
try {
|
|
73227
|
-
return verifyPrivateLessonEnvelope(
|
|
73764
|
+
return verifyPrivateLessonEnvelope(envelope2, kind, refreshedKeySet);
|
|
73228
73765
|
} catch (error2) {
|
|
73229
73766
|
rethrowPrivateLessonProfileVerificationError(error2, kind);
|
|
73230
73767
|
if (kind === "policy") {
|
|
73231
|
-
const policy = signedPrivateLessonPolicySchema.safeParse(
|
|
73768
|
+
const policy = signedPrivateLessonPolicySchema.safeParse(envelope2);
|
|
73232
73769
|
const keys = privateLessonVerificationKeySetSchema.safeParse(refreshedKeySet);
|
|
73233
73770
|
if (!policy.success || canonicalJson(policy.data.payload) === policy.data.canonical_payload && (!keys.success || !keys.data.keys.some((key) => key.kid === policy.data.key_id))) {
|
|
73234
73771
|
throw new PrivateLessonRemoteError(
|
|
@@ -73258,14 +73795,14 @@ function rethrowPrivateLessonProfileVerificationError(error, kind) {
|
|
|
73258
73795
|
);
|
|
73259
73796
|
}
|
|
73260
73797
|
}
|
|
73261
|
-
function verifyPrivateLessonEnvelope(
|
|
73798
|
+
function verifyPrivateLessonEnvelope(envelope2, kind, keySet) {
|
|
73262
73799
|
if (kind === "policy") {
|
|
73263
|
-
return verifyPrivateLessonSignedEnvelope({ envelope, kind, keySet });
|
|
73800
|
+
return verifyPrivateLessonSignedEnvelope({ envelope: envelope2, kind, keySet });
|
|
73264
73801
|
}
|
|
73265
73802
|
if (kind === "receipt") {
|
|
73266
|
-
return verifyPrivateLessonSignedEnvelope({ envelope, kind, keySet });
|
|
73803
|
+
return verifyPrivateLessonSignedEnvelope({ envelope: envelope2, kind, keySet });
|
|
73267
73804
|
}
|
|
73268
|
-
return verifyPrivateLessonSignedEnvelope({ envelope, kind, keySet });
|
|
73805
|
+
return verifyPrivateLessonSignedEnvelope({ envelope: envelope2, kind, keySet });
|
|
73269
73806
|
}
|
|
73270
73807
|
var PRIVATE_LESSON_PAYLOAD_OVER_POLICY = "payload_exceeds_policy_limit";
|
|
73271
73808
|
function privateLessonRefusalCode(body) {
|
|
@@ -73656,23 +74193,23 @@ function stringField(record4, key) {
|
|
|
73656
74193
|
return value;
|
|
73657
74194
|
}
|
|
73658
74195
|
async function submitRemembrance(payload, access, transport) {
|
|
73659
|
-
const { verified_attestation: verifiedAttestation, ...
|
|
74196
|
+
const { verified_attestation: verifiedAttestation, ...request2 } = payload;
|
|
73660
74197
|
if (!verifiedAttestation) {
|
|
73661
|
-
return callRemembrance(mustFindTool("submit_remembrance"),
|
|
74198
|
+
return callRemembrance(mustFindTool("submit_remembrance"), request2, {
|
|
73662
74199
|
access,
|
|
73663
74200
|
transport
|
|
73664
74201
|
});
|
|
73665
74202
|
}
|
|
73666
|
-
const skillSlug =
|
|
74203
|
+
const skillSlug = request2.skill?.slug;
|
|
73667
74204
|
if (!skillSlug) {
|
|
73668
74205
|
throw new McpPublicError("verified_attestation requires skill.slug.");
|
|
73669
74206
|
}
|
|
73670
74207
|
const evidence = {
|
|
73671
|
-
trace_hash:
|
|
73672
|
-
artifact_hashes:
|
|
74208
|
+
trace_hash: request2.evidence.trace_hash ?? null,
|
|
74209
|
+
artifact_hashes: request2.evidence.artifact_hashes ?? []
|
|
73673
74210
|
};
|
|
73674
74211
|
const remembrancePayload = {
|
|
73675
|
-
...
|
|
74212
|
+
...request2,
|
|
73676
74213
|
evidence
|
|
73677
74214
|
};
|
|
73678
74215
|
const attestation = await signedRemembranceAttestation(
|
|
@@ -73694,38 +74231,38 @@ async function submitRemembrance(payload, access, transport) {
|
|
|
73694
74231
|
);
|
|
73695
74232
|
}
|
|
73696
74233
|
async function submitFeedback(payload, access, transport) {
|
|
73697
|
-
const { verified_attestation: verifiedAttestation, ...
|
|
74234
|
+
const { verified_attestation: verifiedAttestation, ...request2 } = payload;
|
|
73698
74235
|
if (!verifiedAttestation) {
|
|
73699
|
-
return callRemembrance(mustFindTool("submit_feedback"),
|
|
74236
|
+
return callRemembrance(mustFindTool("submit_feedback"), request2, {
|
|
73700
74237
|
access,
|
|
73701
74238
|
transport
|
|
73702
74239
|
});
|
|
73703
74240
|
}
|
|
73704
74241
|
const identity2 = await ensureSigningIdentity(transport);
|
|
73705
|
-
const agent =
|
|
74242
|
+
const agent = request2.agent ?? {
|
|
73706
74243
|
provider: agentProviderForIdentity(identity2.provider),
|
|
73707
74244
|
agent_id: identity2.subject
|
|
73708
74245
|
};
|
|
73709
74246
|
const evidence = {
|
|
73710
|
-
trace_hash:
|
|
73711
|
-
artifact_hashes:
|
|
74247
|
+
trace_hash: request2.evidence?.trace_hash ?? null,
|
|
74248
|
+
artifact_hashes: request2.evidence?.artifact_hashes ?? []
|
|
73712
74249
|
};
|
|
73713
|
-
const lesson =
|
|
74250
|
+
const lesson = request2.lesson?.trim() || (request2.useful ? `The ${request2.skill_slug} skill was useful.` : `The ${request2.skill_slug} skill was not useful.`);
|
|
73714
74251
|
const remembrancePayload = {
|
|
73715
74252
|
schema_version: "0.1",
|
|
73716
74253
|
type: "skill_feedback",
|
|
73717
74254
|
agent,
|
|
73718
74255
|
task: {
|
|
73719
74256
|
domain: "agent-feedback",
|
|
73720
|
-
summary: `Feedback for ${
|
|
74257
|
+
summary: `Feedback for ${request2.skill_slug}: ${lesson}`,
|
|
73721
74258
|
privacy: "redacted_public"
|
|
73722
74259
|
},
|
|
73723
|
-
skill: { slug:
|
|
74260
|
+
skill: { slug: request2.skill_slug },
|
|
73724
74261
|
outcome: {
|
|
73725
|
-
success:
|
|
73726
|
-
usefulness_rating:
|
|
74262
|
+
success: request2.useful,
|
|
74263
|
+
usefulness_rating: request2.rating ?? (request2.useful ? 5 : 2),
|
|
73727
74264
|
confidence: 0.8,
|
|
73728
|
-
user_accepted:
|
|
74265
|
+
user_accepted: request2.useful,
|
|
73729
74266
|
failure_modes: []
|
|
73730
74267
|
},
|
|
73731
74268
|
lesson,
|
|
@@ -73734,14 +74271,14 @@ async function submitFeedback(payload, access, transport) {
|
|
|
73734
74271
|
};
|
|
73735
74272
|
const attestation = await signedRemembranceAttestation(
|
|
73736
74273
|
remembrancePayload,
|
|
73737
|
-
|
|
74274
|
+
request2.skill_slug,
|
|
73738
74275
|
access,
|
|
73739
74276
|
transport
|
|
73740
74277
|
);
|
|
73741
74278
|
return callRemembrance(
|
|
73742
74279
|
mustFindTool("submit_feedback"),
|
|
73743
74280
|
{
|
|
73744
|
-
...
|
|
74281
|
+
...request2,
|
|
73745
74282
|
agent,
|
|
73746
74283
|
evidence: {
|
|
73747
74284
|
...evidence,
|
|
@@ -73908,7 +74445,7 @@ async function createAndPersistIdentity(args, keyPath) {
|
|
|
73908
74445
|
private_key: String(privateKey.export({ type: "pkcs8", format: "pem" })),
|
|
73909
74446
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
73910
74447
|
};
|
|
73911
|
-
await mkdir5(
|
|
74448
|
+
await mkdir5(dirname11(keyPath), { recursive: true, mode: 448 });
|
|
73912
74449
|
try {
|
|
73913
74450
|
await writeFile2(keyPath, `${JSON.stringify(identity2, null, 2)}
|
|
73914
74451
|
`, {
|
|
@@ -73984,7 +74521,7 @@ async function ensureSigningIdentity(transport) {
|
|
|
73984
74521
|
return promise;
|
|
73985
74522
|
}
|
|
73986
74523
|
async function callPrivateSkillDeliveryResolution(rawRequest, predecessor, access, transport) {
|
|
73987
|
-
const
|
|
74524
|
+
const request2 = privateSkillDeliveryResolveRequestSchema.parse(rawRequest);
|
|
73988
74525
|
const headers = {
|
|
73989
74526
|
"content-type": "application/json",
|
|
73990
74527
|
"user-agent": `@remembrance-ai/mcp-server/${SERVER_VERSION}`,
|
|
@@ -74012,7 +74549,7 @@ async function callPrivateSkillDeliveryResolution(rawRequest, predecessor, acces
|
|
|
74012
74549
|
{
|
|
74013
74550
|
method: "POST",
|
|
74014
74551
|
headers,
|
|
74015
|
-
body: JSON.stringify(
|
|
74552
|
+
body: JSON.stringify(request2),
|
|
74016
74553
|
redirect: "manual",
|
|
74017
74554
|
signal: controller.signal
|
|
74018
74555
|
}
|
|
@@ -74234,7 +74771,7 @@ async function callRemembrance(definition, rawArguments, options) {
|
|
|
74234
74771
|
clearTimeout(timeout);
|
|
74235
74772
|
}
|
|
74236
74773
|
if (["get_review_comparison", "repair_review_draft"].includes(definition.name) && (!response.ok || redirectRejected)) {
|
|
74237
|
-
const
|
|
74774
|
+
const failure2 = remembranceMcpToolFailure({
|
|
74238
74775
|
ok: false,
|
|
74239
74776
|
status: response.status,
|
|
74240
74777
|
body,
|
|
@@ -74242,10 +74779,10 @@ async function callRemembrance(definition, rawArguments, options) {
|
|
|
74242
74779
|
redirect_rejected: redirectRejected
|
|
74243
74780
|
}, definition.name);
|
|
74244
74781
|
body = {
|
|
74245
|
-
error:
|
|
74246
|
-
code:
|
|
74247
|
-
retryable:
|
|
74248
|
-
delivery:
|
|
74782
|
+
error: failure2?.message ?? "The review operation failed.",
|
|
74783
|
+
code: failure2?.code ?? "review_workflow_failed",
|
|
74784
|
+
retryable: failure2?.retryable ?? false,
|
|
74785
|
+
delivery: failure2?.delivery ?? "unknown",
|
|
74249
74786
|
...definition.name === "repair_review_draft" ? {
|
|
74250
74787
|
request_id: parsed.request_id,
|
|
74251
74788
|
next_action: "If delivery is unknown, repeat only the identical request_id, capture and snapshot to reconcile it. Never create a new replacement for an unresolved write."
|
|
@@ -74962,7 +75499,7 @@ function localRuntimeProfile(identity2) {
|
|
|
74962
75499
|
const runtime = isPluginHostSurface(configuredSurface) ? configuredSurface : "other";
|
|
74963
75500
|
const clientName = connectedClientInfo?.name ?? agentHostBySurface(runtime)?.host_name ?? "MCP";
|
|
74964
75501
|
const hostSurface = localRuntimeHostSurface(runtime, clientName);
|
|
74965
|
-
const profileDigest =
|
|
75502
|
+
const profileDigest = createHash10("sha256").update(
|
|
74966
75503
|
[identity2.key_id, runtime, hostSurface, clientName.toLowerCase()].join(
|
|
74967
75504
|
":"
|
|
74968
75505
|
),
|
|
@@ -75020,13 +75557,13 @@ function agentProviderForIdentity(provider) {
|
|
|
75020
75557
|
}
|
|
75021
75558
|
return "generic";
|
|
75022
75559
|
}
|
|
75023
|
-
function writeResponse(
|
|
75024
|
-
process.stdout.write(formatJsonRpcResponse(
|
|
75560
|
+
function writeResponse(id2, result, error) {
|
|
75561
|
+
process.stdout.write(formatJsonRpcResponse(id2, result, error));
|
|
75025
75562
|
}
|
|
75026
|
-
function formatJsonRpcResponse(
|
|
75563
|
+
function formatJsonRpcResponse(id2, result, error, framing = clientFraming) {
|
|
75027
75564
|
const body = JSON.stringify({
|
|
75028
75565
|
jsonrpc: "2.0",
|
|
75029
|
-
id:
|
|
75566
|
+
id: id2 ?? null,
|
|
75030
75567
|
...error ? { error } : { result }
|
|
75031
75568
|
});
|
|
75032
75569
|
if (framing === "content-length") {
|