ctxmedic 0.5.1 → 0.7.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/dist/index.js
CHANGED
|
@@ -129,6 +129,19 @@ var FinOpsReport = z.object({
|
|
|
129
129
|
potentialMonthlySavingsUsd: z.number(),
|
|
130
130
|
pricingAsOf: z.string()
|
|
131
131
|
});
|
|
132
|
+
var GraphNode = z.object({
|
|
133
|
+
id: z.string(),
|
|
134
|
+
kind: z.union([FileRole, z.enum(["harness", "target"])]),
|
|
135
|
+
label: z.string(),
|
|
136
|
+
tokens: z.number().int().nonnegative().optional(),
|
|
137
|
+
broken: z.boolean().optional(),
|
|
138
|
+
/** Absent on harness nodes, which belong to neither scope. */
|
|
139
|
+
scope: z.enum(["project", "global"]).optional()
|
|
140
|
+
});
|
|
141
|
+
var ConfigGraph = z.object({
|
|
142
|
+
nodes: z.array(GraphNode),
|
|
143
|
+
edges: z.array(z.object({ source: z.string(), target: z.string(), kind: z.enum(["loads", "symlink", "duplicate"]) }))
|
|
144
|
+
});
|
|
132
145
|
|
|
133
146
|
// ../core/src/paths.ts
|
|
134
147
|
import os from "os";
|
|
@@ -1659,7 +1672,7 @@ var harnesses = [
|
|
|
1659
1672
|
];
|
|
1660
1673
|
|
|
1661
1674
|
// ../clinical/src/engine.ts
|
|
1662
|
-
var VERSION = true ? "0.
|
|
1675
|
+
var VERSION = true ? "0.7.0" : "0.0.0-dev";
|
|
1663
1676
|
var TRIAGE = { critical: "resuscitation", warning: "therapy", info: "preventive" };
|
|
1664
1677
|
var ORDER = ["resuscitation", "therapy", "preventive"];
|
|
1665
1678
|
var human = (k) => k.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase());
|
|
@@ -1909,6 +1922,81 @@ import path15 from "path";
|
|
|
1909
1922
|
import { serve } from "@hono/node-server";
|
|
1910
1923
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
1911
1924
|
import { Hono } from "hono";
|
|
1925
|
+
import { streamSSE } from "hono/streaming";
|
|
1926
|
+
function configWatcher(root) {
|
|
1927
|
+
const subs = /* @__PURE__ */ new Set();
|
|
1928
|
+
let watchers = [];
|
|
1929
|
+
let timer;
|
|
1930
|
+
let ready = Promise.resolve();
|
|
1931
|
+
const close = () => {
|
|
1932
|
+
for (const w of watchers) w.close();
|
|
1933
|
+
watchers = [];
|
|
1934
|
+
};
|
|
1935
|
+
const watch = async () => {
|
|
1936
|
+
const ex = await examine(root, harnesses);
|
|
1937
|
+
close();
|
|
1938
|
+
if (!subs.size) return;
|
|
1939
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
1940
|
+
for (const f of ex.files) {
|
|
1941
|
+
const dir = path15.dirname(f.path);
|
|
1942
|
+
if (dirs.get(dir) !== null) dirs.set(dir, (dirs.get(dir) ?? /* @__PURE__ */ new Set()).add(path15.basename(f.path)));
|
|
1943
|
+
if (f.role === "skill") dirs.set(path15.dirname(dir), null);
|
|
1944
|
+
}
|
|
1945
|
+
const sig = (p3, isDir) => {
|
|
1946
|
+
try {
|
|
1947
|
+
if (isDir) return fs10.readdirSync(p3).sort().join("/");
|
|
1948
|
+
const st = fs10.statSync(p3);
|
|
1949
|
+
return `${st.mtimeMs}:${st.size}`;
|
|
1950
|
+
} catch {
|
|
1951
|
+
return "gone";
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1955
|
+
for (const [dir, names] of dirs) {
|
|
1956
|
+
if (!names) seen.set(dir, sig(dir, true));
|
|
1957
|
+
else for (const n2 of names) seen.set(path15.join(dir, n2), sig(path15.join(dir, n2), false));
|
|
1958
|
+
}
|
|
1959
|
+
const onEvent = (dir, names, name) => {
|
|
1960
|
+
const p3 = names ? name && names.has(name) ? path15.join(dir, name) : null : dir;
|
|
1961
|
+
if (!p3) return;
|
|
1962
|
+
const now = sig(p3, !names);
|
|
1963
|
+
if (now === seen.get(p3)) return;
|
|
1964
|
+
seen.set(p3, now);
|
|
1965
|
+
changed();
|
|
1966
|
+
};
|
|
1967
|
+
for (const [dir, names] of dirs) {
|
|
1968
|
+
try {
|
|
1969
|
+
const w = fs10.watch(dir, (_, name) => onEvent(dir, names, name === null ? null : String(name)));
|
|
1970
|
+
w.unref();
|
|
1971
|
+
watchers.push(w);
|
|
1972
|
+
} catch {
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
};
|
|
1976
|
+
const changed = () => {
|
|
1977
|
+
clearTimeout(timer);
|
|
1978
|
+
timer = setTimeout(async () => {
|
|
1979
|
+
await (ready = watch());
|
|
1980
|
+
for (const s of subs) s();
|
|
1981
|
+
}, 300);
|
|
1982
|
+
};
|
|
1983
|
+
return {
|
|
1984
|
+
subscribe(fn) {
|
|
1985
|
+
subs.add(fn);
|
|
1986
|
+
if (subs.size === 1) ready = watch();
|
|
1987
|
+
return {
|
|
1988
|
+
ready,
|
|
1989
|
+
off: () => {
|
|
1990
|
+
subs.delete(fn);
|
|
1991
|
+
if (!subs.size) {
|
|
1992
|
+
clearTimeout(timer);
|
|
1993
|
+
close();
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
1912
2000
|
function createApp(opts) {
|
|
1913
2001
|
const app = new Hono();
|
|
1914
2002
|
const root = path15.resolve(opts.root);
|
|
@@ -1917,6 +2005,20 @@ function createApp(opts) {
|
|
|
1917
2005
|
if (c.req.method !== "GET" && c.req.header("x-ctxmedic-token") !== opts.token) return c.json({ error: "invalid session token" }, 403);
|
|
1918
2006
|
await next();
|
|
1919
2007
|
});
|
|
2008
|
+
const watcher = configWatcher(root);
|
|
2009
|
+
app.get(
|
|
2010
|
+
"/api/events",
|
|
2011
|
+
(c) => streamSSE(c, async (stream) => {
|
|
2012
|
+
const sub = watcher.subscribe(() => void stream.writeSSE({ event: "changed", data: "" }));
|
|
2013
|
+
stream.onAbort(sub.off);
|
|
2014
|
+
await sub.ready;
|
|
2015
|
+
await stream.writeSSE({ event: "ready", data: "" });
|
|
2016
|
+
while (!stream.aborted) {
|
|
2017
|
+
await stream.sleep(25e3);
|
|
2018
|
+
if (!stream.aborted) await stream.writeSSE({ event: "ping", data: "" });
|
|
2019
|
+
}
|
|
2020
|
+
})
|
|
2021
|
+
);
|
|
1920
2022
|
app.get("/api/checkup", async (c) => {
|
|
1921
2023
|
const lang = c.req.query("lang") ? resolveLang(c.req.query("lang")) : opts.lang;
|
|
1922
2024
|
return c.json(await checkup({ root, lang, days: opts.days, record: c.req.query("record") === "1" }));
|
|
@@ -1940,7 +2042,7 @@ function createApp(opts) {
|
|
|
1940
2042
|
for (let i = 0; i < docs.length; i++)
|
|
1941
2043
|
for (let j = i + 1; j < docs.length; j++)
|
|
1942
2044
|
if (similarity(docs[i].text, docs[j].text) > 0.75) edges.push({ source: docs[i].path, target: docs[j].path, kind: "duplicate" });
|
|
1943
|
-
return c.json({ nodes, edges });
|
|
2045
|
+
return c.json(ConfigGraph.parse({ nodes, edges }));
|
|
1944
2046
|
});
|
|
1945
2047
|
app.post("/api/treat/:rx", async (c) => {
|
|
1946
2048
|
const dryRun = c.req.query("dryRun") === "1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctxmedic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The context medic for your AI coding setup: checkup, treat, savings for Claude Code, Cursor, Windsurf, Codex CLI, OpenCode, Cline and Copilot.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-MIT",
|