feat(schema/numeric-methods-and-defaults): implement categorical numeric functions and resolveDefaults

This commit is contained in:
2026-04-27 11:25:43 +00:00
parent 30f20a9f26
commit 0613a190ce
4 changed files with 375 additions and 6 deletions

View File

@@ -1,4 +1,18 @@
import { Type, type Static } from "@alkdev/typebox";
import { Type, type Static, type TSchema } from "@alkdev/typebox";
import {
TaskScopeEnum,
TaskRiskEnum,
TaskImpactEnum,
TaskLevelEnum,
TaskPriorityEnum,
TaskStatusEnum,
} from "./enums.js";
// --- Nullable helper (also exported from enums.ts, duplicated here for schema locality) ---
/** Wrap a schema to also accept `null`. */
const Nullable = <T extends TSchema>(schema: T) =>
Type.Union([schema, Type.Null()]);
// --- RiskPathResult ---
@@ -96,4 +110,32 @@ export const RiskDistributionResult = Type.Object({
unspecified: Type.Array(Type.String()),
});
/** Distribution of tasks by risk level */
export type RiskDistributionResult = Static<typeof RiskDistributionResult>;
export type RiskDistributionResult = Static<typeof RiskDistributionResult>;
// --- ResolvedTaskAttributes ---
/**
* The output of `resolveDefaults` — all categorical fields resolved to their
* numeric equivalents for use in analysis.
*
* Categorical fields that have defaults (scope, risk, impact) are no longer
* optional — `resolveDefaults` fills them in. Label-only fields (level,
* priority, status) remain nullable since they have no meaningful default.
*/
export const ResolvedTaskAttributes = Type.Object({
name: Type.String(),
scope: TaskScopeEnum,
risk: TaskRiskEnum,
impact: TaskImpactEnum,
level: Nullable(TaskLevelEnum),
priority: Nullable(TaskPriorityEnum),
status: Nullable(TaskStatusEnum),
// Numeric equivalents (always present after resolution):
costEstimate: Type.Number(),
tokenEstimate: Type.Number(),
successProbability: Type.Number(),
riskWeight: Type.Number(),
impactWeight: Type.Number(),
});
/** Inferred type for {@link ResolvedTaskAttributes} schema. */
export type ResolvedTaskAttributes = Static<typeof ResolvedTaskAttributes>;