feat: enhance parser feedback mechanism for improved user guidance

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-23 22:55:16 -04:00
parent c2d12ffcc9
commit 2f6af46c79
5 changed files with 174 additions and 16 deletions

View File

@@ -17,6 +17,7 @@ export interface AppStateSnapshot {
export interface TurnResult {
narration: string;
parser: "fallback";
parser_feedback?: string;
actions: Action[];
accepted: Action[];
rejected: { action: Action; reason: string }[];
@@ -152,10 +153,15 @@ function narrateResult(
worldState: WorldState,
accepted: Action[],
rejected: { action: Action; reason: string }[],
latentReason?: string
latentReason?: string,
parserFeedback?: string
): string {
const lines: string[] = [];
if (parserFeedback) {
lines.push(parserFeedback);
}
if (latentReason) {
lines.push(latentReason);
}
@@ -212,7 +218,7 @@ export function createCharacterGardenApp(dbPath: string): CharacterGardenApp {
function processTurn(input: string): TurnResult {
const turnNumber = db.listTurns().length + 1;
const { actions, parser } = extractActionsFromProse(input);
const { actions, parser, parser_feedback: parserFeedback } = extractActionsFromProse(input);
let activeWorldState = worldState;
let latentResolution: TurnResult["latent_resolution"];
@@ -260,7 +266,13 @@ export function createCharacterGardenApp(dbPath: string): CharacterGardenApp {
const validation = validate(normalizedActions, activeWorldState);
const nextWorldState = applyChanges(activeWorldState, validation.state_changes);
const narration = narrateResult(nextWorldState, validation.accepted, validation.rejected, latentResolution?.reason);
const narration = narrateResult(
nextWorldState,
validation.accepted,
validation.rejected,
latentResolution?.reason,
parserFeedback
);
const turnRecord: Turn = {
id: randomUUID(),
@@ -300,6 +312,7 @@ export function createCharacterGardenApp(dbPath: string): CharacterGardenApp {
return {
narration,
parser,
parser_feedback: parserFeedback,
actions: normalizedActions,
accepted: validation.accepted,
rejected: validation.rejected,