samagotchi 0.54.0 → 0.56.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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -1
  3. data/bin/chi +3 -2
  4. data/docs/architecture.md +6 -2
  5. data/docs/cli.md +29 -7
  6. data/docs/configuration.md +113 -8
  7. data/docs/internals/background-tasks.md +1 -1
  8. data/docs/internals/context-telemetry.md +23 -5
  9. data/docs/internals/engine.md +54 -18
  10. data/docs/internals/prompt-caching.md +8 -0
  11. data/docs/sessions.md +2 -2
  12. data/docs/testing.md +23 -3
  13. data/lib/samagotchi/bridge/turn_accumulator.rb +6 -6
  14. data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
  15. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  16. data/lib/samagotchi/cache_confirm.rb +51 -0
  17. data/lib/samagotchi/client_id.rb +12 -0
  18. data/lib/samagotchi/config.rb +9 -3
  19. data/lib/samagotchi/engine.rb +102 -8
  20. data/lib/samagotchi/engine_peers.rb +1 -0
  21. data/lib/samagotchi/file_ref.rb +59 -0
  22. data/lib/samagotchi/host_config.rb +6 -3
  23. data/lib/samagotchi/host_registry.rb +4 -3
  24. data/lib/samagotchi/kernel_loop.rb +99 -16
  25. data/lib/samagotchi/llm/chat_loop.rb +122 -71
  26. data/lib/samagotchi/llm/openai_chat.rb +2 -1
  27. data/lib/samagotchi/llm/stream_drops.rb +63 -0
  28. data/lib/samagotchi/llm/turn_settings.rb +9 -5
  29. data/lib/samagotchi/model_settings.rb +5 -2
  30. data/lib/samagotchi/reasoning_history.rb +132 -0
  31. data/lib/samagotchi/reasoning_history_command.rb +107 -0
  32. data/lib/samagotchi/self_report.rb +21 -0
  33. data/lib/samagotchi/session.rb +23 -2
  34. data/lib/samagotchi/session_commands.rb +55 -15
  35. data/lib/samagotchi/session_manager.rb +2 -1
  36. data/lib/samagotchi/session_setup.rb +7 -5
  37. data/lib/samagotchi/setting_explained.rb +20 -0
  38. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  39. data/lib/samagotchi/terminal_ui/attached_loop.rb +11 -0
  40. data/lib/samagotchi/terminal_ui/formatting.rb +8 -5
  41. data/lib/samagotchi/terminal_ui.rb +13 -6
  42. data/lib/samagotchi/thinking.rb +20 -25
  43. data/lib/samagotchi/thinking_command.rb +33 -11
  44. data/lib/samagotchi/tool_row_fields.rb +46 -0
  45. data/lib/samagotchi/tool_runner.rb +7 -11
  46. data/lib/samagotchi/tools/builtins.rb +6 -2
  47. data/lib/samagotchi/tools/peers.rb +4 -2
  48. data/lib/samagotchi/tools/task_runtime.rb +2 -1
  49. data/lib/samagotchi/version.rb +1 -1
  50. data/lib/samagotchi/web/app.rb +48 -4
  51. data/lib/samagotchi/web/capabilities.rb +13 -9
  52. data/lib/samagotchi/web/editor.rb +38 -0
  53. data/lib/samagotchi/web/message_parts.rb +5 -10
  54. data/lib/samagotchi/web/public/activity.js +33 -18
  55. data/lib/samagotchi/web/public/app.js +256 -1133
  56. data/lib/samagotchi/web/public/commands.js +269 -0
  57. data/lib/samagotchi/web/public/composer.js +105 -0
  58. data/lib/samagotchi/web/public/diff_view.js +30 -4
  59. data/lib/samagotchi/web/public/index.html +11 -3
  60. data/lib/samagotchi/web/public/info_bar.js +80 -0
  61. data/lib/samagotchi/web/public/level_chip.js +174 -0
  62. data/lib/samagotchi/web/public/lists_view.js +725 -0
  63. data/lib/samagotchi/web/public/llm_context_chip.js +9 -6
  64. data/lib/samagotchi/web/public/model_pick.js +1 -1
  65. data/lib/samagotchi/web/public/question_cards.js +2 -1
  66. data/lib/samagotchi/web/public/reasoning_history_chip.js +49 -0
  67. data/lib/samagotchi/web/public/refs.js +134 -0
  68. data/lib/samagotchi/web/public/restore.js +81 -0
  69. data/lib/samagotchi/web/public/session_state.js +57 -0
  70. data/lib/samagotchi/web/public/stream_handlers.js +332 -0
  71. data/lib/samagotchi/web/public/thinking_chip.js +38 -144
  72. data/lib/samagotchi/web/public/turn_events.js +17 -258
  73. data/lib/samagotchi/web/public/turn_html.js +5 -1
  74. data/lib/samagotchi/web/server.rb +4 -4
  75. data/lib/samagotchi/worker.rb +17 -5
  76. metadata +18 -2
  77. data/lib/samagotchi/web/public/stable_html.js +0 -18
@@ -30,6 +30,32 @@ export function newActivity() {
30
30
  return { rows: [] };
31
31
  }
32
32
 
33
+ // A row's fields beyond its params, as the server's ToolRowFields lists
34
+ // them; each list is copied in one place per path (addStarted, addCompleted's
35
+ // synthesized row, turn_events.js snapshotEvents), so a new field is added
36
+ // here. ACTIVITY_FIELDS: top-level on tool_call_started, inside `activity`
37
+ // on tool_call_completed. EVENT_FIELDS: top-level on both.
38
+ // title: what the call did in a few words (the server's tool title: a
39
+ // project-relative path, a command without its "cd … &&"); rows show
40
+ // it in place of the params when there is one.
41
+ // called_as: the name the model called the tool by when it was an
42
+ // alias's ("bash" run as execute); the row says so.
43
+ // view: the call's full arguments for the expanded row and the hovers
44
+ // (the server's ToolView: an execute/task_create's command, its cwd).
45
+ // ref: what the row traces to (the server's FileRef: {kind: "file",
46
+ // path, line?, end_line?}, the file a file tool touched), which
47
+ // refs.js makes the row's title and diff lines open.
48
+ export const ACTIVITY_FIELDS = Object.freeze(["title", "called_as"]);
49
+ export const EVENT_FIELDS = Object.freeze(["view", "ref"]);
50
+ const ROW_FIELDS = Object.freeze([...ACTIVITY_FIELDS, ...EVENT_FIELDS]);
51
+
52
+ // The +fields+ of +source+ that are set, as an object (for a spread).
53
+ export function pickFields(source, fields) {
54
+ const picked = {};
55
+ for (const field of fields) if (source?.[field]) picked[field] = source[field];
56
+ return picked;
57
+ }
58
+
33
59
  // Stable key for a call within a turn. iteration + call_index are both present
34
60
  // on :tool_call_started and :tool_call_completed, so the same key links a
35
61
  // "running" row to its completion.
@@ -52,9 +78,7 @@ export function addStarted(model, event = {}, now = null) {
52
78
  row.tool = event.tool || row.tool;
53
79
  row.label = event.label || row.label;
54
80
  row.params = event.params || row.params;
55
- row.title = event.title || row.title;
56
- row.called_as = event.called_as || row.called_as;
57
- row.view = event.view || row.view;
81
+ for (const field of ROW_FIELDS) row[field] = event[field] || row[field];
58
82
  markStart(row, event, now);
59
83
  return { row, created: false };
60
84
  }
@@ -65,16 +89,8 @@ export function addStarted(model, event = {}, now = null) {
65
89
  tool: event.tool || "tool",
66
90
  label: event.label || null,
67
91
  params: event.params || "",
68
- // What the call did in a few words (the server's tool title: a
69
- // project-relative path, a command without its "cd … &&"); rows show it
70
- // in place of the params when there is one.
71
- title: event.title || null,
72
- // The name the model called the tool by when it was an alias's ("bash"
73
- // run as execute); the row says so.
74
- called_as: event.called_as || null,
75
- // The call's full arguments for the expanded row and the hovers (the
76
- // server's ToolView: an execute/task_create's command, its cwd).
77
- view: event.view || null,
92
+ // ACTIVITY_FIELDS and EVENT_FIELDS (above), null when unset.
93
+ ...Object.fromEntries(ROW_FIELDS.map((field) => [field, event[field] || null])),
78
94
  status: ROW_STATUS.RUNNING,
79
95
  output: "",
80
96
  output_truncated: false,
@@ -107,9 +123,8 @@ export function addCompleted(model, event = {}, now = null) {
107
123
  tool: event.tool,
108
124
  label: event.label,
109
125
  params: event.activity?.params || "",
110
- title: event.activity?.title,
111
- called_as: event.activity?.called_as,
112
- view: event.view,
126
+ ...pickFields(event.activity, ACTIVITY_FIELDS),
127
+ ...pickFields(event, EVENT_FIELDS),
113
128
  });
114
129
  row = synthesized.row;
115
130
  }
@@ -117,8 +132,8 @@ export function addCompleted(model, event = {}, now = null) {
117
132
  row.output = event.output || "";
118
133
  row.output_truncated = !!event.output_truncated;
119
134
  if (event.activity?.params) row.params = event.activity.params;
120
- if (event.activity?.title) row.title = event.activity.title;
121
- if (event.activity?.called_as) row.called_as = event.activity.called_as;
135
+ // The completed event carries the title (ACTIVITY_FIELDS) in its activity.
136
+ Object.assign(row, pickFields(event.activity, ACTIVITY_FIELDS));
122
137
  // A grep that found nothing (status ok): the row says "no match".
123
138
  if (event.activity?.no_match) row.no_match = true;
124
139
  // The images the tool returned (a reload in the turn view draws them from