feat(research): cut over canonical runtime and enforce agent budgets

This commit is contained in:
Boki 2026-10-24 16:47:19 -04:00
parent ab08db82fd
commit bbf0dd4453
103 changed files with 6138 additions and 3112 deletions

View file

@ -2,6 +2,7 @@ import { createHash, randomUUID } from 'node:crypto';
import type { PoolClient, QueryResultRow } from 'pg';
import { z } from 'zod';
import { requireServices, type IServiceContainer } from '@stock-bot/services';
import { researchActorSchema } from '@stock-bot/stock-config/research';
import {
assertStrategyJsonText,
builtinCatalogDescriptors,
@ -11,15 +12,17 @@ import {
} from '@stock-bot/stock-config/strategy';
import type {
ParameterValidationResult,
ResearchActor,
StrategyRecord,
StrategyReviewEvent,
StrategyVersionPackage,
StrategyVersionSummary,
} from '@stock-bot/types';
import { lockResearchAgent } from './research-agent-budget';
export type { StrategyRecord, StrategyVersionSummary } from '@stock-bot/types';
export type StrategyActor = 'operator' | 'service';
export type StrategyActor = ResearchActor;
export class StrategyCatalogError extends Error {
constructor(
public readonly status: 400 | 401 | 403 | 404 | 409,
@ -29,7 +32,7 @@ export class StrategyCatalogError extends Error {
}
}
const id = z.string().uuid();
const actorSchema = z.enum(['operator', 'service']);
const actorSchema = researchActorSchema;
const keySchema = z.string().regex(/^[\x21-\x7e]{1,200}$/);
const createSchema = z
.object({ name: z.string().trim().min(1), description: z.string().default('') })
@ -144,6 +147,7 @@ export class StrategyCatalogService {
const data = updateSchema.parse(input);
checkText(data);
return this.database.transaction(async client => {
await lockResearchAgent(client, actor);
const old = await this.lock(client, strategyId, false);
const row = (
await client.query(
@ -303,6 +307,7 @@ export class StrategyCatalogService {
let versionId: string;
try {
versionId = await this.database.transaction(async client => {
await lockResearchAgent(client, actor);
const old = await this.receipt(client, actor, key, fingerprint);
return old ?? (await work(client));
});
@ -476,6 +481,7 @@ export class StrategyCatalogService {
const data = reviewSchema.parse(input);
checkText(data);
await this.database.transaction(async client => {
await lockResearchAgent(client, actor);
const row = (
await client.query('SELECT strategy_id FROM strategy_versions WHERE id=$1', [versionId])
).rows[0];