@narumitw/pi-cbmem 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,233 @@
1
+ import { StringEnum } from "@earendil-works/pi-ai";
2
+ import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
3
+ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from "@earendil-works/pi-coding-agent";
4
+ import type { TSchema } from "typebox";
5
+ import { Type } from "typebox";
6
+
7
+ export type BridgeToolDefinition = Pick<
8
+ ToolDefinition<TSchema>,
9
+ "name" | "label" | "description" | "parameters"
10
+ >;
11
+
12
+ const Project = Type.String({ description: "Indexed project name from list_projects." });
13
+ const outputLimit = `Output is limited to ${DEFAULT_MAX_LINES} lines or ${formatSize(DEFAULT_MAX_BYTES)}; byte-oversized responses fail validation instead of returning partial JSON.`;
14
+
15
+ export const TOOL_DEFINITIONS = [
16
+ {
17
+ name: "index_repository",
18
+ label: "Index Repository",
19
+ description: `Index a repository in the Codebase Memory graph. ${outputLimit}`,
20
+ parameters: Type.Object({
21
+ repo_path: Type.String({ description: "Path to the repository." }),
22
+ mode: Type.Optional(
23
+ StringEnum(["full", "moderate", "fast", "cross-repo-intelligence"] as const),
24
+ ),
25
+ target_projects: Type.Optional(Type.Array(Type.String())),
26
+ name: Type.Optional(Type.String({ description: "Override the derived project name." })),
27
+ persistence: Type.Optional(Type.Boolean()),
28
+ }),
29
+ },
30
+ {
31
+ name: "search_graph",
32
+ label: "Search Graph",
33
+ description: `Search indexed symbols by text, name, file, relationship, or degree. ${outputLimit}`,
34
+ parameters: Type.Object({
35
+ project: Project,
36
+ query: Type.Optional(Type.String({ description: "Natural-language or keyword search." })),
37
+ label: Type.Optional(Type.String()),
38
+ name_pattern: Type.Optional(Type.String()),
39
+ qn_pattern: Type.Optional(Type.String()),
40
+ file_pattern: Type.Optional(Type.String()),
41
+ relationship: Type.Optional(Type.String()),
42
+ min_degree: Type.Optional(Type.Integer()),
43
+ max_degree: Type.Optional(Type.Integer()),
44
+ exclude_entry_points: Type.Optional(Type.Boolean()),
45
+ include_connected: Type.Optional(Type.Boolean()),
46
+ semantic_query: Type.Optional(Type.Array(Type.String())),
47
+ limit: Type.Optional(Type.Integer()),
48
+ offset: Type.Optional(Type.Integer()),
49
+ format: Type.Optional(StringEnum(["tree", "json"] as const)),
50
+ fields: Type.Optional(Type.Array(Type.String())),
51
+ detail: Type.Optional(StringEnum(["ids", "default"] as const)),
52
+ }),
53
+ },
54
+ {
55
+ name: "query_graph",
56
+ label: "Query Graph",
57
+ description: `Execute a Cypher query against the code or missed-coverage graph. ${outputLimit}`,
58
+ parameters: Type.Object({
59
+ query: Type.String({ description: "Cypher query." }),
60
+ project: Project,
61
+ graph: Type.Optional(StringEnum(["code", "missed"] as const)),
62
+ max_rows: Type.Optional(Type.Integer()),
63
+ }),
64
+ },
65
+ {
66
+ name: "trace_path",
67
+ label: "Trace Path",
68
+ description: `Trace callers, callees, data flow, or cross-service paths. ${outputLimit}`,
69
+ parameters: Type.Object({
70
+ function_name: Type.String(),
71
+ project: Project,
72
+ direction: Type.Optional(StringEnum(["inbound", "outbound", "both"] as const)),
73
+ depth: Type.Optional(Type.Integer()),
74
+ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 5000 })),
75
+ cursor: Type.Optional(Type.String()),
76
+ mode: Type.Optional(StringEnum(["calls", "data_flow", "cross_service"] as const)),
77
+ parameter_name: Type.Optional(Type.String()),
78
+ edge_types: Type.Optional(Type.Array(Type.String())),
79
+ risk_labels: Type.Optional(Type.Boolean()),
80
+ include_tests: Type.Optional(Type.Boolean()),
81
+ format: Type.Optional(StringEnum(["tree", "json"] as const)),
82
+ include_evidence: Type.Optional(Type.Boolean()),
83
+ }),
84
+ },
85
+ {
86
+ name: "get_code_snippet",
87
+ label: "Get Code Snippet",
88
+ description: `Read source for an indexed symbol by qualified name. ${outputLimit}`,
89
+ parameters: Type.Object({
90
+ qualified_name: Type.String(),
91
+ project: Project,
92
+ include_neighbors: Type.Optional(Type.Boolean()),
93
+ }),
94
+ },
95
+ {
96
+ name: "get_graph_schema",
97
+ label: "Get Graph Schema",
98
+ description: `Get graph node labels and edge types. ${outputLimit}`,
99
+ parameters: Type.Object({ project: Project }),
100
+ },
101
+ {
102
+ name: "get_architecture",
103
+ label: "Get Architecture",
104
+ description: `Summarize architecture, dependencies, boundaries, clusters, or hotspots. ${outputLimit}`,
105
+ parameters: Type.Object({
106
+ project: Project,
107
+ path: Type.Optional(Type.String()),
108
+ aspects: Type.Optional(
109
+ Type.Array(
110
+ StringEnum([
111
+ "all",
112
+ "overview",
113
+ "structure",
114
+ "dependencies",
115
+ "routes",
116
+ "languages",
117
+ "packages",
118
+ "entry_points",
119
+ "hotspots",
120
+ "boundaries",
121
+ "layers",
122
+ "file_tree",
123
+ "clusters",
124
+ "cycles",
125
+ ] as const),
126
+ ),
127
+ ),
128
+ }),
129
+ },
130
+ {
131
+ name: "search_code",
132
+ label: "Search Code",
133
+ description: `Search source text and enrich matches with graph context. ${outputLimit}`,
134
+ parameters: Type.Object({
135
+ pattern: Type.String(),
136
+ project: Project,
137
+ file_pattern: Type.Optional(Type.String()),
138
+ path_filter: Type.Optional(Type.String()),
139
+ mode: Type.Optional(StringEnum(["compact", "full", "files"] as const)),
140
+ context: Type.Optional(Type.Integer()),
141
+ regex: Type.Optional(Type.Boolean()),
142
+ debug: Type.Optional(Type.Boolean()),
143
+ limit: Type.Optional(Type.Integer({ minimum: 1 })),
144
+ }),
145
+ },
146
+ {
147
+ name: "list_projects",
148
+ label: "List Projects",
149
+ description: `List indexed Codebase Memory projects. ${outputLimit}`,
150
+ parameters: Type.Object({
151
+ offset: Type.Optional(Type.Integer({ minimum: 0 })),
152
+ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })),
153
+ include_details: Type.Optional(Type.Boolean()),
154
+ metadata_only: Type.Optional(Type.Boolean()),
155
+ }),
156
+ },
157
+ {
158
+ name: "delete_project",
159
+ label: "Delete Project",
160
+ description: `Delete a project from the Codebase Memory index. ${outputLimit}`,
161
+ parameters: Type.Object({ project: Project }),
162
+ },
163
+ {
164
+ name: "index_status",
165
+ label: "Index Status",
166
+ description: `Get project index health, Git context, and coverage gaps. ${outputLimit}`,
167
+ parameters: Type.Object({
168
+ project: Project,
169
+ verbose: Type.Optional(Type.Boolean()),
170
+ }),
171
+ },
172
+ {
173
+ name: "check_index_coverage",
174
+ label: "Check Index Coverage",
175
+ description: `Check best-effort index coverage for exact paths or bounded scopes. ${outputLimit}`,
176
+ parameters: Type.Object({
177
+ project: Project,
178
+ paths: Type.Optional(Type.Array(Type.String(), { maxItems: 128 })),
179
+ scopes: Type.Optional(Type.Array(Type.String(), { maxItems: 32 })),
180
+ scope_limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 1000 })),
181
+ scope_offset: Type.Optional(Type.Integer({ minimum: 0 })),
182
+ }),
183
+ },
184
+ {
185
+ name: "detect_changes",
186
+ label: "Detect Changes",
187
+ description: `Map a Git diff to changed files and impacted graph symbols. ${outputLimit}`,
188
+ parameters: Type.Object({
189
+ project: Project,
190
+ scope: Type.Optional(StringEnum(["files", "impact"] as const)),
191
+ direction: Type.Optional(StringEnum(["inbound", "outbound", "both"] as const)),
192
+ depth: Type.Optional(Type.Integer()),
193
+ limit: Type.Optional(Type.Integer({ maximum: 5000 })),
194
+ base_branch: Type.Optional(Type.String()),
195
+ since: Type.Optional(Type.String()),
196
+ format: Type.Optional(StringEnum(["tree", "json"] as const)),
197
+ }),
198
+ },
199
+ {
200
+ name: "manage_adr",
201
+ label: "Manage ADR",
202
+ description: `Read or replace Architecture Decision Records. ${outputLimit}`,
203
+ parameters: Type.Object(
204
+ {
205
+ project: Project,
206
+ mode: Type.Optional(StringEnum(["get", "update", "sections"] as const)),
207
+ content: Type.Optional(Type.String()),
208
+ },
209
+ { additionalProperties: false },
210
+ ),
211
+ },
212
+ {
213
+ name: "ingest_traces",
214
+ label: "Ingest Traces",
215
+ description: `Ingest runtime caller-to-callee traces into the graph. ${outputLimit}`,
216
+ parameters: Type.Object({
217
+ traces: Type.Array(
218
+ Type.Object(
219
+ {
220
+ caller: Type.Optional(Type.String()),
221
+ callee: Type.Optional(Type.String()),
222
+ count: Type.Optional(Type.Integer()),
223
+ },
224
+ { additionalProperties: false },
225
+ ),
226
+ ),
227
+ project: Project,
228
+ }),
229
+ },
230
+ ] as const satisfies readonly BridgeToolDefinition[];
231
+
232
+ export type ToolName = (typeof TOOL_DEFINITIONS)[number]["name"];
233
+ export const TOOL_NAMES: readonly ToolName[] = TOOL_DEFINITIONS.map(({ name }) => name);