@elinpf/dsh-ops-tool-prometheus 0.2.1 → 0.4.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/index.d.ts CHANGED
@@ -9,17 +9,18 @@
9
9
  * reaches the result, the displayed command, or any error text (every
10
10
  * returned string is scrubbed against it defensively).
11
11
  *
12
- * The result shape `{ exitCode, stdout, stderr, command, error? }`, output
13
- * schema, and render duplicate the ops-shell-tool contract verbatim — that
14
- * factory wraps ctx.shell commands, which this tool is not, and it does not
15
- * export the contract separately.
12
+ * The result shape `{ exitCode, stdout, stderr, command, error? }` and the
13
+ * output schema/render come from `shellToolOutput`/`ShellToolResult` in
14
+ * ops-shell-tool the suite-standard contract, reused (that factory wraps
15
+ * ctx.shell commands, which this tool is not, but the contract stands alone).
16
16
  *
17
17
  * @module @elinpf/dsh-ops-tool-prometheus
18
18
  */
19
19
  import type { Context } from '@deepseek-ai/cordis';
20
20
  import z from '@deepseek-ai/schemastery';
21
21
  import type { PrometheusToolConfig } from './types.js';
22
- export type { PrometheusToolConfig, PrometheusToolResult } from './types.js';
22
+ export type { PrometheusToolConfig } from './types.js';
23
+ export type { ShellToolResult as PrometheusToolResult } from '@elinpf/dsh-ops-shell-tool';
23
24
  export declare const name = "ops-tool-prometheus";
24
25
  export declare const inject: string[];
25
26
  export declare const Config: z<PrometheusToolConfig>;
package/lib/index.js CHANGED
@@ -9,16 +9,17 @@
9
9
  * reaches the result, the displayed command, or any error text (every
10
10
  * returned string is scrubbed against it defensively).
11
11
  *
12
- * The result shape `{ exitCode, stdout, stderr, command, error? }`, output
13
- * schema, and render duplicate the ops-shell-tool contract verbatim — that
14
- * factory wraps ctx.shell commands, which this tool is not, and it does not
15
- * export the contract separately.
12
+ * The result shape `{ exitCode, stdout, stderr, command, error? }` and the
13
+ * output schema/render come from `shellToolOutput`/`ShellToolResult` in
14
+ * ops-shell-tool the suite-standard contract, reused (that factory wraps
15
+ * ctx.shell commands, which this tool is not, but the contract stands alone).
16
16
  *
17
17
  * @module @elinpf/dsh-ops-tool-prometheus
18
18
  */
19
19
  import z from '@deepseek-ai/schemastery';
20
20
  import { defineTool } from '@deepseek-ai/dsh-tools';
21
21
  import { readFile } from 'node:fs/promises';
22
+ import { shellToolOutput } from '@elinpf/dsh-ops-shell-tool';
22
23
  // ── Plugin identity ───────────────────────────────────────────────────────────
23
24
  export const name = 'ops-tool-prometheus';
24
25
  export const inject = ['tools'];
@@ -27,36 +28,8 @@ export const Config = z.object({
27
28
  /** Per-call HTTP timeout for Prometheus queries (ms). Slow queries may need more. */
28
29
  timeoutMs: z.number().default(30000),
29
30
  });
30
- // ── Output contract (verbatim copy of the ops-shell-tool one) ────────────────
31
- const output = {
32
- schema: {
33
- type: 'object',
34
- additionalProperties: false,
35
- properties: {
36
- exitCode: { type: 'number', required: true },
37
- stdout: { type: 'string', required: true },
38
- stderr: { type: 'string', required: true },
39
- command: { type: 'string', required: true },
40
- error: { type: 'string' },
41
- },
42
- },
43
- // Pure function of (args, value): same inputs, same text, no state touched.
44
- render: (_args, value) => {
45
- const parts = [];
46
- if (value.command)
47
- parts.push(`$ ${value.command}`);
48
- if (value.stdout)
49
- parts.push(value.stdout);
50
- if (value.stderr)
51
- parts.push(`[stderr]\n${value.stderr}`);
52
- if (value.error)
53
- parts.push(`[error] ${value.error}`);
54
- if (value.exitCode !== 0 && value.exitCode !== undefined && value.exitCode !== null) {
55
- parts.push(`[exit code: ${value.exitCode}]`);
56
- }
57
- return [{ type: 'text', text: parts.join('\n\n') || '(no output)' }];
58
- },
59
- };
31
+ // ── Output contract: the ops-shell-tool one, shared ──────────────────────────
32
+ const output = shellToolOutput;
60
33
  // ── Formatting ───────────────────────────────────────────────────────────────
61
34
  /** Hard caps guarding the model's context against a fat range query. */
62
35
  const MAX_SERIES = 100;
@@ -156,6 +129,7 @@ export function createPrometheusTool(ctx, config, deps = {}) {
156
129
  end: { type: 'string', description: 'Range query end (RFC3339 or unix seconds). Requires start and step.' },
157
130
  step: { type: 'string', description: 'Range query resolution step, e.g. "15s", "1m". Requires start and end.' },
158
131
  timeoutSec: { type: 'number', description: 'Optional per-call timeout in seconds (default 30, max 600). Use only for a query you KNOW is slow (a wide range over many series) — a longer wait does not fix an unreachable server.' },
132
+ tier: { type: 'string', enum: ['ro', 'rw'], description: 'Credential tier for THIS call. Omit = decided by the grant. "ro" = deliberate downgrade under an rw grant (declare it for pure queries). "rw" = require the write tier; fails loudly without a session grant and points at request_access.' },
159
133
  },
160
134
  output,
161
135
  async execute(args, exec) {
@@ -192,8 +166,10 @@ export function createPrometheusTool(ctx, config, deps = {}) {
192
166
  }
193
167
  // Pass the caller agent through so the access gate (if mounted) can
194
168
  // key grants on the session id. Core tolerates a `prometheus/` prefix
195
- // on the name.
196
- const profile = await opsAccess.resolve('prometheus', cluster, exec.agent);
169
+ // on the name. An explicit tier arg is the per-call declaration
170
+ // ('ro' = deliberate downgrade; 'rw' = fail loudly when ungranted).
171
+ const tierArg = args.tier === 'ro' || args.tier === 'rw' ? args.tier : undefined;
172
+ const profile = await opsAccess.resolve('prometheus', cluster, exec.agent, tierArg ? { tier: tierArg } : undefined);
197
173
  const baseUrl = String(profile.fields.url ?? '');
198
174
  const endpoint = isRange ? '/api/v1/query_range' : '/api/v1/query';
199
175
  command = `${display} @ ${baseUrl}${endpoint}`;
package/lib/types.d.ts CHANGED
@@ -13,17 +13,3 @@ export interface PrometheusToolConfig {
13
13
  /** Per-call HTTP timeout for Prometheus queries (ms). Slow queries may need more. */
14
14
  timeoutMs: number;
15
15
  }
16
- /**
17
- * The suite-standard tool result shape — identical to ShellToolResult in
18
- * @elinpf/dsh-ops-shell-tool. Duplicated here (with the output schema/render)
19
- * because this tool speaks HTTP, not shell: it does not go through
20
- * registerProfiledShellTool, and ops-shell-tool does not export the contract
21
- * separately.
22
- */
23
- export interface PrometheusToolResult {
24
- exitCode: number;
25
- stdout: string;
26
- stderr: string;
27
- command: string;
28
- error?: string;
29
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elinpf/dsh-ops-tool-prometheus",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "prometheus tool consumer of the ops-access seam — resolves prometheus profiles and runs PromQL instant/range queries over the Prometheus HTTP API, injecting the bearer token automatically.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -33,12 +33,13 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@deepseek-ai/schemastery": "^3.18.1"
36
+ "@deepseek-ai/schemastery": "^3.18.1",
37
+ "@elinpf/dsh-ops-shell-tool": "0.4.0"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "@deepseek-ai/cordis": "^4.0.1",
40
41
  "@deepseek-ai/dsh-tools": "^0.1.0-rc.8",
41
- "@elinpf/dsh-ops-access": "^0.2.1"
42
+ "@elinpf/dsh-ops-access": "^0.4.0"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@deepseek-ai/cordis": "4.0.1",
@@ -46,7 +47,8 @@
46
47
  "@types/node": "^22.0.0",
47
48
  "typescript": "^5.4.0",
48
49
  "vitest": "^4.1.11",
49
- "@elinpf/dsh-ops-access": "0.2.1"
50
+ "@elinpf/dsh-ops-test-support": "0.0.0",
51
+ "@elinpf/dsh-ops-access": "0.4.0"
50
52
  },
51
53
  "license": "MIT",
52
54
  "publishConfig": {