#!/usr/bin/env ruby
# encoding: UTF-8
# Usage: hook-continue <index_path> <store_root> <mode>
# Renders the dashboard `continue` cockpit as UserPromptSubmit additionalContext.
# Exits silently (no output) if the dashboard produces nothing — the bash caller
# then falls back to a minimal notice.

require "json"
require "open3"

index_path, _store_root, _mode = ARGV
exit 0 unless index_path && File.exist?(index_path)

dashboard = File.expand_path("dashboard.rb", __dir__)
exit 0 unless File.exist?(dashboard)

cockpit, _err, status = Open3.capture3("ruby", dashboard, "continue")
exit 0 unless status.success? && !cockpit.strip.empty?

context = cockpit.rstrip +
  "\n\nFollow the plastic-continuing skill workflow to resume: " \
  "if active intents exist, read their state and resume; otherwise offer the " \
  "Value×Effort matrix items above, surfacing any stale (Nd) / ⚑ triage intents."

payload = {
  "hookSpecificOutput" => {
    "hookEventName" => "UserPromptSubmit",
    "additionalContext" => context
  }
}
puts JSON.generate(payload)
