docs(contrib): scheduling templates for mempalace-pi-session

Drop-in equivalents of the opencode templates for each scheduler
mechanism:

  systemd/mempalace-pi-session.{service,timer}
  launchd/se.jordbo.mempalace-pi-session.plist
  cron/mempalace-pi-session.cron

Schedule is staggered from the opencode jobs (Mon 03:00 -> Tue 03:00)
so machines running both don't race each other on the post-mine HNSW
repair step. Service unit uses ConditionPathExists=%h/.pi/agent/sessions
to no-op silently on machines that haven't used pi, matching the
opencode template's guard on ~/.local/share/opencode/opencode.db.

contrib/README.md grows a 'Templates at a glance' table so the set is
discoverable without reading the whole doc.
This commit is contained in:
2026-05-05 08:48:33 +02:00
parent 14d253f929
commit 53d96adc65
5 changed files with 155 additions and 4 deletions
+19 -4
View File
@@ -1,11 +1,26 @@
# contrib/ — automation recipes for `mempalace-session`
# contrib/ — automation recipes for `mempalace-session` and `mempalace-pi-session`
Manual invocation of `mempalace-session` is fine on a machine you actively drive. For long-running devboxes, a weekly automated mine keeps the palace fresh without thinking about it. This directory ships ready-to-use templates for two common scheduling mechanisms.
Manual invocation of the session-mining wrappers is fine on a machine you actively drive. For long-running devboxes, a weekly automated mine keeps the palace fresh without thinking about it. This directory ships ready-to-use templates for two common scheduling mechanisms, for each wrapper.
> **Before using either**: confirm the toolkit is installed and the wrapper works —
> `mempalace-session --dry-run` should list qualifying sessions. If that errors, fix the install before scheduling.
> `mempalace-session --dry-run` (and/or `mempalace-pi-session --dry-run`) should list qualifying sessions. If that errors, fix the install before scheduling.
Pick **one**. Running both would double-mine (harmless — dedup skips everything on the second run — but wastes wall time on the HNSW repair).
Pick **one scheduler** (systemd *or* launchd *or* cron). The opencode and pi jobs can be installed side by side and staggered — templates ship with Mon 03:00 for opencode, Tue 03:00 for pi to avoid racing the post-mine HNSW repair.
## Templates at a glance
| File | What it schedules | When |
|---|---|---|
| `systemd/mempalace-session.{service,timer}` | opencode → palace | Mon 03:00 |
| `systemd/mempalace-pi-session.{service,timer}` | pi → palace | Tue 03:00 |
| `systemd/mempalace-session-devbox.{service,timer}` | opencode (inside a devbox container) → palace | Mon 03:00 |
| `launchd/se.jordbo.mempalace-session.plist` | opencode → palace (macOS) | Mon 03:00 |
| `launchd/se.jordbo.mempalace-pi-session.plist` | pi → palace (macOS) | Tue 03:00 |
| `cron/mempalace-session.cron` | opencode → palace | Mon 03:00 |
| `cron/mempalace-pi-session.cron` | pi → palace | Tue 03:00 |
| `cron/mempalace-session-devbox.cron` | opencode (devbox) → palace | Mon 03:00 |
The pi variants are drop-in copies of the opencode variants with script name and schedule updated; the install recipes below apply equally — just swap `mempalace-session` for `mempalace-pi-session` and the schedule day.
---
+18
View File
@@ -0,0 +1,18 @@
# Sample crontab entry for mempalace-pi-session.
#
# Runs a full pi → MemPalace mine weekly (Tuesdays at 03:00 local).
# Staggered from mempalace-session.cron (Mondays) so if both are installed
# they don't race the post-mine HNSW repair step.
#
# To install:
# (crontab -l 2>/dev/null; cat contrib/cron/mempalace-pi-session.cron) | crontab -
#
# To remove, edit your crontab:
# crontab -e
#
# Replace USER with your actual username.
PATH=/home/USER/.local/bin:/usr/local/bin:/usr/bin:/bin
# m h dom mon dow command
0 3 * * 2 mempalace-pi-session >> /home/USER/.cache/mempalace-pi-session/cron.log 2>&1
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!--
se.jordbo.mempalace-pi-session.plist — macOS launchd user agent
that mines pi coding-agent session history into MemPalace weekly.
Template: replace USER with your macOS short username before installing.
The install recipe in contrib/README.md does this for you via `sed`.
Parity with contrib/systemd/mempalace-pi-session.{service,timer}:
- Weekly Tue 03:00 local time → StartCalendarInterval below.
(Staggered from the opencode one, which runs Mon 03:00.)
- Low-priority background I/O → ProcessType=Background + LowPriorityIO.
- Single-instance guard → launchd refuses to start a second copy of
the same Label while one is running.
- "Skip if pi has never been used" → no native equivalent.
mempalace-pi-session exits cleanly (zero drawers filed, fast) when
~/.pi/agent/sessions is absent, so no guard is strictly needed.
-->
<key>Label</key>
<string>se.jordbo.mempalace-pi-session</string>
<key>ProgramArguments</key>
<array>
<string>/Users/USER/.local/bin/mempalace-pi-session</string>
</array>
<!-- launchd gives agents a minimal PATH. mempalace-pi-session invokes
`mempalace` and `python3`, both must resolve. -->
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/Users/USER/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
<key>HOME</key>
<string>/Users/USER</string>
</dict>
<!-- Weekly, Tuesday 03:00 local time. Staggered from the opencode job
(Mon 03:00) so a machine with both installed won't race the HNSW
repair step. -->
<key>StartCalendarInterval</key>
<dict>
<key>Weekday</key>
<integer>2</integer>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<key>RunAtLoad</key>
<false/>
<key>ProcessType</key>
<string>Background</string>
<key>LowPriorityIO</key>
<true/>
<key>Nice</key>
<integer>10</integer>
<!-- Runaway guard. Pi corpora are typically smaller than opencode's
(short tactical sessions), so 2h is generous. -->
<key>ExitTimeOut</key>
<integer>7200</integer>
<!-- Logs. Tail with:
tail -f ~/Library/Logs/mempalace-pi-session.log -->
<key>StandardOutPath</key>
<string>/Users/USER/Library/Logs/mempalace-pi-session.log</string>
<key>StandardErrorPath</key>
<string>/Users/USER/Library/Logs/mempalace-pi-session.err.log</string>
</dict>
</plist>
@@ -0,0 +1,23 @@
[Unit]
Description=Mine pi coding-agent session history into MemPalace
Documentation=https://gitea.jordbo.se/joakimp/mempalace-toolkit
# Only run if pi has actually been used (avoids noise on idle machines)
ConditionPathExists=%h/.pi/agent/sessions
# Don't start if a previous run is still going
ConditionPathExists=!%t/mempalace-pi-session.lock
[Service]
Type=oneshot
# The wrapper writes to ~/.cache/mempalace-pi-session/ and the palace.
# Keep stdout/stderr in the journal — inspect with:
# journalctl --user -u mempalace-pi-session --since today
ExecStart=%h/.local/bin/mempalace-pi-session
# Belt-and-braces lock so two overlapping runs can't corrupt staging
ExecStartPre=/bin/sh -c 'touch %t/mempalace-pi-session.lock'
ExecStopPost=/bin/sh -c 'rm -f %t/mempalace-pi-session.lock'
# Protect against runaway runs. Pi sessions tend to be short/tactical so the
# corpus is much smaller than opencode's; 2h is generous headroom.
TimeoutStartSec=7200
# Low priority — this is background maintenance
Nice=10
IOSchedulingClass=idle
@@ -0,0 +1,18 @@
[Unit]
Description=Weekly pi → MemPalace session mine
Documentation=https://gitea.jordbo.se/joakimp/mempalace-toolkit
[Timer]
# Every Tuesday at 03:00 local time. Staggered from mempalace-session.timer
# (Mon 03:00) so if both are installed, the HNSW repair step in one doesn't
# race the repair step in the other.
# Use `systemctl --user list-timers mempalace-pi-session.timer` to see next run.
OnCalendar=Tue 03:00
# If the machine was off at the scheduled time, run at next boot.
Persistent=true
# Randomize up to 30 minutes to avoid thundering-herd across machines.
RandomizedDelaySec=30m
AccuracySec=1m
[Install]
WantedBy=timers.target