[GH-ISSUE #6634] [Feature]: Let capability packages register, read, and unlock their own achievements #3716

Closed
opened 2026-10-21 06:06:27 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Gunterlie on GitHub (Sep 24, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6634

Originally assigned to: @Gunterlie on GitHub.

Problem

Achievements are a closed, Engine-only set. ACHIEVEMENT_DEFINITIONS is a hard-coded array in packages/shared/src/constants/achievements.ts, the metrics are a fixed union counted off Engine tables in achievements.service.ts, and the icons are a fixed AchievementIconKey enum mapped to Lucide components in HomeAchievements.tsx.

So a capability package (agent) cannot ship achievements for its own feature. Slurp, Noodle, a turn-game package, or any community agent has no way to say "unlock Fed The Noodle after 10 noodle runs", no way to ask whether that badge is already unlocked, and no way to mark it unlocked. Users also get no idea which badges came from which agent.

Everything an agent needs is already present as a pattern — packages already register conversation commands, services, prompt context, and privileged routes through CapabilityActivationContext, already get a persistence host, and already serve their own static files via GET /api/capability-packages/:id/assets/*. Achievements are simply the one subsystem nobody wired up.

Proposed change

Add a package-contributed achievement lane that reuses the existing registry pattern instead of inventing a second achievement system.

1. Registry + activation API

New capability-achievement-registry.service.ts, modelled directly on capability-command-registry.service.ts. Expose on the activation context:

api.registerAchievements(definitions: PackagedAchievementDefinition[]): Cleanup

Gated by a new achievements value in capabilityPermissionSchema. IDs are namespaced "<packageId>.<localId>" at registration; the registry rejects a collision with a built-in ID or another package.

2. Definition shape

Extend AchievementDefinition (shared) with two optional fields, both back-compatible:

  • source?: { packageId: string; packageName: string } — absent means Engine.
  • iconUrl?: string — a package-served asset path. The client already falls back to Trophy for an unknown icon, so iconUrl renders when present and the enum stays authoritative for built-ins.

3. Read / write / progress

On CapabilityRuntimeHost, add an achievements host scoped to the calling package's own IDs:

  • list() — definitions + progress for this package.
  • isUnlocked(id) — read whether it is fulfilled.
  • unlock(id) — write that it is fulfilled; returns whether this call is the one that unlocked it, so the package can react once.

Counting stays with the package. A registered definition may carry target plus an optional readProgress(): Promise<number> callback that status() invokes; the package keeps its own counter in the persistence host it already has. This deliberately avoids a new table and a STORAGE_VERSION bump — achievement_unlocks is keyed by a plain string ID and already stores arbitrary IDs correctly.

4. Status + UI sections

achievements.service.ts merges registry definitions into status(), and unlock/catch-up logic runs over the merged set. HomeAchievements.tsx groups the grid by source: the existing ungrouped Engine set first, then one labelled section per package that contributed at least one badge, each headed by the package name. The unlock toast is already definition-driven and needs only the iconUrl path.

5. Lifecycle

Unregistering a package leaves its unlock rows in place (achievements never re-lock, per the documented behaviour) but drops its definitions from status(), so orphaned IDs simply stop rendering and come back if the package is reinstalled.

Scope

  • packages/shared: AchievementDefinition fields, PackagedAchievementDefinition, achievements permission, CapabilityRuntimeHost.achievements, bump supportedCapabilityApi minor (1.16 → 1.17).
  • packages/server: new achievement registry service, activation-context wiring in capability-module-runtime.service.ts, merge in achievements.service.ts.
  • packages/client: grouped sections + iconUrl rendering in HomeAchievements.tsx and achievement-toast.tsx.
  • Docs: docs/home/achievements.md (agent-contributed badges + per-agent sections), the capability package API reference, and the permission list. Translated docs on docs-i18n need a matching update or a [docs-i18n] follow-up issue.

Explicitly out of scope

  • No client-side HTTP endpoint for packages to unlock badges. Package server modules run in-process and the host API covers it; a public unlock endpoint is an unlock-anything hole.
  • No new Engine metrics, no achievement editor UI, no reset/clear button.

Test plan

  • Manually verify in the browser that a test package registering two badges shows its own section on the Home Achievements panel, headed by the package name.
  • Manually verify a package-supplied iconUrl renders on both the card and the unlock toast, and that a missing/broken asset falls back to the trophy icon.
  • Manually verify unlock() returns true once and false on a second call, and that the toast fires exactly once.
  • Manually verify a readProgress-backed badge shows a correct progress bar and auto-unlocks on reaching target.
  • Manually verify a package without the achievements permission is refused at registerAchievements.
  • Manually verify that uninstalling the package hides its cards, and that reinstalling restores them as already unlocked.
  • Run pnpm check.
Originally created by @Gunterlie on GitHub (Sep 24, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6634 Originally assigned to: @Gunterlie on GitHub. ## Problem Achievements are a closed, Engine-only set. `ACHIEVEMENT_DEFINITIONS` is a hard-coded array in `packages/shared/src/constants/achievements.ts`, the metrics are a fixed union counted off Engine tables in `achievements.service.ts`, and the icons are a fixed `AchievementIconKey` enum mapped to Lucide components in `HomeAchievements.tsx`. So a capability package (agent) cannot ship achievements for its own feature. Slurp, Noodle, a turn-game package, or any community agent has no way to say "unlock *Fed The Noodle* after 10 noodle runs", no way to ask whether that badge is already unlocked, and no way to mark it unlocked. Users also get no idea which badges came from which agent. Everything an agent needs is already present as a *pattern* — packages already register conversation commands, services, prompt context, and privileged routes through `CapabilityActivationContext`, already get a persistence host, and already serve their own static files via `GET /api/capability-packages/:id/assets/*`. Achievements are simply the one subsystem nobody wired up. ## Proposed change Add a package-contributed achievement lane that reuses the existing registry pattern instead of inventing a second achievement system. ### 1. Registry + activation API New `capability-achievement-registry.service.ts`, modelled directly on `capability-command-registry.service.ts`. Expose on the activation context: ```ts api.registerAchievements(definitions: PackagedAchievementDefinition[]): Cleanup ``` Gated by a new `achievements` value in `capabilityPermissionSchema`. IDs are namespaced `"<packageId>.<localId>"` at registration; the registry rejects a collision with a built-in ID or another package. ### 2. Definition shape Extend `AchievementDefinition` (shared) with two optional fields, both back-compatible: - `source?: { packageId: string; packageName: string }` — absent means Engine. - `iconUrl?: string` — a package-served asset path. The client already falls back to `Trophy` for an unknown `icon`, so `iconUrl` renders when present and the enum stays authoritative for built-ins. ### 3. Read / write / progress On `CapabilityRuntimeHost`, add an `achievements` host scoped to the calling package's own IDs: - `list()` — definitions + progress for this package. - `isUnlocked(id)` — read whether it is fulfilled. - `unlock(id)` — write that it is fulfilled; returns whether this call is the one that unlocked it, so the package can react once. Counting stays with the package. A registered definition may carry `target` plus an optional `readProgress(): Promise<number>` callback that `status()` invokes; the package keeps its own counter in the persistence host it already has. This deliberately avoids a new table and a `STORAGE_VERSION` bump — `achievement_unlocks` is keyed by a plain string ID and already stores arbitrary IDs correctly. ### 4. Status + UI sections `achievements.service.ts` merges registry definitions into `status()`, and unlock/catch-up logic runs over the merged set. `HomeAchievements.tsx` groups the grid by `source`: the existing ungrouped Engine set first, then one labelled section per package that contributed at least one badge, each headed by the package name. The unlock toast is already definition-driven and needs only the `iconUrl` path. ### 5. Lifecycle Unregistering a package leaves its unlock rows in place (achievements never re-lock, per the documented behaviour) but drops its definitions from `status()`, so orphaned IDs simply stop rendering and come back if the package is reinstalled. ## Scope - `packages/shared`: `AchievementDefinition` fields, `PackagedAchievementDefinition`, `achievements` permission, `CapabilityRuntimeHost.achievements`, bump `supportedCapabilityApi` minor (1.16 → 1.17). - `packages/server`: new achievement registry service, activation-context wiring in `capability-module-runtime.service.ts`, merge in `achievements.service.ts`. - `packages/client`: grouped sections + `iconUrl` rendering in `HomeAchievements.tsx` and `achievement-toast.tsx`. - Docs: `docs/home/achievements.md` (agent-contributed badges + per-agent sections), the capability package API reference, and the permission list. Translated docs on `docs-i18n` need a matching update or a `[docs-i18n]` follow-up issue. ## Explicitly out of scope - No client-side HTTP endpoint for packages to unlock badges. Package server modules run in-process and the host API covers it; a public unlock endpoint is an unlock-anything hole. - No new Engine metrics, no achievement editor UI, no reset/clear button. ## Test plan - [ ] Manually verify in the browser that a test package registering two badges shows its own section on the Home Achievements panel, headed by the package name. - [ ] Manually verify a package-supplied `iconUrl` renders on both the card and the unlock toast, and that a missing/broken asset falls back to the trophy icon. - [ ] Manually verify `unlock()` returns true once and false on a second call, and that the toast fires exactly once. - [ ] Manually verify a `readProgress`-backed badge shows a correct progress bar and auto-unlocks on reaching `target`. - [ ] Manually verify a package without the `achievements` permission is refused at `registerAchievements`. - [ ] Manually verify that uninstalling the package hides its cards, and that reinstalling restores them as already unlocked. - [ ] Run `pnpm check`.
bsakaguchi 2026-10-21 06:06:27 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3716
No description provided.