Habit tracker — add a daily entry
Files and layout
- Location:
data/habit-tracker/*.ts(one file per habit). - Each file ends with a sentinel row (not a real log):
{ date: '2026-12-31', count: 1, level: 4 }. - Never remove or move that sentinel; never append after it.
- The last real entry is always the second-to-last object in the array (the line immediately above the sentinel).
Before editing
- Today’s date: Use the date from user/chat context when provided (e.g. “Today’s date” in user_info). If missing, ask the user for
YYYY-MM-DDor confirm you should use the system date. - Which habit(s): If the user names one file (e.g.
sunscreen.ts), only edit that file. If they say “all habits” or “every habit”, apply the same insertion to eachdata/habit-tracker/*.tsfile.
Insertion rule
Insert one new line after the last real entry and before the sentinel:
{ date: 'YYYY-MM-DD', count: 1, level: 4 },
Preserve existing formatting: two spaces before {, trailing comma on the new line, comma kept on the previous last-real line.
Validation
- If the last real entry’s
dateequals the new date, do not add a duplicate; tell the user it’s already logged and ask whether to changecount/levelinstead. - If the new date is before the last real date, warn that rows are usually chronological; ask whether they want a backfill or to fix order manually.
- If the new date is after the last real date (normal case), proceed after confirmation.
Export names (do not rename)
Match each file’s existing const and export default names, e.g. readBook in read-book.ts, studyMl in study-ml.ts, intermittentFasting in intermittent-fasting.ts.
Checklist
- Identified file(s) under
data/habit-tracker/ - Confirmed target date (
count: 1,level: 4unless user overrides) - Inserted the new row above
{ date: '2026-12-31', count: 0, level: 0 } - Left sentinel as the last element
Source: imteekay/iamtk.co — distributed by TomeVault.