@oyasmi/pipiclaw 0.5.1 → 0.5.3
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 +308 -209
- package/dist/agent/channel-runner.d.ts +47 -0
- package/dist/agent/channel-runner.js +441 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.js +2 -0
- package/dist/agent/progress-formatter.d.ts +4 -0
- package/dist/agent/progress-formatter.js +52 -0
- package/dist/agent/run-queue.d.ts +7 -0
- package/dist/agent/run-queue.js +26 -0
- package/dist/agent/runner-factory.d.ts +3 -0
- package/dist/agent/runner-factory.js +10 -0
- package/dist/agent/session-events.d.ts +14 -0
- package/dist/agent/session-events.js +215 -0
- package/dist/agent/session-resource-gate.d.ts +10 -0
- package/dist/agent/session-resource-gate.js +44 -0
- package/dist/agent/type-guards.d.ts +22 -0
- package/dist/agent/type-guards.js +106 -0
- package/dist/agent/types.d.ts +160 -0
- package/dist/agent/types.js +22 -0
- package/dist/agent.d.ts +2 -16
- package/dist/agent.js +1 -782
- package/dist/command-extension.d.ts +0 -1
- package/dist/command-extension.js +0 -1
- package/dist/commands.d.ts +0 -1
- package/dist/commands.js +0 -1
- package/dist/config-loader.d.ts +0 -1
- package/dist/config-loader.js +1 -2
- package/dist/context.d.ts +58 -15
- package/dist/context.js +50 -8
- package/dist/index.d.ts +12 -13
- package/dist/index.js +12 -13
- package/dist/log.d.ts +0 -1
- package/dist/log.js +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.js +5 -405
- package/dist/memory/bootstrap.d.ts +6 -0
- package/dist/memory/bootstrap.js +46 -0
- package/dist/{memory-candidates.d.ts → memory/candidates.d.ts} +1 -1
- package/dist/{memory-candidates.js → memory/candidates.js} +33 -21
- package/dist/memory/chinese-words.d.ts +1 -0
- package/dist/memory/chinese-words.js +273 -0
- package/dist/{memory-consolidation.d.ts → memory/consolidation.d.ts} +0 -1
- package/dist/{memory-consolidation.js → memory/consolidation.js} +26 -35
- package/dist/{memory-files.d.ts → memory/files.d.ts} +0 -6
- package/dist/{memory-files.js → memory/files.js} +11 -36
- package/dist/{memory-lifecycle.d.ts → memory/lifecycle.d.ts} +23 -6
- package/dist/memory/lifecycle.js +246 -0
- package/dist/{memory-recall.d.ts → memory/recall.d.ts} +2 -2
- package/dist/memory/recall.js +501 -0
- package/dist/{session-memory.d.ts → memory/session.d.ts} +1 -1
- package/dist/{session-memory.js → memory/session.js} +31 -62
- package/dist/model-utils.d.ts +0 -1
- package/dist/model-utils.js +0 -1
- package/dist/paths.d.ts +0 -1
- package/dist/paths.js +0 -1
- package/dist/prompt-builder.d.ts +0 -1
- package/dist/prompt-builder.js +0 -1
- package/dist/runtime/bootstrap.d.ts +47 -0
- package/dist/runtime/bootstrap.js +450 -0
- package/dist/{delivery.d.ts → runtime/delivery.d.ts} +0 -1
- package/dist/{delivery.js → runtime/delivery.js} +1 -2
- package/dist/{dingtalk.d.ts → runtime/dingtalk.d.ts} +10 -1
- package/dist/{dingtalk.js → runtime/dingtalk.js} +87 -28
- package/dist/{events.d.ts → runtime/events.d.ts} +0 -1
- package/dist/{events.js → runtime/events.js} +1 -2
- package/dist/{store.d.ts → runtime/store.d.ts} +5 -1
- package/dist/{store.js → runtime/store.js} +60 -20
- package/dist/sandbox.d.ts +0 -1
- package/dist/sandbox.js +1 -2
- package/dist/{llm-json.d.ts → shared/llm-json.d.ts} +0 -1
- package/dist/{llm-json.js → shared/llm-json.js} +0 -1
- package/dist/shared/markdown-sections.d.ts +6 -0
- package/dist/{markdown-sections.js → shared/markdown-sections.js} +10 -4
- package/dist/{shell-escape.d.ts → shared/shell-escape.d.ts} +0 -1
- package/dist/{shell-escape.js → shared/shell-escape.js} +0 -1
- package/dist/shared/text-utils.d.ts +9 -0
- package/dist/shared/text-utils.js +36 -0
- package/dist/shared/type-guards.d.ts +5 -0
- package/dist/shared/type-guards.js +12 -0
- package/dist/shared/types.d.ts +14 -0
- package/dist/shared/types.js +1 -0
- package/dist/sidecar-worker.d.ts +0 -1
- package/dist/sidecar-worker.js +1 -8
- package/dist/{sub-agents.d.ts → subagents/discovery.d.ts} +0 -1
- package/dist/{sub-agents.js → subagents/discovery.js} +2 -3
- package/dist/{tools/subagent.d.ts → subagents/tool.d.ts} +2 -16
- package/dist/{tools/subagent.js → subagents/tool.js} +16 -38
- package/dist/tools/attach.d.ts +0 -1
- package/dist/tools/attach.js +0 -1
- package/dist/tools/bash.d.ts +0 -1
- package/dist/tools/bash.js +0 -1
- package/dist/tools/edit.d.ts +0 -1
- package/dist/tools/edit.js +1 -2
- package/dist/tools/index.d.ts +1 -2
- package/dist/tools/index.js +1 -2
- package/dist/tools/read.d.ts +0 -1
- package/dist/tools/read.js +1 -2
- package/dist/tools/truncate.d.ts +0 -1
- package/dist/tools/truncate.js +0 -1
- package/dist/tools/write-content.d.ts +0 -1
- package/dist/tools/write-content.js +1 -2
- package/dist/tools/write.d.ts +0 -1
- package/dist/tools/write.js +0 -1
- package/package.json +9 -3
- package/CHANGELOG.md +0 -47
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js.map +0 -1
- package/dist/command-extension.d.ts.map +0 -1
- package/dist/command-extension.js.map +0 -1
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js.map +0 -1
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/delivery.d.ts.map +0 -1
- package/dist/delivery.js.map +0 -1
- package/dist/dingtalk.d.ts.map +0 -1
- package/dist/dingtalk.js.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/llm-json.d.ts.map +0 -1
- package/dist/llm-json.js.map +0 -1
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/markdown-sections.d.ts +0 -6
- package/dist/markdown-sections.d.ts.map +0 -1
- package/dist/markdown-sections.js.map +0 -1
- package/dist/memory-candidates.d.ts.map +0 -1
- package/dist/memory-candidates.js.map +0 -1
- package/dist/memory-consolidation.d.ts.map +0 -1
- package/dist/memory-consolidation.js.map +0 -1
- package/dist/memory-files.d.ts.map +0 -1
- package/dist/memory-files.js.map +0 -1
- package/dist/memory-lifecycle.d.ts.map +0 -1
- package/dist/memory-lifecycle.js +0 -150
- package/dist/memory-lifecycle.js.map +0 -1
- package/dist/memory-recall.d.ts.map +0 -1
- package/dist/memory-recall.js +0 -218
- package/dist/memory-recall.js.map +0 -1
- package/dist/model-utils.d.ts.map +0 -1
- package/dist/model-utils.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/prompt-builder.d.ts.map +0 -1
- package/dist/prompt-builder.js.map +0 -1
- package/dist/sandbox.d.ts.map +0 -1
- package/dist/sandbox.js.map +0 -1
- package/dist/session-memory-files.d.ts +0 -2
- package/dist/session-memory-files.d.ts.map +0 -1
- package/dist/session-memory-files.js +0 -2
- package/dist/session-memory-files.js.map +0 -1
- package/dist/session-memory.d.ts.map +0 -1
- package/dist/session-memory.js.map +0 -1
- package/dist/shell-escape.d.ts.map +0 -1
- package/dist/shell-escape.js.map +0 -1
- package/dist/sidecar-worker.d.ts.map +0 -1
- package/dist/sidecar-worker.js.map +0 -1
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/sub-agents.d.ts.map +0 -1
- package/dist/sub-agents.js.map +0 -1
- package/dist/tools/attach.d.ts.map +0 -1
- package/dist/tools/attach.js.map +0 -1
- package/dist/tools/bash.d.ts.map +0 -1
- package/dist/tools/bash.js.map +0 -1
- package/dist/tools/edit.d.ts.map +0 -1
- package/dist/tools/edit.js.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/read.d.ts.map +0 -1
- package/dist/tools/read.js.map +0 -1
- package/dist/tools/subagent.d.ts.map +0 -1
- package/dist/tools/subagent.js.map +0 -1
- package/dist/tools/truncate.d.ts.map +0 -1
- package/dist/tools/truncate.js.map +0 -1
- package/dist/tools/write-content.d.ts.map +0 -1
- package/dist/tools/write-content.js.map +0 -1
- package/dist/tools/write.d.ts.map +0 -1
- package/dist/tools/write.js.map +0 -1
- package/docs/improve-memory/design.md +0 -537
- package/docs/improve-memory/interfaces-and-tests.md +0 -473
- package/docs/improve-memory/spec.md +0 -357
- package/docs/memory-rfc.md +0 -297
- package/docs/proj-review.md +0 -188
- package/docs/subagent/pi-subagent-analyse.txt +0 -190
- package/docs/subagent/pi-subagent-design.txt +0 -266
- package/docs/subagent/pi-subagent-phase1-plan.txt +0 -529
- package/docs/test-supplementation-plan.md +0 -553
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import * as log from "../log.js";
|
|
2
|
+
import { runBackgroundMaintenance, runInlineConsolidation, } from "./consolidation.js";
|
|
3
|
+
import { updateChannelSessionMemory } from "./session.js";
|
|
4
|
+
const IDLE_CONSOLIDATION_DELAY_MS = 60_000;
|
|
5
|
+
export class MemoryLifecycle {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
this.backgroundQueue = Promise.resolve();
|
|
9
|
+
this.sessionRefreshQueue = Promise.resolve();
|
|
10
|
+
this.turnsSinceSessionUpdate = 0;
|
|
11
|
+
this.toolCallsSinceSessionUpdate = 0;
|
|
12
|
+
this.thresholdFailureBackoffTurnsRemaining = 0;
|
|
13
|
+
this.thresholdRefreshQueued = false;
|
|
14
|
+
this.sessionRefreshRunning = false;
|
|
15
|
+
this.durableDirty = false;
|
|
16
|
+
this.durableRevision = 0;
|
|
17
|
+
this.lastAssistantTurnRevision = 0;
|
|
18
|
+
this.lastDurableConsolidationRevision = 0;
|
|
19
|
+
this.idleConsolidationTimer = null;
|
|
20
|
+
this.idleConsolidationQueued = false;
|
|
21
|
+
}
|
|
22
|
+
buildRunOptions(messages, sessionEntries) {
|
|
23
|
+
return {
|
|
24
|
+
channelDir: this.options.channelDir,
|
|
25
|
+
model: this.options.getModel(),
|
|
26
|
+
resolveApiKey: this.options.resolveApiKey,
|
|
27
|
+
messages: messages ?? this.options.getMessages(),
|
|
28
|
+
sessionEntries: sessionEntries ?? this.options.getSessionEntries(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
createExtensionFactory() {
|
|
32
|
+
return (pi) => {
|
|
33
|
+
pi.on("session_before_compact", async (event) => {
|
|
34
|
+
await this.handleSessionBeforeCompact(event);
|
|
35
|
+
});
|
|
36
|
+
pi.on("session_compact", async (event) => {
|
|
37
|
+
this.handleSessionCompact(event);
|
|
38
|
+
});
|
|
39
|
+
pi.on("session_before_switch", async (event) => {
|
|
40
|
+
await this.handleSessionBeforeSwitch(event);
|
|
41
|
+
});
|
|
42
|
+
pi.on("session_switch", async (event) => {
|
|
43
|
+
this.handleSessionSwitch(event);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
noteUserTurnStarted() {
|
|
48
|
+
this.clearIdleConsolidationTimer();
|
|
49
|
+
}
|
|
50
|
+
noteToolCall() {
|
|
51
|
+
this.durableDirty = true;
|
|
52
|
+
this.durableRevision++;
|
|
53
|
+
this.toolCallsSinceSessionUpdate++;
|
|
54
|
+
this.clearIdleConsolidationTimer();
|
|
55
|
+
}
|
|
56
|
+
noteCompletedAssistantTurn() {
|
|
57
|
+
this.durableDirty = true;
|
|
58
|
+
this.durableRevision++;
|
|
59
|
+
this.lastAssistantTurnRevision = this.durableRevision;
|
|
60
|
+
const settings = this.options.getSessionMemorySettings();
|
|
61
|
+
if (settings.enabled) {
|
|
62
|
+
this.turnsSinceSessionUpdate++;
|
|
63
|
+
let canTriggerThresholdRefresh = true;
|
|
64
|
+
if (this.thresholdFailureBackoffTurnsRemaining > 0) {
|
|
65
|
+
this.thresholdFailureBackoffTurnsRemaining--;
|
|
66
|
+
canTriggerThresholdRefresh = this.thresholdFailureBackoffTurnsRemaining === 0;
|
|
67
|
+
}
|
|
68
|
+
if (canTriggerThresholdRefresh &&
|
|
69
|
+
(this.turnsSinceSessionUpdate >= settings.minTurnsBetweenUpdate ||
|
|
70
|
+
this.toolCallsSinceSessionUpdate >= settings.minToolCallsBetweenUpdate)) {
|
|
71
|
+
this.requestThresholdSessionRefresh();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
this.scheduleIdleConsolidation();
|
|
75
|
+
}
|
|
76
|
+
clearIdleConsolidationTimer() {
|
|
77
|
+
if (!this.idleConsolidationTimer) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
clearTimeout(this.idleConsolidationTimer);
|
|
81
|
+
this.idleConsolidationTimer = null;
|
|
82
|
+
}
|
|
83
|
+
shouldForceRefreshFor(reason, settings) {
|
|
84
|
+
if (!settings.enabled) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return reason === "compaction" ? settings.forceRefreshBeforeCompact : settings.forceRefreshBeforeNewSession;
|
|
88
|
+
}
|
|
89
|
+
async refreshSessionMemory(request) {
|
|
90
|
+
const settings = this.options.getSessionMemorySettings();
|
|
91
|
+
if (!settings.enabled) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const { reason } = request;
|
|
95
|
+
this.sessionRefreshRunning = true;
|
|
96
|
+
try {
|
|
97
|
+
await updateChannelSessionMemory({
|
|
98
|
+
channelDir: this.options.channelDir,
|
|
99
|
+
messages: request.messages ?? this.options.getMessages(),
|
|
100
|
+
model: this.options.getModel(),
|
|
101
|
+
resolveApiKey: this.options.resolveApiKey,
|
|
102
|
+
timeoutMs: settings.timeoutMs,
|
|
103
|
+
});
|
|
104
|
+
this.turnsSinceSessionUpdate = 0;
|
|
105
|
+
this.toolCallsSinceSessionUpdate = 0;
|
|
106
|
+
this.thresholdFailureBackoffTurnsRemaining = 0;
|
|
107
|
+
log.logInfo(`[${this.options.channelId}] Session memory updated (${reason})`);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
112
|
+
if (reason === "threshold") {
|
|
113
|
+
this.thresholdFailureBackoffTurnsRemaining = Math.max(0, settings.failureBackoffTurns);
|
|
114
|
+
}
|
|
115
|
+
log.logWarning(`[${this.options.channelId}] Session memory update failed (${reason})`, message);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
this.sessionRefreshRunning = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
runSessionRefreshSerial(request) {
|
|
123
|
+
const run = async () => this.refreshSessionMemory(request);
|
|
124
|
+
const resultPromise = this.sessionRefreshQueue.then(run, run);
|
|
125
|
+
this.sessionRefreshQueue = resultPromise.then(() => undefined, () => undefined);
|
|
126
|
+
return resultPromise;
|
|
127
|
+
}
|
|
128
|
+
requestThresholdSessionRefresh() {
|
|
129
|
+
if (this.thresholdRefreshQueued || this.sessionRefreshRunning) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.thresholdRefreshQueued = true;
|
|
133
|
+
void this.runSessionRefreshSerial({ reason: "threshold" }).finally(() => {
|
|
134
|
+
this.thresholdRefreshQueued = false;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
enqueueBackgroundJob(job, failureMessage) {
|
|
138
|
+
this.backgroundQueue = this.backgroundQueue.then(job).catch((error) => {
|
|
139
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
140
|
+
log.logWarning(failureMessage, message);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
hasPendingAssistantSnapshot() {
|
|
144
|
+
return this.durableDirty && this.lastAssistantTurnRevision > this.lastDurableConsolidationRevision;
|
|
145
|
+
}
|
|
146
|
+
markDurableConsolidationCheckpoint(revision) {
|
|
147
|
+
this.lastDurableConsolidationRevision = Math.max(this.lastDurableConsolidationRevision, revision);
|
|
148
|
+
this.durableDirty = this.durableRevision > this.lastDurableConsolidationRevision;
|
|
149
|
+
}
|
|
150
|
+
logConsolidationResult(reason, result) {
|
|
151
|
+
if (result.skipped) {
|
|
152
|
+
log.logInfo(`[${this.options.channelId}] Memory consolidation skipped (${reason}): no meaningful snapshot`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
log.logInfo(`[${this.options.channelId}] Memory consolidation finished (${reason}): memory entries=${result.appendedMemoryEntries}, history=${result.appendedHistoryBlock ? "yes" : "no"}`);
|
|
156
|
+
}
|
|
157
|
+
scheduleIdleConsolidation() {
|
|
158
|
+
this.clearIdleConsolidationTimer();
|
|
159
|
+
if (!this.hasPendingAssistantSnapshot() || this.idleConsolidationQueued) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.idleConsolidationTimer = setTimeout(() => {
|
|
163
|
+
this.idleConsolidationTimer = null;
|
|
164
|
+
if (!this.hasPendingAssistantSnapshot() || this.idleConsolidationQueued) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.idleConsolidationQueued = true;
|
|
168
|
+
const messageSnapshot = [...this.options.getMessages()];
|
|
169
|
+
const sessionEntrySnapshot = [...this.options.getSessionEntries()];
|
|
170
|
+
const revisionSnapshot = this.durableRevision;
|
|
171
|
+
this.enqueueBackgroundJob(async () => {
|
|
172
|
+
try {
|
|
173
|
+
log.logInfo(`[${this.options.channelId}] Memory consolidation starting (idle)`);
|
|
174
|
+
const result = await runInlineConsolidation(this.buildRunOptions(messageSnapshot, sessionEntrySnapshot));
|
|
175
|
+
this.markDurableConsolidationCheckpoint(revisionSnapshot);
|
|
176
|
+
this.logConsolidationResult("idle", result);
|
|
177
|
+
const maintenance = await runBackgroundMaintenance(this.buildRunOptions(messageSnapshot, sessionEntrySnapshot));
|
|
178
|
+
this.logBackgroundResult(maintenance);
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
this.idleConsolidationQueued = false;
|
|
182
|
+
if (this.durableDirty) {
|
|
183
|
+
this.scheduleIdleConsolidation();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}, `[${this.options.channelId}] Memory consolidation failed (idle)`);
|
|
187
|
+
}, IDLE_CONSOLIDATION_DELAY_MS);
|
|
188
|
+
}
|
|
189
|
+
async runPreflightConsolidation(reason, messages, sessionEntries) {
|
|
190
|
+
this.clearIdleConsolidationTimer();
|
|
191
|
+
const messageSnapshot = [...(messages ?? this.options.getMessages())];
|
|
192
|
+
const sessionEntrySnapshot = sessionEntries ? [...sessionEntries] : [...this.options.getSessionEntries()];
|
|
193
|
+
const revisionSnapshot = this.durableRevision;
|
|
194
|
+
const settings = this.options.getSessionMemorySettings();
|
|
195
|
+
if (this.shouldForceRefreshFor(reason, settings)) {
|
|
196
|
+
await this.runSessionRefreshSerial({
|
|
197
|
+
reason,
|
|
198
|
+
messages: messageSnapshot,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
log.logInfo(`[${this.options.channelId}] Memory consolidation starting (${reason})`);
|
|
203
|
+
const result = await runInlineConsolidation(this.buildRunOptions(messageSnapshot, sessionEntrySnapshot));
|
|
204
|
+
this.markDurableConsolidationCheckpoint(revisionSnapshot);
|
|
205
|
+
this.logConsolidationResult(reason, result);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
209
|
+
log.logWarning(`[${this.options.channelId}] Memory consolidation failed (${reason})`, message);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async handleSessionBeforeCompact(event) {
|
|
213
|
+
await this.runPreflightConsolidation("compaction", event.preparation.messagesToSummarize);
|
|
214
|
+
}
|
|
215
|
+
handleSessionCompact(_event) {
|
|
216
|
+
this.enqueueBackgroundMaintenance();
|
|
217
|
+
}
|
|
218
|
+
async handleSessionBeforeSwitch(event) {
|
|
219
|
+
if (event.reason !== "new") {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
await this.runPreflightConsolidation("new-session");
|
|
223
|
+
}
|
|
224
|
+
handleSessionSwitch(event) {
|
|
225
|
+
if (event.reason !== "new") {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this.enqueueBackgroundMaintenance();
|
|
229
|
+
}
|
|
230
|
+
enqueueBackgroundMaintenance() {
|
|
231
|
+
this.enqueueBackgroundJob(async () => {
|
|
232
|
+
const result = await runBackgroundMaintenance(this.buildRunOptions([], []));
|
|
233
|
+
this.logBackgroundResult(result);
|
|
234
|
+
}, `[${this.options.channelId}] Background memory maintenance failed`);
|
|
235
|
+
}
|
|
236
|
+
logBackgroundResult(result) {
|
|
237
|
+
if (!result.cleanedMemory && !result.foldedHistory) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const details = [
|
|
241
|
+
`memory cleanup=${result.cleanedMemory ? "yes" : "no"}`,
|
|
242
|
+
`history fold=${result.foldedHistory ? "yes" : "no"}`,
|
|
243
|
+
].join(", ");
|
|
244
|
+
log.logInfo(`[${this.options.channelId}] Background memory maintenance complete: ${details}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Api, Model } from "@mariozechner/pi-ai";
|
|
2
|
-
import { type MemoryCandidate, type MemoryCandidateCache } from "./
|
|
2
|
+
import { type MemoryCandidate, type MemoryCandidateCache } from "./candidates.js";
|
|
3
3
|
export interface RecallRequest {
|
|
4
4
|
query: string;
|
|
5
5
|
workspaceDir: string;
|
|
@@ -25,5 +25,5 @@ export interface RecallResult {
|
|
|
25
25
|
items: RecalledMemory[];
|
|
26
26
|
renderedText: string;
|
|
27
27
|
}
|
|
28
|
+
export declare function tokenizeRecallText(text: string): string[];
|
|
28
29
|
export declare function recallRelevantMemory(request: RecallRequest): Promise<RecallResult>;
|
|
29
|
-
//# sourceMappingURL=memory-recall.d.ts.map
|