aegisone 1.0.22 → 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 -3020
  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 -4003
  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 -2179
  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 -110
  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 -133
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  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 -3301
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  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 -227
  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 -3301
  160. package/vendor/desktop/lib/local/entitlement.js +1 -660
  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 -4529
  179. package/vendor/desktop/package.json +3 -2
  180. package/vendor/desktop/preload.js +1 -636
  181. package/vendor/desktop/renderer/app.js +1 -6660
  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 -736
  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 -2179
  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 -110
  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 -133
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -373
  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
@@ -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
- // 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
- * 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};