Files
sovereign_browser/plans/system-prompt-as-skill.md

9.0 KiB

System Prompt as the Default Sovereign Browser Skill

Goal

The system prompt on sovereign://agents is essentially the default skill for sovereign_browser. Instead of having a separate "System Prompt" field, we treat it as an unsaved skill that the user can edit, save, and share — matching how ai.html handles skills.

Current state

  • sovereign://agents (config page) has a "System Prompt" textarea saved to sovereign_browser.agent.system_prompt in the d:user-settings event.
  • sovereign://agents/chat has a skills list (kind 31123) with checkboxes.
  • The agent loop (agent_loop.c) uses the system prompt from settings, OR the concatenated templates of selected skills (if any skills are selected).

Desired state

  • Rename "System Prompt" to "Sovereign Browser Skill" on the config page.
  • The system prompt is presented as an unsaved skill — a skill that exists locally but hasn't been published to Nostr yet.
  • In the chat page, the "Sovereign Browser Skill" appears in the skills list as an unsaved skill (with a "Save" button to publish it as kind 31123).
  • The user can edit the skill (name, description, template, tools) inline, matching ai.html's renderSkillsEditor() pattern.
  • The user can save the skill to Nostr (publishes kind 31123), making it available to other apps (client, didactyl).
  • The user can modify saved skills the same way (if they're the author).

Design

On sovereign://agents (config page)

Replace the "System Prompt" section with a "Sovereign Browser Skill" section:

┌─────────────────────────────────────────────┐
│ Sovereign Browser Skill                     │
├─────────────────────────────────────────────┤
│ Name: [Sovereign Browser Default      ]     │
│ Description: [Default agent skill     ]     │
│ Template:                                   │
│ ┌───────────────────────────────────────┐   │
│ │ You are an AI assistant embedded in   │   │
│ │ a web browser. You have access to...  │   │
│ └───────────────────────────────────────┘   │
│ Requires tools: [browser, fs, shell   ]     │
│                                              │
│ [💾 Save as Skill]  (publishes to Nostr)    │
└─────────────────────────────────────────────┘
  • The template is the current system prompt value.
  • "Save as Skill" publishes a kind 31123 event with the skill content.
  • The skill is saved to sovereign_browser.agent.system_prompt locally (as now) AND optionally published to Nostr as a skill.

On sovereign://agents/chat (chat page)

The skills list shows:

  1. Sovereign Browser Skill (unsaved) — always at the top, with a checkbox (selected by default), an edit button, and a "Save" button.
  2. Saved skills (kind 31123) — fetched from Nostr, with checkboxes, edit buttons (if user-authored), and delete buttons.

When the user selects the Sovereign Browser Skill, its template is used as the system prompt (concatenated with any other selected skills, matching the existing agent_skills_build_system_prompt() logic).

Skill editor (matching ai.html)

When the user clicks "Edit" on a skill (or the Sovereign Browser Skill), an inline editor expands (like ai.html's renderSkillsEditor()):

▼ Sovereign Browser Default
  ┌──────────────────────────────────────────┐
  │ Name:    [Sovereign Browser Default    ] │
  │ Description: [Default agent skill      ] │
  │ Template:                                │
  │ ┌────────────────────────────────────┐   │
  │ │ You are an AI assistant embedded...│   │
  │ └────────────────────────────────────┘   │
  │ Requires tools: [browser, fs, shell  ]   │
  │                                          │
  │ [💾 Save / Update]  [Cancel]             │
  └──────────────────────────────────────────┘
  • For the Sovereign Browser Skill (unsaved): "Save" publishes it to Nostr as a new kind 31123 event AND updates the local system prompt.
  • For saved skills (user-authored): "Save / Update" re-publishes the kind 31123 event with the edited content.
  • For saved skills (not user-authored): "View Only (not your skill)" — no edit, matching ai.html's canSave logic.

Implementation

Phase 1 — Rename + restructure the config page

  1. www/agents/config.html + config.js — Replace the "System Prompt" section with a "Sovereign Browser Skill" section with Name, Description, Template, and Requires Tools fields. Add a "Save as Skill" button.

  2. src/nostr_bridge.c — Update handle_agents_set() to handle the new skill fields (agent.skill_name, agent.skill_description, agent.skill_template, agent.skill_requires_tools). These are saved to sovereign_browser.agent in the d:user-settings event (replacing the old system_prompt field).

  3. src/agent_loop.c — Update the system prompt logic: use sovereign_browser.agent.skill_template as the default system prompt (instead of system_prompt). If skills are selected, concatenate their templates (as now).

Phase 2 — Show the Sovereign Browser Skill in the chat page

  1. www/agents/chat.js — In renderSkillList(), add the Sovereign Browser Skill at the top of the list as an "unsaved" skill. It has:

    • A checkbox (selected by default)
    • The skill name (from sovereign_browser.agent.skill_name)
    • An "Edit" button that opens the inline editor
    • A "Save" button that publishes it to Nostr
  2. src/agent_skills.c — Add a function agent_skills_get_default() that returns the Sovereign Browser Skill from the local settings (not from Nostr). This is used by the chat page to show the unsaved skill.

  3. src/nostr_bridge.c — Add a sovereign://agents/skills/default endpoint that returns the Sovereign Browser Skill from settings.

Phase 3 — Skill editor in the chat page

  1. www/agents/chat.js — Implement renderSkillEditor(skill) matching ai.html's renderSkillsEditor():

    • Expandable <details> for each selected skill
    • Name, Description, Template, Requires Tools fields
    • "Save / Update" button (for user-authored or unsaved skills)
    • "View Only" for skills not authored by the user
  2. src/nostr_bridge.c — Add a sovereign://agents/skills/update endpoint that re-publishes an existing skill (kind 31123) with edited content. For the Sovereign Browser Skill, this also updates the local settings.

  3. src/agent_skills.c — Add agent_skills_update(d_tag, name, description, content, requires_tools) that fetches the existing skill event, updates its content, re-signs, and re-publishes.

Phase 4 — Wire the default skill into the agent loop

  1. src/agent_loop.c — The system prompt is now:

    • If the Sovereign Browser Skill is selected (default): use its template
    • If other skills are selected: concatenate their templates
    • If no skills selected: use the Sovereign Browser Skill template as fallback (it's always the default)
  2. src/agent_skills.c — Update agent_skills_build_system_prompt() to always include the Sovereign Browser Skill template (either as the base prompt, or concatenated with selected skills).

Files to modify

File Change
www/agents/config.html Rename "System Prompt" to "Sovereign Browser Skill", restructure fields
www/agents/config.js Handle new skill fields, "Save as Skill" button
www/agents/chat.js Show Sovereign Browser Skill in skills list, implement skill editor
www/agents/chat.css Style the skill editor (matching ai.html)
src/nostr_bridge.c New endpoints: skills/default, skills/update; update handle_agents_set()
src/agent_skills.c / .h agent_skills_get_default(), agent_skills_update()
src/agent_loop.c Use skill template as system prompt
src/settings.h / settings.c Rename agent_llm_system_prompt to agent_skill_template, add agent_skill_name, agent_skill_description, agent_skill_requires_tools

Reference

  • ~/lt/client/www/ai.html lines 1454-1540 — renderSkillsEditor() pattern
  • ~/lt/client/www/ai.html lines 1534-1538 — "Save / Update Skill" button
  • ~/lt/client/www/ai.html lines 1471 — canSave logic (only author can edit)