@prom.codes/saver 0.1.5 → 0.1.6

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.
Files changed (3) hide show
  1. package/README.md +7 -4
  2. package/dist/bin.js +48 -29
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -25,10 +25,13 @@ never for code/destructive work). The rules keep code, caveats, destructive step
25
25
  and anything the agent needs later **verbatim** — it shapes phrasing, never what the
26
26
  agent does or remembers.
27
27
 
28
- A second tool, `status`, reports where it would write, the key state, and which
29
- runtimes already have the block installed. If a fresh window opens with no
30
- project (workspace falls back to home), `setup` **refuses to write rule files
31
- into your home dir** open your project folder first.
28
+ **It installs itself.** An MCP server can't act on its own, so the rule only
29
+ saves tokens once it's in a config file. On startup the Saver **auto-installs**
30
+ the marked rule block into config files you already have (CLAUDE.md / AGENTS.md /
31
+ Cursor / Augment)idempotent, never creates a new file, skipped for home/root,
32
+ opt out with `PROMETHEUS_SAVER_AUTO_SETUP=off`. Run `setup` to install into all
33
+ runtimes (incl. creating AGENTS.md if you have none). A `status` tool reports
34
+ where it writes, the key state, and which runtimes already have the block.
32
35
 
33
36
  No database and no native modules — `npx` works turnkey everywhere (Node ≥ 20.10).
34
37
  The workspace is auto-detected (Claude Code `CLAUDE_PROJECT_DIR`); set
package/dist/bin.js CHANGED
@@ -13,36 +13,10 @@ function classifyKey(raw) {
13
13
  return KEY_PATTERN.test(key) ? "valid" : "malformed";
14
14
  }
15
15
 
16
- // dist/workspace.js
17
- import { homedir } from "node:os";
18
- import { dirname, resolve } from "node:path";
19
- function isHomeOrFilesystemRoot(root) {
20
- const abs = resolve(root);
21
- if (abs === "")
22
- return true;
23
- if (abs === resolve(homedir()))
24
- return true;
25
- if (dirname(abs) === abs)
26
- return true;
27
- return false;
28
- }
29
- function resolveWorkspaceRoot(env = process.env) {
30
- const explicit = (env.PROMETHEUS_WORKSPACE_ROOT ?? "").trim();
31
- if (explicit !== "")
32
- return resolve(explicit);
33
- const claude = (env.CLAUDE_PROJECT_DIR ?? "").trim();
34
- if (claude !== "")
35
- return resolve(claude);
36
- return resolve(process.cwd());
37
- }
38
-
39
- // dist/tools.js
40
- import { z } from "zod";
41
-
42
16
  // dist/setup.js
43
17
  import { existsSync, readFileSync } from "node:fs";
44
18
  import { mkdir, readFile, writeFile } from "node:fs/promises";
45
- import { dirname as dirname2, join } from "node:path";
19
+ import { dirname, join } from "node:path";
46
20
  var SAVER_LEVELS = ["lite", "balanced", "aggressive"];
47
21
  var DEFAULT_LEVEL = "balanced";
48
22
  var SAVER_RUNTIMES = [
@@ -117,6 +91,16 @@ function installedRuntimes(workspaceRoot) {
117
91
  }
118
92
  });
119
93
  }
94
+ function existingRuntimes(workspaceRoot) {
95
+ return SAVER_RUNTIMES.filter((rt) => existsSync(join(workspaceRoot, TARGETS[rt].detect)));
96
+ }
97
+ async function autoInstallExisting(workspaceRoot, level) {
98
+ const results = [];
99
+ for (const rt of existingRuntimes(workspaceRoot)) {
100
+ results.push(await installRuntime(workspaceRoot, rt, level));
101
+ }
102
+ return results;
103
+ }
120
104
  function upsertBlock(existing, block) {
121
105
  const marked = withMarkers(block);
122
106
  const start = existing.indexOf(BLOCK_START);
@@ -137,12 +121,36 @@ async function installRuntime(workspaceRoot, runtime, level) {
137
121
  if (exists && before === after) {
138
122
  return { runtime, path: absPath, action: "unchanged" };
139
123
  }
140
- await mkdir(dirname2(absPath), { recursive: true });
124
+ await mkdir(dirname(absPath), { recursive: true });
141
125
  await writeFile(absPath, after, "utf-8");
142
126
  return { runtime, path: absPath, action: exists ? "updated" : "created" };
143
127
  }
144
128
 
129
+ // dist/workspace.js
130
+ import { homedir } from "node:os";
131
+ import { dirname as dirname2, resolve } from "node:path";
132
+ function isHomeOrFilesystemRoot(root) {
133
+ const abs = resolve(root);
134
+ if (abs === "")
135
+ return true;
136
+ if (abs === resolve(homedir()))
137
+ return true;
138
+ if (dirname2(abs) === abs)
139
+ return true;
140
+ return false;
141
+ }
142
+ function resolveWorkspaceRoot(env = process.env) {
143
+ const explicit = (env.PROMETHEUS_WORKSPACE_ROOT ?? "").trim();
144
+ if (explicit !== "")
145
+ return resolve(explicit);
146
+ const claude = (env.CLAUDE_PROJECT_DIR ?? "").trim();
147
+ if (claude !== "")
148
+ return resolve(claude);
149
+ return resolve(process.cwd());
150
+ }
151
+
145
152
  // dist/tools.js
153
+ import { z } from "zod";
146
154
  var REQUIRE_KEY_ENV = "PROMETHEUS_SAVER_REQUIRE_KEY";
147
155
  function textResult(payload) {
148
156
  return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
@@ -228,7 +236,7 @@ var SERVER_IDENTITY = {
228
236
  version: "0.1.0",
229
237
  title: "prom.codes Saver"
230
238
  };
231
- var SERVER_INSTRUCTIONS = "prom.codes Saver cuts token cost by trimming the agent's own prose \u2014 preamble, play-by-play narration and pasted tool output \u2014 while keeping code, caveats and destructive sequences verbatim. Run `setup` once per workspace to install the efficient-output protocol into the runtime rule files. Default level is `balanced` (lean, not terse): lead with the answer, summarize long output, one end-of-task summary. Never sacrifice correctness, safety or completeness to save tokens.";
239
+ var SERVER_INSTRUCTIONS = "prom.codes Saver cuts token cost by trimming the agent's own prose \u2014 preamble, play-by-play narration and pasted tool output \u2014 while keeping code, caveats and destructive sequences verbatim. The rule only works once it is installed into this workspace's runtime config: the server AUTO-INSTALLS it on startup when a config file already exists; otherwise call `setup` once to install it (it also creates AGENTS.md if you have no config yet). Call `status` to check. Default level `balanced` (lean, not terse): lead with the answer, summarize long output, one end-of-task summary. Never sacrifice correctness, safety or completeness to save tokens.";
232
240
  function createServer(deps, options = {}) {
233
241
  const identity = { ...SERVER_IDENTITY, ...options.identity ?? {} };
234
242
  const capabilities = options.capabilities ?? { tools: {} };
@@ -263,6 +271,17 @@ async function main() {
263
271
  requireKey,
264
272
  ...apiKey !== void 0 ? { apiKey } : {}
265
273
  });
274
+ const autoSetup = !/^(off|0|false|no)$/i.test(process.env.PROMETHEUS_SAVER_AUTO_SETUP ?? "");
275
+ if (autoSetup && !isHomeOrFilesystemRoot(workspaceRoot)) {
276
+ void autoInstallExisting(workspaceRoot, DEFAULT_LEVEL).then((results) => {
277
+ const wrote = results.filter((r) => r.action !== "unchanged");
278
+ if (wrote.length > 0) {
279
+ process.stderr.write(`prom-codes-saver: auto-installed the efficiency rule into ${wrote.map((r) => r.runtime).join(", ")} (set PROMETHEUS_SAVER_AUTO_SETUP=off to disable)
280
+ `);
281
+ }
282
+ }).catch(() => {
283
+ });
284
+ }
266
285
  const transport = new StdioServerTransport();
267
286
  const shutdown = async (signal) => {
268
287
  process.stderr.write(`prom-codes-saver: received ${signal}, shutting down
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prom.codes/saver",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "prom.codes Saver — cut token cost without cutting quality, as an MCP installer.",
5
5
  "type": "module",
6
6
  "bin": {