@falkenslab/agent-kit 0.14.0 → 0.16.0

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.
Files changed (70) hide show
  1. package/README.md +110 -110
  2. package/assets/knowledge-plugin/.claude-plugin/plugin.json +1 -1
  3. package/assets/knowledge-plugin/commands/ingest.md +1 -1
  4. package/assets/knowledge-plugin/commands/lint.md +1 -1
  5. package/assets/knowledge-plugin/skills/knowledge-ingest/SKILL.md +13 -19
  6. package/assets/knowledge-plugin/skills/knowledge-lint/SKILL.md +18 -14
  7. package/assets/knowledge-plugin/skills/knowledge-query/SKILL.md +5 -5
  8. package/assets/knowledge-plugin-files/.claude-plugin/plugin.json +4 -0
  9. package/assets/knowledge-plugin-files/commands/ingest.md +7 -0
  10. package/assets/knowledge-plugin-files/commands/lint.md +5 -0
  11. package/assets/knowledge-plugin-files/commands/query.md +5 -0
  12. package/assets/knowledge-plugin-files/skills/knowledge-ingest/SKILL.md +46 -0
  13. package/assets/knowledge-plugin-files/skills/knowledge-lint/SKILL.md +26 -0
  14. package/assets/knowledge-plugin-files/skills/knowledge-query/SKILL.md +14 -0
  15. package/dist/core/agentSpec.d.ts +27 -2
  16. package/dist/core/extractText.d.ts +13 -0
  17. package/dist/core/extractText.js +147 -0
  18. package/dist/core/fileKnowledgeStore.d.ts +10 -0
  19. package/dist/core/fileKnowledgeStore.js +378 -0
  20. package/dist/core/hooks/fileScopeGate.d.ts +8 -0
  21. package/dist/core/hooks/fileScopeGate.js +20 -0
  22. package/dist/core/hooks/humanInput.d.ts +18 -0
  23. package/dist/core/hooks/humanInput.js +30 -2
  24. package/dist/core/hooks/planGate.js +14 -5
  25. package/dist/core/hooks/stepGate.js +6 -0
  26. package/dist/core/interaction.d.ts +20 -0
  27. package/dist/core/knowledge.d.ts +14 -4
  28. package/dist/core/knowledge.js +36 -6
  29. package/dist/core/knowledgeStore.d.ts +134 -0
  30. package/dist/core/knowledgeStore.js +84 -0
  31. package/dist/core/messages/de.js +65 -0
  32. package/dist/core/messages/en.d.ts +41 -0
  33. package/dist/core/messages/en.js +65 -0
  34. package/dist/core/messages/es.js +65 -0
  35. package/dist/core/messages/fr.js +65 -0
  36. package/dist/core/modeControl.d.ts +36 -0
  37. package/dist/core/modeControl.js +61 -0
  38. package/dist/core/session.d.ts +6 -31
  39. package/dist/core/session.js +76 -71
  40. package/dist/core/sources.d.ts +122 -0
  41. package/dist/core/sources.js +312 -0
  42. package/dist/core/todos.d.ts +23 -0
  43. package/dist/core/todos.js +33 -0
  44. package/dist/core/toolLabels.d.ts +1 -1
  45. package/dist/core/toolLabels.js +42 -2
  46. package/dist/core/tools/humanApproval.d.ts +9 -5
  47. package/dist/core/tools/humanApproval.js +39 -7
  48. package/dist/core/tools/knowledgeTools.d.ts +16 -0
  49. package/dist/core/tools/knowledgeTools.js +161 -0
  50. package/dist/core/tools/saveToSources.d.ts +27 -8
  51. package/dist/core/tools/saveToSources.js +203 -55
  52. package/dist/core/tools/time.d.ts +29 -0
  53. package/dist/core/tools/time.js +129 -0
  54. package/dist/index.d.ts +7 -4
  55. package/dist/index.js +4 -1
  56. package/dist/tui/chatTui.js +14 -1
  57. package/dist/tui/consoleRenderer.js +16 -2
  58. package/dist/tui/ink/SessionView.js +72 -17
  59. package/dist/tui/ink/inkInteraction.d.ts +4 -2
  60. package/dist/tui/ink/inkInteraction.js +20 -2
  61. package/dist/tui/ink/progressView.d.ts +5 -1
  62. package/dist/tui/ink/runChatInk.d.ts +16 -1
  63. package/dist/tui/ink/runChatInk.js +7 -0
  64. package/dist/tui/ink/sessionModel.d.ts +10 -3
  65. package/dist/tui/ink/sessionModel.js +26 -4
  66. package/dist/tui/ink/toolGroup.d.ts +23 -2
  67. package/dist/tui/ink/toolGroup.js +17 -4
  68. package/dist/tui/terminalInteraction.js +2 -0
  69. package/package.json +31 -1
  70. /package/assets/{knowledge-plugin → knowledge-plugin-files}/skills/knowledge-pages/SKILL.md +0 -0
package/README.md CHANGED
@@ -1,110 +1,110 @@
1
- <h1>
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-readme-dark.svg">
4
- <img src="docs/assets/logo-readme.svg" alt="agent-kit" height="64">
5
- </picture>
6
- </h1>
7
-
8
- [![npm](https://img.shields.io/npm/v/@falkenslab/agent-kit?logo=npm)](https://www.npmjs.com/package/@falkenslab/agent-kit)
9
- [![npm downloads](https://img.shields.io/npm/dm/@falkenslab/agent-kit)](https://www.npmjs.com/package/@falkenslab/agent-kit)
10
- [![types](https://img.shields.io/npm/types/@falkenslab/agent-kit)](https://www.npmjs.com/package/@falkenslab/agent-kit)
11
- [![node](https://img.shields.io/node/v/@falkenslab/agent-kit)](https://nodejs.org/)
12
- [![license](https://img.shields.io/npm/l/@falkenslab/agent-kit)](LICENSE)
13
- [![docs](https://img.shields.io/badge/docs-falkenslab.github.io%2Fagent--kit-4453b8)](https://falkenslab.github.io/agent-kit/)
14
-
15
- A foundation for building AI agents on top of the [Claude Agent SDK](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk). It isn't an agent itself: it solves once what every agent needs (human oversight, safety, memory and a good terminal interface), so each concrete agent only has to write what belongs to its own domain: what it knows how to do, with which tools, and how it talks.
16
-
17
- ## What an agent built with it can do
18
-
19
- - **Work at different levels of oversight.** Autonomous, guided (it asks for permission before anything that can't be undone or that other people will see) or step by step (it asks before every action), and a plan mode where it only reads and plans until you let it act. Within the same conversation you can switch among guided, step by step and plan.
20
- - **Ask a person for help.** It asks for approvals, or stops so someone can do something by hand, such as signing in to a website. It can be answered from the keyboard or from another program driving it, for example a desktop app.
21
- - **Remember between sessions.** It keeps its own knowledge base, a small wiki of notes that grows with every session, and keeps the original documents you give it or that it downloads untouched. Each conversation stays in the project's folder, so you can pick it up again with `--continue` (the latest one) or `/resume` (any of them).
22
- - **Speak your language.** Its interface comes in English, Spanish, French or German, the system's by default or the one you ask for with `--language=fr`, and it answers in that language unless you write to it in another one.
23
- - **Delegate to subagents safely.** Only to the ones it declares, always waiting for their result, and without the main agent being able to slip past its own limits through them.
24
- - **Stay within limits.** It only reads and writes in the folders that belong to it, and never in protected files, such as one holding passwords.
25
- - **Use external tools.** MCP servers of its own or of the project, and skills and commands organized in plugins.
26
- - **Leave a trail.** It records every action and the whole conversation, with secrets hidden.
27
- - **Look the way you want.** The terminal's colors come from a theme by roles (the agent's replies, tool results, the focused option, borders…): pass only the ones you want to change, as a color name, a hex or a function.
28
- - **Chat in a terminal the way Claude Code does.** Full screen, with the reply written live and its markdown already formatted, the tools it uses summed up in one line (Ctrl+O unfolds it), panels for approvals, history and search, a suggestion for the next message, pasted blocks, file mentions with `@`, mouse selection (right-click to copy), and the agent's status in the tab and in the Windows taskbar.
29
- - **Also work without a terminal.** The same foundation runs inside a desktop app or a server, which bring their own interface.
30
-
31
- ## Examples
32
-
33
- ### Captain Whiskers
34
-
35
- [Captain Whiskers](./examples/captain-whiskers) is a toy agent to see the kit in action: a retired pirate cat who tells jokes in the terminal, in your language. It starts full screen with its logo and has a small crew of subagents: one looks for new jokes on the web, another rates them before they're told, and a third tells the time with a tool of the captain's own. It lets you try the different levels of oversight and is the best starting point for an agent of your own. Its README explains how to run it.
36
-
37
- ![Captain Whiskers in Windows Terminal: its logo at the top, the conversation in the middle and the framed prompt at the bottom, with a suggestion for the next message](docs/assets/captain-whiskers.png)
38
-
39
- ### teacher-agent
40
-
41
- [teacher-agent](https://github.com/falkenslab/teacher-agent) is a real assistant for Moodle teachers. It signs in with your account in a Chrome window and works as you would: it grades submissions, answers in the forum, creates or reviews content and sums up how the class is going. It asks for your permission before publishing anything students will see, and takes notes about the course to remember everything in the next session.
42
-
43
- Oversight, memory, safety and the chat come from the kit; teacher-agent brings what it knows about Moodle and driving the browser.
44
-
45
- ## Installation
46
-
47
- ```
48
- npm install @falkenslab/agent-kit
49
- ```
50
-
51
- To try changes to the kit without publishing them, point to a local clone with `"file:../agent-kit"` in your `package.json` and build it with `npm run build` after each change.
52
-
53
- Requires Node.js 20 or later.
54
-
55
- ## A minimal agent
56
-
57
- An agent only describes what belongs to it (who it is, which MCP servers, skills and subagents it has) and picks a level of oversight; the kit sets up the session and the chat:
58
-
59
- ```ts
60
- import path from "node:path";
61
- import { buildSessionOptions, ensureClaudeAuth, runChatInk, type AgentSpec, type BaseSessionConfig } from "@falkenslab/agent-kit";
62
-
63
- // The only part specific to the agent: who it is and what it has.
64
- const spec: AgentSpec<BaseSessionConfig> = {
65
- buildSystemPrompt: () => "You are a pirate cat who tells jokes. Always answer in character.",
66
- buildMcpServers: () => ({}), // its own MCP servers, if any
67
- pluginRoots: () => [], // folders with skills and commands
68
- buildSubagents: () => undefined, // subagents, if it delegates to any
69
- };
70
-
71
- await ensureClaudeAuth(); // offers to create a Claude token if it finds none
72
-
73
- const config: BaseSessionConfig = { mode: "guided", projectDir: process.cwd() };
74
-
75
- // Each run gets a folder of its own under .run/ (keep it out of git): its log, its
76
- // transcript and the conversation, to pick it up again with --continue or /resume.
77
- await runChatInk((run) => buildSessionOptions(config, run.dir, spec, { run }), {
78
- runsDir: path.resolve(".run"),
79
- header: { title: "My agent" },
80
- mode: config.mode, // Shift+Tab cycles through guided, step by step and plan
81
- fullscreen: true,
82
- theme: { toolResult: "gray", selection: "#ffb86c" }, // only the colors you want to change
83
- });
84
- ```
85
-
86
- Save it as `agent.ts` in a project with the kit and `tsx` installed and `"type": "module"` in its `package.json`, and run it with `npx tsx agent.ts`. Captain Whiskers is this same skeleton with more pieces: skills, subagents and its logo.
87
-
88
- ## Documentation
89
-
90
- The full documentation is at **[falkenslab.github.io/agent-kit](https://falkenslab.github.io/agent-kit/)**: a tutorial, guides for every part of the kit (modes, human in the loop, security, tools, subagents, the knowledge base, the terminal UI, runs, languages, themes, hosts without a terminal), recipes, and an API reference generated from the source, for each released version.
91
-
92
- For whoever works on the kit itself, the specification in [`.minispec/`](./.minispec/README.md) explains how each part is built and why, including the SDK behaviors checked by hand that motivate several of its safeguards.
93
-
94
- ## Development
95
-
96
- | Command | What it does |
97
- | --- | --- |
98
- | `npm run build` | Builds the kit into `dist/` |
99
- | `npm run typecheck` | Checks the types without building |
100
- | `npm run lint` | Checks the code style |
101
- | `npm test` | Runs all the tests |
102
- | `npm run docs:install` | Installs the documentation site's dependencies (once) |
103
- | `npm run docs:start` | Serves the documentation site locally, reloading on changes |
104
- | `npm run docs:build` | Builds the documentation site (fails on broken links) |
105
-
106
- To run a single test file:
107
-
108
- ```
109
- npx tsx --test test/tui/promptErrors.test.ts
110
- ```
1
+ <h1>
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-readme-dark.svg">
4
+ <img src="docs/assets/logo-readme.svg" alt="agent-kit" height="64">
5
+ </picture>
6
+ </h1>
7
+
8
+ [![npm](https://img.shields.io/npm/v/@falkenslab/agent-kit?logo=npm)](https://www.npmjs.com/package/@falkenslab/agent-kit)
9
+ [![npm downloads](https://img.shields.io/npm/dm/@falkenslab/agent-kit)](https://www.npmjs.com/package/@falkenslab/agent-kit)
10
+ [![types](https://img.shields.io/npm/types/@falkenslab/agent-kit)](https://www.npmjs.com/package/@falkenslab/agent-kit)
11
+ [![node](https://img.shields.io/node/v/@falkenslab/agent-kit)](https://nodejs.org/)
12
+ [![license](https://img.shields.io/npm/l/@falkenslab/agent-kit)](LICENSE)
13
+ [![docs](https://img.shields.io/badge/docs-falkenslab.github.io%2Fagent--kit-4453b8)](https://falkenslab.github.io/agent-kit/)
14
+
15
+ A foundation for building AI agents on top of the [Claude Agent SDK](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk). It isn't an agent itself: it solves once what every agent needs (human oversight, safety, memory and a good terminal interface), so each concrete agent only has to write what belongs to its own domain: what it knows how to do, with which tools, and how it talks.
16
+
17
+ ## What an agent built with it can do
18
+
19
+ - **Work at different levels of oversight.** Autonomous, guided (it asks for permission before anything that can't be undone or that other people will see) or step by step (it asks before every action), and a plan mode where it only reads and plans until you let it act. Within the same conversation you can switch among guided, step by step and plan.
20
+ - **Ask a person for help.** It asks for approvals, or stops so someone can do something by hand, such as signing in to a website. It can be answered from the keyboard or from another program driving it, for example a desktop app.
21
+ - **Remember between sessions.** It keeps its own knowledge base, a small wiki of notes that grows with every session, and keeps the original documents you give it or that it downloads untouched. Each conversation stays in the project's folder, so you can pick it up again with `--continue` (the latest one) or `/resume` (any of them).
22
+ - **Speak your language.** Its interface comes in English, Spanish, French or German, the system's by default or the one you ask for with `--language=fr`, and it answers in that language unless you write to it in another one.
23
+ - **Delegate to subagents safely.** Only to the ones it declares, always waiting for their result, and without the main agent being able to slip past its own limits through them.
24
+ - **Stay within limits.** It only reads and writes in the folders that belong to it, and never in protected files, such as one holding passwords.
25
+ - **Use external tools.** MCP servers of its own or of the project, and skills and commands organized in plugins.
26
+ - **Leave a trail.** It records every action and the whole conversation, with secrets hidden.
27
+ - **Look the way you want.** The terminal's colors come from a theme by roles (the agent's replies, tool results, the focused option, borders…): pass only the ones you want to change, as a color name, a hex or a function.
28
+ - **Chat in a terminal the way Claude Code does.** Full screen, with the reply written live and its markdown already formatted, the tools it uses shown in as much detail as the agent chooses (each call with its result, the calls alone, or one line per group; Ctrl+O unfolds them), panels for approvals, history and search, a suggestion for the next message, pasted blocks, file mentions with `@`, mouse selection (right-click to copy), and the agent's status in the tab and in the Windows taskbar.
29
+ - **Also work without a terminal.** The same foundation runs inside a desktop app or a server, which bring their own interface.
30
+
31
+ ## Examples
32
+
33
+ ### Captain Whiskers
34
+
35
+ [Captain Whiskers](./examples/captain-whiskers) is a toy agent to see the kit in action: a retired pirate cat who tells jokes in the terminal, in your language. It starts full screen with its logo and has a small crew of subagents: one looks for new jokes on the web, another rates them before they're told, and a third tells the time with a tool of the captain's own. It lets you try the different levels of oversight and is the best starting point for an agent of your own. Its README explains how to run it.
36
+
37
+ ![Captain Whiskers in Windows Terminal: its logo at the top, the conversation in the middle and the framed prompt at the bottom, with a suggestion for the next message](docs/assets/captain-whiskers.png)
38
+
39
+ ### teacher-agent
40
+
41
+ [teacher-agent](https://github.com/falkenslab/teacher-agent) is a real assistant for Moodle teachers. It signs in with your account in a Chrome window and works as you would: it grades submissions, answers in the forum, creates or reviews content and sums up how the class is going. It asks for your permission before publishing anything students will see, and takes notes about the course to remember everything in the next session.
42
+
43
+ Oversight, memory, safety and the chat come from the kit; teacher-agent brings what it knows about Moodle and driving the browser.
44
+
45
+ ## Installation
46
+
47
+ ```
48
+ npm install @falkenslab/agent-kit
49
+ ```
50
+
51
+ To try changes to the kit without publishing them, point to a local clone with `"file:../agent-kit"` in your `package.json` and build it with `npm run build` after each change.
52
+
53
+ Requires Node.js 20 or later.
54
+
55
+ ## A minimal agent
56
+
57
+ An agent only describes what belongs to it (who it is, which MCP servers, skills and subagents it has) and picks a level of oversight; the kit sets up the session and the chat:
58
+
59
+ ```ts
60
+ import path from "node:path";
61
+ import { buildSessionOptions, ensureClaudeAuth, runChatInk, type AgentSpec, type BaseSessionConfig } from "@falkenslab/agent-kit";
62
+
63
+ // The only part specific to the agent: who it is and what it has.
64
+ const spec: AgentSpec<BaseSessionConfig> = {
65
+ buildSystemPrompt: () => "You are a pirate cat who tells jokes. Always answer in character.",
66
+ buildMcpServers: () => ({}), // its own MCP servers, if any
67
+ pluginRoots: () => [], // folders with skills and commands
68
+ buildSubagents: () => undefined, // subagents, if it delegates to any
69
+ };
70
+
71
+ await ensureClaudeAuth(); // offers to create a Claude token if it finds none
72
+
73
+ const config: BaseSessionConfig = { mode: "guided", projectDir: process.cwd() };
74
+
75
+ // Each run gets a folder of its own under .run/ (keep it out of git): its log, its
76
+ // transcript and the conversation, to pick it up again with --continue or /resume.
77
+ await runChatInk((run) => buildSessionOptions(config, run.dir, spec, { run }), {
78
+ runsDir: path.resolve(".run"),
79
+ header: { title: "My agent" },
80
+ mode: config.mode, // Shift+Tab cycles through guided, step by step and plan
81
+ fullscreen: true,
82
+ theme: { toolResult: "gray", selection: "#ffb86c" }, // only the colors you want to change
83
+ });
84
+ ```
85
+
86
+ Save it as `agent.ts` in a project with the kit and `tsx` installed and `"type": "module"` in its `package.json`, and run it with `npx tsx agent.ts`. Captain Whiskers is this same skeleton with more pieces: skills, subagents and its logo.
87
+
88
+ ## Documentation
89
+
90
+ The full documentation is at **[falkenslab.github.io/agent-kit](https://falkenslab.github.io/agent-kit/)**: a tutorial, guides for every part of the kit (modes, human in the loop, security, tools, subagents, the knowledge base, the terminal UI, runs, languages, themes, hosts without a terminal), recipes, and an API reference generated from the source, for each released version.
91
+
92
+ For whoever works on the kit itself, the specification in [`.minispec/`](./.minispec/README.md) explains how each part is built and why, including the SDK behaviors checked by hand that motivate several of its safeguards.
93
+
94
+ ## Development
95
+
96
+ | Command | What it does |
97
+ | --- | --- |
98
+ | `npm run build` | Builds the kit into `dist/` |
99
+ | `npm run typecheck` | Checks the types without building |
100
+ | `npm run lint` | Checks the code style |
101
+ | `npm test` | Runs all the tests |
102
+ | `npm run docs:install` | Installs the documentation site's dependencies (once) |
103
+ | `npm run docs:start` | Serves the documentation site locally, reloading on changes |
104
+ | `npm run docs:build` | Builds the documentation site (fails on broken links) |
105
+
106
+ To run a single test file:
107
+
108
+ ```
109
+ npx tsx --test test/tui/promptErrors.test.ts
110
+ ```
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "knowledge",
3
- "description": "Built-in knowledge base workflows (an LLM wiki): page templates, ingesting sources, querying the knowledge base and health-checking it."
3
+ "description": "Built-in knowledge base workflows (an LLM wiki) over the kit's knowledge_* tools: ingesting sources, querying the knowledge base and health-checking it."
4
4
  }
@@ -4,4 +4,4 @@ description: Ingest material into the knowledge base right now - the files or to
4
4
 
5
5
  Apply the `knowledge-ingest` skill right now to: $ARGUMENTS
6
6
 
7
- If nothing is given above, find every file in the sources folder that has no summary page in the knowledge base yet (check `index.md` and `summaries/`) and ingest them all. When you're done, summarize which pages you created and updated, and anything you couldn't read.
7
+ If nothing is given above, ingest every original `list_sources` reports as new, and update the summaries of the ones it reports as changed. When you're done, summarize which pages you created and updated, and anything you couldn't read.
@@ -2,4 +2,4 @@
2
2
  description: Health-check the knowledge base right now - broken links, orphans, duplicates, contradictions, gaps
3
3
  ---
4
4
 
5
- Apply the `knowledge-lint` skill right now over the whole knowledge base. Fix what's mechanical (links, index, missing back-links) and report the rest: what needs the human's decision, and the gaps worth filling next.
5
+ Apply the `knowledge-lint` skill right now over the whole knowledge base. Fix what's mechanical (broken links, orphans, links to retired pages) and report the rest: what needs the human's decision, and the gaps worth filling next.
@@ -1,42 +1,36 @@
1
1
  ---
2
2
  name: knowledge-ingest
3
- description: Ingest one source into the knowledge base - a file in sources/, a document, a page - creating its summary page, creating or updating the concept and entity pages it touches, linking everything both ways, and updating index.md and log.md.
3
+ description: Ingest one source into the knowledge base - an original in sources/, a document, a page - creating its summary page, creating or updating the concept and entity pages it touches, and logging it.
4
4
  ---
5
5
 
6
6
  # Ingesting a source into the knowledge base
7
7
 
8
- A source is ingested once, and from then on the knowledge base holds what it taught: later sessions read the pages, not the original again. Ingesting is not summarizing a file in isolation - its value is in how it connects to what the knowledge base already knows. Load the `knowledge-pages` skill first for the page templates.
8
+ A source is ingested once, and from then on the knowledge base holds what it taught: later sessions read the pages, not the original again. Its value is in how it connects to what the knowledge base already knows. Work only through the `knowledge_*` tools; links between pages are ids, `[Bowline](concept/bowline)`, and the index and backlinks are kept for you.
9
9
 
10
10
  ## 1. Check it isn't already ingested
11
11
 
12
- Look for it in `index.md` (Summaries) or `Grep` its file name or URL inside the knowledge base. If it already has a page:
13
- - unchanged source: nothing to do;
14
- - the source changed or the page is thin: update that page instead of creating another.
12
+ `list_sources` gives each original's status and summary pages: *new* needs ingesting; *ingested* has a page; *changed* changed after its ingest (update its summary). For a document from elsewhere, `knowledge_search` its title or URL.
15
13
 
16
14
  ## 2. Read it for real
17
15
 
18
- Read the whole source, not its first page. If it exists only outside the sources folder (a downloaded document, a remote file), save it with `save_to_sources` first, so the original is kept as obtained.
16
+ Read the whole source, not its first page (a long PDF in parts: `list_sources` gives its pages). Its path is `sources/<path>` in the project folder, not in this skill's folder. `Read` reads PDFs and images; `extract_text` reads DOCX, PPTX (with its speaker notes) and XLSX. If it exists only outside the sources folder, keep the original first: `download_to_sources` for a URL (a web page is kept as markdown too: read that one), `save_to_sources` for a file in the run's folder, `request_file` to ask the person for one.
19
17
 
20
18
  ## 3. Write the summary page
21
19
 
22
- Create `summaries/<slug>.md` with the template: summary, key points (literal wording where exactness matters), frontmatter `file`/`url` pointing to the original.
20
+ `knowledge_create` with type `summary` (call it once without content to get the template), and the field `file` (the original, relative to sources/) or `url`. Key points quote literally where exactness matters. Create the new concept and entity pages it feeds in the same call (`also`): they can link to each other.
23
21
 
24
22
  ## 4. Update concepts and entities
25
23
 
26
- For every concept or entity the source explains or relies on:
27
- - no page yet: create it;
28
- - page exists: add what is new (a better definition, an example, a nuance, a fact) with `Edit`, and link the summary under "Sources".
24
+ For every concept or entity the source explains or relies on, `knowledge_search` it first (under other names and aliases too: a duplicate page is worse than none):
25
+ - no page yet: create it, with the summary (`also`) or on its own;
26
+ - page exists: add what is new (a better definition, an example, a nuance) with `knowledge_edit`, and link the summary under its sources.
29
27
 
30
- Check first whether it exists under another name (`Grep` the knowledge base for the term and look at `aliases`): a duplicate page is worse than none.
28
+ If the source contradicts a page, record both versions with attribution in both pages; don't overwrite.
31
29
 
32
- ## 5. Link both ways and look for conflicts
30
+ ## 5. Close
33
31
 
34
- Every link you added from page A to page B needs its counterpart in B. If the source contradicts an existing page, record both versions with attribution in both pages - don't overwrite.
32
+ `knowledge_log` with operation `ingest`, the source's title and the pages created and updated. Rewrite the `overview` (`knowledge_rewrite`) only if the source changes the big picture. When ingesting several sources in a row, log once at the end.
35
33
 
36
- ## 6. Close
34
+ ## An original that was wrong or replaced
37
35
 
38
- - `index.md`: new pages, and one-line descriptions that changed.
39
- - `log.md`: `## [date] ingest | <source title>` with the pages created and updated.
40
- - `overview.md`: only if the source changes the big picture.
41
-
42
- When ingesting several sources in a row, do steps 1-5 for each and close once at the end.
36
+ `retire_source` (the person approves it) moves it aside and marks its summary retired (wrong) or superseded (replaced). Then `knowledge_check` lists the passages that cite it: after a wrong one, correct or remove what it taught (`knowledge_edit`, or `knowledge_retire` for a page that was only about it); after a replaced one, ingest the new original and re-ground those passages on it.
@@ -1,26 +1,30 @@
1
1
  ---
2
2
  name: knowledge-lint
3
- description: Health-check the knowledge base - broken links, pages missing from index.md, orphan pages, one-way links, duplicated concepts, mentioned-but-missing concepts, contradictions, gaps - fix what's mechanical and report the rest.
3
+ description: Health-check the knowledge base - broken links, orphan pages, links to retired pages, missing or changed originals, duplicated concepts, mentioned-but-missing concepts, contradictions, gaps - fix what's mechanical and report the rest.
4
4
  ---
5
5
 
6
6
  # Linting the knowledge base
7
7
 
8
- A knowledge base maintained across sessions drifts: links break, pages go unlisted, the same concept appears under two names. Lint it when asked and after a large ingest. Load `knowledge-pages` first for the templates.
8
+ A knowledge base maintained across sessions drifts. Lint it when asked and after a large ingest.
9
9
 
10
- ## Checks
10
+ ## 1. The mechanical checks, in one call
11
11
 
12
- Use `Glob` to list pages and `Grep` (always with `path` inside the knowledge base) to find links, instead of reading every page in full.
12
+ `knowledge_check` returns broken links, orphan pages, links to retired pages, summaries whose original is gone, originals that are new, changed or missing, and the passages that cite a retired original. The index and backlinks are kept by the store: there's nothing to fix there.
13
13
 
14
- 1. **Broken links**: a relative link whose target file doesn't exist. Fix it if the right target is obvious (a typo, a page under a close name); otherwise report it.
15
- 2. **Index**: every page is listed in `index.md` and every entry there points to an existing page. Fix it.
16
- 3. **Orphans**: pages nothing links to (`Grep` for the file name). Link them from where they belong, or report why they don't belong anywhere.
17
- 4. **One-way links**: a summary that feeds a concept which doesn't list it back... Add the missing side.
18
- 5. **Duplicates**: two pages for the same idea under different names. Merge the content into one, mark the other as superseded (never delete it) and repoint links.
19
- 6. **Missing pages**: terms that several pages treat as concepts or entities but have no page. Create them if the material is there; otherwise list them.
20
- 7. **Contradictions**: claims that disagree across pages without being recorded as such. Record both sides, attributed.
21
- 8. **Provenance**: claims with no traceable source. Add the link, or mark them as unsourced.
22
- 9. **Gaps**: files in the sources folder with no summary page yet, concepts mentioned but never explained by any source. Report them - they are what to ingest or find next.
14
+ - **Broken links**: fix them with `knowledge_edit` when the right target is obvious (a typo, a page under a close name: `knowledge_search`); otherwise report them.
15
+ - **Orphans**: link them from the pages where they belong, or report why they don't belong anywhere.
16
+ - **Links to retired pages, passages citing a retired original**: correct or re-ground them.
17
+ - **New or changed originals**: report them as what to ingest or update next (or do it, if asked).
18
+
19
+ ## 2. The checks that need judgement
20
+
21
+ Use `knowledge_index` and `knowledge_search`; read only the pages a check needs.
22
+
23
+ - **Duplicates**: two pages for the same idea under different names. Merge the content into one with `knowledge_edit`, `knowledge_supersede` the other (never delete it) and repoint links.
24
+ - **Missing pages**: terms that several pages treat as concepts or entities but have no page. Create them if the material is there; otherwise list them.
25
+ - **Contradictions**: claims that disagree across pages without being recorded as such. Record both sides, attributed.
26
+ - **Provenance**: claims with no traceable source. Add the link, or mark them as unsourced.
23
27
 
24
28
  ## Close
25
29
 
26
- Append `## [date] lint | <summary>` to `log.md` listing what was fixed. Then report to the human: what you fixed, and what needs their decision or more material. Don't make judgement calls silently - merging pages that are only similar, or choosing between contradictory sources, goes in the report.
30
+ `knowledge_log` with operation `lint` and what was fixed. Then report to the person: what you fixed, and what needs their decision or more material. Don't make judgement calls silently: merging pages that are only similar, or choosing between contradictory sources, goes in the report.
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  name: knowledge-query
3
- description: Answer a question from the knowledge base - find the relevant pages through the index, read them, answer with links to them, and file the answer back as a synthesis page when it is worth keeping.
3
+ description: Answer a question from the knowledge base - find the relevant pages, read them, answer citing them, and file the answer back as a synthesis page when it is worth keeping.
4
4
  ---
5
5
 
6
6
  # Querying the knowledge base
7
7
 
8
8
  The knowledge base exists so a question doesn't start from zero. Answer from it first; go back to the originals or the web only for what it doesn't hold.
9
9
 
10
- 1. **Start from the index.** Read `index.md`, pick the pages that can matter, read those (not the whole knowledge base). `Grep` inside the knowledge base for terms and aliases the index doesn't reveal.
11
- 2. **Answer from the pages**, linking each one you drew on. Say what comes from the knowledge base, what comes from an original in the sources folder (read it if the knowledge base is thin or contradictory) and what comes from outside (label it as such).
10
+ 1. **Find the pages.** `knowledge_search` the question's terms (and their synonyms), or `knowledge_index` for the catalog; `knowledge_read` only the pages that matter.
11
+ 2. **Answer from the pages**, citing each one you drew on. Say what comes from the knowledge base, what from an original in the sources folder (read it if the knowledge base is thin or contradictory) and what from outside (label it as such).
12
12
  3. **Say what is missing.** If the knowledge base can't answer part of the question, say so and name the source that would fill it, instead of filling the gap from memory silently.
13
- 4. **File it back.** If the answer is a comparison, an analysis or a report that will be asked again, save it as `syntheses/<slug>.md` (template in `knowledge-pages`) with links to its inputs, add it to `index.md`, and log it: `## [date] query | <question>`. A quick factual answer needs no page.
14
- 5. **Feed the knowledge base.** If answering revealed a concept or fact that has no page, or a contradiction, fix that in the knowledge base too and log it.
13
+ 4. **File it back.** If the answer is a comparison, an analysis or a report that will be asked again, `knowledge_create` a `synthesis` page with links to its inputs, and `knowledge_log` it (operation `query`). A quick factual answer needs no page.
14
+ 5. **Feed the knowledge base.** If answering revealed a concept with no page, or a contradiction, fix that too and log it.
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "knowledge",
3
+ "description": "Built-in knowledge base workflows (an LLM wiki): page templates, ingesting sources, querying the knowledge base and health-checking it."
4
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ description: Ingest material into the knowledge base right now - the files or topic given, or everything in sources/ not ingested yet
3
+ ---
4
+
5
+ Apply the `knowledge-ingest` skill right now to: $ARGUMENTS
6
+
7
+ If nothing is given above, ingest every original `list_sources` reports as new, and update the summaries of the ones it reports as changed. When you're done, summarize which pages you created and updated, and anything you couldn't read.
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Health-check the knowledge base right now - broken links, orphans, duplicates, contradictions, gaps
3
+ ---
4
+
5
+ Apply the `knowledge-lint` skill right now over the whole knowledge base. Fix what's mechanical (links, index, missing back-links) and report the rest: what needs the human's decision, and the gaps worth filling next.
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Answer a question from the knowledge base, and file the answer back if it is worth keeping
3
+ ---
4
+
5
+ Apply the `knowledge-query` skill right now to answer: $ARGUMENTS
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: knowledge-ingest
3
+ description: Ingest one source into the knowledge base - a file in sources/, a document, a page - creating its summary page, creating or updating the concept and entity pages it touches, linking everything both ways, and updating index.md and log.md.
4
+ ---
5
+
6
+ # Ingesting a source into the knowledge base
7
+
8
+ A source is ingested once, and from then on the knowledge base holds what it taught: later sessions read the pages, not the original again. Ingesting is not summarizing a file in isolation - its value is in how it connects to what the knowledge base already knows. Load the `knowledge-pages` skill first for the page templates.
9
+
10
+ ## 1. Check it isn't already ingested
11
+
12
+ `list_sources` gives each original's status and summary pages: *new* needs ingesting; *ingested* has a page; *changed* changed after its ingest. For a document from elsewhere, look for it in `index.md` (Summaries) or `Grep` its URL inside the knowledge base. If it already has a page:
13
+ - unchanged source: nothing to do;
14
+ - the source changed or the page is thin: update that page instead of creating another.
15
+
16
+ ## 2. Read it for real
17
+
18
+ Read the whole source, not its first page (a long PDF in parts: `list_sources` gives its pages). If it exists only outside the sources folder, keep the original first: `download_to_sources` for a URL (a web page is kept as markdown too: read that one), `save_to_sources` for a file in the run's folder, `request_file` to ask the person for one. `Read` reads PDFs and images; read DOCX, PPTX (with its speaker notes) and XLSX with `extract_text`.
19
+
20
+ ## 3. Write the summary page
21
+
22
+ Create `summaries/<slug>.md` with the template: summary, key points (literal wording where exactness matters), frontmatter `file`/`url` pointing to the original.
23
+
24
+ ## 4. Update concepts and entities
25
+
26
+ For every concept or entity the source explains or relies on:
27
+ - no page yet: create it;
28
+ - page exists: add what is new (a better definition, an example, a nuance, a fact) with `Edit`, and link the summary under "Sources".
29
+
30
+ Check first whether it exists under another name (`Grep` the knowledge base for the term and look at `aliases`): a duplicate page is worse than none.
31
+
32
+ ## 5. Link both ways and look for conflicts
33
+
34
+ Every link you added from page A to page B needs its counterpart in B. If the source contradicts an existing page, record both versions with attribution in both pages - don't overwrite.
35
+
36
+ ## 6. Close
37
+
38
+ - `index.md`: new pages, and one-line descriptions that changed.
39
+ - `log.md`: `## [date] ingest | <source title>` with the pages created and updated.
40
+ - `overview.md`: only if the source changes the big picture.
41
+
42
+ When ingesting several sources in a row, do steps 1-5 for each and close once at the end.
43
+
44
+ ## An original that was wrong or replaced
45
+
46
+ `retire_source` (the person approves it) moves it aside and marks its summary retired (wrong) or superseded (replaced by a better one). Then update `index.md`, and fix the pages that cite it (`Grep` its file name): after a wrong one, correct or remove what it taught; after a replaced one, ingest the new original and re-ground those passages on it.
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: knowledge-lint
3
+ description: Health-check the knowledge base - broken links, pages missing from index.md, orphan pages, one-way links, duplicated concepts, mentioned-but-missing concepts, contradictions, gaps - fix what's mechanical and report the rest.
4
+ ---
5
+
6
+ # Linting the knowledge base
7
+
8
+ A knowledge base maintained across sessions drifts: links break, pages go unlisted, the same concept appears under two names. Lint it when asked and after a large ingest. Load `knowledge-pages` first for the templates.
9
+
10
+ ## Checks
11
+
12
+ Use `Glob` to list pages and `Grep` (always with `path` inside the knowledge base) to find links, instead of reading every page in full.
13
+
14
+ 1. **Broken links**: a relative link whose target file doesn't exist. Fix it if the right target is obvious (a typo, a page under a close name); otherwise report it.
15
+ 2. **Index**: every page is listed in `index.md` and every entry there points to an existing page. Fix it.
16
+ 3. **Orphans**: pages nothing links to (`Grep` for the file name). Link them from where they belong, or report why they don't belong anywhere.
17
+ 4. **One-way links**: a summary that feeds a concept which doesn't list it back... Add the missing side.
18
+ 5. **Duplicates**: two pages for the same idea under different names. Merge the content into one, mark the other as superseded (never delete it) and repoint links.
19
+ 6. **Missing pages**: terms that several pages treat as concepts or entities but have no page. Create them if the material is there; otherwise list them.
20
+ 7. **Contradictions**: claims that disagree across pages without being recorded as such. Record both sides, attributed.
21
+ 8. **Provenance**: claims with no traceable source. Add the link, or mark them as unsourced.
22
+ 9. **Gaps**: originals `list_sources` reports as new (no summary yet), changed (their summary may be stale) or missing (deleted by hand: their summaries point nowhere), and concepts mentioned but never explained by any source. Report them - they are what to ingest, update or find next.
23
+
24
+ ## Close
25
+
26
+ Append `## [date] lint | <summary>` to `log.md` listing what was fixed. Then report to the human: what you fixed, and what needs their decision or more material. Don't make judgement calls silently - merging pages that are only similar, or choosing between contradictory sources, goes in the report.
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: knowledge-query
3
+ description: Answer a question from the knowledge base - find the relevant pages through the index, read them, answer with links to them, and file the answer back as a synthesis page when it is worth keeping.
4
+ ---
5
+
6
+ # Querying the knowledge base
7
+
8
+ The knowledge base exists so a question doesn't start from zero. Answer from it first; go back to the originals or the web only for what it doesn't hold.
9
+
10
+ 1. **Start from the index.** Read `index.md`, pick the pages that can matter, read those (not the whole knowledge base). `Grep` inside the knowledge base for terms and aliases the index doesn't reveal.
11
+ 2. **Answer from the pages**, linking each one you drew on. Say what comes from the knowledge base, what comes from an original in the sources folder (read it if the knowledge base is thin or contradictory) and what comes from outside (label it as such).
12
+ 3. **Say what is missing.** If the knowledge base can't answer part of the question, say so and name the source that would fill it, instead of filling the gap from memory silently.
13
+ 4. **File it back.** If the answer is a comparison, an analysis or a report that will be asked again, save it as `syntheses/<slug>.md` (template in `knowledge-pages`) with links to its inputs, add it to `index.md`, and log it: `## [date] query | <question>`. A quick factual answer needs no page.
14
+ 5. **Feed the knowledge base.** If answering revealed a concept or fact that has no page, or a contradiction, fix that in the knowledge base too and log it.
@@ -1,4 +1,5 @@
1
1
  import type { AgentDefinition as SdkSubagentDefinition, McpServerConfig, SettingSource } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { KnowledgeStore, PageType } from "./knowledgeStore.js";
2
3
  /**
3
4
  * The human-supervision spectrum every agent built on this kit shares, independent of
4
5
  * domain: "interactive" pauses before every single action, "guided" only pauses before a
@@ -49,6 +50,11 @@ export interface BaseSessionConfig {
49
50
  * language (see language.ts). Pass the same value to the chat, wizard or progress view.
50
51
  */
51
52
  language?: string;
53
+ /**
54
+ * The time zone the date and time tools answer in (`current_time`, `date_math`), an IANA
55
+ * name such as "Europe/Madrid"; the system's if not given.
56
+ */
57
+ timeZone?: string;
52
58
  }
53
59
  /**
54
60
  * Everything actually *about the domain* that `buildSessionOptions()` needs but doesn't
@@ -104,12 +110,31 @@ export interface AgentSpec<TConfig extends BaseSessionConfig> {
104
110
  /**
105
111
  * The built-in knowledge base (see knowledge.ts): when `config.knowledgeDir` is set, the kit
106
112
  * appends its "Knowledge base" rules to the system prompt and loads its plugin (skills
107
- * knowledge-pages/knowledge-ingest/knowledge-query/knowledge-lint, commands /knowledge:ingest, /knowledge:query,
108
- * /knowledge:lint), so the agent maintains its notes as an interlinked wiki. On by default;
113
+ * knowledge-ingest/knowledge-query/knowledge-lint, commands /knowledge:ingest, /knowledge:query,
114
+ * /knowledge:lint), so the agent maintains its notes as an interlinked wiki, through the
115
+ * `knowledge_*` tools by default (see `knowledgeTools`). On by default;
109
116
  * set `false` for an agent that writes its own rules for `knowledgeDir` (or wants plain
110
117
  * notes) — `knowledgePromptSection()`/`knowledgePluginRoot()` are exported to reuse the pieces.
111
118
  */
112
119
  knowledgeBase?: boolean;
120
+ /**
121
+ * How the agent reaches the built-in knowledge base: `"store"` (the default), only through
122
+ * the kit's `knowledge_*` tools over a `KnowledgeStore`, never with the file tools, so the
123
+ * storage can change and the wiki's rules are kept by code (ADR-024); `"files"`, with the
124
+ * file tools on `knowledgeDir` and the rules in the prompt, as before.
125
+ */
126
+ knowledgeTools?: "store" | "files";
127
+ /**
128
+ * The agent's own page types for the built-in knowledge base, besides the kit's four
129
+ * (summary, concept, entity, synthesis): each with its folder (`""` for the root), index
130
+ * section, description (told to the model) and template.
131
+ */
132
+ knowledgePageTypes?: PageType[];
133
+ /**
134
+ * The knowledge base's store, instead of the kit's over markdown files in `knowledgeDir`
135
+ * (e.g. a database or a vector store implementing `KnowledgeStore`).
136
+ */
137
+ knowledgeStore?(config: TConfig): KnowledgeStore;
113
138
  /**
114
139
  * Whether the kit tells the agent (and each subagent) to reply in the resolved language
115
140
  * (`config.language`, `--language`, the system's), following the human if they write in
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Word, PowerPoint and Excel originals as markdown: the SDK's `Read` refuses DOCX and PPTX
3
+ * (confirmed empirically), and course material is often both. The libraries are optional
4
+ * peer dependencies of the kit (`mammoth` for DOCX, `fflate` to open PPTX and XLSX, which
5
+ * are zips of XML); without them the caller is told what to install.
6
+ */
7
+ export declare const EXTRACTABLE: Set<string>;
8
+ export declare class MissingLibraryError extends Error {
9
+ readonly library: string;
10
+ constructor(library: string, options?: ErrorOptions);
11
+ }
12
+ /** An original's text as markdown; `from`/`to` pick slides of a deck. */
13
+ export declare function extractText(file: string, from?: number, to?: number): Promise<string>;