-
Notifications
You must be signed in to change notification settings - Fork 596
fix(dashboard): handle User action requests from the needs-you drawer #5571
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
Open
loopx-agent
wants to merge
2
commits into
main
Choose a base branch
from
codex/attention-user-action-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+464
−50
Open
Changes from all commits
Commits
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
125 changes: 125 additions & 0 deletions
125
apps/presentation/dashboard/src/features/personal-workspace/attention-actions.tsx
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,125 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { CalendarClock, Check, MessageCircleQuestion, MessageSquareReply, MoreHorizontal, Square, X } from "lucide-react"; | ||
| import type { DecisionOutcome } from "../../../../../../loopx/control_plane/todos/user_completion_types.js"; | ||
| import { canDecideAttention, canHandleUserAction, canReviewAttention, nextMorningResumeWhen } from "./attention-details"; | ||
| import { useWorkspaceI18n } from "./i18n"; | ||
| import type { PersonalWorkspaceCallbacks, WorkspaceActionPreviewRequest, WorkspaceAttention } from "./personal-workspace-model"; | ||
|
|
||
| type PreviewState = { status: "idle" } | { status: "pending" } | { status: "error"; message: string }; | ||
|
|
||
| /** Owner affordances for one "needs you" item. Every write is a typed preview | ||
| * the owner confirms once; the Todo owner validates it and decides effects. */ | ||
| export function AttentionActions({ item, readOnly, callbacks, fallbackAgentId }: { | ||
| item: WorkspaceAttention; | ||
| readOnly: boolean; | ||
| callbacks: PersonalWorkspaceCallbacks; | ||
| fallbackAgentId: string; | ||
| }) { | ||
| const { t } = useWorkspaceI18n(); | ||
| const [preview, setPreview] = useState<PreviewState>({ status: "idle" }); | ||
| useEffect(() => setPreview({ status: "idle" }), [item.goalId, item.todoId]); | ||
| // Hard-lease Goals attribute the write to the Agent the request unblocks. | ||
| const agentId = item.details?.blocksAgent ?? fallbackAgentId; | ||
| const context = { goal_id: item.goalId, kind: "todo", todo_id: item.todoId }; | ||
| const key = (suffix: string) => `workspace-attention-${item.todoId}-${suffix}-${Date.now().toString(36)}`; | ||
|
|
||
| async function requestPreview(request: WorkspaceActionPreviewRequest) { | ||
| if (preview.status === "pending" || !callbacks.onPreviewAction) return; | ||
| setPreview({ status: "pending" }); | ||
| try { | ||
| await callbacks.onPreviewAction(request); | ||
| setPreview({ status: "idle" }); | ||
| } catch (error) { | ||
| setPreview({ status: "error", message: error instanceof Error ? error.message : String(error) }); | ||
| } | ||
| } | ||
|
|
||
| function previewDecision(attention: WorkspaceAttention, decision: DecisionOutcome) { | ||
| if (readOnly || !canDecideAttention(attention)) return; | ||
| void requestPreview({ | ||
| actionKind: "gate.resolve", context, idempotencyKey: key(`decision-${decision}`), | ||
| normalizedParameters: { agent_id: agentId, goal_id: attention.goalId, decision, todo_id: attention.todoId }, | ||
| summary: attention.text, | ||
| }); | ||
| } | ||
|
|
||
| function previewUserAction(attention: WorkspaceAttention, operation: "complete" | "defer" | "cancel") { | ||
| if (readOnly || !canHandleUserAction(attention)) return; | ||
| if (operation === "cancel") { | ||
| // Cancelling a user_action is the one decision outcome its owner admits; | ||
| // it closes only this reminder and never resumes or approves other work. | ||
| void requestPreview({ | ||
| actionKind: "gate.resolve", context, idempotencyKey: key("cancel"), | ||
| normalizedParameters: { agent_id: agentId, goal_id: attention.goalId, decision: "cancel", | ||
| note: t("drawer.userActionCancelNote"), todo_id: attention.todoId }, | ||
| summary: t("drawer.userActionCancelSummary", { task: attention.text }), | ||
| }); | ||
| return; | ||
| } | ||
| void requestPreview({ | ||
| actionKind: "todo.update", context, idempotencyKey: key(operation), | ||
| normalizedParameters: { agent_id: agentId, goal_id: attention.goalId, operation, todo_id: attention.todoId, | ||
| ...(operation === "defer" ? { resume_when: nextMorningResumeWhen(new Date()) } : {}) }, | ||
| summary: t(operation === "defer" ? "drawer.userActionDeferSummary" : "drawer.userActionCompleteSummary", { task: attention.text }), | ||
| }); | ||
| } | ||
|
|
||
| const pending = preview.status === "pending"; | ||
| const feedback = preview.status === "error" | ||
| ? <p className="personal-proposal-state is-error" role="alert"><X size={16} /><span>{t("drawer.attentionPreviewFailed", { error: preview.message })}</span></p> | ||
| : pending ? <p className="personal-proposal-state" role="status">{t("drawer.attentionPreparing")}</p> : null; | ||
| const reply = callbacks.onReplyToAttention | ||
| ? <button className="personal-secondary-action" onClick={() => callbacks.onReplyToAttention?.(item, "reply")} type="button"><MessageSquareReply size={16} />{t("drawer.attentionReply")}</button> | ||
| : null; | ||
| const explain = (label: string) => callbacks.onExplainDecision | ||
| ? <button onClick={() => void callbacks.onExplainDecision?.(item)} type="button"><MessageCircleQuestion size={16} />{label}</button> | ||
| : null; | ||
|
|
||
| if (readOnly) { | ||
| return canReviewAttention(item) ? <p className="personal-proposal-explainer" role="status">{t("drawer.attentionReadOnly")}</p> : null; | ||
| } | ||
| if (canDecideAttention(item)) { | ||
| return <> | ||
| <div className="personal-decision-bar" role="group" aria-label={t("drawer.decisionGroup")}> | ||
| <button className="personal-primary-action" disabled={pending} onClick={() => previewDecision(item, "approve")} type="button"><Check size={17} />{t("drawer.decisionApprove")}</button> | ||
| <button className="personal-secondary-action" disabled={pending} onClick={() => previewDecision(item, "reject")} type="button"><X size={17} />{t("drawer.decisionReject")}</button> | ||
| </div> | ||
| {feedback} | ||
| <details className="personal-compact-menu"> | ||
| <summary><MoreHorizontal size={17} />{t("drawer.decisionMore")}</summary> | ||
| <div> | ||
| {explain(t("drawer.explainDecision"))} | ||
| <button disabled={pending} onClick={() => previewDecision(item, "cancel")} type="button"><Square size={16} />{t("drawer.decisionCancel")}</button> | ||
| </div> | ||
| </details> | ||
| </>; | ||
| } | ||
| if (canHandleUserAction(item)) { | ||
| return <> | ||
| <p className="personal-proposal-explainer">{t(item.details?.unblocksTodoId ? "drawer.userActionUnblocks" : "drawer.userActionReminder")}</p> | ||
| <div className="personal-decision-bar" role="group" aria-label={t("drawer.userActionGroup")}> | ||
| <button className="personal-primary-action" disabled={pending} onClick={() => previewUserAction(item, "complete")} type="button"><Check size={17} />{t("drawer.userActionComplete")}</button> | ||
| {reply} | ||
| </div> | ||
| {feedback} | ||
| <details className="personal-compact-menu"> | ||
| <summary><MoreHorizontal size={17} />{t("drawer.userActionMore")}</summary> | ||
| <div> | ||
| <button disabled={pending} onClick={() => previewUserAction(item, "defer")} type="button"><CalendarClock size={16} />{t("drawer.userActionDefer")}</button> | ||
| <button disabled={pending} onClick={() => previewUserAction(item, "cancel")} type="button"><Square size={16} />{t("drawer.userActionCancel")}</button> | ||
| {explain(t("drawer.askAgentExplain"))} | ||
| </div> | ||
| </details> | ||
| </>; | ||
| } | ||
| if (!canReviewAttention(item)) return null; | ||
| const note = item.decisionSource === "run_operator_gate" ? "drawer.decisionRunGate" | ||
| : item.details?.interaction === "user_action" ? "drawer.userActionMissingTodo" : "drawer.decisionNotGate"; | ||
| return <> | ||
| <p className="personal-proposal-explainer">{t(note)}</p> | ||
| <div className="personal-decision-bar" role="group" aria-label={t("drawer.userActionGroup")}> | ||
| {reply} | ||
| {callbacks.onExplainDecision ? <button className="personal-secondary-action" onClick={() => void callbacks.onExplainDecision?.(item)} type="button"><MessageCircleQuestion size={16} />{t("drawer.askAgentExplain")}</button> : null} | ||
| </div> | ||
| </>; | ||
| } | ||
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
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.
[P1]
user_actionbinds its responsibility through canonicalbound_agent, but attentionDetails only retains blocksAgent. This line therefore chooses the first available/default actor. In the compiled UI with a request bound to codex-delivery, it posts agent_id=codex; the real hard-lease File owner refuses completion and cancellation, with no change to the dependency. A registered wrong peer also fails; the bound peer succeeds and reads back only its scoped effects. Carry bound_agent into the projection and prefer it for user_action while retaining blocks_agent for user_gate and all native binding checks; add a packaged UI + real backend case with a non-default bound role.