legion-tty 0.4.36 → 0.4.38

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e331de1a9cb6b1a10576797303b5f1c691b639a74212c5cca6dc5d5fb161f7c
4
- data.tar.gz: 01b5bfdefa8e991d01db3da00c1f0d7f51ff029d08c89e6a008a1abb607c8543
3
+ metadata.gz: 5015163992ac8b889c19088f2caa60b3e80fc09445c7feb27085f4c39c0857a5
4
+ data.tar.gz: 6eadf44a9366956867b097b1a10769ae18b01d1a644daae91c3ea5fade6681b3
5
5
  SHA512:
6
- metadata.gz: f94def1314643beeda49eb00c7a9f70a4cacee8843c56551bf24b9edfa77dfcbf17fbca6f9c5f708574a14bdf3316e382a04d41e542e8d841eba21324cc0d248
7
- data.tar.gz: fa6d3c970d1e33492185f3cb89e3dbc9f349c8f36431558f86f13bd1a48c96656a6b0adecee84bd2dc3713ee11c25a09282bdacc3cc7ffff6a3886e785b1839e
6
+ metadata.gz: 914de3d2b07691224655ac5b1dd4bb7b1dd9b88083fde6a0b719c9398a654c0b91640c621ea88865d11ad8b737909af0a24dcbae9ff1e4d200be8eda58d14af6
7
+ data.tar.gz: dd740544c87c71fa843e72ad602f49d029cd485f16d4b2532e55927ce33b2019042772812f59281aa00633c75af9ed5b3ce0f89c84070bd250ce51c27db304bf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.38] - 2026-03-26
4
+
5
+ ### Added
6
+ - `build_system_prompt` injects a live self-awareness section from `lex-agentic-self` Metacognition when the gem is loaded; guarded with a `defined?` check and `rescue StandardError` so chat is unaffected if the module is absent or raises; narrative is stripped and capped at 2000 chars to prevent prompt bloat
7
+
8
+ ## [0.4.37] - 2026-03-26
9
+
10
+ ### Fixed
11
+ - Token tracking uses `model_id` from RubyLLM::Message response (was incorrectly checking non-existent `model` method)
12
+ - Initialize TokenTracker with actual model from LLM chat session when available
13
+ - Guard against blank `model_id` in `track_response_tokens` — a nil `model_id` no longer overwrites the previously-set model with an empty string
14
+
15
+ ### Added
16
+ - Daemon path token tracking via `track_daemon_tokens` (reads `meta[:tokens_in]`/`meta[:tokens_out]` from daemon response)
17
+ - Extracted `update_status_bar_tokens` helper to DRY up status bar updates after tracking
18
+
3
19
  ## [0.4.36] - 2026-03-26
4
20
 
5
21
  ### Changed
@@ -74,7 +74,10 @@ module Legion
74
74
  @message_stream = Components::MessageStream.new
75
75
  @status_bar = Components::StatusBar.new
76
76
  @llm_chat = app.respond_to?(:llm_chat) ? app.llm_chat : nil
77
- @token_tracker = Components::TokenTracker.new(provider: detect_provider)
77
+ @token_tracker = Components::TokenTracker.new(
78
+ provider: detect_provider,
79
+ model: @llm_chat.respond_to?(:model) ? @llm_chat.model.to_s : nil
80
+ )
78
81
  @session_store = SessionStore.new
79
82
  @session_name = 'default'
80
83
  @plan_mode = false
@@ -251,6 +254,7 @@ module Legion
251
254
  parser = build_tool_call_parser
252
255
  parser.feed(result[:response])
253
256
  parser.flush
257
+ track_daemon_tokens(result)
254
258
  when :error
255
259
  err = result.dig(:error, :message) || 'Unknown error'
256
260
  @message_stream.append_streaming("\n[Daemon error: #{err}]")
@@ -340,6 +344,26 @@ module Legion
340
344
  lines << "Top languages: #{env[:top_languages].keys.join(', ')}" if env[:top_languages]&.any?
341
345
  end
342
346
 
347
+ if defined?(Legion::Extensions::Agentic::Self::Metacognition::Runners::Metacognition)
348
+ begin
349
+ result = Legion::Extensions::Agentic::Self::Metacognition::Runners::Metacognition.self_narrative
350
+ narrative = result[:prose] if result.is_a?(Hash) && result[:prose]
351
+ if narrative
352
+ narrative = narrative.strip
353
+ narrative = narrative[0, 2000] if narrative.length > 2000
354
+ end
355
+ if narrative && !narrative.empty?
356
+ lines << ''
357
+ lines << 'Current self-awareness:'
358
+ lines << narrative
359
+ end
360
+ rescue StandardError => e
361
+ if defined?(Legion::Logging)
362
+ Legion::Logging.warn("Metacognition.self_narrative failed: #{e.class}: #{e.message}")
363
+ end
364
+ end
365
+ end
366
+
343
367
  lines.join("\n")
344
368
  end
345
369
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
@@ -602,12 +626,31 @@ module Legion
602
626
  def track_response_tokens(response)
603
627
  return unless response.respond_to?(:input_tokens)
604
628
 
605
- model_id = response.respond_to?(:model) ? response.model.to_s : nil
629
+ raw_model = response.respond_to?(:model_id) ? response.model_id.to_s : nil
630
+ model_id = raw_model && !raw_model.empty? ? raw_model : nil
631
+ input_tokens = response.input_tokens.to_i
632
+ output_tokens = response.respond_to?(:output_tokens) ? response.output_tokens.to_i : 0
606
633
  @token_tracker.track(
607
- input_tokens: response.input_tokens.to_i,
608
- output_tokens: response.output_tokens.to_i,
634
+ input_tokens: input_tokens,
635
+ output_tokens: output_tokens,
609
636
  model: model_id
610
637
  )
638
+ update_status_bar_tokens
639
+ end
640
+
641
+ def track_daemon_tokens(result)
642
+ meta = result[:meta]
643
+ return unless meta.is_a?(Hash) && (meta[:tokens_in] || meta[:tokens_out])
644
+
645
+ @token_tracker.track(
646
+ input_tokens: meta[:tokens_in].to_i,
647
+ output_tokens: meta[:tokens_out].to_i,
648
+ model: meta[:model]&.to_s
649
+ )
650
+ update_status_bar_tokens
651
+ end
652
+
653
+ def update_status_bar_tokens
611
654
  @status_bar.update(
612
655
  tokens: @token_tracker.total_input_tokens + @token_tracker.total_output_tokens,
613
656
  cost: @token_tracker.total_cost
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module TTY
5
- VERSION = '0.4.36'
5
+ VERSION = '0.4.38'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-tty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.36
4
+ version: 0.4.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity