@remembrance-ai/mcp-server 0.2.5 → 0.2.7
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 +1317 -234
- 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.";
|
|
@@ -23592,6 +23770,17 @@ function buildOrganizationSkillHandoffBundle(input, createdAt = /* @__PURE__ */
|
|
|
23592
23770
|
});
|
|
23593
23771
|
}
|
|
23594
23772
|
|
|
23773
|
+
// ../core/src/public-skill-delivery.ts
|
|
23774
|
+
var SKILL_INSTALL_COMMAND = "npx skills add dreamarkinc/remembrance-skills --skill remembrancer";
|
|
23775
|
+
function publicSkillDeliveryDefaults() {
|
|
23776
|
+
return {
|
|
23777
|
+
install_command: SKILL_INSTALL_COMMAND,
|
|
23778
|
+
repo_url: "https://github.com/dreamarkinc/remembrance-skills",
|
|
23779
|
+
feedback_url: "https://remembrance.dev/api/v1/agent/remembrances",
|
|
23780
|
+
skill_sh_url: null
|
|
23781
|
+
};
|
|
23782
|
+
}
|
|
23783
|
+
|
|
23595
23784
|
// ../core/src/private-skill-delivery.ts
|
|
23596
23785
|
var PRIVATE_SKILL_DELIVERY_CONTRACT_VERSION = "private-skill-delivery-v1";
|
|
23597
23786
|
var PRIVATE_SKILL_PREDECESSOR_HEADER = "x-remembrance-private-skill-predecessor";
|
|
@@ -23962,14 +24151,35 @@ var GEMINI_ADMIN_ALLOWED_TOOLS = Object.freeze(
|
|
|
23962
24151
|
(tool) => !isConfirmedDelete(tool)
|
|
23963
24152
|
)
|
|
23964
24153
|
);
|
|
24154
|
+
var GEMINI_CLI_CHECKED_VERSION = "0.62.0";
|
|
24155
|
+
var GEMINI_ADMIN_POLICY_FILES = Object.freeze({
|
|
24156
|
+
rules: "remembrance.toml",
|
|
24157
|
+
fallback: "remembrance-fallback.toml"
|
|
24158
|
+
});
|
|
23965
24159
|
var json = (value) => JSON.stringify(value, null, 2);
|
|
23966
24160
|
var approveTables = (server, names = tools) => names.map((tool) => `[${server}.tools.${tool}]
|
|
23967
24161
|
approval_mode = "approve"`).join("\n\n");
|
|
23968
|
-
var geminiRule = (tool, decision = "allow") =>
|
|
23969
|
-
|
|
23970
|
-
|
|
23971
|
-
|
|
23972
|
-
|
|
24162
|
+
var geminiRule = (tool, decision = "allow", priority = 200) => [
|
|
24163
|
+
"[[rule]]",
|
|
24164
|
+
'mcpName = "remembrance"',
|
|
24165
|
+
`toolName = "${tool}"`,
|
|
24166
|
+
...decision === "allow" ? ["toolAnnotations = { destructiveHint = false }"] : [],
|
|
24167
|
+
`decision = "${decision}"`,
|
|
24168
|
+
`priority = ${priority}`
|
|
24169
|
+
].join("\n");
|
|
24170
|
+
var geminiFullNameAsk = (tool) => `[[rule]]
|
|
24171
|
+
toolName = "mcp_remembrance_${tool}"
|
|
24172
|
+
decision = "ask_user"
|
|
24173
|
+
priority = 150`;
|
|
24174
|
+
var geminiFullNameAsks = (names) => names.map(
|
|
24175
|
+
(tool, index) => index === 0 ? [
|
|
24176
|
+
"# Every tool again by the full name Gemini CLI also checks calls by,",
|
|
24177
|
+
"# only ever asking. The allow rules above outrank them, so those tools",
|
|
24178
|
+
"# still run in every mode, plan mode over ACP included, and both",
|
|
24179
|
+
"# confirmed-delete tools ask in every mode, YOLO included.",
|
|
24180
|
+
geminiFullNameAsk(tool)
|
|
24181
|
+
].join("\n") : geminiFullNameAsk(tool)
|
|
24182
|
+
);
|
|
23973
24183
|
var claudeCodePluginTools = withCapture.map(
|
|
23974
24184
|
(tool) => `mcp__plugin_remembrance_remembrance__${tool}`
|
|
23975
24185
|
);
|
|
@@ -24042,7 +24252,12 @@ var PRIVATE_SUBMISSION_APPROVAL_SNIPPETS = Object.freeze({
|
|
|
24042
24252
|
geminiCli: [
|
|
24043
24253
|
...tools.map((tool) => geminiRule(tool)),
|
|
24044
24254
|
`${localOnlyComment}
|
|
24045
|
-
${geminiRule(capture)}
|
|
24255
|
+
${geminiRule(capture)}`,
|
|
24256
|
+
...geminiFullNameAsks([
|
|
24257
|
+
...tools,
|
|
24258
|
+
capture,
|
|
24259
|
+
...PRIVATE_SUBMISSION_CONFIRMED_DELETE_TOOLS
|
|
24260
|
+
])
|
|
24046
24261
|
].join("\n\n"),
|
|
24047
24262
|
// The managed recipe's admin policy file. It holds the step's own rules
|
|
24048
24263
|
// above exactly once, so administrators use it instead of them.
|
|
@@ -24051,15 +24266,26 @@ ${geminiRule(capture)}`
|
|
|
24051
24266
|
"# One exact rule per tool in includeTools: allow, except the two",
|
|
24052
24267
|
"# confirmed-delete tools, which ask. To make a tool ask, change its",
|
|
24053
24268
|
'# 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."
|
|
24269
|
+
"# outranks users' own allow rules, and without one a user's allow decides.",
|
|
24270
|
+
"# Keep each allow rule's toolAnnotations line: it stops the rule from also",
|
|
24271
|
+
"# allowing another server's tool that has the same full name."
|
|
24055
24272
|
].join("\n"),
|
|
24056
24273
|
...REMEMBRANCE_MCP_RECOMMENDED_LOCAL_ORG_TOOLS.map((tool) => {
|
|
24057
24274
|
if (isConfirmedDelete(tool)) return geminiRule(tool, "ask_user");
|
|
24058
24275
|
if (tool === capture) return `${localOnlyComment}
|
|
24059
24276
|
${geminiRule(tool)}`;
|
|
24060
24277
|
return geminiRule(tool);
|
|
24061
|
-
})
|
|
24062
|
-
|
|
24278
|
+
}),
|
|
24279
|
+
...geminiFullNameAsks(REMEMBRANCE_MCP_RECOMMENDED_LOCAL_ORG_TOOLS)
|
|
24280
|
+
].join("\n\n"),
|
|
24281
|
+
// Only where mcp.allowed lists Remembrance, which allows every tool of the
|
|
24282
|
+
// server: this admin ask outranks that allow for each tool without its own
|
|
24283
|
+
// rule above, and those rules, at priority 200, still win for their tools.
|
|
24284
|
+
geminiCliAdminFallback: [
|
|
24285
|
+
`# Save as its own file, ${GEMINI_ADMIN_POLICY_FILES.fallback}, only where`,
|
|
24286
|
+
"# mcp.allowed lists Remembrance; keep toolName, or Gemini CLI skips the file.",
|
|
24287
|
+
geminiRule("*", "ask_user", 100)
|
|
24288
|
+
].join("\n")
|
|
24063
24289
|
});
|
|
24064
24290
|
|
|
24065
24291
|
// ../core/src/private-skill-completion.ts
|
|
@@ -24558,8 +24784,7 @@ var privateSkillReviewRepairRequestSchema = external_exports.preprocess((value,
|
|
|
24558
24784
|
}, privateSkillReviewRepairRequest);
|
|
24559
24785
|
|
|
24560
24786
|
// ../core/src/seed.ts
|
|
24561
|
-
var
|
|
24562
|
-
var feedbackUrl = `${siteUrl}/api/v1/agent/remembrances`;
|
|
24787
|
+
var feedbackUrl = publicSkillDeliveryDefaults().feedback_url;
|
|
24563
24788
|
var jsonItems = (values, indent) => values.map((value) => `${indent}${JSON.stringify(value)}`).join(",\n");
|
|
24564
24789
|
var recommendedClaudeToolJson = jsonItems(
|
|
24565
24790
|
REMEMBRANCE_MCP_RECOMMENDED_ORG_TOOLS.map(
|
|
@@ -24581,7 +24806,6 @@ var openClawToolFilterJson = jsonItems(
|
|
|
24581
24806
|
var privateSubmissionToolList = REMEMBRANCE_MCP_PRIVATE_LEARNING_NETWORK_ACTIONS.map(
|
|
24582
24807
|
(tool) => `- \`${tool}\``
|
|
24583
24808
|
).join("\n");
|
|
24584
|
-
var SKILL_INSTALL_COMMAND = "npx skills add dreamarkinc/remembrance-skills --skill remembrancer";
|
|
24585
24809
|
var skillInstallCommand = SKILL_INSTALL_COMMAND;
|
|
24586
24810
|
var seedSkills = [
|
|
24587
24811
|
{
|
|
@@ -24600,10 +24824,7 @@ var seedSkills = [
|
|
|
24600
24824
|
usefulness_index: 50,
|
|
24601
24825
|
usefulness_confidence: 0,
|
|
24602
24826
|
risk_level: "low",
|
|
24603
|
-
|
|
24604
|
-
repo_url: "https://github.com/dreamarkinc/remembrance-skills",
|
|
24605
|
-
skill_sh_url: null,
|
|
24606
|
-
feedback_url: feedbackUrl,
|
|
24827
|
+
...publicSkillDeliveryDefaults(),
|
|
24607
24828
|
last_verified_at: null,
|
|
24608
24829
|
metadata: {
|
|
24609
24830
|
schema_version: "0.1",
|
|
@@ -24664,7 +24885,7 @@ var seedSkills = [
|
|
|
24664
24885
|
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
24886
|
status: "active",
|
|
24666
24887
|
visibility: "public",
|
|
24667
|
-
version: "0.1.
|
|
24888
|
+
version: "0.1.40",
|
|
24668
24889
|
domains: ["agent-skills", "mcp", "resource-discovery"],
|
|
24669
24890
|
tags: [
|
|
24670
24891
|
"remembrance",
|
|
@@ -24688,10 +24909,7 @@ var seedSkills = [
|
|
|
24688
24909
|
usefulness_index: 58,
|
|
24689
24910
|
usefulness_confidence: 0,
|
|
24690
24911
|
risk_level: "low",
|
|
24691
|
-
|
|
24692
|
-
repo_url: "https://github.com/dreamarkinc/remembrance-skills",
|
|
24693
|
-
skill_sh_url: null,
|
|
24694
|
-
feedback_url: feedbackUrl,
|
|
24912
|
+
...publicSkillDeliveryDefaults(),
|
|
24695
24913
|
last_verified_at: null,
|
|
24696
24914
|
metadata: {
|
|
24697
24915
|
schema_version: "0.1",
|
|
@@ -24715,7 +24933,7 @@ var seedSkills = [
|
|
|
24715
24933
|
"gemini",
|
|
24716
24934
|
"rest"
|
|
24717
24935
|
],
|
|
24718
|
-
version: "0.1.
|
|
24936
|
+
version: "0.1.40",
|
|
24719
24937
|
status: "active",
|
|
24720
24938
|
visibility: "public",
|
|
24721
24939
|
providers: ["codex", "claude", "cursor", "openclaw", "generic"],
|
|
@@ -24904,22 +25122,26 @@ claude plugin install remembrance@remembrance
|
|
|
24904
25122
|
|
|
24905
25123
|
Codex:
|
|
24906
25124
|
|
|
25125
|
+
**Codex CLI.** The Codex plugin needs a Codex CLI: \`codex\` on your PATH or, on
|
|
25126
|
+
macOS, the CLI bundled in the ChatGPT desktop app. The setup, update and
|
|
25127
|
+
hook-review commands run the newest one they find, so an older \`codex\` on PATH
|
|
25128
|
+
cannot shadow the app's newer CLI; set \`CODEX_CLI\` to a CLI's full path to
|
|
25129
|
+
choose one yourself. No other host needs the Codex CLI.
|
|
25130
|
+
|
|
24907
25131
|
~~~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"
|
|
25132
|
+
${CODEX_PLUGIN_SETUP_COMMAND}
|
|
24916
25133
|
~~~
|
|
24917
25134
|
|
|
24918
25135
|
This command handles both first install and update. If zsh says
|
|
24919
|
-
"codex: command not found", it
|
|
24920
|
-
|
|
24921
|
-
|
|
24922
|
-
|
|
25136
|
+
"codex: command not found", it still finds the CLI bundled in the ChatGPT
|
|
25137
|
+
desktop app without requiring a shell alias. The final command opens Codex CLI
|
|
25138
|
+
so its secure hook review can be completed immediately when Codex requires it.
|
|
25139
|
+
|
|
25140
|
+
The block runs in a subshell, so a failure prints a message and leaves your
|
|
25141
|
+
terminal open. It uses \`CODEX_CLI\` when set; otherwise it runs the newest of
|
|
25142
|
+
\`codex\` on PATH, the ChatGPT desktop app's bundled CLI
|
|
25143
|
+
(\`/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex\`) and the
|
|
25144
|
+
older bundle paths, and stops at the first failed step.
|
|
24923
25145
|
|
|
24924
25146
|
Codex will not execute plugin hooks until their exact definitions are trusted.
|
|
24925
25147
|
In the Codex window opened by the installer, if Codex shows a **Hooks need
|
|
@@ -25104,6 +25326,39 @@ only the capture is reviewed; its submission still must not prompt.
|
|
|
25104
25326
|
\`run_connection_doctor\` cannot see a persisted approval; its \`host_approval\`
|
|
25105
25327
|
field reports only recent denials.
|
|
25106
25328
|
|
|
25329
|
+
### Unattended runs
|
|
25330
|
+
|
|
25331
|
+
A run no person attends, such as a scheduled job, \`codex exec\` or
|
|
25332
|
+
\`claude -p\`, cannot answer the user decisions the hooks ask about retained
|
|
25333
|
+
private drafts: deliver, keep or delete. To keep its learning going without
|
|
25334
|
+
using those decisions up:
|
|
25335
|
+
|
|
25336
|
+
1. Approve the four private submit and retry tools as above, so the run
|
|
25337
|
+
delivers its own lessons and skills. On a host that asks, a run nobody can
|
|
25338
|
+
answer denies them, and the draft waits in the outbox.
|
|
25339
|
+
2. Start the run with \`REMEMBRANCE_UNATTENDED=1\`. Its hooks then show none of
|
|
25340
|
+
the user decisions (drafts awaiting the user, held drafts, parked drafts
|
|
25341
|
+
coming back), so none is used up, and the next prompt a person makes on the
|
|
25342
|
+
machine gets them. The run still captures and delivers its own lessons,
|
|
25343
|
+
and nothing about the drafts changes.
|
|
25344
|
+
- Codex: \`REMEMBRANCE_UNATTENDED=1 codex exec ...\`.
|
|
25345
|
+
- Claude Code: \`REMEMBRANCE_UNATTENDED=1 claude -p ...\`, or
|
|
25346
|
+
\`{"env":{"REMEMBRANCE_UNATTENDED":"1"}}\` in settings only those runs
|
|
25347
|
+
load: \`--settings\`, or \`.claude/settings.local.json\` in a folder only
|
|
25348
|
+
scheduled runs use.
|
|
25349
|
+
- OpenCode: \`REMEMBRANCE_UNATTENDED=1 opencode run ...\`. A run attached
|
|
25350
|
+
to a server that is already running follows that server's environment.
|
|
25351
|
+
- Cursor and VS Code: the environment the app or CLI starts its hooks
|
|
25352
|
+
with. Cursor asks these decisions only with
|
|
25353
|
+
\`REMEMBRANCE_VISIBLE_COMPLETION_RECOVERY=1\`.
|
|
25354
|
+
- OpenClaw: the Gateway's environment. It then applies to every session
|
|
25355
|
+
that Gateway serves, so set it only on a Gateway or profile that serves
|
|
25356
|
+
no person.
|
|
25357
|
+
|
|
25358
|
+
Leave \`REMEMBRANCE_UNATTENDED\` unset for sessions a person uses. Do not set
|
|
25359
|
+
\`REMEMBRANCE_AUTO_CONTRIBUTE=0\` for this instead: it also stops the run's own
|
|
25360
|
+
learning.
|
|
25361
|
+
|
|
25107
25362
|
### Claude Code
|
|
25108
25363
|
|
|
25109
25364
|
Merge these entries into \`permissions.allow\` in \`~/.claude/settings.json\`,
|
|
@@ -25247,21 +25502,54 @@ mixed-version installs, use allow-always.
|
|
|
25247
25502
|
|
|
25248
25503
|
### Gemini CLI
|
|
25249
25504
|
|
|
25250
|
-
Create \`~/.gemini/policies/remembrance.toml\` with one rule per tool
|
|
25251
|
-
|
|
25505
|
+
Create \`~/.gemini/policies/remembrance.toml\` with one allow rule per tool, the
|
|
25506
|
+
last of them the local-only \`capture_learning\` entry, then one ask rule for
|
|
25507
|
+
each of those tools and for both confirmed-delete tools, by the full names
|
|
25508
|
+
Gemini CLI gives them:
|
|
25252
25509
|
|
|
25253
25510
|
~~~toml
|
|
25254
25511
|
${PRIVATE_SUBMISSION_APPROVAL_SNIPPETS.geminiCli}
|
|
25255
25512
|
~~~
|
|
25256
25513
|
|
|
25257
|
-
Gemini CLI asks before
|
|
25258
|
-
|
|
25259
|
-
|
|
25260
|
-
|
|
25261
|
-
|
|
25262
|
-
|
|
25263
|
-
|
|
25264
|
-
|
|
25514
|
+
Without a rule, Gemini CLI asks before a Remembrance tool in its default
|
|
25515
|
+
and auto-edit modes; YOLO mode runs the tool without asking, and plan mode
|
|
25516
|
+
blocks it or, for a read-only tool, asks. A headless run, such as
|
|
25517
|
+
\`gemini -p\`, cannot ask: the model never sees a tool that no rule covers, and
|
|
25518
|
+
a tool whose rule asks is denied. These rules cover private learning only, so a
|
|
25519
|
+
headless run also needs rules for the other Remembrance tools it calls, such as
|
|
25520
|
+
\`query_skills\`. The rules name no approval mode, so they also apply in plan
|
|
25521
|
+
mode: there the five tools run without a prompt, private submissions included.
|
|
25522
|
+
|
|
25523
|
+
Gemini CLI also checks some calls under the server name \`mcp_remembrance\`,
|
|
25524
|
+
which no rule with \`mcpName = "remembrance"\` matches: in an IDE connected
|
|
25525
|
+
over ACP, before any other check, and in the terminal, after a rule asks. There
|
|
25526
|
+
only the rules that name a tool by its full name, \`mcp_remembrance_<tool>\`,
|
|
25527
|
+
match, and they only ask. In plan mode over ACP, that ask hands the call on to
|
|
25528
|
+
the allow rules, so the five tools run; without it, plan mode denies them. Both
|
|
25529
|
+
delete tools ask in every mode, YOLO included, whether Gemini CLI starts with
|
|
25530
|
+
\`--yolo\` or the user turns it on with Ctrl+Y; without their full-name rules,
|
|
25531
|
+
YOLO mode runs both without asking. Never change a full-name rule to allow: a
|
|
25532
|
+
rule without \`mcpName\` also matches another server's tool that has the same
|
|
25533
|
+
full name, such as the tool \`private_lesson_candidate\` of a server named
|
|
25534
|
+
\`remembrance_submit\`.
|
|
25535
|
+
|
|
25536
|
+
Each allow rule also requires \`destructiveHint = false\`, which Remembrance's
|
|
25537
|
+
server declares for every tool except the two delete tools. Gemini CLI checks a
|
|
25538
|
+
subagent's calls without the server name or the tool's annotations, and takes
|
|
25539
|
+
the server name from the full name, so without that condition an allow rule
|
|
25540
|
+
would also let a subagent run such a look-alike tool without asking; with it,
|
|
25541
|
+
the full-name rule makes that call ask. A user's own "Allow tool for this
|
|
25542
|
+
session" or "Allow all server tools for this session" answer still stops the
|
|
25543
|
+
prompts until Gemini CLI restarts.
|
|
25544
|
+
|
|
25545
|
+
Keep \`trust\` false and do not list the server in \`mcp.allowed\`: Gemini CLI
|
|
25546
|
+
turns \`trust: true\` and an \`mcp.allowed\` entry alike into an allow rule for
|
|
25547
|
+
every tool of the server. A \`--policy\` flag or a \`policyPaths\` setting
|
|
25548
|
+
replaces \`~/.gemini/policies\`, and Gemini CLI then does not read this file.
|
|
25549
|
+
Gemini CLI starts MCP servers only in a trusted folder; "Approve Gemini CLI"
|
|
25550
|
+
covers unattended runs. Administrators use the admin policy file in "Approve
|
|
25551
|
+
Gemini CLI" instead, which already contains these rules. Checked against Gemini
|
|
25552
|
+
CLI ${GEMINI_CLI_CHECKED_VERSION}.
|
|
25265
25553
|
|
|
25266
25554
|
### Claude Desktop and other MCP clients
|
|
25267
25555
|
|
|
@@ -25354,8 +25642,12 @@ memory, encrypts only the canonical safe record in a local outbox, and returns
|
|
|
25354
25642
|
a draft ID. It never writes the original input to disk, logs, telemetry, or
|
|
25355
25643
|
error output. Tags
|
|
25356
25644
|
use an open, bounded lowercase slug vocabulary; new technical terms survive,
|
|
25357
|
-
while malformed or privacy-sensitive
|
|
25358
|
-
|
|
25645
|
+
while a malformed or privacy-sensitive tag is dropped and counted. Each
|
|
25646
|
+
redaction match becomes its marker and the lesson continues; only a stack
|
|
25647
|
+
trace or zero-width or bidirectional control characters hold the draft
|
|
25648
|
+
locally. A draft an earlier client held that the current check would send is
|
|
25649
|
+
offered to the user once to deliver, keep, or delete; only the user's choice
|
|
25650
|
+
delivers it.
|
|
25359
25651
|
|
|
25360
25652
|
The plugin then calls \`submit_private_lesson_candidate\` with that draft ID.
|
|
25361
25653
|
This is the host-visible network action in the flow, and
|
|
@@ -25457,6 +25749,17 @@ requirements also carry an \`mcp_servers\` allowlist, approve this server by its
|
|
|
25457
25749
|
configured command (\`sh\`): Codex disables a server whose name and identity do
|
|
25458
25750
|
not match an approved entry.
|
|
25459
25751
|
|
|
25752
|
+
Codex checks only a server's name and how it is launched, never the plugin's
|
|
25753
|
+
files. The string form, \`identity = { command = "sh" }\`, compares the command
|
|
25754
|
+
alone; the structured form also compares each positional argument, but neither
|
|
25755
|
+
inspects the working directory or environment. So another local server with
|
|
25756
|
+
the same name and identity, such as one a user adds to their own
|
|
25757
|
+
\`config.toml\`, can pass the same check; the marketplace source restriction is
|
|
25758
|
+
what limits where the plugin itself comes from. OpenAI's managed-configuration
|
|
25759
|
+
documentation does not say whether a plugin's bundled server is checked
|
|
25760
|
+
against \`plugins.<plugin>.mcp_servers.<server>\` entries, top-level
|
|
25761
|
+
\`mcp_servers\` entries, or both.
|
|
25762
|
+
|
|
25460
25763
|
Add these entries to \`requirements.toml\`:
|
|
25461
25764
|
|
|
25462
25765
|
~~~toml
|
|
@@ -25717,9 +26020,10 @@ work. See the official
|
|
|
25717
26020
|
|
|
25718
26021
|
### Approve Gemini CLI
|
|
25719
26022
|
|
|
25720
|
-
|
|
25721
|
-
|
|
25722
|
-
|
|
26023
|
+
This recipe was checked against Gemini CLI ${GEMINI_CLI_CHECKED_VERSION}; check it again
|
|
26024
|
+
after upgrading Gemini CLI. Define the canonical server and its tool allowlist
|
|
26025
|
+
in the system override settings, not only user or workspace settings. Keep
|
|
26026
|
+
\`trust\` false; \`trust: true\` bypasses every confirmation for the server:
|
|
25723
26027
|
|
|
25724
26028
|
~~~json
|
|
25725
26029
|
{
|
|
@@ -25741,50 +26045,151 @@ ${geminiIncludeToolJson}
|
|
|
25741
26045
|
~~~
|
|
25742
26046
|
|
|
25743
26047
|
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,
|
|
26048
|
+
\`mcp.allowed\`: the server runs without it, and Gemini CLI turns each
|
|
26049
|
+
\`mcp.allowed\` entry into an allow rule for every tool of that server.
|
|
26050
|
+
Instead, save this file as \`${GEMINI_ADMIN_POLICY_FILES.rules}\` in the admin policy
|
|
26051
|
+
folder: \`/Library/Application Support/GeminiCli/policies\` on macOS,
|
|
25748
26052
|
\`/etc/gemini-cli/policies\` on Linux, or \`C:\\ProgramData\\gemini-cli\\policies\`
|
|
25749
|
-
on Windows.
|
|
26053
|
+
on Windows.
|
|
25750
26054
|
|
|
25751
26055
|
~~~toml
|
|
25752
26056
|
${PRIVATE_SUBMISSION_APPROVAL_SNIPPETS.geminiCliAdmin}
|
|
25753
26057
|
~~~
|
|
25754
26058
|
|
|
26059
|
+
Gemini CLI checks the folder, not the files in it. On macOS and Linux the
|
|
26060
|
+
folder must be owned by root and not writable by group or others. On Windows it
|
|
26061
|
+
must be owned by Administrators, SYSTEM or a system service, and only those may
|
|
26062
|
+
have write access to it, so remove any write access for Users, such as rights
|
|
26063
|
+
inherited from \`C:\\ProgramData\`. Otherwise Gemini CLI skips the whole folder
|
|
26064
|
+
with a security warning. It loads only regular \`.toml\` files, not symbolic
|
|
26065
|
+
links, and checks neither the files' owner nor the parent folders, so keep
|
|
26066
|
+
those owned and writable only by administrators as well. Once the folder holds
|
|
26067
|
+
a \`.toml\` file, Gemini CLI ignores \`--admin-policy\` and \`adminPolicyPaths\`,
|
|
26068
|
+
with a warning.
|
|
26069
|
+
|
|
25755
26070
|
The file has one exact rule for every tool in \`includeTools\`: an allow rule
|
|
25756
26071
|
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
|
-
|
|
26072
|
+
rules make them ask even where a user's own rule allows them, so a headless run
|
|
26073
|
+
denies them. In Gemini CLI's default, auto-edit and YOLO modes, this reproduces
|
|
26074
|
+
the earlier behavior of this recipe, whose \`mcp.allowed\` entry let every
|
|
26075
|
+
included tool run, apart from those two, with exact rules instead of a
|
|
26076
|
+
whole-server rule. Unlike that entry, the rules name no approval mode, so they
|
|
26077
|
+
also apply in plan mode: there the allowed Remembrance tools run as well,
|
|
26078
|
+
private submissions included, and the two delete tools still ask. The file
|
|
26079
|
+
already contains the rules from "Highly Recommended: approve private
|
|
26080
|
+
submissions" for the four private submit and retry tools and the local-only
|
|
26081
|
+
\`capture_learning\`, so do not add those again. To make a tool ask, change its
|
|
26082
|
+
rule to \`decision = "ask_user"\` instead of deleting the rule: an admin-tier ask
|
|
26083
|
+
outranks users' own allow rules, while without an admin rule a user's allow
|
|
26084
|
+
rule decides. A headless run then denies that tool.
|
|
26085
|
+
|
|
26086
|
+
The rules after those name every tool in \`includeTools\` again by the full
|
|
26087
|
+
name Gemini CLI gives it, \`mcp_remembrance_<tool>\`, without \`mcpName\`, and
|
|
26088
|
+
only ask. Gemini CLI ${GEMINI_CLI_CHECKED_VERSION} also checks calls under the server
|
|
26089
|
+
name \`mcp_remembrance\`, which no rule with \`mcpName = "remembrance"\`
|
|
26090
|
+
matches: in an IDE connected over ACP before any other check, and in the
|
|
26091
|
+
terminal after a rule asks. Without a full-name rule, the mode's own default
|
|
26092
|
+
decides there: plan mode denies every tool not marked read-only, and YOLO mode
|
|
26093
|
+
allows every tool. With them, that check only asks. Over ACP it then hands the
|
|
26094
|
+
call on to the exact rules, so the allowed tools run in plan mode as well, and
|
|
26095
|
+
both delete tools ask in every approval mode, YOLO included, whether Gemini
|
|
26096
|
+
CLI started with \`--yolo\` or the user turned it on with Ctrl+Y, while a
|
|
26097
|
+
headless run refuses them. Never change them to allow: without \`mcpName\`, a
|
|
26098
|
+
rule also matches another server's tool that has the same full name, such as
|
|
26099
|
+
the tool \`skills\` of a server named \`remembrance_query\`, whose full name is
|
|
26100
|
+
\`mcp_remembrance_query_skills\`.
|
|
26101
|
+
|
|
26102
|
+
Each allow rule also requires \`destructiveHint = false\`, which Remembrance's
|
|
26103
|
+
server declares for every tool except the two delete tools. Gemini CLI checks a
|
|
26104
|
+
subagent's calls without the server name or the tool's annotations, and takes
|
|
26105
|
+
the server name from the full name, so without that condition the allow rule
|
|
26106
|
+
for \`query_skills\` would also let a subagent run that \`skills\` tool without
|
|
26107
|
+
asking. With it, such a call asks, while Remembrance's own tools still run.
|
|
26108
|
+
|
|
26109
|
+
The delete tools' admin ask rules hold against users' policy rules, but not
|
|
26110
|
+
against a user's own answer to the prompt. After "Allow tool for this session",
|
|
26111
|
+
Gemini CLI does not ask before that tool again until it restarts, and "Allow
|
|
26112
|
+
all server tools for this session" on any Remembrance prompt does the same for
|
|
26113
|
+
every Remembrance tool, both deletes included. Where every delete must ask,
|
|
26114
|
+
also set \`security.disableAlwaysAllow\` to \`true\` in the system settings:
|
|
26115
|
+
Gemini CLI then offers neither answer for any tool, so each tool that asks does
|
|
26116
|
+
so every time.
|
|
26117
|
+
|
|
26118
|
+
To keep users out of YOLO mode altogether, also set \`security.disableYoloMode\`
|
|
26119
|
+
to \`true\` in the system settings. Gemini CLI then refuses to start in YOLO
|
|
26120
|
+
mode, in the terminal, headless or over ACP, and refuses Ctrl+Y. It does not
|
|
26121
|
+
stop an IDE connected over ACP from switching a running session to YOLO mode,
|
|
26122
|
+
so keep the full-name rules above either way.
|
|
25767
26123
|
|
|
25768
26124
|
If the organization already restricts servers with \`mcp.allowed\`, Remembrance
|
|
25769
26125
|
must be listed there to run, and that entry creates the whole-server allow rule.
|
|
25770
|
-
Then also
|
|
25771
|
-
|
|
25772
|
-
|
|
25773
|
-
|
|
26126
|
+
Then also save this rule in the admin policy folder as its own file,
|
|
26127
|
+
\`${GEMINI_ADMIN_POLICY_FILES.fallback}\`, next to \`${GEMINI_ADMIN_POLICY_FILES.rules}\`. It creates no
|
|
26128
|
+
allow rule: admin rules outrank the one \`mcp.allowed\` creates, so a
|
|
26129
|
+
Remembrance tool without its own admin rule asks again, while the per-tool rules
|
|
26130
|
+
above, at priority 200, still win over it for their tools. Keep
|
|
26131
|
+
\`toolName = "*"\`, which matches every tool of the \`remembrance\` server, and
|
|
26132
|
+
keep the rule out of \`${GEMINI_ADMIN_POLICY_FILES.rules}\`: Gemini CLI rejects a rule
|
|
26133
|
+
without \`toolName\`, although its policy engine guide shows one, and an invalid
|
|
26134
|
+
rule makes it skip every rule in the same file.
|
|
25774
26135
|
|
|
25775
26136
|
~~~toml
|
|
25776
|
-
|
|
25777
|
-
mcpName = "remembrance"
|
|
25778
|
-
decision = "ask_user"
|
|
25779
|
-
priority = 100
|
|
26137
|
+
${PRIVATE_SUBMISSION_APPROVAL_SNIPPETS.geminiCliAdminFallback}
|
|
25780
26138
|
~~~
|
|
25781
26139
|
|
|
25782
26140
|
System settings live at \`/Library/Application Support/GeminiCli/settings.json\`
|
|
25783
26141
|
on macOS, \`/etc/gemini-cli/settings.json\` on Linux, and
|
|
25784
|
-
\`C:\\ProgramData\\gemini-cli\\settings.json\` on Windows.
|
|
25785
|
-
|
|
25786
|
-
|
|
25787
|
-
|
|
26142
|
+
\`C:\\ProgramData\\gemini-cli\\settings.json\` on Windows. Gemini CLI checks
|
|
26143
|
+
that file and every folder above it the way it checks the admin policy folder,
|
|
26144
|
+
on Windows \`C:\\ProgramData\` included, and skips the file with a security
|
|
26145
|
+
warning when one fails. System settings outrank user and workspace settings but
|
|
26146
|
+
are not locked: Gemini CLI reads them from whatever file
|
|
26147
|
+
\`GEMINI_CLI_SYSTEM_SETTINGS_PATH\` names, so a user who controls the
|
|
26148
|
+
environment it starts in can drop this definition and use their own, for
|
|
26149
|
+
example without \`includeTools\` or with \`trust: true\`, which in a trusted
|
|
26150
|
+
folder also skips the admin ask rules. The admin policy folder cannot be moved
|
|
26151
|
+
that way. Where this matters, start Gemini CLI through a wrapper that sets the
|
|
26152
|
+
variable to the managed file, as Gemini CLI's enterprise guide describes.
|
|
26153
|
+
|
|
26154
|
+
The system settings also do not cover the MCP servers a subagent defines for
|
|
26155
|
+
itself, or the server list an IDE sends when it opens a session over ACP.
|
|
26156
|
+
Either can define its own server named \`remembrance\` that runs another
|
|
26157
|
+
command, without \`includeTools\`, and Gemini CLI ${GEMINI_CLI_CHECKED_VERSION} then
|
|
26158
|
+
applies the allow rules to that server's tools of the same names. A subagent
|
|
26159
|
+
definition in \`~/.gemini/agents\`, or one the user accepts from a trusted
|
|
26160
|
+
project's \`.gemini/agents\` folder, can also set \`trust: true\`, and that
|
|
26161
|
+
subagent then runs both delete tools without asking: in the terminal in every
|
|
26162
|
+
mode except plan mode, which does not run it, and over ACP in YOLO mode. An
|
|
26163
|
+
IDE's server list cannot set \`trust\`, so both delete tools still ask there.
|
|
26164
|
+
Where every delete must ask, also set \`experimental.enableAgents\` to
|
|
26165
|
+
\`false\` in the system settings. Gemini CLI then loads no subagents, its
|
|
26166
|
+
built-in ones included.
|
|
26167
|
+
|
|
26168
|
+
This recipe was not tested on Windows. A default Windows install may let the
|
|
26169
|
+
Users group create files and folders in \`C:\\ProgramData\`. If it does, Gemini
|
|
26170
|
+
CLI ${GEMINI_CLI_CHECKED_VERSION} skips \`C:\\ProgramData\\gemini-cli\\settings.json\` on
|
|
26171
|
+
every machine, and the admin policy folder too unless its inherited Users
|
|
26172
|
+
rights are removed. To check, run \`icacls C:\\ProgramData\` and
|
|
26173
|
+
\`icacls C:\\ProgramData\\gemini-cli\`: Gemini CLI accepts write, append,
|
|
26174
|
+
delete, ownership or permission rights, such as \`(W)\`, \`(WD)\`, \`(AD)\`,
|
|
26175
|
+
\`(M)\` or \`(F)\`, only for Administrators, SYSTEM, service accounts
|
|
26176
|
+
(\`NT SERVICE\\...\`), CREATOR OWNER and CREATOR GROUP. When a check fails,
|
|
26177
|
+
Gemini CLI's security warning names the folder and the groups that can write
|
|
26178
|
+
to it.
|
|
26179
|
+
|
|
26180
|
+
Gemini CLI fills in \`\${REMEMBRANCE_API_KEY}\` from the environment it starts
|
|
26181
|
+
in. Without that variable the server receives an empty key and uses the shared
|
|
26182
|
+
config file from "Enterprise/org key setup" instead. Gemini CLI starts MCP
|
|
26183
|
+
servers only in a trusted folder, and interactive Gemini CLI asks whether to
|
|
26184
|
+
trust a new folder. In a folder that is not trusted, the Remembrance server does
|
|
26185
|
+
not start, and a headless run, such as \`gemini -p\` in CI, exits with an error
|
|
26186
|
+
unless the folder is trusted, \`--skip-trust\` is passed, or
|
|
26187
|
+
\`GEMINI_CLI_TRUST_WORKSPACE=true\` is set. Use those two only for unattended
|
|
26188
|
+
runs in folders the organization trusts.
|
|
26189
|
+
|
|
26190
|
+
Also allow \`remembrance.dev\` in the organization's egress policy. Restart
|
|
26191
|
+
Gemini CLI, inspect the registered server, then run \`run_connection_doctor\`
|
|
26192
|
+
and require organization scope before contribution work. See the official
|
|
25788
26193
|
[enterprise configuration](https://geminicli.com/docs/cli/enterprise/),
|
|
25789
26194
|
[MCP settings](https://geminicli.com/docs/tools/mcp-server/), and
|
|
25790
26195
|
[policy engine](https://geminicli.com/docs/reference/policy-engine/).
|
|
@@ -26148,9 +26553,10 @@ session skills.
|
|
|
26148
26553
|
standing instructions proactively. If tools are still not visible, use the
|
|
26149
26554
|
REST fallback and emit REMEMBRANCE_SUBMISSION_PAYLOAD only when the API is
|
|
26150
26555
|
unavailable.
|
|
26151
|
-
- "codex: command not found": use the complete Codex setup above. It
|
|
26152
|
-
|
|
26153
|
-
|
|
26556
|
+
- "codex: command not found": use the complete Codex setup above. It runs the
|
|
26557
|
+
newest Codex CLI it finds: \`codex\` on PATH, the ChatGPT desktop app's
|
|
26558
|
+
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex", or the
|
|
26559
|
+
older bundle paths. Set CODEX_CLI to a Codex CLI's full path to choose one.
|
|
26154
26560
|
- "401 or 403": the key is missing, expired, revoked, scoped to a different
|
|
26155
26561
|
environment, or not visible to the agent process. Check config file vs env
|
|
26156
26562
|
precedence and regenerate a key from the dashboard if needed.
|
|
@@ -26267,10 +26673,7 @@ session skills.
|
|
|
26267
26673
|
usefulness_index: 50,
|
|
26268
26674
|
usefulness_confidence: 0,
|
|
26269
26675
|
risk_level: "low",
|
|
26270
|
-
|
|
26271
|
-
repo_url: "https://github.com/dreamarkinc/remembrance-skills",
|
|
26272
|
-
skill_sh_url: null,
|
|
26273
|
-
feedback_url: feedbackUrl,
|
|
26676
|
+
...publicSkillDeliveryDefaults(),
|
|
26274
26677
|
last_verified_at: null,
|
|
26275
26678
|
metadata: {
|
|
26276
26679
|
schema_version: "0.1",
|
|
@@ -26385,10 +26788,7 @@ that agents add over time.
|
|
|
26385
26788
|
usefulness_index: 50,
|
|
26386
26789
|
usefulness_confidence: 0,
|
|
26387
26790
|
risk_level: "medium",
|
|
26388
|
-
|
|
26389
|
-
repo_url: "https://github.com/dreamarkinc/remembrance-skills",
|
|
26390
|
-
skill_sh_url: null,
|
|
26391
|
-
feedback_url: feedbackUrl,
|
|
26791
|
+
...publicSkillDeliveryDefaults(),
|
|
26392
26792
|
last_verified_at: null,
|
|
26393
26793
|
metadata: {
|
|
26394
26794
|
schema_version: "0.1",
|
|
@@ -26515,10 +26915,7 @@ over time.
|
|
|
26515
26915
|
usefulness_index: 55,
|
|
26516
26916
|
usefulness_confidence: 0,
|
|
26517
26917
|
risk_level: "medium",
|
|
26518
|
-
|
|
26519
|
-
repo_url: "https://github.com/dreamarkinc/remembrance-skills",
|
|
26520
|
-
skill_sh_url: null,
|
|
26521
|
-
feedback_url: feedbackUrl,
|
|
26918
|
+
...publicSkillDeliveryDefaults(),
|
|
26522
26919
|
last_verified_at: null,
|
|
26523
26920
|
metadata: {
|
|
26524
26921
|
schema_version: "0.1",
|
|
@@ -28751,6 +29148,11 @@ var privateLessonInspectSchema = external_exports.object({
|
|
|
28751
29148
|
"Zero-based local page offset. Follow next_offset until truncated is false."
|
|
28752
29149
|
)
|
|
28753
29150
|
}).strict();
|
|
29151
|
+
var privateLessonRetrySchema = privateLessonDraftReferenceSchema.extend({
|
|
29152
|
+
deliver_rechecked_hold: external_exports.literal(true).optional().describe(
|
|
29153
|
+
"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."
|
|
29154
|
+
)
|
|
29155
|
+
});
|
|
28754
29156
|
var privateLessonDeleteSchema = privateLessonDraftReferenceSchema.extend({
|
|
28755
29157
|
confirm: external_exports.literal(true).describe(
|
|
28756
29158
|
"Must be true. Deletion is explicit and leaves a content-free tombstone."
|
|
@@ -28984,7 +29386,7 @@ var declaredToolDefinitions = [
|
|
|
28984
29386
|
),
|
|
28985
29387
|
localTool(
|
|
28986
29388
|
"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
|
|
29389
|
+
"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
29390
|
"prepare_private_lesson_candidate",
|
|
28989
29391
|
privateLessonPreparationInputSchema
|
|
28990
29392
|
),
|
|
@@ -29003,9 +29405,9 @@ var declaredToolDefinitions = [
|
|
|
29003
29405
|
),
|
|
29004
29406
|
localNetworkTool(
|
|
29005
29407
|
"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.",
|
|
29408
|
+
"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
29409
|
"retry_private_lesson_candidate",
|
|
29008
|
-
|
|
29410
|
+
privateLessonRetrySchema,
|
|
29009
29411
|
"content_write"
|
|
29010
29412
|
),
|
|
29011
29413
|
localTool(
|
|
@@ -29721,14 +30123,26 @@ function normalizeBoundedWriteJsonSchema(schema, name) {
|
|
|
29721
30123
|
schema.allOf = [
|
|
29722
30124
|
{
|
|
29723
30125
|
if: { required: ["replacement_of"] },
|
|
29724
|
-
then: {
|
|
30126
|
+
then: {
|
|
30127
|
+
anyOf: [
|
|
30128
|
+
["^psd_", "private_skill"],
|
|
30129
|
+
["^pld_", "lesson"]
|
|
30130
|
+
].map(([pattern, payload]) => ({
|
|
30131
|
+
required: [payload],
|
|
30132
|
+
properties: {
|
|
30133
|
+
replacement_of: { properties: { draft_id: { pattern } } }
|
|
30134
|
+
}
|
|
30135
|
+
}))
|
|
30136
|
+
}
|
|
29725
30137
|
}
|
|
29726
30138
|
];
|
|
29727
30139
|
const replacement = schemaProperty(schema, "replacement_of");
|
|
29728
|
-
replacement.description = "Optional lineage for a
|
|
29729
|
-
|
|
29730
|
-
schemaProperty(
|
|
29731
|
-
schemaProperty(
|
|
30140
|
+
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.";
|
|
30141
|
+
const [skillLink, lessonLink] = replacement.anyOf;
|
|
30142
|
+
schemaProperty(skillLink, "draft_id").description = "Retained encrypted private-skill draft being replaced.";
|
|
30143
|
+
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.";
|
|
30144
|
+
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.";
|
|
30145
|
+
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
30146
|
}
|
|
29733
30147
|
if (name === "register_agent_key") {
|
|
29734
30148
|
const metadata = schemaProperty(schema, "metadata");
|
|
@@ -31160,6 +31574,7 @@ var PRIVATE_LESSON_CAPACITY_STATE_MAX_BYTES = 1024;
|
|
|
31160
31574
|
var PRIVATE_LESSON_OUTBOX_LOCK_NAMESPACE = "outbox";
|
|
31161
31575
|
var PRIVATE_LESSON_MAX_PAGE_OFFSET = Number.MAX_SAFE_INTEGER - 200;
|
|
31162
31576
|
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.";
|
|
31577
|
+
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
31578
|
var PrivateLessonPolicyFloorError = class extends Error {
|
|
31164
31579
|
constructor(message, code) {
|
|
31165
31580
|
super(message);
|
|
@@ -31169,16 +31584,18 @@ var PrivateLessonPolicyFloorError = class extends Error {
|
|
|
31169
31584
|
code;
|
|
31170
31585
|
};
|
|
31171
31586
|
var PrivateLessonDraftUnavailableError = class extends Error {
|
|
31172
|
-
constructor(draftId, reason) {
|
|
31587
|
+
constructor(draftId, reason, replacementDraftId) {
|
|
31173
31588
|
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."
|
|
31589
|
+
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
31590
|
);
|
|
31176
31591
|
this.draftId = draftId;
|
|
31177
31592
|
this.reason = reason;
|
|
31593
|
+
this.replacementDraftId = replacementDraftId;
|
|
31178
31594
|
this.name = "PrivateLessonDraftUnavailableError";
|
|
31179
31595
|
}
|
|
31180
31596
|
draftId;
|
|
31181
31597
|
reason;
|
|
31598
|
+
replacementDraftId;
|
|
31182
31599
|
jsonRpcCode() {
|
|
31183
31600
|
return this.reason === "corrupt" ? -32603 : -32602;
|
|
31184
31601
|
}
|
|
@@ -31186,22 +31603,84 @@ var PrivateLessonDraftUnavailableError = class extends Error {
|
|
|
31186
31603
|
return {
|
|
31187
31604
|
code: `private_lesson_draft_${this.reason}`,
|
|
31188
31605
|
draft_id: this.draftId,
|
|
31606
|
+
...this.reason === "replaced" && this.replacementDraftId ? { replacement_draft_id: this.replacementDraftId } : {},
|
|
31189
31607
|
retained_locally: this.reason === "corrupt",
|
|
31190
31608
|
candidate_sent: false,
|
|
31191
31609
|
next_action: {
|
|
31192
31610
|
tool: "inspect_private_lesson_outbox",
|
|
31193
|
-
arguments: {
|
|
31611
|
+
arguments: {
|
|
31612
|
+
draft_id: this.reason === "replaced" && this.replacementDraftId ? this.replacementDraftId : this.draftId
|
|
31613
|
+
}
|
|
31194
31614
|
}
|
|
31195
31615
|
};
|
|
31196
31616
|
}
|
|
31197
31617
|
};
|
|
31618
|
+
function privateLessonSafetyRecheck(draft) {
|
|
31619
|
+
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;
|
|
31620
|
+
}
|
|
31621
|
+
var PrivateLessonHoldReleaseRefusedError = class extends Error {
|
|
31622
|
+
constructor(draftId, holdReasons) {
|
|
31623
|
+
super(
|
|
31624
|
+
"The current local safety check still holds this private lesson draft; nothing was sent."
|
|
31625
|
+
);
|
|
31626
|
+
this.draftId = draftId;
|
|
31627
|
+
this.holdReasons = holdReasons;
|
|
31628
|
+
this.name = "PrivateLessonHoldReleaseRefusedError";
|
|
31629
|
+
}
|
|
31630
|
+
draftId;
|
|
31631
|
+
holdReasons;
|
|
31632
|
+
};
|
|
31633
|
+
async function releaseRecheckedPrivateLessonHold(draftId, options = {}) {
|
|
31634
|
+
const outbox = await readyOutbox(options);
|
|
31635
|
+
return withPrivateLessonOutboxLock(outbox.directory, async () => {
|
|
31636
|
+
const draft = await readPrivateLessonDraft(draftId, {
|
|
31637
|
+
...options,
|
|
31638
|
+
outboxDirectory: outbox.directory,
|
|
31639
|
+
encryption: outbox.encryption
|
|
31640
|
+
});
|
|
31641
|
+
if (draft.state !== "held_safety") return draft;
|
|
31642
|
+
if (!privateLessonSafetyRecheck(draft)) {
|
|
31643
|
+
throw new PrivateLessonHoldReleaseRefusedError(
|
|
31644
|
+
draftId,
|
|
31645
|
+
privateLessonCurrentHoldReasons(draft.candidate, draft.held_reasons)
|
|
31646
|
+
);
|
|
31647
|
+
}
|
|
31648
|
+
const now = (options.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
31649
|
+
const released = validateDraft({
|
|
31650
|
+
...draft,
|
|
31651
|
+
state: "retry_scheduled",
|
|
31652
|
+
redactor_digest: privateLessonRedactorDigest(),
|
|
31653
|
+
held_reasons: [],
|
|
31654
|
+
// A policy binding is valid only for its own redactor profile.
|
|
31655
|
+
policy: null,
|
|
31656
|
+
next_retry_at: now,
|
|
31657
|
+
last_error_code: null,
|
|
31658
|
+
hold_telemetry_status: "not_required",
|
|
31659
|
+
hold_event_digest: null,
|
|
31660
|
+
hold_receipt_digest: null,
|
|
31661
|
+
hold_reported_at: null,
|
|
31662
|
+
updated_at: now
|
|
31663
|
+
});
|
|
31664
|
+
await writeDraftUnlocked(released, outbox, true);
|
|
31665
|
+
return released;
|
|
31666
|
+
});
|
|
31667
|
+
}
|
|
31198
31668
|
async function queuePreparedPrivateLesson(prepared, policy, options = {}) {
|
|
31199
|
-
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
31200
31669
|
const outbox = await readyOutbox(options);
|
|
31201
|
-
const
|
|
31670
|
+
const draft = newPrivateLessonDraft(
|
|
31671
|
+
prepared,
|
|
31672
|
+
createPublicId("pld"),
|
|
31673
|
+
policy,
|
|
31674
|
+
options.destination ?? null,
|
|
31675
|
+
options.now ?? /* @__PURE__ */ new Date()
|
|
31676
|
+
);
|
|
31677
|
+
await writeDraft(draft, outbox, false);
|
|
31678
|
+
return draft;
|
|
31679
|
+
}
|
|
31680
|
+
function newPrivateLessonDraft(prepared, draftId, policy, destination, now) {
|
|
31202
31681
|
const createdAt = now.toISOString();
|
|
31203
31682
|
const state = prepared.status === "held_safety" ? "held_safety" : policy ? "ready" : "awaiting_authorization";
|
|
31204
|
-
|
|
31683
|
+
return {
|
|
31205
31684
|
version: PRIVATE_LESSON_OUTBOX_VERSION,
|
|
31206
31685
|
draft_id: draftId,
|
|
31207
31686
|
state,
|
|
@@ -31212,7 +31691,7 @@ async function queuePreparedPrivateLesson(prepared, policy, options = {}) {
|
|
|
31212
31691
|
redactor_digest: prepared.redactor_digest,
|
|
31213
31692
|
held_reasons: prepared.held_reasons,
|
|
31214
31693
|
policy,
|
|
31215
|
-
destination_binding:
|
|
31694
|
+
destination_binding: destination ? parsePrivateLessonDestination(destination) : null,
|
|
31216
31695
|
idempotency_key: `private-lesson-${hashValue(
|
|
31217
31696
|
canonicalJson({
|
|
31218
31697
|
draft_id: draftId,
|
|
@@ -31232,8 +31711,196 @@ async function queuePreparedPrivateLesson(prepared, policy, options = {}) {
|
|
|
31232
31711
|
hold_receipt_digest: null,
|
|
31233
31712
|
hold_reported_at: null
|
|
31234
31713
|
};
|
|
31235
|
-
|
|
31236
|
-
|
|
31714
|
+
}
|
|
31715
|
+
var PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS = 3;
|
|
31716
|
+
var PRIVATE_LESSON_REPLACEMENT_REFUSALS = {
|
|
31717
|
+
unknown: "No retained private lesson draft has this draft_id, so nothing can be replaced. Capture the lesson without replacement_of.",
|
|
31718
|
+
deleted: "This private lesson draft was deleted, so nothing can be replaced. Capture the lesson without replacement_of.",
|
|
31719
|
+
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.",
|
|
31720
|
+
replaced: "This held private lesson draft was already replaced.",
|
|
31721
|
+
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.",
|
|
31722
|
+
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.",
|
|
31723
|
+
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.",
|
|
31724
|
+
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.",
|
|
31725
|
+
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.`,
|
|
31726
|
+
replacement_deleted: "This exact replacement was deleted. Capture a different version, or keep or delete the held draft.",
|
|
31727
|
+
replacement_held: "The local safety check holds this replacement too, so it was not stored. Write a version without what the findings name."
|
|
31728
|
+
};
|
|
31729
|
+
var PrivateLessonReplacementRefusedError = class extends Error {
|
|
31730
|
+
constructor(draftId, reason, attemptsRemaining, replacementDraftId) {
|
|
31731
|
+
super(
|
|
31732
|
+
`${PRIVATE_LESSON_REPLACEMENT_REFUSALS[reason]} Nothing was stored or sent.`
|
|
31733
|
+
);
|
|
31734
|
+
this.draftId = draftId;
|
|
31735
|
+
this.reason = reason;
|
|
31736
|
+
this.attemptsRemaining = attemptsRemaining;
|
|
31737
|
+
this.replacementDraftId = replacementDraftId;
|
|
31738
|
+
this.name = "PrivateLessonReplacementRefusedError";
|
|
31739
|
+
}
|
|
31740
|
+
draftId;
|
|
31741
|
+
reason;
|
|
31742
|
+
attemptsRemaining;
|
|
31743
|
+
replacementDraftId;
|
|
31744
|
+
diagnostic() {
|
|
31745
|
+
return {
|
|
31746
|
+
code: "private_lesson_replacement_refused",
|
|
31747
|
+
reason_code: this.reason,
|
|
31748
|
+
replacement_of: this.draftId,
|
|
31749
|
+
...this.replacementDraftId ? { replacement_draft_id: this.replacementDraftId } : {},
|
|
31750
|
+
attempts_remaining: this.attemptsRemaining,
|
|
31751
|
+
candidate_stored: false,
|
|
31752
|
+
candidate_sent: false
|
|
31753
|
+
};
|
|
31754
|
+
}
|
|
31755
|
+
};
|
|
31756
|
+
async function queuePrivateLessonReplacement(replacementOf, prepared, options = {}) {
|
|
31757
|
+
assertDraftId(replacementOf);
|
|
31758
|
+
const outbox = await readyOutbox(options);
|
|
31759
|
+
const directory = outbox.directory;
|
|
31760
|
+
return withPrivateLessonOutboxLock(directory, async () => {
|
|
31761
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
31762
|
+
const read2 = { ...options, outboxDirectory: directory };
|
|
31763
|
+
const refuse = (reason, used2 = 0, replacementDraftId) => new PrivateLessonReplacementRefusedError(
|
|
31764
|
+
replacementOf,
|
|
31765
|
+
reason,
|
|
31766
|
+
Math.max(0, PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - used2),
|
|
31767
|
+
replacementDraftId
|
|
31768
|
+
);
|
|
31769
|
+
await reconcileSubmittedRecordsUnlocked(directory, now);
|
|
31770
|
+
if (existsSync2(tombstonePath(directory, replacementOf))) {
|
|
31771
|
+
throw refuse("deleted");
|
|
31772
|
+
}
|
|
31773
|
+
let original;
|
|
31774
|
+
try {
|
|
31775
|
+
original = await readPrivateLessonDraft(replacementOf, {
|
|
31776
|
+
...read2,
|
|
31777
|
+
encryption: outbox.encryption
|
|
31778
|
+
});
|
|
31779
|
+
} catch (error) {
|
|
31780
|
+
if (error instanceof PrivateLessonDraftUnavailableError) {
|
|
31781
|
+
if (error.reason === "replaced") {
|
|
31782
|
+
throw refuse(
|
|
31783
|
+
"replaced",
|
|
31784
|
+
PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS,
|
|
31785
|
+
error.replacementDraftId
|
|
31786
|
+
);
|
|
31787
|
+
}
|
|
31788
|
+
if (error.reason === "unknown") throw refuse("unknown");
|
|
31789
|
+
}
|
|
31790
|
+
if (existsSync2(submittedRecordPath(directory, replacementOf))) {
|
|
31791
|
+
throw refuse("submitted");
|
|
31792
|
+
}
|
|
31793
|
+
throw error;
|
|
31794
|
+
}
|
|
31795
|
+
if (original.state === "submitted") throw refuse("submitted");
|
|
31796
|
+
if (original.held_reasons.length === 0 || original.state === "superseded_redactor" || original.replacement_of !== void 0) {
|
|
31797
|
+
throw refuse("not_held");
|
|
31798
|
+
}
|
|
31799
|
+
if (privateLessonSafetyRecheck(original)) throw refuse("releasable");
|
|
31800
|
+
const attempts = original.replacement_attempts ?? [];
|
|
31801
|
+
const digest2 = prepared.payload_digest;
|
|
31802
|
+
const draftId = privateLessonReplacementDraftId(replacementOf, digest2);
|
|
31803
|
+
const replay = attempts.includes(digest2);
|
|
31804
|
+
const used = replay ? attempts.length : attempts.length + 1;
|
|
31805
|
+
if (!replay && privateLessonCapturedForOtherDestination(original, options.destination)) {
|
|
31806
|
+
throw refuse("destination_changed", attempts.length);
|
|
31807
|
+
}
|
|
31808
|
+
const pending = attempts.map((attempt) => privateLessonReplacementDraftId(replacementOf, attempt)).find(
|
|
31809
|
+
(candidate) => candidate !== draftId && existsSync2(draftPath(directory, candidate))
|
|
31810
|
+
);
|
|
31811
|
+
if (pending) throw refuse("replacement_pending", attempts.length, pending);
|
|
31812
|
+
if (!replay) {
|
|
31813
|
+
if (attempts.length >= PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS) {
|
|
31814
|
+
throw refuse("attempts_exhausted", attempts.length);
|
|
31815
|
+
}
|
|
31816
|
+
await writeDraftUnlocked(
|
|
31817
|
+
validateDraft({
|
|
31818
|
+
...original,
|
|
31819
|
+
replacement_attempts: [...attempts, digest2],
|
|
31820
|
+
updated_at: now.toISOString()
|
|
31821
|
+
}),
|
|
31822
|
+
outbox,
|
|
31823
|
+
true
|
|
31824
|
+
);
|
|
31825
|
+
}
|
|
31826
|
+
if (prepared.status === "held_safety") {
|
|
31827
|
+
throw refuse("replacement_held", used);
|
|
31828
|
+
}
|
|
31829
|
+
if (existsSync2(tombstonePath(directory, draftId))) {
|
|
31830
|
+
throw refuse("replacement_deleted", used, draftId);
|
|
31831
|
+
}
|
|
31832
|
+
if (existsSync2(draftPath(directory, draftId))) {
|
|
31833
|
+
return {
|
|
31834
|
+
draft: await readPrivateLessonDraft(draftId, {
|
|
31835
|
+
...read2,
|
|
31836
|
+
encryption: outbox.encryption
|
|
31837
|
+
}),
|
|
31838
|
+
attempts_remaining: PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - used,
|
|
31839
|
+
replayed: true
|
|
31840
|
+
};
|
|
31841
|
+
}
|
|
31842
|
+
const draft = {
|
|
31843
|
+
...newPrivateLessonDraft(
|
|
31844
|
+
prepared,
|
|
31845
|
+
draftId,
|
|
31846
|
+
null,
|
|
31847
|
+
original.destination_binding ?? options.destination ?? null,
|
|
31848
|
+
now
|
|
31849
|
+
),
|
|
31850
|
+
...original.attested_organization_audience_hash !== void 0 ? {
|
|
31851
|
+
attested_organization_audience_hash: original.attested_organization_audience_hash
|
|
31852
|
+
} : {},
|
|
31853
|
+
replacement_of: replacementOf
|
|
31854
|
+
};
|
|
31855
|
+
await writeDraftUnlocked(validateDraft(draft), outbox, false);
|
|
31856
|
+
return {
|
|
31857
|
+
draft,
|
|
31858
|
+
attempts_remaining: PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - used,
|
|
31859
|
+
replayed: replay
|
|
31860
|
+
};
|
|
31861
|
+
});
|
|
31862
|
+
}
|
|
31863
|
+
async function retireReplacedPrivateLessonUnlocked(directory, draftId, replacementDraftId, at) {
|
|
31864
|
+
const path = draftPath(directory, draftId);
|
|
31865
|
+
if (existsSync2(tombstonePath(directory, draftId)) || existsSync2(submittedRecordPath(directory, draftId)) || !existsSync2(path)) {
|
|
31866
|
+
return;
|
|
31867
|
+
}
|
|
31868
|
+
try {
|
|
31869
|
+
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
31870
|
+
const envelope = parseEnvelope(
|
|
31871
|
+
await readBoundedFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES),
|
|
31872
|
+
draftId
|
|
31873
|
+
);
|
|
31874
|
+
if (envelope.state === "submitted") return;
|
|
31875
|
+
} catch {
|
|
31876
|
+
return;
|
|
31877
|
+
}
|
|
31878
|
+
const record4 = {
|
|
31879
|
+
version: "private-lesson-outbox-deletion-v1",
|
|
31880
|
+
draft_id: draftId,
|
|
31881
|
+
deleted_at: at.toISOString(),
|
|
31882
|
+
reason: "replaced_by_verified_replacement",
|
|
31883
|
+
replacement_draft_id: replacementDraftId,
|
|
31884
|
+
expires_at: new Date(
|
|
31885
|
+
at.getTime() + PRIVATE_LESSON_SUBMITTED_RECORD_RETENTION_MS
|
|
31886
|
+
).toISOString()
|
|
31887
|
+
};
|
|
31888
|
+
await atomicCreatePrivateLessonEntry(
|
|
31889
|
+
replacedRecordPath(directory, draftId),
|
|
31890
|
+
`${JSON.stringify(record4)}
|
|
31891
|
+
`,
|
|
31892
|
+
".replaced.tmp"
|
|
31893
|
+
);
|
|
31894
|
+
await unlink2(path).catch(() => {
|
|
31895
|
+
});
|
|
31896
|
+
await syncDirectory2(directory).catch(() => {
|
|
31897
|
+
});
|
|
31898
|
+
}
|
|
31899
|
+
function acceptedPrivateLessonReplacement(directory, draft) {
|
|
31900
|
+
if (draft.state === "submitted") return void 0;
|
|
31901
|
+
return (draft.replacement_attempts ?? []).map((digest2) => privateLessonReplacementDraftId(draft.draft_id, digest2)).find(
|
|
31902
|
+
(replacement) => existsSync2(submittedRecordPath(directory, replacement))
|
|
31903
|
+
);
|
|
31237
31904
|
}
|
|
31238
31905
|
async function readPrivateLessonDraft(draftId, options = {}) {
|
|
31239
31906
|
assertDraftId(draftId);
|
|
@@ -31246,10 +31913,12 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
31246
31913
|
if (existsSync2(tombstonePath(outbox.directory, draftId))) {
|
|
31247
31914
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31248
31915
|
}
|
|
31916
|
+
await assertNotReplacedUnlocked(outbox.directory, draftId);
|
|
31249
31917
|
if (existsSync2(submittedRecordPath(outbox.directory, draftId))) {
|
|
31250
31918
|
throw new Error("Private lesson draft was already submitted.");
|
|
31251
31919
|
}
|
|
31252
31920
|
let draft;
|
|
31921
|
+
let envelope;
|
|
31253
31922
|
try {
|
|
31254
31923
|
const path = draftPath(outbox.directory, draftId);
|
|
31255
31924
|
await assertRegularPrivateFile(path, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
@@ -31257,20 +31926,32 @@ async function readPrivateLessonDraft(draftId, options = {}) {
|
|
|
31257
31926
|
path,
|
|
31258
31927
|
PRIVATE_LESSON_DRAFT_MAX_BYTES
|
|
31259
31928
|
);
|
|
31260
|
-
|
|
31929
|
+
envelope = parseEnvelope(serialized, draftId);
|
|
31261
31930
|
draft = await decryptDraft(envelope, outbox.encryption, true);
|
|
31262
31931
|
} catch (error) {
|
|
31263
31932
|
throw selectedPrivateLessonError(draftId, error);
|
|
31264
31933
|
}
|
|
31265
|
-
const
|
|
31266
|
-
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
const reconciled = normalizeLegacyHeldSafetyDraft(
|
|
31270
|
-
profileReconciled,
|
|
31271
|
-
options.now ?? /* @__PURE__ */ new Date()
|
|
31934
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
31935
|
+
const replacement = acceptedPrivateLessonReplacement(
|
|
31936
|
+
outbox.directory,
|
|
31937
|
+
draft
|
|
31272
31938
|
);
|
|
31273
|
-
if (
|
|
31939
|
+
if (replacement) {
|
|
31940
|
+
await retireReplacedPrivateLessonUnlocked(
|
|
31941
|
+
outbox.directory,
|
|
31942
|
+
draftId,
|
|
31943
|
+
replacement,
|
|
31944
|
+
now
|
|
31945
|
+
).catch(() => {
|
|
31946
|
+
});
|
|
31947
|
+
throw new PrivateLessonDraftUnavailableError(
|
|
31948
|
+
draftId,
|
|
31949
|
+
"replaced",
|
|
31950
|
+
replacement
|
|
31951
|
+
);
|
|
31952
|
+
}
|
|
31953
|
+
const reconciled = reconcileStoredDraft(draft, now);
|
|
31954
|
+
if (reconciled !== draft || staleSafetyRecheckHint(envelope, reconciled)) {
|
|
31274
31955
|
await writeDraft(reconciled, outbox, true, void 0, true);
|
|
31275
31956
|
}
|
|
31276
31957
|
return reconciled;
|
|
@@ -31289,6 +31970,7 @@ async function readPrivateLessonSubmittedRecord(draftId, options = {}) {
|
|
|
31289
31970
|
if (existsSync2(tombstonePath(directory, draftId))) {
|
|
31290
31971
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31291
31972
|
}
|
|
31973
|
+
await assertNotReplacedUnlocked(directory, draftId);
|
|
31292
31974
|
const path = submittedRecordPath(directory, draftId);
|
|
31293
31975
|
if (!existsSync2(path)) return null;
|
|
31294
31976
|
await assertRegularPrivateFile(
|
|
@@ -31312,6 +31994,7 @@ async function readPrivateLessonSubmissionSource(draftId, options = {}) {
|
|
|
31312
31994
|
if (existsSync2(tombstonePath(outbox.directory, draftId))) {
|
|
31313
31995
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31314
31996
|
}
|
|
31997
|
+
await assertNotReplacedUnlocked(outbox.directory, draftId);
|
|
31315
31998
|
const completionPath = submittedRecordPath(outbox.directory, draftId);
|
|
31316
31999
|
if (existsSync2(completionPath)) {
|
|
31317
32000
|
await assertRegularPrivateFile(
|
|
@@ -31344,7 +32027,7 @@ async function readPrivateLessonSubmissionSource(draftId, options = {}) {
|
|
|
31344
32027
|
return { kind: "draft", draft };
|
|
31345
32028
|
});
|
|
31346
32029
|
}
|
|
31347
|
-
async function reconcilePrivateLessonOutboxProfiles(options = {}) {
|
|
32030
|
+
async function reconcilePrivateLessonOutboxProfiles(options = {}, replaced) {
|
|
31348
32031
|
const outbox = await readyOutbox(options, false);
|
|
31349
32032
|
return withPrivateLessonOutboxLock(outbox.directory, async () => {
|
|
31350
32033
|
await reconcilePrivateLessonTemporaryWrites(
|
|
@@ -31378,7 +32061,10 @@ async function reconcilePrivateLessonOutboxProfiles(options = {}) {
|
|
|
31378
32061
|
outboxDirectory: outbox.directory,
|
|
31379
32062
|
encryption: outbox.encryption
|
|
31380
32063
|
});
|
|
31381
|
-
} catch {
|
|
32064
|
+
} catch (error) {
|
|
32065
|
+
if (error instanceof PrivateLessonDraftUnavailableError && error.reason === "replaced") {
|
|
32066
|
+
replaced?.add(draftId);
|
|
32067
|
+
}
|
|
31382
32068
|
continue;
|
|
31383
32069
|
}
|
|
31384
32070
|
inspected += 1;
|
|
@@ -31411,7 +32097,7 @@ async function updatePrivateLessonDraft(draftId, update, options = {}) {
|
|
|
31411
32097
|
throw new PrivateLessonDraftUnavailableError(draftId, "corrupt");
|
|
31412
32098
|
}
|
|
31413
32099
|
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) {
|
|
32100
|
+
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
32101
|
throw new Error("Private lesson draft content is immutable.");
|
|
31416
32102
|
}
|
|
31417
32103
|
next.updated_at = (options.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
@@ -31430,6 +32116,7 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
31430
32116
|
if (existsSync2(tombstonePath(outbox.directory, draftId))) {
|
|
31431
32117
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31432
32118
|
}
|
|
32119
|
+
await assertNotReplacedUnlocked(outbox.directory, draftId);
|
|
31433
32120
|
const existingPath = submittedRecordPath(outbox.directory, draftId);
|
|
31434
32121
|
if (existsSync2(existingPath)) {
|
|
31435
32122
|
let completion2;
|
|
@@ -31461,6 +32148,7 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
31461
32148
|
} catch (error) {
|
|
31462
32149
|
throw selectedPrivateLessonError(draftId, error);
|
|
31463
32150
|
}
|
|
32151
|
+
current = reconcileStoredDraft(current, options.now ?? /* @__PURE__ */ new Date());
|
|
31464
32152
|
if (current.state === "superseded_redactor") {
|
|
31465
32153
|
throw new Error("Terminal private lesson drafts cannot be submitted.");
|
|
31466
32154
|
}
|
|
@@ -31492,6 +32180,15 @@ async function completePrivateLessonSubmission(draftId, input, options = {}) {
|
|
|
31492
32180
|
});
|
|
31493
32181
|
await syncDirectory2(outbox.directory).catch(() => {
|
|
31494
32182
|
});
|
|
32183
|
+
if (draft.replacement_of) {
|
|
32184
|
+
await retireReplacedPrivateLessonUnlocked(
|
|
32185
|
+
outbox.directory,
|
|
32186
|
+
draft.replacement_of,
|
|
32187
|
+
draftId,
|
|
32188
|
+
submittedAt
|
|
32189
|
+
).catch(() => {
|
|
32190
|
+
});
|
|
32191
|
+
}
|
|
31495
32192
|
return completion;
|
|
31496
32193
|
});
|
|
31497
32194
|
}
|
|
@@ -31507,19 +32204,21 @@ async function deletePrivateLessonDraft(draftId, confirmed, options = {}) {
|
|
|
31507
32204
|
const path = draftPath(outbox.directory, draftId);
|
|
31508
32205
|
const completionPath = submittedRecordPath(outbox.directory, draftId);
|
|
31509
32206
|
const deletionPath = tombstonePath(outbox.directory, draftId);
|
|
32207
|
+
const replacedPath = replacedRecordPath(outbox.directory, draftId);
|
|
31510
32208
|
const quarantined = await privateLessonQuarantineEntriesForDraft(
|
|
31511
32209
|
outbox.directory,
|
|
31512
32210
|
draftId
|
|
31513
32211
|
);
|
|
31514
|
-
if (existsSync2(deletionPath) && !existsSync2(path) && !existsSync2(completionPath) && quarantined.length === 0) {
|
|
32212
|
+
if (existsSync2(deletionPath) && !existsSync2(path) && !existsSync2(completionPath) && !existsSync2(replacedPath) && quarantined.length === 0) {
|
|
31515
32213
|
throw new PrivateLessonDraftUnavailableError(draftId, "deleted");
|
|
31516
32214
|
}
|
|
31517
|
-
if (!existsSync2(path) && !existsSync2(completionPath) && !existsSync2(deletionPath) && quarantined.length === 0) {
|
|
32215
|
+
if (!existsSync2(path) && !existsSync2(completionPath) && !existsSync2(deletionPath) && !existsSync2(replacedPath) && quarantined.length === 0) {
|
|
31518
32216
|
throw new PrivateLessonDraftUnavailableError(draftId, "unknown");
|
|
31519
32217
|
}
|
|
31520
32218
|
await removeCanonicalPrivateLessonEntry(path);
|
|
31521
32219
|
await removeCanonicalPrivateLessonEntry(completionPath);
|
|
31522
32220
|
await removeCanonicalPrivateLessonEntry(deletionPath);
|
|
32221
|
+
await removeCanonicalPrivateLessonEntry(replacedPath);
|
|
31523
32222
|
for (const entry of quarantined) {
|
|
31524
32223
|
await removeCanonicalPrivateLessonEntry(entry);
|
|
31525
32224
|
}
|
|
@@ -31540,11 +32239,15 @@ async function deletePrivateLessonDraft(draftId, confirmed, options = {}) {
|
|
|
31540
32239
|
}
|
|
31541
32240
|
async function privateLessonOutboxSummary(options = {}) {
|
|
31542
32241
|
const outbox = await readyOutbox(options, false);
|
|
31543
|
-
|
|
31544
|
-
|
|
31545
|
-
|
|
31546
|
-
|
|
31547
|
-
|
|
32242
|
+
const replaced = /* @__PURE__ */ new Set();
|
|
32243
|
+
await reconcilePrivateLessonOutboxProfiles(
|
|
32244
|
+
{
|
|
32245
|
+
...options,
|
|
32246
|
+
outboxDirectory: outbox.directory,
|
|
32247
|
+
encryption: outbox.encryption
|
|
32248
|
+
},
|
|
32249
|
+
replaced
|
|
32250
|
+
);
|
|
31548
32251
|
const entries = await secureOutboxEntries(outbox.directory);
|
|
31549
32252
|
const counts = {
|
|
31550
32253
|
ready: 0,
|
|
@@ -31559,6 +32262,7 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31559
32262
|
};
|
|
31560
32263
|
let totalBytes = 0;
|
|
31561
32264
|
let deletionTombstones = 0;
|
|
32265
|
+
let replacedRecords = 0;
|
|
31562
32266
|
let terminalBytes = 0;
|
|
31563
32267
|
const terminalReasons = {};
|
|
31564
32268
|
let corruptFiles = 0;
|
|
@@ -31569,6 +32273,10 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31569
32273
|
deletionTombstones += 1;
|
|
31570
32274
|
continue;
|
|
31571
32275
|
}
|
|
32276
|
+
if (name.endsWith(".replaced.json")) {
|
|
32277
|
+
replacedRecords += 1;
|
|
32278
|
+
continue;
|
|
32279
|
+
}
|
|
31572
32280
|
if (name.endsWith(".submitted.json")) {
|
|
31573
32281
|
const draftId = name.slice(0, -".submitted.json".length);
|
|
31574
32282
|
try {
|
|
@@ -31586,6 +32294,10 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31586
32294
|
continue;
|
|
31587
32295
|
}
|
|
31588
32296
|
if (!name.endsWith(".lesson.json")) continue;
|
|
32297
|
+
if (replaced.has(name.slice(0, -".lesson.json".length))) {
|
|
32298
|
+
replacedRecords += 1;
|
|
32299
|
+
continue;
|
|
32300
|
+
}
|
|
31589
32301
|
let envelope;
|
|
31590
32302
|
try {
|
|
31591
32303
|
envelope = parseEnvelope(
|
|
@@ -31642,6 +32354,7 @@ async function privateLessonOutboxSummary(options = {}) {
|
|
|
31642
32354
|
terminal_reasons: terminalReasons,
|
|
31643
32355
|
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
32356
|
deletion_tombstones: deletionTombstones,
|
|
32357
|
+
replaced_records: replacedRecords,
|
|
31645
32358
|
temporary_files: retainedArtifacts.temporaryFiles,
|
|
31646
32359
|
corrupt_files: Math.max(
|
|
31647
32360
|
corruptFiles,
|
|
@@ -31671,13 +32384,14 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31671
32384
|
const recoveryItems = [];
|
|
31672
32385
|
const terminalReasons = {};
|
|
31673
32386
|
let deletionTombstones = 0;
|
|
32387
|
+
let replacedRecords = 0;
|
|
31674
32388
|
let terminalBytes = 0;
|
|
31675
32389
|
let corruptFiles = 0;
|
|
31676
32390
|
for (const entry of await readdir(outbox.directory, {
|
|
31677
32391
|
withFileTypes: true
|
|
31678
32392
|
})) {
|
|
31679
32393
|
const match = entry.name.match(
|
|
31680
|
-
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted)\.json$/u
|
|
32394
|
+
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted|replaced)\.json$/u
|
|
31681
32395
|
);
|
|
31682
32396
|
if (!match) continue;
|
|
31683
32397
|
const draftId = match[1];
|
|
@@ -31689,6 +32403,25 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31689
32403
|
continue;
|
|
31690
32404
|
}
|
|
31691
32405
|
const path = join3(outbox.directory, entry.name);
|
|
32406
|
+
if (entry.name.endsWith(".replaced.json")) {
|
|
32407
|
+
replacedRecords += 1;
|
|
32408
|
+
try {
|
|
32409
|
+
parseReplacedRecord(
|
|
32410
|
+
await readPrivateLessonCanonicalText(
|
|
32411
|
+
path,
|
|
32412
|
+
PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES
|
|
32413
|
+
),
|
|
32414
|
+
draftId
|
|
32415
|
+
);
|
|
32416
|
+
} catch (error) {
|
|
32417
|
+
if (error instanceof PrivateOutboxStorageError) throw error;
|
|
32418
|
+
recoveryItems.push(
|
|
32419
|
+
privateLessonRecoveryItem(draftId, "invalid_canonical_entry")
|
|
32420
|
+
);
|
|
32421
|
+
corruptFiles += 1;
|
|
32422
|
+
}
|
|
32423
|
+
continue;
|
|
32424
|
+
}
|
|
31692
32425
|
if (entry.name.endsWith(".deleted.json")) {
|
|
31693
32426
|
let serialized2;
|
|
31694
32427
|
deletionTombstones += 1;
|
|
@@ -31787,9 +32520,24 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31787
32520
|
corruptFiles += 1;
|
|
31788
32521
|
continue;
|
|
31789
32522
|
}
|
|
31790
|
-
const
|
|
31791
|
-
|
|
31792
|
-
|
|
32523
|
+
const replacement = acceptedPrivateLessonReplacement(
|
|
32524
|
+
outbox.directory,
|
|
32525
|
+
decrypted
|
|
32526
|
+
);
|
|
32527
|
+
if (replacement) {
|
|
32528
|
+
counts[envelope.state] -= 1;
|
|
32529
|
+
replacedRecords += 1;
|
|
32530
|
+
await retireReplacedPrivateLessonUnlocked(
|
|
32531
|
+
outbox.directory,
|
|
32532
|
+
draftId,
|
|
32533
|
+
replacement,
|
|
32534
|
+
now
|
|
32535
|
+
).catch(() => {
|
|
32536
|
+
});
|
|
32537
|
+
continue;
|
|
32538
|
+
}
|
|
32539
|
+
const draft = reconcileStoredDraft(decrypted, now);
|
|
32540
|
+
if (draft !== decrypted || staleSafetyRecheckHint(envelope, draft)) {
|
|
31793
32541
|
counts[envelope.state] -= 1;
|
|
31794
32542
|
counts[draft.state] += 1;
|
|
31795
32543
|
await writeDraftUnlocked(draft, outbox, true, void 0, true);
|
|
@@ -31863,6 +32611,7 @@ async function inspectPrivateLessonOutboxSnapshotUnlocked(outbox, options) {
|
|
|
31863
32611
|
terminal_reasons: terminalReasons,
|
|
31864
32612
|
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
32613
|
deletion_tombstones: deletionTombstones,
|
|
32614
|
+
replaced_records: replacedRecords,
|
|
31866
32615
|
temporary_files: retainedArtifacts.temporaryFiles,
|
|
31867
32616
|
corrupt_files: Math.max(
|
|
31868
32617
|
corruptFiles,
|
|
@@ -31932,6 +32681,7 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
31932
32681
|
terminal_reasons: {},
|
|
31933
32682
|
deletion_guidance: null,
|
|
31934
32683
|
deletion_tombstones: 0,
|
|
32684
|
+
replaced_records: 0,
|
|
31935
32685
|
temporary_files: 0,
|
|
31936
32686
|
corrupt_files: 0,
|
|
31937
32687
|
quarantined_bytes: 0,
|
|
@@ -31970,6 +32720,7 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
31970
32720
|
const counts = emptyOutboxCounts();
|
|
31971
32721
|
let totalBytes = 0;
|
|
31972
32722
|
let deletionTombstones = 0;
|
|
32723
|
+
let replacedRecords = 0;
|
|
31973
32724
|
let terminalBytes = 0;
|
|
31974
32725
|
let corruptFiles = 0;
|
|
31975
32726
|
const terminalReasons = {};
|
|
@@ -31981,6 +32732,10 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
31981
32732
|
deletionTombstones += 1;
|
|
31982
32733
|
continue;
|
|
31983
32734
|
}
|
|
32735
|
+
if (name.endsWith(".replaced.json")) {
|
|
32736
|
+
replacedRecords += 1;
|
|
32737
|
+
continue;
|
|
32738
|
+
}
|
|
31984
32739
|
if (name.endsWith(".submitted.json")) {
|
|
31985
32740
|
const draftId = name.slice(0, -".submitted.json".length);
|
|
31986
32741
|
try {
|
|
@@ -32037,6 +32792,7 @@ async function inspectPrivateLessonOutboxHealth(options = {}) {
|
|
|
32037
32792
|
terminal_reasons: terminalReasons,
|
|
32038
32793
|
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
32794
|
deletion_tombstones: deletionTombstones,
|
|
32795
|
+
replaced_records: replacedRecords,
|
|
32040
32796
|
temporary_files: retainedArtifacts.temporaryFiles,
|
|
32041
32797
|
corrupt_files: corruptFiles,
|
|
32042
32798
|
quarantined_bytes: retainedArtifacts.quarantinedBytes,
|
|
@@ -32461,6 +33217,7 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
32461
33217
|
created_at: validated.created_at,
|
|
32462
33218
|
updated_at: validated.updated_at,
|
|
32463
33219
|
destination_binding: validated.destination_binding,
|
|
33220
|
+
...safetyRecheckField(validated),
|
|
32464
33221
|
encryption: {
|
|
32465
33222
|
algorithm: "aes-256-gcm",
|
|
32466
33223
|
key_source: outbox.encryption.source,
|
|
@@ -32488,7 +33245,7 @@ async function writeDraftUnlocked(draft, outbox, replace, _currentOutboxBytes, a
|
|
|
32488
33245
|
if (replace) {
|
|
32489
33246
|
await atomicReplacePrivate(path, serialized);
|
|
32490
33247
|
} else {
|
|
32491
|
-
await
|
|
33248
|
+
await atomicCreatePrivateLessonEntry(path, serialized);
|
|
32492
33249
|
}
|
|
32493
33250
|
}
|
|
32494
33251
|
async function decryptDraft(envelope, encryption, allowUnsupportedProfile = false) {
|
|
@@ -32603,19 +33360,37 @@ function validateDraft(value, allowUnsupportedProfile = false) {
|
|
|
32603
33360
|
);
|
|
32604
33361
|
}
|
|
32605
33362
|
}
|
|
33363
|
+
if (value.attested_organization_audience_hash !== void 0 && !isSha256Digest(value.attested_organization_audience_hash)) {
|
|
33364
|
+
throw new Error("Private lesson draft attested audience is invalid.");
|
|
33365
|
+
}
|
|
33366
|
+
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)) {
|
|
33367
|
+
throw new Error("Private lesson draft replacement link is invalid.");
|
|
33368
|
+
}
|
|
33369
|
+
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)) {
|
|
33370
|
+
throw new Error("Private lesson draft replacement attempts are invalid.");
|
|
33371
|
+
}
|
|
32606
33372
|
const destinationBinding = value.destination_binding === void 0 ? null : value.destination_binding === null ? null : parsePrivateLessonDestination(value.destination_binding);
|
|
32607
33373
|
return {
|
|
32608
33374
|
...value,
|
|
32609
33375
|
destination_binding: destinationBinding
|
|
32610
33376
|
};
|
|
32611
33377
|
}
|
|
32612
|
-
function
|
|
33378
|
+
function staleSafetyRecheckHint(envelope, draft) {
|
|
33379
|
+
return (envelope.safety_recheck ?? null) !== privateLessonSafetyRecheck(draft);
|
|
33380
|
+
}
|
|
33381
|
+
function reconcileStoredDraft(draft, now) {
|
|
33382
|
+
return normalizeLegacyHeldSafetyDraft(
|
|
33383
|
+
reconcileRedactorProfile(draft, now),
|
|
33384
|
+
now
|
|
33385
|
+
);
|
|
33386
|
+
}
|
|
33387
|
+
function reconcileRedactorProfile(draft, now) {
|
|
32613
33388
|
try {
|
|
32614
33389
|
privateLessonRedactorProfile(
|
|
32615
33390
|
draft.redaction_version,
|
|
32616
33391
|
draft.redactor_digest
|
|
32617
33392
|
);
|
|
32618
|
-
return draft;
|
|
33393
|
+
return resumeDraftRetiredByOlderClient(draft, now);
|
|
32619
33394
|
} catch (error) {
|
|
32620
33395
|
if (!(error instanceof PrivateLessonRedactionProfileError)) throw error;
|
|
32621
33396
|
if (draft.state === "superseded_redactor" && draft.terminal_reason === error.code || // Accepted work is not a draft awaiting a current redactor. Keep a
|
|
@@ -32634,6 +33409,18 @@ function terminalizeUnsupportedProfile(draft, now) {
|
|
|
32634
33409
|
};
|
|
32635
33410
|
}
|
|
32636
33411
|
}
|
|
33412
|
+
function resumeDraftRetiredByOlderClient(draft, now) {
|
|
33413
|
+
if (draft.state !== "superseded_redactor") return draft;
|
|
33414
|
+
const held = draft.held_reasons.length > 0;
|
|
33415
|
+
return validateDraft({
|
|
33416
|
+
...draft,
|
|
33417
|
+
state: held ? "held_safety" : "retry_scheduled",
|
|
33418
|
+
terminal_reason: null,
|
|
33419
|
+
next_retry_at: held ? null : now.toISOString(),
|
|
33420
|
+
hold_telemetry_status: !held ? "not_required" : draft.hold_telemetry_status === "submitted" ? "submitted" : "pending",
|
|
33421
|
+
updated_at: now.toISOString()
|
|
33422
|
+
});
|
|
33423
|
+
}
|
|
32637
33424
|
function normalizeLegacyHeldSafetyDraft(draft, now) {
|
|
32638
33425
|
if (draft.state !== "held_safety" || draft.held_reasons.length > 0) {
|
|
32639
33426
|
return draft;
|
|
@@ -32750,6 +33537,9 @@ async function reconcileSubmittedRecordsUnlocked(directory, now) {
|
|
|
32750
33537
|
changed = true;
|
|
32751
33538
|
}
|
|
32752
33539
|
}
|
|
33540
|
+
if (await reconcileReplacedRecordsUnlocked(directory, entries, now)) {
|
|
33541
|
+
changed = true;
|
|
33542
|
+
}
|
|
32753
33543
|
if (changed) await syncDirectory2(directory);
|
|
32754
33544
|
}
|
|
32755
33545
|
function submittedRecordListItem(completion) {
|
|
@@ -32785,9 +33575,64 @@ function privateLessonDraftListItem(draft) {
|
|
|
32785
33575
|
terminal_reason: draft.terminal_reason,
|
|
32786
33576
|
hold_telemetry_status: draft.hold_telemetry_status,
|
|
32787
33577
|
hold_event_digest: draft.hold_event_digest,
|
|
32788
|
-
hold_reported_at: draft.hold_reported_at
|
|
33578
|
+
hold_reported_at: draft.hold_reported_at,
|
|
33579
|
+
...safetyRecheckField(draft)
|
|
33580
|
+
};
|
|
33581
|
+
}
|
|
33582
|
+
function safetyRecheckField(draft) {
|
|
33583
|
+
const recheck = privateLessonSafetyRecheck(draft);
|
|
33584
|
+
return recheck ? { safety_recheck: recheck } : {};
|
|
33585
|
+
}
|
|
33586
|
+
function privateLessonReplaceable(draft, destination) {
|
|
33587
|
+
return draft.held_reasons.length > 0 && draft.state !== "submitted" && draft.state !== "superseded_redactor" && draft.replacement_of === void 0 && privateLessonSafetyRecheck(draft) === null && !privateLessonCapturedForOtherDestination(draft, destination);
|
|
33588
|
+
}
|
|
33589
|
+
function privateLessonCapturedForOtherDestination(draft, destination) {
|
|
33590
|
+
const bound = draft.destination_binding;
|
|
33591
|
+
return Boolean(
|
|
33592
|
+
bound && destination && (bound.api_base_sha256 !== destination.api_base_sha256 || bound.credential_sha256 !== destination.credential_sha256)
|
|
33593
|
+
);
|
|
33594
|
+
}
|
|
33595
|
+
function privateLessonReplacementAttemptsRemaining(draft) {
|
|
33596
|
+
return Math.max(
|
|
33597
|
+
0,
|
|
33598
|
+
PRIVATE_LESSON_REPLACEMENT_MAX_ATTEMPTS - (draft.replacement_attempts ?? []).length
|
|
33599
|
+
);
|
|
33600
|
+
}
|
|
33601
|
+
function privateLessonAgentRecovery(draftId, attemptsRemaining) {
|
|
33602
|
+
if (attemptsRemaining <= 0) return null;
|
|
33603
|
+
return {
|
|
33604
|
+
tool: "capture_learning",
|
|
33605
|
+
action_code: "recapture_held_private_lesson",
|
|
33606
|
+
arguments: {
|
|
33607
|
+
contract_version: PRIVATE_LEARNING_CAPTURE_VERSION,
|
|
33608
|
+
replacement_of: { draft_id: draftId }
|
|
33609
|
+
},
|
|
33610
|
+
required_input: ["lesson"],
|
|
33611
|
+
context_requirement: "existing_task_context",
|
|
33612
|
+
attempts_remaining: attemptsRemaining,
|
|
33613
|
+
retained_original_available_to_agent: false
|
|
32789
33614
|
};
|
|
32790
33615
|
}
|
|
33616
|
+
function privateLessonRecoveryFields(draft, destination) {
|
|
33617
|
+
if (draft.replacement_of !== void 0) {
|
|
33618
|
+
return { replacement_of: draft.replacement_of };
|
|
33619
|
+
}
|
|
33620
|
+
if (!privateLessonReplaceable(draft)) return {};
|
|
33621
|
+
const remaining = privateLessonReplacementAttemptsRemaining(draft);
|
|
33622
|
+
if (remaining > 0 && !privateLessonReplaceable(draft, destination)) {
|
|
33623
|
+
return {
|
|
33624
|
+
replacement_attempts_remaining: remaining,
|
|
33625
|
+
replacement_requires_captured_destination: true
|
|
33626
|
+
};
|
|
33627
|
+
}
|
|
33628
|
+
return {
|
|
33629
|
+
replacement_attempts_remaining: remaining,
|
|
33630
|
+
agent_recovery: privateLessonAgentRecovery(draft.draft_id, remaining)
|
|
33631
|
+
};
|
|
33632
|
+
}
|
|
33633
|
+
function privateLessonHeldRecoveryActionRequired(attemptsRemaining, capturedDestinationRequired = false) {
|
|
33634
|
+
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.";
|
|
33635
|
+
}
|
|
32791
33636
|
function privateLessonPageOffset(value) {
|
|
32792
33637
|
const requested = Math.trunc(value ?? 0);
|
|
32793
33638
|
if (!Number.isSafeInteger(requested)) {
|
|
@@ -32847,6 +33692,79 @@ function parseDeletionTombstone(serialized, expectedDraftId) {
|
|
|
32847
33692
|
}
|
|
32848
33693
|
return value;
|
|
32849
33694
|
}
|
|
33695
|
+
function parseReplacedRecord(serialized, expectedDraftId) {
|
|
33696
|
+
const value = JSON.parse(serialized);
|
|
33697
|
+
const allowedKeys = /* @__PURE__ */ new Set([
|
|
33698
|
+
"version",
|
|
33699
|
+
"draft_id",
|
|
33700
|
+
"deleted_at",
|
|
33701
|
+
"reason",
|
|
33702
|
+
"replacement_draft_id",
|
|
33703
|
+
"expires_at"
|
|
33704
|
+
]);
|
|
33705
|
+
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)) {
|
|
33706
|
+
throw new Error("Private lesson replaced record is invalid.");
|
|
33707
|
+
}
|
|
33708
|
+
return value;
|
|
33709
|
+
}
|
|
33710
|
+
async function readReplacedRecordUnlocked(directory, draftId) {
|
|
33711
|
+
const path = replacedRecordPath(directory, draftId);
|
|
33712
|
+
if (!existsSync2(path)) return null;
|
|
33713
|
+
try {
|
|
33714
|
+
await assertRegularPrivateFile(path, PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES);
|
|
33715
|
+
return parseReplacedRecord(
|
|
33716
|
+
await readBoundedFile(path, PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES),
|
|
33717
|
+
draftId
|
|
33718
|
+
);
|
|
33719
|
+
} catch (error) {
|
|
33720
|
+
if (error instanceof PrivateOutboxStorageError) throw error;
|
|
33721
|
+
throw new PrivateLessonDraftUnavailableError(draftId, "corrupt");
|
|
33722
|
+
}
|
|
33723
|
+
}
|
|
33724
|
+
async function assertNotReplacedUnlocked(directory, draftId) {
|
|
33725
|
+
const replaced = await readReplacedRecordUnlocked(directory, draftId);
|
|
33726
|
+
if (replaced) {
|
|
33727
|
+
throw new PrivateLessonDraftUnavailableError(
|
|
33728
|
+
draftId,
|
|
33729
|
+
"replaced",
|
|
33730
|
+
replaced.replacement_draft_id
|
|
33731
|
+
);
|
|
33732
|
+
}
|
|
33733
|
+
}
|
|
33734
|
+
async function reconcileReplacedRecordsUnlocked(directory, entries, now) {
|
|
33735
|
+
let changed = false;
|
|
33736
|
+
for (const name of entries.filter(
|
|
33737
|
+
(entry) => entry.endsWith(".replaced.json")
|
|
33738
|
+
)) {
|
|
33739
|
+
const draftId = name.slice(0, -".replaced.json".length);
|
|
33740
|
+
let record4;
|
|
33741
|
+
try {
|
|
33742
|
+
record4 = parseReplacedRecord(
|
|
33743
|
+
await readBoundedFile(
|
|
33744
|
+
join3(directory, name),
|
|
33745
|
+
PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES
|
|
33746
|
+
),
|
|
33747
|
+
draftId
|
|
33748
|
+
);
|
|
33749
|
+
} catch {
|
|
33750
|
+
continue;
|
|
33751
|
+
}
|
|
33752
|
+
const retained = draftPath(directory, draftId);
|
|
33753
|
+
if (existsSync2(retained)) {
|
|
33754
|
+
try {
|
|
33755
|
+
await assertRegularPrivateFile(retained, PRIVATE_LESSON_DRAFT_MAX_BYTES);
|
|
33756
|
+
await unlink2(retained);
|
|
33757
|
+
changed = true;
|
|
33758
|
+
} catch {
|
|
33759
|
+
}
|
|
33760
|
+
}
|
|
33761
|
+
if (Date.parse(record4.expires_at) <= now.getTime()) {
|
|
33762
|
+
await unlink2(join3(directory, name));
|
|
33763
|
+
changed = true;
|
|
33764
|
+
}
|
|
33765
|
+
}
|
|
33766
|
+
return changed;
|
|
33767
|
+
}
|
|
32850
33768
|
async function privateLessonRecoveryItems(options = {}) {
|
|
32851
33769
|
const outbox = await readyOutbox(options, false);
|
|
32852
33770
|
return withPrivateLessonOutboxLock(outbox.directory, async () => {
|
|
@@ -32859,7 +33777,7 @@ async function privateLessonRecoveryItems(options = {}) {
|
|
|
32859
33777
|
withFileTypes: true
|
|
32860
33778
|
})) {
|
|
32861
33779
|
const match = entry.name.match(
|
|
32862
|
-
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted)\.json$/u
|
|
33780
|
+
/^(pld_[A-Za-z0-9_-]{8,96})\.(lesson|submitted|deleted|replaced)\.json$/u
|
|
32863
33781
|
);
|
|
32864
33782
|
if (!match) continue;
|
|
32865
33783
|
const draftId = match[1];
|
|
@@ -32876,10 +33794,7 @@ async function privateLessonRecoveryItems(options = {}) {
|
|
|
32876
33794
|
outbox.encryption
|
|
32877
33795
|
);
|
|
32878
33796
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
32879
|
-
const draft = validatedDraft ?
|
|
32880
|
-
terminalizeUnsupportedProfile(validatedDraft, now),
|
|
32881
|
-
now
|
|
32882
|
-
) : null;
|
|
33797
|
+
const draft = validatedDraft ? reconcileStoredDraft(validatedDraft, now) : null;
|
|
32883
33798
|
if (draft?.state === "retry_scheduled" && draft.last_error_code === "policy_verification_failed") {
|
|
32884
33799
|
items.push(
|
|
32885
33800
|
privateLessonRecoveryItem(draftId, "held_safety_recovery_required")
|
|
@@ -32986,7 +33901,7 @@ function privateLessonRecoveryItem(draftId, reasonCode, storageError) {
|
|
|
32986
33901
|
async function reconcilePrivateLessonTemporaryWrites(directory, encryption) {
|
|
32987
33902
|
const groups = /* @__PURE__ */ new Map();
|
|
32988
33903
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
32989
|
-
if (/^\.[a-f0-9]{24}\.capacity\.tmp$/u.test(entry.name) && entry.isFile()) {
|
|
33904
|
+
if (/^\.[a-f0-9]{24}\.(?:capacity|replaced)\.tmp$/u.test(entry.name) && entry.isFile()) {
|
|
32990
33905
|
await unlink2(join3(directory, entry.name));
|
|
32991
33906
|
continue;
|
|
32992
33907
|
}
|
|
@@ -33084,6 +33999,16 @@ async function validatePrivateLessonCanonicalPath(path, name, encryption) {
|
|
|
33084
33999
|
);
|
|
33085
34000
|
return null;
|
|
33086
34001
|
}
|
|
34002
|
+
if (name.endsWith(".replaced.json")) {
|
|
34003
|
+
parseReplacedRecord(
|
|
34004
|
+
await readPrivateLessonCanonicalText(
|
|
34005
|
+
path,
|
|
34006
|
+
PRIVATE_LESSON_SUBMITTED_RECORD_MAX_BYTES
|
|
34007
|
+
),
|
|
34008
|
+
draftId
|
|
34009
|
+
);
|
|
34010
|
+
return null;
|
|
34011
|
+
}
|
|
33087
34012
|
if (name.endsWith(".deleted.json")) {
|
|
33088
34013
|
parseDeletionTombstone(
|
|
33089
34014
|
await readPrivateLessonCanonicalText(
|
|
@@ -33224,7 +34149,7 @@ async function removeCanonicalPrivateLessonEntry(path) {
|
|
|
33224
34149
|
async function secureOutboxEntries(directory) {
|
|
33225
34150
|
const entries = await readdir(directory, { withFileTypes: true });
|
|
33226
34151
|
return entries.filter(
|
|
33227
|
-
(entry) => entry.isFile() && !entry.isSymbolicLink() && /^(?:pld_[A-Za-z0-9_-]{8,96}\.(?:lesson|submitted|deleted)\.json)$/u.test(
|
|
34152
|
+
(entry) => entry.isFile() && !entry.isSymbolicLink() && /^(?:pld_[A-Za-z0-9_-]{8,96}\.(?:lesson|submitted|deleted|replaced)\.json)$/u.test(
|
|
33228
34153
|
entry.name
|
|
33229
34154
|
)
|
|
33230
34155
|
).map((entry) => entry.name).sort();
|
|
@@ -33250,10 +34175,10 @@ async function atomicWritePrivate(path, data) {
|
|
|
33250
34175
|
}
|
|
33251
34176
|
await syncDirectory2(dirname3(path));
|
|
33252
34177
|
}
|
|
33253
|
-
async function
|
|
34178
|
+
async function atomicCreatePrivateLessonEntry(path, data, temporarySuffix = ".tmp") {
|
|
33254
34179
|
const temporary = join3(
|
|
33255
34180
|
dirname3(path),
|
|
33256
|
-
`.${randomBytes4(12).toString("hex")}
|
|
34181
|
+
`.${randomBytes4(12).toString("hex")}${temporarySuffix}`
|
|
33257
34182
|
);
|
|
33258
34183
|
try {
|
|
33259
34184
|
await atomicWritePrivate(temporary, data);
|
|
@@ -33492,6 +34417,20 @@ function tombstonePath(directory, draftId) {
|
|
|
33492
34417
|
assertDraftId(draftId);
|
|
33493
34418
|
return join3(directory, `${draftId}.deleted.json`);
|
|
33494
34419
|
}
|
|
34420
|
+
function replacedRecordPath(directory, draftId) {
|
|
34421
|
+
assertDraftId(draftId);
|
|
34422
|
+
return join3(directory, `${draftId}.replaced.json`);
|
|
34423
|
+
}
|
|
34424
|
+
function privateLessonReplacementDraftId(replacementOf, payloadDigest) {
|
|
34425
|
+
assertDraftId(replacementOf);
|
|
34426
|
+
return `pld_${hashValue(
|
|
34427
|
+
canonicalJson({
|
|
34428
|
+
domain: "remembrance-private-lesson-replacement-v1",
|
|
34429
|
+
replacement_of: replacementOf,
|
|
34430
|
+
payload_digest: payloadDigest
|
|
34431
|
+
})
|
|
34432
|
+
).slice("sha256:".length, "sha256:".length + 32)}`;
|
|
34433
|
+
}
|
|
33495
34434
|
function assertDraftId(value) {
|
|
33496
34435
|
if (!/^pld_[A-Za-z0-9_-]{8,96}$/.test(value)) {
|
|
33497
34436
|
throw new Error("Private lesson draft id is invalid.");
|
|
@@ -65784,7 +66723,8 @@ var LOCAL_ONLY_HANDLERS = Object.freeze({
|
|
|
65784
66723
|
),
|
|
65785
66724
|
inspect_private_lesson_outbox: (payload, context) => inspectPrivateLessonOutbox(
|
|
65786
66725
|
payload,
|
|
65787
|
-
context.persistence
|
|
66726
|
+
context.persistence,
|
|
66727
|
+
context.privateLessonDestination
|
|
65788
66728
|
),
|
|
65789
66729
|
delete_private_lesson_candidate: (payload, context) => {
|
|
65790
66730
|
const request = payload;
|
|
@@ -65871,19 +66811,64 @@ function acknowledgeFeedbackDenialLocally(input, persistence) {
|
|
|
65871
66811
|
};
|
|
65872
66812
|
}
|
|
65873
66813
|
}
|
|
65874
|
-
async function preparePrivateLessonDraft(input, persistence, destination, tool) {
|
|
66814
|
+
async function preparePrivateLessonDraft(input, persistence, destination, tool, replacementOf) {
|
|
65875
66815
|
const prepared = preparePrivateLessonCandidate(input, { tool });
|
|
66816
|
+
if (replacementOf) {
|
|
66817
|
+
return preparePrivateLessonReplacement(
|
|
66818
|
+
input,
|
|
66819
|
+
prepared,
|
|
66820
|
+
replacementOf,
|
|
66821
|
+
persistence,
|
|
66822
|
+
destination
|
|
66823
|
+
);
|
|
66824
|
+
}
|
|
65876
66825
|
const draft = await persistence.queuePreparedPrivateLesson(
|
|
65877
66826
|
prepared,
|
|
65878
66827
|
destination
|
|
65879
66828
|
);
|
|
65880
|
-
return privateLessonDraftActionResult(draft, {
|
|
66829
|
+
return privateLessonDraftActionResult(draft, destination, {
|
|
65881
66830
|
next_action: prepared.status === "ready" || prepared.status === "held_safety" && privateLessonHealthReportingEnabled() ? {
|
|
65882
66831
|
tool: "submit_private_lesson_candidate",
|
|
65883
66832
|
arguments: { draft_id: draft.draft_id }
|
|
65884
|
-
} : null
|
|
66833
|
+
} : null,
|
|
66834
|
+
// Where the lesson holds, without its text, for a replacement.
|
|
66835
|
+
...prepared.status === "held_safety" ? privateLessonFindings(input) : {}
|
|
65885
66836
|
});
|
|
65886
66837
|
}
|
|
66838
|
+
async function preparePrivateLessonReplacement(input, prepared, replacementOf, persistence, destination) {
|
|
66839
|
+
try {
|
|
66840
|
+
const { draft, attempts_remaining, replayed } = await persistence.queuePrivateLessonReplacement(
|
|
66841
|
+
replacementOf,
|
|
66842
|
+
prepared,
|
|
66843
|
+
destination
|
|
66844
|
+
);
|
|
66845
|
+
return privateLessonDraftActionResult(draft, destination, {
|
|
66846
|
+
replacement_attempts_remaining: attempts_remaining,
|
|
66847
|
+
replayed,
|
|
66848
|
+
...draft.state === "awaiting_authorization" && draft.attempts === 0 ? {
|
|
66849
|
+
next_action: {
|
|
66850
|
+
tool: "submit_private_lesson_candidate",
|
|
66851
|
+
arguments: { draft_id: draft.draft_id }
|
|
66852
|
+
}
|
|
66853
|
+
} : {}
|
|
66854
|
+
});
|
|
66855
|
+
} catch (error) {
|
|
66856
|
+
if (!(error instanceof PrivateLessonReplacementRefusedError) || error.reason !== "replacement_held") {
|
|
66857
|
+
throw error;
|
|
66858
|
+
}
|
|
66859
|
+
return {
|
|
66860
|
+
status: "not_stored",
|
|
66861
|
+
...error.diagnostic(),
|
|
66862
|
+
held_reasons: prepared.held_reasons,
|
|
66863
|
+
...privateLessonFindings(input),
|
|
66864
|
+
agent_recovery: privateLessonAgentRecovery(
|
|
66865
|
+
replacementOf,
|
|
66866
|
+
error.attemptsRemaining
|
|
66867
|
+
),
|
|
66868
|
+
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)
|
|
66869
|
+
};
|
|
66870
|
+
}
|
|
66871
|
+
}
|
|
65887
66872
|
async function captureLearning(input, persistence, lessonDestination, skillDestination) {
|
|
65888
66873
|
const parsed = captureLearningInputSchema.parse(input);
|
|
65889
66874
|
const route = captureLearningRoute(parsed);
|
|
@@ -65899,11 +66884,12 @@ async function captureLearning(input, persistence, lessonDestination, skillDesti
|
|
|
65899
66884
|
};
|
|
65900
66885
|
}
|
|
65901
66886
|
if (route === "private_skill") {
|
|
65902
|
-
const
|
|
65903
|
-
|
|
66887
|
+
const link2 = parsed.replacement_of && "context_source" in parsed.replacement_of ? parsed.replacement_of : void 0;
|
|
66888
|
+
const draft = link2 ? await persistence.queuePrivateSkillReformulation(
|
|
66889
|
+
link2.draft_id,
|
|
65904
66890
|
parsed.private_skill,
|
|
65905
|
-
|
|
65906
|
-
...
|
|
66891
|
+
link2.context_source,
|
|
66892
|
+
...link2.recovery_context_id ? [link2.recovery_context_id] : []
|
|
65907
66893
|
) : await persistence.queuePrivateSkillCapture(
|
|
65908
66894
|
parsed.private_skill,
|
|
65909
66895
|
skillDestination
|
|
@@ -65922,7 +66908,8 @@ async function captureLearning(input, persistence, lessonDestination, skillDesti
|
|
|
65922
66908
|
parsed.lesson,
|
|
65923
66909
|
persistence,
|
|
65924
66910
|
lessonDestination,
|
|
65925
|
-
"capture_learning"
|
|
66911
|
+
"capture_learning",
|
|
66912
|
+
parsed.replacement_of?.draft_id
|
|
65926
66913
|
);
|
|
65927
66914
|
return {
|
|
65928
66915
|
contract_version: parsed.contract_version,
|
|
@@ -66029,7 +67016,7 @@ function privateOutboxDiagnostic(error) {
|
|
|
66029
67016
|
const { reason_code, stage, remediation } = error.diagnostic();
|
|
66030
67017
|
return { reason_code, stage, remediation };
|
|
66031
67018
|
}
|
|
66032
|
-
async function inspectPrivateLessonOutbox(input, persistence) {
|
|
67019
|
+
async function inspectPrivateLessonOutbox(input, persistence, destination) {
|
|
66033
67020
|
const snapshot = await persistence.inspectPrivateLessonOutbox(
|
|
66034
67021
|
input.limit,
|
|
66035
67022
|
input.offset
|
|
@@ -66048,7 +67035,7 @@ async function inspectPrivateLessonOutbox(input, persistence) {
|
|
|
66048
67035
|
}
|
|
66049
67036
|
const draft = await persistence.readPrivateLessonDraft(input.draft_id);
|
|
66050
67037
|
return {
|
|
66051
|
-
draft: privateLessonDraftActionResult(draft),
|
|
67038
|
+
draft: privateLessonDraftActionResult(draft, destination),
|
|
66052
67039
|
outbox: publicOutboxSummary(snapshot.summary),
|
|
66053
67040
|
recovery_items: snapshot.recovery_items
|
|
66054
67041
|
};
|
|
@@ -66106,7 +67093,7 @@ function privateLessonSelectedDraftError(draftId, error) {
|
|
|
66106
67093
|
function privateLessonHealthReportingEnabled(env = process.env) {
|
|
66107
67094
|
return !/^(0|false|no)$/i.test(env.REMEMBRANCE_HEALTH_REPORTING ?? "");
|
|
66108
67095
|
}
|
|
66109
|
-
function privateLessonDraftActionResult(draft, extra = {}) {
|
|
67096
|
+
function privateLessonDraftActionResult(draft, destination, extra = {}) {
|
|
66110
67097
|
return {
|
|
66111
67098
|
draft_id: draft.draft_id,
|
|
66112
67099
|
state: draft.state,
|
|
@@ -66123,8 +67110,10 @@ function privateLessonDraftActionResult(draft, extra = {}) {
|
|
|
66123
67110
|
hold_event_digest: draft.hold_event_digest,
|
|
66124
67111
|
hold_receipt_digest: draft.hold_receipt_digest,
|
|
66125
67112
|
hold_reported_at: draft.hold_reported_at,
|
|
67113
|
+
...safetyRecheckField(draft),
|
|
67114
|
+
...privateLessonRecoveryFields(draft, destination),
|
|
66126
67115
|
retained_locally: draft.state !== "submitted" || hasUnverifiablePrivateLessonCompletion(draft),
|
|
66127
|
-
action_required: privateLessonActionRequired(draft),
|
|
67116
|
+
action_required: privateLessonActionRequired(draft, destination),
|
|
66128
67117
|
next_action: privateLessonNextAction(draft),
|
|
66129
67118
|
...extra
|
|
66130
67119
|
};
|
|
@@ -66172,7 +67161,8 @@ function privateLessonNextAction(draft) {
|
|
|
66172
67161
|
}
|
|
66173
67162
|
return null;
|
|
66174
67163
|
}
|
|
66175
|
-
|
|
67164
|
+
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.";
|
|
67165
|
+
function privateLessonActionRequired(draft, destination) {
|
|
66176
67166
|
if (hasUnverifiablePrivateLessonCompletion(draft)) {
|
|
66177
67167
|
return PRIVATE_LESSON_UNVERIFIABLE_COMPLETION_REMEDIATION;
|
|
66178
67168
|
}
|
|
@@ -66182,6 +67172,15 @@ function privateLessonActionRequired(draft) {
|
|
|
66182
67172
|
if (draft.state === "held_safety" && draft.held_reasons.length === 0) {
|
|
66183
67173
|
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
67174
|
}
|
|
67175
|
+
if (privateLessonSafetyRecheck(draft)) {
|
|
67176
|
+
return PRIVATE_LESSON_RECHECKED_HOLD_DECISION;
|
|
67177
|
+
}
|
|
67178
|
+
if (draft.state === "held_safety" && privateLessonReplaceable(draft)) {
|
|
67179
|
+
return privateLessonHeldRecoveryActionRequired(
|
|
67180
|
+
privateLessonReplacementAttemptsRemaining(draft),
|
|
67181
|
+
!privateLessonReplaceable(draft, destination)
|
|
67182
|
+
);
|
|
67183
|
+
}
|
|
66185
67184
|
if (draft.state === "awaiting_authorization") {
|
|
66186
67185
|
return "Restore authorization for the exact private-lesson submission action, then retry this retained draft.";
|
|
66187
67186
|
}
|
|
@@ -66200,6 +67199,9 @@ function privateLessonActionRequired(draft) {
|
|
|
66200
67199
|
if (draft.state === "held_validation" && draft.last_error_code === "private_lesson_destination_audience_mismatch") {
|
|
66201
67200
|
return "The current credential proves a different organization audience. Restore the captured organization destination; the retained draft was not sent to this one.";
|
|
66202
67201
|
}
|
|
67202
|
+
if (draft.state === "held_validation" && draft.last_error_code === "private_lesson_destination_attestation_mismatch") {
|
|
67203
|
+
return PRIVATE_LESSON_ATTESTATION_MISMATCH_REMEDIATION;
|
|
67204
|
+
}
|
|
66203
67205
|
if (draft.state === "held_validation") {
|
|
66204
67206
|
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
67207
|
}
|
|
@@ -66745,6 +67747,10 @@ function createLocalPersistenceCapabilities(dependencies = {}) {
|
|
|
66745
67747
|
...await withEncryption(),
|
|
66746
67748
|
...destination ? { destination } : {}
|
|
66747
67749
|
}),
|
|
67750
|
+
queuePrivateLessonReplacement: async (replacementOf, prepared, destination) => queuePrivateLessonReplacement(replacementOf, prepared, {
|
|
67751
|
+
...await withEncryption(),
|
|
67752
|
+
...destination ? { destination } : {}
|
|
67753
|
+
}),
|
|
66748
67754
|
queuePrivateSkillCapture: async (candidate, destination) => queuePrivateSkillCapture(candidate, {
|
|
66749
67755
|
...await withEncryption(),
|
|
66750
67756
|
...destination ? { destination } : {}
|
|
@@ -68146,6 +69152,17 @@ function localPluginLifecycleHealth(options) {
|
|
|
68146
69152
|
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
69153
|
};
|
|
68148
69154
|
}
|
|
69155
|
+
var HOOK_TRUST_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
|
|
69156
|
+
"app_server_closed",
|
|
69157
|
+
"app_server_initialize_failed",
|
|
69158
|
+
"app_server_unavailable",
|
|
69159
|
+
"check_disabled",
|
|
69160
|
+
"codex_executable_not_found",
|
|
69161
|
+
"hooks_list_failed",
|
|
69162
|
+
"hooks_list_timeout",
|
|
69163
|
+
"hooks_list_too_large",
|
|
69164
|
+
"plugin_hooks_not_listed"
|
|
69165
|
+
]);
|
|
68149
69166
|
function normalizedPluginHookTrust(value) {
|
|
68150
69167
|
if (!isRecord9(value)) return null;
|
|
68151
69168
|
const status = value.status;
|
|
@@ -68180,7 +69197,8 @@ function normalizedPluginHookTrust(value) {
|
|
|
68180
69197
|
status,
|
|
68181
69198
|
checked_at: typeof value.checked_at === "string" && Number.isFinite(Date.parse(value.checked_at)) ? new Date(value.checked_at).toISOString() : null,
|
|
68182
69199
|
review_events: reviewEvents,
|
|
68183
|
-
hooks
|
|
69200
|
+
hooks,
|
|
69201
|
+
reason: status === "unavailable" && typeof value.reason === "string" && HOOK_TRUST_UNAVAILABLE_REASONS.has(value.reason) ? value.reason : null
|
|
68184
69202
|
};
|
|
68185
69203
|
}
|
|
68186
69204
|
function apiDestinationStatus(baseUrl, source) {
|
|
@@ -68562,7 +69580,7 @@ function inspectPrivateLearningOutbox2(input, dependencies = {}) {
|
|
|
68562
69580
|
}
|
|
68563
69581
|
var MAX_REMOTE_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
68564
69582
|
var DOCTOR_PROBE_TIMEOUT_MS = 7500;
|
|
68565
|
-
var SERVER_VERSION = true ? "0.2.
|
|
69583
|
+
var SERVER_VERSION = true ? "0.2.7" : "0.0.0-dev";
|
|
68566
69584
|
var tools2 = toolDefinitions;
|
|
68567
69585
|
var doctorCliRequested = process.argv[2] === "doctor";
|
|
68568
69586
|
var nativeContextCliRequested = process.argv[2] === "--native-context";
|
|
@@ -68843,6 +69861,9 @@ function jsonRpcErrorForToolError(error) {
|
|
|
68843
69861
|
data: error.diagnostic()
|
|
68844
69862
|
};
|
|
68845
69863
|
}
|
|
69864
|
+
if (error instanceof PrivateLessonReplacementRefusedError) {
|
|
69865
|
+
return { code: -32602, message: error.message, data: error.diagnostic() };
|
|
69866
|
+
}
|
|
68846
69867
|
if (error instanceof PrivateLessonLengthLimitError || error instanceof PrivateSkillSizeLimitError) {
|
|
68847
69868
|
return { code: -32602, message: error.message, data: error.diagnostic() };
|
|
68848
69869
|
}
|
|
@@ -68930,11 +69951,13 @@ async function callNetworkToolWithinExecution(definition, payload, access, trans
|
|
|
68930
69951
|
return bootstrapAgentIdentity(payload, access, transport);
|
|
68931
69952
|
}
|
|
68932
69953
|
if (definition.local === "retry_private_lesson_candidate") {
|
|
69954
|
+
const args = payload;
|
|
68933
69955
|
return submitPrivateLessonDraft(
|
|
68934
|
-
String(
|
|
69956
|
+
String(args.draft_id),
|
|
68935
69957
|
access,
|
|
68936
69958
|
"retry",
|
|
68937
|
-
transport
|
|
69959
|
+
transport,
|
|
69960
|
+
{ deliverRecheckedHold: args.deliver_rechecked_hold === true }
|
|
68938
69961
|
);
|
|
68939
69962
|
}
|
|
68940
69963
|
if (definition.local === "retry_private_skill_candidate") {
|
|
@@ -70019,6 +71042,9 @@ var RECOVERABLE_PRIVATE_LESSON_DESTINATION_ERRORS = /* @__PURE__ */ new Set([
|
|
|
70019
71042
|
"private_lesson_destination_audience_mismatch"
|
|
70020
71043
|
]);
|
|
70021
71044
|
function privateLessonDestinationError(draft, current) {
|
|
71045
|
+
if (draft.state === "held_validation" && draft.last_error_code === "private_lesson_destination_attestation_mismatch") {
|
|
71046
|
+
return "private_lesson_destination_attestation_mismatch";
|
|
71047
|
+
}
|
|
70022
71048
|
const captured = draft.destination_binding;
|
|
70023
71049
|
if (!captured) return "private_lesson_destination_legacy_unbound";
|
|
70024
71050
|
if (captured.api_base_sha256 !== current.api_base_sha256) {
|
|
@@ -70039,17 +71065,22 @@ function privateLessonDestinationActionRequired(code) {
|
|
|
70039
71065
|
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
71066
|
case "private_lesson_destination_audience_mismatch":
|
|
70041
71067
|
return "The current credential proves a different organization audience. Restore the captured organization destination; the retained draft was not sent to this one.";
|
|
71068
|
+
case "private_lesson_destination_attestation_mismatch":
|
|
71069
|
+
return PRIVATE_LESSON_ATTESTATION_MISMATCH_REMEDIATION;
|
|
70042
71070
|
}
|
|
70043
71071
|
}
|
|
70044
71072
|
function privateLessonDestinationNextAction(draftId, code) {
|
|
70045
|
-
|
|
70046
|
-
|
|
70047
|
-
|
|
70048
|
-
|
|
70049
|
-
|
|
70050
|
-
|
|
70051
|
-
|
|
70052
|
-
|
|
71073
|
+
if (code === "private_lesson_destination_legacy_unbound") {
|
|
71074
|
+
return {
|
|
71075
|
+
tool: "capture_learning",
|
|
71076
|
+
action_code: "recapture_legacy_private_lesson_with_destination_binding",
|
|
71077
|
+
retained_source_draft_id: draftId,
|
|
71078
|
+
retained_source_available_to_agent: false,
|
|
71079
|
+
required_input: ["lesson"]
|
|
71080
|
+
};
|
|
71081
|
+
}
|
|
71082
|
+
return {
|
|
71083
|
+
tool: code === "private_lesson_destination_attestation_mismatch" ? "inspect_private_lesson_outbox" : "retry_private_lesson_candidate",
|
|
70053
71084
|
arguments: { draft_id: draftId }
|
|
70054
71085
|
};
|
|
70055
71086
|
}
|
|
@@ -70062,8 +71093,9 @@ async function holdPrivateLessonDestination(draft, code) {
|
|
|
70062
71093
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
70063
71094
|
}));
|
|
70064
71095
|
}
|
|
70065
|
-
async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
71096
|
+
async function submitPrivateLessonDraft(draftId, access, mode, transport, { deliverRecheckedHold = false } = {}) {
|
|
70066
71097
|
const allowPolicyRefresh = mode === "retry";
|
|
71098
|
+
const currentDestination = privateLessonDestinationForAccess(access);
|
|
70067
71099
|
const source = await readPrivateLessonSubmissionSource(draftId);
|
|
70068
71100
|
if (source.kind === "submitted") {
|
|
70069
71101
|
return privateLessonSubmittedActionResult2(source.completion, {
|
|
@@ -70072,7 +71104,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70072
71104
|
}
|
|
70073
71105
|
let draft = source.draft;
|
|
70074
71106
|
if (draft.state === "superseded_redactor") {
|
|
70075
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71107
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70076
71108
|
status: "superseded_redactor",
|
|
70077
71109
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70078
71110
|
});
|
|
@@ -70093,6 +71125,24 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70093
71125
|
status: "already_submitted"
|
|
70094
71126
|
});
|
|
70095
71127
|
}
|
|
71128
|
+
if (deliverRecheckedHold && draft.state === "held_safety" && draft.held_reasons.length > 0) {
|
|
71129
|
+
try {
|
|
71130
|
+
draft = await releaseRecheckedPrivateLessonHold(draft.draft_id);
|
|
71131
|
+
} catch (error) {
|
|
71132
|
+
if (!(error instanceof PrivateLessonHoldReleaseRefusedError)) throw error;
|
|
71133
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
71134
|
+
status: "not_submitted",
|
|
71135
|
+
error_code: "private_lesson_hold_not_released",
|
|
71136
|
+
current_hold_reasons: [...error.holdReasons],
|
|
71137
|
+
// Not sent: replacing it is the way on, as for any held draft.
|
|
71138
|
+
action_required: privateLessonHeldRecoveryActionRequired(
|
|
71139
|
+
privateLessonReplacementAttemptsRemaining(draft),
|
|
71140
|
+
!privateLessonReplaceable(draft, currentDestination)
|
|
71141
|
+
),
|
|
71142
|
+
candidate_sent: false
|
|
71143
|
+
});
|
|
71144
|
+
}
|
|
71145
|
+
}
|
|
70096
71146
|
if (draft.state === "held_safety" && draft.held_reasons.length === 0) {
|
|
70097
71147
|
draft = await updatePrivateLessonDraft(
|
|
70098
71148
|
draft.draft_id,
|
|
@@ -70109,14 +71159,13 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70109
71159
|
} : current
|
|
70110
71160
|
);
|
|
70111
71161
|
}
|
|
70112
|
-
const currentDestination = privateLessonDestinationForAccess(access);
|
|
70113
71162
|
const destinationError = privateLessonDestinationError(
|
|
70114
71163
|
draft,
|
|
70115
71164
|
currentDestination
|
|
70116
71165
|
);
|
|
70117
71166
|
if (destinationError) {
|
|
70118
71167
|
draft = await holdPrivateLessonDestination(draft, destinationError);
|
|
70119
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71168
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70120
71169
|
status: "not_submitted",
|
|
70121
71170
|
action_required: privateLessonDestinationActionRequired(destinationError),
|
|
70122
71171
|
next_action: privateLessonDestinationNextAction(
|
|
@@ -70126,10 +71175,27 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70126
71175
|
candidate_sent: false
|
|
70127
71176
|
});
|
|
70128
71177
|
}
|
|
70129
|
-
|
|
71178
|
+
const restoredHold = draft.held_reasons.length > 0 && draft.state !== "held_safety";
|
|
71179
|
+
if (restoredHold) {
|
|
71180
|
+
draft = await updatePrivateLessonDraft(
|
|
71181
|
+
draft.draft_id,
|
|
71182
|
+
(current) => current.held_reasons.length > 0 && current.state !== "held_safety" && current.state !== "submitted" && current.state !== "superseded_redactor" ? {
|
|
71183
|
+
...current,
|
|
71184
|
+
state: "held_safety",
|
|
71185
|
+
next_retry_at: null,
|
|
71186
|
+
last_error_code: null,
|
|
71187
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
71188
|
+
} : current
|
|
71189
|
+
);
|
|
71190
|
+
}
|
|
71191
|
+
if (mode === "retry" && !restoredHold) {
|
|
70130
71192
|
const retryGate = privateLessonRetryGate(draft);
|
|
70131
71193
|
if (retryGate) {
|
|
70132
|
-
return privateLessonDraftActionResult2(
|
|
71194
|
+
return privateLessonDraftActionResult2(
|
|
71195
|
+
draft,
|
|
71196
|
+
currentDestination,
|
|
71197
|
+
retryGate
|
|
71198
|
+
);
|
|
70133
71199
|
}
|
|
70134
71200
|
}
|
|
70135
71201
|
if (draft.state === "held_safety") {
|
|
@@ -70166,7 +71232,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70166
71232
|
error,
|
|
70167
71233
|
error instanceof PrivateLessonPolicyFloorError ? error.code : void 0
|
|
70168
71234
|
);
|
|
70169
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71235
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70170
71236
|
status: "not_submitted",
|
|
70171
71237
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70172
71238
|
});
|
|
@@ -70174,7 +71240,17 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70174
71240
|
if (draft.destination_binding && draft.destination_binding.credential_sha256 !== currentDestination.credential_sha256 && draft.policy && draft.policy.organization_audience_hash !== currentBinding.organization_audience_hash) {
|
|
70175
71241
|
const code = "private_lesson_destination_audience_mismatch";
|
|
70176
71242
|
draft = await holdPrivateLessonDestination(draft, code);
|
|
70177
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71243
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
71244
|
+
status: "not_submitted",
|
|
71245
|
+
action_required: privateLessonDestinationActionRequired(code),
|
|
71246
|
+
next_action: privateLessonDestinationNextAction(draft.draft_id, code),
|
|
71247
|
+
candidate_sent: false
|
|
71248
|
+
});
|
|
71249
|
+
}
|
|
71250
|
+
if (draft.attested_organization_audience_hash !== void 0 && draft.attested_organization_audience_hash !== currentBinding.organization_audience_hash) {
|
|
71251
|
+
const code = "private_lesson_destination_attestation_mismatch";
|
|
71252
|
+
draft = await holdPrivateLessonDestination(draft, code);
|
|
71253
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70178
71254
|
status: "not_submitted",
|
|
70179
71255
|
action_required: privateLessonDestinationActionRequired(code),
|
|
70180
71256
|
next_action: privateLessonDestinationNextAction(draft.draft_id, code),
|
|
@@ -70192,7 +71268,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70192
71268
|
),
|
|
70193
71269
|
"organization_policy_disabled"
|
|
70194
71270
|
);
|
|
70195
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71271
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70196
71272
|
status: "not_submitted",
|
|
70197
71273
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70198
71274
|
});
|
|
@@ -70205,7 +71281,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70205
71281
|
"payload_limit_unavailable"
|
|
70206
71282
|
)
|
|
70207
71283
|
);
|
|
70208
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71284
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70209
71285
|
status: "not_submitted",
|
|
70210
71286
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70211
71287
|
});
|
|
@@ -70221,7 +71297,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70221
71297
|
new PrivateLessonPolicyHoldError(policyConflict.message),
|
|
70222
71298
|
policyConflict.code
|
|
70223
71299
|
);
|
|
70224
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71300
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70225
71301
|
status: "not_submitted",
|
|
70226
71302
|
action_required: policyConflict.action_required
|
|
70227
71303
|
});
|
|
@@ -70334,7 +71410,7 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70334
71410
|
updated_at: completion.updated_at
|
|
70335
71411
|
};
|
|
70336
71412
|
return {
|
|
70337
|
-
...privateLessonDraftActionResult2(draft, {
|
|
71413
|
+
...privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70338
71414
|
status,
|
|
70339
71415
|
completion_expires_at: completion.expires_at
|
|
70340
71416
|
}),
|
|
@@ -70344,11 +71420,11 @@ async function submitPrivateLessonDraft(draftId, access, mode, transport) {
|
|
|
70344
71420
|
} catch (error) {
|
|
70345
71421
|
draft = await persistPrivateLessonFailure(draft, error);
|
|
70346
71422
|
if (draft.state === "submitted") {
|
|
70347
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71423
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70348
71424
|
status: "already_submitted"
|
|
70349
71425
|
});
|
|
70350
71426
|
}
|
|
70351
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71427
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70352
71428
|
status: "not_submitted",
|
|
70353
71429
|
action_required: privateLessonDraftActionRequired(draft)
|
|
70354
71430
|
});
|
|
@@ -70417,8 +71493,9 @@ function retryDue(nextRetryAt) {
|
|
|
70417
71493
|
}
|
|
70418
71494
|
async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolicyRefresh, transport) {
|
|
70419
71495
|
let draft = initialDraft;
|
|
71496
|
+
const currentDestination = privateLessonDestinationForAccess(access);
|
|
70420
71497
|
if (draft.hold_telemetry_status === "submitted") {
|
|
70421
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71498
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70422
71499
|
status: "already_recorded",
|
|
70423
71500
|
processing_state: "recorded"
|
|
70424
71501
|
});
|
|
@@ -70430,7 +71507,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70430
71507
|
next_retry_at: null,
|
|
70431
71508
|
last_error_code: "health_reporting_disabled"
|
|
70432
71509
|
}));
|
|
70433
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71510
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70434
71511
|
status: "not_submitted",
|
|
70435
71512
|
action_required: null
|
|
70436
71513
|
});
|
|
@@ -70450,7 +71527,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70450
71527
|
);
|
|
70451
71528
|
} catch (error) {
|
|
70452
71529
|
draft = await persistPrivateLessonHoldFailure(draft, error);
|
|
70453
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71530
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70454
71531
|
status: "not_submitted",
|
|
70455
71532
|
action_required: privateLessonHoldActionRequired(draft)
|
|
70456
71533
|
});
|
|
@@ -70463,7 +71540,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70463
71540
|
next_retry_at: null,
|
|
70464
71541
|
last_error_code: "private_lesson_automation_disabled"
|
|
70465
71542
|
}));
|
|
70466
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71543
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70467
71544
|
status: "not_submitted",
|
|
70468
71545
|
action_required: null
|
|
70469
71546
|
});
|
|
@@ -70479,7 +71556,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70479
71556
|
new PrivateLessonPolicyHoldError(policyConflict.message),
|
|
70480
71557
|
policyConflict.code
|
|
70481
71558
|
);
|
|
70482
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71559
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70483
71560
|
status: "not_submitted",
|
|
70484
71561
|
action_required: policyConflict.action_required
|
|
70485
71562
|
});
|
|
@@ -70524,7 +71601,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70524
71601
|
policy: receiptPolicy
|
|
70525
71602
|
}));
|
|
70526
71603
|
return {
|
|
70527
|
-
...privateLessonDraftActionResult2(draft, {
|
|
71604
|
+
...privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70528
71605
|
status: submitted.status
|
|
70529
71606
|
}),
|
|
70530
71607
|
receipt: submitted.receipt,
|
|
@@ -70536,7 +71613,7 @@ async function submitPrivateLessonHoldTelemetry(initialDraft, access, allowPolic
|
|
|
70536
71613
|
continue;
|
|
70537
71614
|
}
|
|
70538
71615
|
draft = await persistPrivateLessonHoldFailure(draft, error);
|
|
70539
|
-
return privateLessonDraftActionResult2(draft, {
|
|
71616
|
+
return privateLessonDraftActionResult2(draft, currentDestination, {
|
|
70540
71617
|
status: "not_submitted",
|
|
70541
71618
|
action_required: privateLessonHoldActionRequired(draft)
|
|
70542
71619
|
});
|
|
@@ -71013,7 +72090,7 @@ function privateLessonRetryAt(attempts, retryAfterMs = null) {
|
|
|
71013
72090
|
Date.now() + Math.max(privateLessonRetryDelayMs(attempts), retryAfterMs ?? 0)
|
|
71014
72091
|
).toISOString();
|
|
71015
72092
|
}
|
|
71016
|
-
function privateLessonDraftActionResult2(draft, extra = {}) {
|
|
72093
|
+
function privateLessonDraftActionResult2(draft, destination, extra = {}) {
|
|
71017
72094
|
return {
|
|
71018
72095
|
draft_id: draft.draft_id,
|
|
71019
72096
|
state: draft.state,
|
|
@@ -71030,6 +72107,8 @@ function privateLessonDraftActionResult2(draft, extra = {}) {
|
|
|
71030
72107
|
hold_event_digest: draft.hold_event_digest,
|
|
71031
72108
|
hold_receipt_digest: draft.hold_receipt_digest,
|
|
71032
72109
|
hold_reported_at: draft.hold_reported_at,
|
|
72110
|
+
...safetyRecheckField(draft),
|
|
72111
|
+
...privateLessonRecoveryFields(draft, destination),
|
|
71033
72112
|
retained_locally: draft.state !== "submitted",
|
|
71034
72113
|
next_action: privateLessonDraftNextAction(draft),
|
|
71035
72114
|
...extra
|
|
@@ -72128,8 +73207,12 @@ function formatConnectionDoctorReport(report) {
|
|
|
72128
73207
|
lines2.push(`[${check.status.toUpperCase()}] ${check.id}: ${check.summary}`);
|
|
72129
73208
|
if (check.remediation) {
|
|
72130
73209
|
lines2.push(` Fix: ${check.remediation.action}`);
|
|
72131
|
-
|
|
72132
|
-
|
|
73210
|
+
const command = check.remediation.command;
|
|
73211
|
+
if (command) {
|
|
73212
|
+
lines2.push(
|
|
73213
|
+
command.includes("\n") ? ` Command:
|
|
73214
|
+
${command.replace(/^/gm, " ")}` : ` Command: ${command}`
|
|
73215
|
+
);
|
|
72133
73216
|
}
|
|
72134
73217
|
}
|
|
72135
73218
|
}
|