From 02ac8f48e90b291b23c84b7f71d9528a3bbeeb91 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Fri, 10 Apr 2026 18:28:59 -0700 Subject: [PATCH] fix: show update prompt for unrecognized orca.yaml keys (#454) --- src/main/hooks.test.ts | 56 +++++++++++++ src/main/hooks.ts | 26 ++++++ src/main/ipc/worktrees.ts | 11 ++- src/preload/api-types.d.ts | 4 +- src/preload/index.ts | 4 +- .../settings/RepositoryHooksSection.tsx | 84 ++++++++++++------- .../components/settings/RepositoryPane.tsx | 3 + .../src/components/settings/Settings.tsx | 14 +++- 8 files changed, 164 insertions(+), 38 deletions(-) diff --git a/src/main/hooks.test.ts b/src/main/hooks.test.ts index ec9e76e8c..48d6c3dc8 100644 --- a/src/main/hooks.test.ts +++ b/src/main/hooks.test.ts @@ -144,6 +144,62 @@ describe('parseOrcaYaml', () => { }) }) +describe('hasUnrecognizedOrcaYamlKeys', () => { + it('returns true when the file contains only keys this version does not handle', async () => { + const fs = await import('fs') + vi.mocked(fs.readFileSync).mockReturnValue('futureFeature: |\n some config\n') + + const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks') + expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(true) + }) + + it('returns true when an unknown key has no trailing space (block-value form)', async () => { + const fs = await import('fs') + vi.mocked(fs.readFileSync).mockReturnValue('futureFeature:\n nested: value\n') + + const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks') + expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(true) + }) + + it('returns true when the file mixes recognised and unrecognised keys', async () => { + const fs = await import('fs') + vi.mocked(fs.readFileSync).mockReturnValue( + 'scripts:\n setup: |\n pnpm install\nnewFeature: enabled\n' + ) + + const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks') + expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(true) + }) + + it('returns false when the file contains only recognised keys', async () => { + const fs = await import('fs') + vi.mocked(fs.readFileSync).mockReturnValue( + 'scripts:\n setup: |\n pnpm install\nissueCommand: |\n claude -p "test"\n' + ) + + const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks') + expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(false) + }) + + it('returns false when the file is empty or has no top-level keys', async () => { + const fs = await import('fs') + vi.mocked(fs.readFileSync).mockReturnValue('# just a comment\n') + + const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks') + expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(false) + }) + + it('returns false when the file cannot be read', async () => { + const fs = await import('fs') + vi.mocked(fs.readFileSync).mockImplementation(() => { + throw new Error('ENOENT') + }) + + const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks') + expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(false) + }) +}) + describe('readIssueCommand', () => { it('prefers the local override over the shared orca.yaml command', async () => { const fs = await import('fs') diff --git a/src/main/hooks.ts b/src/main/hooks.ts index 6dab3228c..c63e2716c 100644 --- a/src/main/hooks.ts +++ b/src/main/hooks.ts @@ -131,6 +131,32 @@ export function hasHooksFile(repoPath: string): boolean { return existsSync(join(repoPath, 'orca.yaml')) } +// Why: when a newer Orca release adds a top-level key to `orca.yaml` (like +// `issueCommand` was added here), older versions that don't recognise it will +// return `null` from `parseOrcaYaml` and show a confusing "could not be parsed" +// error. Detecting well-formed but unrecognised keys lets the UI suggest an +// update instead of implying the file is broken. +const RECOGNIZED_ORCA_YAML_KEYS = new Set(['scripts', 'issueCommand']) + +/** + * Return true when `orca.yaml` contains at least one top-level key that this + * version of Orca does not handle. + */ +export function hasUnrecognizedOrcaYamlKeys(repoPath: string): boolean { + try { + const content = readFileSync(join(repoPath, 'orca.yaml'), 'utf-8') + return content.split(/\r?\n/).some((line) => { + // Why: bare `key:` at end-of-line (no trailing space) is valid YAML for + // a mapping with a block value on the next line. Match both forms so + // newer keys like `futureFeature:\n nested` are still detected. + const m = line.match(/^([A-Za-z][A-Za-z0-9_-]*):(\s|$)/) + return m != null && !RECOGNIZED_ORCA_YAML_KEYS.has(m[1]) + }) + } catch { + return false + } +} + // ─── Issue command files ──────────────────────────────────────────────── // Why: `orca.yaml` is the tracked, project-wide defaults surface, while // `.orca/issue-command` remains the per-user override. Keeping the local file in diff --git a/src/main/ipc/worktrees.ts b/src/main/ipc/worktrees.ts index f1d4358ec..40a048be3 100644 --- a/src/main/ipc/worktrees.ts +++ b/src/main/ipc/worktrees.ts @@ -23,6 +23,7 @@ import { readIssueCommand, runHook, hasHooksFile, + hasUnrecognizedOrcaYamlKeys, shouldRunSetupForCreate, writeIssueCommand } from '../hooks' @@ -301,14 +302,20 @@ export function registerWorktreeHandlers(mainWindow: BrowserWindow, store: Store ipcMain.handle('hooks:check', (_event, args: { repoId: string }) => { const repo = store.getRepo(args.repoId) if (!repo || isFolderRepo(repo)) { - return { hasHooks: false, hooks: null } + return { hasHooks: false, hooks: null, mayNeedUpdate: false } } const has = hasHooksFile(repo.path) const hooks = has ? loadHooks(repo.path) : null + // Why: when a newer Orca version adds a top-level key to `orca.yaml`, older + // versions that don't recognise it return null and show "could not be parsed". + // Detecting well-formed but unrecognised keys lets the UI suggest updating + // instead of implying the file is broken. + const mayNeedUpdate = has && !hooks && hasUnrecognizedOrcaYamlKeys(repo.path) return { hasHooks: has, - hooks + hooks, + mayNeedUpdate } }) diff --git a/src/preload/api-types.d.ts b/src/preload/api-types.d.ts index 14cd761ad..0b7c88c86 100644 --- a/src/preload/api-types.d.ts +++ b/src/preload/api-types.d.ts @@ -241,7 +241,9 @@ export type PreloadApi = { } browser: BrowserApi hooks: { - check: (args: { repoId: string }) => Promise<{ hasHooks: boolean; hooks: OrcaHooks | null }> + check: (args: { + repoId: string + }) => Promise<{ hasHooks: boolean; hooks: OrcaHooks | null; mayNeedUpdate: boolean }> readIssueCommand: (args: { repoId: string }) => Promise<{ localContent: string | null sharedContent: string | null diff --git a/src/preload/index.ts b/src/preload/index.ts index 08c18c55d..9fc6ba230 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -357,7 +357,9 @@ const api = { }, hooks: { - check: (args: { repoId: string }): Promise<{ hasHooks: boolean; hooks: unknown }> => + check: (args: { + repoId: string + }): Promise<{ hasHooks: boolean; hooks: unknown; mayNeedUpdate: boolean }> => ipcRenderer.invoke('hooks:check', args), readIssueCommand: (args: { diff --git a/src/renderer/src/components/settings/RepositoryHooksSection.tsx b/src/renderer/src/components/settings/RepositoryHooksSection.tsx index 7bec883ea..dd5078b9c 100644 --- a/src/renderer/src/components/settings/RepositoryHooksSection.tsx +++ b/src/renderer/src/components/settings/RepositoryHooksSection.tsx @@ -1,3 +1,4 @@ +/* eslint-disable max-lines -- Why: the YAML status card, issue-command editor, policy grid, and legacy-hook section form one cohesive settings surface; splitting them across files would scatter tightly coupled state and prop drilling. */ import { useCallback, useEffect, useRef, useState } from 'react' import type { OrcaHooks, Repo, SetupRunPolicy } from '../../../../shared/types' import { AlertTriangle } from 'lucide-react' @@ -9,6 +10,7 @@ type RepositoryHooksSectionProps = { repo: Repo yamlHooks: OrcaHooks | null hasHooksFile: boolean + mayNeedUpdate: boolean copiedTemplate: boolean onCopyTemplate: () => void onClearLegacyHooks: () => void @@ -35,6 +37,40 @@ const EXAMPLE_TEMPLATE = `scripts: issueCommand: | claude -p "Read issue #{{issue}} and write a design doc to docs/design-{{issue}}.md covering the approach, edge cases, and test plan." && codex exec "Review docs/design-{{issue}}.md for gaps, missing edge cases, or unclear requirements. Add feedback at the bottom."` +const YAML_STATE_STYLES: Record< + string, + { card: string; title: string; heading: string; description: string } +> = { + loaded: { + card: 'border-emerald-500/20 bg-emerald-500/5', + title: 'text-emerald-700 dark:text-emerald-300', + heading: 'Using `orca.yaml`', + description: + 'Shared hook and issue-automation defaults are defined in the repo and available to everyone who uses it.' + }, + 'update-available': { + card: 'border-amber-500/20 bg-amber-500/5', + title: 'text-amber-700 dark:text-amber-300', + heading: '`orca.yaml` could not be parsed', + description: + 'The file contains configuration keys that this version of Orca does not recognize. You may need to update Orca, or check the file for typos.' + }, + invalid: { + card: 'border-amber-500/20 bg-amber-500/5', + title: 'text-amber-700 dark:text-amber-300', + heading: '`orca.yaml` could not be parsed', + description: + 'The core configuration file exists in the repo root, but Orca could not parse the supported hook definitions yet.' + }, + missing: { + card: 'border-border/50 bg-muted/20', + title: 'text-foreground', + heading: 'No `orca.yaml` detected', + description: + 'Add an `orca.yaml` file to enable shared setup, archive, or issue-automation defaults for this repo. Example template:' + } +} + /** Shared button grid for setup run-policy selectors. */ function PolicyOptionGrid

({ options, @@ -86,7 +122,7 @@ function ExampleTemplateCard({ return (

- Example `orca.yaml` template + Example orca.yaml template