pennyrouter 0.1.13 → 0.1.15
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/package.json +2 -2
- package/src/statusline.js +18 -4
- package/src/statusline.test.js +70 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pennyrouter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Install and manage PennyRouter local coding-agent integrations.",
|
|
5
5
|
"homepage": "https://pennyrouter.com",
|
|
6
6
|
"bugs": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"start": "node ./bin/pennyrouter.js",
|
|
27
|
-
"check": "node --check ./bin/pennyrouter.js && find src -name '*.js' -print0 | xargs -0 -n1 node --check"
|
|
27
|
+
"check": "node --check ./bin/pennyrouter.js && find src -name '*.js' -print0 | xargs -0 -n1 node --check && node src/statusline.test.js"
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT"
|
|
30
30
|
}
|
package/src/statusline.js
CHANGED
|
@@ -94,8 +94,16 @@ function readJson(path) {
|
|
|
94
94
|
function claudeEnv() {
|
|
95
95
|
const settings = readJson(join(os.homedir(), ".claude", "settings.json")) || {};
|
|
96
96
|
const env = settings.env || {};
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
// A normal install writes base + pr- key into settings.json's env block. Fall back to the
|
|
98
|
+
// process environment so an out-of-band launch that supplies them there instead — e.g. the
|
|
99
|
+
// interactive probe, which passes creds via --settings <file> + child env rather than the
|
|
100
|
+
// user's settings.json — still resolves Penny. Real installs never set these as env vars, so
|
|
101
|
+
// this fallback is inert for them.
|
|
102
|
+
const base = env.ANTHROPIC_BASE_URL || process.env.ANTHROPIC_BASE_URL || "";
|
|
103
|
+
const keyCandidates = [
|
|
104
|
+
env.ANTHROPIC_API_KEY, env.ANTHROPIC_AUTH_TOKEN,
|
|
105
|
+
process.env.ANTHROPIC_API_KEY, process.env.ANTHROPIC_AUTH_TOKEN,
|
|
106
|
+
];
|
|
99
107
|
const key = keyCandidates.find((v) => typeof v === "string" && v.startsWith("pr-")) || "";
|
|
100
108
|
return { base, key };
|
|
101
109
|
}
|
|
@@ -170,9 +178,15 @@ if (config.wrap_command) {
|
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
if (lines.length === 0) {
|
|
173
|
-
|
|
181
|
+
lines = [penny];
|
|
174
182
|
} else {
|
|
175
183
|
lines[0] = lines[0].trimEnd() + " | " + penny;
|
|
176
|
-
console.log(lines.join("\\n"));
|
|
177
184
|
}
|
|
185
|
+
// Ambient tip: the gateway rotates cache.tip on a slow clock (see tips.statusline_tip).
|
|
186
|
+
// Rendered as its own dim line so it never crowds the cost/model segments; absent field
|
|
187
|
+
// (tips off, old gateway, bypass) renders nothing.
|
|
188
|
+
if (pennyInstalled && cache && cache.tip && !cache.bypass) {
|
|
189
|
+
lines.push("\\x1b[2m" + cache.tip + "\\x1b[0m");
|
|
190
|
+
}
|
|
191
|
+
console.log(lines.join("\\n"));
|
|
178
192
|
`;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Guards against the class of bug found 2026-07-18: an unescaped backtick inside a
|
|
2
|
+
// comment on line 99 of statusline.js terminated the STATUSLINE_SCRIPT template
|
|
3
|
+
// literal early, so every `pennyrouter install` since shipped a syntactically broken
|
|
4
|
+
// generated script — installs succeeded silently, the crash only surfaced later, at
|
|
5
|
+
// Claude Code's next statusline render, in a completely different process.
|
|
6
|
+
//
|
|
7
|
+
// `npm run check` (node --check on every source file) happened to catch this ONE
|
|
8
|
+
// instance because the break also broke the OUTER file's parse — but that's
|
|
9
|
+
// incidental: a subtler bug (backticks that still balance, or valid-looking JS that's
|
|
10
|
+
// semantically wrong) would pass --check on the outer file yet still crash at
|
|
11
|
+
// runtime, because --check never looks at the STRING CONTENT of a template literal.
|
|
12
|
+
// This test extracts the ACTUAL constant (not a source-text regex) and validates the
|
|
13
|
+
// real generated script: syntax-checks it, then executes it end-to-end with a fake
|
|
14
|
+
// stdin payload the way Claude Code actually invokes it, so a broken script fails
|
|
15
|
+
// `npm run check` locally instead of a user's install.
|
|
16
|
+
//
|
|
17
|
+
// No test framework in this package yet — plain assert + a process exit code, run via
|
|
18
|
+
// `node src/statusline.test.js` (wired into `npm run check`).
|
|
19
|
+
import assert from "node:assert/strict";
|
|
20
|
+
import { execFileSync } from "node:child_process";
|
|
21
|
+
import fs from "node:fs";
|
|
22
|
+
import os from "node:os";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
|
|
25
|
+
import { configureClaudeCodeStatusline, statuslineScriptPath } from "./statusline.js";
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
const tmpState = fs.mkdtempSync(path.join(os.tmpdir(), "pr-statusline-test-"));
|
|
29
|
+
const prevXdg = process.env.XDG_STATE_HOME;
|
|
30
|
+
process.env.XDG_STATE_HOME = tmpState;
|
|
31
|
+
try {
|
|
32
|
+
const current = {};
|
|
33
|
+
await configureClaudeCodeStatusline(current);
|
|
34
|
+
const scriptPath = statuslineScriptPath();
|
|
35
|
+
assert.ok(fs.existsSync(scriptPath), "script file was written");
|
|
36
|
+
|
|
37
|
+
// 1. Syntax: node --check on the ACTUAL written file (not a regex-extracted copy).
|
|
38
|
+
execFileSync(process.execPath, ["--check", scriptPath], { stdio: "pipe" });
|
|
39
|
+
|
|
40
|
+
// 2. Behavior: run it the way Claude Code does — JSON on stdin, plain stdout.
|
|
41
|
+
// No PennyRouter env configured -> "penny off", no crash, no tip line, no wrap.
|
|
42
|
+
const payload = JSON.stringify({
|
|
43
|
+
session_id: "test-session",
|
|
44
|
+
model: { display_name: "Test Model" },
|
|
45
|
+
workspace: { current_dir: "/tmp" },
|
|
46
|
+
});
|
|
47
|
+
const out = execFileSync(process.execPath, [scriptPath], {
|
|
48
|
+
input: payload, encoding: "utf8", timeout: 5000,
|
|
49
|
+
});
|
|
50
|
+
assert.ok(out.includes("penny off"), `expected "penny off" in output, got: ${out}`);
|
|
51
|
+
assert.ok(out.includes("Test Model"), `expected model name passed through, got: ${out}`);
|
|
52
|
+
|
|
53
|
+
// 3. Malformed stdin must not crash the script (best-effort JSON.parse fallback).
|
|
54
|
+
const outBadInput = execFileSync(process.execPath, [scriptPath], {
|
|
55
|
+
input: "not json", encoding: "utf8", timeout: 5000,
|
|
56
|
+
});
|
|
57
|
+
assert.ok(outBadInput.length > 0, "script still prints something on bad stdin");
|
|
58
|
+
} finally {
|
|
59
|
+
if (prevXdg === undefined) delete process.env.XDG_STATE_HOME;
|
|
60
|
+
else process.env.XDG_STATE_HOME = prevXdg;
|
|
61
|
+
fs.rmSync(tmpState, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log("statusline.test.js: all checks passed");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
main().catch((err) => {
|
|
68
|
+
console.error(err);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|