dsh-plugin-dbgraph-tool 0.0.0-stage → 0.1.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.
package/lib/schema.js ADDED
@@ -0,0 +1,315 @@
1
+ /**
2
+ * The two dbgraph tools' model-facing schemas: the parameter spec the model fills in, and the
3
+ * canonical output union each tool returns.
4
+ *
5
+ * The output is a closed `oneOf` keyed on `operation`, not one loose object with every field
6
+ * optional, so a Code Mode program that switches on `operation` gets exactly the fields that
7
+ * operation produces and nothing it must test for. The build-side tool gets its own union, also
8
+ * discriminated, because a background run has no report to report yet: "0 objects indexed" and
9
+ * "not indexed yet" are different answers and must stay distinguishable.
10
+ * @module dsh-plugin-dbgraph-tool/schema
11
+ */
12
+ /**
13
+ * Operations the primary `dbgraph` tool accepts, one per `ctx.dbgraph` seam method.
14
+ *
15
+ * `index` is deliberately absent: building an index runs through the dedicated `dbgraph_index`
16
+ * tool, which carries its own (much larger) timeout budget instead of this tool's query-sized one.
17
+ * `connections` is the only operation that takes no `connection` argument — it is how the model
18
+ * learns which connection ids exist.
19
+ */
20
+ export const DBGRAPH_OPERATIONS = ['connections', 'schema', 'objects', 'columns', 'find', 'sql', 'impact', 'refs'];
21
+ /** Modes the index tool accepts; `full` runs L1 then L2. */
22
+ export const DBGRAPH_INDEX_MODES = ['l1', 'l2', 'full'];
23
+ /** Which writer an index run may use. `js` is the parity reference and the fallback. */
24
+ export const DBGRAPH_INDEX_WRITERS = ['auto', 'js', 'rust'];
25
+ /** Column categories a resolver can match a user word against. */
26
+ const MATCH_SOURCES = ['name', 'name-part', 'comment', 'synonym', 'fuzzy'];
27
+ /** Why a `find` request produced the answer it did. */
28
+ const FIND_STATUSES = ['resolved', 'ambiguous', 'missing_predicate', 'not_found'];
29
+ /** One object's index state, as `ctx.dbgraph` reports it. */
30
+ const INDEX_STATE = {
31
+ type: 'object',
32
+ additionalProperties: false,
33
+ properties: {
34
+ l1_indexed_at: { type: 'integer' },
35
+ l2_indexed_at: { type: 'integer' },
36
+ objects: { type: 'integer', required: true },
37
+ columns: { type: 'integer', required: true },
38
+ stale: { type: 'boolean', required: true },
39
+ writer: { type: 'string' },
40
+ },
41
+ };
42
+ /** One configured connection, secrets omitted. */
43
+ const CONNECTION = {
44
+ type: 'object',
45
+ additionalProperties: false,
46
+ properties: {
47
+ id: { type: 'string', required: true },
48
+ engine: { type: 'string', required: true },
49
+ label: { type: 'string' },
50
+ host: { type: 'string' },
51
+ database: { type: 'string' },
52
+ credential_configured: { type: 'boolean', required: true },
53
+ index: { ...INDEX_STATE, required: true },
54
+ },
55
+ };
56
+ /** One object in a listing, without its columns. */
57
+ const OBJECT = {
58
+ type: 'object',
59
+ additionalProperties: false,
60
+ properties: {
61
+ object: { type: 'string', required: true },
62
+ kind: { type: 'string', required: true },
63
+ comment: { type: 'string' },
64
+ column_count: { type: 'integer', required: true },
65
+ row_estimate: { type: 'integer' },
66
+ },
67
+ };
68
+ /** One column in a listing. */
69
+ const COLUMN = {
70
+ type: 'object',
71
+ additionalProperties: false,
72
+ properties: {
73
+ name: { type: 'string', required: true },
74
+ type: { type: 'string', required: true },
75
+ nullable: { type: 'boolean', required: true },
76
+ default_value: { type: 'string' },
77
+ comment: { type: 'string' },
78
+ is_primary_key: { type: 'boolean', required: true },
79
+ is_unique: { type: 'boolean', required: true },
80
+ enum_values: { type: 'array', items: { type: 'string' } },
81
+ },
82
+ };
83
+ /** One column the resolver picked, with the evidence that picked it. */
84
+ const MATCHED_COLUMN = {
85
+ type: 'object',
86
+ additionalProperties: false,
87
+ properties: {
88
+ column: { type: 'string', required: true },
89
+ comment: { type: 'string' },
90
+ matched_by: { type: 'string', required: true, enum: [...MATCH_SOURCES] },
91
+ term: { type: 'string' },
92
+ score: { type: 'number', required: true },
93
+ },
94
+ };
95
+ /** One object the resolver considered. */
96
+ const FIND_CANDIDATE = {
97
+ type: 'object',
98
+ additionalProperties: false,
99
+ properties: {
100
+ object: { type: 'string', required: true },
101
+ kind: { type: 'string', required: true },
102
+ comment: { type: 'string' },
103
+ score: { type: 'number', required: true },
104
+ columns: { type: 'array', required: true, items: MATCHED_COLUMN },
105
+ },
106
+ };
107
+ /** One edge touching an object. */
108
+ const RELATION = {
109
+ type: 'object',
110
+ additionalProperties: false,
111
+ properties: {
112
+ kind: { type: 'string', required: true },
113
+ object: { type: 'string', required: true },
114
+ column: { type: 'string' },
115
+ ref_column: { type: 'string' },
116
+ name: { type: 'string' },
117
+ },
118
+ };
119
+ /** Rows as the seam returns them: JSON-safe scalars, objects, arrays — never a provider handle. */
120
+ const ROWS = { type: 'array', required: true, items: { type: 'json' } };
121
+ /**
122
+ * Build one `oneOf` member for a fixed operation name.
123
+ *
124
+ * Both type parameters are `const` so the member keeps its literal types: without them the helper
125
+ * would widen `operation` to the whole union and erase each member's own fields, and `InferValue`
126
+ * would produce one shapeless object instead of a discriminated union.
127
+ * @param operation - the literal `operation` value discriminating this member.
128
+ * @param properties - the fields this operation returns beyond `operation`.
129
+ * @returns the member's value schema.
130
+ */
131
+ function member(operation, properties) {
132
+ return {
133
+ type: 'object',
134
+ additionalProperties: false,
135
+ properties: {
136
+ operation: { type: 'string', required: true, const: operation },
137
+ ...properties,
138
+ },
139
+ };
140
+ }
141
+ /** The canonical value every `dbgraph` call returns, discriminated by `operation`. */
142
+ export const DBGRAPH_OUTPUT_SCHEMA = {
143
+ oneOf: [
144
+ member('connections', {
145
+ connections: { type: 'array', required: true, items: CONNECTION },
146
+ }),
147
+ member('schema', {
148
+ connection: { type: 'string', required: true },
149
+ engine: { type: 'string', required: true },
150
+ database: { type: 'string', required: true },
151
+ objects: { type: 'array', required: true, items: OBJECT },
152
+ truncated: { type: 'boolean', required: true },
153
+ comment_coverage: { type: 'number', required: true },
154
+ index: { ...INDEX_STATE, required: true },
155
+ }),
156
+ member('objects', {
157
+ connection: { type: 'string', required: true },
158
+ objects: { type: 'array', required: true, items: OBJECT },
159
+ truncated: { type: 'boolean', required: true },
160
+ }),
161
+ member('columns', {
162
+ connection: { type: 'string', required: true },
163
+ object: { type: 'string', required: true },
164
+ kind: { type: 'string', required: true },
165
+ comment: { type: 'string' },
166
+ columns: { type: 'array', required: true, items: COLUMN },
167
+ truncated: { type: 'boolean', required: true },
168
+ }),
169
+ member('find', {
170
+ connection: { type: 'string', required: true },
171
+ status: { type: 'string', required: true, enum: [...FIND_STATUSES] },
172
+ reason: { type: 'string', required: true },
173
+ confidence: { type: 'number', required: true },
174
+ resolved: FIND_CANDIDATE,
175
+ candidates: { type: 'array', items: FIND_CANDIDATE },
176
+ sql: { type: 'string' },
177
+ rows: { type: 'array', items: { type: 'json' } },
178
+ row_count: { type: 'integer' },
179
+ truncated: { type: 'boolean' },
180
+ redacted: { type: 'array', items: { type: 'string' } },
181
+ elapsed_ms: { type: 'integer', required: true },
182
+ }),
183
+ member('sql', {
184
+ connection: { type: 'string', required: true },
185
+ columns: { type: 'array', required: true, items: { type: 'string' } },
186
+ rows: ROWS,
187
+ row_count: { type: 'integer', required: true },
188
+ truncated: { type: 'boolean', required: true },
189
+ redacted: { type: 'array', required: true, items: { type: 'string' } },
190
+ affected_rows: { type: 'integer' },
191
+ elapsed_ms: { type: 'integer', required: true },
192
+ warnings: { type: 'array', items: { type: 'string' } },
193
+ }),
194
+ member('impact', {
195
+ connection: { type: 'string', required: true },
196
+ object: { type: 'string', required: true },
197
+ entries: { type: 'array', required: true, items: RELATION },
198
+ truncated: { type: 'boolean', required: true },
199
+ }),
200
+ member('refs', {
201
+ connection: { type: 'string', required: true },
202
+ object: { type: 'string', required: true },
203
+ entries: { type: 'array', required: true, items: RELATION },
204
+ truncated: { type: 'boolean', required: true },
205
+ }),
206
+ ],
207
+ };
208
+ /** The parameters the model fills in for `dbgraph`. Which ones apply depends on `operation`. */
209
+ export const DBGRAPH_PARAMETERS = {
210
+ operation: {
211
+ type: 'string',
212
+ required: true,
213
+ enum: [...DBGRAPH_OPERATIONS],
214
+ description: 'connections (list configured connections with their index state), schema (one connection\'s structural overview), objects (find tables by word, ranked), columns (one table\'s columns), find (resolve words to a table and columns, then execute ONE parameterized read — the fast path), sql (execute one statement verbatim), impact (what a table\'s change reaches), refs (what references a table). To build or refresh an index, call the dbgraph_index tool instead.',
215
+ },
216
+ connection: {
217
+ type: 'string',
218
+ description: 'Connection id, as listed by operation "connections". Required by every operation except "connections".',
219
+ },
220
+ query: {
221
+ type: 'string',
222
+ description: 'Search text for objects (a table name or comment word), or the statement for sql.',
223
+ },
224
+ object: {
225
+ type: 'string',
226
+ description: 'Table or view name for columns, impact, and refs. For find, names the table outright and skips object resolution.',
227
+ },
228
+ entity: {
229
+ type: 'string',
230
+ description: 'What the user is talking about for find, e.g. 用户 or 订单. Matched against table names, comments, and Chinese aliases.',
231
+ },
232
+ fields: {
233
+ type: 'array',
234
+ items: { type: 'string' },
235
+ description: 'Columns the caller wants for find, e.g. ["密码"]. Omit for every column.',
236
+ },
237
+ where: {
238
+ type: 'json',
239
+ description: 'Filter for find: a JSON object mapping a column name to a value, e.g. {"id": 7}. A column that does not exist fails with the available column list.',
240
+ },
241
+ limit: {
242
+ type: 'number',
243
+ description: 'Largest number of rows or objects to return.',
244
+ },
245
+ };
246
+ /**
247
+ * The parameters the dedicated `dbgraph_index` tool takes. It needs no `operation` — building an
248
+ * index is the only thing it does — and none of the query-side fields, which an index run has no
249
+ * use for.
250
+ */
251
+ export const DBGRAPH_INDEX_PARAMETERS = {
252
+ connection: {
253
+ type: 'string',
254
+ description: 'Connection id to index. Omitted indexes every configured connection.',
255
+ },
256
+ mode: {
257
+ type: 'string',
258
+ enum: [...DBGRAPH_INDEX_MODES],
259
+ description: 'How deep to build: l1 (structure only, fast), full (L1 then L2 enrichment, the default), l2 (accepted as an alias of full: every non-l1 run re-reads L1 first).',
260
+ },
261
+ writer: {
262
+ type: 'string',
263
+ enum: [...DBGRAPH_INDEX_WRITERS],
264
+ description: 'Which writer to prefer: auto (native when available, JS otherwise), js, or rust.',
265
+ },
266
+ };
267
+ /** One finished indexing run, as the model sees it. */
268
+ const INDEX_REPORT = {
269
+ type: 'object',
270
+ additionalProperties: false,
271
+ properties: {
272
+ connection: { type: 'string', required: true },
273
+ level: { type: 'string', required: true, enum: ['l1', 'l2'] },
274
+ objects: { type: 'integer', required: true },
275
+ columns: { type: 'integer', required: true },
276
+ edges: { type: 'integer', required: true },
277
+ terms: { type: 'integer', required: true },
278
+ writer: { type: 'string', required: true, enum: ['js', 'rust'] },
279
+ elapsed_ms: { type: 'integer', required: true },
280
+ warnings: { type: 'array', items: { type: 'string' } },
281
+ },
282
+ };
283
+ /**
284
+ * One `oneOf` member of the index tool's output. Its discriminator is `status`, not `operation`:
285
+ * a started run and a finished run are both answers to the same call.
286
+ * @param status - the literal `status` value discriminating this member.
287
+ * @param properties - the fields this member returns beyond `status`.
288
+ * @returns the member's value schema.
289
+ */
290
+ function indexMember(status, properties) {
291
+ return {
292
+ type: 'object',
293
+ additionalProperties: false,
294
+ properties: {
295
+ status: { type: 'string', required: true, const: status },
296
+ ...properties,
297
+ },
298
+ };
299
+ }
300
+ /** The canonical value every `dbgraph_index` call returns, discriminated by `status`. */
301
+ export const DBGRAPH_INDEX_OUTPUT_SCHEMA = {
302
+ oneOf: [
303
+ indexMember('started', {
304
+ job_id: { type: 'string', required: true },
305
+ connection: { type: 'string' },
306
+ mode: { type: 'string', required: true, enum: [...DBGRAPH_INDEX_MODES] },
307
+ }),
308
+ indexMember('completed', {
309
+ // One entry per indexed connection: a run over several connections must not report only the
310
+ // first, or the model reads the others as never indexed and asks again.
311
+ reports: { type: 'array', required: true, items: INDEX_REPORT },
312
+ }),
313
+ ],
314
+ };
315
+ //# sourceMappingURL=schema.js.map
package/package.json CHANGED
@@ -1,6 +1,81 @@
1
1
  {
2
2
  "name": "dsh-plugin-dbgraph-tool",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Model-facing dbgraph and dbgraph_index tools, the /dbgraph command, and the system-prompt section that carries a schema digest so the model stops spending round-trips learning the schema",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "cordis",
10
+ "cordis-plugin",
11
+ "database",
12
+ "sql",
13
+ "sqlite",
14
+ "mysql",
15
+ "postgresql",
16
+ "mongodb",
17
+ "redis",
18
+ "schema",
19
+ "ai-agent",
20
+ "llm-tools"
21
+ ],
22
+ "license": "MIT",
23
+ "author": "CC ZHAO",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/CC19990113/dsh-plugin-dbgraph.git",
27
+ "directory": "packages/tool"
28
+ },
29
+ "homepage": "https://github.com/CC19990113/dsh-plugin-dbgraph#readme",
30
+ "bugs": "https://github.com/CC19990113/dsh-plugin-dbgraph/issues",
31
+ "type": "module",
32
+ "main": "lib/index.js",
33
+ "types": "lib/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./lib/index.d.ts",
37
+ "default": "./lib/index.js"
38
+ },
39
+ "./invariant": {
40
+ "types": "./lib/invariant.d.ts",
41
+ "default": "./lib/invariant.js"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "files": [
46
+ "lib/**/*.js",
47
+ "lib/**/*.d.ts"
48
+ ],
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "provenance": true
52
+ },
53
+ "peerDependencies": {
54
+ "@deepseek-ai/cordis": ">=4.0.1",
55
+ "@deepseek-ai/dsh-brand": ">=0.1.0-rc.6",
56
+ "@deepseek-ai/dsh-invariants": ">=0.1.0-rc.6",
57
+ "@deepseek-ai/dsh-llm": ">=0.1.0-rc.6",
58
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.6",
59
+ "@deepseek-ai/dsh-system-prompt": ">=0.1.0-rc.6",
60
+ "@deepseek-ai/dsh-timeout": ">=0.1.0-rc.6",
61
+ "@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6"
62
+ },
63
+ "devDependencies": {
64
+ "@deepseek-ai/cordis": "^4.0.1",
65
+ "@deepseek-ai/dsh-brand": "0.1.0-rc.6",
66
+ "@deepseek-ai/dsh-invariants": "0.1.0-rc.6",
67
+ "@deepseek-ai/dsh-llm": "0.1.0-rc.6",
68
+ "@deepseek-ai/dsh-tools": "0.1.0-rc.6",
69
+ "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6",
70
+ "@deepseek-ai/dsh-timeout": "0.1.0-rc.6",
71
+ "@deepseek-ai/dsh-credentials": "0.1.0-rc.6",
72
+ "dsh-plugin-dbgraph-service": "^0.1.0",
73
+ "dsh-plugin-dbgraph-catalog": "^0.1.0",
74
+ "dsh-plugin-dbgraph-store": "^0.1.0"
75
+ },
76
+ "dependencies": {
77
+ "dsh-plugin-dbgraph-service": "^0.1.0",
78
+ "dsh-plugin-dbgraph-catalog": "^0.1.0",
79
+ "dsh-plugin-dbgraph-store": "^0.1.0"
80
+ }
6
81
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.