Make sleep own durable memory promotion

This commit is contained in:
Meta Vens 2026-05-17 12:25:08 +01:00
commit 5df282e6b4
13 changed files with 130 additions and 44 deletions

View file

@ -204,6 +204,7 @@ export const voidSpeechReceiptsSchema = z.object({
export const voidThoughtMemorySchema = z.object({
schemaVersion: z.literal(1),
shortTerm: z.array(distilledMemorySchema).default([]),
memories: z.array(distilledMemorySchema).default([]),
incubation: z.array(incubationThreadSchema).default([]),
updatedAt: timestampSchema,
@ -311,9 +312,15 @@ export const voidSelfStateOperationSchema = z.discriminatedUnion("operation", [
receipt: deliveryReceiptSchema,
}).strict(),
z.object({
operation: z.literal("append_distilled_memory"),
operation: z.literal("record_short_term_memory"),
memory: meaningPreservingMemorySchema,
}).strict(),
z.object({
operation: z.literal("prune_short_term_memories"),
sourceMemoryIds: z.array(nonEmptyStringSchema).min(1),
prunedAt: timestampSchema,
reason: z.string().trim().min(1).max(1000),
}).strict(),
z.object({
operation: z.literal("merge_incubation_support"),
thread: incubationThreadSchema,

View file

@ -70,6 +70,7 @@ export function createEmptyVoidSelfState(
}),
thoughtMemory: voidThoughtMemorySchema.parse({
schemaVersion: 1,
shortTerm: [],
memories: [],
incubation: [],
updatedAt: createdAt,
@ -119,6 +120,10 @@ export function renderVoidSelfStateSummary(
.slice(-6)
.reverse()
.map((memory) => renderTypedMemory(memory));
const shortTermMemories = state.thoughtMemory.shortTerm
.slice(-6)
.reverse()
.map((memory) => renderTypedMemory(memory));
const incubation = state.thoughtMemory.incubation
.filter((thread) => thread.status !== "retired")
.sort((left, right) => right.maturation - left.maturation)
@ -151,6 +156,9 @@ export function renderVoidSelfStateSummary(
memories.length > 0
? ["- What Void remembers:", ...memories].join("\n")
: "- What Void remembers: nothing durable yet.",
shortTermMemories.length > 0
? ["- Short-term residue awaiting sleep:", ...shortTermMemories].join("\n")
: "- Short-term residue awaiting sleep: none.",
incubation.length > 0
? ["- Thoughts still moving:", ...incubation].join("\n")
: "- Thoughts still moving: none.",

View file

@ -128,10 +128,19 @@ function applyTypedOperation(
state.speechReceipts.updatedAt = operation.receipt.sentAt;
closeCasesForReceipt(state.moderationCursor, operation.receipt);
return;
case "append_distilled_memory":
upsertBy(state.thoughtMemory.memories, operation.memory, (entry) => entry.memoryId);
case "record_short_term_memory":
upsertBy(state.thoughtMemory.shortTerm, operation.memory, (entry) => entry.memoryId);
state.thoughtMemory.shortTerm = state.thoughtMemory.shortTerm
.sort((left, right) => left.updatedAt.localeCompare(right.updatedAt))
.slice(-48);
state.thoughtMemory.updatedAt = operation.memory.updatedAt;
return;
case "prune_short_term_memories":
state.thoughtMemory.shortTerm = state.thoughtMemory.shortTerm.filter(
(entry) => !operation.sourceMemoryIds.includes(entry.memoryId),
);
state.thoughtMemory.updatedAt = operation.prunedAt;
return;
case "merge_incubation_support":
upsertBy(state.thoughtMemory.incubation, operation.thread, (entry) => entry.threadId);
state.thoughtMemory.updatedAt = operation.thread.updatedAt;
@ -158,6 +167,9 @@ function applyTypedOperation(
state.thoughtMemory.memories = state.thoughtMemory.memories.filter(
(entry) => !operation.sourceMemoryIds.includes(entry.memoryId) || entry.memoryId === operation.memory.memoryId,
);
state.thoughtMemory.shortTerm = state.thoughtMemory.shortTerm.filter(
(entry) => !operation.sourceMemoryIds.includes(entry.memoryId),
);
state.thoughtMemory.updatedAt = operation.appliedAt;
return;
}