aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-30 11:18:32 +0100
committerDanilo M. <danix@danix.xyz>2026-11-30 11:18:32 +0100
commit202995fc8afab753a9e5c441932779c9a5249c96 (patch)
treefe051c09097e965c7e49f1ccebce3c270d34b415
parent41c503645122f3d2d79ea4a428d6eb72c399c5b5 (diff)
downloaddeck-it-202995fc8afab753a9e5c441932779c9a5249c96.tar.gz
deck-it-202995fc8afab753a9e5c441932779c9a5249c96.zip
feat(todo): read the Vikunja token from pass
[todo] pass names the pass entry holding the API token; it is read once and kept in memory, and read again after Vikunja answers 401. No token file on disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--AGENTS.md4
-rw-r--r--config.toml6
-rw-r--r--deckit/modules/todo.py36
-rw-r--r--docs/superpowers/specs/2026-11-30-todo-design.md6
-rw-r--r--tests/test_todo.py34
5 files changed, 62 insertions, 24 deletions
diff --git a/AGENTS.md b/AGENTS.md
index 8cbfc48..5b8d82a 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -40,8 +40,8 @@ Keep the server dependency-free apart from that one package.
hyprlock` every 2s and sends the tablet `KEYCODE_SLEEP` on lock and
`KEYCODE_WAKEUP` on unlock. (Its Dashboard icons were dropped; the name
stays because keystone's module toggle uses it.)
-- `todo` reads Vikunja (`[todo] url`, an API token in
- `~/.config/deck-it/vikunja-token`) every 60s: open tasks due today or
+- `todo` reads Vikunja (`[todo] url`; an API token from `pass show <[todo]
+ pass>`, kept in memory, read again after a 401) every 60s: open tasks due today or
overdue or whose reminder passed (`/api/v2/tasks` filter), minus any with a
reminder still ahead, so a snooze hides one until it fires. Actions, for an
id the last state listed: `open` (`xdg-open` on the PC, Vikunja's
diff --git a/config.toml b/config.toml
index 6fde20c..8923e8b 100644
--- a/config.toml
+++ b/config.toml
@@ -85,9 +85,11 @@ client_id = ""
[todo]
# Vikunja's base URL, like http://vikunja.example.org:3456. The Dashboard
# lists its open tasks due today or overdue, or whose reminder has passed.
-# The token, an API token that can read and update tasks, goes in
-# ~/.config/deck-it/vikunja-token. Empty: no todo row.
+# Empty: no todo row.
url = ""
+# The pass entry holding a Vikunja API token that can read and update tasks
+# (first line). Read once; gpg may ask for the PIN then.
+pass = ""
[assistant]
# keystone's desktop shell, the quickshell config whose `assistant catalog`
diff --git a/deckit/modules/todo.py b/deckit/modules/todo.py
index 8abbd23..8ce673d 100644
--- a/deckit/modules/todo.py
+++ b/deckit/modules/todo.py
@@ -18,23 +18,21 @@
Open tasks due today or overdue, or whose reminder has passed; one with a
reminder still ahead is hidden, which is how a snooze works. The token is a
-Vikunja API token (read and update tasks) in ~/.config/deck-it/vikunja-token.
+Vikunja API token (read and update tasks) in pass, entry [todo] pass, read
+once and kept in memory until Vikunja refuses it.
"""
import http.client
import json
-import os
import subprocess
import threading
import urllib.error
import urllib.parse
import urllib.request
from datetime import datetime, timedelta, timezone
-from pathlib import Path
from ..module import Module, ModuleError
-TOKEN = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "deck-it" / "vikunja-token"
POLL = 60
SNOOZE = timedelta(minutes=30)
FILTER = "done = false && (due_date < now/d+1d || reminders < now)"
@@ -57,6 +55,17 @@ def _http(method, url, token, data=None):
return json.loads(raw) if raw else {}
+def _pass(entry):
+ """The first line of a pass entry. gpg may ask for the PIN the first time."""
+ try:
+ out = subprocess.run(["pass", "show", entry], capture_output=True, text=True, timeout=120)
+ except subprocess.TimeoutExpired:
+ raise OSError("pass timed out") from None
+ if out.returncode:
+ raise OSError(f"pass show {entry} failed")
+ return out.stdout.partition("\n")[0].strip()
+
+
def _popen(cmd):
subprocess.Popen(cmd, start_new_session=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
@@ -87,10 +96,13 @@ def pick(tasks, now):
class Todo:
def __init__(self, cfg: dict):
- self.url = cfg.get("todo", {}).get("url", "").rstrip("/")
+ tcfg = cfg.get("todo", {})
+ self.url = tcfg.get("url", "").rstrip("/")
+ self.entry = tcfg.get("pass", "")
self.http = cfg.get("http", _http)
self.popen = cfg.get("popen", _popen)
- self.token_path = Path(cfg.get("token", TOKEN))
+ self.pass_ = cfg.get("pass", _pass)
+ self.token = None
self.now = cfg.get("now", lambda: datetime.now(timezone.utc))
self.front = None
self.st = {"tasks": [], "error": None}
@@ -98,8 +110,16 @@ class Todo:
self.actions = {"open": self._open, "done": self._done, "snooze": self._snooze} if self.url else {}
def _call(self, method, path, data=None):
- token = self.token_path.read_text().strip()
- return self.http(method, self.url + path, token, data)
+ if not self.entry:
+ raise OSError("no [todo] pass entry for the token")
+ if self.token is None:
+ self.token = self.pass_(self.entry)
+ try:
+ return self.http(method, self.url + path, self.token, data)
+ except OSError as e:
+ if str(e) == "HTTP 401":
+ self.token = None # revoked or replaced: read pass again next time
+ raise
def refresh(self):
try:
diff --git a/docs/superpowers/specs/2026-11-30-todo-design.md b/docs/superpowers/specs/2026-11-30-todo-design.md
index 72ac21a..b451c90 100644
--- a/docs/superpowers/specs/2026-11-30-todo-design.md
+++ b/docs/superpowers/specs/2026-11-30-todo-design.md
@@ -15,8 +15,10 @@ with no due date (only a reminder) after those. At most 3 lines plus
- `[todo] url`, the Vikunja API base (`http://host:3456`). Empty: the module
reports nothing and starts no thread.
-- Token: `~/.config/deck-it/vikunja-token`, a Vikunja API token allowed to
- read and update tasks. Never in the repo or the shipped config.
+- Token: a Vikunja API token allowed to read and update tasks, the first
+ line of the pass entry `[todo] pass`. Read once and kept in memory; a 401
+ drops it so the next read asks pass again. Never in the repo or the
+ shipped config.
- A thread reads `GET /api/v2/tasks?filter=done = false && (due_date <
now/d+1d || reminders < now)` every 60s and right after an action;
`/api/v1/info`'s `frontend_url` once for links.
diff --git a/tests/test_todo.py b/tests/test_todo.py
index f648a36..9307012 100644
--- a/tests/test_todo.py
+++ b/tests/test_todo.py
@@ -19,7 +19,6 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
-import tempfile
import unittest
from datetime import datetime, timezone
@@ -58,7 +57,7 @@ class Fake:
self.tasks, self.calls = tasks, []
def __call__(self, method, url, token, data=None):
- self.calls.append((method, url, data))
+ self.calls.append((method, url, data, token))
if url.endswith("/api/v1/info"):
return {"frontend_url": "http://vikunja.example.org/"}
if method == "GET" and "/api/v2/tasks?" in url:
@@ -70,17 +69,32 @@ class Fake:
class Module(unittest.TestCase):
def setUp(self):
- self.dir = tempfile.TemporaryDirectory()
- tok = Path(self.dir.name) / "token"
- tok.write_text("secret\n")
+ self.entries = []
self.http = Fake([task(7, due="2026-11-29T09:00:00Z", reminders=["2026-11-29T08:00:00Z"])])
self.opened = []
- self.m = todo.Todo({"todo": {"url": "http://vikunja.example.org:3456/"}, "http": self.http,
- "token": tok, "popen": self.opened.append, "now": lambda: NOW})
+ self.m = todo.Todo({"todo": {"url": "http://vikunja.example.org:3456/", "pass": "vikunja/deck-it"},
+ "http": self.http, "pass": lambda e: self.entries.append(e) or "secret",
+ "popen": self.opened.append, "now": lambda: NOW})
self.m.refresh()
- def tearDown(self):
- self.dir.cleanup()
+ def test_token_read_from_pass_once(self):
+ self.m.refresh()
+ self.assertEqual(self.entries, ["vikunja/deck-it"])
+ self.assertEqual({c[3] for c in self.http.calls if "/api/v2/" in c[1]}, {"secret"})
+
+ def test_refused_token_is_read_again(self):
+ def refuse(*a, **k):
+ raise OSError("HTTP 401")
+ http, self.m.http = self.m.http, refuse
+ self.m.refresh()
+ self.m.http = http
+ self.m.refresh()
+ self.assertEqual(len(self.entries), 2)
+
+ def test_no_entry_is_an_error(self):
+ m = todo.Todo({"todo": {"url": "http://vikunja.example.org"}, "http": self.http})
+ m.refresh()
+ self.assertIn("pass", m.state()["error"])
def test_state_lists_tasks(self):
st = self.m.state()
@@ -98,7 +112,7 @@ class Module(unittest.TestCase):
def test_done_patches_only_done(self):
self.m.actions["done"]({"id": 7})
- self.assertIn(("PATCH", "http://vikunja.example.org:3456/api/v2/tasks/7", {"done": True}),
+ self.assertIn(("PATCH", "http://vikunja.example.org:3456/api/v2/tasks/7", {"done": True}, "secret"),
self.http.calls)
def test_snooze_keeps_old_reminders_and_adds_one(self):