diff --git a/DESIGN.md b/DESIGN.md index 4547a12..7d22c26 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -62,8 +62,8 @@ Note what's *not* here: `last_tick_commit` is deliberately **not** updated by th **Agent half** (`TICK.md`), five steps, each its own commit: 1. Triage `inbox.org` only (other files changing is someone else's edit): events → `esdeveniments.org`, tasks → wherever they actually belong, `:diwan:` items get moved but not acted on yet, new topics only get a new file when nothing existing fits. 2. Tag consistency: any `:session:`/`:chat:` heading without a `:diwan:` tag on itself or an ancestor gets `:diwan:` added directly to it. Then resolve `:chat:` ownership: chats under a `:session:` ancestor are left for that heading's own session; orphan chats get answered inline if trivial, or escalated (see step 3's three-way decision) if not. -3. Handle every `:diwan:`-tagged heading without an open `:session:`: trivial ones get answered inline, no tag beyond `:diwan:` ever assigned. Non-trivial ones split two ways — self-contained within the heading's own subtree gets a `:session:` tag and `diwan do : --diwan-id ` run *by the tick agent itself* (the tick agent is the only thing that ever originates a fresh `DIWAN_ID`); inherently cross-cutting work (spans multiple files/headings, can't be parallelized — archiving, bulk cleanup, moving things between files) is done by the tick agent *directly*, right there, no session at all, possibly spread across several tick runs if it needs Marc's input first. The same handling applies to any open item under `diwan.org`'s `Tasks` heading — diwan's own self-maintenance backlog, no tag needed there since the location already signals it (see PROTOCOL.md's `diwan.org` section). Already-open sessions (`:session:` tag + `DIWAN_ID` present, `Close diwan session` still `[ ]`) get their subtree's content left alone as always, but are checked for a nudge: if any commit in this tick's change range *not* authored by the diwan git identity touched a line inside that subtree (a hand-authored heading edit, a new unread `:chat:` entry, anything Marc did), the tick agent re-runs `diwan do : --diwan-id ` on the existing ID — a continuation dispatch into the session's own tab/agent, not a fresh one — purely to wake it up; no nudge at all if nothing hand-authored touched the subtree. This is the only mechanism that gets a change Marc makes to an active heading in front of its own idle agent — nothing watches the file otherwise. -4. Write one short, titled, checkbox subheading per notable thing this run did into `diwan.org`'s Reports log (not one paragraph for the whole run), each with the title itself linking to the one heading it's about (plain text if there isn't one) and a 1-2 line signed body; delete any already-`[X]` subheadings first. +3. Handle every `:diwan:`-tagged heading without an open `:session:`: trivial ones get answered inline, no tag beyond `:diwan:` ever assigned. Non-trivial ones split two ways — self-contained within the heading's own subtree gets a `:session:` tag and `diwan do : --diwan-id ` run *by the tick agent itself* (the tick agent is the only thing that ever originates a fresh `DIWAN_ID`); inherently cross-cutting work (spans multiple files/headings, can't be parallelized — archiving, bulk cleanup, moving things between files) is done by the tick agent *directly*, right there, no session at all, possibly spread across several tick runs if it needs Marc's input first. The same handling applies to any open item under `diwan.org`'s `Tasks` heading — diwan's own self-maintenance backlog, no tag needed there since the location already signals it (see PROTOCOL.md's `diwan.org` section). Already-open sessions (`:session:` tag + `DIWAN_ID` present, `Close diwan session` still `[ ]`) get their subtree's content left alone as always, but are checked for a nudge: if any commit in this tick's change range *not* authored by the diwan git identity touched a line inside that subtree (a hand-authored heading edit, a new unread `:chat:` entry, anything Marc did), the tick agent re-runs `diwan do : --diwan-id ` on the existing ID — a continuation dispatch into the session's own tab/agent, not a fresh one — purely to wake it up; no nudge at all if nothing hand-authored touched the subtree. This is the only mechanism that gets a change Marc makes to an active heading in front of its own idle agent — nothing watches the file otherwise. A session whose `Close diwan session` is already `[X]` gets retired for real: the tick agent looks up its `DIWAN_ID`'s herdr tab and actually closes it (`herdr tab close`), then removes the `:session:` tag from the heading — the `DIWAN_ID` property itself is left in place as a historical record. None of dispatch, nudge, or closure get a Reports entry on their own; see step 4. +4. Delete any already-`[X]` Reports subheadings first, then — only for things that actually clear the "real information" bar, not routine mechanical steps like a bare dispatch or a session closure Marc asked for — write one short, titled, checkbox subheading per reportable thing this run did into `diwan.org`'s Reports log (not one paragraph for the whole run), each with the title itself linking to the one heading it's about (plain text if there isn't one) and a 1-2 line signed body. Zero new entries is a normal outcome. 5. Only if 1–4 all succeeded: update `state.json.last_tick_commit` to current `HEAD` and commit under the diwan identity. **Verified live** (2026-11-08, herdr 0.9.5 + Claude Code, before both the 2026-11-09 tool/content split and the pi-only harness switch): dispatched for real, ran to completion with zero permission prompts, correctly left two already-open `:session:`-tagged sessions untouched (back when `:session:` was still spelled `:diwan:`, before the tag rename — see "Known gaps" for what's unverified post-rename), correctly found nothing to triage, wrote a proper signed report, and updated `state.json` correctly. A second immediate `diwan tick` correctly no-op'd. **Not yet re-verified with a real dispatched agent** against the current state of things (post-split two-repo layout, `pi` as the sole harness) — path resolution and `pi`'s own startup have each been tested separately (see below and "Known gaps"), but not yet together through a full live tick run. Do that before trusting it for real. @@ -92,13 +92,13 @@ Same split: `cmd_do` (CLI) decides identity/dispatch mechanics; `DO.md` governs A `DIWAN_ID` *is* a herdr tab label in the `diwan` workspace, and (while its agent process is alive) also that agent's name. This is why it must satisfy herdr's agent-name rule: `^[a-z][a-z0-9_-]{0,31}$`. `slugify()` enforces this at mint time (lowercase, non-alnum → hyphen, truncated to 24 chars, forced to start with a letter) and `cmd_do` additionally validates *every* `DIWAN_ID` it's about to dispatch — including ones already stored in a heading — against that same regex before touching herdr, erroring out with a clear message rather than letting herdr reject it after the CLI has already created a tab (which used to leave an orphan tab behind; fixed by closing the just-created tab on any `agent start` failure). -Lifecycle: **fresh** (no property) → `diwan do` mints an ID, creates the tab+agent, heading now has `DIWAN_ID` + open (`[ ]`) `Close diwan session` → **active** (any further `tick`/`do` on this heading is a continuation; `tick` explicitly leaves active sessions alone) → Marc checks off `Close diwan session` (`[X]`) → next `tick` notices and retires it (per `TICK.md` step 3 — note: as of this writing the tick procedure only *reports* that a session closed; it does not yet actually call `herdr tab close` on it — see "Known gaps"). +Lifecycle: **fresh** (no property) → `diwan do` mints an ID, creates the tab+agent, heading now has `DIWAN_ID` + open (`[ ]`) `Close diwan session` → **active** (any further `tick`/`do` on this heading is a continuation; `tick` explicitly leaves active sessions alone) → Marc checks off `Close diwan session` (`[X]`) → next `tick` actually retires it (per `TICK.md` step 3): closes the herdr tab for real, removes the `:session:` tag, leaves the `DIWAN_ID` property in place as a historical record — **retired** (the heading can still be found later by that `DIWAN_ID`, but there's no live terminal and no tag pointing at one). ## Known gaps / explicit non-goals (don't "fix" these without discussing) - **Tool/content repo split just happened (2026-11-09), not yet re-verified live.** This repo used to be both diwan's own dev copy *and* a throwaway test-content repo at once; it's now tool-only, with content split out to a sibling `diwan-dev-notes` repo. The CLI was updated to resolve `DIWAN_DIR` (its own install dir, `Path(__file__).resolve().parent`, overridable via the `DIWAN_DIR` env var) separately from `DIWAN_NOTES_DIR` (`git rev-parse --show-toplevel` from the invoking directory by default, overridable via the `DIWAN_NOTES_DIR` env var), and the dispatch prompts now pass `DIWAN_DIR`-absolute paths for `PROTOCOL.md`/`TICK.md`/`DO.md`. This has been syntax-checked and smoke-tested for path resolution (including both env var overrides, from outside any repo), but **not yet run through a full live tick/do pass with a real dispatched agent** against the new two-repo layout — do that before trusting it for real. - **No flake yet.** The split prepared the ground (tool repo is self-contained, no content-repo assumptions baked into its own files) but there's no `flake.nix` in this repo yet, and the shebang still runs via a bare `nix shell nixpkgs#python3` rather than a proper package. Until that lands, "installed on `PATH`" means manually symlinking/aliasing `diwan` somewhere on `PATH` yourself. `DIWAN_DIR` exists specifically so a future flake's install layout (e.g. docs copied into `$out/share/diwan/` alongside a wrapped binary) can override the default `Path(__file__).resolve().parent` guess if it doesn't hold. -- **Retired-session teardown.** `TICK.md` step 3 says a closed session has "nothing for you to do to the heading's content" and that herdr-side teardown "is not your job" — but nothing else currently closes that tab either. Right now a `Close diwan session` checked off (`[X]`) just... sits there, tab still open. This is a real gap, not yet decided whether the CLI should gain a path for it or whether `TICK.md` should just say to run `herdr tab close` directly. +- **Retired-session teardown is designed but not yet verified live.** `TICK.md` step 3 now has the tick agent actually close the herdr tab (`herdr tab close`) and strip the `:session:` tag once `Close diwan session` is checked off, rather than just reporting that it happened — but no real tick run has exercised this path yet. Worth a close look the first few times it fires: does the tab lookup by `DIWAN_ID` label reliably find the right tab, does tag-stripping leave `:diwan:`/other tags intact, does it behave sanely if the tab was already closed by hand. - **No real conversation continuity across resumption.** Covered above — intentional for now, but worth revisiting if resumed `do` sessions turn out to need more context than the heading text carries. - **`pi` is smoke-tested for ad-hoc dispatch, but not yet exercised against real heading content.** `--approve` has been confirmed live for ad-hoc `diwan do` dispatch and continuation, including against a content repo `pi` had never run in before (no trust-dialog block, unlike Claude Code — see "One harness, chosen deliberately" above). Still untested: a real `diwan tick` run, and `diwan do` against a real `:` heading (DIWAN_ID minting, `:chat:` protocol, scope discipline) rather than a free-text ad-hoc prompt. - **`diwan.org`'s `Config` heading is a placeholder, not wired up.** PROTOCOL.md documents an intended home for configuration values governing diwan's own behavior (tick cadence, tab retention, that kind of thing), but the CLI reads none of it — the env vars (`DIWAN_DIR`, `DIWAN_NOTES_DIR`, `DIWAN_PI_APPROVE`, `DIWAN_MAX_TICK_TABS`) remain the only real knobs. Don't assume anything in that heading does something until the CLI actually reads it. diff --git a/PROTOCOL.md b/PROTOCOL.md index 3d80665..50d8516 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -28,7 +28,7 @@ A heading tagged `:session:` has (or is about to get) a dedicated, persistent ag ** [ ] Close diwan session ``` -Can be added by the user directly, when they already know a heading needs its own ongoing session, or by diwan (ordinarily `tick`) when it decides a `:diwan:`-tagged request is non-trivial and self-contained enough to delegate (see above). `DIWAN_ID` is a herdr terminal name (see "herdr", below) — not an arbitrary id. It points directly at the live/persisted agent session handling this heading, so "jump in personally" is just attaching to that terminal, no separate lookup needed. A heading keeps the same `DIWAN_ID`/`:session:` tag across multiple tick passes until its `Close diwan session` item is checked off (`[X]`) by the user, at which point the *next* tick retires the session and leaves the property and tag as a historical record (does not delete them). +Can be added by the user directly, when they already know a heading needs its own ongoing session, or by diwan (ordinarily `tick`) when it decides a `:diwan:`-tagged request is non-trivial and self-contained enough to delegate (see above). `DIWAN_ID` is a herdr terminal name (see "herdr", below) — not an arbitrary id. It points directly at the live/persisted agent session handling this heading, so "jump in personally" is just attaching to that terminal, no separate lookup needed. A heading keeps the same `DIWAN_ID`/`:session:` tag across multiple tick passes until its `Close diwan session` item is checked off (`[X]`) by the user, at which point the *next* tick actually retires it: closes that `DIWAN_ID`'s herdr tab for real (`herdr tab close`, not just leaving it be) and removes the `:session:` tag from the heading. The `DIWAN_ID` property itself is left in place as a historical record (in case the session's work is ever worth revisiting) — only the tag and the live terminal go away. ## `:chat:` tag @@ -71,16 +71,16 @@ diwan's own operational file, at the root of the content repo — not a place fo ### Reports -Every notable thing a diwan agent does — a tick dispatching something new, a tick triaging a batch of inbox items, a `do` session finishing a real piece of work — gets its own short subheading under the top-level "Reports" heading in `diwan.org`. One entry per notable thing, not one giant paragraph per run: this is what keeps each entry short and the whole log skimmable with everything collapsed. **Whoever actually did the thing writes the entry** — `diwan tick` reports its own actions (triage moves, inline answers, promotions, new dispatches), and a `diwan do` session reports its *own* progress once it has something worth telling the user, not before. In particular: a tick merely nudging an idle active session (see the `:session:` section above) is not itself reportable — tick has no idea yet whether anything came of it, so it stays silent; if the nudge leads the session to actually do something, that session writes the entry once it has. +Only things containing *actual information the user would want to know* — a finding, a decision made on their behalf, an ambiguity flagged, a problem hit — get a short subheading under the top-level "Reports" heading in `diwan.org`. Routine mechanical steps that were always going to happen and say nothing interesting on their own — "dispatched a session", "nudged an idle session", "nothing needed triaging this run", "closed a session Marc asked to close" — are **not** reportable; skip the entry entirely rather than writing one just to have something to show. It is normal and expected for a tick run to add zero new Reports entries. When something *is* reportable, keep it to its own short subheading, not one giant paragraph per run: this is what keeps each entry short and the whole log skimmable with everything collapsed. **Whoever actually did the thing writes the entry** — `diwan tick` reports its own actions (triage moves, inline answers, promotions, new dispatches), and a `diwan do` session reports its *own* progress once it has something worth telling the user, not before. In particular: a tick merely nudging an idle active session (see the `:session:` section above) is not itself reportable — tick has no idea yet whether anything came of it, so it stays silent; if the nudge leads the session to actually do something, that session writes the entry once it has. Format: a `[ ]`/`[X]` checkbox right in the subheading title (same pattern as `Close diwan session`), a short title that *is itself the link* to the one heading the entry is most about (fuzzy heading link, or `id:` link for a note file with an `:ID:` drawer — just plain text with no link if there's no single heading to point at), and a signed one-or-two-line body, no more. No `:LINK:` property, no properties drawer at all — any further links belong inline in the body text: ```org * Reports -** [ ] [[file:personal.org::*Plan the kitchen redecoration][Dispatched kitchen redecoration]] - [diwan 2026-11-08] Non-trivial, dispatched as do-kitchen. -** [X] Triaged 2 inbox items - [diwan 2026-11-07] Moved into esdeveniments.org and personal.org. +** [ ] [[file:personal.org::*Plan the kitchen redecoration][Kitchen redecoration: flagged a budget conflict]] + [diwan 2026-11-08] The heading asks for a 3000€ budget but its linked Pinterest board is all 8000€+ kitchens — asked which one is right in the heading's own :chat: before researching further. +** [X] Archived personal.org's Tasques backlog + [diwan 2026-11-07] 45 DONE tasks moved into archive/archive.org, oldest from 2023 — personal.org's active list was getting hard to scan. ``` Unread = `[ ]`, read = `[X]`, same semantics as `:chat:` — the user checks an entry off once they've seen it. Once an entry is `[X]`, the *next* `diwan tick` deletes the whole subheading, not just the checkbox — this is a disposable log, not a record, and only `tick` ever deletes from it (a `do` session only ever appends its own new entries, never touches an existing one). Questions for the user still go in the relevant heading's own `:chat:`, not here — a report entry may link there, but the report itself is one-way, no back-and-forth expected. diff --git a/TICK.md b/TICK.md index 4a23afe..8977095 100644 --- a/TICK.md +++ b/TICK.md @@ -33,23 +33,25 @@ Commit: `tick: resolve chat ownership and tag consistency`. Find every `:diwan:`-tagged heading in the tree (including ones just tagged in step 2). - No `:session:` tag yet, and the request is trivial (quick lookup, one-line answer you can produce yourself right now): do it inline, write the result into the heading, and leave it — no session, nothing further to track. This is the common case for small asks. -- No `:session:` tag yet, non-trivial, and self-contained within this heading's own subtree (independent delegated work, nothing that needs writes to other files or headings): add the `:session:` tag and run `diwan do : --diwan-id ` yourself (pick a short, readable slug from the heading text — `diwan do` will write the `DIWAN_ID` property and the `Close diwan session` checkbox item for you; don't hand-edit those). Note the dispatch in your report. +- No `:session:` tag yet, non-trivial, and self-contained within this heading's own subtree (independent delegated work, nothing that needs writes to other files or headings): add the `:session:` tag and run `diwan do : --diwan-id ` yourself (pick a short, readable slug from the heading text — `diwan do` will write the `DIWAN_ID` property and the `Close diwan session` checkbox item for you; don't hand-edit those). The dispatch itself isn't reportable (see step 4) — it was always going to happen, there's nothing informative to say about it yet. - No `:session:` tag yet, non-trivial, and inherently cross-cutting — touches multiple files or headings at once, or can't be meaningfully parallelized (archiving, bulk cleanup, moving files/folders between locations, repo-wide renames): do this yourself, directly, right now, in small separate commits per coherent chunk — the same way you'd do any other tick step. Don't add a `:session:` tag for this; a subtree-scoped `do` agent would just hit the same wall a human doing it alone would. If there's a real judgment call to make first (not just mechanical execution), ask in the heading's own `:chat:` and leave the rest for a future tick once Marc answers, rather than guessing or acting unsupervised at scale. It's fine for this kind of task to span several tick runs — pick up wherever the heading's own content (and its sub-TODOs, if any) says you left off. - Already has a `:session:` tag and its `Close diwan session` item is still `[ ]`: it's an active session, already being worked by its own agent — you still have no business editing inside its subtree, but check whether it needs waking up. Look at this tick's change range for any commit *not* authored by the diwan git identity (`diwan `) that touched a line inside that heading's subtree — a direct edit by Marc to the heading body, a new unread `:chat:` entry, anything hand-authored. The tick's own start-of-run manual-edit snapshot commit is the usual source of these. If you find one, nudge the session: run `diwan do : --diwan-id ` again (same existing `DIWAN_ID` — this reuses the session's own tab/agent, it does not create a new one) so it re-reads the heading and notices on its own. If nothing hand-authored touched the subtree, leave it alone entirely, no dispatch at all. A nudge is not itself something to report in step 4 — you have no idea yet whether anything comes of it; if it leads the session to do real work, that session reports it, not you. -- Already has a `:session:` tag and its `Close diwan session` item is `[X]`: this session is being retired. There's nothing for you to do to the heading's content; the CLI/herdr-side teardown of the actual terminal is not your job — just note in your report that it closed. +- Already has a `:session:` tag and its `Close diwan session` item is `[X]`: this session is being retired, for real, right now. Find its herdr tab (the `diwan` workspace, tab label == this heading's `DIWAN_ID`) and close it with `herdr tab close ` — if it's already gone (closed by hand, e.g.), there's nothing to do there, move on. Then remove the `:session:` tag from the heading itself (leave `:diwan:` and any other tags alone). Leave the `DIWAN_ID` property in place — don't delete it, it's the historical record of what ran there, in case it's ever worth revisiting. Leave `Close diwan session` checked as-is. This is routine follow-through on something Marc explicitly asked for by checking the box — not reportable on its own (see step 4), unless something about the teardown itself was unexpected (the tab held uncommitted work, say). Also check `diwan.org`'s `Tasks` heading for any open (not-yet-`DONE`) item — these are the same kind of cross-cutting work as above, already homed in the right spot with no tag needed (see PROTOCOL.md's `diwan.org` section). Pick one up and make progress on it (or finish it) directly, in its own commit(s), the same way as any other cross-cutting `:diwan:` request; mark it `DONE` once actually finished, or ask via a `:chat:` child first if it needs a real judgment call from Marc. -Commit after each dispatch, cross-cutting chunk of work, or batch of inline answers: `tick: dispatch ` / `tick: ` / `tick: answer `. A nudge doesn't change any file content on its own, so there's nothing to commit for it either. +Commit after each dispatch, cross-cutting chunk of work, batch of inline answers, or session closure: `tick: dispatch ` / `tick: ` / `tick: answer ` / `tick: close session `. A nudge doesn't change any file content on its own, so there's nothing to commit for it either. ## 4. Write the report -In `diwan.org` at the repo root, under a top-level "Reports" heading (create the file and heading if this is the very first tick), first delete any existing report subheadings already marked `[X]` in their title — Marc has read those, they're disposable, don't let them pile up (this applies to every entry regardless of who wrote it, including ones a `do` session appended). Then add one new subheading per notable thing *this tick itself* did — a new dispatch, an inline answer, a batch of triage moves, not one giant entry covering the whole run, and not anything that happened inside an active `do` session's own subtree (that session reports its own work, see PROTOCOL.md's Reports section — a bare nudge you sent this run is explicitly not reportable by you). Keep titles short enough that Marc can skim the whole log collapsed and know what happened without opening anything. Each entry: +In `diwan.org` at the repo root, under a top-level "Reports" heading (create the file and heading if this is the very first tick), first delete any existing report subheadings already marked `[X]` in their title — Marc has read those, they're disposable, don't let them pile up (this applies to every entry regardless of who wrote it, including ones a `do` session appended). + +Then, and only if there's something that actually clears the bar, add one new subheading per reportable thing *this tick itself* did. The bar: real information — a finding, a decision you made on Marc's behalf, an ambiguity you flagged, a problem you hit. Below the bar, write nothing: a plain dispatch with nothing to say about it yet, a routine session closure Marc already asked for, a pass where nothing needed triaging, a nudge you sent (that one's not yours to report regardless, see PROTOCOL.md) — none of these get an entry. A tick run that did real mechanical work (moved files, dispatched a session, closed another) but has nothing *informative* to add writes **zero** new Reports entries, full stop — don't manufacture one just to show you were active; `git log` and `diwan.org`'s other headings already show that. Never one giant entry covering the whole run either — one subheading per reportable thing, and don't report anything that happened inside an active `do` session's own subtree (that session reports its own work). Keep titles short enough that Marc can skim the whole log collapsed and know what happened without opening anything. Each entry: ** [ ] [[][]] [diwan YYYY-MM-DD] -Make the title itself the link — no `:LINK:` property, no properties drawer. Leave the title as plain text (no link) when there's no single heading the entry is about (e.g. "nothing to triage this run"). Anything needing Marc's actual input or a reply (as opposed to a passive FYI) belongs as a normal unread entry in the relevant heading's own `:chat:`, not in the report — the report entry's title or body may link there, but don't try to hold a conversation in it. +Make the title itself the link — no `:LINK:` property, no properties drawer. Leave the title as plain text (no link) when there's no single heading the entry is about. Anything needing Marc's actual input or a reply (as opposed to a passive FYI) belongs as a normal unread entry in the relevant heading's own `:chat:`, not in the report — the report entry's title or body may link there, but don't try to hold a conversation in it. Commit: `tick: report`.