aegisone 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 -2
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -939
  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 -369
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/bin/aegiscode.js +2 -914
  17. package/vendor/cli/package.json +3 -2
  18. package/vendor/cli/scripts/check.mjs +1 -52
  19. package/vendor/cli/scripts/demo.mjs +1 -94
  20. package/vendor/cli/scripts/predist.mjs +1 -75
  21. package/vendor/cli/scripts/runtests.mjs +1 -56
  22. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  23. package/vendor/cli/src/agents.js +1 -139
  24. package/vendor/cli/src/app.js +1 -2932
  25. package/vendor/cli/src/art.js +1 -289
  26. package/vendor/cli/src/autonomous.js +1 -515
  27. package/vendor/cli/src/caps.js +1 -879
  28. package/vendor/cli/src/chatflow.js +1 -3008
  29. package/vendor/cli/src/checkpoint.js +1 -90
  30. package/vendor/cli/src/clipboard.js +1 -424
  31. package/vendor/cli/src/cloudsync.js +1 -528
  32. package/vendor/cli/src/commands.js +1 -3987
  33. package/vendor/cli/src/config.js +1 -581
  34. package/vendor/cli/src/connect.js +1 -349
  35. package/vendor/cli/src/credentials.js +1 -33
  36. package/vendor/cli/src/deps.js +1 -232
  37. package/vendor/cli/src/devrun.js +1 -187
  38. package/vendor/cli/src/diff.js +1 -333
  39. package/vendor/cli/src/diffview.js +1 -296
  40. package/vendor/cli/src/engine.js +1 -297
  41. package/vendor/cli/src/entitlement.js +1 -355
  42. package/vendor/cli/src/events.js +1 -707
  43. package/vendor/cli/src/export.js +1 -67
  44. package/vendor/cli/src/fingerprint.js +1 -592
  45. package/vendor/cli/src/format.js +1 -259
  46. package/vendor/cli/src/fuzzy.js +1 -119
  47. package/vendor/cli/src/gate.js +1 -55
  48. package/vendor/cli/src/history.js +1 -401
  49. package/vendor/cli/src/init.js +1 -175
  50. package/vendor/cli/src/input.js +1 -139
  51. package/vendor/cli/src/keys.js +1 -183
  52. package/vendor/cli/src/limits.js +1 -190
  53. package/vendor/cli/src/markdown.js +1 -306
  54. package/vendor/cli/src/mcp.js +1 -694
  55. package/vendor/cli/src/models.js +1 -487
  56. package/vendor/cli/src/naming.js +1 -229
  57. package/vendor/cli/src/overlays.js +1 -461
  58. package/vendor/cli/src/panels.js +1 -1418
  59. package/vendor/cli/src/permissions.js +1 -290
  60. package/vendor/cli/src/ping.js +1 -226
  61. package/vendor/cli/src/presence.js +1 -238
  62. package/vendor/cli/src/provenance.js +2 -182
  63. package/vendor/cli/src/render.js +1 -515
  64. package/vendor/cli/src/screen.js +1 -518
  65. package/vendor/cli/src/screens.js +1 -896
  66. package/vendor/cli/src/secret.js +1 -59
  67. package/vendor/cli/src/securefs.js +1 -359
  68. package/vendor/cli/src/settings.js +1 -155
  69. package/vendor/cli/src/shared.js +1 -52
  70. package/vendor/cli/src/sharedpaths.js +1 -53
  71. package/vendor/cli/src/signup.js +1 -156
  72. package/vendor/cli/src/summarize.js +1 -95
  73. package/vendor/cli/src/sysdiag.js +1 -585
  74. package/vendor/cli/src/system.js +1 -40
  75. package/vendor/cli/src/theme.js +1 -570
  76. package/vendor/cli/src/title.js +1 -220
  77. package/vendor/cli/src/todos.js +1 -115
  78. package/vendor/cli/src/tokens.js +1 -263
  79. package/vendor/cli/src/topup.js +1 -210
  80. package/vendor/cli/src/update.js +1 -181
  81. package/vendor/cli/vendor/client/aegis.js +1 -2054
  82. package/vendor/cli/vendor/client/attest.js +1 -442
  83. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  84. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  85. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  86. package/vendor/cli/vendor/client/byok-catalog.js +1 -230
  87. package/vendor/cli/vendor/client/credentials.js +1 -494
  88. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  89. package/vendor/cli/vendor/client/drive-connect.js +1 -85
  90. package/vendor/cli/vendor/client/drive-upload.js +1 -174
  91. package/vendor/cli/vendor/client/env-file.js +1 -1273
  92. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  93. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  94. package/vendor/cli/vendor/client/google-signin.js +1 -125
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -330
  97. package/vendor/cli/vendor/client/platform.js +1 -937
  98. package/vendor/cli/vendor/client/prefs.js +1 -351
  99. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  100. package/vendor/cli/vendor/client/presence.js +1 -438
  101. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  102. package/vendor/cli/vendor/client/session-store.js +1 -548
  103. package/vendor/cli/vendor/client/topup.js +1 -297
  104. package/vendor/cli/vendor/client/touch.js +1 -458
  105. package/vendor/cli/vendor/client/update.js +1 -704
  106. package/vendor/cli/vendor/client/user-models.js +1 -381
  107. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  108. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  109. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
  110. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
  111. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3228
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -654
  113. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  114. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
  115. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
  116. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  117. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
  118. package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
  119. package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
  120. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  121. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  122. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  123. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  124. package/vendor/cli/vendor/hosts/install.js +1 -638
  125. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  126. package/vendor/cli/vendor/hosts/spec.js +1 -164
  127. package/vendor/cli/vendor/hosts/targets.js +1 -346
  128. package/vendor/cli/vendor/mcp/server.js +1 -221
  129. package/vendor/cli/vendor/mcp/tools.js +1 -408
  130. package/vendor/cli/vendor/one/src/child.js +1 -285
  131. package/vendor/cli/vendor/one/src/permissions.js +1 -369
  132. package/vendor/desktop/bin/aegis.js +1 -32
  133. package/vendor/desktop/lib/account-key.js +1 -56
  134. package/vendor/desktop/lib/auto.js +1 -430
  135. package/vendor/desktop/lib/avatar/companion.js +1 -698
  136. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  137. package/vendor/desktop/lib/avatar/events.js +1 -344
  138. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  139. package/vendor/desktop/lib/avatar/holders.js +1 -612
  140. package/vendor/desktop/lib/avatar/identity.js +1 -641
  141. package/vendor/desktop/lib/avatar/level.js +1 -368
  142. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  143. package/vendor/desktop/lib/avatar/persona.js +1 -388
  144. package/vendor/desktop/lib/avatar/profile.js +1 -977
  145. package/vendor/desktop/lib/avatar/register.js +1 -307
  146. package/vendor/desktop/lib/avatar/store.js +1 -472
  147. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  148. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  149. package/vendor/desktop/lib/avatar/turn.js +1 -216
  150. package/vendor/desktop/lib/avatar/voice.js +1 -328
  151. package/vendor/desktop/lib/avatar/xp.js +1 -404
  152. package/vendor/desktop/lib/deep-link.js +1 -120
  153. package/vendor/desktop/lib/fingerprint.js +2 -347
  154. package/vendor/desktop/lib/google-connect.js +1 -169
  155. package/vendor/desktop/lib/local/agents.js +1 -105
  156. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  157. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  158. package/vendor/desktop/lib/local/context.js +1 -95
  159. package/vendor/desktop/lib/local/engine.js +1 -3228
  160. package/vendor/desktop/lib/local/entitlement.js +1 -654
  161. package/vendor/desktop/lib/local/git-scope.js +1 -228
  162. package/vendor/desktop/lib/local/local.js +1 -2135
  163. package/vendor/desktop/lib/local/prompt.js +1 -275
  164. package/vendor/desktop/lib/local/queue.js +1 -560
  165. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  166. package/vendor/desktop/lib/local/shell.js +1 -680
  167. package/vendor/desktop/lib/local/telemetry.js +1 -470
  168. package/vendor/desktop/lib/local/tools.js +1 -1238
  169. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  170. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  171. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  172. package/vendor/desktop/lib/quick-launcher.js +1 -84
  173. package/vendor/desktop/lib/settings.js +1 -890
  174. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  175. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  176. package/vendor/desktop/lib/sync/sessions.js +1 -106
  177. package/vendor/desktop/lib/window-state.js +1 -66
  178. package/vendor/desktop/main.js +1 -4390
  179. package/vendor/desktop/package.json +3 -5
  180. package/vendor/desktop/preload.js +1 -628
  181. package/vendor/desktop/renderer/app.js +1 -6560
  182. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  183. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  184. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  185. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  186. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  187. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  188. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  189. package/vendor/desktop/renderer/budget.js +1 -168
  190. package/vendor/desktop/renderer/companion.js +1 -223
  191. package/vendor/desktop/renderer/diff.js +1 -359
  192. package/vendor/desktop/renderer/diffview.js +1 -336
  193. package/vendor/desktop/renderer/fingerprint.js +3 -720
  194. package/vendor/desktop/renderer/markdown.js +1 -168
  195. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  196. package/vendor/desktop/renderer/providers.js +1 -259
  197. package/vendor/desktop/renderer/quick.js +1 -191
  198. package/vendor/desktop/renderer/stream-policy.js +1 -306
  199. package/vendor/desktop/renderer/transcript-view.js +1 -323
  200. package/vendor/desktop/renderer/usage.js +1 -1239
  201. package/vendor/desktop/vendor/aegis.js +1 -2054
  202. package/vendor/desktop/vendor/attest.js +1 -442
  203. package/vendor/desktop/vendor/authorship-key.js +1 -410
  204. package/vendor/desktop/vendor/auto-provision.js +1 -134
  205. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  206. package/vendor/desktop/vendor/byok-catalog.js +1 -230
  207. package/vendor/desktop/vendor/credentials.js +1 -494
  208. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  209. package/vendor/desktop/vendor/drive-connect.js +1 -85
  210. package/vendor/desktop/vendor/drive-upload.js +1 -174
  211. package/vendor/desktop/vendor/env-file.js +1 -1273
  212. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  213. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  214. package/vendor/desktop/vendor/google-signin.js +1 -125
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -330
  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 -548
  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 -704
  226. package/vendor/desktop/vendor/user-models.js +1 -381
package/src/host.js CHANGED
@@ -1,113 +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
- * host.js — the ONE place in `one/` that asks the host which OS it is.
10
- *
11
- * Why this file exists (plan ON6 step 5, and the standing Phase 30.1 rule that
12
- * nothing in `one/` reads `process.*` at module scope):
13
- *
14
- * before ON6 the platform answer in `one/` was a bare `process.platform` read
15
- * inside `probes.js`. That is a second answer to a question this repo already
16
- * has exactly one owner for — `client/platform.js`, whose header says it in as
17
- * many words ("the ONE place in this repo that knows which OS it is running
18
- * on"), and which the stager already ships in both emitted shapes. A second
19
- * read is how the two answers drift; a grep in `one/test/one-compat.test.mjs`
20
- * now keeps them from drifting (`process.platform` must not appear in `one/`
21
- * outside `one/vendor/`, which is generated).
22
- *
23
- * So every OS branch in `one/` (the Electron probe's display rule, the doctor's
24
- * platform input, the installer's bundle target) resolves through here, and
25
- * here resolves through `client/platform.js`. Two layouts are tried, in the
26
- * order the two copies actually appear:
27
- *
28
- * 1. `../../client/platform.js` — a checkout of this repo, faces as siblings
29
- * of `one/`;
30
- * 2. `../vendor/desktop/vendor/platform.js` — inside the published tarball,
31
- * where the stager emits the flattened desktop shape (plan D6).
32
- *
33
- * A third candidate covers the mirrored shape (`../vendor/cli/vendor/client/
34
- * platform.js`) so a future bundle shape cannot silently lose the seam.
35
- *
36
- * `os.platform()` is the last-resort fallback, and it is deliberately *not*
37
- * `process.platform`: this file is the seam, so it must be readable as "here is
38
- * the one read" rather than "here is a read, and also the other files have
39
- * their own". It is only reachable when neither staged copy is beside this
40
- * module, which no shipped shape does — and that case is what the grep proves
41
- * cannot silently return to the call sites.
42
- */
43
-
44
- const fs = require('node:fs');
45
- const path = require('node:path');
46
-
47
- /** Candidate locations of the platform seam, nearest-to-furthest. */
48
- function seamCandidates(dir) {
49
- const from = dir || __dirname; // one/src in every shipped shape
50
- return [
51
- path.join(from, '..', '..', 'client', 'platform.js'),
52
- path.join(from, '..', 'vendor', 'desktop', 'vendor', 'platform.js'),
53
- path.join(from, '..', 'vendor', 'cli', 'vendor', 'client', 'platform.js')
54
- ];
55
- }
56
-
57
- /**
58
- * Load the platform seam, or `null` when no copy is beside this module.
59
- *
60
- * @param {object} [deps] injected for tests: { dir, exists, load }
61
- * @returns {object|null} the `client/platform.js` module object
62
- */
63
- function platformSeam(deps) {
64
- const d = deps || {};
65
- const exists = d.exists || fs.existsSync;
66
- const load = d.load || require;
67
- for (const candidate of seamCandidates(d.dir)) {
68
- if (!exists(candidate)) continue;
69
- try {
70
- const mod = load(candidate);
71
- // The function, not the file, is the contract: a copy that loaded but
72
- // exposes no `seams()` would answer nothing and must not be accepted as
73
- // an answer to the OS question.
74
- if (mod && typeof mod.seams === 'function') return mod;
75
- } catch {
76
- /* try the next layout */
77
- }
78
- }
79
- return null;
80
- }
81
-
82
- /**
83
- * The host OS, as `client/platform.js` reports it (`'linux' | 'darwin' | …`).
84
- *
85
- * @param {object} [deps] injected for tests: { dir, exists, load }
86
- * @returns {string}
87
- */
88
- function hostPlatform(deps) {
89
- const d = deps || {};
90
- const seam = platformSeam(d);
91
- if (seam) return seam.seams(d.options || {}).platform;
92
- return require('node:os').platform();
93
- }
94
-
95
- /**
96
- * The platform facts `client/platform.js` derives, so a caller branches on the
97
- * seam's vocabulary (`win32`) instead of comparing strings a second time.
98
- *
99
- * @param {object} [deps] injected for tests: { dir, exists, load, platform }
100
- * @returns {{platform: string, win32: boolean}}
101
- */
102
- function hostSeams(deps) {
103
- const d = deps || {};
104
- const seam = platformSeam(d);
105
- if (seam) {
106
- const facts = seam.seams({ platform: d.platform });
107
- return { platform: facts.platform, win32: Boolean(facts.win32) };
108
- }
109
- const platform = d.platform || require('node:os').platform();
110
- return { platform, win32: platform === 'win32' };
111
- }
112
-
113
- module.exports = { seamCandidates, platformSeam, hostPlatform, hostSeams };
3
+ "use strict";const fs=require("node:fs"),path=require("node:path");function seamCandidates(t){const o=t||__dirname;return[path.join(o,"..","..","client","platform.js"),path.join(o,"..","vendor","desktop","vendor","platform.js"),path.join(o,"..","vendor","cli","vendor","client","platform.js")]}function platformSeam(t){const o=t||{},e=o.exists||fs.existsSync,a=o.load||require;for(const t of seamCandidates(o.dir))if(e(t))try{const o=a(t);if(o&&"function"==typeof o.seams)return o}catch{}return null}function hostPlatform(t){const o=t||{},e=platformSeam(o);return e?e.seams(o.options||{}).platform:require("node:os").platform()}function hostSeams(t){const o=t||{},e=platformSeam(o);if(e){const t=e.seams({platform:o.platform});return{platform:t.platform,win32:Boolean(t.win32)}}const a=o.platform||require("node:os").platform();return{platform:a,win32:"win32"===a}}module.exports={seamCandidates:seamCandidates,platformSeam:platformSeam,hostPlatform:hostPlatform,hostSeams:hostSeams};
@@ -1,371 +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
- * permissions.js — ONE permission posture (AEGISONE, decision D8).
10
- *
11
- * Four permission surfaces used to live in this tree and none of them
12
- * negotiated (see the plan's D8 table): the CLI's rule file + `evalPermission`,
13
- * the desktop's `confirmModeEnabled()` gate, the avatar's level gate, and — out
14
- * of process — the Claude Code child, which runs its own permission system
15
- * whose prompts land on *its* stdin where neither a GUI card nor the CLI's
16
- * prompt loop can answer them. In `-p` mode an unanswered prompt is not a
17
- * refusal, it is a hang.
18
- *
19
- * This module is the product's half of the fix: it resolves the posture ONCE,
20
- * from the facts a caller already has, into a FROZEN decision record that
21
- * everything downstream reads instead of re-deciding for itself.
22
- *
23
- * ## What it is not
24
- *
25
- * * It is not a second rule engine. Rule matching is `evalPermission()`,
26
- * imported from `cli/src/permissions.js` (D8 rule 1: "evalPermission()
27
- * stays the only rule engine"). `loadEvaluator()` below resolves that
28
- * module in both layouts — a checkout and the published bundle — and a
29
- * missing evaluator is a thrown error, never a local re-implementation:
30
- * a rules engine that can silently become a *different* rules engine is the
31
- * drift this phase exists to remove.
32
- * * It is not a switch that reaches the two floors of D8 rule 2. The ÆGIS
33
- * covenant's `preActionAssert` and the avatar's `LEVEL_INDEPENDENT_
34
- * APPROVALS` (`write`/`shell`/`network`/`offDevice`, always `'ask'`) are not
35
- * represented here as skippable at all — `FROZEN_CLASSES` is exported so a
36
- * test can assert it is the SAME set the avatar freezes, and `gateFor()`
37
- * only ever downgrades an `'ask'` verdict, never an explicit `'deny'`.
38
- * * It reads no `process.*` at module scope, and nothing at all in its
39
- * functions: `env`, `interactive`, `skip` and `rules` all arrive as
40
- * arguments. That is the standing seam rule for `one/`, and it is why the
41
- * rule-5 case below can be asserted rather than hoped for.
42
- *
43
- * ## The record
44
- *
45
- * `resolvePosture({ rules, skip, interactive, childKind, env, flag })` returns
46
- * an object that is frozen at every level. Frozen matters: the record is
47
- * produced once per invocation and consumed by (a) this product's gate report,
48
- * (b) the Claude child's argv builder, and (c) the run log. A record a later
49
- * stage can mutate is a second decision, which is the bug D8 names.
50
- *
51
- * ## Rule 3's report
52
- *
53
- * `skipReport(record)` is the one stderr line rule 3 demands — "a flag whose
54
- * blast radius is invisible is how a footgun ships" — and it names both what
55
- * was skipped and, in as many words, what was not.
56
- */
57
-
58
- const path = require('node:path');
59
-
60
- /** The two children D8 rule 4 distinguishes. */
61
- const CHILD_KINDS = Object.freeze({ HEADLESS: 'headless', INTERACTIVE: 'interactive' });
62
-
63
- /**
64
- * What `--dangerously-skip-permissions` skips in THIS product: the configurable
65
- * confirmation gates, i.e. the desktop card / CLI ask for the mutating tools.
66
- * The classes are named the way the gate and the tool registry name them, so
67
- * the report line says exactly which calls stop asking.
68
- */
69
- const CONFIGURABLE_CLASSES = Object.freeze(['exec', 'writeFile', 'editFile']);
70
-
71
- /** The product flag's spelling (D8 rule 3), named once for both the bin and tests. */
72
- const SKIP_FLAG = '--dangerously-skip-permissions';
73
-
74
- /**
75
- * The four classes no setting, flag or env var may auto-approve (D8 rule 2).
76
- * The values are the avatar's, and `test/permissions.test.mjs` asserts this set
77
- * is identical to `LEVEL_INDEPENDENT_APPROVALS`'s keys — so a phase that adds a
78
- * fifth frozen class cannot land here silently.
79
- */
80
- const FROZEN_CLASSES = Object.freeze(['write', 'shell', 'network', 'offDevice']);
81
-
82
- /** D8 rule 4's explicit passthrough values — recorded, never inferred. */
83
- const PERMISSION_MODES = Object.freeze([
84
- 'acceptEdits',
85
- 'auto',
86
- 'bypassPermissions',
87
- 'manual',
88
- 'dontAsk',
89
- 'plan',
90
- ]);
91
-
92
- let cachedEvaluator = null;
93
- let cachedConfig = null;
94
-
95
- /**
96
- * The ONE rule engine, resolved in both layouts:
97
- *
98
- * 1. `one/src/…` in a checkout → `../../cli/src/permissions.js`
99
- * 2. `one/vendor/cli/src/…` in the published product → `../vendor/cli/src/…`
100
- *
101
- * @returns {{evalPermission: Function, resolveSkip: Function, SKIP: object}}
102
- */
103
- function loadEvaluator(injected) {
104
- if (injected) return injected;
105
- if (cachedEvaluator) return cachedEvaluator;
106
- const candidates = [
107
- path.join(__dirname, '..', '..', 'cli', 'src', 'permissions.js'),
108
- path.join(__dirname, '..', 'vendor', 'cli', 'src', 'permissions.js'),
109
- ];
110
- for (const candidate of candidates) {
111
- try {
112
- const mod = require(candidate);
113
- if (mod && typeof mod.evalPermission === 'function' && typeof mod.resolveSkip === 'function') {
114
- cachedEvaluator = mod;
115
- return mod;
116
- }
117
- } catch {
118
- /* try the next layout */
119
- }
120
- }
121
- throw new Error(
122
- 'aegis: the one rule evaluator (cli/src/permissions.js) is missing from this install — ' +
123
- 'refusing to resolve a permission posture from a second, unshared rule engine.'
124
- );
125
- }
126
-
127
- /**
128
- * The faces' OWN posture module, resolved in both layouts, exactly as the
129
- * evaluator above is:
130
- *
131
- * 1. `one/src/…` in a checkout → `../../cli/src/config.js`
132
- * 2. `one/vendor/cli/src/…` in the published product → `../vendor/cli/src/…`
133
- *
134
- * This is deliberately the CLI's module and not a new reader. `confirmPosture()`
135
- * in there is the ONE read of the shared `confirmMode` key both faces write —
136
- * the desktop's *Confirm before running tools* switch and the shell's
137
- * `/automode` (alias `/yolo`) — and reading the store here a second way would
138
- * be the split brain ON8 removed. NotFound is `null`, never a throw: a store
139
- * that cannot be read must leave the gate UP, not blow up a launch.
140
- *
141
- * @returns {object|null}
142
- */
143
- function loadConfigStore(injected) {
144
- if (injected) return injected;
145
- if (cachedConfig) return cachedConfig;
146
- const candidates = [
147
- path.join(__dirname, '..', '..', 'cli', 'src', 'config.js'),
148
- path.join(__dirname, '..', 'vendor', 'cli', 'src', 'config.js'),
149
- ];
150
- for (const candidate of candidates) {
151
- try {
152
- const mod = require(candidate);
153
- if (mod && typeof mod.confirmPosture === 'function') {
154
- cachedConfig = mod;
155
- return mod;
156
- }
157
- } catch {
158
- /* try the next layout */
159
- }
160
- }
161
- return null;
162
- }
163
-
164
- /**
165
- * What the SHARED stores say — the same two facts `one/bin/aegis.js` used to
166
- * pass as `undefined`.
167
- *
168
- * `confirmationsOn` is `confirmPosture().enabled`, i.e. the store's own answer
169
- * with its polarity already resolved (true = the gate is UP, the user is asked
170
- * before mutating tools). `rules` is the CLI's rule set verbatim, which is what
171
- * rule 4's `--allowedTools`/`--disallowedTools` were always meant to be built
172
- * from — the seam shipped with `rules: d.rules`, and nothing ever set `d.rules`
173
- * in production, so the child was handed our rules by nobody.
174
- *
175
- * An unreadable store answers `undefined` for both, never a guess: "no stored
176
- * posture" must mean "exactly as before", not "confirmations off".
177
- *
178
- * @returns {{confirmationsOn: boolean|undefined, rules: object|undefined, source: string}}
179
- */
180
- function storedPermissionFacts(opts = {}) {
181
- const config = loadConfigStore(opts.config);
182
- if (!config) return { confirmationsOn: undefined, rules: undefined, source: 'unavailable' };
183
- try {
184
- const gate = config.confirmPosture();
185
- let rules;
186
- try {
187
- rules = config.loadPermissions();
188
- } catch {
189
- rules = undefined;
190
- }
191
- return {
192
- confirmationsOn: gate && typeof gate.enabled === 'boolean' ? gate.enabled : undefined,
193
- rules,
194
- source: (gate && gate.source) || 'unavailable',
195
- };
196
- } catch {
197
- return { confirmationsOn: undefined, rules: undefined, source: 'unavailable' };
198
- }
199
- }
200
-
201
- /** The CLI's rule shape, verbatim (D8 rule 1: not a new schema). */
202
- function normalizeRules(rules) {
203
- const r = rules && typeof rules === 'object' ? rules : {};
204
- const list = (v) => (Array.isArray(v) ? v.map(String) : []);
205
- return Object.freeze({
206
- defaultMode: r.defaultMode === 'allow' || r.defaultMode === 'deny' ? r.defaultMode : 'ask',
207
- allow: Object.freeze(list(r.allow)),
208
- deny: Object.freeze(list(r.deny)),
209
- ask: Object.freeze(list(r.ask)),
210
- // Only an explicitly written `defaultMode: 'ask'` prompts on the residual;
211
- // the file-free default must not (cli/src/permissions.js's scope note).
212
- explicitAsk: r.explicitAsk === true || r.defaultMode === 'ask',
213
- });
214
- }
215
-
216
- /**
217
- * Resolve the posture ONCE.
218
- *
219
- * @param {object} [input]
220
- * @param {object} [input.rules] the shared rule set (CLI shape)
221
- * @param {boolean} [input.flag] `--dangerously-skip-permissions` was passed
222
- * @param {object} [input.env] environment (read, never mutated)
223
- * @param {boolean} [input.interactive] both stdio ends are a terminal
224
- * @param {string} [input.childKind] 'headless' | 'interactive'
225
- * @param {boolean} [input.gate] the STORE's confirmation posture:
226
- * `false` means the user already turned
227
- * the gates off (`/automode`, or the
228
- * desktop switch). Resolved by the caller
229
- * (`storedPermissionFacts()`), never read
230
- * from `process.*` here — the standing
231
- * seam rule for `one/`.
232
- * @param {object} [opts]
233
- * @param {object} [opts.evaluator] injectable, for tests only
234
- * @returns frozen decision record
235
- */
236
- function resolvePosture(input = {}, opts = {}) {
237
- const evaluator = loadEvaluator(opts.evaluator);
238
- const rules = normalizeRules(input.rules);
239
- const interactive = input.interactive === true;
240
- const childKind = input.childKind === CHILD_KINDS.INTERACTIVE ? CHILD_KINDS.INTERACTIVE : CHILD_KINDS.HEADLESS;
241
- const skip = evaluator.resolveSkip({ flag: input.flag === true, env: input.env, interactive });
242
- // ── the second, already-resolved answer ──────────────────────────────────
243
- //
244
- // `--dangerously-skip-permissions` is not the only way this product can be
245
- // running with the gates down. Since ON8 there is a stored posture, written
246
- // by `/automode` (alias `/yolo`), by `/confirm`, by `/multiyolo` and by the
247
- // desktop's switch, that the faces read on every tool round. This resolver
248
- // read the flag and the environment and nothing else, so a session whose user
249
- // had already said "stop asking" handed the Claude child NO permission flag:
250
- // headless, the child then asked a question nobody could answer — the hang
251
- // rule 4 exists to prevent — while the terminal face beside it ran ungated.
252
- // Two faces, one posture, one of them still asking is precisely the drift D8
253
- // names, so the stored answer is folded in HERE, at the one place that
254
- // produces the record, and never re-derived downstream.
255
- //
256
- // It cannot reach either floor. `skip` only ever downgrades an `'ask'`
257
- // verdict in `gateFor()`, an explicit `deny` still wins, and the covenant's
258
- // `preActionAssert` plus the avatar's `LEVEL_INDEPENDENT_APPROVALS`
259
- // (`write`/`shell`/`network`/`offDevice`) are the same frozen four as before:
260
- // the store is the *configurable* half of rule 2 by definition — it is what
261
- // the confirmation gate itself reads — so honoring it here widens nothing.
262
- const storedOff = input.gate === false;
263
- const effectiveSkip = skip.skip || storedOff;
264
- const skipSource = skip.skip ? skip.source : storedOff ? 'posture' : skip.source;
265
-
266
- const isInteractiveChild = childKind === CHILD_KINDS.INTERACTIVE;
267
- return Object.freeze({
268
- version: 1,
269
- rules,
270
- interactive,
271
- childKind,
272
- // Rule 5 already applied: `skip` is the product's answer, not the raw env.
273
- skip: effectiveSkip,
274
- skipSource,
275
- // Which of the two produced it. The run-log line and the rule-3 report are
276
- // silent for a stored posture on purpose: the report exists because "a flag
277
- // whose blast radius is invisible is how a footgun ships", and a flag typed
278
- // for one run is that. A posture is a setting the user can see in both
279
- // faces' own UI and turn back, and printing a skip banner on every launch
280
- // of a deliberately-ungated install is noise that teaches scrolling — but
281
- // the child's argv is still recorded by `childRecordLine`, so the decision
282
- // remains accountable.
283
- skipFromFlag: skip.skip,
284
- envVarSet: skip.envSet,
285
- // The store's answer, recorded rather than inferred (three states: true,
286
- // false, and `null` for "there was no stored posture to read").
287
- storedGate: input.gate === undefined || input.gate === null ? null : Boolean(input.gate),
288
- warned: skip.warned,
289
- warning: skip.warning || null,
290
- // What a skip covers, and what it cannot touch. Both are frozen lists so a
291
- // caller cannot widen either one in place.
292
- skipped: Object.freeze(effectiveSkip ? CONFIGURABLE_CLASSES : []),
293
- frozen: FROZEN_CLASSES,
294
- // The child's variant, derived here so no spawn site re-derives it (rule 4).
295
- child: Object.freeze({
296
- kind: childKind,
297
- skip: effectiveSkip,
298
- flag: !effectiveSkip
299
- ? null
300
- : isInteractiveChild
301
- ? '--allow-dangerously-skip-permissions'
302
- : '--dangerously-skip-permissions',
303
- why: !effectiveSkip
304
- ? 'no skip was asked for, so no permission flag is passed to the child'
305
- : isInteractiveChild
306
- ? 'the interactive variant offers the bypass as an option (the child still asks; a human is there)'
307
- : 'the headless variant takes the bypass as a default, because no one can answer the child\'s prompt',
308
- }),
309
- });
310
- }
311
-
312
- /**
313
- * The verdict for one tool call, from the ONE evaluator.
314
- *
315
- * Precedence, and each step is load-bearing:
316
- *
317
- * 1. `'deny'` stays `'deny'` — an explicit deny rule is a rule, not a
318
- * confirmation gate, so a skip must not be able to turn it into an allow.
319
- * 2. `'allow'` stays `'allow'`.
320
- * 3. `'ask'` becomes `'allow'` only when the posture says skip. That is
321
- * exactly "this product's confirmation gates", the configurable half.
322
- *
323
- * The frozen four never reach a different answer through this function: their
324
- * floors are the covenant assert and the avatar caps, which read neither this
325
- * record nor the store.
326
- */
327
- function gateFor(posture, tool, args, opts = {}) {
328
- const evaluator = loadEvaluator(opts.evaluator);
329
- const rules = posture && posture.rules ? posture.rules : normalizeRules({});
330
- const verdict = evaluator.evalPermission(tool, args, rules);
331
- if (verdict === 'deny') return 'deny';
332
- if (verdict === 'allow') return 'allow';
333
- return posture && posture.skip ? 'allow' : 'ask';
334
- }
335
-
336
- /** The one-line "what was skipped" report (D8 rule 3). */
337
- function skipReport(posture) {
338
- if (!posture || !posture.skip) return null;
339
- const childClause = posture.child.flag
340
- ? `; the ${posture.child.kind} Claude child is passed ${posture.child.flag}`
341
- : '';
342
- // Named by its actual source, never as a flag the user did not type: a stored
343
- // posture (`/automode`, the desktop switch) is reported for what it is, since
344
- // printing `--dangerously-skip-permissions` for a setting would be the same
345
- // kind of small lie as eating the flag.
346
- const what =
347
- posture.skipSource === 'posture'
348
- ? 'automode (the stored confirmation posture both faces share)'
349
- : '--dangerously-skip-permissions';
350
- return (
351
- `aegis: ${what} (via ${posture.skipSource}) — skipping the configurable ` +
352
- `confirmation gates (${CONFIGURABLE_CLASSES.join(', ')})${childClause}. NOT skipped, and not ` +
353
- `reachable by any setting, flag or env var: the ÆGIS covenant pre-action assert and the ` +
354
- `${FROZEN_CLASSES.join('|')} approvals (always 'ask'), plus any explicit deny rule.`
355
- );
356
- }
357
-
358
- module.exports = {
359
- CHILD_KINDS,
360
- CONFIGURABLE_CLASSES,
361
- FROZEN_CLASSES,
362
- PERMISSION_MODES,
363
- SKIP_FLAG,
364
- loadEvaluator,
365
- loadConfigStore,
366
- storedPermissionFacts,
367
- normalizeRules,
368
- resolvePosture,
369
- gateFor,
370
- skipReport,
371
- };
3
+ "use strict";const path=require("node:path"),CHILD_KINDS=Object.freeze({HEADLESS:"headless",INTERACTIVE:"interactive"}),CONFIGURABLE_CLASSES=Object.freeze(["exec","writeFile","editFile"]),SKIP_FLAG="--dangerously-skip-permissions",FROZEN_CLASSES=Object.freeze(["write","shell","network","offDevice"]),PERMISSION_MODES=Object.freeze(["acceptEdits","auto","bypassPermissions","manual","dontAsk","plan"]);let cachedEvaluator=null,cachedConfig=null;function loadEvaluator(e){if(e)return e;if(cachedEvaluator)return cachedEvaluator;const o=[path.join(__dirname,"..","..","cli","src","permissions.js"),path.join(__dirname,"..","vendor","cli","src","permissions.js")];for(const e of o)try{const o=require(e);if(o&&"function"==typeof o.evalPermission&&"function"==typeof o.resolveSkip)return cachedEvaluator=o,o}catch{}throw new Error("aegis: the one rule evaluator (cli/src/permissions.js) is missing from this install — refusing to resolve a permission posture from a second, unshared rule engine.")}function loadConfigStore(e){if(e)return e;if(cachedConfig)return cachedConfig;const o=[path.join(__dirname,"..","..","cli","src","config.js"),path.join(__dirname,"..","vendor","cli","src","config.js")];for(const e of o)try{const o=require(e);if(o&&"function"==typeof o.confirmPosture)return cachedConfig=o,o}catch{}return null}function storedPermissionFacts(e={}){const o=loadConfigStore(e.config);if(!o)return{confirmationsOn:void 0,rules:void 0,source:"unavailable"};try{const e=o.confirmPosture();let r;try{r=o.loadPermissions()}catch{r=void 0}return{confirmationsOn:e&&"boolean"==typeof e.enabled?e.enabled:void 0,rules:r,source:e&&e.source||"unavailable"}}catch{return{confirmationsOn:void 0,rules:void 0,source:"unavailable"}}}function normalizeRules(e){const o=e&&"object"==typeof e?e:{},r=e=>Array.isArray(e)?e.map(String):[];return Object.freeze({defaultMode:"allow"===o.defaultMode||"deny"===o.defaultMode?o.defaultMode:"ask",allow:Object.freeze(r(o.allow)),deny:Object.freeze(r(o.deny)),ask:Object.freeze(r(o.ask)),explicitAsk:!0===o.explicitAsk||"ask"===o.defaultMode})}function resolvePosture(e={},o={}){const r=loadEvaluator(o.evaluator),s=normalizeRules(e.rules),i=!0===e.interactive,a=e.childKind===CHILD_KINDS.INTERACTIVE?CHILD_KINDS.INTERACTIVE:CHILD_KINDS.HEADLESS,n=r.resolveSkip({flag:!0===e.flag,env:e.env,interactive:i}),t=!1===e.gate,l=n.skip||t,c=n.skip?n.source:t?"posture":n.source,u=a===CHILD_KINDS.INTERACTIVE;return Object.freeze({version:1,rules:s,interactive:i,childKind:a,skip:l,skipSource:c,skipFromFlag:n.skip,envVarSet:n.envSet,storedGate:void 0===e.gate||null===e.gate?null:Boolean(e.gate),warned:n.warned,warning:n.warning||null,skipped:Object.freeze(l?CONFIGURABLE_CLASSES:[]),frozen:FROZEN_CLASSES,child:Object.freeze({kind:a,skip:l,flag:l?u?"--allow-dangerously-skip-permissions":"--dangerously-skip-permissions":null,why:l?u?"the interactive variant offers the bypass as an option (the child still asks; a human is there)":"the headless variant takes the bypass as a default, because no one can answer the child's prompt":"no skip was asked for, so no permission flag is passed to the child"})})}function gateFor(e,o,r,s={}){const i=loadEvaluator(s.evaluator),a=e&&e.rules?e.rules:normalizeRules({}),n=i.evalPermission(o,r,a);return"deny"===n?"deny":"allow"===n||e&&e.skip?"allow":"ask"}function skipReport(e){if(!e||!e.skip)return null;const o=e.child.flag?`; the ${e.child.kind} Claude child is passed ${e.child.flag}`:"";return`aegis: ${"posture"===e.skipSource?"automode (the stored confirmation posture both faces share)":"--dangerously-skip-permissions"} (via ${e.skipSource}) — skipping the configurable confirmation gates (${CONFIGURABLE_CLASSES.join(", ")})${o}. NOT skipped, and not reachable by any setting, flag or env var: the ÆGIS covenant pre-action assert and the ${FROZEN_CLASSES.join("|")} approvals (always 'ask'), plus any explicit deny rule.`}module.exports={CHILD_KINDS:CHILD_KINDS,CONFIGURABLE_CLASSES:CONFIGURABLE_CLASSES,FROZEN_CLASSES:FROZEN_CLASSES,PERMISSION_MODES:PERMISSION_MODES,SKIP_FLAG:SKIP_FLAG,loadEvaluator:loadEvaluator,loadConfigStore:loadConfigStore,storedPermissionFacts:storedPermissionFacts,normalizeRules:normalizeRules,resolvePosture:resolvePosture,gateFor:gateFor,skipReport:skipReport};
package/src/probes.js CHANGED
@@ -1,161 +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
- * The impure half of the dispatch, kept deliberately in its own file.
10
- *
11
- * `dispatch.js` is pure — it reads nothing, so every one of its branches is
12
- * exercisable on a headless Linux CI box. This file is where the honesty
13
- * happens instead: the real `process` facts are gathered in exactly one place
14
- * (`collect()`), and every probe takes its inputs as parameters so the same
15
- * functions can be driven from a test with a fake environment, a fake platform
16
- * and a fake directory.
17
- *
18
- * The split is the whole point. If the reads lived inside the decision, the
19
- * window face would be untestable wherever it was written — and therefore
20
- * untested everywhere it shipped.
21
- */
22
-
23
- const fs = require('node:fs');
24
- const path = require('node:path');
25
- const { createRequire } = require('node:module');
26
- const host = require('./host.js');
27
-
28
- /**
29
- * Is a graphical session plausibly reachable?
30
- *
31
- * X11 and Wayland both announce themselves in the environment; macOS and
32
- * Windows always have one (the check is not "is a screen attached", it is
33
- * "would launching a window be a category error"). Mir and a couple of
34
- * remote-desktop spellings are honoured because they are free and because a
35
- * false negative here costs the user the window for no reason.
36
- */
37
- function hasDisplay(env, platform) {
38
- const e = env || {};
39
- const p = platform || host.hostPlatform();
40
- if (p === 'darwin' || p === 'win32') return true;
41
- return Boolean(e.DISPLAY || e.WAYLAND_DISPLAY || e.MIR_SERVER_SOCKET);
42
- }
43
-
44
- /** Resolve a module as if it were required from `dir`. Null if it cannot be. */
45
- function resolveFrom(dir, spec) {
46
- if (!dir) return null;
47
- try {
48
- return createRequire(path.join(dir, 'package.json')).resolve(spec);
49
- } catch {
50
- return null;
51
- }
52
- }
53
-
54
- /**
55
- * The Electron *executable*, or null.
56
- *
57
- * `require('electron')` outside an Electron process exports the absolute path
58
- * to the binary — that is the documented behaviour of the npm package, and it
59
- * is the same call `desktop/bin/aegis.js` makes (where it throws when Electron
60
- * is missing). Resolving it here means the dispatch probe and the eventual
61
- * spawn agree on what "resolvable" means by construction.
62
- *
63
- * The string is returned rather than a boolean because the caller needs to
64
- * spawn it.
65
- */
66
- function electronExecutable(fromDirs) {
67
- const dirs = Array.isArray(fromDirs) ? fromDirs : [fromDirs];
68
- for (const dir of dirs) {
69
- const entry = resolveFrom(dir, 'electron');
70
- if (!entry) continue;
71
- try {
72
- const mod = createRequire(path.join(dir, 'package.json'))('electron');
73
- if (typeof mod === 'string' && mod) return mod;
74
- // Older package layouts export an object with a `path`/`default`.
75
- if (mod && typeof mod.path === 'string' && mod.path) return mod.path;
76
- if (mod && typeof mod.default === 'string' && mod.default) return mod.default;
77
- } catch {
78
- /* resolved but unloadable: treat as not installed */
79
- }
80
- }
81
- return null;
82
- }
83
-
84
- /** Both ends of stdio, as booleans. Unknown counts as "not a terminal". */
85
- function stdioTty(stdin, stdout) {
86
- const isatty = (s) => {
87
- try {
88
- return Boolean(s && s.isTTY);
89
- } catch {
90
- return false;
91
- }
92
- };
93
- return {
94
- stdin: isatty(stdin === undefined ? process.stdin : stdin),
95
- stdout: isatty(stdout === undefined ? process.stdout : stdout),
96
- };
97
- }
98
-
99
- /** Directories a sibling package might live in, repo layout first. */
100
- function packageDirs(oneDir, name) {
101
- const dirs = [path.join(oneDir, '..', name)];
102
- const vendor = path.join(oneDir, 'vendor', name);
103
- if (fs.existsSync(vendor)) dirs.push(vendor);
104
- return dirs;
105
- }
106
-
107
- /** First existing file from a list of candidates. */
108
- function firstFile(candidates) {
109
- for (const c of candidates) {
110
- if (c && fs.existsSync(c)) return c;
111
- }
112
- return null;
113
- }
114
-
115
- /**
116
- * Gather every fact `decide()` needs. This is the only function in AEGISONE
117
- * that is allowed to read the process, and it reads nothing that a caller
118
- * cannot override — which is what makes the tests below honest.
119
- *
120
- * @param {object} [opts] overrides, used by tests
121
- */
122
- function collect(opts) {
123
- const o = opts || {};
124
- const oneDir = o.oneDir || path.resolve(__dirname, '..');
125
- const env = o.env || process.env;
126
- const platform = o.platform || host.hostPlatform();
127
- const invokedAs = o.invokedAs || path.basename(process.argv[1] || 'aegis');
128
-
129
- const cliBin =
130
- env.AEGISONE_CLI_BIN ||
131
- firstFile(packageDirs(oneDir, 'cli').map((d) => path.join(d, 'bin', 'aegiscode.js')));
132
- const desktopMain =
133
- env.AEGISONE_DESKTOP_BIN ||
134
- firstFile(packageDirs(oneDir, 'desktop').map((d) => path.join(d, 'bin', 'aegis.js')));
135
-
136
- const electron = o.electron !== undefined ? o.electron : electronExecutable(packageDirs(oneDir, 'desktop'));
137
-
138
- return {
139
- argv: o.argv || process.argv.slice(2),
140
- env,
141
- platform,
142
- tty: o.tty || stdioTty(process.stdin, process.stdout),
143
- hasDisplay: o.hasDisplay !== undefined ? Boolean(o.hasDisplay) : hasDisplay(env, platform),
144
- electronResolvable: Boolean(electron),
145
- invokedAs,
146
- // Not read by decide(): the handoff needs the executables themselves.
147
- _cliBin: cliBin,
148
- _desktopMain: desktopMain,
149
- _electron: electron,
150
- };
151
- }
152
-
153
- module.exports = {
154
- hasDisplay,
155
- resolveFrom,
156
- electronExecutable,
157
- stdioTty,
158
- packageDirs,
159
- firstFile,
160
- collect,
161
- };
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{createRequire:createRequire}=require("node:module"),host=require("./host.js");function hasDisplay(e,t){const r=e||{},o=t||host.hostPlatform();return"darwin"===o||"win32"===o||Boolean(r.DISPLAY||r.WAYLAND_DISPLAY||r.MIR_SERVER_SOCKET)}function resolveFrom(e,t){if(!e)return null;try{return createRequire(path.join(e,"package.json")).resolve(t)}catch{return null}}function electronExecutable(e){const t=Array.isArray(e)?e:[e];for(const e of t)if(resolveFrom(e,"electron"))try{const t=createRequire(path.join(e,"package.json"))("electron");if("string"==typeof t&&t)return t;if(t&&"string"==typeof t.path&&t.path)return t.path;if(t&&"string"==typeof t.default&&t.default)return t.default}catch{}return null}function stdioTty(e,t){const r=e=>{try{return Boolean(e&&e.isTTY)}catch{return!1}};return{stdin:r(void 0===e?process.stdin:e),stdout:r(void 0===t?process.stdout:t)}}function packageDirs(e,t){const r=[path.join(e,"..",t)],o=path.join(e,"vendor",t);return fs.existsSync(o)&&r.push(o),r}function firstFile(e){for(const t of e)if(t&&fs.existsSync(t))return t;return null}function collect(e){const t=e||{},r=t.oneDir||path.resolve(__dirname,".."),o=t.env||process.env,s=t.platform||host.hostPlatform(),n=t.invokedAs||path.basename(process.argv[1]||"aegis"),i=o.AEGISONE_CLI_BIN||firstFile(packageDirs(r,"cli").map((e=>path.join(e,"bin","aegiscode.js")))),a=o.AEGISONE_DESKTOP_BIN||firstFile(packageDirs(r,"desktop").map((e=>path.join(e,"bin","aegis.js")))),c=void 0!==t.electron?t.electron:electronExecutable(packageDirs(r,"desktop"));return{argv:t.argv||process.argv.slice(2),env:o,platform:s,tty:t.tty||stdioTty(process.stdin,process.stdout),hasDisplay:void 0!==t.hasDisplay?Boolean(t.hasDisplay):hasDisplay(o,s),electronResolvable:Boolean(c),invokedAs:n,_cliBin:i,_desktopMain:a,_electron:c}}module.exports={hasDisplay:hasDisplay,resolveFrom:resolveFrom,electronExecutable:electronExecutable,stdioTty:stdioTty,packageDirs:packageDirs,firstFile:firstFile,collect:collect};