aegiscode 7.0.25 → 7.0.26
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/package.json +7 -3
- package/scripts/check.mjs +52 -1
- package/scripts/demo.mjs +94 -1
- package/scripts/predist.mjs +75 -1
- package/scripts/runtests.mjs +56 -1
- package/scripts/seal-gate.mjs +74 -1
- package/src/agents.js +139 -1
- package/src/app.js +2957 -1
- package/src/art.js +289 -1
- package/src/chatflow.js +3023 -1
- package/src/checkpoint.js +90 -1
- package/src/clipboard.js +424 -1
- package/src/cloudsync.js +528 -1
- package/src/commands.js +4089 -1
- package/src/config.js +581 -1
- package/src/connect.js +349 -1
- package/src/credentials.js +33 -1
- package/src/deps.js +232 -1
- package/src/devrun.js +187 -1
- package/src/diff.js +333 -1
- package/src/diffview.js +296 -1
- package/src/engine.js +297 -1
- package/src/entitlement.js +355 -1
- package/src/events.js +707 -1
- package/src/export.js +67 -1
- package/src/filepreview.js +153 -1
- package/src/fingerprint.js +592 -1
- package/src/format.js +259 -1
- package/src/fuzzy.js +119 -1
- package/src/history.js +423 -1
- package/src/init.js +175 -1
- package/src/input.js +139 -1
- package/src/keys.js +183 -1
- package/src/markdown.js +306 -1
- package/src/models.js +507 -1
- package/src/naming.js +57 -1
- package/src/overlays.js +462 -1
- package/src/panels.js +1418 -1
- package/src/ping.js +226 -1
- package/src/presence.js +238 -1
- package/src/render.js +516 -1
- package/src/screen.js +518 -1
- package/src/screens.js +896 -1
- package/src/secret.js +59 -1
- package/src/securefs.js +359 -1
- package/src/settings.js +155 -1
- package/src/shared.js +52 -1
- package/src/sharedpaths.js +53 -1
- package/src/signup.js +156 -1
- package/src/summarize.js +95 -1
- package/src/sysdiag.js +585 -1
- package/src/system.js +40 -1
- package/src/theme.js +570 -1
- package/src/title.js +220 -1
- package/src/todos.js +115 -1
- package/src/tokens.js +263 -1
- package/src/topup.js +210 -1
- package/src/update.js +191 -1
- package/vendor/client/aegis.js +2441 -1
- package/vendor/client/attest.js +518 -1
- package/vendor/client/authorship-key.js +410 -1
- package/vendor/client/auto-provision.js +134 -1
- package/vendor/client/brain-catalog.js +268 -1
- package/vendor/client/byok-catalog.js +199 -1
- package/vendor/client/catalog-client.js +487 -1
- package/vendor/client/conversation-export.js +177 -1
- package/vendor/client/credentials.js +494 -1
- package/vendor/client/device-fingerprint.js +141 -1
- package/vendor/client/drive-connect.js +110 -1
- package/vendor/client/drive-upload.js +234 -1
- package/vendor/client/env-file.js +1273 -1
- package/vendor/client/fingerprint.js +1064 -1
- package/vendor/client/foreign-memory.js +669 -1
- package/vendor/client/google-signin.js +133 -1
- package/vendor/client/hooks.js +430 -1
- package/vendor/client/model-discovery.js +373 -1
- package/vendor/client/naming.js +283 -1
- package/vendor/client/platform.js +937 -1
- package/vendor/client/prefs.js +351 -1
- package/vendor/client/presence-constants.js +107 -1
- package/vendor/client/presence.js +438 -1
- package/vendor/client/record-vault.js +1055 -3
- package/vendor/client/session-store.js +575 -1
- package/vendor/client/topup.js +297 -1
- package/vendor/client/touch.js +458 -1
- package/vendor/client/update.js +763 -1
- package/vendor/client/user-models.js +381 -1
- package/vendor/desktop/lib/local/agents.js +105 -1
- package/vendor/desktop/lib/local/attachments.js +276 -1
- package/vendor/desktop/lib/local/autonomous.js +1045 -1
- package/vendor/desktop/lib/local/claude-pro.js +1028 -1
- package/vendor/desktop/lib/local/context.js +125 -1
- package/vendor/desktop/lib/local/engine.js +3666 -1
- package/vendor/desktop/lib/local/entitlement.js +660 -1
- package/vendor/desktop/lib/local/git-scope.js +228 -1
- package/vendor/desktop/lib/local/local.js +2145 -1
- package/vendor/desktop/lib/local/prompt.js +280 -1
- package/vendor/desktop/lib/local/queue.js +560 -1
- package/vendor/desktop/lib/local/session-rounds.js +238 -1
- package/vendor/desktop/lib/local/spill.js +75 -1
- package/vendor/desktop/lib/local/turn-guard.js +300 -1
- package/vendor/desktop/lib/local/worktree-lock.js +235 -1
- package/vendor/desktop/lib/settings.js +890 -1
- package/vendor/desktop/renderer/usage.js +1239 -1
- package/vendor/hosts/install.js +638 -1
- package/vendor/hosts/openai-shim.js +515 -1
- package/vendor/hosts/spec.js +164 -1
- package/vendor/hosts/targets.js +346 -1
- package/vendor/mcp/server.js +221 -1
- package/vendor/mcp/tools.js +408 -1
- package/vendor/one/src/child.js +285 -1
- package/vendor/one/src/permissions.js +383 -1
- package/SOURCE-OFFER.txt +0 -9
|
@@ -1,3 +1,127 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
+
* context.js — token-budget trimmer for very large inputs (plan P1 §5.1 /
|
|
10
|
+
* P2 §6.4).
|
|
11
|
+
*
|
|
12
|
+
* Pure Node, no Electron imports. Estimates tokens with a ~4 chars/token
|
|
13
|
+
* heuristic, keeps the system message plus the newest turns, and drops the
|
|
14
|
+
* oldest turns that exceed the budget. The full transcript always stays in
|
|
15
|
+
* the local session record — this only trims what is sent to the wire.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const CHARS_PER_TOKEN = 4;
|
|
19
|
+
const MESSAGE_OVERHEAD = 4; // per-message framing + role overhead
|
|
20
|
+
// Flat per-image cost charged by messageTokens. Vision encoding is tile-based
|
|
21
|
+
// and provider-specific, so this is an approximation chosen to be pessimistic:
|
|
22
|
+
// undercount an image and the trimmer cuts a conversation that did not fit.
|
|
23
|
+
const IMAGE_COST = 850;
|
|
24
|
+
|
|
25
|
+
/** Rough token count for a string (no tokenizer in a zero-dep shell). */
|
|
26
|
+
function estimateTokens(text) {
|
|
27
|
+
if (text == null) return 0;
|
|
28
|
+
const s = typeof text === 'string' ? text : String(text);
|
|
29
|
+
return Math.max(0, Math.ceil(s.length / CHARS_PER_TOKEN));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Rough token cost of one { role, content } message.
|
|
33
|
+
*
|
|
34
|
+
* `content` is no longer necessarily a string: a dropped picture makes it an
|
|
35
|
+
* OpenAI content-part array (`{type:'image_url'}` / `{type:'text'}`). Two
|
|
36
|
+
* things must hold for the trimmer to stay honest:
|
|
37
|
+
*
|
|
38
|
+
* - An array must be counted by its TEXT, never by `String(content)`. The
|
|
39
|
+
* old coercion turned a 1 MB data URL into "[object Object]" — about four
|
|
40
|
+
* tokens — so a vision turn looked nearly free and the trimmer kept every
|
|
41
|
+
* attachment while dropping the conversation they belonged to.
|
|
42
|
+
* - An image must still cost something real, or the same thing happens in
|
|
43
|
+
* reverse: history is trimmed as if the pixels were not on the wire.
|
|
44
|
+
*
|
|
45
|
+
* So text parts are estimated and each image is billed a flat IMAGE_COST. The
|
|
46
|
+
* real provider figure is tile-based and per-model; this is the conservative
|
|
47
|
+
* flat equivalent, which is the correct direction to be wrong in.
|
|
48
|
+
*/
|
|
49
|
+
function messageTokens(message) {
|
|
50
|
+
if (!message) return 0;
|
|
51
|
+
const content =
|
|
52
|
+
message.content != null
|
|
53
|
+
? message.content
|
|
54
|
+
: message.text != null
|
|
55
|
+
? message.text
|
|
56
|
+
: '';
|
|
57
|
+
if (Array.isArray(content)) {
|
|
58
|
+
let cost = MESSAGE_OVERHEAD;
|
|
59
|
+
for (const part of content) {
|
|
60
|
+
if (!part || typeof part !== 'object') continue;
|
|
61
|
+
if (typeof part.text === 'string') cost += estimateTokens(part.text);
|
|
62
|
+
else if (part.type === 'image_url' || part.image_url) cost += IMAGE_COST;
|
|
63
|
+
}
|
|
64
|
+
return cost;
|
|
65
|
+
}
|
|
66
|
+
return MESSAGE_OVERHEAD + estimateTokens(content);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Trim a message list to fit a token budget, keeping the newest turns.
|
|
71
|
+
*
|
|
72
|
+
* @param {object} opts
|
|
73
|
+
* @param {Array<{role:string,content:string}>} [opts.messages=[]]
|
|
74
|
+
* @param {string} [opts.system='']
|
|
75
|
+
* @param {number} [opts.budgetTokens=8192] total tokens allowed on the wire
|
|
76
|
+
* @param {number} [opts.reserveTokens=0] tokens reserved for the reply
|
|
77
|
+
* @param {number} [opts.fixedTokens=0] wire cost that is NOT a message and
|
|
78
|
+
* cannot be dropped (the tool schemas), counted before any turn is kept
|
|
79
|
+
* @returns {{messages:Array, system:string, dropped:number, estimatedTokens:number, fixedTokens:number}}
|
|
80
|
+
*/
|
|
81
|
+
function trimContext({
|
|
82
|
+
messages = [],
|
|
83
|
+
system = '',
|
|
84
|
+
budgetTokens = 8192,
|
|
85
|
+
reserveTokens = 0,
|
|
86
|
+
fixedTokens = 0,
|
|
87
|
+
} = {}) {
|
|
88
|
+
const limit = Math.max(0, budgetTokens - reserveTokens);
|
|
89
|
+
const kept = [];
|
|
90
|
+
// Tool schemas go on the wire every round and cannot be trimmed away, so they
|
|
91
|
+
// are charged against the budget FIRST. Without this the trimmer believed a
|
|
92
|
+
// 4096-token window had 4096 tokens for history when the schemas had already
|
|
93
|
+
// spent ~1971 of them (measured: 10 schemas, 7882 chars) — and the daemon,
|
|
94
|
+
// run with `--context-shift`, discarded the SYSTEM row to make room instead
|
|
95
|
+
// of erroring. Counting them here is what keeps the system row alive.
|
|
96
|
+
const fixed = Math.max(0, Number(fixedTokens) || 0);
|
|
97
|
+
let used = fixed;
|
|
98
|
+
|
|
99
|
+
if (system) used += MESSAGE_OVERHEAD + estimateTokens(system);
|
|
100
|
+
|
|
101
|
+
// Walk newest -> oldest; keep a turn if it fits, else stop (older turns are
|
|
102
|
+
// even less relevant). Always keep at least the newest turn so a single
|
|
103
|
+
// oversized message is still sent rather than silently emptied.
|
|
104
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
105
|
+
const cost = messageTokens(messages[i]);
|
|
106
|
+
if (used + cost > limit && kept.length > 0) break;
|
|
107
|
+
kept.unshift(messages[i]);
|
|
108
|
+
used += cost;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
messages: kept,
|
|
113
|
+
system,
|
|
114
|
+
dropped: messages.length - kept.length,
|
|
115
|
+
estimatedTokens: used,
|
|
116
|
+
fixedTokens: fixed,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
CHARS_PER_TOKEN,
|
|
122
|
+
MESSAGE_OVERHEAD,
|
|
123
|
+
IMAGE_COST,
|
|
124
|
+
estimateTokens,
|
|
125
|
+
messageTokens,
|
|
126
|
+
trimContext,
|
|
127
|
+
};
|