-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(transcript): the mascot follows the run, and a named agent labels it #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
e579f5a
fix(transcript): the mascot follows the run, and a named agent labels it
yanhenrique-dev 0893b7b
docs(notes): the two rationales move to the notes, code keeps the poi…
yanhenrique-dev 35fd1cc
chore: drop the local plan scratch from the PR
yanhenrique-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // @vitest-environment happy-dom | ||
| /** | ||
| * Three subagents on one screen used to be three identical rows: same name, | ||
| * same sprite. The sprite was hashed from the name, and an unnamed run is always | ||
| * called "Subagent", so the hash had nothing to tell apart. | ||
| * | ||
| * Each run is rendered on its own because a turn with several runs folds them | ||
| * into one summary row ("Ran 3 subagents") until the reader opens it. The | ||
| * sprite a run draws is decided per row, so one render per run is the same | ||
| * question the grouped view asks once it is open. | ||
| */ | ||
| import { createElement, type ReactNode } from "react"; | ||
| import { renderToStaticMarkup } from "react-dom/server"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { resolveEffectiveMascot } from "../lib/customPets"; | ||
| import type { Block } from "../lib/session"; | ||
| import { AgentTranscript } from "./AgentTranscript"; | ||
|
|
||
| function stubExperimentalAnimations(value: string) { | ||
| vi.stubGlobal("localStorage", { | ||
| getItem: (key: string) => | ||
| key === "monocode.experimentalAnimations" ? value : null, | ||
| setItem: () => {}, | ||
| removeItem: () => {}, | ||
| } as unknown as Storage); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| stubExperimentalAnimations("1"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| /** A settled subagent run, which is the state the report was about. */ | ||
| function run(id: string, callId: string, name: string): Block { | ||
| return { | ||
| id, | ||
| role: "tool", | ||
| text: name, | ||
| tool: { callId, kind: "agent", status: "completed" }, | ||
| agentRun: { name, steps: [] }, | ||
| }; | ||
| } | ||
|
|
||
| function render(blocks: Block[]): string { | ||
| return renderToStaticMarkup( | ||
| createElement(AgentTranscript, { | ||
| blocks, | ||
| busy: false, | ||
| latestTurnAccessory: null as ReactNode, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The mascot's outline. | ||
| * | ||
| * Matched on the sprite's own viewBox rather than on the first `d` in the | ||
| * markup, because the row carries other icons (the disclosure chevron, the | ||
| * status glyph) that would otherwise be read as the mascot. | ||
| */ | ||
| function mascot(markup: string): string | undefined { | ||
| const match = /<svg[^>]*viewBox="0 0 8 8"[^>]*>\s*<path d="([^"]+)"/.exec( | ||
| markup, | ||
| ); | ||
| return match?.[1]; | ||
| } | ||
|
|
||
| /** One sprite per run, in the order given. */ | ||
| function sprites(runs: Block[]): Array<string | undefined> { | ||
| return runs.map((block) => mascot(render([block]))); | ||
| } | ||
|
|
||
| const UNNAMED: Array<[string, string]> = [ | ||
| ["r1", "call_task_1"], | ||
| ["r2", "call_task_2"], | ||
| ["r3", "call_task_3"], | ||
| ]; | ||
|
|
||
| describe("subagent mascots", () => { | ||
| it("tells three runs with the same name apart", () => { | ||
| // The reported defect: three rows, all called "Subagent", all with the same | ||
| // face. Asserted as "not all the same" rather than "all different" because | ||
| // the roster is ten sprites and a hash into ten can collide; what the bug | ||
| // did was collapse every run onto one sprite, not shuffle them. | ||
| const drawn = sprites( | ||
| UNNAMED.map(([id, callId]) => run(id, callId, "Subagent")), | ||
| ); | ||
| expect(drawn.every(Boolean)).toBe(true); | ||
| expect(new Set(drawn).size).toBeGreaterThan(1); | ||
| }); | ||
|
|
||
| it("gives the same run the same face twice", () => { | ||
| // A run's sprite has to survive a re-render, or every stream makes the | ||
| // mascot flicker to a different face. | ||
| const [block] = UNNAMED.map(([id, callId]) => run(id, callId, "Subagent")); | ||
| expect(mascot(render([block]))).toBe(mascot(render([block]))); | ||
| }); | ||
|
|
||
| it("keeps a settled run distinct from an earlier one with the same name", () => { | ||
| // The contract the component used to claim in a comment: two agents in a row | ||
| // stay distinguishable through the session. Ten sprites hashed from a key | ||
| // can collide, so the pair is chosen not to (`call_task_a` lands on 4, | ||
| // `call_task_b` on 5). A roster change that collides them says so here | ||
| // rather than passing quietly. | ||
| const [first, second] = sprites([ | ||
| run("r1", "call_task_a", "Subagent"), | ||
| run("r2", "call_task_b", "Subagent"), | ||
| ]); | ||
| expect(first).toBeTruthy(); | ||
| expect(second).toBeTruthy(); | ||
| expect(second).not.toBe(first); | ||
| }); | ||
|
|
||
| it("draws the sprite from the run's key, not from the label", () => { | ||
| // The sharp form of the contract: the sprite is whatever the run's own key | ||
| // hashes to. Pinning it to the resolver also means a project mascot, which | ||
| // has no key, keeps hashing its path, so the sidebar does not move. | ||
| const [sprite] = sprites([run("r1", "call_task_1", "Subagent")]); | ||
| expect(sprite).toBe(resolveEffectiveMascot("call_task_1").restPath); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: yanhenrique-dev/Monocode-linux
Length of output: 9066
🏁 Script executed:
Repository: yanhenrique-dev/Monocode-linux
Length of output: 8577
Limpe
subagentNamesquando a sessão filha terminar.handleSubagentEventregistra cadaagentnão oculto recebido emmessage.updated. Para eventos de sessões filhas,handleEventretorna antes doswitch, exceto para eventos de mensagem, partes, aprovação e pergunta. Portanto,session.statusesession.idleda sessão filha não removem essas entradas.Como
ensureLivereutiliza o mesmoLiveem turnos repetidos, cada sessão filha nomeada permanece no mapa até o encerramento doLive. Uma execução longa pode aumentar o uso de memória sem limite e degradar ou encerrar o harness por pressão de memória.Remova
sessionIdapós a emissão do último evento da sessão filha. Se o evento terminal ainda não for encaminhado, trate-o antes do retorno genérico para sessões filhas.🤖 Prompt for AI Agents