Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
441 changes: 441 additions & 0 deletions public/dashboard/dashboard.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@
var name = parsed.route;
deactivateAllRoutes();

var liveRoutes = ["skills", "memory-files", "plugins", "subagents", "hooks", "settings", "sessions", "cost", "scheduler"];
var comingSoon = ["evolution", "memory"];
var liveRoutes = ["skills", "memory-files", "plugins", "subagents", "hooks", "settings", "sessions", "cost", "scheduler", "evolution", "memory"];
var comingSoon = [];

if (liveRoutes.indexOf(name) >= 0 && routes[name]) {
var containerId = "route-" + name;
Expand Down
634 changes: 634 additions & 0 deletions public/dashboard/evolution.js

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions public/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,18 @@
<svg class="dash-sidebar-icon" fill="none" viewBox="0 0 24 24" stroke-width="1.6" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.25 18 9 11.25l4.306 4.306a11.95 11.95 0 0 1 5.814-5.518l2.74-1.22m0 0-5.94-2.281m5.94 2.28-2.28 5.941"/></svg>
<span>Cost</span>
</a>
</nav>

<div class="dash-sidebar-eyebrow" style="margin-top:var(--space-5);">Coming soon</div>
<nav class="dash-sidebar-nav">
<a href="#/evolution" class="dash-sidebar-item dash-sidebar-item-soon" data-route="evolution">
<a href="#/evolution" class="dash-sidebar-item" data-route="evolution">
<svg class="dash-sidebar-icon" fill="none" viewBox="0 0 24 24" stroke-width="1.6" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"/></svg>
<span>Evolution</span>
<span class="dash-sidebar-soon-pill">soon</span>
</a>
<a href="#/memory" class="dash-sidebar-item dash-sidebar-item-soon" data-route="memory">
<a href="#/memory" class="dash-sidebar-item" data-route="memory">
<svg class="dash-sidebar-icon" fill="none" viewBox="0 0 24 24" stroke-width="1.6" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M8.25 7.5V6.108c0-1.135.845-2.098 1.976-2.192.373-.03.748-.057 1.123-.08M15.75 18H18a2.25 2.25 0 0 0 2.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 0 0-1.123-.08M15.75 18.75v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5A3.375 3.375 0 0 0 6.375 7.5H5.25m11.9-3.664A2.251 2.251 0 0 0 15 2.25h-1.5a2.251 2.251 0 0 0-2.15 1.586m5.8 0c.065.21.1.433.1.664v.75h-6V4.5c0-.231.035-.454.1-.664M6.75 7.5H4.875c-.621 0-1.125.504-1.125 1.125v12c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V16.5a9 9 0 0 0-9-9Z"/></svg>
<span>Memory explorer</span>
<span class="dash-sidebar-soon-pill">soon</span>
</a>
</nav>

<div class="dash-sidebar-footer">
<p class="phantom-meta">Dashboard PR3</p>
<p class="phantom-meta">Dashboard PR5</p>
<p class="phantom-meta">Hand-crafted, not agent-generated.</p>
</div>
</aside>
Expand All @@ -104,6 +98,8 @@
<div id="route-sessions" class="dash-route" hidden></div>
<div id="route-cost" class="dash-route" hidden></div>
<div id="route-scheduler" class="dash-route" hidden></div>
<div id="route-evolution" class="dash-route" hidden></div>
<div id="route-memory" class="dash-route" hidden></div>
<div id="route-soon" class="dash-route" hidden></div>
</main>

Expand All @@ -121,6 +117,8 @@
<script src="/ui/dashboard/sessions.js"></script>
<script src="/ui/dashboard/cost.js"></script>
<script src="/ui/dashboard/scheduler.js"></script>
<script src="/ui/dashboard/evolution.js"></script>
<script src="/ui/dashboard/memory.js"></script>
<script>window.PhantomDashboard.init();</script>
</body>
</html>
582 changes: 582 additions & 0 deletions public/dashboard/memory.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ import { closePreviewResources, createPreviewToolServer, getOrCreatePreviewConte
import {
setBootstrapDb,
setDashboardDb,
setEvolutionEngine,
setEvolutionQueue,
setMemorySystem,
setPublicDir,
setSchedulerInstance,
setSecretSavedCallback,
Expand Down Expand Up @@ -112,6 +115,7 @@ async function main(): Promise<void> {
await memory.initialize();

setMemoryHealthProvider(() => memory.healthCheck());
setMemorySystem(memory);

// Runtime is created before evolution so we can wire it into the engine.
// Evolution judges run through the same Agent SDK subprocess as the main
Expand All @@ -136,6 +140,8 @@ async function main(): Promise<void> {
const cadenceConfig = loadCadenceConfig(engine.getEvolutionConfig());
evolutionCadence = new EvolutionCadence(engine, queue, engine.getEvolutionConfig(), cadenceConfig);
engine.setQueueWiring(queue, () => evolutionCadence?.onEnqueue());
setEvolutionEngine(engine);
setEvolutionQueue(queue);
// The cadence drains the queue out-of-band, so the runtime's in-memory
// evolved config snapshot must be refreshed from disk after each
// applied change. Without this callback the queued path would rewrite
Expand Down
171 changes: 171 additions & 0 deletions src/memory/__tests__/qdrant-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,175 @@ describe("QdrantClient", () => {
expect(deleteBody).not.toBeNull();
expect(deleteBody.points).toEqual(["point-123"]);
});

test("scroll sends POST to points/scroll with limit and with_payload defaults", async () => {
let capturedUrl = "";
let capturedBody: Record<string, unknown> | null = null;
globalThis.fetch = mock((url: string | Request, init?: RequestInit) => {
capturedUrl = typeof url === "string" ? url : url.url;
if (init?.body) capturedBody = JSON.parse(init.body as string);
return Promise.resolve(
new Response(
JSON.stringify({
result: {
points: [{ id: "p1", payload: { a: 1 } }],
next_page_offset: "cursor-1",
},
status: "ok",
}),
{ status: 200, headers: { "Content-Type": "application/json" } },
),
);
}) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
const res = await client.scroll("episodes", { limit: 20 });

expect(capturedUrl).toContain("/collections/episodes/points/scroll");
const body = capturedBody as unknown as Record<string, unknown>;
expect(body.limit).toBe(20);
expect(body.with_payload).toBe(true);
expect(body.offset).toBeUndefined();
expect(body.filter).toBeUndefined();
expect(body.order_by).toBeUndefined();
expect(res.points.length).toBe(1);
expect(res.points[0].id).toBe("p1");
expect(res.points[0].score).toBe(0);
expect(res.points[0].payload.a).toBe(1);
expect(res.nextOffset).toBe("cursor-1");
});

test("scroll passes offset, filter, and order_by through", async () => {
let capturedBody: Record<string, unknown> | null = null;
globalThis.fetch = mock((_url: string | Request, init?: RequestInit) => {
if (init?.body) capturedBody = JSON.parse(init.body as string);
return Promise.resolve(
new Response(JSON.stringify({ result: { points: [], next_page_offset: null } }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
}) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
await client.scroll("facts", {
limit: 10,
offset: "cursor-abc",
filter: { must: [{ key: "category", match: { value: "domain_knowledge" } }] },
orderBy: { key: "valid_from", direction: "desc" },
withPayload: true,
});

const body = capturedBody as unknown as Record<string, unknown>;
expect(body.limit).toBe(10);
expect(body.offset).toBe("cursor-abc");
expect((body.order_by as Record<string, string>).key).toBe("valid_from");
expect((body.order_by as Record<string, string>).direction).toBe("desc");
const filter = body.filter as { must: Array<Record<string, unknown>> };
expect(filter.must[0].key).toBe("category");
});

test("scroll returns nextOffset null when response lacks cursor", async () => {
globalThis.fetch = mock(() =>
Promise.resolve(
new Response(JSON.stringify({ result: { points: [{ id: 42, payload: {} }] } }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
),
) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
const res = await client.scroll("episodes", { limit: 5 });
expect(res.nextOffset).toBeNull();
expect(res.points[0].id).toBe("42");
});

test("scroll paginates through pages", async () => {
const pages = [
{ result: { points: [{ id: "a", payload: {} }], next_page_offset: "cursor-2" } },
{ result: { points: [{ id: "b", payload: {} }], next_page_offset: null } },
];
let call = 0;
globalThis.fetch = mock(() => {
const body = pages[call];
call += 1;
return Promise.resolve(
new Response(JSON.stringify(body), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
}) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
const page1 = await client.scroll("episodes", { limit: 1 });
expect(page1.nextOffset).toBe("cursor-2");
const page2 = await client.scroll("episodes", { limit: 1, offset: page1.nextOffset as string });
expect(page2.nextOffset).toBeNull();
expect(page2.points[0].id).toBe("b");
});

test("scroll throws on Qdrant error", async () => {
globalThis.fetch = mock(() => Promise.resolve(new Response("boom", { status: 500 }))) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
await expect(client.scroll("episodes", { limit: 5 })).rejects.toThrow(/scroll/);
});

test("scroll with_payload=false sends the override", async () => {
let capturedBody: Record<string, unknown> | null = null;
globalThis.fetch = mock((_url: string | Request, init?: RequestInit) => {
if (init?.body) capturedBody = JSON.parse(init.body as string);
return Promise.resolve(
new Response(JSON.stringify({ result: { points: [], next_page_offset: null } }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
}) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
await client.scroll("episodes", { limit: 5, withPayload: false });
expect(capturedBody).not.toBeNull();
const body = capturedBody as unknown as Record<string, unknown>;
expect(body.with_payload).toBe(false);
});

test("countPoints returns the count from the exact response", async () => {
let capturedUrl = "";
let capturedBody: Record<string, unknown> | null = null;
globalThis.fetch = mock((url: string | Request, init?: RequestInit) => {
capturedUrl = typeof url === "string" ? url : url.url;
if (init?.body) capturedBody = JSON.parse(init.body as string);
return Promise.resolve(
new Response(JSON.stringify({ result: { count: 412 } }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
}) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
const n = await client.countPoints("episodes");
expect(n).toBe(412);
expect(capturedUrl).toContain("/collections/episodes/points/count");
expect(capturedBody).not.toBeNull();
const countBody = capturedBody as unknown as Record<string, unknown>;
expect(countBody.exact).toBe(true);
});

test("countPoints returns 0 when result is missing", async () => {
globalThis.fetch = mock(() =>
Promise.resolve(
new Response(JSON.stringify({ status: "ok" }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
),
) as unknown as typeof fetch;

const client = new QdrantClient(TEST_CONFIG);
expect(await client.countPoints("episodes")).toBe(0);
});
});
31 changes: 31 additions & 0 deletions src/memory/episodic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,37 @@ export class EpisodicStore {
.sort((a, b) => b.score - a.score);
}

async scroll(opts: {
limit: number;
offset?: string | number;
}): Promise<{ items: Episode[]; nextOffset: string | number | null }> {
const { points, nextOffset } = await this.qdrant.scroll(this.collectionName, {
limit: opts.limit,
offset: opts.offset,
orderBy: { key: "started_at", direction: "desc" },
withPayload: true,
});
return { items: points.map((p) => this.payloadToEpisode(p)), nextOffset };
}

async getById(id: string): Promise<Episode | null> {
const { points } = await this.qdrant.scroll(this.collectionName, {
limit: 1,
filter: { must: [{ has_id: [id] }] },
withPayload: true,
});
if (points.length === 0) return null;
return this.payloadToEpisode(points[0]);
}

async deleteById(id: string): Promise<void> {
await this.qdrant.deletePoint(this.collectionName, id);
}

async count(): Promise<number> {
return this.qdrant.countPoints(this.collectionName);
}

private payloadToEpisode(result: QdrantSearchResult): Episode {
const p = result.payload;
return {
Expand Down
31 changes: 31 additions & 0 deletions src/memory/procedural.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ export class ProceduralStore {
});
}

async scroll(opts: {
limit: number;
offset?: string | number;
}): Promise<{ items: Procedure[]; nextOffset: string | number | null }> {
const { points, nextOffset } = await this.qdrant.scroll(this.collectionName, {
limit: opts.limit,
offset: opts.offset,
orderBy: { key: "last_used_at", direction: "desc" },
withPayload: true,
});
return { items: points.map((p) => this.payloadToProcedure(p)), nextOffset };
}

async getById(id: string): Promise<Procedure | null> {
const { points } = await this.qdrant.scroll(this.collectionName, {
limit: 1,
filter: { must: [{ has_id: [id] }] },
withPayload: true,
});
if (points.length === 0) return null;
return this.payloadToProcedure(points[0]);
}

async deleteById(id: string): Promise<void> {
await this.qdrant.deletePoint(this.collectionName, id);
}

async count(): Promise<number> {
return this.qdrant.countPoints(this.collectionName);
}

private payloadToProcedure(result: QdrantSearchResult): Procedure {
const p = result.payload;
return {
Expand Down
42 changes: 42 additions & 0 deletions src/memory/qdrant-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,48 @@ export class QdrantClient {
});
}

async scroll(
collection: string,
opts: {
limit: number;
offset?: string | number;
filter?: Record<string, unknown>;
orderBy?: { key: string; direction: "asc" | "desc" };
withPayload?: boolean;
},
): Promise<{ points: QdrantSearchResult[]; nextOffset: string | number | null }> {
const body: Record<string, unknown> = {
limit: opts.limit,
with_payload: opts.withPayload ?? true,
};
if (opts.offset !== undefined) body.offset = opts.offset;
if (opts.filter) body.filter = opts.filter;
if (opts.orderBy) body.order_by = { key: opts.orderBy.key, direction: opts.orderBy.direction };

const response = (await this.request("POST", `/collections/${collection}/points/scroll`, body)) as {
result?: {
points?: Array<{ id: string | number; payload?: Record<string, unknown>; vector?: unknown }>;
next_page_offset?: string | number | null;
};
};

const rawPoints = response.result?.points ?? [];
const points: QdrantSearchResult[] = rawPoints.map((p) => ({
id: String(p.id),
score: 0,
payload: p.payload ?? {},
}));
const nextOffset = response.result?.next_page_offset ?? null;
return { points, nextOffset };
}

async countPoints(collection: string, exact = true): Promise<number> {
const response = (await this.request("POST", `/collections/${collection}/points/count`, {
exact,
})) as { result?: { count?: number } };
return response.result?.count ?? 0;
}

async updatePayload(collection: string, id: string, payload: Record<string, unknown>): Promise<void> {
await this.request("POST", `/collections/${collection}/points/payload`, {
payload,
Expand Down
Loading
Loading