@aragon-agent/cli 0.6.48 → 0.6.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/agent/controller.d.ts +21 -0
- package/dist/agent/controller.js +35 -8
- package/dist/agent/governance-wiring.d.ts +2 -0
- package/dist/agent/governance-wiring.js +4 -0
- package/dist/app/App.d.ts +2 -4
- package/dist/app/App.js +207 -511
- package/dist/cli.js +2 -150
- package/dist/commands/catalog.d.ts +17 -0
- package/dist/commands/catalog.js +52 -0
- package/dist/commands/create-registry.d.ts +13 -0
- package/dist/commands/create-registry.js +19 -0
- package/dist/commands/governance-command.js +5 -1
- package/dist/commands/skills.js +18 -67
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +1 -1
- package/dist/fast/review-call.d.ts +6 -0
- package/dist/fast/review-call.js +10 -0
- package/dist/governance/engine/budget.d.ts +18 -6
- package/dist/governance/engine/budget.js +61 -19
- package/dist/governance/engine/engine-core.d.ts +8 -0
- package/dist/governance/engine/engine-core.js +29 -9
- package/dist/governance/engine/engine.d.ts +1 -0
- package/dist/governance/engine/engine.js +9 -10
- package/dist/governance/engine/inspector.js +4 -3
- package/dist/governance/engine/lifecycle.js +4 -2
- package/dist/governance/engine/report.js +7 -1
- package/dist/governance/engine/run-digest.js +2 -1
- package/dist/governance/engine/stage-runner.js +1 -1
- package/dist/governance/engine/submissions.d.ts +2 -0
- package/dist/governance/engine/submissions.js +22 -3
- package/dist/governance/engine/visibility.d.ts +10 -0
- package/dist/governance/engine/visibility.js +28 -0
- package/dist/governance/rules/settlement.d.ts +7 -0
- package/dist/governance/rules/settlement.js +24 -0
- package/dist/governance/tools/shared-tools.d.ts +2 -0
- package/dist/governance/tools/shared-tools.js +15 -1
- package/dist/governance/tools/submit-tools.js +14 -7
- package/dist/host/commands.d.ts +18 -0
- package/dist/host/commands.js +30 -0
- package/dist/host/controller-factory.d.ts +109 -0
- package/dist/host/controller-factory.js +159 -0
- package/dist/host/controller-feed.d.ts +122 -0
- package/dist/host/controller-feed.js +356 -0
- package/dist/host/index-build.d.ts +23 -0
- package/dist/host/index-build.js +35 -0
- package/dist/host/index.d.ts +21 -0
- package/dist/host/index.js +21 -0
- package/dist/host/interaction.d.ts +58 -0
- package/dist/host/interaction.js +165 -0
- package/dist/host/logging.d.ts +7 -0
- package/dist/host/logging.js +7 -0
- package/dist/host/prompts.d.ts +10 -0
- package/dist/host/prompts.js +9 -0
- package/dist/host/sessions.d.ts +87 -0
- package/dist/host/sessions.js +234 -0
- package/dist/host/settings.d.ts +104 -0
- package/dist/host/settings.js +235 -0
- package/dist/host/skills.d.ts +19 -0
- package/dist/host/skills.js +38 -0
- package/dist/skills/command-names.d.ts +19 -0
- package/dist/skills/command-names.js +28 -0
- package/dist/skills/invoke.d.ts +38 -0
- package/dist/skills/invoke.js +65 -0
- package/dist/team/overseer.d.ts +25 -1
- package/dist/team/overseer.js +38 -1
- package/dist/team/runtime.d.ts +2 -0
- package/dist/team/runtime.js +10 -7
- package/dist/team/subagent.js +2 -4
- package/package.json +3 -3
package/dist/app/App.js
CHANGED
|
@@ -10,9 +10,8 @@ import { selectTranscriptEntries, mergePendingEntries } from '@aragon-agent/tui/
|
|
|
10
10
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
11
11
|
import { Text, useApp, useInput, useStdout } from 'ink';
|
|
12
12
|
import { advanceInterruptGesture, INTERRUPT_CONFIRM_MS, cancelInterruptConfirmation, } from '@aragon-agent/tui/input/interrupt-gesture';
|
|
13
|
-
import { initialViewState,
|
|
14
|
-
import {
|
|
15
|
-
import { computeCost } from '@aragon-agent/tui/model/agent/usage';
|
|
13
|
+
import { initialViewState, viewReducer, } from '@aragon-agent/tui/model/agent/reducer';
|
|
14
|
+
import { ActionCoalescer, attachAgentChannel, attachCompactionChannel, attachContextUsageChannel, attachFastChannel, attachGovernanceChannel, attachProcChannel, attachTeamChannel, attachTodosChannel, attachToolOutputChannel, attachWaitChannel, makePatchSource, } from '../host/controller-feed.js';
|
|
16
15
|
import { parseMaxTokensInput, DEFAULT_TRANSCRIPT_RETAIN, DEFAULT_TRANSCRIPT_WINDOW, } from '@aragon-agent/tui/model/config/schema';
|
|
17
16
|
import { updatePersistedConfig } from '../config/store.js';
|
|
18
17
|
import { appendPrompt, loadPromptHistory } from '../config/prompt-history.js';
|
|
@@ -62,7 +61,6 @@ import { advanceBudget, decideFollowThrough, emptyBudget, } from '@aragon-agent/
|
|
|
62
61
|
// no policy. Imported beside the todo decision it shares one timer with.
|
|
63
62
|
import { decideForcedDispatch, FORCED_NUDGE_NOTICE } from '../team/dispatch-gate.js';
|
|
64
63
|
import { FORCED_NUDGE_GRACE_MS } from '@aragon-agent/tui/model/team/limits';
|
|
65
|
-
import { priceTeamUsage } from '@aragon-agent/tui/model/team/model';
|
|
66
64
|
import { useTerminalSize } from '@aragon-agent/tui/ui/layout/useTerminalSize';
|
|
67
65
|
import { useHeightStore } from '@aragon-agent/tui/ui/use-height-store';
|
|
68
66
|
import { useRenderGovernor } from '@aragon-agent/tui/ui/use-render-governor';
|
|
@@ -92,10 +90,9 @@ import { SettingsScreen, compactionSettingsFrom, fastSettingsFrom, } from '@arag
|
|
|
92
90
|
import { ConfirmDialog } from '@aragon-agent/tui/ui/overlays/ConfirmDialog';
|
|
93
91
|
import { QuestionOverlay } from '@aragon-agent/tui/ui/overlays/QuestionOverlay';
|
|
94
92
|
import { PlanReviewOverlay } from '@aragon-agent/tui/ui/overlays/PlanReviewOverlay';
|
|
95
|
-
import {
|
|
93
|
+
import { parseSlashInput, runSlashInput, } from '../commands/registry.js';
|
|
96
94
|
import { buildInvocationCard, invocationCardsEnabled } from '@aragon-agent/tui/model/agent/invocation-card';
|
|
97
|
-
import {
|
|
98
|
-
import { makeSkillsCommand, registerSkillCommands } from '../commands/skills.js';
|
|
95
|
+
import { createCommandRegistry } from '../commands/create-registry.js';
|
|
99
96
|
import { MODE_TOGGLE_KEYS } from '@aragon-agent/tui/model/agent/agent-mode';
|
|
100
97
|
import { createClipboardCoordinator } from '@aragon-agent/tui/ui/clipboard-task';
|
|
101
98
|
import { QueuePanel } from '@aragon-agent/tui/ui/QueuePanel';
|
|
@@ -623,271 +620,213 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
623
620
|
for (const entry of [...pendingHuman.current])
|
|
624
621
|
settleHuman(entry, null);
|
|
625
622
|
}, [settleHuman]);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
r.register(makeSkillsCommand(skills, version));
|
|
634
|
-
registerSkillCommands(r, skills);
|
|
635
|
-
}
|
|
636
|
-
return r;
|
|
637
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
638
|
-
}, [controller, cfg.skills.enabled, version, skillsNonce]);
|
|
623
|
+
// The set is assembled by `createCommandRegistry`, which the desktop host shares, so the
|
|
624
|
+
// terminal's dispatcher and the desktop's `/` menu cannot drift apart.
|
|
625
|
+
const registry = useMemo(() => createCommandRegistry({
|
|
626
|
+
version, ...(cfg.skills.enabled ? { skills: controller.getSkillService() } : {}),
|
|
627
|
+
}),
|
|
628
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
629
|
+
[controller, cfg.skills.enabled, version, skillsNonce]);
|
|
639
630
|
const commandOptions = useMemo(() => registry.all().map((c) => ({ name: c.name, description: c.description })), [registry]);
|
|
640
631
|
// --- Streaming coalescer + controller subscription. --------------------
|
|
641
|
-
|
|
642
|
-
const flushTimer = useRef(null);
|
|
643
|
-
/** Alias so the subscription effect below reads one stable ref, not a hook. */
|
|
632
|
+
/** Alias so the subscription effects below read one stable ref, not a hook. */
|
|
644
633
|
const governorInterval = governor.intervalMs;
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
650
|
-
if (pending.current.length === 0)
|
|
651
|
-
return;
|
|
652
|
-
const merged = mergeDeltas(pending.current);
|
|
653
|
-
pending.current = [];
|
|
654
|
-
for (const action of merged)
|
|
655
|
-
dispatch(action);
|
|
656
|
-
}, []);
|
|
634
|
+
// READ FROM THE REF AT ARM TIME (L4): the effects' dependency lists never change by
|
|
635
|
+
// construction, so a captured number would pin the ladder to the mount render.
|
|
636
|
+
const coalescer = useMemo(() => new ActionCoalescer(dispatch, () => governorInterval.current), [governorInterval]);
|
|
637
|
+
const flushPending = useCallback(() => coalescer.flush(), [coalescer]);
|
|
657
638
|
/**
|
|
658
639
|
* The CLI-local diff side channel (§3.3.7). Memoized once, beside the `cost`
|
|
659
640
|
* lookup below, because `reduceEvent` TAKES a patch rather than reading one:
|
|
660
641
|
* the store is consume-once, so this object must not be rebuilt per event.
|
|
661
642
|
*/
|
|
662
|
-
const patchSource = useMemo(() => (
|
|
643
|
+
const patchSource = useMemo(() => makePatchSource(controller), [controller]);
|
|
663
644
|
useEffect(() => {
|
|
664
|
-
//
|
|
665
|
-
//
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
if (controller.runGeneration !== generation) {
|
|
684
|
-
// The engine is unwinding a force-stopped run. Adopt the new generation
|
|
685
|
-
// only once it has finished doing so, so a late `agent_end` cannot be
|
|
686
|
-
// mistaken for the next run's.
|
|
687
|
-
if (event.type === 'agent_end')
|
|
688
|
-
generation = controller.runGeneration;
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
metrics.current = updateRunMetrics(metrics.current, event, Date.now());
|
|
692
|
-
if (event.type === 'agent_start') {
|
|
693
|
-
interactionPhase.current = 'running';
|
|
694
|
-
manualMetrics.current = createRunMetrics();
|
|
695
|
-
// THE TWO PER-TURN COUNTERS ONLY (I-10). `nudgesRef` is deliberately
|
|
696
|
-
// absent: a nudge continuation arrives here too, and clearing it would
|
|
697
|
-
// delete the bound that keeps a disobedient model from looping.
|
|
698
|
-
toolsUsedRef.current = 0;
|
|
699
|
-
dispatchAttemptedRef.current = false;
|
|
700
|
-
}
|
|
701
|
-
if (event.type === 'agent_end') {
|
|
702
|
-
interactionPhase.current = 'idle';
|
|
703
|
-
resetInterrupt();
|
|
704
|
-
}
|
|
705
|
-
const cost = controller.getModelInfo().cost;
|
|
706
|
-
for (const action of reduceEvent(event, cost, patchSource)) {
|
|
707
|
-
// MUTATED HERE, ONE INSTANT BEFORE THE ACTION THAT SETS
|
|
708
|
-
// `ViewState.errorNoticed`, rather than read back from the reducer one
|
|
709
|
-
// commit later (C-11). This is the whole of the batching-independence
|
|
710
|
-
// guarantee: `agent_end` can follow this action in the same tick with no
|
|
711
|
-
// render in between, and AC-40 asserts exactly that sequence.
|
|
712
|
-
if (action.type === 'notice' && action.level === 'error') {
|
|
713
|
-
endReasonRef.current.errored = true;
|
|
714
|
-
}
|
|
715
|
-
// THE GATE'S TWO FACTS, counted where the reducer's own actions already
|
|
716
|
-
// flow (no second subscription to keep in step). `toolExecStart` carries
|
|
717
|
-
// the tool NAME, so a `task` call that was REFUSED - team off, dispatch
|
|
718
|
-
// busy, no key - still counts as an attempt (P1-7): the upstream already
|
|
719
|
-
// said no, and urging a re-dispatch would reproduce that refusal one
|
|
720
|
-
// turn later.
|
|
721
|
-
if (action.type === 'toolExecStart') {
|
|
722
|
-
toolsUsedRef.current += 1;
|
|
723
|
-
if (action.toolName === 'task')
|
|
724
|
-
dispatchAttemptedRef.current = true;
|
|
725
|
-
}
|
|
726
|
-
if (action.type === 'textDelta' || action.type === 'thinkingDelta') {
|
|
727
|
-
pending.current.push(action);
|
|
728
|
-
if (!flushTimer.current) {
|
|
729
|
-
// READ FROM THE REF AT ARM TIME (L4). This effect's dependency list
|
|
730
|
-
// never changes by construction, so a captured number would be
|
|
731
|
-
// pinned to the mount render and the ladder would move nothing.
|
|
732
|
-
flushTimer.current = setTimeout(() => flushPending(), governorInterval.current);
|
|
645
|
+
// THE GENERATION GUARD LIVES IN `host/controller-feed.ts::attachAgentChannel` (I-7 / P1-7);
|
|
646
|
+
// what stays here is the TUI's interaction policy, reached through three hooks.
|
|
647
|
+
const detachAgent = attachAgentChannel(controller, {
|
|
648
|
+
dispatch,
|
|
649
|
+
coalescer,
|
|
650
|
+
patchSource,
|
|
651
|
+
hooks: {
|
|
652
|
+
beforeEvent(event) {
|
|
653
|
+
metrics.current = updateRunMetrics(metrics.current, event, Date.now());
|
|
654
|
+
if (event.type === 'agent_start') {
|
|
655
|
+
interactionPhase.current = 'running';
|
|
656
|
+
manualMetrics.current = createRunMetrics();
|
|
657
|
+
// THE TWO PER-TURN COUNTERS ONLY (I-10). `nudgesRef` is deliberately
|
|
658
|
+
// absent: a nudge continuation arrives here too, and clearing it would
|
|
659
|
+
// delete the bound that keeps a disobedient model from looping.
|
|
660
|
+
toolsUsedRef.current = 0;
|
|
661
|
+
dispatchAttemptedRef.current = false;
|
|
733
662
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
// repaint cost this package refuses elsewhere, and Ink's two dedupe
|
|
799
|
-
// gates mean the alternative is not free either.
|
|
800
|
-
cancelFollowThrough(); // I-3: at most one armed continuation, ever
|
|
801
|
-
followTimer.current = setTimeout(() => {
|
|
802
|
-
followTimer.current = null;
|
|
803
|
-
// TWO RE-CHECKS AT FIRE TIME, not only at decision time. The grace
|
|
804
|
-
// window is 3 s and the user can type in it (C-6): without the first,
|
|
805
|
-
// a fired continuation would either be swallowed into
|
|
806
|
-
// `controller.steer()` (the quiet failure) or reach
|
|
807
|
-
// `controller.prompt()`, which REJECTS while running.
|
|
808
|
-
if (controller.isRunning() || controller.isCompactionBusy?.())
|
|
809
|
-
return;
|
|
810
|
-
const live = controller.getTodoSnapshot();
|
|
811
|
-
// `planIsResolved`, NOT `doneCount >= total` (todo-acceptance-criteria
|
|
812
|
-
// §6.7 / AC-20). With steps all done but criteria unchecked the old test
|
|
813
|
-
// said "no work left" and returned silently - one second after the notice
|
|
814
|
-
// promised "Continuing with 2 unchecked acceptance criteria in 3s". A
|
|
815
|
-
// promise that cancels itself is the worst failure this design has.
|
|
816
|
-
if (!live || planIsResolved(live.items, live.acceptance?.items ?? null))
|
|
817
|
-
return;
|
|
818
|
-
budgetRef.current = { ...budgetRef.current, used: budgetRef.current.used + 1 };
|
|
819
|
-
autoContinuationRef.current = true;
|
|
820
|
-
// COUNTS ONLY, NEVER ITEM TEXT (D-19), and only at the fire point —
|
|
821
|
-
// the quiet paths must stay quiet.
|
|
822
|
-
getLogger().debug('agent', 'todo_follow', {
|
|
823
|
-
used: budgetRef.current.used,
|
|
824
|
-
noProgressStreak: budgetRef.current.noProgressStreak,
|
|
825
|
-
total: live.total,
|
|
826
|
-
done: live.doneCount,
|
|
827
|
-
accTotal: live.acceptance?.total ?? 0,
|
|
828
|
-
accChecked: live.acceptance?.checkedCount ?? 0,
|
|
829
|
-
mode: 'auto',
|
|
663
|
+
if (event.type === 'agent_end') {
|
|
664
|
+
interactionPhase.current = 'idle';
|
|
665
|
+
resetInterrupt();
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
onAction(action) {
|
|
669
|
+
// MUTATED HERE, ONE INSTANT BEFORE THE ACTION THAT SETS
|
|
670
|
+
// `ViewState.errorNoticed`, rather than read back from the reducer one
|
|
671
|
+
// commit later (C-11). This is the whole of the batching-independence
|
|
672
|
+
// guarantee: `agent_end` can follow this action in the same tick with no
|
|
673
|
+
// render in between, and AC-40 asserts exactly that sequence.
|
|
674
|
+
if (action.type === 'notice' && action.level === 'error') {
|
|
675
|
+
endReasonRef.current.errored = true;
|
|
676
|
+
}
|
|
677
|
+
// THE GATE'S TWO FACTS, counted where the reducer's own actions already
|
|
678
|
+
// flow (no second subscription to keep in step). `toolExecStart` carries
|
|
679
|
+
// the tool NAME, so a `task` call that was REFUSED - team off, dispatch
|
|
680
|
+
// busy, no key - still counts as an attempt (P1-7): the upstream already
|
|
681
|
+
// said no, and urging a re-dispatch would reproduce that refusal one
|
|
682
|
+
// turn later.
|
|
683
|
+
if (action.type === 'toolExecStart') {
|
|
684
|
+
toolsUsedRef.current += 1;
|
|
685
|
+
if (action.toolName === 'task')
|
|
686
|
+
dispatchAttemptedRef.current = true;
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
afterAgentEnd() {
|
|
690
|
+
// NO OVERLAY OUTLIVES ITS RUN (P1-4). `ctx.signal` already covers the
|
|
691
|
+
// abort path, so this is DELIBERATE REDUNDANCY: it makes "the card cannot
|
|
692
|
+
// survive the run that opened it" a property of the App's lifecycle
|
|
693
|
+
// rather than a consequence of signal plumbing three modules away.
|
|
694
|
+
// Without it, an aborted run leaves a plan card on screen whose `a` key
|
|
695
|
+
// silently flips the session to build, with no visible cause.
|
|
696
|
+
cancelPendingHuman();
|
|
697
|
+
// --- Follow-through (todo-plan-followthrough §3.4). ------------------
|
|
698
|
+
//
|
|
699
|
+
// Round 1 printed one notice here and stopped, under a good argument
|
|
700
|
+
// ("auto-continuation is an unbounded cost loop wearing a helpful hat").
|
|
701
|
+
// That judgement is not overturned: the loop is BOUNDED first, by two
|
|
702
|
+
// structural counters, and only then permitted — opt-in, and off by
|
|
703
|
+
// default, so `followThrough: 'notify'` reproduces the old notice byte for
|
|
704
|
+
// byte (AC-1).
|
|
705
|
+
const todos = controller.getTodoSnapshot();
|
|
706
|
+
budgetRef.current = advanceBudget(budgetRef.current, todos, autoContinuationRef.current);
|
|
707
|
+
autoContinuationRef.current = false;
|
|
708
|
+
// --- Forced-dispatch gate (team-command-forced-dispatch §3.7). --------
|
|
709
|
+
//
|
|
710
|
+
// THE THIRD LAYER, AND THE ONLY MECHANICAL ONE: if a whole turn went by
|
|
711
|
+
// with tools used and nothing dispatched, ask ONCE for a dispatch. It is
|
|
712
|
+
// computed BEFORE the todo decision and DOWN-GRADES that decision to
|
|
713
|
+
// `none` rather than returning early (P0-3 / I-9): the two statements below
|
|
714
|
+
// - the `endReasonRef` reset and `applyPendingMode()` - belong to EVERY
|
|
715
|
+
// turn, and a `return` here would silently defer a pending `plan -> build`
|
|
716
|
+
// by a whole turn and carry `errored` into the next one. It also keeps
|
|
717
|
+
// `cancelFollowThrough()`'s callers at three: the gate reuses the timer
|
|
718
|
+
// instead of adding a fourth canceller.
|
|
719
|
+
const forced = controller.getForcedTeam();
|
|
720
|
+
const gate = decideForcedDispatch({
|
|
721
|
+
armed: forced !== null,
|
|
722
|
+
count: forced?.count ?? 0,
|
|
723
|
+
dispatchAttempted: dispatchAttemptedRef.current,
|
|
724
|
+
toolsUsed: toolsUsedRef.current,
|
|
725
|
+
nudgesUsed: nudgesRef.current,
|
|
726
|
+
runEnd: { ...endReasonRef.current },
|
|
830
727
|
});
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
if (
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
728
|
+
const gated = gate.kind === 'nudge' && forced !== null;
|
|
729
|
+
const decision = gated
|
|
730
|
+
? { kind: 'none' }
|
|
731
|
+
: decideFollowThrough({
|
|
732
|
+
mode: controller.getTodoConfig().followThrough,
|
|
733
|
+
snapshot: todos,
|
|
734
|
+
runEnd: { ...endReasonRef.current },
|
|
735
|
+
budget: budgetRef.current,
|
|
736
|
+
interactive: true,
|
|
737
|
+
});
|
|
738
|
+
endReasonRef.current = { aborted: false, errored: false };
|
|
739
|
+
if (decision.kind === 'notify') {
|
|
740
|
+
dispatch({ type: 'notice', level: decision.level, text: decision.text });
|
|
741
|
+
}
|
|
742
|
+
else if (decision.kind === 'continue') {
|
|
743
|
+
dispatch({ type: 'notice', level: 'info', text: decision.notice });
|
|
744
|
+
// NO LIVE COUNTDOWN (D-10). The notice is written once and does not
|
|
745
|
+
// tick: a 10 Hz re-render of the whole frame to animate a number is the
|
|
746
|
+
// repaint cost this package refuses elsewhere, and Ink's two dedupe
|
|
747
|
+
// gates mean the alternative is not free either.
|
|
748
|
+
cancelFollowThrough(); // I-3: at most one armed continuation, ever
|
|
749
|
+
followTimer.current = setTimeout(() => {
|
|
750
|
+
followTimer.current = null;
|
|
751
|
+
// TWO RE-CHECKS AT FIRE TIME, not only at decision time. The grace
|
|
752
|
+
// window is 3 s and the user can type in it (C-6): without the first,
|
|
753
|
+
// a fired continuation would either be swallowed into
|
|
754
|
+
// `controller.steer()` (the quiet failure) or reach
|
|
755
|
+
// `controller.prompt()`, which REJECTS while running.
|
|
756
|
+
if (controller.isRunning() || controller.isCompactionBusy?.())
|
|
757
|
+
return;
|
|
758
|
+
const live = controller.getTodoSnapshot();
|
|
759
|
+
// `planIsResolved`, NOT `doneCount >= total` (todo-acceptance-criteria
|
|
760
|
+
// §6.7 / AC-20). With steps all done but criteria unchecked the old test
|
|
761
|
+
// said "no work left" and returned silently - one second after the notice
|
|
762
|
+
// promised "Continuing with 2 unchecked acceptance criteria in 3s". A
|
|
763
|
+
// promise that cancels itself is the worst failure this design has.
|
|
764
|
+
if (!live || planIsResolved(live.items, live.acceptance?.items ?? null))
|
|
765
|
+
return;
|
|
766
|
+
budgetRef.current = { ...budgetRef.current, used: budgetRef.current.used + 1 };
|
|
767
|
+
autoContinuationRef.current = true;
|
|
768
|
+
// COUNTS ONLY, NEVER ITEM TEXT (D-19), and only at the fire point —
|
|
769
|
+
// the quiet paths must stay quiet.
|
|
770
|
+
getLogger().debug('agent', 'todo_follow', {
|
|
771
|
+
used: budgetRef.current.used,
|
|
772
|
+
noProgressStreak: budgetRef.current.noProgressStreak,
|
|
773
|
+
total: live.total,
|
|
774
|
+
done: live.doneCount,
|
|
775
|
+
accTotal: live.acceptance?.total ?? 0,
|
|
776
|
+
accChecked: live.acceptance?.checkedCount ?? 0,
|
|
777
|
+
mode: 'auto',
|
|
778
|
+
});
|
|
779
|
+
submitRef.current(decision.message, { userInitiated: false, todoPolicy: 'continue' });
|
|
780
|
+
}, decision.graceMs);
|
|
781
|
+
}
|
|
782
|
+
// THE GATE'S OWN CONTINUATION: after the todo branch (which it has
|
|
783
|
+
// already silenced) and BEFORE `applyPendingMode()`, on the SAME timer and
|
|
784
|
+
// with the same re-checks. `level: 'warn'` and not `'error'` - the error
|
|
785
|
+
// level sets `endReasonRef.errored`, which would make the next turn's gate
|
|
786
|
+
// read "the run failed" and switch itself off for the rest of the session.
|
|
787
|
+
if (gated && gate.kind === 'nudge') {
|
|
788
|
+
nudgesRef.current += 1;
|
|
789
|
+
dispatch({ type: 'notice', level: 'warn', text: FORCED_NUDGE_NOTICE });
|
|
790
|
+
cancelFollowThrough(); // I-9 / I-3: at most one armed continuation, ever
|
|
791
|
+
followTimer.current = setTimeout(() => {
|
|
792
|
+
followTimer.current = null;
|
|
793
|
+
if (controller.isRunning() || controller.isCompactionBusy?.())
|
|
794
|
+
return;
|
|
795
|
+
submitRef.current(gate.message, { userInitiated: false, todoPolicy: 'continue' });
|
|
796
|
+
}, FORCED_NUDGE_GRACE_MS);
|
|
797
|
+
}
|
|
798
|
+
// A deferred `plan -> build` (or any posture change that waited for a governed
|
|
799
|
+
// stage, governance-mode D-23) becomes real here and nowhere else (§3.2).
|
|
800
|
+
const applied = controller.applyPendingPosture();
|
|
801
|
+
if (applied) {
|
|
802
|
+
const split = splitPosture(applied.effective);
|
|
803
|
+
dispatch({
|
|
804
|
+
type: 'setAgentMode',
|
|
805
|
+
mode: split.mode,
|
|
806
|
+
pending: null,
|
|
807
|
+
posture: applied.effective,
|
|
808
|
+
pendingPosture: applied.pending,
|
|
809
|
+
});
|
|
810
|
+
dispatch({
|
|
811
|
+
type: 'pushToast',
|
|
812
|
+
level: 'info',
|
|
813
|
+
text: postureAppliedToast(applied.effective),
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
},
|
|
868
818
|
});
|
|
869
819
|
return () => {
|
|
870
|
-
flushPending();
|
|
871
820
|
// An armed continuation must not outlive the tree that armed it (AC-21):
|
|
872
821
|
// the timer would fire into an unmounted App and `submitRef.current` would
|
|
873
822
|
// prompt a controller nobody is rendering.
|
|
874
823
|
cancelFollowThrough();
|
|
875
|
-
|
|
824
|
+
detachAgent();
|
|
876
825
|
};
|
|
877
|
-
}, [controller, patchSource,
|
|
826
|
+
}, [controller, patchSource, coalescer, cancelPendingHuman, cancelFollowThrough, resetInterrupt]);
|
|
878
827
|
useEffect(() => {
|
|
879
|
-
return controller
|
|
880
|
-
const service = event.service;
|
|
828
|
+
return attachProcChannel(controller, dispatch, (service) => {
|
|
881
829
|
setServices((prev) => ({ ...prev, [service.id]: service }));
|
|
882
|
-
if (event.type === 'started') {
|
|
883
|
-
dispatch({ type: 'serviceStart', service });
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
if (event.type === 'exited' || event.type === 'stopped') {
|
|
887
|
-
dispatch({ type: 'serviceEnd', service });
|
|
888
|
-
return;
|
|
889
|
-
}
|
|
890
|
-
dispatch({ type: 'serviceUpdate', service });
|
|
891
830
|
});
|
|
892
831
|
}, [controller]);
|
|
893
832
|
// --- Team-mode event stream (team-subagents §5.2 / §3.9). --------------
|
|
@@ -901,94 +840,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
901
840
|
// the source at 120 ms per child (§5.2), and pushing it through a second
|
|
902
841
|
// buffer would only delay the roster.
|
|
903
842
|
useEffect(() => {
|
|
904
|
-
const unsubscribeTeam = controller
|
|
905
|
-
switch (event.type) {
|
|
906
|
-
case 'dispatch_start':
|
|
907
|
-
dispatch({
|
|
908
|
-
type: 'teamStart',
|
|
909
|
-
dispatchId: event.dispatchId,
|
|
910
|
-
requested: event.requested,
|
|
911
|
-
specs: event.specs,
|
|
912
|
-
});
|
|
913
|
-
break;
|
|
914
|
-
case 'agent_update': {
|
|
915
|
-
const snapshot = controller.getTeamSnapshot();
|
|
916
|
-
if (snapshot)
|
|
917
|
-
dispatch({ type: 'teamUpdate', snapshot });
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
case 'message': {
|
|
921
|
-
const snapshot = controller.getTeamSnapshot();
|
|
922
|
-
if (snapshot)
|
|
923
|
-
dispatch({ type: 'teamUpdate', snapshot });
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
926
|
-
case 'overseer': {
|
|
927
|
-
// A supervisor decision was applied (team-overseer). The roster
|
|
928
|
-
// already refreshed through the agent_update the runtime publishes
|
|
929
|
-
// with it; re-read the snapshot so the panel cannot miss the row.
|
|
930
|
-
const snap = controller.getTeamSnapshot();
|
|
931
|
-
if (snap)
|
|
932
|
-
dispatch({ type: 'teamUpdate', snapshot: snap });
|
|
933
|
-
// G-4 / AC-5 (subagent-overseer-v2): a TERMINAL verdict is the
|
|
934
|
-
// one decision the user must not discover from the final report
|
|
935
|
-
// - it removes work they watched running. wait and nudge stay
|
|
936
|
-
// panel-only so the transcript gains no per-tick noise.
|
|
937
|
-
if (event.decision.action === 'replace' || event.decision.action === 'abandon') {
|
|
938
|
-
const verb = event.decision.action === 'replace' ? 'replaced' : 'abandoned';
|
|
939
|
-
const level = event.decision.action === 'replace' ? 'info' : 'warn';
|
|
940
|
-
const reason = event.decision.reason.slice(0, 120);
|
|
941
|
-
dispatch({
|
|
942
|
-
type: 'notice',
|
|
943
|
-
level,
|
|
944
|
-
text: `team supervisor ${verb} ${event.label} - ${reason}`,
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
case 'usage': {
|
|
950
|
-
// Child spend is REAL SPEND and must reach the status bar, or the
|
|
951
|
-
// session cost readout under-reports by however much the team consumed
|
|
952
|
-
// — the single most misleading possible failure of this feature (R-5).
|
|
953
|
-
//
|
|
954
|
-
// THE COST TABLE IS SELECTED BY TIER (fast-model-tier §3.6 / R-7).
|
|
955
|
-
// Always using the lead's would over-report a Haiku child under a
|
|
956
|
-
// Sonnet lead by roughly an order of magnitude, which is a different
|
|
957
|
-
// way of being wrong about the same number.
|
|
958
|
-
// FROM THE CONTROLLER, NOT FROM `cfg` (the rule the `agent_end`
|
|
959
|
-
// handler above records): this effect's dependency list never changes,
|
|
960
|
-
// so it closes over the `cfg` object of the render it mounted in, and
|
|
961
|
-
// `setModel` builds a NEW one.
|
|
962
|
-
//
|
|
963
|
-
// PRICED AT THE MODEL THE CHILDREN RAN (`team.model`), through the same
|
|
964
|
-
// resolution the dispatch report prices with: under `fast` / `profile` the
|
|
965
|
-
// lead's table would over-report by up to an order of magnitude, and an
|
|
966
|
-
// unpriced child model must read as unknown (ZERO here), not as the lead's.
|
|
967
|
-
const costDelta = priceTeamUsage(controller.subagentModelResolution(), event.usage, {
|
|
968
|
-
mainCost: controller.getModelInfo().cost,
|
|
969
|
-
isPriced: (ref) => controller.isPricedModel(ref),
|
|
970
|
-
costFor: (ref) => controller.getModelInfoFor(ref).cost,
|
|
971
|
-
});
|
|
972
|
-
dispatch({ type: 'teamUsage', usage: event.usage, costDelta });
|
|
973
|
-
break;
|
|
974
|
-
}
|
|
975
|
-
case 'dispatch_end': {
|
|
976
|
-
// The supervisor's own calls never emit a usage event (they go through the fast
|
|
977
|
-
// registry directly), so their spend reaches the readout HERE, once per
|
|
978
|
-
// dispatch, at the fast tier's price - the same channel review spend uses.
|
|
979
|
-
const spend = event.outcome.overseerUsage;
|
|
980
|
-
if (spend !== undefined && (spend.inputTokens > 0 || spend.outputTokens > 0)) {
|
|
981
|
-
const tier = controller.getFastStatus().tier;
|
|
982
|
-
const costDelta = tier.ok && controller.isPricedModel(tier.ref)
|
|
983
|
-
? computeCost(spend, controller.getModelInfoFor(tier.ref).cost)
|
|
984
|
-
: 0;
|
|
985
|
-
dispatch({ type: 'fastUsage', usage: spend, costDelta });
|
|
986
|
-
}
|
|
987
|
-
dispatch({ type: 'teamEnd', outcome: event.outcome });
|
|
988
|
-
break;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
});
|
|
843
|
+
const unsubscribeTeam = attachTeamChannel(controller, dispatch);
|
|
992
844
|
return () => {
|
|
993
845
|
unsubscribeTeam();
|
|
994
846
|
controller.dispose();
|
|
@@ -1001,18 +853,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1001
853
|
// chatty updates; this effect only folds snapshots into the view, appends the four kinds
|
|
1002
854
|
// of settlement card (charter, phase, escalation, final) and clears the live snapshot when
|
|
1003
855
|
// the run ends. A no-op unsubscribe when governance was not registered.
|
|
1004
|
-
useEffect(() =>
|
|
1005
|
-
return controller.subscribeGovernance((event) => {
|
|
1006
|
-
dispatch({ type: 'govSnapshot', snapshot: event.snapshot });
|
|
1007
|
-
const card = event.type === 'run_started' || event.type === 'stage_ended' ? event.card
|
|
1008
|
-
: event.type === 'escalation' || event.type === 'run_closed' ? event.card
|
|
1009
|
-
: null;
|
|
1010
|
-
if (card)
|
|
1011
|
-
dispatch({ type: 'governanceCard', card });
|
|
1012
|
-
if (event.type === 'run_closed')
|
|
1013
|
-
dispatch({ type: 'govEnd' });
|
|
1014
|
-
});
|
|
1015
|
-
}, [controller]);
|
|
856
|
+
useEffect(() => attachGovernanceChannel(controller, dispatch), [controller]);
|
|
1016
857
|
// --- Todo event stream (todo-plan-execution §3.8 / §5.2). --------------
|
|
1017
858
|
//
|
|
1018
859
|
// A THIRD SUBSCRIPTION, for the reason the team one records: `TodoEvent` is
|
|
@@ -1023,24 +864,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1023
864
|
// merge text/thinking deltas; a `todo_write` is one deliberate act per step,
|
|
1024
865
|
// and delaying the one surface the user is watching a long task through would
|
|
1025
866
|
// be exactly backwards.
|
|
1026
|
-
useEffect(() =>
|
|
1027
|
-
return controller.subscribeTodos((event) => {
|
|
1028
|
-
switch (event.type) {
|
|
1029
|
-
case 'updated':
|
|
1030
|
-
dispatch({ type: 'todoUpdate', snapshot: event.snapshot });
|
|
1031
|
-
break;
|
|
1032
|
-
case 'cleared':
|
|
1033
|
-
dispatch({ type: 'todoCleared' });
|
|
1034
|
-
break;
|
|
1035
|
-
case 'rejected':
|
|
1036
|
-
// THE COMPENSATING PATH FOR SUPPRESSING THE TOOL CARD (§3.8). Without
|
|
1037
|
-
// it, the one case where `todo_write` produces nothing visible would
|
|
1038
|
-
// be the case that most needs to be visible.
|
|
1039
|
-
dispatch({ type: 'notice', level: 'warn', text: event.reason });
|
|
1040
|
-
break;
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1043
|
-
}, [controller]);
|
|
867
|
+
useEffect(() => attachTodosChannel(controller, dispatch), [controller]);
|
|
1044
868
|
// --- Fast-tier event stream (fast-model-tier §5.3). --------------------
|
|
1045
869
|
//
|
|
1046
870
|
// A FOURTH SUBSCRIPTION, for the reason the team and todo ones record:
|
|
@@ -1050,43 +874,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1050
874
|
// `subscribeFast` returns a no-op unsubscribe when the tier was off at
|
|
1051
875
|
// construction, so this can subscribe unconditionally and an ordinary session
|
|
1052
876
|
// pays one closure for the whole run.
|
|
1053
|
-
useEffect(() =>
|
|
1054
|
-
// Seed the chip from the tier resolved at construction, so a fast-enabled
|
|
1055
|
-
// session shows it on the first frame rather than after the first review.
|
|
1056
|
-
const initial = controller.getFastStatus();
|
|
1057
|
-
if (initial.registered)
|
|
1058
|
-
dispatch({ type: 'fastTier', snapshot: initial.snapshot });
|
|
1059
|
-
return controller.subscribeFast((event) => {
|
|
1060
|
-
switch (event.type) {
|
|
1061
|
-
case 'review_start':
|
|
1062
|
-
dispatch({
|
|
1063
|
-
type: 'fastStart',
|
|
1064
|
-
index: event.index,
|
|
1065
|
-
turn: event.turn,
|
|
1066
|
-
model: controller.getFastStatus().snapshot.model,
|
|
1067
|
-
});
|
|
1068
|
-
break;
|
|
1069
|
-
case 'review_end':
|
|
1070
|
-
dispatch({ type: 'fastEnd', review: event.review });
|
|
1071
|
-
// The card settled, so the chip's `inFlight` and the session totals
|
|
1072
|
-
// both moved. One dispatch rather than two: `fastTier` carries them.
|
|
1073
|
-
dispatch({ type: 'fastTier', snapshot: controller.getFastStatus().snapshot });
|
|
1074
|
-
break;
|
|
1075
|
-
case 'usage': {
|
|
1076
|
-
// Review spend is REAL SPEND at the FAST model's price (§3.6 / AC-18).
|
|
1077
|
-
const ref = controller.getFastStatus().tier;
|
|
1078
|
-
const costDelta = ref.ok && controller.isPricedModel(ref.ref)
|
|
1079
|
-
? computeCost(event.usage, controller.getModelInfoFor(ref.ref).cost)
|
|
1080
|
-
: 0;
|
|
1081
|
-
dispatch({ type: 'fastUsage', usage: event.usage, costDelta });
|
|
1082
|
-
break;
|
|
1083
|
-
}
|
|
1084
|
-
case 'tier_changed':
|
|
1085
|
-
dispatch({ type: 'fastTier', snapshot: event.snapshot });
|
|
1086
|
-
break;
|
|
1087
|
-
}
|
|
1088
|
-
});
|
|
1089
|
-
}, [controller]);
|
|
877
|
+
useEffect(() => attachFastChannel(controller, dispatch), [controller]);
|
|
1090
878
|
// --- Context occupancy (context-usage-gauge-accuracy §3.3 / I-1). --------
|
|
1091
879
|
//
|
|
1092
880
|
// A SEVENTH SUBSCRIPTION, AND THE SOLE DISPATCHER OF `contextUsage`. The gauge
|
|
@@ -1099,15 +887,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1099
887
|
// forwarder - the meter exists in every session, including one started with
|
|
1100
888
|
// `--no-compaction`, which is precisely the session whose gauge previously had
|
|
1101
889
|
// one sample per turn and read 0 % after a `/resume`.
|
|
1102
|
-
useEffect(() =>
|
|
1103
|
-
// SEED ON MOUNT so a resumed session shows a real occupancy on frame 1
|
|
1104
|
-
// rather than after its first completed turn. `getContextUsage()` measures
|
|
1105
|
-
// on demand, so this works before any event has ever arrived.
|
|
1106
|
-
dispatch({ type: 'contextUsage', snapshot: controller.getContextUsage() });
|
|
1107
|
-
return controller.subscribeContextUsage((snapshot) => {
|
|
1108
|
-
dispatch({ type: 'contextUsage', snapshot });
|
|
1109
|
-
});
|
|
1110
|
-
}, [controller]);
|
|
890
|
+
useEffect(() => attachContextUsageChannel(controller, dispatch), [controller]);
|
|
1111
891
|
// --- Compaction event stream (context-auto-compaction §5.2). -------------
|
|
1112
892
|
//
|
|
1113
893
|
// A SIXTH SUBSCRIPTION, for the reason the team, todo and fast ones record:
|
|
@@ -1127,74 +907,16 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1127
907
|
// `subscribeCompaction` returns a no-op unsubscribe when compaction was off at
|
|
1128
908
|
// construction, so this can subscribe unconditionally and an ordinary session
|
|
1129
909
|
// pays one closure for the whole run.
|
|
1130
|
-
useEffect(() => {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
if (controller.isCompactionRegistered()) {
|
|
1135
|
-
dispatch({ type: 'compactionSnapshot', snapshot: controller.getCompactionSnapshot() });
|
|
1136
|
-
}
|
|
1137
|
-
return controller.subscribeCompaction((event) => {
|
|
1138
|
-
switch (event.type) {
|
|
1139
|
-
case 'compaction_start':
|
|
1140
|
-
if (interactionPhase.current === 'idle') {
|
|
1141
|
-
manualMetrics.current = updateRunMetrics(createRunMetrics(), { type: 'agent_start' }, Date.now());
|
|
1142
|
-
}
|
|
1143
|
-
dispatch({
|
|
1144
|
-
type: 'compactionStart',
|
|
1145
|
-
index: event.index,
|
|
1146
|
-
trigger: event.trigger,
|
|
1147
|
-
model: event.model,
|
|
1148
|
-
});
|
|
1149
|
-
break;
|
|
1150
|
-
case 'compaction_end':
|
|
1151
|
-
manualMetrics.current = freezeRunMetrics(manualMetrics.current, Date.now());
|
|
1152
|
-
// THE CARD, AND NOTHING ELSE (context-usage-gauge-accuracy §3.3).
|
|
1153
|
-
//
|
|
1154
|
-
// A `contextTokensEstimated` dispatch used to live here, hand-building
|
|
1155
|
-
// the post-compaction occupancy out of `record.tokensAfter` plus the
|
|
1156
|
-
// snapshot's `estimateOffset`. It is gone because the gauge now has ONE
|
|
1157
|
-
// writer: `ContextMeter` learns about the splice from
|
|
1158
|
-
// `CompactionWiring.settlePending` itself and re-measures, so the bar
|
|
1159
|
-
// falls in the same frame WITHOUT this branch and without the `snapshot`
|
|
1160
|
-
// branch below racing it. Those two dispatches were the second and
|
|
1161
|
-
// third writers of one number, and the loser of that race was the
|
|
1162
|
-
// correct value (P0-1).
|
|
1163
|
-
dispatch({ type: 'compactionEnd', record: event.record });
|
|
1164
|
-
break;
|
|
1165
|
-
case 'phase':
|
|
1166
|
-
// THE STAGE LINE ON THE LIVE CARD (context-compaction-never-fires C).
|
|
1167
|
-
// Dispatch is unconditional; the reducer is what ignores a phase that
|
|
1168
|
-
// arrives for a card the settle has already closed.
|
|
1169
|
-
dispatch({ type: 'compactionPhase', index: event.index, phase: event.phase });
|
|
1170
|
-
break;
|
|
1171
|
-
case 'usage': {
|
|
1172
|
-
// Compaction spend is REAL SPEND at the SUMMARIZER's price (§6.4 /
|
|
1173
|
-
// AC-15), which may be neither the lead's nor the fast tier's — so the
|
|
1174
|
-
// ref is ASKED FOR rather than assumed. `getModelInfo()` here would
|
|
1175
|
-
// price a Haiku summarization at the lead's Opus rates, which is the
|
|
1176
|
-
// same class of lie as the `$0.00` `pricingUnknown` exists to prevent,
|
|
1177
|
-
// just in the other direction.
|
|
1178
|
-
const snapshot = controller.getCompactionSnapshot();
|
|
1179
|
-
const ref = event.modelRef ?? controller.getCompactionSummarizerRef();
|
|
1180
|
-
const costDelta = (event.pricingUnknown ?? snapshot.pricingUnknown)
|
|
1181
|
-
? 0
|
|
1182
|
-
: event.costUsd ?? (ref
|
|
1183
|
-
? computeCost(event.usage, controller.getModelInfoFor(ref).cost) : 0);
|
|
1184
|
-
dispatch({ type: 'compactionUsage', usage: event.usage, costDelta });
|
|
1185
|
-
break;
|
|
1186
|
-
}
|
|
1187
|
-
case 'snapshot':
|
|
1188
|
-
// THE CHIP, THE COUNTS AND THE SUMMARIZER (§3.3). The occupancy that
|
|
1189
|
-
// rides along on `snapshot.pressure` is deliberately NOT dispatched
|
|
1190
|
-
// here: the meter that produced it publishes it on its own channel, and
|
|
1191
|
-
// a second dispatch of the same number is the second writer this
|
|
1192
|
-
// feature removed.
|
|
1193
|
-
dispatch({ type: 'compactionSnapshot', snapshot: event.snapshot });
|
|
1194
|
-
break;
|
|
910
|
+
useEffect(() => attachCompactionChannel(controller, dispatch, {
|
|
911
|
+
onStart: () => {
|
|
912
|
+
if (interactionPhase.current === 'idle') {
|
|
913
|
+
manualMetrics.current = updateRunMetrics(createRunMetrics(), { type: 'agent_start' }, Date.now());
|
|
1195
914
|
}
|
|
1196
|
-
}
|
|
1197
|
-
|
|
915
|
+
},
|
|
916
|
+
onEnd: () => {
|
|
917
|
+
manualMetrics.current = freezeRunMetrics(manualMetrics.current, Date.now());
|
|
918
|
+
},
|
|
919
|
+
}), [controller]);
|
|
1198
920
|
// --- Live tool output (agent-activity-presentation-live §3.3.2). --------
|
|
1199
921
|
//
|
|
1200
922
|
// A FIFTH SUBSCRIPTION, and THE ONE THAT DOES GO THROUGH THE STREAMING
|
|
@@ -1214,18 +936,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1214
936
|
//
|
|
1215
937
|
// `Date.now()` IS READ HERE, in the listener, not in the reducer, which is
|
|
1216
938
|
// what keeps `viewReducer` pure.
|
|
1217
|
-
useEffect(() =>
|
|
1218
|
-
return controller.subscribeToolOutput(({ toolCallId, rows }) => {
|
|
1219
|
-
pending.current.push({ type: 'toolOutputDelta', toolCallId, rows, at: Date.now() });
|
|
1220
|
-
if (!flushTimer.current) {
|
|
1221
|
-
// READ FROM THE REF AT ARM TIME, for the reason `App.tsx:439-441`
|
|
1222
|
-
// records: this effect's dependency list never changes, so a captured
|
|
1223
|
-
// number would be pinned to the mount render and the governor's ladder
|
|
1224
|
-
// would move nothing.
|
|
1225
|
-
flushTimer.current = setTimeout(() => flushPending(), governorInterval.current);
|
|
1226
|
-
}
|
|
1227
|
-
});
|
|
1228
|
-
}, [controller, flushPending, governorInterval]);
|
|
939
|
+
useEffect(() => attachToolOutputChannel(controller, coalescer), [controller, coalescer]);
|
|
1229
940
|
// --- The long wait's live view (extended-job-wait §3.8.1). --------------
|
|
1230
941
|
//
|
|
1231
942
|
// THROUGH THE COALESCER, like the tool tail above and for the same reason: a
|
|
@@ -1234,22 +945,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1234
945
|
// RUNNING matching entry); `end` needs no action of its own - `toolExecEnd` and
|
|
1235
946
|
// every idle path clear the view (I-5 / RV-2), and a second clear here would be
|
|
1236
947
|
// a third copy of that rule.
|
|
1237
|
-
useEffect(() =>
|
|
1238
|
-
// OPTIONAL CALL: a duck-typed controller (a test double, a headless shim) predates
|
|
1239
|
-
// this channel and has nothing to subscribe to - exactly as `subscribeTeam?` is.
|
|
1240
|
-
return controller.subscribeWait?.((event) => {
|
|
1241
|
-
if (event.type === 'end')
|
|
1242
|
-
return;
|
|
1243
|
-
pending.current.push({
|
|
1244
|
-
type: 'waitUpdate',
|
|
1245
|
-
toolCallId: event.toolCallId,
|
|
1246
|
-
view: event.view,
|
|
1247
|
-
});
|
|
1248
|
-
if (!flushTimer.current) {
|
|
1249
|
-
flushTimer.current = setTimeout(() => flushPending(), governorInterval.current);
|
|
1250
|
-
}
|
|
1251
|
-
});
|
|
1252
|
-
}, [controller, flushPending, governorInterval]);
|
|
948
|
+
useEffect(() => attachWaitChannel(controller, coalescer), [controller, coalescer]);
|
|
1253
949
|
// Event boundaries own start/end; ticks only refresh the live projection.
|
|
1254
950
|
useEffect(() => {
|
|
1255
951
|
if (state.status !== 'running')
|