samagotchi 0.180.0 → 0.181.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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -1
  3. data/bin/chi +10 -0
  4. data/docs/architecture.md +1 -1
  5. data/docs/bundles.md +7 -2
  6. data/docs/cli.md +16 -9
  7. data/docs/configuration.md +24 -4
  8. data/docs/internals/anthropic.md +4 -3
  9. data/docs/internals/background-tasks.md +2 -0
  10. data/docs/internals/block-renderers.md +9 -6
  11. data/docs/internals/objectives.md +9 -4
  12. data/docs/internals/web-frontend.md +67 -7
  13. data/docs/internals/working-set.md +24 -5
  14. data/docs/memory.md +3 -0
  15. data/docs/plugins.md +11 -4
  16. data/docs/sessions.md +1 -1
  17. data/docs/testing.md +1 -1
  18. data/lib/samagotchi/bundle_command.rb +4 -1
  19. data/lib/samagotchi/bundles/known-names/manifest.yml +2 -2
  20. data/lib/samagotchi/bundles/known-names/plugin.rb +4 -3
  21. data/lib/samagotchi/bundles/system/config_modification_protocol.md +3 -2
  22. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  23. data/lib/samagotchi/client.rb +8 -1
  24. data/lib/samagotchi/config.rb +6 -1
  25. data/lib/samagotchi/core_notice.rb +44 -0
  26. data/lib/samagotchi/host_address.rb +7 -0
  27. data/lib/samagotchi/host_config.rb +8 -5
  28. data/lib/samagotchi/host_registry.rb +26 -8
  29. data/lib/samagotchi/kernel_loop.rb +3 -2
  30. data/lib/samagotchi/llm/adapter_common.rb +3 -2
  31. data/lib/samagotchi/llm/adapters.rb +2 -1
  32. data/lib/samagotchi/llm/anthropic_assembly.rb +5 -0
  33. data/lib/samagotchi/llm/anthropic_messages.rb +6 -2
  34. data/lib/samagotchi/llm/chat_loop.rb +6 -5
  35. data/lib/samagotchi/llm/errors.rb +41 -3
  36. data/lib/samagotchi/llm/http.rb +85 -22
  37. data/lib/samagotchi/llm/openai_chat.rb +20 -3
  38. data/lib/samagotchi/memory_bundle/status.rb +2 -1
  39. data/lib/samagotchi/objectives.rb +7 -2
  40. data/lib/samagotchi/owner_lock.rb +2 -0
  41. data/lib/samagotchi/plugin/api.rb +4 -1
  42. data/lib/samagotchi/plugin/context.rb +9 -0
  43. data/lib/samagotchi/plugin/peer.rb +32 -15
  44. data/lib/samagotchi/plugin/tool_spec.rb +13 -2
  45. data/lib/samagotchi/row_refs.rb +14 -3
  46. data/lib/samagotchi/session_chain/delete.rb +6 -6
  47. data/lib/samagotchi/session_manager/removal.rb +2 -2
  48. data/lib/samagotchi/tool_ids.rb +19 -0
  49. data/lib/samagotchi/tool_runner.rb +8 -4
  50. data/lib/samagotchi/tools/registry.rb +3 -2
  51. data/lib/samagotchi/tools/task_runtime.rb +34 -0
  52. data/lib/samagotchi/turn_stages/objectives.rb +10 -5
  53. data/lib/samagotchi/version.rb +1 -1
  54. data/lib/samagotchi/web/public/app.js +10 -14
  55. data/lib/samagotchi/web/public/block_host.js +20 -20
  56. data/lib/samagotchi/web/public/block_renderers.css +5 -5
  57. data/lib/samagotchi/web/public/context_chips.js +3 -4
  58. data/lib/samagotchi/web/public/images.js +1 -1
  59. data/lib/samagotchi/web/public/index.html +24 -5
  60. data/lib/samagotchi/web/public/objectives_strip.js +16 -6
  61. data/lib/samagotchi/web/public/pan_zoom.js +121 -0
  62. data/lib/samagotchi/web/public/peer_chip.js +3 -3
  63. data/lib/samagotchi/web/public/peer_data.js +27 -15
  64. data/lib/samagotchi/web/public/picture_viewer.js +304 -0
  65. data/lib/samagotchi/web/public/popover_modal.js +3 -2
  66. data/lib/samagotchi/web/public/session_view.js +4 -0
  67. data/lib/samagotchi/web/public/working_set.js +9 -3
  68. data/lib/samagotchi/web/public/working_set_view.js +28 -11
  69. data/lib/samagotchi/web/public/ws_cards.js +36 -10
  70. data/lib/samagotchi/web/public/ws_markdown.js +129 -0
  71. data/lib/samagotchi/web/public/ws_order.js +48 -0
  72. data/lib/samagotchi/web/public/ws_peek.js +22 -5
  73. data/lib/samagotchi/web/public/ws_preview.css +41 -1
  74. data/lib/samagotchi/web/public/ws_reader.js +35 -6
  75. data/lib/samagotchi/web/public/ws_sections.js +24 -15
  76. metadata +6 -1
@@ -1,5 +1,6 @@
1
1
  // The working set's head view (docs/internals/working-set.md, The head
2
- // view): the popover's list as what is in chi's head, in three sections.
2
+ // view): the popover's list as what is in chi's head, in three sections,
3
+ // drawn in this order: read, talk, start (folded until the user opens it).
3
4
  // start From the start: the system prompt's parts (the session's
4
5
  // prompt_parts), in prompt order, the tools part first. A memory
5
6
  // part (identity, a model note, a preload) IS a memory row: merged
@@ -10,7 +11,9 @@
10
11
  // `x@system`, no actions). Other parts are `part` rows: a label, a
11
12
  // sub, their tokens, no actions.
12
13
  // read Read in this session: today's files / memories / urls sections
13
- // (working_set.js bodySections), minus the memories shown in start.
14
+ // (working_set.js bodySections), minus the memories shown in start,
15
+ // in the order of the set given (the view's: last touched first,
16
+ // ws_order.js).
14
17
  // talk Conversation: one row (drawn at section level, no header, no
15
18
  // fold), the rest of the context: the context's
16
19
  // tokens minus the parts' and the held items'. Mixed units (parts and
@@ -25,9 +28,11 @@
25
28
  import { bodySections, itemKey, tokensText } from "./working_set.js";
26
29
 
27
30
  // The sections folded by hand, per session (session_prefs.js): a JSON list
28
- // of section keys. None: all open.
31
+ // of section keys. None stored: start folded (DEFAULT_FOLDED).
29
32
  export const WS_SECTION_FOLD = "chi_ws_sections_folded";
30
33
 
34
+ const DEFAULT_FOLDED = Object.freeze(["start"]);
35
+
31
36
  export const MEMORY_PARTS = Object.freeze(["identity", "notes", "preloads"]);
32
37
 
33
38
  // What a memory part's row says it is.
@@ -118,7 +123,8 @@ export function heldTwiceNote(row, turnItem) {
118
123
  // overlaid), or null without parts (today's list). +parts+: the session's
119
124
  // prompt_parts; +ctxTokens+: the context's tokens now (null: unknown);
120
125
  // +turns+: how many turns the session has (the conversation row's).
121
- // @return [{key, title, meta, tokens, rows?, inner?}] start, read, talk?
126
+ // @return [{key, title, meta, tokens, rows?, inner?, twice?}] read, talk?, start
127
+ // (start's +twice+: how many of its rows are held twice)
122
128
  export function headSections(set, budget, { parts = null, ctxTokens = null, turns = 0, inTurn = false } = {}) {
123
129
  if (!Array.isArray(parts) || !parts.length) return null;
124
130
  const { rows, used, partNames } = startRows(set, parts);
@@ -136,18 +142,19 @@ export function headSections(set, budget, { parts = null, ctxTokens = null, turn
136
142
  // into the conversation's arithmetic, not into either section.
137
143
  const readTokens = sum(readItems.filter(held), (i) => i.tokens);
138
144
  const heldTokens = readTokens + sum(rows.filter(readHeld), (r) => r.tokens);
139
- const sections = [
140
- { key: "start", title: "From the start", meta: inTurn ? "in every turn" : `${rows.length} part${rows.length === 1 ? "" : "s"} · in every turn`, tokens: partsTokens, rows },
141
- {
142
- key: "read", title: "Read in this session", meta: [`${readItems.filter(held).length} held`, out ? `${out} out` : ""].filter(Boolean).join(" · "),
143
- tokens: readTokens, inner: bodySections(rest, budget),
144
- },
145
- ];
145
+ const sections = [{
146
+ key: "read", title: "Read in this session", meta: [`${readItems.filter(held).length} held`, out ? `${out} out` : ""].filter(Boolean).join(" · "),
147
+ tokens: readTokens, inner: bodySections(rest, budget),
148
+ }];
146
149
  const talk = Number.isFinite(ctxTokens) ? ctxTokens - partsTokens - heldTokens : NaN;
147
150
  if (talk > 0) {
148
151
  const row = { kind: "talk", key: "conversation", label: "conversation", sub: `${turns} turn${turns === 1 ? "" : "s"}`, partTokens: talk, ops: [], at: null, count: 0, state: "live" };
149
152
  sections.push({ key: "talk", title: "Conversation", meta: "", tokens: talk, rows: [row] });
150
153
  }
154
+ sections.push({
155
+ key: "start", title: "From the start", meta: inTurn ? "in every turn" : `${rows.length} part${rows.length === 1 ? "" : "s"} · in every turn`, tokens: partsTokens, rows,
156
+ twice: rows.filter(heldTwice).length,
157
+ });
151
158
  return sections;
152
159
  }
153
160
 
@@ -232,14 +239,16 @@ export function lensTouched(sections, touched) {
232
239
  return out;
233
240
  }
234
241
 
235
- // The section keys folded, from the stored value (a JSON list); unreadable: none.
242
+ // The section keys folded, from the stored value (a JSON list). Nothing
243
+ // stored (null) or unreadable: the default, start folded; a stored list,
244
+ // an empty one too, as it is (the user folded or opened them by hand).
236
245
  // Conversation never folds (one row): an older page's stored "talk" is ignored.
237
246
  export function foldedSections(stored) {
238
247
  try {
239
- const list = JSON.parse(stored || "[]");
240
- return new Set(Array.isArray(list) ? list.filter((k) => typeof k === "string" && k !== "talk") : []);
248
+ const list = stored == null ? null : JSON.parse(stored);
249
+ return new Set((Array.isArray(list) ? list : DEFAULT_FOLDED).filter((k) => typeof k === "string" && k !== "talk"));
241
250
  } catch (_) {
242
- return new Set();
251
+ return new Set(DEFAULT_FOLDED);
243
252
  }
244
253
  }
245
254
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samagotchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.180.0
4
+ version: 0.181.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -347,6 +347,7 @@ files:
347
347
  - lib/samagotchi/continue_intent.rb
348
348
  - lib/samagotchi/continue_offer.rb
349
349
  - lib/samagotchi/continued_from.rb
350
+ - lib/samagotchi/core_notice.rb
350
351
  - lib/samagotchi/cut.rb
351
352
  - lib/samagotchi/cut_policy.rb
352
353
  - lib/samagotchi/debug_log.rb
@@ -1031,6 +1032,7 @@ files:
1031
1032
  - lib/samagotchi/web/public/objectives_wiring.js
1032
1033
  - lib/samagotchi/web/public/owner_claim.js
1033
1034
  - lib/samagotchi/web/public/owner_verify.js
1035
+ - lib/samagotchi/web/public/pan_zoom.js
1034
1036
  - lib/samagotchi/web/public/participant_bar.js
1035
1037
  - lib/samagotchi/web/public/participant_history.js
1036
1038
  - lib/samagotchi/web/public/participant_main.js
@@ -1043,6 +1045,7 @@ files:
1043
1045
  - lib/samagotchi/web/public/peer_exchange.js
1044
1046
  - lib/samagotchi/web/public/peer_links.js
1045
1047
  - lib/samagotchi/web/public/peer_note.js
1048
+ - lib/samagotchi/web/public/picture_viewer.js
1046
1049
  - lib/samagotchi/web/public/plain_line.js
1047
1050
  - lib/samagotchi/web/public/popover_modal.js
1048
1051
  - lib/samagotchi/web/public/project_picker.js
@@ -1161,6 +1164,8 @@ files:
1161
1164
  - lib/samagotchi/web/public/working_set_view.js
1162
1165
  - lib/samagotchi/web/public/ws_cards.js
1163
1166
  - lib/samagotchi/web/public/ws_item_sig.js
1167
+ - lib/samagotchi/web/public/ws_markdown.js
1168
+ - lib/samagotchi/web/public/ws_order.js
1164
1169
  - lib/samagotchi/web/public/ws_peek.js
1165
1170
  - lib/samagotchi/web/public/ws_preview.css
1166
1171
  - lib/samagotchi/web/public/ws_reader.js