samagotchi 0.41.0 → 0.43.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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +56 -1
  3. data/docs/cli.md +8 -6
  4. data/docs/configuration.md +8 -0
  5. data/docs/context.md +46 -0
  6. data/docs/memory.md +18 -0
  7. data/docs/plugins.md +27 -5
  8. data/docs/sessions.md +5 -5
  9. data/docs/testing.md +16 -0
  10. data/lib/samagotchi/bundles/github-pr/manifest.yml +4 -4
  11. data/lib/samagotchi/bundles/github-pr/plugin.rb +177 -1
  12. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  13. data/lib/samagotchi/child_reports.rb +8 -4
  14. data/lib/samagotchi/context_command.rb +5 -2
  15. data/lib/samagotchi/context_sources.rb +40 -0
  16. data/lib/samagotchi/engine.rb +31 -1
  17. data/lib/samagotchi/model_notes.rb +7 -4
  18. data/lib/samagotchi/plugin/attached_context.rb +75 -11
  19. data/lib/samagotchi/prompt_note.rb +53 -0
  20. data/lib/samagotchi/self_report.rb +32 -0
  21. data/lib/samagotchi/session.rb +16 -1
  22. data/lib/samagotchi/session_commands.rb +24 -5
  23. data/lib/samagotchi/session_metrics.rb +21 -4
  24. data/lib/samagotchi/system_prompt.rb +14 -1
  25. data/lib/samagotchi/terminal_ui/attached_loop.rb +12 -0
  26. data/lib/samagotchi/terminal_ui/formatting.rb +4 -0
  27. data/lib/samagotchi/tool_declarations.rb +2 -1
  28. data/lib/samagotchi/turn_flow.rb +8 -0
  29. data/lib/samagotchi/version.rb +1 -1
  30. data/lib/samagotchi/web/app.rb +55 -8
  31. data/lib/samagotchi/web/public/app.js +73 -11
  32. data/lib/samagotchi/web/public/ctx.js +27 -2
  33. data/lib/samagotchi/web/public/data.js +6 -3
  34. data/lib/samagotchi/web/public/format.js +24 -0
  35. data/lib/samagotchi/web/public/index.html +8 -0
  36. data/lib/samagotchi/web/public/llm_context_chip.js +151 -21
  37. data/lib/samagotchi/web/public/model_pick.js +3 -1
  38. data/lib/samagotchi/web/public/model_picker.js +2 -0
  39. data/lib/samagotchi/web/public/session_state.js +5 -0
  40. data/lib/samagotchi/web/public/timing.js +3 -1
  41. data/lib/samagotchi/web/public/turn_view.js +15 -2
  42. data/lib/samagotchi/web/session_summary.rb +2 -0
  43. data/lib/samagotchi/worker.rb +16 -4
  44. data/lib/samagotchi/worker_wakes.rb +2 -1
  45. metadata +2 -1
@@ -11,7 +11,7 @@
11
11
  // removed at the end: the answer bubble takes its place.
12
12
  import { leavesBlock } from "./card.js";
13
13
  import { copySourceAttr } from "./copy.js";
14
- import { escapeHtml, messageBodyHtml, noteHtml, normalize, sourceLabel, steerRowHtml } from "./format.js";
14
+ import { escapeHtml, failedTurnText, messageBodyHtml, noteHtml, normalize, sourceLabel, steerRowHtml } from "./format.js";
15
15
  import { thumbsHtml } from "./images.js";
16
16
  import { shouldFollowScroll } from "./scroll.js";
17
17
  import { hookNoticeLabel } from "./turn_events.js";
@@ -701,6 +701,17 @@ function setLabel(summary, gen) {
701
701
  summary.innerHTML = html;
702
702
  }
703
703
 
704
+ // A re-rendered failed turn's line (a .bubble.cancel, as live's
705
+ // addEndBubble), in turn_failed's words (failedTurnText) from what the turn
706
+ // record kept of it (SessionMetrics' failure: summary, message,
707
+ // error_class, kept_steps); "" for any other record, or a failed one saved
708
+ // before records kept that.
709
+ function failedLineHtml(record) {
710
+ const failure = record?.status === "failed" ? record.failure : null;
711
+ if (!failure || typeof failure !== "object") return "";
712
+ return `<div class="bubble cancel">${escapeHtml(failedTurnText(failure))}</div>`;
713
+ }
714
+
704
715
  // A reloaded history in the turn view (renderHistory's object path): per
705
716
  // turn the prompt, a collapsed block of its steps when it had any (texts,
706
717
  // and with the server's parts the thinking, params and output, from the
@@ -789,8 +800,10 @@ export function turnHistoryHtml(items, timing, { thumbs }) {
789
800
  // timing after its prompt and steps, where the live view leaves it.
790
801
  else if (group.answer === null) parts.push(timingHtml(group));
791
802
  else parts.push(answerHtml(items[group.answer], timingHtml(group)));
792
- // A canceled turn ends with its cancel line, as the live view left it.
803
+ // A canceled turn ends with its cancel line, a failed one whose steps
804
+ // stayed with its failure line, as the live view left them.
793
805
  parts.push(cancelLineHtml(group.record, escapeHtml));
806
+ parts.push(failedLineHtml(group.record));
794
807
  return parts.join("");
795
808
  }).join("");
796
809
  }
@@ -47,6 +47,8 @@ module Samagotchi
47
47
  # The session's --memory and --mute lists (info-bar tooltip).
48
48
  preloaded_memory_names: Array(session.preloaded_memory_names),
49
49
  muted_memory_names: Array(session.muted_memory_names),
50
+ # The model notes its prompt carried (the info bar's notes chip).
51
+ prompt_notes: Array(session.prompt_notes).map(&:to_h),
50
52
  # The session that delegated this one (the `delegate` tool), else nil.
51
53
  parent_id: session.parent_id,
52
54
  # Started by the delegate tool (Session#delegate?); a fork has a
@@ -507,6 +507,7 @@ module Samagotchi
507
507
  @wakes.hand_over(reports)
508
508
  Log.info(:worker, "delegate_wake_turn", reports: reports.size, in_a_row: @wakes.count!)
509
509
  @turn_flow.before_prompt_turn
510
+ restores = @turn_flow.restores
510
511
  run_engine_turn(nil, continue: true, origin: reports.first.origin, max_iterations: IterationLimit.for) do |result, error|
511
512
  if error
512
513
  # Rolled back, the rings stay (settle_child_reports): the user's
@@ -519,6 +520,11 @@ module Samagotchi
519
520
  @wakes.pause!
520
521
  else
521
522
  @continue_offer.after_turn(result)
523
+ # Stopped before it got anywhere (a Stop or a before_turn hook's
524
+ # cancel before the model call) and restored: its rings stay, and
525
+ # wait for the user's next message as after a failure, rather
526
+ # than waking again at once.
527
+ @wakes.pause! if result.canceled? && @turn_flow.restores != restores
522
528
  end
523
529
  end
524
530
  true
@@ -656,6 +662,7 @@ module Samagotchi
656
662
  # a fresh worker's first), so the list is this turn's from the start.
657
663
  @merged_this_turn = []
658
664
  @reporting_turn = reports_to_parent?(turn_args[:origin])
665
+ restores = @turn_flow.restores
659
666
  begin
660
667
  @session.status = Session::STATUS_RUNNING
661
668
  @session.save(state_dir: @state_dir)
@@ -682,15 +689,20 @@ module Samagotchi
682
689
  SessionInbox.write_output(@session_dir, response)
683
690
  end
684
691
  save_or_log(:turn) { save_session }
685
- # A failed turn whose work stayed (TurnFlow#prompt_turn_failed) read
686
- # the reports it merged, as a turn that ended does.
687
- settle_child_reports(rolled_back: error && !LLM::FailedTurn.kept_steps(error))
692
+ # The reports the turn merged were read unless its end took the turn
693
+ # back out of the conversation (TurnFlow restored a checkpoint: a
694
+ # failed prompt or wake turn that got nowhere, a canceled continue
695
+ # turn). A failed turn whose work stayed, and a reminder or continue
696
+ # turn that failed (kept with its failed note), read them.
697
+ settle_child_reports(rolled_back: @turn_flow.restores != restores)
688
698
  ring_parent_after_turn
689
699
  end
690
700
 
691
701
  # The delegate reports this turn took: a kept turn moves the cursors on
692
702
  # and deletes their rings; a rolled-back one leaves the rings for the
693
- # next turn.
703
+ # next turn. Once either way: the model reads a report in the
704
+ # conversation, or the next turn brings it (unless a later !rollback
705
+ # erases a kept turn, which drops what it read).
694
706
  def settle_child_reports(rolled_back:)
695
707
  rolled_back ? @child_reports.release : @child_reports.commit
696
708
  end
@@ -73,7 +73,8 @@ module Samagotchi
73
73
  # A wake turn starts. @return [Integer] the wake turns in a row now
74
74
  def count! = @in_a_row += 1
75
75
 
76
- # A wake turn failed: none starts again until a human's input.
76
+ # A wake turn failed (or was stopped before it got anywhere): none
77
+ # starts again until a human's input.
77
78
  def pause!
78
79
  @paused = true
79
80
  end
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.41.0
4
+ version: 0.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -373,6 +373,7 @@ files:
373
373
  - lib/samagotchi/prompt.rb
374
374
  - lib/samagotchi/prompt_history.rb
375
375
  - lib/samagotchi/prompt_literal_guard.rb
376
+ - lib/samagotchi/prompt_note.rb
376
377
  - lib/samagotchi/prompt_warmup.rb
377
378
  - lib/samagotchi/question_desk.rb
378
379
  - lib/samagotchi/recap_setup.rb