@lapis-notes/ai 0.1.0
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/CHANGELOG.md +6 -0
- package/LICENSE.md +8 -0
- package/README.md +20 -0
- package/dist/ai-plugin.d.ts +88 -0
- package/dist/ai-plugin.js +742 -0
- package/dist/bootstrap/build.d.ts +15 -0
- package/dist/bootstrap/build.js +28 -0
- package/dist/bootstrap/folder-instructions.d.ts +4 -0
- package/dist/bootstrap/folder-instructions.js +49 -0
- package/dist/bootstrap/format.d.ts +2 -0
- package/dist/bootstrap/format.js +46 -0
- package/dist/bootstrap/instructions.d.ts +1 -0
- package/dist/bootstrap/instructions.js +8 -0
- package/dist/bootstrap/types.d.ts +36 -0
- package/dist/bootstrap/types.js +3 -0
- package/dist/catalog/ai-catalog-panel.svelte +742 -0
- package/dist/catalog/ai-catalog-panel.svelte.d.ts +13 -0
- package/dist/catalog/ai-catalog-view-type.d.ts +1 -0
- package/dist/catalog/ai-catalog-view-type.js +1 -0
- package/dist/catalog/ai-catalog-view.d.ts +22 -0
- package/dist/catalog/ai-catalog-view.js +48 -0
- package/dist/catalog/filter.d.ts +3 -0
- package/dist/catalog/filter.js +24 -0
- package/dist/catalog/inventory.d.ts +21 -0
- package/dist/catalog/inventory.js +255 -0
- package/dist/catalog/tree.d.ts +12 -0
- package/dist/catalog/tree.js +60 -0
- package/dist/catalog/types.d.ts +44 -0
- package/dist/catalog/types.js +1 -0
- package/dist/chat/ai-approval-card.svelte +54 -0
- package/dist/chat/ai-approval-card.svelte.d.ts +9 -0
- package/dist/chat/ai-chat-panel.svelte +1288 -0
- package/dist/chat/ai-chat-panel.svelte.d.ts +50 -0
- package/dist/chat/ai-inventory-result.css +55 -0
- package/dist/chat/ai-inventory-result.svelte +63 -0
- package/dist/chat/ai-inventory-result.svelte.d.ts +5 -0
- package/dist/chat/ai-question-card.svelte +132 -0
- package/dist/chat/ai-question-card.svelte.d.ts +9 -0
- package/dist/chat/ai-view-bootstrap.d.ts +13 -0
- package/dist/chat/ai-view-bootstrap.js +86 -0
- package/dist/chat/ai-view-panel.svelte +89 -0
- package/dist/chat/ai-view-panel.svelte.d.ts +13 -0
- package/dist/chat/ai-view-type.d.ts +1 -0
- package/dist/chat/ai-view-type.js +1 -0
- package/dist/chat/ai-view.d.ts +60 -0
- package/dist/chat/ai-view.js +121 -0
- package/dist/chat/chat-controller.svelte.d.ts +82 -0
- package/dist/chat/chat-controller.svelte.js +1926 -0
- package/dist/chat/chat-items.d.ts +88 -0
- package/dist/chat/chat-items.js +9 -0
- package/dist/chat/chat-mentions.d.ts +15 -0
- package/dist/chat/chat-mentions.js +77 -0
- package/dist/chat/chat-result-views.d.ts +5 -0
- package/dist/chat/chat-result-views.js +15 -0
- package/dist/chat/chat-session.d.ts +28 -0
- package/dist/chat/chat-session.js +50 -0
- package/dist/chat/chat-status.d.ts +1 -0
- package/dist/chat/chat-status.js +3 -0
- package/dist/chat/chat-time.d.ts +18 -0
- package/dist/chat/chat-time.js +90 -0
- package/dist/chat/chat-tool-display.d.ts +17 -0
- package/dist/chat/chat-tool-display.js +213 -0
- package/dist/chat/chat-tool-identity.d.ts +4 -0
- package/dist/chat/chat-tool-identity.js +42 -0
- package/dist/chat/chat-trace.d.ts +6 -0
- package/dist/chat/chat-trace.js +256 -0
- package/dist/chat/live-runtime-unavailable.d.ts +1 -0
- package/dist/chat/live-runtime-unavailable.js +1 -0
- package/dist/commands/agent.d.ts +8 -0
- package/dist/commands/agent.js +38 -0
- package/dist/commands/catalog.d.ts +18 -0
- package/dist/commands/catalog.js +115 -0
- package/dist/commands/discovery.d.ts +36 -0
- package/dist/commands/discovery.js +151 -0
- package/dist/commands/groups.d.ts +16 -0
- package/dist/commands/groups.js +121 -0
- package/dist/commands/inspect.d.ts +18 -0
- package/dist/commands/inspect.js +29 -0
- package/dist/commands/markdown.d.ts +21 -0
- package/dist/commands/markdown.js +117 -0
- package/dist/commands/parser.d.ts +4 -0
- package/dist/commands/parser.js +24 -0
- package/dist/commands/reserved.d.ts +4 -0
- package/dist/commands/reserved.js +107 -0
- package/dist/commands/router.d.ts +17 -0
- package/dist/commands/router.js +170 -0
- package/dist/commands/seed.d.ts +4 -0
- package/dist/commands/seed.js +8 -0
- package/dist/commands/types.d.ts +54 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/user-agents-node.d.ts +3 -0
- package/dist/commands/user-agents-node.js +52 -0
- package/dist/commands/user-agents.d.ts +22 -0
- package/dist/commands/user-agents.js +40 -0
- package/dist/conversations/approval-grants.d.ts +20 -0
- package/dist/conversations/approval-grants.js +75 -0
- package/dist/conversations/binding-state.d.ts +6 -0
- package/dist/conversations/binding-state.js +35 -0
- package/dist/conversations/context-handoff.d.ts +25 -0
- package/dist/conversations/context-handoff.js +207 -0
- package/dist/conversations/conversation-index-coordinator.d.ts +18 -0
- package/dist/conversations/conversation-index-coordinator.js +81 -0
- package/dist/conversations/conversation-index.d.ts +16 -0
- package/dist/conversations/conversation-index.js +125 -0
- package/dist/conversations/conversation-locator.d.ts +2 -0
- package/dist/conversations/conversation-locator.js +20 -0
- package/dist/conversations/conversation-palette.d.ts +18 -0
- package/dist/conversations/conversation-palette.js +29 -0
- package/dist/conversations/conversation-repository.d.ts +39 -0
- package/dist/conversations/conversation-repository.js +213 -0
- package/dist/conversations/handoff-summary.d.ts +48 -0
- package/dist/conversations/handoff-summary.js +269 -0
- package/dist/conversations/hashes.d.ts +5 -0
- package/dist/conversations/hashes.js +40 -0
- package/dist/conversations/history-creation-scope.d.ts +12 -0
- package/dist/conversations/history-creation-scope.js +44 -0
- package/dist/conversations/jsonl.d.ts +10 -0
- package/dist/conversations/jsonl.js +41 -0
- package/dist/conversations/memory-transcript-store.d.ts +15 -0
- package/dist/conversations/memory-transcript-store.js +119 -0
- package/dist/conversations/paths.d.ts +14 -0
- package/dist/conversations/paths.js +92 -0
- package/dist/conversations/redaction.d.ts +13 -0
- package/dist/conversations/redaction.js +94 -0
- package/dist/conversations/reveal-scope.d.ts +3 -0
- package/dist/conversations/reveal-scope.js +8 -0
- package/dist/conversations/scope-resolver.d.ts +11 -0
- package/dist/conversations/scope-resolver.js +18 -0
- package/dist/conversations/scope-tree.d.ts +10 -0
- package/dist/conversations/scope-tree.js +71 -0
- package/dist/conversations/transcript-projection.d.ts +9 -0
- package/dist/conversations/transcript-projection.js +409 -0
- package/dist/conversations/transcript-store.d.ts +24 -0
- package/dist/conversations/transcript-store.js +27 -0
- package/dist/conversations/types.d.ts +224 -0
- package/dist/conversations/types.js +12 -0
- package/dist/conversations/validation.d.ts +4 -0
- package/dist/conversations/validation.js +383 -0
- package/dist/conversations/vault-transcript-store.d.ts +22 -0
- package/dist/conversations/vault-transcript-store.js +219 -0
- package/dist/core/event-queue.d.ts +6 -0
- package/dist/core/event-queue.js +39 -0
- package/dist/core/types.d.ts +241 -0
- package/dist/core/types.js +50 -0
- package/dist/history/ai-history-panel.svelte +937 -0
- package/dist/history/ai-history-panel.svelte.d.ts +17 -0
- package/dist/history/ai-history-view-type.d.ts +1 -0
- package/dist/history/ai-history-view-type.js +1 -0
- package/dist/history/ai-history-view.d.ts +26 -0
- package/dist/history/ai-history-view.js +51 -0
- package/dist/history/conversation-history-tree.d.ts +15 -0
- package/dist/history/conversation-history-tree.js +71 -0
- package/dist/host/agent-workspace.d.ts +6 -0
- package/dist/host/agent-workspace.js +16 -0
- package/dist/host/create-host-runtimes.d.ts +2 -0
- package/dist/host/create-host-runtimes.js +14 -0
- package/dist/host/desktop-process-host.d.ts +6 -0
- package/dist/host/desktop-process-host.js +74 -0
- package/dist/host/host-runtime-availability.d.ts +1 -0
- package/dist/host/host-runtime-availability.js +3 -0
- package/dist/host/process-host.d.ts +31 -0
- package/dist/host/process-host.js +6 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +49 -0
- package/dist/jsonl/ai-jsonl-preview.d.ts +27 -0
- package/dist/jsonl/ai-jsonl-preview.js +68 -0
- package/dist/jsonl/ai-jsonl-view-type.d.ts +1 -0
- package/dist/jsonl/ai-jsonl-view-type.js +1 -0
- package/dist/jsonl/ai-jsonl-view.d.ts +16 -0
- package/dist/jsonl/ai-jsonl-view.js +57 -0
- package/dist/jsonl/ai-jsonl-view.svelte +260 -0
- package/dist/jsonl/ai-jsonl-view.svelte.d.ts +9 -0
- package/dist/memory/candidate-extractor.d.ts +25 -0
- package/dist/memory/candidate-extractor.js +191 -0
- package/dist/memory/forget-confirmation.d.ts +3 -0
- package/dist/memory/forget-confirmation.js +45 -0
- package/dist/memory/hashes.d.ts +5 -0
- package/dist/memory/hashes.js +37 -0
- package/dist/memory/memory-ingestion-coordinator.d.ts +19 -0
- package/dist/memory/memory-ingestion-coordinator.js +108 -0
- package/dist/memory/memory-record-store.d.ts +62 -0
- package/dist/memory/memory-record-store.js +369 -0
- package/dist/memory/memory-scheduler.d.ts +21 -0
- package/dist/memory/memory-scheduler.js +143 -0
- package/dist/memory/memory-tools.d.ts +61 -0
- package/dist/memory/memory-tools.js +99 -0
- package/dist/memory/native-memory-service.d.ts +72 -0
- package/dist/memory/native-memory-service.js +1256 -0
- package/dist/memory/paths.d.ts +13 -0
- package/dist/memory/paths.js +60 -0
- package/dist/memory/runtime-consolidation-provider.d.ts +18 -0
- package/dist/memory/runtime-consolidation-provider.js +154 -0
- package/dist/memory/types.d.ts +139 -0
- package/dist/memory/types.js +1 -0
- package/dist/providers/acp-model-provider.d.ts +11 -0
- package/dist/providers/acp-model-provider.js +99 -0
- package/dist/providers/codex-model-catalog.d.ts +7 -0
- package/dist/providers/codex-model-catalog.js +179 -0
- package/dist/providers/codex-model-provider.d.ts +12 -0
- package/dist/providers/codex-model-provider.js +42 -0
- package/dist/providers/model-provider.d.ts +26 -0
- package/dist/providers/model-provider.js +26 -0
- package/dist/public-components.d.ts +3 -0
- package/dist/public-components.js +3 -0
- package/dist/registry/runtime-registry.d.ts +11 -0
- package/dist/registry/runtime-registry.js +71 -0
- package/dist/registry/select-runtime.d.ts +9 -0
- package/dist/registry/select-runtime.js +31 -0
- package/dist/runtime-adapters.d.ts +16 -0
- package/dist/runtime-adapters.js +9 -0
- package/dist/runtimes/acp/acp-event-mapper.d.ts +56 -0
- package/dist/runtimes/acp/acp-event-mapper.js +237 -0
- package/dist/runtimes/acp/acp-runtime.d.ts +46 -0
- package/dist/runtimes/acp/acp-runtime.js +165 -0
- package/dist/runtimes/acp/desktop-acp-backend.d.ts +16 -0
- package/dist/runtimes/acp/desktop-acp-backend.js +243 -0
- package/dist/runtimes/codex/app-server-protocol.d.ts +28 -0
- package/dist/runtimes/codex/app-server-protocol.js +274 -0
- package/dist/runtimes/codex/codex-runtime.d.ts +24 -0
- package/dist/runtimes/codex/codex-runtime.js +318 -0
- package/dist/runtimes/fake/fake-runtime.d.ts +51 -0
- package/dist/runtimes/fake/fake-runtime.js +257 -0
- package/dist/sessions/plugin-data.d.ts +8 -0
- package/dist/sessions/plugin-data.js +29 -0
- package/dist/sessions/session-store.d.ts +47 -0
- package/dist/sessions/session-store.js +117 -0
- package/dist/settings/acp-agents.d.ts +8 -0
- package/dist/settings/acp-agents.js +11 -0
- package/dist/settings/ai-settings-tab.d.ts +8 -0
- package/dist/settings/ai-settings-tab.js +249 -0
- package/dist/settings/ai-settings.d.ts +43 -0
- package/dist/settings/ai-settings.js +147 -0
- package/dist/settings/app-tool-setting-rows.d.ts +16 -0
- package/dist/settings/app-tool-setting-rows.js +30 -0
- package/dist/settings/register-ai-settings.d.ts +3 -0
- package/dist/settings/register-ai-settings.js +393 -0
- package/dist/skills/activation.d.ts +2 -0
- package/dist/skills/activation.js +20 -0
- package/dist/skills/bundled/lapis-notes.d.ts +3 -0
- package/dist/skills/bundled/lapis-notes.js +52 -0
- package/dist/skills/bundled/research.d.ts +6 -0
- package/dist/skills/bundled/research.js +29 -0
- package/dist/skills/discovery.d.ts +21 -0
- package/dist/skills/discovery.js +227 -0
- package/dist/skills/manifest.d.ts +3 -0
- package/dist/skills/manifest.js +39 -0
- package/dist/skills/parser.d.ts +12 -0
- package/dist/skills/parser.js +124 -0
- package/dist/skills/registry.d.ts +21 -0
- package/dist/skills/registry.js +89 -0
- package/dist/skills/seed.d.ts +5 -0
- package/dist/skills/seed.js +18 -0
- package/dist/skills/skill-tools.d.ts +8 -0
- package/dist/skills/skill-tools.js +113 -0
- package/dist/skills/types.d.ts +67 -0
- package/dist/skills/types.js +1 -0
- package/dist/styles.css +514 -0
- package/dist/tools/app-tool-host.d.ts +47 -0
- package/dist/tools/app-tool-host.js +419 -0
- package/dist/tools/desktop-app-tool-bridge.d.ts +23 -0
- package/dist/tools/desktop-app-tool-bridge.js +223 -0
- package/dist/tools/mcp-server-registry.d.ts +7 -0
- package/dist/tools/mcp-server-registry.js +30 -0
- package/manifest.json +34 -0
- package/package.json +83 -0
- package/styles.css +1 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { sha256Text } from "./hashes";
|
|
2
|
+
import { memoryScopeKey } from "./paths";
|
|
3
|
+
const DEFAULT_IDLE_MS = 30 * 60 * 1_000;
|
|
4
|
+
const DEFAULT_DAILY_MS = 24 * 60 * 60 * 1_000;
|
|
5
|
+
const DEFAULT_LEASE_MS = 5 * 60 * 1_000;
|
|
6
|
+
export class MemoryMaintenanceScheduler {
|
|
7
|
+
database;
|
|
8
|
+
memory;
|
|
9
|
+
#ownerId;
|
|
10
|
+
#idleMs;
|
|
11
|
+
#dailyMs;
|
|
12
|
+
#leaseMs;
|
|
13
|
+
#now;
|
|
14
|
+
#onError;
|
|
15
|
+
#idleTimers = new Map();
|
|
16
|
+
#scopes = new Map();
|
|
17
|
+
#dailyTimer;
|
|
18
|
+
#disposed = false;
|
|
19
|
+
constructor(database, memory, options = {}) {
|
|
20
|
+
this.database = database;
|
|
21
|
+
this.memory = memory;
|
|
22
|
+
this.#ownerId = options.ownerId ?? crypto.randomUUID();
|
|
23
|
+
this.#idleMs = options.idleMs ?? DEFAULT_IDLE_MS;
|
|
24
|
+
this.#dailyMs = options.dailyMs ?? DEFAULT_DAILY_MS;
|
|
25
|
+
this.#leaseMs = options.leaseMs ?? DEFAULT_LEASE_MS;
|
|
26
|
+
this.#now = options.now ?? (() => Date.now());
|
|
27
|
+
this.#onError = options.onError ?? (() => { });
|
|
28
|
+
}
|
|
29
|
+
start() {
|
|
30
|
+
if (this.#disposed || this.#dailyTimer)
|
|
31
|
+
return;
|
|
32
|
+
this.#dailyTimer = setTimeout(() => void this.runDaily(), this.#dailyMs);
|
|
33
|
+
}
|
|
34
|
+
noteActivity(scope) {
|
|
35
|
+
if (this.#disposed)
|
|
36
|
+
return;
|
|
37
|
+
const key = memoryScopeKey(scope);
|
|
38
|
+
this.#scopes.set(key, scope);
|
|
39
|
+
const current = this.#idleTimers.get(key);
|
|
40
|
+
if (current)
|
|
41
|
+
clearTimeout(current);
|
|
42
|
+
this.#idleTimers.set(key, setTimeout(() => {
|
|
43
|
+
this.#idleTimers.delete(key);
|
|
44
|
+
void this.run(scope);
|
|
45
|
+
}, this.#idleMs));
|
|
46
|
+
}
|
|
47
|
+
async run(scope) {
|
|
48
|
+
if (this.#disposed)
|
|
49
|
+
return null;
|
|
50
|
+
const preview = await this.memory.previewConsolidation(scope);
|
|
51
|
+
if (preview.proposals === 0)
|
|
52
|
+
return null;
|
|
53
|
+
const now = this.#now();
|
|
54
|
+
const scopeKey = memoryScopeKey(scope);
|
|
55
|
+
const candidateFingerprint = (await sha256Text([...preview.candidateIds].sort().join("\n"))).slice(0, 16);
|
|
56
|
+
const job = {
|
|
57
|
+
id: `consolidate:${scopeKey}:${new Date(now).toISOString().slice(0, 10)}:${candidateFingerprint}`,
|
|
58
|
+
kind: "consolidate",
|
|
59
|
+
scopeKey,
|
|
60
|
+
status: "queued",
|
|
61
|
+
attempts: 0,
|
|
62
|
+
maxAttempts: 3,
|
|
63
|
+
createdAt: now,
|
|
64
|
+
};
|
|
65
|
+
const claimed = await this.database.claimMemoryJob({
|
|
66
|
+
job,
|
|
67
|
+
ownerId: this.#ownerId,
|
|
68
|
+
now,
|
|
69
|
+
leaseMs: this.#leaseMs,
|
|
70
|
+
});
|
|
71
|
+
if (!claimed)
|
|
72
|
+
return null;
|
|
73
|
+
const renew = setInterval(() => {
|
|
74
|
+
const renewedAt = this.#now();
|
|
75
|
+
void this.database.updateMemoryJob({
|
|
76
|
+
jobId: job.id,
|
|
77
|
+
ownerId: this.#ownerId,
|
|
78
|
+
now: renewedAt,
|
|
79
|
+
patch: {
|
|
80
|
+
status: "running",
|
|
81
|
+
leaseUntil: renewedAt + this.#leaseMs,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}, Math.max(1_000, Math.floor(this.#leaseMs / 2)));
|
|
85
|
+
try {
|
|
86
|
+
const result = await this.memory.consolidate(scope);
|
|
87
|
+
await this.database.updateMemoryJob({
|
|
88
|
+
jobId: job.id,
|
|
89
|
+
ownerId: this.#ownerId,
|
|
90
|
+
now: this.#now(),
|
|
91
|
+
patch: { status: "completed", finishedAt: this.#now() },
|
|
92
|
+
});
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
await this.database.updateMemoryJob({
|
|
97
|
+
jobId: job.id,
|
|
98
|
+
ownerId: this.#ownerId,
|
|
99
|
+
now: this.#now(),
|
|
100
|
+
patch: {
|
|
101
|
+
status: "failed",
|
|
102
|
+
finishedAt: this.#now(),
|
|
103
|
+
errorCode: "consolidation-failed",
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
this.#onError("consolidate", scope, error);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
clearInterval(renew);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
dispose() {
|
|
114
|
+
this.#disposed = true;
|
|
115
|
+
if (this.#dailyTimer)
|
|
116
|
+
clearTimeout(this.#dailyTimer);
|
|
117
|
+
this.#dailyTimer = undefined;
|
|
118
|
+
for (const timer of this.#idleTimers.values())
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
this.#idleTimers.clear();
|
|
121
|
+
this.#scopes.clear();
|
|
122
|
+
}
|
|
123
|
+
async runDaily() {
|
|
124
|
+
this.#dailyTimer = undefined;
|
|
125
|
+
if (this.#disposed)
|
|
126
|
+
return;
|
|
127
|
+
for (const candidate of await this.database.queryMemoryCandidates({
|
|
128
|
+
states: ["staged"],
|
|
129
|
+
limit: 10_000,
|
|
130
|
+
})) {
|
|
131
|
+
const scope = candidate.candidate.scopeKind === "project"
|
|
132
|
+
? {
|
|
133
|
+
kind: "project",
|
|
134
|
+
projectDir: candidate.candidate.scopePath,
|
|
135
|
+
}
|
|
136
|
+
: { kind: candidate.candidate.scopeKind };
|
|
137
|
+
this.#scopes.set(memoryScopeKey(scope), scope);
|
|
138
|
+
}
|
|
139
|
+
for (const scope of this.#scopes.values())
|
|
140
|
+
await this.run(scope);
|
|
141
|
+
this.start();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AppTool } from "@lapis-notes/api/agent-tools";
|
|
2
|
+
import type { MemoryService } from "./types";
|
|
3
|
+
export declare function createMemoryAppTools(service: MemoryService): AppTool[];
|
|
4
|
+
export declare const MEMORY_APP_TOOL_SCHEMAS: {
|
|
5
|
+
memorySearch: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly additionalProperties: false;
|
|
8
|
+
readonly required: readonly ["query"];
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly query: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly minLength: 1;
|
|
13
|
+
readonly maxLength: 2000;
|
|
14
|
+
};
|
|
15
|
+
readonly scope: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
readonly enum: readonly ["current", "workspace"];
|
|
18
|
+
};
|
|
19
|
+
readonly corpus: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
readonly enum: readonly ["curated", "episodic", "all"];
|
|
22
|
+
};
|
|
23
|
+
readonly limit: {
|
|
24
|
+
readonly type: "integer";
|
|
25
|
+
readonly minimum: 1;
|
|
26
|
+
readonly maximum: 20;
|
|
27
|
+
};
|
|
28
|
+
readonly since: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly minLength: 10;
|
|
31
|
+
readonly maxLength: 64;
|
|
32
|
+
};
|
|
33
|
+
readonly before: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
readonly minLength: 10;
|
|
36
|
+
readonly maxLength: 64;
|
|
37
|
+
};
|
|
38
|
+
readonly includeSuperseded: {
|
|
39
|
+
readonly type: "boolean";
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
memoryGet: {
|
|
44
|
+
readonly type: "object";
|
|
45
|
+
readonly additionalProperties: false;
|
|
46
|
+
readonly required: readonly ["ref"];
|
|
47
|
+
readonly properties: {
|
|
48
|
+
readonly ref: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly minLength: 1;
|
|
51
|
+
readonly maxLength: 512;
|
|
52
|
+
};
|
|
53
|
+
readonly includeEvidence: {
|
|
54
|
+
readonly type: "boolean";
|
|
55
|
+
};
|
|
56
|
+
readonly includeHistory: {
|
|
57
|
+
readonly type: "boolean";
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const MEMORY_SEARCH_INPUT_SCHEMA = {
|
|
2
|
+
type: "object",
|
|
3
|
+
additionalProperties: false,
|
|
4
|
+
required: ["query"],
|
|
5
|
+
properties: {
|
|
6
|
+
query: { type: "string", minLength: 1, maxLength: 2_000 },
|
|
7
|
+
scope: { type: "string", enum: ["current", "workspace"] },
|
|
8
|
+
corpus: { type: "string", enum: ["curated", "episodic", "all"] },
|
|
9
|
+
limit: { type: "integer", minimum: 1, maximum: 20 },
|
|
10
|
+
since: { type: "string", minLength: 10, maxLength: 64 },
|
|
11
|
+
before: { type: "string", minLength: 10, maxLength: 64 },
|
|
12
|
+
includeSuperseded: { type: "boolean" },
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
const MEMORY_GET_INPUT_SCHEMA = {
|
|
16
|
+
type: "object",
|
|
17
|
+
additionalProperties: false,
|
|
18
|
+
required: ["ref"],
|
|
19
|
+
properties: {
|
|
20
|
+
ref: { type: "string", minLength: 1, maxLength: 512 },
|
|
21
|
+
includeEvidence: { type: "boolean" },
|
|
22
|
+
includeHistory: { type: "boolean" },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export function createMemoryAppTools(service) {
|
|
26
|
+
return [createMemorySearchTool(service), createMemoryGetTool(service)];
|
|
27
|
+
}
|
|
28
|
+
function createMemorySearchTool(service) {
|
|
29
|
+
return {
|
|
30
|
+
name: "memory_search",
|
|
31
|
+
description: "Search app-owned durable and episodic memory in the current vault. Returns compact results with provenance references; use memory_get for exact evidence.",
|
|
32
|
+
inputSchema: structuredClone(MEMORY_SEARCH_INPUT_SCHEMA),
|
|
33
|
+
outputSchema: { type: "object" },
|
|
34
|
+
effect: "read",
|
|
35
|
+
execute: async (input, context) => {
|
|
36
|
+
context.signal.throwIfAborted();
|
|
37
|
+
const query = {
|
|
38
|
+
query: input.query,
|
|
39
|
+
...(input.scope ? { scope: input.scope } : {}),
|
|
40
|
+
...(input.corpus ? { corpus: input.corpus } : {}),
|
|
41
|
+
...(input.limit ? { limit: input.limit } : {}),
|
|
42
|
+
...(input.since ? { since: input.since } : {}),
|
|
43
|
+
...(input.before ? { before: input.before } : {}),
|
|
44
|
+
...(input.includeSuperseded !== undefined
|
|
45
|
+
? { includeSuperseded: input.includeSuperseded }
|
|
46
|
+
: {}),
|
|
47
|
+
};
|
|
48
|
+
const results = await service.search(query, memoryContext(context), context.signal);
|
|
49
|
+
context.signal.throwIfAborted();
|
|
50
|
+
const structuredContent = { results };
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: results.length === 0
|
|
56
|
+
? "No matching memory found."
|
|
57
|
+
: JSON.stringify(results, null, 2),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
structuredContent,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function createMemoryGetTool(service) {
|
|
66
|
+
return {
|
|
67
|
+
name: "memory_get",
|
|
68
|
+
description: "Resolve one opaque memory reference and verify its original transcript evidence without returning a complete transcript.",
|
|
69
|
+
inputSchema: structuredClone(MEMORY_GET_INPUT_SCHEMA),
|
|
70
|
+
outputSchema: { type: "object" },
|
|
71
|
+
effect: "read",
|
|
72
|
+
execute: async (input, context) => {
|
|
73
|
+
context.signal.throwIfAborted();
|
|
74
|
+
const detail = await service.get(input.ref, memoryContext(context), context.signal);
|
|
75
|
+
const projected = {
|
|
76
|
+
...detail,
|
|
77
|
+
evidenceMessages: input.includeEvidence === false ? [] : detail.evidenceMessages.slice(0, 6),
|
|
78
|
+
history: input.includeHistory ? detail.history : undefined,
|
|
79
|
+
};
|
|
80
|
+
const structuredContent = JSON.parse(JSON.stringify(projected));
|
|
81
|
+
return {
|
|
82
|
+
content: [{ type: "text", text: JSON.stringify(projected, null, 2) }],
|
|
83
|
+
structuredContent,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function memoryContext(context) {
|
|
89
|
+
return {
|
|
90
|
+
scopeDir: context.scope.directory,
|
|
91
|
+
conversationId: context.conversationId,
|
|
92
|
+
agentBindingId: context.agentBindingId,
|
|
93
|
+
runId: context.runId,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export const MEMORY_APP_TOOL_SCHEMAS = {
|
|
97
|
+
memorySearch: MEMORY_SEARCH_INPUT_SCHEMA,
|
|
98
|
+
memoryGet: MEMORY_GET_INPUT_SCHEMA,
|
|
99
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { AppDatabase } from "@lapis-notes/api";
|
|
2
|
+
import type { ConversationRepository } from "../conversations/conversation-repository";
|
|
3
|
+
import type { AgentContextBlock } from "../core/types";
|
|
4
|
+
import type { ConversationLocation, ConversationSnapshot, TranscriptEntry } from "../conversations/types";
|
|
5
|
+
import { type MemoryRecordStore } from "./memory-record-store";
|
|
6
|
+
import type { ConsolidationPreview, ConsolidationResult, MemoryContext, MemoryDetail, MemoryOriginClass, MemoryRebuildResult, MemoryForgetPreview, MemoryForgetResult, MemoryScope, MemorySearchQuery, MemorySearchResult, MemoryService, MemoryConsolidationProvider } from "./types";
|
|
7
|
+
type RankedEpisode = {
|
|
8
|
+
path: string;
|
|
9
|
+
result: MemorySearchResult;
|
|
10
|
+
retrievalScore: number;
|
|
11
|
+
};
|
|
12
|
+
export type NativeMemoryServiceOptions = {
|
|
13
|
+
now?: () => Date;
|
|
14
|
+
yieldToApp?: () => Promise<void>;
|
|
15
|
+
recordStore?: MemoryRecordStore;
|
|
16
|
+
consolidationProvider?: MemoryConsolidationProvider | (() => MemoryConsolidationProvider | undefined);
|
|
17
|
+
};
|
|
18
|
+
export declare class NativeMemoryService implements MemoryService {
|
|
19
|
+
#private;
|
|
20
|
+
private readonly repository;
|
|
21
|
+
private readonly database;
|
|
22
|
+
constructor(repository: ConversationRepository, database: AppDatabase, options?: NativeMemoryServiceOptions);
|
|
23
|
+
ingestConversation(location: ConversationLocation): Promise<void>;
|
|
24
|
+
search(query: MemorySearchQuery, context: MemoryContext, signal?: AbortSignal): Promise<MemorySearchResult[]>;
|
|
25
|
+
recall(query: string, context: MemoryContext, signal?: AbortSignal): Promise<AgentContextBlock[]>;
|
|
26
|
+
get(ref: string, _context: MemoryContext, signal?: AbortSignal): Promise<MemoryDetail>;
|
|
27
|
+
rebuild(scope?: MemoryScope): Promise<MemoryRebuildResult>;
|
|
28
|
+
previewForgetConversation(location: ConversationLocation): Promise<MemoryForgetPreview>;
|
|
29
|
+
forgetConversation(location: ConversationLocation): Promise<MemoryForgetResult>;
|
|
30
|
+
previewConsolidation(scope: MemoryScope): Promise<ConsolidationPreview>;
|
|
31
|
+
consolidate(scope: MemoryScope): Promise<ConsolidationResult>;
|
|
32
|
+
private markInconsistent;
|
|
33
|
+
private removeStaleConversationDocuments;
|
|
34
|
+
private curatedSearchDocument;
|
|
35
|
+
private verifyEvidence;
|
|
36
|
+
private getCurated;
|
|
37
|
+
private resolveCandidateEvidence;
|
|
38
|
+
private markCandidatePromoted;
|
|
39
|
+
private writeConsolidationReview;
|
|
40
|
+
private recordRecallSignals;
|
|
41
|
+
}
|
|
42
|
+
type ProjectedEpisode = {
|
|
43
|
+
entry: Extract<TranscriptEntry, {
|
|
44
|
+
type: "message" | "tool";
|
|
45
|
+
}>;
|
|
46
|
+
entryHash: string;
|
|
47
|
+
text: string;
|
|
48
|
+
originClass: MemoryOriginClass;
|
|
49
|
+
};
|
|
50
|
+
declare function projectEpisodes(snapshot: ConversationSnapshot): Promise<ProjectedEpisode[]>;
|
|
51
|
+
declare function episodeRef(conversationId: string, entryId: string): string;
|
|
52
|
+
declare function curatedRef(id: string, revision: number): string;
|
|
53
|
+
declare function parseCuratedRef(ref: string): {
|
|
54
|
+
id: string;
|
|
55
|
+
revision: number;
|
|
56
|
+
} | null;
|
|
57
|
+
declare function parseEpisodeRef(ref: string): {
|
|
58
|
+
conversationId: string;
|
|
59
|
+
entryId: string;
|
|
60
|
+
} | null;
|
|
61
|
+
declare function selectMmr(candidates: RankedEpisode[], limit: number): RankedEpisode[];
|
|
62
|
+
declare function contradictory(current: string, proposed: string): boolean;
|
|
63
|
+
export declare const __memoryServiceInternals: {
|
|
64
|
+
contradictory: typeof contradictory;
|
|
65
|
+
curatedRef: typeof curatedRef;
|
|
66
|
+
episodeRef: typeof episodeRef;
|
|
67
|
+
parseCuratedRef: typeof parseCuratedRef;
|
|
68
|
+
parseEpisodeRef: typeof parseEpisodeRef;
|
|
69
|
+
projectEpisodes: typeof projectEpisodes;
|
|
70
|
+
selectMmr: typeof selectMmr;
|
|
71
|
+
};
|
|
72
|
+
export {};
|