aegisone 1.0.21 → 1.0.23
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/LICENSE +661 -0
- package/README.md +1 -1
- package/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -322
- package/package.json +4 -2
- package/scripts/bump.mjs +1 -211
- package/scripts/bundle.js +1 -129
- package/scripts/predist.mjs +1 -939
- package/src/child.js +1 -285
- package/src/dispatch.js +1 -269
- package/src/doctor.js +1 -639
- package/src/host.js +1 -111
- package/src/permissions.js +1 -369
- package/src/probes.js +1 -159
- package/src/release.js +1 -409
- package/vendor/cli/bin/aegiscode.js +2 -914
- package/vendor/cli/package.json +3 -2
- package/vendor/cli/scripts/check.mjs +1 -52
- package/vendor/cli/scripts/demo.mjs +1 -94
- package/vendor/cli/scripts/predist.mjs +1 -75
- package/vendor/cli/scripts/runtests.mjs +1 -56
- package/vendor/cli/scripts/seal-gate.mjs +1 -74
- package/vendor/cli/src/agents.js +1 -139
- package/vendor/cli/src/app.js +1 -2932
- package/vendor/cli/src/art.js +1 -289
- package/vendor/cli/src/autonomous.js +1 -515
- package/vendor/cli/src/caps.js +1 -879
- package/vendor/cli/src/chatflow.js +1 -3008
- package/vendor/cli/src/checkpoint.js +1 -90
- package/vendor/cli/src/clipboard.js +1 -424
- package/vendor/cli/src/cloudsync.js +1 -528
- package/vendor/cli/src/commands.js +1 -3987
- package/vendor/cli/src/config.js +1 -581
- package/vendor/cli/src/connect.js +1 -349
- package/vendor/cli/src/credentials.js +1 -33
- package/vendor/cli/src/deps.js +1 -232
- package/vendor/cli/src/devrun.js +1 -187
- package/vendor/cli/src/diff.js +1 -333
- package/vendor/cli/src/diffview.js +1 -296
- package/vendor/cli/src/engine.js +1 -297
- package/vendor/cli/src/entitlement.js +1 -355
- package/vendor/cli/src/events.js +1 -707
- package/vendor/cli/src/export.js +1 -67
- package/vendor/cli/src/fingerprint.js +1 -592
- package/vendor/cli/src/format.js +1 -259
- package/vendor/cli/src/fuzzy.js +1 -119
- package/vendor/cli/src/gate.js +1 -55
- package/vendor/cli/src/history.js +1 -401
- package/vendor/cli/src/init.js +1 -175
- package/vendor/cli/src/input.js +1 -139
- package/vendor/cli/src/keys.js +1 -183
- package/vendor/cli/src/limits.js +1 -190
- package/vendor/cli/src/markdown.js +1 -306
- package/vendor/cli/src/mcp.js +1 -694
- package/vendor/cli/src/models.js +1 -487
- package/vendor/cli/src/naming.js +1 -229
- package/vendor/cli/src/overlays.js +1 -461
- package/vendor/cli/src/panels.js +1 -1418
- package/vendor/cli/src/permissions.js +1 -290
- package/vendor/cli/src/ping.js +1 -226
- package/vendor/cli/src/presence.js +1 -238
- package/vendor/cli/src/provenance.js +2 -182
- package/vendor/cli/src/render.js +1 -515
- package/vendor/cli/src/screen.js +1 -518
- package/vendor/cli/src/screens.js +1 -896
- package/vendor/cli/src/secret.js +1 -59
- package/vendor/cli/src/securefs.js +1 -359
- package/vendor/cli/src/settings.js +1 -155
- package/vendor/cli/src/shared.js +1 -52
- package/vendor/cli/src/sharedpaths.js +1 -53
- package/vendor/cli/src/signup.js +1 -156
- package/vendor/cli/src/summarize.js +1 -95
- package/vendor/cli/src/sysdiag.js +1 -585
- package/vendor/cli/src/system.js +1 -40
- package/vendor/cli/src/theme.js +1 -570
- package/vendor/cli/src/title.js +1 -220
- package/vendor/cli/src/todos.js +1 -115
- package/vendor/cli/src/tokens.js +1 -263
- package/vendor/cli/src/topup.js +1 -210
- package/vendor/cli/src/update.js +1 -181
- package/vendor/cli/vendor/client/aegis.js +1 -2054
- package/vendor/cli/vendor/client/attest.js +1 -442
- package/vendor/cli/vendor/client/authorship-key.js +1 -410
- package/vendor/cli/vendor/client/auto-provision.js +1 -134
- package/vendor/cli/vendor/client/brain-catalog.js +1 -268
- package/vendor/cli/vendor/client/byok-catalog.js +1 -230
- package/vendor/cli/vendor/client/credentials.js +1 -494
- package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
- package/vendor/cli/vendor/client/drive-connect.js +1 -85
- package/vendor/cli/vendor/client/drive-upload.js +1 -174
- package/vendor/cli/vendor/client/env-file.js +1 -1273
- package/vendor/cli/vendor/client/fingerprint.js +1 -1064
- package/vendor/cli/vendor/client/foreign-memory.js +1 -669
- package/vendor/cli/vendor/client/google-signin.js +1 -125
- package/vendor/cli/vendor/client/hooks.js +1 -430
- package/vendor/cli/vendor/client/model-discovery.js +1 -330
- package/vendor/cli/vendor/client/platform.js +1 -937
- package/vendor/cli/vendor/client/prefs.js +1 -351
- package/vendor/cli/vendor/client/presence-constants.js +1 -107
- package/vendor/cli/vendor/client/presence.js +1 -438
- package/vendor/cli/vendor/client/record-vault.js +3 -1055
- package/vendor/cli/vendor/client/session-store.js +1 -548
- package/vendor/cli/vendor/client/topup.js +1 -297
- package/vendor/cli/vendor/client/touch.js +1 -458
- package/vendor/cli/vendor/client/update.js +1 -704
- package/vendor/cli/vendor/client/user-models.js +1 -381
- package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3228
- package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -654
- package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
- package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/cli/vendor/hosts/install.js +1 -638
- package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
- package/vendor/cli/vendor/hosts/spec.js +1 -164
- package/vendor/cli/vendor/hosts/targets.js +1 -346
- package/vendor/cli/vendor/mcp/server.js +1 -221
- package/vendor/cli/vendor/mcp/tools.js +1 -408
- package/vendor/cli/vendor/one/src/child.js +1 -285
- package/vendor/cli/vendor/one/src/permissions.js +1 -369
- package/vendor/desktop/bin/aegis.js +1 -32
- package/vendor/desktop/lib/account-key.js +1 -56
- package/vendor/desktop/lib/auto.js +1 -430
- package/vendor/desktop/lib/avatar/companion.js +1 -698
- package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
- package/vendor/desktop/lib/avatar/events.js +1 -344
- package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
- package/vendor/desktop/lib/avatar/holders.js +1 -612
- package/vendor/desktop/lib/avatar/identity.js +1 -641
- package/vendor/desktop/lib/avatar/level.js +1 -368
- package/vendor/desktop/lib/avatar/mirror.js +1 -524
- package/vendor/desktop/lib/avatar/persona.js +1 -388
- package/vendor/desktop/lib/avatar/profile.js +1 -977
- package/vendor/desktop/lib/avatar/register.js +1 -307
- package/vendor/desktop/lib/avatar/store.js +1 -472
- package/vendor/desktop/lib/avatar/tiers.js +1 -38
- package/vendor/desktop/lib/avatar/transfer.js +1 -415
- package/vendor/desktop/lib/avatar/turn.js +1 -216
- package/vendor/desktop/lib/avatar/voice.js +1 -328
- package/vendor/desktop/lib/avatar/xp.js +1 -404
- package/vendor/desktop/lib/deep-link.js +1 -120
- package/vendor/desktop/lib/fingerprint.js +2 -347
- package/vendor/desktop/lib/google-connect.js +1 -169
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/desktop/lib/local/engine.js +1 -3228
- package/vendor/desktop/lib/local/entitlement.js +1 -654
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/desktop/lib/local/telemetry.js +1 -470
- package/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/provider-key-mirror.js +1 -252
- package/vendor/desktop/lib/quick-launcher.js +1 -84
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/lib/sync/memory-queue.js +1 -60
- package/vendor/desktop/lib/sync/persist-gate.js +1 -148
- package/vendor/desktop/lib/sync/sessions.js +1 -106
- package/vendor/desktop/lib/window-state.js +1 -66
- package/vendor/desktop/main.js +1 -4390
- package/vendor/desktop/package.json +3 -5
- package/vendor/desktop/preload.js +1 -628
- package/vendor/desktop/renderer/app.js +1 -6560
- package/vendor/desktop/renderer/avatar/assemble.js +1 -335
- package/vendor/desktop/renderer/avatar/avatar.js +1 -380
- package/vendor/desktop/renderer/avatar/cards.js +1 -141
- package/vendor/desktop/renderer/avatar/hud.js +1 -206
- package/vendor/desktop/renderer/avatar/machine.js +1 -213
- package/vendor/desktop/renderer/avatar/pane.js +1 -439
- package/vendor/desktop/renderer/avatar/parts.js +1 -437
- package/vendor/desktop/renderer/budget.js +1 -168
- package/vendor/desktop/renderer/companion.js +1 -223
- package/vendor/desktop/renderer/diff.js +1 -359
- package/vendor/desktop/renderer/diffview.js +1 -336
- package/vendor/desktop/renderer/fingerprint.js +3 -720
- package/vendor/desktop/renderer/markdown.js +1 -168
- package/vendor/desktop/renderer/provider-toolbar.js +1 -134
- package/vendor/desktop/renderer/providers.js +1 -259
- package/vendor/desktop/renderer/quick.js +1 -191
- package/vendor/desktop/renderer/stream-policy.js +1 -306
- package/vendor/desktop/renderer/transcript-view.js +1 -323
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/desktop/vendor/aegis.js +1 -2054
- package/vendor/desktop/vendor/attest.js +1 -442
- package/vendor/desktop/vendor/authorship-key.js +1 -410
- package/vendor/desktop/vendor/auto-provision.js +1 -134
- package/vendor/desktop/vendor/brain-catalog.js +1 -268
- package/vendor/desktop/vendor/byok-catalog.js +1 -230
- package/vendor/desktop/vendor/credentials.js +1 -494
- package/vendor/desktop/vendor/device-fingerprint.js +1 -141
- package/vendor/desktop/vendor/drive-connect.js +1 -85
- package/vendor/desktop/vendor/drive-upload.js +1 -174
- package/vendor/desktop/vendor/env-file.js +1 -1273
- package/vendor/desktop/vendor/fingerprint.js +1 -1064
- package/vendor/desktop/vendor/foreign-memory.js +1 -669
- package/vendor/desktop/vendor/google-signin.js +1 -125
- package/vendor/desktop/vendor/hooks.js +1 -430
- package/vendor/desktop/vendor/model-discovery.js +1 -330
- package/vendor/desktop/vendor/platform.js +1 -937
- package/vendor/desktop/vendor/prefs.js +1 -351
- package/vendor/desktop/vendor/presence-constants.js +1 -107
- package/vendor/desktop/vendor/presence.js +1 -438
- package/vendor/desktop/vendor/record-vault.js +3 -1055
- package/vendor/desktop/vendor/session-store.js +1 -548
- package/vendor/desktop/vendor/topup.js +1 -297
- package/vendor/desktop/vendor/touch.js +1 -458
- package/vendor/desktop/vendor/update.js +1 -704
- package/vendor/desktop/vendor/user-models.js +1 -381
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
|
|
3
|
+
"use strict";
|
|
8
4
|
/**
|
|
9
5
|
* The desktop's φ(α) surface: the same keys and the same records the terminal
|
|
10
6
|
* host mints, driven over IPC instead of argv.
|
|
@@ -47,345 +43,4 @@
|
|
|
47
43
|
* method` string with the real message buried in main-process logs; a returned
|
|
48
44
|
* error is a message the UI can show verbatim, which matters most for the one
|
|
49
45
|
* error a user is likely to hit ("this key file is readable by other users").
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
const fs = require('node:fs');
|
|
53
|
-
const path = require('node:path');
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Resolve a shared client module by existence: repo checkout first, then the
|
|
57
|
-
* packaged app's flattened `vendor/` (electron-builder cannot reach outside the
|
|
58
|
-
* app directory — see scripts/predist.mjs, which must stage all four).
|
|
59
|
-
*/
|
|
60
|
-
function resolveShared(name) {
|
|
61
|
-
const candidates = [
|
|
62
|
-
path.join(__dirname, '..', '..', 'client', name), // dev / CI: repo root
|
|
63
|
-
path.join(__dirname, '..', 'vendor', name), // packaged: desktop/vendor
|
|
64
|
-
];
|
|
65
|
-
for (const candidate of candidates) {
|
|
66
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
67
|
-
}
|
|
68
|
-
throw new Error(
|
|
69
|
-
`aegis-desktop: cannot find client/${name} — expected it beside desktop/ in the repo ` +
|
|
70
|
-
'or under desktop/vendor/ in a build. Run `npm run predist` in desktop/.',
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function load() {
|
|
75
|
-
const fp = require(resolveShared('fingerprint.js'));
|
|
76
|
-
return {
|
|
77
|
-
fp,
|
|
78
|
-
authorship: require(resolveShared('authorship-key.js')),
|
|
79
|
-
attest: require(resolveShared('attest.js')),
|
|
80
|
-
vault: require(resolveShared('record-vault.js')),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function slug(value, max = 80) {
|
|
85
|
-
return (
|
|
86
|
-
String(value || 'session')
|
|
87
|
-
.replace(/[^A-Za-z0-9._-]+/g, '_')
|
|
88
|
-
.replace(/^[._-]+/, '')
|
|
89
|
-
.slice(0, max) || 'session'
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @param {object} o
|
|
95
|
-
* @param {string} o.dir the app's data directory (userData in a package)
|
|
96
|
-
* @param {object} [o.env] process env, injectable for tests
|
|
97
|
-
* @param {() => string} [o.getVaultBackend] reads the live preference
|
|
98
|
-
* ('aegiscloud' | 'drive' | 'off', desktop/lib/settings.js's
|
|
99
|
-
* vaultBackendConfig) — a function, not a value, so a change made in
|
|
100
|
-
* Settings while the app is running reaches the very next vault call with
|
|
101
|
-
* no restart, the same contract getConfirmMode's gate already keeps.
|
|
102
|
-
*/
|
|
103
|
-
function createFingerprintService({ dir, env, getVaultBackend } = {}) {
|
|
104
|
-
if (!dir) throw new Error('aegis-desktop: createFingerprintService needs a data dir');
|
|
105
|
-
// One store: the shared modules read AEGIS_HOME and nothing else.
|
|
106
|
-
const scope = { ...(env || process.env), AEGIS_HOME: (env || process.env).AEGIS_HOME || dir };
|
|
107
|
-
|
|
108
|
-
/** `true` only when the user has explicitly turned sync off — not when no
|
|
109
|
-
* preference has been recorded yet, which must keep resolving to whatever
|
|
110
|
-
* record-vault.js's own default is. */
|
|
111
|
-
function vaultDisabled() {
|
|
112
|
-
return typeof getVaultBackend === 'function' && getVaultBackend() === 'off';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* `scope`, with the vault backend layered on top of it when a preference
|
|
117
|
-
* names one. 'aegiscloud' and an absent preference both fall through to
|
|
118
|
-
* `scope` unchanged — client/record-vault.js's own DEFAULT_BACKEND is
|
|
119
|
-
* already 'aegiscloud', so there is nothing to add for either case. 'drive'
|
|
120
|
-
* is the one preference that actually changes the destination: it asks the
|
|
121
|
-
* rclone adapter for the `gdrive` remote (the user's own Google Drive,
|
|
122
|
-
* configured by them — see client/record-vault.js's DEFAULT_REMOTE). 'off'
|
|
123
|
-
* is handled by `vaultDisabled()` before this is ever called, not here.
|
|
124
|
-
*/
|
|
125
|
-
function vaultScope() {
|
|
126
|
-
if (typeof getVaultBackend === 'function' && getVaultBackend() === 'drive') {
|
|
127
|
-
return { ...scope, AEGIS_VAULT_BACKEND: 'rclone', AEGIS_VAULT_REMOTE: scope.AEGIS_VAULT_REMOTE || 'gdrive' };
|
|
128
|
-
}
|
|
129
|
-
return scope;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const VAULT_OFF_ERROR = 'the vault is turned off — turn it back on (Google Drive or AE) in Settings to publish or inspect it';
|
|
133
|
-
|
|
134
|
-
const recordPath = (record, session) =>
|
|
135
|
-
path.join(dir, 'fingerprints', `${slug(session)}.${String(record.createdAt).replace(/[:.]/g, '-')}.json`);
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
/** Which key is in use, and where it came from. Never returns the key. */
|
|
139
|
-
status() {
|
|
140
|
-
try {
|
|
141
|
-
const { fp, authorship, vault } = load();
|
|
142
|
-
const key = authorship.resolveKey({ argv: [], env: scope });
|
|
143
|
-
const history = path.join(authorship.dataDir(scope), 'history.jsonl');
|
|
144
|
-
if (vaultDisabled()) {
|
|
145
|
-
return {
|
|
146
|
-
ok: true,
|
|
147
|
-
configured: Boolean(key.secret),
|
|
148
|
-
keySource: key.source,
|
|
149
|
-
keyPath: key.path,
|
|
150
|
-
keyFingerprint: key.secret ? fp.keyFingerprint(key.secret) : null,
|
|
151
|
-
publicKey: key.public,
|
|
152
|
-
defaultKeyPath: authorship.defaultKeyPath(scope),
|
|
153
|
-
historyPath: history,
|
|
154
|
-
historyPresent: fs.existsSync(history),
|
|
155
|
-
dataDir: authorship.dataDir(scope),
|
|
156
|
-
vault: { backend: 'off', remote: null, root: null, recordsDir: null },
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
const target = vault.vaultTarget(vaultScope());
|
|
160
|
-
return {
|
|
161
|
-
ok: true,
|
|
162
|
-
configured: Boolean(key.secret),
|
|
163
|
-
keySource: key.source,
|
|
164
|
-
keyPath: key.path,
|
|
165
|
-
keyFingerprint: key.secret ? fp.keyFingerprint(key.secret) : null,
|
|
166
|
-
publicKey: key.public,
|
|
167
|
-
defaultKeyPath: authorship.defaultKeyPath(scope),
|
|
168
|
-
historyPath: history,
|
|
169
|
-
historyPresent: fs.existsSync(history),
|
|
170
|
-
dataDir: authorship.dataDir(scope),
|
|
171
|
-
// Where a publish goes, so the panel can say it before the user asks
|
|
172
|
-
// for one — and so a misconfigured root is visible, not discovered by
|
|
173
|
-
// a record landing in the wrong folder.
|
|
174
|
-
vault: {
|
|
175
|
-
backend: target.backend,
|
|
176
|
-
remote: target.remote,
|
|
177
|
-
root: target.root,
|
|
178
|
-
recordsDir: target.backend === vault.BACKEND_CLOUD ? vault.CLOUD_PREFIX : `${target.root}/${vault.RECORDS_DIR}`,
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
} catch (e) {
|
|
182
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
/** Mint a private key. `force` replaces one, which orphans its records. */
|
|
187
|
-
keygen({ out = null, force = false } = {}) {
|
|
188
|
-
try {
|
|
189
|
-
const { authorship } = load();
|
|
190
|
-
const argv = [];
|
|
191
|
-
if (out) argv.push('--out', out);
|
|
192
|
-
if (force) argv.push('--force');
|
|
193
|
-
const r = authorship.keygen({ argv, env: scope });
|
|
194
|
-
return { ok: true, ...r };
|
|
195
|
-
} catch (e) {
|
|
196
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Seal a session as a record.
|
|
202
|
-
*
|
|
203
|
-
* `turns` may be passed in (the renderer's own view of the session) or left
|
|
204
|
-
* out, in which case the shared adapter reads the session log — same code
|
|
205
|
-
* path as the CLI, so a GUI record and a terminal record of the same
|
|
206
|
-
* session carry the same behaviour digest — and the same AI digest, from the
|
|
207
|
-
* same turns.
|
|
208
|
-
*/
|
|
209
|
-
async mint({ history = null, session = null, turns = null, label = null, account = null,
|
|
210
|
-
model = null, tools = null, codeRoots = null, codeDirty = null, out = null,
|
|
211
|
-
createdAt = null, publish = false, aiSecret = undefined, aiModel = null } = {}) {
|
|
212
|
-
try {
|
|
213
|
-
const { attest, authorship } = load();
|
|
214
|
-
const roots = Array.isArray(codeRoots) ? codeRoots.filter(Boolean) : [];
|
|
215
|
-
const r = attest.mintSession({
|
|
216
|
-
argv: [],
|
|
217
|
-
env: scope,
|
|
218
|
-
history: history || path.join(authorship.dataDir(scope), 'history.jsonl'),
|
|
219
|
-
session: session || undefined,
|
|
220
|
-
turns: turns || undefined,
|
|
221
|
-
label: label || undefined,
|
|
222
|
-
account: account || undefined,
|
|
223
|
-
model: model || undefined,
|
|
224
|
-
tools: Array.isArray(tools) ? tools : undefined,
|
|
225
|
-
code: roots.length ? attest.collectCode({ roots }) : [],
|
|
226
|
-
codeDirty: typeof codeDirty === 'boolean' ? codeDirty : null,
|
|
227
|
-
// The AI axis. `undefined` walks the shared rungs (`--ai-secret` never
|
|
228
|
-
// applies here; `$AEGIS_AI_SECRET` in the app's scope does), and an
|
|
229
|
-
// explicit null means "no credential — mint the axis as unobserved".
|
|
230
|
-
// The authorship key is never borrowed for this: it says who sealed the
|
|
231
|
-
// record, not which mind answered.
|
|
232
|
-
aiSecret,
|
|
233
|
-
aiModel: aiModel === null ? undefined : aiModel,
|
|
234
|
-
// Pinning the time is how the CLI and the app mint the *same* record
|
|
235
|
-
// for the same session (see client/attest.js). Left null, the record
|
|
236
|
-
// is stamped now, which is what an ordinary seal wants.
|
|
237
|
-
createdAt: createdAt || undefined,
|
|
238
|
-
});
|
|
239
|
-
const file = path.resolve(out || recordPath(r.record, session || 'last'));
|
|
240
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
241
|
-
fs.writeFileSync(file, JSON.stringify(r.record, null, 2) + '\n');
|
|
242
|
-
|
|
243
|
-
// Sealing and travelling are separate acts: `publish` is opt-in, and a
|
|
244
|
-
// failed publish NEVER unseals the record — the local file is already
|
|
245
|
-
// written and the error is reported beside it, because the seal is the
|
|
246
|
-
// evidence and the copy is the convenience.
|
|
247
|
-
let vault = null;
|
|
248
|
-
let vaultError = null;
|
|
249
|
-
if (publish) {
|
|
250
|
-
if (vaultDisabled()) {
|
|
251
|
-
vaultError = VAULT_OFF_ERROR;
|
|
252
|
-
} else {
|
|
253
|
-
try {
|
|
254
|
-
const key = authorship.resolveKey({ argv: [], env: scope });
|
|
255
|
-
vault = await load().vault.publish({ file, argv: [], env: vaultScope(), secret: key.secret });
|
|
256
|
-
} catch (e) {
|
|
257
|
-
vaultError = (e && e.message) || String(e);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return {
|
|
262
|
-
ok: true,
|
|
263
|
-
record: r.record,
|
|
264
|
-
out: file,
|
|
265
|
-
keySource: r.keySource,
|
|
266
|
-
public: r.public,
|
|
267
|
-
vault,
|
|
268
|
-
vaultError,
|
|
269
|
-
};
|
|
270
|
-
} catch (e) {
|
|
271
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Publish a sealed record to the vault, and link the local copy to it.
|
|
277
|
-
*
|
|
278
|
-
* `record` is accepted as well as `file` so the panel can publish what it
|
|
279
|
-
* just minted without a round trip through the filesystem — but the
|
|
280
|
-
* preferred path is the file, because the sha256 in the anchor is then about
|
|
281
|
-
* the bytes on disk rather than a re-serialisation of them.
|
|
282
|
-
*/
|
|
283
|
-
async publish({ file = null, record = null, dryRun = false } = {}) {
|
|
284
|
-
if (vaultDisabled()) return { ok: false, error: VAULT_OFF_ERROR };
|
|
285
|
-
try {
|
|
286
|
-
const { authorship, vault } = load();
|
|
287
|
-
const key = authorship.resolveKey({ argv: [], env: scope });
|
|
288
|
-
return {
|
|
289
|
-
ok: true,
|
|
290
|
-
...(await vault.publish({ file, record, argv: [], env: vaultScope(), secret: key.secret, dryRun })),
|
|
291
|
-
};
|
|
292
|
-
} catch (e) {
|
|
293
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Is the published copy still the record that was sealed?
|
|
299
|
-
*
|
|
300
|
-
* Reports the three claims separately (`present`, `unchanged`, `attested`),
|
|
301
|
-
* because "the file is gone" and "the file was replaced" and "the key that
|
|
302
|
-
* sealed it has moved on" are three different situations and a single
|
|
303
|
-
* boolean would flatten them into one that hides the interesting case.
|
|
304
|
-
*/
|
|
305
|
-
async anchor({ file = null, record = null, anchor = null } = {}) {
|
|
306
|
-
if (vaultDisabled()) return { ok: false, error: VAULT_OFF_ERROR };
|
|
307
|
-
try {
|
|
308
|
-
const { authorship, vault } = load();
|
|
309
|
-
if (!file && !record && !anchor) return { ok: false, error: 'anchor needs a record or an anchor' };
|
|
310
|
-
const key = authorship.resolveKey({ argv: [], env: scope });
|
|
311
|
-
return { ok: true, ...(await vault.checkAnchor({ file, record, anchor, argv: [], env: vaultScope(), key })) };
|
|
312
|
-
} catch (e) {
|
|
313
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
|
|
317
|
-
/** What is in the vault. */
|
|
318
|
-
async vaultList() {
|
|
319
|
-
if (vaultDisabled()) return { ok: false, error: VAULT_OFF_ERROR };
|
|
320
|
-
try {
|
|
321
|
-
const { vault } = load();
|
|
322
|
-
return { ok: true, ...(await vault.list({ argv: [], env: vaultScope() })) };
|
|
323
|
-
} catch (e) {
|
|
324
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Inspect the vault for key material — including the `keys/` copy that was
|
|
330
|
-
* already there before publishing was restricted. A finding is a fact about
|
|
331
|
-
* the vault, not about this app, so it is returned rather than acted on.
|
|
332
|
-
*/
|
|
333
|
-
async vaultAudit() {
|
|
334
|
-
if (vaultDisabled()) return { ok: false, error: VAULT_OFF_ERROR };
|
|
335
|
-
try {
|
|
336
|
-
const { authorship, vault } = load();
|
|
337
|
-
const key = authorship.resolveKey({ argv: [], env: scope });
|
|
338
|
-
return { ok: true, ...(await vault.audit({ argv: [], env: vaultScope(), secret: key.secret || null })) };
|
|
339
|
-
} catch (e) {
|
|
340
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Recompute a record's attestation. Accepts a path or the record itself, so
|
|
346
|
-
* the renderer can verify what it just minted without a round trip through
|
|
347
|
-
* the filesystem.
|
|
348
|
-
*/
|
|
349
|
-
verify({ file = null, record = null } = {}) {
|
|
350
|
-
try {
|
|
351
|
-
const { fp, authorship } = load();
|
|
352
|
-
let body = record;
|
|
353
|
-
if (!body) {
|
|
354
|
-
if (!file) return { ok: false, error: 'verify needs a record file or the record itself' };
|
|
355
|
-
body = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
356
|
-
}
|
|
357
|
-
const key = authorship.resolveKey({ argv: [], env: scope });
|
|
358
|
-
if (!key.secret) {
|
|
359
|
-
return { ok: false, error: 'no authorship key — run keygen first', reason: 'no key' };
|
|
360
|
-
}
|
|
361
|
-
const v = fp.verify(body, key.secret);
|
|
362
|
-
return {
|
|
363
|
-
ok: v.ok,
|
|
364
|
-
reason: v.reason,
|
|
365
|
-
id: v.id,
|
|
366
|
-
credentialMatch: v.credentialMatch,
|
|
367
|
-
keySource: key.source,
|
|
368
|
-
recordedKeyFingerprint: body.keyFingerprint || null,
|
|
369
|
-
};
|
|
370
|
-
} catch (e) {
|
|
371
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
|
|
375
|
-
/** Copy the key out. Refuses a destination inside a non-ignored git tree. */
|
|
376
|
-
backup({ to = null, name = null, allowGit = false } = {}) {
|
|
377
|
-
try {
|
|
378
|
-
if (!to) return { ok: false, error: 'backup needs a destination directory' };
|
|
379
|
-
const { authorship } = load();
|
|
380
|
-
const argv = ['--to', to];
|
|
381
|
-
if (name) argv.push('--name', name);
|
|
382
|
-
if (allowGit) argv.push('--allow-git');
|
|
383
|
-
return { ok: true, ...authorship.backup({ argv, env: scope }) };
|
|
384
|
-
} catch (e) {
|
|
385
|
-
return { ok: false, error: (e && e.message) || String(e) };
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
module.exports = { createFingerprintService, resolveShared, slug };
|
|
46
|
+
*/const fs=require("node:fs"),path=require("node:path");function resolveShared(e){const r=[path.join(__dirname,"..","..","client",e),path.join(__dirname,"..","vendor",e)];for(const e of r)if(fs.existsSync(e))return e;throw new Error(`aegis-desktop: cannot find client/${e} — expected it beside desktop/ in the repo or under desktop/vendor/ in a build. Run \`npm run predist\` in desktop/.`)}function load(){return{fp:require(resolveShared("fingerprint.js")),authorship:require(resolveShared("authorship-key.js")),attest:require(resolveShared("attest.js")),vault:require(resolveShared("record-vault.js"))}}function slug(e,r=80){return String(e||"session").replace(/[^A-Za-z0-9._-]+/g,"_").replace(/^[._-]+/,"").slice(0,r)||"session"}function createFingerprintService({dir:e,env:r,getVaultBackend:t}={}){if(!e)throw new Error("aegis-desktop: createFingerprintService needs a data dir");const o={...r||process.env,AEGIS_HOME:(r||process.env).AEGIS_HOME||e};function n(){return"function"==typeof t&&"off"===t()}function a(){return"function"==typeof t&&"drive"===t()?{...o,AEGIS_VAULT_BACKEND:"rclone",AEGIS_VAULT_REMOTE:o.AEGIS_VAULT_REMOTE||"gdrive"}:o}const i="the vault is turned off — turn it back on (Google Drive or AE) in Settings to publish or inspect it";return{status(){try{const{fp:e,authorship:r,vault:t}=load(),i=r.resolveKey({argv:[],env:o}),s=path.join(r.dataDir(o),"history.jsonl");if(n())return{ok:!0,configured:Boolean(i.secret),keySource:i.source,keyPath:i.path,keyFingerprint:i.secret?e.keyFingerprint(i.secret):null,publicKey:i.public,defaultKeyPath:r.defaultKeyPath(o),historyPath:s,historyPresent:fs.existsSync(s),dataDir:r.dataDir(o),vault:{backend:"off",remote:null,root:null,recordsDir:null}};const l=t.vaultTarget(a());return{ok:!0,configured:Boolean(i.secret),keySource:i.source,keyPath:i.path,keyFingerprint:i.secret?e.keyFingerprint(i.secret):null,publicKey:i.public,defaultKeyPath:r.defaultKeyPath(o),historyPath:s,historyPresent:fs.existsSync(s),dataDir:r.dataDir(o),vault:{backend:l.backend,remote:l.remote,root:l.root,recordsDir:l.backend===t.BACKEND_CLOUD?t.CLOUD_PREFIX:`${l.root}/${t.RECORDS_DIR}`}}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},keygen({out:e=null,force:r=!1}={}){try{const{authorship:t}=load(),n=[];return e&&n.push("--out",e),r&&n.push("--force"),{ok:!0,...t.keygen({argv:n,env:o})}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},async mint({history:r=null,session:t=null,turns:s=null,label:l=null,account:u=null,model:c=null,tools:d=null,codeRoots:h=null,codeDirty:v=null,out:y=null,createdAt:p=null,publish:f=!1,aiSecret:g,aiModel:k=null}={}){try{const{attest:S,authorship:m}=load(),b=Array.isArray(h)?h.filter(Boolean):[],A=S.mintSession({argv:[],env:o,history:r||path.join(m.dataDir(o),"history.jsonl"),session:t||void 0,turns:s||void 0,label:l||void 0,account:u||void 0,model:c||void 0,tools:Array.isArray(d)?d:void 0,code:b.length?S.collectCode({roots:b}):[],codeDirty:"boolean"==typeof v?v:null,aiSecret:g,aiModel:null===k?void 0:k,createdAt:p||void 0}),E=path.resolve(y||((r,t)=>path.join(e,"fingerprints",`${slug(t)}.${String(r.createdAt).replace(/[:.]/g,"-")}.json`))(A.record,t||"last"));fs.mkdirSync(path.dirname(E),{recursive:!0}),fs.writeFileSync(E,JSON.stringify(A.record,null,2)+"\n");let _=null,D=null;if(f)if(n())D=i;else try{const e=m.resolveKey({argv:[],env:o});_=await load().vault.publish({file:E,argv:[],env:a(),secret:e.secret})}catch(e){D=e&&e.message||String(e)}return{ok:!0,record:A.record,out:E,keySource:A.keySource,public:A.public,vault:_,vaultError:D}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},async publish({file:e=null,record:r=null,dryRun:t=!1}={}){if(n())return{ok:!1,error:i};try{const{authorship:n,vault:i}=load(),s=n.resolveKey({argv:[],env:o});return{ok:!0,...await i.publish({file:e,record:r,argv:[],env:a(),secret:s.secret,dryRun:t})}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},async anchor({file:e=null,record:r=null,anchor:t=null}={}){if(n())return{ok:!1,error:i};try{const{authorship:n,vault:i}=load();if(!e&&!r&&!t)return{ok:!1,error:"anchor needs a record or an anchor"};const s=n.resolveKey({argv:[],env:o});return{ok:!0,...await i.checkAnchor({file:e,record:r,anchor:t,argv:[],env:a(),key:s})}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},async vaultList(){if(n())return{ok:!1,error:i};try{const{vault:e}=load();return{ok:!0,...await e.list({argv:[],env:a()})}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},async vaultAudit(){if(n())return{ok:!1,error:i};try{const{authorship:e,vault:r}=load(),t=e.resolveKey({argv:[],env:o});return{ok:!0,...await r.audit({argv:[],env:a(),secret:t.secret||null})}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},verify({file:e=null,record:r=null}={}){try{const{fp:t,authorship:n}=load();let a=r;if(!a){if(!e)return{ok:!1,error:"verify needs a record file or the record itself"};a=JSON.parse(fs.readFileSync(e,"utf8"))}const i=n.resolveKey({argv:[],env:o});if(!i.secret)return{ok:!1,error:"no authorship key — run keygen first",reason:"no key"};const s=t.verify(a,i.secret);return{ok:s.ok,reason:s.reason,id:s.id,credentialMatch:s.credentialMatch,keySource:i.source,recordedKeyFingerprint:a.keyFingerprint||null}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}},backup({to:e=null,name:r=null,allowGit:t=!1}={}){try{if(!e)return{ok:!1,error:"backup needs a destination directory"};const{authorship:n}=load(),a=["--to",e];return r&&a.push("--name",r),t&&a.push("--allow-git"),{ok:!0,...n.backup({argv:a,env:o})}}catch(e){return{ok:!1,error:e&&e.message||String(e)}}}}}module.exports={createFingerprintService:createFingerprintService,resolveShared:resolveShared,slug:slug};
|
|
@@ -1,171 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* google-connect.js — the desktop's Google identity + Drive flow.
|
|
10
|
-
*
|
|
11
|
-
* Two distinct steps, run in this order because the second depends on the
|
|
12
|
-
* first having actually landed:
|
|
13
|
-
*
|
|
14
|
-
* 1. Sign in with Google (`client/google-signin.js`'s local round-trip) —
|
|
15
|
-
* replaces this machine's saved AEGIS key with the one tied to that
|
|
16
|
-
* Google identity, exactly as `aegiscode connect` already does for the
|
|
17
|
-
* CLI (cli/src/connect.js). Desktop never had this wiring before this
|
|
18
|
-
* file; the only Google sign-in that existed anywhere in this product
|
|
19
|
-
* was the CLI's.
|
|
20
|
-
* 2. Connect Drive (`client/drive-connect.js`, which opens `/connect/drive`
|
|
21
|
-
* in the system browser and polls `/api/drive/token`) — grants the
|
|
22
|
-
* `drive.file` scope to WHICHEVER Google identity that browser's
|
|
23
|
-
* consent screen uses. That is only the SAME account as step 1 if step
|
|
24
|
-
* 1 ran first on this machine: `/connect/drive`'s callback resolves an
|
|
25
|
-
* account purely by Google identity, with no notion of "the account
|
|
26
|
-
* this machine's API key already belongs to" — so connecting Drive
|
|
27
|
-
* before signing in attaches the tokens to a DIFFERENT account than the
|
|
28
|
-
* one this machine will poll, and the poll just times out. `connectDrive`
|
|
29
|
-
* refuses outright when this machine has no key at all, but cannot
|
|
30
|
-
* detect "has a key, but it is an anonymous one" — that failure still
|
|
31
|
-
* surfaces, just later, as a timeout with the right wording.
|
|
32
|
-
*
|
|
33
|
-
* Electron-free and fully injected — same shape as `account-key.js` next to
|
|
34
|
-
* it — so the whole flow runs under a test with a stub `aegis` client, a
|
|
35
|
-
* stub `googleSignIn`/`driveConnect`/`driveUpload`, and no browser, window or
|
|
36
|
-
* network.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
function createGoogleConnect({
|
|
40
|
-
aegis,
|
|
41
|
-
credentials,
|
|
42
|
-
persistKey,
|
|
43
|
-
openUrl,
|
|
44
|
-
googleSignIn,
|
|
45
|
-
driveConnect,
|
|
46
|
-
driveUpload,
|
|
47
|
-
onAccountChange,
|
|
48
|
-
}) {
|
|
49
|
-
let signInInFlight = null;
|
|
50
|
-
let connectInFlight = null;
|
|
51
|
-
let lastSyncAt = null;
|
|
52
|
-
let lastSyncError = null;
|
|
53
|
-
|
|
54
|
-
/** Sign this machine in with Google, replacing whatever key it had. */
|
|
55
|
-
function signInWithGoogle() {
|
|
56
|
-
if (!signInInFlight) {
|
|
57
|
-
signInInFlight = (async () => {
|
|
58
|
-
try {
|
|
59
|
-
// Everything from here on (binding the local callback server,
|
|
60
|
-
// opening the browser, waiting for the round-trip) can fail, and
|
|
61
|
-
// every caller of this module — the IPC handler in main.js chief
|
|
62
|
-
// among them — is promised `{ ok, … }`/`{ ok: false, error }`,
|
|
63
|
-
// never a rejection. One try covers the whole flow instead of only
|
|
64
|
-
// the `session.wait()` half of it.
|
|
65
|
-
let session;
|
|
66
|
-
try {
|
|
67
|
-
session = await googleSignIn.startGoogleSignIn({ apiBase: aegis.apiBase });
|
|
68
|
-
} catch (e) {
|
|
69
|
-
return { ok: false, error: `could not start the local sign-in server — ${(e && e.message) || e}` };
|
|
70
|
-
}
|
|
71
|
-
const opened = Boolean(openUrl(session.url));
|
|
72
|
-
let result;
|
|
73
|
-
try {
|
|
74
|
-
result = await session.wait();
|
|
75
|
-
} catch (e) {
|
|
76
|
-
return { ok: false, opened, url: session.url, error: (e && e.message) || String(e) };
|
|
77
|
-
}
|
|
78
|
-
// Live client first: the very next call this process makes (e.g.
|
|
79
|
-
// the renderer asking for drive status right after this resolves)
|
|
80
|
-
// must see the new identity, not whatever key this process started
|
|
81
|
-
// with.
|
|
82
|
-
aegis.setApiKey(result.apiKey);
|
|
83
|
-
persistKey(result.apiKey);
|
|
84
|
-
if (result.memoryToken && credentials && typeof credentials.saveMemoryToken === 'function') {
|
|
85
|
-
try {
|
|
86
|
-
credentials.saveMemoryToken(result.memoryToken);
|
|
87
|
-
} catch {
|
|
88
|
-
/* best-effort — the account key itself is already saved */
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (typeof onAccountChange === 'function') onAccountChange();
|
|
92
|
-
return { ok: true, opened, url: session.url, username: result.username || null };
|
|
93
|
-
} finally {
|
|
94
|
-
signInInFlight = null;
|
|
95
|
-
}
|
|
96
|
-
})();
|
|
97
|
-
}
|
|
98
|
-
return signInInFlight;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Open `/connect/drive` and wait for this account to show connected. */
|
|
102
|
-
function connectDrive() {
|
|
103
|
-
if (!aegis.apiKey) {
|
|
104
|
-
return Promise.resolve({
|
|
105
|
-
ok: false,
|
|
106
|
-
error: 'sign in with Google first — this device has no AEGIS account key yet',
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
if (!connectInFlight) {
|
|
110
|
-
connectInFlight = (async () => {
|
|
111
|
-
try {
|
|
112
|
-
const url = driveConnect.driveConnectUrl(aegis.apiBase);
|
|
113
|
-
const opened = Boolean(openUrl(url));
|
|
114
|
-
try {
|
|
115
|
-
const status = await driveConnect.waitForDriveConnected(aegis);
|
|
116
|
-
return { ok: true, opened, url, connected: status.connected, email: status.email };
|
|
117
|
-
} catch (e) {
|
|
118
|
-
return { ok: false, opened, url, error: (e && e.message) || String(e) };
|
|
119
|
-
}
|
|
120
|
-
} finally {
|
|
121
|
-
connectInFlight = null;
|
|
122
|
-
}
|
|
123
|
-
})();
|
|
124
|
-
}
|
|
125
|
-
return connectInFlight;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** A one-shot read: signed in, and if so, is Drive connected. */
|
|
129
|
-
async function status() {
|
|
130
|
-
if (!aegis.apiKey) return { signedIn: false, connected: false, email: null };
|
|
131
|
-
const s = await driveConnect.driveStatus(aegis);
|
|
132
|
-
return { signedIn: true, ...s };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Pull this account's AEGIS cloud memory and back it up to Drive. */
|
|
136
|
-
async function syncMemoryNow() {
|
|
137
|
-
try {
|
|
138
|
-
const tokenInfo = await aegis.driveToken();
|
|
139
|
-
if (!tokenInfo || !tokenInfo.connected || !tokenInfo.access_token) {
|
|
140
|
-
throw new Error('Google Drive is not connected yet');
|
|
141
|
-
}
|
|
142
|
-
const pulled = await aegis.memoryPull(0);
|
|
143
|
-
const entries = (pulled && pulled.entries) || [];
|
|
144
|
-
const content = JSON.stringify({ exportedAt: new Date().toISOString(), entries }, null, 2);
|
|
145
|
-
const result = await driveUpload.uploadMemoryBackup(tokenInfo.access_token, content);
|
|
146
|
-
lastSyncAt = Date.now();
|
|
147
|
-
lastSyncError = null;
|
|
148
|
-
return {
|
|
149
|
-
ok: true,
|
|
150
|
-
count: entries.length,
|
|
151
|
-
fileId: result.fileId,
|
|
152
|
-
webViewLink: result.webViewLink,
|
|
153
|
-
updated: result.updated,
|
|
154
|
-
lastSyncAt,
|
|
155
|
-
};
|
|
156
|
-
} catch (e) {
|
|
157
|
-
lastSyncError = (e && e.message) || String(e);
|
|
158
|
-
return { ok: false, error: lastSyncError, lastSyncAt };
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
signInWithGoogle,
|
|
164
|
-
connectDrive,
|
|
165
|
-
status,
|
|
166
|
-
syncMemoryNow,
|
|
167
|
-
state: () => ({ lastSyncAt, lastSyncError }),
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
module.exports = { createGoogleConnect };
|
|
3
|
+
"use strict";function createGoogleConnect({aegis:e,credentials:n,persistKey:t,openUrl:o,googleSignIn:r,driveConnect:i,driveUpload:a,onAccountChange:c}){let l=null,s=null,u=null,g=null,d=!1;return{signInWithGoogle:function(){return l||(l=(async()=>{try{let i;try{i=await r.startGoogleSignIn({apiBase:e.apiBase})}catch(e){return{ok:!1,error:`could not start the local sign-in server — ${e&&e.message||e}`}}const a=Boolean(o(i.url));let l;try{l=await i.wait()}catch(e){return{ok:!1,opened:a,url:i.url,error:e&&e.message||String(e)}}if(e.setApiKey(l.apiKey),t(l.apiKey),l.memoryToken&&n&&"function"==typeof n.saveMemoryToken)try{n.saveMemoryToken(l.memoryToken)}catch{}return d=!0,"function"==typeof c&&c(),{ok:!0,opened:a,url:i.url,username:l.username||null}}finally{l=null}})()),l},connectDrive:async function(){return e.apiKey?(s||(s=(async()=>{try{let n=!0;try{const t=await i.driveStatus(e);n=!(t.googleLinkedKnown&&!t.googleLinked)}catch{}if(!n)return{ok:!1,error:"sign in with Google first — this account is not linked to a Google identity yet, and connecting Drive now would attach it to a different account"};const t=i.driveConnectUrl(e.apiBase),r=Boolean(o(t));try{const n=await i.waitForDriveConnected(e);return{ok:!0,opened:r,url:t,connected:n.connected,email:n.email}}catch(e){return{ok:!1,opened:r,url:t,error:e&&e.message||String(e)}}}finally{s=null}})()),s):{ok:!1,error:"sign in with Google first — this device has no AEGIS account key yet"}},status:async function(){if(!e.apiKey)return{signedIn:!1,googleLinked:!1,googleLinkedKnown:!0,connected:!1,email:null};const n=await i.driveStatus(e),t=!0===n.googleLinked||d;return{signedIn:t,...n,googleLinked:!0===n.googleLinked||t,googleLinkedKnown:n.googleLinkedKnown||t}},syncMemoryNow:async function(){try{const n=await e.driveToken();if(!n||!n.connected||!n.access_token)throw new Error("Google Drive is not connected yet");const t=await e.memoryPull(0),o=t&&t.entries||[],r=JSON.stringify({exportedAt:(new Date).toISOString(),entries:o},null,2),i=await a.uploadMemoryBackup(n.access_token,r);return u=Date.now(),g=null,{ok:!0,count:o.length,fileId:i.fileId,webViewLink:i.webViewLink,updated:i.updated,lastSyncAt:u}}catch(e){return g=e&&e.message||String(e),{ok:!1,error:g,lastSyncAt:u}}},state:()=>({lastSyncAt:u,lastSyncError:g})}}module.exports={createGoogleConnect:createGoogleConnect};
|
|
@@ -1,107 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* agents.js — subagent prompt presets for the desktop `task` tool, ported
|
|
10
|
-
* from the upstream engine reference (same roles, same synthesis presets).
|
|
11
|
-
* A preset is a system prompt: `task` runs it through the normal engine.chat
|
|
12
|
-
* loop as a nested turn (its own tool rounds, same model class), not a
|
|
13
|
-
* separate runtime, so the presets are pure prompt composition.
|
|
14
|
-
*
|
|
15
|
-
* Text is adapted to the desktop's own tool vocabulary (readFile/writeFile/
|
|
16
|
-
* editFile/listDir/glob/grep/exec/task — see tools.js) so a subagent's
|
|
17
|
-
* instructions never name a tool the desktop doesn't actually advertise.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/** Role → system prompt. */
|
|
21
|
-
const AGENT_PRESETS = {
|
|
22
|
-
synthesizer: `You are a senior technical lead. Given analysis from multiple specialist agents, synthesize their findings into a clear, actionable summary.
|
|
23
|
-
Structure your response as: key findings, recommended approach, top action items.
|
|
24
|
-
Be direct, concrete, and avoid repeating everything the agents said.
|
|
25
|
-
Focus on delivering a decision-ready synthesis.`,
|
|
26
|
-
|
|
27
|
-
architect: `You are a System Architect. Design the new application architecture.
|
|
28
|
-
Define: project structure, tech stack, directory layout, key modules, data flow, API design.
|
|
29
|
-
Consider: scalability, maintainability, testing strategy, deployment.
|
|
30
|
-
Output a concrete file tree and architecture decisions log. Be specific.`,
|
|
31
|
-
|
|
32
|
-
scaffolder: `You are a Project Scaffolder. Build the complete application from scratch.
|
|
33
|
-
|
|
34
|
-
YOUR JOB IS TO CREATE ALL PROJECT FILES - not just describe them.
|
|
35
|
-
|
|
36
|
-
Use writeFile to create: package.json, tsconfig.json, source files, configs, tests.
|
|
37
|
-
Generate COMPLETE, WORKING code - not stubs or placeholders.
|
|
38
|
-
Set up build scripts, lint config, and any necessary tooling.
|
|
39
|
-
|
|
40
|
-
After creating files, use exec to run: npm/pnpm install, then build/compile.
|
|
41
|
-
Fix any errors until the project builds successfully.
|
|
42
|
-
|
|
43
|
-
Be thorough - a real, runnable project is the goal.`,
|
|
44
|
-
|
|
45
|
-
planner: `You are a Refactoring Planner. Given the analyzer findings, create a step-by-step plan.
|
|
46
|
-
Each step: file path, what to change, why, risk level (LOW/MEDIUM/HIGH).
|
|
47
|
-
Include before/after snippets. Order by impact. Be concrete.`,
|
|
48
|
-
|
|
49
|
-
implementer: `You are an Implementation Engineer. Execute the refactoring plan.
|
|
50
|
-
Use editFile and writeFile to make actual code changes.
|
|
51
|
-
After each change, use readFile to verify correctness. Keep existing code style.
|
|
52
|
-
Run build commands with exec to ensure nothing is broken.`,
|
|
53
|
-
|
|
54
|
-
reviewer: `You are a Code Reviewer. Review the approach and code.
|
|
55
|
-
Check: logic errors, type safety, error handling, performance, security.
|
|
56
|
-
Be critical but constructive. Report specific issues with file paths.`,
|
|
57
|
-
|
|
58
|
-
debugger: `You are a Debugging Specialist. Analyze potential issues and edge cases.
|
|
59
|
-
Identify: failure modes, error handling gaps, testing considerations.
|
|
60
|
-
Think about what could go wrong and how to prevent it.`,
|
|
61
|
-
|
|
62
|
-
scanner: `You are a Security Vulnerability Scanner.
|
|
63
|
-
Scan for: hardcoded API keys/secrets, SQL injection, XSS, unsafe eval/exec, path traversal.
|
|
64
|
-
Use grep with targeted patterns. Report every finding with: file path, severity (CRITICAL/HIGH/MEDIUM/LOW), line number.`,
|
|
65
|
-
|
|
66
|
-
analyzer: `You are a Code Analyzer. Find refactoring opportunities.
|
|
67
|
-
Look for: duplicated code, long functions (>20 lines), complex conditionals, unused imports,
|
|
68
|
-
circular dependencies, inconsistent patterns. Report with file paths and line numbers.`,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/** System prompt for a `general` (or unrecognized) subagent type. */
|
|
72
|
-
const GENERAL_AGENT_PROMPT =
|
|
73
|
-
'You are a capable autonomous coding subagent. Complete the assigned task end to end using ' +
|
|
74
|
-
'the available tools (exec, readFile, writeFile, editFile, listDir, glob, grep). Work in the ' +
|
|
75
|
-
'current repository, verify your work, and finish with a concise report of what you did and ' +
|
|
76
|
-
'what you found. You cannot ask follow-up questions — make reasonable assumptions and proceed. ' +
|
|
77
|
-
'When a large sub-task is better handled by a focused specialist, delegate it with the task tool.';
|
|
78
|
-
|
|
79
|
-
/** Human-readable role label for a preset id (falls back to the id). */
|
|
80
|
-
function agentRoleLabel(role) {
|
|
81
|
-
const labels = {
|
|
82
|
-
synthesizer: 'Technical Lead', architect: 'System Architect',
|
|
83
|
-
scaffolder: 'Project Scaffolder', planner: 'Refactoring Planner',
|
|
84
|
-
implementer: 'Implementation Engineer', reviewer: 'Code Reviewer',
|
|
85
|
-
debugger: 'Debugging Specialist', scanner: 'Vulnerability Scanner',
|
|
86
|
-
analyzer: 'Code Analyzer', general: 'General',
|
|
87
|
-
};
|
|
88
|
-
return labels[role] || role;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Every preset id, in palette order (excludes the 'general' fallback). */
|
|
92
|
-
function agentRoles() {
|
|
93
|
-
return Object.keys(AGENT_PRESETS);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Resolve a subagent_type to its system prompt (unknown/absent → general). */
|
|
97
|
-
function agentSystemPrompt(role) {
|
|
98
|
-
return AGENT_PRESETS[role] || GENERAL_AGENT_PROMPT;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
module.exports = {
|
|
102
|
-
AGENT_PRESETS,
|
|
103
|
-
GENERAL_AGENT_PROMPT,
|
|
104
|
-
agentRoleLabel,
|
|
105
|
-
agentRoles,
|
|
106
|
-
agentSystemPrompt,
|
|
107
|
-
};
|
|
3
|
+
"use strict";const AGENT_PRESETS={synthesizer:"You are a senior technical lead. Given analysis from multiple specialist agents, synthesize their findings into a clear, actionable summary.\nStructure your response as: key findings, recommended approach, top action items.\nBe direct, concrete, and avoid repeating everything the agents said.\nFocus on delivering a decision-ready synthesis.",architect:"You are a System Architect. Design the new application architecture.\nDefine: project structure, tech stack, directory layout, key modules, data flow, API design.\nConsider: scalability, maintainability, testing strategy, deployment.\nOutput a concrete file tree and architecture decisions log. Be specific.",scaffolder:"You are a Project Scaffolder. Build the complete application from scratch.\n\nYOUR JOB IS TO CREATE ALL PROJECT FILES - not just describe them.\n\nUse writeFile to create: package.json, tsconfig.json, source files, configs, tests.\nGenerate COMPLETE, WORKING code - not stubs or placeholders.\nSet up build scripts, lint config, and any necessary tooling.\n\nAfter creating files, use exec to run: npm/pnpm install, then build/compile.\nFix any errors until the project builds successfully.\n\nBe thorough - a real, runnable project is the goal.",planner:"You are a Refactoring Planner. Given the analyzer findings, create a step-by-step plan.\nEach step: file path, what to change, why, risk level (LOW/MEDIUM/HIGH).\nInclude before/after snippets. Order by impact. Be concrete.",implementer:"You are an Implementation Engineer. Execute the refactoring plan.\nUse editFile and writeFile to make actual code changes.\nAfter each change, use readFile to verify correctness. Keep existing code style.\nRun build commands with exec to ensure nothing is broken.",reviewer:"You are a Code Reviewer. Review the approach and code.\nCheck: logic errors, type safety, error handling, performance, security.\nBe critical but constructive. Report specific issues with file paths.",debugger:"You are a Debugging Specialist. Analyze potential issues and edge cases.\nIdentify: failure modes, error handling gaps, testing considerations.\nThink about what could go wrong and how to prevent it.",scanner:"You are a Security Vulnerability Scanner.\nScan for: hardcoded API keys/secrets, SQL injection, XSS, unsafe eval/exec, path traversal.\nUse grep with targeted patterns. Report every finding with: file path, severity (CRITICAL/HIGH/MEDIUM/LOW), line number.",analyzer:"You are a Code Analyzer. Find refactoring opportunities.\nLook for: duplicated code, long functions (>20 lines), complex conditionals, unused imports,\ncircular dependencies, inconsistent patterns. Report with file paths and line numbers."},GENERAL_AGENT_PROMPT="You are a capable autonomous coding subagent. Complete the assigned task end to end using the available tools (exec, readFile, writeFile, editFile, listDir, glob, grep). Work in the current repository, verify your work, and finish with a concise report of what you did and what you found. You cannot ask follow-up questions — make reasonable assumptions and proceed. When a large sub-task is better handled by a focused specialist, delegate it with the task tool.";function agentRoleLabel(e){return{synthesizer:"Technical Lead",architect:"System Architect",scaffolder:"Project Scaffolder",planner:"Refactoring Planner",implementer:"Implementation Engineer",reviewer:"Code Reviewer",debugger:"Debugging Specialist",scanner:"Vulnerability Scanner",analyzer:"Code Analyzer",general:"General"}[e]||e}function agentRoles(){return Object.keys(AGENT_PRESETS)}function agentSystemPrompt(e){return AGENT_PRESETS[e]||GENERAL_AGENT_PROMPT}module.exports={AGENT_PRESETS:AGENT_PRESETS,GENERAL_AGENT_PROMPT:GENERAL_AGENT_PROMPT,agentRoleLabel:agentRoleLabel,agentRoles:agentRoles,agentSystemPrompt:agentSystemPrompt};
|