Skip to content

Pass knowledge to a run without writing a file - #140

Open
DavertMik wants to merge 4 commits into
mainfrom
knowledge-as-option
Open

Pass knowledge to a run without writing a file#140
DavertMik wants to merge 4 commits into
mainfrom
knowledge-as-option

Conversation

@DavertMik

@DavertMik DavertMik commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

--knowledge takes facts on the command line and keeps them in memory for that run only, so credentials and one-off test data never land in knowledge/.

npx explorbot explore /pay --knowledge 'my credit card is 13213213213'

Plain text applies everywhere. Frontmatter scopes it the way a knowledge file does — url: for a page, endpoint: for an API endpoint — and the rest of the file grammar follows, including wait/waitForElement and ${env.VAR} interpolation:

npx explorbot explore / --knowledge '---
url: /login
---
Log in as admin@example.com / secret123'

The flag repeats, since gray-matter reads one frontmatter block per string, so several scoped facts need several flags.

How it works

It registers once on the program root, the way --ws does: one .option() plus a preAction hook, both in knowledge-tracker.ts beside the code that reads them. Commander merges parent options down through optsWithGlobals, so that single registration covers every command — the mounted api, docs and prima subcommands included — and the flag can sit anywhere on the line: before the command, after it, or after variadic arguments. Nothing in ExplorBot, Prima, DocBot or ApiBot carries a knowledge option; the three standalone boat bins get one registration line each.

KnowledgeTracker holds the parsed entries beside the ones it loads from disk and matches both through the same structural patterns — no new matching path. Its constructor takes an optional override, which is what the tests use and what keeps the module state a fallback rather than the only way in.

Session entries stay out of knows and listAllKnowledge, which report what is on disk. They do show in /context:knowledge, listed as --knowledge #1.

The API boat now reads knowledge

knowledge/ was never read at runtime by the API boat, so endpoint knowledge written by api know sat unused. Chief now loads it when planning an endpoint and Curler when testing one — which is what makes --knowledge useful for auth on the API side.

This changes behaviour for existing users: endpoint: files already on disk, and EXPLORBOT_KNOWLEDGE, now appear in Chief and Curler prompts where they previously did not.

Breaking: drill --knowledge renamed

explorbot drill --knowledge <path> is now --save-knowledge <path>, in the CLI and in the TUI (/drill --save-knowledge). It saves what drilling learned rather than supplying facts, and the two cannot share a flag on the same command.

Checks

bun test tests/unit (1084), tests/integration (80), boat/prima/tests (131), node --test tests/node/*.mjs (10), format and lint all pass. Eight new unit tests cover session parsing — no-frontmatter reaching every page and endpoint, url: and endpoint: scoping, several entries staying independent, frontmatter hints reaching getStateParameters, ${env.VAR} interpolation, nothing written to the knowledge directory — plus a round trip through the registered option proving the flag reaches a freshly built tracker.

This one is worth a regression run before merge — it changes what reaches Chief and Curler prompts on every API run.

🤖 Generated with Claude Code

DavertMik and others added 4 commits August 24, 2026 17:13
--knowledge takes facts on the command line and keeps them in memory for
that run only, so credentials and one-off test data never land in
knowledge/. Plain text applies everywhere; frontmatter scopes it the way
a knowledge file does - url: for a page, endpoint: for an API endpoint -
and the rest of the file grammar follows, including wait/waitForElement
and ${env.VAR} interpolation. The flag repeats, since gray-matter reads
one frontmatter block per string.

KnowledgeTracker holds session entries beside the ones it loads from
disk and matches both through the same structural patterns. Its
constructor now takes an options object, which lets the API boat point
it at its own knowledge directory without a loaded web ConfigParser.

That directory was never read at runtime before, so endpoint knowledge
written by `api know` sat unused. Chief now loads it when planning an
endpoint and Curler when testing one, which is what makes --knowledge
useful for auth on the API side.

drill's --knowledge <path> becomes --save-knowledge <path>, in the CLI
and in the TUI. It saves what drilling learned rather than supplying
facts, and the two cannot share a flag on the same command.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The flag was threaded through four option interfaces, four buildOptions
functions and four addCommonOptions helpers to reach a tracker that
already knew what to do with it. It now registers on the program the way
--ws does: one option plus a preAction hook, both living in
knowledge-tracker.ts beside the code that reads them.

Commander merges parent options down through optsWithGlobals, so one
registration covers every command, the mounted api/docs/prima
subcommands included, and the flag can sit anywhere on the line -
before the command, after it, or after variadic arguments.

Prima, doc-collector and the api CLI go back to what they were; ExplorBot
no longer carries a knowledge option at all. The constructor still takes
one, which is what the tests use and what makes the module state a
fallback rather than the only way in.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant