From 5870ffc9db84027f5983ed2710c624aada837f97 Mon Sep 17 00:00:00 2001 From: Guilherme Moraes Date: Wed, 21 Oct 2026 13:10:11 -0300 Subject: [PATCH 1/2] feat: the panel can write the plan source settings to workflow.env --- .claude-plugin/plugin.json | 2 +- panel/data/board.ts | 8 ++--- panel/data/settings.ts | 43 ++++++++++++++++++++++++ panel/domain/plan-dir.ts | 10 +++--- panel/domain/workflow-env.test.ts | 38 +++++++++++++++++++++ panel/domain/workflow-env.ts | 55 +++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 panel/data/settings.ts create mode 100644 panel/domain/workflow-env.test.ts create mode 100644 panel/domain/workflow-env.ts diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 1f6b88f..b1f5550 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "taskflow", "description": "Plan-and-task workflow: scope/tasks/questions/progress scaffolding split into pull requests under a line budget, acceptance criteria agreed up front, tests red before green, one-task-per-commit cycle, questions answered at the task that needs them, red-first bug fixes, docs-and-diagram sync, standards review.", - "version": "0.8.1", + "version": "0.8.3", "types": "./types/index.d.ts", "author": { "name": "Guilherme Moraes" }, "license": "MIT" diff --git a/panel/data/board.ts b/panel/data/board.ts index 491fc37..c7d1fe9 100644 --- a/panel/data/board.ts +++ b/panel/data/board.ts @@ -10,7 +10,7 @@ const selected = atom({ plugin: 'taskflow', key: 'selected' } as const, null) const pendingDelete = atom({ plugin: 'taskflow', key: 'pendingDelete' } as const, null) const notice = atom({ plugin: 'taskflow', key: 'notice' } as const, null) -async function repoRoot($: EngineInterface) { +export async function repoRoot($: EngineInterface) { const toplevel = await $.process.run(['git', 'rev-parse', '--show-toplevel']) return toplevel.exitCode === 0 ? toplevel.stdout.trim() : await $.session.cwd() @@ -26,14 +26,14 @@ async function readProjectsDir($: EngineInterface, root: string) { } } -async function readWorkflowEnv($: EngineInterface, root: string) { +export async function readWorkflowEnv($: EngineInterface, root: string) { const path = `${root}/.claude/workflow.env` return parseWorkflowEnv((await $.fs.exists(path)) ? await $.fs.read(path) : '') } // null when obsidian.json is missing or unreadable, so the resolver can name that as the problem. -async function readObsidianVaults($: EngineInterface) { +export async function readObsidianVaults($: EngineInterface) { const home = await $.process.run(['printenv', 'HOME']) if (home.exitCode !== 0) return null try { @@ -52,7 +52,7 @@ async function readObsidianVaults($: EngineInterface) { } } -async function readPlanDir($: EngineInterface, root: string) { +export async function readPlanDir($: EngineInterface, root: string) { const env = await readWorkflowEnv($, root) const needsVaults = env.TASKFLOW_PLANS_SOURCE === 'obsidian' && !env.TASKFLOW_OBSIDIAN_VAULT_PATH diff --git a/panel/data/settings.ts b/panel/data/settings.ts new file mode 100644 index 0000000..0095466 --- /dev/null +++ b/panel/data/settings.ts @@ -0,0 +1,43 @@ +import type { EngineInterface } from 'claude-code' + +import { basename } from '../domain/plan-dir' +import { updateWorkflowEnv } from '../domain/workflow-env' +import type { PlanSourceSettings } from '../domain/workflow-env' +import { loadBoard, readObsidianVaults, readPlanDir, readWorkflowEnv, repoRoot } from './board' + +export async function loadSettings($: EngineInterface) { + const root = await repoRoot($) + const env = await readWorkflowEnv($, root) + const resolved = await readPlanDir($, root) + const vaults = (await readObsidianVaults($))?.map(path => ({ name: basename(path), path })) ?? [] + + return { + source: env.TASKFLOW_PLANS_SOURCE === 'obsidian' ? 'obsidian' : 'repo', + vault: env.TASKFLOW_OBSIDIAN_VAULT, + vaultPath: env.TASKFLOW_OBSIDIAN_VAULT_PATH, + path: env.TASKFLOW_OBSIDIAN_PATH, + vaults, + error: 'error' in resolved ? resolved.error : null, + } as const +} + +// workflow.env holds machine paths, so .claude/.gitignore must list it before the file is written. +async function ensureIgnored($: EngineInterface, root: string) { + const path = `${root}/.claude/.gitignore` + const current = (await $.fs.exists(path)) ? await $.fs.read(path) : '' + if (current.split('\n').some(line => line.trim() === 'workflow.env')) return + const separator = current === '' || current.endsWith('\n') ? '' : '\n' + await $.fs.write(path, `${current}${separator}workflow.env\n`) +} + +export async function saveSettings($: EngineInterface, settings: PlanSourceSettings) { + const root = await repoRoot($) + const path = `${root}/.claude/workflow.env` + const updated = updateWorkflowEnv((await $.fs.exists(path)) ? await $.fs.read(path) : '', settings) + if ('error' in updated) return updated + await ensureIgnored($, root) + await $.fs.write(path, updated.text) + await loadBoard($) + + return { error: null } +} diff --git a/panel/domain/plan-dir.ts b/panel/domain/plan-dir.ts index 24a8b19..b77e940 100644 --- a/panel/domain/plan-dir.ts +++ b/panel/domain/plan-dir.ts @@ -1,6 +1,6 @@ import type { PlanDir } from '../../types' -const ENV_KEYS = [ +export const ENV_KEYS = [ 'TASKFLOW_PLANS_SOURCE', 'TASKFLOW_OBSIDIAN_VAULT', 'TASKFLOW_OBSIDIAN_VAULT_PATH', @@ -11,9 +11,11 @@ export type WorkflowEnv = Partial> export const DEFAULT_PROJECTS_DIR = 'docs/projects' -const isEnvKey = (key: string): key is (typeof ENV_KEYS)[number] => ENV_KEYS.some(allowed => allowed === key) +export const isEnvKey = (key: string): key is (typeof ENV_KEYS)[number] => ENV_KEYS.some(allowed => allowed === key) -const basename = (path: string) => path.replace(/\/+$/, '').split('/').pop() ?? '' +export const basename = (path: string) => path.replace(/\/+$/, '').split('/').pop() ?? '' + +export const escapesVault = (inner: string) => inner.startsWith('/') || inner.split('/').includes('..') // workflow.env is untracked, so only the keys that pick the plan source are read - never gates or models. export function parseWorkflowEnv(text: string): WorkflowEnv { @@ -63,7 +65,7 @@ export function resolvePlanDir(input: { } const inner = (env.TASKFLOW_OBSIDIAN_PATH ?? '').replace(/\/+$/, '') - if (inner.startsWith('/') || inner.split('/').includes('..')) { + if (escapesVault(inner)) { return { error: `TASKFLOW_OBSIDIAN_PATH "${inner}" must stay inside the vault.` } } diff --git a/panel/domain/workflow-env.test.ts b/panel/domain/workflow-env.test.ts new file mode 100644 index 0000000..b957576 --- /dev/null +++ b/panel/domain/workflow-env.test.ts @@ -0,0 +1,38 @@ +import { expect, test } from 'claude-code/testing' + +import { updateWorkflowEnv } from './workflow-env' + +const VAULT = { source: 'obsidian', vaultPath: '/abs/Work', path: 'taskflow/myrepo' } as const + +test('writes only the allow-listed keys', () => { + const settings = { ...VAULT, extra: 'x', TASKFLOW_GATES: 'rm -rf /' } + + expect(updateWorkflowEnv('', settings)).toEqual({ + text: 'TASKFLOW_PLANS_SOURCE=obsidian\nTASKFLOW_OBSIDIAN_VAULT_PATH=/abs/Work\nTASKFLOW_OBSIDIAN_PATH=taskflow/myrepo\n', + }) + expect(updateWorkflowEnv('TASKFLOW_OBSIDIAN_VAULT=Old\n', { source: 'obsidian', vault: 'Work' })).toEqual({ + text: 'TASKFLOW_OBSIDIAN_VAULT=Work\nTASKFLOW_PLANS_SOURCE=obsidian\n', + }) +}) + +test('preserves lines it does not own', () => { + const existing = '# my notes\nOTHER=1\nTASKFLOW_OBSIDIAN_VAULT=Old\n\nTASKFLOW_PLANS_SOURCE=repo\n# end\n' + + expect(updateWorkflowEnv(existing, VAULT)).toEqual({ + text: '# my notes\nOTHER=1\n\nTASKFLOW_PLANS_SOURCE=obsidian\n# end\nTASKFLOW_OBSIDIAN_VAULT_PATH=/abs/Work\nTASKFLOW_OBSIDIAN_PATH=taskflow/myrepo\n', + }) +}) + +test('refuses an escaping inner path', () => { + for (const path of ['../other', 'a/../../b', '/etc']) { + expect(updateWorkflowEnv('OTHER=1\n', { ...VAULT, path })).toEqual({ + error: expect.stringContaining('inside the vault'), + }) + } + expect(updateWorkflowEnv('', { ...VAULT, vaultPath: 'rel/Work' })).toEqual({ + error: expect.stringContaining('absolute'), + }) + expect(updateWorkflowEnv('', { ...VAULT, vault: 'Work\nTASKFLOW_GATES=x', vaultPath: undefined })).toEqual({ + error: expect.stringContaining('one line'), + }) +}) diff --git a/panel/domain/workflow-env.ts b/panel/domain/workflow-env.ts new file mode 100644 index 0000000..0d425d0 --- /dev/null +++ b/panel/domain/workflow-env.ts @@ -0,0 +1,55 @@ +import { ENV_KEYS, escapesVault, isEnvKey } from './plan-dir' +import type { WorkflowEnv } from './plan-dir' + +export type PlanSourceSettings = { + source: 'repo' | 'obsidian' + vault?: string + vaultPath?: string + path?: string +} + +function toEnv(settings: PlanSourceSettings): WorkflowEnv { + const path = settings.path?.trim().replace(/\/+$/, '') + const vaultPath = settings.vaultPath?.trim() + + return { + TASKFLOW_PLANS_SOURCE: settings.source, + TASKFLOW_OBSIDIAN_VAULT: vaultPath ? undefined : settings.vault?.trim() || undefined, + TASKFLOW_OBSIDIAN_VAULT_PATH: vaultPath || undefined, + TASKFLOW_OBSIDIAN_PATH: path || undefined, + } +} + +// Owned keys are rewritten in place or dropped when unset; every other line is kept as it was. +export function updateWorkflowEnv( + existingText: string, + settings: PlanSourceSettings, +): { text: string } | { error: string } { + const env = toEnv(settings) + if (Object.values(env).some(value => value !== undefined && /[\r\n]/.test(value))) { + return { error: 'A setting cannot span more than one line.' } + } + const inner = env.TASKFLOW_OBSIDIAN_PATH ?? '' + if (escapesVault(inner)) return { error: `The inner path "${inner}" must stay inside the vault.` } + const vaultPath = env.TASKFLOW_OBSIDIAN_VAULT_PATH + if (vaultPath && !vaultPath.startsWith('/')) return { error: `The vault path "${vaultPath}" must be absolute.` } + + const written = new Set() + const lines = existingText === '' ? [] : existingText.replace(/\n$/, '').split('\n') + const kept = lines.flatMap(line => { + const key = line.slice(0, line.indexOf('=')).trim() + if (line.trim().startsWith('#') || !isEnvKey(key)) return [line] + const value = env[key] + if (value === undefined || written.has(key)) return [] + written.add(key) + + return [`${key}=${value}`] + }) + const added = ENV_KEYS.flatMap(key => { + const value = env[key] + + return value === undefined || written.has(key) ? [] : [`${key}=${value}`] + }) + + return { text: [...kept, ...added].map(line => `${line}\n`).join('') } +} From 64764d327f04a6de1538d5716901ba026dab7c8a Mon Sep 17 00:00:00 2001 From: Guilherme Moraes Date: Wed, 21 Oct 2026 13:12:13 -0300 Subject: [PATCH 2/2] feat: the panel has an Obsidian settings view to pick where plans live --- panel/data/settings.ts | 36 +++++- .../components/organisms/ObsidianSettings.tsx | 112 ++++++++++++++++++ panel/ui/components/organisms/PlanList.tsx | 8 +- panel/ui/pane.tsx | 32 ++++- types/index.d.ts | 24 ++++ 5 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 panel/ui/components/organisms/ObsidianSettings.tsx diff --git a/panel/data/settings.ts b/panel/data/settings.ts index 0095466..921fdef 100644 --- a/panel/data/settings.ts +++ b/panel/data/settings.ts @@ -1,11 +1,15 @@ +import { atom, update } from 'claude-code' import type { EngineInterface } from 'claude-code' +import type { PlanSettings, SettingsView } from '../../types' import { basename } from '../domain/plan-dir' import { updateWorkflowEnv } from '../domain/workflow-env' import type { PlanSourceSettings } from '../domain/workflow-env' import { loadBoard, readObsidianVaults, readPlanDir, readWorkflowEnv, repoRoot } from './board' -export async function loadSettings($: EngineInterface) { +const settings = atom({ plugin: 'taskflow', key: 'settings' } as const, null) + +export async function loadSettings($: EngineInterface): Promise { const root = await repoRoot($) const env = await readWorkflowEnv($, root) const resolved = await readPlanDir($, root) @@ -18,7 +22,8 @@ export async function loadSettings($: EngineInterface) { path: env.TASKFLOW_OBSIDIAN_PATH, vaults, error: 'error' in resolved ? resolved.error : null, - } as const + repoName: basename(root), + } } // workflow.env holds machine paths, so .claude/.gitignore must list it before the file is written. @@ -41,3 +46,30 @@ export async function saveSettings($: EngineInterface, settings: PlanSourceSetti return { error: null } } + +export async function openSettings($: EngineInterface) { + const current = await loadSettings($) + const view: SettingsView = { + current, + draft: { + source: current.source, + vault: current.vault ?? '', + vaultPath: current.vaultPath ?? '', + path: current.path ?? `taskflow/${current.repoName}`, + }, + saveError: null, + } + await update($, settings, () => view) +} + +export const closeSettings = ($: EngineInterface) => update($, settings, () => null) + +export const editSettings = ($: EngineInterface, change: Partial) => + update($, settings, view => (view === null ? view : { ...view, draft: { ...view.draft, ...change } })) + +export async function submitSettings($: EngineInterface, draft: SettingsView['draft']) { + const saved = await saveSettings($, draft) + if (saved.error === null) return closeSettings($) + + return update($, settings, view => (view === null ? view : { ...view, saveError: saved.error })) +} diff --git a/panel/ui/components/organisms/ObsidianSettings.tsx b/panel/ui/components/organisms/ObsidianSettings.tsx new file mode 100644 index 0000000..e6e2fc1 --- /dev/null +++ b/panel/ui/components/organisms/ObsidianSettings.tsx @@ -0,0 +1,112 @@ +import type { SettingsDraft, SettingsView } from '../../../../types' +import { basename } from '../../../domain/plan-dir' +import type { Ui } from '../ui' + +type ObsidianSettingsProps = { + ui: Ui + view: SettingsView + onBack: () => void + onChange: (change: Partial) => void + onSave: () => void +} + +const SETUP_STEPS = [ + 'Open the vault once in Obsidian so it appears in its vault list, then pick it here or set an absolute path.', + '.claude/workflow.env is local and gitignored.', + 'Add the vault to permissions.additionalDirectories to avoid prompts.', +] + +const OTHER_VAULT = '' + +export function ObsidianSettings({ ui, view, onBack, onChange, onSave }: ObsidianSettingsProps) { + const { Box, Text, Button } = ui + if (!('Input' in ui)) return Settings need a surface that takes input. + const { Input, Select } = ui + const { current, draft, saveError } = view + const vault = current.vaultPath ? basename(current.vaultPath) : current.vault + + return ( + + +