openloops.loops#
Loops: the one record of a commitment, and the pure function that says what is due.
A loop is an open loop in David Allen’s sense: one of the owner’s commitments, held somewhere other than their head. It is one record whatever place it sits on, so every list a method keeps (GTD’s In, Next, Waiting For, Someday, the tickler) is a view over loops rather than a separate store.
Two vocabularies, kept apart on purpose (ADR-013):
stateis the lifecycle, in A2A’s seven names, the same ones equerry’s deskItemuses, so a loop is a desk item without translation. A reminder that is scheduled issubmittedwith aremind_at; once it fires it isinput-required; done iscompleted; dismissed isrejected; withdrawn iscanceled.listis the place the organising method put it in. The record does not know the method (ADR-017): the vocabulary and the rules for moving between places belong toopenloops.method, whose default is Getting Things Done (openloops.gtd.GTD:in,next,waiting,someday,reference; “scheduled”, the tickler, is a loop onnextwith a futureremind_at).
Three times, never conflated: remind_at (when it comes back to you: the tickler,
GTD’s defer date), due (a deadline, a promise to someone) and created. All are
stored as UTC ISO strings.
Nothing here reads a clock, a file or the network: evaluate() takes now and
returns the actions a runner should take (openloops.remind is that runner).
>>> now = datetime(2026, 11, 19, 12, 0, tzinfo=timezone.utc)
>>> loop = new_loop("Send the signed draft", remind_at=now + timedelta(hours=3), now=now, id="loop-a")
>>> loop.state, loop.list
('submitted', 'next')
>>> [a["action"] for a in evaluate([loop], now)]
['arm']
Module Attributes
The lifecycle, in A2A's names (the same as equerry's desk Item). |
|
Nothing leaves these. |
|
How far ahead a reminder is handed to the delivery channel's own scheduler. |
|
Below this lead a scheduled delivery is refused by ntfy (10 s), so it is sent now. |
Functions
|
A new loop, logged as created. |
|
What a runner should do now, as data. |
|
Done. |
|
Bring it back at |
|
Withdrawn: it will not fire. |
|
A copy with |
|
A timezone-aware UTC datetime; a naive one is read as the machine's local time. |
|
UTC ISO with a |
Classes
|
One commitment. |
- class openloops.loops.Loop(id, title, created, state='submitted', list=<factory>, remind_at=None, due=None, reveal=False, source=None, proposed_by=None, project=None, area=None, contexts=(), energy=None, minutes=None, waiting=None, available_when=None, done_when=None, snoozes=0, carried=0, armed=None, log=tuple(), extra=dict())[source]#
Bases:
objectOne commitment. Most fields are optional; GTD-complete, so the default method has every field it needs, and a method that needs fewer ignores the rest.
sourceis where it came from ({kind, ref, quote, said_by}): every loop an agent makes is traceable.proposed_byis set when an agent proposed it and the person has not accepted it; a proposal never pushes.revealsays whether a push may carry the title (pushes cross a public relay by default).armedrecords the delivery the channel holds ({sequence_id, at}), so it can be replaced or cancelled.logis append-only.
- openloops.loops.MAX_HORIZON = datetime.timedelta(days=2, seconds=82800)#
How far ahead a reminder is handed to the delivery channel’s own scheduler. ntfy holds a scheduled message for at most three days; an hour’s margin absorbs a clock that runs ahead of the server’s.
- openloops.loops.MIN_SCHEDULE_LEAD = datetime.timedelta(seconds=15)#
Below this lead a scheduled delivery is refused by ntfy (10 s), so it is sent now.
- openloops.loops.STATES = ('submitted', 'working', 'input-required', 'completed', 'failed', 'canceled', 'rejected')#
The lifecycle, in A2A’s names (the same as equerry’s desk Item).
- openloops.loops.TERMINAL = frozenset({'canceled', 'completed', 'failed', 'rejected'})#
Nothing leaves these.
- openloops.loops.cancel(loop, now, *, by='owner', note=None)[source]#
Withdrawn: it will not fire. A reason belongs in
note.- Return type:
- openloops.loops.complete(loop, now, *, by='owner', note=None)[source]#
Done. Refused on a loop already closed, so a second
doneis visible, not silent.- Return type:
- openloops.loops.evaluate(loops, now, *, horizon=datetime.timedelta(days=2, seconds=82800))[source]#
What a runner should do now, as data. Pure: same loops and
now, same actions.For each open, accepted loop with a
remind_at:arm: due withinhorizonand not yet handed to the channel at that time. The channel delivers it atremind_ateven if this machine is asleep then.deliver: due and never armed (created late, or arming failed, or the machine slept past the horizon). Sent now, saying how late.woke: due and armed, so the channel has delivered it; the loop now needs its owner (input-required).disarm: closed but still armed, or moved (snoozed) outside the horizon while armed at its old time: cancel the channel’s copy.
Proposals (
proposed_byset) never produce a delivery.>>> now = datetime(2026, 11, 19, 12, 0, tzinfo=timezone.utc) >>> far = new_loop("x", remind_at=now + timedelta(days=5), now=now, id="far") >>> late = new_loop("y", remind_at=now - timedelta(minutes=5), now=now, id="late") >>> [(a["action"], a["id"]) for a in evaluate([far, late], now)] [('deliver', 'late')]
- openloops.loops.iso(when)[source]#
UTC ISO with a
Z, to the second.>>> iso(datetime(2026, 11, 19, 12, 0, 30, 999, tzinfo=timezone.utc)) '2026-11-19T12:00:30Z'
- openloops.loops.mark(loop, now, event, *, by='tick', **changes)[source]#
A copy with
changesapplied and one log entry appended.- Return type:
- openloops.loops.new_loop(title, *, remind_at=None, due=None, reveal=False, source=None, by='owner', now=None, id=None, method=None, **extra)[source]#
A new loop, logged as created.
extratakes any otherLoopfield.method(defaultopenloops.method.default_method(), GTD) says where it goes: by default itsdefault_place, where an item the owner asked for directly lands (GTD:next).listinextraoverrides that and must be one of the method’s places; to move a loop with the method’s rules, useopenloops.method.organise().>>> new_loop("x", now=datetime(2026, 11, 28, tzinfo=timezone.utc), list="nowhere") Traceback (most recent call last): ... ValueError: gtd has no list 'nowhere'; its lists are in, next, waiting, someday, reference
- Return type: