@usableapp/cardds 0.7.79 → 0.7.80
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/bin/cardds.mjs +3 -2
- package/css/card.css +3 -0
- package/dist/actions/Btn.d.ts +2 -1
- package/dist/cardds.css +3 -0
- package/dist/cards/CardFoot.d.ts +2 -1
- package/dist/cards/CardFoot.js +2 -1
- package/dist/catalog.json +1 -1
- package/lib/mcp.mjs +26 -5
- package/package.json +4 -2
package/lib/mcp.mjs
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
// lib/mcp.mjs — `npx cardds mcp`: the catalog (lib/catalog.mjs) as an MCP server over stdio, so an AI session asks instead of reading src/.
|
|
2
2
|
// Newline-delimited JSON-RPC 2.0 written by hand: the package has no MCP SDK and takes none. stdout carries protocol messages ONLY.
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import * as catalog from './catalog.mjs';
|
|
8
8
|
import { GUIDE } from './guide.mjs';
|
|
9
9
|
|
|
10
10
|
const { version } = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'));
|
|
11
|
+
/* A server lives as long as its session — hours, across releases. What it serves must be the catalog as it is NOW (Lh 2026-10-10: a
|
|
12
|
+
session opened the day before did not know CardFeed): `keeper` asks `stamp` before every answer and loads again when it changed. */
|
|
13
|
+
const SOURCES = ['src', 'css', '.design-sync/previews', 'docs', 'lib', 'scripts'];
|
|
14
|
+
const newest = (path) => {
|
|
15
|
+
let st;
|
|
16
|
+
try { st = statSync(path); } catch { return 0; }
|
|
17
|
+
if (!st.isDirectory()) return st.mtimeMs;
|
|
18
|
+
return Math.max(0, ...readdirSync(path).map((name) => newest(join(path, name))));
|
|
19
|
+
};
|
|
20
|
+
/** what the catalog was made from: a live repo's sources (the newest change among them), or the package's own catalog file */
|
|
21
|
+
export const stampOf = (root) => root ? Math.max(...SOURCES.map((dir) => newest(join(root, dir)))) : newest(join(dirname(fileURLToPath(import.meta.url)), '..', 'dist', 'catalog.json'));
|
|
22
|
+
/** the catalog, loaded again whenever `stamp()` answers something new. A load that fails keeps the catalog it had (a source half-edited) and is tried again on the next ask */
|
|
23
|
+
export function keeper(load, stamp) {
|
|
24
|
+
let cat, at;
|
|
25
|
+
return () => {
|
|
26
|
+
const now = stamp();
|
|
27
|
+
if (cat !== undefined && now === at) return cat;
|
|
28
|
+
try { cat = load(); at = now; } catch (e) { if (cat === undefined) throw e; }
|
|
29
|
+
return cat;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
11
33
|
const str = (description) => ({ type: 'string', description });
|
|
12
34
|
const bool = (description) => ({ type: 'boolean', description });
|
|
13
35
|
|
|
@@ -60,12 +82,12 @@ const fail = (id, code, message) => ({ jsonrpc: '2.0', id, error: { code, messag
|
|
|
60
82
|
|
|
61
83
|
/** serve the catalog until the client closes stdin; `root` serves a live repo (rebuilt first) instead of the package's */
|
|
62
84
|
export function serve({ root, input = process.stdin, output = process.stdout } = {}) {
|
|
63
|
-
|
|
85
|
+
const current = keeper(() => catalog.load({ root }), () => stampOf(root));
|
|
64
86
|
const text = (r) => typeof r === 'string' ? r : JSON.stringify(r);
|
|
65
87
|
|
|
66
88
|
// the catalog, or nothing: listing the tools must not fail because it cannot be loaded (a call says why)
|
|
67
89
|
function loaded() {
|
|
68
|
-
try { return (
|
|
90
|
+
try { return current(); } catch { return undefined; }
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
function call(params) {
|
|
@@ -75,8 +97,7 @@ export function serve({ root, input = process.stdin, output = process.stdout } =
|
|
|
75
97
|
const missing = tool.inputSchema.required?.find((k) => typeof args[k] !== 'string');
|
|
76
98
|
if (missing) return { content: [{ type: 'text', text: `${tool.name}: "${missing}" is required (a string)` }], isError: true };
|
|
77
99
|
try {
|
|
78
|
-
|
|
79
|
-
const result = tool.run(cat, args);
|
|
100
|
+
const result = tool.run(current(), args);
|
|
80
101
|
return { content: [{ type: 'text', text: text(result) }], ...(result?.error && { isError: true }) };
|
|
81
102
|
} catch (e) { return { content: [{ type: 'text', text: `${tool.name}: ${e.message}` }], isError: true }; }
|
|
82
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usableapp/cardds",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.80",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "card-first mobile design system, React-first: the components in src/ are thin wrappers over the CSS contract (css/*.css stays the only truth); gallery/ shows every story live (npm run dev), tests/ measures the geometry.",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"build": "node scripts/build-icons.mjs && tsc -p tsconfig.json && node scripts/flatten-css.mjs && node scripts/build-catalog.mjs",
|
|
14
14
|
"test": "playwright test",
|
|
15
15
|
"validate:inbox": "node scripts/validate-inbox.mjs",
|
|
16
|
-
"
|
|
16
|
+
"release": "node scripts/publish.mjs",
|
|
17
|
+
"release:check": "node scripts/publish.mjs --check",
|
|
18
|
+
"ci": "node scripts/ci.mjs",
|
|
17
19
|
"prepack": "npm run build",
|
|
18
20
|
"knobs": "node scripts/knobs.mjs",
|
|
19
21
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p gallery/tsconfig.json --noEmit",
|