@agentdocumentformat/cli 0.7.7 → 0.7.8

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.
@@ -0,0 +1,259 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ __export
9
+ } from "./chunk-M2RX3S2T.mjs";
10
+
11
+ // src/main/utils/ssrf-guard.ts
12
+ import { lookup } from "node:dns/promises";
13
+ import { isIP } from "node:net";
14
+ var ALLOWED_FETCH_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]), ALLOWED_CONNECT_PROTOCOLS = /* @__PURE__ */ new Set(["ws:", "wss:", "http:", "https:"]);
15
+ function parseLooseIPv4(host) {
16
+ let parts = host.split(".");
17
+ if (parts.length < 1 || parts.length > 4) return null;
18
+ let nums = [];
19
+ for (let part of parts) {
20
+ if (part === "") return null;
21
+ let n;
22
+ if (/^0[xX][0-9a-fA-F]+$/.test(part)) n = parseInt(part.slice(2), 16);
23
+ else if (/^0[0-7]+$/.test(part)) n = parseInt(part.slice(1), 8);
24
+ else if (/^[0-9]+$/.test(part)) n = parseInt(part, 10);
25
+ else return null;
26
+ if (!Number.isFinite(n) || n < 0) return null;
27
+ nums.push(n);
28
+ }
29
+ for (let i = 0; i < nums.length - 1; i++) if (nums[i] > 255) return null;
30
+ let last = nums[nums.length - 1];
31
+ if (last >= Math.pow(256, 4 - nums.length + 1)) return null;
32
+ let value = last;
33
+ for (let i = 0; i < nums.length - 1; i++) value += nums[i] * Math.pow(256, 3 - i);
34
+ return [value >>> 24 & 255, value >>> 16 & 255, value >>> 8 & 255, value & 255].join(".");
35
+ }
36
+ function isBlockedIPv4(ip) {
37
+ let o = ip.split(".").map(Number);
38
+ if (o.length !== 4 || o.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return !1;
39
+ let [a, b, c] = o;
40
+ return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 0 && c === 0 || a === 192 && b === 168 || a === 198 && (b === 18 || b === 19) || a >= 224;
41
+ }
42
+ function isBlockedIPv6(raw) {
43
+ let addr = raw.toLowerCase().replace(/^\[|\]$/g, "").split("%")[0];
44
+ if (addr === "::" || addr === "::1" || /^(0:){7}[01]$/.test(addr)) return !0;
45
+ let mapped = addr.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
46
+ if (mapped) return isBlockedIPv4(mapped[1]);
47
+ let head = addr.split(":")[0];
48
+ if (!head) return !1;
49
+ let h = parseInt(head, 16);
50
+ return Number.isNaN(h) ? !1 : (h & 65472) === 65152 || (h & 65024) === 64512 || (h & 65280) === 65280;
51
+ }
52
+ function isBlockedIpAddress(ip) {
53
+ let version = isIP(ip.replace(/^\[|\]$/g, ""));
54
+ return version === 4 ? isBlockedIPv4(ip) : version === 6 ? isBlockedIPv6(ip) : !1;
55
+ }
56
+ function isLinkLocalIp(ip) {
57
+ let bare = ip.replace(/^\[|\]$/g, "").split("%")[0], version = isIP(bare);
58
+ if (version === 4) {
59
+ let o = bare.split(".").map(Number);
60
+ return o[0] === 169 && o[1] === 254;
61
+ }
62
+ if (version === 6) {
63
+ let addr = bare.toLowerCase(), mapped = addr.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
64
+ if (mapped) {
65
+ let o = mapped[1].split(".").map(Number);
66
+ return o[0] === 169 && o[1] === 254;
67
+ }
68
+ let head = addr.split(":")[0], h = parseInt(head, 16);
69
+ return Number.isNaN(h) ? !1 : (h & 65472) === 65152;
70
+ }
71
+ return !1;
72
+ }
73
+ function isLoopbackIp(ip) {
74
+ let bare = ip.replace(/^\[|\]$/g, "").split("%")[0], version = isIP(bare);
75
+ if (version === 4) return bare.split(".").map(Number)[0] === 127;
76
+ if (version === 6) {
77
+ let addr = bare.toLowerCase();
78
+ if (addr === "::1" || /^(0:){7}1$/.test(addr)) return !0;
79
+ let mapped = addr.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
80
+ return mapped ? mapped[1].split(".").map(Number)[0] === 127 : !1;
81
+ }
82
+ return !1;
83
+ }
84
+ function isLoopbackHostname(host) {
85
+ let h = host.toLowerCase().replace(/\.$/, "");
86
+ return h === "localhost" || h === "localhost.localdomain" || h.endsWith(".localhost");
87
+ }
88
+ function isUnspecifiedIp(ip) {
89
+ let bare = ip.replace(/^\[|\]$/g, "").split("%")[0].toLowerCase();
90
+ if (bare === "0.0.0.0" || bare === "::" || /^(0{1,4}:){7}0{1,4}$/.test(bare)) return !0;
91
+ let mapped = bare.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
92
+ return mapped ? mapped[1] === "0.0.0.0" : !1;
93
+ }
94
+ function blockedMessage(target) {
95
+ return `Blocked by the sys_fetch SSRF guard: "${target}" is a private-network address (loopback is allowed by default). Set security.allow_local_fetch: true in your config to permit private/LAN fetches \u2014 an agent-initiated write to that setting raises an owner approval request.`;
96
+ }
97
+ function connectBlockedMessage(target) {
98
+ return `Blocked by the ws_connect SSRF guard: "${target}" is a private-network address (loopback is allowed by default). Set security.allow_local_fetch: true in your config to permit private/LAN connections \u2014 an agent-initiated write to that setting raises an owner approval request.`;
99
+ }
100
+ async function classifyHost(host) {
101
+ let loopbackHost = !1, candidates = [];
102
+ if (isIP(host))
103
+ candidates = [host];
104
+ else if (isLoopbackHostname(host))
105
+ loopbackHost = !0;
106
+ else {
107
+ let loose = parseLooseIPv4(host);
108
+ if (loose)
109
+ candidates = [loose];
110
+ else
111
+ try {
112
+ candidates = (await lookup(host, { all: !0, verbatim: !0 })).map((a) => a.address);
113
+ } catch {
114
+ return null;
115
+ }
116
+ }
117
+ return {
118
+ anyLinkLocal: candidates.some(isLinkLocalIp),
119
+ anyLoopback: loopbackHost || candidates.some(isLoopbackIp),
120
+ anyUnspecified: candidates.some(isUnspecifiedIp),
121
+ // Blocked classes minus loopback (private, CGNAT, unspecified, multicast, …)
122
+ // — loopback itself is allowed by default and only tier-gated per-port.
123
+ anyNonLoopbackBlocked: candidates.some((ip) => isBlockedIpAddress(ip) && !isLoopbackIp(ip))
124
+ };
125
+ }
126
+ function applyPolicy(target, port, path, cls, opts, overridableMessage) {
127
+ return cls.anyLinkLocal ? `Blocked: "${target}" is a link-local / cloud-metadata address, which is never fetchable (even with allow_local_fetch).` : (cls.anyLoopback || cls.anyUnspecified) && opts.daemonPort && port === opts.daemonPort ? `Blocked: "${target}" (port ${port}) is the local ADF daemon control API, which is never fetchable, even with allow_local_fetch.` : opts.ownOrigin && cls.anyLoopback && port === opts.ownOrigin.port && path.startsWith(opts.ownOrigin.pathPrefix) || opts.allowLocal ? null : cls.anyNonLoopbackBlocked ? overridableMessage(target) : null;
128
+ }
129
+ async function checkFetchTarget(rawUrl, opts = { allowLocal: !1 }) {
130
+ let url;
131
+ try {
132
+ url = new URL(rawUrl);
133
+ } catch {
134
+ return `Invalid URL: ${rawUrl}`;
135
+ }
136
+ if (!ALLOWED_FETCH_PROTOCOLS.has(url.protocol))
137
+ return `Blocked by the sys_fetch guard: only http and https URLs may be fetched (got "${url.protocol}").`;
138
+ let host = url.hostname.replace(/^\[|\]$/g, "");
139
+ if (!host) return `Invalid URL: ${rawUrl}`;
140
+ let port = url.port ? Number(url.port) : url.protocol === "https:" ? 443 : 80, cls = await classifyHost(host);
141
+ return cls ? applyPolicy(url.hostname, port, url.pathname, cls, opts, blockedMessage) : null;
142
+ }
143
+ async function checkConnectTarget(rawUrl, opts = { allowLocal: !1 }) {
144
+ let url;
145
+ try {
146
+ url = new URL(rawUrl);
147
+ } catch {
148
+ return `Invalid URL: ${rawUrl}`;
149
+ }
150
+ if (!ALLOWED_CONNECT_PROTOCOLS.has(url.protocol))
151
+ return `Blocked by the ws_connect guard: only ws, wss, http and https URLs may be connected (got "${url.protocol}").`;
152
+ let host = url.hostname.replace(/^\[|\]$/g, "");
153
+ if (!host) return `Invalid URL: ${rawUrl}`;
154
+ let secure = url.protocol === "wss:" || url.protocol === "https:", port = url.port ? Number(url.port) : secure ? 443 : 80, cls = await classifyHost(host);
155
+ return cls ? applyPolicy(url.hostname, port, url.pathname, cls, opts, connectBlockedMessage) : null;
156
+ }
157
+
158
+ // src/shared/utils/context-breakdown.ts
159
+ var context_breakdown_exports = {};
160
+ __export(context_breakdown_exports, {
161
+ DEFAULT_COMPACT_THRESHOLD: () => DEFAULT_COMPACT_THRESHOLD,
162
+ contextCategories: () => contextCategories,
163
+ contextTotal: () => contextTotal,
164
+ resolveCompactThreshold: () => resolveCompactThreshold,
165
+ resolveHostThreshold: () => resolveHostThreshold,
166
+ resolveLoopThreshold: () => resolveLoopThreshold
167
+ });
168
+ var DEFAULT_COMPACT_THRESHOLD = 1e5;
169
+ function hostThreshold(config, model) {
170
+ let context = config?.context?.compact_threshold;
171
+ if (context != null) return { value: context, source: "agent" };
172
+ let fromModel = model?.compact_threshold;
173
+ return fromModel != null ? { value: fromModel, source: "model" } : { value: 1e5, source: "default" };
174
+ }
175
+ function resolveCompactThreshold(config, loop) {
176
+ if (!loop || loop === "main") return hostThreshold(config, config?.model);
177
+ let declared = config?.loops?.find((l) => l.name === loop);
178
+ return declared ? declared.compact_threshold != null ? { value: declared.compact_threshold, source: "loop" } : hostThreshold(config, declared.model ?? config?.model) : hostThreshold(config, config?.model);
179
+ }
180
+ function resolveHostThreshold(config) {
181
+ return resolveCompactThreshold(config).value;
182
+ }
183
+ function resolveLoopThreshold(config, loop) {
184
+ return resolveCompactThreshold(config, loop).value;
185
+ }
186
+ function contextTotal(b) {
187
+ return b.system_prompt_tokens + b.tools_total_tokens + b.messages_tokens + b.dynamic_instructions_tokens;
188
+ }
189
+ var byTokens = (list) => [...list].sort((a, b) => b.tokens - a.tokens);
190
+ function contextCategories(b, maxItems = 12) {
191
+ let fileTokens = b.injected_files.reduce((sum, f) => sum + f.tokens, 0), parts = b.system_prompt_parts, out = [
192
+ {
193
+ id: "system",
194
+ key: "system",
195
+ label: "System prompt",
196
+ tokens: Math.max(0, b.system_prompt_tokens - fileTokens),
197
+ items: parts ? byTokens([
198
+ { name: "Base prompt and capability sections", tokens: parts.base_and_sections },
199
+ { name: "Agent instructions", tokens: parts.instructions },
200
+ { name: "Identity, loop roster, runtime blocks", tokens: parts.runtime_blocks }
201
+ ]).filter((i) => i.tokens > 0) : [],
202
+ note: "Base prompt, instructions and runtime blocks: sent with every request."
203
+ }
204
+ ];
205
+ b.injected_files.length > 0 && out.push({
206
+ id: "files",
207
+ key: "files",
208
+ label: "Injected files",
209
+ tokens: fileTokens,
210
+ count: b.injected_files.length,
211
+ items: byTokens(b.injected_files.map((f) => ({ name: f.path, tokens: f.tokens }))).slice(0, maxItems),
212
+ note: "{{path}} files rendered into the system prompt."
213
+ });
214
+ let builtIn = b.tool_groups.filter((g) => g.source === "built-in"), builtInTools = builtIn.flatMap((g) => g.tools);
215
+ out.push({
216
+ id: "tools",
217
+ key: "tools",
218
+ label: "Tools",
219
+ tokens: builtIn.reduce((sum, g) => sum + g.tokens, 0),
220
+ count: builtInTools.length,
221
+ items: byTokens(builtInTools).slice(0, maxItems),
222
+ note: "Built-in tool schemas: sent with every request."
223
+ });
224
+ for (let group of b.tool_groups)
225
+ group.source !== "built-in" && out.push({
226
+ id: `mcp:${group.source}`,
227
+ key: "mcp",
228
+ label: `MCP ${group.source}`,
229
+ tokens: group.tokens,
230
+ count: group.tools.length,
231
+ items: byTokens(group.tools).slice(0, maxItems),
232
+ note: `Tool schemas from the ${group.source} MCP server.`
233
+ });
234
+ return out.push({
235
+ id: "dynamic",
236
+ key: "dynamic",
237
+ label: "Dynamic instructions",
238
+ tokens: b.dynamic_instructions_tokens,
239
+ items: [],
240
+ note: "Per-turn runtime notes (context pressure, reminders)."
241
+ }), out.push({
242
+ id: "messages",
243
+ key: "messages",
244
+ label: "Conversation",
245
+ tokens: b.messages_tokens,
246
+ items: [],
247
+ note: "This loop\u2019s history, compaction summary included (estimate)."
248
+ }), byTokens(out);
249
+ }
250
+
251
+ export {
252
+ checkFetchTarget,
253
+ checkConnectTarget,
254
+ resolveCompactThreshold,
255
+ resolveLoopThreshold,
256
+ contextTotal,
257
+ contextCategories,
258
+ context_breakdown_exports
259
+ };
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-5W7KES6P.mjs";
12
12
  import {
13
13
  resolveWithDefault
14
- } from "./chunk-HPVFJYXR.mjs";
14
+ } from "./chunk-ESP3VNMX.mjs";
15
15
  import {
16
16
  EXIT,
17
17
  enforceToolGate,
@@ -21,7 +21,7 @@ import {
21
21
  getCommand,
22
22
  notifyToolCallObservers,
23
23
  shellReadFile
24
- } from "./chunk-ZROSGV65.mjs";
24
+ } from "./chunk-HSBV6YFU.mjs";
25
25
 
26
26
  // src/main/tools/shell/executor/pipeline-executor.ts
27
27
  function vfsPath(p) {
@@ -44,7 +44,7 @@ function tuiInvocation(argv) {
44
44
  return argv.filter((a) => a !== "--json");
45
45
  }
46
46
  async function defaultLaunchTui(argv) {
47
- let { runTui } = await import("./tui-4ZWZKD4C.mjs");
47
+ let { runTui } = await import("./tui-UQJLK7XI.mjs");
48
48
  return await runTui(argv);
49
49
  }
50
50
  function urlFromArgv(argv) {
@@ -9,7 +9,9 @@ import {
9
9
  getCommand,
10
10
  hasCommand,
11
11
  registry
12
- } from "./chunk-ZROSGV65.mjs";
12
+ } from "./chunk-HSBV6YFU.mjs";
13
+ import "./chunk-G6PH7RPW.mjs";
14
+ import "./chunk-3GNIDM53.mjs";
13
15
  import "./chunk-CD3ATSXE.mjs";
14
16
  import "./chunk-M2RX3S2T.mjs";
15
17
  export {