Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: add CI activity rule to GitHub notification automation, marking CI notices done by default
Adam Eivy4eb028fab5b6
diff --git a/client/src/components/github/GitHubAgentRules.jsx b/client/src/components/github/GitHubAgentRules.jsxindex a1abeaad75..725f560bee 100644--- a/client/src/components/github/GitHubAgentRules.jsx+++ b/client/src/components/github/GitHubAgentRules.jsx@@ -2,7 +2,7 @@ import { useEffect, useId, useRef, useState } from 'react';import { Bot, Pencil, Plus, X } from 'lucide-react';import ProviderModelSelector from '../ProviderModelSelector';import useRunWithPicker from '../../hooks/useRunWithPicker';-import { AGENT_RULE_KINDS } from './githubTriageLabels';+import { AGENT_RULE_KINDS, CI_RULE_ACTIONS } from './githubTriageLabels';const ALL_REPOS = '*';const OTHER_REPO = '__other__';@@ -12,7 +12,10 @@ const newRuleId = () => `rule-${Date.now().toString(36)}-${Math.random().toStrinconst repoLabel = (repo) => (repo === ALL_REPOS ? 'All repos' : repo);+const ciActionLabel = (action) => CI_RULE_ACTIONS.find((option) => option.value === action)?.label || action;+function pinLabel(rule, providers) {+ if (rule.kind === 'ci-activity') return ciActionLabel(rule.action);if (!rule.agent) return "Don't start an agent";const provider = rule.provider ? providers.find((entry) => entry.id === rule.provider)?.name || rule.provider : 'Auto provider';return ['Start an agent', provider, rule.model, rule.effort ? `${rule.effort} effort` : null].filter(Boolean).join(' · ');@@ -25,7 +28,9 @@ function RuleForm({ rule, repos, takenKeys, onCancel, onSubmit, saving }) {const knownRepo = !rule || rule.repo === ALL_REPOS || repos.includes(rule.repo);const [repoChoice, setRepoChoice] = useState(rule ? (knownRepo ? rule.repo : OTHER_REPO) : ALL_REPOS);const [otherRepo, setOtherRepo] = useState(knownRepo ? '' : rule?.repo || '');- const [agent, setAgent] = useState(rule ? rule.agent : true);+ const [agent, setAgent] = useState(rule ? rule.agent !== false : true);+ const [ciAction, setCiAction] = useState(rule?.action || 'done');+ const isCi = kind === 'ci-activity';const seeded = useRef(false);const { loading, setSelectedProviderId, setSelectedModel, setEffort } = picker;useEffect(() => {@@ -43,6 +48,10 @@ function RuleForm({ rule, repos, takenKeys, onCancel, onSubmit, saving }) {const submit = (event) => {event.preventDefault();if (!repoValid || clash) return;+ if (isCi) {+ onSubmit({ id: rule?.id || newRuleId(), kind, repo, action: ciAction });+ return;+ }onSubmit({id: rule?.id || newRuleId(),kind,@@ -73,10 +82,16 @@ function RuleForm({ rule, repos, takenKeys, onCancel, onSubmit, saving }) {</label><label htmlFor={`${formId}-agent`} className="space-y-1 text-xs text-gray-400"><span className="block">Then</span>- <select id={`${formId}-agent`} value={agent ? 'agent' : 'none'} onChange={(event) => setAgent(event.target.value === 'agent')} className="w-full rounded border border-port-border bg-port-card px-2 py-1.5 text-sm text-white">- <option value="agent">Start a CoS agent</option>- <option value="none">Don't start an agent</option>- </select>+ {isCi ? (+ <select id={`${formId}-agent`} value={ciAction} onChange={(event) => setCiAction(event.target.value)} className="w-full rounded border border-port-border bg-port-card px-2 py-1.5 text-sm text-white">+ {CI_RULE_ACTIONS.map((option) => <option key={option.value} value={option.value}>{option.label}</option>)}+ </select>+ ) : (+ <select id={`${formId}-agent`} value={agent ? 'agent' : 'none'} onChange={(event) => setAgent(event.target.value === 'agent')} className="w-full rounded border border-port-border bg-port-card px-2 py-1.5 text-sm text-white">+ <option value="agent">Start a CoS agent</option>+ <option value="none">Don't start an agent</option>+ </select>+ )}</label></div>{repoChoice === OTHER_REPO && (@@ -85,7 +100,7 @@ function RuleForm({ rule, repos, takenKeys, onCancel, onSubmit, saving }) {<input id={`${formId}-other`} value={otherRepo} onChange={(event) => setOtherRepo(event.target.value)} placeholder="owner/repo" autoComplete="off" className="w-full rounded border border-port-border bg-port-card px-2 py-1.5 font-mono text-sm text-white" /></label>)}- {agent && (+ {agent && !isCi && (<div className="space-y-1"><span className="flex items-center gap-1.5 text-xs text-gray-400"><Bot size={12} aria-hidden="true" /> Run with</span><ProviderModelSelector {...picker.selectorProps} compact />@@ -111,6 +126,8 @@ function RuleForm({ rule, repos, takenKeys, onCancel, onSubmit, saving }) {export default function GitHubAgentRules({ account, onSave, saving }) {const [editing, setEditing] = useState(null);const rules = account.agentRules || [];+ // Built-in rules apply until the operator saves a rule for the same kind and repo.+ const defaults = (account.defaultAgentRules || []).filter((rule) => !rules.some((entry) => entry.kind === rule.kind && entry.repo.toLowerCase() === rule.repo.toLowerCase()));const { providers } = useRunWithPicker({ preselectDefaults: false });const repos = account.repos || [];const kindLabel = (kind) => AGENT_RULE_KINDS.find((option) => option.value === kind)?.label || kind;@@ -136,6 +153,21 @@ export default function GitHubAgentRules({ account, onSave, saving }) {{account.mode !== 'autopilot' && rules.length > 0 && (<p className="text-xs text-port-warning">Autopilot follows these rules. This account is in {{ assist: 'Assist', disabled: 'Disabled' }[account.mode] || 'Observe'}, so nothing starts on its own yet.</p>)}+ {defaults.length > 0 && (+ <ul className="divide-y divide-port-border" aria-label="Default rules">+ {defaults.map((rule) => (+ <li key={rule.id} className="flex min-w-0 items-center gap-2 py-2">+ <div className="min-w-0 flex-1">+ <p className="truncate text-sm text-white">{kindLabel(rule.kind)} · {repoLabel(rule.repo)}</p>+ <p className="truncate text-xs text-port-success">{ciActionLabel(rule.action)} · default</p>+ </div>+ <button type="button" onClick={() => setEditing({ id: null, kind: rule.kind, repo: rule.repo, action: rule.action })} disabled={Boolean(editing)} className="inline-flex min-h-[44px] shrink-0 items-center justify-center rounded px-2 text-xs text-gray-400 hover:text-white disabled:opacity-40" aria-label={`Override default ${kindLabel(rule.kind)} rule`}>+ Override+ </button>+ </li>+ ))}+ </ul>+ )}{rules.length === 0 && !editing && (<p className="text-xs text-gray-500">No rules: security alerts and outside issues and pull requests in your apps go to their usual agents, and other review requests wait for you.</p>)}@@ -162,7 +194,7 @@ export default function GitHubAgentRules({ account, onSave, saving }) {</ul>)}{editing && !editing.id && (- <RuleForm rule={null} repos={repos} takenKeys={takenKeys} onCancel={() => setEditing(null)} onSubmit={upsert} saving={saving} />+ <RuleForm rule={editing.kind ? editing : null} repos={repos} takenKeys={takenKeys} onCancel={() => setEditing(null)} onSubmit={upsert} saving={saving} />)}</div>);diff --git a/client/src/components/github/githubTriageLabels.js b/client/src/components/github/githubTriageLabels.jsindex 4d20291a13..3c29f4d590 100644--- a/client/src/components/github/githubTriageLabels.js+++ b/client/src/components/github/githubTriageLabels.js@@ -71,6 +71,14 @@ export const AGENT_RULE_KINDS = [{ value: 'review-request', label: 'Review requests', hint: 'A review request starts a review-only Do:Review run that publishes an inline review. An outside pull request in one of your apps goes to Untrusted:Review instead.' },{ value: 'security-alert', label: 'Security alerts', hint: 'A security alert starts a run that updates the vulnerable dependencies, opens a pull request and merges it when checks pass.' },{ value: 'issue-activity', label: 'Issue activity', hint: 'Outside activity on an issue in one of your apps goes to its issue watcher.' },+ { value: 'ci-activity', label: 'CI activity', hint: 'A workflow run or check suite notice. By default Autopilot and Assist mark these done; pick another action per repo.' },+];++// What a ci-activity rule does with the notice (GITHUB_CI_RULE_ACTIONS on the server).+export const CI_RULE_ACTIONS = [+ { value: 'done', label: 'Mark done' },+ { value: 'mute', label: 'Mute the thread' },+ { value: 'leave', label: 'Leave in the inbox' },];// Why Resolve with agent is unavailable for a thread.diff --git a/server/lib/githubNotificationTriage.js b/server/lib/githubNotificationTriage.jsindex 1c1a3db95c..a9f7c1f3d8 100644--- a/server/lib/githubNotificationTriage.js+++ b/server/lib/githubNotificationTriage.js@@ -229,7 +229,9 @@ const PULL_PATH_RE = /\/pulls\/(\d{1,9})$/;// The notification kinds an agent rule can name (GITHUB_AGENT_RULE_KINDS in// lib/validation.js), and the kind of a thread, or null when no rule applies.-const RULE_KINDS = new Set(['review-request', 'security-alert', 'issue-activity']);+const RULE_KINDS = new Set(['review-request', 'security-alert', 'issue-activity', 'ci-activity']);+// `ci-activity` rules name a GitHub action instead of starting an agent.+export const CI_RULE_ACTIONS = Object.freeze(['done', 'mute', 'leave']);const RULE_REPO_RE = /^(?:\*|[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100})$/;// A review request still waiting on you; one you sorted as done or noise is not.const REVIEW_DECISIONS = new Set(['suggest-review', 'suggest-untrusted-review', 'needs-you', 'surface']);@@ -250,7 +252,28 @@ function threadAgentKind(row) {*/const validRules = (rules, kind) => (Array.isArray(rules) ? rules : []).filter((rule) => rule&& RULE_KINDS.has(rule.kind) && rule.kind === kind- && typeof rule.repo === 'string' && RULE_REPO_RE.test(rule.repo) && typeof rule.agent === 'boolean');+ && typeof rule.repo === 'string' && RULE_REPO_RE.test(rule.repo)+ && (kind === 'ci-activity' ? CI_RULE_ACTIONS.includes(rule.action) : typeof rule.agent === 'boolean'));++// Built-in rules shown under every account. A rule the operator saves for the+// same kind and repo wins; with none, a CI notice is simply marked done.+export const DEFAULT_AGENT_RULES = Object.freeze([+ Object.freeze({ id: 'default-ci-activity', kind: 'ci-activity', repo: '*', action: 'done', builtin: true }),+]);++const isCiThread = (row) => row?.reason === 'ci_activity' || row?.subject_type === 'CheckSuite';++/**+ * What the account's rules do with a CI notification: `done`, `mute` or+ * `leave`. The repo's own rule, else the `*` rule, else the built-in default.+ * Suspect and closed-out threads are handled elsewhere, so this only reads+ * the thread's kind and repo.+ */+export function ciActivityAction({ account, row }) {+ if (!isCiThread(row)) return null;+ const rules = [...(Array.isArray(account?.agentRules) ? account.agentRules : []), ...DEFAULT_AGENT_RULES];+ return matchAgentRule(rules, 'ci-activity', row.repo_full_name)?.action || null;+}function matchAgentRule(rules, kind, repo) {if (!kind) return null;diff --git a/server/lib/githubNotificationTriage.test.js b/server/lib/githubNotificationTriage.test.jsindex 9e0b1b57ec..eca93af957 100644--- a/server/lib/githubNotificationTriage.test.js+++ b/server/lib/githubNotificationTriage.test.js@@ -1,6 +1,6 @@import { describe, it, expect } from 'vitest';import {- agentHandoff, agentRuleScope, applyLearnedRule, assistAction, autopilotHandoff, computeThreadTrust, decideThread, decisionFromVerdict, matchWaitingRun, parseCiBranch,+ agentHandoff, agentRuleScope, ciActivityAction, applyLearnedRule, assistAction, autopilotHandoff, computeThreadTrust, decideThread, decisionFromVerdict, matchWaitingRun, parseCiBranch,selectNotificationProvider, spamSignals,MASS_MENTION_THRESHOLD,} from './githubNotificationTriage.js';@@ -252,3 +252,17 @@ describe('autopilotHandoff', () => {expect(agentHandoff({ account: enterprise, row: { ...review, repo_full_name: 'acme/app' } })).toEqual({ lane: 'pr-reviewer', pullNumber: 42, pin: { provider: 'p1' }, rule: { id: 'r', agent: true } });});});++describe('ciActivityAction', () => {+ const ci = { reason: 'ci_activity', subject_type: 'CheckSuite', repo_full_name: 'acme/app' };+ it('marks CI notices done by default and lets a repo or * rule override it', () => {+ expect(ciActivityAction({ account: { agentRules: [] }, row: ci })).toBe('done');+ const rules = [{ id: 'a', kind: 'ci-activity', repo: '*', action: 'leave' }, { id: 'b', kind: 'ci-activity', repo: 'acme/app', action: 'mute' }];+ expect(ciActivityAction({ account: { agentRules: rules }, row: ci })).toBe('mute');+ expect(ciActivityAction({ account: { agentRules: rules }, row: { ...ci, repo_full_name: 'acme/other' } })).toBe('leave');+ });+ it('ignores non-CI threads and malformed rules', () => {+ expect(ciActivityAction({ account: {}, row: { reason: 'mention', subject_type: 'Issue' } })).toBeNull();+ expect(ciActivityAction({ account: { agentRules: [{ kind: 'ci-activity', repo: '*', action: 'nuke' }] }, row: ci })).toBe('done');+ });+});diff --git a/server/lib/validation.js b/server/lib/validation.jsindex aae5d82109..68eb73b73f 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -955,18 +955,25 @@ export const GITHUB_ACCOUNT_MODES = Object.freeze(['disabled', 'observe', 'assis// Per-repo agent rules for the GitHub inbox: which kind of notification starts// a CoS agent, in one repo (`owner/repo`) or every repo (`*`), and on which// provider/model/effort. A repo rule wins over the `*` rule of the same kind.-export const GITHUB_AGENT_RULE_KINDS = Object.freeze(['review-request', 'security-alert', 'issue-activity']);+export const GITHUB_AGENT_RULE_KINDS = Object.freeze(['review-request', 'security-alert', 'issue-activity', 'ci-activity']);+export const GITHUB_CI_RULE_ACTIONS = Object.freeze(['done', 'mute', 'leave']);export const GITHUB_AGENT_RULE_REPO_RE = /^(?:\*|[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100})$/;const emptyToNullString = (value) => (value === '' ? null : value);export const githubAgentRuleSchema = z.object({id: z.string().regex(/^[A-Za-z0-9-]{1,64}$/),kind: z.enum(GITHUB_AGENT_RULE_KINDS),repo: z.string().trim().regex(GITHUB_AGENT_RULE_REPO_RE, 'Use owner/repo, or * for every repo'),- agent: z.boolean(),+ // `ci-activity` rules carry an `action` instead of `agent`.+ agent: z.boolean().optional(),+ action: z.enum(GITHUB_CI_RULE_ACTIONS).optional(),provider: z.preprocess(emptyToNullString, z.string().trim().min(1).max(128).nullable()).optional(),model: z.preprocess(emptyToNullString, z.string().trim().min(1).max(200).nullable()).optional(),effort: z.preprocess(emptyToNullString, z.enum(EFFORT_LEVELS).nullable()).optional(),-}).strict();+}).strict().superRefine((rule, ctx) => {+ const ci = rule.kind === 'ci-activity';+ if (ci && !rule.action) ctx.addIssue({ code: 'custom', path: ['action'], message: 'Choose what to do with CI notifications' });+ if (!ci && typeof rule.agent !== 'boolean') ctx.addIssue({ code: 'custom', path: ['agent'], message: 'Choose whether to start an agent' });+});export const githubAgentRulesSchema = z.array(githubAgentRuleSchema).max(200).superRefine((rules, ctx) => {const seen = new Set();rules.forEach((rule, index) => {diff --git a/server/services/githubNotificationAssist.js b/server/services/githubNotificationAssist.jsindex daa794bfcc..34f9087fdc 100644--- a/server/services/githubNotificationAssist.js+++ b/server/services/githubNotificationAssist.js@@ -15,7 +15,7 @@ import { z } from 'zod';import { query, withTransaction } from '../lib/db.js';import { safeJSONParse } from '../lib/fileUtils.js';import { repoApiPath } from '../lib/githubNotificationParse.js';-import { ASSIST_VERDICTS, assistAction, decisionFromVerdict, selectNotificationProvider } from '../lib/githubNotificationTriage.js';+import { ASSIST_VERDICTS, assistAction, ciActivityAction, decisionFromVerdict, selectNotificationProvider } from '../lib/githubNotificationTriage.js';import { resolveUntrustedContentPolicy } from '../lib/untrustedContent.js';import { toPgJson } from '../lib/pgJson.js';import { execGh } from './github.js';@@ -128,14 +128,18 @@ export async function assistAccountNotifications(account, env, { act }) {if (!ASSIST_MODES.has(account.mode)) return { sorted: 0, acted: 0 };const sorted = await sortUndecided(account, env);const { rows } = await query(- `SELECT thread_id, decision, trust, suspect, state, evidence->>'rule' AS rule FROM github_notifications- WHERE account_id = $1 AND state = 'open' AND NOT suspect AND decision = ANY($2::text[]) AND NOT (evidence ? 'assisted')+ `SELECT thread_id, decision, trust, suspect, state, reason, subject_type, repo_full_name, evidence->>'rule' AS rule FROM github_notifications+ WHERE account_id = $1 AND state = 'open' AND NOT suspect AND NOT (evidence ? 'assisted')+ AND (decision = ANY($2::text[]) OR reason = 'ci_activity' OR subject_type = 'CheckSuite')ORDER BY gh_updated_at DESC LIMIT ${MAX_ACTIONS_PER_RUN}`,[account.id, ACTIONABLE_DECISIONS],);let acted = 0;for (const row of rows) {- const action = assistAction(row);+ // A CI rule is the operator's own choice, so it needs no trusted actor;+ // `leave` falls back to the fixed table (a closed run is still done).+ const ciAction = ciActivityAction({ account, row });+ const action = (ciAction && ciAction !== 'leave' ? ciAction : null) || (ACTIONABLE_DECISIONS.includes(row.decision) ? assistAction(row) : null);if (!action) continue;const ok = await act(row.thread_id, action, { decision: row.decision, rule: row.rule }).then(() => true)diff --git a/server/services/githubNotifications.js b/server/services/githubNotifications.jsindex c708db4b89..9a5aee41a8 100644--- a/server/services/githubNotifications.js+++ b/server/services/githubNotifications.js@@ -24,7 +24,7 @@ import { getAccount, listAccounts, resolveGitHubAccountEnv } from './githubAccouimport { githubNotificationEvents } from './githubNotificationEvents.js';import { triageAccountNotifications } from './githubNotificationTriage.js';import { assistAccountNotifications } from './githubNotificationAssist.js';-import { agentHandoff, FINISHED_DECISIONS, learnedDecisionForAction } from '../lib/githubNotificationTriage.js';+import { agentHandoff, DEFAULT_AGENT_RULES, FINISHED_DECISIONS, learnedDecisionForAction } from '../lib/githubNotificationTriage.js';import { toPgJson } from '../lib/pgJson.js';const GH_TIMEOUT_MS = 30_000;@@ -670,6 +670,7 @@ export async function getAutomationsOverview() {pending: counts?.pending || 0,allowAgents: account.allowAgents === true,agentRules: Array.isArray(account.agentRules) ? account.agentRules : [],+ defaultAgentRules: DEFAULT_AGENT_RULES,repos: reposById.get(account.id) || [],};}),