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
28 changes: 26 additions & 2 deletions src/board/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { gitShow } from '../bare.js'
import { blobStoreFromEnv, MAX_ATTACHMENT_BYTES, TooLarge, writeHashed, type BlobStore } from '../blobs.js'
import { addComment, ticketThread } from '../comments.js'
import { workAdd, workMove, workSet } from '../commands/project.js'
import { statusBeforeArchive, workRank, type WorkWriteOptions } from '../commands/work.js'
import { statusBeforeArchive, workPromote, workRank, type WorkWriteOptions } from '../commands/work.js'
import { serializeFor } from '../queue.js'
import { findItem, labelCounts, summarizeForRecall, WORK_PRIORITIES, WORK_STATUSES, type LoreWorkItem, type RankTarget } from '../work.js'
import { findItem, labelCounts, parseRequests, requestRows, summarizeForRecall, WORK_PRIORITIES, WORK_STATUSES, type LoreWorkItem, type RankTarget } from '../work.js'
import { assigneeResolver, assigneeOptions, bareProject, bareProjects, bareWorkItems, boardRole, type BoardRole } from './access.js'
import type { LoreConfig } from '../config.js'
import { boardSecret, CodeStore, cookieHeader, normalizeEmail, RateLimiter, readCookie, SessionSigner, type Session } from './auth.js'
Expand Down Expand Up @@ -271,6 +271,30 @@ export function createBoardHandler(opts: BoardOptions): BoardHandler {
return send(res, 200, { projects }), true
}

// Client requests the fold recorded, with the ticket tracking each one (if any);
// a member can turn one into a ticket.
const reqRoute = /^\/p\/([\w.-]+)\/requests(?:\/([\w.-]+)\/promote)?$/.exec(route)
if (reqRoute) {
const [, context, id] = reqRoute
const project = bareProject(opts.repos, context)
const role = project ? boardRole(project.config, email, admins) : undefined
if (!project || !role) return send(res, 404, { error: 'no such board' }), true
const bare = join(opts.repos, `${context}.git`)
const rows = () => requestRows(parseRequests(gitShow(bare, 'context/derived/requests.yaml', true)), bareWorkItems(opts.repos, project).items)
if (!id && method === 'GET') {
return send(res, 200, { context, project: project.config.project, client: project.config.client?.name, role, archived: project.config.lifecycle === 'archived', requests: rows() }), true
}
if (id && method === 'POST') {
if (role !== 'member') return send(res, 403, { error: 'you can view this board but not change it' }), true
const body = await readBody(req)
const item = await serializeFor(context)(async () =>
workPromote(cwd, id, { title: str(body.title), priority: str(body.priority) as never, reason: 'made a ticket from the requests list' }, { context, via: 'web', actor: email, operationId: randomUUID() }),
)
return send(res, 201, { item, request: rows().find((r) => r.id === id) }), true
}
return send(res, 404, { error: 'not found' }), true
}

const fileRoute = /^\/p\/([\w.-]+)\/files\/([a-f0-9]{64})$/.exec(route)
const m = fileRoute ? null : /^\/p\/([\w.-]+)(?:\/items(?:\/([\w.-]+)(?:\/(move|rank|thread|comments|files|detach))?)?)?$/.exec(route)
if (!m && !fileRoute) return send(res, 404, { error: 'not found' }), true
Expand Down
10 changes: 8 additions & 2 deletions src/commands/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
rankItem,
readExternalIssues,
readWorkItems,
shortTitle,
stateFor,
summarizeForRecall,
WORK_PRIORITIES,
Expand Down Expand Up @@ -246,7 +247,7 @@ export function workAdd(cwd: string, input: WorkAddInput, opts: WorkWriteOptions
}

/** Turn a derived request (req-0007) into a tracked item, keeping its evidence. */
export function workPromote(cwd: string, requestId: string, input: { title?: string; priority?: WorkPriority; reason?: string } = {}, opts: WorkWriteOptions = {}): LoreWorkItem {
export function workPromote(cwd: string, requestId: string, input: { title?: string; description?: string; priority?: WorkPriority; reason?: string } = {}, opts: WorkWriteOptions = {}): LoreWorkItem {
const ctx = resolveContext(cwd, opts)
const path = join(ctx.root, 'context/derived/requests.yaml')
const requests = existsSync(path) ? ((parse(readFileSync(path, 'utf8')) as Record<string, unknown>[] | null) ?? []) : []
Expand All @@ -257,9 +258,14 @@ export function workPromote(cwd: string, requestId: string, input: { title?: str
const already = items.find((i) => i.request === req.id)
if (already) throw new Error(`work promote: ${req.id} is already tracked as ${already.key}`)
const source = typeof req.source === 'string' ? req.source : undefined
// A long ask becomes a short title, with the ask itself kept as the ticket's body.
const asked = String(req.request ?? req.id).replace(/\s+/g, ' ').trim()
const title = input.title?.trim() || shortTitle(asked)
const description = input.description?.trim() || (title === asked ? undefined : `${asked}${req.requested_by ? `\n\nAsked by ${req.requested_by}${req.date ? ` on ${String(req.date).slice(0, 10)}` : ''}.` : ''}`)
const item: LoreWorkItem = {
key: nextKey(items, prefix),
title: input.title?.trim() || String(req.request ?? req.id),
title,
...(description ? { description } : {}),
status: 'todo',
state: 'open',
...(priority ? { priority } : {}),
Expand Down
53 changes: 53 additions & 0 deletions src/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,59 @@ export function lastHumanChange(item: LoreWorkItem, field: string): string | und
return at
}

/** One entry of `context/derived/requests.yaml`: something the client asked for, as the fold recorded it. */
export interface DerivedRequest {
id: string
request: string
requested_by?: string
date?: string
status?: string
source?: string
}

export function parseRequests(text: string): DerivedRequest[] {
if (!text.trim()) return []
const parsed = parse(text.replace(/^(#.*\n)+/, '')) as unknown
if (!Array.isArray(parsed)) return []
return parsed
.filter((r): r is Record<string, unknown> => Boolean(r) && typeof r === 'object' && typeof (r as Record<string, unknown>).id === 'string')
.map((r) => ({
id: String(r.id),
request: String(r.request ?? r.id).replace(/\s+/g, ' ').trim(),
...(r.requested_by ? { requested_by: String(r.requested_by) } : {}),
...(r.date ? { date: String(r.date).slice(0, 10) } : {}),
...(r.status ? { status: String(r.status) } : {}),
...(typeof r.source === 'string' ? { source: r.source } : {}),
}))
}

/** A request with the ticket that tracks it, or the open ticket that reads like it. */
export interface RequestRow extends DerivedRequest {
/** The ticket promoted from this request. */
ticket?: string
/** An open ticket whose title reads like this request — probably the same work under other words. */
similar?: string
}

export function requestRows(requests: DerivedRequest[], items: Pick<LoreWorkItem, 'key' | 'title' | 'request' | 'state'>[]): RequestRow[] {
const byRequest = new Map(items.filter((i) => i.request).map((i) => [i.request!, i.key]))
return requests.map((r) => {
const ticket = byRequest.get(r.id)
const similar = ticket ? undefined : items.find((i) => i.state === 'open' && titleSimilarity(i.title, shortTitle(r.request)) >= 0.7)?.key
return { ...r, ...(ticket ? { ticket } : {}), ...(similar ? { similar } : {}) }
})
}

/** A ticket title from a longer ask: the whole text when short, else its first sentence, else a cut at a word. */
export function shortTitle(text: string, max = 90): string {
const clean = text.replace(/\s+/g, ' ').trim()
if (clean.length <= max) return clean
const sentence = /^(.{20,}?[.!?])\s/.exec(clean)?.[1]
if (sentence && sentence.length <= max) return sentence.replace(/[.!?]$/, '')
const cut = clean.slice(0, max - 1)
return `${cut.slice(0, Math.max(cut.lastIndexOf(' '), 40)).replace(/[\s,;:(–—-]+$/, '')}…`
}

export function summarizeForRecall(item: LoreWorkItem): WorkItemSummary {
const { history: hist, ...rest } = item
const history = Array.isArray(hist) ? hist : []
Expand Down
37 changes: 37 additions & 0 deletions test/board.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,40 @@ test('board assignees: a photo-only profile reuses a known contact and canonical
const after = await api('/p/lore-identity-board', { cookie })
assert.deepEqual(after.body.assignees, ['Cory Schadt'])
})

test('board requests: lists what the client asked for with its ticket, and a member turns one into a ticket', async () => {
const long = 'Add a skip button to the profile step of onboarding so new members who are in a hurry can finish signing up and fill the rest in later from their settings page'
pushContext(
'lore-reqs',
{ project: 'reqs', client: { name: 'Reqs', domains: ['acme.com'] }, sources: {}, board: { enabled: true, members: ['jane@acme.com'], viewers: ['@viewers.io'] } },
{
'context/work/lore/REQ.yaml': `- key: REQ-1\n title: Checkout copy\n status: todo\n state: open\n request: req-0001\n labels: []\n sources: []\n created: 2026-08-04\n updated: 2026-08-04\n history: []\n- key: REQ-2\n title: Black Friday landing page\n status: in_progress\n state: open\n labels: []\n sources: []\n created: 2026-08-04\n updated: 2026-08-04\n history: []\n`,
'context/derived/requests.yaml': `# Derived\n- id: req-0001\n request: New checkout copy\n requested_by: Priya Patel (client)\n date: 2026-09-01\n status: in_progress\n source: https://slack.com/archives/C1/p1\n- id: req-0002\n request: ${long}\n requested_by: Priya Patel (client)\n date: 2026-09-10\n status: open\n- id: req-0003\n request: Black Friday landing page\n date: 2026-09-11\n status: open\n`,
},
)
const member = await signIn('jane@acme.com')
const viewer = await signIn('sam@viewers.io')

const list = await api('/p/lore-reqs/requests', { cookie: viewer })
assert.equal(list.status, 200)
assert.deepEqual(
list.body.requests.map((r: any) => [r.id, r.ticket ?? null, r.similar ?? null]),
[['req-0001', 'REQ-1', null], ['req-0002', null, null], ['req-0003', null, 'REQ-2']],
'a request knows its ticket, and one that reads like an open ticket says so',
)
assert.equal((await api('/p/lore-reqs/requests', {})).status, 401)
assert.equal((await api('/p/lore-reqs/requests/req-0002/promote', { cookie: viewer, body: {} })).status, 403)

const made = await api('/p/lore-reqs/requests/req-0002/promote', { cookie: member, body: {} })
assert.equal(made.status, 201, JSON.stringify(made.body))
assert.equal(made.body.item.key, 'REQ-3')
assert.equal(made.body.item.request, 'req-0002')
assert.equal(made.body.item.title.length <= 90, true, made.body.item.title)
assert.match(made.body.item.description, /fill the rest in later from their settings page\n\nAsked by Priya Patel \(client\) on 2026-09-10\.$/)
assert.equal(made.body.request.ticket, 'REQ-3')

const twice = await api('/p/lore-reqs/requests/req-0002/promote', { cookie: member, body: {} })
assert.equal(twice.status, 400)
assert.match(twice.body.error, /already tracked as REQ-3/)
assert.equal((await api('/p/lore-reqs/requests/req-9999/promote', { cookie: member, body: {} })).status, 400)
})
17 changes: 12 additions & 5 deletions web/src/BoardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ItemDrawer } from './ItemDrawer'
import { KanbanView } from './KanbanView'
import { ListView } from './ListView'
import { NewItemModal } from './NewItemModal'
import { RequestsView } from './RequestsView'
import { AvatarStack } from './people'
import { boardRoute, href, navigate, type Filters, type Route } from './router'
import { menuPosition, TicketMenu, type OpenTicketMenu, type TicketAction, type TicketMenuPosition } from './TicketMenu'
Expand Down Expand Up @@ -165,7 +166,7 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
{board.archived && ' · archived (read-only)'}
</p>
</div>
<Tabs selectedKey={route.view} onSelectionChange={(k) => navigate({ ...route, view: k as 'list' | 'kanban' }, true)}>
<Tabs selectedKey={route.view} onSelectionChange={(k) => navigate({ ...route, view: k as 'list' | 'kanban' | 'requests' }, true)}>
<Tabs.ListContainer>
<Tabs.List aria-label="View">
<Tabs.Tab id="kanban">
Expand All @@ -176,6 +177,10 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
List
<Tabs.Indicator />
</Tabs.Tab>
<Tabs.Tab id="requests">
Requests
<Tabs.Indicator />
</Tabs.Tab>
</Tabs.List>
</Tabs.ListContainer>
</Tabs>
Expand All @@ -191,12 +196,12 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
<SearchField aria-label="Search tickets" value={filters.q} onChange={(q) => setFilters((f) => ({ ...f, q }))} className="w-full sm:w-72">
<SearchField.Group>
<SearchField.SearchIcon />
<SearchField.Input placeholder="Search title, key, description" />
<SearchField.Input placeholder={route.view === 'requests' ? 'Search requests' : 'Search title, key, description'} />
<SearchField.ClearButton />
</SearchField.Group>
</SearchField>
<FilterSelect label="Label" value={filters.labels} options={labelOptions} onChange={(labels) => setFilters((f) => ({ ...f, labels }))} />
<FilterSelect label="Assignee" value={filters.assignees} options={board.assignees} onChange={(assignees) => setFilters((f) => ({ ...f, assignees }))} withNone />
{route.view !== 'requests' && <FilterSelect label="Label" value={filters.labels} options={labelOptions} onChange={(labels) => setFilters((f) => ({ ...f, labels }))} />}
{route.view !== 'requests' && <FilterSelect label="Assignee" value={filters.assignees} options={board.assignees} onChange={(assignees) => setFilters((f) => ({ ...f, assignees }))} withNone />}
{(filters.labels.length > 0 || filters.assignees.length > 0 || filters.q) && (
<Button size="sm" variant="ghost" onPress={() => setFilters((f) => ({ ...f, q: '', labels: [], assignees: [] }))}>
Clear filters
Expand All @@ -214,7 +219,9 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
)}
</div>

{route.view === 'kanban' ? (
{route.view === 'requests' ? (
<RequestsView context={route.context} canEdit={canEdit} q={filters.q} showAll={filters.closed} onShowAll={(closed) => setFilters((f) => ({ ...f, closed }))} onOpen={open} onPromoted={() => void load()} onError={fail} />
) : route.view === 'kanban' ? (
<KanbanView items={visible} canEdit={canEdit} showArchived={filters.archived} onOpen={open} onMove={moveItem} onMenu={openMenu} />
) : (
<ListView items={visible} onOpen={open} showClosed={filters.closed} onShowClosed={(closed) => setFilters((f) => ({ ...f, closed }))} onMenu={openMenu} />
Expand Down
Loading
Loading