@agentdocumentformat/cli 0.7.6 → 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.
package/dist/adf.mjs CHANGED
@@ -9,7 +9,7 @@ import "./chunks/chunk-M2RX3S2T.mjs";
9
9
 
10
10
  // src/main/cli/bin.ts
11
11
  function version() {
12
- return "0.7.6";
12
+ return "0.7.8";
13
13
  }
14
14
  var DAEMON_HELP = `Usage: adf daemon [--port <n>] [--host <h>] [--settings <file>]
15
15
  adf daemon start [--port <n>] [--force]
@@ -140,9 +140,9 @@ async function main(argv) {
140
140
  let { daemonPaths } = await import("./chunks/daemon-control-HKFVSQTQ.mjs");
141
141
  process.env.ADF_DAEMON_PIDFILE = daemonPaths(Number(process.env.ADF_DAEMON_PORT ?? 7385)).pidFile;
142
142
  }
143
- return await import("./chunks/daemon-ZT5J445W.mjs"), -1;
143
+ return await import("./chunks/daemon-YDIK3AAM.mjs"), -1;
144
144
  }
145
- let [{ runCli, tuiInvocation }, control] = await Promise.all([import("./chunks/cli-XORTCRZW.mjs"), import("./chunks/daemon-control-HKFVSQTQ.mjs")]);
145
+ let [{ runCli, tuiInvocation }, control] = await Promise.all([import("./chunks/cli-NMFIAR7Z.mjs"), import("./chunks/daemon-control-HKFVSQTQ.mjs")]);
146
146
  return tuiInvocation(argv) && process.env.NODE_ENV === void 0 && (process.env.NODE_ENV = "production", process.env.ADF_NODE_ENV_DEFAULTED = "1"), await runCli(argv, {
147
147
  fetch: globalThis.fetch.bind(globalThis),
148
148
  stdout: (text) => process.stdout.write(text),
@@ -140,7 +140,7 @@ import {
140
140
  } from "./chunk-KXEF4F4E.mjs";
141
141
  import {
142
142
  DaemonClient
143
- } from "./chunk-3UCKYP7P.mjs";
143
+ } from "./chunk-VN7UH7I5.mjs";
144
144
  import {
145
145
  DaemonError,
146
146
  MAIN_LOOP,
@@ -154,10 +154,9 @@ import {
154
154
  savePrefs
155
155
  } from "./chunk-5QU5VY7N.mjs";
156
156
  import {
157
- ADF_SKILLS_REGISTRY_URL,
158
157
  checkFetchTarget,
159
158
  context_breakdown_exports
160
- } from "./chunk-2WSQ7V6K.mjs";
159
+ } from "./chunk-Y2QA53AN.mjs";
161
160
  import "./chunk-2NAP2ZF7.mjs";
162
161
  import "./chunk-5PO5PKRV.mjs";
163
162
  import "./chunk-VMHTYDH4.mjs";
@@ -204,6 +203,9 @@ import {
204
203
  external_exports
205
204
  } from "./chunk-ZJKXHM4Q.mjs";
206
205
  import "./chunk-RIX34QHC.mjs";
206
+ import {
207
+ ADF_SKILLS_REGISTRY_URL
208
+ } from "./chunk-G6PH7RPW.mjs";
207
209
  import "./chunk-CD3ATSXE.mjs";
208
210
  import {
209
211
  __export,
@@ -81,7 +81,7 @@ var EnvironmentResolver = class {
81
81
  return "";
82
82
  }
83
83
  try {
84
- let val = this.workspace.getIdentity(name.toLowerCase());
84
+ let val = this.workspace.getIdentityForCode(name.toLowerCase(), null);
85
85
  if (val) return val;
86
86
  } catch {
87
87
  }
@@ -8,9 +8,6 @@ import {
8
8
  AGENT_DEFAULTS,
9
9
  DEFAULT_TOOLS
10
10
  } from "./chunk-CD3ATSXE.mjs";
11
- import {
12
- __export
13
- } from "./chunk-M2RX3S2T.mjs";
14
11
 
15
12
  // src/shared/constants/adf-defaults.ts
16
13
  var ADF_VERSION = "0.2", DOCS_GUIDES_URL = "https://raw.githubusercontent.com/christianbalevski/adf/main/docs/guides", ADF_SKILLS_REGISTRY_URL = "https://raw.githubusercontent.com/christianbalevski/adf/main/skills/registry.json", PROVIDER_TYPES = [
@@ -250,246 +247,6 @@ The \`ws_*\` tools manage your configured connections (schemas have the details)
250
247
  };
251
248
  var DEFAULT_COMPACTION_PROMPT = "You are a conversation compactor. Read the transcript between an AI agent and its environment and write a present-tense status briefing: bullets organized by topic, under 1500 words. Keep current task state, key decisions and their reasoning, exact paths, names, IDs, and values in play, pending work and next steps, constraints or preferences discovered, open questions and hunches the agent was carrying, and anything surprising or still unexplained. Keep exact details; a vague summary is useless. Keep every open thread; anything dropped here is gone. Transcript role tags carry the loop seq when known (`[USER S137]` / `[ASSISTANT S137]`), so when a bullet derives from specific messages, cite them (`[S137]`) and the summary stays traceable to the archived history in adf_audit.";
252
249
 
253
- // src/main/utils/ssrf-guard.ts
254
- import { lookup } from "node:dns/promises";
255
- import { isIP } from "node:net";
256
- var ALLOWED_FETCH_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]), ALLOWED_CONNECT_PROTOCOLS = /* @__PURE__ */ new Set(["ws:", "wss:", "http:", "https:"]);
257
- function parseLooseIPv4(host) {
258
- let parts = host.split(".");
259
- if (parts.length < 1 || parts.length > 4) return null;
260
- let nums = [];
261
- for (let part of parts) {
262
- if (part === "") return null;
263
- let n;
264
- if (/^0[xX][0-9a-fA-F]+$/.test(part)) n = parseInt(part.slice(2), 16);
265
- else if (/^0[0-7]+$/.test(part)) n = parseInt(part.slice(1), 8);
266
- else if (/^[0-9]+$/.test(part)) n = parseInt(part, 10);
267
- else return null;
268
- if (!Number.isFinite(n) || n < 0) return null;
269
- nums.push(n);
270
- }
271
- for (let i = 0; i < nums.length - 1; i++) if (nums[i] > 255) return null;
272
- let last = nums[nums.length - 1];
273
- if (last >= Math.pow(256, 4 - nums.length + 1)) return null;
274
- let value = last;
275
- for (let i = 0; i < nums.length - 1; i++) value += nums[i] * Math.pow(256, 3 - i);
276
- return [value >>> 24 & 255, value >>> 16 & 255, value >>> 8 & 255, value & 255].join(".");
277
- }
278
- function isBlockedIPv4(ip) {
279
- let o = ip.split(".").map(Number);
280
- if (o.length !== 4 || o.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return !1;
281
- let [a, b, c] = o;
282
- 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;
283
- }
284
- function isBlockedIPv6(raw) {
285
- let addr = raw.toLowerCase().replace(/^\[|\]$/g, "").split("%")[0];
286
- if (addr === "::" || addr === "::1" || /^(0:){7}[01]$/.test(addr)) return !0;
287
- let mapped = addr.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
288
- if (mapped) return isBlockedIPv4(mapped[1]);
289
- let head = addr.split(":")[0];
290
- if (!head) return !1;
291
- let h = parseInt(head, 16);
292
- return Number.isNaN(h) ? !1 : (h & 65472) === 65152 || (h & 65024) === 64512 || (h & 65280) === 65280;
293
- }
294
- function isBlockedIpAddress(ip) {
295
- let version = isIP(ip.replace(/^\[|\]$/g, ""));
296
- return version === 4 ? isBlockedIPv4(ip) : version === 6 ? isBlockedIPv6(ip) : !1;
297
- }
298
- function isLinkLocalIp(ip) {
299
- let bare = ip.replace(/^\[|\]$/g, "").split("%")[0], version = isIP(bare);
300
- if (version === 4) {
301
- let o = bare.split(".").map(Number);
302
- return o[0] === 169 && o[1] === 254;
303
- }
304
- if (version === 6) {
305
- let addr = bare.toLowerCase(), mapped = addr.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
306
- if (mapped) {
307
- let o = mapped[1].split(".").map(Number);
308
- return o[0] === 169 && o[1] === 254;
309
- }
310
- let head = addr.split(":")[0], h = parseInt(head, 16);
311
- return Number.isNaN(h) ? !1 : (h & 65472) === 65152;
312
- }
313
- return !1;
314
- }
315
- function isLoopbackIp(ip) {
316
- let bare = ip.replace(/^\[|\]$/g, "").split("%")[0], version = isIP(bare);
317
- if (version === 4) return bare.split(".").map(Number)[0] === 127;
318
- if (version === 6) {
319
- let addr = bare.toLowerCase();
320
- if (addr === "::1" || /^(0:){7}1$/.test(addr)) return !0;
321
- let mapped = addr.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
322
- return mapped ? mapped[1].split(".").map(Number)[0] === 127 : !1;
323
- }
324
- return !1;
325
- }
326
- function isLoopbackHostname(host) {
327
- let h = host.toLowerCase().replace(/\.$/, "");
328
- return h === "localhost" || h === "localhost.localdomain" || h.endsWith(".localhost");
329
- }
330
- function isUnspecifiedIp(ip) {
331
- let bare = ip.replace(/^\[|\]$/g, "").split("%")[0].toLowerCase();
332
- if (bare === "0.0.0.0" || bare === "::" || /^(0{1,4}:){7}0{1,4}$/.test(bare)) return !0;
333
- let mapped = bare.match(/^::(?:ffff:(?:0{1,4}:)?)?((?:\d{1,3}\.){3}\d{1,3})$/);
334
- return mapped ? mapped[1] === "0.0.0.0" : !1;
335
- }
336
- function blockedMessage(target) {
337
- 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.`;
338
- }
339
- function connectBlockedMessage(target) {
340
- 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.`;
341
- }
342
- async function classifyHost(host) {
343
- let loopbackHost = !1, candidates = [];
344
- if (isIP(host))
345
- candidates = [host];
346
- else if (isLoopbackHostname(host))
347
- loopbackHost = !0;
348
- else {
349
- let loose = parseLooseIPv4(host);
350
- if (loose)
351
- candidates = [loose];
352
- else
353
- try {
354
- candidates = (await lookup(host, { all: !0, verbatim: !0 })).map((a) => a.address);
355
- } catch {
356
- return null;
357
- }
358
- }
359
- return {
360
- anyLinkLocal: candidates.some(isLinkLocalIp),
361
- anyLoopback: loopbackHost || candidates.some(isLoopbackIp),
362
- anyUnspecified: candidates.some(isUnspecifiedIp),
363
- // Blocked classes minus loopback (private, CGNAT, unspecified, multicast, …)
364
- // — loopback itself is allowed by default and only tier-gated per-port.
365
- anyNonLoopbackBlocked: candidates.some((ip) => isBlockedIpAddress(ip) && !isLoopbackIp(ip))
366
- };
367
- }
368
- function applyPolicy(target, port, path, cls, opts, overridableMessage) {
369
- 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;
370
- }
371
- async function checkFetchTarget(rawUrl, opts = { allowLocal: !1 }) {
372
- let url;
373
- try {
374
- url = new URL(rawUrl);
375
- } catch {
376
- return `Invalid URL: ${rawUrl}`;
377
- }
378
- if (!ALLOWED_FETCH_PROTOCOLS.has(url.protocol))
379
- return `Blocked by the sys_fetch guard: only http and https URLs may be fetched (got "${url.protocol}").`;
380
- let host = url.hostname.replace(/^\[|\]$/g, "");
381
- if (!host) return `Invalid URL: ${rawUrl}`;
382
- let port = url.port ? Number(url.port) : url.protocol === "https:" ? 443 : 80, cls = await classifyHost(host);
383
- return cls ? applyPolicy(url.hostname, port, url.pathname, cls, opts, blockedMessage) : null;
384
- }
385
- async function checkConnectTarget(rawUrl, opts = { allowLocal: !1 }) {
386
- let url;
387
- try {
388
- url = new URL(rawUrl);
389
- } catch {
390
- return `Invalid URL: ${rawUrl}`;
391
- }
392
- if (!ALLOWED_CONNECT_PROTOCOLS.has(url.protocol))
393
- return `Blocked by the ws_connect guard: only ws, wss, http and https URLs may be connected (got "${url.protocol}").`;
394
- let host = url.hostname.replace(/^\[|\]$/g, "");
395
- if (!host) return `Invalid URL: ${rawUrl}`;
396
- let secure = url.protocol === "wss:" || url.protocol === "https:", port = url.port ? Number(url.port) : secure ? 443 : 80, cls = await classifyHost(host);
397
- return cls ? applyPolicy(url.hostname, port, url.pathname, cls, opts, connectBlockedMessage) : null;
398
- }
399
-
400
- // src/shared/utils/context-breakdown.ts
401
- var context_breakdown_exports = {};
402
- __export(context_breakdown_exports, {
403
- DEFAULT_COMPACT_THRESHOLD: () => DEFAULT_COMPACT_THRESHOLD,
404
- contextCategories: () => contextCategories,
405
- contextTotal: () => contextTotal,
406
- resolveCompactThreshold: () => resolveCompactThreshold,
407
- resolveHostThreshold: () => resolveHostThreshold,
408
- resolveLoopThreshold: () => resolveLoopThreshold
409
- });
410
- var DEFAULT_COMPACT_THRESHOLD = 1e5;
411
- function hostThreshold(config, model) {
412
- let context = config?.context?.compact_threshold;
413
- if (context != null) return { value: context, source: "agent" };
414
- let fromModel = model?.compact_threshold;
415
- return fromModel != null ? { value: fromModel, source: "model" } : { value: 1e5, source: "default" };
416
- }
417
- function resolveCompactThreshold(config, loop) {
418
- if (!loop || loop === "main") return hostThreshold(config, config?.model);
419
- let declared = config?.loops?.find((l) => l.name === loop);
420
- return declared ? declared.compact_threshold != null ? { value: declared.compact_threshold, source: "loop" } : hostThreshold(config, declared.model ?? config?.model) : hostThreshold(config, config?.model);
421
- }
422
- function resolveHostThreshold(config) {
423
- return resolveCompactThreshold(config).value;
424
- }
425
- function resolveLoopThreshold(config, loop) {
426
- return resolveCompactThreshold(config, loop).value;
427
- }
428
- function contextTotal(b) {
429
- return b.system_prompt_tokens + b.tools_total_tokens + b.messages_tokens + b.dynamic_instructions_tokens;
430
- }
431
- var byTokens = (list) => [...list].sort((a, b) => b.tokens - a.tokens);
432
- function contextCategories(b, maxItems = 12) {
433
- let fileTokens = b.injected_files.reduce((sum, f) => sum + f.tokens, 0), parts = b.system_prompt_parts, out = [
434
- {
435
- id: "system",
436
- key: "system",
437
- label: "System prompt",
438
- tokens: Math.max(0, b.system_prompt_tokens - fileTokens),
439
- items: parts ? byTokens([
440
- { name: "Base prompt and capability sections", tokens: parts.base_and_sections },
441
- { name: "Agent instructions", tokens: parts.instructions },
442
- { name: "Identity, loop roster, runtime blocks", tokens: parts.runtime_blocks }
443
- ]).filter((i) => i.tokens > 0) : [],
444
- note: "Base prompt, instructions and runtime blocks: sent with every request."
445
- }
446
- ];
447
- b.injected_files.length > 0 && out.push({
448
- id: "files",
449
- key: "files",
450
- label: "Injected files",
451
- tokens: fileTokens,
452
- count: b.injected_files.length,
453
- items: byTokens(b.injected_files.map((f) => ({ name: f.path, tokens: f.tokens }))).slice(0, maxItems),
454
- note: "{{path}} files rendered into the system prompt."
455
- });
456
- let builtIn = b.tool_groups.filter((g) => g.source === "built-in"), builtInTools = builtIn.flatMap((g) => g.tools);
457
- out.push({
458
- id: "tools",
459
- key: "tools",
460
- label: "Tools",
461
- tokens: builtIn.reduce((sum, g) => sum + g.tokens, 0),
462
- count: builtInTools.length,
463
- items: byTokens(builtInTools).slice(0, maxItems),
464
- note: "Built-in tool schemas: sent with every request."
465
- });
466
- for (let group of b.tool_groups)
467
- group.source !== "built-in" && out.push({
468
- id: `mcp:${group.source}`,
469
- key: "mcp",
470
- label: `MCP ${group.source}`,
471
- tokens: group.tokens,
472
- count: group.tools.length,
473
- items: byTokens(group.tools).slice(0, maxItems),
474
- note: `Tool schemas from the ${group.source} MCP server.`
475
- });
476
- return out.push({
477
- id: "dynamic",
478
- key: "dynamic",
479
- label: "Dynamic instructions",
480
- tokens: b.dynamic_instructions_tokens,
481
- items: [],
482
- note: "Per-turn runtime notes (context pressure, reminders)."
483
- }), out.push({
484
- id: "messages",
485
- key: "messages",
486
- label: "Conversation",
487
- tokens: b.messages_tokens,
488
- items: [],
489
- note: "This loop\u2019s history, compaction summary included (estimate)."
490
- }), byTokens(out);
491
- }
492
-
493
250
  export {
494
251
  DOCS_GUIDES_URL,
495
252
  ADF_SKILLS_REGISTRY_URL,
@@ -500,11 +257,5 @@ export {
500
257
  DEFAULT_BASE_PROMPT,
501
258
  DEFAULT_TOOL_PROMPTS,
502
259
  DEFAULT_DYNAMIC_PROMPTS,
503
- DEFAULT_COMPACTION_PROMPT,
504
- checkFetchTarget,
505
- checkConnectTarget,
506
- resolveCompactThreshold,
507
- contextTotal,
508
- contextCategories,
509
- context_breakdown_exports
260
+ DEFAULT_COMPACTION_PROMPT
510
261
  };