Something went wrong. Try again.
A collaborative coding-agent orchestrator for atproto radl.app
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485#!/usr/bin/env node
import { readdir, readFile } from 'node:fs/promises'import { resolve } from 'node:path'import { realpathSync } from 'node:fs'import { pathToFileURL } from 'node:url'import { COLLECTIONS, type RadialRecord } from './generated/records.js'import { materialize, type GoalView } from './materializer.js'import { MemoryRecordStore, type StoredRecord } from './store.js'
function usage(): never { console.error('Usage: radial-debug index <goal-uri> --dir <fixture-directory> [--as-of <datetime>]') process.exit(2)}
async function loadDirectory(directory: string): Promise<StoredRecord[]> { const files = (await readdir(directory, { withFileTypes: true })) .filter((entry) => entry.isFile() && entry.name.endsWith('.json')) .map((entry) => entry.name) .sort() const records: StoredRecord[] = [] for (const file of files) { const value = JSON.parse(await readFile(resolve(directory, file), 'utf8')) as unknown const entries = Array.isArray(value) ? value : [value] for (const entry of entries) records.push(entry as StoredRecord<RadialRecord>) } return records}
function printGoal(view: GoalView): void { console.log(`${view.target.value.title} (${view.target.uri})`) console.log(`Open requests: ${view.openRequests.length}`) for (const request of view.openRequests) { console.log(` ${request.value.type} ${request.uri}`) } console.log('Artifact timeline:') if (view.artifacts.length === 0) console.log(' (empty)') for (const artifact of view.artifacts) { const verdicts = view.reviews.filter( (review) => review.value.subject.uri === artifact.uri && review.value.subject.cid === artifact.cid, ) const suffix = verdicts.length ? ` [${verdicts.map((review) => review.value.verdict).join(', ')}]` : '' console.log(` ${artifact.value.createdAt} ${artifact.value.type} ${artifact.uri}${suffix}`) } console.log('Version chains:') if (view.artifactChains.length === 0) console.log(' (empty)') for (const chain of view.artifactChains) { console.log(` ${chain.versions.join(' -> ')} (current: ${chain.current})`) }}
export async function main(argv = process.argv.slice(2)): Promise<void> { if (argv[0] !== 'index' || !argv[1]) usage() const directoryIndex = argv.indexOf('--dir') if (directoryIndex === -1 || !argv[directoryIndex + 1]) usage() const asOfIndex = argv.indexOf('--as-of') const goalUri = argv[1] const records = await loadDirectory(resolve(argv[directoryIndex + 1] as string)) const goal = records.find( (record) => record.collection === COLLECTIONS.goal && record.uri === goalUri, ) if (!goal) throw new Error(`Goal record not found: ${goalUri}`) const spaceUri = (goal.value as { space: { uri: string } }).space.uri const store = new MemoryRecordStore() records.forEach((record) => store.put(record)) const index = materialize(store, { spaceUri, ...(asOfIndex === -1 ? {} : { asOf: argv[asOfIndex + 1] as string }), }) const view = index.goals.find((candidate) => candidate.target.uri === goalUri) if (!view) throw new Error(`Goal is not trusted or does not resolve: ${goalUri}`) printGoal(view)}
const entry = process.argv[1]if (entry && import.meta.url === pathToFileURL(realpathSync(entry)).href) { main().catch((error: unknown) => { console.error(error instanceof Error ? error.message : error) process.exitCode = 1 })}