@krtclcdy/tersio 1.0.0 → 1.0.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krtclcdy/tersio",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Amanai reward detector and three toggleable OMP extensions for terse replies, compact shell output, and minimal code decisions — with a manual updater and dry-run support.",
5
5
  "keywords": [
6
6
  "omp",
@@ -109,6 +109,7 @@
109
109
  "scripts": {
110
110
  "clean": "rm -f tersio.js extensions/**/*.js",
111
111
  "build": "tsc",
112
+ "prepublishOnly": "npm run build",
112
113
  "check": "tsc --noEmit",
113
114
  "doctor": "node tersio.js --doctor",
114
115
  "dry-run": "node tersio.js --dry-run --scope user --yes",
package/tersio.js CHANGED
@@ -100,7 +100,9 @@ function debug(...a) {
100
100
  const RL = readline.createInterface({ input: process.stdin, output: process.stdout });
101
101
  let rlOpen = true;
102
102
  function ask(q) {
103
- return new Promise((res) => RL.question(q, (a) => { RL.close(); rlOpen = false; res(a); }));
103
+ const { promise, resolve } = Promise.withResolvers();
104
+ RL.question(q, resolve);
105
+ return promise;
104
106
  }
105
107
  function closeRL() { if (rlOpen) {
106
108
  RL.close();
@@ -1,72 +0,0 @@
1
- // Headroom proxy presence for the combo status bar.
2
- // Wrap-marker read is sync so paint stays cheap; proxy /health is probed async,
3
- // cached per port, and callers repaint when the probe settles.
4
- import { readFileSync } from "node:fs";
5
- import https from "node:https";
6
- import os from "node:os";
7
- import path from "node:path";
8
- export const HEADROOM_MARKER = "# managed by `headroom wrap omp`";
9
- const PROBE_TTL_MS = 60_000;
10
- function modelsPath() {
11
- const base = process.env.PI_CODING_AGENT_DIR?.trim();
12
- if (base)
13
- return path.join(path.resolve(base), "models.yml");
14
- return path.join(os.homedir(), ".omp", "agent", "models.yml");
15
- }
16
- export function readHeadroomWrap() {
17
- let raw;
18
- try {
19
- raw = readFileSync(modelsPath(), "utf8");
20
- }
21
- catch {
22
- return { wrapped: false, port: null };
23
- }
24
- if (!raw.includes(HEADROOM_MARKER))
25
- return { wrapped: false, port: null };
26
- const match = raw.match(/baseUrl:\s*https?:\/\/127\.0\.0\.1:(\d+)/);
27
- return { wrapped: true, port: match ? Number(match[1]) : null };
28
- }
29
- function probeProxy(port) {
30
- return new Promise((resolve) => {
31
- const req = https.get({ host: "127.0.0.1", port, path: "/health", timeout: 2000 }, (res) => {
32
- res.resume();
33
- resolve(res.statusCode !== undefined && res.statusCode < 500);
34
- });
35
- req.on("timeout", () => { req.destroy(); resolve(false); });
36
- req.on("error", () => resolve(false));
37
- });
38
- }
39
- let lastPort;
40
- let lastHealthy = true;
41
- let lastProbeAt = 0;
42
- let inflight = null;
43
- export function refreshHeadroomStatus() {
44
- if (inflight)
45
- return inflight;
46
- inflight = (async () => {
47
- const { wrapped, port } = readHeadroomWrap();
48
- if (!wrapped || port === null) {
49
- lastPort = port;
50
- lastHealthy = true;
51
- lastProbeAt = Date.now();
52
- return;
53
- }
54
- lastHealthy = await probeProxy(port);
55
- lastPort = port;
56
- lastProbeAt = Date.now();
57
- })();
58
- inflight.then(() => { inflight = null; }, () => { inflight = null; });
59
- return inflight;
60
- }
61
- export function getHeadroomStatus() {
62
- const { wrapped, port } = readHeadroomWrap();
63
- if (!wrapped)
64
- return "off";
65
- if (port !== null && port === lastPort && Date.now() - lastProbeAt < PROBE_TTL_MS) {
66
- return lastHealthy ? "on" : "stale";
67
- }
68
- // No fresh probe for this port: kick one off and assume on until a probe
69
- // says otherwise, so first paint never blocks on the network.
70
- void refreshHeadroomStatus();
71
- return port !== null && port === lastPort && !lastHealthy ? "stale" : "on";
72
- }