Compare commits
1 Commits
feat/mosai
...
6553f16d42
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6553f16d42 |
@@ -22,8 +22,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mosaicstack/db": "workspace:^",
|
"@mosaicstack/db": "workspace:^",
|
||||||
"@mosaicstack/types": "workspace:*",
|
"@mosaicstack/types": "workspace:*"
|
||||||
"commander": "^13.0.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.8.0",
|
"typescript": "^5.8.0",
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
|
||||||
import { Command } from 'commander';
|
|
||||||
import { registerBrainCommand } from './cli.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smoke test: verifies the command tree is correctly registered.
|
|
||||||
* No database connection is opened — we only inspect Commander metadata.
|
|
||||||
*/
|
|
||||||
describe('registerBrainCommand', () => {
|
|
||||||
function buildProgram(): Command {
|
|
||||||
const program = new Command('mosaic');
|
|
||||||
// Prevent Commander from calling process.exit on parse errors during tests.
|
|
||||||
program.exitOverride();
|
|
||||||
registerBrainCommand(program);
|
|
||||||
return program;
|
|
||||||
}
|
|
||||||
|
|
||||||
it('registers a top-level "brain" command', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain');
|
|
||||||
expect(brainCmd).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('registers "brain projects" with "list" and "create" subcommands', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const projectsCmd = brainCmd.commands.find((c) => c.name() === 'projects');
|
|
||||||
expect(projectsCmd).toBeDefined();
|
|
||||||
|
|
||||||
const subNames = projectsCmd!.commands.map((c) => c.name());
|
|
||||||
expect(subNames).toContain('list');
|
|
||||||
expect(subNames).toContain('create');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('registers "brain missions" with "list" subcommand', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const missionsCmd = brainCmd.commands.find((c) => c.name() === 'missions');
|
|
||||||
expect(missionsCmd).toBeDefined();
|
|
||||||
|
|
||||||
const subNames = missionsCmd!.commands.map((c) => c.name());
|
|
||||||
expect(subNames).toContain('list');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('registers "brain tasks" with "list" subcommand', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const tasksCmd = brainCmd.commands.find((c) => c.name() === 'tasks');
|
|
||||||
expect(tasksCmd).toBeDefined();
|
|
||||||
|
|
||||||
const subNames = tasksCmd!.commands.map((c) => c.name());
|
|
||||||
expect(subNames).toContain('list');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('registers "brain conversations" with "list" subcommand', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const conversationsCmd = brainCmd.commands.find((c) => c.name() === 'conversations');
|
|
||||||
expect(conversationsCmd).toBeDefined();
|
|
||||||
|
|
||||||
const subNames = conversationsCmd!.commands.map((c) => c.name());
|
|
||||||
expect(subNames).toContain('list');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('"brain projects list" accepts --db and --limit options', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const projectsCmd = brainCmd.commands.find((c) => c.name() === 'projects')!;
|
|
||||||
const listCmd = projectsCmd.commands.find((c) => c.name() === 'list')!;
|
|
||||||
|
|
||||||
const optionNames = listCmd.options.map((o) => o.long);
|
|
||||||
expect(optionNames).toContain('--db');
|
|
||||||
expect(optionNames).toContain('--limit');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('"brain missions list" accepts --project option', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const missionsCmd = brainCmd.commands.find((c) => c.name() === 'missions')!;
|
|
||||||
const listCmd = missionsCmd.commands.find((c) => c.name() === 'list')!;
|
|
||||||
|
|
||||||
const optionNames = listCmd.options.map((o) => o.long);
|
|
||||||
expect(optionNames).toContain('--project');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('"brain tasks list" accepts --project option', () => {
|
|
||||||
const program = buildProgram();
|
|
||||||
const brainCmd = program.commands.find((c) => c.name() === 'brain')!;
|
|
||||||
const tasksCmd = brainCmd.commands.find((c) => c.name() === 'tasks')!;
|
|
||||||
const listCmd = tasksCmd.commands.find((c) => c.name() === 'list')!;
|
|
||||||
|
|
||||||
const optionNames = listCmd.options.map((o) => o.long);
|
|
||||||
expect(optionNames).toContain('--project');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
import type { Command } from 'commander';
|
|
||||||
import { createDb, type DbHandle } from '@mosaicstack/db';
|
|
||||||
import { createBrain } from './brain.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build and attach the `brain` subcommand tree onto an existing Commander program.
|
|
||||||
* Uses the caller's Command instance to avoid cross-package Commander version mismatches.
|
|
||||||
*/
|
|
||||||
export function registerBrainCommand(parent: Command): void {
|
|
||||||
const brain = parent.command('brain').description('Inspect and manage brain data stores');
|
|
||||||
|
|
||||||
// ─── shared DB option helper ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
function addDbOption(cmd: Command): Command {
|
|
||||||
return cmd.option(
|
|
||||||
'--db <connection-string>',
|
|
||||||
'PostgreSQL connection string (overrides MOSAIC_DB_URL)',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveDb(opts: { db?: string }): ReturnType<typeof createBrain> {
|
|
||||||
const connectionString = opts.db ?? process.env['MOSAIC_DB_URL'];
|
|
||||||
if (!connectionString) {
|
|
||||||
console.error('No DB connection string provided. Pass --db <url> or set MOSAIC_DB_URL.');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
const handle: DbHandle = createDb(connectionString);
|
|
||||||
return createBrain(handle.db);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── projects ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const projects = brain.command('projects').description('Manage projects');
|
|
||||||
|
|
||||||
addDbOption(
|
|
||||||
projects
|
|
||||||
.command('list')
|
|
||||||
.description('List all projects')
|
|
||||||
.option('--limit <n>', 'Maximum number of results', '50'),
|
|
||||||
).action(async (opts: { db?: string; limit: string }) => {
|
|
||||||
const b = resolveDb(opts);
|
|
||||||
const limit = parseInt(opts.limit, 10);
|
|
||||||
const rows = await b.projects.findAll();
|
|
||||||
const sliced = rows.slice(0, limit);
|
|
||||||
if (sliced.length === 0) {
|
|
||||||
console.log('No projects found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const p of sliced) {
|
|
||||||
console.log(`${p.id} ${p.name}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addDbOption(
|
|
||||||
projects
|
|
||||||
.command('create <name>')
|
|
||||||
.description('Create a new project')
|
|
||||||
.requiredOption('--owner-id <id>', 'Owner user ID'),
|
|
||||||
).action(async (name: string, opts: { db?: string; ownerId: string }) => {
|
|
||||||
const b = resolveDb(opts);
|
|
||||||
const created = await b.projects.create({
|
|
||||||
name,
|
|
||||||
ownerId: opts.ownerId,
|
|
||||||
ownerType: 'user',
|
|
||||||
});
|
|
||||||
console.log(`Created project: ${created.id} ${created.name}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// ─── missions ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const missions = brain.command('missions').description('Manage missions');
|
|
||||||
|
|
||||||
addDbOption(
|
|
||||||
missions
|
|
||||||
.command('list')
|
|
||||||
.description('List all missions')
|
|
||||||
.option('--limit <n>', 'Maximum number of results', '50')
|
|
||||||
.option('--project <id>', 'Filter by project ID'),
|
|
||||||
).action(async (opts: { db?: string; limit: string; project?: string }) => {
|
|
||||||
const b = resolveDb(opts);
|
|
||||||
const limit = parseInt(opts.limit, 10);
|
|
||||||
const rows = opts.project
|
|
||||||
? await b.missions.findByProject(opts.project)
|
|
||||||
: await b.missions.findAll();
|
|
||||||
const sliced = rows.slice(0, limit);
|
|
||||||
if (sliced.length === 0) {
|
|
||||||
console.log('No missions found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const m of sliced) {
|
|
||||||
console.log(`${m.id} ${m.name}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ─── tasks ────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const tasks = brain.command('tasks').description('Manage generic tasks');
|
|
||||||
|
|
||||||
addDbOption(
|
|
||||||
tasks
|
|
||||||
.command('list')
|
|
||||||
.description('List all tasks')
|
|
||||||
.option('--limit <n>', 'Maximum number of results', '50')
|
|
||||||
.option('--project <id>', 'Filter by project ID'),
|
|
||||||
).action(async (opts: { db?: string; limit: string; project?: string }) => {
|
|
||||||
const b = resolveDb(opts);
|
|
||||||
const limit = parseInt(opts.limit, 10);
|
|
||||||
const rows = opts.project ? await b.tasks.findByProject(opts.project) : await b.tasks.findAll();
|
|
||||||
const sliced = rows.slice(0, limit);
|
|
||||||
if (sliced.length === 0) {
|
|
||||||
console.log('No tasks found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const t of sliced) {
|
|
||||||
console.log(`${t.id} ${t.title} [${t.status}]`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ─── conversations ────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const conversations = brain.command('conversations').description('Manage conversations');
|
|
||||||
|
|
||||||
addDbOption(
|
|
||||||
conversations
|
|
||||||
.command('list')
|
|
||||||
.description('List conversations for a user')
|
|
||||||
.option('--limit <n>', 'Maximum number of results', '50')
|
|
||||||
.requiredOption('--user-id <id>', 'User ID to scope the query'),
|
|
||||||
).action(async (opts: { db?: string; limit: string; userId: string }) => {
|
|
||||||
const b = resolveDb(opts);
|
|
||||||
const limit = parseInt(opts.limit, 10);
|
|
||||||
const rows = await b.conversations.findAll(opts.userId);
|
|
||||||
const sliced = rows.slice(0, limit);
|
|
||||||
if (sliced.length === 0) {
|
|
||||||
console.log('No conversations found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const c of sliced) {
|
|
||||||
console.log(`${c.id} ${c.title ?? '(untitled)'}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
export { createBrain, type Brain } from './brain.js';
|
export { createBrain, type Brain } from './brain.js';
|
||||||
export { registerBrainCommand } from './cli.js';
|
|
||||||
export {
|
export {
|
||||||
createProjectsRepo,
|
createProjectsRepo,
|
||||||
type ProjectsRepo,
|
type ProjectsRepo,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
"@mosaicstack/db": "workspace:*",
|
"@mosaicstack/db": "workspace:*",
|
||||||
"@mosaicstack/storage": "workspace:*",
|
"@mosaicstack/storage": "workspace:*",
|
||||||
"@mosaicstack/types": "workspace:*",
|
"@mosaicstack/types": "workspace:*",
|
||||||
|
"commander": "^13.0.0",
|
||||||
"drizzle-orm": "^0.45.1"
|
"drizzle-orm": "^0.45.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
63
packages/memory/src/cli.spec.ts
Normal file
63
packages/memory/src/cli.spec.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { Command } from 'commander';
|
||||||
|
import { registerMemoryCommand } from './cli.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smoke test — only verifies command wiring.
|
||||||
|
* Does NOT open a database connection.
|
||||||
|
*/
|
||||||
|
describe('registerMemoryCommand', () => {
|
||||||
|
function buildProgram(): Command {
|
||||||
|
const program = new Command('mosaic');
|
||||||
|
program.exitOverride(); // prevent process.exit during tests
|
||||||
|
registerMemoryCommand(program);
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
|
it('registers a "memory" subcommand', () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
const memory = program.commands.find((c) => c.name() === 'memory');
|
||||||
|
expect(memory).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('registers "memory search"', () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
const memory = program.commands.find((c) => c.name() === 'memory')!;
|
||||||
|
const search = memory.commands.find((c) => c.name() === 'search');
|
||||||
|
expect(search).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('registers "memory stats"', () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
const memory = program.commands.find((c) => c.name() === 'memory')!;
|
||||||
|
const stats = memory.commands.find((c) => c.name() === 'stats');
|
||||||
|
expect(stats).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('registers "memory insights list"', () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
const memory = program.commands.find((c) => c.name() === 'memory')!;
|
||||||
|
const insights = memory.commands.find((c) => c.name() === 'insights');
|
||||||
|
expect(insights).toBeDefined();
|
||||||
|
const list = insights!.commands.find((c) => c.name() === 'list');
|
||||||
|
expect(list).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('registers "memory preferences list"', () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
const memory = program.commands.find((c) => c.name() === 'memory')!;
|
||||||
|
const preferences = memory.commands.find((c) => c.name() === 'preferences');
|
||||||
|
expect(preferences).toBeDefined();
|
||||||
|
const list = preferences!.commands.find((c) => c.name() === 'list');
|
||||||
|
expect(list).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('"memory search" has --limit and --agent options', () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
const memory = program.commands.find((c) => c.name() === 'memory')!;
|
||||||
|
const search = memory.commands.find((c) => c.name() === 'search')!;
|
||||||
|
const optNames = search.options.map((o) => o.long);
|
||||||
|
expect(optNames).toContain('--limit');
|
||||||
|
expect(optNames).toContain('--agent');
|
||||||
|
});
|
||||||
|
});
|
||||||
179
packages/memory/src/cli.ts
Normal file
179
packages/memory/src/cli.ts
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
import type { Command } from 'commander';
|
||||||
|
|
||||||
|
import type { MemoryAdapter } from './types.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build and return a connected MemoryAdapter from a connection string or
|
||||||
|
* the MEMORY_DB_URL / DATABASE_URL environment variable.
|
||||||
|
*
|
||||||
|
* For pgvector (postgres://...) the connection string is injected into
|
||||||
|
* DATABASE_URL so that PgVectorAdapter's internal createDb() picks it up.
|
||||||
|
*
|
||||||
|
* Throws with a human-readable message if no connection info is available.
|
||||||
|
*/
|
||||||
|
async function resolveAdapter(dbOption: string | undefined): Promise<MemoryAdapter> {
|
||||||
|
const connStr = dbOption ?? process.env['MEMORY_DB_URL'] ?? process.env['DATABASE_URL'];
|
||||||
|
if (!connStr) {
|
||||||
|
throw new Error(
|
||||||
|
'No database connection string provided. ' +
|
||||||
|
'Pass --db <connection-string> or set MEMORY_DB_URL / DATABASE_URL.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lazy imports so the module loads cleanly without a live DB during smoke tests.
|
||||||
|
const { createMemoryAdapter, registerMemoryAdapter } = await import('./factory.js');
|
||||||
|
|
||||||
|
if (connStr.startsWith('postgres') || connStr.startsWith('pg')) {
|
||||||
|
// PgVectorAdapter reads DATABASE_URL via createDb() — inject it here.
|
||||||
|
process.env['DATABASE_URL'] = connStr;
|
||||||
|
|
||||||
|
const { PgVectorAdapter } = await import('./adapters/pgvector.js');
|
||||||
|
registerMemoryAdapter('pgvector', (cfg) => new PgVectorAdapter(cfg as never));
|
||||||
|
return createMemoryAdapter({ type: 'pgvector' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyword adapter backed by pglite storage; treat connStr as a data directory.
|
||||||
|
const { KeywordAdapter } = await import('./adapters/keyword.js');
|
||||||
|
const { createStorageAdapter, registerStorageAdapter } = await import('@mosaicstack/storage');
|
||||||
|
const { PgliteAdapter } = await import('@mosaicstack/storage');
|
||||||
|
|
||||||
|
registerStorageAdapter('pglite', (cfg) => new PgliteAdapter(cfg as never));
|
||||||
|
|
||||||
|
const storage = createStorageAdapter({ type: 'pglite', dataDir: connStr });
|
||||||
|
|
||||||
|
registerMemoryAdapter('keyword', (cfg) => new KeywordAdapter(cfg as never));
|
||||||
|
return createMemoryAdapter({ type: 'keyword', storage });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register `memory` subcommands on an existing Commander program.
|
||||||
|
* Follows the registerQualityRails pattern from @mosaicstack/quality-rails.
|
||||||
|
*/
|
||||||
|
export function registerMemoryCommand(parent: Command): void {
|
||||||
|
const memory = parent.command('memory').description('Inspect and query the Mosaic memory layer');
|
||||||
|
|
||||||
|
// ── memory search <query> ──────────────────────────────────────────────
|
||||||
|
memory
|
||||||
|
.command('search <query>')
|
||||||
|
.description('Semantic search over insights')
|
||||||
|
.option('--db <connection-string>', 'Database connection string (or set MEMORY_DB_URL)')
|
||||||
|
.option('--limit <n>', 'Maximum number of results', '10')
|
||||||
|
.option('--agent <id>', 'Filter by agent / user ID')
|
||||||
|
.action(async (query: string, opts: { db?: string; limit: string; agent?: string }) => {
|
||||||
|
let adapter: MemoryAdapter | undefined;
|
||||||
|
try {
|
||||||
|
adapter = await resolveAdapter(opts.db);
|
||||||
|
const limit = parseInt(opts.limit, 10);
|
||||||
|
const userId = opts.agent ?? 'system';
|
||||||
|
const results = await adapter.searchInsights(userId, query, { limit });
|
||||||
|
|
||||||
|
if (results.length === 0) {
|
||||||
|
console.log('No insights found.');
|
||||||
|
} else {
|
||||||
|
for (const r of results) {
|
||||||
|
console.log(`[${r.id}] (score=${r.score.toFixed(3)}) ${r.content}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
await adapter?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── memory stats ──────────────────────────────────────────────────────
|
||||||
|
memory
|
||||||
|
.command('stats')
|
||||||
|
.description('Print memory tier info: adapter type, insight count, preference count')
|
||||||
|
.option('--db <connection-string>', 'Database connection string (or set MEMORY_DB_URL)')
|
||||||
|
.option('--agent <id>', 'User / agent ID scope for counts', 'system')
|
||||||
|
.action(async (opts: { db?: string; agent: string }) => {
|
||||||
|
let adapter: MemoryAdapter | undefined;
|
||||||
|
try {
|
||||||
|
adapter = await resolveAdapter(opts.db);
|
||||||
|
|
||||||
|
const adapterType = adapter.name;
|
||||||
|
|
||||||
|
const insightCount = await adapter
|
||||||
|
.searchInsights(opts.agent, '', { limit: 100000 })
|
||||||
|
.then((r) => r.length)
|
||||||
|
.catch(() => -1);
|
||||||
|
|
||||||
|
const prefCount = await adapter
|
||||||
|
.listPreferences(opts.agent)
|
||||||
|
.then((r) => r.length)
|
||||||
|
.catch(() => -1);
|
||||||
|
|
||||||
|
console.log(`adapter: ${adapterType}`);
|
||||||
|
console.log(`insights: ${insightCount === -1 ? 'unavailable' : String(insightCount)}`);
|
||||||
|
console.log(`preferences: ${prefCount === -1 ? 'unavailable' : String(prefCount)}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
await adapter?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── memory insights ───────────────────────────────────────────────────
|
||||||
|
const insightsCmd = memory.command('insights').description('Manage insights');
|
||||||
|
|
||||||
|
insightsCmd
|
||||||
|
.command('list')
|
||||||
|
.description('List recent insights')
|
||||||
|
.option('--db <connection-string>', 'Database connection string (or set MEMORY_DB_URL)')
|
||||||
|
.option('--limit <n>', 'Maximum number of results', '20')
|
||||||
|
.option('--agent <id>', 'User / agent ID scope', 'system')
|
||||||
|
.action(async (opts: { db?: string; limit: string; agent: string }) => {
|
||||||
|
let adapter: MemoryAdapter | undefined;
|
||||||
|
try {
|
||||||
|
adapter = await resolveAdapter(opts.db);
|
||||||
|
const limit = parseInt(opts.limit, 10);
|
||||||
|
const results = await adapter.searchInsights(opts.agent, '', { limit });
|
||||||
|
|
||||||
|
if (results.length === 0) {
|
||||||
|
console.log('No insights found.');
|
||||||
|
} else {
|
||||||
|
for (const r of results) {
|
||||||
|
console.log(`[${r.id}] ${r.content}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
await adapter?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── memory preferences ────────────────────────────────────────────────
|
||||||
|
const prefsCmd = memory.command('preferences').description('Manage stored preferences');
|
||||||
|
|
||||||
|
prefsCmd
|
||||||
|
.command('list')
|
||||||
|
.description('List stored preferences')
|
||||||
|
.option('--db <connection-string>', 'Database connection string (or set MEMORY_DB_URL)')
|
||||||
|
.option('--agent <id>', 'User / agent ID scope', 'system')
|
||||||
|
.option('--category <cat>', 'Filter by category')
|
||||||
|
.action(async (opts: { db?: string; agent: string; category?: string }) => {
|
||||||
|
let adapter: MemoryAdapter | undefined;
|
||||||
|
try {
|
||||||
|
adapter = await resolveAdapter(opts.db);
|
||||||
|
const prefs = await adapter.listPreferences(opts.agent, opts.category);
|
||||||
|
|
||||||
|
if (prefs.length === 0) {
|
||||||
|
console.log('No preferences found.');
|
||||||
|
} else {
|
||||||
|
for (const p of prefs) {
|
||||||
|
console.log(`[${p.category}] ${p.key} = ${JSON.stringify(p.value)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
await adapter?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export { createMemory, type Memory } from './memory.js';
|
export { createMemory, type Memory } from './memory.js';
|
||||||
|
export { registerMemoryCommand } from './cli.js';
|
||||||
export {
|
export {
|
||||||
createPreferencesRepo,
|
createPreferencesRepo,
|
||||||
type PreferencesRepo,
|
type PreferencesRepo,
|
||||||
|
|||||||
@@ -27,10 +27,10 @@
|
|||||||
"test": "vitest run --passWithNoTests"
|
"test": "vitest run --passWithNoTests"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mosaicstack/brain": "workspace:*",
|
|
||||||
"@mosaicstack/config": "workspace:*",
|
"@mosaicstack/config": "workspace:*",
|
||||||
"@mosaicstack/forge": "workspace:*",
|
"@mosaicstack/forge": "workspace:*",
|
||||||
"@mosaicstack/macp": "workspace:*",
|
"@mosaicstack/macp": "workspace:*",
|
||||||
|
"@mosaicstack/memory": "workspace:*",
|
||||||
"@mosaicstack/prdy": "workspace:*",
|
"@mosaicstack/prdy": "workspace:*",
|
||||||
"@mosaicstack/quality-rails": "workspace:*",
|
"@mosaicstack/quality-rails": "workspace:*",
|
||||||
"@mosaicstack/types": "workspace:*",
|
"@mosaicstack/types": "workspace:*",
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import { createRequire } from 'module';
|
import { createRequire } from 'module';
|
||||||
import { Command } from 'commander';
|
import { Command } from 'commander';
|
||||||
import { registerBrainCommand } from '@mosaicstack/brain';
|
|
||||||
import { registerQualityRails } from '@mosaicstack/quality-rails';
|
import { registerQualityRails } from '@mosaicstack/quality-rails';
|
||||||
|
import { registerMemoryCommand } from '@mosaicstack/memory';
|
||||||
import { registerAgentCommand } from './commands/agent.js';
|
import { registerAgentCommand } from './commands/agent.js';
|
||||||
import { registerMissionCommand } from './commands/mission.js';
|
import { registerMissionCommand } from './commands/mission.js';
|
||||||
// prdy is registered via launch.ts
|
// prdy is registered via launch.ts
|
||||||
@@ -315,14 +315,14 @@ registerAgentCommand(program);
|
|||||||
|
|
||||||
registerMissionCommand(program);
|
registerMissionCommand(program);
|
||||||
|
|
||||||
// ─── brain ──────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
registerBrainCommand(program);
|
|
||||||
|
|
||||||
// ─── quality-rails ──────────────────────────────────────────────────────
|
// ─── quality-rails ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
registerQualityRails(program);
|
registerQualityRails(program);
|
||||||
|
|
||||||
|
// ─── memory ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
registerMemoryCommand(program);
|
||||||
|
|
||||||
// ─── update ─────────────────────────────────────────────────────────────
|
// ─── update ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|||||||
12
pnpm-lock.yaml
generated
12
pnpm-lock.yaml
generated
@@ -294,9 +294,6 @@ importers:
|
|||||||
'@mosaicstack/types':
|
'@mosaicstack/types':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../types
|
version: link:../types
|
||||||
commander:
|
|
||||||
specifier: ^13.0.0
|
|
||||||
version: 13.1.0
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
typescript:
|
typescript:
|
||||||
specifier: ^5.8.0
|
specifier: ^5.8.0
|
||||||
@@ -441,6 +438,9 @@ importers:
|
|||||||
'@mosaicstack/types':
|
'@mosaicstack/types':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../types
|
version: link:../types
|
||||||
|
commander:
|
||||||
|
specifier: ^13.0.0
|
||||||
|
version: 13.1.0
|
||||||
drizzle-orm:
|
drizzle-orm:
|
||||||
specifier: ^0.45.1
|
specifier: ^0.45.1
|
||||||
version: 0.45.1(@electric-sql/pglite@0.2.17)(@opentelemetry/api@1.9.0)(@types/better-sqlite3@7.6.13)(@types/pg@8.15.6)(better-sqlite3@12.8.0)(kysely@0.28.11)(postgres@3.4.8)
|
version: 0.45.1(@electric-sql/pglite@0.2.17)(@opentelemetry/api@1.9.0)(@types/better-sqlite3@7.6.13)(@types/pg@8.15.6)(better-sqlite3@12.8.0)(kysely@0.28.11)(postgres@3.4.8)
|
||||||
@@ -457,9 +457,6 @@ importers:
|
|||||||
'@clack/prompts':
|
'@clack/prompts':
|
||||||
specifier: ^0.9.1
|
specifier: ^0.9.1
|
||||||
version: 0.9.1
|
version: 0.9.1
|
||||||
'@mosaicstack/brain':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../brain
|
|
||||||
'@mosaicstack/config':
|
'@mosaicstack/config':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../config
|
version: link:../config
|
||||||
@@ -469,6 +466,9 @@ importers:
|
|||||||
'@mosaicstack/macp':
|
'@mosaicstack/macp':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../macp
|
version: link:../macp
|
||||||
|
'@mosaicstack/memory':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../memory
|
||||||
'@mosaicstack/prdy':
|
'@mosaicstack/prdy':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../prdy
|
version: link:../prdy
|
||||||
|
|||||||
Reference in New Issue
Block a user