@crewhaus/tool-capability 0.0.0-stage → 0.8.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/NOTICE +9 -0
- package/README.md +10 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +92 -0
- package/dist/lib.d.ts +114 -0
- package/dist/lib.js +251 -0
- package/package.json +47 -4
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 reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and 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 choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or 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 [yyyy] [name of copyright owner]
|
|
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/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CrewHaus Factory
|
|
2
|
+
Copyright 2026 Max Meier
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Max Meier
|
|
5
|
+
(operating as StudioMax — https://studiomax.io) and contributors.
|
|
6
|
+
|
|
7
|
+
The CrewHaus name and logo are trademarks of Max Meier. See
|
|
8
|
+
https://github.com/crewhaus/factory/blob/main/TRADEMARK.md for the
|
|
9
|
+
use-of-marks policy.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crewhaus/tool-capability
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ToolRegistry: what builtin tools exist, and which of them this harness is actually running
|
|
4
|
+
|
|
5
|
+
Part of [CrewHaus](https://github.com/crewhaus/factory). Most people install the CLI (`npm install -g crewhaus`) rather than this package.
|
|
6
|
+
|
|
7
|
+
Which tools a spec can turn on, and how: [tools reference](https://github.com/crewhaus/docs/blob/main/TOOLS-REFERENCE.md).
|
|
8
|
+
|
|
9
|
+
Requires [Bun](https://bun.sh) `>=1.3.14`; plain Node is not supported.
|
|
10
|
+
|
|
11
|
+
[Source](https://github.com/crewhaus/factory/tree/main/packages/tool-capability)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RegisteredTool } from "@crewhaus/tool-catalog";
|
|
2
|
+
export { DEFAULT_LIMIT, MAX_LIMIT, MCP_NOTE, type RegistryAnswer, type RegistryQuery, type RegistryRow, buildRegistryAnswer, firstSentence, howToRequest, knownCategories, liveToolNames, matchesQuery, normalizeCategory, } from "./lib";
|
|
3
|
+
export declare const toolRegistry: RegisteredTool;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @crewhaus/tool-capability — `ToolRegistry`, the answer to "what exists that
|
|
3
|
+
* I am not running".
|
|
4
|
+
*
|
|
5
|
+
* TWO QUESTIONS, ONE OF WHICH WAS ALREADY ANSWERED.
|
|
6
|
+
*
|
|
7
|
+
* "What can I call right now?" is `ListTools` (`@crewhaus/runtime-core`).
|
|
8
|
+
* It reads the bound catalog, covers MCP peers that connected after boot,
|
|
9
|
+
* and is authoritative. Nothing here duplicates it.
|
|
10
|
+
*
|
|
11
|
+
* "What exists in this framework that I was not given?" had no answer at
|
|
12
|
+
* all. A compiled bundle contains only the tools its spec granted, so the
|
|
13
|
+
* tools it lacks are, from inside, invisible — an agent could not name one,
|
|
14
|
+
* let alone say what it does. `ToolRegistry` reads the generated manifest in
|
|
15
|
+
* `@crewhaus/tool-registry-manifest` and reports both halves.
|
|
16
|
+
*
|
|
17
|
+
* THIS IS ERGONOMICS, NOT A CONTROL. Leaving a tool out of `tools:` is what
|
|
18
|
+
* shapes a harness; this tool only makes the omission legible, so an operator
|
|
19
|
+
* can see what the agent is missing and decide. In any harness that grants
|
|
20
|
+
* bash, file write or code execution the agent can edit `crewhaus.yaml`
|
|
21
|
+
* itself, so nothing here stands between an agent and a tool — and nothing in
|
|
22
|
+
* its description, its output or its docs says otherwise.
|
|
23
|
+
*
|
|
24
|
+
* WHY ITS OWN PACKAGE. The manifest is roughly 450 KB of description text.
|
|
25
|
+
* `ListTools` lives in `runtime-core`, which is in every bundle of every
|
|
26
|
+
* shape, so growing it would put that text into harnesses that never asked
|
|
27
|
+
* for it. `toolInventory` is the wrong axis — it reads a SPEC file, cannot
|
|
28
|
+
* see MCP tools bound at connect time, and its package depends on
|
|
29
|
+
* `@crewhaus/compiler`, which drags all fourteen target emitters. A separate
|
|
30
|
+
* spec-granted tool makes the cost declared, which is what
|
|
31
|
+
* `collectCrewhausDeps` measures anyway.
|
|
32
|
+
*
|
|
33
|
+
* WHAT IT READS. `granted` is computed against the LIVE catalog off
|
|
34
|
+
* `ToolExecuteContext.bridge`, not against the spec — so an MCP tool
|
|
35
|
+
* registered an hour after boot counts as bound, the same way `ListTools`
|
|
36
|
+
* counts it. The bridge is read structurally (see `lib.ts`) so this package
|
|
37
|
+
* does not depend on the sub-agent fabric.
|
|
38
|
+
*/
|
|
39
|
+
import { buildTool } from "@crewhaus/tool-builder";
|
|
40
|
+
import { REGISTRY_VERSION, TOOL_REGISTRY } from "@crewhaus/tool-registry-manifest";
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
import { DEFAULT_LIMIT, MAX_LIMIT, buildRegistryAnswer, liveToolNames } from "./lib";
|
|
43
|
+
export { DEFAULT_LIMIT, MAX_LIMIT, MCP_NOTE, buildRegistryAnswer, firstSentence, howToRequest, knownCategories, liveToolNames, matchesQuery, normalizeCategory, } from "./lib";
|
|
44
|
+
const json = (value) => JSON.stringify(value);
|
|
45
|
+
export const toolRegistry = buildTool({
|
|
46
|
+
name: "ToolRegistry",
|
|
47
|
+
description: "List the builtin tools CrewHaus ships and mark which ones this harness is actually running, so you can name a tool you do not have and say what it would do. `ListTools` answers what you can call right now; this one also covers what you cannot. Search with `query`, narrow with `category` (`all-fs` or `fs`), or pass one `key` for that tool's full description. Rows you are not running come with a line on how to ask for them. It reports; it enables nothing, and a tool appears here whether or not this harness will ever have it. Builtins only: a spec declares an MCP server rather than the tools it offers, so which MCP tools exist elsewhere cannot be answered offline.",
|
|
48
|
+
inputSchema: z
|
|
49
|
+
.object({
|
|
50
|
+
query: z
|
|
51
|
+
.string()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("lexical search over key, name, description, category and keywords"),
|
|
54
|
+
category: z
|
|
55
|
+
.string()
|
|
56
|
+
.optional()
|
|
57
|
+
.describe('one category, written either way: "all-fs" or "fs"'),
|
|
58
|
+
key: z
|
|
59
|
+
.string()
|
|
60
|
+
.optional()
|
|
61
|
+
.describe("one tool's camelCase spec key; returns that tool with its whole description"),
|
|
62
|
+
only: z
|
|
63
|
+
.enum(["granted", "unlisted", "all"])
|
|
64
|
+
.optional()
|
|
65
|
+
.describe('"granted" = bound here, "unlisted" = exists but not bound; default "all"'),
|
|
66
|
+
limit: z
|
|
67
|
+
.number()
|
|
68
|
+
.int()
|
|
69
|
+
.min(1)
|
|
70
|
+
.max(MAX_LIMIT)
|
|
71
|
+
.optional()
|
|
72
|
+
.describe(`rows to return, up to ${MAX_LIMIT} (default ${DEFAULT_LIMIT})`),
|
|
73
|
+
})
|
|
74
|
+
.strict(),
|
|
75
|
+
readOnly: true,
|
|
76
|
+
destructive: false,
|
|
77
|
+
concurrencySafe: true,
|
|
78
|
+
requiresSandbox: false,
|
|
79
|
+
requireJustification: false,
|
|
80
|
+
scope: "internal",
|
|
81
|
+
execute: async (input, ctx) => {
|
|
82
|
+
const answer = buildRegistryAnswer({
|
|
83
|
+
registry: TOOL_REGISTRY,
|
|
84
|
+
version: REGISTRY_VERSION,
|
|
85
|
+
live: liveToolNames(ctx?.bridge),
|
|
86
|
+
input,
|
|
87
|
+
});
|
|
88
|
+
if ("error" in answer)
|
|
89
|
+
return `[ToolRegistry] ${answer.error}`;
|
|
90
|
+
return json(answer);
|
|
91
|
+
},
|
|
92
|
+
});
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of `ToolRegistry` — everything that can be decided from a
|
|
3
|
+
* manifest, a set of live tool names and an input object, with no runtime
|
|
4
|
+
* attached. Kept separate so the answer can be tested against a hand-built
|
|
5
|
+
* catalog instead of a booted harness.
|
|
6
|
+
*/
|
|
7
|
+
import type { RegistryEntry } from "@crewhaus/tool-registry-manifest";
|
|
8
|
+
/** One tool as `ToolRegistry` reports it in a list. */
|
|
9
|
+
export type RegistryRow = {
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** First sentence in a list; the whole description for a single-`key` ask. */
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly readOnly: boolean;
|
|
15
|
+
readonly destructive: boolean;
|
|
16
|
+
readonly scope: string;
|
|
17
|
+
readonly ioCapability?: string;
|
|
18
|
+
readonly requiresSandbox: boolean;
|
|
19
|
+
readonly requireJustification: boolean;
|
|
20
|
+
readonly categories: ReadonlyArray<string>;
|
|
21
|
+
readonly package: string;
|
|
22
|
+
readonly keywords?: ReadonlyArray<string>;
|
|
23
|
+
/** Present only when the live catalog was readable. */
|
|
24
|
+
readonly granted?: boolean;
|
|
25
|
+
/** Present only on a row this harness is not running. */
|
|
26
|
+
readonly howToRequest?: string;
|
|
27
|
+
};
|
|
28
|
+
export type RegistryQuery = {
|
|
29
|
+
readonly query?: string;
|
|
30
|
+
readonly category?: string;
|
|
31
|
+
readonly key?: string;
|
|
32
|
+
readonly only?: "granted" | "unlisted" | "all";
|
|
33
|
+
readonly limit?: number;
|
|
34
|
+
};
|
|
35
|
+
export declare const DEFAULT_LIMIT = 25;
|
|
36
|
+
export declare const MAX_LIMIT = 100;
|
|
37
|
+
/**
|
|
38
|
+
* The asymmetry, stated in every answer.
|
|
39
|
+
*
|
|
40
|
+
* `registerMcpServer` registers whatever a server offers when it connects,
|
|
41
|
+
* and `watchMcpServer` re-diffs that list mid-run; a spec names the SERVER,
|
|
42
|
+
* never its tools. So "which MCP tools exist that I am not running" has no
|
|
43
|
+
* offline answer, and an answer that quietly covered builtins only would read
|
|
44
|
+
* as complete. Saying it costs one line and is the difference between a short
|
|
45
|
+
* list and a wrong one.
|
|
46
|
+
*/
|
|
47
|
+
export declare const MCP_NOTE = "Builtin tools only, on BOTH sides. A spec declares an MCP server, not the tools it offers, and a server's tools are only known once it connects. So MCP tools you DO have are missing from `granted` \u2014 call ListTools for the whole live toolset \u2014 and which MCP tools exist beyond this harness has no offline answer at all.";
|
|
48
|
+
/** What an agent can do about a tool it is not running. */
|
|
49
|
+
export declare function howToRequest(key: string): string;
|
|
50
|
+
/** The category names the manifest actually uses — leaves and roll-ups alike. */
|
|
51
|
+
export declare function knownCategories(registry: Readonly<Record<string, RegistryEntry>>): ReadonlyArray<string>;
|
|
52
|
+
/** `all-fs` and `fs` mean the same category. */
|
|
53
|
+
export declare function normalizeCategory(raw: string): string;
|
|
54
|
+
export declare function unknownCategoryMessage(raw: string, registry: Readonly<Record<string, RegistryEntry>>): string;
|
|
55
|
+
/** The first sentence, which is what a list needs. `ListTools` does the same. */
|
|
56
|
+
export declare function firstSentence(description: string): string;
|
|
57
|
+
/** Lexical match over the fields a person would search by. */
|
|
58
|
+
export declare function matchesQuery(entry: RegistryEntry, query: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Read the live tool catalog structurally off the execution context.
|
|
61
|
+
*
|
|
62
|
+
* Deliberately structural rather than typed: `RuntimeBridge` lives in
|
|
63
|
+
* `@crewhaus/agent-context-isolation`, and depending on it here would pull a
|
|
64
|
+
* sub-agent fabric into every bundle that wants to list tools. The tree
|
|
65
|
+
* already re-declares shapes this way twice (`tool-approvals` re-declares
|
|
66
|
+
* `PendingApproval`, `tools-cli` re-declares `ToolLike`), and `tool-task`
|
|
67
|
+
* reads the same bridge field.
|
|
68
|
+
*
|
|
69
|
+
* Returns `undefined` — not an empty set — when the catalog is not reachable.
|
|
70
|
+
* The two are completely different answers: an empty set would say "you are
|
|
71
|
+
* running nothing", and the caller must be able to say "I could not tell"
|
|
72
|
+
* instead of reporting every builtin as missing.
|
|
73
|
+
*/
|
|
74
|
+
export declare function liveToolNames(bridge: unknown): ReadonlySet<string> | undefined;
|
|
75
|
+
export type RegistryAnswer = {
|
|
76
|
+
readonly version: string;
|
|
77
|
+
readonly liveCatalog: "read" | "unavailable";
|
|
78
|
+
readonly counts: {
|
|
79
|
+
readonly total: number;
|
|
80
|
+
readonly matched: number;
|
|
81
|
+
readonly shown: number;
|
|
82
|
+
readonly granted?: number;
|
|
83
|
+
readonly unlisted?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Bound tools this manifest cannot describe — MCP tools and any tool a
|
|
86
|
+
* host registered programmatically. Reported as a number rather than
|
|
87
|
+
* silently dropped, so `granted` is never mistaken for the whole toolset.
|
|
88
|
+
*/
|
|
89
|
+
readonly otherBound?: number;
|
|
90
|
+
};
|
|
91
|
+
readonly granted?: ReadonlyArray<RegistryRow>;
|
|
92
|
+
readonly unlisted?: ReadonlyArray<RegistryRow>;
|
|
93
|
+
/** Used instead of the split when the live catalog could not be read. */
|
|
94
|
+
readonly tools?: ReadonlyArray<RegistryRow>;
|
|
95
|
+
readonly truncated: boolean;
|
|
96
|
+
readonly note: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Build the answer.
|
|
100
|
+
*
|
|
101
|
+
* `live` is the set of tool names bound to this runtime right now, or
|
|
102
|
+
* `undefined` when that could not be read. Which builtins a harness HAS is
|
|
103
|
+
* read from that live catalog rather than from the spec, so a tool an MCP
|
|
104
|
+
* peer registered an hour after boot counts as bound — the same reason
|
|
105
|
+
* `ListTools` reads the catalog and not the spec.
|
|
106
|
+
*/
|
|
107
|
+
export declare function buildRegistryAnswer(args: {
|
|
108
|
+
readonly registry: Readonly<Record<string, RegistryEntry>>;
|
|
109
|
+
readonly version: string;
|
|
110
|
+
readonly live: ReadonlySet<string> | undefined;
|
|
111
|
+
readonly input: RegistryQuery;
|
|
112
|
+
}): RegistryAnswer | {
|
|
113
|
+
readonly error: string;
|
|
114
|
+
};
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
export const DEFAULT_LIMIT = 25;
|
|
2
|
+
export const MAX_LIMIT = 100;
|
|
3
|
+
/**
|
|
4
|
+
* The asymmetry, stated in every answer.
|
|
5
|
+
*
|
|
6
|
+
* `registerMcpServer` registers whatever a server offers when it connects,
|
|
7
|
+
* and `watchMcpServer` re-diffs that list mid-run; a spec names the SERVER,
|
|
8
|
+
* never its tools. So "which MCP tools exist that I am not running" has no
|
|
9
|
+
* offline answer, and an answer that quietly covered builtins only would read
|
|
10
|
+
* as complete. Saying it costs one line and is the difference between a short
|
|
11
|
+
* list and a wrong one.
|
|
12
|
+
*/
|
|
13
|
+
export const MCP_NOTE = "Builtin tools only, on BOTH sides. A spec declares an MCP server, not the tools it offers, and a server's tools are only known once it connects. So MCP tools you DO have are missing from `granted` — call ListTools for the whole live toolset — and which MCP tools exist beyond this harness has no offline answer at all.";
|
|
14
|
+
/** What an agent can do about a tool it is not running. */
|
|
15
|
+
export function howToRequest(key) {
|
|
16
|
+
return `Not bound here. Ask the person running this harness to add "${key}" to tools: in crewhaus.yaml.`;
|
|
17
|
+
}
|
|
18
|
+
/** The category names the manifest actually uses — leaves and roll-ups alike. */
|
|
19
|
+
export function knownCategories(registry) {
|
|
20
|
+
const out = new Set();
|
|
21
|
+
for (const entry of Object.values(registry))
|
|
22
|
+
for (const c of entry.categories)
|
|
23
|
+
out.add(c);
|
|
24
|
+
return [...out].sort();
|
|
25
|
+
}
|
|
26
|
+
/** `all-fs` and `fs` mean the same category. */
|
|
27
|
+
export function normalizeCategory(raw) {
|
|
28
|
+
return raw.startsWith("all-") ? raw.slice("all-".length) : raw;
|
|
29
|
+
}
|
|
30
|
+
export function unknownCategoryMessage(raw, registry) {
|
|
31
|
+
const name = normalizeCategory(raw);
|
|
32
|
+
const known = knownCategories(registry);
|
|
33
|
+
const near = known.filter((k) => k.includes(name) || name.includes(k)).slice(0, 3);
|
|
34
|
+
const hint = near.length > 0 ? ` Did you mean ${near.map((k) => `all-${k}`).join(", ")}?` : "";
|
|
35
|
+
// The note rides on this too. A reader who asked for a category that does
|
|
36
|
+
// not exist is one step from concluding the category has no tools, and the
|
|
37
|
+
// categories here cover builtins only.
|
|
38
|
+
return `unknown tool category "${raw}".${hint} There are ${known.length} categories; ask with no category to see them on the rows. ${MCP_NOTE}`;
|
|
39
|
+
}
|
|
40
|
+
/** The first sentence, which is what a list needs. `ListTools` does the same. */
|
|
41
|
+
export function firstSentence(description) {
|
|
42
|
+
return description.split(/(?<=[.!?])\s/)[0] ?? description;
|
|
43
|
+
}
|
|
44
|
+
/** Lexical match over the fields a person would search by. */
|
|
45
|
+
export function matchesQuery(entry, query) {
|
|
46
|
+
const needle = query.toLowerCase();
|
|
47
|
+
if (needle.length === 0)
|
|
48
|
+
return true;
|
|
49
|
+
if (entry.key.toLowerCase().includes(needle))
|
|
50
|
+
return true;
|
|
51
|
+
if (entry.name.toLowerCase().includes(needle))
|
|
52
|
+
return true;
|
|
53
|
+
if (entry.description.toLowerCase().includes(needle))
|
|
54
|
+
return true;
|
|
55
|
+
if (entry.categories.some((c) => c.toLowerCase().includes(needle)))
|
|
56
|
+
return true;
|
|
57
|
+
return entry.keywords.some((k) => k.toLowerCase().includes(needle));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Read the live tool catalog structurally off the execution context.
|
|
61
|
+
*
|
|
62
|
+
* Deliberately structural rather than typed: `RuntimeBridge` lives in
|
|
63
|
+
* `@crewhaus/agent-context-isolation`, and depending on it here would pull a
|
|
64
|
+
* sub-agent fabric into every bundle that wants to list tools. The tree
|
|
65
|
+
* already re-declares shapes this way twice (`tool-approvals` re-declares
|
|
66
|
+
* `PendingApproval`, `tools-cli` re-declares `ToolLike`), and `tool-task`
|
|
67
|
+
* reads the same bridge field.
|
|
68
|
+
*
|
|
69
|
+
* Returns `undefined` — not an empty set — when the catalog is not reachable.
|
|
70
|
+
* The two are completely different answers: an empty set would say "you are
|
|
71
|
+
* running nothing", and the caller must be able to say "I could not tell"
|
|
72
|
+
* instead of reporting every builtin as missing.
|
|
73
|
+
*/
|
|
74
|
+
export function liveToolNames(bridge) {
|
|
75
|
+
if (typeof bridge !== "object" || bridge === null)
|
|
76
|
+
return undefined;
|
|
77
|
+
const tools = bridge.tools;
|
|
78
|
+
if (!Array.isArray(tools))
|
|
79
|
+
return undefined;
|
|
80
|
+
const names = new Set();
|
|
81
|
+
for (const t of tools) {
|
|
82
|
+
if (typeof t === "object" && t !== null) {
|
|
83
|
+
const name = t.name;
|
|
84
|
+
if (typeof name === "string")
|
|
85
|
+
names.add(name);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return names;
|
|
89
|
+
}
|
|
90
|
+
function toRow(entry, opts) {
|
|
91
|
+
return {
|
|
92
|
+
key: entry.key,
|
|
93
|
+
name: entry.name,
|
|
94
|
+
description: opts.full ? entry.description : firstSentence(entry.description),
|
|
95
|
+
readOnly: entry.readOnly,
|
|
96
|
+
destructive: entry.destructive,
|
|
97
|
+
scope: entry.scope,
|
|
98
|
+
...(entry.ioCapability !== undefined ? { ioCapability: entry.ioCapability } : {}),
|
|
99
|
+
requiresSandbox: entry.requiresSandbox,
|
|
100
|
+
requireJustification: entry.requireJustification,
|
|
101
|
+
categories: entry.categories,
|
|
102
|
+
package: entry.package,
|
|
103
|
+
...(opts.full ? { keywords: entry.keywords } : {}),
|
|
104
|
+
...(opts.granted !== undefined ? { granted: opts.granted } : {}),
|
|
105
|
+
...(opts.granted === false ? { howToRequest: howToRequest(entry.key) } : {}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Build the answer.
|
|
110
|
+
*
|
|
111
|
+
* `live` is the set of tool names bound to this runtime right now, or
|
|
112
|
+
* `undefined` when that could not be read. Which builtins a harness HAS is
|
|
113
|
+
* read from that live catalog rather than from the spec, so a tool an MCP
|
|
114
|
+
* peer registered an hour after boot counts as bound — the same reason
|
|
115
|
+
* `ListTools` reads the catalog and not the spec.
|
|
116
|
+
*/
|
|
117
|
+
export function buildRegistryAnswer(args) {
|
|
118
|
+
const { registry, version, live, input } = args;
|
|
119
|
+
const only = input.only ?? "all";
|
|
120
|
+
const limit = Math.min(input.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
|
|
121
|
+
if (live === undefined && only !== "all") {
|
|
122
|
+
return {
|
|
123
|
+
error: `ToolRegistry could not read this runtime's live tool catalog, so it cannot answer only: "${only}". Ask again without \`only\` to get the tools that exist, or call ListTools for what is bound right now. ${MCP_NOTE}`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const all = Object.values(registry);
|
|
127
|
+
// Bound names this manifest has no row for: MCP tools, and anything a host
|
|
128
|
+
// registered programmatically. Counting them is what keeps `granted` from
|
|
129
|
+
// reading as "everything I have".
|
|
130
|
+
const manifestNames = new Set(all.map((e) => e.name));
|
|
131
|
+
const otherBound = live === undefined ? undefined : [...live].filter((n) => !manifestNames.has(n)).length;
|
|
132
|
+
// A single key is a detail lookup, not a search: it answers with the whole
|
|
133
|
+
// description rather than the first sentence, and ignores the other filters.
|
|
134
|
+
if (input.key !== undefined) {
|
|
135
|
+
// `Object.hasOwn`, not a bare index: `TOOL_REGISTRY` is an object literal,
|
|
136
|
+
// so a bare lookup reaches Object.prototype and `key: "constructor"` comes
|
|
137
|
+
// back as a function rather than as `undefined`. The row built from it
|
|
138
|
+
// would name a tool called "Object" and tell the reader to ask an operator
|
|
139
|
+
// to add "constructor" to `tools:` — a confabulated tool from the one tool
|
|
140
|
+
// whose whole job is saying truthfully what exists.
|
|
141
|
+
const entry = Object.hasOwn(registry, input.key) ? registry[input.key] : undefined;
|
|
142
|
+
if (entry === undefined) {
|
|
143
|
+
const near = Object.keys(registry)
|
|
144
|
+
.filter((k) => k.toLowerCase().includes(input.key?.toLowerCase() ?? ""))
|
|
145
|
+
.slice(0, 5);
|
|
146
|
+
const hint = near.length > 0 ? ` Close matches: ${near.join(", ")}.` : "";
|
|
147
|
+
return {
|
|
148
|
+
error: `no builtin tool has the key "${input.key}".${hint} ${MCP_NOTE}`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const isGranted = live === undefined ? undefined : live.has(entry.name);
|
|
152
|
+
const row = toRow(entry, {
|
|
153
|
+
full: true,
|
|
154
|
+
...(isGranted !== undefined ? { granted: isGranted } : {}),
|
|
155
|
+
});
|
|
156
|
+
const counts = { total: all.length, matched: 1, shown: 1 };
|
|
157
|
+
if (live === undefined) {
|
|
158
|
+
return {
|
|
159
|
+
version,
|
|
160
|
+
liveCatalog: "unavailable",
|
|
161
|
+
counts,
|
|
162
|
+
tools: [row],
|
|
163
|
+
truncated: false,
|
|
164
|
+
note: `${unavailableNote()} ${MCP_NOTE}`,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
version,
|
|
169
|
+
liveCatalog: "read",
|
|
170
|
+
counts: {
|
|
171
|
+
...counts,
|
|
172
|
+
granted: isGranted === true ? 1 : 0,
|
|
173
|
+
unlisted: isGranted === true ? 0 : 1,
|
|
174
|
+
...(otherBound !== undefined ? { otherBound } : {}),
|
|
175
|
+
},
|
|
176
|
+
granted: isGranted === true ? [row] : [],
|
|
177
|
+
unlisted: isGranted === true ? [] : [row],
|
|
178
|
+
truncated: false,
|
|
179
|
+
note: MCP_NOTE,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
let matched = all;
|
|
183
|
+
if (input.category !== undefined) {
|
|
184
|
+
const name = normalizeCategory(input.category);
|
|
185
|
+
if (!knownCategories(registry).includes(name)) {
|
|
186
|
+
return { error: unknownCategoryMessage(input.category, registry) };
|
|
187
|
+
}
|
|
188
|
+
matched = matched.filter((e) => e.categories.includes(name));
|
|
189
|
+
}
|
|
190
|
+
if (input.query !== undefined) {
|
|
191
|
+
matched = matched.filter((e) => matchesQuery(e, input.query ?? ""));
|
|
192
|
+
}
|
|
193
|
+
matched = [...matched].sort((a, b) => a.key.localeCompare(b.key));
|
|
194
|
+
if (live === undefined) {
|
|
195
|
+
const shown = matched.slice(0, limit);
|
|
196
|
+
return {
|
|
197
|
+
version,
|
|
198
|
+
liveCatalog: "unavailable",
|
|
199
|
+
counts: { total: all.length, matched: matched.length, shown: shown.length },
|
|
200
|
+
tools: shown.map((e) => toRow(e, { full: false })),
|
|
201
|
+
truncated: shown.length < matched.length,
|
|
202
|
+
note: `${unavailableNote()} ${MCP_NOTE}`,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const grantedEntries = matched.filter((e) => live.has(e.name));
|
|
206
|
+
const unlistedEntries = matched.filter((e) => !live.has(e.name));
|
|
207
|
+
const wantGranted = only === "all" || only === "granted";
|
|
208
|
+
const wantUnlisted = only === "all" || only === "unlisted";
|
|
209
|
+
// How the page is spent.
|
|
210
|
+
//
|
|
211
|
+
// `only` gets the whole budget, because asking for one half and being given
|
|
212
|
+
// half of it is a page nobody wanted. `all` splits it, and the reason is the
|
|
213
|
+
// whole point of this tool: filling the page with what a harness already has
|
|
214
|
+
// would push out what it does not, which is the half that cannot be got from
|
|
215
|
+
// `ListTools`. Each side still takes whatever the other does not use, so a
|
|
216
|
+
// small answer is never padded with blank space.
|
|
217
|
+
let grantedCap = 0;
|
|
218
|
+
let unlistedCap = 0;
|
|
219
|
+
if (only === "granted")
|
|
220
|
+
grantedCap = limit;
|
|
221
|
+
else if (only === "unlisted")
|
|
222
|
+
unlistedCap = limit;
|
|
223
|
+
else {
|
|
224
|
+
grantedCap = Math.min(grantedEntries.length, Math.ceil(limit / 2));
|
|
225
|
+
unlistedCap = Math.min(unlistedEntries.length, limit - grantedCap);
|
|
226
|
+
grantedCap = Math.min(grantedEntries.length, limit - unlistedCap);
|
|
227
|
+
}
|
|
228
|
+
const grantedShown = wantGranted ? grantedEntries.slice(0, grantedCap) : [];
|
|
229
|
+
const unlistedShown = wantUnlisted ? unlistedEntries.slice(0, unlistedCap) : [];
|
|
230
|
+
const shown = grantedShown.length + unlistedShown.length;
|
|
231
|
+
const askedFor = (wantGranted ? grantedEntries.length : 0) + (wantUnlisted ? unlistedEntries.length : 0);
|
|
232
|
+
return {
|
|
233
|
+
version,
|
|
234
|
+
liveCatalog: "read",
|
|
235
|
+
counts: {
|
|
236
|
+
total: all.length,
|
|
237
|
+
matched: matched.length,
|
|
238
|
+
shown,
|
|
239
|
+
granted: grantedEntries.length,
|
|
240
|
+
unlisted: unlistedEntries.length,
|
|
241
|
+
...(otherBound !== undefined ? { otherBound } : {}),
|
|
242
|
+
},
|
|
243
|
+
granted: grantedShown.map((e) => toRow(e, { full: false, granted: true })),
|
|
244
|
+
unlisted: unlistedShown.map((e) => toRow(e, { full: false, granted: false })),
|
|
245
|
+
truncated: shown < askedFor,
|
|
246
|
+
note: MCP_NOTE,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function unavailableNote() {
|
|
250
|
+
return "This runtime's live tool catalog was not reachable from this call, so no row says whether you are running it — these are the tools that exist. Call ListTools for what is bound right now.";
|
|
251
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-capability",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "ToolRegistry: what builtin tools exist, and which of them this harness is actually running",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "bun test src"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@crewhaus/tool-builder": "0.8.1",
|
|
20
|
+
"@crewhaus/tool-catalog": "0.8.1",
|
|
21
|
+
"@crewhaus/tool-registry-manifest": "0.8.1",
|
|
22
|
+
"zod": "^3.23.8"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@crewhaus/tool-executor": "workspace:*"
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Max Meier",
|
|
30
|
+
"email": "max@crewhaus.ai",
|
|
31
|
+
"url": "https://crewhaus.ai"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/crewhaus/factory.git",
|
|
36
|
+
"directory": "packages/tool-capability"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/crewhaus/factory/tree/main/packages/tool-capability#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/crewhaus/factory/issues"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
46
|
+
"engines": {
|
|
47
|
+
"bun": ">=1.3.14"
|
|
48
|
+
}
|
|
49
|
+
}
|