diff --git a/src/board/http.ts b/src/board/http.ts index a1af027..65b9c66 100644 --- a/src/board/http.ts +++ b/src/board/http.ts @@ -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' @@ -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 diff --git a/src/commands/work.ts b/src/commands/work.ts index a9d87b4..d619f4e 100644 --- a/src/commands/work.ts +++ b/src/commands/work.ts @@ -16,6 +16,7 @@ import { rankItem, readExternalIssues, readWorkItems, + shortTitle, stateFor, summarizeForRecall, WORK_PRIORITIES, @@ -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[] | null) ?? []) : [] @@ -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 } : {}), diff --git a/src/work.ts b/src/work.ts index bdf7f8b..e44000a 100644 --- a/src/work.ts +++ b/src/work.ts @@ -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 => Boolean(r) && typeof r === 'object' && typeof (r as Record).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[]): 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 : [] diff --git a/test/board.test.ts b/test/board.test.ts index 45b67ae..50f9d70 100644 --- a/test/board.test.ts +++ b/test/board.test.ts @@ -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) +}) diff --git a/web/src/BoardPage.tsx b/web/src/BoardPage.tsx index 323a275..8668631 100644 --- a/web/src/BoardPage.tsx +++ b/web/src/BoardPage.tsx @@ -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' @@ -165,7 +166,7 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau {board.archived && ' · archived (read-only)'}

- navigate({ ...route, view: k as 'list' | 'kanban' }, true)}> + navigate({ ...route, view: k as 'list' | 'kanban' | 'requests' }, true)}> @@ -176,6 +177,10 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau List + + Requests + + @@ -191,12 +196,12 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau setFilters((f) => ({ ...f, q }))} className="w-full sm:w-72"> - + - setFilters((f) => ({ ...f, labels }))} /> - setFilters((f) => ({ ...f, assignees }))} withNone /> + {route.view !== 'requests' && setFilters((f) => ({ ...f, labels }))} />} + {route.view !== 'requests' && setFilters((f) => ({ ...f, assignees }))} withNone />} {(filters.labels.length > 0 || filters.assignees.length > 0 || filters.q) && (