samagotchi 0.187.0 → 0.189.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +96 -1
- data/bin/chi +2 -0
- data/docs/architecture.md +13 -7
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +139 -120
- data/docs/cli.md +46 -8
- data/docs/configuration.md +4 -4
- data/docs/context.md +18 -162
- data/docs/guardrails.md +6 -3
- data/docs/hooks.md +2 -1
- data/docs/internals/attached-context.md +19 -37
- data/docs/internals/bridge.md +1 -0
- data/docs/internals/bundles.md +3 -3
- data/docs/internals/engine.md +2 -2
- data/docs/internals/llm-context-forget.md +5 -6
- data/docs/internals/objectives.md +1 -0
- data/docs/internals/pages.md +71 -21
- data/docs/internals/peers.md +149 -0
- data/docs/internals/remote-sessions.md +7 -4
- data/docs/internals/session-lifecycle.md +19 -6
- data/docs/internals/web-frontend.md +63 -39
- data/docs/internals/web-push.md +12 -6
- data/docs/memory.md +1 -1
- data/docs/pages.md +70 -16
- data/docs/peers.md +144 -0
- data/docs/plugins.md +77 -28
- data/docs/releasing.md +1 -1
- data/docs/scheduling.md +71 -8
- data/docs/sessions.md +12 -8
- data/docs/sub-agent.md +5 -5
- data/docs/testing.md +1 -1
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundle_manifest.rb +34 -5
- data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
- data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
- data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
- data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
- data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
- data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
- data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
- data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
- data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
- data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
- data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
- data/lib/samagotchi/bundles/schedules/manifest.yml +11 -0
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +159 -0
- data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
- data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +2 -2
- data/lib/samagotchi/bundles/system/skill_pages.md +9 -4
- data/lib/samagotchi/client_id.rb +15 -1
- data/lib/samagotchi/config.rb +8 -7
- data/lib/samagotchi/context_absorber.rb +23 -277
- data/lib/samagotchi/context_sources.rb +17 -69
- data/lib/samagotchi/engine/messages.rb +12 -1
- data/lib/samagotchi/engine/plugins.rb +1 -1
- data/lib/samagotchi/engine.rb +7 -6
- data/lib/samagotchi/engine_peers.rb +0 -3
- data/lib/samagotchi/guardrail_wiring.rb +2 -0
- data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
- data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
- data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
- data/lib/samagotchi/inline_widgets.rb +11 -3
- data/lib/samagotchi/installed_bundles/manifest.rb +8 -1
- data/lib/samagotchi/log_line.rb +1 -1
- data/lib/samagotchi/memory_bundle/asset_installer.rb +3 -2
- data/lib/samagotchi/memory_bundle/builder.rb +1 -0
- data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
- data/lib/samagotchi/note_move.rb +3 -1
- data/lib/samagotchi/page_command.rb +25 -13
- data/lib/samagotchi/pages/builder.rb +7 -8
- data/lib/samagotchi/pages/bundled.rb +83 -0
- data/lib/samagotchi/pages/launch.rb +22 -4
- data/lib/samagotchi/pages/runner.rb +7 -2
- data/lib/samagotchi/pages/runtime.rb +83 -0
- data/lib/samagotchi/pages/store.rb +29 -7
- data/lib/samagotchi/pages.rb +47 -3
- data/lib/samagotchi/peer_command.rb +192 -0
- data/lib/samagotchi/peer_continue.rb +105 -0
- data/lib/samagotchi/peer_exchanges.rb +3 -3
- data/lib/samagotchi/peer_mailbox.rb +360 -0
- data/lib/samagotchi/peer_note.rb +208 -0
- data/lib/samagotchi/peer_receipts.rb +247 -0
- data/lib/samagotchi/peer_registry.rb +44 -0
- data/lib/samagotchi/peer_roster.rb +79 -0
- data/lib/samagotchi/peer_say.rb +168 -0
- data/lib/samagotchi/plugin/api.rb +29 -21
- data/lib/samagotchi/plugin/context.rb +7 -0
- data/lib/samagotchi/plugin/loader.rb +3 -3
- data/lib/samagotchi/plugin/peer.rb +175 -64
- data/lib/samagotchi/plugin/peers.rb +70 -0
- data/lib/samagotchi/run_options.rb +3 -2
- data/lib/samagotchi/schedule_command.rb +88 -39
- data/lib/samagotchi/schedule_display.rb +101 -0
- data/lib/samagotchi/schedules/busy_part.rb +146 -0
- data/lib/samagotchi/schedules/edit_part.rb +120 -0
- data/lib/samagotchi/schedules/history_part.rb +51 -0
- data/lib/samagotchi/schedules/listing_part.rb +52 -0
- data/lib/samagotchi/schedules/notices_part.rb +116 -0
- data/lib/samagotchi/schedules/protection_part.rb +103 -0
- data/lib/samagotchi/schedules/recurrence.rb +103 -0
- data/lib/samagotchi/schedules.rb +134 -330
- data/lib/samagotchi/session_access/contract.rb +18 -1
- data/lib/samagotchi/session_access/local.rb +140 -14
- data/lib/samagotchi/session_access/remote.rb +6 -3
- data/lib/samagotchi/session_access/remote_peers.rb +75 -0
- data/lib/samagotchi/session_chain/delete.rb +7 -5
- data/lib/samagotchi/session_continue.rb +12 -0
- data/lib/samagotchi/session_inbox_delivery.rb +5 -2
- data/lib/samagotchi/session_lifecycle/allowed.rb +2 -1
- data/lib/samagotchi/session_lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/delivery.rb +5 -3
- data/lib/samagotchi/session_manager/removal.rb +18 -9
- data/lib/samagotchi/session_manager/spawn.rb +2 -1
- data/lib/samagotchi/session_manager.rb +1 -0
- data/lib/samagotchi/session_protection.rb +99 -0
- data/lib/samagotchi/session_retention.rb +21 -6
- data/lib/samagotchi/session_stores.rb +17 -0
- data/lib/samagotchi/sessions_command.rb +4 -0
- data/lib/samagotchi/steer.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +1 -1
- data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
- data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
- data/lib/samagotchi/testing/boundary.rb +17 -13
- data/lib/samagotchi/testing/bundle.rb +40 -5
- data/lib/samagotchi/testing/install.rb +4 -4
- data/lib/samagotchi/testing/recording_api.rb +2 -1
- data/lib/samagotchi/tools/cancel_schedule.rb +5 -2
- data/lib/samagotchi/tools/context_read.rb +0 -14
- data/lib/samagotchi/tools/list_schedules.rb +8 -3
- data/lib/samagotchi/turn_outcome.rb +41 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +2 -13
- data/lib/samagotchi/web/message_display.rb +4 -2
- data/lib/samagotchi/web/page_routes.rb +13 -8
- data/lib/samagotchi/web/peer_routes.rb +133 -0
- data/lib/samagotchi/web/public/app.js +23 -29
- data/lib/samagotchi/web/public/bubbles.js +2 -2
- data/lib/samagotchi/web/public/cards_place.js +20 -1
- data/lib/samagotchi/web/public/context_chips.js +45 -46
- data/lib/samagotchi/web/public/history_reveal.js +4 -1
- data/lib/samagotchi/web/public/history_shape.js +3 -2
- data/lib/samagotchi/web/public/index.html +24 -2
- data/lib/samagotchi/web/public/notify.js +1 -1
- data/lib/samagotchi/web/public/owner_claim.js +7 -5
- data/lib/samagotchi/web/public/page_links.js +1 -1
- data/lib/samagotchi/web/public/page_view.js +10 -6
- data/lib/samagotchi/web/public/pages.css +9 -2
- data/lib/samagotchi/web/public/pages_group.js +21 -19
- data/lib/samagotchi/web/public/pages_list.js +73 -0
- data/lib/samagotchi/web/public/pages_model.js +54 -0
- data/lib/samagotchi/web/public/pages_wiring.js +66 -0
- data/lib/samagotchi/web/public/peer_chip.js +60 -74
- data/lib/samagotchi/web/public/peer_data.js +13 -11
- data/lib/samagotchi/web/public/peer_links.js +12 -7
- data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
- data/lib/samagotchi/web/public/peer_note.js +7 -3
- data/lib/samagotchi/web/public/peer_text.js +4 -4
- data/lib/samagotchi/web/public/quiet_notes.js +199 -0
- data/lib/samagotchi/web/public/revise_stack.js +4 -3
- data/lib/samagotchi/web/public/session_view.js +2 -2
- data/lib/samagotchi/web/public/stream_handlers.js +3 -2
- data/lib/samagotchi/web/public/turn_block.js +7 -3
- data/lib/samagotchi/web/public/turn_events.js +6 -0
- data/lib/samagotchi/web/public/views.js +77 -23
- data/lib/samagotchi/web/push/attention.rb +3 -2
- data/lib/samagotchi/web/push/notifier.rb +4 -3
- data/lib/samagotchi/web/server.rb +3 -1
- data/lib/samagotchi/web/session_access_routes.rb +3 -20
- data/lib/samagotchi/web/session_hub.rb +64 -19
- data/lib/samagotchi/worker/leave.rb +3 -0
- data/lib/samagotchi/worker/mail.rb +73 -0
- data/lib/samagotchi/worker/startup.rb +3 -0
- data/lib/samagotchi/worker/wake_turns.rb +20 -5
- data/lib/samagotchi/worker.rb +12 -6
- data/lib/samagotchi/worker_inbound/mail.rb +214 -0
- data/lib/samagotchi/worker_inbound.rb +43 -46
- data/lib/samagotchi/worker_wakes.rb +26 -21
- metadata +35 -2
- data/lib/samagotchi/peer_sources.rb +0 -58
data/docs/plugins.md
CHANGED
|
@@ -862,29 +862,33 @@ index = Samagotchi::Tools::ToolIndex
|
|
|
862
862
|
names itself (an mcp bundle before 0.7.0 has `find_mcp_tools` and
|
|
863
863
|
`mcp_call`) keeps them; with no source, `full` declares neither of chi's.
|
|
864
864
|
|
|
865
|
-
### `chi.
|
|
865
|
+
### `chi.peer(name)`
|
|
866
866
|
|
|
867
|
-
Declares a
|
|
868
|
-
`
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
sources](context.md#peer-sources-the-peer-loop)).
|
|
867
|
+
Declares a peer agent this bundle speaks for: the peer bundles' `claude` and
|
|
868
|
+
`codex`. Its messages in the session's mailbox (`chi peer say NAME`,
|
|
869
|
+
[peers.md](peers.md)) become its notes and may wake the session by the peer
|
|
870
|
+
loop's rules: up to `peer.turns` wake turns in a row, one closing wake
|
|
871
|
+
(outside that count) for a message whose verdict is `VERDICT OK`, and a wake
|
|
872
|
+
line that names the peer and keeps the turn within the user's task.
|
|
874
873
|
|
|
875
874
|
```ruby
|
|
876
|
-
chi.
|
|
875
|
+
chi.peer "codex"
|
|
877
876
|
```
|
|
878
877
|
|
|
879
|
-
- `name`: a
|
|
880
|
-
bundle's is a load error.
|
|
881
|
-
|
|
882
|
-
Codex"): a capital letter, then up to 23 letters and spaces.
|
|
878
|
+
- `name`: a lowercase letter, then lowercase letters and digits, up to 24.
|
|
879
|
+
Another bundle's is a load error. The peer's label is its name capitalised
|
|
880
|
+
("Codex").
|
|
883
881
|
|
|
884
|
-
The declaration lives in the session's process only, like a tool: a
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
882
|
+
The declaration lives in the session's process only, like a tool: a file in
|
|
883
|
+
the mailbox can't make its writer a peer, and uninstalling the bundle ends it
|
|
884
|
+
(a message from a name no loaded bundle declared is refused, and delivered
|
|
885
|
+
once one does). Subclasses of `Samagotchi::Plugin::Peer` (below) declare their
|
|
886
|
+
`PEER`. Needs the next chi (guard it with `chi.respond_to?(:peer)`).
|
|
887
|
+
|
|
888
|
+
`chi.peer_source(name, label:)` (the context-source peers of chi 0.67.0 to
|
|
889
|
+
0.187.0) is gone: it raises "chi.peer_source is gone: upgrade this bundle
|
|
890
|
+
(chi bundle install <name> --force)", so an older peer bundle fails to load
|
|
891
|
+
and chi starts without it.
|
|
888
892
|
|
|
889
893
|
### `chi.judgment(name, questions:, positive: nil, negative: nil)`
|
|
890
894
|
|
|
@@ -1567,7 +1571,7 @@ ctx.context.decline(url: "https://github.com/acme/app/pull/42") # => "pr-42"
|
|
|
1567
1571
|
ctx.context.propose(url: "https://github.com/acme/app/pull/42", title: "#42 Make the thing", mentions: ["#42", "feat/x"])
|
|
1568
1572
|
ctx.context.candidates # => [#<data Candidate name="pr-42", url="https://…", title="#42 Make the thing", …>]
|
|
1569
1573
|
ctx.context.withdraw("pr-42") # => true
|
|
1570
|
-
ctx.context.left_behind # => [#<data Left name="
|
|
1574
|
+
ctx.context.left_behind # => [#<data Left name="notes", hint="…", from="3f2a9c1e-…">]
|
|
1571
1575
|
```
|
|
1572
1576
|
|
|
1573
1577
|
[Attached context](context.md) for the session the plugin runs in: chi runs
|
|
@@ -1616,8 +1620,7 @@ gets a note when its text changes.
|
|
|
1616
1620
|
session left with the previous link ([Movable
|
|
1617
1621
|
context](context.md#movable-context)): `ContextSources::Left` values with
|
|
1618
1622
|
`name`, `hint` (the last pushed one, else the source's) and `from` (the
|
|
1619
|
-
previous link's id); `[]` for a session that isn't a continue's.
|
|
1620
|
-
bundles read it to ask their peer to pair again (below).
|
|
1623
|
+
previous link's id); `[]` for a session that isn't a continue's.
|
|
1621
1624
|
- The source is the session's (not the project's), marked
|
|
1622
1625
|
`added_by: plugin:<bundle>`. It is plugin code, so it isn't asked about as
|
|
1623
1626
|
the agent's `chi context add --cmd` is.
|
|
@@ -1634,6 +1637,23 @@ gets a note when its text changes.
|
|
|
1634
1637
|
The [github-pr bundle](bundles.md#the-github-pr-bundle) proposes the branch's PR from
|
|
1635
1638
|
a quiet `chi.init` task.
|
|
1636
1639
|
|
|
1640
|
+
## Peers: `ctx.peers`
|
|
1641
|
+
|
|
1642
|
+
```ruby
|
|
1643
|
+
ctx.peers.link("claude") # => #<data PeerLink peer="claude", address="/tmp/…sock", paired_at="…", from="…"> or nil
|
|
1644
|
+
ctx.peers.left_behind("claude") # the previous link's pairing, in a continue's new link; else nil
|
|
1645
|
+
ctx.peers.message("claude", 12) # => #<data PeerMessage serial=12, text="…", summary="…", wake=true, re="s-ab12cd", at="…"> or nil
|
|
1646
|
+
ctx.peers.last_message("claude") # the newest message still in the mailbox, or nil
|
|
1647
|
+
```
|
|
1648
|
+
|
|
1649
|
+
What a peer bundle reads of its peer's side of the session (the mailbox,
|
|
1650
|
+
[peers.md](peers.md)): the pairing (`address` nil: the peer answers only) and
|
|
1651
|
+
the peer's messages. Read only: the peer pairs and says through `chi peer`,
|
|
1652
|
+
and the worker takes the messages. A continue leaves the pairing with the
|
|
1653
|
+
previous link, so a new link's `link` is nil until the peer pairs again;
|
|
1654
|
+
`left_behind` is the one the previous link kept (`Plugin::Peer#tell_moved`
|
|
1655
|
+
tells the peer the new id there). Needs the next chi.
|
|
1656
|
+
|
|
1637
1657
|
### Context providers in the manifest
|
|
1638
1658
|
|
|
1639
1659
|
A bundle can turn URLs into sources for every process, without loading
|
|
@@ -1717,6 +1737,26 @@ block_renderers:
|
|
|
1717
1737
|
side and 100M px. Over that, or if the image doesn't decode, the block stays source. The
|
|
1718
1738
|
layers and the residual risk are in [internals/block-renderers.md](internals/block-renderers.md).
|
|
1719
1739
|
|
|
1740
|
+
## Pages
|
|
1741
|
+
|
|
1742
|
+
A bundle can ship [pages](pages.md): Ruby scripts the page runner runs, listed under `pages:` (from chi 0.189.0).
|
|
1743
|
+
|
|
1744
|
+
```yaml
|
|
1745
|
+
# manifest.yml
|
|
1746
|
+
scripts:
|
|
1747
|
+
schedules.rb: sha256:… # scripts/schedules.rb in the bundle
|
|
1748
|
+
pages: [schedules.rb] # scripts: keys named NAME.rb: the page NAME
|
|
1749
|
+
```
|
|
1750
|
+
|
|
1751
|
+
- Each is a `scripts:` file, so it installs and checks as any script does, and one changed after the install runs
|
|
1752
|
+
nothing until the bundle is reinstalled (a `--dev` install's links aren't checked).
|
|
1753
|
+
- chi web lists them from the install records, running no plugin. The first installed bundle (by name) with a page
|
|
1754
|
+
name has it; a bundle whose `requires_chi` this chi doesn't meet has none.
|
|
1755
|
+
- The owner's own `NAME.rb` in the pages folder replaces a bundle's page, and a bundle's page can't be removed but
|
|
1756
|
+
by uninstalling the bundle ([Pages from a bundle](pages.md#pages-from-a-bundle)).
|
|
1757
|
+
- The script is a page script like any other: `page`, `ui` and `runtime` ([pages.md](pages.md)). The shipped
|
|
1758
|
+
schedules bundle is the example (`lib/samagotchi/bundles/schedules/`).
|
|
1759
|
+
|
|
1720
1760
|
## Stable for bundles
|
|
1721
1761
|
|
|
1722
1762
|
Bundles normally use only `chi.*` and `ctx`; the constants, helpers and manifest
|
|
@@ -1741,16 +1781,18 @@ that calls it, or for a real external bundle that does. No method on the chance
|
|
|
1741
1781
|
`Samagotchi::Plugin::Secrets::Busy` and `Samagotchi::Plugin::Secrets::Unavailable` (a bundle rescues them by name).
|
|
1742
1782
|
2. `Samagotchi::Plugin::Peer` as a base class. A subclass defines `post`,
|
|
1743
1783
|
`check_hint!`, `paired_lines`, `transport_line`, `peer_dir` and
|
|
1744
|
-
`setup_paragraph` (optionally `skill_substitutions`), and sets `NAME`,
|
|
1745
|
-
`APP`, `COMMAND`, `USAGE`, `
|
|
1746
|
-
read as `self.class::X`.
|
|
1784
|
+
`setup_paragraph` (optionally `skill_substitutions` and `skill_installed`), and sets `PEER`, `NAME`,
|
|
1785
|
+
`APP`, `COMMAND`, `TOOL`, `READ_TOOL`, `USAGE`, `LEGACY_INBOX`, `LEGACY_OUTBOX` and `SCRIPTS_DIRS`. These
|
|
1786
|
+
constants are read as `self.class::X`. It declares the peer (`chi.peer PEER`), the send tool and
|
|
1787
|
+
`<peer>_read` (a long message by its number, paged), and sends to the pairing's address
|
|
1788
|
+
(`ctx.peers.link`). The base names each send: `Peer.send_id(kind, title, text, salt)` (`s-` and 6 hex
|
|
1747
1789
|
of SHA-256 over the args as given and the send's salt: the tool run's `ctx.tool_id`, a random one for a
|
|
1748
1790
|
`/<peer>` command's, so each send has its own id; a nil salt gives an older chi's id, over the args alone) is the
|
|
1749
1791
|
message's second line (`ref: <id>`), the tool row's `peer` ref (display only, no actions; computed from the args
|
|
1750
1792
|
and the run's id before the call runs, a two-arg `refs:`, so a send that then fails has it too) and the last
|
|
1751
|
-
send's `id`; the peer's answer
|
|
1752
|
-
Successful sends and transport failures are recorded in the session's peer exchange log;
|
|
1753
|
-
|
|
1793
|
+
send's `id`; the peer's answer names it (`chi peer say --re`).
|
|
1794
|
+
Successful sends and transport failures are recorded in the session's peer exchange log; the answers are the
|
|
1795
|
+
mailbox's messages. The log does not enter the model's context.
|
|
1754
1796
|
See the [claude-peer](bundles.md#the-claude-peer-bundle) and
|
|
1755
1797
|
[codex-peer](bundles.md#the-codex-peer-bundle) bundles.
|
|
1756
1798
|
3. `Samagotchi::Tools::ToolIndex::Tool` and `Samagotchi::Tools::ToolIndex::Group`
|
|
@@ -1767,7 +1809,7 @@ that calls it, or for a real external bundle that does. No method on the chance
|
|
|
1767
1809
|
7. **The manifest schema**: the manifest's keys and shapes, as [A bundle with a plugin](#a-bundle-with-a-plugin)
|
|
1768
1810
|
and [bundles.md](bundles.md) document them — `name`, `version`, `scope`, `description`, `files`, `hooks`,
|
|
1769
1811
|
`trust_level`, `plugin`, `requires_chi`, `requires_chi_next` (shipped bundles only: the release tooling
|
|
1770
|
-
reads it, chi doesn't), `needs`, `scripts`, `context_providers`, `block_renderers`, `includes`,
|
|
1812
|
+
reads it, chi doesn't), `needs`, `scripts`, `context_providers`, `block_renderers`, `pages`, `includes`,
|
|
1771
1813
|
`session_settings`, `settings`. Those are `BundleManifest::KEYS`; `BundleManifest::SINCE` is the chi release each
|
|
1772
1814
|
key or shape first worked in, and the docs don't copy it — the code is its truth.
|
|
1773
1815
|
- A key keeps its meaning. A new key gets a `SINCE` entry and a CHANGELOG line, and an older chi says
|
|
@@ -1779,6 +1821,10 @@ that calls it, or for a real external bundle that does. No method on the chance
|
|
|
1779
1821
|
There is no `api_version:`.
|
|
1780
1822
|
- `block_renderers:`, the frame's `chi.defineRenderer` and `chi.features` (`regions`: `render` may return
|
|
1781
1823
|
`{ svg, regions }`) ([Block renderers](#block-renderers)) are part of it. Neither is Ruby, so the scan below doesn't see them.
|
|
1824
|
+
- `pages:` and the page script DSL a bundle's page (or anyone's) is written in: `page`, `ui.text` / `ui.table` /
|
|
1825
|
+
`ui.walk`, and `runtime` with what it returns (`runtime.schedules`: its members, `rows`, `warning`,
|
|
1826
|
+
`unreadable_ids`, `Pages::Runtime::Unreadable`) ([pages.md](pages.md)). A page runs in the page runner, not as a
|
|
1827
|
+
plugin, so the scan below doesn't see it either.
|
|
1782
1828
|
|
|
1783
1829
|
`Samagotchi::Testing::Boundary::ALLOWED` is the checked copy of items 1-6,
|
|
1784
1830
|
and `Boundary::EXCEPTIONS` the per-bundle list of what each shipped bundle
|
|
@@ -1838,6 +1884,9 @@ bundle.set(usage: { tool_calls: 40, active_ms: 600_000 }) # ctx.usage: { turns:,
|
|
|
1838
1884
|
bundle.set(turn_author: "p:p_0123abcd") # a participant's turn: ctx.turn_author, and author: on every event
|
|
1839
1885
|
bundle.set(session_settings: { "cap" => 1 }) # the session's --set values (Bundle.load takes session_settings: too)
|
|
1840
1886
|
bundle.tool_loads.last.names # ctx.load_tools calls; set(load_tools_staged: [...]) limits what they stage
|
|
1887
|
+
bundle.pair_peer("claude", address: "/tmp/c.sock") # a peer's side, as chi peer pair writes it (ctx.peers.link); address: nil answers only
|
|
1888
|
+
bundle.peer_says("claude", "VERDICT OK", summary: "s") # a message in the mailbox, as chi peer say writes it (ctx.peers.message)
|
|
1889
|
+
bundle.unpair_peer("claude") # chi peer unpair; bundle.peer_registry.names: the chi.peer declarations
|
|
1841
1890
|
bundle.shutdown
|
|
1842
1891
|
```
|
|
1843
1892
|
|
|
@@ -1913,7 +1962,7 @@ docs/testing.md). **Minitest:** `require "samagotchi/testing/minitest"` and subc
|
|
|
1913
1962
|
checked: a bundle whose `requires_chi` this chi doesn't meet raises `InstallError` unless `force: true`)
|
|
1914
1963
|
and loads the installed copy with chi's own loaders. It returns `warnings` (the Installer's),
|
|
1915
1964
|
`plugin_failures` / `hook_failures` (each with the `location` in your source, `plugin.rb:12`) and `registered`
|
|
1916
|
-
(commands, tools, hooks per event, inits, toolkits, tool and
|
|
1965
|
+
(commands, tools, hooks per event, inits, toolkits, tool sources and peers). A name chi ships raises
|
|
1917
1966
|
`MemoryBundle::Installer::InstallError` unless `force: true`.
|
|
1918
1967
|
- **From the command line:** `chi bundle test [PATH]` runs a bundle's `test/**/*_test.rb` (or `spec/`) on the
|
|
1919
1968
|
Ruby and lib chi runs on, and `chi bundle check [PATH] [--fix]` runs `Install` (and the manifest, sha and
|
data/docs/releasing.md
CHANGED
|
@@ -13,7 +13,7 @@ can run the whole release; the user approves the notes before the tag and the
|
|
|
13
13
|
and `rake release:check` enforce it). The system bundle upgrades itself when
|
|
14
14
|
chi starts.
|
|
15
15
|
- **Every other shipped bundle** (btw, check-in, guardrails, known-names,
|
|
16
|
-
loop-guard, mcp, skills, slow-commands, agents-md, cost-cap, work-cap, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes, decision-card, inline-widgets, web-search, and the profiles core and dev) has its own semver in its
|
|
16
|
+
loop-guard, mcp, skills, slow-commands, agents-md, cost-cap, work-cap, source-links, github-pr, coordinator, claude-peer, codex-peer, ruby, model-notes, decision-card, inline-widgets, web-search, schedules, and the profiles core and dev) has its own semver in its
|
|
17
17
|
`manifest.yml` and, when it needs a newer chi, a `requires_chi:` line. They never upgrade by themselves: users run
|
|
18
18
|
`chi update` (all of them, with the gem) or `chi bundle upgrade NAME`. So:
|
|
19
19
|
- a change to a bundle's files bumps that bundle's `version:`
|
data/docs/scheduling.md
CHANGED
|
@@ -105,7 +105,11 @@ time zones.
|
|
|
105
105
|
|
|
106
106
|
## The busy check
|
|
107
107
|
|
|
108
|
-
A cron tick cannot read a worker's memory, so the tick has two paths.
|
|
108
|
+
A cron tick cannot read a worker's memory, so the tick has two paths. What the
|
|
109
|
+
session's lifecycle state answers (deleting, stopped, a worker starting, leaving or
|
|
110
|
+
on a newer chi) comes from the lifecycle table (`SessionLifecycle::ALLOWED`,
|
|
111
|
+
[internals](internals/session-lifecycle.md)); the Bridge ask and the file checks
|
|
112
|
+
below are the busy check's own.
|
|
109
113
|
|
|
110
114
|
**Being deleted** (a deleter holds the owner lock) comes before a stop marker.
|
|
111
115
|
The skip is "the session is being deleted", and the next tick finds the session
|
|
@@ -197,6 +201,29 @@ tick is about an hour of patience, which is what the count really measures.
|
|
|
197
201
|
`chi schedule enable` resets both counters too: a schedule turned back on gets its
|
|
198
202
|
whole budget again, not one skip.
|
|
199
203
|
|
|
204
|
+
`chi schedule show ID` ends with the entry's last 20 outcomes, newest first, one
|
|
205
|
+
line each in local time: `fired`, `skipped`, `failed`, `missed`, your `enabled` and
|
|
206
|
+
`disabled`, a `chi schedule edit`'s `edited` (naming the fields), with the reason and
|
|
207
|
+
the session it acted on (a skip or
|
|
208
|
+
failure that used up the budget says `disabled: <reason>`). `list --format json` has
|
|
209
|
+
them as each entry's `history` (and an unpushed turn-off as `disabled_notice`).
|
|
210
|
+
|
|
211
|
+
`list --format json` gives each entry every stored field (with any key a newer chi
|
|
212
|
+
added), then `recurrence_words`, `skip_window`, and what a reader would otherwise work
|
|
213
|
+
out: `name` (the title, or the start of the prompt in quotes, as `list` names it),
|
|
214
|
+
`state` (`on`, `firing` while a firing is in flight, `off`) and `off_reason`, why an
|
|
215
|
+
off one is off: `owner` (your `disable`), `skips` or `failures` (a budget used up),
|
|
216
|
+
and for a `date` one-off its last outcome in the history: `done` (it fired),
|
|
217
|
+
`failures` (it failed) or `missed`; `off` when none of these says (an older file's
|
|
218
|
+
spent one-off). These come last, so a stored key of the same name never hides them
|
|
219
|
+
(`ScheduleDisplay.json`).
|
|
220
|
+
|
|
221
|
+
`chi schedule edit ID` changes a schedule in place (its title, prompt, recurrence,
|
|
222
|
+
catch-up or budgets; [CLI](cli.md#durable-schedules-chi-schedule)) and keeps its id,
|
|
223
|
+
session, mode, counters and history. A new recurrence starts its clock at the edit, as
|
|
224
|
+
an `add`'s does, and waits for a firing in flight to settle; a spent `date` one-off
|
|
225
|
+
stays disabled after an edit until you `enable` it.
|
|
226
|
+
|
|
200
227
|
A recurring schedule the owner has disabled stays off when an in-flight skip or
|
|
201
228
|
failure is recorded. A `date` one-off is the exception: a skip or failure puts its
|
|
202
229
|
moment back and re-enables it. `run-now` still tries a disabled schedule, but a
|
|
@@ -204,13 +231,19 @@ refusal records its result without moving the skip or failure counters.
|
|
|
204
231
|
|
|
205
232
|
The tick line that disabled an entry ends `(disabled)` (`chi schedule tick`,
|
|
206
233
|
`run-now`), and `tick --format json` gives that outcome `"disabled": true`
|
|
207
|
-
(`Schedules::Outcome#disabled`). When
|
|
208
|
-
|
|
234
|
+
(`Schedules::Outcome#disabled`). When any tick — chi web's own (`schedule.auto_tick`),
|
|
235
|
+
a cron `chi schedule tick` or a `chi schedule run-now` — disables a recurring schedule
|
|
236
|
+
by its budget, the phone gets one notification
|
|
209
237
|
([Phone notifications](configuration.md#phone-notifications-web-push)): "Schedule
|
|
210
238
|
disabled: Heartbeat", "skipped 12 times: <the last reason>" and the `chi schedule
|
|
211
|
-
enable <id>` that turns it back on; a tap opens its session.
|
|
212
|
-
|
|
213
|
-
|
|
239
|
+
enable <id>` that turns it back on; a tap opens its session. The tick leaves a notice
|
|
240
|
+
on the entry in `schedules.json` (`disabled_notice`) and a running chi web pushes it:
|
|
241
|
+
right after its own tick, and within `schedule.tick_interval_minutes` for another
|
|
242
|
+
ticker's, with `schedule.auto_tick` off too. Only chi web pushes, so with no chi web
|
|
243
|
+
running the notice waits for one; a notice more than a day old, or one whose schedule
|
|
244
|
+
you enabled again, is dropped unpushed, and `chi schedule enable` clears it. It shows
|
|
245
|
+
even with a chi web page in front and waits a day for a phone that is offline. Two chi
|
|
246
|
+
webs on one state dir push it once. Nothing notifies for a `--dry-run`, your own
|
|
214
247
|
`chi schedule disable`, or a `date` one-off (spent when it fires; one that then fails
|
|
215
248
|
stays disabled with the failure in `chi schedule list`).
|
|
216
249
|
|
|
@@ -222,7 +255,9 @@ and `show`. A question does not time out with the 40-second firing step: the tur
|
|
|
222
255
|
stays pending until its hard limit, derived from the schedule interval (at least
|
|
223
256
|
10 minutes and at most 6 hours). If no outcome is known by then, it counts as a
|
|
224
257
|
failure with reason `no outcome`. Failed, canceled and expired turns are not
|
|
225
|
-
re-fired; `next_due` remains at the next occurrence.
|
|
258
|
+
re-fired; `next_due` remains at the next occurrence. The turn's outcome is read
|
|
259
|
+
from its files by `TurnOutcome.for` (`turn_outcome.rb`: its reply, its settled turn and
|
|
260
|
+
the words); `Schedules#resolve_pending` keeps the order: the reply, the question, the turn, expiry.
|
|
226
261
|
|
|
227
262
|
A chain holds at most `schedule.max_per_session` enabled schedules (default 10) and
|
|
228
263
|
the machine `schedule.max_total` (default 50); `schedule_task` and `chi schedule add`
|
|
@@ -267,6 +302,17 @@ its descendants, and archived sessions are outside the retention sweep
|
|
|
267
302
|
count. The `anchor` is never pruned: it is the chain's root, the id the user and
|
|
268
303
|
the coordinator remember, and `last:<anchor>` must keep resolving.
|
|
269
304
|
|
|
305
|
+
What a schedule protects (its anchor, its head and its resolved target, while it is
|
|
306
|
+
enabled) the retention sweep keeps and a delete refuses: schedules are
|
|
307
|
+
`SessionProtection`'s one protector (`Schedules::ProtectionPart`, [sessions.md](sessions.md)). It reads
|
|
308
|
+
`schedules.json` strictly: a file that is there but doesn't read (not JSON, a `schedules` member that isn't a list, a
|
|
309
|
+
file chi can't open) makes the sweep delete nothing that round (`retention_skipped`, retried at the next sweep
|
|
310
|
+
interval) and every delete refused, "schedules.json is unreadable (…): fix or remove it before deleting sessions". One
|
|
311
|
+
schedule that doesn't read does the same in its own words, "schedule entry <id> in schedules.json is unreadable
|
|
312
|
+
(lacks prompt): chi schedule cancel <id>, or fix the file, before deleting sessions": `chi schedule cancel <id>` removes
|
|
313
|
+
such a record by its id (`list` doesn't show it). The tick keeps its own rule (it refuses a file that isn't JSON and
|
|
314
|
+
skips a schedule that doesn't read).
|
|
315
|
+
|
|
270
316
|
Schedule prune leaves the deleted links' background tasks running: a later link
|
|
271
317
|
may still use a server started by an earlier link in the same project. Continue
|
|
272
318
|
does not yet transfer task ownership.
|
|
@@ -303,7 +349,8 @@ Run it from systemd or launchd instead if you prefer a timer: the command is the
|
|
|
303
349
|
same, `chi schedule tick`, and the lock makes overlapping runs harmless — the
|
|
304
350
|
second one exits 0 with "no schedules due (another tick holds the lock)".
|
|
305
351
|
`--dry-run` prints what would fire and changes nothing; `--format json` is the seam
|
|
306
|
-
for scripts
|
|
352
|
+
for scripts; a page script reads the schedules in chi itself instead
|
|
353
|
+
(`runtime.schedules`, [pages.md](pages.md#reading-chis-data-runtime)). `chi schedule run-now` reserves the entry
|
|
307
354
|
under the same lock before starting its action, so it cannot race a tick into a
|
|
308
355
|
duplicate firing.
|
|
309
356
|
|
|
@@ -327,5 +374,21 @@ the configured interval, `chi schedule add`, `chi schedule list` and `schedule_t
|
|
|
327
374
|
warn to turn `schedule.auto_tick` on or run `chi schedule tick` from cron; `--dry-run`
|
|
328
375
|
and lock-held attempts do not refresh `last_tick_at`.
|
|
329
376
|
|
|
377
|
+
## The Schedules page
|
|
378
|
+
|
|
379
|
+
`chi bundle install schedules` adds a **Schedules** page to chi web (`#/p/schedules`,
|
|
380
|
+
under the `pages` pill; `chi page run schedules` in a terminal) from the shipped
|
|
381
|
+
schedules bundle ([bundles.md](bundles.md#the-schedules-bundle)). It shows how many
|
|
382
|
+
schedules there are and in which state, with the tick warning when nothing ticks; each
|
|
383
|
+
schedule that is off and why ("turned off by you", "skipped 12 times (≈1 h at a 5 min
|
|
384
|
+
tick): busy", "failed 3 times: …", "one-off, done") with the `chi schedule enable ID`
|
|
385
|
+
that turns it back on (for a spent one-off, which has no next time, a `chi schedule
|
|
386
|
+
edit ID --date …` first); each entry of `schedules.json` that can't be read with the
|
|
387
|
+
`chi schedule cancel ID` that removes it; a table of every schedule (on and firing
|
|
388
|
+
first by next due, those with none last, then off; times in this machine's zone) and the recent runs, newest
|
|
389
|
+
first. It is read-only: ask chi, or use `chi schedule`, to change one. What it shows is
|
|
390
|
+
as of its last run: Refresh to update. A `schedules.json` that isn't JSON fails the
|
|
391
|
+
run with the store's own words, and the last good result stays.
|
|
392
|
+
|
|
330
393
|
See [cli.md](cli.md) for the subcommands and flags, and
|
|
331
394
|
[configuration.md](configuration.md) for the `schedule.*` settings.
|
data/docs/sessions.md
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/sessions/<uuid>.json` (XDG-aware via `XDG_STATE_HOME`) plus a sidecar dir `<uuid>/` with `input/`/`notes/`/`output/`/`owner.lock`/`bridge.json` (`Session.session_dir`), `turn_drawings.jsonl` once a turn ended with a Bridge or in a one-shot run (each finished turn as live drew it, which the web's reload draws: [bridge.md](internals/bridge.md#turndrawings); a fork starts with its parent's lines for the turns its seed keeps unchanged, a continue with none: its turns, and any without a line, are drawn from their messages), and `tool_output/` once a long `execute` result was cut: its whole output, which the cut result names (`ToolOutputFiles`, the newest 50 kept; see [Tool output guardrails](internals/tool-output-limits.md#the-runners-cut-max_tool_output_chars)). Its keys are in [the Session file table](#session-file). A file from before `used_memory_names`, `preloaded_memory_names`, `muted_memory_names`, `parent_id` or `continues` reads those as empty lists, no parent and no previous link.
|
|
4
4
|
|
|
5
|
-
The sidecar's `peer_exchanges.jsonl` records peer sends
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
The sidecar's `peer_exchanges.jsonl` records peer sends and transport
|
|
6
|
+
failures, never their text, and `peer_receipts.json` what the worker did with
|
|
7
|
+
each peer message (its worker writes it alone); the messages themselves are in
|
|
8
|
+
the mailbox, `$XDG_STATE_HOME/samagotchi/mailbox/<uuid>/<peer>/`, apart from
|
|
9
|
+
the sessions folder. All three stay with the previous link on a continue (its
|
|
10
|
+
unread messages reach the new link as one note); a delete removes them. See
|
|
11
|
+
[peers.md](peers.md).
|
|
8
12
|
|
|
9
13
|
**Message times:** an entry of `messages` may carry `at`, when it happened: a local-offset ISO time with milliseconds (`2026-10-24T14:32:05.120+02:00`). User prompts, lines merged into a turn and steers, reminders, context and task notes, and the model's replies have one (a note's is its `created_at`); tool results, `!cmd` messages and chi's own turn notes don't, nor does anything saved before chi stamped messages (no backfill). It is for the UIs only (the gap dividers, a bubble's time): it never goes to the model, so it changes nothing in the requests or their prompt cache. The one time the model reads is the reminders': due reminders go into a turn as a system message headed `[SYSTEM: REMINDERS DUE 2026-10-24 14:32 local]` (the turn's local time; `ReminderQueue#inject!`), written into the saved content then, so a later request sends the same text.
|
|
10
14
|
|
|
@@ -27,7 +31,7 @@ continue; the new link starts empty. See [context storage](context.md#storage).
|
|
|
27
31
|
| `SAMAGOTCHI_SESSION_KEEP_STATUS` | (none) | CSV of statuses never auto-pruned |
|
|
28
32
|
| `SAMAGOTCHI_SESSION_SWEEP_INTERVAL_HOURS` | `24` | Throttle lazy sweep |
|
|
29
33
|
|
|
30
|
-
A session is deleted if **expired by age OR overflow by count** (unless `keep_status` or the live-owner guard: a session a worker or `chi` still has open is never pruned). A session's `status` is its turn state (`idle`/`running`), not whether a worker is alive. Orphan dirs without a `*.json` are never deleted, except skeleton-only ones (see *Empty sessions*). Deletion removes its `*.json` and sidecar dir under the deleting owner lock, along with its plugin state, attached context, participant grants, System 1 runs and context-candidate records. Explicit delete and retention use the same cleanup path. Set both `DAYS=0` and `MAX=0` to retain forever.
|
|
34
|
+
A session is deleted if **expired by age OR overflow by count** (unless `keep_status` or the live-owner guard: a session a worker or `chi` still has open is never pruned). A session's `status` is its turn state (`idle`/`running`), not whether a worker is alive. Orphan dirs without a `*.json` are never deleted, except skeleton-only ones (see *Empty sessions*). Deletion removes its `*.json` and sidecar dir under the deleting owner lock, along with its plugin state, attached context, participant grants, System 1 runs and context-candidate records. Explicit delete and retention use the same cleanup path. Set both `DAYS=0` and `MAX=0` to retain forever. A session something protects is kept whatever its age or place: an enabled schedule's anchor, head and resolved target (`SessionProtection.protected_ids`; schedules are its one protector, *Deleting a session*). A protector that can't answer stops the sweep's deletes for that round: a `schedules.json` that is there but doesn't read (not JSON, not a schedules document, a file chi can't open, or a schedule in it that doesn't read) protects everyone until it is fixed (one `retention_skipped` line per sweep interval, the next try at the next interval; the skeleton-only dirs and saved runs are still swept), and `chi sessions prune`/`clean` exit 1 with its words; a missing one is no schedules ([scheduling.md](scheduling.md#keeping-the-chain-short): `chi schedule cancel <id>` removes one schedule that doesn't read).
|
|
31
35
|
|
|
32
36
|
Retention and manual prune/clean silently stop each deleted session's verified background tasks under its deleting lock, with `by: retention` (`stopped_by_retention`). Sessions are processed sequentially, their tasks in parallel. Unverified or unreadable tasks are not signalled; stops and failures are logged per task as `retention_task_stopped` / `retention_task_not_stopped`, without commands. A scratch session's own cleanup does the same with `by: scratch` and `scratch_task_stopped` / `scratch_task_not_stopped`.
|
|
33
37
|
|
|
@@ -51,7 +55,7 @@ A new session field is one `Session::FIELDS` row, plus a `SessionSetup` member w
|
|
|
51
55
|
|
|
52
56
|
**Stopping a worker:** `chi sessions stop ID` marks the session stopped (an `<id>/stopped` file holding when, `{"at"}`, not a session.json field, which a worker saving at that moment would write over; a resume removes it), sends its worker TERM, then CONT (a stopped worker, SIGSTOP or Ctrl-Z, runs its TERM handler only once continued, so it leaves at once instead of outliving the wait), and waits (up to 10 s) until the worker has let go of `owner.lock`. A running turn is canceled over the Bridge first, with reason `session_stopped` (the turn's line ends "(session stopped)", its note says `cancelled (session-stopped)`, and a command it was running says "stopped as the session was stopped"; a bare signal to the worker makes it "stopped by a signal to chi"; an older worker takes the reason as `manual`); the TERM stops whatever still runs as a Stop with reason `signal` and saves it (a spawned worker traps TERM, HUP and INT: `WorkerSignals`; a turn not ended within 3 s, 0.5 s after a stop or a second signal, is cut and the session saved as it was), and a stopped worker still saves its kept turn, since the marker, not the saved status, says stopped. Any TERM, HUP or INT does the same to a worker outside a stop: it leaves (log `worker stop reason=signal`) and the next send wakes a new one, so a `chi --resume ID` right after spawns a fresh worker. That is also how to restart a worker still running an older chi, which the attached terminal reports when a command or a question dismiss gets a 404, and the web when an answer, a dismiss, a command or a cancel does (`501 not_supported`; `BridgeClient.stale_worker_message`). A command this chi has that the older worker doesn't (`/llm-context`, the web's ⚙ panel, against a 0.39.0 worker) says the same, not `not a session command` (`SessionCommandCatalog.builtin_name`); a typo keeps its `400 unknown_command`. The web's `POST /api/sessions/:id/stop` waits the same way, for 2 s (the page's Stop shows the stop at once), or for the body's `wait` up to the same 10 s (`SessionManager::STOP_WAIT`): `chi --remote NAME sessions stop` sends it, so it waits as long as here. Before that stop, the page's `stop session` button asks what the worker still has that the user can stop: `GET /api/sessions/:id/holds` (owner-only) answers the worker's `holds` — the same list the exit ask's 409 carries — always an array, empty when there is no live worker, one from before the route, or one that did not answer. With something, a sheet (a bottom sheet on a phone, a popover at the button otherwise — `stop_sheet.js`) lists them, at most three of a kind named and `+N more`, and offers **Stop all** (`POST /api/sessions/:id/holds/stop` → `HoldStop#stop_all`, then the stop), **Stop session only** (the stop exactly as it was) or **Cancel**. Nothing to ask about is the plain confirm, one tap as before. Both buttons stay because a stop only TERMs the worker: its reminders die with it (a stop also deletes a restart's `reminders.json` no successor took yet, so a later resume doesn't bring them back), while a background task and a delegate are their own processes and keep running. A delete or an archive differs: it never leaves a task the session started running unasked (*Deleting a session*: refused, or `--stop-tasks` stops it), where Stop's "Stop session only" does. A command sent during a turn that waits for its end (`/model X`, `!cmd`; see *Typing during a turn* in [cli.md](cli.md)) and hasn't run when the worker leaves (a stop, a crash) is answered `command_ran {status: "dropped"}`, so no UI keeps showing it waiting.
|
|
53
57
|
|
|
54
|
-
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. While the delete holds it (kind `deleting`), every delivery is refused: a message (`chi send`, the web, a schedule, a delegate, a plugin, a participant) gets 409 `session_deleting`, "the session is being deleted", and a send that read the session before the lock and wrote after it takes its file back and says the same (unless a worker took the file meanwhile: then it is delivered); a note is refused as for a gone session, and a delegate's ring, a push and a fresh verdict are not written. The web asks in one sheet first (*Session chains* → Deleting a link, the page side in docs/internals/web-frontend.md, The delete sheet): what goes, what is stopped first and what stays, one button naming the outcome, no browser confirm. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) goes through `SessionChain::Delete.link` for every session, chained or not (*Session chains* → Deleting a link): **its delegates follow one rule** (`SessionManager::DELEGATES`): the stopped ones (archived ones too) go with it, deepest first, and a running one stays with its whole subtree, its file untouched; a stopped delegate with a running child goes and leaves that child without a parent. The delegates that would go bring their own refusals: one that is a schedule's target, anchor or head refuses the delete (`scheduled`, naming the delegate), as does one in a one-turn run, one a worker took after the plan was made (`worker_running`), and their running background tasks (below); their participant grants end with them. The result lists them in `deleted` (the session last) and the running ones with their subtrees in `left_running`; the CLI's line and `/exit --delete` say how many went. It is also refused while a continue of the session, or of the previous link it would bring back, is under way (`continuing`), and deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly (`delete_resolved`: they pass neither keyword and take no delegates); the retention sweep removes files directly (`remove_files`). **Background tasks still running:** a user's delete (these three, and `chi sessions delete`) asks first when tasks the deleted sessions started (their `task_create` tasks and the `execute` runs handed over at their limit, read from each session's transcript and `<working_directory>/tmp/tasks/<id>/task.json`: `SessionManager::RunningTasks`) still run: it is refused before anything changes (`tasks_running`), and the CLI's `--stop-tasks`, the web's `stop_tasks=true` (the delete's and the chain delete's query; with `&tasks=<id,id>`, the ones the sheet named, only those: `RunningTasks::Policy.stop(only:)`, see *Deleting a link*) stop them first (`stopped_by_user`, TERM then KILL after 3 s, all at once, about 4 s at most), under the deleting lock, after the starting-marker re-check, so no worker takes the session meanwhile; that last check refuses a task that started since the first (`worker_stopped: true` when the worker was stopped by then). One rule, fail-safe: a task whose pid still leads the group chi started at the start time it recorded is *running*; one whose record has no start time (before 2026-10-09) or whose start time reads nothing now, while its pid leads a group, is *unverified* ("may still be running"); a `task.json` that doesn't read is *unreadable*. All three refuse; a stop signals only the running ones (an unverified pid may belong to another process now) and reports the rest as not stopped, then deletes. A record left marked running whose pid is gone (a crashed worker's) isn't listed. The 409 is `{error: "tasks_running", reason, op: "delete", detail, session_id, tasks: {running, unverified, unreadable}, worker_stopped, stopped_worker, stopped_workers}` (`stopped_worker`: whose worker the delete stopped before the last check refused; `stopped_workers`: every worker the delete stopped), each task `{session_id, id, command}` (`links` too for a chain delete's other links); the 200 gains `tasks_stopped`, `tasks_not_stopped` and `tasks_ended` (empty unless stopped). A session's file gone (its folder left) has no tasks. The retention sweep and scratch cleanup stop verified tasks silently; the empty-session discard, failed-continue rollback and schedule prune leave them running.
|
|
58
|
+
**Deleting a session:** `chi sessions delete ID...`, `/exit --delete` in a terminal and the Web UI's delete all go through `SessionManager.delete_session`: it resolves a unique prefix, removes `<id>.json` and the whole `<id>/` dir, and returns what it removed. A session a one-turn `chi --non-interactive` run has (`owner.lock` kind `tui`) is always refused. One a worker runs is refused unless the caller asks to stop it: then it stops the worker as `chi sessions stop` does and deletes once `owner.lock` is free (`--force` on the CLI, 10 s; the web page always, 2 s; `/exit --delete` after the worker agreed to exit, 10 s). A worker that outlives the wait leaves the session in place. A session whose worker is being started (the `<id>/starting` marker) is refused or stopped the same way, and the files go while the delete holds `owner.lock`, so a worker can't take the session in the middle; a worker that still had it loaded doesn't write it back. While the delete holds it (kind `deleting`), every delivery is refused: a message (`chi send`, the web, a schedule, a delegate, a plugin, a participant) gets 409 `session_deleting`, "the session is being deleted", and a send that read the session before the lock and wrote after it takes its file back and says the same (unless a worker took the file meanwhile: then it is delivered); a note is refused as for a gone session, and a delegate's ring, a push and a fresh verdict are not written. The web asks in one sheet first (*Session chains* → Deleting a link, the page side in docs/internals/web-frontend.md, The delete sheet): what goes, what is stopped first and what stays, one button naming the outcome, no browser confirm. The web's route is `DELETE /api/sessions/:id?force=true` (the page sends `force`; without it a live worker's session is 409 `worker_running`, as the CLI without `--force`; 200 `{status: "deleted", session_id, stopped, unarchived, moved_back}`; `deleted` and `left_running` too; 409 with the refusal's reason as its code; 404). A schedule's target, anchor or head is refused (`scheduled`, naming the schedule): deleting a head would make the schedule fall back to an archived link. Who refuses a delete is one question, `SessionProtection` (`session_protection.rb`, beside `SessionStores`, which says what a delete removes): every protector in `PROTECTORS` is asked (`hold` for a session, `chain_hold` for a chain, `protected_ids` for retention), schedules the one there is (`Schedules::ProtectionPart`), and the first hold is the refusal (`SessionManager.refuse_protected!`, `DeleteRefused` with the hold's reason and its `schedule_id`). It fails closed: a protector that raises is logged (`protector_failed`) and the error raised, so nothing is deleted; a store that is there but doesn't read (`SessionProtection::Unreadable`) refuses every delete, `protection_unreadable`, "schedules.json is unreadable (…): fix or remove it before deleting sessions" (the delete sheet shows it as the choice's refusal). An archive asks no protector. A user's delete (these three, `revive_previous:` and `refuse_continuing:` on `delete_session`) goes through `SessionChain::Delete.link` for every session, chained or not (*Session chains* → Deleting a link): **its delegates follow one rule** (`SessionManager::DELEGATES`): the stopped ones (archived ones too) go with it, deepest first, and a running one stays with its whole subtree, its file untouched; a stopped delegate with a running child goes and leaves that child without a parent. The delegates that would go bring their own refusals: one that is a schedule's target, anchor or head refuses the delete (`scheduled`, naming the delegate), as does one in a one-turn run, one a worker took after the plan was made (`worker_running`), and their running background tasks (below); their participant grants end with them. The result lists them in `deleted` (the session last) and the running ones with their subtrees in `left_running`; the CLI's line and `/exit --delete` say how many went. It is also refused while a continue of the session, or of the previous link it would bring back, is under way (`continuing`), and deleting a chain's newest link undoes its continue (D2/D5 below), the ids it brought back in `unarchived` and the delegates it gave back in `moved_back`. A previous link brought back is aged for retention from then on (`unarchived_at`) and has no participants (the archive ended them, and an unarchive doesn't bring them back). The scratch cleanup, the empty-session discard, the failed-continue rollback and a schedule's prune delete plainly (`delete_resolved`: they pass neither keyword and take no delegates); the retention sweep removes files directly (`remove_files`). **Background tasks still running:** a user's delete (these three, and `chi sessions delete`) asks first when tasks the deleted sessions started (their `task_create` tasks and the `execute` runs handed over at their limit, read from each session's transcript and `<working_directory>/tmp/tasks/<id>/task.json`: `SessionManager::RunningTasks`) still run: it is refused before anything changes (`tasks_running`), and the CLI's `--stop-tasks`, the web's `stop_tasks=true` (the delete's and the chain delete's query; with `&tasks=<id,id>`, the ones the sheet named, only those: `RunningTasks::Policy.stop(only:)`, see *Deleting a link*) stop them first (`stopped_by_user`, TERM then KILL after 3 s, all at once, about 4 s at most), under the deleting lock, after the starting-marker re-check, so no worker takes the session meanwhile; that last check refuses a task that started since the first (`worker_stopped: true` when the worker was stopped by then). One rule, fail-safe: a task whose pid still leads the group chi started at the start time it recorded is *running*; one whose record has no start time (before 2026-10-09) or whose start time reads nothing now, while its pid leads a group, is *unverified* ("may still be running"); a `task.json` that doesn't read is *unreadable*. All three refuse; a stop signals only the running ones (an unverified pid may belong to another process now) and reports the rest as not stopped, then deletes. A record left marked running whose pid is gone (a crashed worker's) isn't listed. The 409 is `{error: "tasks_running", reason, op: "delete", detail, session_id, tasks: {running, unverified, unreadable}, worker_stopped, stopped_worker, stopped_workers}` (`stopped_worker`: whose worker the delete stopped before the last check refused; `stopped_workers`: every worker the delete stopped), each task `{session_id, id, command}` (`links` too for a chain delete's other links); the 200 gains `tasks_stopped`, `tasks_not_stopped` and `tasks_ended` (empty unless stopped). A session's file gone (its folder left) has no tasks. The retention sweep and scratch cleanup stop verified tasks silently; the empty-session discard, failed-continue rollback and schedule prune leave them running.
|
|
55
59
|
|
|
56
60
|
<a id="archiving-a-session"></a>**Archiving a session:** `chi sessions archive ID...`, `/archive` in a terminal and the Web UI's `archive` go through `SessionManager.archive_session`: it writes `<id>/archived` (`{"archived_at": …}`; not a session.json field, which every save rewrites) for the session and its delegated children. `Session.list` leaves archived sessions out unless `include_archived:`, and everything built on it follows: `chi sessions list` (`--archived` shows them, `[archived]`), the summaries (`--live`, json/tsv, the desktop panel, the agent's `list_sessions`) and the retention prune, which neither deletes nor counts them against `max_count`. `children_of` (max_children, `delegate_result`) still sees them, and `--resume`/`--attach ID`, `chi send`/`chi note ID` reach them as before, except that `chi send` and `chi note` to a link that was continued go to its chain's newest link (*Session chains*). Refused: a turn running in the session or in one of its children (naming the child; 409 `busy` on the web), a prompt queued in `input/` (it would run on the next resume) or a live worker's step-limit question still open, in it or a child (409 `busy` too), a one-turn `chi --non-interactive` run owning it (`owned_by_tui`), a `chi scratch` session (`scratch`). A live idle worker is stopped first, and the marker is written even if it is still shutting down. Input a human typed brings a session back (`{"unarchived_at": …}`): a prompt from the web, an attached terminal or `chi send` (origin `web:*`, `tui:*`, `cli:send`, its own first prompt: `spawn:first`; input naming no sender doesn't), steering merged into a running turn, a `/continue` answer or a question answered (the step-limit question too); a delegate's follow-up, a plugin's turn, a reminder, the idle recap, a note and just opening it don't. A child's input brings only the child back. The retention sweep ages an unarchived session from when it was unarchived, so unarchiving an old session doesn't let the next sweep take it. `/archive` leaves the session first, as `/exit` does, then archives it: in an attached terminal the worker is asked to exit (one that stays up for another UI is stopped by the archive; a running turn, a queued prompt or an open step-limit question refuses it), and an empty session is discarded instead; `chi scratch` refuses it. Typed while a turn runs, `/archive` waits for the turn's end (an attached terminal for the commands queued behind it too) and then archives. `chi sessions unarchive ID...` and the web's `unarchive` bring back the whole family. **Background tasks still running** in the session or a delegate refuse an archive as they refuse a delete (*Deleting a session*: the same rule and listing), before anything changes: 409 `tasks_running` (not `busy`, so an older client doesn't say "a turn is running"), `op: "archive"`. The web's Archive stays one tap (the toast's Undo) when nothing is in the way; its 409 opens the delete sheet in Archive's words (what is hidden, the tasks it stops first, `Stop them and archive`, which sends the tasks it named), and any other refusal is that sheet's "Can't archive … now". The 409 also says `sessions`: how many sessions the archive would hide (it and its delegates, across every project), plus `stopped_workers` (every stopped worker id). The refusal words name one stopped worker as "its worker was stopped" or "9d0e1f2a's worker was stopped", and several as "N workers were stopped: its own, 9d0e1f2a". `chi sessions archive --stop-tasks`, or the archive route's body `{"stop_tasks": true}` (with `"tasks": [ids]` only those; a running one not named refuses, `tasks_running`, nothing archived: up front before any worker is stopped, and again after the workers let go), stops them first: after the tree's live workers were stopped and let go (or the wait ran out: such a worker's own waiter then records the stop from the `stop_requested_by` flag on disk), and before the marker; the 200 gains `tasks_stopped`, `tasks_not_stopped` and `tasks_ended`. An archive takes no lock for it. Undo (unarchive) doesn't restart them. Web routes: `POST /api/sessions/:id/archive` (200 `{status, session_id, archived, stopped, discarded}`, ids) and `POST /api/sessions/:id/unarchive` (200 `{status, session_id, unarchived}`). The session hub and `GET /api/sessions` keep archived sessions, `archived: true` in their summaries: the page leaves them out of the strip, its count and the list at render, and the `archived` toggle beside the all-sessions search shows them, dimmed with an `archived` badge. The info bar marks a session whose live worker runs an older chi than the newest installed (`worker_version` in its summary): `chi 0.18.1 · Restart`, which asks to confirm and calls `POST /api/sessions/:id/restart` (a refusal's reason shows in a toast); a worker from before restarts shows `chi sessions stop ID` instead. The info bar reads `continue → · archive · stop · delete` (`unarchive` on an archived one; no `continue →` on a link continued already, see *Session chains*; `continue →` is a plain button like `archive`, in the accent on an archived session, where it is the thing to do); archiving the open session stays on it, with an Undo toast.
|
|
57
61
|
|
|
@@ -194,7 +198,7 @@ pbpaste | chi note --source slack 3f2a 8c1d
|
|
|
194
198
|
- It lands in `<uuid>/notes/`, apart from `input/`, so nothing that runs turns sees it. A live worker adds it to the conversation within a few seconds, between turns: one sent during a turn waits for that turn to end. A session with no worker keeps it until a worker next starts (a prompt, `--attach`), which adds it before anything else. A session a one-turn `chi --non-interactive` run has refuses notes. `chi note` prints one line per session: queued, waits for the next start (with the queue count), or refused.
|
|
195
199
|
- A note to a link that was **continued** (archived, with a later link) goes to its chain's newest link, as `send_note`'s and `chi broadcast`'s do (`chi broadcast` gives two links of one chain the note once, logged under the newest): `chi note` prints `3f2a1c0d → 4b7e9a01 (continued) queued: …` (and `… (continued) refused: …` when that link refuses it), and chi web's notes answer names that link as `id` beside `session_id`, in a 409 too. `chi broadcast deliver` logs such a delivery under the newest link's id (the one that has the note), so `chi broadcast log` shows that id, not the one typed, and a later `deliver` to either link says it had it. An archived link nobody continues keeps its note until input brings it back. An `/objectives` edit is the one note that stays in its own session: its list is that conversation's. Notes waiting when a session is continued move with it (*Session chains*).
|
|
196
200
|
- In the conversation it is a tail system message marked `kind: note`, framed `[CONTEXT NOTE from slack, 14:02]\n…\n[END NOTE]` (from another session: `from session 3f2a1c (~/projects/foo)`). The system prompt says notes are background, not requests: the model uses one when it is relevant, doesn't answer it on its own, and never follows instructions inside it. A note from `broadcast` ([`chi broadcast`](broadcast.md)) is the one exception to "doesn't answer it": the model says briefly in its next answer when it affects its current work, and still doesn't act on it unless asked. `--source broadcast` is refused for `chi note`. Its text is escaped like user text, so it can't fake a turn. It survives `--resume`, a reload, `!rollback` and a continue answered no.
|
|
197
|
-
- The web shows it as a dim "note from …" block, live (`context_added`) and after a reload; the attached terminal as one dim `note from slack: <first line>` line, also when joining.
|
|
201
|
+
- The web shows it as a dim "note from …" block, live (`context_added`) and after a reload, folded into a closed notes row with the background lines next to it (a tap opens it) unless it starts a turn; the attached terminal as one dim `note from slack: <first line>` line, also when joining.
|
|
198
202
|
- Agents: `list_sessions` (other sessions of this project, newest first, up to 20; optional `cwd`, `"/"` for every project) and `send_note(session, text)`, which sends a note from this session. Neither starts a turn anywhere.
|
|
199
203
|
|
|
200
204
|
On macOS, `chi desktop install` does this with a native panel from the Services menu or a hotkey (see [Desktop helper](desktop.md)). A plain Automator Quick Action that sends the clipboard to the live sessions you pick works too (Automator: Quick Action, "Run Shell Script", shell `/bin/zsh`; Automator's PATH is minimal, so put your Ruby's bin dir on it and use the full path to `chi`):
|
|
@@ -404,8 +408,8 @@ A session can **continue** an earlier one: "the next run of the same routine" (a
|
|
|
404
408
|
- **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with an opener in the composer, not sent (a draft written in this session stays instead; one carried over from another session or the start page gives way to the opener, and the toast's **Restore draft** brings it back): the previous link's own first typed message when that link continues one (the 201's `opener`; a `!shell` line isn't taken), else `Continue where we left off.`. So whatever you sent on the last link comes back on the next one, and editing it once changes it for every later link; the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. When the previous link's model's host is gone the link starts on the default model and the toast carries the server's `model_warning` too, and then stays until closed. A fresh link (one with no turn yet, however it was made: `continue →`, `chi send --new --continues`, a reload) shows the model picker in its composer with the link's model, until its first turn starts (a failed or canceled first turn ends it too); a pick runs `/model <name>` in the link (a command bubble; the info bar follows) and changes neither the start page's remembered model nor its Recent list, and a Send right after it waits for the `/model` to be taken. A link a one-turn `chi --non-interactive` run has, or one continued already, shows none. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `in use by a one-turn chi --non-interactive run or an older chi's terminal; let it finish`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its id, its full start (`2026-10-10 14:32`) and its preview in the tooltip; a neighbour that started on the open link's own day shows its time instead (`← 09:12`, `14:32 →`). A link made by `continue →` inherits the previous link's preview (and its title, if it has one) when it is created, so its card keeps its chain's title whatever opener it is sent, and its top bar and browser tab show its card's title. A link with a recap of its own reads its auto title, else its recap's first sentence, instead (a link without one reads its chain's name, and a first link's recap names its chain). A link whose title is the opener and nothing else (a `chi send --new --continues` link whose first message is `Continue where we left off.`) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ #N` chip (`#N of M` when later links aren't listed; its tooltip `Session chain: link N of M`) opens a popover of the other links, newest first (`#N`, its date, with its time (`2026-10-17 14:32`) when another link of the chain started the same day, its own title when it differs from the card's (a link inherits its chain's, so mostly it doesn't), else its recap's first sentence, else its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or the `archived` toggle is on: every link is a card of its own then, its chip `#N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
|
|
405
409
|
- **CLI:** `chi send --new --continues (ID|PREFIX|last:ID) [--model M] [-m TEXT]` (see *Starting a session*).
|
|
406
410
|
- **Which link:** an id, a unique prefix, or `last:<id or prefix>`, the latest link of the chain that session is in. It walks the links that still exist: a deleted link in the middle (`chi sessions delete`, the retention sweep of an unarchived one) ends the walk before it, so `last:` of an earlier link then names that earlier link, and continuing it starts a second line beside the links after the gap; name a link after the gap instead. A trigger names the chain this way: a person's message to an archived link that nobody continued brings it back (a human's input), it doesn't continue the chain; an unattended sender's is refused (*Who may wake a session*). That is the rule: `chi send` and a note go to the chain's newest link (*Sending a message*, *Context notes*); the web composer, a participant's turn and `delegate(session:)` go to the link they name. One walker answers every one of these (`SessionChain::Links`: one session listing, archive flags read once; the earliest created successor wins a fork a hand edit made, a loop ends where it would repeat), with two rules on it, not unified on purpose: `last:` and a schedule take the chain's **end** (`Links#latest`: a continue refuses a link continued already, and a schedule never un-archives a chain you retired), `chi send` and a note the **first link not archived** (`Links#first_live`: a person's input goes where the chain is live, and brings back an archived end). A chain pruned by a schedule keeps its `anchor`: the kept window's oldest link still names a link that is gone, so the walk simply stops there; the page's chip counts from the surviving root (pruning renumbers the links) and its popover says `earlier links pruned` where the walk stops, rather than linking to a deleted session.
|
|
407
|
-
- **Deleting a link** (`SessionChain::Delete`; the CLI, the web and `/exit --delete`): a link of a chain is deleted alone by default, and what follows depends on where it is. **The newest link** (nobody continues it, it isn't archived itself, the link before it is archived) undoes its continue: the delegates the continue moved go back to the previous link, finished ones too (`continued_from.json`'s `moved_ids`, still under the link; without the record, its children whose `parent.json` says they came from the previous link), each with a note saying the link was deleted; every note waiting in the link but the continue's own goes back too (`NoteMove.give_back`); then the previous link and what the continue archived with it come back to the lists (without the record, the previous link alone). The previous link is **not started**: reports a moved-back delegate left wait for its next start. What dies with the link: its turns, context sources, objectives edits, session approvals and participant grants (the previous link kept its own copies). Every refusal comes before anything goes: the link's delegates that would go are checked too (a schedule on one
|
|
408
|
-
**The whole chain** (`chi sessions delete --chain`, `DELETE /api/sessions/:id/chain`, `SessionManager.delete_chain`): every link reachable from this one on its branch, newest first, each with its delegates by the same rule. Refused before anything goes when a schedule is on the chain (`chain_scheduled`) or on a delegate that would go (`scheduled`), a link or such a delegate is in a one-turn run, a continue of a link is under way (`continuing`), without `force` a link has a worker, or a link's worker outlives the stop's wait: every link is checked and stopped before the first is deleted, and each then goes under the owner locks of it and its delegates. A chain with a gap before this link reaches only the part after the gap: the earlier links stay archived (`cut_off: true`). A link refused part-way (a worker that took it after its stop) leaves it, its delegates and the earlier part of the chain whole, its new end back in the lists, and the result lists what was left.
|
|
411
|
+
- **Deleting a link** (`SessionChain::Delete`; the CLI, the web and `/exit --delete`): a link of a chain is deleted alone by default, and what follows depends on where it is. **The newest link** (nobody continues it, it isn't archived itself, the link before it is archived) undoes its continue: the delegates the continue moved go back to the previous link, finished ones too (`continued_from.json`'s `moved_ids`, still under the link; without the record, its children whose `parent.json` says they came from the previous link), each with a note saying the link was deleted; every note waiting in the link but the continue's own goes back too (`NoteMove.give_back`); then the previous link and what the continue archived with it come back to the lists (without the record, the previous link alone). The previous link is **not started**: reports a moved-back delegate left wait for its next start. What dies with the link: its turns, context sources, objectives edits, session approvals and participant grants (the previous link kept its own copies). Every refusal comes before anything goes: the link's delegates that would go are checked too (a schedule on one through `SessionProtection.hold`, a one-turn run), and they and the link are removed (and the undo runs) only under their `owner.lock`s (kind deleting, taken without waiting, so a worker that took one refuses it); a moved delegate that can't go back (`ChildMove.unmovable`: an older chi's worker, a one-turn run) refuses it (`delegate_unmovable`, naming it), as does a worker that took the link after the stop. Deleting the links one after another undoes each continue by its own record. **A middle link** splits the chain (the earlier links stay archived, the later ones go on as their own chain); nothing is undone or re-linked. A link whose chain is all archived stays archived around the gap. **The link's own delegates** (any position) follow one rule, `SessionManager::DELEGATES` (`SessionManager::DelegateRule`; one shared preview row snapshot): a running one (a worker owns it or is starting for it, a one-turn run; a saved `running` with no worker is a crashed run, and goes) is left running with its whole subtree, its file untouched (its parent's id names a deleted session; its reports are refused as for any gone parent); every other node under the link goes, deepest first, before the link. A session in no chain (a link alone past a gap too) is a link with nothing to undo: its delegates follow the same rule (*Deleting a session*). **The web asks first**: chi web's delete sheet reads `GET /api/sessions/:id/delete_plan` (`:owner`; no query or body; no-store) for any session, `SessionChain::Delete::Preview` over the same `LinkPlan`/`ChainPlan` and checks the delete runs (`check_link!`, `check_chain!`): the link's place in the chain, what comes back and goes for each choice, and each choice's refusal now (a schedule on the chain, the link or a delegate that would go, a continue under way, a one-turn run, a moved delegate that can't go back and whether the page can stop it). A session in no chain answers `{chained: false, session_id, link}`, the same `link` a chained one gets (`previous_id` null, `earlier`/`later` 0, `next_id` null); an older page reads only `chained`. Each choice (`link`, `chain`) also carries `delegates` (`{delete: [ids], leave: [{id, running}]}`; `running` false for a stopped session left under a running delegate, beside the counts `deletes` and `left_running`), `tasks` (`{running, unverified, unreadable}`: `RunningTasks.of` the ids the choice deletes) and `worker` (a link's: `"turn"` when a worker owns it and a turn runs, `"idle"` when a worker owns it or is starting, null; a chain's `{idle, turn}` counts over its links). No titles: the page names each id from its own list. One shared session-row snapshot serves the link and chain choices; Links lists on its own, and a folder whose session file is gone answers too (the delete still takes it). Each call read-only checks each link's continue lock (a session in no chain too), and writes nothing else but the listing's own repair of an interrupted continue; an unknown id is the usual 404. chi web lists `delete_plan_all` in `/api/info`'s features (`Web::App::DELETE_PLAN_FEATURE`). **The tap stops only what the sheet named**: whenever the choice lists any task, the page sends `stop_tasks=true&tasks=<id,id>`, the choice's running ids (`tasks=` when it has only unverified or unreadable records, which a stop never signals, so such a session can still be deleted); archive's sheet sends `{"stop_tasks": true, "tasks": [ids]}` in its body. `tasks` works only with `stop_tasks`; without it, it is ignored, and `stop_tasks` without `tasks` (the CLI's `--stop-tasks`, an older page) takes every running task the operation can stop. A running task not named refuses (`tasks_running`), and the sheet reads the plan again and shows it with "changed; check again". A chain stops link by link: a link refused that way leaves it and the earlier links whole. The moved count is each moved delegate with its subtree (they come back with it), and a `delegate_unmovable` 409 says `stoppable` itself. Each choice carries a `digest` (`SessionChain::Delete.digest`: the sorted ids it deletes, leaves, revives and moves back); the sheet's DELETE sends it as `expect=`, and the delete compares it with the plan it runs (a link's under its holds, as `delete_link` starts; the chain's before its checks) and refuses `plan_changed` (409) before anything changes; a session in no chain is compared the same way (a sheet shown for a link whose chain is gone since deletes when its ids still match). Without `expect` (the CLI, an older page) it deletes as it plans then.
|
|
412
|
+
**The whole chain** (`chi sessions delete --chain`, `DELETE /api/sessions/:id/chain`, `SessionManager.delete_chain`): every link reachable from this one on its branch, newest first, each with its delegates by the same rule. Refused before anything goes when a schedule is on the chain (`chain_scheduled`, `SessionProtection.chain_hold`) or on a delegate that would go (`scheduled`), a link or such a delegate is in a one-turn run, a continue of a link is under way (`continuing`), without `force` a link has a worker, or a link's worker outlives the stop's wait: every link is checked and stopped before the first is deleted, and each then goes under the owner locks of it and its delegates. A chain with a gap before this link reaches only the part after the gap: the earlier links stay archived (`cut_off: true`). A link refused part-way (a worker that took it after its stop) leaves it, its delegates and the earlier part of the chain whole, its new end back in the lists, and the result lists what was left.
|
|
409
413
|
|
|
410
414
|
## Schedules
|
|
411
415
|
|
data/docs/sub-agent.md
CHANGED
|
@@ -26,15 +26,15 @@ The other direction, chi sending a part of its work to a Claude Code session
|
|
|
26
26
|
you already work with (to validate, as context, or with a question), is the
|
|
27
27
|
[claude-peer bundle](bundles.md#the-claude-peer-bundle): Claude pairs with the
|
|
28
28
|
chi session, chi's `claude_send` tool or `/claude` writes to Claude's inbox,
|
|
29
|
-
and Claude's answer comes back
|
|
30
|
-
|
|
31
|
-
chi
|
|
29
|
+
and Claude's answer comes back with `chi peer say` as a message in the
|
|
30
|
+
session's mailbox, its whole text in a note of chi's conversation, and the
|
|
31
|
+
say prints what chi did with it (Claude can also tell chi something unasked,
|
|
32
|
+
which wakes chi under the same count). The
|
|
32
33
|
[codex-peer bundle](bundles.md#the-codex-peer-bundle) does the same with a
|
|
33
34
|
Codex CLI session (`codex_send`, `/codex`, through `codex queue`). The peer's
|
|
34
35
|
answers wake chi in a short loop (fix or disagree, send again) until it says
|
|
35
36
|
`VERDICT OK` (one closing wake: chi carries on or tells you what was agreed)
|
|
36
|
-
or after `
|
|
37
|
-
sources](context.md#peer-sources-the-peer-loop).
|
|
37
|
+
or after `peer.turns` turns: [peers.md](peers.md).
|
|
38
38
|
|
|
39
39
|
A client with no chi of its own (an iOS Shortcut, a script) can do the same
|
|
40
40
|
over HTTP: one `POST …/ask` to chi web, then a wait token until the answer
|
data/docs/testing.md
CHANGED
|
@@ -683,7 +683,7 @@ that reopens the namespace and nothing else does (then firing the autoload loads
|
|
|
683
683
|
four kinds: a part naming its host's value constants (`Samagotchi::Engine::[A-Z][A-Z_]*` in
|
|
684
684
|
`engine/*.rb`: the host requires the part, so a require back is a cycle; the glob leaves classes a part
|
|
685
685
|
names from elsewhere checked), one-off host pairs (`ToolRun` in `tool_response.rb`), the namespace
|
|
686
|
-
autoloads that load whole (`SessionManager`, `Objectives`, `Config`), and `Plugin::Http`'s (its base file
|
|
686
|
+
autoloads that load whole (`SessionManager`, `Objectives`, `Config`, `Schedules`), and `Plugin::Http`'s (its base file
|
|
687
687
|
loads the reopening file only inside a method, and that file requires the base file first). The summary counts the entries that
|
|
688
688
|
matched and those that match nothing: delete a stale one.
|
|
689
689
|
|
data/lib/samagotchi/bridge.rb
CHANGED
|
@@ -44,6 +44,7 @@ require_relative "working_set"
|
|
|
44
44
|
require_relative "relay_verifier"
|
|
45
45
|
require_relative "relay_watcher"
|
|
46
46
|
require_relative "reply_wait"
|
|
47
|
+
require_relative "peer_mailbox"
|
|
47
48
|
require_relative "task_transcript"
|
|
48
49
|
require_relative "tools/task_runtime"
|
|
49
50
|
|
|
@@ -796,8 +797,7 @@ module Samagotchi
|
|
|
796
797
|
# participant_revise: a participant's Revise draft is kept, and the
|
|
797
798
|
# Engine checks it at the stamp (ParticipantRevise): what chi web needs
|
|
798
799
|
# to pass one on (ReviseAnchor::PARTICIPANT_FEATURE).
|
|
799
|
-
# activity: GET /activity answers with Worker#activity_snapshot
|
|
800
|
-
# `chi schedule tick` can ask a live worker what it is busy with.
|
|
800
|
+
# activity: GET /activity answers with Worker#activity_snapshot (chi schedule tick asks a live worker's).
|
|
801
801
|
# participant_client_id: it reads a participant's client id as
|
|
802
802
|
# participant:<id>; chi web sends a worker without it review:<id>
|
|
803
803
|
# (Delivery::PARTICIPANT_ID_FEATURE).
|
|
@@ -810,7 +810,7 @@ module Samagotchi
|
|
|
810
810
|
WorkerLink::ACTIVITY_FEATURE, ObjectivesTrack::FEATURE, Delivery::OWN_TURN_STEER_FEATURE,
|
|
811
811
|
Delivery::CANCEL_TURN_ID_FEATURE, ReviseAnchor::PARTICIPANT_FEATURE, Delivery::PARTICIPANT_ID_FEATURE,
|
|
812
812
|
WorkingSet::ITEM_FEATURE, BlockFix::FEATURE, Delivery::AGENT_FEATURE,
|
|
813
|
-
Delivery::ASK_FEATURE, ReplyFor::FEATURE].freeze
|
|
813
|
+
Delivery::ASK_FEATURE, ReplyFor::FEATURE, PeerMailbox::FEATURE].freeze
|
|
814
814
|
|
|
815
815
|
# The routes, by method and what follows /session/:id/: a handler takes
|
|
816
816
|
# the session id and the request body and returns [headers, status, body].
|
|
@@ -24,7 +24,8 @@ module Samagotchi
|
|
|
24
24
|
# Resolved on use: Sessions alone loads ~150 files.
|
|
25
25
|
MEMBERS = {
|
|
26
26
|
"Plugin::Api" => { ctx: "Plugin::Context" },
|
|
27
|
-
"Plugin::Context" => { sessions: "Plugin::Sessions", context: "Plugin::AttachedContext",
|
|
27
|
+
"Plugin::Context" => { sessions: "Plugin::Sessions", context: "Plugin::AttachedContext", peers: "Plugin::Peers",
|
|
28
|
+
http: "Plugin::Http",
|
|
28
29
|
judgments: "Plugin::Judgments", cost: "SessionMetrics::Cost", usage: "SessionMetrics::Usage",
|
|
29
30
|
log: "Plugin::Context::Logger", secrets: "Plugin::Secrets" }
|
|
30
31
|
}.freeze
|
|
@@ -464,7 +464,7 @@ module Samagotchi
|
|
|
464
464
|
end
|
|
465
465
|
end
|
|
466
466
|
{ "init" => registered.inits, "toolkit" => registered.toolkits, "tool source" => registered.tool_sources,
|
|
467
|
-
"peer
|
|
467
|
+
"peer" => registered.peers, "prompt section" => registered.prompt_sections }.each do |what, names|
|
|
468
468
|
names.each { |name| add(:info, :registered, plugin, "#{what} #{name}") }
|
|
469
469
|
end
|
|
470
470
|
end
|