Skip to content

Commit ff4890a

Browse files
committed
Merge remote-tracking branch 'origin/main' into codex/reconcile-pr-10015-split-guard
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
2 parents a7fd827 + 8a90a05 commit ff4890a

26 files changed

Lines changed: 1383 additions & 162 deletions

‎apps/workbench/packages/daemon/src/steward-inbox.ts‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ function deriveCoreActionRisk(
8686
return 'medium';
8787
}
8888

89-
function parseCoreActionCard(raw: unknown): Extract<StewardInlineCard, { kind: 'core_action_proposal' }> | null {
89+
const AUTO_FILTERED_STALE_REASONS = new Set(['proposal_expired', 'target_todo_updated']);
90+
91+
function parseCoreActionCard(
92+
raw: unknown,
93+
nowMs: number = Date.now(),
94+
): Extract<StewardInlineCard, { kind: 'core_action_proposal' }> | null {
9095
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
9196
const r = raw as Record<string, unknown>;
9297
const proposalId = typeof r.proposal_id === 'string' ? r.proposal_id.trim() : '';
@@ -99,13 +104,36 @@ function parseCoreActionCard(raw: unknown): Extract<StewardInlineCard, { kind: '
99104
const context = r.context && typeof r.context === 'object' && !Array.isArray(r.context)
100105
? (r.context as Record<string, unknown>)
101106
: {};
107+
const expiresAt = typeof context.expires_at === 'string' && context.expires_at.trim()
108+
? context.expires_at.trim()
109+
: null;
110+
if (expiresAt) {
111+
const expiresMs = Date.parse(expiresAt);
112+
if (!Number.isNaN(expiresMs) && expiresMs <= nowMs) {
113+
return null;
114+
}
115+
}
116+
const staleReason =
117+
r.stale && typeof r.stale === 'object' && !Array.isArray(r.stale) && typeof (r.stale as Record<string, unknown>).reason === 'string'
118+
? String((r.stale as Record<string, unknown>).reason).trim()
119+
: null;
120+
if (staleReason && AUTO_FILTERED_STALE_REASONS.has(staleReason)) {
121+
return null;
122+
}
123+
102124
const rawParams = r.normalized_parameters ?? r.parameters;
103125
const parameters = sanitizeCoreActionParams(rawParams);
104126
const rawGoalId =
105127
(typeof context.goal_id === 'string' && context.goal_id.trim()) ||
106128
(typeof parameters.goal_id === 'string' && parameters.goal_id.trim()) ||
107129
(typeof r.goal_id === 'string' && r.goal_id.trim()) ||
108130
null;
131+
const contextKind =
132+
typeof context.kind === 'string' && context.kind.trim() ? context.kind.trim() : null;
133+
const sourceSessionId =
134+
(typeof context.session_id === 'string' && context.session_id.trim()) ||
135+
(typeof parameters.session_id === 'string' && parameters.session_id.trim()) ||
136+
null;
109137

110138
const evidence = Array.isArray(r.validation_evidence)
111139
? r.validation_evidence.flatMap((item) => {
@@ -173,6 +201,8 @@ function parseCoreActionCard(raw: unknown): Extract<StewardInlineCard, { kind: '
173201
summary: typeof r.summary === 'string' && r.summary.trim() ? r.summary.trim() : actionKind,
174202
status,
175203
goalId: rawGoalId,
204+
contextKind,
205+
sourceSessionId,
176206
parameters,
177207
evidence,
178208
availableTransitions,
@@ -322,6 +352,8 @@ export type StewardInlineCard =
322352
summary: string;
323353
status: string;
324354
goalId: string | null;
355+
contextKind?: string | null;
356+
sourceSessionId?: string | null;
325357
parameters: Record<string, unknown>;
326358
evidence: string[];
327359
availableTransitions: string[];
@@ -875,6 +907,7 @@ export class StewardInboxService {
875907
private async fetchCoreActionCards(
876908
core: URL | null | undefined,
877909
timeoutMs: number,
910+
nowMs: number,
878911
): Promise<{
879912
cards: Array<Extract<StewardInlineCard, { kind: 'core_action_proposal' }>>;
880913
health: StewardSurfaceSourceHealth;
@@ -898,7 +931,7 @@ export class StewardInboxService {
898931
const dismissedIds = this.listDismissedCoreActionIds();
899932
const cards: Array<Extract<StewardInlineCard, { kind: 'core_action_proposal' }>> = [];
900933
for (const item of rawList) {
901-
const card = parseCoreActionCard(item);
934+
const card = parseCoreActionCard(item, nowMs);
902935
if (!card) continue;
903936
// Skip proposals (stale/failed/gated) already superseded by a regenerated proposal.
904937
if (supersededIds.has(card.proposalId)) continue;
@@ -944,7 +977,7 @@ export class StewardInboxService {
944977
const nowIso = new Date(nowMs).toISOString();
945978
const inlineCards: StewardInlineCard[] = [];
946979

947-
const coreResult = await this.fetchCoreActionCards(effectiveCoreUrl, timeoutMs);
980+
const coreResult = await this.fetchCoreActionCards(effectiveCoreUrl, timeoutMs, nowMs);
948981
const coreCards = scoped
949982
? coreResult.cards.filter((card) => scopedGoalId !== null && card.goalId === scopedGoalId)
950983
: coreResult.cards;

‎apps/workbench/packages/daemon/test/steward-inbox.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,25 @@ test('surface() aggregates actionable Core TypedActions into needsYou and fails
529529
context: { kind: 'goal', goal_id: 'goal-alpha' },
530530
normalized_parameters: {},
531531
},
532+
{
533+
proposal_id: 'proposal-expired-context',
534+
action_kind: 'todo.create',
535+
summary: 'Ancient expired proposal',
536+
status: 'preview_ready',
537+
context: { kind: 'manager', goal_id: 'goal-alpha', expires_at: '2020-01-01T00:00:00Z' },
538+
normalized_parameters: { goal_id: 'goal-alpha', text: 'Expired' },
539+
created_at: '2020-01-01T00:00:00Z',
540+
},
541+
{
542+
proposal_id: 'proposal-monitor-superseded',
543+
action_kind: 'monitor.update',
544+
summary: 'Superseded monitor edit',
545+
status: 'stale',
546+
stale: { reason: 'target_todo_updated', todo_id: 'todo_123' },
547+
context: { kind: 'manager', goal_id: 'goal-alpha' },
548+
normalized_parameters: { goal_id: 'goal-alpha', todo_id: 'todo_123', operation: 'edit' },
549+
created_at: '2026-11-30T18:28:39Z',
550+
},
532551
],
533552
}),
534553
);
@@ -576,6 +595,17 @@ test('surface() aggregates actionable Core TypedActions into needsYou and fails
576595
assert.equal(mergeCard.actionKind, 'pr.merge');
577596
assert.equal(mergeCard.riskLevel, 'high');
578597
assert.equal(mergeCard.goalId, 'goal-alpha');
598+
assert.equal(mergeCard.contextKind, 'goal');
599+
assert.equal(
600+
coreCards.some((c: { proposalId: string }) => c.proposalId === 'proposal-expired-context'),
601+
false,
602+
'expired proposals (context.expires_at <= now) must be auto-filtered',
603+
);
604+
assert.equal(
605+
coreCards.some((c: { proposalId: string }) => c.proposalId === 'proposal-monitor-superseded'),
606+
false,
607+
'monitor.update proposals invalidated by target_todo_updated must be auto-filtered',
608+
);
579609
assert.equal(mergeCard.parameters.pr_number, 9401);
580610
assert.equal(mergeCard.parameters.api_key, undefined, 'sensitive parameter keys must be stripped');
581611
assert.equal(mergeCard.parameters.auth_token, undefined, 'sensitive parameter keys must be stripped');

‎apps/workbench/packages/web/src/api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ export type StewardInlineCard =
321321
summary: string;
322322
status: string;
323323
goalId: string | null;
324+
contextKind?: string | null;
325+
sourceSessionId?: string | null;
324326
parameters: Record<string, unknown>;
325327
evidence: string[];
326328
availableTransitions: string[];

‎apps/workbench/packages/web/src/components/StewardConversation.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { mentionAt } from '../mentions';
99
import { IconSend, IconStop } from './icons';
1010
import {
1111
groupStewardMessages,
12+
partitionStewardSurfaceCards,
1213
StewardInlineCards,
1314
StewardStatusDock,
1415
} from './StewardInlineCards';
@@ -506,7 +507,8 @@ export function StewardConversation({
506507
</div>;
507508
}
508509

509-
const hasInlineCards = (surface?.inlineCards.length ?? 0) > 0;
510+
const { streamCards } = partitionStewardSurfaceCards(surface?.inlineCards ?? [], sessionId);
511+
const hasInlineCards = streamCards.length > 0;
510512
const empty = messages !== null && messages.length === 0 && !turn && !hasInlineCards;
511513
const groupedMessages = messages ? groupStewardMessages(messages) : null;
512514
return <div className="steward-chat">
@@ -549,7 +551,7 @@ export function StewardConversation({
549551
{turn.error ? <div className="row channel-note"><span role="alert">{turn.error}</span></div> : null}
550552
</> : null}
551553
<StewardInlineCards
552-
cards={surface?.inlineCards ?? []}
554+
cards={streamCards}
553555
api={api}
554556
token={token}
555557
onChanged={() => refreshSurface()}

‎apps/workbench/packages/web/src/components/StewardInlineCards.tsx‎

Lines changed: 95 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,62 @@ function visibleCoreActionEvidence(evidence: string[]): string[] {
216216
* completing reviewed stale/drifted actions in one click via refresh + safety check + apply,
217217
* while stopping safely on gates or changed intent.
218218
*/
219+
/**
220+
* Format an ISO timestamp compactly (`YYYY-MM-DD HH:mm` or `MM-DD HH:mm` within the same year)
221+
* so owners can immediately spot whether a pending proposal is fresh or historical.
222+
*/
223+
export function formatProposalTimestamp(iso: string | null | undefined, now: Date = new Date()): string | null {
224+
if (!iso || typeof iso !== 'string') return null;
225+
const parsed = new Date(iso);
226+
if (Number.isNaN(parsed.getTime())) return null;
227+
const pad = (n: number) => String(n).padStart(2, '0');
228+
const year = parsed.getFullYear();
229+
const month = pad(parsed.getMonth() + 1);
230+
const day = pad(parsed.getDate());
231+
const hour = pad(parsed.getHours());
232+
const min = pad(parsed.getMinutes());
233+
return year === now.getFullYear()
234+
? `${month}-${day} ${hour}:${min}`
235+
: `${year}-${month}-${day} ${hour}:${min}`;
236+
}
237+
238+
/**
239+
* Derive a concise provenance label for a Core action proposal from its typed `context.kind`.
240+
*/
241+
export function proposalSourceLabel(proposal: Pick<CoreActionProposal, 'context'>): string | null {
242+
const kind = typeof proposal.context?.kind === 'string' ? proposal.context.kind.trim() : '';
243+
if (!kind) return null;
244+
if (kind === 'manager') return t('loopx.coreAction.sourceManager');
245+
if (kind === 'goal') return t('loopx.coreAction.sourceGoal');
246+
if (kind === 'todo') return t('loopx.coreAction.sourceTodo');
247+
return kind;
248+
}
249+
250+
/**
251+
* Partition Steward surface cards so cross-Goal / historical Core proposals stay inside the
252+
* interactive `Needs you` dock drawer instead of cluttering the bottom of the active chat stream.
253+
* Core proposals explicitly bound to the active Steward session remain visible inline in-stream.
254+
*/
255+
export function partitionStewardSurfaceCards(
256+
cards: StewardInlineCard[],
257+
activeSessionId: string | null | undefined,
258+
): { streamCards: StewardInlineCard[]; dockCards: StewardInlineCard[] } {
259+
const normalizedSession = typeof activeSessionId === 'string' && activeSessionId.trim()
260+
? activeSessionId.trim()
261+
: null;
262+
const streamCards: StewardInlineCard[] = [];
263+
for (const card of cards) {
264+
if (card.kind === 'core_action_proposal') {
265+
if (normalizedSession && card.sourceSessionId === normalizedSession) {
266+
streamCards.push(card);
267+
}
268+
} else {
269+
streamCards.push(card);
270+
}
271+
}
272+
return { streamCards, dockCards: cards };
273+
}
274+
219275
export function CoreActionProposalCard({
220276
proposal,
221277
token,
@@ -259,6 +315,9 @@ export function CoreActionProposalCard({
259315
const tone = coreActionBadgeTone(current.actionKind);
260316
const paramEntries = summarizeProposalParams(current.parameters);
261317
const evidenceLines = visibleCoreActionEvidence(current.evidence);
318+
const sourceLabel = proposalSourceLabel(current);
319+
const createdLabel = formatProposalTimestamp(current.createdAt);
320+
const provenanceParts = [sourceLabel, createdLabel].filter((v): v is string => Boolean(v));
262321

263322
const run = async (action: CoreActionCardAction) => {
264323
setBusy(action);
@@ -353,6 +412,16 @@ export function CoreActionProposalCard({
353412
<span className="steward-card-chip">{current.goalId}</span>
354413
)
355414
)}
415+
{provenanceParts.length > 0 && (
416+
<span
417+
className="steward-card-provenance"
418+
data-proposal-source={sourceLabel ?? undefined}
419+
data-proposal-created-at={current.createdAt ?? undefined}
420+
title={current.createdAt ?? undefined}
421+
>
422+
{provenanceParts.join(' · ')}
423+
</span>
424+
)}
356425
</div>
357426

358427
<div className="steward-card-title">{current.summary}</div>
@@ -427,13 +496,17 @@ export function CoreActionProposalCard({
427496
}
428497

429498
function cardToCoreProposal(card: Extract<StewardInlineCard, { kind: 'core_action_proposal' }>): CoreActionProposal {
499+
const context: Record<string, unknown> = {};
500+
if (card.goalId) context.goal_id = card.goalId;
501+
if (card.contextKind) context.kind = card.contextKind;
502+
if (card.sourceSessionId) context.session_id = card.sourceSessionId;
430503
return {
431504
proposalId: card.proposalId,
432505
actionKind: card.actionKind,
433506
summary: card.summary,
434507
status: card.status,
435508
goalId: card.goalId,
436-
context: card.goalId ? { goal_id: card.goalId } : {},
509+
context,
437510
parameters: card.parameters,
438511
evidence: card.evidence,
439512
availableTransitions: card.availableTransitions,
@@ -454,57 +527,19 @@ function cardToCoreProposal(card: Extract<StewardInlineCard, { kind: 'core_actio
454527
};
455528
}
456529

457-
function cardSummaryTitle(card: StewardInlineCard): string {
458-
switch (card.kind) {
459-
case 'followup_due':
460-
return card.prompt;
461-
case 'free_text_question':
462-
return card.question;
463-
case 'supervision_alert':
464-
return card.summary;
465-
case 'core_action_proposal':
466-
return card.summary;
467-
default:
468-
return card.title;
469-
}
470-
}
471-
472-
function cardSummarySubtitle(card: StewardInlineCard): string {
473-
switch (card.kind) {
474-
case 'core_action_proposal':
475-
return coreActionKindLabel(card.actionKind);
476-
case 'plan_approval':
477-
return t('loopx.stewardCard.planGate');
478-
case 'thread_approval':
479-
return t('loopx.stewardCard.approvalGate');
480-
case 'thread_input':
481-
return t('loopx.stewardCard.questionGate');
482-
case 'concern_report':
483-
return t('loopx.stewardCard.concernReceipt');
484-
case 'followup_due':
485-
return t('loopx.stewardCard.followupDue');
486-
case 'free_text_question':
487-
return t('loopx.stewardCard.verifiedQuestion');
488-
case 'supervision_alert':
489-
return card.alertKind === 'no_progress'
490-
? t('loopx.stewardCard.noProgress')
491-
: t('loopx.stewardCard.supervisionAlert');
492-
case 'review_escalated':
493-
return t('loopx.stewardCard.reviewEscalated');
494-
}
495-
}
496-
497530
export function StewardInlineCards({
498531
cards,
499532
api,
500533
token,
534+
compact = false,
501535
onChanged,
502536
onOpenGoal,
503537
onOpenThread,
504538
}: {
505539
cards: StewardInlineCard[];
506540
api?: Api;
507541
token?: string;
542+
compact?: boolean;
508543
onChanged: () => void;
509544
onOpenGoal?: (goalId: string) => void;
510545
onOpenThread?: (threadId: string) => void;
@@ -537,7 +572,7 @@ export function StewardInlineCards({
537572
};
538573

539574
return (
540-
<div className="steward-inline-cards" aria-label={t('loopx.needsYou')}>
575+
<div className={`steward-inline-cards${compact ? ' is-compact' : ''}`} aria-label={t('loopx.needsYou')}>
541576
{cards.map((card) => {
542577
if (card.kind === 'core_action_proposal') {
543578
return (
@@ -1121,16 +1156,25 @@ export function StewardStatusDock({
11211156
</button>
11221157
</li>
11231158
))}
1124-
{(surface?.inlineCards ?? []).slice(0, 8).map((card) => (
1125-
<li key={card.id} className="steward-tray-item">
1126-
<div className="steward-tray-row is-static">
1127-
<span className="steward-tray-title">
1128-
{cardSummaryTitle(card)}
1129-
</span>
1130-
<span className="steward-tray-sub">{cardSummarySubtitle(card)}</span>
1131-
</div>
1159+
{(surface?.inlineCards ?? []).length > 0 && (
1160+
<li className="steward-tray-item steward-tray-cards-item" data-tray-cards="needs_you">
1161+
<StewardInlineCards
1162+
cards={surface?.inlineCards ?? []}
1163+
api={api}
1164+
token={token}
1165+
compact
1166+
onChanged={onChanged}
1167+
onOpenGoal={(goalId) => {
1168+
setOpenTab(null);
1169+
onOpenGoal?.(goalId);
1170+
}}
1171+
onOpenThread={(threadId) => {
1172+
setOpenTab(null);
1173+
onOpenThread?.(threadId);
1174+
}}
1175+
/>
11321176
</li>
1133-
))}
1177+
)}
11341178
{waitingGoals.length > 5 && onOpenGoalsOverview && (
11351179
<li className="steward-tray-item">
11361180
<button type="button" className="steward-tray-more" onClick={() => { setOpenTab(null); onOpenGoalsOverview(); }}>

‎apps/workbench/packages/web/src/i18n/locales/en.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,6 +3740,9 @@ export const en: Messages = {
37403740
'loopx.coreAction.riskHigh': 'High risk',
37413741
'loopx.coreAction.openGoal': 'Open Goal',
37423742
'loopx.coreAction.evidenceTitle': 'Validation evidence',
3743+
'loopx.coreAction.sourceManager': 'Steward',
3744+
'loopx.coreAction.sourceGoal': 'Goal',
3745+
'loopx.coreAction.sourceTodo': 'Todo',
37433746
'loopx.ledger.filter.all': 'All',
37443747
'loopx.ledger.filter.goal': 'Goal',
37453748
'loopx.ledger.filter.supervised': 'Supervised',

0 commit comments

Comments
 (0)