kward 0.70.0 → 0.71.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/pages.yml +1 -1
  3. data/CHANGELOG.md +48 -2
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +90 -2
  6. data/README.md +30 -6
  7. data/Rakefile +96 -0
  8. data/doc/agent-tools.md +43 -0
  9. data/doc/api.md +92 -0
  10. data/doc/authentication.md +39 -25
  11. data/doc/configuration.md +1 -15
  12. data/doc/context-tools.md +70 -0
  13. data/doc/plugins.md +2 -2
  14. data/doc/releasing.md +14 -5
  15. data/doc/rpc.md +3 -11
  16. data/doc/session-management.md +220 -0
  17. data/doc/usage.md +7 -8
  18. data/doc/workspace-tools.md +105 -0
  19. data/lib/kward/cli/commands.rb +8 -0
  20. data/lib/kward/cli/openrouter_commands.rb +55 -0
  21. data/lib/kward/cli/prompt_interface.rb +80 -6
  22. data/lib/kward/cli/rendering.rb +11 -6
  23. data/lib/kward/cli/sessions.rb +260 -11
  24. data/lib/kward/cli/settings.rb +0 -30
  25. data/lib/kward/cli/slash_commands.rb +24 -6
  26. data/lib/kward/cli.rb +13 -0
  27. data/lib/kward/compactor.rb +4 -1
  28. data/lib/kward/config_files.rb +4 -6
  29. data/lib/kward/conversation.rb +49 -20
  30. data/lib/kward/model/client.rb +37 -50
  31. data/lib/kward/model/context_usage.rb +13 -6
  32. data/lib/kward/model/model_info.rb +92 -16
  33. data/lib/kward/model/payloads.rb +2 -0
  34. data/lib/kward/openrouter_model_cache.rb +120 -0
  35. data/lib/kward/plugin_registry.rb +47 -1
  36. data/lib/kward/prompt_interface/banner.rb +16 -51
  37. data/lib/kward/prompt_interface/composer_controller.rb +60 -87
  38. data/lib/kward/prompt_interface/composer_renderer.rb +7 -1
  39. data/lib/kward/prompt_interface/key_handler.rb +31 -10
  40. data/lib/kward/prompt_interface/layout.rb +2 -2
  41. data/lib/kward/prompt_interface/prompt_renderer.rb +32 -13
  42. data/lib/kward/prompt_interface/question_prompt.rb +34 -42
  43. data/lib/kward/prompt_interface/runtime_state.rb +6 -1
  44. data/lib/kward/prompt_interface/screen.rb +1 -0
  45. data/lib/kward/prompt_interface/selection_prompt.rb +513 -54
  46. data/lib/kward/prompt_interface/transcript_buffer.rb +7 -16
  47. data/lib/kward/prompt_interface/transcript_renderer.rb +3 -3
  48. data/lib/kward/prompt_interface.rb +22 -28
  49. data/lib/kward/prompts/commands.rb +2 -1
  50. data/lib/kward/prompts.rb +2 -2
  51. data/lib/kward/rpc/server.rb +3 -8
  52. data/lib/kward/rpc/session_manager.rb +17 -6
  53. data/lib/kward/session_store.rb +23 -4
  54. data/lib/kward/telemetry/logger.rb +5 -3
  55. data/lib/kward/tool_output_compactor.rb +127 -0
  56. data/lib/kward/tools/base.rb +8 -2
  57. data/lib/kward/tools/registry.rb +37 -6
  58. data/lib/kward/tools/retrieve_tool_output.rb +71 -0
  59. data/lib/kward/tools/search/web.rb +2 -2
  60. data/lib/kward/tools/summarize_file_structure.rb +29 -0
  61. data/lib/kward/tools/tool_call.rb +2 -0
  62. data/lib/kward/version.rb +1 -1
  63. data/lib/kward/workspace.rb +58 -2
  64. data/templates/default/fulldoc/html/css/kward.css +256 -7
  65. data/templates/default/fulldoc/html/full_list.erb +107 -0
  66. data/templates/default/fulldoc/html/js/kward.js +161 -2
  67. data/templates/default/fulldoc/html/setup.rb +8 -0
  68. data/templates/default/kward_navigation.rb +91 -0
  69. data/templates/default/layout/html/layout.erb +39 -8
  70. data/templates/default/layout/html/setup.rb +33 -38
  71. metadata +13 -3
  72. data/lib/kward/resources/avatar_kward_logo.rb +0 -50
  73. data/lib/kward/resources/pixel_logo.rb +0 -232
@@ -12,7 +12,7 @@ Or inside interactive Kward:
12
12
  /login
13
13
  ```
14
14
 
15
- Use the provider you already have access to. You can change providers later.
15
+ Use the provider you already have access to. You can change the active model later with `/model`.
16
16
 
17
17
  ## Choose a provider
18
18
 
@@ -34,8 +34,6 @@ kward login openrouter # OpenRouter API key
34
34
  kward login github # GitHub OAuth for experimental Copilot support
35
35
  ```
36
36
 
37
- From source, replace `kward` with `ruby lib/main.rb`.
38
-
39
37
  ## OpenAI / ChatGPT
40
38
 
41
39
  ```bash
@@ -88,54 +86,70 @@ OPENROUTER_API_KEY=sk-or-v1-... kward
88
86
 
89
87
  Choose OpenRouter when you want access to its model catalog or want provider/model selection through an API key.
90
88
 
91
- ## Experimental Copilot support
89
+ ### Refresh the OpenRouter model cache
90
+
91
+ Kward's `/model` picker can show OpenRouter models that are available to your API key. Refresh the local cache after logging in:
92
92
 
93
93
  ```bash
94
- kward login github
94
+ kward openrouter refresh
95
95
  ```
96
96
 
97
- This saves GitHub OAuth credentials to:
97
+ This fetches text-capable OpenRouter models for the configured key and writes them to:
98
98
 
99
99
  ```text
100
- ~/.kward/github_auth.json
100
+ ~/.kward/cache/openrouter_models.json
101
101
  ```
102
102
 
103
- You can also use a token for one run:
103
+ If `KWARD_CONFIG_PATH` points at a custom config file, the cache is written beside that config file under `cache/openrouter_models.json`.
104
+
105
+ Inspect the cached model ids with:
104
106
 
105
107
  ```bash
106
- COPILOT_GITHUB_TOKEN=... kward
108
+ kward openrouter list
107
109
  ```
108
110
 
109
- Copilot support is experimental and uses direct HTTPS calls to the Copilot proxy API. It does not use the official Copilot CLI or SDK runtime.
111
+ Use this when:
110
112
 
111
- ## Which credential wins?
113
+ - you added or changed your OpenRouter API key,
114
+ - OpenRouter added new models,
115
+ - your model picker does not show the model you expect,
116
+ - you want Kward to use current context-window metadata from OpenRouter.
112
117
 
113
- If multiple credentials are available, Kward uses the configured provider.
118
+ After refreshing, start Kward and choose the model with `/model`.
114
119
 
115
- Set it in `~/.kward/config.json`:
120
+ ## Experimental Copilot support
116
121
 
117
- ```json
118
- {
119
- "provider": "anthropic"
120
- }
122
+ ```bash
123
+ kward login github
124
+ ```
125
+
126
+ This saves GitHub OAuth credentials to:
127
+
128
+ ```text
129
+ ~/.kward/github_auth.json
121
130
  ```
122
131
 
123
- Or for one command:
132
+ You can also use a token for one run:
124
133
 
125
134
  ```bash
126
- KWARD_PROVIDER=openrouter kward
135
+ COPILOT_GITHUB_TOKEN=... kward
127
136
  ```
128
137
 
129
- Supported provider values:
138
+ Copilot support is experimental and uses direct HTTPS calls to the Copilot proxy API. It does not use the official Copilot CLI or SDK runtime.
139
+
140
+ ## Choose the active model
141
+
142
+ Authentication makes providers available. The active model is selected separately.
143
+
144
+ Inside Kward, use:
130
145
 
131
146
  ```text
132
- codex
133
- anthropic
134
- openrouter
135
- copilot
147
+ /model
136
148
  ```
137
149
 
138
- Without an explicit provider, OpenAI/ChatGPT credentials are preferred when present.
150
+ The model picker is the normal way to switch between configured providers and models. You can keep credentials for multiple providers and choose the model you want for the current work.
151
+
152
+ For one-off shell runs, `KWARD_PROVIDER` and provider-specific model environment variables remain available. See [Configuration](configuration.md) for the full list.
139
153
 
140
154
  ## Security notes
141
155
 
data/doc/configuration.md CHANGED
@@ -83,7 +83,7 @@ Defaults:
83
83
  - Copilot: `gpt-5-mini`
84
84
  - Reasoning effort: `medium`
85
85
 
86
- The interactive `/model` picker prefers OpenRouter models available to the configured API key when Kward can fetch them. `/openrouter/catalog` and RPC `openrouter/catalog` list the full OpenRouter catalog separately.
86
+ The interactive `/model` picker reads cached OpenRouter models when available. Run `kward openrouter refresh` to fetch text-capable models available to the configured OpenRouter API key and cache them under `~/.kward/cache/openrouter_models.json`. Run `kward openrouter list` to inspect the cached model ids.
87
87
 
88
88
  ## Environment overrides
89
89
 
@@ -148,20 +148,6 @@ Overlay settings control terminal picker/card layout:
148
148
 
149
149
  You can change these interactively with `/settings`.
150
150
 
151
- ## Banner settings
152
-
153
- The interactive terminal banner shows the avatar Kward logo and the “State your business.” message by default. To hide the full banner:
154
-
155
- ```json
156
- {
157
- "banner": {
158
- "enabled": false
159
- }
160
- }
161
- ```
162
-
163
- This only affects the interactive terminal UI.
164
-
165
151
  ## Composer settings
166
152
 
167
153
  The busy composer shows a short Ctrl+C cancellation hint by default. To hide it:
@@ -0,0 +1,70 @@
1
+ # Context tools
2
+
3
+ Context tools help Kward load reusable instructions, recover compacted tool output, and ask structured clarification questions. These tools usually run in the background as part of a turn rather than as commands you type directly.
4
+
5
+ ## `read_skill`
6
+
7
+ `read_skill` loads configured skill instructions when a task matches a known skill.
8
+
9
+ Arguments:
10
+
11
+ - `name`: skill name.
12
+ - `path`: optional path inside the skill, default `SKILL.md`.
13
+
14
+ Skills are reusable instruction bundles stored in the Kward config directory. Kward advertises available skills by name and description, then reads the full skill only when it becomes relevant. That saves tokens because every skill does not need to be injected into every request.
15
+
16
+ Typical uses:
17
+
18
+ - loading test-writing guidance before changing tests,
19
+ - loading security guidance before editing auth, secrets, cookies, uploads, or personal data handling,
20
+ - loading language-specific style guidance before refactoring code.
21
+
22
+ See [Extensibility](extensibility.md) for how skills fit with prompts, personas, and project instructions.
23
+
24
+ ## `retrieve_tool_output`
25
+
26
+ `retrieve_tool_output` reopens original output that was compacted out of the model-facing context.
27
+
28
+ Arguments:
29
+
30
+ - `id`: tool output artifact id, such as `toolout_abc123`.
31
+ - `offset`: optional 1-indexed line offset.
32
+ - `limit`: optional maximum lines to return, default 120.
33
+ - `query`: optional case-insensitive text search within the original output.
34
+
35
+ Kward may compact large shell, search, fetch, or file outputs before sending them back to the model. The compacted result includes enough summary to continue, plus an artifact id when the original output is worth preserving. If later work needs details, Kward can retrieve a focused slice of the original output instead of asking the tool to repeat the whole operation.
36
+
37
+ This saves tokens in two ways:
38
+
39
+ - repeated large outputs are not resent to the model,
40
+ - follow-up reads can target only matching lines or a bounded line range.
41
+
42
+ ## `ask_user_question`
43
+
44
+ `ask_user_question` asks one to four structured clarification questions through an interactive frontend.
45
+
46
+ Arguments:
47
+
48
+ - `questions`: array of one to four questions.
49
+ - each question has:
50
+ - `header`: short label shown in the overlay,
51
+ - `question`: the question text,
52
+ - `options`: two to four selectable answers with labels and descriptions.
53
+
54
+ This tool is advertised only when the active frontend supports structured questions. In terminal use, it lets Kward ask concise multiple-choice questions instead of guessing requirements. In RPC clients, the same question flow is bridged through UI events.
55
+
56
+ Good uses:
57
+
58
+ - choosing between safe implementation approaches,
59
+ - confirming an ambiguous scope,
60
+ - selecting a provider, model, or behavior when no default is obvious.
61
+
62
+ Kward should not use this tool for every small uncertainty. It is best when an answer materially changes the implementation or avoids a risky assumption.
63
+
64
+ ## Availability
65
+
66
+ `Kward::ToolRegistry` only advertises context tools when they are usable:
67
+
68
+ - `read_skill` requires configured skills,
69
+ - `ask_user_question` requires frontend support,
70
+ - `retrieve_tool_output` is available in normal sessions so compacted artifacts can be inspected later.
data/doc/plugins.md CHANGED
@@ -53,7 +53,7 @@ end
53
53
  Start Kward and run:
54
54
 
55
55
  ```text
56
- /hello Kai
56
+ /hello World
57
57
  ```
58
58
 
59
59
  ## Add a slash command
@@ -161,7 +161,7 @@ RPC clients can:
161
161
 
162
162
  - list plugin commands through `commands/list`,
163
163
  - run plugin commands through `commands/run`,
164
- - run plugin slash commands through `turns/start` input such as `/hello Kai`.
164
+ - run plugin slash commands through `turns/start` input such as `/hello World`.
165
165
 
166
166
  Plugin command output is emitted through normal turn events without calling the model.
167
167
 
data/doc/releasing.md CHANGED
@@ -10,23 +10,32 @@ Release steps before publishing:
10
10
  bundle exec rake test
11
11
  ```
12
12
 
13
- 4. Generate documentation:
13
+ 4. Preview docs locally if you changed documentation or public APIs:
14
+
15
+ ```bash
16
+ bundle exec rake docs:serve
17
+ ```
18
+
19
+ The preview builds `_yardoc/`, serves it with WEBrick, and rebuilds in a fresh process when documentation sources, library code, or templates change. Refresh your browser after rebuilds.
20
+
21
+ 5. Generate and check documentation:
14
22
 
15
23
  ```bash
16
24
  bundle exec rake rdoc
17
25
  bundle exec rake docs:build
26
+ bundle exec rake docs:check
18
27
  ```
19
28
 
20
- Pushes to `main` deploy the generated YARD site to GitHub Pages.
29
+ `docs:check` validates generated internal links, images, and scripts. Pushes to `main` deploy the generated YARD site to GitHub Pages.
21
30
 
22
- 5. Build the gem locally:
31
+ 6. Build the gem locally:
23
32
 
24
33
  ```bash
25
34
  gem build kward.gemspec
26
35
  ```
27
36
 
28
- 6. Inspect the packaged files and confirm no local config, sessions, logs, or secrets are included.
29
- 7. Install the built gem locally and smoke test the `kward` executable.
37
+ 7. Inspect the packaged files and confirm no local config, sessions, logs, or secrets are included.
38
+ 8. Install the built gem locally and smoke test the `kward` executable.
30
39
 
31
40
  Publish the built gem from the release checkout:
32
41
 
data/doc/rpc.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Kward RPC Protocol
2
2
 
3
+ <div class="kward-no-toc"></div>
4
+
3
5
  Kward RPC is an experimental backend protocol for UI clients. It is versioned as protocol version `1`, but method names and payloads may still change while the UI integration is built.
4
6
 
5
7
  This page is for people building UI clients or integrations. If you use Kward from the terminal, you can skip it.
@@ -10,12 +12,6 @@ This page is for people building UI clients or integrations. If you use Kward fr
10
12
  kward rpc
11
13
  ```
12
14
 
13
- From source:
14
-
15
- ```bash
16
- ruby lib/main.rb rpc
17
- ```
18
-
19
15
  The process uses stdin/stdout exclusively for protocol messages. Diagnostics are written to stderr.
20
16
 
21
17
  ## Framing
@@ -507,11 +503,7 @@ Returns `{ "memories": [] }`.
507
503
 
508
504
  ### `models/list`
509
505
 
510
- Returns known model entries from the current client/config backend. OpenRouter entries prefer models available to the configured OpenRouter API key when they can be fetched; otherwise Kward falls back to defaults/currently configured options. Entries use `{ "provider", "id", "name", "reasoning", "reasoningEffort", "contextWindow", "current" }`.
511
-
512
- ### `openrouter/catalog`
513
-
514
- Returns the full OpenRouter model catalog as model entries. This is separate from `models/list`, which prefers models available to the configured API key. Models returned here may still fail at request time if the active OpenRouter key cannot access them.
506
+ Returns known model entries from the current client/config backend. OpenRouter entries come from the local OpenRouter model cache when present; otherwise Kward falls back to defaults/currently configured options. Refresh the cache with the CLI-only `kward openrouter refresh` command. Entries use `{ "provider", "id", "name", "reasoning", "reasoningEffort", "contextWindow", "current" }`.
515
507
 
516
508
  ### `models/current`
517
509
 
@@ -0,0 +1,220 @@
1
+ # Sessions
2
+
3
+ Sessions are Kward's way of keeping real work alive across time. An interactive chat is not just a scrollback buffer: it is saved as a session with messages, tool calls, tool results, compaction checkpoints, branches, and enough metadata for Kward to resume the work later.
4
+
5
+ Think of sessions as **context management**. They let you decide which conversation context Kward should use next.
6
+
7
+ Think of rewinding and forking as **context time travel**. You can go back to an earlier prompt, try a different path, and keep both versions instead of losing the original work.
8
+
9
+ ## Where sessions live
10
+
11
+ Interactive sessions are saved under:
12
+
13
+ ```text
14
+ ~/.kward/sessions/
15
+ ```
16
+
17
+ Sessions are scoped to the workspace. If you run Kward in two different projects, each project has its own recent sessions.
18
+
19
+ One-shot prompts such as `kward "Explain this project"` do not use session history. Start interactive Kward when you want ongoing context:
20
+
21
+ ```bash
22
+ cd ~/code/project
23
+ kward
24
+ ```
25
+
26
+ ## A normal session workflow
27
+
28
+ Start a chat and give it a useful name:
29
+
30
+ ```text
31
+ /rename oauth cleanup
32
+ ```
33
+
34
+ Work normally:
35
+
36
+ ```text
37
+ Find the OAuth callback code and explain how errors are handled.
38
+ Add a focused test for the missing expired-token case.
39
+ Run the related test file.
40
+ ```
41
+
42
+ Leave when you are done for now:
43
+
44
+ ```text
45
+ /exit
46
+ ```
47
+
48
+ Later, resume the work:
49
+
50
+ ```text
51
+ /sessions
52
+ ```
53
+
54
+ The session picker shows recent sessions for the current workspace. Choose one to restore its transcript and continue with the same context.
55
+
56
+ `/resume` is an alias for `/sessions`.
57
+
58
+ ## The sessions picker
59
+
60
+ Open it with:
61
+
62
+ ```text
63
+ /sessions
64
+ ```
65
+
66
+ Inside the picker you can:
67
+
68
+ | Key | Action |
69
+ | --- | --- |
70
+ | `Enter` | resume the highlighted session. |
71
+ | `r` | rename the highlighted session. |
72
+ | `c` | clone the highlighted session. |
73
+ | `f` | fork the highlighted session from an earlier prompt. |
74
+ | `d d` | delete the highlighted session after confirmation. |
75
+
76
+ Use names generously. A session named `oauth cleanup` or `release checklist` is much easier to find later than a timestamp.
77
+
78
+ ## Clone a session
79
+
80
+ Clone when you want an exact copy of the current conversation and then continue in a separate branch.
81
+
82
+ From inside the active session:
83
+
84
+ ```text
85
+ /clone
86
+ ```
87
+
88
+ Or from `/sessions`, highlight a session and press `c`.
89
+
90
+ A clone keeps the same conversation so far, but future messages are written to the new session file. The original session remains unchanged.
91
+
92
+ Good uses:
93
+
94
+ - try a risky refactor while preserving the safe version,
95
+ - continue a review with a different strategy,
96
+ - keep a checkpoint before asking Kward to make broad changes,
97
+ - split one investigation into two independent paths.
98
+
99
+ Mental model: **clone copies the whole timeline and starts a new future from now.**
100
+
101
+ ## Fork from an earlier prompt
102
+
103
+ Fork when you want to go back to a specific user prompt and create a new independent session from before that prompt.
104
+
105
+ From inside the active session:
106
+
107
+ ```text
108
+ /fork
109
+ ```
110
+
111
+ Or from `/sessions`, highlight a session and press `f`.
112
+
113
+ Kward shows earlier user prompts. Choose the prompt where the new path should begin. Kward creates a new session containing the conversation before that prompt, then pre-fills the selected prompt so you can edit or resubmit it.
114
+
115
+ Good uses:
116
+
117
+ - you asked the wrong question and want to rephrase it,
118
+ - Kward solved the right problem in the wrong style,
119
+ - you want to try a smaller implementation after a larger one,
120
+ - you want two alternative designs starting from the same point.
121
+
122
+ Mental model: **fork cuts the timeline before a selected prompt and starts a new session there.**
123
+
124
+ ## Rewind within the current session
125
+
126
+ Rewind is the fastest way to revisit an earlier prompt in the current session:
127
+
128
+ ```text
129
+ /rewind
130
+ ```
131
+
132
+ Kward shows previous user prompts from the active branch. Choose one, edit it if needed, and continue from that point. Future messages become a new branch in the same session history.
133
+
134
+ Use rewind when you are still working inside one session and want to quickly try a different direction.
135
+
136
+ Good uses:
137
+
138
+ - undo a bad turn without throwing away the whole session,
139
+ - retry an earlier request with tighter instructions,
140
+ - branch from a known-good point after a tool result revealed something new,
141
+ - jump back after realizing the current path is too broad.
142
+
143
+ When available, `/rewind` also offers a return option so you can go back to where you were before rewinding.
144
+
145
+ Mental model: **rewind moves the active point inside the same session timeline.**
146
+
147
+ ## Inspect the full tree
148
+
149
+ Use `/tree` when you need the technical view of a session's history:
150
+
151
+ ```text
152
+ /tree
153
+ ```
154
+
155
+ The session tree includes more than the friendly `/rewind` list. It can show branches, assistant entries, tool calls, tool results, compaction checkpoints, and the current active leaf. Choose an entry to move the active session position there.
156
+
157
+ Most users should reach for `/rewind` first. Use `/tree` when you need to understand or navigate the full branching structure.
158
+
159
+ Good uses:
160
+
161
+ - inspect where a branch split,
162
+ - return to a specific tool-heavy checkpoint,
163
+ - understand what happened after multiple rewinds,
164
+ - navigate a long session with several alternative paths.
165
+
166
+ Mental model: **`/tree` is the map; `/rewind` is the friendly time machine.**
167
+
168
+ ## Compact long sessions
169
+
170
+ Long sessions can outgrow the model's useful context window. Use compacting to keep going:
171
+
172
+ ```text
173
+ /compact
174
+ ```
175
+
176
+ You can add focus instructions:
177
+
178
+ ```text
179
+ /compact preserve the API docs navigation decisions and current failing checks
180
+ ```
181
+
182
+ Compaction summarizes older conversation into a checkpoint and keeps recent context active. Historical messages remain in the session file for audit, export, and tree navigation, but the live model context becomes smaller.
183
+
184
+ After compaction, Kward may need to re-read files before editing them again. That is normal: read-before-edit guardrails apply to the current live context.
185
+
186
+ Compaction is also context management. It trades detailed old conversation for a concise working summary so Kward can spend tokens on the next task.
187
+
188
+ ## Export a session
189
+
190
+ Export when you want notes outside Kward:
191
+
192
+ ```text
193
+ /export notes.md
194
+ ```
195
+
196
+ Exports are useful for handoff notes, review summaries, release records, or saving a human-readable transcript before deleting old sessions.
197
+
198
+ ## Which command should I use?
199
+
200
+ | Need | Use |
201
+ | --- | --- |
202
+ | Continue earlier work | `/sessions` or `/resume` |
203
+ | Give the current session a better name | `/rename <name>` |
204
+ | Keep the current state but try another future | `/clone` |
205
+ | Start a separate session from before an earlier prompt | `/fork` |
206
+ | Quickly retry an earlier prompt in this session | `/rewind` |
207
+ | Inspect or navigate the full branch structure | `/tree` |
208
+ | Reduce old context so a long session can continue | `/compact` |
209
+ | Save a readable transcript | `/export <path>` |
210
+
211
+ ## Practical habits
212
+
213
+ - Rename sessions early when work becomes important.
214
+ - Clone before risky or broad changes.
215
+ - Fork when the earlier prompt was the wrong starting point.
216
+ - Rewind when you want a fast alternate attempt inside the same session.
217
+ - Use `/tree` only when the friendly commands are not enough.
218
+ - Compact when the conversation gets long, but keep the focus instruction specific.
219
+
220
+ Sessions make Kward less like a single chat box and more like a workspace timeline. You can preserve context, branch it, compress it, and return to it when the work needs another pass.
data/doc/usage.md CHANGED
@@ -99,7 +99,8 @@ Use slash commands for local actions that should not go to the model:
99
99
  | `/new` | start a fresh session. |
100
100
  | `/sessions` | open the saved sessions picker or continue a previous session by path. |
101
101
  | `/resume` | alias for `/sessions`. |
102
- | `/name <name>` | name the current session. |
102
+ | `/name <name>` | name or clear the current session. |
103
+ | `/rename <name>` | rename the current session. |
103
104
  | `/clone` | copy the current session into a new branch. |
104
105
  | `/rewind` | revisit an earlier prompt and try a different direction. |
105
106
  | `/tree` | inspect and navigate the full technical session tree. |
@@ -115,18 +116,18 @@ Prompt templates and plugins can add more slash commands.
115
116
 
116
117
  ## Sessions
117
118
 
118
- Interactive chats are saved under:
119
+ Interactive chats are saved as workspace-scoped sessions under:
119
120
 
120
121
  ```text
121
122
  ~/.kward/sessions/
122
123
  ```
123
124
 
124
- Sessions are scoped to the workspace. Use them when work spans more than one terminal sitting.
125
+ Use sessions when work spans more than one terminal sitting, or when you want to branch a conversation and try another direction.
125
126
 
126
127
  Typical flow:
127
128
 
128
129
  ```text
129
- /name oauth cleanup
130
+ /rename oauth cleanup
130
131
  # work with Kward
131
132
  /export oauth-notes.md
132
133
  /exit
@@ -138,11 +139,9 @@ Later:
138
139
  /sessions
139
140
  ```
140
141
 
141
- `/resume` remains available as an alias.
142
+ In the sessions picker, press `r` to rename the highlighted session, `c` to clone it, `f` to fork from an earlier prompt, or `d` twice to delete it. `/resume` remains available as an alias for `/sessions`.
142
143
 
143
- Use `/rewind` when you want to go back to an earlier prompt and try a different direction. Kward shows user prompts from the current session, lets you edit a prior prompt, and continues from that point as a branch. Use `/tree` when you need the full technical session tree, including branches, assistant entries, tool calls, and tool results.
144
-
145
- Use `/compact` when a conversation gets long. Kward summarizes older context and keeps recent context active. After compaction, it may need to re-read files before editing them again.
144
+ For the full guide to context management, cloning, forking, rewinding, `/tree`, compaction, and exports, read [Sessions](session-management.md).
146
145
 
147
146
  ## One-shot prompts
148
147
 
@@ -0,0 +1,105 @@
1
+ # Workspace tools
2
+
3
+ Workspace tools let Kward inspect and change the local project. They are the tools behind prompts such as:
4
+
5
+ ```text
6
+ Find where configuration is loaded.
7
+ Add a focused test for this behavior.
8
+ Run the related test file.
9
+ ```
10
+
11
+ Kward normally chooses these tools itself. You do not need to know their exact names to use them, but understanding the boundaries helps explain why Kward sometimes reads before editing or asks before running broad checks.
12
+
13
+ ## Guardrails
14
+
15
+ Workspace tools use the active workspace as their boundary. File paths are workspace-relative by default, and file tools are guarded so Kward does not edit arbitrary unread files.
16
+
17
+ Important behavior:
18
+
19
+ - Existing files must be read in the current conversation before `write_file` or `edit_file` can change them.
20
+ - Reads are bounded to avoid pulling very large files into context by accident.
21
+ - Edits use exact text replacement, so accidental partial or fuzzy changes fail instead of guessing.
22
+ - Shell commands run as your operating-system user from the workspace. They are powerful and should be treated like commands you run yourself.
23
+
24
+ ## Reading the workspace
25
+
26
+ ### `list_directory`
27
+
28
+ Lists entries in a workspace-relative directory. Kward uses it to discover project structure before reading specific files.
29
+
30
+ Arguments:
31
+
32
+ - `path`: workspace-relative directory.
33
+
34
+ ### `read_file`
35
+
36
+ Reads a workspace text file. Output is capped, and Kward can continue with line offsets when it needs more detail.
37
+
38
+ Arguments:
39
+
40
+ - `path`: workspace-relative file path.
41
+ - `offset`: optional 1-indexed start line.
42
+ - `limit`: optional maximum number of lines.
43
+
44
+ A successful read marks the resolved file path as read for the conversation, allowing later edits to that file.
45
+
46
+ ### `summarize_file_structure`
47
+
48
+ Returns a compact outline of classes, modules, methods, and functions in a source file. Kward uses it when a file may be too large to read fully at first.
49
+
50
+ Arguments:
51
+
52
+ - `path`: workspace-relative source file path.
53
+
54
+ This tool saves tokens by letting Kward identify relevant entry points before requesting exact line ranges with `read_file`.
55
+
56
+ ## Changing files
57
+
58
+ ### `write_file`
59
+
60
+ Writes complete file content. Existing files must be read first. New files can be created when the path is inside the workspace.
61
+
62
+ Arguments:
63
+
64
+ - `path`: workspace-relative file path.
65
+ - `content`: complete file content.
66
+
67
+ Use full writes when replacing generated content or creating a new file. For small edits to existing files, Kward should usually prefer `edit_file`.
68
+
69
+ ### `edit_file`
70
+
71
+ Applies one or more exact replacements to a file that has already been read.
72
+
73
+ Arguments:
74
+
75
+ - `path`: workspace-relative file path.
76
+ - `edits`: array of replacements:
77
+ - `old_text`: unique exact text to replace.
78
+ - `new_text`: replacement text.
79
+
80
+ Each `old_text` must match exactly once, and replacements must not overlap. This keeps edits deterministic and avoids broad fuzzy rewriting.
81
+
82
+ ## Running commands
83
+
84
+ ### `run_shell_command`
85
+
86
+ Runs a shell command from the workspace root.
87
+
88
+ Arguments:
89
+
90
+ - `command`: command to run.
91
+ - `timeout_seconds`: optional timeout, default 30 seconds.
92
+
93
+ Kward uses shell commands for tests, linters, build checks, and simple repository inspection. Command output is bounded and may be compacted before it is sent back into model context, while the original output remains available in the session record.
94
+
95
+ ## Token behavior
96
+
97
+ Workspace tools are intentionally incremental:
98
+
99
+ 1. list directories to find likely files,
100
+ 2. summarize large source files before reading everything,
101
+ 3. read focused line ranges,
102
+ 4. make exact edits,
103
+ 5. run focused verification commands.
104
+
105
+ This keeps the model's context window focused on relevant evidence instead of flooding it with entire repositories or long command output.