



















@@ -48,6 +48,12 @@ type MemoryEntry = {
4848createdAt: number;
4949};
505051+type MemoryListEntry = Omit<MemoryEntry, "vector">;
52+53+type MemoryListOptions = {
54+orderByCreatedAt?: boolean;
55+};
56+5157type MemorySearchResult = {
5258entry: MemoryEntry;
5359score: number;
@@ -151,6 +157,17 @@ function resolveAutoCaptureStartIndex(
151157const TABLE_NAME = "memories";
152158const DEFAULT_AUTO_RECALL_TIMEOUT_MS = 15_000;
153159160+function parsePositiveIntegerOption(value: string | undefined, flag: string): number | undefined {
161+if (value === undefined) {
162+return undefined;
163+}
164+const parsed = Number(value);
165+if (!Number.isInteger(parsed) || parsed < 1) {
166+throw new Error(`${flag} must be a positive integer`);
167+}
168+return parsed;
169+}
170+154171class MemoryDB {
155172private db: LanceDB.Connection | null = null;
156173private table: LanceDB.Table | null = null;
@@ -241,6 +258,31 @@ class MemoryDB {
241258return mapped.filter((r) => r.score >= minScore);
242259}
243260261+async list(limit?: number, options: MemoryListOptions = {}): Promise<MemoryListEntry[]> {
262+await this.ensureInitialized();
263+264+let query = this.table!.query().select(["id", "text", "importance", "category", "createdAt"]);
265+// Push limit to LanceDB only when we don't need to sort in-memory.
266+if (!options.orderByCreatedAt && limit !== undefined) {
267+query = query.limit(limit);
268+}
269+270+const rows = await query.toArray();
271+272+const entries = rows.map((row) => ({
273+id: row.id as string,
274+text: row.text as string,
275+importance: row.importance as number,
276+category: row.category as MemoryEntry["category"],
277+createdAt: row.createdAt as number,
278+}));
279+if (options.orderByCreatedAt) {
280+entries.sort((a, b) => b.createdAt - a.createdAt);
281+}
282+283+return limit === undefined ? entries : entries.slice(0, limit);
284+}
285+244286async delete(id: string): Promise<boolean> {
245287await this.ensureInitialized();
246288// Validate UUID format to prevent injection
@@ -797,9 +839,14 @@ export default definePluginEntry({
797839memory
798840.command("list")
799841.description("List memories")
800-.action(async () => {
801-const count = await db.count();
802-console.log(`Total memories: ${count}`);
842+.option("--limit <n>", "Max results")
843+.option("--order-by-created-at", "Order memories by createdAt descending", false)
844+.action(async (opts) => {
845+const limit = parsePositiveIntegerOption(opts.limit, "--limit");
846+const entries = await db.list(limit, {
847+orderByCreatedAt: Boolean(opts.orderByCreatedAt),
848+});
849+console.log(JSON.stringify(entries, null, 2));
803850});
804851805852memory
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。