@aragon-agent/cli 0.6.71 → 0.6.73

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.
@@ -0,0 +1,194 @@
1
+ /**
2
+ * `/login`, `/logout` (C5) and `/account` (tui-account-identity-and-panel A7): the slash commands
3
+ * over the CLI's account layer.
4
+ *
5
+ * WHAT LIVES HERE AND WHY. The command body lives in its own module for the reason
6
+ * `agents-command.ts`, `kit-command.ts` and `queue-command.ts` record: `builtins.ts` is past the
7
+ * thousand-line guideline. The network and the credential file are NOT here either - they are
8
+ * `account/login-flow.ts` and `account/store.ts`; this module turns a status into transcript
9
+ * lines and asks the App to open the sign-in panel.
10
+ *
11
+ * THE PORT SEAM (`AccountCommandPort`), AND WHY IT IS A MODULE-LEVEL REGISTRATION rather than a
12
+ * field on `CommandContext`: this work package owns this file and `App.tsx` but NOT
13
+ * `commands/registry.ts`, where `CommandContext` is declared, and adding a required field to it
14
+ * would break the dozens of fixtures in this package that build the context by literal. The App
15
+ * installs the port from `makeCtx` and replaces it on every command run, so a stale App instance
16
+ * cannot outlive its own panel. With NO port installed the two commands answer honestly instead
17
+ * of throwing or reaching for the network - which is what a headless context, a sub-agent and a
18
+ * host double must get.
19
+ *
20
+ * ASCII ONLY - `commands/` is inside `glyphs.test.ts::inScope`, and these strings reach a
21
+ * legacy console.
22
+ */
23
+ import { describeExpiry, describeStartupNotice, formatIsoDate } from '../account/format.js';
24
+ /** C5, verbatim. `catalog.ts` and `BUILTIN_COMMAND_NAMES` carry the same bytes. */
25
+ export const LOGIN_DESCRIPTION = 'Sign in with your aragonagent.com account (20 days); no args shows status';
26
+ /** C5, verbatim. */
27
+ export const LOGOUT_DESCRIPTION = 'Sign out and delete the local account credential';
28
+ /**
29
+ * `/account` (tui-account-identity-and-panel A7). THE SAME BYTES live in
30
+ * `commands/catalog.ts` and in `docs/guide-doc/src/content/data/slash-commands.mjs`, and the
31
+ * guide's gate compares them character for character - a reworded copy is a red build, which
32
+ * is the only thing that keeps three surfaces honest.
33
+ */
34
+ export const ACCOUNT_DESCRIPTION = 'Open the account panel: who is signed in, the token expiry, sign in or sign out';
35
+ /**
36
+ * Said when the build has no account port. NAMING WHAT DID NOT HAPPEN IS THE POINT: a user who
37
+ * reads "sign-in is not available" must not wonder whether a request went out or a file was
38
+ * written, and neither must a reviewer reading a headless log.
39
+ */
40
+ const NO_PORT_MESSAGE = 'Sign-in is not available in this session (no account port). Nothing was sent and no ' +
41
+ 'credential file was touched.';
42
+ let installedPort = null;
43
+ /**
44
+ * Install (or clear) the App's account port.
45
+ *
46
+ * CALLED FROM `App.tsx::makeCtx`, so the port always belongs to the App that is running the
47
+ * command. `null` removes it, which is how a test - or an App that unmounts - leaves the two
48
+ * commands answering the honest "not available" branch.
49
+ */
50
+ export function setAccountCommandPort(port) {
51
+ installedPort = port;
52
+ }
53
+ /** The installed port, or `null` in a context that has none. */
54
+ export function getAccountCommandPort() {
55
+ return installedPort;
56
+ }
57
+ /** `3 days` / `1 day`, so a one-day credential does not read as "1 days". */
58
+ function pluralDays(count) {
59
+ return count === 1 ? '1 day' : `${count} days`;
60
+ }
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 function accountStatusLines(status, accountPath) {
72
+ const lines = [describeExpiry(status)];
73
+ lines.push(` credential ${accountPath}`);
74
+ if (status.user !== null)
75
+ lines.push(` user ${status.user.username}`);
76
+ const prefix = status.tokenPrefix === null ? 'none' : `${status.tokenPrefix}...`;
77
+ lines.push(` token ${prefix} (prefix only)`);
78
+ if (status.expiresAt !== null) {
79
+ const left = status.state === 'expired' ? 'expired' : `${pluralDays(status.daysLeft)} left`;
80
+ lines.push(` expires ${formatIsoDate(status.expiresAt)} (${left})`);
81
+ }
82
+ lines.push(status.state === 'signed-out'
83
+ ? ' /login press Enter in the panel to sign in'
84
+ : ' /login press Enter in the panel to sign in again; this credential is replaced');
85
+ return lines;
86
+ }
87
+ /**
88
+ * The ONE startup line for the credential, or `null` when there is nothing to say (spec 6.6).
89
+ *
90
+ * `expiring` gets the account layer's own wording (it names the days left and `/login`);
91
+ * `expired` gets `describeExpiry`, because a credential that stopped working is not "expiring"
92
+ * and the user has to be told to sign in again rather than "renew". `signed-out` and `valid`
93
+ * stay completely silent: a terminal that greets a guest with a sign-in pitch on every launch is
94
+ * nagging, and the panel is one keystroke away.
95
+ *
96
+ * RETURNING A STRING RATHER THAN DISPATCHING keeps the "one notice per launch" rule in the App
97
+ * (a ref guard there) and lets this be asserted without mounting a terminal.
98
+ */
99
+ export function startupAccountNotice(status) {
100
+ if (status.state === 'expiring')
101
+ return describeStartupNotice(status) ?? describeExpiry(status);
102
+ if (status.state === 'expired')
103
+ return describeExpiry(status);
104
+ return null;
105
+ }
106
+ /** The shared first half of both commands. */
107
+ function resolvePort(ctx) {
108
+ const port = installedPort;
109
+ if (port === null)
110
+ ctx.notify('warn', NO_PORT_MESSAGE);
111
+ return port;
112
+ }
113
+ /**
114
+ * `/login [status]`.
115
+ *
116
+ * NO ARGS MEANS "SHOW ME WHERE I STAND, THEN LET ME SIGN IN": the report is printed and the
117
+ * panel opens in its `prompt` phase, where Enter starts the device flow. `status` prints the
118
+ * report and stops. Anything else is refused with the usage line rather than ignored, so a typo
119
+ * cannot be mistaken for a start.
120
+ */
121
+ function runLogin(ctx) {
122
+ const arg = ctx.args.trim().toLowerCase();
123
+ if (arg !== '' && arg !== 'status') {
124
+ ctx.notify('warn', `Unknown argument "${arg}" - use /login [status].`);
125
+ return;
126
+ }
127
+ const port = resolvePort(ctx);
128
+ if (port === null)
129
+ return;
130
+ for (const line of accountStatusLines(port.status(), port.accountPath())) {
131
+ ctx.notify('info', line);
132
+ }
133
+ if (arg === 'status')
134
+ return;
135
+ port.openLogin();
136
+ }
137
+ /**
138
+ * `/logout`.
139
+ *
140
+ * THREE ANSWERS, NOT TWO: deleted, nothing to delete, and the filesystem refused. Collapsing the
141
+ * last one into a cheerful "signed out" would leave a live 20-day bearer token on disk while the
142
+ * user believes it is gone, and that is the one failure of this command that matters.
143
+ */
144
+ function runLogout(ctx) {
145
+ const port = resolvePort(ctx);
146
+ if (port === null)
147
+ return;
148
+ const result = port.signOut();
149
+ if (!result.ok) {
150
+ ctx.notify('error', `Sign-out failed: the credential at ${port.accountPath()} is still there. ` +
151
+ 'Delete that file by hand or fix its permissions.');
152
+ return;
153
+ }
154
+ if (!result.hadCredential) {
155
+ ctx.notify('info', 'Not signed in - there was no credential to delete.');
156
+ return;
157
+ }
158
+ ctx.notify('info', `Signed out. Deleted ${port.accountPath()}.`);
159
+ ctx.toast('success', 'Signed out.');
160
+ }
161
+ /**
162
+ * `/account` (tui-account-identity-and-panel A7).
163
+ *
164
+ * THE THIRD ROUTE TO THE PANEL, and the only one that survives a terminal which swallows both
165
+ * `Ctrl+X` and `Alt+X` - the same reason `/memory` and `/gene` exist beside their keys. It
166
+ * prints the ONE sentence `describeExpiry` owns and then opens the panel: the panel is where
167
+ * the facts and the two actions live, and printing every field twice would give the same
168
+ * numbers two places to be wrong.
169
+ */
170
+ function runAccount(ctx) {
171
+ const port = resolvePort(ctx);
172
+ if (port === null)
173
+ return;
174
+ ctx.notify('info', describeExpiry(port.status()));
175
+ port.openAccount();
176
+ }
177
+ /** Register all three commands. Unconditional, so they can always explain a missing port. */
178
+ export function registerAccountCommands(registry) {
179
+ registry.register({
180
+ name: 'login',
181
+ description: LOGIN_DESCRIPTION,
182
+ run: runLogin,
183
+ });
184
+ registry.register({
185
+ name: 'logout',
186
+ description: LOGOUT_DESCRIPTION,
187
+ run: runLogout,
188
+ });
189
+ registry.register({
190
+ name: 'account',
191
+ description: ACCOUNT_DESCRIPTION,
192
+ run: runAccount,
193
+ });
194
+ }
@@ -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,14 @@ 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',
1391
+ // `account` joins them for the same reason (tui-account-identity-and-panel A7): its body lives
1392
+ // in `commands/account-command.ts`, so this array is the only documentation surface that sees
1393
+ // it, and `command-catalog.test.ts` compares the catalog against the live registry.
1394
+ 'account',
1376
1395
  ...COMMANDS.flatMap((c) => [
1377
1396
  c.name,
1378
1397
  ...(c.aliases ?? []),
@@ -59,4 +59,28 @@ 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
+ },
78
+ // `/account` (tui-account-identity-and-panel A7): the third route to the panel, for the
79
+ // terminals where Ctrl+X and Alt+X both get swallowed. Retyped here for the reason the two
80
+ // rows above record - `command-catalog.test.ts` is what keeps these bytes equal.
81
+ {
82
+ name: 'account',
83
+ aliases: [],
84
+ description: 'Open the account panel: who is signed in, the token expiry, sign in or sign out',
85
+ },
62
86
  ];
@@ -14,6 +14,7 @@
14
14
  * ├── config.json.bak `aragon config edit` pre-edit backup
15
15
  * ├── model-windows.json per-model context windows, user-edited
16
16
  * ├── prompt-history.jsonl submitted prompts, append-only (0600 on POSIX)
17
+ * ├── account.json device-flow credentials, 0600 on POSIX (`aragon login`)
17
18
  * ├── state.json UI bookkeeping scalars (0600 on POSIX)
18
19
  * ├── update-state.json auto-update coordination (0600 on POSIX)
19
20
  * ├── update-install.lock held by the running `npm i -g` child
@@ -106,6 +107,20 @@ export declare function getPromptHistoryPath(): string;
106
107
  * Naming follows `getPromptHistoryPath` beside it.
107
108
  */
108
109
  export declare function getQuickPromptsPath(): string;
110
+ /**
111
+ * <home>/account.json - the device-flow credential (C3 of the CLI login work package).
112
+ *
113
+ * A DIRECT CHILD OF THE ROOT, for the reason the four files above record: `logs/`,
114
+ * `sessions/` and `skills/` are SCAN roots, and a credential inside one of them is one
115
+ * more file every walk has to recognise and skip - and one careless recursive delete
116
+ * away from being gone. A sibling of `config.json`, not a child of any directory.
117
+ *
118
+ * It holds a BEARER TOKEN in plaintext, which is why `account/store.ts` writes it
119
+ * 0600 on POSIX through a temp file plus rename. Derived from the same
120
+ * `resolution.root`, so the `ARAGON_HOME` / VITEST isolation contract at the top of
121
+ * this file covers it too.
122
+ */
123
+ export declare function getAccountPath(): string;
109
124
  /** `<home>/state.json` — UI bookkeeping scalars only; see `ui-state.ts`. */
110
125
  export declare function getUiStatePath(): string;
111
126
  /**
@@ -14,6 +14,7 @@
14
14
  * ├── config.json.bak `aragon config edit` pre-edit backup
15
15
  * ├── model-windows.json per-model context windows, user-edited
16
16
  * ├── prompt-history.jsonl submitted prompts, append-only (0600 on POSIX)
17
+ * ├── account.json device-flow credentials, 0600 on POSIX (`aragon login`)
17
18
  * ├── state.json UI bookkeeping scalars (0600 on POSIX)
18
19
  * ├── update-state.json auto-update coordination (0600 on POSIX)
19
20
  * ├── update-install.lock held by the running `npm i -g` child
@@ -183,6 +184,22 @@ export function getPromptHistoryPath() {
183
184
  export function getQuickPromptsPath() {
184
185
  return join(resolution.root, 'quick-prompts.json');
185
186
  }
187
+ /**
188
+ * <home>/account.json - the device-flow credential (C3 of the CLI login work package).
189
+ *
190
+ * A DIRECT CHILD OF THE ROOT, for the reason the four files above record: `logs/`,
191
+ * `sessions/` and `skills/` are SCAN roots, and a credential inside one of them is one
192
+ * more file every walk has to recognise and skip - and one careless recursive delete
193
+ * away from being gone. A sibling of `config.json`, not a child of any directory.
194
+ *
195
+ * It holds a BEARER TOKEN in plaintext, which is why `account/store.ts` writes it
196
+ * 0600 on POSIX through a temp file plus rename. Derived from the same
197
+ * `resolution.root`, so the `ARAGON_HOME` / VITEST isolation contract at the top of
198
+ * this file covers it too.
199
+ */
200
+ export function getAccountPath() {
201
+ return join(resolution.root, 'account.json');
202
+ }
186
203
  /** `<home>/state.json` — UI bookkeeping scalars only; see `ui-state.ts`. */
187
204
  export function getUiStatePath() {
188
205
  return join(resolution.root, 'state.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aragon-agent/cli",
3
- "version": "0.6.71",
3
+ "version": "0.6.73",
4
4
  "description": "AragonAgent CLI — a Claude-Code / Codex-style interactive terminal UI (TUI) on top of the @aragon-agent/core engine. Installable and runnable via npm / npx.",
5
5
  "license": "MIT",
6
6
  "author": "AragonAgent contributors",
@@ -58,8 +58,8 @@
58
58
  "prepublishOnly": "npm run build"
59
59
  },
60
60
  "dependencies": {
61
- "@aragon-agent/core": "^0.2.83",
62
- "@aragon-agent/tui": "0.0.24",
61
+ "@aragon-agent/core": "^0.2.85",
62
+ "@aragon-agent/tui": "0.0.26",
63
63
  "commander": "^12.1.0",
64
64
  "dotenv": "^16.6.1",
65
65
  "env-paths": "^3.0.0",