@aragon-agent/cli 0.6.71 → 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.
@@ -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 ?? []),
@@ -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
  ];
@@ -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.72",
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.84",
62
+ "@aragon-agent/tui": "0.0.25",
63
63
  "commander": "^12.1.0",
64
64
  "dotenv": "^16.6.1",
65
65
  "env-paths": "^3.0.0",