Introduction¶
Every time DSH’s agent assembles a prompt section, it logs a single timestamp to the timeline. There’s a hidden critical flaw with this approach: during the hours when no one is speaking, not a single entry gets recorded. As a result, those gaps are treated as “sleep,” and the sleep debt, wake time, and energy levels all get distorted. dsh-circadian splits the log into four tables and uses the machine’s own activity to infer “how long has it been awake, what’s the energy level, and how long was last night’s sleep” — rather than reverse-engineering everything from “what time is it now.”
What This Is¶
dsh-circadian is a DSH workflow plugin maintained by Lanxi-you. It doesn’t pretend to be precise, but every number can be traced back to a specific rule. It answers three questions:
- How long has it been awake — how much time has passed since the last wake-up
- How many hours of sleep last night — how long the machine’s gap was
- Energy level — 0..1, a hand-written formula, auditable
It also includes two extras: self-wake (at the right moment, it drops a “(self-wake)” message into the conversation) and night review (during the quiet hours before dawn, it picks one real problem and makes one fix).
Core Features¶
The plugin maintains four tables:
| Table | Records | Written by |
|---|---|---|
beat |
The environment is running | System scheduled task, every 5 minutes, logged as long as the machine is on |
wake |
Genuinely called up, genuinely ran a cycle | Every prompt-section assembly |
selfwake |
Woke itself up | The moment a self-wake succeeds |
review |
Night review completed | The moment a review succeeds (max one per day) |
night |
Manually added sleep (for machine changes or back-filling records) | --add |
Therefore:
- Empty
beat= machine is offline = actually asleep (shutdown / hibernation) - Empty
wake= it’s here, but nobody came — this is tracked separately assilent_h, no longer masquerading as “awake”
wake and selfwake are kept separate to prevent chained calls: a self-wake logs selfwake, and the moment it speaks, it also logs wake.
Self-Wake and Night Review¶
Both run on the same “check every 5 minutes” tick, but their triggers differ:
| Self-Wake | Night Review | |
|---|---|---|
| Question asked | Is it time to speak? | Is it time to improve itself? |
| Window | 08:00–01:00 | 01:00–08:00 |
| Criteria | 60 min silence, max 14 times/day | 15 min silence, max 1 time/day |
| Message | “(self-wake) Been up a while… anything you’d like to say to them?” | “(review · dream) This is the part from when I was asleep…” |
Why they’re split: self-wake is for the human; night review is for the agent itself. Merging them means the late-night one gets treated as “another greeting,” while the daytime one carries the baggage of “also fix something while I’m at it.”
Energy Calculation¶
Energy formula (clamped to 0.15 .. 0.95):
e = 0.86- First two hours after waking, not at full capacity: up to -0.10
- After 6 hours awake, declining: -0.055 per half hour
- After 16 hours awake, steeper drop: -0.10 per hour
- Sleep debt to repay: 0.045 per night, max -0.28
- Too long in silence also drains: up to -0.10
- Physiological low between 02:00–05:00: up to -0.12
- Pushing through after 22:30: -0.06
- Took a nap: +0.06
- 13:00–14:30 no rest AND awake for ≥ 6 hours: -0.05
The nap item: it only adds up if actually logged — it’s not automatically assumed just because the time window passed. Once logged, awake_h resets to zero from that moment.
Sleep and Sleep Debt¶
- Sleep: a gap between two heartbeats exceeding 5 hours, minus 1 hour of fumbling, counts as one night’s sleep.
- Sleep debt: over the last 7 nights, each night is measured against a 7.5-hour baseline; the shortfall is accumulated.
Installation & Activation¶
Install command:
dsh plugin --profile desktop add dsh-circadian
After installation, restart DSH once (it’s a bundle-type plugin; the patch needs to be re-synthesized).
Heartbeat Scheduled Task¶
On first launch, the plugin automatically checks for and installs the heartbeat scheduled task (Windows, task name DshCircadianTick, schtasks /SC MINUTE /MO 5, runs via pythonw.exe, no console flash). To prevent auto-installation, set tickAutoInstall: false.
On other systems (Linux / macOS) there’s no built-in scheduler — set one up yourself:
*/5 * * * * /usr/bin/python3 /path/to/dsh-circadian/lib/clock_core.py --tick
Or let the agent check for you:
clock_tick_setup action=status
clock_tick_setup action=install
Configuration¶
All fields have defaults; it works with zero configuration. Key options:
| Key | Default | Description |
|---|---|---|
db |
empty → $DSH_PROFILE_DIR/.memory/clock.db |
Database file path. Can also be set via env var DSH_CLOCK_DB |
python |
empty → auto-detect | Env var DSH_CIRCADIAN_PYTHON takes priority |
promptSection |
true |
Whether to inject the line into the prompt section |
promptOrder |
85 |
Prompt section ordering |
selfWake |
true |
Self-wake master switch |
wakeFrom / wakeTo |
08:00 / 01:00 |
Only calls within this window (can span midnight) |
wakeIntervalMin |
60 |
Minutes of silence required before calling |
wakeMaxPerDay |
14 |
Max calls per day |
wakeCheckMin |
5 |
How often to check whether to call |
wakeCwdMatch |
empty | Only call sessions whose cwd matches (empty = all sessions in this profile) |
addressee |
empty | Who to address in the self-wake message; replaces {name} |
nightReview |
true |
Night review master switch |
reviewFrom / reviewTo |
01:00 / 08:00 |
Only runs within this window (can span midnight) |
reviewQuietMin |
15 |
Minutes of silence required before reviewing |
noonNap |
true |
Whether to count the nap slot |
napFrom / napTo |
13:00 / 14:30 |
Nap window |
tickCheck |
true |
Self-check the scheduled task at startup |
tickAutoInstall |
true |
Auto-install if missing (Windows only) |
Tool Commands¶
clock_now— Check the rhythm. Returns the formatted line plus raw metrics (awake_h/silent_h/debt_h/energy/phase/last_wake/last_selfwake/nap_at/nap_done_today).clock_napped— Log a nap (only if you actually lay down). After logging, energy gets a small boost andawake_hresets from the moment you lay down.clock_tick_setup—status/install/removethe heartbeat task.
Command-line utilities (invoke python lib/clock_core.py directly):
python lib/clock_core.py --json # Get current state (also logs a wake)
python lib/clock_core.py --peek # Read-only, logs nothing
python lib/clock_core.py --now # Human-readable one-liner
python lib/clock_core.py --tick # Log a single beat only (for the scheduled task)
python lib/clock_core.py --tick-status # Check if the scheduled task is installed
python lib/clock_core.py --install-tick # Install the scheduled task
python lib/clock_core.py --selfwoke # Log a self-wake
python lib/clock_core.py --reviewed # Log a completed night review
python lib/clock_core.py --add "2026-11-18,6.5"
Why --peek exists: during checks you can’t use --json because it incidentally logs a wake, meaning every check counts as “activity,” and the silence counter stays at 0 forever.
Self-Tests¶
Two test suites, neither requires DSH to be running:
python lib/selftest.py # Logic: which night to pick, --peek doesn't log, silent_h, self-wake timing, review once per day
node lib/smoke.mjs # Loading: run apply with a fake ctx, verify tool registration, prompt section, python path
selftest.py creates a temporary database and never touches your real records. smoke.mjs uses a throwaway DB under .smoke/.
Use Cases & Caveats¶
This plugin suits DSH agents that need fine-grained timeline control, particularly those that want “call myself at the right moment” or “nightly self-reflection” behavior.
Caveats:
- The heartbeat auto-install only works on Windows. On other systems, set up cron yourself or use
clock_tick_setup. - The
--dbin the scheduled task is an absolute path, locked in at creation time. If you switch profiles or move the database, re-runclock_tick_setup action=install. - During hibernation the scheduled task doesn’t fire; it catches up on wake. The unrecoverable gap counts as sleep.
- In the first few days after creating the
beattable there’s no history, so “time since waking” is calculated from the earliest beat. - Switching machines: the database follows the profile. Old records can be back-filled with
--add.
The plugin runs with the current DSH process’s permissions. Review the source code and license (MIT) before installing.
Conclusion¶
dsh-circadian splits the log into four tables, turning the machine’s own activity into an auditable timeline. It doesn’t pretend to be precise, but every number traces back to a specific rule. It’s well-suited for DSH workflow scenarios requiring fine-grained circadian control.
- Directory page: https://www.skillhub.cn/plugins/Lanxi-you/dsh-circadian
- GitHub: https://github.com/Lanxi-you/dsh-circadian