Skip to content

Feature/quest persistence#326

Open
Truphile wants to merge 5 commits into
Bitcoindefi:mainfrom
Truphile:feature/quest-persistence
Open

Feature/quest persistence#326
Truphile wants to merge 5 commits into
Bitcoindefi:mainfrom
Truphile:feature/quest-persistence

Conversation

@Truphile

Copy link
Copy Markdown

closes #268

Here is a summary of the changes:

  1. Persistence Store ( lib/gamification/quest-store.ts ):
    • Created the store to manage writing and loading the quests , questStats , and agentXp data structures using the provided JSON format.
    • Implemented atomic writes by writing the serialized JSON to .data/quests.json.tmp first, then utilizing fs.renameSync to safely swap it to .data/quests.json .
    • Added a fallback mechanism that initializes the store with empty data and emits a console.warn if the parsed JSON is corrupt.
    • Included an auto-execution hook using a globalThis flag openStellarQuestStoreLoaded which calls loadQuestStore() exactly once upon the first import of the module.
  2. State Integration ( lib/gamification/quests.ts & lib/gamification/xp.ts ):
    • Modified hydrateSubTasks in quests.ts to hydrate subtaskDb directly from the stored questStoreData.quests entries on startup.
    • Hooked persistQuestStore() into the addSubTask and updateSubTask functions to automatically capture new state when subtasks are progressed.
    • Modified xp.ts to hydrate agentXpDb on initialization and persist whenever awardXP updates an agent's experience.
  3. Unit Tests ( lib/gamification/quest-store.test.ts ):
    • Added a complete Vitest suite to evaluate the persistence logic.
    • The test validates that completing a quest's subtask updates the memory store, correctly serializes the status to string, and successfully restores the "completed" status after deserializing from a simulated restart.
    • Included an additional test case to cover the fallback behavior when the JSON is found to be corrupt.
  4. Version Control:
    • The functionality has been staged and committed successfully to the new feature/quest-persistence branch.

@leocagli

Copy link
Copy Markdown
Collaborator

Same as PR#325 — conflicts with main. Rebase after PR#322 merges since you share files with it. git rebase upstream/main && git push --force-with-lease

@leocagli

Copy link
Copy Markdown
Collaborator

Three TS errors to fix:

  1. questStoreData is not exported from ./quest-store — use the existing exported accessor instead, or export it explicitly
  2. persistQuestStore doesn't exist — the exported name is resetQuestStore. Rename your function or export it with the correct name
  3. Parameter 'q' implicitly has an 'any' type in quest-store.test.ts lines 54 and 72 — add explicit type annotation: (q: QuestRecord)

Also rebase on main first to pull in recent changes to quest-store.ts.

@sonarqubecloud

Copy link
Copy Markdown

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.

Quest progress persistence: save quest completion state to disk so it survives server restarts

2 participants