@dudko.dev/agent 0.0.37 → 0.0.38

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/README.md CHANGED
@@ -302,7 +302,7 @@ import { createAgent, loadSkillsFromDir, parseSkillMarkdown, defineSkill } from
302
302
 
303
303
  const skills = await loadSkillsFromDir('./skills') // every ./skills/<skill>/SKILL.md
304
304
  const agent = await createAgent({ ...config, skills })
305
- agent.listSkills() // [{ name, description }]
305
+ agent.listSkills() // [{ name, description }] (+ learned: true on the agent's own, see Learning)
306
306
  ```
307
307
 
308
308
  Progressive disclosure keeps them cheap:
@@ -493,6 +493,62 @@ and the run are untouched. Only a child that has started is listed; one still wa
493
493
  child stops them with it. What each child does is the `subagent.event` stream, the same events the
494
494
  parent emits.
495
495
 
496
+ ## Egress: what the model may fetch
497
+
498
+ By default the agent has **no way to reach the network of its own**: its only outbound paths are the provider API and the MCP servers and tools *you* configure. To let the model read the web, switch on `egress`:
499
+
500
+ ```ts
501
+ const agent = await createAgent({
502
+ // ...
503
+ egress: {
504
+ allow: ['docs.example.com', '*.github.com'], // optional: only these (then web_fetch counts as read-only)
505
+ deny: ['internal.example.com', '10.0.0.0/8'], // optional: always refused, wins over allow
506
+ },
507
+ })
508
+ // egress: true = any public host over https. CLI: AGENT_EGRESS=on, AGENT_EGRESS_ALLOW, AGENT_EGRESS_DENY, ...
509
+ ```
510
+
511
+ That registers one tool, `web_fetch({ url, maxChars? })`: a GET that returns the page as readable text (HTML reduced, JSON and text as they are), flagged `untrusted: true` — facts to use, never instructions. Every request goes through **`createSafeFetch`**, which you can also use on its own (it is a drop-in `fetch`, e.g. for an MCP transport):
512
+
513
+ - **Its own DNS lookup, inside the connect.** The addresses that were checked are the addresses that are connected to, so DNS rebinding has nowhere to hide. A name with *any* unacceptable address is refused whole.
514
+ - **Refused by default:** loopback, private networks, link-local, CGNAT, multicast, reserved and documentation ranges, and **cloud metadata endpoints** (`169.254.169.254`, `fd00:ec2::254`, Alibaba, Oracle). IPv4 hidden in IPv6 (mapped, NAT64, 6to4, compatible) is judged as the IPv4 it is; the URL parser's tricks (`2130706433`, `0x7f.1`, `127.1`) are normalized first. `allowPrivateNetwork: true` opens the private ranges for an intranet agent — metadata and the never-routable ranges stay refused.
515
+ - **Allow / deny** by host (`example.com`, `*.example.com` — subdomains, not the apex), IP or CIDR; deny wins; an allow list is exclusive. A deny CIDR also applies to what a *name* resolves to.
516
+ - **https only, port 443, GET/HEAD**, no credentials in URLs — widen with `protocols`, `ports`, `methods`.
517
+ - **Redirects** are followed up to `maxRedirects` (3), **each hop judged again**, never from https to http, credentials dropped across origins.
518
+ - **Bounded:** `timeoutMs` (15 s) for the whole request, `maxResponseBytes` (2 MB) on what is read *after decompression* (a small gzip cannot unpack into the heap).
519
+ - Certificates are always verified; `ca` adds a CA to trust (an internal one).
520
+
521
+ Approval: an open-internet `web_fetch` is a way to leak data through the URL, so it asks like a **write** (`ask-writes` prompts for it); with an `allow` list it is **read-only**. Each request emits `egress.request` (`url` is origin and path only — no query string — `allowed`, `status` / `reason`).
522
+
523
+ What it is not: a sandbox for what a fetched *page says* — that stays data the model reads, which is why the result is flagged untrusted. And it does not govern the provider's own calls, or the MCP servers and tools you configure — those are your configuration, not the model's. A subagent has its own `egress` (none unless you set it). The browser sibling cannot pin DNS; see `@dudko.dev/agent-web`.
524
+
525
+ ## Learning: lessons that outlive the task
526
+
527
+ Switch on `learning` and the agent keeps a notebook. When it hits a problem and finds the way around it — a tool error it resolved, a wrong assumption it corrected, a procedure it had to look up — it writes the lesson down with `save_skill`, and the lesson **is a [skill](#skills)**: it shows up in the planner's `SKILLS:` index right away (even for the next step of the same run) and loads with `load_skill` like any other. Nothing new to learn on the reading side.
528
+
529
+ ```ts
530
+ import { createAgent, DirSkillStore } from '@dudko.dev/agent'
531
+
532
+ const agent = await createAgent({ ...config, learning: true }) // this session (the process)
533
+ // ...or keep them as <dir>/<name>/SKILL.md, readable, editable and committable like your own:
534
+ const agent = await createAgent({ ...config, learning: { store: new DirSkillStore('./learned-skills') } })
535
+
536
+ agent.listSkills() // [{ name, description, learned }]
537
+ agent.listLearnedSkills() // the agent's own, with origin: when, which run, revision, where it read
538
+ await agent.forgetSkill('image-format-jpg') // one went stale
539
+ ```
540
+
541
+ It is a *knowledge* feature and nothing else:
542
+
543
+ - **Knowledge, never policy.** A lesson is loaded under a header saying it is the agent's own hint, not an instruction from the user; the user's request and your rules win a conflict. It cannot grant a permission, switch a tool on or loosen `egress`.
544
+ - **A normal gated tool.** `save_skill` / `forget_skill` go through [tool approval](#tool-approval-and-autopilot) like any write — `ask-writes` asks a human first, `read-only` refuses, a `toolRules` entry can deny them.
545
+ - **No secrets.** Names, descriptions, instructions and sources are scanned for API keys, tokens, private keys and the like; a hit is refused to the model (and never stored). Sources keep origin and path only.
546
+ - **Yours stay yours.** A skill you configured is never overwritten or deleted by the agent; on a name clash yours wins. Caps: `maxSkills` (50), `maxSkillChars` (6000), a one-line description.
547
+ - **Provenance.** Each lesson records when it was written, by which run, its revision and — recorded by the harness, not by the model — the pages `web_fetch` read in that run.
548
+ - **Quiet by default for the rest.** Without `learning` there are no extra tools and not a word more in the prompts. `learning: { nudge: false }` keeps the tools but drops the guidance that tells the executor to write lessons down (and to look for a fix before giving up — with `egress` on, `web_fetch` can read the docs).
549
+
550
+ Every save emits `skill.learned` (`name`, `description`, `update`, `chars`, `sources`), every forget `skill.forgotten`. CLI: `AGENT_LEARNING=on`, `AGENT_LEARNING_DIR=<dir>`; in the REPL `/skills` lists skills (the agent's own marked) and `/forget <name>` deletes one.
551
+
496
552
  ## Autonomy
497
553
 
498
554
  The stage prompts are written for an agent that acts on its own:
@@ -576,7 +632,9 @@ Notes:
576
632
  interface IAgent {
577
633
  run(options: IAgentRunOptions): Promise<IAgentRunResult>
578
634
  listTools(): { name: string; description: string; server?: string; readOnly?: boolean }[]
579
- listSkills(): { name: string; description: string }[]
635
+ listSkills(): { name: string; description: string; learned?: true }[]
636
+ listLearnedSkills(): ISkill[] // the agent's own lessons, with origin (see Learning)
637
+ forgetSkill(name: string): Promise<boolean> // delete one of them; false if there is none
580
638
  compact(options: { history: IConversationTurn[]; signal?: AbortSignal; force?: boolean }): Promise<{
581
639
  history: IConversationTurn[]
582
640
  summary?: string
@@ -628,7 +686,7 @@ dd-agent --env-file=.env
628
686
 
629
687
  `--env-file=<path>` is loaded via Node's built-in `process.loadEnvFile`, so no `dotenv` dependency is needed. Without the flag the CLI reads the ambient process env. `-h` / `--help` prints the supported flags and the in-REPL slash commands (`/status`, `/tools`, `/history`, `/reset`, `/compact`, `/autopilot`, `/approval <mode>`, `/reconnect`, `/agents`, `/stop`, `/exit`).
630
688
 
631
- The newer features are env-driven too: `AGENT_THINKING` (`off | minimal | low | medium | high | xhigh | <budget tokens>`), `AGENT_MAX_INPUT_TOKENS` / `AGENT_MAX_OUTPUT_TOKENS` / `AGENT_MAX_REASONING_TOKENS` / `AGENT_MAX_TOTAL_TOKENS`, `AGENT_MAX_TOOL_CALLS`, `AGENT_TOOL_APPROVAL` (`autopilot | ask-writes | ask-all | read-only`), `AGENT_TOOL_RULES` (JSON `{ "<tool or glob*>": "allow" | "ask" | "deny" }`, beats the mode — e.g. `{"github__delete_*":"deny"}`), `AGENT_SKILLS_DIR`, `AGENT_TOOL_SELECTION_STRATEGY` (`auto | all | plan-narrowed | search`), `AGENT_CONTEXT_WINDOW_TOKENS` and `AGENT_COMPACTION=off`. The REPL prints the model's thoughts dimmed, auto-compacts its history with the same settings, and — when the approval mode asks — prompts `allow? [y]es / [n]o / [a]lways` right in the terminal; `/autopilot` toggles between autopilot and the last asking mode.
689
+ The newer features are env-driven too: `AGENT_THINKING` (`off | minimal | low | medium | high | xhigh | <budget tokens>`), `AGENT_MAX_INPUT_TOKENS` / `AGENT_MAX_OUTPUT_TOKENS` / `AGENT_MAX_REASONING_TOKENS` / `AGENT_MAX_TOTAL_TOKENS`, `AGENT_MAX_TOOL_CALLS`, `AGENT_TOOL_APPROVAL` (`autopilot | ask-writes | ask-all | read-only`), `AGENT_TOOL_RULES` (JSON `{ "<tool or glob*>": "allow" | "ask" | "deny" }`, beats the mode — e.g. `{"github__delete_*":"deny"}`), `AGENT_EGRESS` (`on | off`; with `AGENT_EGRESS_ALLOW`, `AGENT_EGRESS_DENY`, `AGENT_EGRESS_PROTOCOLS`, `AGENT_EGRESS_ALLOW_PRIVATE` — see [Egress](#egress-what-the-model-may-fetch)), `AGENT_SKILLS_DIR`, `AGENT_LEARNING` (`on | off`; `AGENT_LEARNING_DIR` keeps the lessons across sessions — see [Learning](#learning-lessons-that-outlive-the-task)), `AGENT_TOOL_SELECTION_STRATEGY` (`auto | all | plan-narrowed | search`), `AGENT_CONTEXT_WINDOW_TOKENS` and `AGENT_COMPACTION=off`. The REPL prints the model's thoughts dimmed, auto-compacts its history with the same settings, and — when the approval mode asks — prompts `allow? [y]es / [n]o / [a]lways` right in the terminal; `/autopilot` toggles between autopilot and the last asking mode.
632
690
 
633
691
  **Talking to the agent while it works.** The REPL keeps reading while a run goes. Text you type then is said to the running agent (it sees it at its next boundary and the replanner re-checks the plan — see [Steering a run](#steering-a-run-that-is-already-going)): the REPL prints `[you->agent] queued` and then `delivered (round|step|final)`, and the message enters the history as a user turn. A message that arrives while the answer is being written is sent as the next prompt (`[follow-up]`). After Ctrl-C nothing is sent behind your back: what the agent never saw is listed as `[not delivered]`. While a run goes, `/agents` lists the running subagents and `/stop <n>` (or an id prefix, or just `/stop` when one runs) stops one — the run goes on; the other REPL commands work between runs. Each subagent's own steps and tool calls are logged as `[name id] ...` lines, so parallel ones can be told apart.
634
692