aegisone 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -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 -7
  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 -5
  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,292 +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
- // The silent gate, loaded directly rather than trusted to have been asked by
9
- // somebody up the call stack. FAIL CLOSED if it cannot be loaded at all: a tree
10
- // with no `src/limits.js` is a tree someone edited to remove the question, and
11
- // "the checker is missing" must read as "not the published build" for the same
12
- // reason `src/provenance.js` treats a missing manifest as a failure and not a
13
- // pass. Note what this deliberately does NOT do: it never throws, and it never
14
- // stops `resolveSkip` from returning a decision — it only ever takes the skip
15
- // away, so the worst a broken gate can cause is a confirmation prompt.
16
- const limits = (() => {
17
- try {
18
- return require('./limits.js');
19
- } catch {
20
- return { armed: () => true, refuse: () => 1, check: () => ({ tripped: true, code: 'p2', units: 0 }) };
21
- }
22
- })();
23
-
24
- /**
25
- * Real enforcement for the /permissions rules (src/config.js) in the
26
- * direct-provider tool loop. The `claude` CLI path already has its own real
27
- * approval UX from the real binary, so this only applies to
28
- * Bash/Read/Write/Edit/Glob/Grep run by a provider model.
29
- *
30
- * Scope decision: the multi-directory-change Bash heuristic,
31
- * explicit /permissions allow|deny|ask rules, and `defaultMode: 'ask'` when
32
- * the permissions file *explicitly* writes it (rules.explicitAsk) are
33
- * enforced here. The file-free default ('ask' in DEFAULT_PERMISSIONS) is
34
- * NOT consulted — honoring the implicit default would prompt on every tool
35
- * call out of the box and make the agentic loop unusable by default.
36
- * /confirm and /yolo still toggle defaultMode for the explicit case.
37
- *
38
- * Not tools.js's Glob-tool globToRegex: that one is filesystem-glob (`*`
39
- * stops at `/`, matching one path segment) because it walks a directory
40
- * tree. Rule subjects here are just as often a Bash command string, where
41
- * `/` is ordinary text ("rm -rf /tmp/x") — a `Bash(npm run *)` rule (see
42
- * DEFAULT_PERMISSIONS's own example) needs `*` to match the rest of the
43
- * line, slashes included. So `*` and `?` here are plain "match anything"
44
- * wildcards, not path-segment-bounded ones; reimplemented rather than
45
- * imported so this module has no import-cycle with tools.js (executeTool's
46
- * home, which calls into this one).
47
- *
48
- * Ported from the upstream engine reference (ESM → CommonJS).
49
- */
50
-
51
- const RULE_RE = /^(\w+)(?:\((.*)\))?$/;
52
-
53
- /**
54
- * Tool-name aliases. The shipped engine (desktop/lib/local/tools.js) names its
55
- * tools readFile/writeFile/editFile/listDir/glob/grep/exec/task, while this
56
- * module was ported from the reference and keyed on that CLI's names —
57
- * Read/Write/Edit/Glob/Grep/Bash/Task. Those reference names are also what
58
- * users write into /permissions, so both spellings must fold onto one
59
- * capability. Keying on the reference's spelling alone meant subjectFor()
60
- * returned '' for every tool the engine actually calls: `exec(git *)` never
61
- * matched its subject, `Read(*.env)` never matched a readFile, and the
62
- * multi-directory rail never fired — a permission system blind to the very
63
- * tools it was meant to govern.
64
- */
65
- const TOOL_ALIAS = {
66
- exec: 'shell', Bash: 'shell',
67
- readFile: 'read', Read: 'read',
68
- writeFile: 'write', Write: 'write',
69
- editFile: 'edit', Edit: 'edit',
70
- listDir: 'list', LS: 'list',
71
- glob: 'glob', Glob: 'glob',
72
- grep: 'grep', Grep: 'grep',
73
- task: 'task', Task: 'task',
74
- };
75
-
76
- /** Fold either registry's name for a tool onto the capability it names. */
77
- function canonTool(name) {
78
- const key = String(name == null ? '' : name);
79
- return TOOL_ALIAS[key] || key;
80
- }
81
-
82
- /** True for the engine's `exec` and the reference's `Bash` alike. */
83
- function isShellTool(toolName) {
84
- return canonTool(toolName) === 'shell';
85
- }
86
-
87
- function globToRegex(pattern) {
88
- let re = '^';
89
- for (const c of pattern) {
90
- if (c === '*') re += '.*';
91
- else if (c === '?') re += '.';
92
- else if (/[.+^${}()|[\]\\]/.test(c)) re += `\\${c}`;
93
- else re += c;
94
- }
95
- return new RegExp(re + "$");
96
- }
97
-
98
- /** The subject a rule's pattern matches against, per tool. */
99
- function subjectFor(toolName, args = {}) {
100
- switch (canonTool(toolName)) {
101
- case 'shell': return String(args.command || '');
102
- case 'read': case 'write': case 'edit': return String(args.file_path || '');
103
- case 'glob': case 'grep': return String(args.pattern || '');
104
- case 'list': return String(args.path || '');
105
- default: return '';
106
- }
107
- }
108
-
109
- function matchRule(rule, toolName, subject) {
110
- const m = RULE_RE.exec(String(rule || '').trim());
111
- if (!m) return false;
112
- const [, tool, pattern] = m;
113
- // A rule spelled with the reference's name governs the engine's tool and
114
- // vice versa: `Bash(git *)` and `exec(git *)` are one rule, not two.
115
- if (canonTool(tool) !== canonTool(toolName)) return false;
116
- if (pattern === undefined) return true; // bare "Bash"/"exec" matches every call
117
- try { return globToRegex(pattern).test(subject); } catch { return false; }
118
- }
119
-
120
- const matchesAny = (list, toolName, subject) =>
121
- Array.isArray(list) && list.some((r) => matchRule(r, toolName, subject));
122
-
123
- /**
124
- * A Bash command that changes directory more than once needs a second look:
125
- * each `&&`/`;`/`|`/newline-separated segment starting with `cd` counts.
126
- * Mirrors the captured Claude Code 2.1.228 heuristic ("Multiple directory
127
- * changes in one command require approval for clarity") — a hardcoded UX
128
- * safety rail, not a configurable rule.
129
- */
130
- function isMultiDirCommand(command) {
131
- const segments = String(command || '').split(/&&|\|\||;|\n/).map((s) => s.trim());
132
- const cdCount = segments.filter((s) => /^cd(\s|$)/.test(s)).length;
133
- return cdCount > 1;
134
- }
135
-
136
- /**
137
- * Evaluate a tool call against the persisted /permissions rules.
138
- * Returns 'allow' | 'deny' | 'ask'. Precedence: an explicit deny rule always
139
- * wins (a security floor). An explicit allow rule is the real "always
140
- * allow" escape hatch, so it's checked next and suppresses the multi-cd
141
- * heuristic below it — same as upstream, where an always-allow rule for
142
- * Bash stops it asking again. With no allow rule, the multi-cd heuristic
143
- * forces 'ask' on its own; then explicit ask rules. Anything left
144
- * unmatched falls through to rules.explicitAsk (an explicitly written
145
- * `defaultMode: 'ask'` prompts on the residual); otherwise 'allow' — see
146
- * the scope note above, the implicit defaultMode is intentionally not
147
- * consulted.
148
- */
149
- function evalPermission(toolName, args, rules = {}) {
150
- const subject = subjectFor(toolName, args);
151
- if (matchesAny(rules.deny, toolName, subject)) return 'deny';
152
- if (matchesAny(rules.allow, toolName, subject)) return 'allow';
153
- if (isShellTool(toolName) && isMultiDirCommand(args && args.command)) return 'ask';
154
- if (matchesAny(rules.ask, toolName, subject)) return 'ask';
155
- if (rules.explicitAsk && rules.defaultMode === 'ask') return 'ask';
156
- return 'allow';
157
- }
158
-
159
- // ── "Skip permissions", resolved ONCE (AEGISONE, D8 rules 3 and 5) ──────────
160
- //
161
- // One resolver, two callers: `one/src/permissions.js` (the product's posture,
162
- // which feeds a spawned Claude child's argv) and `cli/src/app.js` (this face's
163
- // own confirmation gate). It lives HERE, beside `evalPermission`, so the rule
164
- // engine and the skip resolver are one module rather than two spellings that
165
- // can drift — the same reason D8 keeps one rule language.
166
- //
167
- // The three sources, and why they are three:
168
- //
169
- // flag `--dangerously-skip-permissions`, typed by a human. Always
170
- // honored: it is the whole point of the flag, and rule 3 requires
171
- // a one-line report of what it skipped (the caller prints it).
172
- // productEnv `AEGISONE_SKIP_PERMISSIONS`, set by the `aegis` bin ONLY after
173
- // it resolved the posture for the child it is about to spawn —
174
- // i.e. the flag, already checked against rule 5. That indirection
175
- // is what lets the terminal face honor `aegis … --dangerously-
176
- // skip-permissions` without the face ever reading the *user's*
177
- // environment for a skip it was not asked for.
178
- // env `AEGIS_SKIP_PERMISSIONS`, the CI/queue spelling. It equals the
179
- // flag only when the process is NON-interactive: a stray `export`
180
- // in a shell profile must not be able to disarm a human's own
181
- // gate (rule 5). Interactive + unasked ⇒ warn and ignore.
182
- //
183
- // It never returns why something was skipped beyond naming its source: what a
184
- // skip DOES cover is rule 2's business, and rule 2's floors (the covenant
185
- // assert and the four level-independent approvals) are not reachable from here
186
- // at all.
187
- const SKIP = Object.freeze({
188
- flag: '--dangerously-skip-permissions',
189
- env: 'AEGIS_SKIP_PERMISSIONS',
190
- productEnv: 'AEGISONE_SKIP_PERMISSIONS',
191
- truthy: Object.freeze(['1', 'true', 'yes', 'on']),
192
- });
193
-
194
- const isTruthyEnv = (v) => v !== undefined && SKIP.truthy.includes(String(v).trim().toLowerCase());
195
-
196
- /**
197
- * The mark an interlock-failed build carries (`AEGIS_REDUCED_MODE`, set in
198
- * bin/aegiscode.js from src/limits.js). A build that is not the published one
199
- * does not get to disarm the confirmation gate — from the flag, from the
200
- * product env or from the CI env. That is the whole payoff of editing this
201
- * file, so it is the one thing this file will not do when it is not itself.
202
- *
203
- * Read from the caller's env AND from process.env, because the two callers
204
- * differ: `one/src/permissions.js` passes an env it assembled, and the mark is
205
- * set on the process. Deliberately not documented anywhere a manipulator would
206
- * read before deciding what to edit next.
207
- *
208
- * …and asked for directly, through `limits.armed()`, rather than only read off
209
- * the environment. Reading the mark alone made this file's refusal depend on
210
- * somebody else's call: delete the one line in `bin/aegiscode.js` that sets it
211
- * and `--dangerously-skip-permissions` starts working again on a build that is
212
- * not the published one. The question is now asked HERE, by the module that owns
213
- * the privilege, and the answer is memoised in src/limits.js — so the same edit
214
- * buys nothing, and a scrubbed `input.env` cannot spoof the answer either.
215
- */
216
- function reducedMode(input = {}) {
217
- const env = input.env || {};
218
- if (isTruthyEnv(env.AEGIS_REDUCED_MODE) || isTruthyEnv(process.env.AEGIS_REDUCED_MODE)) return true;
219
- return limits.armed();
220
- }
221
-
222
- /** Rule 5's warning, spelled once so both callers print the same sentence. */
223
- const SKIP_ENV_WARNING =
224
- `AEGIS_SKIP_PERMISSIONS is set but this session is interactive — ignoring it. ` +
225
- `Pass --dangerously-skip-permissions to skip the configurable gates on purpose; ` +
226
- `the ÆGIS covenant and the write|shell|network|offDevice approvals are never skipped.`;
227
-
228
- /**
229
- * @param {object} [input]
230
- * @param {boolean} [input.flag] the flag was explicitly passed
231
- * @param {object} [input.env] environment to read (never mutated)
232
- * @param {boolean} [input.interactive] both stdio ends are a terminal
233
- * @returns {{skip: boolean, source: 'flag'|'product'|'env'|'env-ignored'|'reduced'|'none',
234
- * flag: boolean, envSet: boolean, interactive: boolean,
235
- * warned: boolean, warning: string|null}}
236
- */
237
- function resolveSkip(input = {}) {
238
- const flag = input.flag === true;
239
- const env = input.env || {};
240
- const interactive = input.interactive === true;
241
- const envSet = isTruthyEnv(env[SKIP.env]);
242
- const productSet = isTruthyEnv(env[SKIP.productEnv]);
243
-
244
- // A build that failed the interlock never skips, whatever it was asked: the
245
- // flag and both env spellings are refused at the source, so the confirm gate
246
- // is the one thing a modified build cannot switch off. Reported as its own
247
- // source so a caller does not print "the user asked for this".
248
- if (reducedMode(input)) {
249
- return { skip: false, source: 'reduced', flag, envSet, interactive, warned: false, warning: null };
250
- }
251
-
252
- // src: flag → product → env(non-interactive). No `catch`-all default that
253
- // could skip: every other path returns skip: false.
254
- if (flag || productSet) {
255
- return {
256
- skip: true,
257
- source: flag ? 'flag' : 'product',
258
- flag,
259
- envSet,
260
- interactive,
261
- warned: false,
262
- warning: null,
263
- };
264
- }
265
- if (envSet && !interactive) {
266
- return { skip: true, source: 'env', flag, envSet, interactive, warned: false, warning: null };
267
- }
268
- if (envSet && interactive) {
269
- return {
270
- skip: false,
271
- source: 'env-ignored',
272
- flag,
273
- envSet,
274
- interactive,
275
- warned: true,
276
- warning: SKIP_ENV_WARNING,
277
- };
278
- }
279
- return { skip: false, source: 'none', flag, envSet: false, interactive, warned: false, warning: null };
280
- }
281
-
282
- module.exports = {
283
- canonTool,
284
- isShellTool,
285
- subjectFor,
286
- matchRule,
287
- isMultiDirCommand,
288
- evalPermission,
289
- SKIP,
290
- SKIP_ENV_WARNING,
291
- resolveSkip,
292
- };
3
+ "use strict";const limits=(()=>{try{return require("./limits.js")}catch{return{armed:()=>!0,refuse:()=>1,check:()=>({tripped:!0,code:"p2",units:0})}}})(),RULE_RE=/^(\w+)(?:\((.*)\))?$/,TOOL_ALIAS={exec:"shell",Bash:"shell",readFile:"read",Read:"read",writeFile:"write",Write:"write",editFile:"edit",Edit:"edit",listDir:"list",LS:"list",glob:"glob",Glob:"glob",grep:"grep",Grep:"grep",task:"task",Task:"task"};function canonTool(e){const t=String(null==e?"":e);return TOOL_ALIAS[t]||t}function isShellTool(e){return"shell"===canonTool(e)}function globToRegex(e){let t="^";for(const n of e)"*"===n?t+=".*":"?"===n?t+=".":/[.+^${}()|[\]\\]/.test(n)?t+=`\\${n}`:t+=n;return new RegExp(t+"$")}function subjectFor(e,t={}){switch(canonTool(e)){case"shell":return String(t.command||"");case"read":case"write":case"edit":return String(t.file_path||"");case"glob":case"grep":return String(t.pattern||"");case"list":return String(t.path||"");default:return""}}function matchRule(e,t,n){const r=RULE_RE.exec(String(e||"").trim());if(!r)return!1;const[,i,s]=r;if(canonTool(i)!==canonTool(t))return!1;if(void 0===s)return!0;try{return globToRegex(s).test(n)}catch{return!1}}const matchesAny=(e,t,n)=>Array.isArray(e)&&e.some((e=>matchRule(e,t,n)));function isMultiDirCommand(e){return String(e||"").split(/&&|\|\||;|\n/).map((e=>e.trim())).filter((e=>/^cd(\s|$)/.test(e))).length>1}function evalPermission(e,t,n={}){const r=subjectFor(e,t);return matchesAny(n.deny,e,r)?"deny":matchesAny(n.allow,e,r)?"allow":isShellTool(e)&&isMultiDirCommand(t&&t.command)||matchesAny(n.ask,e,r)||n.explicitAsk&&"ask"===n.defaultMode?"ask":"allow"}const SKIP=Object.freeze({flag:"--dangerously-skip-permissions",env:"AEGIS_SKIP_PERMISSIONS",productEnv:"AEGISONE_SKIP_PERMISSIONS",truthy:Object.freeze(["1","true","yes","on"])}),isTruthyEnv=e=>void 0!==e&&SKIP.truthy.includes(String(e).trim().toLowerCase());function reducedMode(e={}){const t=e.env||{};return!(!isTruthyEnv(t.AEGIS_REDUCED_MODE)&&!isTruthyEnv(process.env.AEGIS_REDUCED_MODE))||limits.armed()}const SKIP_ENV_WARNING="AEGIS_SKIP_PERMISSIONS is set but this session is interactive — ignoring it. Pass --dangerously-skip-permissions to skip the configurable gates on purpose; the ÆGIS covenant and the write|shell|network|offDevice approvals are never skipped.";function resolveSkip(e={}){const t=!0===e.flag,n=e.env||{},r=!0===e.interactive,i=isTruthyEnv(n[SKIP.env]),s=isTruthyEnv(n[SKIP.productEnv]);return reducedMode(e)?{skip:!1,source:"reduced",flag:t,envSet:i,interactive:r,warned:!1,warning:null}:t||s?{skip:!0,source:t?"flag":"product",flag:t,envSet:i,interactive:r,warned:!1,warning:null}:i&&!r?{skip:!0,source:"env",flag:t,envSet:i,interactive:r,warned:!1,warning:null}:i&&r?{skip:!1,source:"env-ignored",flag:t,envSet:i,interactive:r,warned:!0,warning:SKIP_ENV_WARNING}:{skip:!1,source:"none",flag:t,envSet:!1,interactive:r,warned:!1,warning:null}}module.exports={canonTool:canonTool,isShellTool:isShellTool,subjectFor:subjectFor,matchRule:matchRule,isMultiDirCommand:isMultiDirCommand,evalPermission:evalPermission,SKIP:SKIP,SKIP_ENV_WARNING:SKIP_ENV_WARNING,resolveSkip:resolveSkip};
@@ -1,228 +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
- * /ping — the terminal's "reply ready" alert.
10
- *
11
- * WHAT IT IS, AND WHY HERE. aegis-desktop already tells the user a turn landed
12
- * when they are looking somewhere else: `notifyReplyIfUnfocused()` in
13
- * desktop/main.js raises a native Notification from the one place every chat
14
- * call resolves, and only when the window is minimized, hidden or unfocused — a
15
- * foregrounded chat needs no OS-level nudge. The terminal has no `isFocused()`,
16
- * so the two things that function reads have to be re-derived:
17
- *
18
- * * "the window is not in front" — approximate it with TIME. A turn that took
19
- * less than `pingMinSeconds` ran while the user was still watching the
20
- * spinner; one that took longer is a turn they plausibly walked away from.
21
- * That is the only honest proxy a TUI has, and it is why the threshold
22
- * exists at all rather than pinging on every reply.
23
- * * "the window can show a notification" — check `process.stdout.isTTY`
24
- * instead of `Notification.isSupported()`. A `-p` headless run, a piped
25
- * transcript or an autonomous queue worker has no user to notify, and
26
- * writing escape sequences into a file is not a notice.
27
- *
28
- * WHAT IT SENDS. Terminal notification escapes, the only channel a CLI has:
29
- * OSC 9 (iTerm2, WezTerm, Windows Terminal, conhost) and OSC 777
30
- * (`notify;title;body` — VTE/GNOME Terminal, kitty, urxvt), each BEL-terminated,
31
- * plus optionally the plain BEL bell for terminals that implement neither
32
- * (macOS Terminal.app) — what the user hears is then whatever their terminal's
33
- * bell setting says. Modes are one word on purpose: `off`, `bell`, `notify`,
34
- * `both`.
35
- *
36
- * Ported verbatim in behaviour from the upstream engine's `src/ping.js`, ESM →
37
- * CommonJS, dependency-free: no TTY, no config file, no app.js import, so the
38
- * decision and the byte sequence are both unit-testable. It keeps all four of
39
- * the properties that module is built around:
40
- *
41
- * 1. It cannot break the host. `writePing()` returns a boolean and never
42
- * throws, whatever the stream does (a closed stdout, an EPIPE, a stub with
43
- * no `write`). A notice that can take down a session is worse than none.
44
- * 2. It cannot corrupt the terminal. Both payloads are free text written
45
- * INSIDE an escape sequence: a BEL in the text would end the OSC early, an
46
- * ESC would start a new escape, a newline would break a WM's rendering.
47
- * `sanitizePingText()` strips every control byte before anything is
48
- * written — the same reasoning as `flattenTitle` at the OSC 0 edge in
49
- * this host's `title.js`.
50
- * 3. It cannot lie about what happened. The notice row is only pushed when a
51
- * sequence was actually written; `off` writes nothing and says nothing
52
- * rather than reporting a ping it did not send.
53
- * 4. It cannot nag. An aborted turn never pings — the user pressed Escape, so
54
- * they are demonstrably looking at the screen.
55
- */
56
-
57
- /** The one-word modes, in the order `/ping` lists them. */
58
- const PING_MODES = Object.freeze(['off', 'bell', 'notify', 'both']);
59
-
60
- /** Default mode. On, like the desktop's own notification — it is the whole
61
- * point of the feature, and the threshold below is what keeps it quiet. */
62
- const DEFAULT_PING_MODE = 'both';
63
-
64
- /** The desktop's rule is "unfocused", not "slow". 30s is where a terminal turn
65
- * stops reading as one the user is still watching, and it is the floor under
66
- * the noise: a two-second reply never pings. */
67
- const DEFAULT_PING_SECONDS = 30;
68
-
69
- /** One hour. Past this the duration is a story, not a threshold. */
70
- const MAX_PING_SECONDS = 3600;
71
-
72
- /** The title every notification carries, matching desktop/main.js's own. */
73
- const PING_TITLE = 'AEGIS Code';
74
-
75
- /** Longest payload the sanitizer will pass through. A title is a short line; a
76
- * notification daemon truncates anyway, so a cap here only bounds what this
77
- * module can be made to write. */
78
- const PING_TEXT_MAX = 120;
79
-
80
- const BEL = '\u0007';
81
- const ESC = '\u001b';
82
- const BODY = 'Reply ready';
83
-
84
- /**
85
- * One of PING_MODES, or the default. An unknown string is NOT an error here —
86
- * the config file is user-editable and a typo must not disable the feature
87
- * silently, so it reads as "unset" and takes the default. `/ping` refuses the
88
- * same strings out loud, which is where a typo is actually seen.
89
- */
90
- function normalizePingMode(value) {
91
- const v = String(value == null ? '' : value).trim().toLowerCase();
92
- return PING_MODES.includes(v) ? v : DEFAULT_PING_MODE;
93
- }
94
-
95
- /**
96
- * Seconds, clamped to [0, MAX_PING_SECONDS]. 0 is legal and means "ping every
97
- * turn, however short". Anything unparseable falls back to the default rather
98
- * than to 0, so a corrupt config cannot turn the notice into a per-turn nag.
99
- */
100
- function normalizePingSeconds(value) {
101
- // `Number('')` is 0 and `Number(' ')` is 0, so an ABSENT value would read as
102
- // "ping every turn" — the loudest setting from the weakest input. Unset is
103
- // separated from zero before anything is parsed.
104
- const raw = typeof value === 'number' ? value : String(value == null ? '' : value).trim();
105
- if (raw === '') return DEFAULT_PING_SECONDS;
106
- const n = typeof raw === 'number' ? raw : Number(raw);
107
- if (!Number.isFinite(n) || n < 0) return DEFAULT_PING_SECONDS;
108
- return Math.min(MAX_PING_SECONDS, Math.floor(n));
109
- }
110
-
111
- /** Strip every byte that could end or re-open the escape sequence, collapse to
112
- * one printable line, cap the length. */
113
- function sanitizePingText(text, max = PING_TEXT_MAX) {
114
- const flat = String(text == null ? '' : text)
115
- .replace(/[\u0000-\u001f\u007f]/g, ' ')
116
- .replace(/\s+/g, ' ')
117
- .trim();
118
- const limit = Number.isFinite(max) && max > 0 ? Math.floor(max) : PING_TEXT_MAX;
119
- return flat.length > limit ? `${flat.slice(0, Math.max(0, limit - 1))}…` : flat;
120
- }
121
-
122
- /**
123
- * The decision, in one place so it can be tested without a TTY:
124
- *
125
- * off → never. "Off is off" is the rule /yolo and /confirm follow.
126
- * aborted → never. Escape means the user was looking at the screen.
127
- * !isTTY → never. Headless/piped: there is no one to ping.
128
- * short turn → never, until the threshold.
129
- */
130
- function shouldPing({ mode, elapsedMs, minSeconds, isTTY, aborted } = {}) {
131
- if (normalizePingMode(mode) === 'off') return false;
132
- if (aborted) return false;
133
- if (!isTTY) return false;
134
- // `Number(null)` is 0 and 0 is a legal duration, so an ABSENT elapsed time
135
- // would read as "this turn just finished" and ping on a caller's bug. Only a
136
- // real number (or a non-empty numeric string) counts.
137
- const raw = typeof elapsedMs === 'number' ? elapsedMs : String(elapsedMs == null ? '' : elapsedMs).trim();
138
- if (raw === '') return false;
139
- const elapsed = Number(raw);
140
- if (!Number.isFinite(elapsed) || elapsed < 0) return false;
141
- return elapsed >= normalizePingSeconds(minSeconds) * 1000;
142
- }
143
-
144
- /**
145
- * The bytes to write. Empty string when the mode is off, so a caller cannot
146
- * accidentally send something "off" did not mean. Both payloads are sanitized
147
- * into locals first, so no branch can write an unsanitized string.
148
- */
149
- function buildPing({ mode = DEFAULT_PING_MODE, title = PING_TITLE, body = BODY } = {}) {
150
- const m = normalizePingMode(mode);
151
- if (m === 'off') return '';
152
- const t = sanitizePingText(title);
153
- const b = sanitizePingText(body);
154
- const parts = [];
155
- if (m === 'notify' || m === 'both') {
156
- // OSC 9: "notification with this body" — no title field, so it carries the
157
- // body only. OSC 777: the form that DOES take a title, and the one VTE and
158
- // kitty implement. Both are BEL-terminated; both are ignored harmlessly by
159
- // a terminal that knows neither.
160
- parts.push(`${ESC}]9;${b}${BEL}`);
161
- parts.push(`${ESC}]777;notify;${t};${b}${BEL}`);
162
- }
163
- if (m === 'bell' || m === 'both') parts.push(BEL);
164
- return parts.join('');
165
- }
166
-
167
- /**
168
- * Write it, or do not — never throws. Returns whether anything was written, and
169
- * the caller pushes its notice row only on `true` (property 3 above).
170
- */
171
- function writePing(stream, text) {
172
- if (!text) return false;
173
- if (!stream || typeof stream.write !== 'function') return false;
174
- try {
175
- stream.write(text);
176
- return true;
177
- } catch {
178
- return false;
179
- }
180
- }
181
-
182
- /** "45s" / "3m12s" / "1h02m" — the compact shape the turn's own timing row
183
- * uses. Seconds in, one short string out. */
184
- function formatPingDuration(seconds) {
185
- const s = Math.max(0, Math.floor(Number(seconds) || 0));
186
- if (s < 60) return `${s}s`;
187
- const m = Math.floor(s / 60);
188
- if (m < 60) return `${m}m${String(s % 60).padStart(2, '0')}s`;
189
- return `${Math.floor(m / 60)}h${String(m % 60).padStart(2, '0')}m`;
190
- }
191
-
192
- /** The transcript row: the duration, which channel fired, and the one switch a
193
- * user needs at that moment. */
194
- function pingNoticeText({ seconds, mode } = {}) {
195
- const m = normalizePingMode(mode);
196
- const how = m === 'bell' ? 'bell rung' : m === 'notify' ? 'notification sent' : 'bell rung, notification sent';
197
- return `[ping] reply ready after ${formatPingDuration(seconds)} — ${how}; /ping off silences this`;
198
- }
199
-
200
- /**
201
- * The whole act, in one call the session loop can make: decide, write, and
202
- * describe. Returns the notice text to push, or null when nothing was sent
203
- * (off, aborted, not a TTY, under the threshold, or a stream that refused).
204
- */
205
- function pingTurn({ stream, mode, minSeconds, elapsedMs, isTTY, aborted } = {}) {
206
- if (!shouldPing({ mode, minSeconds, elapsedMs, isTTY, aborted })) return null;
207
- const text = buildPing({ mode });
208
- if (!writePing(stream, text)) return null;
209
- return pingNoticeText({ seconds: Number(elapsedMs) / 1000, mode });
210
- }
211
-
212
- module.exports = {
213
- PING_MODES,
214
- DEFAULT_PING_MODE,
215
- DEFAULT_PING_SECONDS,
216
- MAX_PING_SECONDS,
217
- PING_TITLE,
218
- PING_TEXT_MAX,
219
- normalizePingMode,
220
- normalizePingSeconds,
221
- sanitizePingText,
222
- shouldPing,
223
- buildPing,
224
- writePing,
225
- formatPingDuration,
226
- pingNoticeText,
227
- pingTurn,
228
- };
3
+ "use strict";const PING_MODES=Object.freeze(["off","bell","notify","both"]),DEFAULT_PING_MODE="both",DEFAULT_PING_SECONDS=30,MAX_PING_SECONDS=3600,PING_TITLE="AEGIS Code",PING_TEXT_MAX=120,BEL="",ESC="",BODY="Reply ready";function normalizePingMode(n){const i=String(null==n?"":n).trim().toLowerCase();return PING_MODES.includes(i)?i:DEFAULT_PING_MODE}function normalizePingSeconds(n){const i="number"==typeof n?n:String(null==n?"":n).trim();if(""===i)return DEFAULT_PING_SECONDS;const e="number"==typeof i?i:Number(i);return!Number.isFinite(e)||e<0?DEFAULT_PING_SECONDS:Math.min(MAX_PING_SECONDS,Math.floor(e))}function sanitizePingText(n,i=PING_TEXT_MAX){const e=String(null==n?"":n).replace(/[\u0000-\u001f\u007f]/g," ").replace(/\s+/g," ").trim(),t=Number.isFinite(i)&&i>0?Math.floor(i):PING_TEXT_MAX;return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function shouldPing({mode:n,elapsedMs:i,minSeconds:e,isTTY:t,aborted:o}={}){if("off"===normalizePingMode(n))return!1;if(o)return!1;if(!t)return!1;const r="number"==typeof i?i:String(null==i?"":i).trim();if(""===r)return!1;const u=Number(r);return!(!Number.isFinite(u)||u<0)&&u>=1e3*normalizePingSeconds(e)}function buildPing({mode:n=DEFAULT_PING_MODE,title:i=PING_TITLE,body:e=BODY}={}){const t=normalizePingMode(n);if("off"===t)return"";const o=sanitizePingText(i),r=sanitizePingText(e),u=[];return"notify"!==t&&"both"!==t||(u.push(`${ESC}]9;${r}${BEL}`),u.push(`${ESC}]777;notify;${o};${r}${BEL}`)),"bell"!==t&&"both"!==t||u.push(BEL),u.join("")}function writePing(n,i){if(!i)return!1;if(!n||"function"!=typeof n.write)return!1;try{return n.write(i),!0}catch{return!1}}function formatPingDuration(n){const i=Math.max(0,Math.floor(Number(n)||0));if(i<60)return`${i}s`;const e=Math.floor(i/60);return e<60?`${e}m${String(i%60).padStart(2,"0")}s`:`${Math.floor(e/60)}h${String(e%60).padStart(2,"0")}m`}function pingNoticeText({seconds:n,mode:i}={}){const e=normalizePingMode(i),t="bell"===e?"bell rung":"notify"===e?"notification sent":"bell rung, notification sent";return`[ping] reply ready after ${formatPingDuration(n)} — ${t}; /ping off silences this`}function pingTurn({stream:n,mode:i,minSeconds:e,elapsedMs:t,isTTY:o,aborted:r}={}){return shouldPing({mode:i,minSeconds:e,elapsedMs:t,isTTY:o,aborted:r})&&writePing(n,buildPing({mode:i}))?pingNoticeText({seconds:Number(t)/1e3,mode:i}):null}module.exports={PING_MODES:PING_MODES,DEFAULT_PING_MODE:DEFAULT_PING_MODE,DEFAULT_PING_SECONDS:DEFAULT_PING_SECONDS,MAX_PING_SECONDS:MAX_PING_SECONDS,PING_TITLE:PING_TITLE,PING_TEXT_MAX:PING_TEXT_MAX,normalizePingMode:normalizePingMode,normalizePingSeconds:normalizePingSeconds,sanitizePingText:sanitizePingText,shouldPing:shouldPing,buildPing:buildPing,writePing:writePing,formatPingDuration:formatPingDuration,pingNoticeText:pingNoticeText,pingTurn:pingTurn};