← Back to Skills Marketplace
534422530

习惯追踪

by 534422530 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
28
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install laosi-habit-checkin
Description
习惯追踪 - 每天打卡,自动计算连续天数/历史最佳/总打卡数,多习惯管理,本地JSON持久化
README (SKILL.md)

Habit Checkin - 习惯追踪

激活词: 打卡 / 签到 / 习惯 / checkin

功能

  • 每日一键打卡
  • 自动计算连续天数(streak)
  • 历史最佳记录
  • 多习惯独立追踪
  • 本地 JSON 持久化

Python 实现

import os, json
from datetime import datetime, date

HABIT_FILE = os.path.join(os.path.dirname(__file__), "habit_streaks.json")

class HabitTracker:
    def __init__(self):
        os.makedirs(os.path.dirname(HABIT_FILE), exist_ok=True)
        self.habits = self._load()
    
    def _load(self):
        if os.path.exists(HABIT_FILE):
            with open(HABIT_FILE, encoding="utf-8") as f:
                return json.load(f)
        return {}
    
    def _save(self):
        with open(HABIT_FILE, "w", encoding="utf-8") as f:
            json.dump(self.habits, f, ensure_ascii=False, indent=2)
    
    def _today(self):
        return date.today().isoformat()
    
    def checkin(self, name: str = "default") -> dict:
        """打卡一次"""
        today = self._today()
        if name not in self.habits:
            self.habits[name] = {
                "dates": [],
                "streak": 0,
                "best": 0,
                "total": 0,
                "created": today
            }
        
        h = self.habits[name]
        
        if today in h["dates"]:
            return {"status": "already_done", "habit": name, "streak": h["streak"]}
        
        # 检查是否连续
        h["dates"].append(today)
        h["total"] += 1
        
        if h["dates"]:
            last_date = h["dates"][-2] if len(h["dates"]) >= 2 else None
            from datetime import timedelta
            if last_date and date.fromisoformat(last_date) == date.today() - timedelta(days=1):
                h["streak"] += 1
            else:
                h["streak"] = 1
        else:
            h["streak"] = 1
        
        if h["streak"] > h["best"]:
            h["best"] = h["streak"]
        
        self._save()
        return {
            "status": "checked_in",
            "habit": name,
            "streak": h["streak"],
            "best": h["best"],
            "total": h["total"]
        }
    
    def stats(self, name: str = "default") -> dict:
        """查看习惯统计"""
        if name not in self.habits:
            return {"exists": False}
        h = self.habits[name]
        return {
            "exists": True,
            "habit": name,
            "streak": h["streak"],
            "best": h["best"],
            "total": h["total"],
            "last_checkin": h["dates"][-1] if h["dates"] else None,
            "created": h["created"]
        }
    
    def list_all(self) -> list:
        """列出所有习惯"""
        return [self.stats(n) for n in self.habits]

# 使用示例
tracker = HabitTracker()

# 每天早上打卡
result = tracker.checkin("阅读")
if result["status"] == "checked_in":
    print(f"✅ {result['habit']} 打卡成功!连续 {result['streak']} 天")
elif result["status"] == "already_done":
    print(f"✅ 今天已打卡,连续 {result['streak']} 天")

# 查看统计
s = tracker.stats("阅读")
print(f"📊 {s['habit']}: 连续{s['streak']}天 🏆最佳{s['best']}天 📅共{s['total']}天")

# 一周戒糖打卡
tracker.checkin("戒糖")

命令行用法

# 阅读打卡
python -c "from habit_tracker import HabitTracker; r=HabitTracker().checkin('阅读'); print(f'连续{r[\"streak\"]}天')"

# 查看所有习惯
python -c "from habit_tracker import HabitTracker; [print(f'{s[\"habit\"]}: {s[\"streak\"]}d') for s in HabitTracker().list_all()]"

数据格式

{
  "阅读": {
    "dates": ["2026-05-26", "2026-05-27", "2026-05-28"],
    "streak": 3,
    "best": 7,
    "total": 15,
    "created": "2026-05-01"
  }
}

使用场景

  1. 阅读习惯: 每天读10分钟书,打卡记录
  2. 健身打卡: 跑步/健身/拉伸,坚持看得见
  3. 早睡早起: 23点前睡+7点前起,双重打卡
  4. 戒断习惯: 戒糖/戒烟/戒刷短视频,天数就是动力
  5. 学习追踪: 每天学英语/编程,连续天数激励

核心心理机制

  • 不要断链(Don't break the chain) — Jerry Seinfeld 的经典方法
  • 连续天数 > 总天数 — streak 比 total 更有激励性
  • 最佳记录 — 激励你超越自己的历史高点

依赖

  • Python 3.8+
  • 无第三方依赖
Usage Guidance
Before installing, note that words like “习惯”, “打卡”, and “签到” may activate the skill in ordinary conversation. Confirm the habit name before recording a check-in if accidental entries would bother you; the stored data appears limited to local habit dates and streak counts.
Capability Assessment
Purpose & Capability
The stated purpose is daily habit check-in tracking, streak calculation, and multi-habit stats; the included Python code directly matches that purpose.
Instruction Scope
The activation words are broad Chinese terms for habits and check-ins, which could trigger more often than intended, but the resulting action is limited to local habit tracking.
Install Mechanism
The package contains only SKILL.md, declares no third-party dependencies, and static scan metadata reports no suspicious patterns.
Credentials
The code uses standard Python file and JSON APIs only, with no network, credentials, shell execution, or broad filesystem scanning.
Persistence & Privilege
The skill intentionally persists habit data to a local habit_streaks.json file, which is disclosed and proportionate for a habit tracker.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install laosi-habit-checkin
  3. After installation, invoke the skill by name or use /laosi-habit-checkin
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release of habit-checkin. - Track daily habits with one-click check-in. - Automatic calculation of current streak, best streak, and total check-ins. - Support for managing multiple independent habits. - All data is stored locally in JSON for privacy and persistence. - Simple Python implementation with no external dependencies.
Metadata
Slug laosi-habit-checkin
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is 习惯追踪?

习惯追踪 - 每天打卡,自动计算连续天数/历史最佳/总打卡数,多习惯管理,本地JSON持久化. It is an AI Agent Skill for Claude Code / OpenClaw, with 28 downloads so far.

How do I install 习惯追踪?

Run "/install laosi-habit-checkin" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is 习惯追踪 free?

Yes, 习惯追踪 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does 习惯追踪 support?

习惯追踪 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created 习惯追踪?

It is built and maintained by 534422530 (@534422530); the current version is v1.0.0.

💬 Comments