Class: Studio::App
- Inherits:
-
Roda
- Object
- Roda
- Studio::App
- 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.("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
Constants included from Forms
Class Attribute Summary collapse
-
.insika ⇒ Object
readonly
Runtime dependencies injected at boot (same surface as Server::App).
Class Method Summary collapse
- .clear_restart_needed! ⇒ Object
-
.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, memory_audit_store: nil, settings_store: nil, llm_provider_store: nil, mcp_store: nil, system_file_store: nil, tool_trace_store: nil, context_trace_store: nil, cache_series_store: nil, task_store: nil, checkpoint_store: nil, pending_action_store: nil, refinement_store: nil, golden_store: nil, session_secret: nil, outcome_store: nil, shadow_pair_store: nil, parity_criterion: nil, funnel_store: nil, budget_ledger: nil, followup_store: nil, contact_store: nil, proposal_store: nil, harvest_store: nil, harvest_criterion: nil, negative_list: nil, channel_registry: nil) ⇒ Object
Studio wiring (called by the boot: serve_real / config.ru).
-
.derive_secret(admin_token) ⇒ Object
Deterministic per-deploy session secret (>=64 bytes required by Roda sessions).
- .mark_restart_needed! ⇒ Object
-
.restart_needed? ⇒ Boolean
--- Restart recommended — per-process state -------------------.
Methods included from NavIcons
Methods included from Forms
#alerts_patch, #allowlist_patch, #budget_patch, #coerce, #config_patch, #distill_patch, #edge_float, #edge_int, #edge_patch, #edge_stream_patch, #evals_patch, #followup_patch, #funnel_patch, #golden_patch, #grounding_patch, #guardrail_responses_patch, #guardrails_patch, #harvest_miner_patch, #harvest_patch, #json_block, #json_patch, #lines, #list, #list_patch, #mcp_patch, #model_defaults_patch, #model_params_patch, #model_policy_patch, #params_patch, #parse_kv_lines, #parse_param_lines, #parse_parameters, #provider_patch, #refinement_patch, #reliability_patch, #settings_patch, #skills_eager_patch, #tool_patch
Class Attribute Details
.insika ⇒ Object (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
192 |
# File 'lib/insika/studio/app.rb', line 192 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, memory_audit_store: nil, settings_store: nil, llm_provider_store: nil, mcp_store: nil, system_file_store: nil, tool_trace_store: nil, context_trace_store: nil, cache_series_store: nil, task_store: nil, checkpoint_store: nil, pending_action_store: nil, refinement_store: nil, golden_store: nil, session_secret: nil, outcome_store: nil, shadow_pair_store: nil, parity_criterion: nil, funnel_store: nil, budget_ledger: nil, followup_store: nil, contact_store: nil, proposal_store: nil, harvest_store: nil, harvest_criterion: nil, negative_list: nil, channel_registry: 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# 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, memory_audit_store: nil, settings_store: nil, llm_provider_store: nil, mcp_store: nil, system_file_store: nil, tool_trace_store: nil, context_trace_store: nil, cache_series_store: nil, task_store: nil, checkpoint_store: nil, pending_action_store: nil, refinement_store: nil, golden_store: nil, session_secret: nil, outcome_store: nil, shadow_pair_store: nil, parity_criterion: nil, funnel_store: nil, budget_ledger: nil, followup_store: nil, contact_store: nil, proposal_store: nil, harvest_store: nil, harvest_criterion: nil, negative_list: nil, channel_registry: 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. 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, # the Customers drill renders the audit lines (digests + # counts, never content). nil = the audit section renders empty. memory_audit_store: memory_audit_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. tool_trace_store: tool_trace_store, # per-session context breakdown: tokens by category + # budget per turn, on the same viewer. Counts only, no content. context_trace_store: context_trace_store, # per-AGENT cache-hit series (percentages + counts, no # content) — the cache tab on the agent detail. nil = tab renders # "No turns recorded.". cache_series_store: cache_series_store, # operate: tasks + human-in-the-loop approvals. 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: the ranked failure report per agent. # Read-only here; the "Run" button dispatches :run_refinement on the bus. refinement_store: refinement_store, # eval cases: read to render; writes go through:write_golden. golden_store: golden_store, # WS7: business outcomes — the agents grid's last-outcome pill; the # agent detail shows the per-day series. Reads only; recording goes # through POST /v1/outcomes. outcome_store: outcome_store, # the Funnel page reads the fold's cells and the # BudgetLedger's current counters (D6). nil = the page renders its # empty state. funnel_store: funnel_store, budget_ledger: budget_ledger, # the shadow pair store (read to render /studio/parity), the # frozen criterion (folded by Verdict), and the channel registry (the # nav row only exists when a shadow channel is registered — the page # is not an invitation, unlike Refinement's). shadow_pair_store: shadow_pair_store, parity_criterion: parity_criterion, channel_registry: channel_registry, # the Follow-ups page READS the stores directly; # its only mutations — cancel a pending record, force-revoke a contact # — dispatch :cancel_followup / :revoke_contact on the bus. nil = the # page renders its empty state. followup_store: followup_store, contact_store: contact_store, # the Facts (wiki) page reads the proposal store directly # (approvals/rejections dispatch :resolve_proposal on the bus). # nil = the page renders its empty state. proposal_store: proposal_store, # the Harvest page reads the harvest store directly # (the pending/awaiting/promoted lists); its mutations — mine, gate, # promote, reject, rollback — dispatch bus commands. The criterion # (boot-loaded, with its sha) and the negative list render the two # pre-registered artifacts. nil = the page renders its empty state. harvest_store: harvest_store, harvest_criterion: harvest_criterion, negative_list: negative_list }.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.
185 186 187 |
# File 'lib/insika/studio/app.rb', line 185 def derive_secret(admin_token) Digest::SHA512.hexdigest("insika-studio-session-v1:#{admin_token}") end |
.mark_restart_needed! ⇒ Object
191 |
# File 'lib/insika/studio/app.rb', line 191 def mark_restart_needed! = (@restart_needed = true) |
.restart_needed? ⇒ Boolean
--- Restart recommended — per-process state -------------------
190 |
# File 'lib/insika/studio/app.rb', line 190 def restart_needed? = @restart_needed == true |