kward 0.71.0 → 0.73.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +30 -0
- data/CHANGELOG.md +93 -0
- data/Gemfile.lock +2 -2
- data/README.md +4 -0
- data/doc/agent-tools.md +15 -6
- data/doc/authentication.md +22 -1
- data/doc/code-search.md +42 -2
- data/doc/configuration.md +106 -3
- data/doc/context-budgeting.md +136 -0
- data/doc/context-tools.md +16 -3
- data/doc/editor.md +415 -0
- data/doc/extensibility.md +16 -7
- data/doc/files.md +100 -0
- data/doc/getting-started.md +25 -18
- data/doc/git.md +123 -0
- data/doc/memory.md +24 -4
- data/doc/personas.md +34 -5
- data/doc/plugins.md +72 -1
- data/doc/releasing.md +37 -9
- data/doc/rpc.md +75 -5
- data/doc/session-management.md +35 -1
- data/doc/shell.md +332 -0
- data/doc/tabs.md +122 -0
- data/doc/troubleshooting.md +77 -1
- data/doc/usage.md +79 -7
- data/doc/web-search.md +12 -4
- data/doc/workspace-tools.md +51 -12
- data/examples/plugins/space_invaders.rb +377 -0
- data/lib/kward/agent.rb +1 -1
- data/lib/kward/ansi.rb +62 -23
- data/lib/kward/cli/commands.rb +33 -2
- data/lib/kward/cli/git.rb +150 -0
- data/lib/kward/cli/interactive_turn.rb +73 -9
- data/lib/kward/cli/plugins.rb +54 -4
- data/lib/kward/cli/prompt_interface.rb +32 -1
- data/lib/kward/cli/rendering.rb +4 -1
- data/lib/kward/cli/runtime_helpers.rb +268 -4
- data/lib/kward/cli/sessions.rb +2 -2
- data/lib/kward/cli/settings.rb +217 -9
- data/lib/kward/cli/slash_commands.rb +628 -2
- data/lib/kward/cli/tabs.rb +725 -0
- data/lib/kward/cli/tool_summaries.rb +6 -0
- data/lib/kward/cli.rb +150 -26
- data/lib/kward/clipboard.rb +2 -3
- data/lib/kward/compactor.rb +7 -19
- data/lib/kward/config_files.rb +145 -1
- data/lib/kward/context_budget_meter.rb +44 -0
- data/lib/kward/conversation.rb +12 -4
- data/lib/kward/editor_mode.rb +25 -0
- data/lib/kward/ekwsh.rb +559 -0
- data/lib/kward/image_attachments.rb +3 -1
- data/lib/kward/interactive_pty_runner.rb +151 -0
- data/lib/kward/local_command_runner.rb +155 -0
- data/lib/kward/local_pty_command_runner.rb +171 -0
- data/lib/kward/model/context_usage.rb +2 -2
- data/lib/kward/model/payloads.rb +2 -5
- data/lib/kward/plugin_registry.rb +61 -0
- data/lib/kward/project_files.rb +52 -0
- data/lib/kward/prompt_history.rb +84 -0
- data/lib/kward/prompt_interface/composer_controller.rb +69 -1
- data/lib/kward/prompt_interface/composer_renderer.rb +109 -13
- data/lib/kward/prompt_interface/composer_state.rb +96 -27
- data/lib/kward/prompt_interface/editor/auto_close_pairs.rb +123 -0
- data/lib/kward/prompt_interface/editor/auto_indent.rb +510 -0
- data/lib/kward/prompt_interface/editor/buffer.rb +109 -0
- data/lib/kward/prompt_interface/editor/controller.rb +1218 -0
- data/lib/kward/prompt_interface/editor/endwise.rb +321 -0
- data/lib/kward/prompt_interface/editor/file_marker.rb +40 -0
- data/lib/kward/prompt_interface/editor/indent_navigation.rb +61 -0
- data/lib/kward/prompt_interface/editor/kill_ring.rb +78 -0
- data/lib/kward/prompt_interface/editor/modes/emacs.rb +259 -0
- data/lib/kward/prompt_interface/editor/modes/modern.rb +354 -0
- data/lib/kward/prompt_interface/editor/modes/vibe.rb +1812 -0
- data/lib/kward/prompt_interface/editor/modes/vibe_insert_readline.rb +166 -0
- data/lib/kward/prompt_interface/editor/renderer.rb +244 -0
- data/lib/kward/prompt_interface/editor/search.rb +76 -0
- data/lib/kward/prompt_interface/editor/selections.rb +120 -0
- data/lib/kward/prompt_interface/editor/state.rb +1271 -0
- data/lib/kward/prompt_interface/editor/status_text.rb +23 -0
- data/lib/kward/prompt_interface/editor/syntax_highlighter.rb +422 -0
- data/lib/kward/prompt_interface/editor/undo_history.rb +46 -0
- data/lib/kward/prompt_interface/editor/vibe_state.rb +44 -0
- data/lib/kward/prompt_interface/file_overlay.rb +211 -0
- data/lib/kward/prompt_interface/git_prompt.rb +288 -0
- data/lib/kward/prompt_interface/interactive/controller.rb +186 -0
- data/lib/kward/prompt_interface/interactive/renderer.rb +71 -0
- data/lib/kward/prompt_interface/interactive/state.rb +62 -0
- data/lib/kward/prompt_interface/key_handler.rb +451 -57
- data/lib/kward/prompt_interface/overlay_renderer.rb +21 -2
- data/lib/kward/prompt_interface/project_browser.rb +524 -0
- data/lib/kward/prompt_interface/question_prompt.rb +99 -56
- data/lib/kward/prompt_interface/runtime_state.rb +43 -0
- data/lib/kward/prompt_interface/screen.rb +19 -3
- data/lib/kward/prompt_interface/selection_prompt.rb +10 -19
- data/lib/kward/prompt_interface/slash_overlay.rb +2 -0
- data/lib/kward/prompt_interface/stream_state.rb +7 -0
- data/lib/kward/prompt_interface/transcript_buffer.rb +6 -0
- data/lib/kward/prompt_interface.rb +366 -222
- data/lib/kward/prompts/commands.rb +9 -0
- data/lib/kward/prompts.rb +2 -0
- data/lib/kward/rpc/memory_methods.rb +83 -0
- data/lib/kward/rpc/server.rb +169 -83
- data/lib/kward/rpc/session_manager.rb +45 -121
- data/lib/kward/rpc/session_tree_rows.rb +9 -115
- data/lib/kward/rpc/tool_event_normalizer.rb +1 -1
- data/lib/kward/rpc/tool_metadata.rb +11 -0
- data/lib/kward/rpc/transcript_normalizer.rb +4 -39
- data/lib/kward/scratchpad_runner.rb +56 -0
- data/lib/kward/session_diff.rb +20 -3
- data/lib/kward/session_naming.rb +11 -0
- data/lib/kward/session_store.rb +44 -0
- data/lib/kward/session_tree_nodes.rb +136 -0
- data/lib/kward/session_tree_renderer.rb +9 -131
- data/lib/kward/tab_store.rb +47 -0
- data/lib/kward/terminal_keys.rb +84 -0
- data/lib/kward/terminal_sequences.rb +42 -0
- data/lib/kward/text_boundary.rb +25 -0
- data/lib/kward/tools/context_budget_stats.rb +54 -0
- data/lib/kward/tools/context_for_task.rb +204 -0
- data/lib/kward/tools/read_file.rb +8 -4
- data/lib/kward/tools/registry.rb +62 -16
- data/lib/kward/tools/tool_call.rb +10 -0
- data/lib/kward/version.rb +1 -1
- data/lib/kward/workers/git_guard.rb +93 -0
- data/lib/kward/workers/job.rb +99 -0
- data/lib/kward/workers/live_view.rb +49 -0
- data/lib/kward/workers/manager.rb +288 -0
- data/lib/kward/workers/queue_runner.rb +166 -0
- data/lib/kward/workers/queue_store.rb +112 -0
- data/lib/kward/workers/store.rb +72 -0
- data/lib/kward/workers/tool_policy.rb +23 -0
- data/lib/kward/workers/worker.rb +82 -0
- data/lib/kward/workers/write_lock.rb +38 -0
- data/lib/kward/workers.rb +10 -0
- data/lib/kward/workspace.rb +125 -87
- data/templates/default/fulldoc/html/css/kward.css +140 -36
- data/templates/default/fulldoc/html/images/kward_screen_1.png +0 -0
- data/templates/default/fulldoc/html/setup.rb +1 -0
- data/templates/default/kward_navigation.rb +12 -1
- data/templates/default/layout/html/layout.erb +23 -34
- data/templates/default/layout/html/setup.rb +6 -0
- metadata +67 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3b7a272f3d5171660fc2669a486830e334910cfef50af203b1eeedb989b6289
|
|
4
|
+
data.tar.gz: 3fb9b4ede65361609b6a1c594431d20136bb83c57e205e4b1b32332db75b2fbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9dec61bbf302b69eb5501a130c29d8104b342266cac1489f53608051db1cb03fb44a5b3d47388f43e2f271673f1ba2b4744637dc108701d13a37abd322913657
|
|
7
|
+
data.tar.gz: 5d057f370c989e973b2cd2bbef8464932251f7b2ffcddcfff6c86d3ecb28db4c5a1241e3eda1f5fa3b7f460cddbd7938dde6396e3335d6bbe9fb1b131d81f9a4
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Ruby
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
22
|
+
with:
|
|
23
|
+
ruby-version: '3.3'
|
|
24
|
+
bundler-cache: true
|
|
25
|
+
|
|
26
|
+
- name: Check syntax
|
|
27
|
+
run: find lib test -name '*.rb' -print0 | xargs -0 ruby -c
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,99 @@ All notable changes to Kward will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.73.0] - 2026-06-29
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Added persistent session-backed worker queue job metadata as the first step toward tab-based worker queues.
|
|
12
|
+
- Added experimental `/queue add` and `/queue list` commands for enqueueing the current tab session into the worker queue.
|
|
13
|
+
- Added a first session-backed worker queue runner that executes one queued job and marks it ready for review after committing changes.
|
|
14
|
+
- Added clean-workspace blocking for queued workers so jobs do not start on top of existing local changes.
|
|
15
|
+
- Added `/queue run` to manually drain queued tab worker jobs sequentially until the queue is empty or a job needs attention.
|
|
16
|
+
- Added worker git stash helpers as groundwork for cooperative queue suspension.
|
|
17
|
+
- Added explicit queue runner suspend/resume primitives that stash and restore a running job's workspace changes.
|
|
18
|
+
- Added `/queue suspend <id>` and `/queue resume <id>` commands for manually parking and resuming queued worker jobs.
|
|
19
|
+
- Added `/queue open <id>` to open a queued worker's session for review or follow-up.
|
|
20
|
+
- Added `/diff` to open the chronological file changes recorded in the current session in the integrated diff viewer.
|
|
21
|
+
- Added `/scratchpad [text|markdown|ruby]` for opening unsaved editor buffers, including Vibe `:w filename` save-as support and Ruby `:run`/Modern `Ctrl+R` output written after `__END__`.
|
|
22
|
+
- Added `/pty <command>` and the `ekwsh` `pty <command>` built-in for explicit interactive PTY passthrough sessions, enabling terminal-owned tools such as pagers to run from Kward.
|
|
23
|
+
- Added minimal PTY execution for external `ekwsh` commands so terminal-aware tools can detect a TTY and terminal width.
|
|
24
|
+
- Added Ctrl+C cancellation for running `ekwsh` commands and preserved tab-switch actions while shell commands are active.
|
|
25
|
+
- Added quoted path completion and cached `$PATH` executable completion for `ekwsh`.
|
|
26
|
+
- Added streaming `ekwsh` command output in the TUI transcript while commands run.
|
|
27
|
+
- Added separate workspace-scoped `ekwsh` command history so embedded shell input no longer shares normal prompt history.
|
|
28
|
+
- Added structured RPC `runtime/updateSetting` `defaultModel` values so clients can send provider and model separately while keeping the existing string format.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Changed PTY-backed `ekwsh` commands to refresh terminal window size while running so long-lived commands can adapt to resizes.
|
|
33
|
+
- Changed `ekwsh` to default `GIT_PAGER` to `cat`, while preserving user-provided values, so Git commands do not unexpectedly enter an interactive pager under PTY execution.
|
|
34
|
+
- Improved `ekwsh` POSIX-oriented built-ins, including `exit [status]`, stricter `cd`/`pwd`, `export NAME`, assignment persistence, `unalias`, and shared alias-name validation.
|
|
35
|
+
- Changed `ekwsh` configuration to prefer a POSIX `/bin/sh` default shell and validate runtime settings for command timeout, output cap, and shell history size.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- Normalized ordinary PTY line endings in `ekwsh` command output so transcripts avoid stray carriage returns.
|
|
40
|
+
- Added `ekwsh` timeout and output-limit enforcement for external commands using the shared local command runner.
|
|
41
|
+
- Consolidated workspace shell command execution on a shared local command runner with timeout, cancellation, bounded capture, and optional streaming support.
|
|
42
|
+
- Fixed `ekwsh` shell output sanitization so unsafe terminal controls are stripped before command output is shown while SGR color is preserved.
|
|
43
|
+
- Split Vibe editor insert/readline key handling into a focused mixin without changing editor behavior.
|
|
44
|
+
- Consolidated compaction message-field reads through the shared message access helper.
|
|
45
|
+
- Consolidated RPC transcript tool metadata normalization with tool event metadata so tool names, args, diffs, and changed files stay aligned.
|
|
46
|
+
- Fixed RPC tool capabilities so `changedFiles` is advertised when emitted in tool results.
|
|
47
|
+
- Removed a stale `count-tests` CLI branch that could crash instead of treating the input as a prompt.
|
|
48
|
+
- Fixed tab failures and cancellations so red tab states always emit a runtime message explaining what happened.
|
|
49
|
+
- Fixed model and reasoning changes from CLI/RPC settings so active session runtime metadata is persisted before the next turn.
|
|
50
|
+
- Fixed `context_for_task` so candidate files with no task matches return a clear no-match message instead of only a header.
|
|
51
|
+
- Fixed workspace file tools so expected filesystem permission and path-type errors are returned as tool errors instead of aborting a turn.
|
|
52
|
+
- Fixed composer `Ctrl+C` so it no longer exits the app when no process is running.
|
|
53
|
+
- Fixed the Git diff viewer so `Ctrl+C` and terminal-forwarded `Cmd+C` copy selected text.
|
|
54
|
+
- Fixed pasted or dropped shell-escaped image paths so the composer hides the path text after adding the image badge.
|
|
55
|
+
- Fixed `read_skill` tool transcript rendering so skill frontmatter starts on the line after the tool label.
|
|
56
|
+
- Fixed built-in editor soft-wrap vertical movement so moving up or down preserves the visual column across wrapped visual rows and logical line boundaries.
|
|
57
|
+
|
|
58
|
+
## [0.72.0] - 2026-06-28
|
|
59
|
+
|
|
60
|
+
### Added
|
|
61
|
+
|
|
62
|
+
- Added a built-in editor that can be opened from the TUI with `$` or directly from the CLI with `kward edit <filename>`, with modern, Emacs-style, and Vibe editing modes.
|
|
63
|
+
- Added richer editor workflows including syntax highlighting, undo/redo, auto-indent, soft wrap, mouse support, multi-cursor editing, relative line numbers, and an expanded Vim-like Vibe mode with visual selections, text objects, registers, marks, macros, substitution, and Ruby navigation.
|
|
64
|
+
- Added `/shell`, an embedded Kward shell (`ekwsh`) for running workspace commands without leaving the TUI, including command/path completion, safe color output, optional global `ekwsh.yml` configuration, and rbenv shim autodetection.
|
|
65
|
+
- Added `/files`, a searchable project file browser that can open files in the editor and remembers cursor and folder expansion state per workspace.
|
|
66
|
+
- Added persistent TUI tabs for session-backed conversations, plus tab commands, shortcuts, status colors, and restoration across restarts.
|
|
67
|
+
- Added `/git` workflows for reviewing changes, viewing diffs, staging or unstaging files, and writing commit messages from inside the TUI.
|
|
68
|
+
- Added TUI composer improvements including `@` file mentions, persistent workspace prompt history with Ctrl+R search, and Tab/Shift+Tab reasoning-effort cycling.
|
|
69
|
+
- Added CLI execution modes via `--mode auto|chat|oneshot|filter` and `--filter` for transforming piped input.
|
|
70
|
+
- Added context-budgeting tools and workflows, including `read_file` modes, richer source outlines, `context_for_task`, `context_budget_stats`, and restored compacted tool-output inspection.
|
|
71
|
+
- Added interactive plugin commands backed by a Kward-driven canvas render loop.
|
|
72
|
+
- Added experimental agent-worker support behind the existing experimental workflow.
|
|
73
|
+
- Added new and expanded guides for editor usage, tabs, project files, Git workflows, agent tools, context budgeting, workspace tools, web search, code search, plugins, RPC, authentication, memory, sessions, troubleshooting, and releasing.
|
|
74
|
+
|
|
75
|
+
### Changed
|
|
76
|
+
|
|
77
|
+
- Changed the built-in editor to use the modern editing mode by default, with smarter indentation and improved keyboard handling across terminal encodings.
|
|
78
|
+
- Improved TUI interaction polish across pickers, tabs, editor rendering, Git workflows, composer refresh behavior, mouse handling, and modal input isolation.
|
|
79
|
+
- Improved embedded shell environment handling so Kward-managed environment values are preserved while workspace shell conveniences still work.
|
|
80
|
+
- Improved RPC and session internals around steering events, session cleanup, worker metadata, session-tree traversal, and config updates.
|
|
81
|
+
- Improved tool-output context budgeting so agents start with focused context, preserve inspectable originals, and report active-conversation savings more accurately.
|
|
82
|
+
- Expanded documentation and generated-doc navigation to better reflect current workflows and configuration options.
|
|
83
|
+
|
|
84
|
+
### Fixed
|
|
85
|
+
|
|
86
|
+
- Fixed embedded-shell completion, environment preservation, and rbenv handling issues.
|
|
87
|
+
- Fixed editor and TUI input edge cases involving shifted keys, CSI-u encodings, Command/Ctrl shortcuts, selection preservation, mouse scrolling, tab switching, modal questions, and commit-message editing.
|
|
88
|
+
- Fixed many built-in editor behaviors around selection rendering, cursor movement, soft wrap, indentation, deletion/change operations, undo/search behavior, macro recording, registers, text objects, visual mode, and viewport positioning.
|
|
89
|
+
- Fixed Git overlay staging and commit-message behavior.
|
|
90
|
+
- Fixed session, tab, and worker state issues including tab restoration, session cleanup, worker handoff, foreground write locks, and plugin/test isolation.
|
|
91
|
+
- Fixed RPC steering, tool-output restoration, context-budget statistics, and session-manager lifecycle behavior.
|
|
92
|
+
- Fixed documentation rendering, navigation, tables, quote styling, and generated guide layout issues.
|
|
93
|
+
- Fixed persona time-of-day handling to use the current local time.
|
|
94
|
+
|
|
95
|
+
### Removed
|
|
96
|
+
|
|
97
|
+
- Removed the placeholder message from `/status` output.
|
|
98
|
+
- Removed unused RPC session helpers and temporarily hid worker labels behind the experimental worker flow.
|
|
99
|
+
|
|
7
100
|
## [0.71.0] - 2026-06-21
|
|
8
101
|
|
|
9
102
|
### Fixed
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
kward (0.
|
|
4
|
+
kward (0.73.0)
|
|
5
5
|
base64
|
|
6
6
|
nokogiri
|
|
7
7
|
tiktoken_ruby
|
|
@@ -146,7 +146,7 @@ CHECKSUMS
|
|
|
146
146
|
html-proofer (5.2.1) sha256=fdd958a7cbf9c3255fb96fe7cfc4e611f64e2706e469488a3326309ad007d2fd
|
|
147
147
|
io-event (1.16.2) sha256=9f9cb0a96ea5c3850a672606c65f27bc96d7621399ef6196acbfe2be0cd1279c
|
|
148
148
|
json (2.19.9) sha256=9b9025b7cdddafa38d316eca0b2358488e42d417045c1b90d216a9fefe46b79a
|
|
149
|
-
kward (0.
|
|
149
|
+
kward (0.73.0)
|
|
150
150
|
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
151
151
|
metrics (0.15.0) sha256=61ded5bac95118e995b1bc9ed4a5f19bc9814928a312a85b200abbdac9039072
|
|
152
152
|
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
|
data/README.md
CHANGED
|
@@ -78,6 +78,9 @@ Start here:
|
|
|
78
78
|
Feature guides:
|
|
79
79
|
|
|
80
80
|
- [Sessions](doc/session-management.md): resume, clone, fork, rewind, compact, and navigate saved work.
|
|
81
|
+
- [Integrated Editor](doc/editor.md): open files from the composer, edit in-place, and choose editor keybindings.
|
|
82
|
+
- [Git](doc/git.md): review changes, use the diff viewer, stage files, and commit from the interactive TUI.
|
|
83
|
+
- [Shell](doc/shell.md): use `/shell`, the embedded Kward shell with aliases, completion, and per-tab state.
|
|
81
84
|
- [Memory](doc/memory.md): opt-in core, soft, and session memory.
|
|
82
85
|
- [Personas](doc/personas.md): configure Kward's tone and role by default, workspace, model, reasoning effort, time, and weekday.
|
|
83
86
|
|
|
@@ -89,6 +92,7 @@ Advanced:
|
|
|
89
92
|
- [Releasing](doc/releasing.md): release checklist for RubyGems publishing.
|
|
90
93
|
- [Agent tools](doc/agent-tools.md): overview of model-callable tools, token-saving behavior, and tool categories.
|
|
91
94
|
- [Workspace tools](doc/workspace-tools.md): local file, edit, and shell command tools.
|
|
95
|
+
- [Context budgeting](doc/context-budgeting.md): focused context gathering, budgeted reads, output compaction, and token-saving history.
|
|
92
96
|
- [Web search](doc/web-search.md): live search providers and network behavior for the web search agent tool.
|
|
93
97
|
- [Code search](doc/code-search.md): package lookup, GitHub repository cache, and external source reading for the code search agent tool.
|
|
94
98
|
- [Context tools](doc/context-tools.md): skills, compacted output retrieval, and structured clarification questions.
|
data/doc/agent-tools.md
CHANGED
|
@@ -6,8 +6,9 @@ Tools are part of Kward's safety and context-management boundary:
|
|
|
6
6
|
|
|
7
7
|
- schemas describe what the model is allowed to call,
|
|
8
8
|
- Ruby tool objects validate and execute those calls,
|
|
9
|
-
- workspace tools stay inside the active workspace by default,
|
|
9
|
+
- workspace tools stay inside the active workspace by default (see [Configuration](configuration.md) for the guardrail setting),
|
|
10
10
|
- file-changing tools require the file to be read first,
|
|
11
|
+
- mutation tools (`edit_file`, `write_file`, `run_shell_command`) are gated by a write lock when agent workers are active, so only one worker can change the workspace at a time,
|
|
11
12
|
- large outputs are bounded or compacted before they enter model context,
|
|
12
13
|
- full tool outputs are kept in the session record for later inspection.
|
|
13
14
|
|
|
@@ -15,22 +16,26 @@ Tools are part of Kward's safety and context-management boundary:
|
|
|
15
16
|
|
|
16
17
|
| Category | Tools | Guide |
|
|
17
18
|
| --- | --- | --- |
|
|
18
|
-
| Workspace tools | `list_directory`, `read_file`, `summarize_file_structure`, `write_file`, `edit_file`, `run_shell_command` | [Workspace tools](workspace-tools.md) |
|
|
19
|
+
| Workspace tools | `list_directory`, `read_file`, `context_for_task`, `context_budget_stats`, `summarize_file_structure`, `write_file`, `edit_file`, `run_shell_command` | [Workspace tools](workspace-tools.md) |
|
|
19
20
|
| Web tools | `web_search`, `fetch_content`, `fetch_raw` | [Web search](web-search.md) |
|
|
20
21
|
| Code search | `code_search` | [Code search](code-search.md) |
|
|
21
22
|
| Context and interaction tools | `read_skill`, `retrieve_tool_output`, `ask_user_question` | [Context tools](context-tools.md) |
|
|
22
23
|
|
|
23
24
|
## How tools save tokens
|
|
24
25
|
|
|
25
|
-
Kward tries to keep tool context useful without flooding the model:
|
|
26
|
+
Kward tries to keep tool context useful without flooding the model. The built-in prompt tells Kward to start with focused context tools and escalate from outlines/previews to exact ranges before full-file reads:
|
|
26
27
|
|
|
27
|
-
- `read_file` reads bounded line ranges
|
|
28
|
+
- `read_file` reads bounded line ranges, supports continuation with `offset` and `limit`, and accepts explicit `preview`, `outline`, `range`, and `full` modes with optional per-call byte budgets.
|
|
29
|
+
- `context_for_task` builds a task-shaped bundle from ranked files, outlines, and matching excerpts within a caller-supplied byte budget.
|
|
30
|
+
- `context_budget_stats` reports approximate active-conversation bytes and estimated tokens saved by compaction and duplicate output replacement.
|
|
28
31
|
- `summarize_file_structure` returns a compact outline for large source files before reading all code.
|
|
29
32
|
- Search, fetch, and shell outputs are capped or compacted before model ingestion.
|
|
30
33
|
- Repeated identical tool output is replaced with a short reference instead of being sent again.
|
|
31
|
-
- Compacted outputs are stored as artifacts that can be reopened with `retrieve_tool_output
|
|
34
|
+
- Compacted outputs are stored as artifacts that can be reopened with `retrieve_tool_output`, including after resuming a saved session that contains the original tool execution record.
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
When a tool output exceeds 12 KB, Kward compacts it before sending it to the model. The compactor preserves the first 40 and last 40 lines, keeps lines matching error, test, or search-result patterns with 2 lines of surrounding context, and replaces omitted sections with `[... omitted lines ...]` markers. Shell command output is section-aware: STDOUT and STDERR sections are compacted separately. Compacted outputs include a header with the original and compacted byte counts and the artifact ID for retrieval. Error outputs under 8 KB are left intact so failure details stay visible.
|
|
37
|
+
|
|
38
|
+
This lets the assistant reason from focused evidence while preserving access to original outputs when needed. For a fuller overview of Kward's context budgeting and token-saving work, see [Context budgeting](context-budgeting.md).
|
|
34
39
|
|
|
35
40
|
## How tools are exposed
|
|
36
41
|
|
|
@@ -40,4 +45,8 @@ This lets the assistant reason from focused evidence while preserving access to
|
|
|
40
45
|
- `read_skill` is advertised only when skills are available,
|
|
41
46
|
- `ask_user_question` is advertised only when the frontend can display structured questions.
|
|
42
47
|
|
|
48
|
+
When agent workers are active, the registry can scope each worker to a subset of tools via an allowed-tool-names filter, so workers only see the tools they need.
|
|
49
|
+
|
|
50
|
+
When `write_file` or `edit_file` changes an `AGENTS.md` file in the workspace root, Kward automatically rebuilds the system message so the model picks up the new instructions without a restart.
|
|
51
|
+
|
|
43
52
|
Unknown tool calls are recorded as tool results instead of crashing the session, so the model can recover and choose an advertised tool on the next turn.
|
data/doc/authentication.md
CHANGED
|
@@ -12,6 +12,8 @@ Or inside interactive Kward:
|
|
|
12
12
|
/login
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
`/login` opens a provider picker; `kward login` accepts the provider as an argument.
|
|
16
|
+
|
|
15
17
|
Use the provider you already have access to. You can change the active model later with `/model`.
|
|
16
18
|
|
|
17
19
|
## Choose a provider
|
|
@@ -56,6 +58,14 @@ If Kward asks for an OAuth client ID, add it to `~/.kward/config.json`:
|
|
|
56
58
|
}
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
Kward ships with a built-in client ID, so this is only needed if login fails or you want to use your own.
|
|
62
|
+
|
|
63
|
+
For a single shell session without OAuth, you can set an access token directly:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
OPENAI_ACCESS_TOKEN=... kward
|
|
67
|
+
```
|
|
68
|
+
|
|
59
69
|
## Anthropic Claude Pro/Max
|
|
60
70
|
|
|
61
71
|
```bash
|
|
@@ -151,10 +161,21 @@ The model picker is the normal way to switch between configured providers and mo
|
|
|
151
161
|
|
|
152
162
|
For one-off shell runs, `KWARD_PROVIDER` and provider-specific model environment variables remain available. See [Configuration](configuration.md) for the full list.
|
|
153
163
|
|
|
164
|
+
## Custom auth file locations
|
|
165
|
+
|
|
166
|
+
Each auth file has an environment variable override, useful for isolated or multi-account setups. When unset, they default to the paths shown above under `~/.kward/`.
|
|
167
|
+
|
|
168
|
+
- `KWARD_AUTH_PATH` — OpenAI OAuth credentials (`auth.json`)
|
|
169
|
+
- `KWARD_ANTHROPIC_AUTH_PATH` — Anthropic OAuth credentials (`anthropic_auth.json`)
|
|
170
|
+
- `KWARD_GITHUB_AUTH_PATH` — GitHub OAuth credentials (`github_auth.json`)
|
|
171
|
+
|
|
172
|
+
When `KWARD_CONFIG_PATH` points at a custom config file, the OpenRouter API key is stored in that file instead of `~/.kward/config.json`.
|
|
173
|
+
|
|
154
174
|
## Security notes
|
|
155
175
|
|
|
156
176
|
- Auth files are written with file mode `0600` when possible.
|
|
157
177
|
- Do not commit `~/.kward/config.json` or auth files.
|
|
158
178
|
- Prefer environment variables for temporary credentials.
|
|
159
179
|
- `kward auth status` shows credential status without printing secrets.
|
|
160
|
-
- `kward auth logout` removes saved credentials.
|
|
180
|
+
- `kward auth logout` removes **all** saved credentials at once: every OAuth file (OpenAI, Anthropic, GitHub) and the stored OpenRouter API key. There is no per-provider logout; to remove a single provider, delete its auth file by hand.
|
|
181
|
+
- `kward doctor` reports which credentials are currently configured alongside other local checks.
|
data/doc/code-search.md
CHANGED
|
@@ -31,6 +31,18 @@ The `code_search` tool can:
|
|
|
31
31
|
|
|
32
32
|
Kward should use this when the best answer depends on how another project actually implemented something.
|
|
33
33
|
|
|
34
|
+
## Supported ecosystems
|
|
35
|
+
|
|
36
|
+
`package_search` and `github_search` accept an `ecosystem` parameter to narrow results:
|
|
37
|
+
|
|
38
|
+
- `rubygems` — RubyGems
|
|
39
|
+
- `npm` — npm registry
|
|
40
|
+
- `pypi` — Python Package Index
|
|
41
|
+
- `crates` — crates.io (Rust)
|
|
42
|
+
- `go` — Go module documentation
|
|
43
|
+
|
|
44
|
+
When omitted, `package_search` requires a `package` name and infers the registry from the ecosystem. `github_search` uses the ecosystem as an optional hint alongside the search query.
|
|
45
|
+
|
|
34
46
|
## Cache location
|
|
35
47
|
|
|
36
48
|
Repositories are cached outside your workspace:
|
|
@@ -63,7 +75,7 @@ or:
|
|
|
63
75
|
GH_TOKEN=...
|
|
64
76
|
```
|
|
65
77
|
|
|
66
|
-
Tokens are used for GitHub API requests and are not included in tool output.
|
|
78
|
+
Tokens are used for GitHub API requests and are not included in tool output. See [Configuration](configuration.md) for the full environment variable reference.
|
|
67
79
|
|
|
68
80
|
## Tool actions
|
|
69
81
|
|
|
@@ -80,4 +92,32 @@ The tool uses an `action` parameter:
|
|
|
80
92
|
| `refresh_cache` | fetch updates for a cached repository. |
|
|
81
93
|
| `clear_cache` | remove a cached repository. |
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
### Action arguments
|
|
96
|
+
|
|
97
|
+
| Action | Required arguments | Optional arguments |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `package_search` | `ecosystem`, `package` | — |
|
|
100
|
+
| `github_search` | `query` | `ecosystem`, `max_results` |
|
|
101
|
+
| `repo_clone` | `repo` | — |
|
|
102
|
+
| `repo_search` | `repo`, `query` | `max_results`, `context_lines` |
|
|
103
|
+
| `repo_read` | `repo`, `path` | `start_line`, `line_count` |
|
|
104
|
+
| `list_cache` | — | — |
|
|
105
|
+
| `refresh_cache` | `repo` | — |
|
|
106
|
+
| `clear_cache` | `repo` | — |
|
|
107
|
+
|
|
108
|
+
- `repo` is a GitHub URL or `owner/name`.
|
|
109
|
+
- `query` is a plain-text search string (not regex). Matching is case-sensitive substring.
|
|
110
|
+
- `start_line` is 1-indexed.
|
|
111
|
+
- `context_lines` controls how many lines before and after a match are included in search snippets.
|
|
112
|
+
|
|
113
|
+
## Limits
|
|
114
|
+
|
|
115
|
+
Search and read results are bounded so Kward does not load large external repositories into context by accident:
|
|
116
|
+
|
|
117
|
+
- Search results: default 10 per query, max 50.
|
|
118
|
+
- Context lines in search snippets: default 2, max 5.
|
|
119
|
+
- Lines returned by `repo_read`: default 200, max 400.
|
|
120
|
+
- File size limit: 512 KB. Files larger than this are skipped during search and rejected on read.
|
|
121
|
+
- Scanned files in `repo_search`: max 5,000 files per scan. Files in `.git` directories, symlinks, files outside the repo root, and oversized files are skipped. Binary files fail gracefully via encoding detection and are skipped.
|
|
122
|
+
- Output truncation: 16 KB total per tool result.
|
|
123
|
+
- HTTP timeout: 10 seconds for all network requests.
|
data/doc/configuration.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Kward reads user configuration from `~/.kward/config.json` by default. Most users do not need to edit this file by hand at first: use `/login`, `/model`, `/reasoning`, and `/settings` from inside Kward when possible.
|
|
4
4
|
|
|
5
|
-
On first start, if the file does not exist, Kward creates a starter config with an active Kward persona, explicit disabled memory settings, and the default composer busy-help setting so you can inspect and edit them. Provider-specific model defaults are added only when you choose a provider/model. If `KWARD_CONFIG_PATH` is set, Kward uses that file instead and treats that file's directory as the config directory for prompts, skills, memory, logs, and caches.
|
|
5
|
+
On first start, if the file does not exist, Kward creates a starter config with an active Kward persona, explicit disabled memory settings, and the default composer busy-help setting so you can inspect and edit them. Provider-specific model defaults are added only when you choose a provider/model. See [Personas](personas.md) for configuring persona selection by workspace, model, or reasoning effort. If `KWARD_CONFIG_PATH` is set, Kward uses that file instead and treats that file's directory as the config directory for prompts, skills, memory, logs, and caches.
|
|
6
6
|
|
|
7
7
|
Small examples:
|
|
8
8
|
|
|
@@ -34,9 +34,31 @@ By default, Kward stores user data under `~/.kward`:
|
|
|
34
34
|
~/.kward/memory/
|
|
35
35
|
~/.kward/logs/
|
|
36
36
|
~/.kward/cache/
|
|
37
|
+
~/.kward/plugins/
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
When `KWARD_CONFIG_PATH=/path/to/config.json` is set, most config-related files live beside that file instead. User plugins are the exception: they are loaded only from `~/.kward/plugins`.
|
|
40
|
+
When `KWARD_CONFIG_PATH=/path/to/config.json` is set, most config-related files live beside that file instead. User plugins are the exception: they are loaded only from `~/.kward/plugins`. See [Plugins](plugins.md) for writing and loading user plugins.
|
|
41
|
+
|
|
42
|
+
## Embedded shell config
|
|
43
|
+
|
|
44
|
+
The embedded Kward shell (`/shell`, internally `ekwsh`) reads optional global settings from `~/.kward/ekwsh.yml` or, when `KWARD_CONFIG_PATH` is set, from `ekwsh.yml` beside that config file.
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
|
|
48
|
+
```yaml
|
|
49
|
+
env:
|
|
50
|
+
FORCE_COLOR: "1"
|
|
51
|
+
CLICOLOR_FORCE: "1"
|
|
52
|
+
|
|
53
|
+
aliases:
|
|
54
|
+
ll: "ls -la"
|
|
55
|
+
gs: "git status --short"
|
|
56
|
+
gd: "git diff --color=always"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`env` values are applied when shell mode starts, after Kward's conservative color defaults. Keys must look like environment variable names (`A_Z`, digits after the first character, and underscores); invalid keys are ignored. Values are converted to strings.
|
|
60
|
+
|
|
61
|
+
`aliases` expand the first word of a command once. For example, `ll lib` runs `ls -la lib`. Built-in `ekwsh` commands such as `cd`, `pwd`, `export`, `unset`, `alias`, `clear`, `pty`, and `exit` take precedence over aliases. Run `alias` inside `ekwsh` to list configured aliases. Aliases are also included in command-name Tab completion.
|
|
40
62
|
|
|
41
63
|
## Provider and model settings
|
|
42
64
|
|
|
@@ -48,6 +70,8 @@ Set `provider` to choose the active backend:
|
|
|
48
70
|
}
|
|
49
71
|
```
|
|
50
72
|
|
|
73
|
+
When `provider` is unset, Kward infers the backend from available credentials, defaulting to OpenAI/Codex when OAuth credentials are present. Set `provider` or `KWARD_PROVIDER` to select another backend explicitly.
|
|
74
|
+
|
|
51
75
|
Supported values are:
|
|
52
76
|
|
|
53
77
|
- `codex` for the OpenAI/ChatGPT Codex backend.
|
|
@@ -73,7 +97,7 @@ Model settings:
|
|
|
73
97
|
}
|
|
74
98
|
```
|
|
75
99
|
|
|
76
|
-
`model` is a generic setting for the active provider. Provider-specific values such as `openai_model`, `anthropic_model`, `openrouter_model`, and `copilot_model` take precedence for their provider. `reasoning_effort` and `thinking_level` are generic reasoning settings. `openai_reasoning_effort`, `anthropic_reasoning_effort`, `openrouter_reasoning_effort`, and `copilot_reasoning_effort` are provider-specific forms.
|
|
100
|
+
`model` is a generic setting for the active provider. Provider-specific values such as `openai_model`, `anthropic_model`, `openrouter_model`, and `copilot_model` take precedence for their provider. `reasoning_effort` and `thinking_level` are generic reasoning settings. `thinking_level` is an alias for `reasoning_effort` honored by all providers. For each provider, Kward resolves reasoning in this order: the provider-specific key (for example `openai_reasoning_effort`), then the generic `reasoning_effort`, then `thinking_level`, then the default `medium`. `openai_reasoning_effort`, `anthropic_reasoning_effort`, `openrouter_reasoning_effort`, and `copilot_reasoning_effort` are provider-specific forms.
|
|
77
101
|
|
|
78
102
|
Defaults:
|
|
79
103
|
|
|
@@ -162,6 +186,85 @@ The busy composer shows a short Ctrl+C cancellation hint by default. To hide it:
|
|
|
162
186
|
|
|
163
187
|
This only hides the hint text; Ctrl+C still stops the current running response.
|
|
164
188
|
|
|
189
|
+
In the normal composer prompt, `Tab` cycles forward through the current model's reasoning efforts and `Shift+Tab` cycles backward. The shortcuts wrap around and update the persisted reasoning setting; file and slash-command completion overlays keep their existing `Tab` completion behavior.
|
|
190
|
+
|
|
191
|
+
`tab_keybindings` controls how the composer handles tab navigation shortcuts:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"composer": {
|
|
196
|
+
"tab_keybindings": "auto"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
`auto` (default) detects terminal support, `ctrl` uses `Ctrl+Tab`/`Shift+Tab` to cycle suggestions and indent, `alt` uses `Alt+Tab` for terminals where `Ctrl+Tab` is swallowed.
|
|
202
|
+
|
|
203
|
+
## Editor settings
|
|
204
|
+
|
|
205
|
+
The built-in TUI file editor supports three keybinding modes. Modern is the default:
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"editor": {
|
|
210
|
+
"mode": "modern"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`mode` can be `modern`, `emacs`, or `vibe`. The old `default` value is still accepted as an alias for `modern`. You can change this from `/settings` > Interface > Editor mode; newly opened editor buffers pick up the setting immediately.
|
|
216
|
+
|
|
217
|
+
The editor automatically highlights Ruby, Crystal, Elixir, Julia, JavaScript, TypeScript, JSON, Markdown, YAML, Shell, Makefile, HTML, CSS, SCSS, Python, Go, Rust, Java, C#, C, C++, Swift, Kotlin, Lua, and SQL files when terminal color is enabled. Unknown file types and color-disabled terminals render plain text.
|
|
218
|
+
|
|
219
|
+
Auto-indent is enabled by default. Pressing Enter copies the current line indentation, detects the file's indentation unit when possible, and applies lightweight syntax-based indentation for recognized file types. For Ruby, Crystal, Elixir, Julia, Lua, Makefiles, and shell scripts, Enter after a block opener inserts the matching closing keyword, and Ctrl+Enter can force that behavior from the middle of the line in terminals that report modified Enter keys. When auto-indent is enabled, typing obvious closing tokens such as `}`, Ruby/Lua `end`, and shell `fi`/`done`/`esac` re-indents the current line, and Backspace in leading indentation removes one detected indentation unit. To disable it:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"editor": {
|
|
224
|
+
"auto_indent": false,
|
|
225
|
+
"auto_close_pairs": false
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`auto_indent` and `auto_close_pairs` both default to `true`. Set `auto_close_pairs` to `false` to disable automatic insertion of matching `()`, `[]`, `{}`, quotes, and backticks.
|
|
231
|
+
|
|
232
|
+
Line numbers are absolute by default. Set `line_numbers` to `relative` to show distances from the cursor line in editable buffers while keeping the current cursor line absolute:
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
{
|
|
236
|
+
"editor": {
|
|
237
|
+
"line_numbers": "relative"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Soft-wrap is enabled by default so long lines wrap within the editor width instead of scrolling. To disable it:
|
|
243
|
+
|
|
244
|
+
```json
|
|
245
|
+
{
|
|
246
|
+
"editor": {
|
|
247
|
+
"soft_wrap": false
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Editable editor buffers request a vertical bar cursor by default. Terminals that do not support cursor-shape escape sequences ignore this. To keep the terminal's normal cursor shape while editing:
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"editor": {
|
|
257
|
+
"bar_cursor": false
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Modern mode uses composer-style keys: `Ctrl+S` saves, `Ctrl+Q` quits, `Ctrl+F` searches, Shift+Arrow selects text, `Ctrl+C` copies, `Ctrl+X` cuts, `Ctrl+V` pastes the editor kill buffer, `Ctrl+A`/`Ctrl+E` move to the start/end of the line, `Ctrl+B` moves left, `Ctrl+K` kills to end of line, `Ctrl+U` kills to start of line, and `Alt+B`/`Alt+F` move by word.
|
|
263
|
+
|
|
264
|
+
Emacs mode uses Emacs-style non-modal keys: `Ctrl+X Ctrl+S` saves, `Ctrl+X Ctrl+C` quits, `Ctrl+S` searches forward, `Ctrl+R` searches backward, `Ctrl+Space` sets the mark, `Ctrl+W` kills the region or previous word, `Alt+W` copies the region, `Ctrl+K` kills to end of line, `Ctrl+Y` yanks, and `Alt+Y` cycles the per-buffer kill ring after a yank.
|
|
265
|
+
|
|
266
|
+
Vibe mode opens files in normal mode and supports a compact classic-vibe subset: normal/insert/command modes, character and line visual modes with `v`/`V`, `h/j/k/l`, word and line movement, counts, simple `d`/`y` operator motions, `dd`, `yy`, `p`, `/` search, `u` undo, and `:w`, `:q`, `:q!`, `:wq`, `:x`, and `:number` commands. Yanks also copy to the terminal clipboard when OSC 52 is supported.
|
|
267
|
+
|
|
165
268
|
## Session settings
|
|
166
269
|
|
|
167
270
|
Interactive CLI and RPC clients start fresh by default. To automatically resume the last active session for the current workspace:
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Context budgeting and token savings
|
|
2
|
+
|
|
3
|
+
Kward tries to keep the model's context focused. Instead of reading whole files and pasting every byte of command output back into the conversation, it gathers evidence in small steps, compacts noisy output, and keeps the original data available when needed.
|
|
4
|
+
|
|
5
|
+
This page summarizes the token-saving work in Kward: what existed before, what the newer focused-context tools add, and how those pieces fit together during normal agent work.
|
|
6
|
+
|
|
7
|
+
## Why this matters
|
|
8
|
+
|
|
9
|
+
Coding agents spend a lot of tokens just finding the right code. A single broad file read, failed test run, or web fetch can add thousands of tokens to the next model call. That makes sessions slower, more expensive, and more likely to lose the useful details in noise.
|
|
10
|
+
|
|
11
|
+
Kward's goal is not to build a heavyweight semantic index. It is to stay lightweight and local while giving the agent a disciplined path:
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
find likely files -> inspect outlines/previews -> read exact ranges -> read full files only when needed
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## The current workflow
|
|
18
|
+
|
|
19
|
+
When Kward needs code context, it should usually start with one of these tools:
|
|
20
|
+
|
|
21
|
+
- `context_for_task` for a compact task-shaped bundle.
|
|
22
|
+
- `summarize_file_structure` for a source outline of one file.
|
|
23
|
+
- `read_file` with `mode: "outline"` or `mode: "preview"`.
|
|
24
|
+
|
|
25
|
+
Then it can escalate only as needed:
|
|
26
|
+
|
|
27
|
+
- `read_file` with `mode: "range"`, `offset`, and `limit` for exact sections.
|
|
28
|
+
- `read_file` with `mode: "full"` only when focused context is not enough.
|
|
29
|
+
|
|
30
|
+
The built-in system prompt tells Kward to follow that escalation path, so these tools are part of normal agent behavior rather than hidden manual features.
|
|
31
|
+
|
|
32
|
+
## Focused task context
|
|
33
|
+
|
|
34
|
+
`context_for_task` is the highest-level context-budgeting tool. Give it a task and, optionally, focused paths and a byte budget. It returns a compact text bundle with:
|
|
35
|
+
|
|
36
|
+
- ranked candidate files (by term-matching score),
|
|
37
|
+
- source outlines for each file,
|
|
38
|
+
- matching excerpts around task terms (2 lines of context),
|
|
39
|
+
- a header with the task, budget, and search terms used.
|
|
40
|
+
|
|
41
|
+
Tool arguments:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"task": "debug token validation failure",
|
|
46
|
+
"paths": ["lib"],
|
|
47
|
+
"budget": 4000
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- `task` is required.
|
|
52
|
+
- `paths` is optional; defaults to the workspace root. Each entry is a file or directory.
|
|
53
|
+
- `budget` is optional; defaults to 4,000 bytes, max 20,000.
|
|
54
|
+
|
|
55
|
+
Limits: at most 8 ranked files are returned, with up to 8 matching excerpts per file. Up to 64 files are scanned. Skipped directories include `.git`, `node_modules`, `vendor`, `tmp`, `log`, `coverage`, `dist`, `build`, `.bundle`, `.yardoc`, and `_yardoc`. Only files with known extensions (`.rb`, `.js`, `.ts`, `.py`, `.go`, `.rs`, `.java`, `.cs`, `.md`, `.yml`, `.json`, etc.) plus `Gemfile` are considered.
|
|
56
|
+
|
|
57
|
+
This is useful when Kward needs orientation before choosing exact files or line ranges. It is intentionally lightweight: no daemon, no database, no persistent graph, and no semantic/vector index.
|
|
58
|
+
|
|
59
|
+
## Budgeted file reads
|
|
60
|
+
|
|
61
|
+
`read_file` supports explicit context modes:
|
|
62
|
+
|
|
63
|
+
| Mode | Use it when |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `outline` | You need a source declaration outline (classes, modules, methods, functions) with line numbers before reading code. Capped at 80 entries. |
|
|
66
|
+
| `preview` | You want a short first look. Defaults to 120 lines when no `limit` is given. Respects `offset` and `limit` if provided. |
|
|
67
|
+
| `range` | You know the relevant line range. Uses `offset` and `limit` to read a specific section. |
|
|
68
|
+
| `full` | You need the full file content up to Kward's read caps. Functionally identical to `range` but signals full-read intent. |
|
|
69
|
+
|
|
70
|
+
`range` and `full` behave the same: both read a bounded slice using `offset`, `limit`, and `max_bytes`. The difference is semantic — use `full` when you want everything up to the cap, use `range` when you are targeting a section.
|
|
71
|
+
|
|
72
|
+
`read_file` also accepts `max_bytes`, which lets Kward request a smaller per-call byte budget. This can only reduce the output below the workspace default (50 KB); it cannot increase it.
|
|
73
|
+
|
|
74
|
+
Large source files still get special handling when read without a mode: Kward returns an outline plus the first 120 lines instead of blindly flooding context. See [Workspace tools](workspace-tools.md) for the full `read_file` argument reference and read limits.
|
|
75
|
+
|
|
76
|
+
## Source outlines
|
|
77
|
+
|
|
78
|
+
`summarize_file_structure` and `read_file` with `mode: "outline"` return compact source outlines. These include recognizable declarations, declaration kind, indentation, and approximate line ranges.
|
|
79
|
+
|
|
80
|
+
The outline recognizer is deliberately simple. It uses lightweight patterns for common Ruby, JavaScript/TypeScript, Go, Rust, Java, and C#-style declarations. It is not a compiler or LSP replacement, but it is fast and dependency-free. See [Workspace tools](workspace-tools.md) for argument details.
|
|
81
|
+
|
|
82
|
+
## Output compaction
|
|
83
|
+
|
|
84
|
+
Kward also saves tokens after tools run.
|
|
85
|
+
|
|
86
|
+
When a tool output is large enough, Kward compacts it before sending it back into model context. The original output is kept in the session record and can be reopened with `retrieve_tool_output`, including after resuming a saved session that contains the original tool execution record.
|
|
87
|
+
|
|
88
|
+
The compactor preserves:
|
|
89
|
+
|
|
90
|
+
- the first 40 lines,
|
|
91
|
+
- the last 40 lines,
|
|
92
|
+
- error, failure, test, search-result, URL, and heading context,
|
|
93
|
+
- separate STDOUT/STDERR sections for shell commands.
|
|
94
|
+
|
|
95
|
+
This is especially useful for commands like test runs, linters, package installs, and large fetches. The model sees the useful parts first, but the full output is not lost. See [Agent tools](agent-tools.md) for the full compaction strategy and artifact retrieval details.
|
|
96
|
+
|
|
97
|
+
## Duplicate output reuse
|
|
98
|
+
|
|
99
|
+
If the same tool output appears again, Kward does not repeat it in model context. Instead, it inserts a short reference to the already-stored artifact.
|
|
100
|
+
|
|
101
|
+
That helps when commands or searches are retried and return the same large result.
|
|
102
|
+
|
|
103
|
+
## Session compaction
|
|
104
|
+
|
|
105
|
+
Kward also supports conversation/session compaction. This is separate from tool-output compaction: instead of trimming one tool result, it summarizes older conversation state so a long session can continue with less context pressure.
|
|
106
|
+
|
|
107
|
+
Session compaction keeps the working conversation manageable while preserving the session history on disk. Run `/compact` manually, or enable auto-compaction in config — see [Session management](session-management.md) and [Configuration](configuration.md).
|
|
108
|
+
|
|
109
|
+
## Measuring savings
|
|
110
|
+
|
|
111
|
+
Use `context_budget_stats` to see approximate savings for the current active conversation since it was opened in this process. These runtime stats are not reconstructed when a saved session is resumed.
|
|
112
|
+
|
|
113
|
+
It reports:
|
|
114
|
+
|
|
115
|
+
- tool calls counted,
|
|
116
|
+
- original bytes,
|
|
117
|
+
- model-facing returned bytes,
|
|
118
|
+
- saved bytes,
|
|
119
|
+
- estimated tokens saved,
|
|
120
|
+
- per-tool breakdown with `calls`, `savedBytes`, `returnedBytes`, and `originalBytes` for each tool.
|
|
121
|
+
|
|
122
|
+
The token estimate is intentionally rough, using about four bytes per token. It is meant to show whether context budgeting is helping, not to match provider billing exactly. See [Workspace tools](workspace-tools.md) for the tool reference.
|
|
123
|
+
|
|
124
|
+
## Practical example
|
|
125
|
+
|
|
126
|
+
A good debugging flow looks like this:
|
|
127
|
+
|
|
128
|
+
```text
|
|
129
|
+
User: Debug why auth token validation fails.
|
|
130
|
+
Kward: context_for_task(task: "debug auth token validation", paths: ["lib", "test"], budget: 5000)
|
|
131
|
+
Kward: read_file(path: "lib/auth.rb", mode: "range", offset: 40, limit: 80)
|
|
132
|
+
Kward: run_shell_command(command: "ruby -Itest test/test_auth.rb")
|
|
133
|
+
Kward: retrieve_tool_output(...) only if the compacted test output omitted something important.
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
That gives the model enough evidence to work without reading the whole repository or stuffing every command byte into the next request.
|