@aragon-agent/cli 0.6.70 → 0.6.72

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +33 -14
  3. package/dist/account/config.d.ts +61 -0
  4. package/dist/account/config.js +83 -0
  5. package/dist/account/device-client.d.ts +113 -0
  6. package/dist/account/device-client.js +425 -0
  7. package/dist/account/format.d.ts +51 -0
  8. package/dist/account/format.js +102 -0
  9. package/dist/account/login-flow.d.ts +68 -0
  10. package/dist/account/login-flow.js +305 -0
  11. package/dist/account/session.d.ts +62 -0
  12. package/dist/account/session.js +63 -0
  13. package/dist/account/store.d.ts +86 -0
  14. package/dist/account/store.js +231 -0
  15. package/dist/agent/controller.d.ts +25 -1
  16. package/dist/agent/controller.js +78 -3
  17. package/dist/agent/project-guidance-prompt.js +97 -97
  18. package/dist/app/App.d.ts +12 -3
  19. package/dist/app/App.js +216 -3
  20. package/dist/cli.js +2 -2
  21. package/dist/commands/account-command.d.ts +86 -0
  22. package/dist/commands/account-command.js +165 -0
  23. package/dist/commands/builtins.js +15 -0
  24. package/dist/commands/catalog.js +17 -1
  25. package/dist/config/app-paths.d.ts +15 -0
  26. package/dist/config/app-paths.js +17 -0
  27. package/dist/config/cli-commands.d.ts +1 -1
  28. package/dist/config/cli-commands.js +4 -0
  29. package/dist/config/env.js +6 -0
  30. package/dist/config/load.js +36 -1
  31. package/dist/governance/engine/lifecycle.js +1 -1
  32. package/dist/governance/prompts/orchestrator-block.js +3 -3
  33. package/dist/host/controller-factory.d.ts +15 -0
  34. package/dist/host/controller-factory.js +10 -2
  35. package/dist/host/memory.d.ts +5 -1
  36. package/dist/host/memory.js +13 -0
  37. package/dist/memory/block.d.ts +38 -4
  38. package/dist/memory/block.js +52 -5
  39. package/dist/memory/command.js +56 -2
  40. package/dist/memory/journal.d.ts +58 -0
  41. package/dist/memory/journal.js +202 -0
  42. package/dist/memory/ledger.d.ts +54 -0
  43. package/dist/memory/ledger.js +105 -0
  44. package/dist/memory/paths.d.ts +10 -0
  45. package/dist/memory/paths.js +31 -0
  46. package/dist/memory/service.d.ts +54 -1
  47. package/dist/memory/service.js +156 -1
  48. package/dist/memory/store.d.ts +21 -3
  49. package/dist/memory/store.js +66 -6
  50. package/dist/memory/tools-batch.d.ts +27 -0
  51. package/dist/memory/tools-batch.js +462 -0
  52. package/dist/memory/tools-shared.d.ts +176 -0
  53. package/dist/memory/tools-shared.js +305 -0
  54. package/dist/memory/tools.d.ts +19 -28
  55. package/dist/memory/tools.js +148 -228
  56. package/dist/memory/undo.d.ts +53 -0
  57. package/dist/memory/undo.js +173 -0
  58. package/dist/redteam/prompt-template.js +16 -16
  59. package/dist/tools/index.d.ts +2 -2
  60. package/dist/tools/index.js +16 -1
  61. package/package.json +3 -3
  62. package/runtime/insecure-tls-warning.cjs +62 -62
  63. package/runtime/insecure-tls-warning.d.cts +5 -5
  64. package/skills/project-indexer/templates/artifact-hygiene-template.md +14 -14
package/dist/app/App.js CHANGED
@@ -69,6 +69,10 @@ import { useGovernanceRounds } from './use-governance-rounds.js';
69
69
  // deferred arming and the banner. Same adapter shape as `use-team-mode` above.
70
70
  import { redTeamToastTtlMs, useRedTeamMode, } from './use-redteam-mode.js';
71
71
  import { RedTeamDisclaimerOverlay } from '@aragon-agent/tui/ui/overlays/RedTeamDisclaimerOverlay';
72
+ // THE SIGN-IN PANEL (`/login`, C6): pure presentation, four phases. Imported beside the waiver
73
+ // overlay because it is the same kind of surface - one Ink component the App drives from
74
+ // `state.overlay`.
75
+ import { LoginOverlay } from '@aragon-agent/tui/ui/overlays/LoginOverlay';
72
76
  import { teamStatusFromView } from '@aragon-agent/tui/model/team/team-mode';
73
77
  import { FORCED_NUDGE_GRACE_MS } from '@aragon-agent/tui/model/team/limits';
74
78
  import { TeamWakeDriver } from '../host/team-wake-driver.js';
@@ -86,6 +90,16 @@ import { INDEX_SKILL_NAME, buildIndexConfirmSummary, hasProjectIndex, indexBuild
86
90
  import { installConsoleBridge } from '@aragon-agent/tui/ui/console-bridge';
87
91
  import { publishExitSnapshot } from '@aragon-agent/tui/ui/exit-snapshot';
88
92
  import { publishSessionView } from './session-bridge.js';
93
+ // THE DEVICE-FLOW ACCOUNT LAYER (`/login`, `/logout`: C3-C6). The network state machine and the
94
+ // 0600 credential file live in `account/`; this file owns only the panel's four-phase state and
95
+ // the promise that drives it. `setAccountCommandPort` is how the two commands reach the App -
96
+ // `CommandContext` has no account field and `commands/registry.ts` is outside this work package.
97
+ import { setAccountCommandPort, startupAccountNotice, } from '../commands/account-command.js';
98
+ import { readAccountStatus } from '../account/session.js';
99
+ import { clearAccount } from '../account/store.js';
100
+ import { formatIsoDate } from '../account/format.js';
101
+ import { startLogin } from '../account/login-flow.js';
102
+ import { getAccountPath } from '../config/app-paths.js';
89
103
  import { OverlayFrame, overlayPageSize } from '@aragon-agent/tui/ui/layout/OverlayFrame';
90
104
  import { helpRows } from '@aragon-agent/tui/ui/overlays/HelpOverlay';
91
105
  import { ModelPicker } from '@aragon-agent/tui/ui/overlays/ModelPicker';
@@ -251,6 +265,15 @@ function firstUserText(entries) {
251
265
  * shape of refusal as `tooSmall` - and the header keeps naming `Esc close`.
252
266
  */
253
267
  const DECISION_OVERLAYS = new Set(['confirm', 'question', 'plan']);
268
+ /** The panel before anything has been asked of the server (`/login` and every retry start here). */
269
+ const INITIAL_LOGIN_VIEW = {
270
+ phase: 'prompt',
271
+ link: '',
272
+ code: '',
273
+ elapsedSec: 0,
274
+ account: null,
275
+ message: '',
276
+ };
254
277
  /** The LAST finished assistant message's text, or `null` — the source for memory `l`. */
255
278
  function lastAssistantText(entries) {
256
279
  for (let index = entries.length - 1; index >= 0; index -= 1) {
@@ -270,7 +293,7 @@ function lastUserText(entries) {
270
293
  }
271
294
  return '';
272
295
  }
273
- export function App({ controller, version, initialOverlay, initialPrompt, confirmBridge, humanInputBridge, mouseSource, vtInputWarning, updateBridge, pasteBridge, terminal, scrollMode = 'app', scrollback, initialEntries, session, sessionBridge, sessionNotice, redTeamNotice, }) {
296
+ export function App({ controller, version, initialOverlay, initialPrompt, confirmBridge, humanInputBridge, noticeBridge, mouseSource, vtInputWarning, updateBridge, pasteBridge, terminal, scrollMode = 'app', scrollback, initialEntries, session, sessionBridge, sessionNotice, redTeamNotice, }) {
274
297
  const native = scrollMode === 'native' && scrollback !== undefined;
275
298
  /** Set when the native writer swallowed repeated tall frames; cleared by a resize. */
276
299
  const [guardTripped, setGuardTripped] = useState(false);
@@ -1586,6 +1609,21 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
1586
1609
  confirmBridge.handler = null;
1587
1610
  };
1588
1611
  }, [confirmBridge]);
1612
+ // --- Notice bridge (memory receipts and other one-liners). -------------
1613
+ useEffect(() => {
1614
+ if (!noticeBridge)
1615
+ return undefined;
1616
+ const bridge = noticeBridge;
1617
+ bridge.handler = (level, text) => {
1618
+ dispatch({ type: 'notice', level, text });
1619
+ };
1620
+ return () => {
1621
+ // `App` unmounts (or swaps controllers) and the channel closes again: the controller reads it
1622
+ // LIVE on every call, exactly as the approval gates do, so nothing keeps writing into a tree
1623
+ // that is gone.
1624
+ bridge.handler = null;
1625
+ };
1626
+ }, [noticeBridge]);
1589
1627
  // --- Human-input bridge (ask_user / submit_plan). ----------------------
1590
1628
  useEffect(() => {
1591
1629
  if (!humanInputBridge)
@@ -1676,6 +1714,154 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
1676
1714
  // --- Helpers -----------------------------------------------------------
1677
1715
  const notify = (level, text) => dispatch({ type: 'notice', level, text });
1678
1716
  const toast = (level, text) => dispatch({ type: 'pushToast', level, text });
1717
+ // --- Device-flow sign-in (`/login`, C5 / C6) -----------------------------
1718
+ //
1719
+ // THE FLOW IS NOT THE PANEL, and that separation is the whole design. `startLogin` is a
1720
+ // promise THIS component owns; `state.overlay === 'login'` only decides whether the panel is
1721
+ // on screen. So `Esc` hides the panel and the device poll keeps running (C6: "waiting Esc =
1722
+ // onClose, the flow does not stop"), and the outcome is announced from the promise's
1723
+ // continuation - which is the only place that still knows about it after a hide.
1724
+ const [loginView, setLoginView] = useState(INITIAL_LOGIN_VIEW);
1725
+ /** ONE FLOW AT A TIME: a second Enter must not start a second authorization. */
1726
+ const loginBusy = useRef(false);
1727
+ /** The abort handle, so UNMOUNTING stops a poll nobody can see. `Esc` never touches it. */
1728
+ const loginAbort = useRef(null);
1729
+ /** The startup-notice latch: spec 6.6 asks for ONE prompt per launch, not one per render. */
1730
+ const accountNoticeShown = useRef(false);
1731
+ /** `/login` and the panel's `prompt` phase: show the panel, ask the server nothing yet. */
1732
+ const openLoginPanel = () => {
1733
+ // A FLOW ALREADY IN FLIGHT IS NOT RESET. `/login` typed while the device poll is waiting
1734
+ // (a second terminal, a second thought) has to show the code that is still valid; dropping
1735
+ // back to `prompt` would hide it behind an Enter that `startLoginFlow` then refuses, and
1736
+ // the panel would look broken while the sign-in was in fact progressing.
1737
+ if (!loginBusy.current)
1738
+ setLoginView(INITIAL_LOGIN_VIEW);
1739
+ dispatch({ type: 'setOverlay', overlay: 'login' });
1740
+ };
1741
+ /**
1742
+ * Apply a finished flow: the success toast plus the durable transcript notice, or the
1743
+ * `error` phase carrying the account layer's own sentence.
1744
+ *
1745
+ * THE SUCCESS NOTICE IS DISPATCHED HERE RATHER THAN BY THE PANEL because `Esc` may have
1746
+ * hidden the panel minutes ago; a 20-day credential that quietly landed on disk is the one
1747
+ * outcome a user must not be able to miss.
1748
+ */
1749
+ const settleLogin = (outcome) => {
1750
+ if (!mounted.current)
1751
+ return;
1752
+ if (!outcome.ok) {
1753
+ setLoginView((view) => ({ ...view, phase: 'error', message: outcome.message }));
1754
+ return;
1755
+ }
1756
+ const { username, expiresAt } = outcome.account;
1757
+ setLoginView({
1758
+ phase: 'success', link: '', code: '', elapsedSec: 0,
1759
+ account: { username, expiresAt }, message: '',
1760
+ });
1761
+ toast('success', `Signed in as ${username}.`);
1762
+ notify('info', `${username} signed in. The credential expires on ${formatIsoDate(expiresAt)}; ` +
1763
+ 'run /login any time to renew it.');
1764
+ };
1765
+ /**
1766
+ * Run one device-flow login, DETACHED from the composer (the panel's Enter, and every retry).
1767
+ *
1768
+ * `waiting` IS SET BEFORE THE FIRST REQUEST on purpose: the panel must never sit on the
1769
+ * `prompt` phase (whose Enter is live) while a POST it already started is in flight, or a
1770
+ * second Enter would open a second authorization.
1771
+ */
1772
+ const startLoginFlow = async () => {
1773
+ if (loginBusy.current) {
1774
+ toast('info', 'A sign-in is already in progress.');
1775
+ return;
1776
+ }
1777
+ loginBusy.current = true;
1778
+ const abort = new AbortController();
1779
+ loginAbort.current = abort;
1780
+ setLoginView({ ...INITIAL_LOGIN_VIEW, phase: 'waiting' });
1781
+ let outcome = null;
1782
+ try {
1783
+ outcome = await startLogin({
1784
+ signal: abort.signal,
1785
+ onCode: (code) => {
1786
+ if (!mounted.current)
1787
+ return;
1788
+ setLoginView({
1789
+ phase: 'waiting', link: code.link, code: code.code,
1790
+ elapsedSec: 0, account: null, message: '',
1791
+ });
1792
+ },
1793
+ // The flow's own clock: every poll iteration reports how long we have waited, so the
1794
+ // panel's seconds come from the same timer the polls are scheduled on.
1795
+ onProgress: ({ elapsedSec }) => {
1796
+ if (!mounted.current)
1797
+ return;
1798
+ setLoginView((view) => (view.phase === 'waiting' ? { ...view, elapsedSec } : view));
1799
+ },
1800
+ });
1801
+ }
1802
+ catch (error) {
1803
+ // `startLogin` promises never to throw; this is the honest answer if that ever changes,
1804
+ // because a rejection here would otherwise vanish as an unhandled promise rejection.
1805
+ getLogger().warn('cli', 'account.login_threw', {
1806
+ reason: error instanceof Error ? error.name : 'unknown',
1807
+ });
1808
+ }
1809
+ finally {
1810
+ loginBusy.current = false;
1811
+ loginAbort.current = null;
1812
+ }
1813
+ if (!mounted.current)
1814
+ return;
1815
+ if (outcome === null) {
1816
+ setLoginView((view) => ({
1817
+ ...view,
1818
+ phase: 'error',
1819
+ message: 'Sign-in failed unexpectedly. Run /login to try again.',
1820
+ }));
1821
+ return;
1822
+ }
1823
+ settleLogin(outcome);
1824
+ };
1825
+ /**
1826
+ * Install the App's account port and contribute NO context fields.
1827
+ *
1828
+ * A SPREAD FOR ITS SIDE EFFECT, which is unusual enough to justify in place: `CommandContext`
1829
+ * has no account field and `commands/registry.ts` (where it is declared) is outside this work
1830
+ * package, so the two commands read the port from `commands/account-command.ts`'s own
1831
+ * registration seam instead. Installing it from `makeCtx` means the port always belongs to
1832
+ * the App that is dispatching the command, and a build that never builds a context
1833
+ * (headless, a sub-agent, a host double) leaves the commands on their honest "not available"
1834
+ * branch.
1835
+ */
1836
+ const installAccountPort = () => {
1837
+ setAccountCommandPort({
1838
+ status: () => readAccountStatus(),
1839
+ accountPath: getAccountPath,
1840
+ openLogin: openLoginPanel,
1841
+ signOut: () => {
1842
+ const hadCredential = readAccountStatus().state !== 'signed-out';
1843
+ return { ok: clearAccount(), hadCredential };
1844
+ },
1845
+ });
1846
+ return {};
1847
+ };
1848
+ // THE ONE STARTUP LINE (spec 6.6): read the credential once, say ONE thing about it, and
1849
+ // stay completely silent for `signed-out` and `valid`. The latch is a ref rather than state
1850
+ // because a re-render must not replay it, and it is set BEFORE the read so nothing in the
1851
+ // account layer can turn this into a notice on every frame.
1852
+ useEffect(() => {
1853
+ if (accountNoticeShown.current)
1854
+ return;
1855
+ accountNoticeShown.current = true;
1856
+ const text = startupAccountNotice(readAccountStatus());
1857
+ if (text !== null)
1858
+ notify('info', text);
1859
+ // Mount-only by design: `/login` and `/logout` report for themselves.
1860
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1861
+ }, []);
1862
+ // A poll nobody can see must not outlive the tree that could show it. This is the ONLY
1863
+ // abort: `Esc` deliberately leaves the flow running (C6).
1864
+ useEffect(() => () => loginAbort.current?.abort(), []);
1679
1865
  // --- Quick prompt library: two one-shot channels and the store port ------
1680
1866
  const refreshPromptLibrary = useCallback(() => setPromptLibrary(loadPromptLibrary()), []);
1681
1867
  /**
@@ -1760,6 +1946,11 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
1760
1946
  resetMount: (id) => service.setOverride(id, 'reset'),
1761
1947
  setAutoload: (value) => service.setAutoload(value),
1762
1948
  subscribe: (listener) => service.subscribe(listener),
1949
+ // The activity page and `/memory undo` read and act through the SAME port as the list, so a
1950
+ // recovery does not need a second path into the service (memory-agent-autonomy 14.4).
1951
+ activity: (limit) => service.activity(limit),
1952
+ undo: (batchId) => service.undoLast(batchId),
1953
+ autonomy: () => service.getView().autonomy,
1763
1954
  };
1764
1955
  }, [controller]);
1765
1956
  // The status chip's data. The service emits only when the whole view CHANGED, so this does
@@ -2262,6 +2453,10 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
2262
2453
  };
2263
2454
  const invocationCardsOn = invocationCardsEnabled();
2264
2455
  const makeCtx = (args) => ({
2456
+ // INSTALLED FIRST, BEFORE ANY FIELD IS READ, so `/login` and `/logout` can never run against
2457
+ // a port from a previous App instance. See `installAccountPort` for why this is a spread and
2458
+ // not a field on `CommandContext`.
2459
+ ...installAccountPort(),
2265
2460
  args,
2266
2461
  invocationCards: invocationCardsOn,
2267
2462
  requestCopy: copyCoordinator.requestCopy,
@@ -3324,6 +3519,13 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
3324
3519
  const overlay = stateRef.current.overlay;
3325
3520
  if (overlay === 'settings')
3326
3521
  return;
3522
+ // THE SIGN-IN PANEL OWNS ITS `Esc` (C6). `App` steps aside rather than closing it here:
3523
+ // the panel's own handler calls `onClose`, which hides it and NOTHING ELSE. Closing it in
3524
+ // both places would be one state change twice, and it would put the abort handle within
3525
+ // reach of this branch - which is exactly the coupling C6 forbids (Esc must not stop the
3526
+ // device flow).
3527
+ if (overlay === 'login')
3528
+ return;
3327
3529
  // THE MEMORY MANAGER OWNS ITS Esc, like settings: the editor's first Esc only ARMS the
3328
3530
  // discard, and closing the overlay here as well would throw the half-typed note away on
3329
3531
  // that first press (AC-31). Only when it is actually mounted: with no port nothing renders
@@ -3812,7 +4014,10 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
3812
4014
  // mounted with `{...props}` and an undeclared prop arrives as
3813
4015
  // `undefined`. A construction-time snapshot, so reading it per frame is
3814
4016
  // honest (I-7).
3815
- teamRegistered: controller.isTeamRegistered(), governanceRegistered: controller.isGovernanceRegistered(), memoryRegistered: typeof controller.getMemoryService === 'function' && controller.getMemoryService() !== undefined, ...(terminal?.enhancedKeys === undefined ? {} : { enhancedKeys: terminal.enhancedKeys }), probe: probe, onProfileSave: handleProfileSave, onReload: () => controller.createModelSettingsDraft(), onClose: () => dispatch({ type: 'setOverlay', overlay: null }),
4017
+ teamRegistered: controller.isTeamRegistered(), governanceRegistered: controller.isGovernanceRegistered(), memoryRegistered: typeof controller.getMemoryService === 'function' && controller.getMemoryService() !== undefined,
4018
+ // The counters the Memory page prints beside the rows that set them
4019
+ // (memory-agent-autonomy 10.1). The same live view the status chip reads.
4020
+ memoryView: memoryView, ...(terminal?.enhancedKeys === undefined ? {} : { enhancedKeys: terminal.enhancedKeys }), probe: probe, onProfileSave: handleProfileSave, onReload: () => controller.createModelSettingsDraft(), onClose: () => dispatch({ type: 'setOverlay', overlay: null }),
3816
4021
  // Read from `cfg` (render scope, re-read every frame), so `/retry off`
3817
4022
  // while the screen is open shows the new value on the next paint.
3818
4023
  // THE LADDER IS PART OF THE ANSWER (AC-17): `API retries: 10` would keep
@@ -3828,7 +4033,15 @@ export function App({ controller, version, initialOverlay, initialPrompt, confir
3828
4033
  // THE WAIVER (red-team-security-mode 4.3). Rendered from the reducer's overlay field like
3829
4034
  // every other surface, so it cannot be open at the same time as a decision dialog - the
3830
4035
  // requests that would have replaced it are queued in `queuedDecisions` instead (D-21).
3831
- _jsx(RedTeamDisclaimerOverlay, { isActive: !tooSmall, cols: viewCols, maxRows: overlayMaxRows, theme: theme, caps: caps, onAccept: acceptRedTeamWaiver, onDecline: declineRedTeamWaiver })) : overlay === 'confirm' && confirmState ? (_jsx(ConfirmDialog, { isActive: !tooSmall, state: confirmState, maxRows: overlayMaxRows, cols: viewCols, theme: theme, caps: caps, onClose: closeConfirm })) : overlay === 'question' && humanRequest?.kind === 'questions' ? (_jsx(QuestionOverlay, { isActive: !tooSmall, questions: humanRequest.questions, maxRows: overlayMaxRows, cols: viewCols, theme: theme, caps: caps, onSubmit: (answers) => resolveHuman({ kind: 'answers', answers, cancelled: false }), ...interviewProps })) : overlay === 'plan' && humanRequest?.kind === 'plan' ? (_jsx(PlanReviewOverlay, { isActive: !tooSmall, plan: humanRequest.plan, maxRows: overlayMaxRows, cols: viewCols, scrollOffset: overlayScroll, onScrollClamp: setOverlayScroll, theme: theme, caps: caps, onVerdict: handlePlanVerdict })) : null;
4036
+ _jsx(RedTeamDisclaimerOverlay, { isActive: !tooSmall, cols: viewCols, maxRows: overlayMaxRows, theme: theme, caps: caps, onAccept: acceptRedTeamWaiver, onDecline: declineRedTeamWaiver })) : overlay === 'login' ? (
4037
+ // THE SIGN-IN PANEL (C6). THE BRANCH AND THE `Overlay` MEMBER SHIP TOGETHER (R-11), like
4038
+ // `agents` and `governance` above: a missing branch is not a type error, it is a SILENT
4039
+ // BLANK FRAME behind a keyboard that `active={overlay === null}` has already disabled.
4040
+ //
4041
+ // `onStart` runs the flow; `onClose` HIDES the panel and nothing else - the device poll it
4042
+ // started keeps running and reports through `settleLogin`, which is why a success notice
4043
+ // can still arrive after the user pressed Esc.
4044
+ _jsx(LoginOverlay, { isActive: !tooSmall, phase: loginView.phase, link: loginView.link, code: loginView.code, elapsedSec: loginView.elapsedSec, ...(loginView.account === null ? {} : { account: loginView.account }), ...(loginView.message === '' ? {} : { message: loginView.message }), maxRows: overlayMaxRows, cols: viewCols, theme: theme, caps: caps, onStart: () => { void startLoginFlow(); }, onClose: () => dispatch({ type: 'setOverlay', overlay: null }) })) : overlay === 'confirm' && confirmState ? (_jsx(ConfirmDialog, { isActive: !tooSmall, state: confirmState, maxRows: overlayMaxRows, cols: viewCols, theme: theme, caps: caps, onClose: closeConfirm })) : overlay === 'question' && humanRequest?.kind === 'questions' ? (_jsx(QuestionOverlay, { isActive: !tooSmall, questions: humanRequest.questions, maxRows: overlayMaxRows, cols: viewCols, theme: theme, caps: caps, onSubmit: (answers) => resolveHuman({ kind: 'answers', answers, cancelled: false }), ...interviewProps })) : overlay === 'plan' && humanRequest?.kind === 'plan' ? (_jsx(PlanReviewOverlay, { isActive: !tooSmall, plan: humanRequest.plan, maxRows: overlayMaxRows, cols: viewCols, scrollOffset: overlayScroll, onScrollClamp: setOverlayScroll, theme: theme, caps: caps, onVerdict: handlePlanVerdict })) : null;
3832
4045
  const density = cfg.density;
3833
4046
  const transcriptWindow = cfg.transcriptWindow ?? DEFAULT_TRANSCRIPT_WINDOW;
3834
4047
  // The fixed status bar remains visible underneath every overlay and toast.
package/dist/cli.js CHANGED
@@ -412,7 +412,7 @@ async function runInteractive(flags, extras = {}) {
412
412
  // MUTABLE BECAUSE `/resume` ROTATES IT (D-15). The chip follows through the
413
413
  // App's `onIdentity`, and the writer reads `parentId` from here on every write.
414
414
  let identity = startup.identity;
415
- const { controller, confirmBridge, humanInputBridge } = makeController(flags, {
415
+ const { controller, confirmBridge, humanInputBridge, noticeBridge } = makeController(flags, {
416
416
  interactive: true,
417
417
  // THE ONE LAUNCH PATH THAT MAY START ARMED (4.8). `flags.redteam` is already tri-state and
418
418
  // the `preAction` hook has already refused the two impossible combinations, so this is a
@@ -1147,7 +1147,7 @@ async function runInteractive(flags, extras = {}) {
1147
1147
  config.update.mode !== 'off';
1148
1148
  let instance;
1149
1149
  try {
1150
- instance = render(_jsx(App, { controller: controller, version: VERSION, confirmBridge: confirmBridge, humanInputBridge: humanInputBridge, initialPrompt: extras.initialPrompt, initialOverlay: extras.initialOverlay, mouseSource: mouseOn && filter ? filter.source : undefined,
1150
+ instance = render(_jsx(App, { controller: controller, version: VERSION, confirmBridge: confirmBridge, humanInputBridge: humanInputBridge, noticeBridge: noticeBridge, initialPrompt: extras.initialPrompt, initialOverlay: extras.initialOverlay, mouseSource: mouseOn && filter ? filter.source : undefined,
1151
1151
  // Present ONLY when this console swallows `CSI Z` and mouse reports.
1152
1152
  // Passed in rather than probed inside `App` so that every test renders
1153
1153
  // the same tree on every machine — reading `process.versions.node` from
@@ -0,0 +1,86 @@
1
+ /**
2
+ * `/login` and `/logout` (C5): the two slash commands over the CLI's account layer.
3
+ *
4
+ * WHAT LIVES HERE AND WHY. The command body lives in its own module for the reason
5
+ * `agents-command.ts`, `kit-command.ts` and `queue-command.ts` record: `builtins.ts` is past the
6
+ * thousand-line guideline. The network and the credential file are NOT here either - they are
7
+ * `account/login-flow.ts` and `account/store.ts`; this module turns a status into transcript
8
+ * lines and asks the App to open the sign-in panel.
9
+ *
10
+ * THE PORT SEAM (`AccountCommandPort`), AND WHY IT IS A MODULE-LEVEL REGISTRATION rather than a
11
+ * field on `CommandContext`: this work package owns this file and `App.tsx` but NOT
12
+ * `commands/registry.ts`, where `CommandContext` is declared, and adding a required field to it
13
+ * would break the dozens of fixtures in this package that build the context by literal. The App
14
+ * installs the port from `makeCtx` and replaces it on every command run, so a stale App instance
15
+ * cannot outlive its own panel. With NO port installed the two commands answer honestly instead
16
+ * of throwing or reaching for the network - which is what a headless context, a sub-agent and a
17
+ * host double must get.
18
+ *
19
+ * ASCII ONLY - `commands/` is inside `glyphs.test.ts::inScope`, and these strings reach a
20
+ * legacy console.
21
+ */
22
+ import type { CommandRegistry } from './registry.js';
23
+ import type { AccountStatus } from '../account/session.js';
24
+ /** C5, verbatim. `catalog.ts` and `BUILTIN_COMMAND_NAMES` carry the same bytes. */
25
+ export declare const LOGIN_DESCRIPTION = "Sign in with your aragonagent.com account (20 days); no args shows status";
26
+ /** C5, verbatim. */
27
+ export declare const LOGOUT_DESCRIPTION = "Sign out and delete the local account credential";
28
+ /** What `/logout` did. `ok: false` means the credential file is still there. */
29
+ export interface AccountSignOutResult {
30
+ readonly ok: boolean;
31
+ /** Whether a credential existed before the delete, so "nothing to do" is not "deleted". */
32
+ readonly hadCredential: boolean;
33
+ }
34
+ /**
35
+ * The App's side of the feature: read the credential, open the panel, delete the credential.
36
+ *
37
+ * THREE METHODS, NOT ONE, because they are three different user intentions and the command has
38
+ * to report each one truthfully: `status` is a read, `openLogin` starts a device flow the App
39
+ * owns (so `/login` returns before the person has touched their phone), and `signOut` must be
40
+ * able to answer "nothing to delete" as well as "still there, the filesystem refused".
41
+ */
42
+ export interface AccountCommandPort {
43
+ /** Fresh read. The App reads the file, so `/login` never shows a cached credential. */
44
+ status(): AccountStatus;
45
+ /** Absolute path of `<home>/account.json`, for the reports below. */
46
+ accountPath(): string;
47
+ /** Open the four-phase panel and run `startLogin` in the background (C6). */
48
+ openLogin(): void;
49
+ signOut(): AccountSignOutResult;
50
+ }
51
+ /**
52
+ * Install (or clear) the App's account port.
53
+ *
54
+ * CALLED FROM `App.tsx::makeCtx`, so the port always belongs to the App that is running the
55
+ * command. `null` removes it, which is how a test - or an App that unmounts - leaves the two
56
+ * commands answering the honest "not available" branch.
57
+ */
58
+ export declare function setAccountCommandPort(port: AccountCommandPort | null): void;
59
+ /** The installed port, or `null` in a context that has none. */
60
+ export declare function getAccountCommandPort(): AccountCommandPort | null;
61
+ /**
62
+ * The report `/login` prints before it opens the panel: the state first, then the three facts a
63
+ * user can act on.
64
+ *
65
+ * THE TOKEN IS NEVER ONE OF THEM. `tokenPrefix` is what `account.json` already stores for
66
+ * exactly this purpose (`sha256` lives on the server; the prefix is the identifier a person
67
+ * recognises), and it is printed with a trailing `...` so nobody mistakes it for the secret.
68
+ * The full token is not reachable from `AccountStatus` at all, which is the structural half of
69
+ * "never show a plaintext token": this module has no API that could return one.
70
+ */
71
+ export declare function accountStatusLines(status: AccountStatus, accountPath: string): string[];
72
+ /**
73
+ * The ONE startup line for the credential, or `null` when there is nothing to say (spec 6.6).
74
+ *
75
+ * `expiring` gets the account layer's own wording (it names the days left and `/login`);
76
+ * `expired` gets `describeExpiry`, because a credential that stopped working is not "expiring"
77
+ * and the user has to be told to sign in again rather than "renew". `signed-out` and `valid`
78
+ * stay completely silent: a terminal that greets a guest with a sign-in pitch on every launch is
79
+ * nagging, and the panel is one keystroke away.
80
+ *
81
+ * RETURNING A STRING RATHER THAN DISPATCHING keeps the "one notice per launch" rule in the App
82
+ * (a ref guard there) and lets this be asserted without mounting a terminal.
83
+ */
84
+ export declare function startupAccountNotice(status: AccountStatus): string | null;
85
+ /** Register both commands. Unconditional, so they can always explain a missing port. */
86
+ export declare function registerAccountCommands(registry: CommandRegistry): void;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * `/login` and `/logout` (C5): the two slash commands over the CLI's account layer.
3
+ *
4
+ * WHAT LIVES HERE AND WHY. The command body lives in its own module for the reason
5
+ * `agents-command.ts`, `kit-command.ts` and `queue-command.ts` record: `builtins.ts` is past the
6
+ * thousand-line guideline. The network and the credential file are NOT here either - they are
7
+ * `account/login-flow.ts` and `account/store.ts`; this module turns a status into transcript
8
+ * lines and asks the App to open the sign-in panel.
9
+ *
10
+ * THE PORT SEAM (`AccountCommandPort`), AND WHY IT IS A MODULE-LEVEL REGISTRATION rather than a
11
+ * field on `CommandContext`: this work package owns this file and `App.tsx` but NOT
12
+ * `commands/registry.ts`, where `CommandContext` is declared, and adding a required field to it
13
+ * would break the dozens of fixtures in this package that build the context by literal. The App
14
+ * installs the port from `makeCtx` and replaces it on every command run, so a stale App instance
15
+ * cannot outlive its own panel. With NO port installed the two commands answer honestly instead
16
+ * of throwing or reaching for the network - which is what a headless context, a sub-agent and a
17
+ * host double must get.
18
+ *
19
+ * ASCII ONLY - `commands/` is inside `glyphs.test.ts::inScope`, and these strings reach a
20
+ * legacy console.
21
+ */
22
+ import { describeExpiry, describeStartupNotice, formatIsoDate } from '../account/format.js';
23
+ /** C5, verbatim. `catalog.ts` and `BUILTIN_COMMAND_NAMES` carry the same bytes. */
24
+ export const LOGIN_DESCRIPTION = 'Sign in with your aragonagent.com account (20 days); no args shows status';
25
+ /** C5, verbatim. */
26
+ export const LOGOUT_DESCRIPTION = 'Sign out and delete the local account credential';
27
+ /**
28
+ * Said when the build has no account port. NAMING WHAT DID NOT HAPPEN IS THE POINT: a user who
29
+ * reads "sign-in is not available" must not wonder whether a request went out or a file was
30
+ * written, and neither must a reviewer reading a headless log.
31
+ */
32
+ const NO_PORT_MESSAGE = 'Sign-in is not available in this session (no account port). Nothing was sent and no ' +
33
+ 'credential file was touched.';
34
+ let installedPort = null;
35
+ /**
36
+ * Install (or clear) the App's account port.
37
+ *
38
+ * CALLED FROM `App.tsx::makeCtx`, so the port always belongs to the App that is running the
39
+ * command. `null` removes it, which is how a test - or an App that unmounts - leaves the two
40
+ * commands answering the honest "not available" branch.
41
+ */
42
+ export function setAccountCommandPort(port) {
43
+ installedPort = port;
44
+ }
45
+ /** The installed port, or `null` in a context that has none. */
46
+ export function getAccountCommandPort() {
47
+ return installedPort;
48
+ }
49
+ /** `3 days` / `1 day`, so a one-day credential does not read as "1 days". */
50
+ function pluralDays(count) {
51
+ return count === 1 ? '1 day' : `${count} days`;
52
+ }
53
+ /**
54
+ * The report `/login` prints before it opens the panel: the state first, then the three facts a
55
+ * user can act on.
56
+ *
57
+ * THE TOKEN IS NEVER ONE OF THEM. `tokenPrefix` is what `account.json` already stores for
58
+ * exactly this purpose (`sha256` lives on the server; the prefix is the identifier a person
59
+ * recognises), and it is printed with a trailing `...` so nobody mistakes it for the secret.
60
+ * The full token is not reachable from `AccountStatus` at all, which is the structural half of
61
+ * "never show a plaintext token": this module has no API that could return one.
62
+ */
63
+ export function accountStatusLines(status, accountPath) {
64
+ const lines = [describeExpiry(status)];
65
+ lines.push(` credential ${accountPath}`);
66
+ if (status.user !== null)
67
+ lines.push(` user ${status.user.username}`);
68
+ const prefix = status.tokenPrefix === null ? 'none' : `${status.tokenPrefix}...`;
69
+ lines.push(` token ${prefix} (prefix only)`);
70
+ if (status.expiresAt !== null) {
71
+ const left = status.state === 'expired' ? 'expired' : `${pluralDays(status.daysLeft)} left`;
72
+ lines.push(` expires ${formatIsoDate(status.expiresAt)} (${left})`);
73
+ }
74
+ lines.push(status.state === 'signed-out'
75
+ ? ' /login press Enter in the panel to sign in'
76
+ : ' /login press Enter in the panel to sign in again; this credential is replaced');
77
+ return lines;
78
+ }
79
+ /**
80
+ * The ONE startup line for the credential, or `null` when there is nothing to say (spec 6.6).
81
+ *
82
+ * `expiring` gets the account layer's own wording (it names the days left and `/login`);
83
+ * `expired` gets `describeExpiry`, because a credential that stopped working is not "expiring"
84
+ * and the user has to be told to sign in again rather than "renew". `signed-out` and `valid`
85
+ * stay completely silent: a terminal that greets a guest with a sign-in pitch on every launch is
86
+ * nagging, and the panel is one keystroke away.
87
+ *
88
+ * RETURNING A STRING RATHER THAN DISPATCHING keeps the "one notice per launch" rule in the App
89
+ * (a ref guard there) and lets this be asserted without mounting a terminal.
90
+ */
91
+ export function startupAccountNotice(status) {
92
+ if (status.state === 'expiring')
93
+ return describeStartupNotice(status) ?? describeExpiry(status);
94
+ if (status.state === 'expired')
95
+ return describeExpiry(status);
96
+ return null;
97
+ }
98
+ /** The shared first half of both commands. */
99
+ function resolvePort(ctx) {
100
+ const port = installedPort;
101
+ if (port === null)
102
+ ctx.notify('warn', NO_PORT_MESSAGE);
103
+ return port;
104
+ }
105
+ /**
106
+ * `/login [status]`.
107
+ *
108
+ * NO ARGS MEANS "SHOW ME WHERE I STAND, THEN LET ME SIGN IN": the report is printed and the
109
+ * panel opens in its `prompt` phase, where Enter starts the device flow. `status` prints the
110
+ * report and stops. Anything else is refused with the usage line rather than ignored, so a typo
111
+ * cannot be mistaken for a start.
112
+ */
113
+ function runLogin(ctx) {
114
+ const arg = ctx.args.trim().toLowerCase();
115
+ if (arg !== '' && arg !== 'status') {
116
+ ctx.notify('warn', `Unknown argument "${arg}" - use /login [status].`);
117
+ return;
118
+ }
119
+ const port = resolvePort(ctx);
120
+ if (port === null)
121
+ return;
122
+ for (const line of accountStatusLines(port.status(), port.accountPath())) {
123
+ ctx.notify('info', line);
124
+ }
125
+ if (arg === 'status')
126
+ return;
127
+ port.openLogin();
128
+ }
129
+ /**
130
+ * `/logout`.
131
+ *
132
+ * THREE ANSWERS, NOT TWO: deleted, nothing to delete, and the filesystem refused. Collapsing the
133
+ * last one into a cheerful "signed out" would leave a live 20-day bearer token on disk while the
134
+ * user believes it is gone, and that is the one failure of this command that matters.
135
+ */
136
+ function runLogout(ctx) {
137
+ const port = resolvePort(ctx);
138
+ if (port === null)
139
+ return;
140
+ const result = port.signOut();
141
+ if (!result.ok) {
142
+ ctx.notify('error', `Sign-out failed: the credential at ${port.accountPath()} is still there. ` +
143
+ 'Delete that file by hand or fix its permissions.');
144
+ return;
145
+ }
146
+ if (!result.hadCredential) {
147
+ ctx.notify('info', 'Not signed in - there was no credential to delete.');
148
+ return;
149
+ }
150
+ ctx.notify('info', `Signed out. Deleted ${port.accountPath()}.`);
151
+ ctx.toast('success', 'Signed out.');
152
+ }
153
+ /** Register both commands. Unconditional, so they can always explain a missing port. */
154
+ export function registerAccountCommands(registry) {
155
+ registry.register({
156
+ name: 'login',
157
+ description: LOGIN_DESCRIPTION,
158
+ run: runLogin,
159
+ });
160
+ registry.register({
161
+ name: 'logout',
162
+ description: LOGOUT_DESCRIPTION,
163
+ run: runLogout,
164
+ });
165
+ }
@@ -43,6 +43,11 @@ import { registerRedTeamCommand } from './redteam-command.js';
43
43
  // UNCONDITIONAL, even with `taskSummary.enabled=false`, because they are the only
44
44
  // surfaces that can explain the switch.
45
45
  import { keysCommand } from './keys-command.js';
46
+ // `/login` and `/logout` (C5 of the CLI login work package): the body is
47
+ // `commands/account-command.ts` and this import is the whole registration, the `/team` shape.
48
+ // UNCONDITIONAL: a session with no account port is exactly where a user types `/login` to find
49
+ // out why, so registering them may not read the credential file or send a request.
50
+ import { registerAccountCommands } from './account-command.js';
46
51
  import { taskCommand } from './task-command.js';
47
52
  import { perfCommand } from './perf.js';
48
53
  import { runCompactCommand } from '../compaction/command.js';
@@ -1352,6 +1357,12 @@ export function registerBuiltinCommands(registry) {
1352
1357
  // the same overlay `Ctrl+G` opens, and `/task` reports what the header cell says.
1353
1358
  registry.register(keysCommand);
1354
1359
  registry.register(taskCommand);
1360
+ // `/login` and `/logout`. Registered HERE rather than from `COMMANDS` because their bodies
1361
+ // live in `commands/account-command.ts` (this file is past the 1000-line guideline), and
1362
+ // UNCONDITIONALLY for the reason the import records: the session that cannot sign in is the
1363
+ // one where the commands have to be able to say so. `BUILTIN_COMMAND_NAMES` below lists both
1364
+ // by hand for the same reason it lists `team` and `retry`.
1365
+ registerAccountCommands(registry);
1355
1366
  }
1356
1367
  /**
1357
1368
  * Every built-in command name INCLUDING aliases (`quit`), for documentation and
@@ -1373,6 +1384,10 @@ export const BUILTIN_COMMAND_NAMES = ['queue', 'prompts', 'agents', 'subagent',
1373
1384
  // `commands/retry-command.ts`, so the `flatMap` below no longer sees it.
1374
1385
  'retry',
1375
1386
  'keys', 'task',
1387
+ // `login` / `logout` join the list for the reason `team` above records: their bodies live in
1388
+ // `commands/account-command.ts`, so the `flatMap` below never sees them, and this array is the
1389
+ // documentation/tests surface for every built-in name (C5 requires both, verbatim).
1390
+ 'login', 'logout',
1376
1391
  ...COMMANDS.flatMap((c) => [
1377
1392
  c.name,
1378
1393
  ...(c.aliases ?? []),
@@ -43,7 +43,7 @@ export const BUILTIN_COMMAND_CATALOG = [
43
43
  { name: 'queue', aliases: [], description: '\u67e5\u770b\u5f85\u5904\u7406\u6d88\u606f\u5168\u6587' },
44
44
  { name: 'kit', aliases: [], description: 'Agent kits: status, list, use for this session' },
45
45
  { name: 'prompts', aliases: [], description: 'Quick prompt library: pick, list, add, edit, remove, reorder' },
46
- { name: 'memory', aliases: ['mem'], description: 'Memory manager: list, save, show, remove, mount, auto-load, agent writes' },
46
+ { name: 'memory', aliases: ['mem'], description: 'Memory manager: list, save, show, remove, mount, auto-load, agent writes, undo' },
47
47
  { name: 'gene', aliases: ['genes'], description: 'Gene Bank: status, search, show, explain, pin, archive, rollback, queue, stats, export, import, import-memory' },
48
48
  { name: 'agents', aliases: [], description: 'Open the subagent board: every child, its facts and its timeline' },
49
49
  { name: 'subagent', aliases: [], description: 'Deprecated alias of /team - same arguments' },
@@ -59,4 +59,20 @@ export const BUILTIN_COMMAND_CATALOG = [
59
59
  { name: 'gov', aliases: [], description: 'Governed multi-agent team: /gov help' },
60
60
  { name: 'keys', aliases: [], description: 'List every keyboard shortcut (opens the drawer)' },
61
61
  { name: 'task', aliases: [], description: 'Show the header task summary (/task refresh regenerates it)' },
62
+ // Device-flow sign-in (C5 of the CLI login work package). Listed here so the slash palette
63
+ // advertises it. The wording is retyped rather than imported from `account-command.ts` on
64
+ // purpose: this module is what the desktop host serves and must stay a leaf (no config, no
65
+ // filesystem, no logger behind it), and `__tests__/command-catalog.test.ts` already compares
66
+ // every description against the live registry - that test, not a shared constant, is what
67
+ // keeps these bytes equal to `/login`'s.
68
+ {
69
+ name: 'login',
70
+ aliases: [],
71
+ description: 'Sign in with your aragonagent.com account (20 days); no args shows status',
72
+ },
73
+ {
74
+ name: 'logout',
75
+ aliases: [],
76
+ description: 'Sign out and delete the local account credential',
77
+ },
62
78
  ];