@dudong2/pi-context 0.0.0-stage → 0.3.2-rev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +274 -2
- package/dist/commands/context-command.d.ts +2 -0
- package/dist/commands/context-command.js +65 -0
- package/dist/commands/context-command.js.map +1 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.js +184 -0
- package/dist/config.js.map +1 -0
- package/dist/context-format.d.ts +20 -0
- package/dist/context-format.js +200 -0
- package/dist/context-format.js.map +1 -0
- package/dist/context-scope.d.ts +7 -0
- package/dist/context-scope.js +44 -0
- package/dist/context-scope.js.map +1 -0
- package/dist/eval/checks.d.ts +9 -0
- package/dist/eval/checks.js +241 -0
- package/dist/eval/checks.js.map +1 -0
- package/dist/eval/codemode-benchmark.d.ts +25 -0
- package/dist/eval/codemode-benchmark.js +308 -0
- package/dist/eval/codemode-benchmark.js.map +1 -0
- package/dist/eval/fixtures.d.ts +31 -0
- package/dist/eval/fixtures.js +79 -0
- package/dist/eval/fixtures.js.map +1 -0
- package/dist/eval/index.d.ts +4 -0
- package/dist/eval/index.js +56 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/report.d.ts +3 -0
- package/dist/eval/report.js +45 -0
- package/dist/eval/report.js.map +1 -0
- package/dist/eval/scenarios.d.ts +3 -0
- package/dist/eval/scenarios.js +52 -0
- package/dist/eval/scenarios.js.map +1 -0
- package/dist/eval/types.d.ts +48 -0
- package/dist/eval/types.js +2 -0
- package/dist/eval/types.js.map +1 -0
- package/dist/export-files.d.ts +9 -0
- package/dist/export-files.js +45 -0
- package/dist/export-files.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +2 -0
- package/dist/lifecycle.js +59 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/policy.d.ts +3 -0
- package/dist/policy.js +39 -0
- package/dist/policy.js.map +1 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +39 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.sql +49 -0
- package/dist/store/maintenance.d.ts +19 -0
- package/dist/store/maintenance.js +155 -0
- package/dist/store/maintenance.js.map +1 -0
- package/dist/store/registry.d.ts +7 -0
- package/dist/store/registry.js +44 -0
- package/dist/store/registry.js.map +1 -0
- package/dist/store/retrieval.d.ts +8 -0
- package/dist/store/retrieval.js +127 -0
- package/dist/store/retrieval.js.map +1 -0
- package/dist/store/row-schemas.d.ts +73 -0
- package/dist/store/row-schemas.js +74 -0
- package/dist/store/row-schemas.js.map +1 -0
- package/dist/store.d.ts +53 -0
- package/dist/store.js +408 -0
- package/dist/store.js.map +1 -0
- package/dist/text.d.ts +11 -0
- package/dist/text.js +226 -0
- package/dist/text.js.map +1 -0
- package/dist/tool-output.d.ts +6 -0
- package/dist/tool-output.js +48 -0
- package/dist/tool-output.js.map +1 -0
- package/dist/tools/export.d.ts +2 -0
- package/dist/tools/export.js +99 -0
- package/dist/tools/export.js.map +1 -0
- package/dist/tools/get.d.ts +2 -0
- package/dist/tools/get.js +61 -0
- package/dist/tools/get.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list.d.ts +2 -0
- package/dist/tools/list.js +72 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/output-schemas.d.ts +93 -0
- package/dist/tools/output-schemas.js +89 -0
- package/dist/tools/output-schemas.js.map +1 -0
- package/dist/tools/purge.d.ts +2 -0
- package/dist/tools/purge.js +73 -0
- package/dist/tools/purge.js.map +1 -0
- package/dist/tools/search.d.ts +2 -0
- package/dist/tools/search.js +63 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/stats.d.ts +2 -0
- package/dist/tools/stats.js +37 -0
- package/dist/tools/stats.js.map +1 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/menu.d.ts +8 -0
- package/dist/ui/menu.js +88 -0
- package/dist/ui/menu.js.map +1 -0
- package/dist/ui/settings.d.ts +7 -0
- package/dist/ui/settings.js +353 -0
- package/dist/ui/settings.js.map +1 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Scott Spence
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,275 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @spences10/pi-context
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- package-readme:header:start -->
|
|
4
|
+
|
|
5
|
+
[](https://viteplus.dev)
|
|
6
|
+
[](https://vitest.dev)
|
|
7
|
+
[](https://www.npmjs.com/package/@spences10/pi-context)
|
|
8
|
+
[](https://www.npmjs.com/package/@spences10/pi-context)
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
<!-- package-readme:header:end -->
|
|
13
|
+
|
|
14
|
+
Keep huge tool output useful without flooding the model context.
|
|
15
|
+
`pi-context` stores oversized model-facing command, file, MCP, and LSP
|
|
16
|
+
results in a local searchable SQLite sidecar, then gives the agent
|
|
17
|
+
compact receipts it can search or retrieve when needed.
|
|
18
|
+
|
|
19
|
+
With native Pi codemode, intermediate tool results pass through
|
|
20
|
+
unchanged by the sidecar so scripts can filter or aggregate them
|
|
21
|
+
before returning anything to the model. Only oversized final output is
|
|
22
|
+
captured. Existing permission and redaction hooks still apply. The
|
|
23
|
+
sidecar is a searchable overflow fallback, not a replacement for
|
|
24
|
+
codemode filtering.
|
|
25
|
+
|
|
26
|
+
A deterministic native-codemode benchmark (five workloads, three
|
|
27
|
+
repeats) reduced model-facing output from **5,872 to 831 bytes** per
|
|
28
|
+
suite compared with the previous sidecar behavior, with identical
|
|
29
|
+
answers and retrieval calls reduced from four to one. These are
|
|
30
|
+
**output bytes, not measured API tokens or billed cost**. Filtering
|
|
31
|
+
workloads matched native-only output size without SQLite captures;
|
|
32
|
+
final oversized output remained searchable. Methodology, native-only
|
|
33
|
+
comparison, limitations, and reproduction commands are in the
|
|
34
|
+
[benchmark notes](https://github.com/spences10/my-pi/blob/main/docs/pi-context-benchmark.md#native-codemode-benchmark).
|
|
35
|
+
|
|
36
|
+
The context tools use normal object-schema tool calling because their
|
|
37
|
+
optional filters are not portable across providers' strict-schema
|
|
38
|
+
rules. They also declare native output schemas: codemode receives
|
|
39
|
+
structured results rather than formatted prose. Search returns
|
|
40
|
+
`{ results }`, get returns `{ chunks, message }`, list returns
|
|
41
|
+
`{ sources }`, export returns metadata including `file_path`, and
|
|
42
|
+
stats/purge return their accounting/deletion fields. Missing get or
|
|
43
|
+
export results carry an explanatory `message`; export uses
|
|
44
|
+
`exported: false` and `file_path: null` when nothing was written.
|
|
45
|
+
|
|
46
|
+
In a SvelteKit docs extraction benchmark against the published
|
|
47
|
+
full-chunk retrieval flow, snippet-first search plus focused retrieval
|
|
48
|
+
and file export reduced total tokens by **68%**, cache-read tokens by
|
|
49
|
+
**70%**, and cost by **54%** while producing a comparable answer. See
|
|
50
|
+
[`docs/pi-context-benchmark.md`](https://github.com/spences10/my-pi/blob/main/docs/pi-context-benchmark.md)
|
|
51
|
+
for the scenario and raw comparison.
|
|
52
|
+
|
|
53
|
+
| Metric | Published | Current flow | Reduction |
|
|
54
|
+
| --------------------------- | --------: | -----------: | --------: |
|
|
55
|
+
| Tool calls | 49 | 27 | 45% |
|
|
56
|
+
| Context tool chars returned | 438,655 | 181,417 | 59% |
|
|
57
|
+
| Total tool chars returned | 488,258 | 196,530 | 60% |
|
|
58
|
+
| Input tokens | 163,626 | 116,844 | 29% |
|
|
59
|
+
| Cache-read tokens | 2,943,488 | 884,224 | 70% |
|
|
60
|
+
| Total tokens | 3,113,785 | 1,004,674 | 68% |
|
|
61
|
+
| Cost | $2.49 | $1.13 | 54% |
|
|
62
|
+
|
|
63
|
+
This is an ephemeral overflow cache for large artifacts, not durable
|
|
64
|
+
session memory. Use `pirecall` for durable session history.
|
|
65
|
+
|
|
66
|
+
## Runtime
|
|
67
|
+
|
|
68
|
+
Requires Node.js `>=24.15.0` for native `node:sqlite` plus FTS5. The
|
|
69
|
+
`pi` and `my-pi` CLIs suppress Node's expected `node:sqlite`
|
|
70
|
+
`ExperimentalWarning`; standalone package consumers own their process
|
|
71
|
+
warning policy until Node marks `node:sqlite` stable.
|
|
72
|
+
|
|
73
|
+
## Local development
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm --filter @spences10/pi-context run build
|
|
77
|
+
pi install ./packages/pi-context
|
|
78
|
+
# or for one run only
|
|
79
|
+
pi -e ./packages/pi-context
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Commands/tools
|
|
83
|
+
|
|
84
|
+
- `context_search` — search indexed tool output in the current
|
|
85
|
+
project/session scope by default. Use it snippet-first before
|
|
86
|
+
retrieving chunks. `full_content: true` returns full matched chunks
|
|
87
|
+
and should be a last resort for small matches, not broad retrieval.
|
|
88
|
+
Pass `global: true` to search all scopes.
|
|
89
|
+
- `context_get` — retrieve focused stored chunks by source id into the
|
|
90
|
+
model context. Normally pass `source_id` plus `chunk_id`, then add
|
|
91
|
+
`before` / `after` to include nearby surrounding chunks without
|
|
92
|
+
retrieving the full source. Neighbor ranges are capped at 3 chunks
|
|
93
|
+
each side; omitting `chunk_id` is exceptional full-source chat
|
|
94
|
+
retrieval. Use `context_export` for broader inspection.
|
|
95
|
+
- `context_export` — write full or ranged stored chunks to a managed
|
|
96
|
+
export file without returning chunk content to the model, useful
|
|
97
|
+
before `jq`, Python, `sed`, `awk`, or `rg` processing. Omit
|
|
98
|
+
`chunk_id` when you intentionally want full-source offline
|
|
99
|
+
processing. Pass `file_path` to choose a destination.
|
|
100
|
+
- `context_list` / `/context list [limit]` — list recent indexed
|
|
101
|
+
sources in the current scope with source ids, tool names, sizes, and
|
|
102
|
+
previews.
|
|
103
|
+
- `context_stats` / `/context stats` / `/context-stats` — scoped
|
|
104
|
+
totals, global totals, DB size, oldest/newest sources, and active
|
|
105
|
+
retention policy.
|
|
106
|
+
- `context_purge` / `/context purge [days]` — delete old indexed
|
|
107
|
+
output. Also supports source/project/session filters and
|
|
108
|
+
`/context purge expired`.
|
|
109
|
+
- `/context settings` — choose retention/size presets or inspect the
|
|
110
|
+
effective saved/env-backed policy.
|
|
111
|
+
|
|
112
|
+
`context_stats` and `context_purge` use native deferred exposure to
|
|
113
|
+
avoid adding their definitions to every model request. Find them with
|
|
114
|
+
codemode `searchTools()` or an enabled native `tool_search`; their
|
|
115
|
+
slash commands remain available without codemode.
|
|
116
|
+
|
|
117
|
+
Use `/context` in interactive mode for a small modal with list, stats,
|
|
118
|
+
settings, and purge actions.
|
|
119
|
+
|
|
120
|
+
## Programmatic API
|
|
121
|
+
|
|
122
|
+
The default export is the Pi extension. The root module also exposes
|
|
123
|
+
sidecar helpers used by sibling packages and custom harnesses:
|
|
124
|
+
|
|
125
|
+
- context settings helpers such as `get_context_capture_limits()` and
|
|
126
|
+
`load_context_settings_config()` for sharing retention and capture
|
|
127
|
+
policy.
|
|
128
|
+
- store helpers such as `get_context_store()` and
|
|
129
|
+
`set_context_sidecar_enabled()` for controlled direct indexing and
|
|
130
|
+
tests.
|
|
131
|
+
- eval helpers `run_context_eval()` and `run_context_eval_cli()` for
|
|
132
|
+
package evaluation workflows.
|
|
133
|
+
|
|
134
|
+
The `./store` subpath exposes the store API, including
|
|
135
|
+
`maybe_store_context_output()`, for store-only consumers.
|
|
136
|
+
|
|
137
|
+
Receipts include the source id, first exact chunk id, capture reason,
|
|
138
|
+
and a preview capped at eight lines / 768 bytes (plus an omission
|
|
139
|
+
notice). Reusable retrieval guidance lives in tool descriptions rather
|
|
140
|
+
than being repeated in every receipt. Use the ids with these tools:
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
First chunk id: ctx_..._0001
|
|
144
|
+
context_search query:"..." source_id:"ctx_..."
|
|
145
|
+
context_get source_id:"ctx_..." chunk_id:"ctx_..._0001" before:1 after:1
|
|
146
|
+
context_export source_id:"ctx_..."
|
|
147
|
+
context_list
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`context_get` accepts exact chunk ids plus ordinal aliases such as `1`
|
|
151
|
+
or `0001`, and legacy guessed references such as `ctx_...:chunk:000`.
|
|
152
|
+
Use `before` / `after` with `chunk_id` to include neighboring chunks
|
|
153
|
+
in one call. Neighbor ranges are capped at 3 chunks each side to avoid
|
|
154
|
+
accidentally recreating full-source retrieval. `context_export`
|
|
155
|
+
accepts the same source/chunk selectors and neighbor options. By
|
|
156
|
+
default it writes to
|
|
157
|
+
`${PI_CODING_AGENT_DIR:-~/.pi/agent}/context-exports/`, next to the
|
|
158
|
+
sidecar database, and cleans that managed export directory using the
|
|
159
|
+
same retention-days policy as the sidecar. Pass `file_path` to write
|
|
160
|
+
elsewhere; relative paths resolve from the current working directory.
|
|
161
|
+
The tool returns only export metadata.
|
|
162
|
+
|
|
163
|
+
## Coverage policy
|
|
164
|
+
|
|
165
|
+
Intentional sidecar-backed output:
|
|
166
|
+
|
|
167
|
+
- Top-level `read`, `bash`, and final `codemode` text output: handled
|
|
168
|
+
by the generic `tool_result` hook when output exceeds byte/line
|
|
169
|
+
thresholds. Non-text content such as images is preserved alongside
|
|
170
|
+
the receipt.
|
|
171
|
+
- Pi native MCP tool output: handled by the generic hook like other
|
|
172
|
+
top-level text tool results. Text that already contains a
|
|
173
|
+
`[context-sidecar]` receipt is not indexed again.
|
|
174
|
+
- Native Bash/PowerShell structured output and text-only MCP results
|
|
175
|
+
are preferred over their potentially truncated model-facing
|
|
176
|
+
previews. The sidecar redacts this text before persistence. Native
|
|
177
|
+
bounded output is explicitly marked partial; the sidecar does not
|
|
178
|
+
automatically read native temporary files or recover omitted text.
|
|
179
|
+
Read results and converted MCP resources retain their native
|
|
180
|
+
selected-range/truncation semantics.
|
|
181
|
+
- LSP tool output: handled by the generic hook for large text
|
|
182
|
+
diagnostics or symbol/reference dumps; small structured summaries
|
|
183
|
+
stay inline.
|
|
184
|
+
- Team Mode output: list actions are bounded at source; unusually
|
|
185
|
+
large full-detail results use the generic hook and return a sidecar
|
|
186
|
+
receipt.
|
|
187
|
+
- Hook output and telemetry summaries: not directly indexed unless
|
|
188
|
+
they appear as large text tool results.
|
|
189
|
+
|
|
190
|
+
Intentionally skipped output:
|
|
191
|
+
|
|
192
|
+
- Nested calls carrying `parentToolCallId`, including codemode tool
|
|
193
|
+
calls: intermediate output belongs to the calling tool, which can
|
|
194
|
+
filter it before deciding what to return to the model. This also
|
|
195
|
+
preserves native structured result contracts.
|
|
196
|
+
- Results marked `isError: true`: error diagnostics stay inline in the
|
|
197
|
+
session instead of depending on the expiring sidecar.
|
|
198
|
+
- `context_*` tools: avoids recursive indexing of
|
|
199
|
+
retrieval/maintenance output.
|
|
200
|
+
- Non-text/image results: ignored by `pi-context`; image/file handling
|
|
201
|
+
should use dedicated tool-specific surfaces.
|
|
202
|
+
|
|
203
|
+
Any newly sidecar-backed text follows the same redaction,
|
|
204
|
+
project/session scope, retention, and dedupe rules. Duplicate outputs
|
|
205
|
+
reuse an existing source only when that source is visible to the same
|
|
206
|
+
default retrieval scope.
|
|
207
|
+
|
|
208
|
+
## Storage, scoping, and retention
|
|
209
|
+
|
|
210
|
+
The default DB path is
|
|
211
|
+
`${PI_CODING_AGENT_DIR:-~/.pi/agent}/context.db`. Set
|
|
212
|
+
`MY_PI_CONTEXT_DB` to override it.
|
|
213
|
+
|
|
214
|
+
Default `context_export` files are written next to that database under
|
|
215
|
+
`context-exports/`, for example
|
|
216
|
+
`${PI_CODING_AGENT_DIR:-~/.pi/agent}/context-exports/ctx_....txt`.
|
|
217
|
+
Older managed export files are pruned on export using the same
|
|
218
|
+
retention-days setting as the sidecar.
|
|
219
|
+
|
|
220
|
+
New sources are scoped by Pi session file/id when available, falling
|
|
221
|
+
back to the current project path. Retrieval tools use that scope by
|
|
222
|
+
default to avoid leaking other projects or sessions into results; pass
|
|
223
|
+
`global: true` when you intend to search or list everything.
|
|
224
|
+
|
|
225
|
+
Retention, storage cap, and capture thresholds are saved at
|
|
226
|
+
`~/.config/my-pi/context.json` via `/context settings`. Presets
|
|
227
|
+
include `default`, `light`, `balanced`, `research`, and `archive`;
|
|
228
|
+
custom values are available with:
|
|
229
|
+
|
|
230
|
+
```text
|
|
231
|
+
/context settings custom <days|off> <max-mb|off> [capture-kb] [capture-lines] [purge-on-shutdown]
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Saved settings are validated with Valibot on load. Malformed JSON and
|
|
235
|
+
non-object values are ignored. Invalid fields fall back independently
|
|
236
|
+
to preset defaults; explicit `null` retention and size caps are
|
|
237
|
+
preserved.
|
|
238
|
+
|
|
239
|
+
Capture thresholds control when large tool output is moved into the
|
|
240
|
+
sidecar instead of staying inline in the model context. Defaults match
|
|
241
|
+
historical behavior: tools capture after `24 KiB` or `300` lines.
|
|
242
|
+
|
|
243
|
+
Environment variables override saved settings:
|
|
244
|
+
|
|
245
|
+
- `MY_PI_CONTEXT_RETENTION_DAYS` — default `7`; set `0`, `off`, or
|
|
246
|
+
`disabled` to disable age cleanup.
|
|
247
|
+
- `MY_PI_CONTEXT_PURGE_ON_SHUTDOWN` — set `true`/`1`/`yes`/`on` to run
|
|
248
|
+
cleanup on shutdown.
|
|
249
|
+
- `MY_PI_CONTEXT_MAX_MB` — optional max stored raw bytes; oldest
|
|
250
|
+
sources are removed first when exceeded.
|
|
251
|
+
- `MY_PI_CONTEXT_CAPTURE_MAX_KB` / `MY_PI_CONTEXT_CAPTURE_MAX_LINES` —
|
|
252
|
+
generic tool-output capture threshold.
|
|
253
|
+
- `MY_PI_CONTEXT_CONFIG` — override the saved settings file path.
|
|
254
|
+
|
|
255
|
+
## Safety model
|
|
256
|
+
|
|
257
|
+
This is redacted local persistence and retrieval, not a security
|
|
258
|
+
sandbox. Stored text is redacted with `@spences10/pi-redact` before
|
|
259
|
+
persistence, but anything persisted in the local SQLite DB should
|
|
260
|
+
still be treated as local tool output.
|
|
261
|
+
|
|
262
|
+
## Development
|
|
263
|
+
|
|
264
|
+
<!-- package-readme:development:start commands="check,test,build" -->
|
|
265
|
+
|
|
266
|
+
Package scripts build transitive workspace dependencies first, then
|
|
267
|
+
run local tools through Vite+ with `vp exec`.
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
pnpm --filter @spences10/pi-context run check
|
|
271
|
+
pnpm --filter @spences10/pi-context run test
|
|
272
|
+
pnpm --filter @spences10/pi-context run build
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
<!-- package-readme:development:end -->
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { purge_context, show_context_list, show_context_menu, } from '../ui/menu.js';
|
|
2
|
+
import { handle_context_settings, show_context_stats, } from '../ui/settings.js';
|
|
3
|
+
export function register_context_commands(pi) {
|
|
4
|
+
pi.registerCommand('context', {
|
|
5
|
+
description: 'Inspect and manage the context sidecar',
|
|
6
|
+
getArgumentCompletions: (prefix) => ['list', 'stats', 'settings', 'purge'].flatMap((item) => item.startsWith(prefix.trim())
|
|
7
|
+
? [{ value: item, label: item }]
|
|
8
|
+
: []),
|
|
9
|
+
handler: async (args, ctx) => {
|
|
10
|
+
const [sub = '', ...rest] = args
|
|
11
|
+
.trim()
|
|
12
|
+
.split(/\s+/)
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
if (!sub && ctx.hasUI) {
|
|
15
|
+
await show_context_menu(ctx);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
switch (sub || 'list') {
|
|
19
|
+
case 'list': {
|
|
20
|
+
const [limit_text] = rest;
|
|
21
|
+
const limit = limit_text ? Number(limit_text) : undefined;
|
|
22
|
+
if (limit !== undefined && !Number.isFinite(limit)) {
|
|
23
|
+
ctx.ui.notify('Usage: /context list [limit]', 'warning');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
await show_context_list(ctx, limit);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
case 'stats':
|
|
30
|
+
await show_context_stats(ctx);
|
|
31
|
+
return;
|
|
32
|
+
case 'settings':
|
|
33
|
+
await handle_context_settings(ctx, rest);
|
|
34
|
+
return;
|
|
35
|
+
case 'purge': {
|
|
36
|
+
const [kind, value] = rest;
|
|
37
|
+
if (kind === 'expired') {
|
|
38
|
+
await purge_context(ctx, { expired: true });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (kind === 'source' && value) {
|
|
42
|
+
await purge_context(ctx, { source_id: value });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const days = kind ? Number(kind) : undefined;
|
|
46
|
+
if (days !== undefined && !Number.isFinite(days)) {
|
|
47
|
+
ctx.ui.notify('Usage: /context purge [older-than-days] | expired | source <source-id>', 'warning');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await purge_context(ctx, { older_than_days: days });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
default:
|
|
54
|
+
ctx.ui.notify(`Unknown context command: ${sub}. Use list, stats, settings, or purge.`, 'warning');
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
pi.registerCommand('context-stats', {
|
|
59
|
+
description: 'Show context sidecar byte accounting',
|
|
60
|
+
handler: async (_args, ctx) => {
|
|
61
|
+
await show_context_stats(ctx);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=context-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-command.js","sourceRoot":"","sources":["../../src/commands/context-command.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,UAAU,yBAAyB,CAAC,EAAgB;IACzD,EAAE,CAAC,eAAe,CAAC,SAAS,EAAE;QAC7B,WAAW,EAAE,wCAAwC;QACrD,sBAAsB,EAAE,CAAC,MAAM,EAAE,EAAE,CAClC,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACvD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC7B,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAChC,CAAC,CAAC,EAAE,CACL;QACF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;YAC5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AK,QAAQ,IAAI,KAAK,EAAE,CAAC;wBAChC,MAAM,aAAa,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;wBAE/C,OAAO;oBACR,CAAC;oBAED,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;oBAE7C,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;wBAClD,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,wEAAwE,EACxE,SAAS,CACT,CAAC;wBAEF,OAAO;oBACR,CAAC;oBAED,MAAM,aAAa,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;oBAEpD,OAAO;gBACR,CAAC;gBAED;oBACC,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,4BAA4B,GAAG,wCAAwC,EACvE,SAAS,CACT,CAAC;YACJ,CAAC;QACF,CAAC;KACD,CAAC,CAAC;IAEH,EAAE,CAAC,eAAe,CAAC,eAAe,EAAE;QACnC,WAAW,EAAE,sCAAsC;QACnD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC7B,MAAM,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type ContextSettingsPreset = 'default' | 'light' | 'balanced' | 'research' | 'archive';
|
|
2
|
+
export interface ContextOutputLimits {
|
|
3
|
+
max_bytes: number;
|
|
4
|
+
max_lines: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ContextSettingsValues {
|
|
7
|
+
retention_days: number | null;
|
|
8
|
+
max_mb: number | null;
|
|
9
|
+
purge_on_shutdown: boolean;
|
|
10
|
+
capture_max_bytes: number;
|
|
11
|
+
capture_max_lines: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ContextSettingsConfig extends ContextSettingsValues {
|
|
14
|
+
version: 1;
|
|
15
|
+
preset: ContextSettingsPreset | 'custom';
|
|
16
|
+
}
|
|
17
|
+
export interface ContextSettingsPresetDefinition extends ContextSettingsValues {
|
|
18
|
+
label: string;
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_CONTEXT_CAPTURE_MAX_BYTES: number;
|
|
22
|
+
export declare const DEFAULT_CONTEXT_CAPTURE_MAX_LINES = 300;
|
|
23
|
+
export declare const CONTEXT_SETTINGS_PRESETS: Record<ContextSettingsPreset, ContextSettingsPresetDefinition>;
|
|
24
|
+
export declare const DEFAULT_CONTEXT_SETTINGS: ContextSettingsConfig;
|
|
25
|
+
export declare function get_context_settings_config_path(): string;
|
|
26
|
+
export declare function context_settings_from_preset(preset: ContextSettingsPreset): ContextSettingsConfig;
|
|
27
|
+
export declare function load_context_settings_config(): ContextSettingsConfig | null;
|
|
28
|
+
export declare function save_context_settings_config(config: ContextSettingsConfig): void;
|
|
29
|
+
export declare function get_context_capture_limits(env?: NodeJS.ProcessEnv): ContextOutputLimits;
|
|
30
|
+
export declare function normalize_context_settings_config(value: Partial<ContextSettingsConfig>): ContextSettingsConfig;
|
|
31
|
+
export declare function is_context_settings_preset(value: unknown): value is ContextSettingsPreset;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { read_package_settings, write_package_settings, } from '@spences10/pi-settings';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import * as v from 'valibot';
|
|
6
|
+
const context_settings_preset_schema = v.picklist([
|
|
7
|
+
'default',
|
|
8
|
+
'light',
|
|
9
|
+
'balanced',
|
|
10
|
+
'research',
|
|
11
|
+
'archive',
|
|
12
|
+
]);
|
|
13
|
+
const positive_number_schema = v.pipe(v.number(), v.finite(), v.minValue(Number.MIN_VALUE));
|
|
14
|
+
// Invalid fields fall back independently to the selected preset below.
|
|
15
|
+
const context_settings_input_schema = v.pipe(v.unknown(), v.check((value) => !Array.isArray(value)), v.object({
|
|
16
|
+
preset: v.fallback(v.optional(v.union([
|
|
17
|
+
context_settings_preset_schema,
|
|
18
|
+
v.literal('custom'),
|
|
19
|
+
])), undefined),
|
|
20
|
+
retention_days: v.fallback(v.optional(v.nullable(positive_number_schema)), undefined),
|
|
21
|
+
max_mb: v.fallback(v.optional(v.nullable(positive_number_schema)), undefined),
|
|
22
|
+
purge_on_shutdown: v.fallback(v.optional(v.boolean()), undefined),
|
|
23
|
+
capture_max_bytes: v.fallback(v.optional(positive_number_schema), undefined),
|
|
24
|
+
capture_max_lines: v.fallback(v.optional(positive_number_schema), undefined),
|
|
25
|
+
}));
|
|
26
|
+
export const DEFAULT_CONTEXT_CAPTURE_MAX_BYTES = 24 * 1024;
|
|
27
|
+
export const DEFAULT_CONTEXT_CAPTURE_MAX_LINES = 300;
|
|
28
|
+
export const CONTEXT_SETTINGS_PRESETS = {
|
|
29
|
+
default: {
|
|
30
|
+
label: 'Default',
|
|
31
|
+
description: '7 days, no size cap; capture after 24 KiB / 300 lines',
|
|
32
|
+
retention_days: 7,
|
|
33
|
+
max_mb: null,
|
|
34
|
+
purge_on_shutdown: false,
|
|
35
|
+
capture_max_bytes: DEFAULT_CONTEXT_CAPTURE_MAX_BYTES,
|
|
36
|
+
capture_max_lines: DEFAULT_CONTEXT_CAPTURE_MAX_LINES,
|
|
37
|
+
},
|
|
38
|
+
light: {
|
|
39
|
+
label: 'Light',
|
|
40
|
+
description: '1 day, 50 MiB cap; capture after 16 KiB / 200 lines',
|
|
41
|
+
retention_days: 1,
|
|
42
|
+
max_mb: 50,
|
|
43
|
+
purge_on_shutdown: false,
|
|
44
|
+
capture_max_bytes: 16 * 1024,
|
|
45
|
+
capture_max_lines: 200,
|
|
46
|
+
},
|
|
47
|
+
balanced: {
|
|
48
|
+
label: 'Balanced',
|
|
49
|
+
description: '7 days, 250 MiB cap; capture after 24 KiB / 300 lines',
|
|
50
|
+
retention_days: 7,
|
|
51
|
+
max_mb: 250,
|
|
52
|
+
purge_on_shutdown: false,
|
|
53
|
+
capture_max_bytes: DEFAULT_CONTEXT_CAPTURE_MAX_BYTES,
|
|
54
|
+
capture_max_lines: DEFAULT_CONTEXT_CAPTURE_MAX_LINES,
|
|
55
|
+
},
|
|
56
|
+
research: {
|
|
57
|
+
label: 'Research',
|
|
58
|
+
description: '30 days, 1 GiB cap; capture after 48 KiB / 600 lines',
|
|
59
|
+
retention_days: 30,
|
|
60
|
+
max_mb: 1024,
|
|
61
|
+
purge_on_shutdown: false,
|
|
62
|
+
capture_max_bytes: 48 * 1024,
|
|
63
|
+
capture_max_lines: 600,
|
|
64
|
+
},
|
|
65
|
+
archive: {
|
|
66
|
+
label: 'Archive',
|
|
67
|
+
description: '90 days, 5 GiB cap; capture after 64 KiB / 1,000 lines',
|
|
68
|
+
retention_days: 90,
|
|
69
|
+
max_mb: 5120,
|
|
70
|
+
purge_on_shutdown: false,
|
|
71
|
+
capture_max_bytes: 64 * 1024,
|
|
72
|
+
capture_max_lines: 1_000,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
export const DEFAULT_CONTEXT_SETTINGS = {
|
|
76
|
+
version: 1,
|
|
77
|
+
preset: 'default',
|
|
78
|
+
retention_days: CONTEXT_SETTINGS_PRESETS.default.retention_days,
|
|
79
|
+
max_mb: CONTEXT_SETTINGS_PRESETS.default.max_mb,
|
|
80
|
+
purge_on_shutdown: CONTEXT_SETTINGS_PRESETS.default.purge_on_shutdown,
|
|
81
|
+
capture_max_bytes: CONTEXT_SETTINGS_PRESETS.default.capture_max_bytes,
|
|
82
|
+
capture_max_lines: CONTEXT_SETTINGS_PRESETS.default.capture_max_lines,
|
|
83
|
+
};
|
|
84
|
+
export function get_context_settings_config_path() {
|
|
85
|
+
if (process.env.MY_PI_CONTEXT_CONFIG)
|
|
86
|
+
return process.env.MY_PI_CONTEXT_CONFIG;
|
|
87
|
+
const xdg = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
|
|
88
|
+
return join(xdg, 'my-pi', 'context.json');
|
|
89
|
+
}
|
|
90
|
+
export function context_settings_from_preset(preset) {
|
|
91
|
+
const definition = CONTEXT_SETTINGS_PRESETS[preset];
|
|
92
|
+
return {
|
|
93
|
+
version: 1,
|
|
94
|
+
preset,
|
|
95
|
+
retention_days: definition.retention_days,
|
|
96
|
+
max_mb: definition.max_mb,
|
|
97
|
+
purge_on_shutdown: definition.purge_on_shutdown,
|
|
98
|
+
capture_max_bytes: definition.capture_max_bytes,
|
|
99
|
+
capture_max_lines: definition.capture_max_lines,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function load_context_settings_config() {
|
|
103
|
+
const path = get_context_settings_config_path();
|
|
104
|
+
try {
|
|
105
|
+
let raw;
|
|
106
|
+
if (process.env.MY_PI_CONTEXT_CONFIG)
|
|
107
|
+
raw = existsSync(path)
|
|
108
|
+
? JSON.parse(readFileSync(path, 'utf-8'))
|
|
109
|
+
: null;
|
|
110
|
+
else
|
|
111
|
+
raw = read_package_settings('context', null);
|
|
112
|
+
const parsed = v.safeParse(context_settings_input_schema, raw);
|
|
113
|
+
if (!parsed.success)
|
|
114
|
+
return null;
|
|
115
|
+
return normalize_context_settings_config(parsed.output);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function save_context_settings_config(config) {
|
|
122
|
+
if (!process.env.MY_PI_CONTEXT_CONFIG) {
|
|
123
|
+
write_package_settings('context', config);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const path = get_context_settings_config_path();
|
|
127
|
+
const dir = dirname(path);
|
|
128
|
+
if (!existsSync(dir))
|
|
129
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
130
|
+
const tmp = `${path}.tmp-${Date.now()}`;
|
|
131
|
+
writeFileSync(tmp, JSON.stringify(config, null, '\t') + '\n', {
|
|
132
|
+
mode: 0o600,
|
|
133
|
+
});
|
|
134
|
+
renameSync(tmp, path);
|
|
135
|
+
}
|
|
136
|
+
export function get_context_capture_limits(env = process.env) {
|
|
137
|
+
const saved = load_context_settings_config();
|
|
138
|
+
const fallback = saved ?? DEFAULT_CONTEXT_SETTINGS;
|
|
139
|
+
return {
|
|
140
|
+
max_bytes: parse_positive_byte_env(env.MY_PI_CONTEXT_CAPTURE_MAX_KB, fallback.capture_max_bytes),
|
|
141
|
+
max_lines: parse_positive_number_env(env.MY_PI_CONTEXT_CAPTURE_MAX_LINES, fallback.capture_max_lines),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export function normalize_context_settings_config(value) {
|
|
145
|
+
const preset = is_context_settings_preset(value.preset)
|
|
146
|
+
? value.preset
|
|
147
|
+
: 'custom';
|
|
148
|
+
const base = preset !== 'custom'
|
|
149
|
+
? context_settings_from_preset(preset)
|
|
150
|
+
: DEFAULT_CONTEXT_SETTINGS;
|
|
151
|
+
return {
|
|
152
|
+
version: 1,
|
|
153
|
+
preset,
|
|
154
|
+
retention_days: normalize_optional_positive_number(value.retention_days, base.retention_days),
|
|
155
|
+
max_mb: normalize_optional_positive_number(value.max_mb, base.max_mb),
|
|
156
|
+
purge_on_shutdown: v.is(v.boolean(), value.purge_on_shutdown)
|
|
157
|
+
? value.purge_on_shutdown
|
|
158
|
+
: base.purge_on_shutdown,
|
|
159
|
+
capture_max_bytes: normalize_positive_number(value.capture_max_bytes, base.capture_max_bytes),
|
|
160
|
+
capture_max_lines: normalize_positive_number(value.capture_max_lines, base.capture_max_lines),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
export function is_context_settings_preset(value) {
|
|
164
|
+
return v.is(context_settings_preset_schema, value);
|
|
165
|
+
}
|
|
166
|
+
function normalize_optional_positive_number(value, fallback) {
|
|
167
|
+
const parsed = v.safeParse(v.nullable(positive_number_schema), value);
|
|
168
|
+
return parsed.success ? parsed.output : fallback;
|
|
169
|
+
}
|
|
170
|
+
function normalize_positive_number(value, fallback) {
|
|
171
|
+
const parsed = v.safeParse(positive_number_schema, value);
|
|
172
|
+
return parsed.success ? parsed.output : fallback;
|
|
173
|
+
}
|
|
174
|
+
function parse_positive_number_env(value, fallback) {
|
|
175
|
+
if (value === undefined || value.trim() === '')
|
|
176
|
+
return fallback;
|
|
177
|
+
const parsed = Number(value.trim());
|
|
178
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
179
|
+
}
|
|
180
|
+
function parse_positive_byte_env(value, fallback) {
|
|
181
|
+
const kb = parse_positive_number_env(value, fallback / 1024);
|
|
182
|
+
return Math.round(kb * 1024);
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,aAAa,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,MAAM,8BAA8B,GAAG,CAAC,CAAC,QAAQ,CAAC;IACjD,SAAS;IACT,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;CACT,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,CAAC,CAAC,IAAI,CACpC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,QAAQ,CAAC,MAAM,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ACL,CAAC;IAEF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClD,CAAC;AAED,SAAS,yBAAyB,CACjC,KAAyB,EACzB,QAAgB;IAEhB,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;IAE1D,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClD,CAAC;AAED,SAAS,yBAAyB,CACjC,KAAyB,EACzB,QAAgB;IAEhB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,QAAQ,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAEpC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClE,CAAC;AAED,SAAS,uBAAuB,CAC/B,KAAyB,EACzB,QAAgB;IAEhB,MAAM,EAAE,GAAG,yBAAyB,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;IAE7D,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ContextChunk, type ContextChunkSummary, type ContextListResult, type ContextPurgeDetails, type ContextSearchResult, type ContextStats } from './store.js';
|
|
2
|
+
export declare function format_search_results(results: ContextSearchResult[]): string;
|
|
3
|
+
export declare function format_get_result(source_id: string, chunk_id: string | undefined, chunks: ContextChunk[], summary: ContextChunkSummary | null): string;
|
|
4
|
+
export declare function format_list_results(results: ContextListResult[], options?: {
|
|
5
|
+
audience?: 'tool' | 'tui';
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function format_purge_details(details: ContextPurgeDetails): string;
|
|
8
|
+
export declare function format_stats(stats: ContextStats, options?: {
|
|
9
|
+
audience?: 'tool' | 'tui';
|
|
10
|
+
title?: boolean;
|
|
11
|
+
}): string;
|
|
12
|
+
export declare function format_timestamp(timestamp: number | null): string;
|
|
13
|
+
export declare function format_days(days: number | null): string;
|
|
14
|
+
export declare function format_max_mb(max_mb: number | null): string;
|
|
15
|
+
export declare function format_kib(bytes: number): string;
|
|
16
|
+
export declare function format_output_limit(bytes: number, lines: number): string;
|
|
17
|
+
export declare function format_context_settings_status(stats: ContextStats, options?: {
|
|
18
|
+
audience?: 'tool' | 'tui';
|
|
19
|
+
title?: boolean;
|
|
20
|
+
}): string;
|