aegiscode 7.0.26 → 7.0.27
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/SOURCE-OFFER.txt +9 -0
- package/package.json +4 -7
- package/scripts/check.mjs +1 -52
- package/scripts/demo.mjs +1 -94
- package/scripts/predist.mjs +1 -75
- package/scripts/runtests.mjs +1 -56
- package/scripts/seal-gate.mjs +1 -74
- package/src/agents.js +1 -139
- package/src/app.js +1 -2957
- package/src/art.js +1 -289
- package/src/chatflow.js +1 -3023
- package/src/checkpoint.js +1 -90
- package/src/clipboard.js +1 -424
- package/src/cloudsync.js +1 -528
- package/src/commands.js +1 -4089
- package/src/config.js +1 -581
- package/src/connect.js +1 -349
- package/src/credentials.js +1 -33
- package/src/deps.js +1 -232
- package/src/devrun.js +1 -187
- package/src/diff.js +1 -333
- package/src/diffview.js +1 -296
- package/src/engine.js +1 -297
- package/src/entitlement.js +1 -355
- package/src/events.js +1 -707
- package/src/export.js +1 -67
- package/src/filepreview.js +1 -153
- package/src/fingerprint.js +1 -592
- package/src/format.js +1 -259
- package/src/fuzzy.js +1 -119
- package/src/history.js +1 -423
- package/src/init.js +1 -175
- package/src/input.js +1 -139
- package/src/keys.js +1 -183
- package/src/markdown.js +1 -306
- package/src/models.js +1 -507
- package/src/naming.js +1 -57
- package/src/overlays.js +1 -462
- package/src/panels.js +1 -1418
- package/src/ping.js +1 -226
- package/src/presence.js +1 -238
- package/src/render.js +1 -516
- package/src/screen.js +1 -518
- package/src/screens.js +1 -896
- package/src/secret.js +1 -59
- package/src/securefs.js +1 -359
- package/src/settings.js +1 -155
- package/src/shared.js +1 -52
- package/src/sharedpaths.js +1 -53
- package/src/signup.js +1 -156
- package/src/summarize.js +1 -95
- package/src/sysdiag.js +1 -585
- package/src/system.js +1 -40
- package/src/theme.js +1 -570
- package/src/title.js +1 -220
- package/src/todos.js +1 -115
- package/src/tokens.js +1 -263
- package/src/topup.js +1 -210
- package/src/update.js +1 -191
- package/vendor/client/aegis.js +1 -2441
- package/vendor/client/attest.js +1 -518
- package/vendor/client/authorship-key.js +1 -410
- package/vendor/client/auto-provision.js +1 -134
- package/vendor/client/brain-catalog.js +1 -268
- package/vendor/client/byok-catalog.js +1 -199
- package/vendor/client/catalog-client.js +1 -487
- package/vendor/client/conversation-export.js +1 -177
- package/vendor/client/credentials.js +1 -494
- package/vendor/client/device-fingerprint.js +1 -141
- package/vendor/client/drive-connect.js +1 -110
- package/vendor/client/drive-upload.js +1 -234
- package/vendor/client/env-file.js +1 -1273
- package/vendor/client/fingerprint.js +1 -1064
- package/vendor/client/foreign-memory.js +1 -669
- package/vendor/client/google-signin.js +1 -133
- package/vendor/client/hooks.js +1 -430
- package/vendor/client/model-discovery.js +1 -373
- package/vendor/client/naming.js +1 -283
- package/vendor/client/platform.js +1 -937
- package/vendor/client/prefs.js +1 -351
- package/vendor/client/presence-constants.js +1 -107
- package/vendor/client/presence.js +1 -438
- package/vendor/client/record-vault.js +3 -1055
- package/vendor/client/session-store.js +1 -575
- package/vendor/client/topup.js +1 -297
- package/vendor/client/touch.js +1 -458
- package/vendor/client/update.js +1 -763
- package/vendor/client/user-models.js +1 -381
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/attachments.js +1 -276
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -1028
- package/vendor/desktop/lib/local/context.js +1 -125
- package/vendor/desktop/lib/local/engine.js +1 -3666
- package/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/desktop/lib/local/exec-plan.js +1 -269
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/integrity.js +1 -163
- package/vendor/desktop/lib/local/local.js +1 -2145
- package/vendor/desktop/lib/local/prompt.js +1 -280
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -238
- package/vendor/desktop/lib/local/shell.js +1 -712
- package/vendor/desktop/lib/local/spill.js +1 -75
- package/vendor/desktop/lib/local/tools.js +1 -1328
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/main.js +3 -4890
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/hosts/install.js +1 -638
- package/vendor/hosts/openai-shim.js +1 -515
- package/vendor/hosts/spec.js +1 -164
- package/vendor/hosts/targets.js +1 -346
- package/vendor/mcp/server.js +1 -221
- package/vendor/mcp/tools.js +1 -408
- package/vendor/one/src/child.js +1 -285
- package/vendor/one/src/permissions.js +1 -383
package/src/fingerprint.js
CHANGED
|
@@ -1,594 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
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
|
-
* `aegiscode fingerprint` — the key and the record, from the terminal.
|
|
10
|
-
*
|
|
11
|
-
* aegiscode fingerprint status which key is in use, and where
|
|
12
|
-
* aegiscode fingerprint keygen mint a private authorship key
|
|
13
|
-
* aegiscode fingerprint mint seal a session as a φ(α) record
|
|
14
|
-
* aegiscode fingerprint verify <file> recompute a record's attestation
|
|
15
|
-
* aegiscode fingerprint backup --to DIR copy the key somewhere safe
|
|
16
|
-
* aegiscode fingerprint publish [<file>] put a record in the vault, link it
|
|
17
|
-
* aegiscode fingerprint anchor <file> is the published copy still ours?
|
|
18
|
-
* aegiscode fingerprint vault [--audit] what is in the vault (and is a key)
|
|
19
|
-
*
|
|
20
|
-
* This file is argv plumbing, output and exit codes: the cryptography and the
|
|
21
|
-
* key-handling rules are in `client/{fingerprint,authorship-key,attest}.js`,
|
|
22
|
-
* shared byte-for-byte with the desktop app so the two hosts cannot mint
|
|
23
|
-
* incompatible records. It is deliberately thin for the same reason `src/
|
|
24
|
-
* presence.js` is: the part worth testing is the shared part.
|
|
25
|
-
*
|
|
26
|
-
* ## Exit codes, because this is a script surface
|
|
27
|
-
*
|
|
28
|
-
* 0 the question was answered ("is it configured?" yes; "does it verify?" yes)
|
|
29
|
-
* 1 the answer is no — not configured, or the record does not verify
|
|
30
|
-
* 2 the command could not be carried out at all (usage, missing file, no key)
|
|
31
|
-
*
|
|
32
|
-
* 1 vs 2 is the difference a caller needs: `mint` failing because no key exists
|
|
33
|
-
* is not the same event as `verify` reporting a tampered record, and a monitoring
|
|
34
|
-
* script has to be able to tell them apart without parsing prose.
|
|
35
|
-
*
|
|
36
|
-
* ## The key is never printed
|
|
37
|
-
*
|
|
38
|
-
* Every subcommand that touches the key prints a *derived* 12-hex fingerprint
|
|
39
|
-
* (`keyFingerprint(secret)` = `sha256('aegiscode-agent-v1\n' + secret)[0:12]`,
|
|
40
|
-
* the same value the avatar registry indexes by), and
|
|
41
|
-
* `test/cli-fingerprint.test.mjs` asserts the key's text appears nowhere in
|
|
42
|
-
* stdout or stderr. That is the only way "which key is this?" can be answered
|
|
43
|
-
* across two machines without either machine revealing one.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
const fs = require('node:fs');
|
|
47
|
-
const path = require('node:path');
|
|
48
|
-
|
|
49
|
-
const { resolveClientModule } = require('./shared.js');
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The shared modules are resolved by existence (repo checkout first, staged
|
|
53
|
-
* vendor tree second) — see `src/shared.js`. `fingerprint.js` requires
|
|
54
|
-
* `./touch.js` and `authorship-key.js` requires `./fingerprint.js` by plain
|
|
55
|
-
* same-directory paths, so all five must be staged together; a package missing
|
|
56
|
-
* one would be a MODULE_NOT_FOUND at load, which is loud and correct.
|
|
57
|
-
*/
|
|
58
|
-
function load() {
|
|
59
|
-
return {
|
|
60
|
-
fp: require(resolveClientModule('fingerprint.js')),
|
|
61
|
-
authorship: require(resolveClientModule('authorship-key.js')),
|
|
62
|
-
attest: require(resolveClientModule('attest.js')),
|
|
63
|
-
vault: require(resolveClientModule('record-vault.js')),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** `--flag value`, repeatable flags returned in order. */
|
|
68
|
-
function flag(argv, name, fallback = null) {
|
|
69
|
-
const i = argv.indexOf(name);
|
|
70
|
-
return i !== -1 && argv[i + 1] !== undefined && !argv[i + 1].startsWith('--')
|
|
71
|
-
? argv[i + 1]
|
|
72
|
-
: fallback;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function everyFlag(argv, name) {
|
|
76
|
-
const out = [];
|
|
77
|
-
for (let i = 0; i < argv.length - 1; i += 1) {
|
|
78
|
-
if (argv[i] === name && !argv[i + 1].startsWith('--')) out.push(argv[i + 1]);
|
|
79
|
-
}
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function has(argv, name) {
|
|
84
|
-
return argv.includes(name);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** A session id goes into a filename, so it may not be a path. */
|
|
88
|
-
function slug(value, max = 80) {
|
|
89
|
-
return String(value || 'session')
|
|
90
|
-
.replace(/[^A-Za-z0-9._-]+/g, '_')
|
|
91
|
-
.replace(/^[._-]+/, '')
|
|
92
|
-
.slice(0, max) || 'session';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Where a minted record lands with no `--out`. `last` is the honest name for
|
|
97
|
-
* "the last session in the log" — this module does not know the id because
|
|
98
|
-
* `attest` chose it, and inventing one would put a wrong name in the filename.
|
|
99
|
-
*/
|
|
100
|
-
function defaultRecordPath(record, session, dataDir) {
|
|
101
|
-
const stamp = String(record.createdAt).replace(/[:.]/g, '-');
|
|
102
|
-
return path.join(dataDir, 'fingerprints', `${slug(session)}.${stamp}.json`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const HELP = `aegiscode fingerprint — φ(α): a sealed record of what a session was.
|
|
106
|
-
|
|
107
|
-
Usage:
|
|
108
|
-
aegiscode fingerprint status [--json]
|
|
109
|
-
aegiscode fingerprint keygen [--out F] [--force]
|
|
110
|
-
aegiscode fingerprint mint [--history F] [--session ID] [--turns N]
|
|
111
|
-
[--label L] [--account A] [--model M] [--tools a,b]
|
|
112
|
-
[--code-root DIR]... [--code-file F]...
|
|
113
|
-
[--code-clean | --code-dirty] [--out F] [--json]
|
|
114
|
-
[--ai-secret FILE] [--ai-model M]
|
|
115
|
-
aegiscode fingerprint verify <record.json> [--secret FILE] [--json]
|
|
116
|
-
aegiscode fingerprint backup [--secret FILE] --to DIR [--name N]
|
|
117
|
-
aegiscode fingerprint publish [<record.json>] [--remote R] [--root D]
|
|
118
|
-
[--dry-run] [--no-index] [--out F] [--json]
|
|
119
|
-
aegiscode fingerprint anchor <record.json> [--json]
|
|
120
|
-
aegiscode fingerprint vault [--audit] [--max N] [--json]
|
|
121
|
-
|
|
122
|
-
Key:
|
|
123
|
-
--secret FILE also --secret-file (the engine's spelling). A private
|
|
124
|
-
key, which MUST NOT be group/other readable.
|
|
125
|
-
--ai-secret FILE the credential the session RAN ON — a model-provider key,
|
|
126
|
-
not the authorship key. Only its 12-hex fingerprint is
|
|
127
|
-
recorded as 'aiKey'; the key itself never is. Also read
|
|
128
|
-
from $AEGIS_AI_SECRET. With neither, the record says
|
|
129
|
-
aiKey: null rather than borrowing the sealing key.
|
|
130
|
-
--ai-model M the model that answered. Defaults to whatever the session
|
|
131
|
-
log recorded, else null.
|
|
132
|
-
--out F where keygen writes, or where mint writes the record
|
|
133
|
-
--force keygen: replace an existing key. Orphans every record
|
|
134
|
-
minted under the old one, so it is never implicit.
|
|
135
|
-
--public --covenant F
|
|
136
|
-
key to the published covenant hash instead of a private
|
|
137
|
-
key. Such a record verifies for ANY covenant holder —
|
|
138
|
-
integrity, not authorship — and is labelled as such.
|
|
139
|
-
|
|
140
|
-
Vault:
|
|
141
|
-
publish copies the SEALED BYTES to the vault, byte-identical, and
|
|
142
|
-
writes the link (<record>.anchor.json) beside the local
|
|
143
|
-
copy.
|
|
144
|
-
|
|
145
|
-
DEFAULT BACKEND: aegiscloud — the account this machine
|
|
146
|
-
already registered for (the same device key every other
|
|
147
|
-
cloud feature uses, so publishing needs no second
|
|
148
|
-
sign-in). Nothing to configure; if there is no key yet,
|
|
149
|
-
'aegiscode login' gives you one.
|
|
150
|
-
|
|
151
|
-
--backend rclone puts the copy somewhere YOU own instead:
|
|
152
|
-
--remote <name> --root <folder> (AEGIS_VAULT_REMOTE /
|
|
153
|
-
AEGIS_VAULT_ROOT), e.g. --remote gdrive --root
|
|
154
|
-
AEGIS-AGPL. That needs an rclone remote already
|
|
155
|
-
configured; the account vault does not.
|
|
156
|
-
anchor re-downloads the published copy and checks three separate
|
|
157
|
-
things: present, unchanged (sha256), still attested.
|
|
158
|
-
vault --audit inspects every object already in the vault for key
|
|
159
|
-
material and names it. The key is never published: a
|
|
160
|
-
secret in cloud storage can mint records that
|
|
161
|
-
impersonate yours.
|
|
162
|
-
|
|
163
|
-
The key is read from --secret, then $AEGIS_FINGERPRINT_SECRET, then
|
|
164
|
-
$AEGIS_HOME/keys/authorship.key (default ~/.aegiscode/keys/authorship.key).
|
|
165
|
-
With none of those, mint and verify refuse: a key nobody chose is a key whose
|
|
166
|
-
records prove nothing.`;
|
|
167
|
-
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
// subcommands
|
|
170
|
-
// ---------------------------------------------------------------------------
|
|
171
|
-
|
|
172
|
-
function status(argv, io) {
|
|
173
|
-
const { authorship } = load();
|
|
174
|
-
const env = io.env || process.env;
|
|
175
|
-
const key = authorship.resolveKey({ argv, env });
|
|
176
|
-
const history = path.join(authorship.dataDir(env), 'history.jsonl');
|
|
177
|
-
const report = {
|
|
178
|
-
configured: Boolean(key.secret),
|
|
179
|
-
key_source: key.source,
|
|
180
|
-
key_path: key.path,
|
|
181
|
-
key_file_mode: key.path && !/^win/.test(process.platform) ? authorship.modeString(fs.statSync(key.path).mode & 0o777) : null,
|
|
182
|
-
key_fingerprint: key.secret ? load().fp.keyFingerprint(key.secret) : null,
|
|
183
|
-
public_key: key.public,
|
|
184
|
-
default_key_path: authorship.defaultKeyPath(env),
|
|
185
|
-
history_path: history,
|
|
186
|
-
history_present: fs.existsSync(history),
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
if (io.json) {
|
|
190
|
-
io.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
191
|
-
return report.configured ? 0 : 1;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const lines = [
|
|
195
|
-
`key: ${report.configured ? report.key_fingerprint : 'not set'}`,
|
|
196
|
-
`source: ${report.key_source || 'none'}`,
|
|
197
|
-
`file: ${report.key_path || report.default_key_path}`,
|
|
198
|
-
`mode: ${report.key_file_mode || 'n/a'}`,
|
|
199
|
-
`public key: ${report.public_key ? 'YES — anyone holding the covenant can forge these records' : 'no'}`,
|
|
200
|
-
`history: ${report.history_path}${report.history_present ? '' : ' (not created yet)'}`,
|
|
201
|
-
];
|
|
202
|
-
if (!report.configured) {
|
|
203
|
-
lines.push('', 'No key yet. Mint one: aegiscode fingerprint keygen');
|
|
204
|
-
}
|
|
205
|
-
io.stdout.write(lines.join('\n') + '\n');
|
|
206
|
-
return report.configured ? 0 : 1;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function keygen(argv, io) {
|
|
210
|
-
const { authorship } = load();
|
|
211
|
-
const r = authorship.keygen({ argv, env: io.env || process.env });
|
|
212
|
-
if (io.json) {
|
|
213
|
-
io.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
214
|
-
return 0;
|
|
215
|
-
}
|
|
216
|
-
io.stdout.write(
|
|
217
|
-
[
|
|
218
|
-
`${r.replaced ? 'replaced' : 'created'} ${r.out} (mode ${r.mode})`,
|
|
219
|
-
`key: ${r.keyFingerprint} (derived — the key itself was not printed)`,
|
|
220
|
-
`bytes: ${r.bytes} random (256-bit)`,
|
|
221
|
-
'',
|
|
222
|
-
'Next: aegiscode fingerprint mint seal the last session',
|
|
223
|
-
` aegiscode fingerprint backup --to ~/safe keep a copy of the key`,
|
|
224
|
-
].join('\n') + '\n',
|
|
225
|
-
);
|
|
226
|
-
return 0;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function mint(argv, io) {
|
|
230
|
-
const { attest, authorship } = load();
|
|
231
|
-
const env = io.env || process.env;
|
|
232
|
-
const roots = everyFlag(argv, '--code-root');
|
|
233
|
-
const files = everyFlag(argv, '--code-file');
|
|
234
|
-
const codeClean = has(argv, '--code-clean');
|
|
235
|
-
const codeDirty = has(argv, '--code-dirty');
|
|
236
|
-
if (codeClean && codeDirty) throw new Error('fingerprint: --code-clean and --code-dirty are exclusive');
|
|
237
|
-
|
|
238
|
-
const code = roots.length || files.length
|
|
239
|
-
? attest.collectCode({ roots, files, skip: everyFlag(argv, '--code-skip') })
|
|
240
|
-
: [];
|
|
241
|
-
|
|
242
|
-
// The AI half. `attestedFields` carries the field list, so the AI flags are
|
|
243
|
-
// read by the shared adapter (`--ai-secret`, `$AEGIS_AI_SECRET`) exactly as the
|
|
244
|
-
// module documents; this host only forwards the one flag it must shape.
|
|
245
|
-
const r = attest.mintSession({
|
|
246
|
-
argv,
|
|
247
|
-
env,
|
|
248
|
-
aiModel: flag(argv, '--ai-model') || undefined,
|
|
249
|
-
history: flag(argv, '--history') || undefined,
|
|
250
|
-
session: flag(argv, '--session') || undefined,
|
|
251
|
-
turns: flag(argv, '--turns') || undefined,
|
|
252
|
-
label: flag(argv, '--label') || undefined,
|
|
253
|
-
account: flag(argv, '--account') || undefined,
|
|
254
|
-
model: flag(argv, '--model') || undefined,
|
|
255
|
-
tools: flag(argv, '--tools') ? flag(argv, '--tools').split(',').map((s) => s.trim()).filter(Boolean) : undefined,
|
|
256
|
-
code,
|
|
257
|
-
codeDirty: codeClean ? false : codeDirty ? true : null,
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const out =
|
|
261
|
-
flag(argv, '--out') ||
|
|
262
|
-
defaultRecordPath(r.record, flag(argv, '--session') || 'last', authorship.dataDir(env));
|
|
263
|
-
fs.mkdirSync(path.dirname(path.resolve(out)), { recursive: true });
|
|
264
|
-
fs.writeFileSync(path.resolve(out), JSON.stringify(r.record, null, 2) + '\n');
|
|
265
|
-
|
|
266
|
-
if (io.json) {
|
|
267
|
-
io.stdout.write(JSON.stringify({ ...r.record, keySource: r.keySource, out: path.resolve(out) }, null, 2) + '\n');
|
|
268
|
-
return 0;
|
|
269
|
-
}
|
|
270
|
-
io.stdout.write(
|
|
271
|
-
[
|
|
272
|
-
`record ${path.resolve(out)}`,
|
|
273
|
-
`identity φ_${r.record.keyFingerprint} (key: ${r.keySource}${r.public ? ' — PUBLIC, forgeable by any covenant holder' : ''})`,
|
|
274
|
-
`behaviour ${r.record.behaviour || 'none'} from ${r.record.behaviourSamples} turn(s)`,
|
|
275
|
-
`code ${r.record.code || 'none'} ${r.record.codeFiles} file(s)${
|
|
276
|
-
r.record.codeDirty === null ? ' (clean/dirty unknown)' : r.record.codeDirty ? ' (dirty tree)' : ' (clean tree)'
|
|
277
|
-
}`,
|
|
278
|
-
`ai ${r.record.aiKey || 'none'}${r.record.aiKey ? ` (${r.aiKeySource})` : ' — no AI credential nominated (--ai-secret | $AEGIS_AI_SECRET)'}`,
|
|
279
|
-
`ai habit ${r.record.ai || 'unobserved'} from ${r.record.aiSamples} reply/replies${
|
|
280
|
-
r.record.aiModel ? ` on ${r.record.aiModel}` : ''
|
|
281
|
-
}`,
|
|
282
|
-
`sealed ${r.record.attestation} (v${r.record.v}, ${r.record.algo})`,
|
|
283
|
-
r.samples === 0 ? 'note: no turns matched — the record says so rather than signing nothing' : '',
|
|
284
|
-
]
|
|
285
|
-
.filter(Boolean)
|
|
286
|
-
.join('\n') + '\n',
|
|
287
|
-
);
|
|
288
|
-
return 0;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function verify(argv, io) {
|
|
292
|
-
const { fp, authorship } = load();
|
|
293
|
-
const file = argv.find((a) => !a.startsWith('-'));
|
|
294
|
-
if (!file) throw new Error('fingerprint: verify needs a record file');
|
|
295
|
-
|
|
296
|
-
let record;
|
|
297
|
-
try {
|
|
298
|
-
record = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
299
|
-
} catch (e) {
|
|
300
|
-
throw new Error(`fingerprint: cannot read ${file} as JSON — ${e.message}`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const key = authorship.resolveKey({ argv, env: io.env || process.env });
|
|
304
|
-
if (!key.secret) {
|
|
305
|
-
throw new Error(
|
|
306
|
-
'fingerprint: no key to verify with — pass --secret <file>, set ' +
|
|
307
|
-
'AEGIS_FINGERPRINT_SECRET, or run `aegiscode fingerprint keygen`',
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const v = fp.verify(record, key.secret);
|
|
312
|
-
const body = {
|
|
313
|
-
ok: v.ok,
|
|
314
|
-
reason: v.reason,
|
|
315
|
-
id: v.id,
|
|
316
|
-
credential_match: v.credentialMatch,
|
|
317
|
-
key_source: key.source,
|
|
318
|
-
key_fingerprint_recorded: record.keyFingerprint || null,
|
|
319
|
-
file: path.resolve(file),
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
if (io.json) {
|
|
323
|
-
io.stdout.write(JSON.stringify(body, null, 2) + '\n');
|
|
324
|
-
return v.ok ? 0 : 1;
|
|
325
|
-
}
|
|
326
|
-
io.stdout.write(
|
|
327
|
-
v.ok
|
|
328
|
-
? `verified ${record.keyFingerprint} — intact, and minted by ${key.source}\n` +
|
|
329
|
-
`record ${v.id}\n`
|
|
330
|
-
: `FAILED ${v.reason}\n` +
|
|
331
|
-
`key used ${key.source}\n` +
|
|
332
|
-
`fingerprint recorded ${record.keyFingerprint || '(none)'}\n`,
|
|
333
|
-
);
|
|
334
|
-
return v.ok ? 0 : 1;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function backup(argv, io) {
|
|
338
|
-
const { authorship } = load();
|
|
339
|
-
const r = authorship.backup({ argv, env: io.env || process.env });
|
|
340
|
-
if (io.json) {
|
|
341
|
-
io.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
342
|
-
return 0;
|
|
343
|
-
}
|
|
344
|
-
io.stdout.write(
|
|
345
|
-
[
|
|
346
|
-
`key copied ${r.from} -> ${r.to}`,
|
|
347
|
-
`fingerprint ${r.keyFingerprint} (same key, confirmed by re-reading the copy)`,
|
|
348
|
-
'restore: point --secret at the copy (or copy it back to the key path). ' +
|
|
349
|
-
'Nothing else changes.',
|
|
350
|
-
].join('\n') + '\n',
|
|
351
|
-
);
|
|
352
|
-
return 0;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* The key, when there is one, for the vault's leak check.
|
|
357
|
-
*
|
|
358
|
-
* `null` rather than a throw: publishing is a thing you do *after* sealing, and
|
|
359
|
-
* a host whose key resolution fails should still be told what is wrong by the
|
|
360
|
-
* vault check rather than by an unrelated resolve error. When a key does
|
|
361
|
-
* resolve, the vault compares every published byte against it.
|
|
362
|
-
*/
|
|
363
|
-
function secretOrNull(authorship, argv, env) {
|
|
364
|
-
try {
|
|
365
|
-
return authorship.resolveKey({ argv, env }).secret || null;
|
|
366
|
-
} catch {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/** The newest local record, for `publish` with no path. */
|
|
372
|
-
function newestRecord(dataDir) {
|
|
373
|
-
const dir = path.join(dataDir, 'fingerprints');
|
|
374
|
-
if (!fs.existsSync(dir)) return null;
|
|
375
|
-
const files = fs
|
|
376
|
-
.readdirSync(dir)
|
|
377
|
-
.filter((f) => f.endsWith('.json') && !f.endsWith('.anchor.json'))
|
|
378
|
-
.map((f) => path.join(dir, f))
|
|
379
|
-
.map((f) => ({ f, mtime: fs.statSync(f).mtimeMs }))
|
|
380
|
-
.sort((a, b) => b.mtime - a.mtime);
|
|
381
|
-
return files.length ? files[0].f : null;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
async function publish(argv, io) {
|
|
385
|
-
const { authorship, vault } = load();
|
|
386
|
-
const env = io.env || process.env;
|
|
387
|
-
const positional = argv.find((a) => !a.startsWith('-'));
|
|
388
|
-
const file = positional ? path.resolve(positional) : newestRecord(authorship.dataDir(env));
|
|
389
|
-
|
|
390
|
-
if (!file) {
|
|
391
|
-
throw new Error(
|
|
392
|
-
'fingerprint: no record to publish — seal one first ' +
|
|
393
|
-
'(`aegiscode fingerprint mint`), or name the file: ' +
|
|
394
|
-
'`aegiscode fingerprint publish <record.json>`',
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
if (!fs.existsSync(file)) throw new Error(`fingerprint: no record at ${file}`);
|
|
398
|
-
|
|
399
|
-
const r = await vault.publish({
|
|
400
|
-
file,
|
|
401
|
-
argv,
|
|
402
|
-
env,
|
|
403
|
-
dryRun: has(argv, '--dry-run'),
|
|
404
|
-
secret: secretOrNull(authorship, argv, env),
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
if (io.json) {
|
|
408
|
-
io.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
409
|
-
return 0;
|
|
410
|
-
}
|
|
411
|
-
if (r.dryRun) {
|
|
412
|
-
io.stdout.write(
|
|
413
|
-
[
|
|
414
|
-
`dry run nothing uploaded`,
|
|
415
|
-
`backend ${r.backend}`,
|
|
416
|
-
`record ${file}`,
|
|
417
|
-
`would go ${r.remotePath}`,
|
|
418
|
-
...r.commands.map((c) => ` ${c}`),
|
|
419
|
-
].join('\n') + '\n',
|
|
420
|
-
);
|
|
421
|
-
return 0;
|
|
422
|
-
}
|
|
423
|
-
io.stdout.write(
|
|
424
|
-
[
|
|
425
|
-
`published ${r.remotePath} (${r.backend})`,
|
|
426
|
-
`identity φ_${r.anchor.keyFingerprint}-${r.anchor.behaviour || 'unobserved'}`,
|
|
427
|
-
`digest sha256 ${r.sha256.slice(0, 16)}… (${r.bytes} bytes, byte-identical to ${file})`,
|
|
428
|
-
`link ${r.url || '(no share link — the copy is at the path above)'}`,
|
|
429
|
-
`anchored ${r.localAnchor}${r.indexLines === null ? '' : ` · ledger lines ${r.indexLines}`}`,
|
|
430
|
-
'',
|
|
431
|
-
'The key was NOT published. Only the sealed record travels; verify the copy',
|
|
432
|
-
`any time with: aegiscode fingerprint anchor ${path.basename(file)}`,
|
|
433
|
-
].join('\n') + '\n',
|
|
434
|
-
);
|
|
435
|
-
return 0;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
async function anchorCmd(argv, io) {
|
|
439
|
-
const { vault } = load();
|
|
440
|
-
const file = argv.find((a) => !a.startsWith('-'));
|
|
441
|
-
if (!file) throw new Error('fingerprint: anchor needs a record file (the one you published)');
|
|
442
|
-
|
|
443
|
-
const r = await vault.checkAnchor({ file: path.resolve(file), argv, env: io.env || process.env });
|
|
444
|
-
if (io.json) {
|
|
445
|
-
io.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
446
|
-
return r.ok ? 0 : 1;
|
|
447
|
-
}
|
|
448
|
-
if (!r.anchor) {
|
|
449
|
-
io.stdout.write(`not linked ${path.resolve(file)}\n ${r.reason}\n`);
|
|
450
|
-
return 1;
|
|
451
|
-
}
|
|
452
|
-
io.stdout.write(
|
|
453
|
-
[
|
|
454
|
-
`record ${path.resolve(file)}`,
|
|
455
|
-
`published ${r.anchor.path}${r.anchor.url ? `\n ${r.anchor.url}` : ''}`,
|
|
456
|
-
`emitted ${r.anchor.emittedAt}`,
|
|
457
|
-
`present ${r.present ? 'yes' : 'NO'}`,
|
|
458
|
-
`unchanged ${r.unchanged ? 'yes — the copy is the bytes that were sealed' : 'NO — sha256 differs'}`,
|
|
459
|
-
`attested ${r.attested === null ? `unknown (${r.attestationReason})` : r.attested ? 'yes — this key still recomputes it' : `NO — ${r.attestationReason}`}`,
|
|
460
|
-
'',
|
|
461
|
-
r.ok ? 'ok — the vault copy is the sealed record, unchanged.' : `FAILED — ${r.reason}`,
|
|
462
|
-
].join('\n') + '\n',
|
|
463
|
-
);
|
|
464
|
-
return r.ok ? 0 : 1;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
async function vaultCmd(argv, io) {
|
|
468
|
-
const { authorship, vault } = load();
|
|
469
|
-
const env = io.env || process.env;
|
|
470
|
-
const audit = has(argv, '--audit');
|
|
471
|
-
|
|
472
|
-
if (audit) {
|
|
473
|
-
const r = await vault.audit({ argv, env, secret: secretOrNull(authorship, argv, env) });
|
|
474
|
-
if (io.json) {
|
|
475
|
-
io.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
476
|
-
return r.ok ? 0 : 1;
|
|
477
|
-
}
|
|
478
|
-
if (r.error) {
|
|
479
|
-
io.stdout.write(`vault unreachable — ${r.error}\n`);
|
|
480
|
-
return 2;
|
|
481
|
-
}
|
|
482
|
-
io.stdout.write(
|
|
483
|
-
[
|
|
484
|
-
`vault ${r.where} (backend ${r.backend})`,
|
|
485
|
-
`inspected ${r.checked} of ${r.files} object(s)`,
|
|
486
|
-
r.uninspected.length ? `skipped ${r.uninspected.length} (see --json)` : '',
|
|
487
|
-
'',
|
|
488
|
-
r.findings.length === 0
|
|
489
|
-
? 'clean — no key material in the vault.'
|
|
490
|
-
: [
|
|
491
|
-
`KEY MATERIAL IN THE VAULT — ${r.findings.length} finding(s):`,
|
|
492
|
-
...r.findings.map((f) => ` ${f.path}\n ${f.reason}`),
|
|
493
|
-
'',
|
|
494
|
-
'Anyone who can read that folder can mint records that look like yours.',
|
|
495
|
-
'Move it out, then rotate: aegiscode fingerprint keygen --force',
|
|
496
|
-
'(rotation orphans every record minted under the old key — publish new ones.)',
|
|
497
|
-
].join('\n'),
|
|
498
|
-
]
|
|
499
|
-
.filter(Boolean)
|
|
500
|
-
.join('\n') + '\n',
|
|
501
|
-
);
|
|
502
|
-
return r.ok ? 0 : 1;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
const r = await vault.list({ argv, env });
|
|
506
|
-
if (io.json) {
|
|
507
|
-
io.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
508
|
-
return 0;
|
|
509
|
-
}
|
|
510
|
-
const lines = [`vault ${r.where} (${r.records.length} record(s), backend ${r.backend})`];
|
|
511
|
-
for (const rec of r.records) {
|
|
512
|
-
lines.push(
|
|
513
|
-
` ${rec.name}`,
|
|
514
|
-
` id ${rec.id || '(no anchor)'} · sha256 ${rec.sha256 ? rec.sha256.slice(0, 16) + '…' : '(none)'}`,
|
|
515
|
-
rec.url ? ` ${rec.url}` : '',
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
if (!r.records.length) lines.push(' (no records published yet — `aegiscode fingerprint publish`)');
|
|
519
|
-
io.stdout.write(lines.filter(Boolean).join('\n') + '\n');
|
|
520
|
-
return 0;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Run a subcommand. Returns the process exit code; never throws (a throw here
|
|
525
|
-
* would be a stack trace over a usage message, which is what a user reads when
|
|
526
|
-
* the command is spelled wrong).
|
|
527
|
-
*/
|
|
528
|
-
function runFingerprint(sub, argv = [], io = {}) {
|
|
529
|
-
const out = {
|
|
530
|
-
json: false,
|
|
531
|
-
stdout: process.stdout,
|
|
532
|
-
stderr: process.stderr,
|
|
533
|
-
env: process.env,
|
|
534
|
-
...io,
|
|
535
|
-
// `--json` is the SUBCOMMAND's flag. bin/aegiscode.js hands the tail of the
|
|
536
|
-
// line over verbatim (like `mcp`/`autonomous`, and for the same reason:
|
|
537
|
-
// `--secret-file` is not a session flag), so the session parser never sees
|
|
538
|
-
// it and `io.json` is always false here. Honouring both keeps
|
|
539
|
-
// `aegiscode fingerprint status --json` meaning what it reads as.
|
|
540
|
-
json: Boolean(io.json) || argv.includes('--json'),
|
|
541
|
-
};
|
|
542
|
-
const name = String(sub || 'status').toLowerCase();
|
|
543
|
-
|
|
544
|
-
try {
|
|
545
|
-
if (name === 'help' || name === '--help' || name === '-h') {
|
|
546
|
-
out.stdout.write(HELP + '\n');
|
|
547
|
-
return 0;
|
|
548
|
-
}
|
|
549
|
-
switch (name) {
|
|
550
|
-
case 'status':
|
|
551
|
-
return status(argv, out);
|
|
552
|
-
case 'keygen':
|
|
553
|
-
return keygen(argv, out);
|
|
554
|
-
case 'mint':
|
|
555
|
-
return mint(argv, out);
|
|
556
|
-
case 'verify':
|
|
557
|
-
return verify(argv, out);
|
|
558
|
-
case 'backup':
|
|
559
|
-
return backup(argv, out);
|
|
560
|
-
// The three vault subcommands are async because the default vault is
|
|
561
|
-
// the account (an HTTP vault) as well as rclone. They keep the same
|
|
562
|
-
// contract though — an exit code, and a throw becomes exit 2 — so a
|
|
563
|
-
// caller only has to `await` the result; the sync subcommands above
|
|
564
|
-
// still return a plain number, which is what `runFingerprint` always did
|
|
565
|
-
// and what its tests assert.
|
|
566
|
-
case 'publish':
|
|
567
|
-
return asExitCode(publish(argv, out), out);
|
|
568
|
-
case 'anchor':
|
|
569
|
-
return asExitCode(anchorCmd(argv, out), out);
|
|
570
|
-
case 'vault':
|
|
571
|
-
return asExitCode(vaultCmd(argv, out), out);
|
|
572
|
-
default:
|
|
573
|
-
out.stderr.write(`aegiscode: unknown fingerprint subcommand "${sub}"\n\n${HELP}\n`);
|
|
574
|
-
return 2;
|
|
575
|
-
}
|
|
576
|
-
} catch (e) {
|
|
577
|
-
out.stderr.write(`aegiscode: ${(e && e.message) || e}\n`);
|
|
578
|
-
return 2;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* A vault subcommand's promise, as the same exit-code contract the sync
|
|
584
|
-
* subcommands have: a rejection is a usage-shaped line on stderr and exit 2,
|
|
585
|
-
* never a stack trace over a user's record (see this file's header on 1 vs 2).
|
|
586
|
-
*/
|
|
587
|
-
function asExitCode(promise, io) {
|
|
588
|
-
return promise.catch((e) => {
|
|
589
|
-
io.stderr.write(`aegiscode: ${(e && e.message) || e}\n`);
|
|
590
|
-
return 2;
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
module.exports = { runFingerprint, HELP, slug, defaultRecordPath, flag, everyFlag };
|
|
3
|
+
"use strict";const fs=require("node:fs"),path=require("node:path"),{resolveClientModule:resolveClientModule}=require("./shared.js");function load(){return{fp:require(resolveClientModule("fingerprint.js")),authorship:require(resolveClientModule("authorship-key.js")),attest:require(resolveClientModule("attest.js")),vault:require(resolveClientModule("record-vault.js"))}}function flag(e,n,t=null){const r=e.indexOf(n);return-1===r||void 0===e[r+1]||e[r+1].startsWith("--")?t:e[r+1]}function everyFlag(e,n){const t=[];for(let r=0;r<e.length-1;r+=1)e[r]!==n||e[r+1].startsWith("--")||t.push(e[r+1]);return t}function has(e,n){return e.includes(n)}function slug(e,n=80){return String(e||"session").replace(/[^A-Za-z0-9._-]+/g,"_").replace(/^[._-]+/,"").slice(0,n)||"session"}function defaultRecordPath(e,n,t){const r=String(e.createdAt).replace(/[:.]/g,"-");return path.join(t,"fingerprints",`${slug(n)}.${r}.json`)}const HELP="aegiscode fingerprint — φ(α): a sealed record of what a session was.\n\nUsage:\n aegiscode fingerprint status [--json]\n aegiscode fingerprint keygen [--out F] [--force]\n aegiscode fingerprint mint [--history F] [--session ID] [--turns N]\n [--label L] [--account A] [--model M] [--tools a,b]\n [--code-root DIR]... [--code-file F]...\n [--code-clean | --code-dirty] [--out F] [--json]\n [--ai-secret FILE] [--ai-model M]\n aegiscode fingerprint verify <record.json> [--secret FILE] [--json]\n aegiscode fingerprint backup [--secret FILE] --to DIR [--name N]\n aegiscode fingerprint publish [<record.json>] [--remote R] [--root D]\n [--dry-run] [--no-index] [--out F] [--json]\n aegiscode fingerprint anchor <record.json> [--json]\n aegiscode fingerprint vault [--audit] [--max N] [--json]\n\nKey:\n --secret FILE also --secret-file (the engine's spelling). A private\n key, which MUST NOT be group/other readable.\n --ai-secret FILE the credential the session RAN ON — a model-provider key,\n not the authorship key. Only its 12-hex fingerprint is\n recorded as 'aiKey'; the key itself never is. Also read\n from $AEGIS_AI_SECRET. With neither, the record says\n aiKey: null rather than borrowing the sealing key.\n --ai-model M the model that answered. Defaults to whatever the session\n log recorded, else null.\n --out F where keygen writes, or where mint writes the record\n --force keygen: replace an existing key. Orphans every record\n minted under the old one, so it is never implicit.\n --public --covenant F\n key to the published covenant hash instead of a private\n key. Such a record verifies for ANY covenant holder —\n integrity, not authorship — and is labelled as such.\n\nVault:\n publish copies the SEALED BYTES to the vault, byte-identical, and\n writes the link (<record>.anchor.json) beside the local\n copy.\n\n DEFAULT BACKEND: aegiscloud — the account this machine\n already registered for (the same device key every other\n cloud feature uses, so publishing needs no second\n sign-in). Nothing to configure; if there is no key yet,\n 'aegiscode login' gives you one.\n\n --backend rclone puts the copy somewhere YOU own instead:\n --remote <name> --root <folder> (AEGIS_VAULT_REMOTE /\n AEGIS_VAULT_ROOT), e.g. --remote gdrive --root\n AEGIS-AGPL. That needs an rclone remote already\n configured; the account vault does not.\n anchor re-downloads the published copy and checks three separate\n things: present, unchanged (sha256), still attested.\n vault --audit inspects every object already in the vault for key\n material and names it. The key is never published: a\n secret in cloud storage can mint records that\n impersonate yours.\n\nThe key is read from --secret, then $AEGIS_FINGERPRINT_SECRET, then\n$AEGIS_HOME/keys/authorship.key (default ~/.aegiscode/keys/authorship.key).\nWith none of those, mint and verify refuse: a key nobody chose is a key whose\nrecords prove nothing.";function status(e,n){const{authorship:t}=load(),r=n.env||process.env,o=t.resolveKey({argv:e,env:r}),i=path.join(t.dataDir(r),"history.jsonl"),s={configured:Boolean(o.secret),key_source:o.source,key_path:o.path,key_file_mode:o.path&&!/^win/.test(process.platform)?t.modeString(511&fs.statSync(o.path).mode):null,key_fingerprint:o.secret?load().fp.keyFingerprint(o.secret):null,public_key:o.public,default_key_path:t.defaultKeyPath(r),history_path:i,history_present:fs.existsSync(i)};if(n.json)return n.stdout.write(JSON.stringify(s,null,2)+"\n"),s.configured?0:1;const a=[`key: ${s.configured?s.key_fingerprint:"not set"}`,`source: ${s.key_source||"none"}`,`file: ${s.key_path||s.default_key_path}`,`mode: ${s.key_file_mode||"n/a"}`,"public key: "+(s.public_key?"YES — anyone holding the covenant can forge these records":"no"),`history: ${s.history_path}${s.history_present?"":" (not created yet)"}`];return s.configured||a.push("","No key yet. Mint one: aegiscode fingerprint keygen"),n.stdout.write(a.join("\n")+"\n"),s.configured?0:1}function keygen(e,n){const{authorship:t}=load(),r=t.keygen({argv:e,env:n.env||process.env});return n.json?(n.stdout.write(JSON.stringify(r,null,2)+"\n"),0):(n.stdout.write([`${r.replaced?"replaced":"created"} ${r.out} (mode ${r.mode})`,`key: ${r.keyFingerprint} (derived — the key itself was not printed)`,`bytes: ${r.bytes} random (256-bit)`,"","Next: aegiscode fingerprint mint seal the last session"," aegiscode fingerprint backup --to ~/safe keep a copy of the key"].join("\n")+"\n"),0)}function mint(e,n){const{attest:t,authorship:r}=load(),o=n.env||process.env,i=everyFlag(e,"--code-root"),s=everyFlag(e,"--code-file"),a=has(e,"--code-clean"),c=has(e,"--code-dirty");if(a&&c)throw new Error("fingerprint: --code-clean and --code-dirty are exclusive");const d=i.length||s.length?t.collectCode({roots:i,files:s,skip:everyFlag(e,"--code-skip")}):[],l=t.mintSession({argv:e,env:o,aiModel:flag(e,"--ai-model")||void 0,history:flag(e,"--history")||void 0,session:flag(e,"--session")||void 0,turns:flag(e,"--turns")||void 0,label:flag(e,"--label")||void 0,account:flag(e,"--account")||void 0,model:flag(e,"--model")||void 0,tools:flag(e,"--tools")?flag(e,"--tools").split(",").map((e=>e.trim())).filter(Boolean):void 0,code:d,codeDirty:!a&&(!!c||null)}),u=flag(e,"--out")||defaultRecordPath(l.record,flag(e,"--session")||"last",r.dataDir(o));return fs.mkdirSync(path.dirname(path.resolve(u)),{recursive:!0}),fs.writeFileSync(path.resolve(u),JSON.stringify(l.record,null,2)+"\n"),n.json?(n.stdout.write(JSON.stringify({...l.record,keySource:l.keySource,out:path.resolve(u)},null,2)+"\n"),0):(n.stdout.write([`record ${path.resolve(u)}`,`identity φ_${l.record.keyFingerprint} (key: ${l.keySource}${l.public?" — PUBLIC, forgeable by any covenant holder":""})`,`behaviour ${l.record.behaviour||"none"} from ${l.record.behaviourSamples} turn(s)`,`code ${l.record.code||"none"} ${l.record.codeFiles} file(s)${null===l.record.codeDirty?" (clean/dirty unknown)":l.record.codeDirty?" (dirty tree)":" (clean tree)"}`,`ai ${l.record.aiKey||"none"}${l.record.aiKey?` (${l.aiKeySource})`:" — no AI credential nominated (--ai-secret | $AEGIS_AI_SECRET)"}`,`ai habit ${l.record.ai||"unobserved"} from ${l.record.aiSamples} reply/replies${l.record.aiModel?` on ${l.record.aiModel}`:""}`,`sealed ${l.record.attestation} (v${l.record.v}, ${l.record.algo})`,0===l.samples?"note: no turns matched — the record says so rather than signing nothing":""].filter(Boolean).join("\n")+"\n"),0)}function verify(e,n){const{fp:t,authorship:r}=load(),o=e.find((e=>!e.startsWith("-")));if(!o)throw new Error("fingerprint: verify needs a record file");let i;try{i=JSON.parse(fs.readFileSync(o,"utf8"))}catch(e){throw new Error(`fingerprint: cannot read ${o} as JSON — ${e.message}`)}const s=r.resolveKey({argv:e,env:n.env||process.env});if(!s.secret)throw new Error("fingerprint: no key to verify with — pass --secret <file>, set AEGIS_FINGERPRINT_SECRET, or run `aegiscode fingerprint keygen`");const a=t.verify(i,s.secret),c={ok:a.ok,reason:a.reason,id:a.id,credential_match:a.credentialMatch,key_source:s.source,key_fingerprint_recorded:i.keyFingerprint||null,file:path.resolve(o)};return n.json?(n.stdout.write(JSON.stringify(c,null,2)+"\n"),a.ok?0:1):(n.stdout.write(a.ok?`verified ${i.keyFingerprint} — intact, and minted by ${s.source}\nrecord ${a.id}\n`:`FAILED ${a.reason}\nkey used ${s.source}\nfingerprint recorded ${i.keyFingerprint||"(none)"}\n`),a.ok?0:1)}function backup(e,n){const{authorship:t}=load(),r=t.backup({argv:e,env:n.env||process.env});return n.json?(n.stdout.write(JSON.stringify(r,null,2)+"\n"),0):(n.stdout.write([`key copied ${r.from} -> ${r.to}`,`fingerprint ${r.keyFingerprint} (same key, confirmed by re-reading the copy)`,"restore: point --secret at the copy (or copy it back to the key path). Nothing else changes."].join("\n")+"\n"),0)}function secretOrNull(e,n,t){try{return e.resolveKey({argv:n,env:t}).secret||null}catch{return null}}function newestRecord(e){const n=path.join(e,"fingerprints");if(!fs.existsSync(n))return null;const t=fs.readdirSync(n).filter((e=>e.endsWith(".json")&&!e.endsWith(".anchor.json"))).map((e=>path.join(n,e))).map((e=>({f:e,mtime:fs.statSync(e).mtimeMs}))).sort(((e,n)=>n.mtime-e.mtime));return t.length?t[0].f:null}async function publish(e,n){const{authorship:t,vault:r}=load(),o=n.env||process.env,i=e.find((e=>!e.startsWith("-"))),s=i?path.resolve(i):newestRecord(t.dataDir(o));if(!s)throw new Error("fingerprint: no record to publish — seal one first (`aegiscode fingerprint mint`), or name the file: `aegiscode fingerprint publish <record.json>`");if(!fs.existsSync(s))throw new Error(`fingerprint: no record at ${s}`);const a=await r.publish({file:s,argv:e,env:o,dryRun:has(e,"--dry-run"),secret:secretOrNull(t,e,o)});return n.json?(n.stdout.write(JSON.stringify(a,null,2)+"\n"),0):a.dryRun?(n.stdout.write(["dry run nothing uploaded",`backend ${a.backend}`,`record ${s}`,`would go ${a.remotePath}`,...a.commands.map((e=>` ${e}`))].join("\n")+"\n"),0):(n.stdout.write([`published ${a.remotePath} (${a.backend})`,`identity φ_${a.anchor.keyFingerprint}-${a.anchor.behaviour||"unobserved"}`,`digest sha256 ${a.sha256.slice(0,16)}… (${a.bytes} bytes, byte-identical to ${s})`,`link ${a.url||"(no share link — the copy is at the path above)"}`,`anchored ${a.localAnchor}${null===a.indexLines?"":` · ledger lines ${a.indexLines}`}`,"","The key was NOT published. Only the sealed record travels; verify the copy",`any time with: aegiscode fingerprint anchor ${path.basename(s)}`].join("\n")+"\n"),0)}async function anchorCmd(e,n){const{vault:t}=load(),r=e.find((e=>!e.startsWith("-")));if(!r)throw new Error("fingerprint: anchor needs a record file (the one you published)");const o=await t.checkAnchor({file:path.resolve(r),argv:e,env:n.env||process.env});return n.json?(n.stdout.write(JSON.stringify(o,null,2)+"\n"),o.ok?0:1):o.anchor?(n.stdout.write([`record ${path.resolve(r)}`,`published ${o.anchor.path}${o.anchor.url?`\n ${o.anchor.url}`:""}`,`emitted ${o.anchor.emittedAt}`,"present "+(o.present?"yes":"NO"),"unchanged "+(o.unchanged?"yes — the copy is the bytes that were sealed":"NO — sha256 differs"),"attested "+(null===o.attested?`unknown (${o.attestationReason})`:o.attested?"yes — this key still recomputes it":`NO — ${o.attestationReason}`),"",o.ok?"ok — the vault copy is the sealed record, unchanged.":`FAILED — ${o.reason}`].join("\n")+"\n"),o.ok?0:1):(n.stdout.write(`not linked ${path.resolve(r)}\n ${o.reason}\n`),1)}async function vaultCmd(e,n){const{authorship:t,vault:r}=load(),o=n.env||process.env;if(has(e,"--audit")){const i=await r.audit({argv:e,env:o,secret:secretOrNull(t,e,o)});return n.json?(n.stdout.write(JSON.stringify(i,null,2)+"\n"),i.ok?0:1):i.error?(n.stdout.write(`vault unreachable — ${i.error}\n`),2):(n.stdout.write([`vault ${i.where} (backend ${i.backend})`,`inspected ${i.checked} of ${i.files} object(s)`,i.uninspected.length?`skipped ${i.uninspected.length} (see --json)`:"","",0===i.findings.length?"clean — no key material in the vault.":[`KEY MATERIAL IN THE VAULT — ${i.findings.length} finding(s):`,...i.findings.map((e=>` ${e.path}\n ${e.reason}`)),"","Anyone who can read that folder can mint records that look like yours.","Move it out, then rotate: aegiscode fingerprint keygen --force","(rotation orphans every record minted under the old key — publish new ones.)"].join("\n")].filter(Boolean).join("\n")+"\n"),i.ok?0:1)}const i=await r.list({argv:e,env:o});if(n.json)return n.stdout.write(JSON.stringify(i,null,2)+"\n"),0;const s=[`vault ${i.where} (${i.records.length} record(s), backend ${i.backend})`];for(const e of i.records)s.push(` ${e.name}`,` id ${e.id||"(no anchor)"} · sha256 ${e.sha256?e.sha256.slice(0,16)+"…":"(none)"}`,e.url?` ${e.url}`:"");return i.records.length||s.push(" (no records published yet — `aegiscode fingerprint publish`)"),n.stdout.write(s.filter(Boolean).join("\n")+"\n"),0}function runFingerprint(e,n=[],t={}){const r={json:!1,stdout:process.stdout,stderr:process.stderr,env:process.env,...t,json:Boolean(t.json)||n.includes("--json")},o=String(e||"status").toLowerCase();try{if("help"===o||"--help"===o||"-h"===o)return r.stdout.write(HELP+"\n"),0;switch(o){case"status":return status(n,r);case"keygen":return keygen(n,r);case"mint":return mint(n,r);case"verify":return verify(n,r);case"backup":return backup(n,r);case"publish":return asExitCode(publish(n,r),r);case"anchor":return asExitCode(anchorCmd(n,r),r);case"vault":return asExitCode(vaultCmd(n,r),r);default:return r.stderr.write(`aegiscode: unknown fingerprint subcommand "${e}"\n\n${HELP}\n`),2}}catch(e){return r.stderr.write(`aegiscode: ${e&&e.message||e}\n`),2}}function asExitCode(e,n){return e.catch((e=>(n.stderr.write(`aegiscode: ${e&&e.message||e}\n`),2)))}module.exports={runFingerprint:runFingerprint,HELP:HELP,slug:slug,defaultRecordPath:defaultRecordPath,flag:flag,everyFlag:everyFlag};
|