@agentage/cli 0.64.1 → 0.65.1
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/dist/commands/extension/lifecycle-list.js +8 -0
- package/dist/commands/status/status.js +3 -0
- package/dist/lib/auth/account-user.d.ts +5 -0
- package/dist/lib/auth/account-user.js +22 -0
- package/dist/lib/auth/callback-page.d.ts +1 -1
- package/dist/lib/auth/callback-page.js +16 -3
- package/dist/lib/auth/callback-server.d.ts +1 -1
- package/dist/lib/auth/callback-server.js +4 -2
- package/dist/lib/auth/return-link.d.ts +2 -0
- package/dist/lib/auth/return-link.js +8 -0
- package/dist/lib/auth/sign-in.d.ts +2 -0
- package/dist/lib/auth/sign-in.js +22 -2
- package/dist/lib/update/update-cache.d.ts +1 -0
- package/dist/lib/update/update-cache.js +5 -0
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import {} from '../../lib/daemon/host-client.js';
|
|
2
3
|
import { CliError, messageOf, WithMeta } from '../../lib/json-output.js';
|
|
3
4
|
import {} from '../../lib/net/market.js';
|
|
@@ -29,11 +30,18 @@ const available = async (deps) => {
|
|
|
29
30
|
console.error(`skipped ${skipped.map((s) => `${s.id} (${s.reason})`).join(', ')}`);
|
|
30
31
|
return new WithMeta(offered, { skipped });
|
|
31
32
|
};
|
|
33
|
+
// A failed folder row whose folder is gone (a deleted worktree) can only be removed.
|
|
34
|
+
const goneHints = (rows) => {
|
|
35
|
+
for (const r of rows)
|
|
36
|
+
if (r.state === 'failed' && typeof r['path'] === 'string' && !existsSync(r['path']))
|
|
37
|
+
console.error(`${r.id}: its folder is gone; remove the row: agentage extension remove ${r.id}`);
|
|
38
|
+
};
|
|
32
39
|
export const runList = async (opts, deps) => {
|
|
33
40
|
if (opts.available)
|
|
34
41
|
return available(deps);
|
|
35
42
|
const rows = (await (await deps.host()).list()).map(shown);
|
|
36
43
|
printRows(rows);
|
|
44
|
+
goneHints(rows);
|
|
37
45
|
return rows;
|
|
38
46
|
};
|
|
39
47
|
// The market's newest. A market that answers without the id keeps the installed version (one
|
|
@@ -4,6 +4,7 @@ import { resolveAuth } from '../../lib/auth/credentials.js';
|
|
|
4
4
|
import { daemonOfStatus } from './status-daemon.js';
|
|
5
5
|
import { DEFAULT_FQDN, siteFqdn } from '../../lib/net/origins.js';
|
|
6
6
|
import { gatherStatus } from '../../lib/status/status-info.js';
|
|
7
|
+
import { markUpdateReported } from '../../lib/update/update-cache.js';
|
|
7
8
|
import { INSTALL_HINT } from '../../lib/update/update-check.js';
|
|
8
9
|
import { signedInAccount } from '../extension/account.js';
|
|
9
10
|
import { printWarnings, summaryLines } from '../extension/row-lines.js';
|
|
@@ -43,6 +44,8 @@ const updateLine = (update) => {
|
|
|
43
44
|
export const printStatus = (report) => {
|
|
44
45
|
row('version', report.version);
|
|
45
46
|
row('update', updateLine(report.update));
|
|
47
|
+
if (report.update.status.kind !== 'unknown')
|
|
48
|
+
markUpdateReported();
|
|
46
49
|
const t = report.target;
|
|
47
50
|
const targetSuffix = t.reachable ? '' : ' - unreachable';
|
|
48
51
|
// "production" is the default site only: any other production-shaped fqdn came from the override.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cliFetch } from '../net/fetch.js';
|
|
2
|
+
const TIMEOUT_MS = 5_000;
|
|
3
|
+
const userOf = (body) => {
|
|
4
|
+
const user = body?.data?.user;
|
|
5
|
+
const { id, email } = user ?? {};
|
|
6
|
+
return typeof id === 'string' && typeof email === 'string' ? { id, email } : undefined;
|
|
7
|
+
};
|
|
8
|
+
// The user a cloud app host's shell shows: auth answers its exchange with { id, email }, so the
|
|
9
|
+
// local shell reads the same fields. The short token in the answer is dropped, never stored.
|
|
10
|
+
export const fetchAccountUser = async (issuer, accessToken) => {
|
|
11
|
+
try {
|
|
12
|
+
const res = await cliFetch(`${issuer}/account/extension-token`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: { authorization: `Bearer ${accessToken}`, 'content-type': 'application/json' },
|
|
15
|
+
body: JSON.stringify({ extension: 'platform', access: 'read' }),
|
|
16
|
+
}, { timeoutMs: TIMEOUT_MS });
|
|
17
|
+
return res.status === 201 ? userOf(await res.json()) : void (await res.body?.cancel());
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const escapeHtml: (text: string) => string;
|
|
2
|
-
export declare const callbackPage: (ok: boolean, detail: string) => string;
|
|
2
|
+
export declare const callbackPage: (ok: boolean, detail: string, returnLink?: string) => string;
|
|
@@ -19,6 +19,8 @@ box-shadow:0 10px 15px -3px oklch(0 0 0/.1),0 4px 6px -4px oklch(0 0 0/.1)}
|
|
|
19
19
|
h1{font-size:1.25rem;font-weight:600;letter-spacing:-.02em;margin-bottom:8px}
|
|
20
20
|
p{color:oklch(0.59 0.014 256);font-size:.875rem;line-height:1.5}
|
|
21
21
|
.hint{margin-top:24px;font-size:.75rem;color:oklch(0.59 0.014 256)}
|
|
22
|
+
.open{display:inline-block;margin-top:20px;padding:8px 16px;border-radius:.5rem;font-size:.875rem;
|
|
23
|
+
font-weight:600;background:#f3a52b;color:#000;text-decoration:none}
|
|
22
24
|
`;
|
|
23
25
|
const ICON = {
|
|
24
26
|
ok: '<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>',
|
|
@@ -27,14 +29,25 @@ const ICON = {
|
|
|
27
29
|
const ESCAPES = { '&': '&', '<': '<', '>': '>', '"': '"' };
|
|
28
30
|
// The error text comes from the authorization server's redirect: never trust it as markup.
|
|
29
31
|
export const escapeHtml = (text) => text.replace(/[&<>"]/g, (c) => ESCAPES[c] ?? c);
|
|
30
|
-
|
|
32
|
+
// A success with a return link (the desktop deep link) hands over to the app; the text stays.
|
|
33
|
+
const handOver = (link) => {
|
|
34
|
+
if (!link)
|
|
35
|
+
return { head: '', body: '' };
|
|
36
|
+
const href = escapeHtml(link);
|
|
37
|
+
return {
|
|
38
|
+
head: `<meta http-equiv="refresh" content="0;url=${href}">`,
|
|
39
|
+
body: `<a class="open" href="${href}">Open the agentage app</a>`,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export const callbackPage = (ok, detail, returnLink) => {
|
|
31
43
|
const kind = ok ? 'ok' : 'err';
|
|
32
44
|
const title = ok ? 'Signed in' : 'Sign-in failed';
|
|
33
45
|
const hint = ok ? 'You can close this tab.' : 'Run agentage setup again to retry.';
|
|
34
|
-
|
|
46
|
+
const back = handOver(ok ? returnLink : undefined);
|
|
47
|
+
return (`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">${back.head}` +
|
|
35
48
|
`<title>${title} - agentage</title><style>${STYLE}</style></head><body><main class="card ${kind}">` +
|
|
36
49
|
`<div class="brand"><svg viewBox="0 0 416 416" aria-hidden="true"><rect width="416" height="416" rx="83" fill="#f3a52b"/>` +
|
|
37
50
|
`<g transform="translate(25.7 25.7) scale(1.3812)"><path d="${LOGO}" fill="#000"/></g></svg>agentage</div>` +
|
|
38
|
-
`<div class="icon">${ICON[kind]}</div><h1>${title}</h1><p>${escapeHtml(detail)}</p
|
|
51
|
+
`<div class="icon">${ICON[kind]}</div><h1>${title}</h1><p>${escapeHtml(detail)}</p>${back.body}` +
|
|
39
52
|
`<p class="hint">${hint}</p></main></body></html>`);
|
|
40
53
|
};
|
|
@@ -3,4 +3,4 @@ export interface CallbackServer {
|
|
|
3
3
|
waitForCode: (timeoutMs?: number) => Promise<string>;
|
|
4
4
|
close: () => void;
|
|
5
5
|
}
|
|
6
|
-
export declare const startCallbackServer: (expectedState: string) => Promise<CallbackServer>;
|
|
6
|
+
export declare const startCallbackServer: (expectedState: string, returnLink?: string) => Promise<CallbackServer>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
2
|
import { callbackPage as page } from './callback-page.js';
|
|
3
|
-
|
|
3
|
+
const TERMINAL = 'You can return to the terminal.';
|
|
4
|
+
// returnLink: the fixed deep link of a sign-in the desktop started (return-link.ts), else none.
|
|
5
|
+
export const startCallbackServer = (expectedState, returnLink) => new Promise((resolveServer) => {
|
|
4
6
|
let settle = null;
|
|
5
7
|
let result = null;
|
|
6
8
|
const finish = (code, error) => {
|
|
@@ -33,7 +35,7 @@ export const startCallbackServer = (expectedState) => new Promise((resolveServer
|
|
|
33
35
|
}
|
|
34
36
|
res
|
|
35
37
|
.writeHead(200, { 'content-type': 'text/html' })
|
|
36
|
-
.end(page(true, 'You can return to the
|
|
38
|
+
.end(page(true, returnLink ? 'You can return to the agentage app.' : TERMINAL, returnLink));
|
|
37
39
|
finish(code);
|
|
38
40
|
});
|
|
39
41
|
// Bind loopback only so the one-shot sign-in callback is never LAN-reachable.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The last hop of a sign-in the desktop started: a fixed allowlist, never a value from a request.
|
|
2
|
+
export const SIGN_IN_RETURN_ENV = 'AGENTAGE_SIGN_IN_RETURN';
|
|
3
|
+
const RETURNS = { desktop: 'agentage://signed-in' };
|
|
4
|
+
// Unset, empty or any other value (a prototype key too) is no link: the page keeps its text.
|
|
5
|
+
export const returnLinkOf = (env = process.env) => {
|
|
6
|
+
const raw = env[SIGN_IN_RETURN_ENV] ?? '';
|
|
7
|
+
return Object.hasOwn(RETURNS, raw) ? RETURNS[raw] : undefined;
|
|
8
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Links } from '../net/origins.js';
|
|
2
|
+
import { fetchAccountUser } from './account-user.js';
|
|
2
3
|
import { startCallbackServer } from './callback-server.js';
|
|
3
4
|
import { introspectToken } from './introspect.js';
|
|
4
5
|
import { exchangeCode, registerClient, revokeToken } from './oauth.js';
|
|
@@ -14,6 +15,7 @@ export interface SignInDeps {
|
|
|
14
15
|
startServer: typeof startCallbackServer;
|
|
15
16
|
openBrowser: (url: string) => Promise<void>;
|
|
16
17
|
introspect: typeof introspectToken;
|
|
18
|
+
accountUser: typeof fetchAccountUser;
|
|
17
19
|
discover: (fqdn: string) => Promise<Links>;
|
|
18
20
|
log: (msg: string) => void;
|
|
19
21
|
}
|
package/dist/lib/auth/sign-in.js
CHANGED
|
@@ -3,11 +3,14 @@ import { deleteAuth, ensureConfigDir, mutateAuth, readAuth } from '../fs/config.
|
|
|
3
3
|
import { discoverTarget } from '../net/discovery.js';
|
|
4
4
|
import { siteFqdn } from '../net/origins.js';
|
|
5
5
|
import { CliError, isJsonRun } from '../json-output.js';
|
|
6
|
+
import { fetchAccountUser } from './account-user.js';
|
|
7
|
+
import { updateSession } from './api.js';
|
|
6
8
|
import { AuthRequiredError } from './auth-errors.js';
|
|
7
9
|
import { startCallbackServer } from './callback-server.js';
|
|
8
10
|
import { credentialLinks, detectEnvMismatch } from './env-match.js';
|
|
9
11
|
import { introspectToken } from './introspect.js';
|
|
10
12
|
import { revokePlatformPats } from './platform-pat.js';
|
|
13
|
+
import { returnLinkOf } from './return-link.js';
|
|
11
14
|
import { buildAuthorizeUrl, exchangeCode, pkcePair, randomState, registerClient, revokeToken, tokensFrom, } from './oauth.js';
|
|
12
15
|
const defaultDeps = {
|
|
13
16
|
register: registerClient,
|
|
@@ -19,6 +22,7 @@ const defaultDeps = {
|
|
|
19
22
|
await open(url);
|
|
20
23
|
},
|
|
21
24
|
introspect: introspectToken,
|
|
25
|
+
accountUser: fetchAccountUser,
|
|
22
26
|
discover: async (fqdn) => (await discoverTarget(fqdn)).links,
|
|
23
27
|
log: (msg) => console.log(msg),
|
|
24
28
|
};
|
|
@@ -49,14 +53,21 @@ export const signIn = async (opts, deps = defaultDeps) => {
|
|
|
49
53
|
const authUrl = to.auth;
|
|
50
54
|
ensureConfigDir();
|
|
51
55
|
const state = randomState();
|
|
52
|
-
const server = await deps.startServer(state);
|
|
56
|
+
const server = await deps.startServer(state, returnLinkOf());
|
|
53
57
|
try {
|
|
54
58
|
const { clientId, code, verifier } = await authorize(server, state, opts, deps, authUrl);
|
|
55
59
|
const redirectUri = server.redirectUri;
|
|
56
60
|
const res = await deps.exchange(authUrl, { clientId, code, redirectUri, verifier });
|
|
57
61
|
const tokens = tokensFrom(res);
|
|
62
|
+
const user = await deps.accountUser(authUrl, tokens.accessToken);
|
|
58
63
|
const old = readAuth();
|
|
59
|
-
await mutateAuth(() => ({
|
|
64
|
+
await mutateAuth(() => ({
|
|
65
|
+
siteFqdn: fqdn,
|
|
66
|
+
issuer: authUrl,
|
|
67
|
+
clientId,
|
|
68
|
+
tokens,
|
|
69
|
+
...(user && { user }),
|
|
70
|
+
}));
|
|
60
71
|
if (old)
|
|
61
72
|
await revokePlatformPats({ ...old, clientId, tokens }, to);
|
|
62
73
|
deps.log(chalk.green('\nSigned in.\n'));
|
|
@@ -78,10 +89,19 @@ export const signOut = async (deps = defaultDeps) => {
|
|
|
78
89
|
};
|
|
79
90
|
const mismatchNote = (m) => `Signed in to ${m.credentialFqdn} (${m.credentialEnv}), but this run targets ` +
|
|
80
91
|
`${m.targetFqdn} (${m.targetEnv}) - signing you into ${m.targetEnv}.\n`;
|
|
92
|
+
// A session stored before cli 0.66 has no user, so the local shell would show the bare id.
|
|
93
|
+
const rememberUser = async (auth, deps) => {
|
|
94
|
+
if (auth.user || !auth.issuer)
|
|
95
|
+
return;
|
|
96
|
+
const user = await deps.accountUser(auth.issuer, auth.tokens.accessToken);
|
|
97
|
+
if (user)
|
|
98
|
+
await updateSession(auth.clientId, (current) => void (current.user = user));
|
|
99
|
+
};
|
|
81
100
|
// Only a dead session re-signs: a transient verify failure keeps the credentials.
|
|
82
101
|
const verifyStored = async (auth, deps) => {
|
|
83
102
|
try {
|
|
84
103
|
await deps.introspect(auth, credentialLinks(auth));
|
|
104
|
+
await rememberUser(auth, deps);
|
|
85
105
|
deps.log(`Already signed in. Run ${chalk.white('agentage setup --reauth')} to sign in again.\n`);
|
|
86
106
|
return true;
|
|
87
107
|
}
|
|
@@ -4,6 +4,7 @@ export interface UpdateCache {
|
|
|
4
4
|
}
|
|
5
5
|
export declare const isUpdateCache: (value: unknown) => value is UpdateCache;
|
|
6
6
|
export declare const readUpdateCache: () => UpdateCache | null;
|
|
7
|
+
export declare const markUpdateReported: () => void;
|
|
7
8
|
export declare const updateHint: () => string | null;
|
|
8
9
|
export declare const fetchLatestVersion: (timeoutMs: number, url?: string) => Promise<string | null>;
|
|
9
10
|
export interface RefreshDeps {
|
|
@@ -17,9 +17,14 @@ const writeUpdateCache = (latest, now) => {
|
|
|
17
17
|
ensureConfigDir();
|
|
18
18
|
writeJsonAtomic(cachePath(), { checkedAt: now, latest });
|
|
19
19
|
};
|
|
20
|
+
// Set once a run printed the live update row (status, and setup through it): one line, one version.
|
|
21
|
+
let reported = false;
|
|
22
|
+
export const markUpdateReported = () => void (reported = true);
|
|
20
23
|
// The one dim hint line printed after a command, read purely from the cache (never the network),
|
|
21
24
|
// only when the cached latest is newer than us. null = print nothing.
|
|
22
25
|
export const updateHint = () => {
|
|
26
|
+
if (reported)
|
|
27
|
+
return null;
|
|
23
28
|
const c = readUpdateCache();
|
|
24
29
|
if (!c?.latest)
|
|
25
30
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.1",
|
|
4
4
|
"description": "The agentage CLI - connect this machine to agentage from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"prepublishOnly": "npm run verify"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@agentage/extension": "0.18.
|
|
57
|
+
"@agentage/extension": "0.18.9",
|
|
58
58
|
"@electric-sql/pglite": "^0.5.16",
|
|
59
59
|
"@tailwindcss/postcss": "^4.3.5",
|
|
60
60
|
"chalk": "^6.0.0",
|