aegisone 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +1 -1
- package/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -322
- package/package.json +4 -5
- package/scripts/bump.mjs +1 -211
- package/scripts/bundle.js +1 -129
- package/scripts/predist.mjs +1 -939
- package/src/child.js +1 -285
- package/src/dispatch.js +1 -269
- package/src/doctor.js +1 -639
- package/src/host.js +1 -111
- package/src/permissions.js +1 -369
- package/src/probes.js +1 -159
- package/src/release.js +1 -409
- package/vendor/cli/bin/aegiscode.js +2 -914
- package/vendor/cli/package.json +3 -7
- package/vendor/cli/scripts/check.mjs +1 -52
- package/vendor/cli/scripts/demo.mjs +1 -94
- package/vendor/cli/scripts/predist.mjs +1 -75
- package/vendor/cli/scripts/runtests.mjs +1 -56
- package/vendor/cli/scripts/seal-gate.mjs +1 -74
- package/vendor/cli/src/agents.js +1 -139
- package/vendor/cli/src/app.js +1 -2932
- package/vendor/cli/src/art.js +1 -289
- package/vendor/cli/src/autonomous.js +1 -515
- package/vendor/cli/src/caps.js +1 -879
- package/vendor/cli/src/chatflow.js +1 -3020
- package/vendor/cli/src/checkpoint.js +1 -90
- package/vendor/cli/src/clipboard.js +1 -424
- package/vendor/cli/src/cloudsync.js +1 -528
- package/vendor/cli/src/commands.js +1 -4003
- package/vendor/cli/src/config.js +1 -581
- package/vendor/cli/src/connect.js +1 -349
- package/vendor/cli/src/credentials.js +1 -33
- package/vendor/cli/src/deps.js +1 -232
- package/vendor/cli/src/devrun.js +1 -187
- package/vendor/cli/src/diff.js +1 -333
- package/vendor/cli/src/diffview.js +1 -296
- package/vendor/cli/src/engine.js +1 -297
- package/vendor/cli/src/entitlement.js +1 -355
- package/vendor/cli/src/events.js +1 -707
- package/vendor/cli/src/export.js +1 -67
- package/vendor/cli/src/fingerprint.js +1 -592
- package/vendor/cli/src/format.js +1 -259
- package/vendor/cli/src/fuzzy.js +1 -119
- package/vendor/cli/src/gate.js +1 -55
- package/vendor/cli/src/history.js +1 -401
- package/vendor/cli/src/init.js +1 -175
- package/vendor/cli/src/input.js +1 -139
- package/vendor/cli/src/keys.js +1 -183
- package/vendor/cli/src/limits.js +1 -190
- package/vendor/cli/src/markdown.js +1 -306
- package/vendor/cli/src/mcp.js +1 -694
- package/vendor/cli/src/models.js +1 -487
- package/vendor/cli/src/naming.js +1 -229
- package/vendor/cli/src/overlays.js +1 -461
- package/vendor/cli/src/panels.js +1 -1418
- package/vendor/cli/src/permissions.js +1 -290
- package/vendor/cli/src/ping.js +1 -226
- package/vendor/cli/src/presence.js +1 -238
- package/vendor/cli/src/provenance.js +2 -182
- package/vendor/cli/src/render.js +1 -515
- package/vendor/cli/src/screen.js +1 -518
- package/vendor/cli/src/screens.js +1 -896
- package/vendor/cli/src/secret.js +1 -59
- package/vendor/cli/src/securefs.js +1 -359
- package/vendor/cli/src/settings.js +1 -155
- package/vendor/cli/src/shared.js +1 -52
- package/vendor/cli/src/sharedpaths.js +1 -53
- package/vendor/cli/src/signup.js +1 -156
- package/vendor/cli/src/summarize.js +1 -95
- package/vendor/cli/src/sysdiag.js +1 -585
- package/vendor/cli/src/system.js +1 -40
- package/vendor/cli/src/theme.js +1 -570
- package/vendor/cli/src/title.js +1 -220
- package/vendor/cli/src/todos.js +1 -115
- package/vendor/cli/src/tokens.js +1 -263
- package/vendor/cli/src/topup.js +1 -210
- package/vendor/cli/src/update.js +1 -181
- package/vendor/cli/vendor/client/aegis.js +1 -2179
- package/vendor/cli/vendor/client/attest.js +1 -442
- package/vendor/cli/vendor/client/authorship-key.js +1 -410
- package/vendor/cli/vendor/client/auto-provision.js +1 -134
- package/vendor/cli/vendor/client/brain-catalog.js +1 -268
- package/vendor/cli/vendor/client/byok-catalog.js +1 -230
- package/vendor/cli/vendor/client/credentials.js +1 -494
- package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
- package/vendor/cli/vendor/client/drive-connect.js +1 -110
- package/vendor/cli/vendor/client/drive-upload.js +1 -174
- package/vendor/cli/vendor/client/env-file.js +1 -1273
- package/vendor/cli/vendor/client/fingerprint.js +1 -1064
- package/vendor/cli/vendor/client/foreign-memory.js +1 -669
- package/vendor/cli/vendor/client/google-signin.js +1 -133
- package/vendor/cli/vendor/client/hooks.js +1 -430
- package/vendor/cli/vendor/client/model-discovery.js +1 -373
- package/vendor/cli/vendor/client/platform.js +1 -937
- package/vendor/cli/vendor/client/prefs.js +1 -351
- package/vendor/cli/vendor/client/presence-constants.js +1 -107
- package/vendor/cli/vendor/client/presence.js +1 -438
- package/vendor/cli/vendor/client/record-vault.js +3 -1055
- package/vendor/cli/vendor/client/session-store.js +1 -548
- package/vendor/cli/vendor/client/topup.js +1 -297
- package/vendor/cli/vendor/client/touch.js +1 -458
- package/vendor/cli/vendor/client/update.js +1 -704
- package/vendor/cli/vendor/client/user-models.js +1 -381
- package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3301
- package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
- package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/cli/vendor/hosts/install.js +1 -638
- package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
- package/vendor/cli/vendor/hosts/spec.js +1 -164
- package/vendor/cli/vendor/hosts/targets.js +1 -346
- package/vendor/cli/vendor/mcp/server.js +1 -221
- package/vendor/cli/vendor/mcp/tools.js +1 -408
- package/vendor/cli/vendor/one/src/child.js +1 -285
- package/vendor/cli/vendor/one/src/permissions.js +1 -369
- package/vendor/desktop/bin/aegis.js +1 -32
- package/vendor/desktop/lib/account-key.js +1 -56
- package/vendor/desktop/lib/auto.js +1 -430
- package/vendor/desktop/lib/avatar/companion.js +1 -698
- package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
- package/vendor/desktop/lib/avatar/events.js +1 -344
- package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
- package/vendor/desktop/lib/avatar/holders.js +1 -612
- package/vendor/desktop/lib/avatar/identity.js +1 -641
- package/vendor/desktop/lib/avatar/level.js +1 -368
- package/vendor/desktop/lib/avatar/mirror.js +1 -524
- package/vendor/desktop/lib/avatar/persona.js +1 -388
- package/vendor/desktop/lib/avatar/profile.js +1 -977
- package/vendor/desktop/lib/avatar/register.js +1 -307
- package/vendor/desktop/lib/avatar/store.js +1 -472
- package/vendor/desktop/lib/avatar/tiers.js +1 -38
- package/vendor/desktop/lib/avatar/transfer.js +1 -415
- package/vendor/desktop/lib/avatar/turn.js +1 -216
- package/vendor/desktop/lib/avatar/voice.js +1 -328
- package/vendor/desktop/lib/avatar/xp.js +1 -404
- package/vendor/desktop/lib/deep-link.js +1 -120
- package/vendor/desktop/lib/fingerprint.js +2 -347
- package/vendor/desktop/lib/google-connect.js +1 -227
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/desktop/lib/local/engine.js +1 -3301
- package/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/desktop/lib/local/telemetry.js +1 -470
- package/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/provider-key-mirror.js +1 -252
- package/vendor/desktop/lib/quick-launcher.js +1 -84
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/lib/sync/memory-queue.js +1 -60
- package/vendor/desktop/lib/sync/persist-gate.js +1 -148
- package/vendor/desktop/lib/sync/sessions.js +1 -106
- package/vendor/desktop/lib/window-state.js +1 -66
- package/vendor/desktop/main.js +1 -4529
- package/vendor/desktop/package.json +3 -5
- package/vendor/desktop/preload.js +1 -636
- package/vendor/desktop/renderer/app.js +1 -6660
- package/vendor/desktop/renderer/avatar/assemble.js +1 -335
- package/vendor/desktop/renderer/avatar/avatar.js +1 -380
- package/vendor/desktop/renderer/avatar/cards.js +1 -141
- package/vendor/desktop/renderer/avatar/hud.js +1 -206
- package/vendor/desktop/renderer/avatar/machine.js +1 -213
- package/vendor/desktop/renderer/avatar/pane.js +1 -439
- package/vendor/desktop/renderer/avatar/parts.js +1 -437
- package/vendor/desktop/renderer/budget.js +1 -168
- package/vendor/desktop/renderer/companion.js +1 -223
- package/vendor/desktop/renderer/diff.js +1 -359
- package/vendor/desktop/renderer/diffview.js +1 -336
- package/vendor/desktop/renderer/fingerprint.js +3 -736
- package/vendor/desktop/renderer/markdown.js +1 -168
- package/vendor/desktop/renderer/provider-toolbar.js +1 -134
- package/vendor/desktop/renderer/providers.js +1 -259
- package/vendor/desktop/renderer/quick.js +1 -191
- package/vendor/desktop/renderer/stream-policy.js +1 -306
- package/vendor/desktop/renderer/transcript-view.js +1 -323
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/desktop/vendor/aegis.js +1 -2179
- package/vendor/desktop/vendor/attest.js +1 -442
- package/vendor/desktop/vendor/authorship-key.js +1 -410
- package/vendor/desktop/vendor/auto-provision.js +1 -134
- package/vendor/desktop/vendor/brain-catalog.js +1 -268
- package/vendor/desktop/vendor/byok-catalog.js +1 -230
- package/vendor/desktop/vendor/credentials.js +1 -494
- package/vendor/desktop/vendor/device-fingerprint.js +1 -141
- package/vendor/desktop/vendor/drive-connect.js +1 -110
- package/vendor/desktop/vendor/drive-upload.js +1 -174
- package/vendor/desktop/vendor/env-file.js +1 -1273
- package/vendor/desktop/vendor/fingerprint.js +1 -1064
- package/vendor/desktop/vendor/foreign-memory.js +1 -669
- package/vendor/desktop/vendor/google-signin.js +1 -133
- package/vendor/desktop/vendor/hooks.js +1 -430
- package/vendor/desktop/vendor/model-discovery.js +1 -373
- package/vendor/desktop/vendor/platform.js +1 -937
- package/vendor/desktop/vendor/prefs.js +1 -351
- package/vendor/desktop/vendor/presence-constants.js +1 -107
- package/vendor/desktop/vendor/presence.js +1 -438
- package/vendor/desktop/vendor/record-vault.js +3 -1055
- package/vendor/desktop/vendor/session-store.js +1 -548
- package/vendor/desktop/vendor/topup.js +1 -297
- package/vendor/desktop/vendor/touch.js +1 -458
- package/vendor/desktop/vendor/update.js +1 -704
- package/vendor/desktop/vendor/user-models.js +1 -381
|
@@ -1,240 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The CLI's presence beacon — the `aegiscode` half of `client/presence.js`.
|
|
10
|
-
*
|
|
11
|
-
* `client/presence.js` owns the protocol (the route, the cadence the server
|
|
12
|
-
* asks for, the backoff ladder, the body allowlist). This file owns the three
|
|
13
|
-
* things only the CLI can know:
|
|
14
|
-
*
|
|
15
|
-
* - WHICH key. The credential store resolution (env → credentials.json →
|
|
16
|
-
* config.json) is the CLI's, not the shared transport's, and it is the same
|
|
17
|
-
* resolution every other CLI call uses. A host with no key does not beacon:
|
|
18
|
-
* `presence.js` returns an inert store rather than 401-looping, and this
|
|
19
|
-
* module simply reports that it is off.
|
|
20
|
-
* - WHICH build. `cli/package.json` at require time, so the panel shows the
|
|
21
|
-
* version the user actually installed rather than a constant that drifts
|
|
22
|
-
* from the release.
|
|
23
|
-
* - HOW BUSY. `autonomous: true` while `aegiscode autonomous` is draining a
|
|
24
|
-
* queue, and the pending depth at send time, so the panel can tell "an idle
|
|
25
|
-
* terminal is open" from "this machine is working through a queue".
|
|
26
|
-
*
|
|
27
|
-
* A module-level singleton, because a beacon is a process-wide fact and the
|
|
28
|
-
* lifecycle hooks that start and stop it are in `bin/aegiscode.js` — argument
|
|
29
|
-
* parsing and process lifecycle, which is not testable — while everything
|
|
30
|
-
* below is driven directly by `test/cli-presence.test.mjs`.
|
|
31
|
-
*
|
|
32
|
-
* Kill switch: `AEGIS_NO_PRESENCE=1` (or `0`/`false` for the settings-file
|
|
33
|
-
* equivalent is NOT read here — this host has no settings store). An operator
|
|
34
|
-
* debugging a network stack, or a CI runner that must make no outbound calls,
|
|
35
|
-
* gets to turn the beacon off without a code change.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
const path = require('node:path');
|
|
39
|
-
const { resolveShared } = require('./sharedpaths.js');
|
|
40
|
-
|
|
41
|
-
/** `AEGIS_NO_PRESENCE` truthy ⇒ never beacon from this host. Anything else
|
|
42
|
-
* (unset, '', '0', 'false', 'no') leaves the beacon on: the default has to be
|
|
43
|
-
* "beacon", because a presence panel that is off unless someone remembers to
|
|
44
|
-
* switch it on is a panel with no rows in it. */
|
|
45
|
-
const KILL_ENV = 'AEGIS_NO_PRESENCE';
|
|
46
|
-
|
|
47
|
-
function presenceDisabled(env) {
|
|
48
|
-
try {
|
|
49
|
-
const raw = env && env[KILL_ENV];
|
|
50
|
-
if (raw == null || String(raw).trim() === '') return false;
|
|
51
|
-
return /^(1|true|on|yes)$/i.test(String(raw).trim());
|
|
52
|
-
} catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Lazily required so `--help`, `--version` and `key status` stay instant and
|
|
58
|
-
* dependency-free: a beacon is for a *session*, not for a subcommand. */
|
|
59
|
-
function loadShared() {
|
|
60
|
-
const presence = require(resolveShared(path.join('client', 'presence.js')));
|
|
61
|
-
const fingerprint = require(resolveShared(path.join('client', 'device-fingerprint.js')));
|
|
62
|
-
return { presence, fingerprint };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The CLI's own build string. A missing/unreadable package.json is not a
|
|
66
|
-
* reason to skip the beacon: the fields are individually optional server-side. */
|
|
67
|
-
function cliVersion() {
|
|
68
|
-
try {
|
|
69
|
-
return require(path.join(__dirname, '..', 'package.json')).version || null;
|
|
70
|
-
} catch {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let current = null;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Start (or restart) the CLI beacon. Idempotent by replacement: calling it
|
|
79
|
-
* twice stops the first store, so the timer count cannot grow with the number
|
|
80
|
-
* of calls. Never throws — a beacon that cannot start is a beacon that is off,
|
|
81
|
-
* and the session proceeds.
|
|
82
|
-
*
|
|
83
|
-
* @param {object} [opts]
|
|
84
|
-
* @param {object} [opts.client] an already-built aegis client (its apiKey wins)
|
|
85
|
-
* @param {object} [opts.credentials] the credential store to resolve a key from
|
|
86
|
-
* @param {boolean} [opts.autonomous] this process is draining a queue
|
|
87
|
-
* @param {number|function} [opts.queueDepth] pending tasks, or a reader for them
|
|
88
|
-
* @param {object} [opts.env] override process.env (tests)
|
|
89
|
-
* @param {object} [opts.io] { stdout, stderr } — never used today, kept
|
|
90
|
-
* so a future `--verbose` can narrate a beat
|
|
91
|
-
* @returns {{enabled: boolean, reason: string|null, stop: () => void, state: () => object}}
|
|
92
|
-
*/
|
|
93
|
-
function start(opts = {}) {
|
|
94
|
-
stop();
|
|
95
|
-
const env = opts.env || process.env;
|
|
96
|
-
if (presenceDisabled(env)) {
|
|
97
|
-
return (current = inert('kill-switch'));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let apiKey = '';
|
|
101
|
-
try {
|
|
102
|
-
if (opts.client && typeof opts.client.apiKey === 'string') apiKey = opts.client.apiKey;
|
|
103
|
-
if (!apiKey && opts.credentials && typeof opts.credentials.resolveApiKey === 'function') {
|
|
104
|
-
const resolved = opts.credentials.resolveApiKey({ env });
|
|
105
|
-
apiKey = (resolved && (resolved.key || resolved.apiKey)) || '';
|
|
106
|
-
}
|
|
107
|
-
} catch {
|
|
108
|
-
apiKey = '';
|
|
109
|
-
}
|
|
110
|
-
if (!apiKey) return (current = inert('no-api-key'));
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
const { presence, fingerprint } = loadShared();
|
|
114
|
-
const store = presence.createPresence({
|
|
115
|
-
apiKey,
|
|
116
|
-
// 'cli', not 'aegiscode': aegis1 keeps only the names in its own
|
|
117
|
-
// PRESENCE_APPS tuple (app.py) and stores anything else as 'other', so a
|
|
118
|
-
// product name here would make every terminal session unidentifiable in
|
|
119
|
-
// the admin panel while still answering 200. See
|
|
120
|
-
// client/presence-constants.js — a test parses the server's tuple and
|
|
121
|
-
// fails if the two lists drift.
|
|
122
|
-
app: 'cli',
|
|
123
|
-
version: cliVersion(),
|
|
124
|
-
platform: process.platform,
|
|
125
|
-
// The SAME identity the device-registration path uses — see the header of
|
|
126
|
-
// client/presence.js for why the beacon must carry the machine, not a
|
|
127
|
-
// per-run random token. Computed here rather than inside presence.js so a
|
|
128
|
-
// fingerprint failure is visible at the call site.
|
|
129
|
-
install: fingerprint.machineFingerprint(),
|
|
130
|
-
queueDepth: opts.queueDepth,
|
|
131
|
-
autonomous: Boolean(opts.autonomous),
|
|
132
|
-
log: opts.log,
|
|
133
|
-
fetchImpl: opts.fetchImpl,
|
|
134
|
-
now: opts.now,
|
|
135
|
-
setTimer: opts.setTimer,
|
|
136
|
-
clearTimer: opts.clearTimer,
|
|
137
|
-
});
|
|
138
|
-
store.start();
|
|
139
|
-
return (current = store);
|
|
140
|
-
} catch (err) {
|
|
141
|
-
// A require failure here is a packaging bug, not a user-facing one: stay
|
|
142
|
-
// quiet, keep the session working, and leave `state().reason` for a test.
|
|
143
|
-
return (current = inert(`load-failed:${String((err && err.message) || err).slice(0, 80)}`));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function inert(reason) {
|
|
148
|
-
return {
|
|
149
|
-
enabled: false,
|
|
150
|
-
reason,
|
|
151
|
-
install: null,
|
|
152
|
-
stop: () => true,
|
|
153
|
-
state: () => ({ enabled: false, reason, beats: 0, failures: 0, running: false }),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** Stop the beacon. Idempotent; safe when `start()` never ran. */
|
|
158
|
-
function stop() {
|
|
159
|
-
if (!current) return false;
|
|
160
|
-
try {
|
|
161
|
-
current.stop();
|
|
162
|
-
} catch {
|
|
163
|
-
/* an already-dead beacon is not an error */
|
|
164
|
-
}
|
|
165
|
-
current = null;
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** The active store (or null). For tests and for a host that wants to read
|
|
170
|
-
* `state()` — `{beats, failures, lastSeenAt, intervalMs}` — after a beat. */
|
|
171
|
-
function active() {
|
|
172
|
-
return current;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* How many tasks are waiting, read at SEND time.
|
|
177
|
-
*
|
|
178
|
-
* Resolved through the shared-path resolver (`sharedpaths.js`) rather than by
|
|
179
|
-
* re-implementing a queue counter, so there is exactly one queue file and one
|
|
180
|
-
* definition of "pending" in this repo — the same `desktop/lib/local/queue.js`
|
|
181
|
-
* the desktop drains. A missing module, an unreadable file or a malformed line
|
|
182
|
-
* is 0: the beacon reports presence, not bookkeeping, and a broken queue must
|
|
183
|
-
* not silence the beacon that would have shown the machine was alive.
|
|
184
|
-
*/
|
|
185
|
-
function queueDepthReader() {
|
|
186
|
-
let queue = null;
|
|
187
|
-
try {
|
|
188
|
-
queue = require(resolveShared(path.join('desktop', 'lib', 'local', 'queue.js')));
|
|
189
|
-
} catch {
|
|
190
|
-
queue = null;
|
|
191
|
-
}
|
|
192
|
-
return () => {
|
|
193
|
-
try {
|
|
194
|
-
if (!queue || typeof queue.readQueue !== 'function' || typeof queue.queuePath !== 'function') return 0;
|
|
195
|
-
const items = queue.readQueue(queue.queuePath());
|
|
196
|
-
return (Array.isArray(items) ? items : []).filter((t) => t && t.status === 'pending').length;
|
|
197
|
-
} catch {
|
|
198
|
-
return 0;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Let an in-flight beat finish before the process exits.
|
|
205
|
-
*
|
|
206
|
-
* This is not optional politeness — it is the difference between a beat and no
|
|
207
|
-
* beat. `bin/aegiscode.js` ends with `process.exit()`, and a one-shot run
|
|
208
|
-
* (`aegiscode -p "…"`, `aegiscode autonomous run`) reaches it in tens of
|
|
209
|
-
* milliseconds, so the first beat posted at startup would be killed mid-flight
|
|
210
|
-
* and the machine would never appear in the panel. Bounded, because a beacon
|
|
211
|
-
* must never be the reason a CLI hangs: if the request has not answered within
|
|
212
|
-
* `timeoutMs`, the process exits and that beat is simply lost.
|
|
213
|
-
*
|
|
214
|
-
* @param {number} [timeoutMs] default 1500 — the beacon's own request timeout
|
|
215
|
-
* is 20 s, far too long to hold an exit open.
|
|
216
|
-
* @returns {Promise<'drained'|'none'|'timeout'>}
|
|
217
|
-
*/
|
|
218
|
-
function flush(timeoutMs = 1500) {
|
|
219
|
-
try {
|
|
220
|
-
if (!current || typeof current.pending !== 'function') return Promise.resolve('none');
|
|
221
|
-
const inflight = current.pending();
|
|
222
|
-
if (!inflight) return Promise.resolve('none');
|
|
223
|
-
const limit = Number.isFinite(Number(timeoutMs)) && Number(timeoutMs) > 0 ? Number(timeoutMs) : 1500;
|
|
224
|
-
return Promise.race([
|
|
225
|
-
Promise.resolve(inflight).then(() => 'drained', () => 'drained'),
|
|
226
|
-
new Promise((resolve) => {
|
|
227
|
-
// Deliberately NOT unref'd, unlike every other timer in this module: the
|
|
228
|
-
// caller is already in its exit path and has asked for a bounded wait, so
|
|
229
|
-
// this timer is the thing that must be allowed to keep the loop alive
|
|
230
|
-
// long enough to fire. An unref'd timer here would leave the process with
|
|
231
|
-
// an empty event loop and a `flush()` promise that never settles.
|
|
232
|
-
setTimeout(() => resolve('timeout'), limit);
|
|
233
|
-
}),
|
|
234
|
-
]);
|
|
235
|
-
} catch {
|
|
236
|
-
return Promise.resolve('none');
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
module.exports = { start, stop, active, flush, presenceDisabled, queueDepthReader, cliVersion, KILL_ENV };
|
|
3
|
+
"use strict";const path=require("node:path"),{resolveShared:resolveShared}=require("./sharedpaths.js"),KILL_ENV="AEGIS_NO_PRESENCE";function presenceDisabled(e){try{const r=e&&e[KILL_ENV];return null!=r&&""!==String(r).trim()&&/^(1|true|on|yes)$/i.test(String(r).trim())}catch{return!1}}function loadShared(){return{presence:require(resolveShared(path.join("client","presence.js"))),fingerprint:require(resolveShared(path.join("client","device-fingerprint.js")))}}function cliVersion(){try{return require(path.join(__dirname,"..","package.json")).version||null}catch{return null}}let current=null;function start(e={}){stop();const r=e.env||process.env;if(presenceDisabled(r))return current=inert("kill-switch");let t="";try{if(e.client&&"string"==typeof e.client.apiKey&&(t=e.client.apiKey),!t&&e.credentials&&"function"==typeof e.credentials.resolveApiKey){const n=e.credentials.resolveApiKey({env:r});t=n&&(n.key||n.apiKey)||""}}catch{t=""}if(!t)return current=inert("no-api-key");try{const{presence:r,fingerprint:n}=loadShared(),i=r.createPresence({apiKey:t,app:"cli",version:cliVersion(),platform:process.platform,install:n.machineFingerprint(),queueDepth:e.queueDepth,autonomous:Boolean(e.autonomous),log:e.log,fetchImpl:e.fetchImpl,now:e.now,setTimer:e.setTimer,clearTimer:e.clearTimer});return i.start(),current=i}catch(e){return current=inert(`load-failed:${String(e&&e.message||e).slice(0,80)}`)}}function inert(e){return{enabled:!1,reason:e,install:null,stop:()=>!0,state:()=>({enabled:!1,reason:e,beats:0,failures:0,running:!1})}}function stop(){if(!current)return!1;try{current.stop()}catch{}return current=null,!0}function active(){return current}function queueDepthReader(){let e=null;try{e=require(resolveShared(path.join("desktop","lib","local","queue.js")))}catch{e=null}return()=>{try{if(!e||"function"!=typeof e.readQueue||"function"!=typeof e.queuePath)return 0;const r=e.readQueue(e.queuePath());return(Array.isArray(r)?r:[]).filter((e=>e&&"pending"===e.status)).length}catch{return 0}}}function flush(e=1500){try{if(!current||"function"!=typeof current.pending)return Promise.resolve("none");const r=current.pending();if(!r)return Promise.resolve("none");const t=Number.isFinite(Number(e))&&Number(e)>0?Number(e):1500;return Promise.race([Promise.resolve(r).then((()=>"drained"),(()=>"drained")),new Promise((e=>{setTimeout((()=>e("timeout")),t)}))])}catch{return Promise.resolve("none")}}module.exports={start:start,stop:stop,active:active,flush:flush,presenceDisabled:presenceDisabled,queueDepthReader:queueDepthReader,cliVersion:cliVersion,KILL_ENV:KILL_ENV};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
3
|
+
"use strict";
|
|
8
4
|
/**
|
|
9
5
|
* provenance — who this program is, and whether it is still the program that
|
|
10
6
|
* was published.
|
|
@@ -59,180 +55,4 @@
|
|
|
59
55
|
* so absence is reported (`unverifiable`) instead of being read as "nothing
|
|
60
56
|
* configured". `AEGIS_NO_PROVENANCE_CHECK=1` silences it for a development tree
|
|
61
57
|
* that is mid-edit — loudly, and by name, so it is never the quiet path.
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
const { createHash } = require('node:crypto');
|
|
65
|
-
const { existsSync, readFileSync } = require('node:fs');
|
|
66
|
-
const path = require('node:path');
|
|
67
|
-
const limits = require('./limits.js');
|
|
68
|
-
|
|
69
|
-
/** Everything a copy would have to change to look like its own product. */
|
|
70
|
-
const IDENTITY = Object.freeze({
|
|
71
|
-
product: 'AEGIS Code',
|
|
72
|
-
bin: 'aegiscode',
|
|
73
|
-
license: 'AGPL-3.0-or-later',
|
|
74
|
-
copyright: 'Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.',
|
|
75
|
-
source: 'https://github.com/aegisinfo/aegiscode-plugin',
|
|
76
|
-
homepage: 'https://aegiscloud.org',
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The sealed set: id → path. This table is the mapping the manifest refuses to
|
|
81
|
-
* carry, and the only reason a report can say `p3` at all. Keep it in step with
|
|
82
|
-
* `tools/provenance.mjs`, which writes both halves from it.
|
|
83
|
-
*/
|
|
84
|
-
const UNITS = Object.freeze([
|
|
85
|
-
Object.freeze({ id: 'p1', rel: 'bin/aegiscode.js' }),
|
|
86
|
-
Object.freeze({ id: 'p2', rel: 'src/provenance.js' }),
|
|
87
|
-
Object.freeze({ id: 'p3', rel: 'src/gate.js' }),
|
|
88
|
-
Object.freeze({ id: 'p4', rel: 'src/permissions.js' }),
|
|
89
|
-
Object.freeze({ id: 'p5', rel: 'src/caps.js' }),
|
|
90
|
-
Object.freeze({ id: 'p6', rel: 'src/autonomous.js' }),
|
|
91
|
-
Object.freeze({ id: 'p7', rel: 'src/limits.js' }),
|
|
92
|
-
Object.freeze({ id: 'p8', rel: 'src/mcp.js' }),
|
|
93
|
-
]);
|
|
94
|
-
|
|
95
|
-
const PACKAGE_ROOT = path.join(__dirname, '..');
|
|
96
|
-
const MANIFEST_FILE = path.join(__dirname, 'provenance.lock.json');
|
|
97
|
-
|
|
98
|
-
const sha256 = (data) => createHash('sha256').update(data).digest('hex');
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Read the shipped manifest. Two shapes are accepted:
|
|
102
|
-
*
|
|
103
|
-
* - current: `{ v: 1, alg: 'sha256', units: { p1: '<hex>', … } }` — ids only,
|
|
104
|
-
* no paths, nothing to read off the file except which digests moved;
|
|
105
|
-
* - legacy: `{ files: { '<rel path>': '<hex>' } }` — still honoured so a
|
|
106
|
-
* package built from an older tree can still be checked, and still reported
|
|
107
|
-
* by id rather than by path.
|
|
108
|
-
*/
|
|
109
|
-
function readManifest() {
|
|
110
|
-
try {
|
|
111
|
-
const parsed = JSON.parse(readFileSync(MANIFEST_FILE, 'utf8'));
|
|
112
|
-
if (!parsed) return null;
|
|
113
|
-
if (parsed.units && typeof parsed.units === 'object') {
|
|
114
|
-
return { units: parsed.units, legacyPaths: null };
|
|
115
|
-
}
|
|
116
|
-
if (parsed.files && typeof parsed.files === 'object') {
|
|
117
|
-
return { units: parsed.files, legacyPaths: parsed.files };
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
} catch {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Resolve a unit's expected digest, in either manifest shape. */
|
|
126
|
-
function expectedFor(manifest, unit) {
|
|
127
|
-
if (!manifest) return undefined;
|
|
128
|
-
if (manifest.legacyPaths) return manifest.legacyPaths[unit.rel];
|
|
129
|
-
return manifest.units[unit.id];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Compare this install's safety files to the shipped manifest.
|
|
134
|
-
*
|
|
135
|
-
* Never throws: this is a diagnostic, and a diagnostic that can break the
|
|
136
|
-
* program it is reporting on is worse than no diagnostic.
|
|
137
|
-
*
|
|
138
|
-
* Reports unit ids, never paths. See the header for why the difference matters.
|
|
139
|
-
*
|
|
140
|
-
* @returns {{ ok: boolean, checked: number, problems: string[], unverifiable: boolean }}
|
|
141
|
-
*/
|
|
142
|
-
function selfCheck() {
|
|
143
|
-
const manifest = readManifest();
|
|
144
|
-
if (!manifest) {
|
|
145
|
-
return {
|
|
146
|
-
ok: false,
|
|
147
|
-
checked: 0,
|
|
148
|
-
problems: [`${path.basename(MANIFEST_FILE)} is missing or unreadable`],
|
|
149
|
-
unverifiable: true,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
const problems = [];
|
|
153
|
-
let checked = 0;
|
|
154
|
-
for (const unit of UNITS) {
|
|
155
|
-
const abs = path.join(PACKAGE_ROOT, unit.rel);
|
|
156
|
-
if (!existsSync(abs)) {
|
|
157
|
-
problems.push(`${unit.id}: sealed unit missing from this install`);
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const actual = sha256(readFileSync(abs));
|
|
162
|
-
checked++;
|
|
163
|
-
const expected = expectedFor(manifest, unit);
|
|
164
|
-
if (expected && actual !== expected) problems.push(`${unit.id}: digest moved`);
|
|
165
|
-
} catch {
|
|
166
|
-
problems.push(`${unit.id}: unreadable`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return { ok: problems.length === 0, checked, problems, unverifiable: false };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* The one stderr line worth writing, or null when everything is as published.
|
|
174
|
-
*
|
|
175
|
-
* It names ids and counts. It does not name files, does not describe what those
|
|
176
|
-
* files do, and does not say how to re-seal: those three sentences are exactly
|
|
177
|
-
* what a tampered build would otherwise hand its author for free.
|
|
178
|
-
*
|
|
179
|
-
* A development tree can silence it with AEGIS_NO_PROVENANCE_CHECK=1; the
|
|
180
|
-
* silence is printed too, because a control that can be switched off quietly is
|
|
181
|
-
* not a control.
|
|
182
|
-
*/
|
|
183
|
-
function warning(report) {
|
|
184
|
-
if (!report || report.ok) return null;
|
|
185
|
-
if (process.env.AEGIS_NO_PROVENANCE_CHECK) {
|
|
186
|
-
return `aegiscode: provenance check SKIPPED (AEGIS_NO_PROVENANCE_CHECK is set): ${report.problems[0]}\n`;
|
|
187
|
-
}
|
|
188
|
-
return (
|
|
189
|
-
`aegiscode: provenance — ${report.problems.length} sealed unit${
|
|
190
|
-
report.problems.length === 1 ? '' : 's'
|
|
191
|
-
} do not match the published manifest (${IDENTITY.license}):\n` +
|
|
192
|
-
report.problems.map((p) => `aegiscode: ${p}\n`).join('') +
|
|
193
|
-
'aegiscode: this build is not the published one; do not trust what it reports about itself.\n'
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** The human-readable answer for `aegiscode provenance`. */
|
|
198
|
-
function describe({ version } = {}) {
|
|
199
|
-
const report = selfCheck();
|
|
200
|
-
const lines = [
|
|
201
|
-
`${IDENTITY.product} (${IDENTITY.bin})${version ? ` ${version}` : ''} — ${IDENTITY.license}`,
|
|
202
|
-
`source: ${IDENTITY.source}`,
|
|
203
|
-
`homepage: ${IDENTITY.homepage}`,
|
|
204
|
-
IDENTITY.copyright,
|
|
205
|
-
];
|
|
206
|
-
// The identity half is MEANT to be read — it is the notice that has to travel
|
|
207
|
-
// with a copy, and withholding it would defeat the licence half of this file.
|
|
208
|
-
// The integrity half is not. A build that failed the silent gate does not get
|
|
209
|
-
// to report on itself: it is told exactly as much as any other module is
|
|
210
|
-
// (src/limits.js, "reduced mode"), and the ids it would otherwise print stay
|
|
211
|
-
// here. Asked through limits.armed() rather than trusting the caller, so that
|
|
212
|
-
// deleting the entry point's own refusal does not hand this back — the guard
|
|
213
|
-
// lives in a file the sealed set covers.
|
|
214
|
-
if (limits.armed()) {
|
|
215
|
-
lines.push('safety: reduced mode — this build is not the one that was published.');
|
|
216
|
-
return {
|
|
217
|
-
text: lines.join('\n') + '\n',
|
|
218
|
-
ok: false,
|
|
219
|
-
report: { ok: false, checked: report.checked, problems: [], unverifiable: report.unverifiable, withheld: true },
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
if (report.ok) {
|
|
223
|
-
lines.push(`safety: ${report.checked} sealed units verified`);
|
|
224
|
-
} else if (report.unverifiable) {
|
|
225
|
-
lines.push(`safety: UNVERIFIABLE — ${report.problems[0]}`);
|
|
226
|
-
} else {
|
|
227
|
-
lines.push(`safety: ${report.problems.length} sealed unit(s) do not match the published manifest:`);
|
|
228
|
-
for (const p of report.problems) lines.push(` ${p}`);
|
|
229
|
-
}
|
|
230
|
-
return { text: lines.join('\n') + '\n', ok: report.ok, report };
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** The id→path mapping, for the development tool only. Never called at runtime. */
|
|
234
|
-
function sealMap() {
|
|
235
|
-
return UNITS.map((u) => ({ id: u.id, rel: u.rel }));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
module.exports = { IDENTITY, UNITS, MANIFEST_FILE, selfCheck, warning, describe, sealMap };
|
|
58
|
+
*/const{createHash:createHash}=require("node:crypto"),{existsSync:existsSync,readFileSync:readFileSync}=require("node:fs"),path=require("node:path"),limits=require("./limits.js"),IDENTITY=Object.freeze({product:"AEGIS Code",bin:"aegiscode",license:"AGPL-3.0-or-later",copyright:"Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.",source:"https://github.com/aegisinfo/aegiscode-plugin",homepage:"https://aegiscloud.org"}),UNITS=Object.freeze([Object.freeze({id:"p1",rel:"bin/aegiscode.js"}),Object.freeze({id:"p2",rel:"src/provenance.js"}),Object.freeze({id:"p3",rel:"src/gate.js"}),Object.freeze({id:"p4",rel:"src/permissions.js"}),Object.freeze({id:"p5",rel:"src/caps.js"}),Object.freeze({id:"p6",rel:"src/autonomous.js"}),Object.freeze({id:"p7",rel:"src/limits.js"}),Object.freeze({id:"p8",rel:"src/mcp.js"})]),PACKAGE_ROOT=path.join(__dirname,".."),MANIFEST_FILE=path.join(__dirname,"provenance.lock.json"),sha256=e=>createHash("sha256").update(e).digest("hex");function readManifest(){try{const e=JSON.parse(readFileSync(MANIFEST_FILE,"utf8"));return e?e.units&&"object"==typeof e.units?{units:e.units,legacyPaths:null}:e.files&&"object"==typeof e.files?{units:e.files,legacyPaths:e.files}:null:null}catch{return null}}function expectedFor(e,s){if(e)return e.legacyPaths?e.legacyPaths[s.rel]:e.units[s.id]}function selfCheck(){const e=readManifest();if(!e)return{ok:!1,checked:0,problems:[`${path.basename(MANIFEST_FILE)} is missing or unreadable`],unverifiable:!0};const s=[];let t=0;for(const i of UNITS){const r=path.join(PACKAGE_ROOT,i.rel);if(existsSync(r))try{const n=sha256(readFileSync(r));t++;const o=expectedFor(e,i);o&&n!==o&&s.push(`${i.id}: digest moved`)}catch{s.push(`${i.id}: unreadable`)}else s.push(`${i.id}: sealed unit missing from this install`)}return{ok:0===s.length,checked:t,problems:s,unverifiable:!1}}function warning(e){return!e||e.ok?null:process.env.AEGIS_NO_PROVENANCE_CHECK?`aegiscode: provenance check SKIPPED (AEGIS_NO_PROVENANCE_CHECK is set): ${e.problems[0]}\n`:`aegiscode: provenance — ${e.problems.length} sealed unit${1===e.problems.length?"":"s"} do not match the published manifest (${IDENTITY.license}):\n`+e.problems.map((e=>`aegiscode: ${e}\n`)).join("")+"aegiscode: this build is not the published one; do not trust what it reports about itself.\n"}function describe({version:e}={}){const s=selfCheck(),t=[`${IDENTITY.product} (${IDENTITY.bin})${e?` ${e}`:""} — ${IDENTITY.license}`,`source: ${IDENTITY.source}`,`homepage: ${IDENTITY.homepage}`,IDENTITY.copyright];if(limits.armed())return t.push("safety: reduced mode — this build is not the one that was published."),{text:t.join("\n")+"\n",ok:!1,report:{ok:!1,checked:s.checked,problems:[],unverifiable:s.unverifiable,withheld:!0}};if(s.ok)t.push(`safety: ${s.checked} sealed units verified`);else if(s.unverifiable)t.push(`safety: UNVERIFIABLE — ${s.problems[0]}`);else{t.push(`safety: ${s.problems.length} sealed unit(s) do not match the published manifest:`);for(const e of s.problems)t.push(` ${e}`)}return{text:t.join("\n")+"\n",ok:s.ok,report:s}}function sealMap(){return UNITS.map((e=>({id:e.id,rel:e.rel})))}module.exports={IDENTITY:IDENTITY,UNITS:UNITS,MANIFEST_FILE:MANIFEST_FILE,selfCheck:selfCheck,warning:warning,describe:describe,sealMap:sealMap};
|