Context Manager + Agent Prompt UI #8
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_code#8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Coding Spec — Context Manager + Agent Prompt UI
Objective
Build a coding-agent interface with 2 tabs:
The system lets users:
1. Core Concepts
1.1 Context
A Context is a reusable saved selection of files from one or more repositories.
A context contains:
A context is editable and reusable.
1.2 Agent Prompt Session
An Agent Prompt Session is a chat-like workspace for interacting with an agent.
A session contains:
2. Main UI Structure
Tab 1 — Context Manager
Used to create, edit, inspect, copy, and save contexts.
Tab 2 — Agents
Used to create prompt sessions, attach contexts, write prompts, and execute via hero_proc.
3. Context Manager
3.1 Purpose
The Context Manager allows the user to:
3.2 Repository Tree
The tree starts at known repositories.
Tree levels
Example:
hero_router
hero_proc
3.3 Selection Model
File selection
A file can be selected only if its extension is allowed.
Directory selection
Selecting a directory recursively includes all allowed files underneath it.
Multi-select
User can select:
Selection states
Each node supports:
Partial means some children are selected.
4. Allowed Extensions Model
4.1 Rule
We do not maintain ignore logic.
We use a strict allowlist.
Only files with these extensions are interesting.
4.2 Base allowed extensions
Optional to also support
.ymllater, but base spec uses the list above.4.3 Inclusion logic
Directory traversal
5. Tree UI Behavior
5.1 Display rules
Preferred behavior:
Alternative:
Preferred implementation is simpler:
5.2 Lazy loading
Directory children should load lazily to keep UI fast.
5.3 Search/filter
Tree should support quick filtering by:
Search only affects visibility, not saved selection state.
6. Context Builder Panel
Alongside the tree, show a live summary panel.
6.1 Summary data
Show:
6.2 File preview list
Show a flat preview list of included files.
Each row:
Actions:
7. Saved Contexts
7.1 Create context
User makes a selection, enters a name, saves it.
Required fields:
idnameselected_pathsallowed_extensionscreated_atupdated_atOptional:
description7.2 Saved context model
7.3 Reopen/edit
A saved context can be reopened.
When reopened:
7.4 Saved contexts list
The UI must show all contexts.
Each row/card shows:
Actions:
8. Context Rendering
8.1 Purpose
A context must be renderable into a prompt-ready text bundle for Claude.
8.2 Output format
Recommended format:
File: hero_router/src/lib.rs
Main requirement:
8.3 Ordering
Files should be rendered in stable deterministic order:
8.4 Copy action
User clicks Copy Context.
This copies the full rendered context bundle to clipboard.
9. Agents Tab
9.1 Purpose
The Agents tab is where users write prompts and execute them against Claude using saved contexts.
9.2 Layout
Left sidebar
List of prompt sessions
Main panel
Chat/prompt history
Right sidebar or top section
Attached contexts + execution status
10. Agent Prompt Sessions
10.1 Session model
A session stores:
idnameagent_idattached_context_idsmessagescreated_atupdated_at10.2 Message types
Messages can be:
10.3 Session actions
User can:
11. Claude Agent Integration
11.1 Initial scope
Only one agent is supported initially:
claude11.2 Execution backend
Claude is executed through your existing shell-based runner setup and managed by hero_proc.
The UI should not directly execute Claude.
It should create a hero_proc job.
11.3 Runner profiles
Future-ready support for runner variants:
Initial implementation may:
12. Attaching Contexts to Prompts
12.1 Rules
A prompt session can attach:
12.2 Actions
User can:
12.3 Execution composition
Final execution input is composed as:
Optionally later:
3. prior session history
13. Prompt Composer
13.1 Required UI elements
13.2 Basic flow
14. hero_proc Integration
14.1 Role
hero_proc is the job manager for all executions.
It is responsible for:
14.2 Execution request
When user clicks execute, UI creates a job request containing:
14.3 Job states
Use standard states:
14.4 Job metadata
Recommended metadata:
15. Recommended Data Models
15.1 Context
15.2 Prompt session
15.3 Execution record
16. Backend Requirements
16.1 Repository source
The system already knows repositories.
The Context Manager must read from that source of truth.
16.2 Filesystem API requirements
Need backend endpoints/services for:
17. Minimal API Surface
Context APIs
listRepos()listTree(path)saveContext(input)updateContext(id, input)deleteContext(id)listContexts()getContext(id)renderContext(id)Prompt/session APIs
listSessions()createSession(input)updateSession(id, input)deleteSession(id)attachContext(sessionId, contextId)detachContext(sessionId, contextId)Execution APIs
executeSession(sessionId, prompt, runnerProfile?)getExecution(jobId)getExecutionLogs(jobId)18. UX Requirements
Context Manager must feel:
Agents tab must feel:
19. Non-goals for initial version
Do not add yet:
20. MVP Scope
Context Manager MVP
Agents MVP
21. Short Implementation Summary
Tab 1: Context Manager
“Select useful files from repos, save as named reusable context.”
Tab 2: Agents
“Create a prompt session, attach one or more saved contexts, send to Claude via hero_proc.”
Filtering model
“Only include files with these extensions:
.py .rs .md .txt .ts .js .hero .hs .oschema .toml .json .yaml.”22. One-line product definition
A Repo Prompt-style context builder and Claude execution UI, backed by hero_proc, with reusable named contexts built from selected repository files.
If you want, I can turn this into a much more implementation-ready Rust/OpenRPC spec next.
use skills
Implementation Spec for Issue #8
Objective
Add a Context Manager + Agents UI to the existing
hero_codeadmin dashboard that lets users (a) browse repositories already known underCODEROOT, select files and directories with extension allowlist filtering, and save reusable named Contexts, and (b) create Agent Prompt Sessions, attach one or more contexts, write a prompt, and execute it through hero_proc as a tagged Claude agentic job (via thenuinterpreter +a 2 -i ...recipe). Only Claude is supported for v1.Requirements
static/js/*.jsincrates/hero_code_ui, JSON-RPC 2.0 via/rpcrouted tohero_code_server(do not introduce Dioxus or any new framework — the dashboard is a vanilla-JS Bootstrap SPA with tab panes inindex.html).nav-tabs-custombar and.app-contenttab-pane pattern.code.listRPC (walksCODEROOT). A newcode.treeRPC lazily lists directory children, filtered by the allowlist..py .rs .md .txt .ts .js .hero .hs .oschema .toml .json .yaml— strict positive filtering (hidden dotfiles andtarget/,node_modules/,.git/are also skipped).hero_proc_sdk(a 2 -i "<bundle + prompt>"), records the returnedjob_id, and pollsjob.*on hero_proc for status/logs.hero_code.db(newhero_code_agents.db) — matches the existinghero_code_lib::dbpattern (WAL,rusqlite, schema inmodel.rs, API infactory.rs). Do not use Redis or the filesystem — the repo already ships SQLite for jobs/logs.crates/hero_code_server/src/rpc/mod.rsand documented inopenrpc.json.Files to Modify/Create
hero_code_lib (new persistence)
crates/hero_code_lib/src/db/contexts/mod.rs— module wiring.crates/hero_code_lib/src/db/contexts/model.rs—Contextstruct, CRUD functions, schema init.crates/hero_code_lib/src/db/sessions/mod.rs— module wiring.crates/hero_code_lib/src/db/sessions/model.rs—PromptSession,ChatMessage,ExecutionRecordstructs + CRUD + schema init.crates/hero_code_lib/src/db/factory.rs— MODIFY: open a second SQLite file (hero_code_agents.db) next to the main DB; addpub contexts: ContextsApiandpub sessions: SessionsApifields onHeroRunnerDb.crates/hero_code_lib/src/db/mod.rs— MODIFY:pub mod contexts; pub mod sessions;.hero_code_server (RPC + Claude job launcher)
crates/hero_code_server/Cargo.toml— MODIFY: addhero_proc_sdk = { workspace = true }.crates/hero_code_server/src/rpc/tree.rs— new:code.tree(lazy, allowlist-filtered dir listing).crates/hero_code_server/src/rpc/context.rs— new:context.list,context.get,context.save,context.update,context.delete,context.render.crates/hero_code_server/src/rpc/session.rs— new:session.list,session.create,session.update,session.delete,session.attach_context,session.detach_context,session.add_message.crates/hero_code_server/src/rpc/agent.rs— new:agent.execute(builds Claude nu job viahero_proc_sdk, recordsExecutionRecord),agent.execution_get,agent.execution_logs.crates/hero_code_server/src/rpc/mod.rs— MODIFY: register new methods.crates/hero_code_server/openrpc.json— MODIFY: add new method definitions + component schemas.crates/hero_code_server/src/web.rs— MODIFY: add new methods topositional_to_namedmapping (optional — all new calls can mandate named params from JS to sidestep this).crates/hero_code_server/src/types/mod.rs&responses.rs— MODIFY if needed to re-export new domain types.hero_code_ui (dashboard tabs)
crates/hero_code_ui/templates/index.html— MODIFY: add two<a class="nav-link" data-tab="...">entries and two new<div class="tab-pane" id="tab-contexts">/id="tab-agents">panes.crates/hero_code_ui/static/js/contexts.js— new: Context Manager logic (repo picker → tree → selection → builder → save/list/edit/render/copy).crates/hero_code_ui/static/js/agents.js— new: session list, chat view, attach contexts, execute, poll logs.crates/hero_code_ui/static/js/dashboard.js— MODIFY: extend the tab-switch handler to callcontextsInit()/agentsInit()on first activation (mirrorscodeInit()).crates/hero_code_ui/static/css/dashboard.css— MODIFY: minor additions for the tree, builder panel, and chat bubble layout (no new<style>blocks in templates).Implementation Plan
Step 1: Data models + persistence
Files:
crates/hero_code_lib/src/db/contexts/{mod,model}.rs,crates/hero_code_lib/src/db/sessions/{mod,model}.rs,crates/hero_code_lib/src/db/factory.rs,crates/hero_code_lib/src/db/mod.rs.contexts/model.rs: withinit_schema,insert,update,get,list,delete. Storeselected_pathsandallowed_extensionsas JSON TEXT columns.sessions/model.rs: withinit_schema, CRUD, pluslist_messages(session_id),list_executions(session_id),update_execution_status(id, status, finished_at).factory.rs: open a second SQLite connection atparent/hero_code_agents.db, run schema init for both new tables, exposepub contexts: ContextsApi,pub sessions: SessionsApi.test_namespaced_jobs_apistyle.Dependencies: none.
Step 2: Context RPC + directory tree RPC
Files:
crates/hero_code_server/src/rpc/tree.rs,crates/hero_code_server/src/rpc/context.rs,crates/hero_code_server/src/rpc/mod.rs.tree.rs—code.tree(params: { path: string })returns{ entries: [{name, path, kind: "dir"|"file", size?}] }for one directory level, skipping hidden entries,target/,node_modules/,.git/, and files whose extension is not on the allowlist. Path must resolve underCODEROOT.context.rs:context.list→{ contexts: [...] }.context.get(id)→ full Context.context.save({ name, description?, selected_paths[], allowed_extensions? })→ created Context.context.update({ id, ... }).context.delete({ id }).context.render({ id })→{ text, file_count, byte_count }. Expansion logic:repoprefix fromCODEROOT/<org>/<repo>/....(repo, relative_path).rpc/mod.rsdispatch.Dependencies: Step 1.
Step 3: Session + execution RPC (Claude via hero_proc)
Files:
crates/hero_code_server/src/rpc/session.rs,crates/hero_code_server/src/rpc/agent.rs,crates/hero_code_server/src/rpc/mod.rs,crates/hero_code_server/Cargo.toml.hero_proc_sdk = { workspace = true }inhero_code_server/Cargo.toml.session.rs— CRUD + attach/detach/add_message againstdb.sessions.agent.rs:agent.execute({ session_id, prompt, runner_profile? }):render(ctx1)\n\n...\n\nrender(ctxN)\n\n# User Prompt\n\n<prompt>.ChatMessage {role:"user", content: prompt}.$HOME/hero/var/agents/<session_id>/<ts>.txt.ActionSpecperhero_proc_sdk_jobs_use:nu, tagshero_code + agent + claude, 10-min timeout,no_retry.use <HERO_AGENT_NU_PATH> *; let p = open "<bundle_path>"; a 2 -i $p.hero_proc_sdk::hero_proc_factory().await?.job_create(...).ExecutionRecordwithhero_proc_job_id,status="pending".{ execution_id, job_id, status }.agent.execution_get({ execution_id })→ fetch local record, live-poll hero_procjob.get, append the final agent message when the job terminates, return merged view.agent.execution_logs({ execution_id, lines? })→ proxy to hero_procjob.logs.rpc/mod.rs.Dependencies: Step 1, Step 2.
Step 4: OpenRPC spec updates
Files:
crates/hero_code_server/openrpc.json.$refcomponent schemas forContext,PromptSession,ChatMessage,ExecutionRecord, and all new method params/results.Dependencies: Step 3.
Step 5: UI — Contexts tab
Files:
crates/hero_code_ui/templates/index.html,crates/hero_code_ui/static/js/contexts.js,crates/hero_code_ui/static/js/dashboard.js,crates/hero_code_ui/static/css/dashboard.css.index.html:<a class="nav-link" data-tab="contexts" href="#/contexts"><i class="bi bi-folder-symlink"></i> Contexts</a>.#tab-contexts):code.tree), tri-state checkboxes, search filter.contexts.js:contextsInit()loads contexts + repos.contextsExpandDir(path)callscode.tree.contextsSave(),contextsLoad(id),contextsRender(id)→navigator.clipboard.writeText(text).dashboard.js: addcontextsto the tab switch callback map.dashboard.css: tree + tri-state checkbox styles using existing--accent-*CSS vars.Dependencies: Step 2.
Step 6: UI — Agents tab
Files:
crates/hero_code_ui/templates/index.html,crates/hero_code_ui/static/js/agents.js,crates/hero_code_ui/static/js/dashboard.js,crates/hero_code_ui/static/css/dashboard.css.index.html:<a class="nav-link" data-tab="agents" href="#/agents"><i class="bi bi-robot"></i> Agents</a>.#tab-agents): left = sessions list + "+ New"; center = chat + prompt textarea + "Run"; right = attached contexts (up/down reorder + "Add context" dropdown) + live execution status panel with log tail.agents.js:agentsInit()loadssession.list.agentsSelectSession(id)renders messages, attached contexts, resumes polling of any in-flight execution.agentsRun()callsagent.execute, pollsagent.execution_getevery 1s andagent.execution_logsevery 500ms until terminal.dashboard.js: registeragentsin the tab callback map.dashboard.css: chat bubbles + log tail<pre>styling.Dependencies: Step 3, Step 5.
Step 7: Tests + smoke
Files: unit tests inline in new modules.
context.renderexact format (fence, stable sort, allowlist filter).agent.rs(no real hero_proc — assert the script string and tags).hero_code --start, open the UI, create a repo-scoped context, save it, create a session, attach, execute "say hello", verify the job appears inhero_proc_uiwith taghero_code+agent+claudeand the agent stdout lands back in the chat.Dependencies: Steps 1–6.
Acceptance Criteria
CODEROOTrepos appear; clicking a directory lazily expands viacode.tree; only allowlisted files are shown.hero_code + agent + claude, returns ajob_id, and that job appears inhero_proc_uiat#jobs/<id>.pending -> running -> succeeded/failedby pollingagent.execution_get; live log tail appears while running.role:"agent"ChatMessage and displayed in the chat history.openrpc.jsonand reachable viaPOST /rpc.cargo check -p hero_code_lib -p hero_code_server -p hero_code_uipasses with no new warnings; existing tests still green.Notes
Persistence choice. SQLite via
rusqlite— the workspace already ships it forhero_code_lib::db. A second DB file (hero_code_agents.db) next tohero_code.dbreuses the factory idiom and avoids introducing sled, hero_db, or filesystem JSON. Redis (code_db) is only a cache/metadata store and is not a good fit for structured, queryable entities like contexts/sessions.UI framework choice. The repo is vanilla JS + Bootstrap + Askama (see
templates/index.html,static/js/*.js, existing tabs: Forge, IDE, Jobs, Logs, Docs, Admin, Perf, Stats). Adding Contexts and Agents tabs follows the same recipe as the existingcode_manage.js. No new UI framework.RPC routing.
hero_code_uino longer proxies/rpc— the router sends/rpcdirectly tohero_code_server's Unix socket. New methods only need to be implemented inhero_code_server/src/rpc/*.hero_proc integration. The
hero_codeCLI already useshero_proc_sdkto register its own service. The same SDK is reused insideagent.rsto submit Claude jobs, following thehero_proc_sdk_jobs_userecipe verbatim. The agent.nu path is read fromHERO_AGENT_NU_PATHwith a sensible default.Prompt size handling. A rendered bundle can easily exceed 1 MB and break shell quoting. The bundle is written to
$HOME/hero/var/agents/<session_id>/<ts>.txtand the nu script reads it withopen <path>. Bundles remain on disk for post-mortem inspection.Scope cut for v1 (this PR). Dropped from the MVP: token-count estimation (only file-count + byte-count), non-Claude agents, runner-profile selection (hardcode "A0"), drag-drop reorder for attached contexts (up/down buttons instead), inline message editing.
Follow-ups (explicitly deferred, not steps):
Test Results
cargo testcompleted successfully. All unit tests pass including:Implementation Summary
All planned steps have been implemented.
Changes made
New files:
crates/hero_code_lib/src/db/contexts/— Context data model and SQLite CRUD (stored in hero_code_agents.db)crates/hero_code_lib/src/db/sessions/— PromptSession, ChatMessage, ExecutionRecord models and SQLite CRUDcrates/hero_code_server/src/rpc/context.rs— JSON-RPC handlers: context.list/get/save/update/delete/rendercrates/hero_code_server/src/rpc/tree.rs— JSON-RPC handler: code.tree (directory listing under CODEROOT)crates/hero_code_server/src/rpc/session.rs— JSON-RPC handlers: session.list/get/save/update/delete/messages/message_add + agent.execute/execution_get/execution_logscrates/hero_code_ui/static/js/contexts.js— Contexts tab UI: file tree, multi-select, save/edit/delete contexts, copy rendered bundlecrates/hero_code_ui/static/js/agents.js— Agents tab UI: session list, chat history, prompt input, context attachment, execution pollingModified files:
crates/hero_code_lib/src/db/factory.rs— Added ContextsApi and SessionsApi to HeroRunnerDb, opened hero_code_agents.dbcrates/hero_code_lib/src/db/mod.rs— Exposed contexts and sessions modulescrates/hero_code_server/src/rpc/mod.rs— Registered all new RPC routescrates/hero_code_server/src/web.rs— Minor cleanupcrates/hero_code_server/Cargo.toml— Added hero_proc_sdk dependencycrates/hero_code_server/openrpc.json— Added code.tree, context., session., agent.* methods and schema typescrates/hero_code_ui/templates/index.html— Added Contexts and Agents tab links and panescrates/hero_code_ui/static/js/dashboard.js— Added switchTab cases for contexts and agentsKey design decisions