Skip to content

Commit 07b4e8b

Browse files
Copilotnitrocodecoderabbitai[bot]CodeRabbit
authored
feat: implement AI Guilt-O-Meter (Phase 3 PRD #2) (#106)
* feat: implement AI Guilt-O-Meter (Phase 3 PRD #2) Agent-Logs-Url: https://github.com/nitrocode/token-deathclock/sessions/26d4dab7-c844-4225-b1f6-3530f6167a53 Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com> * docs: add LEARNINGS entry for AI Guilt-O-Meter PR Agent-Logs-Url: https://github.com/nitrocode/token-deathclock/sessions/26d4dab7-c844-4225-b1f6-3530f6167a53 Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com> * fix: apply CodeRabbit auto-fixes Fixed 2 file(s) based on 2 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai> --------- Signed-off-by: RB <7775707+nitrocode@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
1 parent d2d12fa commit 07b4e8b

10 files changed

Lines changed: 301 additions & 2 deletions

File tree

‎death-clock-core.js‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,40 @@ function getDailyHoroscope(nowMs, templates) {
823823
return templates[day % templates.length];
824824
}
825825

826+
// ============================================================
827+
// AI GUILT-O-METER (Phase 3 PRD #2)
828+
// ============================================================
829+
830+
/**
831+
* Label thresholds for the Guilt-O-Meter progress bar.
832+
* Each entry defines the minimum fill percentage at which that label is shown.
833+
* Sorted ascending by `min`; the highest matching entry wins.
834+
*/
835+
const GUILT_LABELS = [
836+
{ min: 0, icon: '\uD83D\uDE10', text: 'Mildly Aware' },
837+
{ min: 20, icon: '\uD83D\uDE1F', text: 'Mild Regret' },
838+
{ min: 40, icon: '\uD83D\uDE2C', text: 'Full Doomscroller' },
839+
{ min: 60, icon: '\uD83D\uDE30', text: 'Carbon Hypocrite in Training' },
840+
{ min: 80, icon: '\uD83D\uDE31', text: 'Fully Complicit' },
841+
{ min: 100, icon: '\uD83D\uDC80', text: 'Certified Hypocrite' },
842+
];
843+
844+
/**
845+
* Return the guilt label entry for a given fill percentage (0–100).
846+
* Returns the entry with the highest `min` value that is ≤ pct.
847+
*
848+
* @param {number} pct - Fill percentage, clamped to [0, 100]
849+
* @returns {{ min: number, icon: string, text: string }}
850+
*/
851+
function getGuiltLabel(pct) {
852+
const clamped = Math.max(0, Math.min(100, pct));
853+
let result = GUILT_LABELS[0];
854+
for (const label of GUILT_LABELS) {
855+
if (clamped >= label.min) result = label;
856+
}
857+
return result;
858+
}
859+
826860
// ============================================================
827861
// EXPORTS — CommonJS for Jest; window global for the browser
828862
// ============================================================
@@ -865,6 +899,8 @@ const DeathClockCore = {
865899
getSimulatedViewerCount,
866900
HOROSCOPE_TEMPLATES,
867901
getDailyHoroscope,
902+
GUILT_LABELS,
903+
getGuiltLabel,
868904
};
869905

870906
/* istanbul ignore else */

‎docs/LEARNINGS.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ Entries are grouped by release. Add new entries at the top of the appropriate re
144144

145145
### v1.7.x
146146

147+
#### PR #106 — feat: implement AI Guilt-O-Meter (Phase 3 PRD #2)
148+
149+
- **Problem:** Phase 3 PRD #2 (AI Guilt-O-Meter) was the next unimplemented low-effort high-impact feature; the site lacked a persistent emotional hook to keep sessions engaged past the initial counter shock.
150+
- **Approach:** Added `GUILT_LABELS` constant and `getGuiltLabel(pct)` pure function to `death-clock-core.js` for unit-testability; created `src/js/22-guilt-meter.js` with `initGuiltMeter()` / `updateGuiltMeter()` updating on the existing 1s interval; added HTML `<progress>` element with ARIA attributes and a share button; renamed `22-boot.js` → `23-boot.js` to maintain strict sequential file ordering; added the `certified_hypocrite` badge to `BADGE_DEFS`.
151+
- **Learning:** Progress bar fill transitions in CSS require `appearance: none` plus browser-prefixed pseudo-elements (`::-webkit-progress-value`, `::-moz-progress-bar`) to render correctly across Chromium and Firefox. Always add both. (→ CSS)
152+
- **Key files:** `death-clock-core.js`, `src/js/22-guilt-meter.js`, `src/js/23-boot.js`, `src/js/14-badges.js`, `scripts/build-js.js`, `index.html`, `styles/features.css`, `tests/death-clock.test.js`
153+
154+
---
155+
147156
#### PR #107 — fix: extinction countdown ticks down by 2 seconds instead of 1
148157

149158
- **Problem:** The extinction countdown header displayed the seconds decreasing by ~2 per tick instead of 1, because `updateExtinctionCountdown` used `tokensRemaining / currentRate` (linear approximation) while `getCurrentTokens` uses an exponentially-growing integral model.
@@ -153,7 +162,7 @@ Entries are grouped by release. Add new entries at the top of the appropriate re
153162

154163
---
155164

156-
165+
#### PR #103 — feat: implement Token Horoscope daily satirical AI horoscope (Phase 3 PRD #1)
157166

158167
- **Problem:** The site had no daily-rotating content to drive return visits; Phase 3 PRD #1 (Token Horoscope) was the highest-impact lowest-effort unimplemented feature.
159168
- **Approach:** Added `HOROSCOPE_TEMPLATES` (30 entries) and `getDailyHoroscope(nowMs, templates)` pure function to `death-clock-core.js`; wired up a new `src/js/21-horoscope.js` DOM module with `<details>/<summary>` collapse, localStorage date tracking, and a share button reusing `openSharePopup()`.

‎index.html‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,32 @@ <h2>Global Token Counter</h2>
203203
</div>
204204
</section>
205205

206+
<!-- ── AI Guilt-O-Meter (Phase 3 PRD #2) ───────────────────── -->
207+
<section id="guilt-meter-section">
208+
<div class="container">
209+
<div class="guilt-meter-wrap">
210+
<div class="guilt-meter-header">
211+
<span class="guilt-meter-title">😬 Your Guilt Level</span>
212+
<span class="guilt-meter-hint">filling up the longer you stay…</span>
213+
</div>
214+
<progress
215+
id="guiltMeterBar"
216+
class="guilt-meter-bar"
217+
value="0"
218+
max="100"
219+
aria-valuemin="0"
220+
aria-valuemax="100"
221+
aria-valuenow="0"
222+
aria-label="Mildly Aware"
223+
></progress>
224+
<div class="guilt-meter-label-row">
225+
<span id="guiltMeterLabel" class="guilt-meter-label" aria-live="polite" aria-atomic="true">😐 Mildly Aware</span>
226+
</div>
227+
<button id="guiltShareBtn" class="btn-sm guilt-share-btn" hidden>📤 Share My Guilt</button>
228+
</div>
229+
</div>
230+
</section>
231+
206232
<!-- ── Daily AI Horoscope ────────────────────────────────── -->
207233
<section id="horoscope-section">
208234
<div class="container">

‎scripts/build-js.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const PARTS = [
4444
'19-milestone-alert.js',
4545
'20-tabs.js',
4646
'21-horoscope.js',
47-
'22-boot.js',
47+
'22-guilt-meter.js',
48+
'23-boot.js',
4849
];
4950

5051
const HEADER = [

‎src/js/00-state.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
getSimulatedViewerCount,
3838
HOROSCOPE_TEMPLATES,
3939
getDailyHoroscope,
40+
GUILT_LABELS,
41+
getGuiltLabel,
4042
} = window.DeathClockCore;
4143

4244
// ---- Unpack changelog data ----------------------------------

‎src/js/14-badges.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
{ id: 'lights_out', icon: '☠️', name: 'Lights Out', desc: 'Replaced every human worker. Fully automated.', type: 'manual' },
3030
// Witness badges
3131
{ id: 'witness', icon: '👁️', name: 'Witness', desc: 'Stayed to watch a milestone get crossed in real time.', type: 'manual' },
32+
// Guilt-O-Meter badge
33+
{ id: 'certified_hypocrite', icon: '\uD83D\uDE2C', name: 'Certified Hypocrite', desc: 'Watched the apocalypse for 5 minutes without doing anything about it.', type: 'manual' },
3234
];
3335

3436
const LS_BADGES_KEY = 'tokenDeathclockBadges';

‎src/js/22-guilt-meter.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ---- AI Guilt-O-Meter (Phase 3 PRD #2) ----------------------
2+
3+
const GUILT_DURATION_MS = 300000; // 5 minutes → 100 %
4+
5+
let _guiltCertified = false;
6+
7+
function updateGuiltMeter() {
8+
const bar = document.getElementById('guiltMeterBar');
9+
const labelEl = document.getElementById('guiltMeterLabel');
10+
const shareBtn = document.getElementById('guiltShareBtn');
11+
if (!bar || !labelEl) return;
12+
13+
const elapsed = Math.max(0, Date.now() - pageLoadTime);
14+
const pct = Math.min(100, Math.floor((elapsed / GUILT_DURATION_MS) * 100));
15+
const label = getGuiltLabel(pct);
16+
const labelText = label.icon + '\u00A0' + label.text;
17+
18+
bar.value = pct;
19+
bar.setAttribute('aria-valuenow', pct);
20+
bar.setAttribute('aria-label', labelText);
21+
labelEl.textContent = labelText;
22+
23+
if (shareBtn) shareBtn.hidden = pct < 20;
24+
25+
if (pct >= 100 && !_guiltCertified) {
26+
_guiltCertified = true;
27+
awardBadge('certified_hypocrite');
28+
}
29+
}
30+
31+
function initGuiltMeter() {
32+
const shareBtn = document.getElementById('guiltShareBtn');
33+
34+
if (shareBtn) {
35+
shareBtn.addEventListener('click', () => {
36+
const elapsed = Math.max(0, Date.now() - pageLoadTime);
37+
const mins = Math.floor(elapsed / 60000) || 1;
38+
const labelEl = document.getElementById('guiltMeterLabel');
39+
const labelText = labelEl ? labelEl.textContent : '';
40+
const shareText =
41+
'\uD83D\uDE2C I\u2019ve been watching AI consume tokens for ' +
42+
mins + ' minute' + (mins !== 1 ? 's' : '') +
43+
' and done absolutely nothing about it.' +
44+
' My guilt level: ' + labelText +
45+
'. Are you as bad as me?\n\u2192 ' + SITE_URL +
46+
' #TokenDeathClock #CertifiedHypocrite';
47+
openSharePopup(shareText);
48+
awardBadge('spreading_doom');
49+
});
50+
}
51+
52+
// Render initial state
53+
updateGuiltMeter();
54+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
initCalculator();
5050
initAccelerator();
5151
initHoroscope();
52+
initGuiltMeter();
5253
// Engagement features
5354
initPresenceStrip();
5455
initEventLog();
@@ -78,6 +79,7 @@
7879
checkTimeBadges();
7980
checkMilestoneAlert();
8081
updateExtinctionCountdown();
82+
updateGuiltMeter();
8183
}, 1000);
8284
}
8385

‎styles/features.css‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,83 @@
725725
.calc-result-grid { grid-template-columns: 1fr 1fr; }
726726
}
727727

728+
/* ---- AI Guilt-O-Meter ---- */
729+
.guilt-meter-wrap {
730+
background: var(--surface-2);
731+
border: 1px solid var(--border);
732+
border-radius: 0.75rem;
733+
padding: 1rem 1.25rem;
734+
margin-top: 1.5rem;
735+
}
736+
737+
.guilt-meter-header {
738+
display: flex;
739+
align-items: baseline;
740+
gap: 0.6rem;
741+
margin-bottom: 0.6rem;
742+
flex-wrap: wrap;
743+
}
744+
745+
.guilt-meter-title {
746+
font-size: 0.9rem;
747+
font-weight: 700;
748+
color: var(--text);
749+
}
750+
751+
.guilt-meter-hint {
752+
font-size: 0.78rem;
753+
color: var(--text-muted);
754+
font-style: italic;
755+
}
756+
757+
.guilt-meter-bar {
758+
width: 100%;
759+
height: 1.1rem;
760+
border-radius: 0.55rem;
761+
overflow: hidden;
762+
appearance: none;
763+
-webkit-appearance: none;
764+
background: var(--surface-3, var(--surface-2));
765+
border: 1px solid var(--border);
766+
display: block;
767+
transition: width 0.6s ease;
768+
}
769+
770+
/* WebKit / Blink */
771+
.guilt-meter-bar::-webkit-progress-bar {
772+
background: var(--surface-3, var(--surface-2));
773+
border-radius: 0.55rem;
774+
}
775+
.guilt-meter-bar::-webkit-progress-value {
776+
background: linear-gradient(90deg, var(--accent, #38d9a9) 0%, var(--danger, #ff6b6b) 100%);
777+
border-radius: 0.55rem;
778+
transition: width 0.6s ease;
779+
}
780+
781+
/* Firefox */
782+
.guilt-meter-bar::-moz-progress-bar {
783+
background: linear-gradient(90deg, var(--accent, #38d9a9) 0%, var(--danger, #ff6b6b) 100%);
784+
border-radius: 0.55rem;
785+
transition: width 0.6s ease;
786+
}
787+
788+
.guilt-meter-label-row {
789+
display: flex;
790+
align-items: center;
791+
justify-content: space-between;
792+
margin-top: 0.45rem;
793+
}
794+
795+
.guilt-meter-label {
796+
font-size: 0.88rem;
797+
font-weight: 600;
798+
color: var(--text);
799+
}
800+
801+
.guilt-share-btn {
802+
margin-top: 0.75rem;
803+
}
804+
728805
/* ---- Reduced motion ---- */
729806
@media (prefers-reduced-motion: reduce) {
730807
.toast, .toast-in, .toast-out,
@@ -733,5 +810,8 @@
733810
.ai-ticker-text { transition: none; animation: none; }
734811
.badge-item.badge-anim-out,
735812
.badge-item.badge-anim-in { animation: none; opacity: 1; transform: none; filter: none; }
813+
.guilt-meter-bar,
814+
.guilt-meter-bar::-webkit-progress-value,
815+
.guilt-meter-bar::-moz-progress-bar { transition: none; }
736816
}
737817

‎tests/death-clock.test.js‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,3 +1686,90 @@ describe('getDailyHoroscope', () => {
16861686
expect(HOROSCOPE_TEMPLATES).toContain(result);
16871687
});
16881688
});
1689+
1690+
// ============================================================
1691+
// GUILT_LABELS
1692+
// ============================================================
1693+
const { GUILT_LABELS, getGuiltLabel } = core;
1694+
1695+
describe('GUILT_LABELS', () => {
1696+
test('is a non-empty array', () => {
1697+
expect(Array.isArray(GUILT_LABELS)).toBe(true);
1698+
expect(GUILT_LABELS.length).toBeGreaterThan(0);
1699+
});
1700+
1701+
test('every entry has min, icon, and text properties', () => {
1702+
GUILT_LABELS.forEach((label) => {
1703+
expect(typeof label.min).toBe('number');
1704+
expect(typeof label.icon).toBe('string');
1705+
expect(label.icon.length).toBeGreaterThan(0);
1706+
expect(typeof label.text).toBe('string');
1707+
expect(label.text.length).toBeGreaterThan(0);
1708+
});
1709+
});
1710+
1711+
test('first entry has min === 0', () => {
1712+
expect(GUILT_LABELS[0].min).toBe(0);
1713+
});
1714+
1715+
test('entries are sorted ascending by min', () => {
1716+
for (let i = 1; i < GUILT_LABELS.length; i++) {
1717+
expect(GUILT_LABELS[i].min).toBeGreaterThan(GUILT_LABELS[i - 1].min);
1718+
}
1719+
});
1720+
1721+
test('includes a 100% Certified Hypocrite entry', () => {
1722+
const full = GUILT_LABELS.find((l) => l.min === 100);
1723+
expect(full).toBeDefined();
1724+
expect(full.text).toContain('Certified Hypocrite');
1725+
});
1726+
});
1727+
1728+
// ============================================================
1729+
// getGuiltLabel
1730+
// ============================================================
1731+
describe('getGuiltLabel', () => {
1732+
test('returns the first label for pct === 0', () => {
1733+
const result = getGuiltLabel(0);
1734+
expect(result).toBe(GUILT_LABELS[0]);
1735+
});
1736+
1737+
test('returns the correct label at each threshold boundary', () => {
1738+
GUILT_LABELS.forEach((label) => {
1739+
const result = getGuiltLabel(label.min);
1740+
expect(result).toBe(label);
1741+
});
1742+
});
1743+
1744+
test('returns the last label for pct === 100', () => {
1745+
const last = GUILT_LABELS[GUILT_LABELS.length - 1];
1746+
expect(getGuiltLabel(100)).toBe(last);
1747+
});
1748+
1749+
test('returns the Certified Hypocrite label for pct > 100 (clamped)', () => {
1750+
const last = GUILT_LABELS[GUILT_LABELS.length - 1];
1751+
expect(getGuiltLabel(200)).toBe(last);
1752+
});
1753+
1754+
test('returns the first label for negative pct (clamped)', () => {
1755+
expect(getGuiltLabel(-10)).toBe(GUILT_LABELS[0]);
1756+
});
1757+
1758+
test('returns the correct label for mid-range values', () => {
1759+
// pct = 50 should be 'Full Doomscroller' (min 40) but not 'Carbon Hypocrite in Training' (min 60)
1760+
const result = getGuiltLabel(50);
1761+
expect(result.text).toBe('Full Doomscroller');
1762+
});
1763+
1764+
test('returns an object with icon and text properties', () => {
1765+
const result = getGuiltLabel(30);
1766+
expect(typeof result.icon).toBe('string');
1767+
expect(typeof result.text).toBe('string');
1768+
});
1769+
1770+
test('boundary just below a threshold returns the previous label', () => {
1771+
// pct = 39 should be 'Mild Regret' (min 20), not 'Full Doomscroller' (min 40)
1772+
const result = getGuiltLabel(39);
1773+
expect(result.text).toBe('Mild Regret');
1774+
});
1775+
});

0 commit comments

Comments
 (0)