Skip to content

Badges system award visual badges for agent milestones #416

Open
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Badges-system-award-visual-badges-for-agent-milestones-#201
Open

Badges system award visual badges for agent milestones #416
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Badges-system-award-visual-badges-for-agent-milestones-#201

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

Motivation

  • Implement a badge/achievement system to surface agent milestones referenced by existing gamification features and enable visual reward feedback on the agent page.
  • Persist badge awards independently of reputation metrics so badges are idempotent and durable across restarts.
  • Evaluate awards automatically after task completion so milestones like "first task" and "speed runner" are granted in real usage flows.

Description

  • Add a new module lib/gamification/badges.ts that defines all five milestone badges (first_task, speed_runner, top_earner, quest_master, early_adopter), stores earned badges at /.data/agent-badges.json, records task completions for rolling-window checks, and exposes checkAndAwardBadges() (idempotent) and recordTaskCompletion() APIs.
  • Mirror persisted badge awards into the reputation store so existing reputation-based badge lists remain consistent via upsertReputationMetrics().
  • Wire badge evaluation hooks into runtime task completion and queued task draining by calling recordTaskCompletion() and checkAndAwardBadges() from lib/agent-runtime/agent.ts and app/api/agents/[id]/tasks/drain/route.ts.
  • Enhance GET /api/agents/[id]/badges (app/api/agents/[id]/badges/route.ts) to merge persisted awards with reputation badges and return display metadata including earnedAt, iconName, rarity, and xpValue.
  • Update the agent detail UI (app/agents/[id]/page.tsx) to fetch /api/agents/[id]/badges and render a badge icon grid with hover tooltips showing name and description.
  • Add unit tests at __tests__/gamification/badges.test.ts covering badge definitions, idempotent awarding, persistence, and the speed-runner 10-in-1-hour condition.

Testing

  • Ran targeted unit tests: __tests__/gamification/badges.test.ts, __tests__/api/agents/badges.test.ts, and __tests__/api/badges/catalog.test.ts, and all tests passed (Test Files: 3 passed, Tests: 21 passed).
  • Ran npx eslint against the changed files (lib/gamification/badges.ts, app/api/agents/[id]/badges/route.ts, lib/agent-runtime/agent.ts, app/agents/[id]/page.tsx, app/api/agents/[id]/tasks/drain/route.ts, and the new test), which completed for those targets without new errors.
  • Noted environment-wide caveats: npm run lint surfaces pre-existing unrelated lint/TS issues in other files and npx tsc --noEmit fails in this environment due to missing dev dependencies/types (e.g., lru-cache, @wagmi/connectors), but these are unrelated to the badge changes and did not block the badge tests.

Closes #201

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
13.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

Badges system: award visual badges for agent milestones

1 participant