Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, under **Settings → Prompt components**). 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:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (Settings)
- **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
Expand Down
425 changes: 425 additions & 0 deletions prompts/fe-perf-loop.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/main/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ export async function initDb(): Promise<void> {
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),
Expand Down
1 change: 1 addition & 0 deletions src/main/db/queries/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const TABLE_MAP: Record<ShareableEntityType, string> = {
publishTarget: 'publish_targets',
repository: 'repositories',
globalMcpServer: 'global_mcp_servers',
globalPromptComponent: 'global_prompt_components',
}

// Rewrites `?` placeholders to pg-style `$1..$n` in positional order.
Expand Down
143 changes: 143 additions & 0 deletions src/main/db/queries/globalPromptComponents.ts
Original file line number Diff line number Diff line change
@@ -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<string | null> {
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<GlobalPromptComponent[]> {
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<GlobalPromptComponent[]> {
const rows = await getDb()
.select()
.from(globalPromptComponents)
.where(eq(globalPromptComponents.enabled, true))
return rows.map(rowToComponent)
}

export async function getGlobalPromptComponent(id: string): Promise<GlobalPromptComponent | null> {
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<GlobalPromptComponent, 'id' | 'createdAt' | 'updatedAt'>,
ownerId: string
): Promise<GlobalPromptComponent> {
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<Omit<GlobalPromptComponent, 'id' | 'createdAt' | 'updatedAt'>>
): Promise<GlobalPromptComponent> {
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<number> {
await deleteSharesForEntity('globalPromptComponent', id)
const deleted = await getDb()
.delete(globalPromptComponents)
.where(eq(globalPromptComponents.id, id))
.returning({ id: globalPromptComponents.id })
return deleted.length
}
12 changes: 12 additions & 0 deletions src/main/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/components/agents/AgentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const AgentEditor = forwardRef<AgentEditorHandle, AgentEditorProps>(funct
const { data: allRepos = [] } = useRepositories()
const { data: triggers = [] } = useTriggers(agentId)
useRepoSyncEvents()
const { setShowPublishTargets, setShowRepositories } = useUIStore()
const { setShowPublishTargets, setShowRepositories, setShowSettings } = useUIStore()

const [draft, setDraft] = useState<Partial<AgentConfig>>({})
const [saveState, setSaveState] = useState<SaveState>('idle')
Expand Down Expand Up @@ -422,6 +422,16 @@ export const AgentEditor = forwardRef<AgentEditorHandle, AgentEditorProps>(funct

{/* Prompt — the heart of the agent */}
<CollapsibleSection title="Prompt" hero summary={promptSummary}>
<p className="text-[11px] text-[var(--text-secondary)] mb-2">
Conduit-wide instructions and files are prepended automatically.{' '}
<button
type="button"
className="text-[var(--accent)] hover:underline"
onClick={() => setShowSettings(true)}
>
Manage in Settings
</button>
</p>
<PromptEditor
value={draft.prompt ?? ''}
onChange={(v) => handleChange('prompt', v)}
Expand Down
Loading
Loading