Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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.2",
"version": "0.8.3",
"types": "./types/index.d.ts",
"author": { "name": "Guilherme Moraes" },
"license": "MIT"
Expand Down
8 changes: 4 additions & 4 deletions panel/data/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const notice = atom({ plugin: 'taskflow', key: 'notice' } as const, null)
const trashEntries = atom({ plugin: 'taskflow', key: 'trashEntries' } as const, null)
const pendingClear = atom({ plugin: 'taskflow', key: 'pendingClear' } as const, false)

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()
Expand All @@ -38,14 +38,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 {
Expand All @@ -64,7 +64,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

Expand Down
75 changes: 75 additions & 0 deletions panel/data/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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'

const settings = atom({ plugin: 'taskflow', key: 'settings' } as const, null)

export async function loadSettings($: EngineInterface): Promise<PlanSettings> {
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,
repoName: basename(root),
}
}

// 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 }
}

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<SettingsView['draft']>) =>
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 }))
}
10 changes: 6 additions & 4 deletions panel/domain/plan-dir.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -11,9 +11,11 @@ export type WorkflowEnv = Partial<Record<(typeof ENV_KEYS)[number], string>>

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 {
Expand Down Expand Up @@ -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.` }
}

Expand Down
38 changes: 38 additions & 0 deletions panel/domain/workflow-env.test.ts
Original file line number Diff line number Diff line change
@@ -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'),
})
})
55 changes: 55 additions & 0 deletions panel/domain/workflow-env.ts
Original file line number Diff line number Diff line change
@@ -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<string>()
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('') }
}
112 changes: 112 additions & 0 deletions panel/ui/components/organisms/ObsidianSettings.tsx
Original file line number Diff line number Diff line change
@@ -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<SettingsDraft>) => 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 <Text dimColor>Settings need a surface that takes input.</Text>
const { Input, Select } = ui
const { current, draft, saveError } = view
const vault = current.vaultPath ? basename(current.vaultPath) : current.vault

return (
<Box flexDirection="column" gap={1}>
<Box justifyContent="space-between">
<Button key="back" hotkey="b" label="← Plans (b)" onPress={onBack} />
<Button key="save" hotkey="s" label="Save (s)" onPress={onSave} />
</Box>

<Box flexDirection="column">
<Text weight="bold">Plan source</Text>
<Text>
<Text dimColor>Source </Text>
{current.source === 'obsidian' ? 'Obsidian' : 'Repo'}
</Text>
{current.source === 'obsidian' && (
<Box flexDirection="column">
<Text wrap="truncate-end">
<Text dimColor>Vault </Text>
{vault || 'not set'}
</Text>
<Text wrap="truncate-end">
<Text dimColor>Inner path </Text>
{current.path || 'vault root'}
</Text>
</Box>
)}
{current.error && <Text color="error">{current.error}</Text>}
</Box>

{(current.source !== 'obsidian' || current.error !== null) && (
<Box flexDirection="column">
<Text weight="bold">Set up Obsidian</Text>
{SETUP_STEPS.map((step, index) => (
<Text key={`step-${index}`} dimColor>
{index + 1}. {step}
</Text>
))}
</Box>
)}

<Box flexDirection="column">
<Select
key="source"
label="Source"
value={draft.source}
options={[
{ value: 'repo', label: 'Repo' },
{ value: 'obsidian', label: 'Obsidian' },
]}
onSelect={value => onChange({ source: value === 'obsidian' ? 'obsidian' : 'repo' })}
/>
{draft.source === 'obsidian' && (
<Box flexDirection="column">
<Select
key="vault"
label="Vault"
value={draft.vaultPath === '' ? draft.vault : OTHER_VAULT}
options={[
...current.vaults.map(item => ({ value: item.name, label: item.name })),
{ value: OTHER_VAULT, label: 'Absolute path' },
]}
onSelect={value => onChange({ vault: value, vaultPath: '' })}
/>
<Input
key="vault-path"
label="Vault path"
placeholder="/absolute/path/to/vault"
value={draft.vaultPath}
onInput={value => onChange({ vaultPath: value })}
onSubmit={onSave}
/>
<Input
key="inner-path"
label="Inner path"
placeholder={`taskflow/${current.repoName}`}
value={draft.path}
onInput={value => onChange({ path: value })}
onSubmit={onSave}
/>
</Box>
)}
{saveError && <Text color="error">{saveError}</Text>}
</Box>
</Box>
)
}
4 changes: 3 additions & 1 deletion panel/ui/components/organisms/PlanList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ type PlanListProps = {
message: string | null
onOpen: (name: string) => void
onRefresh: () => void
onSettings: () => void
onOpenTrash: () => void
}

export function PlanList({ ui, projects, message, onOpen, onRefresh, onOpenTrash }: PlanListProps) {
export function PlanList({ ui, projects, message, onOpen, onRefresh, onSettings, onOpenTrash }: PlanListProps) {
const { Box, Text, Button } = ui

return (
Expand All @@ -21,6 +22,7 @@ export function PlanList({ ui, projects, message, onOpen, onRefresh, onOpenTrash
Plans <Text dimColor>{projects.length}</Text>
</Text>
<Box gap={1}>
<Button key="settings" hotkey="s" label="⚙" onPress={onSettings} />
<Button key="trash" hotkey="t" label="🗑️ Trash (t)" onPress={onOpenTrash} />
<Button key="refresh" hotkey="r" label="🔄" onPress={onRefresh} />
</Box>
Expand Down
Loading
Loading