aegisone 1.0.34 → 1.0.35

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.
Files changed (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -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};