samagotchi 0.176.0 → 0.177.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 +30 -1
- data/docs/cli.md +8 -4
- data/docs/internals/participants.md +2 -1
- data/docs/internals/prompt-caching.md +3 -0
- data/docs/internals/web-frontend.md +18 -5
- data/docs/internals/working-set.md +77 -6
- data/docs/sessions.md +1 -0
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/engine/models.rb +11 -0
- data/lib/samagotchi/engine/session.rb +9 -0
- data/lib/samagotchi/engine.rb +1 -0
- data/lib/samagotchi/engine_snapshots.rb +3 -0
- data/lib/samagotchi/prompt_part.rb +66 -0
- data/lib/samagotchi/session.rb +10 -1
- data/lib/samagotchi/system_prompt.rb +191 -12
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/participant_show.rb +1 -1
- data/lib/samagotchi/web/public/app.js +3 -0
- data/lib/samagotchi/web/public/ctx_tokens.js +33 -0
- data/lib/samagotchi/web/public/index.html +43 -9
- data/lib/samagotchi/web/public/session_fields.js +10 -4
- data/lib/samagotchi/web/public/session_prefs.js +5 -2
- data/lib/samagotchi/web/public/session_state.js +14 -1
- data/lib/samagotchi/web/public/session_store.js +1 -1
- data/lib/samagotchi/web/public/session_view.js +1 -1
- data/lib/samagotchi/web/public/stream_handlers.js +7 -3
- data/lib/samagotchi/web/public/tokens.css +2 -2
- data/lib/samagotchi/web/public/working_set.js +51 -7
- data/lib/samagotchi/web/public/working_set_view.js +188 -58
- data/lib/samagotchi/web/public/ws_sections.js +251 -0
- data/lib/samagotchi/web/session_show.rb +13 -2
- data/lib/samagotchi/worker/command_queue.rb +5 -1
- data/lib/samagotchi/worker/startup.rb +1 -1
- data/lib/samagotchi/worker.rb +1 -0
- data/lib/samagotchi/working_set.rb +32 -4
- data/lib/samagotchi/working_set_command.rb +3 -2
- data/lib/samagotchi/working_set_steer.rb +21 -3
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90399195c08d46ac5fa722766255c24686b727cad1201a90aef486112d4c1143
|
|
4
|
+
data.tar.gz: bb77da3a5486da4fc03f9d81def5a1e12423a831316873ac8bc7c6a907b376aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c26233ce726fb6f646c1e6f3895d9d5f3df9e86a39e81e54a747684b44ba1286a5c59885fbf3f08eac728bcb6a9eb3e5a086eeb0b294ba313c2179401483221e
|
|
7
|
+
data.tar.gz: 2f8c68f82e0a3ea4ab4646f3d37e567fed8c33c1f03404a22c377425058fd2a06632adfcf734a461213ac86180f4299913fba07eb9bae284139e417e624b687f
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,34 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.177.0] - 2026-11-17
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- chi web: the working-set list is now a view of what is in chi's head, in three groups: **From the start** (every
|
|
16
|
+
part of the system prompt, with its size: tools, the base prompt, the identity memory, model notes, preloaded
|
|
17
|
+
memories, AGENTS.md, plugin sections, the memory indexes), **Read in this session** (files, memories and URLs) and
|
|
18
|
+
**Conversation** (the rest of the context). The line under the header says how much is in chi's head now. Each
|
|
19
|
+
group folds, and the fold is kept per session.
|
|
20
|
+
- chi web: the list's turn picker is a lens. Picking a turn (the arrows, a footprint, the rail) keeps the whole list
|
|
21
|
+
and lights the rows that turn touched with its step tags; the rest dim. The line under the header says what the
|
|
22
|
+
turn touched and how many items were new.
|
|
23
|
+
- chi web: a memory that is in the system prompt and was also read again shows "held twice", with the extra size.
|
|
24
|
+
- Sessions record the sizes of their system prompt's parts (`prompt_parts`), which the list above reads.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- chi web: the working-set list's header no longer shows "N items · ctx %"; the line under it does. On the phone the
|
|
29
|
+
header fits on one line, and the list's rows and buttons are 44 px tall.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- chi web: the working-set list includes model notes in the system prompt and redraws an open list when notes change.
|
|
34
|
+
- /working-set add: refuse to re-read a memory already in the system prompt unless its output is in the working set.
|
|
35
|
+
- chi web: a project memory and a system memory with the same name are no longer shown as one row.
|
|
36
|
+
|
|
37
|
+
Update with `chi update`.
|
|
38
|
+
|
|
11
39
|
## [0.176.0] - 2026-11-16
|
|
12
40
|
|
|
13
41
|
### Added
|
|
@@ -6452,7 +6480,8 @@ and long-lived sessions.
|
|
|
6452
6480
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6453
6481
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6454
6482
|
|
|
6455
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6483
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.177.0...HEAD
|
|
6484
|
+
[0.177.0]: https://github.com/dm1try/samagotchi/compare/v0.176.0...v0.177.0
|
|
6456
6485
|
[0.176.0]: https://github.com/dm1try/samagotchi/compare/v0.175.0...v0.176.0
|
|
6457
6486
|
[0.175.0]: https://github.com/dm1try/samagotchi/compare/v0.174.0...v0.175.0
|
|
6458
6487
|
[0.174.0]: https://github.com/dm1try/samagotchi/compare/v0.173.0...v0.174.0
|
data/docs/cli.md
CHANGED
|
@@ -1387,11 +1387,15 @@ session bar shows the `mem N` chip again.
|
|
|
1387
1387
|
tooltip goes too): the session's whole set, preloaded (`--memory`) and muted
|
|
1388
1388
|
(`--mute`) memories included; its dot lights when the set changed since you
|
|
1389
1389
|
last opened it.
|
|
1390
|
-
- **The list** the three open (a bottom sheet on a phone):
|
|
1391
|
-
|
|
1390
|
+
- **The list** the three open (a bottom sheet on a phone): always the whole
|
|
1391
|
+
session's set, files grouped by folder (a group opens in place), memories
|
|
1392
1392
|
(used, preloaded, muted) and URLs, each with what was done to it (`read ×2`,
|
|
1393
|
-
`read, edited`, `preloaded`) and a step tag (`s3`, `
|
|
1394
|
-
|
|
1393
|
+
`read, edited`, `preloaded`) and a step tag (`t2·s3`, `prompt` for a preloaded
|
|
1394
|
+
memory) that goes to the call. The header's `session | ‹ turn N ›` is a lens:
|
|
1395
|
+
the chip opens the session, a footprint or the rail opens a turn, and `‹` `›`
|
|
1396
|
+
step through the turns. In a turn's lens the rows that turn touched are lit,
|
|
1397
|
+
with that turn's words and step tag (`s3`), the others dimmed; the line under
|
|
1398
|
+
the header says `turn 2 touched 3 · 1 new`; a folded group still shows its lit rows. A file opens
|
|
1395
1399
|
as its row's title does, a URL in a new tab. A row (on hover or keyboard
|
|
1396
1400
|
focus) and a folded group offer `drop`, which runs `/working-set drop` (see
|
|
1397
1401
|
`/working-set` above); a dropped row offers `undrop`, and so does one whose
|
|
@@ -537,7 +537,8 @@ fields: a field added to an event later reaches nobody until it is named there.
|
|
|
537
537
|
- **The queue.** Their own queued turns (enqueued id and text, for Take back) and how many others wait.
|
|
538
538
|
- **The working set** (`.working_set`: the event and `GET …/working_set`): the file items inside the project, the
|
|
539
539
|
key made relative, with `state`, `tokens`, `ops`, `count`, `pinned`, and the set's `at`. Never a memory or URL
|
|
540
|
-
item, a path outside the project, `first_id`, `has_drop` or the pending `adds`.
|
|
540
|
+
item, a path outside the project, `first_id`, `has_drop` or the pending `adds`. A memory item's `scope` and the
|
|
541
|
+
prompt parts' `scope` reach no participant either: memory items are dropped and their `prompt_parts` is `[]`.
|
|
541
542
|
|
|
542
543
|
### The main page's show
|
|
543
544
|
|
|
@@ -63,6 +63,9 @@ right-hand column happens.
|
|
|
63
63
|
└──────────────────────────────────────────────────────────────────────────┘
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
- The sections above are recorded as `prompt_parts` (`SystemPrompt#prompt_parts`, `PromptPart`: kind, label, chars,
|
|
67
|
+
tokens at `TokenUsage::CHARS_PER_TOKEN`, ref, a memory part's scope; one per memory, file and plugin section, plus a
|
|
68
|
+
`tools` part): sizes only, worked out once with the build and saved on the session; the prompt's text is unchanged.
|
|
66
69
|
- The system prompt is built **once per key** and kept (`SystemPrompt#build`, keyed by `[chat, thinking, layers]`:
|
|
67
70
|
the loop, the thinking level, the turn's LLM context layers; a `/thinking` change builds under another key). All
|
|
68
71
|
of them are dropped only on `@prompt_builder.reset!`: a model switch (`Engine#switch_model!`), a plugin's
|
|
@@ -29,7 +29,7 @@ page. A factory dep a new version stops passing is the same hazard the other way
|
|
|
29
29
|
out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
|
|
30
30
|
until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
|
|
31
31
|
`turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
|
|
32
|
-
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (Deleting a chained session, below), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
32
|
+
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `delete_sheet.js` (Deleting a chained session, below), `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; the history without its cards and questions, and those as data: the page's `card_registry.js` against one seeded from the read, this turn's entries, a capped read's missing keys skipped), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `card_registry.js` (the open session's cards as data, an observer of the stream's card events and a read's seed: Where state lives), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `participant_history.js` (a participant's ↑/↓ list), `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `session_prefs.js` (a session's own view settings, `<key>:<session>`: Storage keys, below), `ws_sections.js` (the working set's head view: its sections from the prompt's parts, [working-set.md](working-set.md), The head view), `ctx_tokens.js` (the context's token count beside its %: `ctxTokens`, below), `stage_view_memory.js` (what was opened of a running turn, per session, in memory: Where state lives), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
33
33
|
|
|
34
34
|
## One page, every viewer
|
|
35
35
|
|
|
@@ -97,12 +97,22 @@ field only when the payload carries it: `session_payload.js` reads its sources f
|
|
|
97
97
|
(`fieldsFromCard`: owner, workerVersion, workerFeatures, bridgeUp; never status), its redraws (store `ORDER` names)
|
|
98
98
|
and its writers. A new field starts in `emptySessionState` and gets an entry (its spec checks both).
|
|
99
99
|
|
|
100
|
+
A source's `undefined` means "this payload doesn't say", never "none": `promptParts` (the show's `prompt_parts`)
|
|
101
|
+
is the case to copy. A turn end's `?tail=1` re-read from an older live worker leaves the key out, so the page keeps
|
|
102
|
+
the parts it has; only a list (`[]` too) replaces them. `ctxTokens` is the context's token count next to `ctxPct`
|
|
103
|
+
(the working set's "in chi's head now · ~X of Y" and its Conversation row): from the same data (`ctx_tokens.js
|
|
104
|
+
ctxTokensOf`: a `context_status`'s `usage.estimated_used_tokens`, a chunk's `counts.total_tokens`), cleared where
|
|
105
|
+
`ctxPct` is (`usage: null`); on load `loadedCtxTokens` turns the live worker's % back into tokens (against the
|
|
106
|
+
window, or the smaller budget), else the saved `timing.context.used_tokens`. It changes with almost every chunk, so it
|
|
107
|
+
has a redraw of its own, `workingSetTokens` (with `ctxWindow`, the line's "of Y"): `workingSet.tokensChanged()` draws
|
|
108
|
+
the open list only when the text it shows of them changes (the head line, the Conversation row's tokens).
|
|
109
|
+
|
|
100
110
|
A changed value (`!==`) marks its field's redraws; `sessions` marks `lists` and `infoBar` (the bar reads the list:
|
|
101
111
|
the chain's ← → links, the children chip, the archived button, the card's title, the fresh link's picker); `selected`
|
|
102
112
|
marks `paintActive`, `composer` and `infoBar`; `touch(name)` marks one redraw for an input the store doesn't hold
|
|
103
113
|
(the clock, versions, the stream, `liveTurn.running`). They run synchronously, once each, at the end of the outermost
|
|
104
114
|
`batch()` (at once for a bare write), in one `ORDER`: `lists`, `paintActive`, the open panels (`settingsPanel`,
|
|
105
|
-
`workingSetStrategy`), `featureGates`, `composer`, `infoBar`. `lists` comes before
|
|
115
|
+
`workingSetStrategy`, `workingSet`, `workingSetTokens`), `featureGates`, `composer`, `infoBar`. `lists` comes before
|
|
106
116
|
the bar because `updateSessionTitle` reads the strip's active card; `composer` before the bar as `setTurnRunning`
|
|
107
117
|
runs them. Not a rAF (a background tab runs none, and the title badge tests run there; the e2e per-frame checks would
|
|
108
118
|
see the composer move a frame late) and not a microtask (code that reads the page right after a write would see it
|
|
@@ -110,7 +120,8 @@ stale).
|
|
|
110
120
|
|
|
111
121
|
**The redraws are registered, not called.** app.js registers each name once (`store.on`, at the bottom, once every
|
|
112
122
|
piece a redraw calls exists): `lists` → `lists.render()`, `paintActive` → `lists.paintActive()`, `settingsPanel` →
|
|
113
|
-
`settingsControl.refresh()`, `workingSetStrategy` → `workingSet.strategyChanged()`, `
|
|
123
|
+
`settingsControl.refresh()`, `workingSetStrategy` → `workingSet.strategyChanged()`, `workingSet` →
|
|
124
|
+
`workingSet.sessionChanged()`, `workingSetTokens` → `workingSet.tokensChanged()`, `featureGates` (below), `composer` →
|
|
114
125
|
`composerMode.update()` (`composer_mode.js`), `infoBar` → `updateInfoBar()`. A writer writes and stops there: no `updateInfoBar()` after
|
|
115
126
|
a store write. A value written unchanged redraws nothing (a chunk with the same ctx %).
|
|
116
127
|
|
|
@@ -693,18 +704,20 @@ reach another device or the server.
|
|
|
693
704
|
| `chi_strip_hidden` (`chi_zen`: the old name, read once) | `strip_hidden.js` | the session strip hidden |
|
|
694
705
|
| `chi_stage_collapsed:<session>` | `stage_asking.js` (through `session_prefs.js`) | the session's stage collapsed or opened by hand (not written from the asking form, whose fold is that question's only); none: the page's default, `<body data-stage-collapsed="1">` (`web.stage_collapsed`), else open |
|
|
695
706
|
| `chi_working_set_collapsed:<session>` | `working_set_rail.js` (through `session_prefs.js`) | the session's working set rail collapsed |
|
|
707
|
+
| `chi_ws_sections_folded:<session>` | `working_set_view.js` (through `session_prefs.js`; the key is `ws_sections.js WS_SECTION_FOLD`) | the working-set list's sections folded by hand, a JSON list of keys (`start`, `read`, `talk`); none: all open |
|
|
696
708
|
| `chi_markdown_tip_dismissed` | `markdown_tip.js` | the markdown tip dismissed |
|
|
697
709
|
| `chi_update_available_shown` | `version_notices.js` | update notices already shown |
|
|
698
710
|
| `chi_notify`, `chi_push_device` | `notifications.js` (an injected storage) | the bell's state, this device's push id |
|
|
699
711
|
| `chi_answer_fold:<session>` | `answer_fold.js`, `revise_stack.js` | the answers and long prompts (`<turn id>:prompt`) folded by hand, and the Revise stubs unfolded by hand (`stub:<turn id>`) (swept with the session list) |
|
|
700
712
|
|
|
701
|
-
**A session's view settings** (`session_prefs.js`): the
|
|
713
|
+
**A session's view settings** (`session_prefs.js`): the five `<key>:<session>` keys above (the fifth's name is
|
|
714
|
+
defined in `ws_sections.js`, a new module, so `session_prefs.js` exports nothing new: the mixed-cache rule). `read(key, session)` is the
|
|
702
715
|
session's own value, else the page's default (only the stage fold has one: `web.stage_collapsed` on `<body>`), else
|
|
703
716
|
the module's; `write(key, session, value)` writes the session's key only; with no session (the start page) the value
|
|
704
717
|
stays in memory until a reload. Each module reads its value again when a session's view is drawn (`session_view.js
|
|
705
718
|
applyPrefs`: at the end of `forgetSession`, so on a select once the new session is set, and at the start of each
|
|
706
719
|
`renderSessionView`): `stage_view.js applyPrefs` (the stage's fold, `stage_asking.js reloadChoice`, and the rail's),
|
|
707
|
-
`composer_mount.js applyPrefs` (the floor; the fold is read at each call). One sweep for the
|
|
720
|
+
`composer_mount.js applyPrefs` (the floor; the fold is read at each call). The list's section folds are read at each draw. One sweep for the five
|
|
708
721
|
(`sweepSessionPrefs`, app.js `sweepFoldsOnce`, next to `sweepAnswerFolds`): only on an unscoped list, since these keys
|
|
709
722
|
hold no project root. The old page-wide keys (`chi_stage_collapsed`, `chi_composer_floor`, `chi_composer_collapsed`,
|
|
710
723
|
`chi_working_set_collapsed`, no `:<session>`) are no longer read or written, and left in storage as they were.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# The working set: what the model really has
|
|
2
2
|
|
|
3
3
|
The stage view's working set (`web.working_set`, [cli.md](../cli.md#the-working-set)) shows the files, memories
|
|
4
|
-
and URLs a session's tool runs brought into the model's context
|
|
4
|
+
and URLs a session's tool runs brought into the model's context, and model notes carried in the system prompt as
|
|
5
|
+
`prompt` rows. The page builds the set itself from its tool rows
|
|
5
6
|
(`working_set.js`, phase 1). The server says what the model still has of each item: **live**, **stale** (a file
|
|
6
7
|
changed since the model last saw it) or **forgotten** (nothing of it is still sent), and its size in tokens. This
|
|
7
8
|
page covers the server's side and how the page overlays it.
|
|
@@ -49,8 +50,13 @@ is pure and returns a `WorkingSet::Snapshot` (`items`, `at`: the conversation's
|
|
|
49
50
|
key). Each `WorkingSet::Item` is `kind` (`file`, `memory`, `url`), `key`, `state` (`live`, `stale`, `forgotten`,
|
|
50
51
|
`dropped`), `tokens`, `ops`, `count`,
|
|
51
52
|
`first_id` (the first run's ToolIds id), `pinned` (the session's `working_set_pins` name it, whatever the
|
|
52
|
-
strategy: the page shows the mark only under forget, so a switch shows it at once)
|
|
53
|
-
outputs holds the user's applied drop, whatever the state: an undrop has something to take back)
|
|
53
|
+
strategy: the page shows the mark only under forget, so a switch shows it at once), `has_drop` (any of its content
|
|
54
|
+
outputs holds the user's applied drop, whatever the state: an undrop has something to take back) and, for a memory,
|
|
55
|
+
`scope`: the scope its latest `memory_read` answered from (the memory stamp's file, as `MemoryPart#scope` reads it;
|
|
56
|
+
`memory_item_scope`, no text read), in `to_h` only when known (nil for a memory only written, or read before memory
|
|
57
|
+
stamps). Cost: one field per memory item, from the stamp lookup the stale check makes anyway. Known limit: the set
|
|
58
|
+
has one item per memory name, so a session that read both a project `x` and a system `x` has one item carrying the
|
|
59
|
+
latest read's scope. The Engine's event and the GET
|
|
54
60
|
both pass the session's pins.
|
|
55
61
|
|
|
56
62
|
**Runs.** It pairs the runs twice with `LLMContextStale.paired_runs`: once on the stored conversation, once on what
|
|
@@ -220,9 +226,11 @@ projection), on both loops. It costs one model step; a model may skip it (the no
|
|
|
220
226
|
- **`WorkingSetSteer.add`** refuses an item already added (pending), a URL not http(s) (`web_fetch` fetches only
|
|
221
227
|
those), what the caller's `found` look says can't be read (`WorkingSetCommand#missing`: a file not there or a
|
|
222
228
|
directory; a memory name `memory_read` rejects or that neither scope holds), an item holding the user's drop
|
|
223
|
-
(`undrop_first`: undrop brings it back without a step),
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
(`undrop_first`: undrop brings it back without a step), one already in the system prompt and with no working-set
|
|
230
|
+
output (`in_prompt`: nothing to add), and one the model has whole (`already_sent`: live, a read of it sent). The
|
|
231
|
+
prompt-only refusal doesn't apply when the set holds a read of that memory: a stale or forgotten item may still be
|
|
232
|
+
added as the web row's `refresh`. **`unadd`** takes a pending add back (free); without one it is refused
|
|
233
|
+
(`not_added`).
|
|
226
234
|
- **The note**: an add always joins it (`the user added lib/tax.rb, memory style to your context: before anything
|
|
227
235
|
else, load them with read "/abs/lib/tax.rb", memory_read "style"`); a file is named by its absolute path in the
|
|
228
236
|
call, since a `read` resolves a relative path against the process's folder. An unadd cancels its add there.
|
|
@@ -316,6 +324,69 @@ passes `working_set_updated` to it, and does nothing when the flag is off. A new
|
|
|
316
324
|
`details_motion.js` skips `.ws-foot`, and `footClick` cancels the click;
|
|
317
325
|
- the rail (`onServer`, the stage's `scheduleRefresh`).
|
|
318
326
|
|
|
327
|
+
**The list's lens.** The expanded list is always the session's set (`sessionSet()`), seen through a lens: `null`
|
|
328
|
+
(the session) or a turn's index (`createWorkingSet`'s `lens`). The chip (and the reader's `‹ Set`, `openList`) opens the
|
|
329
|
+
session lens; a footprint (`footClick`) and the rail (`openTurn`) open the lens on their turn. In a turn lens
|
|
330
|
+
(`working_set.js turnLens`, `lensItem`) the rows the turn touched are `lit` and the rest `dim` (`opacity:
|
|
331
|
+
var(--ws-lens-dim)`, a `:root` token in both palettes). A lit row is the session item's state, tokens and actions with
|
|
332
|
+
the turn item's `at`, ops and count (its step tag is the turn's, `s3`; a dimmed row keeps the session's, `t1·s3`): the
|
|
333
|
+
turn item is passed through, the session item is never overwritten. The header's `session | ‹ turn N ›` steps over the
|
|
334
|
+
finished turns and the running one (`lastTurn()`), `‹` and `›` disabled at the ends; the line under it reads "turn N
|
|
335
|
+
touched A · B new" (new: the session set's first `at` is this turn's, a prompt memory never). A folded inner group
|
|
336
|
+
(`labelsTemplate`) shows its lit members while folded. A new seed that leaves the lens past the last turn, or a reset
|
|
337
|
+
that drops the running turn, puts it back to the session.
|
|
338
|
+
|
|
339
|
+
**The head view: sections** (`ws_sections.js headSections`, drawn by `working_set_view.js headTemplate`). With the
|
|
340
|
+
session's `prompt_parts` (the worker's sizes of its system prompt; `promptParts` on the page) the list is what is in
|
|
341
|
+
chi's head, in three sections:
|
|
342
|
+
- **From the start** (`start`): every part in prompt order, the tools part first. A memory part (identity, a model
|
|
343
|
+
note, a preload) IS a memory row: merged with the session set's rows of the same memory, else a row of its own
|
|
344
|
+
(identity: the set never lists it). **The match is scope + name** (`same`): the names match (`memoryName`, which
|
|
345
|
+
also reads an older page's preloaded `system/x` as `x`) and so do the scopes (the part's `scope`, the item's from the
|
|
346
|
+
server, `overlay`); a scope either side lacks (an older worker's part or item, an item the server hasn't stamped)
|
|
347
|
+
matches by name alone, as before scopes. So a project `x` read beside a system `x` in the prompt is two rows: the
|
|
348
|
+
read stays in Read as a plain read (not "prompt", never held twice), and the part's own row gets the key `x@system`
|
|
349
|
+
(no collision with the read's `x`), its words its scope ("preloaded · system") and, like identity's, no actions or
|
|
350
|
+
peek. A note and a preload of one name and scope stay one row with both sizes; of two scopes, two rows. The start
|
|
351
|
+
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
|
|
352
|
+
droppable or pinnable until read). Its tokens are the part's, plus `+X` for the read's (the item's server tokens: a
|
|
353
|
+
preloaded row carries none of its own, so the two never double-count). Other parts are read-only `part` rows: a
|
|
354
|
+
label, a sub (the tools part's "N declared"; dropped on a phone), `~tokens`, no actions, no peek; a turn lens dims
|
|
355
|
+
them.
|
|
356
|
+
- **Read in this session** (`read`): today's files / memories / urls folds (`bodySections`), minus the memories the
|
|
357
|
+
start section shows. Its meta: held (not struck) and out (forgotten or dropped); its tokens the held items'.
|
|
358
|
+
- **Conversation** (`talk`): one row at section level, "Conversation · N turns ~X" (`headSections` still returns the
|
|
359
|
+
section; `headTemplate` draws it headerless, no fold; never lit, so dim in a turn lens),
|
|
360
|
+
`ctxTokens − Σ parts − Σ held items' tokens` (the read
|
|
361
|
+
section's and the start memories' reads), shown only when `ctxTokens` is known and the rest is > 0. Mixed units,
|
|
362
|
+
accepted: parts and items are chars/4, `ctxTokens` the server's count or chi's estimate (which on a chat host leaves
|
|
363
|
+
the tool schemas out, so without server usage the rest can go negative and the row hides); the "~" says so.
|
|
364
|
+
|
|
365
|
+
**Held twice.** A start memory row whose ops include `read` is held twice: in the prompt and in a read's output. The
|
|
366
|
+
session lens tags it `held twice` (warn tokens); a turn lens whose items read it lights it amber with a note under it:
|
|
367
|
+
"read again in this turn: already in the prompt, held twice (+X)". A lens lights a merged row by any of its merged
|
|
368
|
+
keys (`lensTouched`), and a part-only start row (no merged item, e.g. `x@system`) by its bare name too: a turn's rows
|
|
369
|
+
come from tool titles, which carry no scope, so in a turn lens a project `x` read lights a system `x`'s own row (lit,
|
|
370
|
+
not held twice: that row holds no read). A row with a merged item lights by its items' keys only. A turn lens counts
|
|
371
|
+
new over `headItems` (the set as the head view sees it: another scope's read is a plain read, not the prompt's), so a
|
|
372
|
+
project `x` first read beside a system `x` preload is new. It never counts a prompt memory as new (`promptKeys`, out of `turnLens`'s list). A forget or a
|
|
373
|
+
drop strikes the row where it stands (today's state words); the server knows an item's state now, not the turn that
|
|
374
|
+
changed it, so a turn lens has no forget count.
|
|
375
|
+
|
|
376
|
+
**Section folds.** Each section header folds (`data-ws="section"`), per session (`chi_ws_sections_folded:<session>`,
|
|
377
|
+
`session_prefs.js`); none stored: all open. Conversation has no header to fold: a stored `talk` (an older page's) is
|
|
378
|
+
ignored (`foldedSections`) and the next toggle writes the list without it. Folded, a section shows only the rows the lens lights (the read section's
|
|
379
|
+
lit members flat, without their inner groups). The header carries no size (the name, the lens, the ring
|
|
380
|
+
and ×: one line on a phone at 390 px); the line under it does. The session lens's: "in chi's head now · ~X of Y"
|
|
381
|
+
(`headLine`: X `ctxTokens`, Y the window; no "of Y" without one). Without parts or without `ctxTokens` that line is
|
|
382
|
+
the size line instead, "N items · ctx N %" (`.ws-size-line`), so the list never lacks a size; a turn lens has its
|
|
383
|
+
touched line only. The tokens-change check (`tokenText`) compares both lines' text. On a phone's sheet rows, section
|
|
384
|
+
headers and the lens buttons are 44 px targets.
|
|
385
|
+
|
|
386
|
+
**No parts** (an old session file, a worker before `prompt_parts`, a participant's list: `[]`): `headSections` is
|
|
387
|
+
null and the list is the flat files / memories / urls one with the lens unchanged. A turn end's `?tail=1` from an
|
|
388
|
+
older live worker leaves the key out: the page keeps the parts it has (`session_fields.js`: unknown is not none).
|
|
389
|
+
|
|
319
390
|
A state is the item's state now, not when its turn ran. A state change never refolds and never moves a line: the
|
|
320
391
|
rail's line key carries the label's state and its forgotten count, which are patched in place.
|
|
321
392
|
|
data/docs/sessions.md
CHANGED
|
@@ -141,6 +141,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
141
141
|
| `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 |
|
|
142
142
|
| `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 |
|
|
143
143
|
| `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 |
|
|
144
|
+
| `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 |
|
|
144
145
|
| `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 |
|
|
145
146
|
| `scratch` | A `chi scratch` session, deleted when its terminal leaves. | creation |
|
|
146
147
|
| `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/lib/samagotchi/bridge.rb
CHANGED
|
@@ -1177,11 +1177,11 @@ module Samagotchi
|
|
|
1177
1177
|
raise IntakeClosed if stopped?
|
|
1178
1178
|
next :expired if expired?("exit_expired", deadline, sid: session_id, client_id: client_id)
|
|
1179
1179
|
|
|
1180
|
-
|
|
1180
|
+
accepted = @on_exit_request.call(client_id, **options)
|
|
1181
1181
|
# Read here, right after the accept: every accept runs with the log
|
|
1182
1182
|
# held, so no later exit's list can be the one this 200 carries.
|
|
1183
|
-
stopped = @exit_stopped&.call if
|
|
1184
|
-
next
|
|
1183
|
+
stopped = @exit_stopped&.call if accepted.nil? && !restart
|
|
1184
|
+
next accepted
|
|
1185
1185
|
end
|
|
1186
1186
|
return deadline_passed("exit request") if hold == :expired
|
|
1187
1187
|
|
|
@@ -81,6 +81,16 @@ module Samagotchi
|
|
|
81
81
|
end
|
|
82
82
|
private :record_prompt_notes
|
|
83
83
|
|
|
84
|
+
# Records +parts+ (PromptPart) on the session as the sizes of the
|
|
85
|
+
# prompt's parts; saved with it. A switch records [] (the old model's
|
|
86
|
+
# parts are not the new one's; the next build records its own; a build
|
|
87
|
+
# in flight on another thread may still record the old ones, as
|
|
88
|
+
# prompt_notes may).
|
|
89
|
+
def record_prompt_parts(parts)
|
|
90
|
+
@session.prompt_parts = Array(parts) if @session
|
|
91
|
+
end
|
|
92
|
+
private :record_prompt_parts
|
|
93
|
+
|
|
84
94
|
# A failed turn's one line (the error's #summary). A host's failure
|
|
85
95
|
# under an alias says what the alias became (HostRegistry#alias_note):
|
|
86
96
|
# "host main" alone doesn't tell --model splash's user it was splash.
|
|
@@ -174,6 +184,7 @@ module Samagotchi
|
|
|
174
184
|
# The notes the new model's prompt loads at its next build, so /model,
|
|
175
185
|
# /stats and the web name them before the next turn does.
|
|
176
186
|
record_prompt_notes(model_notes) if @session
|
|
187
|
+
record_prompt_parts([])
|
|
177
188
|
sync_kernel_client!
|
|
178
189
|
@client.invalidate_context_window!
|
|
179
190
|
@metrics.forget_model_reports!
|
|
@@ -22,6 +22,13 @@ module Samagotchi
|
|
|
22
22
|
@muted_memory_names.dup
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# @return [Array<String>] sorted, deduped names the prompt carries or
|
|
26
|
+
# will carry on a fresh session
|
|
27
|
+
def prompt_memory_names
|
|
28
|
+
names = Array(@prompt_builder.prompt_memory_names) + Array(prompt_notes).map(&:name)
|
|
29
|
+
names.map { |name| name.to_s.strip }.reject(&:empty?).uniq.sort
|
|
30
|
+
end
|
|
31
|
+
|
|
25
32
|
# @return [Array<String>] the names the session preloads (config baseline
|
|
26
33
|
# + --memory, minus mutes), known before the prompt is built, unlike
|
|
27
34
|
# #activated_memory_names
|
|
@@ -72,6 +79,8 @@ module Samagotchi
|
|
|
72
79
|
@metrics.memory_index = @prompt_builder.memory_index
|
|
73
80
|
# The model notes it carries: the session records them (/stats, /model, the web).
|
|
74
81
|
record_prompt_notes(@prompt_builder.prompt_notes)
|
|
82
|
+
# And the sizes of its parts (PromptPart), for the web's head view.
|
|
83
|
+
record_prompt_parts(@prompt_builder.prompt_parts)
|
|
75
84
|
prompt
|
|
76
85
|
end
|
|
77
86
|
|
data/lib/samagotchi/engine.rb
CHANGED
|
@@ -95,6 +95,7 @@ require_relative "model_binding"
|
|
|
95
95
|
require_relative "model_overlay"
|
|
96
96
|
require_relative "model_notes"
|
|
97
97
|
require_relative "prompt_note"
|
|
98
|
+
require_relative "prompt_part"
|
|
98
99
|
require_relative "served_model"
|
|
99
100
|
require_relative "image_store"
|
|
100
101
|
require_relative "vision_context"
|
|
@@ -124,6 +124,8 @@ module Samagotchi
|
|
|
124
124
|
# :used_memory_names [Array<String>] deduped memory names active this session
|
|
125
125
|
# :prompt_notes [Array<Hash>] the model notes the prompt carried
|
|
126
126
|
# ({name:, scope:, chars:, digest:}; #prompt_notes)
|
|
127
|
+
# :prompt_parts [Array<Hash>] the sizes of the prompt's parts
|
|
128
|
+
# ({kind:, label:, chars:, tokens:, ref:, scope:?}; Session#prompt_parts)
|
|
127
129
|
# :parent_id [String, nil] the session that delegated this one
|
|
128
130
|
# :model_name [String] the model turns run on now (after /model)
|
|
129
131
|
# :served_model, :served_model_for [String, nil] what a generation of
|
|
@@ -153,6 +155,7 @@ module Samagotchi
|
|
|
153
155
|
preloaded_memory_names: preloaded_memory_names,
|
|
154
156
|
muted_memory_names: muted.dup,
|
|
155
157
|
prompt_notes: prompt_notes.map(&:to_h),
|
|
158
|
+
prompt_parts: Array(session&.prompt_parts).map(&:to_h),
|
|
156
159
|
parent_id: session&.parent_id,
|
|
157
160
|
title: session&.title,
|
|
158
161
|
model_name: effective_model_ref,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "token_usage"
|
|
4
|
+
|
|
5
|
+
module Samagotchi
|
|
6
|
+
# One part of a session's system prompt, as its size: what the session
|
|
7
|
+
# file's `prompt_parts` records at each prompt build and the web's head view
|
|
8
|
+
# draws (the text itself is not kept). kind: a SystemPrompt::KINDS word, or
|
|
9
|
+
# "tools" (the tool declarations, wherever the model gets them); label: what
|
|
10
|
+
# the row says ("AGENTS.md", "N declared"); chars: the part's length in the
|
|
11
|
+
# prompt (a multi-item section's headings and joins are in its first part,
|
|
12
|
+
# so a section's parts sum to its text); tokens: chars at TokenUsage's one
|
|
13
|
+
# ratio; ref: the bare memory name (identity, notes, preloads), the file
|
|
14
|
+
# path (agents, appended), "bundle/name" (plugins), the scope (indexes),
|
|
15
|
+
# else nil; scope: a memory part's scope, "project" or "system" (identity:
|
|
16
|
+
# system; a note: its own; a preload: the scope that answered), so the
|
|
17
|
+
# page tells a project x from a system x; nil for other kinds and in a
|
|
18
|
+
# file written before it (the page then matches by name alone).
|
|
19
|
+
PromptPart = Data.define(:kind, :label, :chars, :tokens, :ref, :scope) do
|
|
20
|
+
def initialize(kind:, label:, chars:, tokens:, ref: nil, scope: nil)
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# A part of +chars+ characters, its tokens counted by the one ratio.
|
|
25
|
+
def self.build(kind:, label:, chars:, ref: nil, scope: nil)
|
|
26
|
+
new(kind: kind.to_s, label: label.to_s, chars: chars, tokens: tokens_for(chars), ref: ref&.to_s, scope: scope&.to_s)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @return [Integer] the tokens +chars+ characters count as
|
|
30
|
+
def self.tokens_for(chars) = (chars / TokenUsage::CHARS_PER_TOKEN).ceil
|
|
31
|
+
|
|
32
|
+
# A saved or wire record (string or symbol keys); nil without a kind.
|
|
33
|
+
def self.from_h(raw)
|
|
34
|
+
return raw if raw.is_a?(PromptPart)
|
|
35
|
+
return nil unless raw.is_a?(Hash)
|
|
36
|
+
|
|
37
|
+
get = ->(key) { raw.key?(key.to_s) ? raw[key.to_s] : raw[key] }
|
|
38
|
+
kind = get.call(:kind).to_s.strip
|
|
39
|
+
return nil if kind.empty?
|
|
40
|
+
|
|
41
|
+
chars = get.call(:chars)
|
|
42
|
+
chars = chars.is_a?(Numeric) ? chars.to_i : 0
|
|
43
|
+
tokens = get.call(:tokens)
|
|
44
|
+
new(kind: kind, label: get.call(:label).to_s, chars: chars,
|
|
45
|
+
tokens: tokens.is_a?(Numeric) ? tokens.to_i : tokens_for(chars), ref: get.call(:ref)&.to_s,
|
|
46
|
+
scope: get.call(:scope)&.to_s)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The records of a saved list (others dropped).
|
|
50
|
+
# @return [Array<PromptPart>]
|
|
51
|
+
def self.list(raw)
|
|
52
|
+
Array(raw).filter_map { |entry| from_h(entry) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# The record (the wire's, the file's): without scope when it has none,
|
|
56
|
+
# so a part that has no scope reads as an older chi wrote it.
|
|
57
|
+
def to_h
|
|
58
|
+
hash = super
|
|
59
|
+
hash.delete(:scope) if scope.nil?
|
|
60
|
+
hash
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# The session file's record (string keys).
|
|
64
|
+
def to_file = to_h.transform_keys(&:to_s)
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/samagotchi/session.rb
CHANGED
|
@@ -17,6 +17,7 @@ require_relative "toolkit"
|
|
|
17
17
|
require_relative "session_config"
|
|
18
18
|
require_relative "session_setup"
|
|
19
19
|
require_relative "prompt_note"
|
|
20
|
+
require_relative "prompt_part"
|
|
20
21
|
require_relative "working_set_pin"
|
|
21
22
|
require_relative "session_review"
|
|
22
23
|
require_relative "session_field"
|
|
@@ -182,6 +183,10 @@ module Samagotchi
|
|
|
182
183
|
# Engine at each build (a start, a resume's or a woken worker's first
|
|
183
184
|
# turn, /model) and saved, so what a session ran with can be read later.
|
|
184
185
|
SessionField.list("prompt_notes") { PromptNote },
|
|
186
|
+
# The sizes of the parts that prompt was made of (Array<PromptPart>:
|
|
187
|
+
# kind, label, chars, tokens, ref), recorded with prompt_notes; the web's
|
|
188
|
+
# head view lists them. An older file has none: [].
|
|
189
|
+
SessionField.list("prompt_parts") { PromptPart },
|
|
185
190
|
# The session that delegated this one (the `delegate` tool) or that a
|
|
186
191
|
# plugin forked it from (ctx.sessions.fork), else nil.
|
|
187
192
|
# Set before the spawn and kept on respawns, like preloaded_memory_names.
|
|
@@ -314,13 +319,17 @@ module Samagotchi
|
|
|
314
319
|
|
|
315
320
|
# The value objects' readers and writers: a writer reads its value as
|
|
316
321
|
# its FIELDS row does (a file's Hash, the object itself; nil is none).
|
|
317
|
-
attr_reader :prompt_notes, :pending_question, :last_turn, :interrupted_turn, :toolkit, :review, :verify_fresh,
|
|
322
|
+
attr_reader :prompt_notes, :prompt_parts, :pending_question, :last_turn, :interrupted_turn, :toolkit, :review, :verify_fresh,
|
|
318
323
|
:working_set_pins
|
|
319
324
|
|
|
320
325
|
def prompt_notes=(value)
|
|
321
326
|
@prompt_notes = load_field("prompt_notes", value)
|
|
322
327
|
end
|
|
323
328
|
|
|
329
|
+
def prompt_parts=(value)
|
|
330
|
+
@prompt_parts = load_field("prompt_parts", value)
|
|
331
|
+
end
|
|
332
|
+
|
|
324
333
|
def pending_question=(value)
|
|
325
334
|
@pending_question = load_field("pending_question", value)
|
|
326
335
|
end
|