From 1d4dd157fef016569d9523edcc3052dfe3a8852e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 1 Sep 2026 13:32:51 +0000 Subject: [PATCH 1/2] feat: add Conduit-wide prompt instructions and files Operators can create instructions (prepended to every agent prompt) and files (written into each run workspace and inlined in the prompt) that apply to every run, with the same ownership/sharing model as global MCPs. Co-authored-by: Doug Rathbone --- CLAUDE.md | 8 + README.md | 1 + src/main/db/index.ts | 12 + src/main/db/queries/access.ts | 1 + src/main/db/queries/globalPromptComponents.ts | 143 +++++++ src/main/db/schema.ts | 12 + src/renderer/App.tsx | 5 +- .../components/agents/AgentEditor.tsx | 12 +- src/renderer/components/layout/Sidebar.tsx | 31 +- .../settings/PromptComponentManager.tsx | 401 ++++++++++++++++++ .../hooks/useGlobalPromptComponents.ts | 49 +++ src/renderer/hooks/useShares.ts | 2 + src/renderer/lib/ipc.ts | 3 + src/renderer/lib/ws-client.ts | 12 + src/renderer/store/ui.ts | 41 +- src/server/index.ts | 48 +++ src/server/runner.ts | 7 +- src/server/workers/localWorker.ts | 4 + src/server/workspaceFiles.test.ts | 43 ++ src/server/workspaceFiles.ts | 36 ++ src/shared/promptComponents.test.ts | 87 ++++ src/shared/promptComponents.ts | 118 ++++++ src/shared/types.ts | 38 +- src/shared/worker.ts | 6 + 24 files changed, 1107 insertions(+), 13 deletions(-) create mode 100644 src/main/db/queries/globalPromptComponents.ts create mode 100644 src/renderer/components/settings/PromptComponentManager.tsx create mode 100644 src/renderer/hooks/useGlobalPromptComponents.ts create mode 100644 src/server/workspaceFiles.test.ts create mode 100644 src/server/workspaceFiles.ts create mode 100644 src/shared/promptComponents.test.ts create mode 100644 src/shared/promptComponents.ts diff --git a/CLAUDE.md b/CLAUDE.md index c61b846..4aabf9c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -225,6 +225,14 @@ per-run configs post-run plus a startup sweep (6h grace). Runs record any workspace/config they created when `startRun` throws; `fixedDir` workspaces are local-only. +## Conduit-wide prompt components + +Enabled rows in `global_prompt_components` are applied to **every** run (same +injection model as global MCPs — sharing only controls who can see/edit them +in the UI). Instructions are prepended to the prompt; files are written into +the materialized workspace (`RunSpec.workspaceFiles`) and also inlined in the +prompt. Path validation lives in `src/shared/promptComponents.ts`. + ## Key Patterns **Adding a new entity type** — follow the publish targets pattern: diff --git a/README.md b/README.md index 22e6f0f..96b1f58 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ A self-hosted web app for managing and running AI CLI agents (Claude Code, Amp, - **Multi-runner** — Claude Code, Amp, and Cursor agents - **Live terminal streaming** — xterm.js with full ANSI colour output - **MCP management** — global and per-agent servers with OAuth support and health indicators +- **Prompt components** — Conduit-wide instructions and files prepended to every agent run - **Pluggable execution** — run agents in-process, on remote workers, or as ephemeral EKS Jobs / Fargate tasks - **Scheduled runs** — cron triggers per agent - **Publish targets** — deliver agent output to Slack, email (SMTP), or signed webhooks diff --git a/src/main/db/index.ts b/src/main/db/index.ts index 453c894..e44195a 100644 --- a/src/main/db/index.ts +++ b/src/main/db/index.ts @@ -164,6 +164,18 @@ export async function initDb(): Promise { updated_at BIGINT NOT NULL ); + CREATE TABLE IF NOT EXISTS global_prompt_components ( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + kind TEXT NOT NULL, + content TEXT NOT NULL DEFAULT '', + file_path TEXT, + enabled BOOLEAN NOT NULL DEFAULT TRUE, + owner_id TEXT, + created_at BIGINT NOT NULL, + updated_at BIGINT NOT NULL + ); + CREATE TABLE IF NOT EXISTS runs ( id TEXT PRIMARY KEY, agent_id TEXT NOT NULL REFERENCES agents(id), diff --git a/src/main/db/queries/access.ts b/src/main/db/queries/access.ts index dd6b368..8bac246 100644 --- a/src/main/db/queries/access.ts +++ b/src/main/db/queries/access.ts @@ -7,6 +7,7 @@ const TABLE_MAP: Record = { publishTarget: 'publish_targets', repository: 'repositories', globalMcpServer: 'global_mcp_servers', + globalPromptComponent: 'global_prompt_components', } // Rewrites `?` placeholders to pg-style `$1..$n` in positional order. diff --git a/src/main/db/queries/globalPromptComponents.ts b/src/main/db/queries/globalPromptComponents.ts new file mode 100644 index 0000000..afd1a82 --- /dev/null +++ b/src/main/db/queries/globalPromptComponents.ts @@ -0,0 +1,143 @@ +import { eq } from 'drizzle-orm' +import { getDb } from '../index' +import { globalPromptComponents } from '../schema' +import { getVisibleEntityIds } from './access' +import { deleteSharesForEntity } from './shares' +import type { GlobalPromptComponent, GlobalPromptComponentKind } from '../../../shared/types' +import { validatePromptComponentInput } from '../../../shared/promptComponents' + +function rowToComponent(row: typeof globalPromptComponents.$inferSelect): GlobalPromptComponent { + return { + id: row.id, + name: row.name, + kind: row.kind as GlobalPromptComponentKind, + content: row.content, + filePath: row.filePath ?? undefined, + enabled: row.enabled, + ownerId: row.ownerId ?? undefined, + createdAt: row.createdAt, + updatedAt: row.updatedAt, + } +} + +async function findFilePathConflict(filePath: string, excludeId?: string): Promise { + const rows = await getDb().select().from(globalPromptComponents) + const hit = rows.find((r) => r.kind === 'file' && r.filePath === filePath && r.id !== excludeId) + return hit ? hit.name : null +} + +export async function listGlobalPromptComponents( + userId: string, + userGroupIds: string[] +): Promise { + const visibleIds = await getVisibleEntityIds('globalPromptComponent', userId, userGroupIds) + if (visibleIds.length === 0) return [] + const rows = await getDb().select().from(globalPromptComponents) + return rows.filter((r) => visibleIds.includes(r.id)).map(rowToComponent) +} + +/** All enabled components — injected into every run regardless of sharing. */ +export async function listEnabledGlobalPromptComponents(): Promise { + const rows = await getDb() + .select() + .from(globalPromptComponents) + .where(eq(globalPromptComponents.enabled, true)) + return rows.map(rowToComponent) +} + +export async function getGlobalPromptComponent(id: string): Promise { + const rows = await getDb() + .select() + .from(globalPromptComponents) + .where(eq(globalPromptComponents.id, id)) + return rows.length ? rowToComponent(rows[0]) : null +} + +export async function createGlobalPromptComponent( + data: Omit, + ownerId: string +): Promise { + const validated = validatePromptComponentInput(data) + if (validated.kind === 'file' && validated.filePath) { + const conflict = await findFilePathConflict(validated.filePath) + if (conflict) { + throw new Error( + `A file component already writes "${validated.filePath}" (component "${conflict}"). File paths must be unique.` + ) + } + } + + const now = Date.now() + const id = crypto.randomUUID() + await getDb().insert(globalPromptComponents).values({ + id, + name: data.name.trim(), + kind: validated.kind, + content: data.content ?? '', + filePath: validated.kind === 'file' ? validated.filePath : null, + enabled: data.enabled, + ownerId, + createdAt: now, + updatedAt: now, + }) + + const rows = await getDb() + .select() + .from(globalPromptComponents) + .where(eq(globalPromptComponents.id, id)) + if (rows.length === 0) throw new Error(`Failed to create prompt component with id ${id}`) + return rowToComponent(rows[0]) +} + +export async function updateGlobalPromptComponent( + id: string, + data: Partial> +): Promise { + const existing = await getGlobalPromptComponent(id) + if (!existing) throw new Error(`Prompt component with id ${id} not found`) + + const merged = { + name: data.name ?? existing.name, + kind: data.kind ?? existing.kind, + content: data.content ?? existing.content, + filePath: data.filePath !== undefined ? data.filePath : existing.filePath, + enabled: data.enabled ?? existing.enabled, + } + const validated = validatePromptComponentInput(merged) + if (validated.kind === 'file' && validated.filePath) { + const conflict = await findFilePathConflict(validated.filePath, id) + if (conflict) { + throw new Error( + `A file component already writes "${validated.filePath}" (component "${conflict}"). File paths must be unique.` + ) + } + } + + await getDb() + .update(globalPromptComponents) + .set({ + name: merged.name.trim(), + kind: validated.kind, + content: merged.content, + filePath: validated.kind === 'file' ? validated.filePath : null, + enabled: merged.enabled, + updatedAt: Date.now(), + }) + .where(eq(globalPromptComponents.id, id)) + + const rows = await getDb() + .select() + .from(globalPromptComponents) + .where(eq(globalPromptComponents.id, id)) + if (rows.length === 0) throw new Error(`Prompt component with id ${id} not found after update`) + return rowToComponent(rows[0]) +} + +export async function deleteGlobalPromptComponent(id: string): Promise { + await deleteSharesForEntity('globalPromptComponent', id) + const deleted = await getDb() + .delete(globalPromptComponents) + .where(eq(globalPromptComponents.id, id)) + .returning({ id: globalPromptComponents.id }) + return deleted.length +} diff --git a/src/main/db/schema.ts b/src/main/db/schema.ts index 696dcc7..a497879 100644 --- a/src/main/db/schema.ts +++ b/src/main/db/schema.ts @@ -160,6 +160,18 @@ export const globalMcpServers = pgTable('global_mcp_servers', { updatedAt: bigint('updated_at', { mode: 'number' }).notNull(), }) +export const globalPromptComponents = pgTable('global_prompt_components', { + id: text('id').primaryKey(), + name: text('name').notNull(), + kind: text('kind').notNull(), + content: text('content').notNull().default(''), + filePath: text('file_path'), + enabled: boolean('enabled').notNull().default(true), + ownerId: text('owner_id'), + createdAt: bigint('created_at', { mode: 'number' }).notNull(), + updatedAt: bigint('updated_at', { mode: 'number' }).notNull(), +}) + export const publishTargets = pgTable('publish_targets', { id: text('id').primaryKey(), name: text('name').notNull(), diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 4066f09..06a90b5 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -6,6 +6,7 @@ import { GlobalMcpManager } from './components/settings/GlobalMcpManager' import { PublishTargetManager } from './components/settings/PublishTargetManager' import { RepositoryManager } from './components/settings/RepositoryManager' import { SettingsManager } from './components/settings/SettingsManager' +import { PromptComponentManager } from './components/settings/PromptComponentManager' import { LoginPage } from './components/LoginPage' import { useAuth } from './contexts/AuthContext' import { useUIStore } from './store/ui' @@ -65,7 +66,7 @@ function EmptyState() { export default function App() { const { isAuthenticated } = useAuth() - const { selectedAgentId, selectAgent, showGlobalMcpManager, showPublishTargets, showRepositories, showSettings } = useUIStore() + const { selectedAgentId, selectAgent, showGlobalMcpManager, showPublishTargets, showRepositories, showSettings, showPromptComponents } = useUIStore() const createAgent = useCreateAgent() const handleNewAgent = useCallback(async () => { @@ -133,6 +134,8 @@ export default function App() { ) : showRepositories ? ( + ) : showPromptComponents ? ( + ) : showGlobalMcpManager ? ( ) : showPublishTargets ? ( diff --git a/src/renderer/components/agents/AgentEditor.tsx b/src/renderer/components/agents/AgentEditor.tsx index a268877..0bbd2ef 100644 --- a/src/renderer/components/agents/AgentEditor.tsx +++ b/src/renderer/components/agents/AgentEditor.tsx @@ -174,7 +174,7 @@ export const AgentEditor = forwardRef(funct const { data: allRepos = [] } = useRepositories() const { data: triggers = [] } = useTriggers(agentId) useRepoSyncEvents() - const { setShowPublishTargets, setShowRepositories } = useUIStore() + const { setShowPublishTargets, setShowRepositories, setShowPromptComponents } = useUIStore() const [draft, setDraft] = useState>({}) const [saveState, setSaveState] = useState('idle') @@ -438,6 +438,16 @@ export const AgentEditor = forwardRef(funct {/* Prompt — the heart of the agent */} +

+ Conduit-wide instructions and files are prepended automatically.{' '} + +

handleChange('prompt', v)} diff --git a/src/renderer/components/layout/Sidebar.tsx b/src/renderer/components/layout/Sidebar.tsx index 4a41db2..0d956fa 100644 --- a/src/renderer/components/layout/Sidebar.tsx +++ b/src/renderer/components/layout/Sidebar.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { Plus, Sun, Moon, Monitor, Server, Send, FolderGit2, Settings } from 'lucide-react' +import { Plus, Sun, Moon, Monitor, Server, Send, FolderGit2, Settings, ScrollText } from 'lucide-react' import { Button } from '@renderer/components/ui/button' import { AgentList } from '@renderer/components/agents/AgentList' import { UserMenu } from '@renderer/components/UserMenu' @@ -8,17 +8,20 @@ import { useCreateAgent } from '@renderer/hooks/useAgents' import { useGlobalMcps } from '@renderer/hooks/useGlobalMcps' import { usePublishTargets } from '@renderer/hooks/usePublishTargets' import { useRepositories } from '@renderer/hooks/useRepositories' +import { useGlobalPromptComponents } from '@renderer/hooks/useGlobalPromptComponents' import { cn } from '@renderer/lib/utils' export function Sidebar() { - const { theme, setTheme, selectAgent, showGlobalMcpManager, setShowGlobalMcpManager, showPublishTargets, setShowPublishTargets, showRepositories, setShowRepositories, showSettings, setShowSettings } = useUIStore() + const { theme, setTheme, selectAgent, showGlobalMcpManager, setShowGlobalMcpManager, showPublishTargets, setShowPublishTargets, showRepositories, setShowRepositories, showSettings, setShowSettings, showPromptComponents, setShowPromptComponents } = useUIStore() const createAgent = useCreateAgent() const { data: globalMcps = [] } = useGlobalMcps() const { data: publishTargets = [] } = usePublishTargets() const { data: repositories = [] } = useRepositories() + const { data: promptComponents = [] } = useGlobalPromptComponents() const enabledGlobalCount = globalMcps.filter((m) => m.enabled).length const enabledPublishCount = publishTargets.filter((t) => t.enabled).length const readyRepoCount = repositories.filter((r) => r.syncStatus === 'ready').length + const enabledPromptCount = promptComponents.filter((c) => c.enabled).length const handleNewAgent = async () => { try { @@ -111,6 +114,30 @@ export function Sidebar() { )} + + + +
+ + +
+ + {form.kind === 'file' && ( + + )} + +