samagotchi 0.183.0 → 0.184.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 +40 -1
- data/docs/architecture.md +11 -10
- data/docs/bundles.md +1 -1
- data/docs/configuration.md +2 -1
- data/docs/internals/bridge.md +1 -1
- data/docs/internals/bundles.md +6 -2
- data/docs/internals/engine.md +2 -1
- data/docs/internals/participants.md +1 -1
- data/docs/internals/prompt-caching.md +8 -1
- data/docs/internals/remote-sessions.md +19 -3
- data/docs/internals/web-frontend.md +15 -10
- data/docs/internals/web-push.md +11 -0
- data/docs/internals/working-set.md +238 -6
- data/docs/mcp-server.md +5 -1
- data/docs/memory.md +2 -1
- data/docs/plugins.md +6 -6
- data/docs/scheduling.md +14 -0
- data/docs/sessions.md +1 -1
- data/docs/thin-clients.md +29 -10
- data/lib/samagotchi/bridge_client.rb +12 -4
- data/lib/samagotchi/bundle_command/check.rb +20 -2
- data/lib/samagotchi/bundle_manifest.rb +5 -1
- data/lib/samagotchi/bundles/mcp/http_client.rb +79 -54
- data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/self_map.md +7 -2
- data/lib/samagotchi/engine/session.rb +14 -6
- data/lib/samagotchi/engine/turn_helpers.rb +4 -3
- data/lib/samagotchi/mcp_server/http.rb +3 -3
- data/lib/samagotchi/mcp_server/protocol.rb +23 -4
- data/lib/samagotchi/mcp_server/stdio.rb +1 -0
- data/lib/samagotchi/mcp_server/tools.rb +2 -1
- data/lib/samagotchi/model_notes.rb +34 -12
- data/lib/samagotchi/prompt_files.rb +11 -4
- data/lib/samagotchi/prompt_layout.rb +88 -0
- data/lib/samagotchi/prompt_part.rb +82 -20
- data/lib/samagotchi/reply_wait.rb +6 -3
- data/lib/samagotchi/schedule_command.rb +18 -4
- data/lib/samagotchi/schedules.rb +40 -8
- data/lib/samagotchi/session_access/ask.rb +53 -12
- data/lib/samagotchi/session_access/exchange.rb +5 -2
- data/lib/samagotchi/session_access/local.rb +11 -2
- data/lib/samagotchi/session_inbox.rb +15 -0
- data/lib/samagotchi/session_manager/delivery.rb +8 -4
- data/lib/samagotchi/system_prompt.rb +196 -161
- data/lib/samagotchi/tools/memory.rb +11 -3
- data/lib/samagotchi/turn_stages/warmup.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +1 -2
- data/lib/samagotchi/web/ask_routes.rb +89 -19
- data/lib/samagotchi/web/mcp_route.rb +7 -4
- data/lib/samagotchi/web/public/delete_sheet.js +20 -18
- data/lib/samagotchi/web/public/removal_sheet_model.js +3 -4
- data/lib/samagotchi/web/public/running_tasks.js +0 -16
- data/lib/samagotchi/web/public/session_actions.js +0 -9
- data/lib/samagotchi/web/public/working_set_view.js +167 -21
- data/lib/samagotchi/web/public/ws_part_peek.js +277 -0
- data/lib/samagotchi/web/public/ws_peek.js +3 -1
- data/lib/samagotchi/web/public/ws_preview.css +30 -0
- data/lib/samagotchi/web/public/ws_reader.js +7 -3
- data/lib/samagotchi/web/public/ws_sections.js +37 -7
- data/lib/samagotchi/web/push/notifier.rb +33 -6
- data/lib/samagotchi/web/server.rb +1 -1
- data/lib/samagotchi/web/session_hub.rb +26 -4
- data/lib/samagotchi/web/working_set_routes.rb +93 -5
- data/lib/samagotchi/worker_link.rb +2 -2
- data/lib/samagotchi/working_set.rb +162 -90
- data/lib/samagotchi/working_set_locator.rb +221 -0
- data/lib/samagotchi/working_set_own_changes.rb +221 -0
- data/lib/samagotchi/working_set_part.rb +281 -0
- metadata +6 -1
|
@@ -43,6 +43,23 @@ else that changes it does: a later `execute` (`sed`, `git checkout`), the user's
|
|
|
43
43
|
edit that changed the file anyway leaves the earlier stamp, so the file shows stale. On a filesystem with 1 s mtimes a
|
|
44
44
|
same-size edit in the same second goes unseen (APFS keeps nanoseconds).
|
|
45
45
|
|
|
46
|
+
A memory item follows chi's own changes too (`WorkingSet.build` passes the runs it already walked to
|
|
47
|
+
`WorkingSet::OwnChanges.from_runs`: no second walk; built only when a memory item needs it). A memory whose latest run
|
|
48
|
+
is a `memory_read` and whose stamped files differ stays `live` when every file that differs (the entry, its overlay)
|
|
49
|
+
holds chi's own later change: an `edit` or `write` of the file (its stamp), or a `memory_write` (by content, since
|
|
50
|
+
`memory_write` leaves no stamp). That is the heartbeat case, a memory read once and then edited all session. It runs
|
|
51
|
+
only after `memory_differs`' early answers: a name that now resolves to another file or overlay (a project `x` chi
|
|
52
|
+
wrote now shadowing the read's system `x`) or is gone stays `stale`, conservative. A memory whose latest run is a
|
|
53
|
+
`memory_write` is `stale` when the file it wrote (`<scope dir>/<name>.md`: system from `root`, project from the item's
|
|
54
|
+
read stamp's `project_dir`; a project memory only written has none and stays `live`) no longer holds chi's latest own
|
|
55
|
+
change of it (the write's content, or a later `edit`/`write` of the file by its stamp): one you edit after chi's write. A remove, an overlay write or a description-only write keeps today's `live`. Only a path
|
|
56
|
+
`MemoryGuard.memory_paths?` lets through is read: a stamp's file outside the memories folder counts as no own change
|
|
57
|
+
(stale, as before), never read. Cost in the worker: once any memory item's latest run is a `memory_write` (so every step
|
|
58
|
+
after a session's first one) or a memory item is found stale, one pass over the runs already in memory, testing the tool
|
|
59
|
+
name before anything else (about 0.1 ms at 350 runs on the Studio; testing `failed?` first, which copies each output,
|
|
60
|
+
cost about 1.5 ms); a stat per memory item already found stale, a `File.binread` per memory item whose latest run is a
|
|
61
|
+
`memory_write`.
|
|
62
|
+
|
|
46
63
|
## The projection: `WorkingSet.build`
|
|
47
64
|
|
|
48
65
|
`Samagotchi::WorkingSet.build(conversation, cwd:, strategy:, stat: File.method(:stat), pins: [])` (`lib/samagotchi/working_set.rb`)
|
|
@@ -246,7 +263,8 @@ projection), on both loops. It costs one model step; a model may skip it (the no
|
|
|
246
263
|
directory; a memory name `memory_read` rejects or that neither scope holds), an item holding the user's drop
|
|
247
264
|
(`undrop_first`: undrop brings it back without a step), one already in the system prompt and with no working-set
|
|
248
265
|
output (`in_prompt`: nothing to add; matched by name and scope, `Tools::MemoryRead.prompt_memory?` over
|
|
249
|
-
`Engine#prompt_memories`, a bare name or an unscoped prompt entry by name only), and one the model has whole (`already_sent`: live, a read of it sent
|
|
266
|
+
`Engine#prompt_memories`, a bare name or an unscoped prompt entry by name only), and one the model has whole (`already_sent`: live, a read of it sent; a memory chi read and then changed itself
|
|
267
|
+
is live, so its add is refused as a file chi edited is). The
|
|
250
268
|
prompt-only refusal doesn't apply when the set holds a read of that memory: a stale or forgotten item may still be
|
|
251
269
|
added as the web row's `refresh`. **`unadd`** takes a pending add back (free); without one it is refused
|
|
252
270
|
(`not_added`).
|
|
@@ -297,7 +315,9 @@ now (`WorkingSet::Now`: `text`, `diff`, `gone`): each name that read read, from
|
|
|
297
315
|
overlay stamped with it appended as `Tools::MemoryRead.call` appends it (`Model-specific guidance (<key>):`, the key
|
|
298
316
|
off the overlay's file name), and a missing name's `Error:` tail kept; `diff` is `TextDiff.unified` of what the read
|
|
299
317
|
sent against that (`EditPreview`'s shape, so `diff_view.js` draws it; an empty `text` is "no change"). `gone` when a
|
|
300
|
-
file is; nil without a stamp.
|
|
318
|
+
file is; nil without a stamp. Each name is a `WorkingSet::Locator` of origin `:run` ([Prompt parts as sent](#prompt-parts-as-sent), The locator):
|
|
319
|
+
every name is resolved first (refused: nil; no entry answers: gone), then read, and `memory_now` keeps the join and
|
|
320
|
+
the diff.
|
|
301
321
|
|
|
302
322
|
**The route.** `GET /api/sessions/:id/working_set/item?kind=&key=` (`WorkingSetRoutes#handle_working_set_item`,
|
|
303
323
|
`:owner, :session`: a participant gets 403 from `not_permitted_for`) answers `timeline.to_h`, and with `&now=1` for a
|
|
@@ -388,13 +408,14 @@ chi's head, in three sections, drawn as Read, Conversation, From the start (ever
|
|
|
388
408
|
server, `overlay`); a scope either side lacks (an older worker's part or item, an item the server hasn't stamped)
|
|
389
409
|
matches by name alone, as before scopes. So a project `x` read beside a system `x` in the prompt is two rows: the
|
|
390
410
|
read stays in Read as a plain read (not "prompt", never held twice), and the part's own row gets the key `x@system`
|
|
391
|
-
(no collision with the read's `x`), its words its scope ("preloaded · system") and, like identity's, no actions
|
|
392
|
-
peek. A note and a preload of one name and scope stay one row with both sizes; of two scopes, two rows. The start
|
|
411
|
+
(no collision with the read's `x`), its words its scope ("preloaded · system") and, like identity's, no actions;
|
|
412
|
+
its ▸ is the prompt peek ([Prompt parts as sent](#prompt-parts-as-sent)). A note and a preload of one name and scope stay one row with both sizes; of two scopes, two rows. The start
|
|
393
413
|
section tracks the items it shows by identity, not by key. It keeps the memory row's peek, state and the drop/pin rules of a preloaded memory (not
|
|
394
414
|
droppable or pinnable until read). Its tokens are the part's, plus `+X` for the read's (the item's server tokens: a
|
|
395
415
|
preloaded row carries none of its own, so the two never double-count). Other parts are read-only `part` rows: a
|
|
396
|
-
label, a sub (the tools part's "N declared"; dropped on a phone), `~tokens`, no actions,
|
|
397
|
-
them.
|
|
416
|
+
label, a sub (the tools part's "N declared"; dropped on a phone), `~tokens`, no actions, and a ▸ that opens what chi
|
|
417
|
+
was sent ([Prompt parts as sent](#prompt-parts-as-sent)); a turn lens dims them. Each start row carries the keys of
|
|
418
|
+
the parts it stands for (`partKeys`, `partSizes`: a note also preloaded has two).
|
|
398
419
|
- **Read in this session** (`read`): today's files / memories / urls folds (`bodySections`), minus the memories the
|
|
399
420
|
start section shows. Its meta: held (not struck) and out (forgotten or dropped); its tokens the held items'.
|
|
400
421
|
- **Conversation** (`talk`): one row at section level, "Conversation · N turns ~X" (`headSections` still returns the
|
|
@@ -484,3 +505,214 @@ The secondary text and the rail's rule read through their own tokens, a step bri
|
|
|
484
505
|
base tokens on the light one: `--ws-faint` (the counts, the ops text, step tags; `--text-muted` on dark, `--text-faint`
|
|
485
506
|
on light), `--ws-muted` (the rail's head, the list's `files · n` rows, the drop/pin buttons; `--text-3` / `--text-muted`),
|
|
486
507
|
`--ws-rule` (the rail's left rule; `--border-strong` / `--border`) and `--ws-act-border` (the buttons' border).
|
|
508
|
+
|
|
509
|
+
## Prompt parts as sent
|
|
510
|
+
|
|
511
|
+
Every "From the start" row opens what chi was sent for its part: a slice of the prompt the session already keeps,
|
|
512
|
+
never a copy.
|
|
513
|
+
|
|
514
|
+
**The head and the places.** `Engine#turn_messages` puts the built prompt at `messages[0]`
|
|
515
|
+
(`ContextNote.with_system_head`: `{role: "system", content:}` with no `kind`, `ContextNote.system_head?`) and
|
|
516
|
+
`end_turn` saves it with the turn. Each `prompt_parts` entry says where it sits in that prompt (`PromptPart`, built by
|
|
517
|
+
`PromptLayout` beside the build): `at` (where its lead starts), `len` (lead included), `lead` (the length of what chi
|
|
518
|
+
adds before the item's own text: the identity line, a note's `## name`, the first note of a scope its heading, a
|
|
519
|
+
preload's "this memory is required … memory name: x" line, a file's header, a plugin's `From b (n):`, an index's
|
|
520
|
+
`Project memories:`; none for base, the kit and the volatile lines), so the slice is `head[at, len]` and the item's
|
|
521
|
+
own text `head[at + lead, len - lead]`. Joins between items fall in no span. `chars` is not `len`: a section's first
|
|
522
|
+
part is charged its joins. `digest` is 12 hex of SHA-256 over the item's own text, `head` 16 hex of the whole prompt
|
|
523
|
+
(the same on every part of a build). The tools part has a place only where the declarations are in the prompt: inside
|
|
524
|
+
the base text on a native non-Gemma profile (base's slice leaves them out, and so does its digest), after the
|
|
525
|
+
rstripped prompt on Gemma (an item running into the rstrip is cut at it); on a chat host they are a request field and
|
|
526
|
+
the part has none. `params` say how to fetch an item again: a memory's `requested_scope` (nil for a bare name),
|
|
527
|
+
`model_key`, `fallback_model_key`, `project_dir`, `system_dir` as the build read them; a file's `path`; the tools'
|
|
528
|
+
`[{name, chars}]` (chat: each schema's JSON; native Gemma declarations: each one's text; Qwen's one JSON list gives no
|
|
529
|
+
per-tool length, so names only). The items are recorded where the builders render them
|
|
530
|
+
(`SystemPrompt::Section#items`), so a place can't drift from the bytes. Cost: about 80 bytes a part plus 100–200 for
|
|
531
|
+
a fetchable part's params, 2–3 KB a session, in the file, every snapshot, reset frame and owner show; one SHA-256 of
|
|
532
|
+
the prompt and one per item per changed build.
|
|
533
|
+
|
|
534
|
+
**The key.** A part is named from the parts list alone: `PromptPart.keys` (`kind:ref`, the label without a ref,
|
|
535
|
+
`@scope` when it has one, `#n` for the nth repeat: a duplicate preload is `preloads:x#2`); `ws_sections.js startRows`
|
|
536
|
+
has the twin, both held to `spec/shared/prompt_part_keys.json`.
|
|
537
|
+
|
|
538
|
+
**The route.** `GET /api/sessions/:id/working_set/part?key=` (`WorkingSetRoutes#handle_working_set_part`, `:owner,
|
|
539
|
+
:session`: a participant gets 403, and `Web::ParticipantShow` sends no parts) reads the parts and `messages[0]` from
|
|
540
|
+
one source: a live worker's snapshot frame (`session_state_snapshot.prompt_parts`, `snapshot.messages`), else the
|
|
541
|
+
session file. No Bridge route, no worker feature: one session-file parse. `WorkingSetPart.answer` then: tools always
|
|
542
|
+
answer `{part, tools}` (names and sizes, saved with the part); otherwise case C's table, the first that holds winning,
|
|
543
|
+
its words in `WorkingSetPart::WORDS` (the page shows them as given, `note`, with a `reason`):
|
|
544
|
+
|
|
545
|
+
| # | Condition | `reason` | Source text under it? |
|
|
546
|
+
|---|---|---|---|
|
|
547
|
+
| 1 | the part has no `at`, a live worker of an older chi (its snapshot's `chi_version`; none said: older) | `older_worker` | no |
|
|
548
|
+
| 2 | the part has no `at`, no live worker or one of this chi (a fresh worker keeps the file's parts until a turn) | `older_chi` | no |
|
|
549
|
+
| 3 | `messages[0]` is not a system head | `no_prompt` | no |
|
|
550
|
+
| 4 | the head's digest differs from the part's `head`, a turn runs | `running` (`changed`) | yes, a fetchable part |
|
|
551
|
+
| 5 | the head's digest differs, idle (`!rollback`, a failed turn's old head, an older chi's run) | `idle` (`changed`) | yes, a fetchable part |
|
|
552
|
+
|
|
553
|
+
Else `{part, sent: {text, lead}}`. Mid-turn the snapshot's messages lag the turn, but parts are recorded at its start,
|
|
554
|
+
so the slice is exact unless the prompt was rebuilt (4). A memory file with invalid UTF-8 is scrubbed in the saved
|
|
555
|
+
head, so its session stays in 5: accepted.
|
|
556
|
+
|
|
557
|
+
**The locator.** Every "now" the working set shows is fetched by one resolver, `WorkingSet::Locator`
|
|
558
|
+
(`working_set_locator.rb`, `Data.define(:origin, :kind, :ref, :scope, :params)`; loaded only when a fetch runs, for the
|
|
559
|
+
testing kit's file budget): "where a held text came from and how to fetch it again". `#fetch` has three outcomes: nil
|
|
560
|
+
(refused, or nothing to fetch), a `WorkingSet::Now` with `gone`, a `Now` with its text (diff nil). `#composed` is the
|
|
561
|
+
same fetch with the files it read (`Locator::Composed`: `now`, `files` of `Locator::Source` `{path, role: :base |
|
|
562
|
+
:overlay, key}`, at most two); a gone prompt memory names the base it was sent from (identity's saved `system_dir`, a
|
|
563
|
+
preload's built `scope`'s folder, a note's `requested_scope`'s). A note's overlay is found by
|
|
564
|
+
`ModelNotes.overlay_path`, the build's own lookup (its label keeps the key as given). Its guard follows
|
|
565
|
+
`origin`, and the two stay apart:
|
|
566
|
+
|
|
567
|
+
- `:run`, a `memory_read` stamp's entry (`WorkingSet.memory_now`): resolved with chi web's own `MemoryPaths.system_dir`,
|
|
568
|
+
any saved folder ignored; a path-only stamp (or one whose project folder is outside the root) reads its stamped
|
|
569
|
+
paths; a `read:` stand-in reads the files.
|
|
570
|
+
- `:prompt`, a prompt part's `params` (cases 4 and 5, `&now=1`, the stale states): a memory resolves with the saved
|
|
571
|
+
keys, `requested_scope` and folders only when the saved `system_dir` and `project_dir` are inside chi web's own
|
|
572
|
+
`MemoryPaths.system_dir`, and every path it may look at (the files resolved; a note's file and each saved key's
|
|
573
|
+
overlay, before any is stat'd) passes `memory_paths?`; identity and preloads through `Tools::MemoryRead.resolve` and
|
|
574
|
+
`.compose`, a note through `ModelNotes.body_at` (the composers the build used, so an unchanged memory's text has the
|
|
575
|
+
build's digest). An AGENTS.md is read only when it is on the session `working_directory`'s chain
|
|
576
|
+
(`PromptFiles.agents_paths`, `PromptFiles.content`). An appended file is never fetched (as sent from the head only);
|
|
577
|
+
base, the kit, a plugin's section, an index and the session lines are chi's own text: the line alone. Nothing is
|
|
578
|
+
recomputed: no model key, no folder (a model switch rebuilds the prompt, so the saved keys describe the sent text).
|
|
579
|
+
|
|
580
|
+
The path guard both share is `WorkingSet::MemoryGuard` (in `working_set.rb`: `#build`'s stale check of a read memory
|
|
581
|
+
uses it at load). A file or URL row has no locator: its timeline is the conversation's text, and its stale check is a
|
|
582
|
+
`stat` against its stamp.
|
|
583
|
+
|
|
584
|
+
**Stale prompt parts.** `WorkingSetPart.states(parts, root:, cwd:)` names the parts whose source changed since chi
|
|
585
|
+
was sent it, `[{key, state: "stale"}]` (the stale ones only): a part whose locator fetches text with a different
|
|
586
|
+
`PromptPart.digest_of` from its saved `digest`, or finds the source gone. A digest covers exactly the text the fetch
|
|
587
|
+
returns, so it catches an edit, shadowing (a bare preload now answered by the project scope), an overlay added or
|
|
588
|
+
removed, and a file deleted (gone). It does not catch what changes which parts exist rather than a part's text: a
|
|
589
|
+
note that newly applies (or whose `models:` line no longer matches), a new AGENTS.md in the chain, a memory muted
|
|
590
|
+
after the build. Only fetchable kinds get a state (identity, preloads, notes, AGENTS.md): never an index (it changes at
|
|
591
|
+
every memory write), an appended file, chi's own text, or a part an older chi built (no digest). Cost: about 0.8 ms per
|
|
592
|
+
GET for 11 fetchable parts (the Studio, warm cache; `find_dot_git` is stat-only).
|
|
593
|
+
|
|
594
|
+
**chi's own change of a stale part (`by_chi`).** Given the same source's `messages` (and `running`),
|
|
595
|
+
`WorkingSetPart.states` adds `by_chi: {tool_id, step, op, current}` to a stale part chi changed itself; the state
|
|
596
|
+
stays `"stale"`. The own changes are `WorkingSet::OwnChanges` (`working_set_own_changes.rb`): the latest successful
|
|
597
|
+
change per file still in the stored conversation, so its text is still sent in the call's arguments (`op`
|
|
598
|
+
`memory_write`, `remove`, `write`, `edit`; `step` is `PairedRun#step`). A `memory_write` counts by its output: "saved
|
|
599
|
+
to SCOPE scope" (keyed scope + name), "Model overlay 'x' for KEY saved" (+ the key: the handler's model key, never an
|
|
600
|
+
argument), "removed from" (a remove; "its dangling index line was dropped" is none); never a description-only write
|
|
601
|
+
("(file unchanged)"), the index, or a failed, denied or interrupted run (`WorkingSet.failed?`). An `edit` or `write`
|
|
602
|
+
counts by its `FileRef` path and stamp. Each file the part was read from (`Locator#composed`, at most two) maps to its
|
|
603
|
+
latest own change: a memory's by the saved folder it sits in (`File.dirname(path) == dir`: a project's folder is
|
|
604
|
+
inside the system one), a file tool's by basename then `realpath`. A change is current while the file holds what it
|
|
605
|
+
left: a `memory_write`'s content byte for byte (`File.binread`; a model note's or an overlaid memory's text never
|
|
606
|
+
digests to its file, so the compare is per file), a remove's absence, an edit's stamp (`WorkingSet.differs?`).
|
|
607
|
+
|
|
608
|
+
`current: true` (the row's `✎ edited`) when every file holds chi's change or what was sent, and one holds chi's. "What
|
|
609
|
+
was sent" is the part's sent slice (`sent_of`, only when `messages[0]` is the head the parts were built with), split
|
|
610
|
+
with the text now at `Tools::MemoryRead.overlay_tail` (the overlay's key now, else the build's `model_key`, then
|
|
611
|
+
`fallback_model_key`): the base's text against the body, the overlay's against the tail, and no overlay now must mean
|
|
612
|
+
no tail sent (a project `x` chi wrote now answering a bare preload that was sent with a system overlay is stale). A
|
|
613
|
+
gone part is current only by chi's current remove of the base it was sent from. Otherwise, when chi changed one of the
|
|
614
|
+
files, `current: false` (it changed again after chi's change; or the head is not the build's, case C 4–5, where
|
|
615
|
+
nothing proves the other file unchanged). Rolled back (the call's entries gone, the file still chi's text), interrupted,
|
|
616
|
+
or someone else's change: no `by_chi`. A merged row (a note also preloaded) gets an answer per part.
|
|
617
|
+
|
|
618
|
+
An `edit` is checked harder than its stamp (a stricter reading of D2, the code review's M2): `edit` replaces its
|
|
619
|
+
`old_text` wherever it still matches, so it can land over a change chi never saw, and the stamp then holds. A part
|
|
620
|
+
whose current change of a file is an `edit` is current only when undoing chi's edits of that file, newest first
|
|
621
|
+
(`OwnChanges.undoes_to?`: each `new_text` found exactly once and put back to its `old_text`), reaches the sent side
|
|
622
|
+
exactly (stripped, as a prompt file is), or chi's own `memory_write` of it before those edits. Otherwise there is no
|
|
623
|
+
`by_chi`, so the row stays plain `stale` and the now tab shows the diff. A range edit (`start_line`), an empty
|
|
624
|
+
`new_text` or a `write` among them can't be undone: plain `stale` too. An `edit` or `write` with no stamp (an older
|
|
625
|
+
session's) gives no `by_chi`, never `current: false`. Read rows and file rows keep the stamp rule (D1, as file rows
|
|
626
|
+
always had).
|
|
627
|
+
|
|
628
|
+
Known limit: own changes have no build point. A write from before the prompt's build counts when the file comes back to
|
|
629
|
+
its text (chi writes A; someone writes B; a restart builds the prompt with B; someone writes A back): the row reads
|
|
630
|
+
`✎ edited` though the newer prompt says B. Rare; a session that recorded the message index of the head's build could
|
|
631
|
+
ignore earlier changes.
|
|
632
|
+
|
|
633
|
+
While a turn runs (`running`), only a `current: true` goes out: the GET's messages may lag the turn, so chi's newest
|
|
634
|
+
write may not be in them, and "changed again" could name chi's own change. A row chi changes in the running turn reads
|
|
635
|
+
`stale` until a GET's messages hold the write (D5); in the browser check (2026-11-22, the fake model) the row already
|
|
636
|
+
read `✎ edited` in a later step of the same turn, so the lag seems to be the writing step only (inferred, not traced in
|
|
637
|
+
the worker), and the hand-off's GET settles it either way. Guard: only the Locator's files are read (`binread`, `stat`); no path a call
|
|
638
|
+
or an output names is read, and an overlay key is `[a-z0-9-]+`. Cost: nothing new for a GET with no stale part; with one,
|
|
639
|
+
one `paired_runs` walk (about 3 ms at 600–750 messages on the Studio, about twice on the laptop), the messages'
|
|
640
|
+
top-level keys symbolized (`WorkingSetPart.symbolized`, shared with `working_set_source`), and at most two reads or
|
|
641
|
+
stats per stale part. A stale part stays stale for the worker's life, so each GET of such a session pays it.
|
|
642
|
+
|
|
643
|
+
The carrier is chi web's `GET …/working_set` alone: `handle_working_set` adds `parts:` for the owner whichever of its
|
|
644
|
+
three sources answered (the running turn's set, an idle worker's, a build from the file), from the parts the part
|
|
645
|
+
route reads (`#prompt_source`: the live snapshot frame's, else the file's), so a stopped session, a live idle worker
|
|
646
|
+
and an older (0.183.0) worker all get them. No field means none stale. No event field, no worker change; a
|
|
647
|
+
participant's answer never has it (`ParticipantView.working_set` rebuilds `{items, at}`). The page asks the GET each
|
|
648
|
+
time the list opens. A `:working_set_updated` event carries no parts: the page keeps the session's last GET's states on
|
|
649
|
+
the event's set (`working_set_view.js takeServer`), and a GET an event overtook still gives its parts. The page asks
|
|
650
|
+
the GET again when the session's parts are rebuilt (their heads or digests change, `sessionChanged`) and at a turn's
|
|
651
|
+
hand-off when it holds states or the list is open, so a rebuilt prompt's states go.
|
|
652
|
+
|
|
653
|
+
Stale lasts in a live worker until chi rebuilds its prompt: `SystemPrompt#built_for` caches the build until
|
|
654
|
+
`#reset!` (a model switch, a participants change, a plugin's `prompt_changed!`, a toolkit change). An outside edit,
|
|
655
|
+
and chi's own `memory_write` of a preloaded memory, do not reset it, so the worker keeps sending the old text across
|
|
656
|
+
turns until one of those or a restart. Someone else's change reads `stale`; chi's own (a current `by_chi`) reads
|
|
657
|
+
`✎ edited`, since the new text is in chi's conversation; while the turn that made it still runs it may read `stale`
|
|
658
|
+
until a GET's messages hold the write (see `by_chi` above).
|
|
659
|
+
|
|
660
|
+
**The source now.** `GET …/working_set/part?key=&now=1` adds, beside the sent slice, `now: {text, diff, gone}`: the
|
|
661
|
+
locator's text (scrubbed to valid UTF-8 before JSON) and `TextDiff.unified` of the sent text against it (nil when
|
|
662
|
+
gone), and `rebuild`: when chi's prompt gets the source now, `restart` with a live worker (it keeps its prompt until it
|
|
663
|
+
is next built) or `next_turn` without one (the next turn builds it). Under cases 4 and 5 the answer stays as above (the
|
|
664
|
+
source now, no diff: nothing sent to diff against; no `rebuild`, their words say when). Parts without a locator have no
|
|
665
|
+
`now`. An older chi web sends no `rebuild`, and the page leaves its line out.
|
|
666
|
+
|
|
667
|
+
**The page.** `ws_part_peek.js` (made by `ws_reader.js` with the reader's markdown cache, handed to the view as
|
|
668
|
+
`peek.part`): the peek's head "in the prompt · sent with every request", the text (a memory's and an `.md` file's
|
|
669
|
+
rendered), chi's lead folded under "chi adds a line before it", no foot buttons; tools as names and sizes; case C's
|
|
670
|
+
line with the source now under it. A row of several holds gets one tab per hold, its kind and size (`note · ~0.9k`,
|
|
671
|
+
`preload · ~1.2k`, `in the prompt · ~1.4k`), and `read · t1·s1` for an item that was read: the item peek, first. One
|
|
672
|
+
peek open at a time. The popover is 520 wide open or closed.
|
|
673
|
+
|
|
674
|
+
The GET's `parts` reach the start rows as `headSections`' `states` option (`startRows`: `partStates` beside
|
|
675
|
+
`partKeys`, `partStale` when one is). A stale row says `stale` in `--warn-text` (`.ws-pstale`) in place of its words,
|
|
676
|
+
which move to its title ("model note · changed after chi's prompt was built"); a memory row whose read is stale too
|
|
677
|
+
still says one `stale`, its title and its now tab naming both ("read changed · prompt text changed"). Its peek gets a `now · changed` tab right after the stale hold (`warn`):
|
|
678
|
+
the `&now=1` answer, drawn as "<label> changed after chi's prompt was built" with the diff's `+a −d` and
|
|
679
|
+
`diff_view.js`'s diff ("no change" once it was edited back), or "Its source is gone now." It opens first unless the row
|
|
680
|
+
has a read. No new export: an older `ws_sections.js` ignores `states`, and the 0.183.0 page ignores the field.
|
|
681
|
+
|
|
682
|
+
**chi's own change on the page.** The view reads the GET's `by_chi` itself, off `server.parts` (`working_set_view.js
|
|
683
|
+
ownRow`: an older cached `ws_sections.js` has no `partKeys`, build 2's maps states to `"stale"` or none): a stale part
|
|
684
|
+
whose `by_chi.current` is true becomes `"edited"` in the row's `partStates`, and a row none of whose parts is still
|
|
685
|
+
stale is edited. It reads `✎` (the file rows' `.e`), then `<span class="st ws-pedited"><span class="ws-pwords">preloaded
|
|
686
|
+
· </span>edited</span>` (`removed` for a remove) in `--text-2`, not the warn colour; for AGENTS.md `project instructions ·
|
|
687
|
+
edited`. Its title: "preloaded · chi edited it at turn 3, step 2: the new text is in its conversation; its prompt
|
|
688
|
+
still sends the old text until it is next built" (a remove: "… chi removed it at turn 3, step 2: its prompt still sends
|
|
689
|
+
it until it is next built"). Its tag after the tokens is the call's place, found by `tool_id` over every turn's items
|
|
690
|
+
(`ws_timeline.js placeOf`), drawn as the read rows' jump (`.ws-step.ws-own`, `data-ws="jump"`); without a place, a
|
|
691
|
+
plain `step N` (the server's step). A memory row whose read is stale says the read's `stale` as before; the
|
|
692
|
+
both-causes words ("read changed · prompt text changed") need a read op, so a memory chi only wrote and someone changed
|
|
693
|
+
after reads "changed after chi's prompt was built" (its item is stale by D1, faded). A row whose part carries `by_chi`
|
|
694
|
+
and whose item has no read gets no `read` tab (the item peek of chi's write): its edited tab, or its now tab with the
|
|
695
|
+
"chi edited it at …" line, opens first. In a turn lens the call's tag replaces the lit row's step tag. A merged row
|
|
696
|
+
(a note also preloaded) stays `stale` while any part is stale without a current change; each part gets its own tab.
|
|
697
|
+
On a phone's sheet the part words go (`.ws-popover.sheet .ws-pwords{display:none}`, D7): `✎ edited` alone, the name
|
|
698
|
+
keeps its room; a part row keeps `edited` where it drops its sub text, and the tabs wrap.
|
|
699
|
+
|
|
700
|
+
The peek (`ws_part_peek.js`) gives an edited part the tab `edited · t3·s2` (`removed · t3·s2`) right after its hold, in
|
|
701
|
+
place of the now tab; it opens first unless the row has a read. Its body is the `&now=1` answer: the head "chi edited
|
|
702
|
+
`<label>` at t3·s2" with the diff's `+a −d`, the diff sent → now, and one line, "Its prompt still sends the old text with
|
|
703
|
+
every request; chi has the new text from its edit.", followed by "The prompt gets it when it is next built (a restart,
|
|
704
|
+
a model switch)." (`rebuild: "restart"`) or "The prompt gets it when it is next built (at its next turn)."
|
|
705
|
+
(`"next_turn"`); none without `rebuild`. A remove's tab: "chi removed it at t3·s2; its prompt still sends it until it
|
|
706
|
+
is next built." A stale now tab gets the rebuild line under the diff: "chi gets the new text when its prompt is next
|
|
707
|
+
built (a restart, a model switch)." or "chi gets the new text at its next turn."; with `by_chi.current === false`,
|
|
708
|
+
above it (warn) "chi edited it at t3·s2; it changed again after that.". The words are constants beside `BOTH_CHANGED`
|
|
709
|
+
(`REBUILD_LIVE`, `REBUILD_NEXT`, `STILL_SENT`, `PROMPT_GETS`). No new export: an older cached peek given `"edited"`
|
|
710
|
+
sees no stale and shows the sent text only (`v0.183.0` has no `ws_part_peek.js`, so that pairing gets a fixture once
|
|
711
|
+
0.184.0 is tagged); the 0.183.0 page and view ignore `by_chi`; a new page against an older chi web (no `by_chi`, no
|
|
712
|
+
`rebuild`) draws build 2's stale with no rebuild line.
|
|
713
|
+
|
|
714
|
+
**Compat.** An older page ignores the fields and the route; a build-2 page maps any state but `"stale"` to none, so
|
|
715
|
+
`by_chi` rides beside `state: "stale"` (no new state value) and such a page draws today's `stale`; an older chi reading a newer file drops the fields
|
|
716
|
+
(`PromptPart.from_h`), and its own save drops them (cases 1–2). The corpus's `compat-prompt` session has a head and
|
|
717
|
+
placed parts (`ReleaseTools.write_compat_corpus!`, read in `spec/compat/readers_spec.rb`); in the wire samples the head
|
|
718
|
+
is `CompatWire::SYSTEM_PROMPT`, so the digest never matches and a wire reader asserts the fallback.
|
data/docs/mcp-server.md
CHANGED
|
@@ -47,7 +47,11 @@ host isn't left waiting on that call.
|
|
|
47
47
|
| `chi_wait` | `token` | keeps waiting for a turn that was still running |
|
|
48
48
|
| `chi_answer` | `session`, `question_id`, `option?` / `options?` / `text?` | answers the question a session waits on, then waits |
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
`chi_ask` with `/continue yes` follows the continued turn: its answer, or a `chi_wait` token while it runs.
|
|
51
|
+
|
|
52
|
+
A call waits at most 25 seconds (a `chi_ask` or `chi_answer` 35 in all, under Claude Code HTTP's 60 s). Under `chi
|
|
53
|
+
--remote NAME` (stdio, where no host has a 60 s limit) a session whose worker is slow can take about a minute: the
|
|
54
|
+
other chi web makes its own tries. Then:
|
|
51
55
|
|
|
52
56
|
- the turn still runs: `Still running. Call chi_wait with this token to keep waiting.` with a `token`;
|
|
53
57
|
- a question waits: the question, its numbered options and `Call chi_answer with session, question_id and option
|
data/docs/memory.md
CHANGED
|
@@ -155,7 +155,8 @@ Each memory entry may have a companion file named `<name>.<model-key>.md` in the
|
|
|
155
155
|
- **Key derivation**: The harness normalizes the model name sent to the server, without its host prefix (`box:qwen3.6-35b-a3b` keys as `qwen3.6-35b-a3b`; an alias keys as its target, and the alias's own key is read when the target has no overlay) (lowercase, replace non-alphanumeric with `-`, squeeze dashes) to derive the file key. For example, `qwen3.6-35b-a3b` → `qwen3-6-35b-a3b`.
|
|
156
156
|
- **Saving overlays**: Pass `current_model_only: true` to `memory_write` (the harness resolves the model key automatically). This writes the content as `<name>.<model-key>.md` and skips index maintenance. The guardrails bundle asks before a model writes one (`model-overlay-write`). Habits of a model in general go in a [model note](#model-notes), which can name a family or all small models.
|
|
157
157
|
- **Which key is mine**: the system prompt's `Model:` line names the session's model key, and `chi self` (via `execute`) has a `model key` row; both follow `/model`.
|
|
158
|
-
- **In the system prompt**: the identity memory and the preloaded memories (`--memory`, config `memories:`) get their overlays too, as `memory_read` gives them; after `/model` the rebuilt prompt carries the new model's.
|
|
158
|
+
- **In the system prompt**: the identity memory and the preloaded memories (`--memory`, config `memories:`) get their overlays too, as `memory_read` gives them; after `/model` the rebuilt prompt carries the new model's. Each prompt part saves the keys and folders its build resolved with, so the web's working set re-resolves it the same way (an overlay added or removed since, or a project memory now shadowing a system one, makes its "From the start" row `stale`; a source chi changed itself, with `memory_write` or an `edit`, reads `✎ edited`
|
|
159
|
+
and links the call, not `stale`; see [working-set.md](internals/working-set.md#prompt-parts-as-sent)).
|
|
159
160
|
- **Dormancy**: Overlays are only active under the matching model key; other models see the base entry only.
|
|
160
161
|
- **Invariant**: The base entry is the contract. Overlays only add model-specific guidance and never contradict the base protocol.
|
|
161
162
|
- **In a bundle**: ship `<name>.<key>.md` next to `<name>.md` (ship the base too; an overlay with no base anywhere installs with a warning and loads only once the base exists; one whose base is only among your installed memories is taken as an overlay of it, with a warning naming it). The overlay gets no `index.md` line, so other models don't see it, and `chi bundle status` reads it `ok (model overlay)`; `chi bundle build FILES...` brings a named memory's overlays along.
|
data/docs/plugins.md
CHANGED
|
@@ -31,7 +31,7 @@ plugin:
|
|
|
31
31
|
# required: true # optional: a guardrail plugin; if it fails to load, every tool call is
|
|
32
32
|
# denied (see chi.on's on_error: :fail_closed; chi 0.157.0 or newer)
|
|
33
33
|
# parts: # optional: more .rb files of the plugin, loaded in this order before file:
|
|
34
|
-
# client.rb: sha256:… # (see "A plugin in several files" below; needs
|
|
34
|
+
# client.rb: sha256:… # (see "A plugin in several files" below; needs chi 0.183.0)
|
|
35
35
|
requires_chi: ">= 0.1.28" # optional: a gem-style requirement (">= 0.1.28, < 0.2"); the bundle's rules check it too
|
|
36
36
|
# every key below has a chi floor: check warns when requires_chi admits a chi that never read it
|
|
37
37
|
# requires_chi_next: true # shipped bundles only, ignored by chi: rake release:bump raises requires_chi
|
|
@@ -108,7 +108,7 @@ plugin:
|
|
|
108
108
|
- A part is a `.rb` name in the bundle's top directory, not the plugin file's own nor another part's, in any case
|
|
109
109
|
(`Plugin.rb` beside `plugin.rb` is one file on a case-insensitive disk), listed once; at most 16. It is installed
|
|
110
110
|
beside the plugin file in `plugin/`, checked like it at every load, and listed by `chi bundle status`, `diff`,
|
|
111
|
-
`build` and `uninstall`.
|
|
111
|
+
`build` and `uninstall`. `chi bundle check` warns when a `.rb` in a subdirectory would be left out of the install.
|
|
112
112
|
- chi evaluates the parts **in the listed order**, then the plugin file, all into the same fresh module, so they
|
|
113
113
|
share one namespace. Only the plugin file names the class chi builds; a part usually reopens it
|
|
114
114
|
(`class Plugin; class HttpClient …`).
|
|
@@ -119,8 +119,8 @@ plugin:
|
|
|
119
119
|
- Not `require_relative`: a file pulled in that way skips the sha256 check, is cached by Ruby across reloads (a
|
|
120
120
|
reload would keep the old classes) and defines its constants outside the bundle's namespace.
|
|
121
121
|
- A bundle that uses `parts:` should require a chi that reads them (`requires_chi`): an older chi would install the
|
|
122
|
-
plugin file alone. `chi bundle check` warns of a
|
|
123
|
-
|
|
122
|
+
plugin file alone. `chi bundle check` warns of a `requires_chi` below 0.183.0, the
|
|
123
|
+
release that brings parts. A record written that way is refused at load with `bundle NAME's
|
|
124
124
|
plugin parts aren't installed (reinstall the bundle)`.
|
|
125
125
|
|
|
126
126
|
## The API: `register(chi)`
|
|
@@ -956,7 +956,7 @@ full label, `plugin.rb (bundle my-bundle)`.
|
|
|
956
956
|
| `ctx.judge(name, state:)`, `ctx.judge_later(name, state:) { |result| … }`, `ctx.judgments` | a cheap System 1 question this bundle declared, saved as a run: see [Judgments](#judgments-chijudgment-and-ctxjudge) |
|
|
957
957
|
| `ctx.sign_in(title:, button:, timeout: 300, port: nil, path: "/callback", cancel: nil) { \|redirect_uri\| address }` | send the owner to an address and get back where the browser was sent: see [Sign-in](#sign-in-ctxsign_in) |
|
|
958
958
|
| `ctx.secrets` | the bundle's tokens, kept apart from its data files (`get`, `set`, `delete`, `update`): see [Secrets](#secrets-ctxsecrets) |
|
|
959
|
-
| `ctx.http` | an HTTP client for calling services (`get`, `post_json`, `request`): see [Calling services](#calling-services-ctxhttp) |
|
|
959
|
+
| `ctx.http` | an HTTP client for calling services (`get`, `post_json`, `request`, `stream`): see [Calling services](#calling-services-ctxhttp) |
|
|
960
960
|
| `ctx.sessions` | fork, send to, read, list and stop other sessions: see [Other sessions](#other-sessions-ctxsessions) |
|
|
961
961
|
| `ctx.toolkit` | the name of the session's toolkit (`full` for a session from before toolkits); nil with no session |
|
|
962
962
|
| `ctx.declared_tools` | the tool names the session's next turn declares (its toolkit resolved, with its own adds and removes): ask this, not the name, whether a tool is there. Your bundle's own `chi.tool` tools are in it only on a kit that declares them (`full`, an `add:`); elsewhere they are reachable, not declared (the testing kit answers every tool, as on full, unless `bundle.set(declared_tools: […])`) |
|
|
@@ -1065,7 +1065,7 @@ A card from a thread of your own (a sign-in's result, a server's state) that a t
|
|
|
1065
1065
|
lands in that turn's block, which the web collapses when the turn ends. `between_turns: true` keeps it out: while a
|
|
1066
1066
|
turn runs it is shown as an anytime command's card is (outside the turn's block, marked `anytime: true`), else as
|
|
1067
1067
|
any card between turns. It is the rule chi's own sign-in cards follow. The test kit records it on the card
|
|
1068
|
-
(`between_turns: true`). The keyword needs
|
|
1068
|
+
(`between_turns: true`). The keyword needs chi 0.183.0 or newer (an older one raises `ArgumentError`).
|
|
1069
1069
|
|
|
1070
1070
|
A worker keeps its last 20 cards (questions included) and, apart, its
|
|
1071
1071
|
last 20 hook notices, for a UI that joins later; a question still waiting
|
data/docs/scheduling.md
CHANGED
|
@@ -194,6 +194,20 @@ disables the entry and `chi schedule list` says why. **Any successful firing res
|
|
|
194
194
|
both counters**, so twelve skips spread over months do not kill a healthy weekly
|
|
195
195
|
schedule. `list` prints the skip budget as a time window — 12 skips at a 5 minute
|
|
196
196
|
tick is about an hour of patience, which is what the count really measures.
|
|
197
|
+
`chi schedule enable` resets both counters too: a schedule turned back on gets its
|
|
198
|
+
whole budget again, not one skip.
|
|
199
|
+
|
|
200
|
+
The tick line that disabled an entry ends `(disabled)` (`chi schedule tick`,
|
|
201
|
+
`run-now`), and `tick --format json` gives that outcome `"disabled": true`
|
|
202
|
+
(`Schedules::Outcome#disabled`). When **chi web's** tick (`schedule.auto_tick`)
|
|
203
|
+
disables a recurring schedule, the phone gets one notification
|
|
204
|
+
([Phone notifications](configuration.md#phone-notifications-web-push)): "Schedule
|
|
205
|
+
disabled: Heartbeat", "skipped 12 times: <the last reason>" and the `chi schedule
|
|
206
|
+
enable <id>` that turns it back on; a tap opens its session. It shows even with a chi
|
|
207
|
+
web page in front and waits a day for a phone that is offline. Nothing notifies for a
|
|
208
|
+
cron tick or `chi schedule run-now` (only chi web pushes), a `--dry-run`, your own
|
|
209
|
+
`chi schedule disable`, or a `date` one-off (spent when it fires; one that then fails
|
|
210
|
+
stays disabled with the failure in `chi schedule list`).
|
|
197
211
|
|
|
198
212
|
An accepted delivery is **pending**, not fired: `schedules.json` records its
|
|
199
213
|
session and turn id, and the next tick follows that turn's own outcome, even if a
|
data/docs/sessions.md
CHANGED
|
@@ -149,7 +149,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
149
149
|
| `project_id` | A marked project's id (its `.chi/project.yml`'s `id:`), saved beside `project_root`: the session's project context sources are keyed by it, so they follow a moved folder. Absent for any other project. | creation |
|
|
150
150
|
| `preloaded_memory_names`, `muted_memory_names` | `--memory` and `--mute`, written before the worker starts so a respawn builds the same prompt; copied by a fork and a continue. A fork drops the reserved `system/delegated` memory so its `parent_id` does not make it a delegate; a continuation of a delegate child drops it because the new link is not a delegate. | creation |
|
|
151
151
|
| `prompt_notes` | The model notes the system prompt carried at its last build (`[{name, scope, chars, digest}]`, see [Memory](memory.md#model-notes)). | the Engine, at each prompt build |
|
|
152
|
-
| `prompt_parts` | The sizes of the parts the system prompt was made of at its last build (`[{kind, label, chars, tokens, ref, scope?}]`: a `tools` part first, then one per memory, file and plugin section in prompt order, the indexes one per scope; tokens at `chars / 4`; no text). `scope` is a memory part's, `project` or `system` (identity `system`, a model note its own, a preload the scope that answered its read); other parts and an older file leave it out, and the page then matches the part to the set's memory by name alone. A `/model` switch records `[]` until the next build. The web's head view lists them; an older file or worker has none and reads as `[]` (a missing field is the old case, the page draws without the part rows). | the Engine, at each prompt build |
|
|
152
|
+
| `prompt_parts` | The sizes of the parts the system prompt was made of at its last build (`[{kind, label, chars, tokens, ref, scope?}]`: a `tools` part first, then one per memory, file and plugin section in prompt order, the indexes one per scope; tokens at `chars / 4`; no text). `scope` is a memory part's, `project` or `system` (identity `system`, a model note its own, a preload the scope that answered its read); other parts and an older file leave it out, and the page then matches the part to the set's memory by name alone. A `/model` switch records `[]` until the next build. Each part also says where it sits in the prompt the build made (`at`, `len` with its `lead`, a 12-hex `digest` of its own text, the build's 16-hex `head` digest) and how to fetch it again (`params`: a memory's requested scope, overlay keys and folders, a file's path, the tools' names and sizes), each left out when nil; the prompt itself is `messages[0]` (a `system` message with no `kind`), so chi web's part route slices it rather than keeping a copy ([working-set.md](internals/working-set.md#prompt-parts-as-sent)). About 2–3 KB a session, in the file and every snapshot. An older chi reads the parts and drops the new fields. The web's head view lists them; an older file or worker has none and reads as `[]` (a missing field is the old case, the page draws without the part rows). | the Engine, at each prompt build (never the turn-end warm-up's) |
|
|
153
153
|
| `parent_id` | The session that delegated this one or forked it (`ctx.sessions.fork`); `null` otherwise. See [Delegating](#delegating). | `SessionManager.spawn_session`; `ChildMove` writes a `parent.json` beside it instead of this file |
|
|
154
154
|
| `scratch` | A `chi scratch` session, deleted when its terminal leaves. | creation |
|
|
155
155
|
| `last_turn` | How the last turn ended (`LastTurn`), for a parent's wait and the web's notifications. | the Engine, at a turn's end |
|
data/docs/thin-clients.md
CHANGED
|
@@ -33,12 +33,12 @@ another link ran it. Body fields:
|
|
|
33
33
|
|
|
34
34
|
- `prompt` (required): the message, at most 16 KiB. A terminal-only command such
|
|
35
35
|
as `/stats` is refused (400 `local_command`); a session command such as
|
|
36
|
-
`/model x` runs and answers `{"status": "command"}`, with no token.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
`/model x` runs and answers `{"status": "command"}`, with no token.
|
|
37
|
+
`/continue yes` on a session whose turn ran out of steps, while its worker
|
|
38
|
+
runs, continues that turn and answers as a message does (its reply, or a
|
|
39
|
+
`token`); if the offer was answered elsewhere first you get what came of it.
|
|
40
|
+
A continue offer still shown as a question (409 `waiting`) is answered
|
|
41
|
+
through `/answer`.
|
|
42
42
|
- `timeout`: seconds to wait for the answer, at most 30 (the default).
|
|
43
43
|
- `queue`: `true` (the default) means a session running a turn queues your
|
|
44
44
|
message as its own turn, and you get that turn's answer. `false` refuses a
|
|
@@ -46,6 +46,19 @@ another link ran it. Body fields:
|
|
|
46
46
|
- `client_id`: who is asking. Leave it out for yourself (the line is the
|
|
47
47
|
owner's, as from the web composer). An agent sends `"cli:send"`: see
|
|
48
48
|
[An agent over HTTP](#an-agent-over-http).
|
|
49
|
+
- `request_id`: your own key for this ask, 1 to 128 printable ASCII
|
|
50
|
+
characters. Send the same ask again with the same `request_id` (a retry
|
|
51
|
+
after a dropped connection) and you get the first one's turn instead of
|
|
52
|
+
sending it again. It is for messages only: a session command with one (a
|
|
53
|
+
line starting `!`, or `/name` then a space or nothing) is 400
|
|
54
|
+
`invalid_ask`; a path such as `/Users/me/a.rb fails` is a message. It holds
|
|
55
|
+
while that turn is running, queued, or has replied or ended, and otherwise
|
|
56
|
+
while the session's worker remembers the key; it does not hold across a
|
|
57
|
+
continue to a new link. Use a new key for a new message: while the first
|
|
58
|
+
turn is running, queued, or has replied or ended, the same key with another
|
|
59
|
+
prompt gets that turn's answer and nothing is sent; otherwise a worker that
|
|
60
|
+
remembers the key answers 409 `enqueued_id_conflict`. An answer that echoes
|
|
61
|
+
`request_id` means chi web used it (an older chi web ignores the field).
|
|
49
62
|
|
|
50
63
|
A question that is waiting for an answer refuses the ask with 409 `waiting` and
|
|
51
64
|
the `question`. Answer it first (below).
|
|
@@ -54,9 +67,9 @@ the `question`. Answer it first (below).
|
|
|
54
67
|
|
|
55
68
|
Each call answers within **35 seconds** of its request, whatever it waits for
|
|
56
69
|
(a continue in flight, a worker starting, the answer), so a proxy or a Shortcut
|
|
57
|
-
with a 60 s limit is safe.
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
with a 60 s limit is safe. A worker that hangs while it takes the message in
|
|
71
|
+
is given at most 8 s past that, then the call answers 504 `worker_timeout`; the
|
|
72
|
+
message was not taken. A turn still running then answers
|
|
60
73
|
`"status": "timeout"` with a `"token": "w1.…"`. Send that token back until the
|
|
61
74
|
status is something else:
|
|
62
75
|
|
|
@@ -101,6 +114,9 @@ The answer goes in before the wait starts, so a wait that fails afterwards
|
|
|
101
114
|
`wait_failed`, and a `detail`) in place of `reply`. Don't answer again (that
|
|
102
115
|
would be 409): ask or wait on the session instead.
|
|
103
116
|
|
|
117
|
+
Ask waits also return 409 `busy` / `waiting` / `continuing` / `owned_by_tui`, or 503
|
|
118
|
+
`server_stopping` (ask again).
|
|
119
|
+
|
|
104
120
|
## An agent over HTTP
|
|
105
121
|
|
|
106
122
|
An agent (Claude Code, Codex, a script acting on its own) should drive chi
|
|
@@ -134,7 +150,10 @@ answers the first turn.
|
|
|
134
150
|
1. **Dictate Text** (or **Ask for Input**).
|
|
135
151
|
2. **Get Contents of URL**: `https://<your chi web>/api/sessions/<id>/ask`,
|
|
136
152
|
method POST, header `Authorization: Bearer <token>`, JSON body `prompt` =
|
|
137
|
-
the dictated text.
|
|
153
|
+
the dictated text. To survive a dropped connection, first **Set Variable**
|
|
154
|
+
`key` to **Current Date** formatted with seconds, send `request_id` = `key`,
|
|
155
|
+
and if the step fails (no `status` in the answer) run it again with the same
|
|
156
|
+
`key`: the retry answers the first one's turn instead of sending it twice.
|
|
138
157
|
3. **Repeat** while the answer's `status` is `timeout`: **Get Contents of URL**
|
|
139
158
|
for `…/api/sessions/<session_id>/wait` with the JSON body `token` = the
|
|
140
159
|
answer's `token`.
|
|
@@ -89,11 +89,11 @@ module Samagotchi
|
|
|
89
89
|
# new secret) is reached by a client made after it, never by hand.
|
|
90
90
|
# @param sidecar [WorkerSidecar, nil]
|
|
91
91
|
# @return [BridgeClient, nil] nil without a sidecar
|
|
92
|
-
def self.for_sidecar(session_id, sidecar, host: HOST, read_timeout: READ_TIMEOUT)
|
|
92
|
+
def self.for_sidecar(session_id, sidecar, host: HOST, read_timeout: READ_TIMEOUT, deadline_margin: nil)
|
|
93
93
|
return nil unless sidecar
|
|
94
94
|
|
|
95
95
|
new(session_id: session_id, port: sidecar.port, secret: sidecar.secret, host: host, read_timeout: read_timeout,
|
|
96
|
-
features: sidecar.features)
|
|
96
|
+
features: sidecar.features, deadline_margin: deadline_margin)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
# How often a wait for a new worker's Bridge looks: a missing sidecar is
|
|
@@ -131,7 +131,11 @@ module Samagotchi
|
|
|
131
131
|
# none); from the worker's sidecar (.for_sidecar), never typed
|
|
132
132
|
# @param read_timeout [Numeric] see READ_TIMEOUT
|
|
133
133
|
# @param features [Array<String>] the sidecar's (#features)
|
|
134
|
-
|
|
134
|
+
# @param deadline_margin [Numeric, nil] the fewest seconds the deadline
|
|
135
|
+
# leaves before the read timeout for the write and the reply (a short
|
|
136
|
+
# read's DEADLINE_SHARE leaves under a second); nil: the share alone
|
|
137
|
+
def initialize(session_id:, port:, secret:, host: HOST, read_timeout: READ_TIMEOUT, features: [], deadline_margin: nil)
|
|
138
|
+
@deadline_margin = deadline_margin
|
|
135
139
|
@features = Array(features).freeze
|
|
136
140
|
@session_id = session_id
|
|
137
141
|
@port = port
|
|
@@ -442,7 +446,11 @@ module Samagotchi
|
|
|
442
446
|
# When this client stops waiting for a reply, as epoch seconds (see
|
|
443
447
|
# DEADLINE_SHARE). Wall clock: the worker runs on this machine and reads
|
|
444
448
|
# the same one.
|
|
445
|
-
def deadline
|
|
449
|
+
def deadline
|
|
450
|
+
allowed = @read_timeout * DEADLINE_SHARE
|
|
451
|
+
allowed = [allowed, @read_timeout - @deadline_margin].min if @deadline_margin
|
|
452
|
+
(Time.now.to_f + allowed).round(3)
|
|
453
|
+
end
|
|
446
454
|
|
|
447
455
|
def post(path, payload, read_body:, read_timeout: @read_timeout)
|
|
448
456
|
sock = TCPSocket.new(@host, @port)
|
|
@@ -208,8 +208,7 @@ module Samagotchi
|
|
|
208
208
|
|
|
209
209
|
# @return [Boolean] whether a listed file is missing
|
|
210
210
|
def check_files(manifest)
|
|
211
|
-
listed = manifest
|
|
212
|
-
manifest.scripts.keys.map { |s| File.join("scripts", s) }
|
|
211
|
+
listed = listed_files(manifest)
|
|
213
212
|
missing = listed.reject { |rel| File.file?(path(rel)) }
|
|
214
213
|
missing.each do |rel|
|
|
215
214
|
add(:error, :"missing-file", "manifest.yml", "lists #{rel}, which isn't in the bundle", line: manifest_line(rel),
|
|
@@ -218,6 +217,11 @@ module Samagotchi
|
|
|
218
217
|
!missing.empty?
|
|
219
218
|
end
|
|
220
219
|
|
|
220
|
+
def listed_files(manifest)
|
|
221
|
+
manifest.files.keys + manifest.plugin_files.map(&:first) +
|
|
222
|
+
manifest.scripts.keys.map { |s| File.join("scripts", s) }
|
|
223
|
+
end
|
|
224
|
+
|
|
221
225
|
# What an install leaves out: a memory files: doesn't list (by
|
|
222
226
|
# MemoryFiles' rules), a plugin or script the manifest doesn't name.
|
|
223
227
|
def check_unlisted(manifest)
|
|
@@ -231,6 +235,14 @@ module Samagotchi
|
|
|
231
235
|
Dir.glob(path("*.rb")).map { |f| File.basename(f) }.sort.each do |name|
|
|
232
236
|
unlisted(name, "plugin: parts:") unless plugin_files.include?(name)
|
|
233
237
|
end
|
|
238
|
+
listed = listed_files(manifest)
|
|
239
|
+
Dir.glob(path("**/*.rb")).sort.each do |file|
|
|
240
|
+
rel = file.delete_prefix("#{@dir}/")
|
|
241
|
+
next unless rel.include?("/")
|
|
242
|
+
next if rel.start_with?("spec/", "test/") || listed.include?(rel)
|
|
243
|
+
|
|
244
|
+
unlisted_nested_plugin_part(rel, manifest.plugin[:file])
|
|
245
|
+
end
|
|
234
246
|
elsif File.file?(path("plugin.rb"))
|
|
235
247
|
unlisted("plugin.rb", "plugin:")
|
|
236
248
|
end
|
|
@@ -239,6 +251,12 @@ module Samagotchi
|
|
|
239
251
|
end
|
|
240
252
|
end
|
|
241
253
|
|
|
254
|
+
def unlisted_nested_plugin_part(rel, plugin_file)
|
|
255
|
+
add(:warn, :unlisted, rel,
|
|
256
|
+
"manifest.yml's plugin: parts: doesn't list it, so an install leaves it out; parts sit next to #{plugin_file}",
|
|
257
|
+
fix: "move it up as #{File.basename(rel)} and list it under plugin: parts:, then chi bundle check --fix")
|
|
258
|
+
end
|
|
259
|
+
|
|
242
260
|
def unlisted(rel, key)
|
|
243
261
|
add(:warn, :unlisted, rel, "manifest.yml's #{key} doesn't list it, so an install leaves it out",
|
|
244
262
|
fix: "list it under #{key}, then chi bundle check --fix")
|
|
@@ -578,7 +578,11 @@ module Samagotchi
|
|
|
578
578
|
raw.each_with_object({}) do |(name, sha), parts|
|
|
579
579
|
name = name.to_s.strip
|
|
580
580
|
unless name.match?(PLUGIN_FILE)
|
|
581
|
-
|
|
581
|
+
message = "plugin parts: #{name.inspect} isn't a .rb file name in the bundle's top directory"
|
|
582
|
+
if name.include?("/") && name.end_with?(".rb")
|
|
583
|
+
message = "#{message}: parts sit next to #{plugin_file} (move #{name} up and list it as #{File.basename(name)})"
|
|
584
|
+
end
|
|
585
|
+
raise ValidationError, message
|
|
582
586
|
end
|
|
583
587
|
raise ValidationError, "plugin parts: #{name} is the plugin file itself" if name == plugin_file
|
|
584
588
|
|