@prom.codes/saver 0.1.2 → 0.1.3
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/dist/bin.js +40 -8
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve } from "node:path";
|
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
6
|
|
|
7
7
|
// dist/key.js
|
|
8
|
-
var KEY_PATTERN = /^prom_(live|test)_[A-Za-z0-9]{
|
|
8
|
+
var KEY_PATTERN = /^prom_(live|test)_[A-Za-z0-9]{6,}(?:_[A-Za-z0-9]{6,})?$/;
|
|
9
9
|
var API_KEY_ENV = "PROMETHEUS_API_KEY";
|
|
10
10
|
function classifyKey(raw) {
|
|
11
11
|
const key = raw?.trim();
|
|
@@ -14,9 +14,6 @@ function classifyKey(raw) {
|
|
|
14
14
|
return KEY_PATTERN.test(key) ? "valid" : "malformed";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// dist/server.js
|
|
18
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
19
|
-
|
|
20
17
|
// dist/tools.js
|
|
21
18
|
import { z } from "zod";
|
|
22
19
|
|
|
@@ -112,6 +109,7 @@ async function installRuntime(workspaceRoot, runtime, level) {
|
|
|
112
109
|
}
|
|
113
110
|
|
|
114
111
|
// dist/tools.js
|
|
112
|
+
var REQUIRE_KEY_ENV = "PROMETHEUS_SAVER_REQUIRE_KEY";
|
|
115
113
|
function textResult(payload) {
|
|
116
114
|
return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
|
|
117
115
|
}
|
|
@@ -122,23 +120,47 @@ var setupInput = {
|
|
|
122
120
|
runtimes: z.array(runtimeEnum).min(1).optional()
|
|
123
121
|
};
|
|
124
122
|
function registerTools(server, deps) {
|
|
125
|
-
const { workspaceRoot, apiKey } = deps;
|
|
123
|
+
const { workspaceRoot, apiKey, requireKey } = deps;
|
|
124
|
+
const keyState = deps.keyState ?? (apiKey !== void 0 ? "valid" : "absent");
|
|
126
125
|
server.registerTool("setup", {
|
|
127
126
|
title: "Install the prom.codes Saver efficient-output rules",
|
|
128
127
|
description: "Idempotently install the prom.codes Saver efficient-output rule block into this workspace's agent runtime configs (CLAUDE.md / .cursor/rules / .augment/rules / AGENTS.md). The rules cut token cost by trimming the agent's own prose (preamble, narration, pasted tool output) while keeping code, caveats and destructive sequences verbatim. `level`: `lite` (filler only) | `balanced` (default \u2014 lean, not terse) | `aggressive` (telegraphic, opt-in, never for code/destructive). Without `runtimes` it auto-detects which are present (fallback: agents). Re-running updates the block in place. Run this once per workspace.",
|
|
129
128
|
inputSchema: setupInput
|
|
130
129
|
}, async (args) => {
|
|
130
|
+
if (requireKey === true && keyState !== "valid") {
|
|
131
|
+
return {
|
|
132
|
+
isError: true,
|
|
133
|
+
content: [
|
|
134
|
+
{
|
|
135
|
+
type: "text",
|
|
136
|
+
text: JSON.stringify({
|
|
137
|
+
ok: false,
|
|
138
|
+
installed: false,
|
|
139
|
+
keyState,
|
|
140
|
+
error: `prom.codes Saver: a valid ${API_KEY_ENV} (prom_live_\u2026 / prom_test_\u2026) is required to install because ${REQUIRE_KEY_ENV} is enabled (key is "${keyState}"). Set the key in this server's env block, or unset ${REQUIRE_KEY_ENV} to install keyless.`
|
|
141
|
+
}, null, 2)
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
};
|
|
145
|
+
}
|
|
131
146
|
const level = args.level ?? DEFAULT_LEVEL;
|
|
132
147
|
const runtimes = args.runtimes ?? detectRuntimes(workspaceRoot);
|
|
133
148
|
const results = [];
|
|
134
149
|
for (const runtime of runtimes) {
|
|
135
150
|
results.push(await installRuntime(workspaceRoot, runtime, level));
|
|
136
151
|
}
|
|
137
|
-
return textResult({
|
|
152
|
+
return textResult({
|
|
153
|
+
workspaceRoot,
|
|
154
|
+
level,
|
|
155
|
+
keyed: apiKey !== void 0,
|
|
156
|
+
keyState,
|
|
157
|
+
results
|
|
158
|
+
});
|
|
138
159
|
});
|
|
139
160
|
}
|
|
140
161
|
|
|
141
162
|
// dist/server.js
|
|
163
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
142
164
|
var SERVER_IDENTITY = {
|
|
143
165
|
name: "prom-codes-saver",
|
|
144
166
|
version: "0.1.0",
|
|
@@ -161,14 +183,24 @@ async function main() {
|
|
|
161
183
|
const workspaceRoot = resolve(process.env.PROMETHEUS_WORKSPACE_ROOT ?? process.cwd());
|
|
162
184
|
const rawKey = process.env[API_KEY_ENV];
|
|
163
185
|
const keyState = classifyKey(rawKey);
|
|
186
|
+
const requireKey = /^(1|true|yes|on)$/i.test(process.env[REQUIRE_KEY_ENV] ?? "");
|
|
164
187
|
if (keyState === "malformed") {
|
|
165
188
|
process.stderr.write(`prom-codes-saver: ${API_KEY_ENV} is malformed (expected prom_live_\u2026 / prom_test_\u2026); continuing keyless.
|
|
189
|
+
`);
|
|
190
|
+
}
|
|
191
|
+
if (requireKey && keyState !== "valid") {
|
|
192
|
+
process.stderr.write(`prom-codes-saver: ${REQUIRE_KEY_ENV} is on but ${API_KEY_ENV} is ${keyState}; setup will refuse to install until a valid prom_ key is provided.
|
|
166
193
|
`);
|
|
167
194
|
}
|
|
168
195
|
const apiKey = keyState === "valid" ? rawKey.trim() : void 0;
|
|
169
|
-
process.stderr.write(`prom-codes-saver: workspace=${workspaceRoot} key=${keyState}
|
|
196
|
+
process.stderr.write(`prom-codes-saver: workspace=${workspaceRoot} key=${keyState} requireKey=${requireKey}
|
|
170
197
|
`);
|
|
171
|
-
const server = createServer({
|
|
198
|
+
const server = createServer({
|
|
199
|
+
workspaceRoot,
|
|
200
|
+
keyState,
|
|
201
|
+
requireKey,
|
|
202
|
+
...apiKey !== void 0 ? { apiKey } : {}
|
|
203
|
+
});
|
|
172
204
|
const transport = new StdioServerTransport();
|
|
173
205
|
const shutdown = async (signal) => {
|
|
174
206
|
process.stderr.write(`prom-codes-saver: received ${signal}, shutting down
|