@remembrance-ai/mcp-server 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -20
- package/dist/server.js +1300 -211
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/server.js
CHANGED
|
@@ -471,6 +471,32 @@ function agentHostBySurface(surface) {
|
|
|
471
471
|
function isPluginHostSurface(value) {
|
|
472
472
|
return PLUGIN_HOSTS.some((host) => host.surface === value);
|
|
473
473
|
}
|
|
474
|
+
var CODEX_CLI_LOOKUP = `set +eu; unalias codex 2>/dev/null || :; unset -f codex 2>/dev/null || :
|
|
475
|
+
if [ -n "$CODEX_CLI" ]; then
|
|
476
|
+
[ -x "$CODEX_CLI" ] || { printf 'CODEX_CLI is set but is not an executable file: %s\\n' "$CODEX_CLI" >&2; exit 1; }
|
|
477
|
+
else
|
|
478
|
+
best=-1
|
|
479
|
+
for c in "$(command -v codex 2>/dev/null)" \\
|
|
480
|
+
/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex \\
|
|
481
|
+
/Applications/ChatGPT.app/Contents/Resources/codex \\
|
|
482
|
+
/Applications/Codex.app/Contents/Resources/codex; do
|
|
483
|
+
case "$c" in /*) [ -x "$c" ] || continue ;; *) continue ;; esac
|
|
484
|
+
out=$("$c" --version </dev/null 2>/dev/null) || continue
|
|
485
|
+
v=$(printf '%s\\n' "$out" | awk 'match($0, /[0-9]+[.][0-9]+[.][0-9]+/) { split(substr($0, RSTART, RLENGTH), n, "."); v = n[1] * 1000000 + n[2] * 1000 + n[3]; exit } END { print v + 0 }')
|
|
486
|
+
[ "$v" -gt "$best" ] && best=$v && CODEX_CLI=$c
|
|
487
|
+
done
|
|
488
|
+
[ -n "$CODEX_CLI" ] || { printf '%s\\n' "Codex CLI not found. Install the Codex CLI, or install or update the ChatGPT desktop app on macOS, or set CODEX_CLI to a Codex CLI path, then try again." >&2; exit 1; }
|
|
489
|
+
fi
|
|
490
|
+
printf 'Using Codex CLI: %s\\n' "$CODEX_CLI" >&2`;
|
|
491
|
+
function codexCliCommand(...steps) {
|
|
492
|
+
return ["(", CODEX_CLI_LOOKUP, steps.join(" &&\n "), ")"].join("\n");
|
|
493
|
+
}
|
|
494
|
+
var CODEX_PLUGIN_SETUP_COMMAND = codexCliCommand(
|
|
495
|
+
'"$CODEX_CLI" plugin marketplace add dreamarkinc/remembrance-skills',
|
|
496
|
+
'"$CODEX_CLI" plugin marketplace upgrade remembrance',
|
|
497
|
+
'"$CODEX_CLI" plugin add remembrance@remembrance',
|
|
498
|
+
'"$CODEX_CLI"'
|
|
499
|
+
);
|
|
474
500
|
|
|
475
501
|
// ../../node_modules/zod/v3/external.js
|
|
476
502
|
var external_exports = {};
|
|
@@ -4580,14 +4606,10 @@ var clientHealthReportSchema = external_exports.object({
|
|
|
4580
4606
|
|
|
4581
4607
|
// ../core/src/client-release.ts
|
|
4582
4608
|
var CLIENT_RELEASE_SCHEMA_VERSION = "1";
|
|
4583
|
-
var CODEX_UPDATE_COMMAND =
|
|
4584
|
-
'CODEX_CLI="${CODEX_CLI:-$(command -v codex || true)}"',
|
|
4585
|
-
'[ -x "$CODEX_CLI" ] || CODEX_CLI="/Applications/ChatGPT.app/Contents/Resources/codex"',
|
|
4586
|
-
'[ -x "$CODEX_CLI" ] || CODEX_CLI="/Applications/Codex.app/Contents/Resources/codex"',
|
|
4587
|
-
`[ -x "$CODEX_CLI" ] || { printf '%s\\n' "Codex CLI not found. Install the Codex CLI, or update the ChatGPT desktop app, then try again." >&2; exit 1; }`,
|
|
4609
|
+
var CODEX_UPDATE_COMMAND = codexCliCommand(
|
|
4588
4610
|
'"$CODEX_CLI" plugin marketplace upgrade remembrance',
|
|
4589
4611
|
'"$CODEX_CLI" plugin add remembrance@remembrance --json'
|
|
4590
|
-
|
|
4612
|
+
);
|
|
4591
4613
|
var CLIENT_UPDATE_GUIDANCE = {
|
|
4592
4614
|
codex: {
|
|
4593
4615
|
surface: "codex",
|
|
@@ -4898,7 +4920,7 @@ var HOST_POLICY_OPERATION_CLASSES = /* @__PURE__ */ new Set([
|
|
|
4898
4920
|
"feedback",
|
|
4899
4921
|
"other"
|
|
4900
4922
|
]);
|
|
4901
|
-
var CODEX_HOOK_REVIEW_COMMAND =
|
|
4923
|
+
var CODEX_HOOK_REVIEW_COMMAND = codexCliCommand('"$CODEX_CLI"');
|
|
4902
4924
|
var CODEX_HOOK_EVENTS = [
|
|
4903
4925
|
"SessionStart",
|
|
4904
4926
|
"UserPromptSubmit",
|
|
@@ -4916,7 +4938,7 @@ function codexHookReviewAction(followupTool, reviewEvents = []) {
|
|
|
4916
4938
|
function codexHookEvents(value) {
|
|
4917
4939
|
return Array.isArray(value) ? CODEX_HOOK_EVENTS.filter((event) => value.includes(event)) : [];
|
|
4918
4940
|
}
|
|
4919
|
-
var CODEX_HOOKS_PENDING_APPROVAL_NOTICE = "Remembrance hooks await Codex approval:
|
|
4941
|
+
var CODEX_HOOKS_PENDING_APPROVAL_NOTICE = "Remembrance hooks await Codex approval: run_connection_doctor gives the command.";
|
|
4920
4942
|
var CODEX_HOOK_TRUST_UNREADABLE_NOTICE = "Could not read Codex hook trust state; check hooks with run_connection_doctor.";
|
|
4921
4943
|
var CODEX_MANAGED_HOOKS_ONLY_NOTICE = "Remembrance plugin hooks are off: Codex policy runs only managed hooks. Tools work.";
|
|
4922
4944
|
function codexHooksPendingApproval(value, followupTool) {
|
|
@@ -7610,8 +7632,7 @@ var PRIVATE_LESSON_TAG_RELATIONAL_PREFIXES = /* @__PURE__ */ new Set([
|
|
|
7610
7632
|
"sub"
|
|
7611
7633
|
]);
|
|
7612
7634
|
var privateLessonCanonicalTagSchema = privateLessonTagSyntaxSchema.superRefine((tag, ctx) => {
|
|
7613
|
-
|
|
7614
|
-
if (inspected.tag !== tag || inspected.held_reasons.length > 0) {
|
|
7635
|
+
if (inspectPrivateLessonTag(tag).tag !== tag) {
|
|
7615
7636
|
ctx.addIssue({
|
|
7616
7637
|
code: external_exports.ZodIssueCode.custom,
|
|
7617
7638
|
message: "tag must be canonical and pass private-lesson safety checks"
|
|
@@ -7978,10 +7999,10 @@ var EXISTING_REDACTION_MARKER = new RegExp(
|
|
|
7978
7999
|
var REPLACEMENTS = [
|
|
7979
8000
|
{ category: "unicode_control", pattern: ZERO_WIDTH_OR_BIDI, hold: true },
|
|
7980
8001
|
{ category: "stack_trace", pattern: STACK_TRACE, hold: true },
|
|
7981
|
-
{ category: "screenshot", pattern: SCREENSHOT, hold:
|
|
8002
|
+
{ category: "screenshot", pattern: SCREENSHOT, hold: false },
|
|
7982
8003
|
{ category: "connection_string", pattern: CONNECTION_STRING, hold: false },
|
|
7983
8004
|
{ category: "private_url", pattern: PRIVATE_URL, hold: false },
|
|
7984
|
-
{ category: "public_url", pattern: PUBLIC_URL, hold:
|
|
8005
|
+
{ category: "public_url", pattern: PUBLIC_URL, hold: false },
|
|
7985
8006
|
{ category: "jwt", pattern: JWT, hold: false },
|
|
7986
8007
|
{ category: "cookie", pattern: COOKIE, hold: false },
|
|
7987
8008
|
{ category: "credential", pattern: CREDENTIAL, hold: false },
|
|
@@ -7991,24 +8012,24 @@ var REPLACEMENTS = [
|
|
|
7991
8012
|
{
|
|
7992
8013
|
category: "encoded_or_high_entropy",
|
|
7993
8014
|
pattern: SHORT_PADDED_BASE64,
|
|
7994
|
-
hold:
|
|
8015
|
+
hold: false
|
|
7995
8016
|
},
|
|
7996
8017
|
{
|
|
7997
8018
|
category: "encoded_or_high_entropy",
|
|
7998
8019
|
pattern: SHORT_MIXED_OPAQUE,
|
|
7999
|
-
hold:
|
|
8020
|
+
hold: false
|
|
8000
8021
|
},
|
|
8001
8022
|
{
|
|
8002
8023
|
category: "credential",
|
|
8003
8024
|
pattern: SHORT_CONTEXTUAL_CREDENTIAL,
|
|
8004
8025
|
hold: false
|
|
8005
8026
|
},
|
|
8006
|
-
{ category: "encoded_or_high_entropy", pattern: HIGH_ENTROPY, hold:
|
|
8027
|
+
{ category: "encoded_or_high_entropy", pattern: HIGH_ENTROPY, hold: false },
|
|
8007
8028
|
{ category: "path", pattern: FILE_PATH, hold: false },
|
|
8008
8029
|
{ category: "hostname", pattern: INTERNAL_HOSTNAME, hold: false },
|
|
8009
8030
|
{ category: "hostname", pattern: HOSTNAME, hold: false },
|
|
8010
8031
|
{ category: "identifier", pattern: IDENTIFIER, hold: false },
|
|
8011
|
-
{ category: "code_block", pattern: CODE_BLOCK, hold:
|
|
8032
|
+
{ category: "code_block", pattern: CODE_BLOCK, hold: false }
|
|
8012
8033
|
];
|
|
8013
8034
|
function normalizePrivateLessonText(value) {
|
|
8014
8035
|
return value.normalize("NFC").replace(/\r\n?/gu, "\n").replace(/[\t ]+/gu, " ").replace(/ *\n */gu, "\n").replace(/\n{3,}/gu, "\n\n").trim();
|
|
@@ -8043,6 +8064,141 @@ function redactPrivateLessonText(value) {
|
|
|
8043
8064
|
held_reasons: [...held].sort()
|
|
8044
8065
|
};
|
|
8045
8066
|
}
|
|
8067
|
+
function redactPrivateLessonTextWithSpans(value) {
|
|
8068
|
+
const normalized2 = normalizePrivateLessonText(value);
|
|
8069
|
+
const existingMarkers = [];
|
|
8070
|
+
let text = "";
|
|
8071
|
+
let origin = [];
|
|
8072
|
+
let cursor = 0;
|
|
8073
|
+
const keep = (from, to) => {
|
|
8074
|
+
text += normalized2.slice(from, to);
|
|
8075
|
+
for (let index = from; index < to; index += 1) {
|
|
8076
|
+
origin.push([index, index + 1]);
|
|
8077
|
+
}
|
|
8078
|
+
};
|
|
8079
|
+
const markers = new RegExp(
|
|
8080
|
+
EXISTING_REDACTION_MARKER.source,
|
|
8081
|
+
EXISTING_REDACTION_MARKER.flags
|
|
8082
|
+
);
|
|
8083
|
+
for (const match of normalized2.matchAll(markers)) {
|
|
8084
|
+
keep(cursor, match.index);
|
|
8085
|
+
const placeholder = `\uFFF0${existingMarkers.push(match[0]) - 1}\uFFF1`;
|
|
8086
|
+
text += placeholder;
|
|
8087
|
+
for (let index = 0; index < placeholder.length; index += 1) {
|
|
8088
|
+
origin.push([match.index, match.index + match[0].length]);
|
|
8089
|
+
}
|
|
8090
|
+
cursor = match.index + match[0].length;
|
|
8091
|
+
}
|
|
8092
|
+
keep(cursor, normalized2.length);
|
|
8093
|
+
const counts = {};
|
|
8094
|
+
const held = /* @__PURE__ */ new Set();
|
|
8095
|
+
const spans = [];
|
|
8096
|
+
for (const rule of REPLACEMENTS) {
|
|
8097
|
+
const marker = `[redacted:${rule.category}]`;
|
|
8098
|
+
let next = "";
|
|
8099
|
+
const nextOrigin = [];
|
|
8100
|
+
let position = 0;
|
|
8101
|
+
let matches = 0;
|
|
8102
|
+
for (const match of text.matchAll(
|
|
8103
|
+
new RegExp(rule.pattern.source, rule.pattern.flags)
|
|
8104
|
+
)) {
|
|
8105
|
+
next += text.slice(position, match.index);
|
|
8106
|
+
nextOrigin.push(...origin.slice(position, match.index));
|
|
8107
|
+
const start = origin[match.index]?.[0] ?? normalized2.length;
|
|
8108
|
+
const end = Math.max(
|
|
8109
|
+
start,
|
|
8110
|
+
origin[match.index + match[0].length - 1]?.[1] ?? start
|
|
8111
|
+
);
|
|
8112
|
+
spans.push({ category: rule.category, hold: rule.hold, start, end });
|
|
8113
|
+
next += marker;
|
|
8114
|
+
for (let index = 0; index < marker.length; index += 1) {
|
|
8115
|
+
nextOrigin.push([start, end]);
|
|
8116
|
+
}
|
|
8117
|
+
position = match.index + match[0].length;
|
|
8118
|
+
matches += 1;
|
|
8119
|
+
}
|
|
8120
|
+
if (matches === 0) continue;
|
|
8121
|
+
next += text.slice(position);
|
|
8122
|
+
nextOrigin.push(...origin.slice(position));
|
|
8123
|
+
text = next;
|
|
8124
|
+
origin = nextOrigin;
|
|
8125
|
+
counts[rule.category] = (counts[rule.category] ?? 0) + matches;
|
|
8126
|
+
if (rule.hold) held.add(rule.category);
|
|
8127
|
+
}
|
|
8128
|
+
text = text.replace(/\uFFF0(\d+)\uFFF1/gu, (_, index) => {
|
|
8129
|
+
return existingMarkers[Number(index)] ?? "[redacted:identifier]";
|
|
8130
|
+
});
|
|
8131
|
+
return {
|
|
8132
|
+
text: normalizePrivateLessonText(text),
|
|
8133
|
+
counts: privateLessonRedactionCountsSchema.parse(counts),
|
|
8134
|
+
held_reasons: [...held].sort(),
|
|
8135
|
+
spans
|
|
8136
|
+
};
|
|
8137
|
+
}
|
|
8138
|
+
var PRIVATE_LESSON_MAX_FINDINGS = 16;
|
|
8139
|
+
function privateLessonFindings(input) {
|
|
8140
|
+
const parsed = privateLessonPreparationInputSchema.parse(input);
|
|
8141
|
+
const findings = [];
|
|
8142
|
+
const textFields = [
|
|
8143
|
+
...parsed.generalized_lesson ? [["generalized_lesson", parsed.generalized_lesson, 0]] : [],
|
|
8144
|
+
...(parsed.stable_conditions ?? []).map(
|
|
8145
|
+
(condition, index) => [`stable_conditions[${index}]`, condition, 1 + index]
|
|
8146
|
+
)
|
|
8147
|
+
];
|
|
8148
|
+
for (const [field, value, rank] of textFields) {
|
|
8149
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
8150
|
+
for (const span of redactPrivateLessonTextWithSpans(value).spans) {
|
|
8151
|
+
byCategory.set(span.category, [
|
|
8152
|
+
...byCategory.get(span.category) ?? [],
|
|
8153
|
+
span
|
|
8154
|
+
]);
|
|
8155
|
+
}
|
|
8156
|
+
for (const [category, spans] of byCategory) {
|
|
8157
|
+
const first = spans.find((span) => span.hold) ?? spans[0];
|
|
8158
|
+
findings.push({
|
|
8159
|
+
field,
|
|
8160
|
+
category,
|
|
8161
|
+
rule: "text_pattern",
|
|
8162
|
+
occurrences: spans.length,
|
|
8163
|
+
approx_offset: first.start,
|
|
8164
|
+
length: first.end - first.start,
|
|
8165
|
+
holds: spans.some((span) => span.hold),
|
|
8166
|
+
rank
|
|
8167
|
+
});
|
|
8168
|
+
}
|
|
8169
|
+
}
|
|
8170
|
+
(parsed.tags ?? []).forEach((tag, index) => {
|
|
8171
|
+
if (inspectPrivateLessonTag(tag).tag !== null) return;
|
|
8172
|
+
const lowered = normalizePrivateLessonText(tag).toLowerCase();
|
|
8173
|
+
const aliased = PRIVATE_LESSON_SAFE_TAG_ALIASES[lowered] ?? lowered;
|
|
8174
|
+
const spans = redactPrivateLessonTextWithSpans(aliased).spans;
|
|
8175
|
+
const rule = spans.length > 0 ? "tag_pattern" : privateLessonTagSyntaxSchema.safeParse(aliased).success ? "tag_identity" : "tag_format";
|
|
8176
|
+
const categories = spans.length > 0 ? [...new Set(spans.map((span) => span.category))] : ["identifier"];
|
|
8177
|
+
for (const category of categories) {
|
|
8178
|
+
const matched = spans.filter((span) => span.category === category);
|
|
8179
|
+
findings.push({
|
|
8180
|
+
field: `tags[${index}]`,
|
|
8181
|
+
category,
|
|
8182
|
+
rule,
|
|
8183
|
+
occurrences: Math.max(1, matched.length),
|
|
8184
|
+
approx_offset: matched[0]?.start ?? 0,
|
|
8185
|
+
length: matched[0] ? matched[0].end - matched[0].start : aliased.length,
|
|
8186
|
+
holds: false,
|
|
8187
|
+
rank: 1e3 + index
|
|
8188
|
+
});
|
|
8189
|
+
}
|
|
8190
|
+
});
|
|
8191
|
+
findings.sort(
|
|
8192
|
+
(left, right) => Number(right.holds) - Number(left.holds) || left.rank - right.rank || left.approx_offset - right.approx_offset
|
|
8193
|
+
);
|
|
8194
|
+
return {
|
|
8195
|
+
findings: findings.slice(0, PRIVATE_LESSON_MAX_FINDINGS).map(({ rank: _rank, ...finding }) => finding),
|
|
8196
|
+
findings_omitted: Math.max(
|
|
8197
|
+
0,
|
|
8198
|
+
findings.length - PRIVATE_LESSON_MAX_FINDINGS
|
|
8199
|
+
)
|
|
8200
|
+
};
|
|
8201
|
+
}
|
|
8046
8202
|
function preparePrivateLessonCandidate(input, options = {}) {
|
|
8047
8203
|
input = privateLessonPreparationInputSchema.parse(input);
|
|
8048
8204
|
const redactedParts = [
|
|
@@ -8061,14 +8217,13 @@ function preparePrivateLessonCandidate(input, options = {}) {
|
|
|
8061
8217
|
}
|
|
8062
8218
|
const tagParts = (input.tags ?? []).map(inspectPrivateLessonTag);
|
|
8063
8219
|
const counts = {};
|
|
8064
|
-
const held = /* @__PURE__ */ new Set();
|
|
8065
8220
|
for (const part of [...redactedParts, ...tagParts]) {
|
|
8066
8221
|
for (const [category, count] of Object.entries(part.counts)) {
|
|
8067
8222
|
const key = category;
|
|
8068
8223
|
counts[key] = Math.min(999, (counts[key] ?? 0) + Number(count));
|
|
8069
8224
|
}
|
|
8070
|
-
for (const reason of part.held_reasons) held.add(reason);
|
|
8071
8225
|
}
|
|
8226
|
+
const held = new Set(redactedParts.flatMap((part) => part.held_reasons));
|
|
8072
8227
|
const lesson = redactedParts[0]?.text || null;
|
|
8073
8228
|
const candidate = privateLessonCanonicalPayloadSchema.parse({
|
|
8074
8229
|
contract_version: PRIVATE_LESSON_CONTRACT_VERSION,
|
|
@@ -8124,6 +8279,7 @@ function computePrivateLessonRedactorDigest() {
|
|
|
8124
8279
|
correlation_ids: "domain-separated-sha256-v1",
|
|
8125
8280
|
tag_syntax: PRIVATE_LESSON_TAG_PATTERN.source,
|
|
8126
8281
|
tag_safety: "redaction-plus-identity-hints-v2",
|
|
8282
|
+
tag_failure: "drop-and-count-v1",
|
|
8127
8283
|
tag_identity_hints: [...PRIVATE_LESSON_TAG_IDENTITY_HINTS].sort(),
|
|
8128
8284
|
tag_identity_label_suffixes: [
|
|
8129
8285
|
...PRIVATE_LESSON_TAG_IDENTITY_LABEL_SUFFIXES
|
|
@@ -8147,10 +8303,6 @@ function inspectPrivateLessonTag(value) {
|
|
|
8147
8303
|
const aliased = PRIVATE_LESSON_SAFE_TAG_ALIASES[normalized2] ?? normalized2;
|
|
8148
8304
|
const redacted = redactPrivateLessonText(aliased);
|
|
8149
8305
|
const counts = { ...redacted.counts };
|
|
8150
|
-
const held = /* @__PURE__ */ new Set([
|
|
8151
|
-
...redacted.held_reasons,
|
|
8152
|
-
...Object.keys(redacted.counts)
|
|
8153
|
-
]);
|
|
8154
8306
|
const identityHints = new Set(
|
|
8155
8307
|
aliased.split(/[-_]/u).filter((segment) => PRIVATE_LESSON_TAG_IDENTITY_HINTS.has(segment))
|
|
8156
8308
|
);
|
|
@@ -8158,21 +8310,10 @@ function inspectPrivateLessonTag(value) {
|
|
|
8158
8310
|
const isGenericOrganizationRelationship = segments.length === 2 && PRIVATE_LESSON_TAG_RELATIONAL_PREFIXES.has(segments[0] ?? "") && PRIVATE_LESSON_TAG_IDENTITY_LABEL_SUFFIXES.has(segments[1] ?? "");
|
|
8159
8311
|
const hasLikelyIdentityLabel = segments.length >= 2 && !isGenericOrganizationRelationship && PRIVATE_LESSON_TAG_IDENTITY_LABEL_SUFFIXES.has(segments.at(-1) ?? "") && segments.slice(0, -1).some((segment) => !PRIVATE_LESSON_TAG_IDENTITY_HINTS.has(segment));
|
|
8160
8312
|
if (!privateLessonTagSyntaxSchema.safeParse(aliased).success || redacted.text !== aliased || identityHints.size >= 2 || hasLikelyIdentityLabel) {
|
|
8161
|
-
if (
|
|
8162
|
-
|
|
8163
|
-
held.add("identifier");
|
|
8164
|
-
}
|
|
8165
|
-
return {
|
|
8166
|
-
tag: null,
|
|
8167
|
-
counts,
|
|
8168
|
-
held_reasons: [...held].sort()
|
|
8169
|
-
};
|
|
8313
|
+
if (Object.keys(counts).length === 0) counts.identifier = 1;
|
|
8314
|
+
return { tag: null, counts };
|
|
8170
8315
|
}
|
|
8171
|
-
return {
|
|
8172
|
-
tag: aliased,
|
|
8173
|
-
counts: {},
|
|
8174
|
-
held_reasons: []
|
|
8175
|
-
};
|
|
8316
|
+
return { tag: aliased, counts: {} };
|
|
8176
8317
|
}
|
|
8177
8318
|
function pseudonymizeCorrelationId(value) {
|
|
8178
8319
|
const digest2 = hashValue(
|
|
@@ -8184,6 +8325,7 @@ function pseudonymizeCorrelationId(value) {
|
|
|
8184
8325
|
return `corr_${digest2.slice(0, 48)}`;
|
|
8185
8326
|
}
|
|
8186
8327
|
var CURRENT_PRIVATE_LESSON_REDACTOR_DIGEST = computePrivateLessonRedactorDigest();
|
|
8328
|
+
var PRIVATE_LESSON_BROAD_HOLD_REDACTOR_DIGEST = "sha256:e3414b36b1f8d5512e42148c0d06b958c7010bbdb52024bd78ad4e68b0356324";
|
|
8187
8329
|
var PRIVATE_LESSON_LEGACY_V2_REDACTOR_DIGEST = "sha256:bca83ac50b0124a0401f806b3498bbb1ec977c02c1975d5345cb8d0b85c00b75";
|
|
8188
8330
|
var PRIVATE_LESSON_SUPPORTED_REDACTOR_PROFILES = Object.freeze({
|
|
8189
8331
|
[PRIVATE_LESSON_REDACTION_VERSION]: Object.freeze({
|
|
@@ -8192,6 +8334,14 @@ var PRIVATE_LESSON_SUPPORTED_REDACTOR_PROFILES = Object.freeze({
|
|
|
8192
8334
|
digest: CURRENT_PRIVATE_LESSON_REDACTOR_DIGEST,
|
|
8193
8335
|
normalization: "unicode-nfc-lf-space-v1"
|
|
8194
8336
|
}),
|
|
8337
|
+
// Retained drafts and candidates of published 0.2 clients keep a
|
|
8338
|
+
// supported profile; a candidate is still checked against the current
|
|
8339
|
+
// canonical schema and network-safety refinements.
|
|
8340
|
+
[PRIVATE_LESSON_BROAD_HOLD_REDACTOR_DIGEST]: Object.freeze({
|
|
8341
|
+
version: PRIVATE_LESSON_REDACTION_VERSION,
|
|
8342
|
+
digest: PRIVATE_LESSON_BROAD_HOLD_REDACTOR_DIGEST,
|
|
8343
|
+
normalization: "unicode-nfc-lf-space-v1"
|
|
8344
|
+
}),
|
|
8195
8345
|
// Published pre-negotiation clients produced this exact v2 profile.
|
|
8196
8346
|
// Retain it for the 0.2.x compatibility window; all candidates still pass
|
|
8197
8347
|
// the current canonical schema and network-safety refinements.
|
|
@@ -8219,6 +8369,27 @@ var PrivateLessonRedactionProfileError = class extends Error {
|
|
|
8219
8369
|
function privateLessonRedactorDigest() {
|
|
8220
8370
|
return CURRENT_PRIVATE_LESSON_REDACTOR_DIGEST;
|
|
8221
8371
|
}
|
|
8372
|
+
function privateLessonCurrentHoldReasons(candidate, heldReasons) {
|
|
8373
|
+
const known = new Set(privateLessonRedactionCategorySchema.options);
|
|
8374
|
+
const holding = new Set(
|
|
8375
|
+
REPLACEMENTS.filter((rule) => rule.hold).map((rule) => rule.category)
|
|
8376
|
+
);
|
|
8377
|
+
const text = [
|
|
8378
|
+
candidate.generalized_lesson ?? "",
|
|
8379
|
+
...candidate.stable_conditions
|
|
8380
|
+
].join("\n");
|
|
8381
|
+
return [
|
|
8382
|
+
.../* @__PURE__ */ new Set([
|
|
8383
|
+
...[...holding].filter(
|
|
8384
|
+
(category) => text.includes(`[redacted:${category}]`)
|
|
8385
|
+
),
|
|
8386
|
+
...heldReasons.filter((category) => holding.has(category)),
|
|
8387
|
+
...[...Object.keys(candidate.redaction_counts), ...heldReasons].filter(
|
|
8388
|
+
(category) => !known.has(category)
|
|
8389
|
+
)
|
|
8390
|
+
])
|
|
8391
|
+
].sort();
|
|
8392
|
+
}
|
|
8222
8393
|
function privateLessonSupportedRedactorProfiles() {
|
|
8223
8394
|
return Object.entries(PRIVATE_LESSON_SUPPORTED_REDACTOR_PROFILES).flatMap(
|
|
8224
8395
|
([redactionVersion, profiles]) => Object.keys(profiles).map((redactorDigest) => ({
|
|
@@ -8479,6 +8650,9 @@ var privateSkillReplacementLinkSchema = external_exports.object({
|
|
|
8479
8650
|
context_source: privateSkillReformulationContextSourceSchema,
|
|
8480
8651
|
recovery_context_id: external_exports.string().regex(/^pctx_[a-f0-9]{64}$/u).optional()
|
|
8481
8652
|
}).strict();
|
|
8653
|
+
var privateLessonReplacementLinkSchema = external_exports.object({
|
|
8654
|
+
draft_id: external_exports.string().regex(/^pld_[A-Za-z0-9_-]{8,96}$/u)
|
|
8655
|
+
}).strict();
|
|
8482
8656
|
var privateSkillCaptureSchema = privateSkillIdeaRequestSchema.omit({
|
|
8483
8657
|
agent: true,
|
|
8484
8658
|
enterprise_encryption: true,
|
|
@@ -8560,7 +8734,10 @@ var captureLearningInputSchema = external_exports.object({
|
|
|
8560
8734
|
contract_version: external_exports.literal(PRIVATE_LEARNING_CAPTURE_VERSION).default(PRIVATE_LEARNING_CAPTURE_VERSION),
|
|
8561
8735
|
lesson: privateLessonPreparationInputSchema.optional(),
|
|
8562
8736
|
private_skill: privateSkillCaptureSchema.optional(),
|
|
8563
|
-
replacement_of:
|
|
8737
|
+
replacement_of: external_exports.union([
|
|
8738
|
+
privateSkillReplacementLinkSchema,
|
|
8739
|
+
privateLessonReplacementLinkSchema
|
|
8740
|
+
]).optional(),
|
|
8564
8741
|
preference: recordPreferenceRequestSchema.optional()
|
|
8565
8742
|
}).strict().superRefine((value, ctx) => {
|
|
8566
8743
|
const populated = [
|
|
@@ -8574,10 +8751,11 @@ var captureLearningInputSchema = external_exports.object({
|
|
|
8574
8751
|
message: "Exactly one lesson, private_skill, or preference payload is required."
|
|
8575
8752
|
});
|
|
8576
8753
|
}
|
|
8577
|
-
|
|
8754
|
+
const replaces = value.replacement_of?.draft_id.slice(0, 4);
|
|
8755
|
+
if (replaces === "psd_" && value.private_skill === void 0 || replaces === "pld_" && value.lesson === void 0) {
|
|
8578
8756
|
ctx.addIssue({
|
|
8579
8757
|
code: external_exports.ZodIssueCode.custom,
|
|
8580
|
-
message: "replacement_of is valid only with a private_skill payload.",
|
|
8758
|
+
message: replaces === "psd_" ? "replacement_of with a private-skill draft_id is valid only with a private_skill payload." : "replacement_of with a private-lesson draft_id is valid only with a lesson payload.",
|
|
8581
8759
|
path: ["replacement_of"]
|
|
8582
8760
|
});
|
|
8583
8761
|
}
|
|
@@ -8601,7 +8779,7 @@ function captureLearningRoute(input) {
|
|
|
8601
8779
|
|
|
8602
8780
|
// ../core/src/agent-guidance.ts
|
|
8603
8781
|
var REMEMBRANCE_QUERY_TOOL_DESCRIPTION = "Call before non-trivial service, API, tool, library, workflow, UI, review, test, security, or deployment work to find relevant Remembrance skills and resources. This is a read-only routine action: do not ask the user for a separate conversational permission step. For short context-dependent follow-ups, infer the concrete task from the full conversation, preserve any plugin-supplied client_context.directive_id/runtime/trigger_reason, and query anyway. Compare each candidate's bounded why_matched evidence and applicability conditions before opening it; discard stated unlikely or corner-case mismatches. High matches should be fetched before custom work; possible and exploratory matches remain optional. Do not use for broad web search or one-off facts. Results refer by key or preference_fingerprint to preferences stated once in top-level effective_preferences, and get_skill returns the full text of a description_truncated summary. semantic_status says, without content, whether vector retrieval contributed to each result list; lexical_only results remain usable.";
|
|
8604
|
-
var REMEMBRANCE_QUERY_FEEDBACK_TOOL_DESCRIPTION = "Submit one complete set of bounded explicit good, partial, or poor judgments for result_id values from one query_skills call, using the same auth scope as that query. Use overall_fit none only when every rated result is poor; if any result is partial or good, use partial or good as appropriate. Keep honest per-result judgments when correcting validation errors; do not drop them or relabel matches to bypass validation. Each result_id appears once; poor ratings require at least one reason. This bounded feedback action carries no reusable content and needs no separate conversational permission request. Unrated results stay neutral. Notes are optional and compact; this path remains independent of private learning capture and never accepts a reusable lesson. An identical retry is safe, but changed later judgments conflict. Labels adjust bounded retrieval profiles without changing global skill usefulness; use submit_feedback only after actually using a skill.";
|
|
8782
|
+
var REMEMBRANCE_QUERY_FEEDBACK_TOOL_DESCRIPTION = "Submit one complete set of bounded explicit good, partial, or poor judgments for result_id values from one query_skills call, using the same auth scope as that query. Use overall_fit none only when every rated result is poor; if any result is partial or good, use partial or good as appropriate. Keep honest per-result judgments when correcting validation errors; do not drop them or relabel matches to bypass validation. Each result_id appears once; poor ratings require at least one reason. This bounded feedback action carries no reusable content and needs no separate conversational permission request. Unrated results stay neutral. Notes are optional and compact; this path remains independent of private learning capture and never accepts a reusable lesson. Keep routine organization ratings minimal: use the Remembrance-issued query_id and result_id values, judgments, required reasons, and an idempotency key when needed, and do not automatically attach internal artifact hashes, task text, source snippets, or raw logs. An identical retry is safe, but changed later judgments conflict. Labels adjust bounded retrieval profiles without changing global skill usefulness; use submit_feedback only after actually using a skill.";
|
|
8605
8783
|
var REMEMBRANCE_INVOKE_SKILL_TOOL_DESCRIPTION = "Load an explicitly selected skill through the authoritative policy boundary. Use an exact slug returned by list_skills, an MCP resource, or query_skills. This resolves the current active reviewed version, records direct selection, and returns post-use feedback and outcome instructions. Pass version_id only when a session-start directive or subagent handoff supplies one; that exact version is loaded and never substituted, and 409 skill_version_unavailable means it cannot be served. Use scope session only for an organization session skill named by a session-start directive; omit scope for ordinary task use. Do not use submit_query_feedback for this explicit selection.";
|
|
8606
8784
|
var REMEMBRANCE_CONNECTION_STATUS_TOOL_DESCRIPTION = "Inspect the active Remembrance transport, credential source, authenticated registry scope, and content-free recent contribution outcomes for the current installation or API key without exposing credentials or lesson content. Call this before diagnosing authentication, checking environment variables, or making anonymous REST/browser probes. Local or bundled MCP can read REMEMBRANCE_API_KEY or ~/.config/remembrance/config.json; hosted MCP cannot read local files and authenticates from its request header. When a declared native lifecycle is degraded, local MCP may submit bounded, content-free health evidence unless REMEMBRANCE_HEALTH_REPORTING=0. Never infer the plugin's scope from REMEMBRANCE_API_KEY alone.";
|
|
8607
8785
|
var REMEMBRANCE_CONNECTION_DOCTOR_TOOL_DESCRIPTION = "Run a bounded, non-mutating Remembrance connection diagnostic. It verifies the active transport, a redacted registry destination, authenticated scope, query authorization, a real catalog read, and organization submission capability. Local MCP also checks shared-config permissions, destination consistency, native plugin lifecycle, and signing identity; hosted MCP marks local-only checks unavailable. It never submits content, creates query demand, opens a review item, or returns credentials, absolute paths, private registry URLs, prompts, or repository data.";
|
|
@@ -23962,14 +24140,35 @@ var GEMINI_ADMIN_ALLOWED_TOOLS = Object.freeze(
|
|
|
23962
24140
|
(tool) => !isConfirmedDelete(tool)
|
|
23963
24141
|
)
|
|
23964
24142
|
);
|
|
24143
|
+
var GEMINI_CLI_CHECKED_VERSION = "0.62.0";
|
|
24144
|
+
var GEMINI_ADMIN_POLICY_FILES = Object.freeze({
|
|
24145
|
+
rules: "remembrance.toml",
|
|
24146
|
+
fallback: "remembrance-fallback.toml"
|
|
24147
|
+
});
|
|
23965
24148
|
var json = (value) => JSON.stringify(value, null, 2);
|
|
23966
24149
|
var approveTables = (server, names = tools) => names.map((tool) => `[${server}.tools.${tool}]
|
|
23967
24150
|
approval_mode = "approve"`).join("\n\n");
|
|
23968
|
-
var geminiRule = (tool, decision = "allow") =>
|
|
23969
|
-
|
|
23970
|
-
|
|
23971
|
-
|
|
23972
|
-
|
|
24151
|
+
var geminiRule = (tool, decision = "allow", priority = 200) => [
|
|
24152
|
+
"[[rule]]",
|
|
24153
|
+
'mcpName = "remembrance"',
|
|
24154
|
+
`toolName = "${tool}"`,
|
|
24155
|
+
...decision === "allow" ? ["toolAnnotations = { destructiveHint = false }"] : [],
|
|
24156
|
+
`decision = "${decision}"`,
|
|
24157
|
+
`priority = ${priority}`
|
|
24158
|
+
].join("\n");
|
|
24159
|
+
var geminiFullNameAsk = (tool) => `[[rule]]
|
|
24160
|
+
toolName = "mcp_remembrance_${tool}"
|
|
24161
|
+
decision = "ask_user"
|
|
24162
|
+
priority = 150`;
|
|
24163
|
+
var geminiFullNameAsks = (names) => names.map(
|
|
24164
|
+
(tool, index) => index === 0 ? [
|
|
24165
|
+
"# Every tool again by the full name Gemini CLI also checks calls by,",
|
|
24166
|
+
"# only ever asking. The allow rules above outrank them, so those tools",
|
|
24167
|
+
"# still run in every mode, plan mode over ACP included, and both",
|
|
24168
|
+
"# confirmed-delete tools ask in every mode, YOLO included.",
|
|
24169
|
+
geminiFullNameAsk(tool)
|
|
24170
|
+
].join("\n") : geminiFullNameAsk(tool)
|
|
24171
|
+
);
|
|
23973
24172
|
var claudeCodePluginTools = withCapture.map(
|
|
23974
24173
|
(tool) => `mcp__plugin_remembrance_remembrance__${tool}`
|
|
23975
24174
|
);
|
|
@@ -24042,7 +24241,12 @@ var PRIVATE_SUBMISSION_APPROVAL_SNIPPETS = Object.freeze({
|
|
|
24042
24241
|
geminiCli: [
|
|
24043
24242
|
...tools.map((tool) => geminiRule(tool)),
|
|
24044
24243
|
`${localOnlyComment}
|
|
24045
|
-
${geminiRule(capture)}
|
|
24244
|
+
${geminiRule(capture)}`,
|
|
24245
|
+
...geminiFullNameAsks([
|
|
24246
|
+
...tools,
|
|
24247
|
+
capture,
|
|
24248
|
+
...PRIVATE_SUBMISSION_CONFIRMED_DELETE_TOOLS
|
|
24249
|
+
])
|
|
24046
24250
|
].join("\n\n"),
|
|
24047
24251
|
// The managed recipe's admin policy file. It holds the step's own rules
|
|
24048
24252
|
// above exactly once, so administrators use it instead of them.
|
|
@@ -24051,15 +24255,26 @@ ${geminiRule(capture)}`
|
|
|
24051
24255
|
"# One exact rule per tool in includeTools: allow, except the two",
|
|
24052
24256
|
"# confirmed-delete tools, which ask. To make a tool ask, change its",
|
|
24053
24257
|
'# decision to "ask_user" rather than deleting its rule: an admin ask',
|
|
24054
|
-
"# outranks users' own allow rules, and without one a user's allow decides."
|
|
24258
|
+
"# outranks users' own allow rules, and without one a user's allow decides.",
|
|
24259
|
+
"# Keep each allow rule's toolAnnotations line: it stops the rule from also",
|
|
24260
|
+
"# allowing another server's tool that has the same full name."
|
|
24055
24261
|
].join("\n"),
|
|
24056
24262
|
...REMEMBRANCE_MCP_RECOMMENDED_LOCAL_ORG_TOOLS.map((tool) => {
|
|
24057
24263
|
if (isConfirmedDelete(tool)) return geminiRule(tool, "ask_user");
|
|
24058
24264
|
if (tool === capture) return `${localOnlyComment}
|
|
24059
24265
|
${geminiRule(tool)}`;
|
|
24060
24266
|
return geminiRule(tool);
|
|
24061
|
-
})
|
|
24062
|
-
|
|
24267
|
+
}),
|
|
24268
|
+
...geminiFullNameAsks(REMEMBRANCE_MCP_RECOMMENDED_LOCAL_ORG_TOOLS)
|
|
24269
|
+
].join("\n\n"),
|
|
24270
|
+
// Only where mcp.allowed lists Remembrance, which allows every tool of the
|
|
24271
|
+
// server: this admin ask outranks that allow for each tool without its own
|
|
24272
|
+
// rule above, and those rules, at priority 200, still win for their tools.
|
|
24273
|
+
geminiCliAdminFallback: [
|
|
24274
|
+
`# Save as its own file, ${GEMINI_ADMIN_POLICY_FILES.fallback}, only where`,
|
|
24275
|
+
"# mcp.allowed lists Remembrance; keep toolName, or Gemini CLI skips the file.",
|
|
24276
|
+
geminiRule("*", "ask_user", 100)
|
|
24277
|
+
].join("\n")
|
|
24063
24278
|
});
|
|
24064
24279
|
|
|
24065
24280
|
// ../core/src/private-skill-completion.ts
|
|
@@ -24664,7 +24879,7 @@ var seedSkills = [
|
|
|
24664
24879
|
summary: "Operational setup and troubleshooting workflow for Remembrance across Claude Code, Codex, OpenClaw, Cursor, Gemini, MCP, REST, skill-only installs, enterprise keys, and local agent identity.",
|
|
24665
24880
|
status: "active",
|
|
24666
24881
|
visibility: "public",
|
|
24667
|
-
version: "0.1.
|
|
24882
|
+
version: "0.1.40",
|
|
24668
24883
|
domains: ["agent-skills", "mcp", "resource-discovery"],
|
|
24669
24884
|
tags: [
|
|
24670
24885
|
"remembrance",
|
|
@@ -24715,7 +24930,7 @@ var seedSkills = [
|
|
|
24715
24930
|
"gemini",
|
|
24716
24931
|
"rest"
|
|
24717
24932
|
],
|
|
24718
|
-
version: "0.1.
|
|
24933
|
+
version: "0.1.40",
|
|
24719
24934
|
status: "active",
|
|
24720
24935
|
visibility: "public",
|
|
24721
24936
|
providers: ["codex", "claude", "cursor", "openclaw", "generic"],
|
|
@@ -24904,22 +25119,26 @@ claude plugin install remembrance@remembrance
|
|
|
24904
25119
|
|
|
24905
25120
|
Codex:
|
|
24906
25121
|
|
|
25122
|
+
**Codex CLI.** The Codex plugin needs a Codex CLI: \`codex\` on your PATH or, on
|
|
25123
|
+
macOS, the CLI bundled in the ChatGPT desktop app. The setup, update and
|
|
25124
|
+
hook-review commands run the newest one they find, so an older \`codex\` on PATH
|
|
25125
|
+
cannot shadow the app's newer CLI; set \`CODEX_CLI\` to a CLI's full path to
|
|
25126
|
+
choose one yourself. No other host needs the Codex CLI.
|
|
25127
|
+
|
|
24907
25128
|
~~~bash
|
|
24908
|
-
|
|
24909
|
-
[ -x "$CODEX_CLI" ] || CODEX_CLI="/Applications/ChatGPT.app/Contents/Resources/codex"
|
|
24910
|
-
[ -x "$CODEX_CLI" ] || CODEX_CLI="/Applications/Codex.app/Contents/Resources/codex"
|
|
24911
|
-
[ -x "$CODEX_CLI" ] || { printf '%s\\n' "Codex CLI not found. Install the Codex CLI, or install or update the ChatGPT desktop app on macOS, then try again." >&2; exit 1; }
|
|
24912
|
-
"$CODEX_CLI" plugin marketplace add dreamarkinc/remembrance-skills &&
|
|
24913
|
-
"$CODEX_CLI" plugin marketplace upgrade remembrance &&
|
|
24914
|
-
"$CODEX_CLI" plugin add remembrance@remembrance &&
|
|
24915
|
-
"$CODEX_CLI"
|
|
25129
|
+
${CODEX_PLUGIN_SETUP_COMMAND}
|
|
24916
25130
|
~~~
|
|
24917
25131
|
|
|
24918
25132
|
This command handles both first install and update. If zsh says
|
|
24919
|
-
"codex: command not found", it
|
|
24920
|
-
|
|
24921
|
-
|
|
24922
|
-
|
|
25133
|
+
"codex: command not found", it still finds the CLI bundled in the ChatGPT
|
|
25134
|
+
desktop app without requiring a shell alias. The final command opens Codex CLI
|
|
25135
|
+
so its secure hook review can be completed immediately when Codex requires it.
|
|
25136
|
+
|
|
25137
|
+
The block runs in a subshell, so a failure prints a message and leaves your
|
|
25138
|
+
terminal open. It uses \`CODEX_CLI\` when set; otherwise it runs the newest of
|
|
25139
|
+
\`codex\` on PATH, the ChatGPT desktop app's bundled CLI
|
|
25140
|
+
(\`/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex\`) and the
|
|
25141
|
+
older bundle paths, and stops at the first failed step.
|
|
24923
25142
|
|
|
24924
25143
|
Codex will not execute plugin hooks until their exact definitions are trusted.
|
|
24925
25144
|
In the Codex window opened by the installer, if Codex shows a **Hooks need
|
|
@@ -25104,6 +25323,39 @@ only the capture is reviewed; its submission still must not prompt.
|
|
|
25104
25323
|
\`run_connection_doctor\` cannot see a persisted approval; its \`host_approval\`
|
|
25105
25324
|
field reports only recent denials.
|
|
25106
25325
|
|
|
25326
|
+
### Unattended runs
|
|
25327
|
+
|
|
25328
|
+
A run no person attends, such as a scheduled job, \`codex exec\` or
|
|
25329
|
+
\`claude -p\`, cannot answer the user decisions the hooks ask about retained
|
|
25330
|
+
private drafts: deliver, keep or delete. To keep its learning going without
|
|
25331
|
+
using those decisions up:
|
|
25332
|
+
|
|
25333
|
+
1. Approve the four private submit and retry tools as above, so the run
|
|
25334
|
+
delivers its own lessons and skills. On a host that asks, a run nobody can
|
|
25335
|
+
answer denies them, and the draft waits in the outbox.
|
|
25336
|
+
2. Start the run with \`REMEMBRANCE_UNATTENDED=1\`. Its hooks then show none of
|
|
25337
|
+
the user decisions (drafts awaiting the user, held drafts, parked drafts
|
|
25338
|
+
coming back), so none is used up, and the next prompt a person makes on the
|
|
25339
|
+
machine gets them. The run still captures and delivers its own lessons,
|
|
25340
|
+
and nothing about the drafts changes.
|
|
25341
|
+
- Codex: \`REMEMBRANCE_UNATTENDED=1 codex exec ...\`.
|
|
25342
|
+
- Claude Code: \`REMEMBRANCE_UNATTENDED=1 claude -p ...\`, or
|
|
25343
|
+
\`{"env":{"REMEMBRANCE_UNATTENDED":"1"}}\` in settings only those runs
|
|
25344
|
+
load: \`--settings\`, or \`.claude/settings.local.json\` in a folder only
|
|
25345
|
+
scheduled runs use.
|
|
25346
|
+
- OpenCode: \`REMEMBRANCE_UNATTENDED=1 opencode run ...\`. A run attached
|
|
25347
|
+
to a server that is already running follows that server's environment.
|
|
25348
|
+
- Cursor and VS Code: the environment the app or CLI starts its hooks
|
|
25349
|
+
with. Cursor asks these decisions only with
|
|
25350
|
+
\`REMEMBRANCE_VISIBLE_COMPLETION_RECOVERY=1\`.
|
|
25351
|
+
- OpenClaw: the Gateway's environment. It then applies to every session
|
|
25352
|
+
that Gateway serves, so set it only on a Gateway or profile that serves
|
|
25353
|
+
no person.
|
|
25354
|
+
|
|
25355
|
+
Leave \`REMEMBRANCE_UNATTENDED\` unset for sessions a person uses. Do not set
|
|
25356
|
+
\`REMEMBRANCE_AUTO_CONTRIBUTE=0\` for this instead: it also stops the run's own
|
|
25357
|
+
learning.
|
|
25358
|
+
|
|
25107
25359
|
### Claude Code
|
|
25108
25360
|
|
|
25109
25361
|
Merge these entries into \`permissions.allow\` in \`~/.claude/settings.json\`,
|
|
@@ -25247,21 +25499,54 @@ mixed-version installs, use allow-always.
|
|
|
25247
25499
|
|
|
25248
25500
|
### Gemini CLI
|
|
25249
25501
|
|
|
25250
|
-
Create \`~/.gemini/policies/remembrance.toml\` with one rule per tool
|
|
25251
|
-
|
|
25502
|
+
Create \`~/.gemini/policies/remembrance.toml\` with one allow rule per tool, the
|
|
25503
|
+
last of them the local-only \`capture_learning\` entry, then one ask rule for
|
|
25504
|
+
each of those tools and for both confirmed-delete tools, by the full names
|
|
25505
|
+
Gemini CLI gives them:
|
|
25252
25506
|
|
|
25253
25507
|
~~~toml
|
|
25254
25508
|
${PRIVATE_SUBMISSION_APPROVAL_SNIPPETS.geminiCli}
|
|
25255
25509
|
~~~
|
|
25256
25510
|
|
|
25257
|
-
Gemini CLI asks before
|
|
25258
|
-
|
|
25259
|
-
|
|
25260
|
-
|
|
25261
|
-
|
|
25262
|
-
|
|
25263
|
-
|
|
25264
|
-
|
|
25511
|
+
Without a rule, Gemini CLI asks before a Remembrance tool in its default
|
|
25512
|
+
and auto-edit modes; YOLO mode runs the tool without asking, and plan mode
|
|
25513
|
+
blocks it or, for a read-only tool, asks. A headless run, such as
|
|
25514
|
+
\`gemini -p\`, cannot ask: the model never sees a tool that no rule covers, and
|
|
25515
|
+
a tool whose rule asks is denied. These rules cover private learning only, so a
|
|
25516
|
+
headless run also needs rules for the other Remembrance tools it calls, such as
|
|
25517
|
+
\`query_skills\`. The rules name no approval mode, so they also apply in plan
|
|
25518
|
+
mode: there the five tools run without a prompt, private submissions included.
|
|
25519
|
+
|
|
25520
|
+
Gemini CLI also checks some calls under the server name \`mcp_remembrance\`,
|
|
25521
|
+
which no rule with \`mcpName = "remembrance"\` matches: in an IDE connected
|
|
25522
|
+
over ACP, before any other check, and in the terminal, after a rule asks. There
|
|
25523
|
+
only the rules that name a tool by its full name, \`mcp_remembrance_<tool>\`,
|
|
25524
|
+
match, and they only ask. In plan mode over ACP, that ask hands the call on to
|
|
25525
|
+
the allow rules, so the five tools run; without it, plan mode denies them. Both
|
|
25526
|
+
delete tools ask in every mode, YOLO included, whether Gemini CLI starts with
|
|
25527
|
+
\`--yolo\` or the user turns it on with Ctrl+Y; without their full-name rules,
|
|
25528
|
+
YOLO mode runs both without asking. Never change a full-name rule to allow: a
|
|
25529
|
+
rule without \`mcpName\` also matches another server's tool that has the same
|
|
25530
|
+
full name, such as the tool \`private_lesson_candidate\` of a server named
|
|
25531
|
+
\`remembrance_submit\`.
|
|
25532
|
+
|
|
25533
|
+
Each allow rule also requires \`destructiveHint = false\`, which Remembrance's
|
|
25534
|
+
server declares for every tool except the two delete tools. Gemini CLI checks a
|
|
25535
|
+
subagent's calls without the server name or the tool's annotations, and takes
|
|
25536
|
+
the server name from the full name, so without that condition an allow rule
|
|
25537
|
+
would also let a subagent run such a look-alike tool without asking; with it,
|
|
25538
|
+
the full-name rule makes that call ask. A user's own "Allow tool for this
|
|
25539
|
+
session" or "Allow all server tools for this session" answer still stops the
|
|
25540
|
+
prompts until Gemini CLI restarts.
|
|
25541
|
+
|
|
25542
|
+
Keep \`trust\` false and do not list the server in \`mcp.allowed\`: Gemini CLI
|
|
25543
|
+
turns \`trust: true\` and an \`mcp.allowed\` entry alike into an allow rule for
|
|
25544
|
+
every tool of the server. A \`--policy\` flag or a \`policyPaths\` setting
|
|
25545
|
+
replaces \`~/.gemini/policies\`, and Gemini CLI then does not read this file.
|
|
25546
|
+
Gemini CLI starts MCP servers only in a trusted folder; "Approve Gemini CLI"
|
|
25547
|
+
covers unattended runs. Administrators use the admin policy file in "Approve
|
|
25548
|
+
Gemini CLI" instead, which already contains these rules. Checked against Gemini
|
|
25549
|
+
CLI ${GEMINI_CLI_CHECKED_VERSION}.
|
|
25265
25550
|
|
|
25266
25551
|
### Claude Desktop and other MCP clients
|
|
25267
25552
|
|
|
@@ -25354,8 +25639,12 @@ memory, encrypts only the canonical safe record in a local outbox, and returns
|
|
|
25354
25639
|
a draft ID. It never writes the original input to disk, logs, telemetry, or
|
|
25355
25640
|
error output. Tags
|
|
25356
25641
|
use an open, bounded lowercase slug vocabulary; new technical terms survive,
|
|
25357
|
-
while malformed or privacy-sensitive
|
|
25358
|
-
|
|
25642
|
+
while a malformed or privacy-sensitive tag is dropped and counted. Each
|
|
25643
|
+
redaction match becomes its marker and the lesson continues; only a stack
|
|
25644
|
+
trace or zero-width or bidirectional control characters hold the draft
|
|
25645
|
+
locally. A draft an earlier client held that the current check would send is
|
|
25646
|
+
offered to the user once to deliver, keep, or delete; only the user's choice
|
|
25647
|
+
delivers it.
|
|
25359
25648
|
|
|
25360
25649
|
The plugin then calls \`submit_private_lesson_candidate\` with that draft ID.
|
|
25361
25650
|
This is the host-visible network action in the flow, and
|
|
@@ -25457,6 +25746,17 @@ requirements also carry an \`mcp_servers\` allowlist, approve this server by its
|
|
|
25457
25746
|
configured command (\`sh\`): Codex disables a server whose name and identity do
|
|
25458
25747
|
not match an approved entry.
|
|
25459
25748
|
|
|
25749
|
+
Codex checks only a server's name and how it is launched, never the plugin's
|
|
25750
|
+
files. The string form, \`identity = { command = "sh" }\`, compares the command
|
|
25751
|
+
alone; the structured form also compares each positional argument, but neither
|
|
25752
|
+
inspects the working directory or environment. So another local server with
|
|
25753
|
+
the same name and identity, such as one a user adds to their own
|
|
25754
|
+
\`config.toml\`, can pass the same check; the marketplace source restriction is
|
|
25755
|
+
what limits where the plugin itself comes from. OpenAI's managed-configuration
|
|
25756
|
+
documentation does not say whether a plugin's bundled server is checked
|
|
25757
|
+
against \`plugins.<plugin>.mcp_servers.<server>\` entries, top-level
|
|
25758
|
+
\`mcp_servers\` entries, or both.
|
|
25759
|
+
|
|
25460
25760
|
Add these entries to \`requirements.toml\`:
|
|
25461
25761
|
|
|
25462
25762
|
~~~toml
|
|
@@ -25717,9 +26017,10 @@ work. See the official
|
|
|
25717
26017
|
|
|
25718
26018
|
### Approve Gemini CLI
|
|
25719
26019
|
|
|
25720
|
-
|
|
25721
|
-
|
|
25722
|
-
|
|
26020
|
+
This recipe was checked against Gemini CLI ${GEMINI_CLI_CHECKED_VERSION}; check it again
|
|
26021
|
+
after upgrading Gemini CLI. Define the canonical server and its tool allowlist
|
|
26022
|
+
in the system override settings, not only user or workspace settings. Keep
|
|
26023
|
+
\`trust\` false; \`trust: true\` bypasses every confirmation for the server:
|
|
25723
26024
|
|
|
25724
26025
|
~~~json
|
|
25725
26026
|
{
|
|
@@ -25741,50 +26042,151 @@ ${geminiIncludeToolJson}
|
|
|
25741
26042
|
~~~
|
|
25742
26043
|
|
|
25743
26044
|
Approve tools only with exact per-tool policy rules. Do not list the server in
|
|
25744
|
-
\`mcp.allowed\`: the server runs without it, and
|
|
25745
|
-
|
|
25746
|
-
Instead, save this file as
|
|
25747
|
-
\`/Library/Application Support/GeminiCli/policies\` on macOS,
|
|
26045
|
+
\`mcp.allowed\`: the server runs without it, and Gemini CLI turns each
|
|
26046
|
+
\`mcp.allowed\` entry into an allow rule for every tool of that server.
|
|
26047
|
+
Instead, save this file as \`${GEMINI_ADMIN_POLICY_FILES.rules}\` in the admin policy
|
|
26048
|
+
folder: \`/Library/Application Support/GeminiCli/policies\` on macOS,
|
|
25748
26049
|
\`/etc/gemini-cli/policies\` on Linux, or \`C:\\ProgramData\\gemini-cli\\policies\`
|
|
25749
|
-
on Windows.
|
|
26050
|
+
on Windows.
|
|
25750
26051
|
|
|
25751
26052
|
~~~toml
|
|
25752
26053
|
${PRIVATE_SUBMISSION_APPROVAL_SNIPPETS.geminiCliAdmin}
|
|
25753
26054
|
~~~
|
|
25754
26055
|
|
|
26056
|
+
Gemini CLI checks the folder, not the files in it. On macOS and Linux the
|
|
26057
|
+
folder must be owned by root and not writable by group or others. On Windows it
|
|
26058
|
+
must be owned by Administrators, SYSTEM or a system service, and only those may
|
|
26059
|
+
have write access to it, so remove any write access for Users, such as rights
|
|
26060
|
+
inherited from \`C:\\ProgramData\`. Otherwise Gemini CLI skips the whole folder
|
|
26061
|
+
with a security warning. It loads only regular \`.toml\` files, not symbolic
|
|
26062
|
+
links, and checks neither the files' owner nor the parent folders, so keep
|
|
26063
|
+
those owned and writable only by administrators as well. Once the folder holds
|
|
26064
|
+
a \`.toml\` file, Gemini CLI ignores \`--admin-policy\` and \`adminPolicyPaths\`,
|
|
26065
|
+
with a warning.
|
|
26066
|
+
|
|
25755
26067
|
The file has one exact rule for every tool in \`includeTools\`: an allow rule
|
|
25756
26068
|
for each tool except the two confirmed-delete tools, whose admin \`ask_user\`
|
|
25757
|
-
rules
|
|
25758
|
-
them.
|
|
25759
|
-
recipe, whose \`mcp.allowed\` entry let every
|
|
25760
|
-
|
|
25761
|
-
|
|
25762
|
-
|
|
25763
|
-
|
|
25764
|
-
|
|
25765
|
-
|
|
25766
|
-
|
|
26069
|
+
rules make them ask even where a user's own rule allows them, so a headless run
|
|
26070
|
+
denies them. In Gemini CLI's default, auto-edit and YOLO modes, this reproduces
|
|
26071
|
+
the earlier behavior of this recipe, whose \`mcp.allowed\` entry let every
|
|
26072
|
+
included tool run, apart from those two, with exact rules instead of a
|
|
26073
|
+
whole-server rule. Unlike that entry, the rules name no approval mode, so they
|
|
26074
|
+
also apply in plan mode: there the allowed Remembrance tools run as well,
|
|
26075
|
+
private submissions included, and the two delete tools still ask. The file
|
|
26076
|
+
already contains the rules from "Highly Recommended: approve private
|
|
26077
|
+
submissions" for the four private submit and retry tools and the local-only
|
|
26078
|
+
\`capture_learning\`, so do not add those again. To make a tool ask, change its
|
|
26079
|
+
rule to \`decision = "ask_user"\` instead of deleting the rule: an admin-tier ask
|
|
26080
|
+
outranks users' own allow rules, while without an admin rule a user's allow
|
|
26081
|
+
rule decides. A headless run then denies that tool.
|
|
26082
|
+
|
|
26083
|
+
The rules after those name every tool in \`includeTools\` again by the full
|
|
26084
|
+
name Gemini CLI gives it, \`mcp_remembrance_<tool>\`, without \`mcpName\`, and
|
|
26085
|
+
only ask. Gemini CLI ${GEMINI_CLI_CHECKED_VERSION} also checks calls under the server
|
|
26086
|
+
name \`mcp_remembrance\`, which no rule with \`mcpName = "remembrance"\`
|
|
26087
|
+
matches: in an IDE connected over ACP before any other check, and in the
|
|
26088
|
+
terminal after a rule asks. Without a full-name rule, the mode's own default
|
|
26089
|
+
decides there: plan mode denies every tool not marked read-only, and YOLO mode
|
|
26090
|
+
allows every tool. With them, that check only asks. Over ACP it then hands the
|
|
26091
|
+
call on to the exact rules, so the allowed tools run in plan mode as well, and
|
|
26092
|
+
both delete tools ask in every approval mode, YOLO included, whether Gemini
|
|
26093
|
+
CLI started with \`--yolo\` or the user turned it on with Ctrl+Y, while a
|
|
26094
|
+
headless run refuses them. Never change them to allow: without \`mcpName\`, a
|
|
26095
|
+
rule also matches another server's tool that has the same full name, such as
|
|
26096
|
+
the tool \`skills\` of a server named \`remembrance_query\`, whose full name is
|
|
26097
|
+
\`mcp_remembrance_query_skills\`.
|
|
26098
|
+
|
|
26099
|
+
Each allow rule also requires \`destructiveHint = false\`, which Remembrance's
|
|
26100
|
+
server declares for every tool except the two delete tools. Gemini CLI checks a
|
|
26101
|
+
subagent's calls without the server name or the tool's annotations, and takes
|
|
26102
|
+
the server name from the full name, so without that condition the allow rule
|
|
26103
|
+
for \`query_skills\` would also let a subagent run that \`skills\` tool without
|
|
26104
|
+
asking. With it, such a call asks, while Remembrance's own tools still run.
|
|
26105
|
+
|
|
26106
|
+
The delete tools' admin ask rules hold against users' policy rules, but not
|
|
26107
|
+
against a user's own answer to the prompt. After "Allow tool for this session",
|
|
26108
|
+
Gemini CLI does not ask before that tool again until it restarts, and "Allow
|
|
26109
|
+
all server tools for this session" on any Remembrance prompt does the same for
|
|
26110
|
+
every Remembrance tool, both deletes included. Where every delete must ask,
|
|
26111
|
+
also set \`security.disableAlwaysAllow\` to \`true\` in the system settings:
|
|
26112
|
+
Gemini CLI then offers neither answer for any tool, so each tool that asks does
|
|
26113
|
+
so every time.
|
|
26114
|
+
|
|
26115
|
+
To keep users out of YOLO mode altogether, also set \`security.disableYoloMode\`
|
|
26116
|
+
to \`true\` in the system settings. Gemini CLI then refuses to start in YOLO
|
|
26117
|
+
mode, in the terminal, headless or over ACP, and refuses Ctrl+Y. It does not
|
|
26118
|
+
stop an IDE connected over ACP from switching a running session to YOLO mode,
|
|
26119
|
+
so keep the full-name rules above either way.
|
|
25767
26120
|
|
|
25768
26121
|
If the organization already restricts servers with \`mcp.allowed\`, Remembrance
|
|
25769
26122
|
must be listed there to run, and that entry creates the whole-server allow rule.
|
|
25770
|
-
Then also
|
|
25771
|
-
|
|
25772
|
-
|
|
25773
|
-
|
|
26123
|
+
Then also save this rule in the admin policy folder as its own file,
|
|
26124
|
+
\`${GEMINI_ADMIN_POLICY_FILES.fallback}\`, next to \`${GEMINI_ADMIN_POLICY_FILES.rules}\`. It creates no
|
|
26125
|
+
allow rule: admin rules outrank the one \`mcp.allowed\` creates, so a
|
|
26126
|
+
Remembrance tool without its own admin rule asks again, while the per-tool rules
|
|
26127
|
+
above, at priority 200, still win over it for their tools. Keep
|
|
26128
|
+
\`toolName = "*"\`, which matches every tool of the \`remembrance\` server, and
|
|
26129
|
+
keep the rule out of \`${GEMINI_ADMIN_POLICY_FILES.rules}\`: Gemini CLI rejects a rule
|
|
26130
|
+
without \`toolName\`, although its policy engine guide shows one, and an invalid
|
|
26131
|
+
rule makes it skip every rule in the same file.
|
|
25774
26132
|
|
|
25775
26133
|
~~~toml
|
|
25776
|
-
|
|
25777
|
-
mcpName = "remembrance"
|
|
25778
|
-
decision = "ask_user"
|
|
25779
|
-
priority = 100
|
|
26134
|
+
${PRIVATE_SUBMISSION_APPROVAL_SNIPPETS.geminiCliAdminFallback}
|
|
25780
26135
|
~~~
|
|
25781
26136
|
|
|
25782
26137
|
System settings live at \`/Library/Application Support/GeminiCli/settings.json\`
|
|
25783
26138
|
on macOS, \`/etc/gemini-cli/settings.json\` on Linux, and
|
|
25784
|
-
\`C:\\ProgramData\\gemini-cli\\settings.json\` on Windows.
|
|
25785
|
-
|
|
25786
|
-
|
|
25787
|
-
|
|
26139
|
+
\`C:\\ProgramData\\gemini-cli\\settings.json\` on Windows. Gemini CLI checks
|
|
26140
|
+
that file and every folder above it the way it checks the admin policy folder,
|
|
26141
|
+
on Windows \`C:\\ProgramData\` included, and skips the file with a security
|
|
26142
|
+
warning when one fails. System settings outrank user and workspace settings but
|
|
26143
|
+
are not locked: Gemini CLI reads them from whatever file
|
|
26144
|
+
\`GEMINI_CLI_SYSTEM_SETTINGS_PATH\` names, so a user who controls the
|
|
26145
|
+
environment it starts in can drop this definition and use their own, for
|
|
26146
|
+
example without \`includeTools\` or with \`trust: true\`, which in a trusted
|
|
26147
|
+
folder also skips the admin ask rules. The admin policy folder cannot be moved
|
|
26148
|
+
that way. Where this matters, start Gemini CLI through a wrapper that sets the
|
|
26149
|
+
variable to the managed file, as Gemini CLI's enterprise guide describes.
|
|
26150
|
+
|
|
26151
|
+
The system settings also do not cover the MCP servers a subagent defines for
|
|
26152
|
+
itself, or the server list an IDE sends when it opens a session over ACP.
|
|
26153
|
+
Either can define its own server named \`remembrance\` that runs another
|
|
26154
|
+
command, without \`includeTools\`, and Gemini CLI ${GEMINI_CLI_CHECKED_VERSION} then
|
|
26155
|
+
applies the allow rules to that server's tools of the same names. A subagent
|
|
26156
|
+
definition in \`~/.gemini/agents\`, or one the user accepts from a trusted
|
|
26157
|
+
project's \`.gemini/agents\` folder, can also set \`trust: true\`, and that
|
|
26158
|
+
subagent then runs both delete tools without asking: in the terminal in every
|
|
26159
|
+
mode except plan mode, which does not run it, and over ACP in YOLO mode. An
|
|
26160
|
+
IDE's server list cannot set \`trust\`, so both delete tools still ask there.
|
|
26161
|
+
Where every delete must ask, also set \`experimental.enableAgents\` to
|
|
26162
|
+
\`false\` in the system settings. Gemini CLI then loads no subagents, its
|
|
26163
|
+
built-in ones included.
|
|
26164
|
+
|
|
26165
|
+
This recipe was not tested on Windows. A default Windows install may let the
|
|
26166
|
+
Users group create files and folders in \`C:\\ProgramData\`. If it does, Gemini
|
|
26167
|
+
CLI ${GEMINI_CLI_CHECKED_VERSION} skips \`C:\\ProgramData\\gemini-cli\\settings.json\` on
|
|
26168
|
+
every machine, and the admin policy folder too unless its inherited Users
|
|
26169
|
+
rights are removed. To check, run \`icacls C:\\ProgramData\` and
|
|
26170
|
+
\`icacls C:\\ProgramData\\gemini-cli\`: Gemini CLI accepts write, append,
|
|
26171
|
+
delete, ownership or permission rights, such as \`(W)\`, \`(WD)\`, \`(AD)\`,
|
|
26172
|
+
\`(M)\` or \`(F)\`, only for Administrators, SYSTEM, service accounts
|
|
26173
|
+
(\`NT SERVICE\\...\`), CREATOR OWNER and CREATOR GROUP. When a check fails,
|
|
26174
|
+
Gemini CLI's security warning names the folder and the groups that can write
|
|
26175
|
+
to it.
|
|
26176
|
+
|
|
26177
|
+
Gemini CLI fills in \`\${REMEMBRANCE_API_KEY}\` from the environment it starts
|
|
26178
|
+
in. Without that variable the server receives an empty key and uses the shared
|
|
26179
|
+
config file from "Enterprise/org key setup" instead. Gemini CLI starts MCP
|
|
26180
|
+
servers only in a trusted folder, and interactive Gemini CLI asks whether to
|
|
26181
|
+
trust a new folder. In a folder that is not trusted, the Remembrance server does
|
|
26182
|
+
not start, and a headless run, such as \`gemini -p\` in CI, exits with an error
|
|
26183
|
+
unless the folder is trusted, \`--skip-trust\` is passed, or
|
|
26184
|
+
\`GEMINI_CLI_TRUST_WORKSPACE=true\` is set. Use those two only for unattended
|
|
26185
|
+
runs in folders the organization trusts.
|
|
26186
|
+
|
|
26187
|
+
Also allow \`remembrance.dev\` in the organization's egress policy. Restart
|
|
26188
|
+
Gemini CLI, inspect the registered server, then run \`run_connection_doctor\`
|
|
26189
|
+
and require organization scope before contribution work. See the official
|
|
25788
26190
|
[enterprise configuration](https://geminicli.com/docs/cli/enterprise/),
|
|
25789
26191
|
[MCP settings](https://geminicli.com/docs/tools/mcp-server/), and
|
|
25790
26192
|
[policy engine](https://geminicli.com/docs/reference/policy-engine/).
|
|
@@ -26148,9 +26550,10 @@ session skills.
|
|
|
26148
26550
|
standing instructions proactively. If tools are still not visible, use the
|
|
26149
26551
|
REST fallback and emit REMEMBRANCE_SUBMISSION_PAYLOAD only when the API is
|
|
26150
26552
|
unavailable.
|
|
26151
|
-
- "codex: command not found": use the complete Codex setup above. It
|
|
26152
|
-
|
|
26153
|
-
|
|
26553
|
+
- "codex: command not found": use the complete Codex setup above. It runs the
|
|
26554
|
+
newest Codex CLI it finds: \`codex\` on PATH, the ChatGPT desktop app's
|
|
26555
|
+
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex", or the
|
|
26556
|
+
older bundle paths. Set CODEX_CLI to a Codex CLI's full path to choose one.
|
|
26154
26557
|
- "401 or 403": the key is missing, expired, revoked, scoped to a different
|
|
26155
26558
|
environment, or not visible to the agent process. Check config file vs env
|
|
26156
26559
|
precedence and regenerate a key from the dashboard if needed.
|
|
@@ -28751,6 +29154,11 @@ var privateLessonInspectSchema = external_exports.object({
|
|
|
28751
29154
|
"Zero-based local page offset. Follow next_offset until truncated is false."
|
|
28752
29155
|
)
|
|
28753
29156
|
}).strict();
|
|
29157
|
+
var privateLessonRetrySchema = privateLessonDraftReferenceSchema.extend({
|
|
29158
|
+
deliver_rechecked_hold: external_exports.literal(true).optional().describe(
|
|
29159
|
+
"Only after the user chose to deliver a held draft whose safety_recheck is passes_current_rule: send it under the current safety rule. A draft the current check still holds is refused locally and not sent."
|
|
29160
|
+
)
|
|
29161
|
+
});
|
|
28754
29162
|
var privateLessonDeleteSchema = privateLessonDraftReferenceSchema.extend({
|
|
28755
29163
|
confirm: external_exports.literal(true).describe(
|
|
28756
29164
|
"Must be true. Deletion is explicit and leaves a content-free tombstone."
|
|
@@ -28984,7 +29392,7 @@ var declaredToolDefinitions = [
|
|
|
28984
29392
|
),
|
|
28985
29393
|
localTool(
|
|
28986
29394
|
"prepare_private_lesson_candidate",
|
|
28987
|
-
"Locally canonicalize, redact, validate, encrypt, and durably queue one compact organization-private failure, correction, or evidence lesson. Limits apply after local redaction: generalized_lesson at most 1200 characters and each stable_conditions item at most 240; an over-limit call is refused with the field and its length, and nothing is stored. This is an evidence lane, not a complete-skill transport: use propose_private_skill or propose_skill_idea for a complete reusable procedure, playbook, or actionable instructions. Tags use an open, bounded lowercase slug vocabulary; malformed or privacy-sensitive
|
|
29395
|
+
"Locally canonicalize, redact, validate, encrypt, and durably queue one compact organization-private failure, correction, or evidence lesson. Limits apply after local redaction: generalized_lesson at most 1200 characters and each stable_conditions item at most 240; an over-limit call is refused with the field and its length, and nothing is stored. This is an evidence lane, not a complete-skill transport: use propose_private_skill or propose_skill_idea for a complete reusable procedure, playbook, or actionable instructions. Tags use an open, bounded lowercase slug vocabulary; a malformed or privacy-sensitive tag is dropped and counted. Every redaction match becomes its [redacted:category] marker and the draft continues; only a stack trace or zero-width or bidirectional control characters hold it as held_safety. Pre-redaction input remains memory-only and this tool performs no network request. The result returns a draft handle and never echoes lesson prose. Follow the returned next_action with submit_private_lesson_candidate; held_safety content remains local. An unsupported redactor version or digest becomes terminal superseded_redactor and is never retried or re-redacted.",
|
|
28988
29396
|
"prepare_private_lesson_candidate",
|
|
28989
29397
|
privateLessonPreparationInputSchema
|
|
28990
29398
|
),
|
|
@@ -29003,9 +29411,9 @@ var declaredToolDefinitions = [
|
|
|
29003
29411
|
),
|
|
29004
29412
|
localNetworkTool(
|
|
29005
29413
|
"retry_private_lesson_candidate",
|
|
29006
|
-
"Retry one retained private-lesson draft through the same private_lesson approval lane as submit_private_lesson_candidate. Network access is allowed only for authorization-pending, due transient retry, newly compatible profile, or refreshable policy states; a fresh ready draft is rejected locally. It never falls back to a public or alternate transport.",
|
|
29414
|
+
"Retry one retained private-lesson draft through the same private_lesson approval lane as submit_private_lesson_candidate. Network access is allowed only for authorization-pending, due transient retry, newly compatible profile, or refreshable policy states, and for a held draft the current local safety check releases once the user chose to deliver it (deliver_rechecked_hold=true); a fresh ready draft is rejected locally. It never falls back to a public or alternate transport.",
|
|
29007
29415
|
"retry_private_lesson_candidate",
|
|
29008
|
-
|
|
29416
|
+
privateLessonRetrySchema,
|
|
29009
29417
|
"content_write"
|
|
29010
29418
|
),
|
|
29011
29419
|
localTool(
|
|
@@ -29721,14 +30129,26 @@ function normalizeBoundedWriteJsonSchema(schema, name) {
|
|
|
29721
30129
|
schema.allOf = [
|
|
29722
30130
|
{
|
|
29723
30131
|
if: { required: ["replacement_of"] },
|
|
29724
|
-
then: {
|
|
30132
|
+
then: {
|
|
30133
|
+
anyOf: [
|
|
30134
|
+
["^psd_", "private_skill"],
|
|
30135
|
+
["^pld_", "lesson"]
|
|
30136
|
+
].map(([pattern, payload]) => ({
|
|
30137
|
+
required: [payload],
|
|
30138
|
+
properties: {
|
|
30139
|
+
replacement_of: { properties: { draft_id: { pattern } } }
|
|
30140
|
+
}
|
|
30141
|
+
}))
|
|
30142
|
+
}
|
|
29725
30143
|
}
|
|
29726
30144
|
];
|
|
29727
30145
|
const replacement = schemaProperty(schema, "replacement_of");
|
|
29728
|
-
replacement.description = "Optional lineage for a
|
|
29729
|
-
|
|
29730
|
-
schemaProperty(
|
|
29731
|
-
schemaProperty(
|
|
30146
|
+
replacement.description = "Optional lineage for a replacement of one retained draft: a complete private skill for a private-skill draft, or a lesson for a held private-lesson draft. It carries audit/context identity only and grants no approval, destination authority, or permission to reuse held content.";
|
|
30147
|
+
const [skillLink, lessonLink] = replacement.anyOf;
|
|
30148
|
+
schemaProperty(skillLink, "draft_id").description = "Retained encrypted private-skill draft being replaced.";
|
|
30149
|
+
schemaProperty(skillLink, "context_source").description = "Audit-only source label: active_task_context or separately inspected, explicitly partial safe_recovery_context. Neither source is submission authority.";
|
|
30150
|
+
schemaProperty(skillLink, "recovery_context_id").description = "Omit this field unless the current inspect_private_learning_outbox agent_recovery.arguments.replacement_of supplies this exact ID. Never invent an ID or derive one from a draft, digest, or ordinary recovery_context. A supplied native context ID may establish a new context epoch but grants no approval or authority to reuse held content. safe_recovery_context alone does not require an ID.";
|
|
30151
|
+
schemaProperty(lessonLink, "draft_id").description = "Held private-lesson draft that this lesson replaces, from its agent_recovery. Write the lesson from the current task, without what the findings name; the held content is never available. The held draft is retired only once the organization accepts this lesson, and accepts at most three versions; a held version is refused with its findings.";
|
|
29732
30152
|
}
|
|
29733
30153
|
if (name === "register_agent_key") {
|
|
29734
30154
|
const metadata = schemaProperty(schema, "metadata");
|
|
@@ -31160,6 +31580,7 @@ var PRIVATE_LESSON_CAPACITY_STATE_MAX_BYTES = 1024;
|
|
|
31160
31580
|
var PRIVATE_LESSON_OUTBOX_LOCK_NAMESPACE = "outbox";
|
|
31161
31581
|
var PRIVATE_LESSON_MAX_PAGE_OFFSET = Number.MAX_SAFE_INTEGER - 200;
|
|
31162
31582
|
var PRIVATE_LESSON_UNVERIFIABLE_COMPLETION_REMEDIATION = "This retained draft records a submission whose completion metadata is missing or invalid, so its acceptance cannot be verified locally. It is kept unchanged and is never resubmitted or retried automatically. Keep it until the user confirms whether the organization received it; delete it with delete_private_lesson_candidate only after explicit confirmation.";
|
|
31583
|
+
var PRIVATE_LESSON_ATTESTATION_MISMATCH_REMEDIATION = "The configured key belongs to a different organization than the owner attested for this recovered draft, and nothing was sent. Only a new owner-attested recovery naming the right destination releases it. Otherwise keep it, or delete it with delete_private_lesson_candidate and confirm=true once the user explicitly confirms.";
|
|
31163
31584
|
var PrivateLessonPolicyFloorError = class extends Error {
|
|
31164
31585
|
constructor(message, code) {
|
|
31165
31586
|
super(message);
|
|
@@ -31169,16 +31590,18 @@ var PrivateLessonPolicyFloorError = class extends Error {
|
|
|
31169
31590
|
code;
|
|
31170
31591
|
};
|
|
31171
31592
|
var PrivateLessonDraftUnavailableError = class extends Error {
|
|
31172
|
-
constructor(draftId, reason) {
|
|
31593
|
+
constructor(draftId, reason, replacementDraftId) {
|
|
31173
31594
|
super(
|
|
31174
|
-
reason === "deleted" ? "Private lesson draft was explicitly deleted." : reason === "corrupt" ? "Private lesson draft is retained but its canonical entry is unavailable. Inspect content-free recovery state before taking any destructive action." : "Private lesson draft does not exist. Inspect content-free outbox state before deciding whether task context supports a fresh capture; do not claim that the missing draft was submitted."
|
|
31595
|
+
reason === "deleted" ? "Private lesson draft was explicitly deleted." : reason === "corrupt" ? "Private lesson draft is retained but its canonical entry is unavailable. Inspect content-free recovery state before taking any destructive action." : reason === "replaced" ? "Private lesson draft was held and has been replaced by a re-captured draft the organization accepted; the held draft was never sent and is no longer retained." : "Private lesson draft does not exist. Inspect content-free outbox state before deciding whether task context supports a fresh capture; do not claim that the missing draft was submitted."
|
|
31175
31596
|
);
|
|
31176
31597
|
this.draftId = draftId;
|
|
31177
31598
|
this.reason = reason;
|
|
31599
|
+
this.replacementDraftId = replacementDraftId;
|
|
31178
31600
|
this.name = "PrivateLessonDraftUnavailableError";
|
|
31179
31601
|
}
|
|
31180
31602
|
draftId;
|
|
31181
31603
|
reason;
|
|
31604
|
+
replacementDraftId;
|
|
31182
31605
|
jsonRpcCode() {
|
|
31183
31606
|
return this.reason === "corrupt" ? -32603 : -32602;
|
|
31184
31607
|
}
|
|
@@ -31186,22 +31609,84 @@ var PrivateLessonDraftUnavailableError = class extends Error {
|
|
|
31186
31609
|
return {
|
|
31187
31610
|
code: `private_lesson_draft_${this.reason}`,
|
|
31188
31611
|
draft_id: this.draftId,
|
|
31612
|
+
...this.reason === "replaced" && this.replacementDraftId ? { replacement_draft_id: this.replacementDraftId } : {},
|
|
31189
31613
|
retained_locally: this.reason === "corrupt",
|
|
31190
31614
|
candidate_sent: false,
|
|
31191
31615
|
next_action: {
|
|
31192
31616
|
tool: "inspect_private_lesson_outbox",
|
|
31193
|
-
arguments: {
|
|
31617
|
+
arguments: {
|
|
31618
|
+
draft_id: this.reason === "replaced" && this.replacementDraftId ? this.replacementDraftId : this.draftId
|
|
31619
|
+
}
|
|
31194
31620
|
}
|
|
31195
31621
|
};
|
|
31196
31622
|
}
|
|
31197
31623
|
};
|
|
31624
|
+
function privateLessonSafetyRecheck(draft) {
|
|
31625
|
+
return draft.state === "held_safety" && draft.redaction_version === PRIVATE_LESSON_REDACTION_VERSION && draft.redactor_digest !== privateLessonRedactorDigest() && draft.held_reasons.length > 0 && (draft.replacement_attempts ?? []).length === 0 && privateLessonCurrentHoldReasons(draft.candidate, draft.held_reasons).length === 0 ? "passes_current_rule" : null;
|
|
31626
|
+
}
|
|
31627
|
+
var PrivateLessonHoldReleaseRefusedError = class extends Error {
|
|
31628
|
+
constructor(draftId, holdReasons) {
|
|
31629
|
+
super(
|
|
31630
|
+
"The current local safety check still holds this private lesson draft; nothing was sent."
|
|
31631
|
+
);
|
|
31632
|
+
this.draftId = draftId;
|
|
31633
|
+
this.holdReasons = holdReasons;
|
|
31634
|
+
this.name = "PrivateLessonHoldReleaseRefusedError";
|
|
31635
|
+
}
|
|
31636
|
+
draftId;
|
|
31637
|
+
holdReasons;
|
|
31638
|
+
};
|
|
31639
|
+
async function releaseRecheckedPrivateLessonHold(draftId, options = {}) {
|
|
31640
|
+
const outbox = await readyOutbox(options);
|
|
31641
|
+
return withPrivateLessonOutboxLock(outbox.directory, async () => {
|
|
31642
|
+
const draft = await readPrivateLessonDraft(draftId, {
|
|
31643
|
+
...options,
|
|
31644
|
+
outboxDirectory: outbox.directory,
|
|
31645
|
+
encryption: outbox.encryption
|
|
31646
|
+
});
|
|
31647
|
+
if (draft.state !== "held_safety") return draft;
|
|
31648
|
+
if (!privateLessonSafetyRecheck(draft)) {
|
|
31649
|
+
throw new PrivateLessonHoldReleaseRefusedError(
|
|
31650
|
+
draftId,
|
|
31651
|
+
privateLessonCurrentHoldReasons(draft.candidate, draft.held_reasons)
|
|
31652
|
+
);
|
|
31653
|
+
}
|
|
31654
|
+
const now = (options.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
31655
|
+
const released = validateDraft({
|
|
31656
|
+
...draft,
|
|
31657
|
+
state: "retry_scheduled",
|
|
31658
|
+
redactor_digest: privateLessonRedactorDigest(),
|
|
31659
|
+
held_reasons: [],
|
|
31660
|
+
// A policy binding is valid only for its own redactor profile.
|
|
31661
|
+
policy: null,
|
|
31662
|
+
next_retry_at: now,
|
|
31663
|
+
last_error_code: null,
|
|
31664
|
+
hold_telemetry_status: "not_required",
|
|
31665
|
+
hold_event_digest: null,
|
|
31666
|
+
hold_receipt_digest: null,
|
|
31667
|
+
hold_reported_at: null,
|
|
31668
|
+
updated_at: now
|
|
31669
|
+
});
|
|
31670
|
+
await writeDraftUnlocked(released, outbox, true);
|
|
31671
|
+
return released;
|
|
31672
|
+
});
|
|
31673
|
+
}
|
|
31198
31674
|
async function queuePreparedPrivateLesson(prepared, policy, options = {}) {
|
|
31199
|
-
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
31200
31675
|
const outbox = await readyOutbox(options);
|
|
31201
|
-
const
|
|
31676
|
+
const draft = newPrivateLessonDraft(
|
|
31677
|
+
prepared,
|
|
31678
|
+
createPublicId("pld"),
|
|
31679
|
+
policy,
|
|
31680
|
+
options.destination ?? null,
|
|
31681
|
+
options.now ?? /* @__PURE__ */ new Date()
|
|
31682
|
+
);
|
|
31683
|
+
await writeDraft(draft, outbox, false);
|
|
31684
|
+
return draft;
|
|
31685
|
+
}
|
|
31686
|
+
function newPrivateLessonDraft(prepared, draftId, policy, destination, now) {
|
|
31202
31687
|
const createdAt = now.toISOString();
|
|
31203
31688
|
const state = prepared.status === "held_safety" ? "held_safety" : policy ? "ready" : "awaiting_authorization";
|
|
31204
|
-
|
|
31689
|
+
return {
|
|
31205
31690
|
version: PRIVATE_LESSON_OUTBOX_VERSION,
|
|
31206
31691
|
draft_id: draftId,
|
|
31207
31692
|
state,
|
|
@@ -31212,7 +31697,7 @@ async function queuePreparedPrivateLesson(prepared, policy, options = {}) {
|
|
|
31212
31697
|
redactor_digest: prepared.redactor_digest,
|
|
31213
31698
|
held_reasons: prepared.held_reasons,
|
|
31214
31699
|
policy,
|
|
31215
|
-
destination_binding:
|
|
31700
|
+
destination_binding: destination ? parsePrivateLessonDestination(destination) : null,
|
|
31216
31701
|
idempotency_key: `private-lesson-${hashValue(
|
|
31217
31702
|
canonicalJson({
|
|
31218
31703
|
draft_id: draftId,
|
|
@@ -31232,8 +31717,196 @@ async function queuePreparedPrivateLesson(prepared, policy, options = {}) {
|
|
|
31232
31717
|
hold_receipt_digest: null,
|
|
31233
31718
|
hold_reported_at: null
|
|
31234
31719
|
};
|
|
31235
|
-
|
|
31236
|
-
|
|
31720
|
+
}
|
|
31721
|
+
var PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS = 3;
|
|
31722
|
+
var PRIVATE_LESSON_REPLACEMENT_REFUSALS = {
|
|
31723
|
+
unknown: "No retained private lesson draft has this draft_id, so nothing can be replaced. Capture the lesson without replacement_of.",
|
|
31724
|
+
deleted: "This private lesson draft was deleted, so nothing can be replaced. Capture the lesson without replacement_of.",
|
|
31725
|
+
submitted: "This private lesson draft was already sent, so a replacement would be a second lesson. Capture without replacement_of only for a new lesson.",
|
|
31726
|
+
replaced: "This held private lesson draft was already replaced.",
|
|
31727
|
+
not_held: "Only a draft the local safety check holds can be replaced, and this one is not held. Follow its own next_action instead.",
|
|
31728
|
+
destination_changed: "This held private lesson draft was captured for another API base or organization credential than this session uses, and a version written here must not go there. Capture the lesson without replacement_of; the held draft stays as it is.",
|
|
31729
|
+
releasable: "The current safety check would send this held draft as it is, so it is not replaced: the user chooses whether to deliver, keep or delete it.",
|
|
31730
|
+
replacement_pending: "A replacement of this held draft is already retained. Submit it with its next_action, or delete it with delete_private_lesson_candidate and confirm=true before capturing another.",
|
|
31731
|
+
attempts_exhausted: `This held private lesson draft has used all ${PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS} replacement attempts. Keep it, or delete it with delete_private_lesson_candidate and confirm=true once the user confirms.`,
|
|
31732
|
+
replacement_deleted: "This exact replacement was deleted. Capture a different version, or keep or delete the held draft.",
|
|
31733
|
+
replacement_held: "The local safety check holds this replacement too, so it was not stored. Write a version without what the findings name."
|
|
31734
|
+
};
|
|
31735
|
+
var PrivateLessonReplacementRefusedError = class extends Error {
|
|
31736
|
+
constructor(draftId, reason, attemptsRemaining, replacementDraftId) {
|
|
31737
|
+
super(
|
|
31738
|
+
`${PRIVATE_LESSON_REPLACEMENT_REFUSALS[reason]} Nothing was stored or sent.`
|
|
31739
|
+
);
|
|
31740
|
+
this.draftId = draftId;
|
|
31741
|
+
this.reason = reason;
|
|
31742
|
+
this.attemptsRemaining = attemptsRemaining;
|
|
31743
|
+
this.replacementDraftId = replacementDraftId;
|
|
31744
|
+
this.name = "PrivateLessonReplacementRefusedError";
|
|
31745
|
+
}
|
|
31746
|
+
draftId;
|
|
31747
|
+
reason;
|
|
31748
|
+
attemptsRemaining;
|
|
31749
|
+
replacementDraftId;
|
|
31750
|
+
diagnostic() {
|
|
31751
|
+
return {
|
|
31752
|
+
code: "private_lesson_replacement_refused",
|
|
31753
|
+
reason_code: this.reason,
|
|
31754
|
+
replacement_of: this.draftId,
|
|
31755
|
+
...this.replacementDraftId ? { replacement_draft_id: this.replacementDraftId } : {},
|
|
31756
|
+
attempts_remaining: this.attemptsRemaining,
|
|
31757
|
+
candidate_stored: false,
|
|
31758
|
+
candidate_sent: false
|
|
31759
|
+
};
|
|
31760
|
+
}
|
|
31761
|
+
};
|
|
31762
|
+
async function queuePrivateLessonReplacement(replacementOf, prepared, options = {}) {
|
|
31763
|
+
assertDraftId(replacementOf);
|
|
31764
|
+
const outbox = await readyOutbox(options);
|
|
31765
|
+
const directory = outbox.directory;
|
|
31766
|
+
return withPrivateLessonOutboxLock(directory, async () => {
|
|
31767
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
31768
|
+
const read2 = { ...options, outboxDirectory: directory };
|
|
31769
|
+
const refuse = (reason, used2 = 0, replacementDraftId) => new PrivateLessonReplacementRefusedError(
|
|
31770
|
+
replacementOf,
|
|
31771
|
+
reason,
|
|
31772
|
+
Math.max(0, PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - used2),
|
|
31773
|
+
replacementDraftId
|
|
31774
|
+
);
|
|
31775
|
+
await reconcileSubmittedRecordsUnlocked(directory, now);
|
|
31776
|
+
if (existsSync2(tombstonePath(directory, replacementOf))) {
|
|
31777
|
+
throw refuse("deleted");
|
|
31778
|
+
}
|
|
31779
|
+
let original;
|
|
31780
|
+
try {
|
|
31781
|
+
original = await readPrivateLessonDraft(replacementOf, {
|
|
31782
|
+
...read2,
|
|
31783
|
+
encryption: outbox.encryption
|
|
31784
|
+
});
|
|
31785
|
+
} catch (error) {
|
|
31786
|
+
if (error instanceof PrivateLessonDraftUnavailableError) {
|
|
31787
|
+
if (error.reason === "replaced") {
|
|
31788
|
+
throw refuse(
|
|
31789
|
+
"replaced",
|
|
31790
|
+
PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS,
|
|
31791
|
+
error.replacementDraftId
|
|
31792
|
+
);
|
|
31793
|
+
}
|
|
31794
|
+
if (error.reason === "unknown") throw refuse("unknown");
|
|
31795
|
+
}
|
|
31796
|
+
if (existsSync2(submittedRecordPath(directory, replacementOf))) {
|
|
31797
|
+
throw refuse("submitted");
|
|
31798
|
+
}
|
|
31799
|
+
throw error;
|
|
31800
|
+
}
|
|
31801
|
+
if (original.state === "submitted") throw refuse("submitted");
|
|
31802
|
+
if (original.held_reasons.length === 0 || original.state === "superseded_redactor" || original.replacement_of !== void 0) {
|
|
31803
|
+
throw refuse("not_held");
|
|
31804
|
+
}
|
|
31805
|
+
if (privateLessonSafetyRecheck(original)) throw refuse("releasable");
|
|
31806
|
+
const attempts = original.replacement_attempts ?? [];
|
|
31807
|
+
const digest2 = prepared.payload_digest;
|
|
31808
|
+
const draftId = privateLessonReplacementDraftId(replacementOf, digest2);
|
|
31809
|
+
const replay = attempts.includes(digest2);
|
|
31810
|
+
const used = replay ? attempts.length : attempts.length + 1;
|
|
31811
|
+
if (!replay && privateLessonCapturedForOtherDestination(original, options.destination)) {
|
|
31812
|
+
throw refuse("destination_changed", attempts.length);
|
|
31813
|
+
}
|
|
31814
|
+
const pending = attempts.map((attempt) => privateLessonReplacementDraftId(replacementOf, attempt)).find(
|
|
31815
|
+
(candidate) => candidate !== draftId && existsSync2(draftPath(directory, candidate))
|
|
31816
|
+
);
|
|
31817
|
+
if (pending) throw refuse("replacement_pending", attempts.length, pending);
|
|
31818
|
+
if (!replay) {
|
|
31819
|
+
if (attempts.length >= PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS) {
|
|
31820
|
+
throw refuse("attempts_exhausted", attempts.length);
|
|
31821
|
+
}
|
|
31822
|
+
await writeDraftUnlocked(
|
|
31823
|
+
validateDraft({
|
|
31824
|
+
...original,
|
|
31825
|
+
replacement_attempts: [...attempts, digest2],
|
|
31826
|
+
updated_at: now.toISOString()
|
|
31827
|
+
}),
|
|
31828
|
+
outbox,
|
|
31829
|
+
true
|
|
31830
|
+
);
|
|
31831
|
+
}
|
|
31832
|
+
if (prepared.status === "held_safety") {
|
|
31833
|
+
throw refuse("replacement_held", used);
|
|
31834
|
+
}
|
|
31835
|
+
if (existsSync2(tombstonePath(directory, draftId))) {
|
|
31836
|
+
throw refuse("replacement_deleted", used, draftId);
|
|
31837
|
+
}
|
|
31838
|
+
if (existsSync2(draftPath(directory, draftId))) {
|
|
31839
|
+
return {
|
|
31840
|
+
draft: await readPrivateLessonDraft(draftId, {
|
|
31841
|
+
...read2,
|
|
31842
|
+
encryption: outbox.encryption
|
|
31843
|
+
}),
|
|
31844
|
+
attempts_remaining: PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - used,
|
|
31845
|
+
replayed: true
|
|
31846
|
+
};
|
|
31847
|
+
}
|
|
31848
|
+
const draft = {
|
|
31849
|
+
...newPrivateLessonDraft(
|
|
31850
|
+
prepared,
|
|
31851
|
+
draftId,
|
|
31852
|
+
null,
|
|
31853
|
+
original.destination_binding ?? options.destination ?? null,
|
|
31854
|
+
now
|
|
31855
|
+
),
|
|
31856
|
+
...original.attested_organization_audience_hash !== void 0 ? {
|
|
31857
|
+
attested_organization_audience_hash: original.attested_organization_audience_hash
|
|
31858
|
+
} : {},
|
|
31859
|
+
replacement_of: replacementOf
|
|
31860
|
+
};
|
|
31861
|
+
await writeDraftUnlocked(validateDraft(draft), outbox, false);
|
|
31862
|
+
return {
|
|
31863
|
+
draft,
|
|
31864
|
+
attempts_remaining: PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - used,
|
|
31865
|
+
replayed: replay
|
|
31866
|
+
};
|
|
31867
|
+
});
|
|
31868
|
+
}
|
|
31869
|
+
async function retireReplacedPrivateLessonUnlocked(directory, draftId, replacementDraftId, at) {
|
|
31870
|
+
const path = draftPath(directory, draftId);
|
|
31871
|
+
if (existsSync2(tombstonePath(directory, draftId)) || existsSync2(submittedRecordPath(directory, draftId)) || !existsSync2(path)) {
|
|
31872
|
+
return;
|
|
31873
|
+
}
|
|
31874
|
+
try {
|
|
31875
|
+
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
31876
|
+
const envelope = parseEnvelope(
|
|
31877
|
+
await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
31878
|
+
draftId
|
|
31879
|
+
);
|
|
31880
|
+
if (envelope.state === "submitted") return;
|
|
31881
|
+
} catch {
|
|
31882
|
+
return;
|
|
31883
|
+
}
|
|
31884
|
+
const record4 = {
|
|
31885
|
+
version: "private-lesson-outbox-deletion-v1",
|
|
31886
|
+
draft_id: draftId,
|
|
31887
|
+
deleted_at: at.toISOString(),
|
|
31888
|
+
reason: "replaced_by_verified_replacement",
|
|
31889
|
+
replacement_draft_id: replacementDraftId,
|
|
31890
|
+
expires_at: new Date(
|
|
31891
|
+
at.getTime() + PRIVATE_LESSON_SUBMITTED_RECORD_RETENTION_MS
|
|
31892
|
+
).toISOString()
|
|
31893
|
+
};
|
|
31894
|
+
await atomicCreatePrivateLessonEntry(
|
|
31895
|
+
replacedRecordPath(directory, draftId),
|
|
31896
|
+
`${JSON.stringify(record4)}
|
|
31897
|
+
`,
|
|
31898
|
+
".replaced.tmp"
|
|
31899
|
+
);
|
|
31900
|
+
await unlink2(path).catch(() => {
|
|
31901
|
+
});
|
|
31902
|
+
await syncDirectory2(directory).catch(() => {
|
|
31903
|
+
});
|
|
31904
|
+
}
|
|
31905
|
+
function acceptedPrivateLessonReplacement(directory, draft) {
|
|
31906
|
+
if (draft.state === "submitted") return void 0;
|
|
31907
|
+
return (draft.replacement_attempts ?? []).map((digest2) => privateLessonReplacementDraftId(draft.draft_id, digest2)).find(
|
|
31908
|
+
(replacement) => existsSync2(submittedRecordPath(directory, replacement))
|
|
31909
|
+
);
|
|
31237
31910
|
}
|
|
31238
31911
|
async function readPrivateLessonDraft(draftId, options = {}) {
|
|
31239
31912
|
assertDraftId(draftId);
|
|
@@ -31246,10 +31919,12 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
31246
31919
|
if (existsSync2(tombstonePath(outbox.directory, draftId))) {
|
|
31247
31920
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31248
31921
|
}
|
|
31922
|
+
await assertNotReplacedUnlocked(outbox.directory, draftId);
|
|
31249
31923
|
if (existsSync2(submittedRecordPath(outbox.directory, draftId))) {
|
|
31250
31924
|
throw new Error("Private lesson draft was already submitted.");
|
|
31251
31925
|
}
|
|
31252
31926
|
let draft;
|
|
31927
|
+
let envelope;
|
|
31253
31928
|
try {
|
|
31254
31929
|
const path = draftPath(outbox.directory, draftId);
|
|
31255
31930
|
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
@@ -31257,20 +31932,32 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
31257
31932
|
path,
|
|
31258
31933
|
PRIVATE_LESSON_DRAFT_MAX_BYTES
|
|
31259
31934
|
);
|
|
31260
|
-
|
|
31935
|
+
envelope = parseEnvelope(serialized, draftId);
|
|
31261
31936
|
draft = await decryptDraft(envelope, outbox.encryption, true);
|
|
31262
31937
|
} catch (error) {
|
|
31263
31938
|
throw selectedPrivateLessonError(draftId, error);
|
|
31264
31939
|
}
|
|
31265
|
-
const
|
|
31266
|
-
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
const reconciled = normalizeLegacyHeldSafetyDraft(
|
|
31270
|
-
profileReconciled,
|
|
31271
|
-
options.now ?? /* @__PURE__ */ new Date()
|
|
31940
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
31941
|
+
const replacement = acceptedPrivateLessonReplacement(
|
|
31942
|
+
outbox.directory,
|
|
31943
|
+
draft
|
|
31272
31944
|
);
|
|
31273
|
-
if (
|
|
31945
|
+
if (replacement) {
|
|
31946
|
+
await retireReplacedPrivateLessonUnlocked(
|
|
31947
|
+
outbox.directory,
|
|
31948
|
+
draftId,
|
|
31949
|
+
replacement,
|
|
31950
|
+
now
|
|
31951
|
+
).catch(() => {
|
|
31952
|
+
});
|
|
31953
|
+
throw new PrivateLessonDraftUnavailableError(
|
|
31954
|
+
draftId,
|
|
31955
|
+
"replaced",
|
|
31956
|
+
replacement
|
|
31957
|
+
);
|
|
31958
|
+
}
|
|
31959
|
+
const reconciled = reconcileStoredDraft(draft, now);
|
|
31960
|
+
if (reconciled !== draft || staleSafetyRecheckHint(envelope, reconciled)) {
|
|
31274
31961
|
await writeDraft(reconciled, outbox, true, void 0, true);
|
|
31275
31962
|
}
|
|
31276
31963
|
return reconciled;
|
|
@@ -31289,6 +31976,7 @@ async function readPrivateLessonSubmittedRecord(draftId, options = {}) {
|
|
|
31289
31976
|
if (existsSync2(tombstonePath(directory, draftId))) {
|
|
31290
31977
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31291
31978
|
}
|
|
31979
|
+
await assertNotReplacedUnlocked(directory, draftId);
|
|
31292
31980
|
const path = submittedRecordPath(directory, draftId);
|
|
31293
31981
|
if (!existsSync2(path)) return null;
|
|
31294
31982
|
await assertRegularPrivateFile(
|
|
@@ -31312,6 +32000,7 @@ async function readPrivateLessonSubmissionSource(draftId, options = {}) {
|
|
|
31312
32000
|
if (existsSync2(tombstonePath(outbox.directory, draftId))) {
|
|
31313
32001
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31314
32002
|
}
|
|
32003
|
+
await assertNotReplacedUnlocked(outbox.directory, draftId);
|
|
31315
32004
|
const completionPath = submittedRecordPath(outbox.directory, draftId);
|
|
31316
32005
|
if (existsSync2(completionPath)) {
|
|
31317
32006
|
await assertRegularPrivateFile(
|
|
@@ -31344,7 +32033,7 @@ async function readPrivateLessonSubmissionSource(draftId, options = {}) {
|
|
|
31344
32033
|
return { kind: "draft", draft };
|
|
31345
32034
|
});
|
|
31346
32035
|
}
|
|
31347
|
-
async function reconcilePrivateLessonOutboxProfiles(options = {}) {
|
|
32036
|
+
async function reconcilePrivateLessonOutboxProfiles(options = {}, replaced) {
|
|
31348
32037
|
const outbox = await readyOutbox(options, false);
|
|
31349
32038
|
return withPrivateLessonOutboxLock(outbox.directory, async () => {
|
|
31350
32039
|
await reconcilePrivateLessonTemporaryWrites(
|
|
@@ -31378,7 +32067,10 @@ async function reconcilePrivateLessonOutboxProfiles(options = {}) {
|
|
|
31378
32067
|
outboxDirectory: outbox.directory,
|
|
31379
32068
|
encryption: outbox.encryption
|
|
31380
32069
|
});
|
|
31381
|
-
} catch {
|
|
32070
|
+
} catch (error) {
|
|
32071
|
+
if (error instanceof PrivateLessonDraftUnavailableError && error.reason === "replaced") {
|
|
32072
|
+
replaced?.add(draftId);
|
|
32073
|
+
}
|
|
31382
32074
|
continue;
|
|
31383
32075
|
}
|
|
31384
32076
|
inspected += 1;
|
|
@@ -31411,7 +32103,7 @@ async function updatePrivateLessonDraft(draftId, update, options = {}) {
|
|
|
31411
32103
|
throw new PrivateLessonDraftUnavailableError(draftId, "corrupt");
|
|
31412
32104
|
}
|
|
31413
32105
|
const next = validateDraft(update(structuredClone(current)));
|
|
31414
|
-
if (next.draft_id !== current.draft_id || next.payload_digest !== current.payload_digest || next.canonical_payload !== current.canonical_payload || next.redaction_version !== current.redaction_version || next.redactor_digest !== current.redactor_digest || canonicalJson(next.destination_binding) !== canonicalJson(current.destination_binding) || next.idempotency_key !== current.idempotency_key) {
|
|
32106
|
+
if (next.draft_id !== current.draft_id || next.payload_digest !== current.payload_digest || next.canonical_payload !== current.canonical_payload || next.redaction_version !== current.redaction_version || next.redactor_digest !== current.redactor_digest || canonicalJson(next.destination_binding) !== canonicalJson(current.destination_binding) || next.attested_organization_audience_hash !== current.attested_organization_audience_hash || next.idempotency_key !== current.idempotency_key) {
|
|
31415
32107
|
throw new Error("Private lesson draft content is immutable.");
|
|
31416
32108
|
}
|
|
31417
32109
|
next.updated_at = (options.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
@@ -31430,6 +32122,7 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
31430
32122
|
if (existsSync2(tombstonePath(outbox.directory, draftId))) {
|
|
31431
32123
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31432
32124
|
}
|
|
32125
|
+
await assertNotReplacedUnlocked(outbox.directory, draftId);
|
|
31433
32126
|
const existingPath = submittedRecordPath(outbox.directory, draftId);
|
|
31434
32127
|
if (existsSync2(existingPath)) {
|
|
31435
32128
|
let completion2;
|
|
@@ -31461,6 +32154,7 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
31461
32154
|
} catch (error) {
|
|
31462
32155
|
throw selectedPrivateLessonError(draftId, error);
|
|
31463
32156
|
}
|
|
32157
|
+
current = reconcileStoredDraft(current, options.now ?? /* @__PURE__ */ new Date());
|
|
31464
32158
|
if (current.state === "superseded_redactor") {
|
|
31465
32159
|
throw new Error("Terminal private lesson drafts cannot be submitted.");
|
|
31466
32160
|
}
|
|
@@ -31492,6 +32186,15 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
31492
32186
|
});
|
|
31493
32187
|
await syncDirectory2(outbox.directory).catch(() => {
|
|
31494
32188
|
});
|
|
32189
|
+
if (draft.replacement_of) {
|
|
32190
|
+
await retireReplacedPrivateLessonUnlocked(
|
|
32191
|
+
outbox.directory,
|
|
32192
|
+
draft.replacement_of,
|
|
32193
|
+
draftId,
|
|
32194
|
+
submittedAt
|
|
32195
|
+
).catch(() => {
|
|
32196
|
+
});
|
|
32197
|
+
}
|
|
31495
32198
|
return completion;
|
|
31496
32199
|
});
|
|
31497
32200
|
}
|
|
@@ -31507,19 +32210,21 @@ async function deletePrivateLessonDraft(draftId, confirmed, options = {}) {
|
|
|
31507
32210
|
const path = draftPath(outbox.directory, draftId);
|
|
31508
32211
|
const completionPath = submittedRecordPath(outbox.directory, draftId);
|
|
31509
32212
|
const deletionPath = tombstonePath(outbox.directory, draftId);
|
|
32213
|
+
const replacedPath = replacedRecordPath(outbox.directory, draftId);
|
|
31510
32214
|
const quarantined = await privateLessonQuarantineEntriesForDraft(
|
|
31511
32215
|
outbox.directory,
|
|
31512
32216
|
draftId
|
|
31513
32217
|
);
|
|
31514
|
-
if (existsSync2(deletionPath) && !existsSync2(path) && !existsSync2(completionPath) && quarantined.length === 0) {
|
|
32218
|
+
if (existsSync2(deletionPath) && !existsSync2(path) && !existsSync2(completionPath) && !existsSync2(replacedPath) && quarantined.length === 0) {
|
|
31515
32219
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31516
32220
|
}
|
|
31517
|
-
if (!existsSync2(path) && !existsSync2(completionPath) && !existsSync2(deletionPath) && quarantined.length === 0) {
|
|
32221
|
+
if (!existsSync2(path) && !existsSync2(completionPath) && !existsSync2(deletionPath) && !existsSync2(replacedPath) && quarantined.length === 0) {
|
|
31518
32222
|
throw new PrivateLessonDraftUnavailableError(draftId, "unknown");
|
|
31519
32223
|
}
|
|
31520
32224
|
await removeCanonicalPrivateLessonEntry(path);
|
|
31521
32225
|
await removeCanonicalPrivateLessonEntry(completionPath);
|
|
31522
32226
|
await removeCanonicalPrivateLessonEntry(deletionPath);
|
|
32227
|
+
await removeCanonicalPrivateLessonEntry(replacedPath);
|
|
31523
32228
|
for (const entry of quarantined) {
|
|
31524
32229
|
await removeCanonicalPrivateLessonEntry(entry);
|
|
31525
32230
|
}
|
|
@@ -31540,11 +32245,15 @@ async function deletePrivateLessonDraft(draftId, confirmed, options = {}) {
|
|
|
31540
32245
|
}
|
|
31541
32246
|
async function privateLessonOutboxSummary(options = {}) {
|
|
31542
32247
|
const outbox = await readyOutbox(options, false);
|
|
31543
|
-
|
|
31544
|
-
|
|
31545
|
-
|
|
31546
|
-
|
|
31547
|
-
|
|
32248
|
+
const replaced = /* @__PURE__ */ new Set();
|
|
32249
|
+
await reconcilePrivateLessonOutboxProfiles(
|
|
32250
|
+
{
|
|
32251
|
+
...options,
|
|
32252
|
+
outboxDirectory: outbox.directory,
|
|
32253
|
+
encryption: outbox.encryption
|
|
32254
|
+
},
|
|
32255
|
+
replaced
|
|
32256
|
+
);
|
|
31548
32257
|
const entries = await secureOutboxEntries(outbox.directory);
|
|
31549
32258
|
const counts = {
|
|
31550
32259
|
ready: 0,
|
|
@@ -31559,6 +32268,7 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31559
32268
|
};
|
|
31560
32269
|
let totalBytes = 0;
|
|
31561
32270
|
let deletionTombstones = 0;
|
|
32271
|
+
let replacedRecords = 0;
|
|
31562
32272
|
let terminalBytes = 0;
|
|
31563
32273
|
const terminalReasons = {};
|
|
31564
32274
|
let corruptFiles = 0;
|
|
@@ -31569,6 +32279,10 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31569
32279
|
deletionTombstones += 1;
|
|
31570
32280
|
continue;
|
|
31571
32281
|
}
|
|
32282
|
+
if (name.endsWith(".replaced.json")) {
|
|
32283
|
+
replacedRecords += 1;
|
|
32284
|
+
continue;
|
|
32285
|
+
}
|
|
31572
32286
|
if (name.endsWith(".submitted.json")) {
|
|
31573
32287
|
const draftId = name.slice(0, -".submitted.json".length);
|
|
31574
32288
|
try {
|
|
@@ -31586,6 +32300,10 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31586
32300
|
continue;
|
|
31587
32301
|
}
|
|
31588
32302
|
if (!name.endsWith(".lesson.json")) continue;
|
|
32303
|
+
if (replaced.has(name.slice(0, -".lesson.json".length))) {
|
|
32304
|
+
replacedRecords += 1;
|
|
32305
|
+
continue;
|
|
32306
|
+
}
|
|
31589
32307
|
let envelope;
|
|
31590
32308
|
try {
|
|
31591
32309
|
envelope = parseEnvelope(
|
|
@@ -31642,6 +32360,7 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31642
32360
|
terminal_reasons: terminalReasons,
|
|
31643
32361
|
deletion_guidance: counts.superseded_redactor > 0 ? "Update the client, then re-capture the lesson with capture_learning before considering deletion. Delete the superseded draft with delete_private_lesson_candidate only after confirming the replacement was retained or accepted." : null,
|
|
31644
32362
|
deletion_tombstones: deletionTombstones,
|
|
32363
|
+
replaced_records: replacedRecords,
|
|
31645
32364
|
temporary_files: retainedArtifacts.temporaryFiles,
|
|
31646
32365
|
corrupt_files: Math.max(
|
|
31647
32366
|
corruptFiles,
|
|
@@ -31671,13 +32390,14 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31671
32390
|
const recoveryItems = [];
|
|
31672
32391
|
const terminalReasons = {};
|
|
31673
32392
|
let deletionTombstones = 0;
|
|
32393
|
+
let replacedRecords = 0;
|
|
31674
32394
|
let terminalBytes = 0;
|
|
31675
32395
|
let corruptFiles = 0;
|
|
31676
32396
|
for (const entry of await readdir(outbox.directory, {
|
|
31677
32397
|
withFileTypes: true
|
|
31678
32398
|
})) {
|
|
31679
32399
|
const match = entry.name.match(
|
|
31680
|
-
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted)\.json$/u
|
|
32400
|
+
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted|replaced)\.json$/u
|
|
31681
32401
|
);
|
|
31682
32402
|
if (!match) continue;
|
|
31683
32403
|
const draftId = match[1];
|
|
@@ -31689,6 +32409,25 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31689
32409
|
continue;
|
|
31690
32410
|
}
|
|
31691
32411
|
const path = join3(outbox.directory, entry.name);
|
|
32412
|
+
if (entry.name.endsWith(".replaced.json")) {
|
|
32413
|
+
replacedRecords += 1;
|
|
32414
|
+
try {
|
|
32415
|
+
parseReplacedRecord(
|
|
32416
|
+
await readPrivateLessonCanonicalText(
|
|
32417
|
+
path,
|
|
32418
|
+
PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES
|
|
32419
|
+
),
|
|
32420
|
+
draftId
|
|
32421
|
+
);
|
|
32422
|
+
} catch (error) {
|
|
32423
|
+
if (error instanceof PrivateOutboxStorageError) throw error;
|
|
32424
|
+
recoveryItems.push(
|
|
32425
|
+
privateLessonRecoveryItem(draftId, "invalid_canonical_entry")
|
|
32426
|
+
);
|
|
32427
|
+
corruptFiles += 1;
|
|
32428
|
+
}
|
|
32429
|
+
continue;
|
|
32430
|
+
}
|
|
31692
32431
|
if (entry.name.endsWith(".deleted.json")) {
|
|
31693
32432
|
let serialized2;
|
|
31694
32433
|
deletionTombstones += 1;
|
|
@@ -31787,9 +32526,24 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31787
32526
|
corruptFiles += 1;
|
|
31788
32527
|
continue;
|
|
31789
32528
|
}
|
|
31790
|
-
const
|
|
31791
|
-
|
|
31792
|
-
|
|
32529
|
+
const replacement = acceptedPrivateLessonReplacement(
|
|
32530
|
+
outbox.directory,
|
|
32531
|
+
decrypted
|
|
32532
|
+
);
|
|
32533
|
+
if (replacement) {
|
|
32534
|
+
counts[envelope.state] -= 1;
|
|
32535
|
+
replacedRecords += 1;
|
|
32536
|
+
await retireReplacedPrivateLessonUnlocked(
|
|
32537
|
+
outbox.directory,
|
|
32538
|
+
draftId,
|
|
32539
|
+
replacement,
|
|
32540
|
+
now
|
|
32541
|
+
).catch(() => {
|
|
32542
|
+
});
|
|
32543
|
+
continue;
|
|
32544
|
+
}
|
|
32545
|
+
const draft = reconcileStoredDraft(decrypted, now);
|
|
32546
|
+
if (draft !== decrypted || staleSafetyRecheckHint(envelope, draft)) {
|
|
31793
32547
|
counts[envelope.state] -= 1;
|
|
31794
32548
|
counts[draft.state] += 1;
|
|
31795
32549
|
await writeDraftUnlocked(draft, outbox, true, void 0, true);
|
|
@@ -31863,6 +32617,7 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31863
32617
|
terminal_reasons: terminalReasons,
|
|
31864
32618
|
deletion_guidance: counts.superseded_redactor > 0 ? "Update the client, then re-capture the lesson with capture_learning before considering deletion. Delete the superseded draft with delete_private_lesson_candidate only after confirming the replacement was retained or accepted." : null,
|
|
31865
32619
|
deletion_tombstones: deletionTombstones,
|
|
32620
|
+
replaced_records: replacedRecords,
|
|
31866
32621
|
temporary_files: retainedArtifacts.temporaryFiles,
|
|
31867
32622
|
corrupt_files: Math.max(
|
|
31868
32623
|
corruptFiles,
|
|
@@ -31932,6 +32687,7 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
31932
32687
|
terminal_reasons: {},
|
|
31933
32688
|
deletion_guidance: null,
|
|
31934
32689
|
deletion_tombstones: 0,
|
|
32690
|
+
replaced_records: 0,
|
|
31935
32691
|
temporary_files: 0,
|
|
31936
32692
|
corrupt_files: 0,
|
|
31937
32693
|
quarantined_bytes: 0,
|
|
@@ -31970,6 +32726,7 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
31970
32726
|
const counts = emptyOutboxCounts();
|
|
31971
32727
|
let totalBytes = 0;
|
|
31972
32728
|
let deletionTombstones = 0;
|
|
32729
|
+
let replacedRecords = 0;
|
|
31973
32730
|
let terminalBytes = 0;
|
|
31974
32731
|
let corruptFiles = 0;
|
|
31975
32732
|
const terminalReasons = {};
|
|
@@ -31981,6 +32738,10 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
31981
32738
|
deletionTombstones += 1;
|
|
31982
32739
|
continue;
|
|
31983
32740
|
}
|
|
32741
|
+
if (name.endsWith(".replaced.json")) {
|
|
32742
|
+
replacedRecords += 1;
|
|
32743
|
+
continue;
|
|
32744
|
+
}
|
|
31984
32745
|
if (name.endsWith(".submitted.json")) {
|
|
31985
32746
|
const draftId = name.slice(0, -".submitted.json".length);
|
|
31986
32747
|
try {
|
|
@@ -32037,6 +32798,7 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
32037
32798
|
terminal_reasons: terminalReasons,
|
|
32038
32799
|
deletion_guidance: counts.superseded_redactor > 0 ? "Update the client, then re-capture the lesson with capture_learning before considering deletion. Delete the superseded draft with delete_private_lesson_candidate only after confirming the replacement was retained or accepted." : null,
|
|
32039
32800
|
deletion_tombstones: deletionTombstones,
|
|
32801
|
+
replaced_records: replacedRecords,
|
|
32040
32802
|
temporary_files: retainedArtifacts.temporaryFiles,
|
|
32041
32803
|
corrupt_files: corruptFiles,
|
|
32042
32804
|
quarantined_bytes: retainedArtifacts.quarantinedBytes,
|
|
@@ -32461,6 +33223,7 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
32461
33223
|
created_at: validated.created_at,
|
|
32462
33224
|
updated_at: validated.updated_at,
|
|
32463
33225
|
destination_binding: validated.destination_binding,
|
|
33226
|
+
...safetyRecheckField(validated),
|
|
32464
33227
|
encryption: {
|
|
32465
33228
|
algorithm: "aes-256-gcm",
|
|
32466
33229
|
key_source: outbox.encryption.source,
|
|
@@ -32488,7 +33251,7 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
32488
33251
|
if (replace) {
|
|
32489
33252
|
await atomicReplacePrivate(path, serialized);
|
|
32490
33253
|
} else {
|
|
32491
|
-
await
|
|
33254
|
+
await atomicCreatePrivateLessonEntry(path, serialized);
|
|
32492
33255
|
}
|
|
32493
33256
|
}
|
|
32494
33257
|
async function decryptDraft(envelope, encryption, allowUnsupportedProfile = false) {
|
|
@@ -32603,19 +33366,37 @@ function validateDraft(value, allowUnsupportedProfile = false) {
|
|
|
32603
33366
|
);
|
|
32604
33367
|
}
|
|
32605
33368
|
}
|
|
33369
|
+
if (value.attested_organization_audience_hash !== void 0 && !isSha256Digest(value.attested_organization_audience_hash)) {
|
|
33370
|
+
throw new Error("Private lesson draft attested audience is invalid.");
|
|
33371
|
+
}
|
|
33372
|
+
if (value.replacement_of !== void 0 && (typeof value.replacement_of !== "string" || !/^pld_[A-Za-z0-9_-]{8,96}$/u.test(value.replacement_of) || value.replacement_of === value.draft_id)) {
|
|
33373
|
+
throw new Error("Private lesson draft replacement link is invalid.");
|
|
33374
|
+
}
|
|
33375
|
+
if (value.replacement_attempts !== void 0 && (!Array.isArray(value.replacement_attempts) || value.replacement_attempts.length > PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS || !value.replacement_attempts.every(isSha256Digest) || new Set(value.replacement_attempts).size !== value.replacement_attempts.length)) {
|
|
33376
|
+
throw new Error("Private lesson draft replacement attempts are invalid.");
|
|
33377
|
+
}
|
|
32606
33378
|
const destinationBinding = value.destination_binding === void 0 ? null : value.destination_binding === null ? null : parsePrivateLessonDestination(value.destination_binding);
|
|
32607
33379
|
return {
|
|
32608
33380
|
...value,
|
|
32609
33381
|
destination_binding: destinationBinding
|
|
32610
33382
|
};
|
|
32611
33383
|
}
|
|
32612
|
-
function
|
|
33384
|
+
function staleSafetyRecheckHint(envelope, draft) {
|
|
33385
|
+
return (envelope.safety_recheck ?? null) !== privateLessonSafetyRecheck(draft);
|
|
33386
|
+
}
|
|
33387
|
+
function reconcileStoredDraft(draft, now) {
|
|
33388
|
+
return normalizeLegacyHeldSafetyDraft(
|
|
33389
|
+
reconcileRedactorProfile(draft, now),
|
|
33390
|
+
now
|
|
33391
|
+
);
|
|
33392
|
+
}
|
|
33393
|
+
function reconcileRedactorProfile(draft, now) {
|
|
32613
33394
|
try {
|
|
32614
33395
|
privateLessonRedactorProfile(
|
|
32615
33396
|
draft.redaction_version,
|
|
32616
33397
|
draft.redactor_digest
|
|
32617
33398
|
);
|
|
32618
|
-
return draft;
|
|
33399
|
+
return resumeDraftRetiredByOlderClient(draft, now);
|
|
32619
33400
|
} catch (error) {
|
|
32620
33401
|
if (!(error instanceof PrivateLessonRedactionProfileError)) throw error;
|
|
32621
33402
|
if (draft.state === "superseded_redactor" && draft.terminal_reason === error.code || // Accepted work is not a draft awaiting a current redactor. Keep a
|
|
@@ -32634,6 +33415,18 @@ function terminalizeUnsupportedProfile(draft, now) {
|
|
|
32634
33415
|
};
|
|
32635
33416
|
}
|
|
32636
33417
|
}
|
|
33418
|
+
function resumeDraftRetiredByOlderClient(draft, now) {
|
|
33419
|
+
if (draft.state !== "superseded_redactor") return draft;
|
|
33420
|
+
const held = draft.held_reasons.length > 0;
|
|
33421
|
+
return validateDraft({
|
|
33422
|
+
...draft,
|
|
33423
|
+
state: held ? "held_safety" : "retry_scheduled",
|
|
33424
|
+
terminal_reason: null,
|
|
33425
|
+
next_retry_at: held ? null : now.toISOString(),
|
|
33426
|
+
hold_telemetry_status: !held ? "not_required" : draft.hold_telemetry_status === "submitted" ? "submitted" : "pending",
|
|
33427
|
+
updated_at: now.toISOString()
|
|
33428
|
+
});
|
|
33429
|
+
}
|
|
32637
33430
|
function normalizeLegacyHeldSafetyDraft(draft, now) {
|
|
32638
33431
|
if (draft.state !== "held_safety" || draft.held_reasons.length > 0) {
|
|
32639
33432
|
return draft;
|
|
@@ -32750,6 +33543,9 @@ async function reconcileSubmittedRecordsUnlocked(directory, now) {
|
|
|
32750
33543
|
changed = true;
|
|
32751
33544
|
}
|
|
32752
33545
|
}
|
|
33546
|
+
if (await reconcileReplacedRecordsUnlocked(directory, entries, now)) {
|
|
33547
|
+
changed = true;
|
|
33548
|
+
}
|
|
32753
33549
|
if (changed) await syncDirectory2(directory);
|
|
32754
33550
|
}
|
|
32755
33551
|
function submittedRecordListItem(completion) {
|
|
@@ -32785,9 +33581,64 @@ function privateLessonDraftListItem(draft) {
|
|
|
32785
33581
|
terminal_reason: draft.terminal_reason,
|
|
32786
33582
|
hold_telemetry_status: draft.hold_telemetry_status,
|
|
32787
33583
|
hold_event_digest: draft.hold_event_digest,
|
|
32788
|
-
hold_reported_at: draft.hold_reported_at
|
|
33584
|
+
hold_reported_at: draft.hold_reported_at,
|
|
33585
|
+
...safetyRecheckField(draft)
|
|
33586
|
+
};
|
|
33587
|
+
}
|
|
33588
|
+
function safetyRecheckField(draft) {
|
|
33589
|
+
const recheck = privateLessonSafetyRecheck(draft);
|
|
33590
|
+
return recheck ? { safety_recheck: recheck } : {};
|
|
33591
|
+
}
|
|
33592
|
+
function privateLessonReplaceable(draft, destination) {
|
|
33593
|
+
return draft.held_reasons.length > 0 && draft.state !== "submitted" && draft.state !== "superseded_redactor" && draft.replacement_of === void 0 && privateLessonSafetyRecheck(draft) === null && !privateLessonCapturedForOtherDestination(draft, destination);
|
|
33594
|
+
}
|
|
33595
|
+
function privateLessonCapturedForOtherDestination(draft, destination) {
|
|
33596
|
+
const bound = draft.destination_binding;
|
|
33597
|
+
return Boolean(
|
|
33598
|
+
bound && destination && (bound.api_base_sha256 !== destination.api_base_sha256 || bound.credential_sha256 !== destination.credential_sha256)
|
|
33599
|
+
);
|
|
33600
|
+
}
|
|
33601
|
+
function privateLessonReplacementAttemptsRemaining(draft) {
|
|
33602
|
+
return Math.max(
|
|
33603
|
+
0,
|
|
33604
|
+
PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - (draft.replacement_attempts ?? []).length
|
|
33605
|
+
);
|
|
33606
|
+
}
|
|
33607
|
+
function privateLessonAgentRecovery(draftId, attemptsRemaining) {
|
|
33608
|
+
if (attemptsRemaining <= 0) return null;
|
|
33609
|
+
return {
|
|
33610
|
+
tool: "capture_learning",
|
|
33611
|
+
action_code: "recapture_held_private_lesson",
|
|
33612
|
+
arguments: {
|
|
33613
|
+
contract_version: PRIVATE_LEARNING_CAPTURE_VERSION,
|
|
33614
|
+
replacement_of: { draft_id: draftId }
|
|
33615
|
+
},
|
|
33616
|
+
required_input: ["lesson"],
|
|
33617
|
+
context_requirement: "existing_task_context",
|
|
33618
|
+
attempts_remaining: attemptsRemaining,
|
|
33619
|
+
retained_original_available_to_agent: false
|
|
32789
33620
|
};
|
|
32790
33621
|
}
|
|
33622
|
+
function privateLessonRecoveryFields(draft, destination) {
|
|
33623
|
+
if (draft.replacement_of !== void 0) {
|
|
33624
|
+
return { replacement_of: draft.replacement_of };
|
|
33625
|
+
}
|
|
33626
|
+
if (!privateLessonReplaceable(draft)) return {};
|
|
33627
|
+
const remaining = privateLessonReplacementAttemptsRemaining(draft);
|
|
33628
|
+
if (remaining > 0 && !privateLessonReplaceable(draft, destination)) {
|
|
33629
|
+
return {
|
|
33630
|
+
replacement_attempts_remaining: remaining,
|
|
33631
|
+
replacement_requires_captured_destination: true
|
|
33632
|
+
};
|
|
33633
|
+
}
|
|
33634
|
+
return {
|
|
33635
|
+
replacement_attempts_remaining: remaining,
|
|
33636
|
+
agent_recovery: privateLessonAgentRecovery(draft.draft_id, remaining)
|
|
33637
|
+
};
|
|
33638
|
+
}
|
|
33639
|
+
function privateLessonHeldRecoveryActionRequired(attemptsRemaining, capturedDestinationRequired = false) {
|
|
33640
|
+
return attemptsRemaining <= 0 ? "The local safety check holds this lesson draft (held_reasons), so it will not be sent, and it has used every replacement attempt. Keep it, or delete it with delete_private_lesson_candidate and confirm=true once the user confirms." : capturedDestinationRequired ? "The local safety check holds this lesson draft (held_reasons), so it will not be sent. It was captured for another API base or organization credential than this session uses, so a version written here cannot replace it (replacement_requires_captured_destination). Keep it, delete it with delete_private_lesson_candidate and confirm=true, or replace it from a session that uses its own destination. Never resubmit the held content." : "The local safety check holds this lesson draft (held_reasons), so it will not be sent. If this task still has the lesson, write a version without what holds it and capture it as agent_recovery says (capture_learning with replacement_of); this draft is replaced only once that version is accepted. Otherwise keep it, or delete it with delete_private_lesson_candidate and confirm=true. Never resubmit the held content.";
|
|
33641
|
+
}
|
|
32791
33642
|
function privateLessonPageOffset(value) {
|
|
32792
33643
|
const requested = Math.trunc(value ?? 0);
|
|
32793
33644
|
if (!Number.isSafeInteger(requested)) {
|
|
@@ -32847,6 +33698,79 @@ function parseDeletionTombstone(serialized, expectedDraftId) {
|
|
|
32847
33698
|
}
|
|
32848
33699
|
return value;
|
|
32849
33700
|
}
|
|
33701
|
+
function parseReplacedRecord(serialized, expectedDraftId) {
|
|
33702
|
+
const value = JSON.parse(serialized);
|
|
33703
|
+
const allowedKeys = /* @__PURE__ */ new Set([
|
|
33704
|
+
"version",
|
|
33705
|
+
"draft_id",
|
|
33706
|
+
"deleted_at",
|
|
33707
|
+
"reason",
|
|
33708
|
+
"replacement_draft_id",
|
|
33709
|
+
"expires_at"
|
|
33710
|
+
]);
|
|
33711
|
+
if (!isRecord3(value) || Object.keys(value).some((key) => !allowedKeys.has(key)) || value.version !== "private-lesson-outbox-deletion-v1" || value.draft_id !== expectedDraftId || value.reason !== "replaced_by_verified_replacement" || typeof value.replacement_draft_id !== "string" || !/^pld_[A-Za-z0-9_-]{8,96}$/u.test(value.replacement_draft_id) || value.replacement_draft_id === expectedDraftId || !isIsoTimestamp(value.deleted_at) || !isIsoTimestamp(value.expires_at) || Date.parse(value.expires_at) <= Date.parse(value.deleted_at)) {
|
|
33712
|
+
throw new Error("Private lesson replaced record is invalid.");
|
|
33713
|
+
}
|
|
33714
|
+
return value;
|
|
33715
|
+
}
|
|
33716
|
+
async function readReplacedRecordUnlocked(directory, draftId) {
|
|
33717
|
+
const path = replacedRecordPath(directory, draftId);
|
|
33718
|
+
if (!existsSync2(path)) return null;
|
|
33719
|
+
try {
|
|
33720
|
+
await assertRegularPrivateFile(path, PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES);
|
|
33721
|
+
return parseReplacedRecord(
|
|
33722
|
+
await readBoundedFile(path, PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES),
|
|
33723
|
+
draftId
|
|
33724
|
+
);
|
|
33725
|
+
} catch (error) {
|
|
33726
|
+
if (error instanceof PrivateOutboxStorageError) throw error;
|
|
33727
|
+
throw new PrivateLessonDraftUnavailableError(draftId, "corrupt");
|
|
33728
|
+
}
|
|
33729
|
+
}
|
|
33730
|
+
async function assertNotReplacedUnlocked(directory, draftId) {
|
|
33731
|
+
const replaced = await readReplacedRecordUnlocked(directory, draftId);
|
|
33732
|
+
if (replaced) {
|
|
33733
|
+
throw new PrivateLessonDraftUnavailableError(
|
|
33734
|
+
draftId,
|
|
33735
|
+
"replaced",
|
|
33736
|
+
replaced.replacement_draft_id
|
|
33737
|
+
);
|
|
33738
|
+
}
|
|
33739
|
+
}
|
|
33740
|
+
async function reconcileReplacedRecordsUnlocked(directory, entries, now) {
|
|
33741
|
+
let changed = false;
|
|
33742
|
+
for (const name of entries.filter(
|
|
33743
|
+
(entry) => entry.endsWith(".replaced.json")
|
|
33744
|
+
)) {
|
|
33745
|
+
const draftId = name.slice(0, -".replaced.json".length);
|
|
33746
|
+
let record4;
|
|
33747
|
+
try {
|
|
33748
|
+
record4 = parseReplacedRecord(
|
|
33749
|
+
await readBoundedFile(
|
|
33750
|
+
join3(directory, name),
|
|
33751
|
+
PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES
|
|
33752
|
+
),
|
|
33753
|
+
draftId
|
|
33754
|
+
);
|
|
33755
|
+
} catch {
|
|
33756
|
+
continue;
|
|
33757
|
+
}
|
|
33758
|
+
const retained = draftPath(directory, draftId);
|
|
33759
|
+
if (existsSync2(retained)) {
|
|
33760
|
+
try {
|
|
33761
|
+
await assertRegularPrivateFile(retained, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
33762
|
+
await unlink2(retained);
|
|
33763
|
+
changed = true;
|
|
33764
|
+
} catch {
|
|
33765
|
+
}
|
|
33766
|
+
}
|
|
33767
|
+
if (Date.parse(record4.expires_at) <= now.getTime()) {
|
|
33768
|
+
await unlink2(join3(directory, name));
|
|
33769
|
+
changed = true;
|
|
33770
|
+
}
|
|
33771
|
+
}
|
|
33772
|
+
return changed;
|
|
33773
|
+
}
|
|
32850
33774
|
async function privateLessonRecoveryItems(options = {}) {
|
|
32851
33775
|
const outbox = await readyOutbox(options, false);
|
|
32852
33776
|
return withPrivateLessonOutboxLock(outbox.directory, async () => {
|
|
@@ -32859,7 +33783,7 @@ async function privateLessonRecoveryItems(options = {}) {
|
|
|
32859
33783
|
withFileTypes: true
|
|
32860
33784
|
})) {
|
|
32861
33785
|
const match = entry.name.match(
|
|
32862
|
-
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted)\.json$/u
|
|
33786
|
+
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted|replaced)\.json$/u
|
|
32863
33787
|
);
|
|
32864
33788
|
if (!match) continue;
|
|
32865
33789
|
const draftId = match[1];
|
|
@@ -32876,10 +33800,7 @@ async function privateLessonRecoveryItems(options = {}) {
|
|
|
32876
33800
|
outbox.encryption
|
|
32877
33801
|
);
|
|
32878
33802
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
32879
|
-
const draft = validatedDraft ?
|
|
32880
|
-
terminalizeUnsupportedProfile(validatedDraft, now),
|
|
32881
|
-
now
|
|
32882
|
-
) : null;
|
|
33803
|
+
const draft = validatedDraft ? reconcileStoredDraft(validatedDraft, now) : null;
|
|
32883
33804
|
if (draft?.state === "retry_scheduled" && draft.last_error_code === "policy_verification_failed") {
|
|
32884
33805
|
items.push(
|
|
32885
33806
|
privateLessonRecoveryItem(draftId, "held_safety_recovery_required")
|
|
@@ -32986,7 +33907,7 @@ function privateLessonRecoveryItem(draftId, reasonCode, storageError) {
|
|
|
32986
33907
|
async function reconcilePrivateLessonTemporaryWrites(directory, encryption) {
|
|
32987
33908
|
const groups = /* @__PURE__ */ new Map();
|
|
32988
33909
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
32989
|
-
if (/^\.[a-f0-9]{24}\.capacity\.tmp$/u.test(entry.name) && entry.isFile()) {
|
|
33910
|
+
if (/^\.[a-f0-9]{24}\.(?:capacity|replaced)\.tmp$/u.test(entry.name) && entry.isFile()) {
|
|
32990
33911
|
await unlink2(join3(directory, entry.name));
|
|
32991
33912
|
continue;
|
|
32992
33913
|
}
|
|
@@ -33084,6 +34005,16 @@ async function validatePrivateLessonCanonicalPath(path, name, encryption) {
|
|
|
33084
34005
|
);
|
|
33085
34006
|
return null;
|
|
33086
34007
|
}
|
|
34008
|
+
if (name.endsWith(".replaced.json")) {
|
|
34009
|
+
parseReplacedRecord(
|
|
34010
|
+
await readPrivateLessonCanonicalText(
|
|
34011
|
+
path,
|
|
34012
|
+
PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES
|
|
34013
|
+
),
|
|
34014
|
+
draftId
|
|
34015
|
+
);
|
|
34016
|
+
return null;
|
|
34017
|
+
}
|
|
33087
34018
|
if (name.endsWith(".deleted.json")) {
|
|
33088
34019
|
parseDeletionTombstone(
|
|
33089
34020
|
await readPrivateLessonCanonicalText(
|
|
@@ -33224,7 +34155,7 @@ async function removeCanonicalPrivateLessonEntry(path) {
|
|
|
33224
34155
|
async function secureOutboxEntries(directory) {
|
|
33225
34156
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
33226
34157
|
return entries.filter(
|
|
33227
|
-
(entry) => entry.isFile() && !entry.isSymbolicLink() && /^(?:pld_[A-Za-z0-9_-]{8,96}\.(?:lesson|submitted|deleted)\.json)$/u.test(
|
|
34158
|
+
(entry) => entry.isFile() && !entry.isSymbolicLink() && /^(?:pld_[A-Za-z0-9_-]{8,96}\.(?:lesson|submitted|deleted|replaced)\.json)$/u.test(
|
|
33228
34159
|
entry.name
|
|
33229
34160
|
)
|
|
33230
34161
|
).map((entry) => entry.name).sort();
|
|
@@ -33250,10 +34181,10 @@ async function atomicWritePrivate(path, data) {
|
|
|
33250
34181
|
}
|
|
33251
34182
|
await syncDirectory2(dirname3(path));
|
|
33252
34183
|
}
|
|
33253
|
-
async function
|
|
34184
|
+
async function atomicCreatePrivateLessonEntry(path, data, temporarySuffix = ".tmp") {
|
|
33254
34185
|
const temporary = join3(
|
|
33255
34186
|
dirname3(path),
|
|
33256
|
-
`.${randomBytes4(12).toString("hex")}
|
|
34187
|
+
`.${randomBytes4(12).toString("hex")}${temporarySuffix}`
|
|
33257
34188
|
);
|
|
33258
34189
|
try {
|
|
33259
34190
|
await atomicWritePrivate(temporary, data);
|
|
@@ -33492,6 +34423,20 @@ function tombstonePath(directory, draftId) {
|
|
|
33492
34423
|
assertDraftId(draftId);
|
|
33493
34424
|
return join3(directory, `${draftId}.deleted.json`);
|
|
33494
34425
|
}
|
|
34426
|
+
function replacedRecordPath(directory, draftId) {
|
|
34427
|
+
assertDraftId(draftId);
|
|
34428
|
+
return join3(directory, `${draftId}.replaced.json`);
|
|
34429
|
+
}
|
|
34430
|
+
function privateLessonReplacementDraftId(replacementOf, payloadDigest) {
|
|
34431
|
+
assertDraftId(replacementOf);
|
|
34432
|
+
return `pld_${hashValue(
|
|
34433
|
+
canonicalJson({
|
|
34434
|
+
domain: "remembrance-private-lesson-replacement-v1",
|
|
34435
|
+
replacement_of: replacementOf,
|
|
34436
|
+
payload_digest: payloadDigest
|
|
34437
|
+
})
|
|
34438
|
+
).slice("sha256:".length, "sha256:".length + 32)}`;
|
|
34439
|
+
}
|
|
33495
34440
|
function assertDraftId(value) {
|
|
33496
34441
|
if (!/^pld_[A-Za-z0-9_-]{8,96}$/.test(value)) {
|
|
33497
34442
|
throw new Error("Private lesson draft id is invalid.");
|
|
@@ -65784,7 +66729,8 @@ var LOCAL_ONLY_HANDLERS = Object.freeze({
|
|
|
65784
66729
|
),
|
|
65785
66730
|
inspect_private_lesson_outbox: (payload, context) => inspectPrivateLessonOutbox(
|
|
65786
66731
|
payload,
|
|
65787
|
-
context.persistence
|
|
66732
|
+
context.persistence,
|
|
66733
|
+
context.privateLessonDestination
|
|
65788
66734
|
),
|
|
65789
66735
|
delete_private_lesson_candidate: (payload, context) => {
|
|
65790
66736
|
const request = payload;
|
|
@@ -65871,19 +66817,64 @@ function acknowledgeFeedbackDenialLocally(input, persistence) {
|
|
|
65871
66817
|
};
|
|
65872
66818
|
}
|
|
65873
66819
|
}
|
|
65874
|
-
async function preparePrivateLessonDraft(input, persistence, destination, tool) {
|
|
66820
|
+
async function preparePrivateLessonDraft(input, persistence, destination, tool, replacementOf) {
|
|
65875
66821
|
const prepared = preparePrivateLessonCandidate(input, { tool });
|
|
66822
|
+
if (replacementOf) {
|
|
66823
|
+
return preparePrivateLessonReplacement(
|
|
66824
|
+
input,
|
|
66825
|
+
prepared,
|
|
66826
|
+
replacementOf,
|
|
66827
|
+
persistence,
|
|
66828
|
+
destination
|
|
66829
|
+
);
|
|
66830
|
+
}
|
|
65876
66831
|
const draft = await persistence.queuePreparedPrivateLesson(
|
|
65877
66832
|
prepared,
|
|
65878
66833
|
destination
|
|
65879
66834
|
);
|
|
65880
|
-
return privateLessonDraftActionResult(draft, {
|
|
66835
|
+
return privateLessonDraftActionResult(draft, destination, {
|
|
65881
66836
|
next_action: prepared.status === "ready" || prepared.status === "held_safety" && privateLessonHealthReportingEnabled() ? {
|
|
65882
66837
|
tool: "submit_private_lesson_candidate",
|
|
65883
66838
|
arguments: { draft_id: draft.draft_id }
|
|
65884
|
-
} : null
|
|
66839
|
+
} : null,
|
|
66840
|
+
// Where the lesson holds, without its text, for a replacement.
|
|
66841
|
+
...prepared.status === "held_safety" ? privateLessonFindings(input) : {}
|
|
65885
66842
|
});
|
|
65886
66843
|
}
|
|
66844
|
+
async function preparePrivateLessonReplacement(input, prepared, replacementOf, persistence, destination) {
|
|
66845
|
+
try {
|
|
66846
|
+
const { draft, attempts_remaining, replayed } = await persistence.queuePrivateLessonReplacement(
|
|
66847
|
+
replacementOf,
|
|
66848
|
+
prepared,
|
|
66849
|
+
destination
|
|
66850
|
+
);
|
|
66851
|
+
return privateLessonDraftActionResult(draft, destination, {
|
|
66852
|
+
replacement_attempts_remaining: attempts_remaining,
|
|
66853
|
+
replayed,
|
|
66854
|
+
...draft.state === "awaiting_authorization" && draft.attempts === 0 ? {
|
|
66855
|
+
next_action: {
|
|
66856
|
+
tool: "submit_private_lesson_candidate",
|
|
66857
|
+
arguments: { draft_id: draft.draft_id }
|
|
66858
|
+
}
|
|
66859
|
+
} : {}
|
|
66860
|
+
});
|
|
66861
|
+
} catch (error) {
|
|
66862
|
+
if (!(error instanceof PrivateLessonReplacementRefusedError) || error.reason !== "replacement_held") {
|
|
66863
|
+
throw error;
|
|
66864
|
+
}
|
|
66865
|
+
return {
|
|
66866
|
+
status: "not_stored",
|
|
66867
|
+
...error.diagnostic(),
|
|
66868
|
+
held_reasons: prepared.held_reasons,
|
|
66869
|
+
...privateLessonFindings(input),
|
|
66870
|
+
agent_recovery: privateLessonAgentRecovery(
|
|
66871
|
+
replacementOf,
|
|
66872
|
+
error.attemptsRemaining
|
|
66873
|
+
),
|
|
66874
|
+
action_required: error.attemptsRemaining > 0 ? `The local safety check holds this version too (held_reasons and findings), so it was not stored or sent, and the held draft stays as it is. Write a version without what the findings name and capture it again with the same replacement_of; ${error.attemptsRemaining} attempt${error.attemptsRemaining === 1 ? "" : "s"} left.` : privateLessonHeldRecoveryActionRequired(0)
|
|
66875
|
+
};
|
|
66876
|
+
}
|
|
66877
|
+
}
|
|
65887
66878
|
async function captureLearning(input, persistence, lessonDestination, skillDestination) {
|
|
65888
66879
|
const parsed = captureLearningInputSchema.parse(input);
|
|
65889
66880
|
const route = captureLearningRoute(parsed);
|
|
@@ -65899,11 +66890,12 @@ async function captureLearning(input, persistence, lessonDestination, skillDesti
|
|
|
65899
66890
|
};
|
|
65900
66891
|
}
|
|
65901
66892
|
if (route === "private_skill") {
|
|
65902
|
-
const
|
|
65903
|
-
|
|
66893
|
+
const link2 = parsed.replacement_of && "context_source" in parsed.replacement_of ? parsed.replacement_of : void 0;
|
|
66894
|
+
const draft = link2 ? await persistence.queuePrivateSkillReformulation(
|
|
66895
|
+
link2.draft_id,
|
|
65904
66896
|
parsed.private_skill,
|
|
65905
|
-
|
|
65906
|
-
...
|
|
66897
|
+
link2.context_source,
|
|
66898
|
+
...link2.recovery_context_id ? [link2.recovery_context_id] : []
|
|
65907
66899
|
) : await persistence.queuePrivateSkillCapture(
|
|
65908
66900
|
parsed.private_skill,
|
|
65909
66901
|
skillDestination
|
|
@@ -65922,7 +66914,8 @@ async function captureLearning(input, persistence, lessonDestination, skillDesti
|
|
|
65922
66914
|
parsed.lesson,
|
|
65923
66915
|
persistence,
|
|
65924
66916
|
lessonDestination,
|
|
65925
|
-
"capture_learning"
|
|
66917
|
+
"capture_learning",
|
|
66918
|
+
parsed.replacement_of?.draft_id
|
|
65926
66919
|
);
|
|
65927
66920
|
return {
|
|
65928
66921
|
contract_version: parsed.contract_version,
|
|
@@ -66029,7 +67022,7 @@ function privateOutboxDiagnostic(error) {
|
|
|
66029
67022
|
const { reason_code, stage, remediation } = error.diagnostic();
|
|
66030
67023
|
return { reason_code, stage, remediation };
|
|
66031
67024
|
}
|
|
66032
|
-
async function inspectPrivateLessonOutbox(input, persistence) {
|
|
67025
|
+
async function inspectPrivateLessonOutbox(input, persistence, destination) {
|
|
66033
67026
|
const snapshot = await persistence.inspectPrivateLessonOutbox(
|
|
66034
67027
|
input.limit,
|
|
66035
67028
|
input.offset
|
|
@@ -66048,7 +67041,7 @@ async function inspectPrivateLessonOutbox(input, persistence) {
|
|
|
66048
67041
|
}
|
|
66049
67042
|
const draft = await persistence.readPrivateLessonDraft(input.draft_id);
|
|
66050
67043
|
return {
|
|
66051
|
-
draft: privateLessonDraftActionResult(draft),
|
|
67044
|
+
draft: privateLessonDraftActionResult(draft, destination),
|
|
66052
67045
|
outbox: publicOutboxSummary(snapshot.summary),
|
|
66053
67046
|
recovery_items: snapshot.recovery_items
|
|
66054
67047
|
};
|
|
@@ -66106,7 +67099,7 @@ function privateLessonSelectedDraftError(draftId, error) {
|
|
|
66106
67099
|
function privateLessonHealthReportingEnabled(env = process.env) {
|
|
66107
67100
|
return !/^(0|false|no)$/i.test(env.REMEMBRANCE_HEALTH_REPORTING ?? "");
|
|
66108
67101
|
}
|
|
66109
|
-
function privateLessonDraftActionResult(draft, extra = {}) {
|
|
67102
|
+
function privateLessonDraftActionResult(draft, destination, extra = {}) {
|
|
66110
67103
|
return {
|
|
66111
67104
|
draft_id: draft.draft_id,
|
|
66112
67105
|
state: draft.state,
|
|
@@ -66123,8 +67116,10 @@ function privateLessonDraftActionResult(draft, extra = {}) {
|
|
|
66123
67116
|
hold_event_digest: draft.hold_event_digest,
|
|
66124
67117
|
hold_receipt_digest: draft.hold_receipt_digest,
|
|
66125
67118
|
hold_reported_at: draft.hold_reported_at,
|
|
67119
|
+
...safetyRecheckField(draft),
|
|
67120
|
+
...privateLessonRecoveryFields(draft, destination),
|
|
66126
67121
|
retained_locally: draft.state !== "submitted" || hasUnverifiablePrivateLessonCompletion(draft),
|
|
66127
|
-
action_required: privateLessonActionRequired(draft),
|
|
67122
|
+
action_required: privateLessonActionRequired(draft, destination),
|
|
66128
67123
|
next_action: privateLessonNextAction(draft),
|
|
66129
67124
|
...extra
|
|
66130
67125
|
};
|
|
@@ -66172,7 +67167,8 @@ function privateLessonNextAction(draft) {
|
|
|
66172
67167
|
}
|
|
66173
67168
|
return null;
|
|
66174
67169
|
}
|
|
66175
|
-
|
|
67170
|
+
var PRIVATE_LESSON_RECHECKED_HOLD_DECISION = "An earlier safety check held this draft and the current one would not. It stays held unless the user chooses to deliver it (retry_private_lesson_candidate with deliver_rechecked_hold=true) or to delete it (delete_private_lesson_candidate with confirm=true); keeping it needs no action.";
|
|
67171
|
+
function privateLessonActionRequired(draft, destination) {
|
|
66176
67172
|
if (hasUnverifiablePrivateLessonCompletion(draft)) {
|
|
66177
67173
|
return PRIVATE_LESSON_UNVERIFIABLE_COMPLETION_REMEDIATION;
|
|
66178
67174
|
}
|
|
@@ -66182,6 +67178,15 @@ function privateLessonActionRequired(draft) {
|
|
|
66182
67178
|
if (draft.state === "held_safety" && draft.held_reasons.length === 0) {
|
|
66183
67179
|
return "This legacy safety hold has no classified content reason. Retry the exact retained draft so current policy validation can recover it; no replacement has been submitted.";
|
|
66184
67180
|
}
|
|
67181
|
+
if (privateLessonSafetyRecheck(draft)) {
|
|
67182
|
+
return PRIVATE_LESSON_RECHECKED_HOLD_DECISION;
|
|
67183
|
+
}
|
|
67184
|
+
if (draft.state === "held_safety" && privateLessonReplaceable(draft)) {
|
|
67185
|
+
return privateLessonHeldRecoveryActionRequired(
|
|
67186
|
+
privateLessonReplacementAttemptsRemaining(draft),
|
|
67187
|
+
!privateLessonReplaceable(draft, destination)
|
|
67188
|
+
);
|
|
67189
|
+
}
|
|
66185
67190
|
if (draft.state === "awaiting_authorization") {
|
|
66186
67191
|
return "Restore authorization for the exact private-lesson submission action, then retry this retained draft.";
|
|
66187
67192
|
}
|
|
@@ -66200,6 +67205,9 @@ function privateLessonActionRequired(draft) {
|
|
|
66200
67205
|
if (draft.state === "held_validation" && draft.last_error_code === "private_lesson_destination_audience_mismatch") {
|
|
66201
67206
|
return "The current credential proves a different organization audience. Restore the captured organization destination; the retained draft was not sent to this one.";
|
|
66202
67207
|
}
|
|
67208
|
+
if (draft.state === "held_validation" && draft.last_error_code === "private_lesson_destination_attestation_mismatch") {
|
|
67209
|
+
return PRIVATE_LESSON_ATTESTATION_MISMATCH_REMEDIATION;
|
|
67210
|
+
}
|
|
66203
67211
|
if (draft.state === "held_validation") {
|
|
66204
67212
|
return "The encrypted draft remains local because the response or draft failed validation. Inspect its content-free state before choosing any further action; it will not be retried automatically.";
|
|
66205
67213
|
}
|
|
@@ -66745,6 +67753,10 @@ function createLocalPersistenceCapabilities(dependencies = {}) {
|
|
|
66745
67753
|
...await withEncryption(),
|
|
66746
67754
|
...destination ? { destination } : {}
|
|
66747
67755
|
}),
|
|
67756
|
+
queuePrivateLessonReplacement: async (replacementOf, prepared, destination) => queuePrivateLessonReplacement(replacementOf, prepared, {
|
|
67757
|
+
...await withEncryption(),
|
|
67758
|
+
...destination ? { destination } : {}
|
|
67759
|
+
}),
|
|
66748
67760
|
queuePrivateSkillCapture: async (candidate, destination) => queuePrivateSkillCapture(candidate, {
|
|
66749
67761
|
...await withEncryption(),
|
|
66750
67762
|
...destination ? { destination } : {}
|
|
@@ -68146,6 +69158,17 @@ function localPluginLifecycleHealth(options) {
|
|
|
68146
69158
|
explanation: "Each host process session is tracked independently. Turn-specific prompt, tool, and completion observations are combined only when they share the current SessionStart marker."
|
|
68147
69159
|
};
|
|
68148
69160
|
}
|
|
69161
|
+
var HOOK_TRUST_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
|
|
69162
|
+
"app_server_closed",
|
|
69163
|
+
"app_server_initialize_failed",
|
|
69164
|
+
"app_server_unavailable",
|
|
69165
|
+
"check_disabled",
|
|
69166
|
+
"codex_executable_not_found",
|
|
69167
|
+
"hooks_list_failed",
|
|
69168
|
+
"hooks_list_timeout",
|
|
69169
|
+
"hooks_list_too_large",
|
|
69170
|
+
"plugin_hooks_not_listed"
|
|
69171
|
+
]);
|
|
68149
69172
|
function normalizedPluginHookTrust(value) {
|
|
68150
69173
|
if (!isRecord9(value)) return null;
|
|
68151
69174
|
const status = value.status;
|
|
@@ -68180,7 +69203,8 @@ function normalizedPluginHookTrust(value) {
|
|
|
68180
69203
|
status,
|
|
68181
69204
|
checked_at: typeof value.checked_at === "string" && Number.isFinite(Date.parse(value.checked_at)) ? new Date(value.checked_at).toISOString() : null,
|
|
68182
69205
|
review_events: reviewEvents,
|
|
68183
|
-
hooks
|
|
69206
|
+
hooks,
|
|
69207
|
+
reason: status === "unavailable" && typeof value.reason === "string" && HOOK_TRUST_UNAVAILABLE_REASONS.has(value.reason) ? value.reason : null
|
|
68184
69208
|
};
|
|
68185
69209
|
}
|
|
68186
69210
|
function apiDestinationStatus(baseUrl, source) {
|
|
@@ -68562,7 +69586,7 @@ function inspectPrivateLearningOutbox2(input, dependencies = {}) {
|
|
|
68562
69586
|
}
|
|
68563
69587
|
var MAX_REMOTE_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
68564
69588
|
var DOCTOR_PROBE_TIMEOUT_MS = 7500;
|
|
68565
|
-
var SERVER_VERSION = true ? "0.2.
|
|
69589
|
+
var SERVER_VERSION = true ? "0.2.6" : "0.0.0-dev";
|
|
68566
69590
|
var tools2 = toolDefinitions;
|
|
68567
69591
|
var doctorCliRequested = process.argv[2] === "doctor";
|
|
68568
69592
|
var nativeContextCliRequested = process.argv[2] === "--native-context";
|
|
@@ -68843,6 +69867,9 @@ function jsonRpcErrorForToolError(error) {
|
|
|
68843
69867
|
data: error.diagnostic()
|
|
68844
69868
|
};
|
|
68845
69869
|
}
|
|
69870
|
+
if (error instanceof PrivateLessonReplacementRefusedError) {
|
|
69871
|
+
return { code: -32602, message: error.message, data: error.diagnostic() };
|
|
69872
|
+
}
|
|
68846
69873
|
if (error instanceof PrivateLessonLengthLimitError || error instanceof PrivateSkillSizeLimitError) {
|
|
68847
69874
|
return { code: -32602, message: error.message, data: error.diagnostic() };
|
|
68848
69875
|
}
|
|
@@ -68930,11 +69957,13 @@ async function callNetworkToolWithinExecution(definition, payload, access, trans
|
|
|
68930
69957
|
return bootstrapAgentIdentity(payload, access, transport);
|
|
68931
69958
|
}
|
|
68932
69959
|
if (definition.local === "retry_private_lesson_candidate") {
|
|
69960
|
+
const args = payload;
|
|
68933
69961
|
return submitPrivateLessonDraft(
|
|
68934
|
-
String(
|
|
69962
|
+
String(args.draft_id),
|
|
68935
69963
|
access,
|
|
68936
69964
|
"retry",
|
|
68937
|
-
transport
|
|
69965
|
+
transport,
|
|
69966
|
+
{ deliverRecheckedHold: args.deliver_rechecked_hold === true }
|
|
68938
69967
|
);
|
|
68939
69968
|
}
|
|
68940
69969
|
if (definition.local === "retry_private_skill_candidate") {
|
|
@@ -70019,6 +71048,9 @@ var RECOVERABLE_PRIVATE_LESSON_DESTINATION_ERRORS = /* @__PURE__ */ new Set([
|
|
|
70019
71048
|
"private_lesson_destination_audience_mismatch"
|
|
70020
71049
|
]);
|
|
70021
71050
|
function privateLessonDestinationError(draft, current) {
|
|
71051
|
+
if (draft.state === "held_validation" && draft.last_error_code === "private_lesson_destination_attestation_mismatch") {
|
|
71052
|
+
return "private_lesson_destination_attestation_mismatch";
|
|
71053
|
+
}
|
|
70022
71054
|
const captured = draft.destination_binding;
|
|
70023
71055
|
if (!captured) return "private_lesson_destination_legacy_unbound";
|
|
70024
71056
|
if (captured.api_base_sha256 !== current.api_base_sha256) {
|
|
@@ -70039,17 +71071,22 @@ function privateLessonDestinationActionRequired(code) {
|
|
|
70039
71071
|
return "The credential differs from capture and no verified organization audience was established. Restore the captured credential and API base, then retry the exact retained draft.";
|
|
70040
71072
|
case "private_lesson_destination_audience_mismatch":
|
|
70041
71073
|
return "The current credential proves a different organization audience. Restore the captured organization destination; the retained draft was not sent to this one.";
|
|
71074
|
+
case "private_lesson_destination_attestation_mismatch":
|
|
71075
|
+
return PRIVATE_LESSON_ATTESTATION_MISMATCH_REMEDIATION;
|
|
70042
71076
|
}
|
|
70043
71077
|
}
|
|
70044
71078
|
function privateLessonDestinationNextAction(draftId, code) {
|
|
70045
|
-
|
|
70046
|
-
|
|
70047
|
-
|
|
70048
|
-
|
|
70049
|
-
|
|
70050
|
-
|
|
70051
|
-
|
|
70052
|
-
|
|
71079
|
+
if (code === "private_lesson_destination_legacy_unbound") {
|
|
71080
|
+
return {
|
|
71081
|
+
tool: "capture_learning",
|
|
71082
|
+
action_code: "recapture_legacy_private_lesson_with_destination_binding",
|
|
71083
|
+
retained_source_draft_id: draftId,
|
|
71084
|
+
retained_source_available_to_agent: false,
|
|
71085
|
+
required_input: ["lesson"]
|
|
71086
|
+
};
|
|
71087
|
+
}
|
|
71088
|
+
return {
|
|
71089
|
+
tool: code === "private_lesson_destination_attestation_mismatch" ? "inspect_private_lesson_outbox" : "retry_private_lesson_candidate",
|
|
70053
71090
|
arguments: { draft_id: draftId }
|
|
70054
71091
|
};
|
|
70055
71092
|
}
|
|
@@ -70062,8 +71099,9 @@ async function holdPrivateLessonDestination(draft, code) {
|
|
|
70062
71099
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
70063
71100
|
}));
|
|
70064
71101
|
}
|
|
70065
|
-
async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
71102
|
+
async function submitPrivateLessonDraft(draftId, access, mode, transport, { deliverRecheckedHold = false } = {}) {
|
|
70066
71103
|
const allowPolicyRefresh = mode === "retry";
|
|
71104
|
+
const currentDestination = privateLessonDestinationForAccess(access);
|
|
70067
71105
|
const source = await readPrivateLessonSubmissionSource(draftId);
|
|
70068
71106
|
if (source.kind === "submitted") {
|
|
70069
71107
|
return privateLessonSubmittedActionResult2(source.completion, {
|
|
@@ -70072,7 +71110,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70072
71110
|
}
|
|
70073
71111
|
let draft = source.draft;
|
|
70074
71112
|
if (draft.state === "superseded_redactor") {
|
|
70075
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71113
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70076
71114
|
status: "superseded_redactor",
|
|
70077
71115
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70078
71116
|
});
|
|
@@ -70093,6 +71131,24 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70093
71131
|
status: "already_submitted"
|
|
70094
71132
|
});
|
|
70095
71133
|
}
|
|
71134
|
+
if (deliverRecheckedHold && draft.state === "held_safety" && draft.held_reasons.length > 0) {
|
|
71135
|
+
try {
|
|
71136
|
+
draft = await releaseRecheckedPrivateLessonHold(draft.draft_id);
|
|
71137
|
+
} catch (error) {
|
|
71138
|
+
if (!(error instanceof PrivateLessonHoldReleaseRefusedError)) throw error;
|
|
71139
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
71140
|
+
status: "not_submitted",
|
|
71141
|
+
error_code: "private_lesson_hold_not_released",
|
|
71142
|
+
current_hold_reasons: [...error.holdReasons],
|
|
71143
|
+
// Not sent: replacing it is the way on, as for any held draft.
|
|
71144
|
+
action_required: privateLessonHeldRecoveryActionRequired(
|
|
71145
|
+
privateLessonReplacementAttemptsRemaining(draft),
|
|
71146
|
+
!privateLessonReplaceable(draft, currentDestination)
|
|
71147
|
+
),
|
|
71148
|
+
candidate_sent: false
|
|
71149
|
+
});
|
|
71150
|
+
}
|
|
71151
|
+
}
|
|
70096
71152
|
if (draft.state === "held_safety" && draft.held_reasons.length === 0) {
|
|
70097
71153
|
draft = await updatePrivateLessonDraft(
|
|
70098
71154
|
draft.draft_id,
|
|
@@ -70109,14 +71165,13 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70109
71165
|
} : current
|
|
70110
71166
|
);
|
|
70111
71167
|
}
|
|
70112
|
-
const currentDestination = privateLessonDestinationForAccess(access);
|
|
70113
71168
|
const destinationError = privateLessonDestinationError(
|
|
70114
71169
|
draft,
|
|
70115
71170
|
currentDestination
|
|
70116
71171
|
);
|
|
70117
71172
|
if (destinationError) {
|
|
70118
71173
|
draft = await holdPrivateLessonDestination(draft, destinationError);
|
|
70119
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71174
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70120
71175
|
status: "not_submitted",
|
|
70121
71176
|
action_required: privateLessonDestinationActionRequired(destinationError),
|
|
70122
71177
|
next_action: privateLessonDestinationNextAction(
|
|
@@ -70126,10 +71181,27 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70126
71181
|
candidate_sent: false
|
|
70127
71182
|
});
|
|
70128
71183
|
}
|
|
70129
|
-
|
|
71184
|
+
const restoredHold = draft.held_reasons.length > 0 && draft.state !== "held_safety";
|
|
71185
|
+
if (restoredHold) {
|
|
71186
|
+
draft = await updatePrivateLessonDraft(
|
|
71187
|
+
draft.draft_id,
|
|
71188
|
+
(current) => current.held_reasons.length > 0 && current.state !== "held_safety" && current.state !== "submitted" && current.state !== "superseded_redactor" ? {
|
|
71189
|
+
...current,
|
|
71190
|
+
state: "held_safety",
|
|
71191
|
+
next_retry_at: null,
|
|
71192
|
+
last_error_code: null,
|
|
71193
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
71194
|
+
} : current
|
|
71195
|
+
);
|
|
71196
|
+
}
|
|
71197
|
+
if (mode === "retry" && !restoredHold) {
|
|
70130
71198
|
const retryGate = privateLessonRetryGate(draft);
|
|
70131
71199
|
if (retryGate) {
|
|
70132
|
-
return privateLessonDraftActionResult2(
|
|
71200
|
+
return privateLessonDraftActionResult2(
|
|
71201
|
+
draft,
|
|
71202
|
+
currentDestination,
|
|
71203
|
+
retryGate
|
|
71204
|
+
);
|
|
70133
71205
|
}
|
|
70134
71206
|
}
|
|
70135
71207
|
if (draft.state === "held_safety") {
|
|
@@ -70166,7 +71238,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70166
71238
|
error,
|
|
70167
71239
|
error instanceof PrivateLessonPolicyFloorError ? error.code : void 0
|
|
70168
71240
|
);
|
|
70169
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71241
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70170
71242
|
status: "not_submitted",
|
|
70171
71243
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70172
71244
|
});
|
|
@@ -70174,7 +71246,17 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70174
71246
|
if (draft.destination_binding && draft.destination_binding.credential_sha256 !== currentDestination.credential_sha256 && draft.policy && draft.policy.organization_audience_hash !== currentBinding.organization_audience_hash) {
|
|
70175
71247
|
const code = "private_lesson_destination_audience_mismatch";
|
|
70176
71248
|
draft = await holdPrivateLessonDestination(draft, code);
|
|
70177
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71249
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
71250
|
+
status: "not_submitted",
|
|
71251
|
+
action_required: privateLessonDestinationActionRequired(code),
|
|
71252
|
+
next_action: privateLessonDestinationNextAction(draft.draft_id, code),
|
|
71253
|
+
candidate_sent: false
|
|
71254
|
+
});
|
|
71255
|
+
}
|
|
71256
|
+
if (draft.attested_organization_audience_hash !== void 0 && draft.attested_organization_audience_hash !== currentBinding.organization_audience_hash) {
|
|
71257
|
+
const code = "private_lesson_destination_attestation_mismatch";
|
|
71258
|
+
draft = await holdPrivateLessonDestination(draft, code);
|
|
71259
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70178
71260
|
status: "not_submitted",
|
|
70179
71261
|
action_required: privateLessonDestinationActionRequired(code),
|
|
70180
71262
|
next_action: privateLessonDestinationNextAction(draft.draft_id, code),
|
|
@@ -70192,7 +71274,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70192
71274
|
),
|
|
70193
71275
|
"organization_policy_disabled"
|
|
70194
71276
|
);
|
|
70195
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71277
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70196
71278
|
status: "not_submitted",
|
|
70197
71279
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70198
71280
|
});
|
|
@@ -70205,7 +71287,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70205
71287
|
"payload_limit_unavailable"
|
|
70206
71288
|
)
|
|
70207
71289
|
);
|
|
70208
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71290
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70209
71291
|
status: "not_submitted",
|
|
70210
71292
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70211
71293
|
});
|
|
@@ -70221,7 +71303,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70221
71303
|
new PrivateLessonPolicyHoldError(policyConflict.message),
|
|
70222
71304
|
policyConflict.code
|
|
70223
71305
|
);
|
|
70224
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71306
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70225
71307
|
status: "not_submitted",
|
|
70226
71308
|
action_required: policyConflict.action_required
|
|
70227
71309
|
});
|
|
@@ -70334,7 +71416,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70334
71416
|
updated_at: completion.updated_at
|
|
70335
71417
|
};
|
|
70336
71418
|
return {
|
|
70337
|
-
...privateLessonDraftActionResult2(draft, {
|
|
71419
|
+
...privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70338
71420
|
status,
|
|
70339
71421
|
completion_expires_at: completion.expires_at
|
|
70340
71422
|
}),
|
|
@@ -70344,11 +71426,11 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70344
71426
|
} catch (error) {
|
|
70345
71427
|
draft = await persistPrivateLessonFailure(draft, error);
|
|
70346
71428
|
if (draft.state === "submitted") {
|
|
70347
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71429
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70348
71430
|
status: "already_submitted"
|
|
70349
71431
|
});
|
|
70350
71432
|
}
|
|
70351
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71433
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70352
71434
|
status: "not_submitted",
|
|
70353
71435
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70354
71436
|
});
|
|
@@ -70417,8 +71499,9 @@ function retryDue(nextRetryAt) {
|
|
|
70417
71499
|
}
|
|
70418
71500
|
async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolicyRefresh, transport) {
|
|
70419
71501
|
let draft = initialDraft;
|
|
71502
|
+
const currentDestination = privateLessonDestinationForAccess(access);
|
|
70420
71503
|
if (draft.hold_telemetry_status === "submitted") {
|
|
70421
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71504
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70422
71505
|
status: "already_recorded",
|
|
70423
71506
|
processing_state: "recorded"
|
|
70424
71507
|
});
|
|
@@ -70430,7 +71513,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70430
71513
|
next_retry_at: null,
|
|
70431
71514
|
last_error_code: "health_reporting_disabled"
|
|
70432
71515
|
}));
|
|
70433
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71516
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70434
71517
|
status: "not_submitted",
|
|
70435
71518
|
action_required: null
|
|
70436
71519
|
});
|
|
@@ -70450,7 +71533,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70450
71533
|
);
|
|
70451
71534
|
} catch (error) {
|
|
70452
71535
|
draft = await persistPrivateLessonHoldFailure(draft, error);
|
|
70453
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71536
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70454
71537
|
status: "not_submitted",
|
|
70455
71538
|
action_required: privateLessonHoldActionRequired(draft)
|
|
70456
71539
|
});
|
|
@@ -70463,7 +71546,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70463
71546
|
next_retry_at: null,
|
|
70464
71547
|
last_error_code: "private_lesson_automation_disabled"
|
|
70465
71548
|
}));
|
|
70466
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71549
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70467
71550
|
status: "not_submitted",
|
|
70468
71551
|
action_required: null
|
|
70469
71552
|
});
|
|
@@ -70479,7 +71562,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70479
71562
|
new PrivateLessonPolicyHoldError(policyConflict.message),
|
|
70480
71563
|
policyConflict.code
|
|
70481
71564
|
);
|
|
70482
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71565
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70483
71566
|
status: "not_submitted",
|
|
70484
71567
|
action_required: policyConflict.action_required
|
|
70485
71568
|
});
|
|
@@ -70524,7 +71607,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70524
71607
|
policy: receiptPolicy
|
|
70525
71608
|
}));
|
|
70526
71609
|
return {
|
|
70527
|
-
...privateLessonDraftActionResult2(draft, {
|
|
71610
|
+
...privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70528
71611
|
status: submitted.status
|
|
70529
71612
|
}),
|
|
70530
71613
|
receipt: submitted.receipt,
|
|
@@ -70536,7 +71619,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70536
71619
|
continue;
|
|
70537
71620
|
}
|
|
70538
71621
|
draft = await persistPrivateLessonHoldFailure(draft, error);
|
|
70539
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71622
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70540
71623
|
status: "not_submitted",
|
|
70541
71624
|
action_required: privateLessonHoldActionRequired(draft)
|
|
70542
71625
|
});
|
|
@@ -71013,7 +72096,7 @@ function privateLessonRetryAt(attempts, retryAfterMs = null) {
|
|
|
71013
72096
|
Date.now() + Math.max(privateLessonRetryDelayMs(attempts), retryAfterMs ?? 0)
|
|
71014
72097
|
).toISOString();
|
|
71015
72098
|
}
|
|
71016
|
-
function privateLessonDraftActionResult2(draft, extra = {}) {
|
|
72099
|
+
function privateLessonDraftActionResult2(draft, destination, extra = {}) {
|
|
71017
72100
|
return {
|
|
71018
72101
|
draft_id: draft.draft_id,
|
|
71019
72102
|
state: draft.state,
|
|
@@ -71030,6 +72113,8 @@ function privateLessonDraftActionResult2(draft, extra = {}) {
|
|
|
71030
72113
|
hold_event_digest: draft.hold_event_digest,
|
|
71031
72114
|
hold_receipt_digest: draft.hold_receipt_digest,
|
|
71032
72115
|
hold_reported_at: draft.hold_reported_at,
|
|
72116
|
+
...safetyRecheckField(draft),
|
|
72117
|
+
...privateLessonRecoveryFields(draft, destination),
|
|
71033
72118
|
retained_locally: draft.state !== "submitted",
|
|
71034
72119
|
next_action: privateLessonDraftNextAction(draft),
|
|
71035
72120
|
...extra
|
|
@@ -72128,8 +73213,12 @@ function formatConnectionDoctorReport(report) {
|
|
|
72128
73213
|
lines2.push(`[${check.status.toUpperCase()}] ${check.id}: ${check.summary}`);
|
|
72129
73214
|
if (check.remediation) {
|
|
72130
73215
|
lines2.push(` Fix: ${check.remediation.action}`);
|
|
72131
|
-
|
|
72132
|
-
|
|
73216
|
+
const command = check.remediation.command;
|
|
73217
|
+
if (command) {
|
|
73218
|
+
lines2.push(
|
|
73219
|
+
command.includes("\n") ? ` Command:
|
|
73220
|
+
${command.replace(/^/gm, " ")}` : ` Command: ${command}`
|
|
73221
|
+
);
|
|
72133
73222
|
}
|
|
72134
73223
|
}
|
|
72135
73224
|
}
|