Skip to main content

agentmux_srv/server/app_api/
kanban_tokens.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The card's `tokens.not_measured` (docs/specs/SPEC_TOKEN_ANALYSIS_PER_KANBAN_TASK_2026_11_22.md section 4.8): the
5//! agents that held a task whose provider reports no usage srv reads, so a figure that leaves them out is not taken
6//! for the whole. It needs the agent definitions, which the board's own store does not have, so the Kanban answer
7//! adds it.
8
9use std::collections::HashMap;
10
11use crate::backend::storage::store::Store;
12use crate::backend::storage::work_board::BoardTask;
13use crate::backend::storage::work_tokens::is_measured;
14
15/// Name, for each task whose tally is on the card, the agents that held it and whose tokens are not counted: by
16/// display name, once each, in the order they took it. A holder whose definition is gone is not named (nothing says
17/// what it ran on).
18pub(super) fn mark_not_measured(work: &Store, defs: &Store, tasks: &mut [BoardTask]) {
19    let ids: Vec<String> = tasks.iter().filter(|t| t.card.tokens.is_some()).map(|t| t.item.id.clone()).collect();
20    let Ok(holders) = work.work_holders(&ids) else { return };
21    if holders.is_empty() {
22        return;
23    }
24    let by_slug: HashMap<String, (String, bool)> = defs
25        .agent_def_list()
26        .unwrap_or_default()
27        .into_iter()
28        .map(|d| (d.slug.to_lowercase(), (if d.name.trim().is_empty() { d.slug.clone() } else { d.name.clone() }, is_measured(&d.provider, &d.agent_type))))
29        .collect();
30    for t in tasks {
31        let Some(tokens) = t.card.tokens.as_mut() else { continue };
32        let mut names: Vec<String> = Vec::new();
33        for holder in holders.get(&t.item.id).into_iter().flatten() {
34            if let Some((name, false)) = by_slug.get(&holder.to_lowercase()) {
35                if !names.contains(name) {
36                    names.push(name.clone());
37                }
38            }
39        }
40        tokens.not_measured = (!names.is_empty()).then_some(names);
41    }
42}