dsh-brain/vendor/dsh-mnemon/scripts/fixtures/archive-copies.mjs

37 lines
2.6 KiB
JavaScript

import { realpathSync } from 'node:fs'
import { MemoryCompositionRunner } from 'dsh-brain-mnemon/testing'
import * as runtimePlugin from 'dsh-brain-mnemon-source-runtime'
import * as spacesPlugin from 'dsh-brain-mnemon-source-memory-spaces'
import * as strategyPlugin from 'dsh-brain-mnemon-strategy-default-three-tier'
export const archiveCopiesEntries = [
{ content: 'Issue 339 synthetic rule: release candidates run the full verify locally, then the packed-plugin checks, before a maintainer approves the release pull request.', importance: 'normal' },
{ content: 'Issue 339 synthetic rule: database migrations ship with a rollback script and a dry run against the staging snapshot; never edit an applied migration.', importance: 'normal' },
{ content: 'Issue 339 synthetic rule: dependency upgrades land one package family at a time, each with its changelog read and the lockfile regenerated by the pinned pnpm.', importance: 'normal' },
]
export const archiveCopiesPending = 'Issue 339 synthetic rule: on-call maintainers record every production decision in the project documents within the same day, with the evidence they relied on and the follow-up owner.'
export const archiveCopiesLimitBytes = 640
export async function seedArchiveCopies({ dataDir, workspace }) {
const runner = new MemoryCompositionRunner()
try {
await runner.mount(strategyPlugin, { instanceId: 'archive-strategy' })
await runner.mount(runtimePlugin, { instanceId: 'runtime', config: { dataDir, userDataDir: dataDir } })
await runner.mount(spacesPlugin, { instanceId: 'memory-spaces', config: {
dataDir, timeoutMs: 20_000,
providers: [{ use: 'dsh-brain-mnemon-provider-mnemon-native', instanceId: 'mnemon-native' }],
} })
const scope = { storage: 'global', workspaceId: realpathSync(workspace) }
const runtime = await runner.managementClient('source:runtime', scope)
for (const entry of archiveCopiesEntries) await runtime.mutate('mutate', { action: 'add', target: 'memory', ...entry }, { confirmed: true })
const spaces = await runner.managementClient('source:memory-spaces', scope)
const body = (await spaces.mutate('body-create', { name: 'Project notes', description: 'Release, migration and dependency rules of the synthetic project.', active: true, providerId: 'mnemon-native', connection: {} }, { confirmed: true })).value
await spaces.mutate('remember-many', { requests: archiveCopiesEntries.map(entry => ({ content: entry.content, category: 'context', importance: 3, source: 'agent', memoryBodyId: body.id })) }, { confirmed: true })
return body.id
} finally {
await runner.dispose()
}
}