mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-06 05:58:38 +01:00
fix(orangecat): order actor status by attention before the 25-project cap (#916)
The cap took the first 25 projects in list order, so an account with 37 projects never showed OrangeCat's Cat its own `orangecat` project. Sort by what needs the owner (blocked on them, new feedback, working, queued, linked, live) and cut after. Stable: ties keep list order. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
921081d51e
commit
6e596cd63e
2 files changed
+60
-1
No files matched your search
@@ -106,6 +106,40 @@ async function main(): Promise<void> {
|
||||
assert.equal(many.length, ACTOR_STATUS_MAX_PROJECTS);
|
||||
console.log(" ✓ capped at 25 projects");
|
||||
|
||||
// The cap keeps what needs the person, not the first 25 in list order: an
|
||||
// account with 37 projects never showed OrangeCat its own `orangecat` project.
|
||||
const crowd = Array.from({ length: 30 }, (_, i) => ({
|
||||
id: `c${i}`,
|
||||
name: `C${i}`,
|
||||
liveUrl: null,
|
||||
entityProjectId: null,
|
||||
}));
|
||||
const ordered = shapeActorStatus({
|
||||
...base,
|
||||
projects: crowd,
|
||||
states: [
|
||||
{
|
||||
projectKey: "c29",
|
||||
agentRunning: false,
|
||||
sessionStatus: "ready",
|
||||
sessionBlockReason: "awaiting_user",
|
||||
promptQueue: [],
|
||||
currentPromptLabel: null,
|
||||
},
|
||||
],
|
||||
outcomes: new Map(),
|
||||
feedback: [],
|
||||
links: [{ projectId: "c28", entityType: "project", entityId: "oc-9" }],
|
||||
});
|
||||
assert.equal(ordered.length, ACTOR_STATUS_MAX_PROJECTS);
|
||||
assert.equal(ordered[0].id, "c29", "a project waiting on its owner leads, even from position 30");
|
||||
assert.ok(
|
||||
ordered.some((p) => p.id === "c28"),
|
||||
"a project linked to OrangeCat survives the cap",
|
||||
);
|
||||
assert.equal(ordered[2].id, "c0", "the rest keep their list order");
|
||||
console.log(" ✓ ordered by attention before the cap");
|
||||
|
||||
const now = Date.parse("2026-09-24T12:00:00Z");
|
||||
assert.ok(isFreshIssuedAt("2026-09-24T11:57:00Z", now));
|
||||
assert.ok(isFreshIssuedAt("2026-09-24T12:02:00Z", now), "small clock skew ahead is fine");
|
||||
|
||||
@@ -73,7 +73,7 @@ export function shapeActorStatus(input: ActorStatusInput): ActorProjectStatus[]
|
||||
// entities.id), which user_projects carries as entityProjectId.
|
||||
const feedbackByEntity = new Map(input.feedback.map((f) => [f.projectId, f]));
|
||||
|
||||
return input.projects.slice(0, ACTOR_STATUS_MAX_PROJECTS).map((p) => {
|
||||
const shaped = input.projects.map((p) => {
|
||||
const s = stateByKey.get(p.name.toLowerCase());
|
||||
const blockReason = s?.sessionBlockReason ?? null;
|
||||
const status: ActorProjectState = blockReason
|
||||
@@ -98,4 +98,29 @@ export function shapeActorStatus(input: ActorStatusInput): ActorProjectStatus[]
|
||||
.map((l) => ({ entityType: l.entityType, entityId: l.entityId })),
|
||||
};
|
||||
});
|
||||
|
||||
// Cut to the cap only AFTER ordering by what needs the person. The cap used
|
||||
// to take the first 25 in list order, so an account with 37 projects never
|
||||
// showed OrangeCat's Cat its own `orangecat` project — the list order said
|
||||
// nothing about which ones mattered. Stable sort: ties keep list order.
|
||||
return shaped
|
||||
.map((project, index) => ({ project, index }))
|
||||
.sort((a, b) => attention(b.project) - attention(a.project) || a.index - b.index)
|
||||
.slice(0, ACTOR_STATUS_MAX_PROJECTS)
|
||||
.map(({ project }) => project);
|
||||
}
|
||||
|
||||
/**
|
||||
* How much a project needs its owner right now — waiting on them first, then
|
||||
* new visitor feedback, then work in motion, then projects that exist in the
|
||||
* world (linked to OrangeCat, or live), then the rest.
|
||||
*/
|
||||
export function attention(p: ActorProjectStatus): number {
|
||||
if (p.status === "blocked") return p.blockReason === "awaiting_user" ? 100 : 80;
|
||||
if (p.feedback.new > 0) return 60 + Math.min(p.feedback.new, 19);
|
||||
if (p.status === "working") return 50;
|
||||
if (p.queueDepth > 0) return 40;
|
||||
if (p.orangecat.length > 0) return 30;
|
||||
if (p.liveUrl) return 20;
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user