Class: Studio::App

Inherits:
Roda
  • Object
show all
Includes:
Forms, NavIcons
Defined in:
lib/insika/studio/app.rb

Overview

Insika Studio — the server-rendered management UI, replacing OpenClaw's agent-studio. FRAMEWORK AT THE EDGE: it's a separate Roda app, mounted under /studio; lib/insika and server/ do NOT gain a Roda dependency. It talks to the runtime through the SAME surface as the API: dispatches Commands on the CommandBus and READS profiles/stores — never writes to a store directly (the transport's constitutional rule).

SESSION/cookie auth: login compares the token in constant time against ADMIN_TOKEN, sets an httpOnly SameSite=Lax cookie and protects /studio/* fail-closed (no token configured → login never validates → studio inaccessible). Replaces the manual LocalAdminShim/Bearer. CSRF on the POSTs.

Same-origin assets: versioned esbuild bundle in assets/dist/*, served by /studio/assets/dist/*. Strict 'self' CSP (no unsafe-inline).

Constant Summary collapse

SESSION_MAX_AGE =

The session cookie lives N days. 7 days = parity with the OpenClaw default.

7 * 24 * 3600
ASSETS_DIR =
File.expand_path("assets/dist", __dir__)
CONTENT_TYPES =
{
  ".js" => "text/javascript; charset=utf-8",
  ".css" => "text/css; charset=utf-8",
  ".map" => "application/json; charset=utf-8",
  ".woff2" => "font/woff2", ".svg" => "image/svg+xml"
}.freeze

Constants included from NavIcons

NavIcons::NAV_ICONS

Constants included from Forms

Forms::UNEDITED_TOOL_FIELDS

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from NavIcons

#nav_icon

Methods included from Forms

#coerce, #config_patch, #edge_float, #edge_int, #edge_patch, #evals_patch, #golden_patch, #guardrail_responses_patch, #guardrails_patch, #mcp_patch, #model_defaults_patch, #model_params_patch, #model_policy_patch, #params_patch, #parse_kv_lines, #parse_param_lines, #parse_parameters, #provider_patch, #settings_patch, #tool_patch

Class Attribute Details

.insikaObject (readonly)

Runtime dependencies injected at boot (same surface as Server::App).



70
71
72
# File 'lib/insika/studio/app.rb', line 70

def insika
  @insika
end

Class Method Details

.clear_restart_needed!Object



144
# File 'lib/insika/studio/app.rb', line 144

def clear_restart_needed! = (@restart_needed = false)

.configure(command_bus:, profile_source:, event_stream:, config:, agent_file_store: nil, skill_store: nil, skill_catalog: nil, tool_catalog: nil, tool_store: nil, memory_store: nil, session_store: nil, settings_store: nil, llm_provider_store: nil, mcp_store: nil, system_file_store: nil, tool_trace_store: nil, task_store: nil, checkpoint_store: nil, pending_action_store: nil, refinement_store: nil, golden_store: nil, session_secret: nil) ⇒ Object

Studio wiring (called by the boot: serve_real / config.ru). Loads the plugins that depend on the secret (sessions/csrf/flash) and stores the deps. An explicit session_secret is for the specs; in production it derives from the admin token (stable across restarts, without requiring one more env var).

Besides the usual trio (command_bus/profile_source/config), the Studio now READS authoring stores (agent_file/skill/tool/memory/session) to render the pages. All optional (default nil): pages that depend on a store degrade to an empty-state if it was not injected.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/insika/studio/app.rb', line 81

def configure(command_bus:, profile_source:, event_stream:, config:,
              agent_file_store: nil, skill_store: nil, skill_catalog: nil,
              tool_catalog: nil, tool_store: nil, memory_store: nil, session_store: nil,
              settings_store: nil, llm_provider_store: nil, mcp_store: nil,
              system_file_store: nil, tool_trace_store: nil,
              task_store: nil, checkpoint_store: nil, pending_action_store: nil,
              refinement_store: nil, golden_store: nil, session_secret: nil)
  @insika = {
    command_bus: command_bus, profile_source: profile_source,
    event_stream: event_stream, config: config,
    agent_file_store: agent_file_store, skill_store: skill_store,
    skill_catalog: skill_catalog, tool_catalog: tool_catalog,
    # tool_store: DATA-DEFINED tool definitions (Phase 5). The catalog already
    # shows the data-tools in the matrix; the store feeds the authoring page.
    tool_store: tool_store,
    memory_store: memory_store, session_store: session_store,
    # runtime config (settings/LLM/MCP) + global system
    # files + conversations index. All optional (empty-state if nil).
    settings_store: settings_store, llm_provider_store: llm_provider_store,
    mcp_store: mcp_store, system_file_store: system_file_store,
    # per-session tool-call trace (debug): args + result + status per
    # turn, rendered in the session viewer (FOLLOWUP §3.1).
    tool_trace_store: tool_trace_store,
    # operate: tasks + human-in-the-loop approvals (§12 G5). Reads the
    # task/checkpoint/pending stores to render; controls (pause/resume/
    # cancel/approve) dispatch on the bus — parity with server/admin.
    task_store: task_store, checkpoint_store: checkpoint_store,
    pending_action_store: pending_action_store,
    # refinement runs (RFC-0013 phase A): the ranked failure report per agent.
    # Read-only here; the "Run" button dispatches :run_refinement on the bus.
    refinement_store: refinement_store,
    # eval cases (RFC-0008 §3.1): read to render; writes go through :write_golden.
    golden_store: golden_store
  }.freeze
  # "restart recommended" flag — in memory, PER PROCESS. A
  # config change that the runtime only re-reads at boot (e.g.: MCP instances are
  # wired at startup) lights the flag; restarting the process clears it
  # naturally (new process = `configure` runs again = flag reset).
  # Deliberately not put in the session: the session survives the restart (the secret
  # derives from the token) and the flag would stay stuck on.
  @restart_needed = false
  secret = session_secret || derive_secret(config[:admin_token])
  plugin :sessions, key: "insika.studio", secret: secret,
                    max_seconds: SESSION_MAX_AGE, same_site: :lax
  # CSRF token bound to the SESSION (not the method+path pair). route_csrf's
  # per-path binding uses `request.path` = POST-MOUNT PATH_INFO ("/login",
  # not "/studio/login"), which would confuse form-action × token under the
  # URLMap. Session-bound is safe for the single-tenant target.
  plugin :route_csrf, require_request_specific_tokens: false, csrf_failure: :empty_403
  plugin :flash
  self
end

.derive_secret(admin_token) ⇒ Object

Deterministic per-deploy session secret (>=64 bytes required by Roda sessions). Derives from the admin token → stable across restarts (the session survives) without a new env var; change the token and all sessions drop.



137
138
139
# File 'lib/insika/studio/app.rb', line 137

def derive_secret(admin_token)
  Digest::SHA512.hexdigest("insika-studio-session-v1:#{admin_token}")
end

.mark_restart_needed!Object



143
# File 'lib/insika/studio/app.rb', line 143

def mark_restart_needed! = (@restart_needed = true)

.restart_needed?Boolean

--- Restart recommended — per-process state -------------------

Returns:

  • (Boolean)


142
# File 'lib/insika/studio/app.rb', line 142

def restart_needed? = @restart_needed == true