@aragon-agent/cli 0.6.62 → 0.6.64
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 +70 -2
- package/README.md +143 -27
- package/dist/agent/controller.d.ts +66 -14
- package/dist/agent/controller.js +291 -81
- package/dist/agent/headless.d.ts +16 -0
- package/dist/agent/headless.js +62 -3
- package/dist/agent/team-notices.d.ts +57 -7
- package/dist/agent/team-notices.js +93 -10
- package/dist/app/App.js +199 -77
- package/dist/cli.js +4 -1
- package/dist/commands/builtins.js +2 -1
- package/dist/commands/catalog.js +1 -1
- package/dist/compaction/archive.d.ts +27 -1
- package/dist/compaction/archive.js +8 -0
- package/dist/compaction/budget.d.ts +73 -0
- package/dist/compaction/budget.js +89 -0
- package/dist/compaction/child.js +6 -1
- package/dist/compaction/command.js +147 -1
- package/dist/compaction/compactor.d.ts +132 -15
- package/dist/compaction/compactor.js +288 -95
- package/dist/compaction/context-command.js +21 -0
- package/dist/compaction/memory-agent-prompt.d.ts +32 -0
- package/dist/compaction/memory-agent-prompt.js +76 -0
- package/dist/compaction/memory-agent-tools.d.ts +88 -0
- package/dist/compaction/memory-agent-tools.js +338 -0
- package/dist/compaction/memory-agent.d.ts +114 -0
- package/dist/compaction/memory-agent.js +220 -0
- package/dist/compaction/prune.d.ts +129 -0
- package/dist/compaction/prune.js +386 -0
- package/dist/compaction/retry-plan.d.ts +103 -0
- package/dist/compaction/retry-plan.js +136 -0
- package/dist/compaction/summarize-ladder.d.ts +149 -0
- package/dist/compaction/summarize-ladder.js +273 -0
- package/dist/compaction/wiring.d.ts +19 -0
- package/dist/compaction/wiring.js +65 -1
- package/dist/config/cli-commands.d.ts +2 -2
- package/dist/config/cli-commands.js +27 -0
- package/dist/config/env.d.ts +3 -1
- package/dist/config/env.js +44 -2
- package/dist/exec/events.d.ts +30 -0
- package/dist/exec/index.js +2 -0
- package/dist/exec/runner.js +16 -1
- package/dist/gene/commit-prepare.js +27 -1
- package/dist/gene/curator/curator.d.ts +15 -0
- package/dist/gene/curator/curator.js +26 -2
- package/dist/gene/curator/scripted-lane.d.ts +12 -0
- package/dist/gene/curator/scripted-lane.js +101 -0
- package/dist/gene/curator/task-context.d.ts +21 -0
- package/dist/gene/curator/task-context.js +33 -0
- package/dist/gene/curator/task-runner.d.ts +10 -1
- package/dist/gene/curator/task-runner.js +39 -4
- package/dist/gene/curator/tool-support.js +11 -4
- package/dist/gene/curator/toolkit.d.ts +13 -0
- package/dist/gene/curator/toolkit.js +23 -1
- package/dist/gene/curator/tools-verify.js +2 -2
- package/dist/gene/curator/tools-write.js +6 -1
- package/dist/gene/curator/validate/evidence-tokens.js +133 -22
- package/dist/gene/curator/validate/knowledge.d.ts +41 -1
- package/dist/gene/curator/validate/knowledge.js +74 -11
- package/dist/gene/curator/validate/prompts.d.ts +10 -2
- package/dist/gene/curator/validate/prompts.js +2 -2
- package/dist/gene/learn/draft-guard.d.ts +17 -0
- package/dist/gene/learn/draft-guard.js +113 -0
- package/dist/gene/learn/learn-prompt.d.ts +22 -1
- package/dist/gene/learn/learn-prompt.js +27 -2
- package/dist/gene/learn/learner.js +20 -2
- package/dist/gene/queue.d.ts +16 -0
- package/dist/gene/queue.js +44 -1
- package/dist/governance/store/run-store.d.ts +20 -0
- package/dist/governance/store/run-store.js +54 -8
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/host/interaction.d.ts +8 -17
- package/dist/host/interaction.js +50 -72
- package/dist/host/team-wake-driver.d.ts +90 -0
- package/dist/host/team-wake-driver.js +114 -0
- package/dist/logging/install.d.ts +59 -1
- package/dist/logging/install.js +15 -0
- package/dist/session/validate-session.js +11 -0
- package/dist/team/console-tools.d.ts +12 -0
- package/dist/team/console-tools.js +20 -3
- package/dist/team/console-view.js +11 -1
- package/dist/team/notices.d.ts +81 -4
- package/dist/team/notices.js +187 -22
- package/dist/team/prompt.js +1 -1
- package/dist/team/runtime.d.ts +67 -24
- package/dist/team/runtime.js +250 -31
- package/dist/team/stall-watch.d.ts +54 -0
- package/dist/team/stall-watch.js +119 -0
- package/dist/team/task-tool.js +2 -2
- package/dist/team/wake.d.ts +176 -0
- package/dist/team/wake.js +444 -0
- package/package.json +81 -81
package/dist/app/App.js
CHANGED
|
@@ -14,7 +14,7 @@ import { Text, useApp, useInput, useStdout } from 'ink';
|
|
|
14
14
|
import { advanceInterruptGesture, INTERRUPT_CONFIRM_MS, cancelInterruptConfirmation, } from '@aragon-agent/tui/input/interrupt-gesture';
|
|
15
15
|
import { initialViewState, viewReducer, } from '@aragon-agent/tui/model/agent/reducer';
|
|
16
16
|
import { ActionCoalescer, attachAgentChannel, attachCompactionChannel, attachContextUsageChannel, attachFastChannel, attachGovernanceChannel, attachProcChannel, attachTeamChannel, attachTodosChannel, attachToolOutputChannel, attachWaitChannel, makePatchSource, } from '../host/controller-feed.js';
|
|
17
|
-
import { parseMaxTokensInput, DEFAULT_TRANSCRIPT_RETAIN, DEFAULT_TRANSCRIPT_WINDOW, } from '@aragon-agent/tui/model/config/schema';
|
|
17
|
+
import { parseMaxTokensInput, toRunResumePolicy, DEFAULT_TRANSCRIPT_RETAIN, DEFAULT_TRANSCRIPT_WINDOW, } from '@aragon-agent/tui/model/config/schema';
|
|
18
18
|
import { updatePersistedConfig } from '../config/store.js';
|
|
19
19
|
import { appendPrompt, loadPromptHistory } from '../config/prompt-history.js';
|
|
20
20
|
import { bumpSubmitCount, getGovernanceIntroSeen, setGovernanceIntroSeen, setMouseNoticeVersion, setPromptKeyNoticeVersion, setScrollModeNoticeVersion, setVtInputNoticeVersion, } from '../config/ui-state.js';
|
|
@@ -58,7 +58,7 @@ import { ScrollViewport } from '@aragon-agent/tui/ui/layout/ScrollViewport';
|
|
|
58
58
|
import { acceptanceChip, acceptanceRung, buildTodoRailLayout } from '@aragon-agent/tui/ui/layout/todo-layout';
|
|
59
59
|
import { buildTeamPanelLayout } from '@aragon-agent/tui/ui/layout/team-panel';
|
|
60
60
|
import { isLiveTeamCard, lastTeamEntry, rosterCounts } from '@aragon-agent/tui/ui/team-status';
|
|
61
|
-
import { advanceBudget, decideFollowThrough, emptyBudget, isTransientRunEnd, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
61
|
+
import { advanceBudget, chargeResume, decideFollowThrough, emptyBudget, emptyResumeCounters, isTransientRunEnd, settleResumeCounters, } from '@aragon-agent/tui/model/todo/follow-through';
|
|
62
62
|
// THE THIRD LAYER OF FORCED TEAM MODE (team-command-forced-dispatch §3.7): the
|
|
63
63
|
// decision and its two strings live in a pure module, so `App` gains wiring and
|
|
64
64
|
// no policy. Imported beside the todo decision it shares one timer with.
|
|
@@ -70,7 +70,7 @@ import { redTeamToastTtlMs, useRedTeamMode, } from './use-redteam-mode.js';
|
|
|
70
70
|
import { RedTeamDisclaimerOverlay } from '@aragon-agent/tui/ui/overlays/RedTeamDisclaimerOverlay';
|
|
71
71
|
import { teamStatusFromView } from '@aragon-agent/tui/model/team/team-mode';
|
|
72
72
|
import { FORCED_NUDGE_GRACE_MS } from '@aragon-agent/tui/model/team/limits';
|
|
73
|
-
import {
|
|
73
|
+
import { TeamWakeDriver } from '../host/team-wake-driver.js';
|
|
74
74
|
import { formatDuration } from '@aragon-agent/tui/model/agent/usage';
|
|
75
75
|
import { useTerminalSize } from '@aragon-agent/tui/ui/layout/useTerminalSize';
|
|
76
76
|
import { useHeightStore } from '@aragon-agent/tui/ui/use-height-store';
|
|
@@ -546,7 +546,28 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
546
546
|
*/
|
|
547
547
|
const updateToastPushed = useRef(false);
|
|
548
548
|
const budgetRef = useRef(emptyBudget());
|
|
549
|
+
/**
|
|
550
|
+
* The two counters bounding a re-run of an engine-interrupted run
|
|
551
|
+
* (`team-idle-watchdog-dead-run` F3). A REF OF ITS OWN, NOT A FIELD OF
|
|
552
|
+
* `budgetRef`: that budget belongs to a PLAN LINEAGE and `advanceBudget` zeroes
|
|
553
|
+
* it the moment the plan is gone, whereas a stalled link has nothing to do with
|
|
554
|
+
* any plan - sharing it would hand the user a fresh allowance every time the
|
|
555
|
+
* model finished a todo list.
|
|
556
|
+
*
|
|
557
|
+
* `consecutive` is cleared by any run that ends without an error
|
|
558
|
+
* (`afterAgentEnd`); `total` ONLY by the user typing (`submitMessage`). It is
|
|
559
|
+
* deliberately NOT touched by `agent_start`: a recovery IS a new run, and
|
|
560
|
+
* clearing there would reset both counters on every recovery and make the bound
|
|
561
|
+
* unreachable.
|
|
562
|
+
*/
|
|
563
|
+
const resumeRef = useRef(emptyResumeCounters());
|
|
549
564
|
const followTimer = useRef(null);
|
|
565
|
+
/**
|
|
566
|
+
* The team wake driver (team-lead-wake-signals 4.10), mounted in an effect below. A
|
|
567
|
+
* ref because `cancelFollowThrough` - the one place every "the user did something"
|
|
568
|
+
* path already passes through - has to reach it without being re-created.
|
|
569
|
+
*/
|
|
570
|
+
const teamWakeRef = useRef(null);
|
|
550
571
|
/**
|
|
551
572
|
* The forced-dispatch gate's three counters (team-command-forced-dispatch
|
|
552
573
|
* §3.7). REFS, for the reason the follow-through block above records: every
|
|
@@ -739,79 +760,116 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
739
760
|
*
|
|
740
761
|
* ONE SLOT: `Esc`, `submitMessage`, the reset/restore port, the effect cleanup
|
|
741
762
|
* and both follow-through arms (todo, then the gate) all cancel before arming.
|
|
763
|
+
*
|
|
764
|
+
* THE TEAM WAKE COUNTDOWN SITS IN THAT SAME SLOT (team-lead-wake-signals I-WK9), so
|
|
765
|
+
* cancelling it is the same act: the driver is told after the timer is cleared, and
|
|
766
|
+
* it only reacts when it actually holds a countdown (its own submit passes through
|
|
767
|
+
* `submitMessage` -> here and must find nothing to cancel).
|
|
742
768
|
*/
|
|
743
769
|
const cancelFollowThrough = useCallback(() => {
|
|
744
770
|
if (followTimer.current) {
|
|
745
771
|
clearTimeout(followTimer.current);
|
|
746
772
|
followTimer.current = null;
|
|
747
773
|
}
|
|
774
|
+
teamWakeRef.current?.cancel();
|
|
748
775
|
}, []);
|
|
749
776
|
/**
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
* shared. That split is R9's mitigation - the desktop coordinator runs the same
|
|
755
|
-
* function against its own timer.
|
|
777
|
+
* Re-run a run the ENGINE interrupted, after `graceMs`
|
|
778
|
+
* (`team-idle-watchdog-dead-run` F3). `decideFollowThrough` decided WHETHER; this
|
|
779
|
+
* is the host's half, and it deliberately reuses the one `followTimer` slot so
|
|
780
|
+
* "at most one armed continuation, ever" (I-3) stays true.
|
|
756
781
|
*
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
782
|
+
* IT STARTS THE RUN WITH `controller.continue()`, NOT `submit()`. Nothing is
|
|
783
|
+
* appended to the history: the interrupted turn's input is already there and the
|
|
784
|
+
* half-written reply never was, so `continue()` just asks again. That is also why
|
|
785
|
+
* there is no card, no `userInitiated` bookkeeping and no prompt-history entry.
|
|
761
786
|
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
787
|
+
* A TEAM WAKE COUNTDOWN OUTRANKS IT. If the team already owes the lead a signal and
|
|
788
|
+
* its countdown is running, that wake starts a turn which redoes the interrupted
|
|
789
|
+
* work anyway (and delivers a real signal while doing it); arming here would cancel
|
|
790
|
+
* the wake (`cancelFollowThrough` -> `teamWakeRef.cancel()`) and spend an
|
|
791
|
+
* allowance to do the same thing worse. So this yields, silently, WITHOUT charging.
|
|
765
792
|
*/
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
const facts = controller.teamSettleFacts?.() ?? null;
|
|
770
|
-
if (facts === null)
|
|
771
|
-
return;
|
|
772
|
-
// Same defence as the gate: a double without the team surface never reaches
|
|
773
|
-
// this line, and one that has `teamSettleFacts` but no config still gets the
|
|
774
|
-
// documented defaults rather than a crash inside an event handler.
|
|
775
|
-
const teamConfig = controller.getTeamConfig?.() ?? {
|
|
776
|
-
autoResume: 'auto',
|
|
777
|
-
settleGraceMs: 3_000,
|
|
778
|
-
detachDispatch: true,
|
|
779
|
-
};
|
|
780
|
-
const decision = planSettleContinuation({
|
|
781
|
-
mode: teamConfig.autoResume,
|
|
782
|
-
settled: facts.settled,
|
|
783
|
-
settledInsideTurn: facts.settledInsideTurn,
|
|
784
|
-
runEnd: { aborted: facts.aborted, errored: facts.errored },
|
|
785
|
-
continuedThisDispatch: facts.continuedThisDispatch,
|
|
786
|
-
userPending: controller.hasPendingUserMessages(),
|
|
787
|
-
followThroughArmed: armed.followThroughArmed,
|
|
788
|
-
graceMs: teamConfig.settleGraceMs,
|
|
789
|
-
outcome: facts.outcome,
|
|
790
|
-
});
|
|
791
|
-
if (decision.kind === 'notice') {
|
|
792
|
-
dispatch({ type: 'notice', level: decision.level, text: decision.text });
|
|
793
|
+
const armRunResume = (graceMs, notice) => {
|
|
794
|
+
if (teamWakeRef.current?.isCounting() === true) {
|
|
795
|
+
getLogger().debug('agent', 'run_resume_yield', { reason: 'team_wake_counting' });
|
|
793
796
|
return;
|
|
794
797
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
dispatch({ type: 'notice', level: decision.level, text: decision.notice });
|
|
798
|
-
cancelFollowThrough(); // I-9: at most one armed continuation, ever
|
|
798
|
+
dispatch({ type: 'notice', level: 'info', text: notice });
|
|
799
|
+
cancelFollowThrough(); // I-3: at most one armed continuation, ever
|
|
799
800
|
followTimer.current = setTimeout(() => {
|
|
800
801
|
followTimer.current = null;
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
802
|
+
void fireRunResume();
|
|
803
|
+
}, graceMs);
|
|
804
|
+
};
|
|
805
|
+
/**
|
|
806
|
+
* THE FIRE POINT. Every guard `drainCompactionQueue` applies to its own
|
|
807
|
+
* `controller.continue()` applies here, for the same reason: `Agent.continue()`
|
|
808
|
+
* THROWS while running, and the grace window is open to the user, who may have
|
|
809
|
+
* started typing at its very end. `submitMessage` -> `cancelFollowThrough()` already
|
|
810
|
+
* covers a message typed EARLIER in the window; what it cannot cover is a run that
|
|
811
|
+
* began in the same tick the timer fired, which `interactionPhase` does.
|
|
812
|
+
*
|
|
813
|
+
* ITS FAILURES ARE `warn`, NEVER `error`: the error level sets
|
|
814
|
+
* `endReasonRef.errored` (see the gate's note), and a failed START has no
|
|
815
|
+
* `agent_end` to clear it - the next, unrelated run would then be judged to have
|
|
816
|
+
* failed and recovered or reported for nothing.
|
|
817
|
+
*/
|
|
818
|
+
const fireRunResume = async () => {
|
|
819
|
+
if (!mounted.current || switchingConversation.current
|
|
820
|
+
|| controller.isCompactionBusy?.() || controller.isRunning()
|
|
821
|
+
|| interactionPhase.current !== 'idle'
|
|
822
|
+
|| controller.areModelSettingsBlocked?.() === true) {
|
|
823
|
+
getLogger().debug('agent', 'run_resume_skipped', { reason: 'host_busy' });
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const preflight = controller.preflight();
|
|
827
|
+
if (!preflight.ok) {
|
|
828
|
+
dispatch({ type: 'notice', level: 'warn', text: preflight.message ?? 'Configuration error.' });
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
// CHARGED AT THE FIRE POINT, never at decision time: a recovery the user cancelled
|
|
832
|
+
// was never issued and must not spend their allowance.
|
|
833
|
+
resumeRef.current = chargeResume(resumeRef.current);
|
|
834
|
+
// COUNTS ONLY: no message body ever reaches this log.
|
|
835
|
+
getLogger().info('agent', 'run_resume', {
|
|
836
|
+
consecutive: resumeRef.current.consecutive,
|
|
837
|
+
total: resumeRef.current.total,
|
|
838
|
+
});
|
|
839
|
+
interactionPhase.current = 'starting';
|
|
840
|
+
try {
|
|
841
|
+
const outcome = await controller.continue();
|
|
842
|
+
if (outcome?.status === 'not-started' && outcome.reason !== 'cancelled') {
|
|
843
|
+
dispatch({
|
|
844
|
+
type: 'notice',
|
|
845
|
+
level: 'warn',
|
|
846
|
+
text: 'Could not retry the run automatically. Send any message to continue.',
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
catch (error) {
|
|
851
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
852
|
+
dispatch({
|
|
853
|
+
type: 'notice',
|
|
854
|
+
level: 'warn',
|
|
855
|
+
text: `Could not retry the run automatically (${reason}). Send any message to continue.`,
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
finally {
|
|
859
|
+
if (interactionPhase.current === 'starting')
|
|
860
|
+
interactionPhase.current = 'idle';
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
/**
|
|
864
|
+
* `armRunResume` as of the LATEST render, for the `afterAgentEnd` hook - the same
|
|
865
|
+
* reason `submitRef` exists just below: the subscription effect never re-runs, so a
|
|
866
|
+
* direct call would close over the mount render's binding forever. That binding
|
|
867
|
+
* would happen to be correct today because the function reads only refs and stable
|
|
868
|
+
* values, which is exactly the "happens to be correct" this file keeps having to
|
|
869
|
+
* unwind.
|
|
870
|
+
*/
|
|
871
|
+
const armRunResumeRef = useRef(() => { });
|
|
872
|
+
armRunResumeRef.current = armRunResume;
|
|
815
873
|
/**
|
|
816
874
|
* `submitMessage` as of the LATEST render, for the grace timer.
|
|
817
875
|
*
|
|
@@ -823,7 +881,7 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
823
881
|
* (P1-1, P1-6). Assigned during render, the same discipline `stateRef` uses
|
|
824
882
|
* twenty lines up.
|
|
825
883
|
*/
|
|
826
|
-
const submitRef = useRef(() => { });
|
|
884
|
+
const submitRef = useRef(() => ({ accepted: false }));
|
|
827
885
|
/**
|
|
828
886
|
* THE SINGLE SETTLE PATH for a human request. Idempotent per entry, and it
|
|
829
887
|
* clears the overlay as its last act.
|
|
@@ -948,6 +1006,11 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
948
1006
|
const todos = controller.getTodoSnapshot();
|
|
949
1007
|
budgetRef.current = advanceBudget(budgetRef.current, todos, autoContinuationRef.current);
|
|
950
1008
|
autoContinuationRef.current = false;
|
|
1009
|
+
// A RUN THAT ENDED WITHOUT AN ERROR BREAKS THE CHAIN OF BACK-TO-BACK DEATHS
|
|
1010
|
+
// (F3). Read AFTER the engine's verdict was folded in at the top of this
|
|
1011
|
+
// hook and BEFORE `endReasonRef` is reset below, which is the only window in
|
|
1012
|
+
// which both facts are still true.
|
|
1013
|
+
resumeRef.current = settleResumeCounters(resumeRef.current, endReasonRef.current);
|
|
951
1014
|
// --- Forced-dispatch gate (team-command-forced-dispatch §3.7). --------
|
|
952
1015
|
//
|
|
953
1016
|
// THE THIRD LAYER, AND THE ONLY MECHANICAL ONE: if a whole turn went by
|
|
@@ -993,11 +1056,24 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
993
1056
|
runEnd: { ...endReasonRef.current },
|
|
994
1057
|
budget: budgetRef.current,
|
|
995
1058
|
interactive: true,
|
|
1059
|
+
// READ LIVE, like `followThrough` above: `/retry off` and `config set`
|
|
1060
|
+
// take effect on the very next death, not on relaunch.
|
|
1061
|
+
resume: {
|
|
1062
|
+
...toRunResumePolicy(controller.getConfig().retry),
|
|
1063
|
+
consecutive: resumeRef.current.consecutive,
|
|
1064
|
+
total: resumeRef.current.total,
|
|
1065
|
+
// The engine's own verdict, for the WORDING only (`RunEndFacts` is a
|
|
1066
|
+
// structural subset of `AgentEndEvent`).
|
|
1067
|
+
cause: end,
|
|
1068
|
+
},
|
|
996
1069
|
});
|
|
997
1070
|
endReasonRef.current = { aborted: false, errored: false, transient: false };
|
|
998
1071
|
if (decision.kind === 'notify') {
|
|
999
1072
|
dispatch({ type: 'notice', level: decision.level, text: decision.text });
|
|
1000
1073
|
}
|
|
1074
|
+
else if (decision.kind === 'resume') {
|
|
1075
|
+
armRunResumeRef.current(decision.graceMs, decision.notice);
|
|
1076
|
+
}
|
|
1001
1077
|
else if (decision.kind === 'continue') {
|
|
1002
1078
|
dispatch({ type: 'notice', level: 'info', text: decision.notice });
|
|
1003
1079
|
// NO LIVE COUNTDOWN (D-10). The notice is written once and does not
|
|
@@ -1063,20 +1139,11 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1063
1139
|
});
|
|
1064
1140
|
}, FORCED_NUDGE_GRACE_MS);
|
|
1065
1141
|
}
|
|
1066
|
-
//
|
|
1067
|
-
//
|
|
1068
|
-
//
|
|
1069
|
-
//
|
|
1070
|
-
//
|
|
1071
|
-
// - after the nudge, before `onTurnEnd()` - nothing downstream cancels it.
|
|
1072
|
-
//
|
|
1073
|
-
// A dispatch that settled INSIDE this turn needs no new turn (its report
|
|
1074
|
-
// already arrived as a steering message), and one that settled while the
|
|
1075
|
-
// user was typing does not need one either (their turn carries it). Both
|
|
1076
|
-
// are `planSettleContinuation`'s rules, not this block's.
|
|
1077
|
-
armTeamSettle({
|
|
1078
|
-
followThroughArmed: followTimer.current !== null || decision.kind === 'continue' || gated,
|
|
1079
|
-
});
|
|
1142
|
+
// NO TEAM DECISION IS MADE HERE (team-lead-wake-signals). It used to be, once per
|
|
1143
|
+
// `agent_end`, and a dispatch that ends while the lead is idle never produces
|
|
1144
|
+
// one - so the team's report waited for the user to type. The controller's
|
|
1145
|
+
// governor now judges at every moment a signal could be collectable, and the
|
|
1146
|
+
// wake driver mounted below acts on its requests through this same timer slot.
|
|
1080
1147
|
// A team-mode change asked for during the turn lands here, AFTER the gate above
|
|
1081
1148
|
// read its basis (I-9). The posture lands next: a pending GOVERN entry that
|
|
1082
1149
|
// arrives with it is reported by the same toast channel, not silently swallowed.
|
|
@@ -1136,6 +1203,51 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
1136
1203
|
controller.dispose();
|
|
1137
1204
|
};
|
|
1138
1205
|
}, [controller]);
|
|
1206
|
+
// --- The team wake driver (team-lead-wake-signals 4.10). ------------------
|
|
1207
|
+
//
|
|
1208
|
+
// THE TERMINAL'S HALF OF "THE TEAM NEEDS THE LEAD": the controller's governor decides
|
|
1209
|
+
// that a turn is owed; this starts it. The countdown lives in `followTimer` - the one
|
|
1210
|
+
// slot the todo follow-through and the forced nudge already share - so at most one
|
|
1211
|
+
// continuation is ever armed, and a wake that finds the slot taken answers `busy` and
|
|
1212
|
+
// is retried rather than stealing it or being dropped (I-WK9).
|
|
1213
|
+
useEffect(() => {
|
|
1214
|
+
const driver = new TeamWakeDriver({
|
|
1215
|
+
controller,
|
|
1216
|
+
timer: {
|
|
1217
|
+
set: (fn, ms) => {
|
|
1218
|
+
if (followTimer.current)
|
|
1219
|
+
clearTimeout(followTimer.current);
|
|
1220
|
+
followTimer.current = setTimeout(() => {
|
|
1221
|
+
followTimer.current = null;
|
|
1222
|
+
fn();
|
|
1223
|
+
}, ms);
|
|
1224
|
+
},
|
|
1225
|
+
clear: () => {
|
|
1226
|
+
if (followTimer.current)
|
|
1227
|
+
clearTimeout(followTimer.current);
|
|
1228
|
+
followTimer.current = null;
|
|
1229
|
+
},
|
|
1230
|
+
armed: () => followTimer.current !== null,
|
|
1231
|
+
},
|
|
1232
|
+
// The countdown is a transcript line (it does not tick - D-10), the cancellation a toast.
|
|
1233
|
+
announce: (level, text) => dispatch({ type: 'notice', level, text }),
|
|
1234
|
+
toast: (level, text) => dispatch({ type: 'pushToast', level, text }),
|
|
1235
|
+
// THROUGH `submitMessage`, so the wake gets the same card, phase bookkeeping and
|
|
1236
|
+
// `userInitiated: false` treatment as every other continuation. It is only ever
|
|
1237
|
+
// called with the lead idle (the driver re-checks in the same synchronous block),
|
|
1238
|
+
// so it can never take the "running -> queue as user steering" branch.
|
|
1239
|
+
submit: (text, invocation) => submitRef.current(text, { userInitiated: false, todoPolicy: 'continue', invocation })
|
|
1240
|
+
.accepted,
|
|
1241
|
+
cancelHint: () => 'Esc cancels',
|
|
1242
|
+
leadBusy: () => interactionPhase.current !== 'idle',
|
|
1243
|
+
});
|
|
1244
|
+
teamWakeRef.current = driver;
|
|
1245
|
+
const detach = driver.attach();
|
|
1246
|
+
return () => {
|
|
1247
|
+
detach();
|
|
1248
|
+
teamWakeRef.current = null;
|
|
1249
|
+
};
|
|
1250
|
+
}, [controller]);
|
|
1139
1251
|
// --- Governance event stream (governance-mode 8.6 / 14.4). --------------
|
|
1140
1252
|
//
|
|
1141
1253
|
// ANOTHER CLI-LOCAL SUBSCRIPTION, for the reason the team one records: `GovernanceEvent`
|
|
@@ -2352,6 +2464,11 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
2352
2464
|
// nudge continuation arrives here with `userInitiated: false`, so it cannot
|
|
2353
2465
|
// refill its own budget.
|
|
2354
2466
|
nudgesRef.current = 0;
|
|
2467
|
+
// THE ONE PLACE THE PER-PROMPT RECOVERY CEILING IS REFILLED (F3), for the same
|
|
2468
|
+
// reason as the nudge budget: only a human may hand an automatic mechanism
|
|
2469
|
+
// another allowance, and a recovery or a todo continuation arrives here with
|
|
2470
|
+
// `userInitiated: false` and so cannot refill its own.
|
|
2471
|
+
resumeRef.current = emptyResumeCounters();
|
|
2355
2472
|
}
|
|
2356
2473
|
// Mirrors where the reducer clears its own copies, in the same action
|
|
2357
2474
|
// (C-11): a new turn's end reason must not inherit the previous one's.
|
|
@@ -3172,8 +3289,13 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
|
|
|
3172
3289
|
// the pre-existing meaning of Esc here ("start nothing"), and a second rung
|
|
3173
3290
|
// below it must not take that away.
|
|
3174
3291
|
if (followTimer.current) {
|
|
3292
|
+
// A cancelled team wake says so itself ("Wake cancelled. The report goes with your
|
|
3293
|
+
// next message."); a second, generic toast would say the same thing twice.
|
|
3294
|
+
const wakeOwnsIt = teamWakeRef.current?.isCounting() === true;
|
|
3175
3295
|
cancelFollowThrough();
|
|
3176
|
-
|
|
3296
|
+
if (!wakeOwnsIt) {
|
|
3297
|
+
dispatch({ type: 'pushToast', level: 'info', text: 'Auto-continue cancelled.' });
|
|
3298
|
+
}
|
|
3177
3299
|
return;
|
|
3178
3300
|
}
|
|
3179
3301
|
// --- The team rung (team-detached-dispatch 5.6, I-DD11) -----------------
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import { COMPACTION_CONFIG_SET_KEYS, FAST_CONFIG_SET_KEYS, LOG_CONFIG_SET_KEYS,
|
|
|
19
19
|
import { attachAgentEvents, attachTeamEvents, installLogging, setScreenRestore, setSignalTerminator, } from './logging/install.js';
|
|
20
20
|
import { getLogger } from './logging/logger.js';
|
|
21
21
|
import { runLogsCommand } from './logging/cli-commands.js';
|
|
22
|
-
import { ADAPTER_PROVIDERS, clampDensity, clampTheme, clampThinkingLevel, clampHumanTimeout, clampSkillsIntegrity, clampSkillsToolPolicy, clampContextWindow, clampMaxRenderInterval, clampScrollMode, clampScrollResumeMs, clampTranscriptRetain, clampTranscriptWindow, coercePositiveInt, isAdapterProvider, isAutoToken, parseMaxTokensInput, RETIRED_CONFIG_KEYS, DEFAULT_MAX_RENDER_INTERVAL_MS, DEFAULT_MAX_TOKENS, DEFAULT_PLAN_HUMAN_TIMEOUT_MS, DEFAULT_SCROLL_MODE, DEFAULT_SCROLL_RESUME_MS, DEFAULT_SKILLS_CONFIG, DEFAULT_TRANSCRIPT_RETAIN, DEFAULT_TRANSCRIPT_WINDOW, } from '@aragon-agent/tui/model/config/schema';
|
|
22
|
+
import { ADAPTER_PROVIDERS, clampDensity, clampTheme, clampThinkingLevel, clampHumanTimeout, clampSkillsIntegrity, clampSkillsToolPolicy, clampContextWindow, clampMaxRenderInterval, clampScrollMode, clampScrollResumeMs, clampTranscriptRetain, clampTranscriptWindow, coercePositiveInt, isAdapterProvider, isAutoToken, parseMaxTokensInput, RETIRED_CONFIG_KEYS, DEFAULT_MAX_RENDER_INTERVAL_MS, DEFAULT_MAX_TOKENS, DEFAULT_PLAN_HUMAN_TIMEOUT_MS, DEFAULT_SCROLL_MODE, DEFAULT_SCROLL_RESUME_MS, DEFAULT_SKILLS_CONFIG, DEFAULT_TRANSCRIPT_RETAIN, DEFAULT_TRANSCRIPT_WINDOW, toRunResumePolicy, } from '@aragon-agent/tui/model/config/schema';
|
|
23
23
|
import { makeGetApiKey } from './config/load.js';
|
|
24
24
|
import { runSkillsCommand } from './skills/cli-commands.js';
|
|
25
25
|
import { runHeadless } from './agent/headless.js';
|
|
@@ -1344,6 +1344,9 @@ async function runOneShot(flags, prompt, quiet) {
|
|
|
1344
1344
|
code = await runHeadless(controller, prompt, {
|
|
1345
1345
|
quiet,
|
|
1346
1346
|
followThrough: controller.getTodoConfig().followThrough,
|
|
1347
|
+
// ONE RECOVERY for a run the engine interrupted (team-idle-watchdog-dead-run F3);
|
|
1348
|
+
// `headless` is where that cap comes from.
|
|
1349
|
+
resume: toRunResumePolicy(controller.getConfig().retry, { headless: true }),
|
|
1347
1350
|
});
|
|
1348
1351
|
}
|
|
1349
1352
|
finally {
|
|
@@ -904,7 +904,8 @@ const COMMANDS = [
|
|
|
904
904
|
// file is already past the 1000-line guideline and `/compact` has six forms
|
|
905
905
|
// plus the longest status report in the package (C-16 / P1-12).
|
|
906
906
|
name: 'compact',
|
|
907
|
-
description: 'Context compaction: status |
|
|
907
|
+
description: 'Context compaction: status | spend | budget | agent | prune | threshold ' +
|
|
908
|
+
'| keep | history | show | <instructions>',
|
|
908
909
|
run: (ctx) => runCompactCommand(ctx),
|
|
909
910
|
},
|
|
910
911
|
{
|
package/dist/commands/catalog.js
CHANGED
|
@@ -21,7 +21,7 @@ export const BUILTIN_COMMAND_CATALOG = [
|
|
|
21
21
|
{ name: 'update', aliases: [], description: 'Auto-update: status | now | skip | off' },
|
|
22
22
|
{ name: 'todo', aliases: [], description: 'Todo planning: status | on | off | panel on|off | follow <mode> | acceptance [on|off|reset] | clear | continue' },
|
|
23
23
|
{ name: 'retry', aliases: [], description: 'API retry: show | on | off | max <n>' },
|
|
24
|
-
{ name: 'compact', aliases: [], description: 'Context compaction: status |
|
|
24
|
+
{ name: 'compact', aliases: [], description: 'Context compaction: status | spend | budget | agent | prune | threshold | keep | history | show | <instructions>' },
|
|
25
25
|
{ name: 'context', aliases: [], description: 'Show context occupancy, the window it is measured against, and session spend' },
|
|
26
26
|
{ name: 'expand', aliases: [], description: 'Expand / collapse a recent tool card (default: last)' },
|
|
27
27
|
{ name: 'tools', aliases: [], description: 'List active tools' },
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* it has no terminal, no theme and no glyphs.
|
|
20
20
|
*/
|
|
21
21
|
import type { Message } from '@aragon-agent/core';
|
|
22
|
-
import type { CompactionMode, CompactionUiTrigger } from '@aragon-agent/tui/model/compaction/types';
|
|
22
|
+
import type { ArchivePruneAction, CompactionMode, CompactionRecord, CompactionUiTrigger } from '@aragon-agent/tui/model/compaction/types';
|
|
23
23
|
/** Bumped only when the SHAPE changes; the reader rejects anything else. */
|
|
24
24
|
export declare const ARCHIVE_FORMAT_VERSION = 1;
|
|
25
25
|
export interface CompactionArchive {
|
|
@@ -57,6 +57,20 @@ export interface CompactionArchive {
|
|
|
57
57
|
messages: number;
|
|
58
58
|
charsRemoved: number;
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* THE THREE v3 SECTIONS, ALL OPTIONAL AND ALL ADDITIVE (P0-3).
|
|
62
|
+
*
|
|
63
|
+
* `version` STAYS 1 ON PURPOSE. The reader accepts a document only when
|
|
64
|
+
* `raw.version === ARCHIVE_FORMAT_VERSION` (strict equality), so bumping it
|
|
65
|
+
* would make every archive written before this feature invisible to
|
|
66
|
+
* `/compact history` and `/compact show` - the exact corruption R-13 records.
|
|
67
|
+
* A missing section is read as absent, the way `tailRelief` already is.
|
|
68
|
+
*/
|
|
69
|
+
prune?: {
|
|
70
|
+
actions: ArchivePruneAction[];
|
|
71
|
+
};
|
|
72
|
+
budget?: CompactionRecord['budget'];
|
|
73
|
+
agent?: CompactionRecord['agent'];
|
|
60
74
|
/** True when `dropped` was shortened to fit `archiveMaxBytes`. */
|
|
61
75
|
clipped: boolean;
|
|
62
76
|
/** THE ARRAY. Verbatim, oldest first. */
|
|
@@ -85,6 +99,12 @@ export interface ArchiveEntry {
|
|
|
85
99
|
messages: number;
|
|
86
100
|
charsRemoved: number;
|
|
87
101
|
};
|
|
102
|
+
/** The prune tally, absent for every archive written before v3. */
|
|
103
|
+
prune?: {
|
|
104
|
+
actions: ArchivePruneAction[];
|
|
105
|
+
};
|
|
106
|
+
budget?: CompactionRecord['budget'];
|
|
107
|
+
agent?: CompactionRecord['agent'];
|
|
88
108
|
clipped: boolean;
|
|
89
109
|
}
|
|
90
110
|
export interface ArchiveWriteInput {
|
|
@@ -103,6 +123,12 @@ export interface ArchiveWriteInput {
|
|
|
103
123
|
messages: number;
|
|
104
124
|
charsRemoved: number;
|
|
105
125
|
};
|
|
126
|
+
/** The three optional v3 sections (P0-3: additive, never a version bump). */
|
|
127
|
+
prune?: {
|
|
128
|
+
actions: ArchivePruneAction[];
|
|
129
|
+
};
|
|
130
|
+
budget?: CompactionRecord['budget'];
|
|
131
|
+
agent?: CompactionRecord['agent'];
|
|
106
132
|
dropped: Message[];
|
|
107
133
|
/** Injected by the tests; production passes nothing. */
|
|
108
134
|
dir?: string;
|
|
@@ -130,6 +130,9 @@ export function writeArchive(input) {
|
|
|
130
130
|
droppedCount: input.dropped.length,
|
|
131
131
|
...(input.summary !== undefined ? { summary: input.summary } : {}),
|
|
132
132
|
...(input.tailRelief ? { tailRelief: input.tailRelief } : {}),
|
|
133
|
+
...(input.prune ? { prune: input.prune } : {}),
|
|
134
|
+
...(input.budget ? { budget: input.budget } : {}),
|
|
135
|
+
...(input.agent ? { agent: input.agent } : {}),
|
|
133
136
|
clipped: false,
|
|
134
137
|
// agent-image-reading: the archive is the SECOND place messages reach the disk. A tool
|
|
135
138
|
// picture is re-fetchable, so it is archived as its label and a note; verbatim pixels
|
|
@@ -258,6 +261,11 @@ function readArchiveEntry(path, fileName) {
|
|
|
258
261
|
droppedCount: Number(raw.droppedCount ?? 0),
|
|
259
262
|
...(typeof raw.summary === 'string' ? { summary: raw.summary } : {}),
|
|
260
263
|
...(raw.tailRelief ? { tailRelief: raw.tailRelief } : {}),
|
|
264
|
+
// A MISSING SECTION IS ABSENT, NOT AN ERROR (P0-3): every archive written
|
|
265
|
+
// before this feature has none of the three, and all of them stay readable.
|
|
266
|
+
...(raw.prune ? { prune: raw.prune } : {}),
|
|
267
|
+
...(raw.budget ? { budget: raw.budget } : {}),
|
|
268
|
+
...(raw.agent ? { agent: raw.agent } : {}),
|
|
261
269
|
clipped: raw.clipped === true,
|
|
262
270
|
};
|
|
263
271
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-operation spend ceiling (context-compaction-v3 W3).
|
|
3
|
+
*
|
|
4
|
+
* ASCII ONLY: `src/compaction/**` is inside the glyph scanner's scope.
|
|
5
|
+
*
|
|
6
|
+
* WHY PER OPERATION AND NOT PER SESSION (D-8). A session-level cap turns the
|
|
7
|
+
* seventh compaction of a long run into an unexplained cliff: the feature simply
|
|
8
|
+
* stops working, with nothing about the moment that explains it. Per-operation
|
|
9
|
+
* keeps every refusal local, visible on the card that caused it, and repeatable.
|
|
10
|
+
*
|
|
11
|
+
* TWO UNITS, TWO MECHANISMS:
|
|
12
|
+
*
|
|
13
|
+
* - TOKENS are charged from the provider's REAL `usage`, and the projection is
|
|
14
|
+
* used only to refuse a request that is obviously already over. Charging the
|
|
15
|
+
* projection would bill a request that never happened.
|
|
16
|
+
* - DOLLARS need a price table. When the summarizer model is not priced the
|
|
17
|
+
* dollar gate is switched off and says so (`priceUnknown`), because a
|
|
18
|
+
* fake `$0.00` on a feature that is spending money is the same class of lie
|
|
19
|
+
* the fast tier's RV-11 records (D-9).
|
|
20
|
+
*
|
|
21
|
+
* `0` MEANS UNLIMITED IN BOTH UNITS, and that is why the arithmetic never has to
|
|
22
|
+
* special-case "no budget": a zero limit is never reached by a growing total.
|
|
23
|
+
*/
|
|
24
|
+
import type { TokenUsage } from '@aragon-agent/core';
|
|
25
|
+
export interface BudgetLimits {
|
|
26
|
+
/** Total tokens this operation may spend; `0` = unlimited. */
|
|
27
|
+
tokens: number;
|
|
28
|
+
/** Total dollars this operation may spend; `0` = unlimited. */
|
|
29
|
+
usd: number;
|
|
30
|
+
}
|
|
31
|
+
export interface BudgetSnapshot {
|
|
32
|
+
limitTokens: number;
|
|
33
|
+
spentTokens: number;
|
|
34
|
+
limitUsd: number;
|
|
35
|
+
spentUsd: number;
|
|
36
|
+
/** True when the dollar gate could not price the summarizer and is not in force. */
|
|
37
|
+
priceUnknown: boolean;
|
|
38
|
+
stop?: 'budget_tokens' | 'budget_usd';
|
|
39
|
+
}
|
|
40
|
+
export interface BudgetCharge {
|
|
41
|
+
usage: TokenUsage;
|
|
42
|
+
costUsd: number;
|
|
43
|
+
pricingUnknown: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Tokens a usage entry actually costs; cache reads and writes count as input. */
|
|
46
|
+
export declare function chargedTokens(usage: TokenUsage): number;
|
|
47
|
+
export declare class CompactionBudget {
|
|
48
|
+
private readonly limits;
|
|
49
|
+
private spentTokens;
|
|
50
|
+
private spentUsd;
|
|
51
|
+
private priceUnknown;
|
|
52
|
+
private stopped;
|
|
53
|
+
/**
|
|
54
|
+
* THE DEDUPE KEY IS THE USAGE OBJECT'S IDENTITY, not a turn counter.
|
|
55
|
+
*
|
|
56
|
+
* One `callOnce` can produce several REAL billable calls inside core's
|
|
57
|
+
* `withRetry`, and each of them hands back its own usage object. A counter
|
|
58
|
+
* would charge the retries as one; object identity charges what was spent and
|
|
59
|
+
* still refuses to charge the same object twice (the single-shot path forwards
|
|
60
|
+
* the same usage to two callbacks).
|
|
61
|
+
*/
|
|
62
|
+
private readonly charged;
|
|
63
|
+
constructor(limits: BudgetLimits);
|
|
64
|
+
/** Whether a request of this projected size would cross the token ceiling. */
|
|
65
|
+
wouldExceed(projectedTokens: number): boolean;
|
|
66
|
+
/** Record what a real call cost. Never throws: a budget cannot fail a compaction. */
|
|
67
|
+
charge(input: BudgetCharge): void;
|
|
68
|
+
/** The ceiling that has been crossed, if any; `undefined` while work may continue. */
|
|
69
|
+
get exhausted(): 'budget_tokens' | 'budget_usd' | undefined;
|
|
70
|
+
snapshot(): BudgetSnapshot;
|
|
71
|
+
/** Both gates, in a fixed order, so one snapshot has one `stop` value. */
|
|
72
|
+
private evaluate;
|
|
73
|
+
}
|