Skip to content

AutoStory: shared core - #648

Draft
dayfine wants to merge 32 commits into
autostory/screen-machinefrom
autostory/shared-core
Draft

dayfine wants to merge 32 commits into
autostory/screen-machinefrom
autostory/shared-core

Conversation

@dayfine

@dayfine dayfine commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Depends on #667

Base: autostory/screen-machine (#667, the screen layer split out of this PR), on autostory/story-range-options-sv (PokemonAutomation#1921's branch). The diff shows only this change. The logic test target (#654) and plza/lean (#644) merge this branch; FRLG and BDSP merge it next.

This is the AutoStory core FRLG, BDSP and PLZA share: checkpoints read from JSON into steps ready to run, a game's save/reload hooks (StoryGame), a backend of press, stick, wait, observe, log and scope, and one engine that runs a checkpoint's steps and retries after a reload. It is cut down to what every game needs (S1-S5, S8, S9, S12-S14 in the shared core plan): no pose types or template, no backend kind or battle(), no declared start or metadata (the reader ignores start and metadata), no execution rows or autosave policy (each game reads its own), and the engine runs plan steps itself instead of through a second event runner.

Plan format (S10, S11): a step names its action ({"id": "a", "action": "talk", "args": {...}}); there is no step kind enum. A game hands the reader its actions by name (StoryActions), each a parser that turns the step's args object into its own typed args and returns the step's run with them bound, or throws ParseException; reject_unknown_keys() is the one helper on top of the JsonObject getters. So unknown actions, unknown or missing args fail when the plan loads, and loading every plan is the lint. devtools/autostory/rewrite_plan_actions.py rewrites old plan files ("kind" + optional "action") to the new form, keeping formatting and line endings.

Results are std::optional<StoryFailure> (code, detail, repeats; S15): a failure that repeats (game not running) stops the run with no reload. The engine tracks no saves (S6): after another failure, game.reload says which checkpoint's start the game is at, possibly an earlier one, and the run replays from there until a checkpoint has failed attempts_per_checkpoint times; a reload at no start of the run stops it. The retry loop is inline in run_checkpoints (S7). Stored callables are MoveOnlyFunction and the fake backend lives in Testing/.

Tested with the shared AutoStory suites in Fork Draft CI. StoryStepJson cases read a plan with a test game's actions and run it on the fake backend (typed args reach the handler; unknown key, missing arg, unknown action rejected); StoryEngine cases cover a replay from an earlier checkpoint, a repeating failure stopping at once, and an unknown reload start stopping the run. The rewrite script was run on copies of the 25 PLZA plans: idempotent, and the result matches the expected events.

SerialProgramsLogicTests (-DPA_CORE_ONLY=ON -DPA_LOGIC_TESTS=ON) links CoreLib
plus the pure AutoStory, ScreenEvents and ScreenMachine sources and runs their
suites with a small sequential runner. The Logic Tests workflow configures,
builds and runs only that target, so it needs no ONNX Runtime download.
Closed lists get the grid games' members now, so FRLG and BDSP extend the
core without changing its API later:

- StoryArgType/StoryArgValue: DIRECTION, GRID_POSE, LEGS, ITEMS (with
  StoryLeg, StoryItem), in FRLG's order.
- DeclaredPose: a TileDeclared alternative (map, tiles, facing).
- The step JSON reads them: "north", {"map", "tiles", "facing"},
  [{"direction", "tiles"}], [{"item", "quantity"}]; a declared pose with
  "map" is a tile one, with "place" a zone one, both or neither fail.

Pokemon_Grid.h/.cpp (TilePos) and Types/Pokemon_GridPose.h come unchanged
from frlg/lean.
This reverts commit 3b8c9aa: the core stays grid-free (user, 2026-11-18).
The grid items move to autostory/grid-core.
The core keeps no tile-grid concept (user, 2026-11-18):

- StoryBackend drops tap(Direction) and hold(Direction): the games move
  with stick(); a tile game adds its own moves in its backend.
  direction_degrees() and Navigation/Pokemon_Direction leave the core.
- Pose drops PoseCertainty; a game's Position subclass says how sure it is.

Two extension points let a grid layer plug in without core enum edits:

- StoryArgType::REGISTERED: a game registers a StoryArgKind (name, JSON
  reader) on its arg specs; the step holds a StoryRegisteredArgValue
  (std::any plus its type's ==) read back with registered_arg<T>().
- DeclaredPose is a zone or a registered value; read_story_checkpoint()
  takes the game's declared-pose kind (default: zones).
One-line file headers; comments that restated a type's name now say its
contract.
…reloads

story_run_segments() becomes split_at_reloads(): it cuts rows where a run
reloads, which is not a segment (an id-prefix group).
One-line file headers; mechanism and edge-case lists dropped.
…ineFailure

Shape: two one-field structs plus a using alias; the old struct could hold both
a terminal and a failure, or neither.
# Conflicts:
#	SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEventTypes.h
#	SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents.cpp
#	SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp
#	SerialPrograms/Source/CommonTools/ScreenMachine/ScreenMachine.h
@dayfine
dayfine changed the base branch from autostory/story-range-options-sv to autostory/screen-machine November 19, 2026 05:44
Pokemon_StoryBackend_Tests prints ScreenEvents with std::format, as describe() is gone.
…etadata, execution rows, autosave policy and the event runner

S1-S5, S8, S9, S12-S14 of the shared core plan: the engine is no longer a
template; StoryBackend::observe() returns a ScreenObservation; the reader
ignores a checkpoint's "start" and "metadata"; the engine runs plan steps
itself (StoryEvent and run_checkpoint are gone).
…line retry loop

S15: actions, the save and the engine return std::optional<StoryFailure>
(code, detail, repeats); nullopt is success. Outcome, outcome_ok/failed/
unchanged, changed_nothing and to_string go; std::formatter prints a
failure. GAME_NOT_RUNNING is a repeats = true failure, as are lint and
unsupported-step failures, so the engine keeps no list of codes.

S6 + retry rule: the engine tracks no saves (no start_saved, no saved flag,
no NOT_SAVED). After a failure that does not repeat, game.reload(backend,
failed) returns the id of the checkpoint whose start the game is at; the
run goes on from there, which may be an earlier checkpoint, until a
checkpoint fails attempts_per_checkpoint times. A reload at no start of
the run stops it (start_unknown).

S7: the retry loop is inline in run_checkpoints; CheckpointAttempts,
AttemptResult, CheckpointAttemptsResult and their tests are deleted.
run_checkpoints returns std::optional<CheckpointFailure> (checkpoint id,
event index, failure) instead of a vector of CheckpointRun.

Round-2 rules: stored callables (handler, save, reload) are
MoveOnlyFunction, so run_checkpoints/run_story_step take StoryGame&;
FakeStoryBackend moves to Testing/; = {} on fields; StorySavePolicy.h and
Pokemon_StoryOutcome.* are gone (the type lives in Pokemon_StoryFailure.h).

Shape: StoryFailure struct + formatter (header only); StoryGame with three
MoveOnlyFunction members; run_checkpoints ~25 lines + a reload helper.
Estimate +200/-450; actual +244/-640.
…rgs at load (S10, S11)

Shape: StoryStep{name, why, run} where run is a MoveOnlyFunction
(StoryBackend&, RunState&) with the typed args bound; StoryActions =
map<name, std::function<StoryStepRun(const JsonObject& args)>>; one helper,
reject_unknown_keys(); read_story_checkpoint(value, source, actions) parses
every step, so a plan load is the lint. The engine runs step.run directly.
Deleted: StoryStepKind, StoryActionSpec/StoryArgSpec, StoryArgValue/
StoryArgType/StoryActionArgs, fallbacks, story_args_errors, story_arg<>,
StoryActionRegistry (lint_story_checkpoint, run_story_step, [Step] line),
StoryGame::actions, Pokemon_MapUtil.h. story_run_rows returns a span
(steps are move-only). Plus devtools/autostory/rewrite_plan_actions.py,
which rewrites plan JSON from "kind" (+ "action") to "action".

Estimate: about +350/-1000 (C++ +250, script +100).
dayfine added a commit that referenced this pull request Nov 19, 2026
…ed core

PLZA follows the core's API (S1-S15):
- PlzaBackend is the plain StoryBackend; observe() returns ScreenObservation.
  No kind() or battle(): the battle action calls PlzaStoryTools::battle.
- Results are std::optional<StoryFailure>; a console action with no console
  fails as CONSOLE_ONLY with repeats = true.
- Actions parse their own args at load (plza_story_actions(tools)); a plan
  load is the lint. Plans rewritten with rewrite_plan_actions.py
  --default scene=mash; the lead-in lint reads the plan JSON.
- PLZA reads its own "execution" block (save, reload_when_chained,
  autosave_step, start_signature) into StoryRows; autosave_policy() and
  note_autosaves() live in PLZA.
- The console reload says the failed checkpoint's start; PLZA's
  reloading_only_to_start() says none once the checkpoint autosaved.
  run_plza_segments() runs each row through run_checkpoints(); the
  backup rewind (03.08 -> 03.06) and start signatures are kept as they were.
- Tests: [Step] golden lines become [Event] lines; walk logs name "walk".
dayfine added a commit that referenced this pull request Nov 19, 2026
A walk's end event and its black fade returned "walk on" instead of
"ended" after the Outcome to optional<StoryFailure> port, so every walk
with an end event failed as walk_no_end. The test rows built by hand now
carry their step's action as plan-loaded rows do. The walk's log lines
name the walk, not the step (the core's actions get no step id), and the
chain tests take the core's wording and verdict.
dayfine added a commit that referenced this pull request Nov 19, 2026
… fake backend in a .cpp, clearer comments

- Pokemon_StoryCheckpointJson merges AuthoredCheckpointJson and StoryStepJson:
  read_story_checkpoint() reads the file envelope and its checkpoint; the game
  reads "execution" from the file itself (no ExecutionReader); parsers are
  MoveOnlyFunction. EmbeddedJsonFile (unused) is gone.
- Delete StoryFiles.h and its tests (story_run_rows has one user, in PLZA) and
  devtools/autostory/rewrite_plan_actions.py (plans already rewritten).
- FakeStoryBackend: methods defined in Testing/Pokemon_StoryFakeBackend.cpp.
- run_checkpoints(), StoryStep and screen_observation() comments say what
  std::nullopt means, how a step relates to a checkpoint and what is filtered.
event_line, checkpoint_failed_line, checkpoint_done_line,
checkpoint_no_start_line and save_failed_line replace the engine's local
builders and its raw [Save] format; the text is unchanged.
dayfine added a commit that referenced this pull request Nov 19, 2026
…ng/StoryFakeBackend; deleted files dropped)
dayfine added a commit that referenced this pull request Nov 19, 2026
…648's checkpoint reader

read_plza_checkpoint calls read_story_checkpoint and reads the execution
block from the file; the actions map is built by emplace since its parsers
are move-only; story_run_rows moves into the backups .cpp. #648's own copies
of the shared edits, deletions and logic-test lists replace plza/lean's.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant