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):

  • state is the lifecycle, in A2A’s seven names, the same ones equerry’s desk Item uses, so a loop is a desk item without translation. A reminder that is scheduled is submitted with a remind_at; once it fires it is input-required; done is completed; dismissed is rejected; withdrawn is canceled.

  • list is 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 to openloops.method, whose default is Getting Things Done (openloops.gtd.GTD: in, next, waiting, someday, reference; “scheduled”, the tickler, is a loop on next with a future remind_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

STATES

The lifecycle, in A2A's names (the same as equerry's desk Item).

TERMINAL

Nothing leaves these.

MAX_HORIZON

How far ahead a reminder is handed to the delivery channel's own scheduler.

MIN_SCHEDULE_LEAD

Below this lead a scheduled delivery is refused by ntfy (10 s), so it is sent now.

Functions

new_loop(title, *[, remind_at, due, reveal, ...])

A new loop, logged as created.

evaluate(loops, now, *[, horizon])

What a runner should do now, as data.

complete(loop, now, *[, by, note])

Done.

snooze(loop, until, now, *[, by])

Bring it back at until: scheduled again, one more snooze counted.

cancel(loop, now, *[, by, note])

Withdrawn: it will not fire.

mark(loop, now, event, *[, by])

A copy with changes applied and one log entry appended.

to_utc(when)

A timezone-aware UTC datetime; a naive one is read as the machine's local time.

iso(when)

UTC ISO with a Z, to the second.

Classes

Loop(id, title, created[, state, list, ...])

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: object

One 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.

source is where it came from ({kind, ref, quote, said_by}): every loop an agent makes is traceable. proposed_by is set when an agent proposed it and the person has not accepted it; a proposal never pushes. reveal says whether a push may carry the title (pushes cross a public relay by default). armed records the delivery the channel holds ({sequence_id, at}), so it can be replaced or cancelled. log is append-only.

extra: Mapping[str, Any]#

kept and written back.

Type:

Keys a newer writer added that this version does not know

classmethod from_dict(data)[source]#

Read a stored loop; keys this version does not know are kept in extra.

Return type:

Loop

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:

Loop

openloops.loops.complete(loop, now, *, by='owner', note=None)[source]#

Done. Refused on a loop already closed, so a second done is visible, not silent.

Return type:

Loop

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 within horizon and not yet handed to the channel at that time. The channel delivers it at remind_at even 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_by set) 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')]
Return type:

list[dict[str, Any]]

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'
Return type:

str | None

openloops.loops.mark(loop, now, event, *, by='tick', **changes)[source]#

A copy with changes applied and one log entry appended.

Return type:

Loop

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. extra takes any other Loop field.

method (default openloops.method.default_method(), GTD) says where it goes: by default its default_place, where an item the owner asked for directly lands (GTD: next). list in extra overrides that and must be one of the method’s places; to move a loop with the method’s rules, use openloops.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:

Loop

openloops.loops.snooze(loop, until, now, *, by='owner')[source]#

Bring it back at until: scheduled again, one more snooze counted.

Return type:

Loop

openloops.loops.to_utc(when)[source]#

A timezone-aware UTC datetime; a naive one is read as the machine’s local time.

>>> to_utc("2026-11-19T12:00:00Z").isoformat()
'2026-11-19T12:00:00+00:00'
Return type:

datetime