@burtson-labs/host-kit 0.3.1
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 +201 -0
- package/README.md +55 -0
- package/dist/backgroundTasks.d.ts +113 -0
- package/dist/backgroundTasks.d.ts.map +1 -0
- package/dist/backgroundTasks.js +137 -0
- package/dist/backgroundTasks.js.map +1 -0
- package/dist/checkpoints.d.ts +99 -0
- package/dist/checkpoints.d.ts.map +1 -0
- package/dist/checkpoints.js +227 -0
- package/dist/checkpoints.js.map +1 -0
- package/dist/hooks.d.ts +51 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +152 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +398 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +1933 -0
- package/dist/insights.js.map +1 -0
- package/dist/mcp.d.ts +60 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +281 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcpConnectors.d.ts +108 -0
- package/dist/mcpConnectors.d.ts.map +1 -0
- package/dist/mcpConnectors.js +217 -0
- package/dist/mcpConnectors.js.map +1 -0
- package/dist/mcpToolCache.d.ts +43 -0
- package/dist/mcpToolCache.d.ts.map +1 -0
- package/dist/mcpToolCache.js +150 -0
- package/dist/mcpToolCache.js.map +1 -0
- package/dist/mcpTrust.d.ts +22 -0
- package/dist/mcpTrust.d.ts.map +1 -0
- package/dist/mcpTrust.js +104 -0
- package/dist/mcpTrust.js.map +1 -0
- package/dist/memory.d.ts +38 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +151 -0
- package/dist/memory.js.map +1 -0
- package/dist/memoryIndex.d.ts +38 -0
- package/dist/memoryIndex.d.ts.map +1 -0
- package/dist/memoryIndex.js +142 -0
- package/dist/memoryIndex.js.map +1 -0
- package/dist/mentions.d.ts +33 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +126 -0
- package/dist/mentions.js.map +1 -0
- package/dist/ollamaModels.d.ts +36 -0
- package/dist/ollamaModels.d.ts.map +1 -0
- package/dist/ollamaModels.js +83 -0
- package/dist/ollamaModels.js.map +1 -0
- package/dist/permissions.d.ts +72 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +271 -0
- package/dist/permissions.js.map +1 -0
- package/dist/tools/extraTools.d.ts +80 -0
- package/dist/tools/extraTools.d.ts.map +1 -0
- package/dist/tools/extraTools.js +471 -0
- package/dist/tools/extraTools.js.map +1 -0
- package/dist/tools/readMemoryTool.d.ts +3 -0
- package/dist/tools/readMemoryTool.d.ts.map +1 -0
- package/dist/tools/readMemoryTool.js +115 -0
- package/dist/tools/readMemoryTool.js.map +1 -0
- package/dist/tools/taskTool.d.ts +119 -0
- package/dist/tools/taskTool.d.ts.map +1 -0
- package/dist/tools/taskTool.js +466 -0
- package/dist/tools/taskTool.js.map +1 -0
- package/dist/tools/testRunTool.d.ts +59 -0
- package/dist/tools/testRunTool.d.ts.map +1 -0
- package/dist/tools/testRunTool.js +308 -0
- package/dist/tools/testRunTool.js.map +1 -0
- package/dist/turnLog.d.ts +89 -0
- package/dist/turnLog.d.ts.map +1 -0
- package/dist/turnLog.js +469 -0
- package/dist/turnLog.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf
|
|
170
|
+
and on Your sole responsibility, not on behalf of any other Contributor,
|
|
171
|
+
and only if You agree to indemnify, defend, and hold each Contributor
|
|
172
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
173
|
+
such Contributor by reason of your accepting any such warranty or
|
|
174
|
+
additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Burtson Labs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.burtson.ai/logos/burtson-labs-logo-alt.png" />
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://cdn.burtson.ai/logos/burtson-labs-logo.png" />
|
|
5
|
+
<img src="https://cdn.burtson.ai/logos/burtson-labs-logo-alt.png" alt="Burtson Labs" width="150" />
|
|
6
|
+
</picture>
|
|
7
|
+
|
|
8
|
+
# @burtson-labs/host-kit
|
|
9
|
+
|
|
10
|
+
**Host-agnostic building blocks shared between the Bandit CLI and the VS Code extension.**
|
|
11
|
+
|
|
12
|
+
Writing a new host (a Cursor sidebar, a JetBrains plugin, a custom CLI)? Pull from here.
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## <img src="https://api.iconify.design/lucide/package.svg?color=%23a60ee5&width=22" align="absmiddle"> Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @burtson-labs/host-kit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## <img src="https://api.iconify.design/lucide/puzzle.svg?color=%23a60ee5&width=22" align="absmiddle"> What's in the box
|
|
24
|
+
|
|
25
|
+
- **Memory loader** — discovers and merges `BANDIT.md` / `CLAUDE.md` / `AGENTS.md` files across workspace + global locations
|
|
26
|
+
- **`@-mention` expansion** — detects `@path/to/file` in user input and inlines file contents (with secret redaction) or attaches images as base64
|
|
27
|
+
- **Hook runner** — executes PreToolUse / PostToolUse / Stop / UserPromptSubmit hooks from `.bandit/settings.json` matching the Claude Code spec
|
|
28
|
+
- **MCP loader** — reads `mcp-servers.json` (global + workspace, workspace wins), auto-injects `BANDIT_API_KEY`, registers servers with the pool
|
|
29
|
+
- **Turn trace reader** — parses workspace and global `.bandit/turns/*.jsonl` into summaries and markdown timelines for CLI `/trace`, IDE `/trace`, tests, and future bug-bundle export
|
|
30
|
+
- **Insights** — usage analytics aggregator (CLI sessions → human report)
|
|
31
|
+
- **Extra tool builders** — `todo_write`, `web_fetch`, `web_search`, `task` (subagent), `remember`, `test_run`, `pdf_read`
|
|
32
|
+
|
|
33
|
+
## <img src="https://api.iconify.design/lucide/shield-check.svg?color=%23a60ee5&width=22" align="absmiddle"> Status
|
|
34
|
+
|
|
35
|
+
Stable. Imported by both [`apps/bandit-cli/`](../../apps/bandit-cli/) and [`apps/bandit-stealth/`](../../apps/bandit-stealth/) — breaking changes here require coordinated PRs to both hosts.
|
|
36
|
+
|
|
37
|
+
## <img src="https://api.iconify.design/lucide/zap.svg?color=%23a60ee5&width=22" align="absmiddle"> Quick example
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { loadMemory, expandMentions, registerMcpServersFromDisk } from '@burtson-labs/host-kit';
|
|
41
|
+
|
|
42
|
+
const memory = await loadMemory(workspaceCwd);
|
|
43
|
+
const { prompt, images } = await expandMentions(rawUserInput, workspaceCwd);
|
|
44
|
+
const count = await registerMcpServersFromDisk(workspaceCwd, mcpPool);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## <img src="https://api.iconify.design/lucide/flask-conical.svg?color=%23a60ee5&width=22" align="absmiddle"> Tests
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pnpm --filter @burtson-labs/host-kit test
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
[Apache License 2.0](../../LICENSE) — Copyright 2026 Burtson Labs.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BackgroundTaskStore — host-managed registry of long-running subagent
|
|
3
|
+
* tasks that the parent agent has spawned in the background.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists:
|
|
6
|
+
* The original `task` tool was synchronous from the parent agent's
|
|
7
|
+
* perspective: the parent's tool call awaited the subagent's full run
|
|
8
|
+
* before getting a result. That blocked the entire conversation for
|
|
9
|
+
* however long the subagent took (often minutes on local models). The
|
|
10
|
+
* user couldn't ask follow-ups or change direction mid-investigation.
|
|
11
|
+
*
|
|
12
|
+
* Background tasks fix that. The agent calls `task` with
|
|
13
|
+
* `run_in_background: true`, gets a task id back immediately, and the
|
|
14
|
+
* parent loop continues. When the subagent eventually completes, the
|
|
15
|
+
* host injects a synthetic system message before the next agent turn:
|
|
16
|
+
*
|
|
17
|
+
* [Background task abc123 completed]
|
|
18
|
+
* <synopsis>
|
|
19
|
+
*
|
|
20
|
+
* The agent can call `check_task` or `list_tasks` to inspect state on
|
|
21
|
+
* demand, but the auto-injection means it usually doesn't have to.
|
|
22
|
+
*
|
|
23
|
+
* Design notes:
|
|
24
|
+
* - This module only defines the interface + an in-memory implementation.
|
|
25
|
+
* Hosts that need persistence (cross-session resume, web app sharing
|
|
26
|
+
* tasks across browser tabs, etc) can ship their own implementation.
|
|
27
|
+
* - Cancellation is cooperative — a cancelled task stops accepting new
|
|
28
|
+
* tool-result events but the running tool call (if any) finishes
|
|
29
|
+
* first. Hard kill of a model generation in flight is provider-
|
|
30
|
+
* specific and out of scope here.
|
|
31
|
+
* - We surface progress as tool-call counts rather than streaming a
|
|
32
|
+
* live tool log — the live log is high-volume and noisy for the
|
|
33
|
+
* "how's that task going" status check the agent actually wants.
|
|
34
|
+
*/
|
|
35
|
+
export type BackgroundTaskStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
36
|
+
export interface BackgroundTaskRecord {
|
|
37
|
+
id: string;
|
|
38
|
+
goal: string;
|
|
39
|
+
status: BackgroundTaskStatus;
|
|
40
|
+
/** Wall-clock when the task was spawned. */
|
|
41
|
+
startedAt: number;
|
|
42
|
+
/** Wall-clock when the task reached a terminal state. Undefined while running. */
|
|
43
|
+
endedAt?: number;
|
|
44
|
+
/** Subagent iteration count at last update. */
|
|
45
|
+
iterations: number;
|
|
46
|
+
/** Number of tool calls the subagent has made so far. */
|
|
47
|
+
toolCalls: number;
|
|
48
|
+
/** Last tool name the subagent called — handy for status display. */
|
|
49
|
+
lastTool?: string;
|
|
50
|
+
/** Final synopsis when status === 'completed'. */
|
|
51
|
+
synopsis?: string;
|
|
52
|
+
/** Error message when status === 'failed'. */
|
|
53
|
+
error?: string;
|
|
54
|
+
/** True after the parent agent has consumed the completion event
|
|
55
|
+
* (via auto-injection or check_task). Lets the host stop showing the
|
|
56
|
+
* task in the "needs attention" UI section. */
|
|
57
|
+
consumed: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface BackgroundTaskProgress {
|
|
60
|
+
iterations?: number;
|
|
61
|
+
toolCalls?: number;
|
|
62
|
+
lastTool?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface BackgroundTaskStore {
|
|
65
|
+
/**
|
|
66
|
+
* Register a newly-spawned task. The store assigns and returns the id.
|
|
67
|
+
* The host is expected to actually run the subagent — this method
|
|
68
|
+
* just records the record and emits a `start` event.
|
|
69
|
+
*/
|
|
70
|
+
start(goal: string): string;
|
|
71
|
+
/** Update progress fields on an in-flight task. No-op if id unknown. */
|
|
72
|
+
progress(id: string, progress: BackgroundTaskProgress): void;
|
|
73
|
+
/** Mark the task completed with its final synopsis. */
|
|
74
|
+
complete(id: string, synopsis: string): void;
|
|
75
|
+
/** Mark the task failed with an error message. */
|
|
76
|
+
fail(id: string, error: string): void;
|
|
77
|
+
/** Mark the task cancelled. The actual subagent kill is the host's
|
|
78
|
+
* responsibility — this method just flips the status so subsequent
|
|
79
|
+
* progress events are dropped. */
|
|
80
|
+
cancel(id: string): void;
|
|
81
|
+
/** Get a single task record by id, or undefined. */
|
|
82
|
+
get(id: string): BackgroundTaskRecord | undefined;
|
|
83
|
+
/** All known tasks. Order is start-time ascending. */
|
|
84
|
+
list(): BackgroundTaskRecord[];
|
|
85
|
+
/** Subset filtered by status. Convenience over filtering list(). */
|
|
86
|
+
listByStatus(status: BackgroundTaskStatus): BackgroundTaskRecord[];
|
|
87
|
+
/** Mark a completed/failed/cancelled task as consumed. */
|
|
88
|
+
markConsumed(id: string): void;
|
|
89
|
+
/** Subscribe to task lifecycle events. Returns an unsubscribe fn. */
|
|
90
|
+
on(event: 'start' | 'progress' | 'complete' | 'failed' | 'cancelled', listener: (record: BackgroundTaskRecord) => void): () => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* In-memory store. Per-session, no persistence. Suitable for the CLI
|
|
94
|
+
* and the VS Code extension session lifetime. A web host that wants
|
|
95
|
+
* resume-across-reload can implement the same interface backed by
|
|
96
|
+
* IndexedDB or a server endpoint.
|
|
97
|
+
*/
|
|
98
|
+
export declare class InMemoryBackgroundTaskStore implements BackgroundTaskStore {
|
|
99
|
+
private readonly tasks;
|
|
100
|
+
private readonly emitter;
|
|
101
|
+
private idCounter;
|
|
102
|
+
start(goal: string): string;
|
|
103
|
+
progress(id: string, progress: BackgroundTaskProgress): void;
|
|
104
|
+
complete(id: string, synopsis: string): void;
|
|
105
|
+
fail(id: string, error: string): void;
|
|
106
|
+
cancel(id: string): void;
|
|
107
|
+
get(id: string): BackgroundTaskRecord | undefined;
|
|
108
|
+
list(): BackgroundTaskRecord[];
|
|
109
|
+
listByStatus(status: BackgroundTaskStatus): BackgroundTaskRecord[];
|
|
110
|
+
markConsumed(id: string): void;
|
|
111
|
+
on(event: 'start' | 'progress' | 'complete' | 'failed' | 'cancelled', listener: (record: BackgroundTaskRecord) => void): () => void;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=backgroundTasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backgroundTasks.d.ts","sourceRoot":"","sources":["../src/backgroundTasks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpF,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,CAAC;IAC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ned in the background.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists:
|
|
7
|
+
* The original `task` tool was synchronous from the parent agent's
|
|
8
|
+
* perspective: the parent's tool call awaited the subagent's full run
|
|
9
|
+
* before getting a result. That blocked the entire conversation for
|
|
10
|
+
* however long the subagent took (often minutes on local models). The
|
|
11
|
+
* user couldn't ask follow-ups or change direction mid-investigation.
|
|
12
|
+
*
|
|
13
|
+
* Background tasks fix that. The agent calls `task` with
|
|
14
|
+
* `run_in_background: true`, gets a task id back immediately, and the
|
|
15
|
+
* parent loop continues. When the subagent eventually completes, the
|
|
16
|
+
* host injects a synthetic system message before the next agent turn:
|
|
17
|
+
*
|
|
18
|
+
* [Background task abc123 completed]
|
|
19
|
+
* <synopsis>
|
|
20
|
+
*
|
|
21
|
+
* The agent can call `check_task` or `list_tasks` to inspect state on
|
|
22
|
+
* demand, but the auto-injection means it usually doesn't have to.
|
|
23
|
+
*
|
|
24
|
+
* Design notes:
|
|
25
|
+
* - This module only defines the interface + an in-memory implementation.
|
|
26
|
+
* Hosts that need persistence (cross-session resume, web app sharing
|
|
27
|
+
* tasks across browser tabs, etc) can ship their own implementation.
|
|
28
|
+
* - Cancellation is cooperative — a cancelled task stops accepting new
|
|
29
|
+
* tool-result events but the running tool call (if any) finishes
|
|
30
|
+
* first. Hard kill of a model generation in flight is provider-
|
|
31
|
+
* specific and out of scope here.
|
|
32
|
+
* - We surface progress as tool-call counts rather than streaming a
|
|
33
|
+
* live tool log — the live log is high-volume and noisy for the
|
|
34
|
+
* "how's that task going" status check the agent actually wants.
|
|
35
|
+
*/
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.InMemoryBackgroundTaskStore = void 0;
|
|
38
|
+
const node_events_1 = require("node:events");
|
|
39
|
+
/**
|
|
40
|
+
* In-memory store. Per-session, no persistence. Suitable for the CLI
|
|
41
|
+
* and the VS Code extension session lifetime. A web host that wants
|
|
42
|
+
* resume-across-reload can implement the same interface backed by
|
|
43
|
+
* IndexedDB or a server endpoint.
|
|
44
|
+
*/
|
|
45
|
+
class InMemoryBackgroundTaskStore {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.tasks = new Map();
|
|
48
|
+
this.emitter = new node_events_1.EventEmitter();
|
|
49
|
+
this.idCounter = 0;
|
|
50
|
+
}
|
|
51
|
+
start(goal) {
|
|
52
|
+
// Short, human-readable id. We don't need uniqueness across hosts;
|
|
53
|
+
// collisions inside a single CLI/extension session would require
|
|
54
|
+
// ~thousands of subagents which isn't the workload.
|
|
55
|
+
this.idCounter += 1;
|
|
56
|
+
const id = `bg${Date.now().toString(36)}${this.idCounter.toString(36)}`;
|
|
57
|
+
const record = {
|
|
58
|
+
id,
|
|
59
|
+
goal,
|
|
60
|
+
status: 'running',
|
|
61
|
+
startedAt: Date.now(),
|
|
62
|
+
iterations: 0,
|
|
63
|
+
toolCalls: 0,
|
|
64
|
+
consumed: false
|
|
65
|
+
};
|
|
66
|
+
this.tasks.set(id, record);
|
|
67
|
+
this.emitter.emit('start', record);
|
|
68
|
+
return id;
|
|
69
|
+
}
|
|
70
|
+
progress(id, progress) {
|
|
71
|
+
const record = this.tasks.get(id);
|
|
72
|
+
if (!record)
|
|
73
|
+
return;
|
|
74
|
+
if (record.status !== 'running')
|
|
75
|
+
return;
|
|
76
|
+
if (typeof progress.iterations === 'number')
|
|
77
|
+
record.iterations = progress.iterations;
|
|
78
|
+
if (typeof progress.toolCalls === 'number')
|
|
79
|
+
record.toolCalls = progress.toolCalls;
|
|
80
|
+
if (typeof progress.lastTool === 'string')
|
|
81
|
+
record.lastTool = progress.lastTool;
|
|
82
|
+
this.emitter.emit('progress', record);
|
|
83
|
+
}
|
|
84
|
+
complete(id, synopsis) {
|
|
85
|
+
const record = this.tasks.get(id);
|
|
86
|
+
if (!record)
|
|
87
|
+
return;
|
|
88
|
+
if (record.status !== 'running')
|
|
89
|
+
return;
|
|
90
|
+
record.status = 'completed';
|
|
91
|
+
record.endedAt = Date.now();
|
|
92
|
+
record.synopsis = synopsis;
|
|
93
|
+
this.emitter.emit('complete', record);
|
|
94
|
+
}
|
|
95
|
+
fail(id, error) {
|
|
96
|
+
const record = this.tasks.get(id);
|
|
97
|
+
if (!record)
|
|
98
|
+
return;
|
|
99
|
+
if (record.status !== 'running')
|
|
100
|
+
return;
|
|
101
|
+
record.status = 'failed';
|
|
102
|
+
record.endedAt = Date.now();
|
|
103
|
+
record.error = error;
|
|
104
|
+
this.emitter.emit('failed', record);
|
|
105
|
+
}
|
|
106
|
+
cancel(id) {
|
|
107
|
+
const record = this.tasks.get(id);
|
|
108
|
+
if (!record)
|
|
109
|
+
return;
|
|
110
|
+
if (record.status !== 'running')
|
|
111
|
+
return;
|
|
112
|
+
record.status = 'cancelled';
|
|
113
|
+
record.endedAt = Date.now();
|
|
114
|
+
this.emitter.emit('cancelled', record);
|
|
115
|
+
}
|
|
116
|
+
get(id) {
|
|
117
|
+
return this.tasks.get(id);
|
|
118
|
+
}
|
|
119
|
+
list() {
|
|
120
|
+
return [...this.tasks.values()].sort((a, b) => a.startedAt - b.startedAt);
|
|
121
|
+
}
|
|
122
|
+
listByStatus(status) {
|
|
123
|
+
return this.list().filter((r) => r.status === status);
|
|
124
|
+
}
|
|
125
|
+
markConsumed(id) {
|
|
126
|
+
const record = this.tasks.get(id);
|
|
127
|
+
if (!record)
|
|
128
|
+
return;
|
|
129
|
+
record.consumed = true;
|
|
130
|
+
}
|
|
131
|
+
on(event, listener) {
|
|
132
|
+
this.emitter.on(event, listener);
|
|
133
|
+
return () => this.emitter.off(event, listener);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.InMemoryBackgroundTaskStore = InMemoryBackgroundTaskStore;
|
|
137
|
+
//# sourceMappingURL=backgroundTasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backgroundTasks.js","sourceRoot":"","sources":["../src/backgroundTasks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;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ool-driven file edit so the user
|
|
3
|
+
* can rewind after the fact. One entry per successful write_file /
|
|
4
|
+
* apply_edit; stores the full `before` text (plus metadata about the
|
|
5
|
+
* edit) under `.bandit/checkpoints/<turnId>/<id>.json`, and maintains
|
|
6
|
+
* a small flat index at `.bandit/checkpoints/index.json` for fast
|
|
7
|
+
* listing without walking the directory.
|
|
8
|
+
*
|
|
9
|
+
* Honest scope:
|
|
10
|
+
* - Only reverts edits the agent made through write_file / apply_edit / replace_range / apply_patch.
|
|
11
|
+
* Manual saves the user made between turns are NOT captured.
|
|
12
|
+
* - Not a replacement for git. Meant for in-session undo when an
|
|
13
|
+
* edit goes sideways and the user wants the previous state back
|
|
14
|
+
* without hand-unwinding.
|
|
15
|
+
*
|
|
16
|
+
* Storage format is deliberately simple (plain JSON, one file per
|
|
17
|
+
* checkpoint) so it's inspectable with cat/jq when debugging.
|
|
18
|
+
*/
|
|
19
|
+
export interface CheckpointEntry {
|
|
20
|
+
/** Short slug id — "chk-<turnSlug>-<seq>". Used for /rewind lookup. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Turn this checkpoint belongs to (matches the turn-log filename stem). */
|
|
23
|
+
turnId: string;
|
|
24
|
+
/** Epoch ms when the checkpoint was written. */
|
|
25
|
+
timestamp: number;
|
|
26
|
+
/** Which tool produced the edit. */
|
|
27
|
+
tool: 'write_file' | 'apply_edit' | 'replace_range' | 'apply_patch';
|
|
28
|
+
/** Absolute path on disk. */
|
|
29
|
+
path: string;
|
|
30
|
+
/** Workspace-relative path (for display in lists). */
|
|
31
|
+
relPath: string;
|
|
32
|
+
/** Full content of the file BEFORE the edit. Empty string for new files. */
|
|
33
|
+
before: string;
|
|
34
|
+
/** Full content of the file AFTER the edit. Stored so listing can
|
|
35
|
+
* show +N/−M stats without re-reading the file (which may have
|
|
36
|
+
* been further edited since). */
|
|
37
|
+
after: string;
|
|
38
|
+
/** True when the edit CREATED the file — rewind should `unlink` rather
|
|
39
|
+
* than write `before`. */
|
|
40
|
+
isNewFile: boolean;
|
|
41
|
+
/** Iteration index within the turn (1-indexed for display). */
|
|
42
|
+
iteration: number;
|
|
43
|
+
/** Optional short description — first ~80 chars of the change's first
|
|
44
|
+
* line, for human-readable listing. */
|
|
45
|
+
description?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Flat index entry. Holds only the fields needed for listing so we
|
|
49
|
+
* don't have to read every checkpoint JSON when the user runs /rewind.
|
|
50
|
+
*/
|
|
51
|
+
export interface CheckpointIndexEntry {
|
|
52
|
+
id: string;
|
|
53
|
+
turnId: string;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
tool: CheckpointEntry['tool'];
|
|
56
|
+
relPath: string;
|
|
57
|
+
iteration: number;
|
|
58
|
+
description?: string;
|
|
59
|
+
plus: number;
|
|
60
|
+
minus: number;
|
|
61
|
+
}
|
|
62
|
+
export interface CheckpointStoreOptions {
|
|
63
|
+
/** Workspace root where `.bandit/checkpoints/` lives. */
|
|
64
|
+
workspaceRoot: string;
|
|
65
|
+
/** Optional max number of index entries to keep. Older entries stay
|
|
66
|
+
* on disk but drop off the index. Default: 200. */
|
|
67
|
+
maxIndexEntries?: number;
|
|
68
|
+
}
|
|
69
|
+
export declare class CheckpointStore {
|
|
70
|
+
private readonly workspaceRoot;
|
|
71
|
+
private readonly dir;
|
|
72
|
+
private readonly maxIndexEntries;
|
|
73
|
+
private counter;
|
|
74
|
+
constructor(options: CheckpointStoreOptions);
|
|
75
|
+
/** Create a checkpoint entry, persist it, and update the index. */
|
|
76
|
+
create(input: {
|
|
77
|
+
turnId: string;
|
|
78
|
+
tool: CheckpointEntry['tool'];
|
|
79
|
+
absolutePath: string;
|
|
80
|
+
before: string;
|
|
81
|
+
after: string;
|
|
82
|
+
iteration: number;
|
|
83
|
+
}): Promise<CheckpointEntry>;
|
|
84
|
+
/** Return the most recent N index entries (newest first). */
|
|
85
|
+
list(limit?: number): Promise<CheckpointIndexEntry[]>;
|
|
86
|
+
/** Load a full checkpoint by id. Returns null when not found. */
|
|
87
|
+
get(id: string): Promise<CheckpointEntry | null>;
|
|
88
|
+
/**
|
|
89
|
+
* Restore the file to its pre-edit state. Returns the resolved entry
|
|
90
|
+
* on success, or null when the id wasn't found / couldn't be applied.
|
|
91
|
+
* New-file checkpoints are handled by unlinking the file (the file
|
|
92
|
+
* DIDN'T exist before, so that's the correct reverse operation).
|
|
93
|
+
*/
|
|
94
|
+
rewind(id: string): Promise<CheckpointEntry | null>;
|
|
95
|
+
private readIndex;
|
|
96
|
+
private writeIndex;
|
|
97
|
+
private appendToIndex;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=checkpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoints.d.ts","sourceRoot":"","sources":["../src/checkpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,IAAI,EAAE,YAAY,GAAG,YAAY,GAAG,eAAe,GAAG,aAAa,CAAC;IACpE,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf;;sCAEkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd;+BAC2B;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB;4CACwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAA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