UI completion pass + accountability & benchmarking
UI (daily-drivable now): - Board: dnd-kit drag-and-drop between columns; click a card → task detail drawer (Sheet) with status, member assignee picker, send-to-AI-seat dispatch, description/artifact, parent/children navigation; seat-triad assignee chips (AI indigo monogram / human slate). - Cartable page (the personal pending slice), Members & invitations page (invite + copy join token; V1 sends no email), Review inbox now shows a word-level diff of your edits vs the proposal (lib/diff.ts, LCS), Org chart page (React Flow: org → teams → seats in the human/open/AI triad). Nav reordered; nothing left "soon". Accountability & benchmarking: - Identity: GET /members (directory + org role) and GET /invitations (with join token, inviter-only) — the directory also resolves names client-side everywhere. - OrgBoard: work_item_transitions recorded on every status change (AddWorkItemTransitions migration); GET /performance — per assignee (human and AI on the same scale): pending by column, done, worked hours (time in InProgress), avg cycle time (start of work → done), plus the unassigned-pending count. Owner-level capability. - Performance page: benchmark table merging board metrics with AI trust metrics (approval rate + edit distance from analytics); flags work with no one accountable. Verified: build green; ArchitectureTests 8/8; IntegrationTests 43/43 (new: directory, invitations list + Member 403s, transition-derived worked-hours/cycle-time, unassigned count); client npm build green (TS strict). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,8 @@ internal static class OrgBoardEndpoints
|
||||
group.MapGet("/seats", ListSeats).RequireAuthorization();
|
||||
group.MapPost("/seats/{id:guid}/agent", ConfigureAgent).RequireAuthorization();
|
||||
group.MapGet("/seats/{id:guid}/agent", GetAgent).RequireAuthorization();
|
||||
|
||||
group.MapGet("/performance", PerformanceEndpoints.Get).RequireAuthorization();
|
||||
}
|
||||
|
||||
private static TaskResponse ToResponse(WorkItem item) => new(
|
||||
@@ -175,7 +177,15 @@ internal static class OrgBoardEndpoints
|
||||
return Results.Forbid();
|
||||
}
|
||||
|
||||
item!.MoveTo(request.Status, clock.GetUtcNow());
|
||||
var fromStatus = item!.Status;
|
||||
item.MoveTo(request.Status, clock.GetUtcNow());
|
||||
if (fromStatus != request.Status)
|
||||
{
|
||||
// The raw material for working-hours / cycle-time accountability metrics.
|
||||
db.Transitions.Add(new WorkItemTransition(
|
||||
item.Id, team.Id, fromStatus, request.Status, user.MemberId, clock.GetUtcNow()));
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync(ct);
|
||||
await audit.WriteAsync(new AuditEvent("task.moved", "WorkItem", item.Id, user.MemberId, request.Status.ToString()), ct);
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeamUp.Modules.OrgBoard.Domain;
|
||||
using TeamUp.Modules.OrgBoard.Persistence;
|
||||
using TeamUp.SharedKernel.Access;
|
||||
|
||||
namespace TeamUp.Modules.OrgBoard.Endpoints;
|
||||
|
||||
internal sealed record PerformanceRow(
|
||||
string AssigneeKind,
|
||||
Guid AssigneeId,
|
||||
string? Name,
|
||||
int Backlog,
|
||||
int InProgress,
|
||||
int InReview,
|
||||
int Done,
|
||||
double WorkedHours,
|
||||
double? AvgCycleHours);
|
||||
|
||||
internal sealed record PerformanceResponse(int UnassignedPending, List<PerformanceRow> Rows);
|
||||
|
||||
/// <summary>
|
||||
/// Accountability metrics per assignee — human and AI on the same scale: pending load by column
|
||||
/// (who is accountable for what), working hours (time tasks spent InProgress, attributed to the
|
||||
/// current assignee), throughput (done), and avg cycle time (first InProgress → Done).
|
||||
/// </summary>
|
||||
internal static class PerformanceEndpoints
|
||||
{
|
||||
public static async Task<IResult> Get(
|
||||
Guid organizationId, IPermissionService permissions, OrgBoardDbContext db,
|
||||
TimeProvider clock, CancellationToken ct)
|
||||
{
|
||||
if (!permissions.Has(Capability.ViewAuditLog, ScopeRef.Org(organizationId)))
|
||||
{
|
||||
return Results.Forbid();
|
||||
}
|
||||
|
||||
var teamIds = await db.Teams
|
||||
.Where(t => t.OrganizationId == organizationId)
|
||||
.Select(t => t.Id)
|
||||
.ToListAsync(ct);
|
||||
|
||||
var items = await db.WorkItems.Where(w => teamIds.Contains(w.TeamId)).ToListAsync(ct);
|
||||
var transitions = (await db.Transitions.Where(t => teamIds.Contains(t.TeamId)).ToListAsync(ct))
|
||||
.GroupBy(t => t.WorkItemId)
|
||||
.ToDictionary(g => g.Key, g => g.OrderBy(t => t.OccurredAtUtc).ToList());
|
||||
var agentNames = await db.Agents.ToDictionaryAsync(a => a.Id, a => a.Name, ct);
|
||||
var now = clock.GetUtcNow();
|
||||
|
||||
var rows = items
|
||||
.Where(i => i.AssigneeKind != AssigneeKind.Unassigned && i.AssigneeId.HasValue)
|
||||
.GroupBy(i => (i.AssigneeKind, AssigneeId: i.AssigneeId!.Value))
|
||||
.Select(group =>
|
||||
{
|
||||
var byStatus = group.GroupBy(i => i.Status).ToDictionary(s => s.Key, s => s.Count());
|
||||
var workedHours = group.Sum(i => HoursInProgress(i, transitions, now));
|
||||
var cycles = group
|
||||
.Where(i => i.Status == WorkItemStatus.Done)
|
||||
.Select(i => CycleHours(i, transitions))
|
||||
.Where(h => h.HasValue)
|
||||
.Select(h => h!.Value)
|
||||
.ToList();
|
||||
|
||||
return new PerformanceRow(
|
||||
group.Key.AssigneeKind.ToString(),
|
||||
group.Key.AssigneeId,
|
||||
group.Key.AssigneeKind == AssigneeKind.Agent
|
||||
? agentNames.GetValueOrDefault(group.Key.AssigneeId)
|
||||
: null, // member names are joined client-side from /api/identity/members
|
||||
byStatus.GetValueOrDefault(WorkItemStatus.Backlog),
|
||||
byStatus.GetValueOrDefault(WorkItemStatus.InProgress),
|
||||
byStatus.GetValueOrDefault(WorkItemStatus.InReview),
|
||||
byStatus.GetValueOrDefault(WorkItemStatus.Done),
|
||||
Math.Round(workedHours, 2),
|
||||
cycles.Count == 0 ? null : Math.Round(cycles.Average(), 2));
|
||||
})
|
||||
.OrderByDescending(r => r.Done)
|
||||
.ToList();
|
||||
|
||||
var unassignedPending = items.Count(i =>
|
||||
i.AssigneeKind == AssigneeKind.Unassigned && i.Status != WorkItemStatus.Done);
|
||||
|
||||
return Results.Ok(new PerformanceResponse(unassignedPending, rows));
|
||||
}
|
||||
|
||||
/// <summary>Total hours the item has spent in InProgress (open span counts up to now).</summary>
|
||||
private static double HoursInProgress(
|
||||
WorkItem item,
|
||||
Dictionary<Guid, List<WorkItemTransition>> transitions,
|
||||
DateTimeOffset now)
|
||||
{
|
||||
if (!transitions.TryGetValue(item.Id, out var list))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double hours = 0;
|
||||
DateTimeOffset? entered = null;
|
||||
foreach (var transition in list)
|
||||
{
|
||||
if (transition.ToStatus == WorkItemStatus.InProgress)
|
||||
{
|
||||
entered ??= transition.OccurredAtUtc;
|
||||
}
|
||||
else if (entered.HasValue && transition.FromStatus == WorkItemStatus.InProgress)
|
||||
{
|
||||
hours += (transition.OccurredAtUtc - entered.Value).TotalHours;
|
||||
entered = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (entered.HasValue)
|
||||
{
|
||||
hours += (now - entered.Value).TotalHours;
|
||||
}
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
/// <summary>First entry into InProgress (or creation) → the last transition to Done.</summary>
|
||||
private static double? CycleHours(
|
||||
WorkItem item,
|
||||
Dictionary<Guid, List<WorkItemTransition>> transitions)
|
||||
{
|
||||
if (!transitions.TryGetValue(item.Id, out var list))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var done = list.LastOrDefault(t => t.ToStatus == WorkItemStatus.Done);
|
||||
if (done is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var started = list.FirstOrDefault(t => t.ToStatus == WorkItemStatus.InProgress)?.OccurredAtUtc
|
||||
?? item.CreatedAtUtc;
|
||||
var hours = (done.OccurredAtUtc - started).TotalHours;
|
||||
return hours < 0 ? null : hours;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user