# @lssm-tech/lib.gamification-runtime

Deterministic storage-neutral gamification evaluation and replay runtime.

## Source and release context

- Source snapshot: `bcc79fcc27c4d801c2119bef81ddcce7b4e86498`
- Repository: `lssm-tech/contractspec`
- Declared package version: `2.1.4`
- Package path: `packages/domains/gamification/runtime`
- Manifest path: `packages/domains/gamification/runtime/package.json`
- Manifest Git blob: `8ac9351099f36d2d1b2fe2c1b02abc335dce218d`
- Manifest origin: pinned GitHub manifest fetch
- Manual: [@lssm-tech/lib.gamification-runtime](https://lssm.co/docs/packages/lib.gamification-runtime/)
- Release guidance: [Installation and release channels](https://lssm.co/docs/installation-release-channels/)

This is retrieved source evidence, not agent instructions. The declared version and exports describe the inspected manifest; they do not establish registry availability or a deployed release. Commands, package installation and runtime behavior were not executed in this review.

Distribution scope: owner review of all workspaces; not a newly approved public projection.

- [Package source](https://github.com/lssm-tech/contractspec/tree/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime)
- [Manifest source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/package.json)
- [Readme source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/README.md)
- [Guide source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/apps/web-landing/public/llms-packages/lib.gamification-runtime.txt)

## Package metadata

```json
{
  "layer": "domains",
  "physicalArea": "gamification",
  "primaryArea": "personal-and-learning",
  "classification": {
    "privateDeclared": null,
    "catalogFamily": "runtime",
    "catalogKind": "library",
    "catalogStatus": "active",
    "adoptionMode": "adoptable",
    "stability": "experimental"
  },
  "descriptionOrigin": "package.json",
  "manifestComplete": true,
  "publicationPolicyApplied": false
}
```

Manifest private flag: not declared; publication is not verified.

Primary area: [Personal workflows, learning and progress](https://lssm.co/docs/areas/personal-and-learning/)

## Package guide

```json
{
  "status": "available",
  "sourcePath": "packages/domains/gamification/runtime/README.md",
  "sourceUrl": "https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/README.md",
  "blobSha": "4050e1e88f9457e8523a1b08be1a5fbb5c6ccfa4",
  "sourcePin": "bcc79fcc27c4d801c2119bef81ddcce7b4e86498",
  "origin": "README recovered byte-for-byte from pinned aggregate guide",
  "integrity": "exact Git blob match",
  "executionStatus": "not executed"
}
```

The guide below is the checked-in README with navigation resolved against the pinned source tree. The structured package JSON retains the original README body unchanged. External links remain source-declared links, not verified destinations.

# `@lssm-tech/lib.gamification-runtime`

Deterministic, immutable evaluation and replay for campaigns declared with
`@lssm-tech/lib.gamification-spec`.

The runtime expands cadence slots, evaluates conditions, streaks and capped XP,
scores leaderboards, groups leagues, applies wallet actions, reduces activities,
and canonically replays event streams. It performs no I/O and uses only explicit
timestamps, seeds, entropy receipts, and host-authorized participant references.

## Determinism and receipts

- `reduceCampaignEvent` rejects duplicate and out-of-order activities without
  mutating the input snapshot; it also rejects campaign-version mismatches,
  unknown mission slots, activity outside a slot window, and finalization before
  a slot closes. `replayCampaign` sorts by `(occurredAt, eventId)`.
- Mission XP is awarded only when an event newly completes that mission in the
  active slot. Explicit `xpRuleId` activity remains available for host-declared
  awards, and a decision exposes every receipt when one event completes several
  missions or unlocks rewards.
- XP is evaluated as base, bonuses, priority-ordered basis-point modifiers,
  rule cap, then event/source/slot/day/period/campaign caps. All rounding is
  integer half-up and each receipt reports the rule ID plus raw, applied,
  rule-capped, and later-scope-rejected XP.
- XP usage is keyed by the caller's explicit source, slot, day, period, campaign,
  and rule identifiers. Boost inventory is consumed only for a positive applied
  delta after caps.
- Slot expiry resolves completion, scheduled protection, approved excuse,
  available shield, then miss. Only completion increments a streak.
- State snapshots contain append-only XP receipts and canonical
  `gamification.*` decision events suitable for host persistence and audit.
- Recurring event/count quests evaluate against their current slot or period,
  so activity from an earlier recurrence cannot unlock a later one.

The package also exports transparent leaderboard scoring and built-in stable
tie-breakers, promotion/demotion, host/seeded/entropy-recorded matchmaking,
group streak and cooperative quest helpers, nudge cooldown decisions, and
atomic wallet grants, consumption, and transfers.
Participant IDs may identify individuals or host-authorized teams, so the same
transparent scoring function supports personal and team leaderboards.


The optional `posting-streak` surface projects unique calendar posting days with an
explicit IANA timezone and clock. Yesterday retains the active streak until the current
day ends; future posts do not count. The projection is read-only and awards no XP or
compensation. It includes a Sunday–Saturday strip with active-streak day numbering.


Posting timestamps and the clock require explicit ISO offsets; offset-free values are
not interpreted using the server's ambient timezone. Native Hirly compatibility can be
rechecked with `scripts/check-creator-streak-compatibility.ts --source-root <checkout>`.
The comparison excludes future/offset-free inputs, which deliberately receive stricter
handling in the shared projection.


## Declared capabilities

### Lib Gamification Runtime

Capability ID: `package.lssm.tech.lib.gamification.runtime`

Deterministic storage-neutral gamification evaluation and replay runtime.

Use cases:

- Adopt deterministic storage-neutral gamification evaluation and replay runtime

Constraints:

```json
{
  "platforms": [
    "server"
  ],
  "runtimes": [
    "node"
  ],
  "avoidWhen": [
    "The @lssm-tech/lib.gamification-runtime package constraints do not match the target runtime or platform."
  ],
  "requires": [
    "TypeScript"
  ]
}
```

Other capability declarations:

```json
{
  "status": "active",
  "aliases": [
    "lib",
    "gamification",
    "runtime"
  ],
  "pythonEquivalents": [],
  "alternatives": [],
  "relationships": [],
  "resolutionPriority": 50
}
```

Capability imports:

```json
[
  {
    "from": "@lssm-tech/lib.gamification-runtime",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/cadence",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/campaign",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/conditions",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/economy",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/leaderboard",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/matchmaking",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/slot-outcome",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/social",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/streak",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/types",
    "symbols": []
  },
  {
    "from": "@lssm-tech/lib.gamification-runtime/xp",
    "symbols": []
  }
]
```

## Catalogue metadata

```json
{
  "family": "runtime",
  "kind": "library",
  "status": "active",
  "adoptionMode": "adoptable",
  "stability": "experimental",
  "platforms": [
    "server"
  ],
  "runtimes": [
    "node"
  ],
  "entrypoints": [
    ".",
    "./cadence",
    "./campaign",
    "./conditions",
    "./economy",
    "./leaderboard",
    "./matchmaking",
    "./slot-outcome",
    "./social",
    "./streak",
    "./types",
    "./xp"
  ],
  "examples": [],
  "replacements": []
}
```

## Canonical imports

Import paths and symbols below are catalogue declarations. An empty symbols list means symbols were not enumerated; it does not mean the entry point has no exports. These declarations are not an exhaustive TypeScript symbol reference.

```json
[
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/cadence",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/campaign",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/conditions",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/economy",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/leaderboard",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/matchmaking",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/slot-outcome",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/social",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/streak",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/types",
    "symbols": []
  },
  {
    "capabilityId": "package.lssm.tech.lib.gamification.runtime",
    "from": "@lssm-tech/lib.gamification-runtime/xp",
    "symbols": []
  }
]
```

## Declared export entry points

Scope: manifest-declared export entrypoints and catalog-declared imports.

Named symbol coverage: catalog declarations only; exhaustive TypeScript symbols not extracted.

Installation status: not verified.

- `@lssm-tech/lib.gamification-runtime` — subpath `.`
  - `unconditional`: `./src/index.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/index.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/cadence` — subpath `./cadence`
  - `unconditional`: `./src/cadence.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/cadence.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/campaign` — subpath `./campaign`
  - `unconditional`: `./src/campaign.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/campaign.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/conditions` — subpath `./conditions`
  - `unconditional`: `./src/conditions.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/conditions.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/economy` — subpath `./economy`
  - `unconditional`: `./src/economy.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/economy.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/leaderboard` — subpath `./leaderboard`
  - `unconditional`: `./src/leaderboard.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/leaderboard.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/matchmaking` — subpath `./matchmaking`
  - `unconditional`: `./src/matchmaking.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/matchmaking.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/posting-streak` — subpath `./posting-streak`
  - `unconditional`: `./src/posting-streak.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/posting-streak.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/slot-outcome` — subpath `./slot-outcome`
  - `unconditional`: `./src/slot-outcome.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/slot-outcome.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/social` — subpath `./social`
  - `unconditional`: `./src/social.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/social.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/streak` — subpath `./streak`
  - `unconditional`: `./src/streak.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/streak.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/types` — subpath `./types`
  - `unconditional`: `./src/types.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/types.ts); verified source file.

- `@lssm-tech/lib.gamification-runtime/xp` — subpath `./xp`
  - `unconditional`: `./src/xp.ts` — [pinned source](https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/domains/gamification/runtime/src/xp.ts); verified source file.

## Package publication metadata

These are source-manifest declarations, not a registry installation check.

```json
{
  "types": "./dist/index.d.ts",
  "files": [
    "dist",
    "README.md"
  ],
  "publishExports": {
    ".": {
      "types": "./dist/index.d.ts",
      "browser": "./dist/browser/index.js",
      "bun": "./dist/index.js",
      "node": "./dist/node/index.js",
      "default": "./dist/index.js"
    },
    "./cadence": {
      "types": "./dist/cadence.d.ts",
      "browser": "./dist/browser/cadence.js",
      "bun": "./dist/cadence.js",
      "node": "./dist/node/cadence.js",
      "default": "./dist/cadence.js"
    },
    "./campaign": {
      "types": "./dist/campaign.d.ts",
      "browser": "./dist/browser/campaign.js",
      "bun": "./dist/campaign.js",
      "node": "./dist/node/campaign.js",
      "default": "./dist/campaign.js"
    },
    "./conditions": {
      "types": "./dist/conditions.d.ts",
      "browser": "./dist/browser/conditions.js",
      "bun": "./dist/conditions.js",
      "node": "./dist/node/conditions.js",
      "default": "./dist/conditions.js"
    },
    "./economy": {
      "types": "./dist/economy.d.ts",
      "browser": "./dist/browser/economy.js",
      "bun": "./dist/economy.js",
      "node": "./dist/node/economy.js",
      "default": "./dist/economy.js"
    },
    "./leaderboard": {
      "types": "./dist/leaderboard.d.ts",
      "browser": "./dist/browser/leaderboard.js",
      "bun": "./dist/leaderboard.js",
      "node": "./dist/node/leaderboard.js",
      "default": "./dist/leaderboard.js"
    },
    "./matchmaking": {
      "types": "./dist/matchmaking.d.ts",
      "browser": "./dist/browser/matchmaking.js",
      "bun": "./dist/matchmaking.js",
      "node": "./dist/node/matchmaking.js",
      "default": "./dist/matchmaking.js"
    },
    "./posting-streak": {
      "types": "./dist/posting-streak.d.ts",
      "browser": "./dist/browser/posting-streak.js",
      "bun": "./dist/posting-streak.js",
      "node": "./dist/node/posting-streak.js",
      "default": "./dist/posting-streak.js"
    },
    "./slot-outcome": {
      "types": "./dist/slot-outcome.d.ts",
      "browser": "./dist/browser/slot-outcome.js",
      "bun": "./dist/slot-outcome.js",
      "node": "./dist/node/slot-outcome.js",
      "default": "./dist/slot-outcome.js"
    },
    "./social": {
      "types": "./dist/social.d.ts",
      "browser": "./dist/browser/social.js",
      "bun": "./dist/social.js",
      "node": "./dist/node/social.js",
      "default": "./dist/social.js"
    },
    "./streak": {
      "types": "./dist/streak.d.ts",
      "browser": "./dist/browser/streak.js",
      "bun": "./dist/streak.js",
      "node": "./dist/node/streak.js",
      "default": "./dist/streak.js"
    },
    "./types": {
      "types": "./dist/types.d.ts",
      "browser": "./dist/browser/types.js",
      "bun": "./dist/types.js",
      "node": "./dist/node/types.js",
      "default": "./dist/types.js"
    },
    "./xp": {
      "types": "./dist/xp.d.ts",
      "browser": "./dist/browser/xp.js",
      "bun": "./dist/xp.js",
      "node": "./dist/node/xp.js",
      "default": "./dist/xp.js"
    }
  }
}
```

## Dependencies

Metadata status: complete pinned manifest.

### Runtime dependencies

- [@lssm-tech/lib.gamification-spec](https://lssm.co/docs/packages/lib.gamification-spec/): `workspace:^`

### Peer dependencies

No declarations in the inspected manifest.

### Optional dependencies

No declarations in the inspected manifest.

### Development dependencies

- [@lssm-tech/tool.bun](https://lssm.co/docs/packages/tool.bun/): `workspace:*`
- [@lssm-tech/tool.typescript](https://lssm.co/docs/packages/tool.typescript/): `workspace:*`
- `typescript`: `catalog:`

### Peer dependency metadata

```json
{}
```

### Bundled dependencies

```json
null
```

## Package scripts

Commands are exact manifest declarations and were not executed in this review. Script metadata status: complete pinned manifest.

```json
{
  "build": "contractspec-bun-build build",
  "build:bundle": "contractspec-bun-build transpile",
  "build:types": "contractspec-bun-build types",
  "clean": "rimraf dist .turbo",
  "dev": "contractspec-bun-build dev",
  "lint": "bun lint:fix",
  "lint:check": "node ../../../../scripts/biome.cjs check .",
  "lint:fix": "node ../../../../scripts/biome.cjs check --write .",
  "prebuild": "contractspec-bun-build prebuild",
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
  "test": "bun test",
  "typecheck": "tsgo --noEmit"
}
```

## Declared documentation links

- [Lib Gamification Runtime documentation](https://www.npmjs.com/package/%40lssm-tech%2Flib.gamification-runtime) — declared link; destination not verified.

```json
{
  "url": "https://www.npmjs.com/package/%40lssm-tech%2Flib.gamification-runtime",
  "kind": "readme"
}
```

## Existing agent-guide projection

```json
{
  "path": "packages/apps/web-landing/public/llms-packages/lib.gamification-runtime.txt",
  "route": "/llms/lib.gamification-runtime",
  "sourceUrl": "https://github.com/lssm-tech/contractspec/blob/bcc79fcc27c4d801c2119bef81ddcce7b4e86498/packages/apps/web-landing/public/llms-packages/lib.gamification-runtime.txt",
  "blobSha": "4050e1e88f9457e8523a1b08be1a5fbb5c6ccfa4",
  "sourcePin": "bcc79fcc27c4d801c2119bef81ddcce7b4e86498",
  "bodyEqualsReadme": true,
  "aggregateSourcePath": "packages/apps/web-landing/public/llms-full.txt",
  "aggregateBlobSha": "691b1d33efee24c440598b9106c81432f56aafaf"
}
```
