aegisone 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +1 -1
- package/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -322
- package/package.json +4 -2
- package/scripts/bump.mjs +1 -211
- package/scripts/bundle.js +1 -129
- package/scripts/predist.mjs +1 -939
- package/src/child.js +1 -285
- package/src/dispatch.js +1 -269
- package/src/doctor.js +1 -639
- package/src/host.js +1 -111
- package/src/permissions.js +1 -369
- package/src/probes.js +1 -159
- package/src/release.js +1 -409
- package/vendor/cli/bin/aegiscode.js +2 -914
- package/vendor/cli/package.json +3 -2
- package/vendor/cli/scripts/check.mjs +1 -52
- package/vendor/cli/scripts/demo.mjs +1 -94
- package/vendor/cli/scripts/predist.mjs +1 -75
- package/vendor/cli/scripts/runtests.mjs +1 -56
- package/vendor/cli/scripts/seal-gate.mjs +1 -74
- package/vendor/cli/src/agents.js +1 -139
- package/vendor/cli/src/app.js +1 -2932
- package/vendor/cli/src/art.js +1 -289
- package/vendor/cli/src/autonomous.js +1 -515
- package/vendor/cli/src/caps.js +1 -879
- package/vendor/cli/src/chatflow.js +1 -3008
- package/vendor/cli/src/checkpoint.js +1 -90
- package/vendor/cli/src/clipboard.js +1 -424
- package/vendor/cli/src/cloudsync.js +1 -528
- package/vendor/cli/src/commands.js +1 -3987
- package/vendor/cli/src/config.js +1 -581
- package/vendor/cli/src/connect.js +1 -349
- package/vendor/cli/src/credentials.js +1 -33
- package/vendor/cli/src/deps.js +1 -232
- package/vendor/cli/src/devrun.js +1 -187
- package/vendor/cli/src/diff.js +1 -333
- package/vendor/cli/src/diffview.js +1 -296
- package/vendor/cli/src/engine.js +1 -297
- package/vendor/cli/src/entitlement.js +1 -355
- package/vendor/cli/src/events.js +1 -707
- package/vendor/cli/src/export.js +1 -67
- package/vendor/cli/src/fingerprint.js +1 -592
- package/vendor/cli/src/format.js +1 -259
- package/vendor/cli/src/fuzzy.js +1 -119
- package/vendor/cli/src/gate.js +1 -55
- package/vendor/cli/src/history.js +1 -401
- package/vendor/cli/src/init.js +1 -175
- package/vendor/cli/src/input.js +1 -139
- package/vendor/cli/src/keys.js +1 -183
- package/vendor/cli/src/limits.js +1 -190
- package/vendor/cli/src/markdown.js +1 -306
- package/vendor/cli/src/mcp.js +1 -694
- package/vendor/cli/src/models.js +1 -487
- package/vendor/cli/src/naming.js +1 -229
- package/vendor/cli/src/overlays.js +1 -461
- package/vendor/cli/src/panels.js +1 -1418
- package/vendor/cli/src/permissions.js +1 -290
- package/vendor/cli/src/ping.js +1 -226
- package/vendor/cli/src/presence.js +1 -238
- package/vendor/cli/src/provenance.js +2 -182
- package/vendor/cli/src/render.js +1 -515
- package/vendor/cli/src/screen.js +1 -518
- package/vendor/cli/src/screens.js +1 -896
- package/vendor/cli/src/secret.js +1 -59
- package/vendor/cli/src/securefs.js +1 -359
- package/vendor/cli/src/settings.js +1 -155
- package/vendor/cli/src/shared.js +1 -52
- package/vendor/cli/src/sharedpaths.js +1 -53
- package/vendor/cli/src/signup.js +1 -156
- package/vendor/cli/src/summarize.js +1 -95
- package/vendor/cli/src/sysdiag.js +1 -585
- package/vendor/cli/src/system.js +1 -40
- package/vendor/cli/src/theme.js +1 -570
- package/vendor/cli/src/title.js +1 -220
- package/vendor/cli/src/todos.js +1 -115
- package/vendor/cli/src/tokens.js +1 -263
- package/vendor/cli/src/topup.js +1 -210
- package/vendor/cli/src/update.js +1 -181
- package/vendor/cli/vendor/client/aegis.js +1 -2054
- package/vendor/cli/vendor/client/attest.js +1 -442
- package/vendor/cli/vendor/client/authorship-key.js +1 -410
- package/vendor/cli/vendor/client/auto-provision.js +1 -134
- package/vendor/cli/vendor/client/brain-catalog.js +1 -268
- package/vendor/cli/vendor/client/byok-catalog.js +1 -230
- package/vendor/cli/vendor/client/credentials.js +1 -494
- package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
- package/vendor/cli/vendor/client/drive-connect.js +1 -85
- package/vendor/cli/vendor/client/drive-upload.js +1 -174
- package/vendor/cli/vendor/client/env-file.js +1 -1273
- package/vendor/cli/vendor/client/fingerprint.js +1 -1064
- package/vendor/cli/vendor/client/foreign-memory.js +1 -669
- package/vendor/cli/vendor/client/google-signin.js +1 -125
- package/vendor/cli/vendor/client/hooks.js +1 -430
- package/vendor/cli/vendor/client/model-discovery.js +1 -330
- package/vendor/cli/vendor/client/platform.js +1 -937
- package/vendor/cli/vendor/client/prefs.js +1 -351
- package/vendor/cli/vendor/client/presence-constants.js +1 -107
- package/vendor/cli/vendor/client/presence.js +1 -438
- package/vendor/cli/vendor/client/record-vault.js +3 -1055
- package/vendor/cli/vendor/client/session-store.js +1 -548
- package/vendor/cli/vendor/client/topup.js +1 -297
- package/vendor/cli/vendor/client/touch.js +1 -458
- package/vendor/cli/vendor/client/update.js +1 -704
- package/vendor/cli/vendor/client/user-models.js +1 -381
- package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3228
- package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -654
- package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
- package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/cli/vendor/hosts/install.js +1 -638
- package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
- package/vendor/cli/vendor/hosts/spec.js +1 -164
- package/vendor/cli/vendor/hosts/targets.js +1 -346
- package/vendor/cli/vendor/mcp/server.js +1 -221
- package/vendor/cli/vendor/mcp/tools.js +1 -408
- package/vendor/cli/vendor/one/src/child.js +1 -285
- package/vendor/cli/vendor/one/src/permissions.js +1 -369
- package/vendor/desktop/bin/aegis.js +1 -32
- package/vendor/desktop/lib/account-key.js +1 -56
- package/vendor/desktop/lib/auto.js +1 -430
- package/vendor/desktop/lib/avatar/companion.js +1 -698
- package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
- package/vendor/desktop/lib/avatar/events.js +1 -344
- package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
- package/vendor/desktop/lib/avatar/holders.js +1 -612
- package/vendor/desktop/lib/avatar/identity.js +1 -641
- package/vendor/desktop/lib/avatar/level.js +1 -368
- package/vendor/desktop/lib/avatar/mirror.js +1 -524
- package/vendor/desktop/lib/avatar/persona.js +1 -388
- package/vendor/desktop/lib/avatar/profile.js +1 -977
- package/vendor/desktop/lib/avatar/register.js +1 -307
- package/vendor/desktop/lib/avatar/store.js +1 -472
- package/vendor/desktop/lib/avatar/tiers.js +1 -38
- package/vendor/desktop/lib/avatar/transfer.js +1 -415
- package/vendor/desktop/lib/avatar/turn.js +1 -216
- package/vendor/desktop/lib/avatar/voice.js +1 -328
- package/vendor/desktop/lib/avatar/xp.js +1 -404
- package/vendor/desktop/lib/deep-link.js +1 -120
- package/vendor/desktop/lib/fingerprint.js +2 -347
- package/vendor/desktop/lib/google-connect.js +1 -169
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/desktop/lib/local/engine.js +1 -3228
- package/vendor/desktop/lib/local/entitlement.js +1 -654
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/desktop/lib/local/telemetry.js +1 -470
- package/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/provider-key-mirror.js +1 -252
- package/vendor/desktop/lib/quick-launcher.js +1 -84
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/lib/sync/memory-queue.js +1 -60
- package/vendor/desktop/lib/sync/persist-gate.js +1 -148
- package/vendor/desktop/lib/sync/sessions.js +1 -106
- package/vendor/desktop/lib/window-state.js +1 -66
- package/vendor/desktop/main.js +1 -4390
- package/vendor/desktop/package.json +3 -5
- package/vendor/desktop/preload.js +1 -628
- package/vendor/desktop/renderer/app.js +1 -6560
- package/vendor/desktop/renderer/avatar/assemble.js +1 -335
- package/vendor/desktop/renderer/avatar/avatar.js +1 -380
- package/vendor/desktop/renderer/avatar/cards.js +1 -141
- package/vendor/desktop/renderer/avatar/hud.js +1 -206
- package/vendor/desktop/renderer/avatar/machine.js +1 -213
- package/vendor/desktop/renderer/avatar/pane.js +1 -439
- package/vendor/desktop/renderer/avatar/parts.js +1 -437
- package/vendor/desktop/renderer/budget.js +1 -168
- package/vendor/desktop/renderer/companion.js +1 -223
- package/vendor/desktop/renderer/diff.js +1 -359
- package/vendor/desktop/renderer/diffview.js +1 -336
- package/vendor/desktop/renderer/fingerprint.js +3 -720
- package/vendor/desktop/renderer/markdown.js +1 -168
- package/vendor/desktop/renderer/provider-toolbar.js +1 -134
- package/vendor/desktop/renderer/providers.js +1 -259
- package/vendor/desktop/renderer/quick.js +1 -191
- package/vendor/desktop/renderer/stream-policy.js +1 -306
- package/vendor/desktop/renderer/transcript-view.js +1 -323
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/desktop/vendor/aegis.js +1 -2054
- package/vendor/desktop/vendor/attest.js +1 -442
- package/vendor/desktop/vendor/authorship-key.js +1 -410
- package/vendor/desktop/vendor/auto-provision.js +1 -134
- package/vendor/desktop/vendor/brain-catalog.js +1 -268
- package/vendor/desktop/vendor/byok-catalog.js +1 -230
- package/vendor/desktop/vendor/credentials.js +1 -494
- package/vendor/desktop/vendor/device-fingerprint.js +1 -141
- package/vendor/desktop/vendor/drive-connect.js +1 -85
- package/vendor/desktop/vendor/drive-upload.js +1 -174
- package/vendor/desktop/vendor/env-file.js +1 -1273
- package/vendor/desktop/vendor/fingerprint.js +1 -1064
- package/vendor/desktop/vendor/foreign-memory.js +1 -669
- package/vendor/desktop/vendor/google-signin.js +1 -125
- package/vendor/desktop/vendor/hooks.js +1 -430
- package/vendor/desktop/vendor/model-discovery.js +1 -330
- package/vendor/desktop/vendor/platform.js +1 -937
- package/vendor/desktop/vendor/prefs.js +1 -351
- package/vendor/desktop/vendor/presence-constants.js +1 -107
- package/vendor/desktop/vendor/presence.js +1 -438
- package/vendor/desktop/vendor/record-vault.js +3 -1055
- package/vendor/desktop/vendor/session-store.js +1 -548
- package/vendor/desktop/vendor/topup.js +1 -297
- package/vendor/desktop/vendor/touch.js +1 -458
- package/vendor/desktop/vendor/update.js +1 -704
- package/vendor/desktop/vendor/user-models.js +1 -381
package/src/child.js
CHANGED
|
@@ -1,287 +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
|
-
* child.js — the Claude child's argv, DERIVED (AEGISONE, decision D8 rule 4).
|
|
10
|
-
*
|
|
11
|
-
* AEGISONE spawns `claude` for the Claude-Pro/BYOK path. That process runs its
|
|
12
|
-
* own permission system, and its prompts land on *its* stdin — which neither a
|
|
13
|
-
* GUI approval card nor the CLI's prompt loop can answer. The repo already ran
|
|
14
|
-
* this invocation for real (`benchmarks/frozen-run-final-noaider.json`):
|
|
15
|
-
*
|
|
16
|
-
* -p --output-format stream-json --dangerously-skip-permissions
|
|
17
|
-
* (ANTHROPIC_BASE_URL=api.deepseek.com/anthropic)
|
|
18
|
-
*
|
|
19
|
-
* Two bugs that shape every choice below:
|
|
20
|
-
*
|
|
21
|
-
* 1. **A hand-typed argv is a second decision.** If the spawn site writes its
|
|
22
|
-
* own flags, the child's policy and ours drift the moment either changes —
|
|
23
|
-
* and the child's is the one nobody can answer. So the argv is built here,
|
|
24
|
-
* from the posture record `one/src/permissions.js` already resolved, and
|
|
25
|
-
* the exact array is asserted by test (argv EQUALITY, not "a flag was
|
|
26
|
-
* passed"), for both child kinds.
|
|
27
|
-
* 2. **`-p` with an unanswered prompt is a HANG, not a refusal.** For a
|
|
28
|
-
* headless child the bypass is the derived skip; without it the child asks
|
|
29
|
-
* a question nobody can answer. The negative control for that lives with
|
|
30
|
-
* the runner (the "no one to answer it" path), and this module's half of it
|
|
31
|
-
* is that the headless argv carries NO permission flag when the posture
|
|
32
|
-
* says no skip — so the run fails fast instead of parking.
|
|
33
|
-
*
|
|
34
|
-
* ## Rule 4, in full
|
|
35
|
-
*
|
|
36
|
-
* headless `--dangerously-skip-permissions` iff our posture says skip;
|
|
37
|
-
* otherwise nothing at all (never a "harmless" default).
|
|
38
|
-
* interactive `--allow-dangerously-skip-permissions` instead — the same
|
|
39
|
-
* capability offered as an option rather than made the default,
|
|
40
|
-
* which is the narrowest thing that works and the variant
|
|
41
|
-
* Claude's own help describes as "without it being enabled by
|
|
42
|
-
* default".
|
|
43
|
-
* both `--allowedTools` / `--disallowedTools` from the SAME rule set
|
|
44
|
-
* (`allow` → allowed, `deny` → disallowed), so the child's policy
|
|
45
|
-
* tracks ours; `--permission-mode` only when it was explicitly
|
|
46
|
-
* given, validated against the CLI's own list, and ALWAYS
|
|
47
|
-
* recorded — recorded, never inferred.
|
|
48
|
-
*
|
|
49
|
-
* No `process.*` anywhere, module scope or not: the argv is a pure function of
|
|
50
|
-
* its descriptor, which is what makes the equality assertions above possible.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
/** Rule 4's own flag spellings (verified against claude 2.1.228's --help). */
|
|
54
|
-
const FLAGS = Object.freeze({
|
|
55
|
-
headlessSkip: '--dangerously-skip-permissions',
|
|
56
|
-
interactiveSkip: '--allow-dangerously-skip-permissions',
|
|
57
|
-
permissionMode: '--permission-mode',
|
|
58
|
-
allowedTools: '--allowedTools',
|
|
59
|
-
disallowedTools: '--disallowedTools',
|
|
60
|
-
print: '-p',
|
|
61
|
-
outputFormat: '--output-format',
|
|
62
|
-
model: '--model',
|
|
63
|
-
// Conversation continuity for the Pro child (see `sessionId` below). Both
|
|
64
|
-
// spellings are the CLI's own (claude 2.1.228 --help): `--session-id <uuid>`
|
|
65
|
-
// names the session a NEW conversation runs in, `--resume <id>` reattaches to
|
|
66
|
-
// an existing one, which is what carries the prior turns' context across
|
|
67
|
-
// separate child processes.
|
|
68
|
-
sessionId: '--session-id',
|
|
69
|
-
resume: '--resume',
|
|
70
|
-
// The extra working directories the child may touch (claude 2.1.228 --help:
|
|
71
|
-
// "Additional directories to allow tool …"). See addDirArgs() — the spelling
|
|
72
|
-
// here is deliberately the EQUALS form and that is not cosmetic.
|
|
73
|
-
addDir: '--add-dir',
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* `--add-dir` is the child's own sandbox boundary: by default a headless child
|
|
78
|
-
* resolves every relative path and every tool's root against the directory it
|
|
79
|
-
* was spawned in, so a turn started in `repo/cli/` cannot read, run or even
|
|
80
|
-
* SEE `repo/test/` — the exact "outside the sandboxed directory" wall a real
|
|
81
|
-
* session reported from this product.
|
|
82
|
-
*
|
|
83
|
-
* ── why the EQUALS form, and why one flag per directory ─────────────────────
|
|
84
|
-
*
|
|
85
|
-
* `--add-dir` is VARIADIC: the child keeps consuming the words after it as
|
|
86
|
-
* directories. So the obvious `['--add-dir', dir, prompt]` is not merely
|
|
87
|
-
* fragile, it is broken — and this was measured against the installed binary
|
|
88
|
-
* (2.1.228), not reasoned about:
|
|
89
|
-
*
|
|
90
|
-
* claude -p --add-dir /tmp "do the thing" → Error: Input must be provided
|
|
91
|
-
* either through stdin or as a
|
|
92
|
-
* prompt argument when using --print
|
|
93
|
-
* claude -p --add-dir=/tmp "do the thing" → runs
|
|
94
|
-
*
|
|
95
|
-
* The prompt is the LAST item of the argv (rule 4 keeps it there, because the
|
|
96
|
-
* child reads it as the initial message). A space-form `--add-dir` immediately
|
|
97
|
-
* before it therefore swallows the user's prompt into the directory list, and
|
|
98
|
-
* the turn dies as an empty-input error before the model is ever reached.
|
|
99
|
-
* Attaching the value to the flag with `=` terminates the variadic run, so the
|
|
100
|
-
* prompt survives, and one flag per directory keeps a directory whose name
|
|
101
|
-
* begins with `-` from being re-read as another option. Empty and duplicate
|
|
102
|
-
* entries are dropped here rather than passed on: the list reaches the child's
|
|
103
|
-
* sandbox, so what it contains is a decision, not a formality.
|
|
104
|
-
*/
|
|
105
|
-
function addDirArgs(dirs) {
|
|
106
|
-
const out = [];
|
|
107
|
-
for (const dir of unique(dirs)) out.push(`${FLAGS.addDir}=${dir}`);
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* A UUID, as `--session-id` requires. The CLI rejects anything else, and it
|
|
113
|
-
* rejects it AFTER the spawn — an argv that cannot work must not be built, so
|
|
114
|
-
* this returns null and the caller throws rather than typing a value the child
|
|
115
|
-
* will refuse while the turn looks as if it started.
|
|
116
|
-
*/
|
|
117
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
118
|
-
|
|
119
|
-
const DEFAULT_OUTPUT_FORMAT = 'stream-json';
|
|
120
|
-
|
|
121
|
-
/** Dedupe while keeping the user's own rule order (rules are read top-down). */
|
|
122
|
-
function unique(list) {
|
|
123
|
-
const seen = new Set();
|
|
124
|
-
const out = [];
|
|
125
|
-
for (const item of Array.isArray(list) ? list : []) {
|
|
126
|
-
const v = String(item).trim();
|
|
127
|
-
if (!v || seen.has(v)) continue;
|
|
128
|
-
seen.add(v);
|
|
129
|
-
out.push(v);
|
|
130
|
-
}
|
|
131
|
-
return out;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Build the Claude child's argv from the resolved posture.
|
|
136
|
-
*
|
|
137
|
-
* @param {object} [descriptor]
|
|
138
|
-
* @param {object} [descriptor.posture] a record from resolvePosture()
|
|
139
|
-
* @param {string} [descriptor.prompt] initial prompt (both kinds accept one)
|
|
140
|
-
* @param {string} [descriptor.model] explicit model id, if any
|
|
141
|
-
* @param {string} [descriptor.outputFormat] headless only; defaults to stream-json
|
|
142
|
-
* @param {string} [descriptor.permissionMode] explicit passthrough, one of
|
|
143
|
-
* PERMISSION_MODES (else throw)
|
|
144
|
-
* @param {string} [descriptor.resumeSessionId] reattach to an existing child
|
|
145
|
-
* session → `--resume <uuid>`
|
|
146
|
-
* @param {string} [descriptor.sessionId] name a NEW child session, so a
|
|
147
|
-
* LATER turn can `--resume` it
|
|
148
|
-
* @param {string[]} [descriptor.addDir] extra directories the child may
|
|
149
|
-
* work in → `--add-dir=<dir>` each
|
|
150
|
-
* @param {string[]} [descriptor.extra] extra argv items, appended last
|
|
151
|
-
* @returns {{argv: string[], record: object}} both frozen
|
|
152
|
-
* @throws when `permissionMode` is set to something Claude does not accept —
|
|
153
|
-
* a mode we cannot name is a mode we must not silently drop, because
|
|
154
|
-
* the run log would then record "no passthrough" for a run that asked
|
|
155
|
-
* for one.
|
|
156
|
-
* @throws when a session id is given that is not a UUID. Same reason, harder:
|
|
157
|
-
* `claude` refuses a malformed `--session-id` itself, after the spawn,
|
|
158
|
-
* so passing one through would turn a continuity bug into an opaque
|
|
159
|
-
* failed turn.
|
|
160
|
-
*/
|
|
161
|
-
function claudeArgv(descriptor = {}) {
|
|
162
|
-
const posture = descriptor.posture;
|
|
163
|
-
if (!posture || typeof posture !== 'object') {
|
|
164
|
-
throw new Error('claudeArgv requires a resolved posture record (one/src/permissions.js resolvePosture)');
|
|
165
|
-
}
|
|
166
|
-
const kind = posture.childKind;
|
|
167
|
-
const headless = kind !== 'interactive';
|
|
168
|
-
|
|
169
|
-
// Imported lazily to keep this module free of a load-time dependency on the
|
|
170
|
-
// evaluator, and to keep the enum's single definition in one place.
|
|
171
|
-
const { PERMISSION_MODES } = require('./permissions.js');
|
|
172
|
-
|
|
173
|
-
const modeGiven = descriptor.permissionMode !== undefined && descriptor.permissionMode !== null;
|
|
174
|
-
const mode = modeGiven ? String(descriptor.permissionMode) : null;
|
|
175
|
-
if (modeGiven && !PERMISSION_MODES.includes(mode)) {
|
|
176
|
-
throw new Error(
|
|
177
|
-
`--permission-mode ${JSON.stringify(mode)} is not one of ${PERMISSION_MODES.join('|')} — ` +
|
|
178
|
-
'refusing to pass (or to silently drop) a mode the child does not accept.'
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const rules = posture.rules || {};
|
|
183
|
-
const allowedTools = unique(rules.allow);
|
|
184
|
-
const disallowedTools = unique(rules.deny);
|
|
185
|
-
// Ask rules have no `--allowedTools`/`--disallowedTools` spelling: they are
|
|
186
|
-
// recorded rather than approximated, because approximating "ask" as "deny"
|
|
187
|
-
// would be a refusal the user never asked for.
|
|
188
|
-
const unmappedAsk = unique(rules.ask);
|
|
189
|
-
|
|
190
|
-
// ── conversation continuity ───────────────────────────────────────────────
|
|
191
|
-
//
|
|
192
|
-
// The Pro child runs its own agent loop, so the engine does not replay the
|
|
193
|
-
// transcript into it (engine.js's `pro` branch). Continuity therefore has to
|
|
194
|
-
// come from the CLI's own session store, or every turn is a new conversation
|
|
195
|
-
// with no memory of the last one — which is exactly what it was.
|
|
196
|
-
//
|
|
197
|
-
// `resumeSessionId` wins over `sessionId`: a reattach to a session we already
|
|
198
|
-
// had is the same conversation, and naming a NEW id while resuming would
|
|
199
|
-
// start a second thread beside the live one. Both are validated as UUIDs
|
|
200
|
-
// before they reach argv, because the CLI's own rejection lands after the
|
|
201
|
-
// spawn.
|
|
202
|
-
const wantedResumeId = descriptor.resumeSessionId ? String(descriptor.resumeSessionId).trim() : '';
|
|
203
|
-
const wantedNewId = descriptor.sessionId ? String(descriptor.sessionId).trim() : '';
|
|
204
|
-
const resumeId = wantedResumeId || null;
|
|
205
|
-
const newId = !resumeId && wantedNewId ? wantedNewId : null;
|
|
206
|
-
for (const [label, value] of [['resumeSessionId', resumeId], ['sessionId', newId]]) {
|
|
207
|
-
if (value && !UUID_RE.test(value)) {
|
|
208
|
-
throw new Error(
|
|
209
|
-
`${label} ${JSON.stringify(value)} is not a UUID — refusing to pass it to ` +
|
|
210
|
-
'--resume/--session-id, which the child rejects after the spawn (turning a ' +
|
|
211
|
-
'continuity bug into an opaque failed turn).'
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const argv = [];
|
|
217
|
-
if (headless) {
|
|
218
|
-
argv.push(FLAGS.print, FLAGS.outputFormat, String(descriptor.outputFormat || DEFAULT_OUTPUT_FORMAT));
|
|
219
|
-
}
|
|
220
|
-
if (descriptor.model) argv.push(FLAGS.model, String(descriptor.model));
|
|
221
|
-
// The widened sandbox, before the permission flags: what the child may reach
|
|
222
|
-
// is decided here, and the prompt stays last (see addDirArgs).
|
|
223
|
-
const addDir = addDirArgs(descriptor.addDir);
|
|
224
|
-
argv.push(...addDir);
|
|
225
|
-
if (allowedTools.length) argv.push(FLAGS.allowedTools, allowedTools.join(','));
|
|
226
|
-
if (disallowedTools.length) argv.push(FLAGS.disallowedTools, disallowedTools.join(','));
|
|
227
|
-
if (modeGiven) argv.push(FLAGS.permissionMode, mode);
|
|
228
|
-
if (posture.child && posture.child.flag) argv.push(posture.child.flag);
|
|
229
|
-
// Before `extra` (the transport's own flags) and before the prompt, which
|
|
230
|
-
// must stay last so the child reads it as the initial message.
|
|
231
|
-
if (resumeId) argv.push(FLAGS.resume, resumeId);
|
|
232
|
-
else if (newId) argv.push(FLAGS.sessionId, newId);
|
|
233
|
-
if (Array.isArray(descriptor.extra)) argv.push(...descriptor.extra.map(String));
|
|
234
|
-
if (descriptor.prompt !== undefined && descriptor.prompt !== null) argv.push(String(descriptor.prompt));
|
|
235
|
-
|
|
236
|
-
const record = Object.freeze({
|
|
237
|
-
kind,
|
|
238
|
-
// "always recorded" (rule 4): the mode is in the record whether or not it
|
|
239
|
-
// was passed, and `passThrough` says which of the two happened.
|
|
240
|
-
permissionMode: mode,
|
|
241
|
-
permissionModePassed: modeGiven,
|
|
242
|
-
skip: Boolean(posture.child && posture.child.skip),
|
|
243
|
-
skipFlag: (posture.child && posture.child.flag) || null,
|
|
244
|
-
allowedTools: Object.freeze(allowedTools),
|
|
245
|
-
disallowedTools: Object.freeze(disallowedTools),
|
|
246
|
-
unmappedAsk: Object.freeze(unmappedAsk),
|
|
247
|
-
// Recorded, not inferred, exactly like the argv: an install that WIDENED its
|
|
248
|
-
// sandbox for the child is the one thing a later reader of the run log must
|
|
249
|
-
// not have to reconstruct from the argv's shape.
|
|
250
|
-
addDir: Object.freeze(addDir.map((a) => a.slice(FLAGS.addDir.length + 1))),
|
|
251
|
-
// Continuity, recorded the same way the mode is: which of the two happened
|
|
252
|
-
// (reattached vs. named a new session) is part of what this turn asked for,
|
|
253
|
-
// and a caller reading only the argv would have to infer it from position.
|
|
254
|
-
resumeSessionId: resumeId,
|
|
255
|
-
sessionId: newId,
|
|
256
|
-
argv: Object.freeze(argv.slice()),
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
return { argv: record.argv, record };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** The run-log line for a child argv (rule 4: recorded, never inferred). */
|
|
263
|
-
function childRecordLine(record) {
|
|
264
|
-
if (!record || typeof record !== 'object') return null;
|
|
265
|
-
const mode = record.permissionModePassed
|
|
266
|
-
? `${FLAGS.permissionMode}=${record.permissionMode}`
|
|
267
|
-
: 'no --permission-mode (none was set)';
|
|
268
|
-
return (
|
|
269
|
-
`aegis: claude child [${record.kind}] ${record.skipFlag || 'no permission flag'} · ${mode} · ` +
|
|
270
|
-
`allowedTools=[${record.allowedTools.join(', ')}] disallowedTools=[${record.disallowedTools.join(', ')}]` +
|
|
271
|
-
(record.unmappedAsk.length ? ` (ask rules recorded, unmapped: ${record.unmappedAsk.join(', ')})` : '') +
|
|
272
|
-
// The widened sandbox, named for the same reason the mode is: "the child
|
|
273
|
-
// could only see its own directory" is otherwise indistinguishable, in a
|
|
274
|
-
// transcript, from "the model chose not to look".
|
|
275
|
-
(record.addDir && record.addDir.length ? ` · addDir=[${record.addDir.join(', ')}]` : '') +
|
|
276
|
-
// The continuity half, named rather than left to be read off the argv:
|
|
277
|
-
// "resumed" and "new id" are the two things a turn can mean here, and a
|
|
278
|
-
// turn that silently did neither is the bug this line makes visible.
|
|
279
|
-
(record.resumeSessionId
|
|
280
|
-
? ` · resumed session ${record.resumeSessionId}`
|
|
281
|
-
: record.sessionId
|
|
282
|
-
? ` · new session ${record.sessionId}`
|
|
283
|
-
: ' · no session id (each turn is a new conversation)')
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
module.exports = { FLAGS, DEFAULT_OUTPUT_FORMAT, claudeArgv, addDirArgs, childRecordLine };
|
|
3
|
+
"use strict";const FLAGS=Object.freeze({headlessSkip:"--dangerously-skip-permissions",interactiveSkip:"--allow-dangerously-skip-permissions",permissionMode:"--permission-mode",allowedTools:"--allowedTools",disallowedTools:"--disallowedTools",print:"-p",outputFormat:"--output-format",model:"--model",sessionId:"--session-id",resume:"--resume",addDir:"--add-dir"});function addDirArgs(e){const s=[];for(const o of unique(e))s.push(`${FLAGS.addDir}=${o}`);return s}const UUID_RE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,DEFAULT_OUTPUT_FORMAT="stream-json";function unique(e){const s=new Set,o=[];for(const i of Array.isArray(e)?e:[]){const e=String(i).trim();e&&!s.has(e)&&(s.add(e),o.push(e))}return o}function claudeArgv(e={}){const s=e.posture;if(!s||"object"!=typeof s)throw new Error("claudeArgv requires a resolved posture record (one/src/permissions.js resolvePosture)");const o=s.childKind,i="interactive"!==o,{PERMISSION_MODES:r}=require("./permissions.js"),n=void 0!==e.permissionMode&&null!==e.permissionMode,d=n?String(e.permissionMode):null;if(n&&!r.includes(d))throw new Error(`--permission-mode ${JSON.stringify(d)} is not one of ${r.join("|")} — refusing to pass (or to silently drop) a mode the child does not accept.`);const t=s.rules||{},l=unique(t.allow),a=unique(t.deny),u=unique(t.ask),p=e.resumeSessionId?String(e.resumeSessionId).trim():"",c=e.sessionId?String(e.sessionId).trim():"",m=p||null,h=!m&&c?c:null;for(const[e,s]of[["resumeSessionId",m],["sessionId",h]])if(s&&!UUID_RE.test(s))throw new Error(`${e} ${JSON.stringify(s)} is not a UUID — refusing to pass it to --resume/--session-id, which the child rejects after the spawn (turning a continuity bug into an opaque failed turn).`);const f=[];i&&f.push(FLAGS.print,FLAGS.outputFormat,String(e.outputFormat||"stream-json")),e.model&&f.push(FLAGS.model,String(e.model));const g=addDirArgs(e.addDir);f.push(...g),l.length&&f.push(FLAGS.allowedTools,l.join(",")),a.length&&f.push(FLAGS.disallowedTools,a.join(",")),n&&f.push(FLAGS.permissionMode,d),s.child&&s.child.flag&&f.push(s.child.flag),m?f.push(FLAGS.resume,m):h&&f.push(FLAGS.sessionId,h),Array.isArray(e.extra)&&f.push(...e.extra.map(String)),void 0!==e.prompt&&null!==e.prompt&&f.push(String(e.prompt));const S=Object.freeze({kind:o,permissionMode:d,permissionModePassed:n,skip:Boolean(s.child&&s.child.skip),skipFlag:s.child&&s.child.flag||null,allowedTools:Object.freeze(l),disallowedTools:Object.freeze(a),unmappedAsk:Object.freeze(u),addDir:Object.freeze(g.map((e=>e.slice(FLAGS.addDir.length+1)))),resumeSessionId:m,sessionId:h,argv:Object.freeze(f.slice())});return{argv:S.argv,record:S}}function childRecordLine(e){if(!e||"object"!=typeof e)return null;const s=e.permissionModePassed?`${FLAGS.permissionMode}=${e.permissionMode}`:"no --permission-mode (none was set)";return`aegis: claude child [${e.kind}] ${e.skipFlag||"no permission flag"} · ${s} · allowedTools=[${e.allowedTools.join(", ")}] disallowedTools=[${e.disallowedTools.join(", ")}]`+(e.unmappedAsk.length?` (ask rules recorded, unmapped: ${e.unmappedAsk.join(", ")})`:"")+(e.addDir&&e.addDir.length?` · addDir=[${e.addDir.join(", ")}]`:"")+(e.resumeSessionId?` · resumed session ${e.resumeSessionId}`:e.sessionId?` · new session ${e.sessionId}`:" · no session id (each turn is a new conversation)")}module.exports={FLAGS:FLAGS,DEFAULT_OUTPUT_FORMAT:"stream-json",claudeArgv:claudeArgv,addDirArgs:addDirArgs,childRecordLine:childRecordLine};
|
package/src/dispatch.js
CHANGED
|
@@ -1,271 +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
|
-
* WHO runs — the AEGISONE dispatch rule, as a pure function.
|
|
10
|
-
*
|
|
11
|
-
* One binary, two faces, and a rule a user can hold in one sentence:
|
|
12
|
-
*
|
|
13
|
-
* **the window opens only when there is nothing else to do.**
|
|
14
|
-
*
|
|
15
|
-
* ## Why this is a pure function and not a branch inside bin/aegis.js
|
|
16
|
-
*
|
|
17
|
-
* The window branch has to be testable on machines that must never open a
|
|
18
|
-
* window — CI, a container, a server — and this host cannot be relied on to be
|
|
19
|
-
* one of them: `DISPLAY=:0` is set here and Electron does resolve, so a live
|
|
20
|
-
* branch written on this box would open a real window during its own test run.
|
|
21
|
-
* (The earlier wording of this paragraph claimed this development host is
|
|
22
|
-
* headless; a live run disproved that, which is precisely the failure mode the
|
|
23
|
-
* seam exists to prevent.) So nothing in this file reads `process.*`, at module
|
|
24
|
-
* scope or anywhere else. Every fact arrives as an input (`argv`, `env`,
|
|
25
|
-
* `platform`, `tty`, `hasDisplay`, `electronResolvable`, `invokedAs`) and every
|
|
26
|
-
* branch is exercisable by injection. That is the Phase 30.1 seam rule, and it
|
|
27
|
-
* is the only reason the window face can be asserted without being opened.
|
|
28
|
-
*
|
|
29
|
-
* ## The rule, in order
|
|
30
|
-
*
|
|
31
|
-
* | Invocation | Face | Reason |
|
|
32
|
-
* |-----------------------------------------|-----------|---------------------------------|
|
|
33
|
-
* | `aegiscode …` | TUI | compatibility bin, byte-for-byte|
|
|
34
|
-
* | `AEGISONE_FACE=cli\|gui` | forced | CI and tests |
|
|
35
|
-
* | `aegis --gui` | GUI/error | explicit; error if impossible |
|
|
36
|
-
* | `aegis --tui` | TUI | explicit |
|
|
37
|
-
* | `aegis desktop` | GUI/error | spelling for muscle memory |
|
|
38
|
-
* | `aegis code` | TUI | spelling for muscle memory |
|
|
39
|
-
* | `aegis <verb> …` / `aegis "prompt"` | TUI | a verb or a prompt is terminal |
|
|
40
|
-
* | `aegis -p …` / piped stdin | TUI | scripted calls never spawn a window |
|
|
41
|
-
* | `aegis` bare + display + electron + tty | GUI | the one case the window is what was asked for |
|
|
42
|
-
* | `aegis` bare, anything missing | TUI + one stderr line saying why | never silently do nothing |
|
|
43
|
-
*
|
|
44
|
-
* Two asymmetries in that table are deliberate and load-bearing:
|
|
45
|
-
*
|
|
46
|
-
* 1. **Implicit GUI requires a terminal; explicit GUI does not.** Bare `aegis`
|
|
47
|
-
* is only allowed to open a window when a human is plausibly there (both
|
|
48
|
-
* stdio ends are TTYs), so no CI or sealed pipe can ever take that branch.
|
|
49
|
-
* But `aegis desktop` / `AEGISONE_FACE=gui` are things a `.desktop` launcher
|
|
50
|
-
* or a test does on purpose, with no TTY anywhere; demanding a terminal there
|
|
51
|
-
* would break the only legitimate headless-GUI caller.
|
|
52
|
-
*
|
|
53
|
-
* 2. **`requested` GUI that cannot be delivered is an error, not a downgrade.**
|
|
54
|
-
* exit 2, naming `--tui`. Someone who types `--gui` and silently gets a
|
|
55
|
-
* terminal has been told nothing true about their machine.
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
const FACE = Object.freeze({ TUI: 'tui', GUI: 'gui' });
|
|
59
|
-
|
|
60
|
-
/** Forced-face env var. Documented in D3; used by CI and by the tests below. */
|
|
61
|
-
const FACE_ENV = 'AEGISONE_FACE';
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Verbs that belong to the terminal face. `aegis login` must work, and it must
|
|
65
|
-
* not open a window to do it.
|
|
66
|
-
*
|
|
67
|
-
* Drift here is cheap on purpose: anything not in this set still lands on the
|
|
68
|
-
* TUI, because a positional argument that is not the `desktop` spelling always
|
|
69
|
-
* does (a prompt is not a window request). So a missing verb costs a worse
|
|
70
|
-
* *reason string*, never a wrong face — which is why this list is allowed to be
|
|
71
|
-
* a plain heuristic instead of a shared registry with the CLI.
|
|
72
|
-
*/
|
|
73
|
-
const TUI_VERBS = new Set([
|
|
74
|
-
'login',
|
|
75
|
-
'connect',
|
|
76
|
-
'logout',
|
|
77
|
-
'key',
|
|
78
|
-
'mcp',
|
|
79
|
-
'fingerprint',
|
|
80
|
-
'gate',
|
|
81
|
-
'autonomous',
|
|
82
|
-
'permissions',
|
|
83
|
-
'doctor',
|
|
84
|
-
'update',
|
|
85
|
-
'models',
|
|
86
|
-
'config',
|
|
87
|
-
'init',
|
|
88
|
-
'signup',
|
|
89
|
-
'help',
|
|
90
|
-
'version',
|
|
91
|
-
'status',
|
|
92
|
-
'resume',
|
|
93
|
-
]);
|
|
94
|
-
|
|
95
|
-
/** Flags that mean "this call is a script", per cli/bin/aegiscode.js. */
|
|
96
|
-
const SCRIPT_FLAGS = new Set(['-p', '--print', '--json']);
|
|
97
|
-
|
|
98
|
-
/** Flags that force a face. They are stripped before argv is forwarded. */
|
|
99
|
-
const FORCE_GUI_FLAGS = ['--gui'];
|
|
100
|
-
const FORCE_TUI_FLAGS = ['--tui'];
|
|
101
|
-
|
|
102
|
-
/** The two spellings a user types for muscle memory. */
|
|
103
|
-
const SPELLING_GUI = 'desktop';
|
|
104
|
-
const SPELLING_TUI = 'code';
|
|
105
|
-
|
|
106
|
-
function flagIndex(argv, flags) {
|
|
107
|
-
for (let i = 0; i < argv.length; i++) if (flags.includes(argv[i])) return i;
|
|
108
|
-
return -1;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function without(argv, flags) {
|
|
112
|
-
return argv.filter((a) => !flags.includes(a));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function has(argv, flags) {
|
|
116
|
-
return argv.some((a) => flags.includes(a));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Why the window cannot open, in the user's terms, or [] if it can. */
|
|
120
|
-
function guiBlockers(hasDisplay, electronResolvable) {
|
|
121
|
-
const missing = [];
|
|
122
|
-
if (!hasDisplay) missing.push('no display (DISPLAY / WAYLAND_DISPLAY are unset)');
|
|
123
|
-
if (!electronResolvable) missing.push('Electron is not installed beside this package');
|
|
124
|
-
return missing;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Decide which face runs.
|
|
129
|
-
*
|
|
130
|
-
* @param {object} input
|
|
131
|
-
* @param {string[]} [input.argv] arguments after the program name
|
|
132
|
-
* @param {object} [input.env] environment (read, never mutated)
|
|
133
|
-
* @param {string} [input.platform] process.platform
|
|
134
|
-
* @param {object} [input.tty] { stdin?: boolean, stdout?: boolean }; undefined = unknown
|
|
135
|
-
* @param {boolean} [input.hasDisplay] the injected display probe
|
|
136
|
-
* @param {boolean} [input.electronResolvable] the injected Electron probe
|
|
137
|
-
* @param {string} [input.invokedAs] basename the process was launched as
|
|
138
|
-
* @returns {{face: 'tui'|'gui'|null, kind: string, reason: string,
|
|
139
|
-
* args: string[], notice: string|null, code?: number,
|
|
140
|
-
* error?: string, hint?: string}}
|
|
141
|
-
*/
|
|
142
|
-
function decide(input) {
|
|
143
|
-
const src = input || {};
|
|
144
|
-
const argv = Array.isArray(src.argv) ? src.argv.map(String) : [];
|
|
145
|
-
const env = src.env || {};
|
|
146
|
-
const tty = src.tty || {};
|
|
147
|
-
const hasDisplay = Boolean(src.hasDisplay);
|
|
148
|
-
const electronResolvable = Boolean(src.electronResolvable);
|
|
149
|
-
const invokedAs = String(src.invokedAs || 'aegis').replace(/\.js$/, '');
|
|
150
|
-
|
|
151
|
-
const blockers = guiBlockers(hasDisplay, electronResolvable);
|
|
152
|
-
const guiCapable = blockers.length === 0;
|
|
153
|
-
|
|
154
|
-
const gui = (kind, reason, args) => ({
|
|
155
|
-
face: FACE.GUI,
|
|
156
|
-
kind,
|
|
157
|
-
reason,
|
|
158
|
-
args,
|
|
159
|
-
notice: null,
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const tui = (kind, reason, args, notice) => ({
|
|
163
|
-
face: FACE.TUI,
|
|
164
|
-
kind,
|
|
165
|
-
reason,
|
|
166
|
-
args,
|
|
167
|
-
notice: notice || null,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const refuseGui = (what) => ({
|
|
171
|
-
face: null,
|
|
172
|
-
kind: 'error',
|
|
173
|
-
code: 2,
|
|
174
|
-
reason: `${what} cannot open the window`,
|
|
175
|
-
error: `${what}: cannot open the window — ${blockers.join(', ')}.`,
|
|
176
|
-
hint: 'Use --tui for the terminal face.',
|
|
177
|
-
args: [],
|
|
178
|
-
notice: null,
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// ── 0. The compatibility bin ──────────────────────────────────────────────
|
|
182
|
-
// `aegiscode` must behave byte-for-byte as it does today: terminal, always,
|
|
183
|
-
// and argv forwarded untouched (today's parser has never heard of --gui, and
|
|
184
|
-
// silently eating a flag the user typed would be its own small lie).
|
|
185
|
-
if (invokedAs === 'aegiscode') {
|
|
186
|
-
return tui('compat', 'aegiscode is the compatibility bin', argv);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ── 1. Forced face (CI, tests, a user who means it) ───────────────────────
|
|
190
|
-
const forced = String(env[FACE_ENV] == null ? '' : env[FACE_ENV])
|
|
191
|
-
.trim()
|
|
192
|
-
.toLowerCase();
|
|
193
|
-
if (forced) {
|
|
194
|
-
if (forced === FACE.GUI) {
|
|
195
|
-
return guiCapable ? gui('forced', `${FACE_ENV}=gui`, argv) : refuseGui(`${FACE_ENV}=gui`);
|
|
196
|
-
}
|
|
197
|
-
if (forced === 'cli' || forced === FACE.TUI) {
|
|
198
|
-
return tui('forced', `${FACE_ENV}=${forced}`, argv);
|
|
199
|
-
}
|
|
200
|
-
// Fail loud: a typo'd force must not quietly pick a face for you.
|
|
201
|
-
return {
|
|
202
|
-
face: null,
|
|
203
|
-
kind: 'error',
|
|
204
|
-
code: 2,
|
|
205
|
-
reason: `${FACE_ENV}=${forced} is not a face`,
|
|
206
|
-
error: `${FACE_ENV}=${forced} is not a face. Set cli or gui.`,
|
|
207
|
-
hint: 'Unset it to let aegis decide from the arguments.',
|
|
208
|
-
args: [],
|
|
209
|
-
notice: null,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// ── 2. Explicit flags win over everything below them ──────────────────────
|
|
214
|
-
if (has(argv, FORCE_GUI_FLAGS)) {
|
|
215
|
-
const args = without(argv, FORCE_GUI_FLAGS);
|
|
216
|
-
return guiCapable ? gui('explicit', '--gui was passed', args) : refuseGui('--gui');
|
|
217
|
-
}
|
|
218
|
-
if (has(argv, FORCE_TUI_FLAGS)) {
|
|
219
|
-
return tui('explicit', '--tui was passed', without(argv, FORCE_TUI_FLAGS));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const positionals = argv.filter((a) => !a.startsWith('-'));
|
|
223
|
-
const first = positionals.length ? positionals[0] : null;
|
|
224
|
-
|
|
225
|
-
// ── 3. The two spellings ─────────────────────────────────────────────────
|
|
226
|
-
if (first === SPELLING_GUI) {
|
|
227
|
-
const args = argv.filter((a) => a !== SPELLING_GUI);
|
|
228
|
-
return guiCapable ? gui('spelling', 'aegis desktop', args) : refuseGui('aegis desktop');
|
|
229
|
-
}
|
|
230
|
-
if (first === SPELLING_TUI) {
|
|
231
|
-
return tui('spelling', 'aegis code', argv.filter((a) => a !== SPELLING_TUI));
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// ── 4. Scripted calls, checked before the positional branch ──────────────
|
|
235
|
-
// Order matters here and a test caught it: `aegis -p "hi"` has a positional
|
|
236
|
-
// (`hi`) as well as a script flag, so a positional-first rule described it as
|
|
237
|
-
// "a prompt" — the right face for the wrong reason, which is how a reason
|
|
238
|
-
// string stops being worth printing. A script flag is the stronger signal, so
|
|
239
|
-
// it is read first.
|
|
240
|
-
const scriptFlag = argv.find((a) => SCRIPT_FLAGS.has(a));
|
|
241
|
-
if (scriptFlag) {
|
|
242
|
-
return tui('script', `${scriptFlag} means this call is a script`, argv);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ── 5. Anything else with arguments is terminal work ─────────────────────
|
|
246
|
-
// A verb, a one-shot prompt, or session flags: none of them is a request for
|
|
247
|
-
// a window, and all of them need a terminal to be useful.
|
|
248
|
-
if (first) {
|
|
249
|
-
const why = TUI_VERBS.has(first)
|
|
250
|
-
? `'${first}' is a terminal verb`
|
|
251
|
-
: `'${first}' is a prompt, not a window request`;
|
|
252
|
-
return tui('argument', why, argv);
|
|
253
|
-
}
|
|
254
|
-
if (argv.length) {
|
|
255
|
-
return tui('flags', 'options were passed; the window takes none', argv);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// ── 6. Bare `aegis` — the only place a window is ever opened unasked ──────
|
|
259
|
-
// Scripted stdio is checked before the display probe so that the reason line
|
|
260
|
-
// names the thing that actually happened (a pipe), not the thing that merely
|
|
261
|
-
// would also have stopped it.
|
|
262
|
-
if (tty.stdin === false || tty.stdout === false) {
|
|
263
|
-
return tui('default', 'stdio is not a terminal', [], 'stdio is not a terminal');
|
|
264
|
-
}
|
|
265
|
-
if (blockers.length) {
|
|
266
|
-
return tui('default', blockers[0], [], blockers[0]);
|
|
267
|
-
}
|
|
268
|
-
return gui('default', 'nothing else was asked for', []);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
module.exports = { decide, FACE, FACE_ENV, TUI_VERBS };
|
|
3
|
+
"use strict";const FACE=Object.freeze({TUI:"tui",GUI:"gui"}),FACE_ENV="AEGISONE_FACE",TUI_VERBS=new Set(["login","connect","logout","key","mcp","fingerprint","gate","autonomous","permissions","doctor","update","models","config","init","signup","help","version","status","resume"]),SCRIPT_FLAGS=new Set(["-p","--print","--json"]),FORCE_GUI_FLAGS=["--gui"],FORCE_TUI_FLAGS=["--tui"],SPELLING_GUI="desktop",SPELLING_TUI="code";function flagIndex(e,t){for(let n=0;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function without(e,t){return e.filter((e=>!t.includes(e)))}function has(e,t){return e.some((e=>t.includes(e)))}function guiBlockers(e,t){const n=[];return e||n.push("no display (DISPLAY / WAYLAND_DISPLAY are unset)"),t||n.push("Electron is not installed beside this package"),n}function decide(e){const t=e||{},n=Array.isArray(t.argv)?t.argv.map(String):[],i=t.env||{},s=t.tty||{},o=Boolean(t.hasDisplay),r=Boolean(t.electronResolvable),a=String(t.invokedAs||"aegis").replace(/\.js$/,""),l=guiBlockers(o,r),c=0===l.length,u=(e,t,n)=>({face:FACE.GUI,kind:e,reason:t,args:n,notice:null}),d=(e,t,n,i)=>({face:FACE.TUI,kind:e,reason:t,args:n,notice:i||null}),g=e=>({face:null,kind:"error",code:2,reason:`${e} cannot open the window`,error:`${e}: cannot open the window — ${l.join(", ")}.`,hint:"Use --tui for the terminal face.",args:[],notice:null});if("aegiscode"===a)return d("compat","aegiscode is the compatibility bin",n);const E=String(null==i[FACE_ENV]?"":i[FACE_ENV]).trim().toLowerCase();if(E)return E===FACE.GUI?c?u("forced",`${FACE_ENV}=gui`,n):g(`${FACE_ENV}=gui`):"cli"===E||E===FACE.TUI?d("forced",`${FACE_ENV}=${E}`,n):{face:null,kind:"error",code:2,reason:`${FACE_ENV}=${E} is not a face`,error:`${FACE_ENV}=${E} is not a face. Set cli or gui.`,hint:"Unset it to let aegis decide from the arguments.",args:[],notice:null};if(has(n,FORCE_GUI_FLAGS)){const e=without(n,FORCE_GUI_FLAGS);return c?u("explicit","--gui was passed",e):g("--gui")}if(has(n,FORCE_TUI_FLAGS))return d("explicit","--tui was passed",without(n,FORCE_TUI_FLAGS));const f=n.filter((e=>!e.startsWith("-"))),p=f.length?f[0]:null;if("desktop"===p){const e=n.filter((e=>"desktop"!==e));return c?u("spelling","aegis desktop",e):g("aegis desktop")}if("code"===p)return d("spelling","aegis code",n.filter((e=>"code"!==e)));const A=n.find((e=>SCRIPT_FLAGS.has(e)));return A?d("script",`${A} means this call is a script`,n):p?d("argument",TUI_VERBS.has(p)?`'${p}' is a terminal verb`:`'${p}' is a prompt, not a window request`,n):n.length?d("flags","options were passed; the window takes none",n):!1===s.stdin||!1===s.stdout?d("default","stdio is not a terminal",[],"stdio is not a terminal"):l.length?d("default",l[0],[],l[0]):u("default","nothing else was asked for",[])}module.exports={decide:decide,FACE:FACE,FACE_ENV:FACE_ENV,TUI_VERBS:TUI_VERBS};
|