Skip to content

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

fix: keep GitHub automation rule internals private and their pinned sets immutable (#13192)

Adam Eivy2dec67632b3f
diff --git a/server/lib/README.md b/server/lib/README.md
index ad6549d8a9..d17a2e59f8 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -489,7 +489,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `gitOutputParsers.js` | `parseStatus`, `parseDiffStat`, `parseBranchVerboseLine`, `parseSubmoduleStatusLine`/`SUBMODULE_STATUS_RE`, `extractAgentSummary` — pure parsers turning git command output into structured data for `git.js`. `extractAgentSummary` anchors on `agentOutputMarkers`' completion marker so a TUI agent's PR body carries its sentinel summary, not the lifecycle telemetry above it. `isBenignConcurrentFetchRefRace(stderr)` reads a non-zero `git fetch` as a SUCCESS when its only failure is a lost compare-and-swap whose refs already hold the fetched commits — the routine outcome when the Git tab, `getRemoteBranches`, and CoS agent worktrees fetch one `.git` at once. |
| `githubNotificationAudit.js` | `AUDIT_WINDOW_DAYS`, `buildAuditSuggestions` — the GitHub notifications subscription audit's suggestions from 30 days of stored threads per repo × reason: unwatch, mute handled threads, and links for settings the API cannot change. |
| `githubNotificationParse.js` | `parseGhIncludeOutput`, `linkHeaderHasNext`, `pollIntervalSeconds`, `repoApiPath`, `advisoryIdFromUrl`, `GHSA_RE`, `notificationHtmlUrl`, `toNotificationRecord` — pure parsing for the GitHub notifications inbox: `gh api --include` output and thread records, with links rebuilt only onto the account's own GitHub host. |
-| `githubNotificationTriage.js` | `TRIAGE_DECISIONS`, `TRUST_LEVELS`, `MASS_MENTION_THRESHOLD`, `computeThreadTrust`, `spamSignals`, `parseCiBranch`, `decideThread`, `ASSIST_VERDICTS`, `decisionFromVerdict`, `learnedDecisionForAction`, `applyLearnedRule`, `assistAction`, `selectNotificationProvider`, `agentHandoff`, `autopilotHandoff`, `agentRuleScope`, `agentRunPin`, `GENERIC_AGENT_LANE`, `APP_FREE_AGENT_LANES`, `AGENT_RULE_KINDS`, `AGENT_RULE_ACTIONS`, `threadAgentKind`, `KIND_SQL`, `agentRuleAction`, `normalizeAgentRules`, `ruleAction`, `ruleActionScope`, `PINNED_TRIAGE_RULES` — the GitHub inbox's fixed trust, spam and routing rules plus Assist's verdict enum, learned rules, allowed actions and Private-account provider allow-list, plus agent lanes (with the generic `notification-resolve` lane's trust gate), per-repo automation rules (kind × agent/done/mute/leave, legacy `agent` booleans read as actions) and run-pin precedence; trust comes only from accounts, repo ownership and forge permissions, never from content. |
+| `githubNotificationTriage.js` | `TRIAGE_DECISIONS`, `TRUST_LEVELS`, `MASS_MENTION_THRESHOLD`, `computeThreadTrust`, `spamSignals`, `parseCiBranch`, `decideThread`, `ASSIST_VERDICTS`, `decisionFromVerdict`, `learnedDecisionForAction`, `applyLearnedRule`, `assistAction`, `selectNotificationProvider`, `agentHandoff`, `autopilotHandoff`, `agentRuleScope`, `agentRunPin`, `GENERIC_AGENT_LANE`, `APP_FREE_AGENT_LANES`, `AGENT_RULE_KINDS`, `AGENT_RULE_ACTIONS`, `GENERIC_RULE_KINDS`, `threadAgentKind`, `KIND_SQL`, `normalizeAgentRules`, `ruleAction`, `ruleActionScope`, `PINNED_TRIAGE_RULES` — the GitHub inbox's fixed trust, spam and routing rules plus Assist's verdict enum, learned rules, allowed actions and Private-account provider allow-list, plus agent lanes (with the generic `notification-resolve` lane's trust gate), per-repo automation rules (kind × agent/done/mute/leave, legacy `agent` booleans read as actions) and run-pin precedence; trust comes only from accounts, repo ownership and forge permissions, never from content. |
| `gitRemote.js` | `getOriginInfo`, `classifyOriginRemote`, `parseGitRemoteUrl`, `readRemoteUrl`, `isUpstreamOwner`, `isUpstreamFullName`, `UPSTREAM_OWNER`/`UPSTREAM_REPO` — safely reads and classifies checkout remotes against PortOS or a caller-supplied canonical upstream. Used by self-update and managed integrations to detect forks. |
| `gitStaleLock.js` | `gitLockPathFromError`, `isStaleGitLock`, `clearStaleGitLock`, `clearStaleGitLocksIn`, `STALE_GIT_LOCK_MIN_AGE_MS` — recognizes the `*.lock` a KILLED git process left behind and removes it so the caller can retry. A lock under `.git/modules/<submodule>/` is shared by every worktree of the repo, so one dead process wedges submodule checkout install-wide with a bogus "another git process is running". Removal requires a `.lock` path under a `.git` directory (so a malformed message cannot aim the unlink at `yarn.lock`) that is older than 30 minutes — 3x the longest git command PortOS runs (`worktreeManager.WORKTREE_ADD_TIMEOUT_MS`, pinned by a test), which is what keeps it from deleting a LIVE competitor's lock. The threshold is deliberately not a parameter. `clearStaleGitLock(message)` is the reactive form, wired into `services/gitSubmodules.js#updateSubmodule` and `worktreeManager.addWorktreeWithRetry`; `clearStaleGitLocksIn(gitDir)` sweeps ahead of `update.sh`/`update.ps1`, the most likely producer. `scripts/doctor.js` reports one as the blocker. |
| `repoLinkFields.js` | `deriveRepoLinkFields(url)` / `normalizeRepoLinkFields(link)` / `linkIsRepo(link)` / `repoLinkLabel(link)` — the repository metadata a Brain link carries, plus the dual-write/tolerant-read shim that keeps the pre-multi-host `isGitHubRepo` field names readable across federated peers. |
diff --git a/server/lib/githubNotificationTriage.js b/server/lib/githubNotificationTriage.js
index b9cf81f1da..dd4782688f 100644
--- a/server/lib/githubNotificationTriage.js
+++ b/server/lib/githubNotificationTriage.js
@@ -177,7 +177,7 @@ export function decisionFromVerdict(verdict) {
const LEARNED_DECISIONS = Object.freeze(['surface', 'suggest-done', 'suggest-mute']);
const PINNED_RULES = new Set(['spam-signal', 'security-alert', 'invitation-never-accepted', 'deployment-approval']);
/** Triage rules no learned or automation rule may override. */
-export const PINNED_TRIAGE_RULES = Object.freeze(PINNED_RULES);
+export const PINNED_TRIAGE_RULES = Object.freeze([...PINNED_RULES]);
const ACTION_LESSONS = Object.freeze({ done: 'suggest-done', unsubscribe: 'suggest-done', mute: 'suggest-mute', reopen: 'surface', resubscribe: 'surface' });
/** The decision an operator action teaches, or null when it teaches nothing (a plain read). */
@@ -245,11 +245,12 @@ const RULE_KINDS = new Set(AGENT_RULE_KINDS);
// `agent: true/false` reads as `agent` / `leave`.
export const AGENT_RULE_ACTIONS = Object.freeze(['agent', 'done', 'mute', 'leave']);
// A security alert is never marked done or muted by a rule.
-export const AGENT_ONLY_RULE_KINDS = Object.freeze(new Set(['security-alert']));
+const AGENT_ONLY_RULE_KINDS = new Set(['security-alert']);
// Kinds no specific lane owns: an `agent` rule on one sends it to the generic
// lane on Autopilot. Review, issue and alert rules keep their meaning from
// before #13192 (their own lanes), so they never start a generic run.
-export const GENERIC_RULE_KINDS = Object.freeze(new Set(['ci-activity', 'own-pr', 'mention', 'release', 'other']));
+export const GENERIC_RULE_KINDS = Object.freeze(['ci-activity', 'own-pr', 'mention', 'release', 'other']);
+const GENERIC_KIND_SET = new Set(GENERIC_RULE_KINDS);
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']);
@@ -282,7 +283,7 @@ export const KIND_SQL = `(CASE
ELSE 'other' END)`;
/** A stored rule's action: its `action`, else the legacy `agent` boolean, else null. */
-export function agentRuleAction(rule) {
+function agentRuleAction(rule) {
if (AGENT_RULE_ACTIONS.includes(rule?.action)) return rule.action;
if (typeof rule?.agent === 'boolean') return rule.agent ? 'agent' : 'leave';
return null;
@@ -499,7 +500,7 @@ export function autopilotHandoff({ account, row }) {
const plan = agentHandoff({ account, row });
if (!plan || (plan.rule && plan.rule.action !== 'agent')) return null;
if (plan.lane === GENERIC_AGENT_LANE) {
- if (plan.rule?.action !== 'agent' || !GENERIC_RULE_KINDS.has(threadAgentKind(row))) return null;
+ if (plan.rule?.action !== 'agent' || !GENERIC_KIND_SET.has(threadAgentKind(row))) return null;
return plan.refused === 'finished' || plan.refused === 'handed-off' ? null : plan;
}
if (plan.optIn && plan.rule?.action !== 'agent') return null;
diff --git a/server/services/githubNotificationAssist.js b/server/services/githubNotificationAssist.js
index 34db27deff..4cafc35842 100644
--- a/server/services/githubNotificationAssist.js
+++ b/server/services/githubNotificationAssist.js
@@ -144,7 +144,7 @@ export async function assistAccountNotifications(account, env, { act }) {
AND (decision = ANY($2::text[])
OR (reason <> 'security_alert' AND NOT (COALESCE(evidence->>'rule', '') = ANY($3::text[])) AND (${ruleSql})))
ORDER BY gh_updated_at DESC LIMIT ${MAX_ACTIONS_PER_RUN}`,
- [account.id, ACTIONABLE_DECISIONS, [...PINNED_TRIAGE_RULES], ...scopes.flatMap(({ all, except, only }) => [all, except, only])],
+ [account.id, ACTIONABLE_DECISIONS, PINNED_TRIAGE_RULES, ...scopes.flatMap(({ all, except, only }) => [all, except, only])],
);
let acted = 0;
for (const row of rows) {
diff --git a/server/services/githubNotificationAutopilot.js b/server/services/githubNotificationAutopilot.js
index 537d8e9dce..dec55cc449 100644
--- a/server/services/githubNotificationAutopilot.js
+++ b/server/services/githubNotificationAutopilot.js
@@ -59,9 +59,9 @@ function candidateFilter(rules, first = 2) {
agentRuleScope(rules, 'issue-activity'),
agentRuleScope(rules, 'security-alert'),
];
- const generic = [...GENERIC_RULE_KINDS].map((kind) => agentRuleScope(rules, kind, { optIn: true }));
+ const generic = GENERIC_RULE_KINDS.map((kind) => agentRuleScope(rules, kind, { optIn: true }));
const at = (index) => first + index * 3;
- const genericSql = [...GENERIC_RULE_KINDS].map((kind, index) => `(${KIND_SQL} = '${kind}' AND ${inScope(at(scopes.length + index))})`).join(' OR ');
+ const genericSql = GENERIC_RULE_KINDS.map((kind, index) => `(${KIND_SQL} = '${kind}' AND ${inScope(at(scopes.length + index))})`).join(' OR ');
const sql = `((${KIND_SQL} = 'review-request' AND ${NOT_FINISHED_SQL} AND ${PULL_URL_SQL} AND (
(decision = 'suggest-untrusted-review' AND COALESCE(trust, '') NOT IN ('yours', 'trusted') AND (evidence->>'repoManaged')::boolean IS TRUE AND ${inScope(at(0))})
OR (decision IN ('suggest-review', 'suggest-untrusted-review', 'needs-you', 'surface') AND trust IN ('yours', 'trusted') AND ${inScope(at(1))})))
diff --git a/server/services/githubNotifications.js b/server/services/githubNotifications.js
index 0cc96ad583..1bdedf68ad 100644
--- a/server/services/githubNotifications.js
+++ b/server/services/githubNotifications.js
@@ -670,7 +670,7 @@ export async function getAutomationsOverview() {
FROM github_notifications WHERE account_id = ANY($1::text[]) AND state = 'open' AND NOT suspect
AND decision IS DISTINCT FROM 'handed-off'
GROUP BY 1, 2, 3`,
- [ids, [...PINNED_TRIAGE_RULES]],
+ [ids, PINNED_TRIAGE_RULES],
),
]);
const openById = new Map();