aegiscode 7.0.11 → 7.0.13
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/bin/aegiscode.js +41 -0
- package/package.json +2 -1
- package/scripts/predist.mjs +6 -3
- package/src/app.js +311 -16
- package/src/commands.js +45 -5
- package/src/config.js +7 -0
- package/src/connect.js +351 -0
- package/src/engine.js +14 -0
- package/src/fingerprint.js +46 -16
- package/src/limits.js +1 -1
- package/src/provenance.lock.json +2 -2
- package/src/screens.js +14 -1
- package/src/update.js +103 -12
- package/vendor/client/aegis.js +169 -3
- package/vendor/client/credentials.js +9 -2
- package/vendor/client/drive-connect.js +87 -0
- package/vendor/client/drive-upload.js +176 -0
- package/vendor/client/google-signin.js +127 -0
- package/vendor/client/record-vault.js +431 -113
- package/vendor/client/update.js +366 -8
- package/vendor/desktop/lib/local/claude-pro.js +134 -11
- package/vendor/desktop/lib/local/engine.js +111 -26
- package/vendor/desktop/lib/local/prompt.js +67 -37
- package/vendor/desktop/lib/local/tools.js +49 -13
- package/vendor/desktop/lib/settings.js +65 -24
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
+
// AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
|
|
4
|
+
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
+
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sign this machine in with the user's actual Google identity, instead of the
|
|
10
|
+
* anonymous per-machine key `auto-provision.js`/`connect.js` mint by default.
|
|
11
|
+
*
|
|
12
|
+
* aegis1 already runs the full web side of this (`app.py`: `/auth/google`,
|
|
13
|
+
* `/auth/callback/google`) including a desktop round-trip it was built for:
|
|
14
|
+
* pass `?callback=http://127.0.0.1:{port}` and, once the browser finishes the
|
|
15
|
+
* Google consent screen, aegis1 redirects the browser back to that local
|
|
16
|
+
* address with `token`, `username` and (when available) `memory_token` as
|
|
17
|
+
* query params. Nothing here talks to Google or to aegis1 directly — this
|
|
18
|
+
* module only runs the localhost half of that round-trip: open a one-shot
|
|
19
|
+
* HTTP server, hand the caller the URL to open, and resolve once the browser
|
|
20
|
+
* comes back to it.
|
|
21
|
+
*
|
|
22
|
+
* `token` IS the ordinary AEGIS API key for the account aegis1 resolved
|
|
23
|
+
* (looked up or created by `google_id`/email) — there is no second credential
|
|
24
|
+
* format to support. The caller saves it exactly as `register-device`'s key,
|
|
25
|
+
* through `credentials.saveApiKey`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const http = require('node:http');
|
|
29
|
+
const { URL } = require('node:url');
|
|
30
|
+
|
|
31
|
+
/** Escapes text placed into the one-shot HTML page — the values riding in the
|
|
32
|
+
* query string came back through the user's browser, so treat them as
|
|
33
|
+
* untrusted even though this server only ever talks to localhost. */
|
|
34
|
+
function escapeHtml(s) {
|
|
35
|
+
return String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({
|
|
36
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
|
37
|
+
}[c]));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function page({ ok, error, username }) {
|
|
41
|
+
const title = ok ? 'Signed in' : 'Sign-in failed';
|
|
42
|
+
const body = ok
|
|
43
|
+
? `Signed in${username ? ` as <b>${escapeHtml(username)}</b>` : ''}. You can close this tab and return to the terminal.`
|
|
44
|
+
: `Sign-in failed: ${escapeHtml(error || 'no token was returned')}. You can close this tab and try again.`;
|
|
45
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>${title} — AEGIS</title></head>` +
|
|
46
|
+
`<body style="font:16px sans-serif;max-width:32rem;margin:4rem auto;text-align:center;">` +
|
|
47
|
+
`<h2>${title}</h2><p>${body}</p></body></html>`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `${apiBase}/auth/google?callback=${callbackUrl}` — the one URL this flow opens. */
|
|
51
|
+
function buildAuthUrl(apiBase, callbackUrl) {
|
|
52
|
+
const url = new URL('/auth/google', apiBase);
|
|
53
|
+
url.searchParams.set('callback', callbackUrl);
|
|
54
|
+
return url.toString();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Starts the local callback server and returns the URL to open, plus a
|
|
59
|
+
* `wait()` that resolves once the browser lands on it.
|
|
60
|
+
*
|
|
61
|
+
* Only a request that carries `token` or `error` ends the wait — anything
|
|
62
|
+
* else (a browser pre-connect, `/favicon.ico`) gets a plain 404 and the
|
|
63
|
+
* server keeps listening for the real one.
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise<{url: string, wait: () => Promise<{apiKey:string, username:?string, memoryToken:?string}>}>}
|
|
66
|
+
*/
|
|
67
|
+
async function startGoogleSignIn({ apiBase, host = '127.0.0.1', timeoutMs = 5 * 60 * 1000 } = {}) {
|
|
68
|
+
if (!apiBase) throw new Error('startGoogleSignIn requires apiBase');
|
|
69
|
+
|
|
70
|
+
let settled = false;
|
|
71
|
+
let resolveResult;
|
|
72
|
+
let rejectResult;
|
|
73
|
+
const result = new Promise((resolve, reject) => {
|
|
74
|
+
resolveResult = resolve;
|
|
75
|
+
rejectResult = reject;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const server = http.createServer((req, res) => {
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = new URL(req.url, `http://${host}`);
|
|
82
|
+
} catch {
|
|
83
|
+
res.writeHead(400).end();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const token = parsed.searchParams.get('token');
|
|
87
|
+
const username = parsed.searchParams.get('username');
|
|
88
|
+
const memoryToken = parsed.searchParams.get('memory_token');
|
|
89
|
+
const error = parsed.searchParams.get('error');
|
|
90
|
+
|
|
91
|
+
if (!token && !error) {
|
|
92
|
+
res.writeHead(404).end();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
96
|
+
res.end(page({ ok: Boolean(token), error, username }));
|
|
97
|
+
|
|
98
|
+
if (settled) return;
|
|
99
|
+
settled = true;
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
server.close();
|
|
102
|
+
if (token) resolveResult({ apiKey: token, username: username || null, memoryToken: memoryToken || null });
|
|
103
|
+
else rejectResult(new Error(error || 'no token was returned'));
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await new Promise((resolve, reject) => {
|
|
107
|
+
server.once('error', reject);
|
|
108
|
+
server.listen(0, host, resolve);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const { port } = server.address();
|
|
112
|
+
const callbackUrl = `http://${host}:${port}`;
|
|
113
|
+
const url = buildAuthUrl(apiBase, callbackUrl);
|
|
114
|
+
|
|
115
|
+
const timer = setTimeout(() => {
|
|
116
|
+
if (settled) return;
|
|
117
|
+
settled = true;
|
|
118
|
+
server.close();
|
|
119
|
+
rejectResult(new Error(`timed out after ${Math.round(timeoutMs / 1000)}s waiting for the browser sign-in`));
|
|
120
|
+
}, timeoutMs);
|
|
121
|
+
// A pending timer must not keep the process alive just for this wait.
|
|
122
|
+
if (typeof timer.unref === 'function') timer.unref();
|
|
123
|
+
|
|
124
|
+
return { url, wait: () => result };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = { startGoogleSignIn, buildAuthUrl };
|