codestation-mcp 1.2.1 → 1.3.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/README.md +86 -59
- package/bin/codestation-mcp.mjs +1857 -899
- package/package.json +1 -1
package/bin/codestation-mcp.mjs
CHANGED
|
@@ -28,6 +28,7 @@ var PRO_TOOLS = /* @__PURE__ */ new Set([
|
|
|
28
28
|
"codestation_jwt_decode",
|
|
29
29
|
"codestation_format_sql",
|
|
30
30
|
"codestation_cron_explain",
|
|
31
|
+
"codestation_cron_next_runs",
|
|
31
32
|
"codestation_timezone_convert",
|
|
32
33
|
"codestation_business_days",
|
|
33
34
|
"codestation_regex_test",
|
|
@@ -1250,6 +1251,7 @@ function formatEnvAuditReport(result) {
|
|
|
1250
1251
|
// lib/tools/mock-data.ts
|
|
1251
1252
|
var Prng = class {
|
|
1252
1253
|
constructor(seed) {
|
|
1254
|
+
this.isDeterministic = seed !== void 0;
|
|
1253
1255
|
this.state = seed !== void 0 ? seed >>> 0 || 1 : Math.floor(Math.random() * 2147483647) || 1;
|
|
1254
1256
|
}
|
|
1255
1257
|
next() {
|
|
@@ -1501,7 +1503,8 @@ function generateValue(col, prng, rowIndex, usedUnique, context) {
|
|
|
1501
1503
|
break;
|
|
1502
1504
|
case "date": {
|
|
1503
1505
|
const pastDays = prng.int(1, 180);
|
|
1504
|
-
const
|
|
1506
|
+
const baseTime = prng.isDeterministic ? 17672256e5 : Date.now();
|
|
1507
|
+
const d = new Date(baseTime - pastDays * 864e5);
|
|
1505
1508
|
val = d.toISOString();
|
|
1506
1509
|
break;
|
|
1507
1510
|
}
|
|
@@ -1872,6 +1875,64 @@ function jsonToYaml(value) {
|
|
|
1872
1875
|
function yamlToJson(value) {
|
|
1873
1876
|
return JSON.stringify(parseYaml(value), null, 2);
|
|
1874
1877
|
}
|
|
1878
|
+
function csvEscape(value) {
|
|
1879
|
+
const text2 = value == null ? "" : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
1880
|
+
return /[",\n\r]/.test(text2) ? `"${text2.replace(/"/g, '""')}"` : text2;
|
|
1881
|
+
}
|
|
1882
|
+
function jsonToCsv(value) {
|
|
1883
|
+
const rows = JSON.parse(value);
|
|
1884
|
+
if (!Array.isArray(rows) || rows.some((row) => !row || typeof row !== "object" || Array.isArray(row))) throw new Error("Expected a JSON array of objects.");
|
|
1885
|
+
const keys = [...new Set(rows.flatMap((row) => Object.keys(row)))];
|
|
1886
|
+
return [keys.join(","), ...rows.map((row) => keys.map((key) => csvEscape(row[key])).join(","))].join("\n");
|
|
1887
|
+
}
|
|
1888
|
+
function csvToJson(value) {
|
|
1889
|
+
const rows = parseCsv(value);
|
|
1890
|
+
if (rows.length < 1 || rows[0].length === 0) throw new Error("Add a CSV header row before converting.");
|
|
1891
|
+
const headers = rows[0];
|
|
1892
|
+
return JSON.stringify(rows.slice(1).filter((row) => row.some(Boolean)).map((row) => Object.fromEntries(headers.map((header, index) => [header, row[index] ?? ""]))), null, 2);
|
|
1893
|
+
}
|
|
1894
|
+
function parseCsv(value) {
|
|
1895
|
+
const rows = [];
|
|
1896
|
+
let row = [];
|
|
1897
|
+
let cell = "";
|
|
1898
|
+
let quoted = false;
|
|
1899
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
1900
|
+
const char = value[i];
|
|
1901
|
+
if (char === '"' && quoted && value[i + 1] === '"') {
|
|
1902
|
+
cell += '"';
|
|
1903
|
+
i += 1;
|
|
1904
|
+
} else if (char === '"') quoted = !quoted;
|
|
1905
|
+
else if (char === "," && !quoted) {
|
|
1906
|
+
row.push(cell);
|
|
1907
|
+
cell = "";
|
|
1908
|
+
} else if ((char === "\n" || char === "\r") && !quoted) {
|
|
1909
|
+
if (char === "\r" && value[i + 1] === "\n") i += 1;
|
|
1910
|
+
row.push(cell);
|
|
1911
|
+
rows.push(row);
|
|
1912
|
+
row = [];
|
|
1913
|
+
cell = "";
|
|
1914
|
+
} else cell += char;
|
|
1915
|
+
}
|
|
1916
|
+
if (cell || row.length) {
|
|
1917
|
+
row.push(cell);
|
|
1918
|
+
rows.push(row);
|
|
1919
|
+
}
|
|
1920
|
+
if (quoted) throw new Error("CSV contains an unclosed quoted field.");
|
|
1921
|
+
return rows;
|
|
1922
|
+
}
|
|
1923
|
+
function jsonDiff(left, right) {
|
|
1924
|
+
const a = JSON.parse(left);
|
|
1925
|
+
const b = JSON.parse(right);
|
|
1926
|
+
return JSON.stringify(diffValue(a, b), null, 2);
|
|
1927
|
+
}
|
|
1928
|
+
function diffValue(a, b) {
|
|
1929
|
+
if (JSON.stringify(a) === JSON.stringify(b)) return { status: "unchanged", value: a };
|
|
1930
|
+
if (a && b && typeof a === "object" && typeof b === "object" && !Array.isArray(a) && !Array.isArray(b)) {
|
|
1931
|
+
const keys = [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].sort();
|
|
1932
|
+
return Object.fromEntries(keys.map((key) => [key, diffValue(a[key], b[key])]));
|
|
1933
|
+
}
|
|
1934
|
+
return { status: a === void 0 ? "added" : b === void 0 ? "removed" : "changed", before: a, after: b };
|
|
1935
|
+
}
|
|
1875
1936
|
function generateJsonSchema(value) {
|
|
1876
1937
|
const sample = JSON.parse(value);
|
|
1877
1938
|
const infer = (node) => {
|
|
@@ -1885,6 +1946,30 @@ function generateJsonSchema(value) {
|
|
|
1885
1946
|
};
|
|
1886
1947
|
return JSON.stringify({ $schema: "https://json-schema.org/draft/2020-12/schema", ...infer(sample) }, null, 2);
|
|
1887
1948
|
}
|
|
1949
|
+
function testJsonPath(value, expression) {
|
|
1950
|
+
const root = JSON.parse(value);
|
|
1951
|
+
const query = expression.trim();
|
|
1952
|
+
if (!query.startsWith("$")) throw new Error("JSONPath must start with $.");
|
|
1953
|
+
const tokens = query.slice(1).match(/(?:\.([A-Za-z_$][\w$-]*)|\[([0-9]+|\*)\])/g) ?? [];
|
|
1954
|
+
if (tokens.join("") !== query.slice(1)) throw new Error("Supported JSONPath syntax: $.property, $[0], and $[*].");
|
|
1955
|
+
let current = [root];
|
|
1956
|
+
for (const token of tokens) {
|
|
1957
|
+
const next = [];
|
|
1958
|
+
for (const item of current) {
|
|
1959
|
+
if (token.startsWith(".")) {
|
|
1960
|
+
const key = token.slice(1);
|
|
1961
|
+
if (item && typeof item === "object" && !Array.isArray(item) && key in item) next.push(item[key]);
|
|
1962
|
+
} else {
|
|
1963
|
+
const selector = token.slice(1, -1);
|
|
1964
|
+
if (!Array.isArray(item)) continue;
|
|
1965
|
+
if (selector === "*") next.push(...item);
|
|
1966
|
+
else if (item[Number(selector)] !== void 0) next.push(item[Number(selector)]);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
current = next;
|
|
1970
|
+
}
|
|
1971
|
+
return JSON.stringify({ expression: query, count: current.length, matches: current }, null, 2);
|
|
1972
|
+
}
|
|
1888
1973
|
function decodeBase64Url2(value) {
|
|
1889
1974
|
return decodeBase64(value.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - value.length % 4) % 4));
|
|
1890
1975
|
}
|
|
@@ -1897,6 +1982,14 @@ function decodeJwt(value) {
|
|
|
1897
1982
|
throw new Error("JWT header and payload must contain valid Base64URL-encoded JSON.");
|
|
1898
1983
|
}
|
|
1899
1984
|
}
|
|
1985
|
+
var htmlEntities = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
1986
|
+
function encodeHtml(value) {
|
|
1987
|
+
return value.replace(/[&<>"']/g, (character) => htmlEntities[character]);
|
|
1988
|
+
}
|
|
1989
|
+
function decodeHtml(value) {
|
|
1990
|
+
const named = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
1991
|
+
return value.replace(/&(#x[\da-f]+|#\d+|\w+);/gi, (_, entity) => entity.startsWith("#x") ? String.fromCodePoint(parseInt(entity.slice(2), 16)) : entity.startsWith("#") ? String.fromCodePoint(parseInt(entity.slice(1), 10)) : named[entity.toLowerCase()] ?? `&${entity};`);
|
|
1992
|
+
}
|
|
1900
1993
|
function testRegex(pattern, flags, text2) {
|
|
1901
1994
|
let regex;
|
|
1902
1995
|
try {
|
|
@@ -2071,6 +2164,250 @@ function crc32(input) {
|
|
|
2071
2164
|
}
|
|
2072
2165
|
return ((crc ^ 4294967295) >>> 0).toString(16).padStart(8, "0");
|
|
2073
2166
|
}
|
|
2167
|
+
function randomBytes(length) {
|
|
2168
|
+
if (!Number.isInteger(length) || length < 0 || length > 65536) throw new RangeError("Length must be an integer between 0 and 65536.");
|
|
2169
|
+
const crypto2 = requireCrypto();
|
|
2170
|
+
const result = new Uint8Array(length);
|
|
2171
|
+
for (let offset = 0; offset < length; offset += 65536) crypto2.getRandomValues(result.subarray(offset, Math.min(offset + 65536, length)));
|
|
2172
|
+
return result;
|
|
2173
|
+
}
|
|
2174
|
+
function secureRandomToken(length = 32, alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.") {
|
|
2175
|
+
if (!Number.isInteger(length) || length < 0 || !alphabet) throw new RangeError("Length must be non-negative and alphabet must not be empty.");
|
|
2176
|
+
return Array.from(randomBytes(length), (byte) => alphabet[byte % alphabet.length]).join("");
|
|
2177
|
+
}
|
|
2178
|
+
function ulid() {
|
|
2179
|
+
const alphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
2180
|
+
let time = Date.now();
|
|
2181
|
+
let result = "";
|
|
2182
|
+
for (let i = 9; i >= 0; i--) {
|
|
2183
|
+
result = alphabet[time % 32] + result;
|
|
2184
|
+
time = Math.floor(time / 32);
|
|
2185
|
+
}
|
|
2186
|
+
return result + secureRandomToken(16, alphabet);
|
|
2187
|
+
}
|
|
2188
|
+
function nanoid(length = 21) {
|
|
2189
|
+
return secureRandomToken(length, "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
// lib/tools/text-station.ts
|
|
2193
|
+
var MAX_TEXT_LENGTH = 1e6;
|
|
2194
|
+
var MAX_DIFF_LINES = 2e3;
|
|
2195
|
+
var MAX_DIFF_CELLS = 4e6;
|
|
2196
|
+
var LOREM_WORDS = [
|
|
2197
|
+
"lorem",
|
|
2198
|
+
"ipsum",
|
|
2199
|
+
"dolor",
|
|
2200
|
+
"sit",
|
|
2201
|
+
"amet",
|
|
2202
|
+
"consectetur",
|
|
2203
|
+
"adipiscing",
|
|
2204
|
+
"elit",
|
|
2205
|
+
"sed",
|
|
2206
|
+
"do",
|
|
2207
|
+
"eiusmod",
|
|
2208
|
+
"tempor",
|
|
2209
|
+
"incididunt",
|
|
2210
|
+
"ut",
|
|
2211
|
+
"labore",
|
|
2212
|
+
"et",
|
|
2213
|
+
"dolore",
|
|
2214
|
+
"magna",
|
|
2215
|
+
"aliqua",
|
|
2216
|
+
"enim",
|
|
2217
|
+
"ad",
|
|
2218
|
+
"minim",
|
|
2219
|
+
"veniam",
|
|
2220
|
+
"quis",
|
|
2221
|
+
"nostrud",
|
|
2222
|
+
"exercitation",
|
|
2223
|
+
"ullamco",
|
|
2224
|
+
"laboris",
|
|
2225
|
+
"nisi",
|
|
2226
|
+
"aliquip",
|
|
2227
|
+
"ex",
|
|
2228
|
+
"ea",
|
|
2229
|
+
"commodo",
|
|
2230
|
+
" consequat",
|
|
2231
|
+
"duis",
|
|
2232
|
+
"aute",
|
|
2233
|
+
"irure",
|
|
2234
|
+
"in",
|
|
2235
|
+
"reprehenderit",
|
|
2236
|
+
"voluptate",
|
|
2237
|
+
"velit",
|
|
2238
|
+
"esse",
|
|
2239
|
+
"cillum",
|
|
2240
|
+
"fugiat",
|
|
2241
|
+
"nulla",
|
|
2242
|
+
"pariatur",
|
|
2243
|
+
"excepteur",
|
|
2244
|
+
"sint",
|
|
2245
|
+
"occaecat",
|
|
2246
|
+
"cupidatat",
|
|
2247
|
+
"non",
|
|
2248
|
+
"proident",
|
|
2249
|
+
"sunt",
|
|
2250
|
+
"culpa",
|
|
2251
|
+
"qui",
|
|
2252
|
+
"officia",
|
|
2253
|
+
"deserunt",
|
|
2254
|
+
"mollit",
|
|
2255
|
+
"anim",
|
|
2256
|
+
"id",
|
|
2257
|
+
"est",
|
|
2258
|
+
"laborum"
|
|
2259
|
+
].map((word) => word.trim());
|
|
2260
|
+
function assertText(value, name = "text") {
|
|
2261
|
+
if (typeof value !== "string") throw new TypeError(`${name} must be a string.`);
|
|
2262
|
+
if (value.length > MAX_TEXT_LENGTH) throw new RangeError(`${name} must be at most ${MAX_TEXT_LENGTH.toLocaleString()} characters.`);
|
|
2263
|
+
return value;
|
|
2264
|
+
}
|
|
2265
|
+
function parseLines(value) {
|
|
2266
|
+
assertText(value);
|
|
2267
|
+
const firstCrLf = value.indexOf("\r\n");
|
|
2268
|
+
const firstLf = value.indexOf("\n");
|
|
2269
|
+
const firstCr = value.indexOf("\r");
|
|
2270
|
+
let ending = "\n";
|
|
2271
|
+
if (firstCrLf >= 0 && (firstLf < 0 || firstCrLf <= firstLf)) ending = "\r\n";
|
|
2272
|
+
else if (firstCr >= 0 && (firstLf < 0 || firstCr < firstLf)) ending = "\r";
|
|
2273
|
+
const normalized = value.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
2274
|
+
if (!normalized) return { lines: [], ending, trailingBreak: false };
|
|
2275
|
+
const trailingBreak = normalized.endsWith("\n");
|
|
2276
|
+
const body = trailingBreak ? normalized.slice(0, -1) : normalized;
|
|
2277
|
+
return { lines: body ? body.split("\n") : [""], ending, trailingBreak };
|
|
2278
|
+
}
|
|
2279
|
+
function firstCharacterUpper(value, locale) {
|
|
2280
|
+
const characters = Array.from(value);
|
|
2281
|
+
if (!characters.length) return value;
|
|
2282
|
+
return characters[0].toLocaleUpperCase(locale) + characters.slice(1).join("");
|
|
2283
|
+
}
|
|
2284
|
+
function wordsOf(value) {
|
|
2285
|
+
return value.replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu, "$1 $2").match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
2286
|
+
}
|
|
2287
|
+
function convertCase(value, style, options = {}) {
|
|
2288
|
+
assertText(value);
|
|
2289
|
+
const locale = options.locale;
|
|
2290
|
+
if (style === "upper") return value.toLocaleUpperCase(locale);
|
|
2291
|
+
if (style === "lower") return value.toLocaleLowerCase(locale);
|
|
2292
|
+
if (style === "title") {
|
|
2293
|
+
return value.toLocaleLowerCase(locale).replace(/(^|[\s\-_\/.])([\p{L}\p{N}])/gu, (_, separator, character) => `${separator}${character.toLocaleUpperCase(locale)}`);
|
|
2294
|
+
}
|
|
2295
|
+
if (style === "sentence") {
|
|
2296
|
+
const lower = value.toLocaleLowerCase(locale);
|
|
2297
|
+
return lower.replace(/(^|[.!?…。!?]\s+)(\s*)([\p{L}\p{N}])/gu, (_, boundary, whitespace, character) => `${boundary}${whitespace}${character.toLocaleUpperCase(locale)}`);
|
|
2298
|
+
}
|
|
2299
|
+
const words2 = wordsOf(value).map((word) => word.toLocaleLowerCase(locale));
|
|
2300
|
+
if (style === "camel") return words2.map((word, index) => index === 0 ? word : firstCharacterUpper(word, locale)).join("");
|
|
2301
|
+
if (style === "pascal") return words2.map((word) => firstCharacterUpper(word, locale)).join("");
|
|
2302
|
+
if (style === "snake") return words2.join("_");
|
|
2303
|
+
if (style === "kebab") return words2.join("-");
|
|
2304
|
+
if (style === "constant") return words2.map((word) => word.toLocaleUpperCase(locale)).join("_");
|
|
2305
|
+
throw new Error(`Unsupported case style: ${String(style)}.`);
|
|
2306
|
+
}
|
|
2307
|
+
function escapeRegex(value) {
|
|
2308
|
+
return value.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
|
|
2309
|
+
}
|
|
2310
|
+
function diffOperations(left, right) {
|
|
2311
|
+
if (left.length > MAX_DIFF_LINES || right.length > MAX_DIFF_LINES) throw new RangeError(`Text diff supports at most ${MAX_DIFF_LINES.toLocaleString()} lines per side.`);
|
|
2312
|
+
if (left.length * right.length > MAX_DIFF_CELLS) throw new RangeError("Text diff inputs are too large to compare safely; reduce the number of lines.");
|
|
2313
|
+
const table = Array.from({ length: left.length + 1 }, () => new Uint32Array(right.length + 1));
|
|
2314
|
+
for (let i2 = left.length - 1; i2 >= 0; i2 -= 1) {
|
|
2315
|
+
for (let j2 = right.length - 1; j2 >= 0; j2 -= 1) table[i2][j2] = left[i2] === right[j2] ? table[i2 + 1][j2 + 1] + 1 : Math.max(table[i2 + 1][j2], table[i2][j2 + 1]);
|
|
2316
|
+
}
|
|
2317
|
+
const operations = [];
|
|
2318
|
+
let i = 0;
|
|
2319
|
+
let j = 0;
|
|
2320
|
+
while (i < left.length && j < right.length) {
|
|
2321
|
+
if (left[i] === right[j]) {
|
|
2322
|
+
operations.push({ type: "equal", text: left[i] });
|
|
2323
|
+
i += 1;
|
|
2324
|
+
j += 1;
|
|
2325
|
+
} else if (table[i + 1][j] >= table[i][j + 1]) {
|
|
2326
|
+
operations.push({ type: "deletion", text: left[i] });
|
|
2327
|
+
i += 1;
|
|
2328
|
+
} else {
|
|
2329
|
+
operations.push({ type: "addition", text: right[j] });
|
|
2330
|
+
j += 1;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
while (i < left.length) operations.push({ type: "deletion", text: left[i++] });
|
|
2334
|
+
while (j < right.length) operations.push({ type: "addition", text: right[j++] });
|
|
2335
|
+
return operations;
|
|
2336
|
+
}
|
|
2337
|
+
function buildUnified(operations) {
|
|
2338
|
+
let oldLine = 1;
|
|
2339
|
+
let newLine = 1;
|
|
2340
|
+
let added = 0;
|
|
2341
|
+
let removed = 0;
|
|
2342
|
+
const lines = operations.map((operation) => {
|
|
2343
|
+
if (operation.type === "equal") return { type: "context", text: operation.text, oldLine: oldLine++, newLine: newLine++ };
|
|
2344
|
+
if (operation.type === "deletion") {
|
|
2345
|
+
removed += 1;
|
|
2346
|
+
return { type: "deletion", text: operation.text, oldLine: oldLine++, newLine: null };
|
|
2347
|
+
}
|
|
2348
|
+
added += 1;
|
|
2349
|
+
return { type: "addition", text: operation.text, oldLine: null, newLine: newLine++ };
|
|
2350
|
+
});
|
|
2351
|
+
const text2 = ["--- left", "+++ right", ...lines.map((line) => `${line.type === "context" ? " " : line.type === "deletion" ? "-" : "+"}${line.text}`)].join("\n");
|
|
2352
|
+
return { lines, text: text2, added, removed };
|
|
2353
|
+
}
|
|
2354
|
+
function buildSideBySide(operations) {
|
|
2355
|
+
const rows = [];
|
|
2356
|
+
let leftLine = 1;
|
|
2357
|
+
let rightLine = 1;
|
|
2358
|
+
for (let i = 0; i < operations.length; i += 1) {
|
|
2359
|
+
const operation = operations[i];
|
|
2360
|
+
if (operation.type === "equal") {
|
|
2361
|
+
rows.push({ type: "equal", left: { line: leftLine++, text: operation.text }, right: { line: rightLine++, text: operation.text } });
|
|
2362
|
+
continue;
|
|
2363
|
+
}
|
|
2364
|
+
const deleted = [];
|
|
2365
|
+
const added = [];
|
|
2366
|
+
while (i < operations.length && operations[i].type !== "equal") {
|
|
2367
|
+
if (operations[i].type === "deletion") deleted.push(operations[i].text);
|
|
2368
|
+
else added.push(operations[i].text);
|
|
2369
|
+
i += 1;
|
|
2370
|
+
}
|
|
2371
|
+
i -= 1;
|
|
2372
|
+
const width = Math.max(deleted.length, added.length);
|
|
2373
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
2374
|
+
const left = deleted[offset];
|
|
2375
|
+
const right = added[offset];
|
|
2376
|
+
rows.push({
|
|
2377
|
+
type: left !== void 0 && right !== void 0 ? "changed" : left !== void 0 ? "removed" : "added",
|
|
2378
|
+
left: left === void 0 ? null : { line: leftLine++, text: left },
|
|
2379
|
+
right: right === void 0 ? null : { line: rightLine++, text: right }
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
return rows;
|
|
2384
|
+
}
|
|
2385
|
+
function textDiff(left, right) {
|
|
2386
|
+
const leftParsed = parseLines(left);
|
|
2387
|
+
const rightParsed = parseLines(right);
|
|
2388
|
+
const operations = diffOperations(leftParsed.lines, rightParsed.lines);
|
|
2389
|
+
const unified = buildUnified(operations);
|
|
2390
|
+
const sideBySide = buildSideBySide(operations);
|
|
2391
|
+
return {
|
|
2392
|
+
changed: unified.added > 0 || unified.removed > 0,
|
|
2393
|
+
added: unified.added,
|
|
2394
|
+
removed: unified.removed,
|
|
2395
|
+
unified: unified.text,
|
|
2396
|
+
unifiedLines: unified.lines,
|
|
2397
|
+
sideBySide,
|
|
2398
|
+
unifiedData: unified.lines,
|
|
2399
|
+
sideBySideData: sideBySide
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
function diffText(left, right) {
|
|
2403
|
+
return textDiff(left, right).unified;
|
|
2404
|
+
}
|
|
2405
|
+
function slugify(value, separator = "-") {
|
|
2406
|
+
assertText(value);
|
|
2407
|
+
assertText(separator, "separator");
|
|
2408
|
+
if (!separator || separator.length > 16 || /[\p{L}\p{N}]/u.test(separator)) throw new Error("Slug separator must be 1\u201316 non-alphanumeric characters.");
|
|
2409
|
+
return value.normalize("NFKD").replace(/[\u0300-\u036f]/gu, "").toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, separator).replace(new RegExp(`(?:${escapeRegex(separator)})+`, "g"), separator).replace(new RegExp(`^${escapeRegex(separator)}|${escapeRegex(separator)}$`, "g"), "");
|
|
2410
|
+
}
|
|
2074
2411
|
|
|
2075
2412
|
// lib/tools/json-to-types.ts
|
|
2076
2413
|
function toPascalCase(str) {
|
|
@@ -2290,270 +2627,677 @@ export type ${typeName} = z.infer<typeof ${safeRootName}>;`;
|
|
|
2290
2627
|
return header + (schemaDeclarations ? `${schemaDeclarations}${typeExport}` : `export const ${safeRootName} = ${rootResult};${typeExport}`);
|
|
2291
2628
|
}
|
|
2292
2629
|
|
|
2293
|
-
// lib/tools/
|
|
2294
|
-
var
|
|
2295
|
-
var
|
|
2296
|
-
var
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
];
|
|
2304
|
-
function parseField(expression, spec) {
|
|
2305
|
-
const fail2 = (message) => {
|
|
2306
|
-
throw new Error(`${spec.label}: ${message}`);
|
|
2307
|
-
};
|
|
2308
|
-
if (expression.length > 128) fail2("field exceeds the 128-character limit.");
|
|
2309
|
-
if (!expression) fail2("field cannot be empty.");
|
|
2310
|
-
const endpoint = (text2) => {
|
|
2311
|
-
let value;
|
|
2312
|
-
if (/^\d+$/.test(text2)) value = Number(text2);
|
|
2313
|
-
else if (spec.name === "month" && MONTH_NAMES.includes(text2.toUpperCase())) value = MONTH_NAMES.indexOf(text2.toUpperCase()) + 1;
|
|
2314
|
-
else if (spec.name === "dayOfWeek" && WEEKDAY_NAMES.includes(text2.toUpperCase())) value = WEEKDAY_NAMES.indexOf(text2.toUpperCase());
|
|
2315
|
-
else return fail2("use integer values, permitted month/weekday names, *, ranges, lists or steps.");
|
|
2316
|
-
if (!Number.isSafeInteger(value) || value < spec.min || value > spec.max) fail2(`value must be between ${spec.min} and ${spec.max}.`);
|
|
2317
|
-
return value;
|
|
2318
|
-
};
|
|
2319
|
-
const selected = /* @__PURE__ */ new Set();
|
|
2320
|
-
for (const item of expression.split(",")) {
|
|
2321
|
-
if (!item) fail2("lists cannot contain empty items.");
|
|
2322
|
-
const pieces = item.split("/");
|
|
2323
|
-
if (pieces.length > 2 || !pieces[0]) fail2("malformed step notation.");
|
|
2324
|
-
let step = 1;
|
|
2325
|
-
if (pieces.length === 2) {
|
|
2326
|
-
if (!/^\d+$/.test(pieces[1])) fail2("step must be a positive integer.");
|
|
2327
|
-
step = Number(pieces[1]);
|
|
2328
|
-
if (!Number.isSafeInteger(step) || step < 1 || step > spec.max - spec.min + 1) fail2(`step must be between 1 and ${spec.max - spec.min + 1}.`);
|
|
2329
|
-
}
|
|
2330
|
-
const base = pieces[0];
|
|
2331
|
-
let first;
|
|
2332
|
-
let last;
|
|
2333
|
-
if (base === "*") {
|
|
2334
|
-
first = spec.min;
|
|
2335
|
-
last = spec.max;
|
|
2336
|
-
} else {
|
|
2337
|
-
const range = base.split("-");
|
|
2338
|
-
if (range.length > 2 || range.some((value) => !value)) fail2("malformed range; negative values are not supported.");
|
|
2339
|
-
first = endpoint(range[0]);
|
|
2340
|
-
last = range.length === 2 ? endpoint(range[1]) : pieces.length === 2 ? spec.max : first;
|
|
2341
|
-
if (last < first) fail2("descending or wrapping ranges are not supported.");
|
|
2342
|
-
}
|
|
2343
|
-
for (let value = first; value <= last; value += step) selected.add(spec.name === "dayOfWeek" && value === 7 ? 0 : value);
|
|
2344
|
-
}
|
|
2345
|
-
return { ...spec, expression, values: [...selected].sort((a, b) => a - b), wildcard: expression.startsWith("*") };
|
|
2630
|
+
// lib/tools/date-time-station.ts
|
|
2631
|
+
var SECOND = 1e3;
|
|
2632
|
+
var MINUTE = 60 * SECOND;
|
|
2633
|
+
var HOUR = 60 * MINUTE;
|
|
2634
|
+
var DAY = 24 * HOUR;
|
|
2635
|
+
var MIN_DATE = -621355968e5;
|
|
2636
|
+
var MAX_DATE = 253402300799999;
|
|
2637
|
+
function integer(value, name, min, max) {
|
|
2638
|
+
if (!Number.isInteger(value) || value < min || value > max) throw new RangeError(`${name} must be an integer between ${min} and ${max}.`);
|
|
2639
|
+
return value;
|
|
2346
2640
|
}
|
|
2347
|
-
function
|
|
2348
|
-
if (typeof
|
|
2349
|
-
|
|
2350
|
-
if (
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
if (expression.includes("@")) throw new Error("Cron macros are not supported; enter five Unix fields or six seconds-first fields.");
|
|
2354
|
-
const tokens = expression.trim().split(/\s+/);
|
|
2355
|
-
if (tokens.length !== 5 && tokens.length !== 6) throw new Error("Expected five Unix fields or six seconds-first fields; years, commands, comments and environment assignments are not supported.");
|
|
2356
|
-
const hasSeconds = tokens.length === 6;
|
|
2357
|
-
const fields = tokens.map((token, index) => parseField(token, SPECS[index + (hasSeconds ? 0 : 1)]));
|
|
2358
|
-
const second = hasSeconds ? fields[0] : parseField("0", SPECS[0]);
|
|
2359
|
-
const [minute, hour, dayOfMonth, month, dayOfWeek] = fields.slice(hasSeconds ? 1 : 0);
|
|
2360
|
-
return { expression, hasSeconds, fields, second, minute, hour, dayOfMonth, month, dayOfWeek, dayMode: dayOfMonth.wildcard || dayOfWeek.wildcard ? "and" : "or" };
|
|
2641
|
+
function inputText(value, name = "Date", max = 256) {
|
|
2642
|
+
if (typeof value !== "string") throw new TypeError(`${name} must be text.`);
|
|
2643
|
+
const text2 = value.trim();
|
|
2644
|
+
if (!text2) throw new Error(`${name} cannot be empty.`);
|
|
2645
|
+
if (text2.length > max) throw new RangeError(`${name} must be at most ${max} characters.`);
|
|
2646
|
+
return text2;
|
|
2361
2647
|
}
|
|
2362
|
-
function
|
|
2363
|
-
|
|
2364
|
-
const dom = cron.dayOfMonth.values.includes(day);
|
|
2365
|
-
const dow = cron.dayOfWeek.values.includes(new Date(Date.UTC(year, month - 1, day)).getUTCDay());
|
|
2366
|
-
return cron.dayMode === "and" ? dom && dow : dom || dow;
|
|
2648
|
+
function isGregorianLeapYear(year) {
|
|
2649
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
2367
2650
|
}
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
var FULL_MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
2371
|
-
var FULL_WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
2372
|
-
var pad = (value) => String(value).padStart(2, "0");
|
|
2373
|
-
function explainCron(cron) {
|
|
2374
|
-
let timing;
|
|
2375
|
-
if (cron.hour.values.length === 1 && cron.minute.values.length === 1 && cron.second.values.length === 1) {
|
|
2376
|
-
timing = `At ${pad(cron.hour.values[0])}:${pad(cron.minute.values[0])}${cron.hasSeconds ? `:${pad(cron.second.values[0])}` : ""}`;
|
|
2377
|
-
} else if (cron.hasSeconds && cron.hour.expression === "*" && cron.minute.expression === "*" && cron.second.expression === "*") timing = "Every second";
|
|
2378
|
-
else if (cron.hour.expression === "*" && cron.minute.expression === "*" && !cron.hasSeconds) timing = "Every minute (at second 0)";
|
|
2379
|
-
else if (cron.hour.expression === "*" && /^\*\/\d+$/.test(cron.minute.expression) && !cron.hasSeconds) timing = `Every ${Number(cron.minute.expression.slice(2))} minutes within each hour (at second 0)`;
|
|
2380
|
-
else if (cron.hour.expression === "*" && cron.minute.values.length === 1 && cron.second.values.length === 1) timing = `Every hour at minute ${cron.minute.values[0]}, second ${cron.second.values[0]}`;
|
|
2381
|
-
else timing = `${cron.hasSeconds ? "Seconds-first schedule" : "Unix schedule (at second 0)"}: hours ${cron.hour.expression === "*" ? "every hour" : cron.hour.values.map(pad).join(", ")}; minutes ${cron.minute.expression === "*" ? "every minute" : cron.minute.values.map(pad).join(", ")}${cron.hasSeconds ? `; seconds ${cron.second.expression === "*" ? "every second" : cron.second.values.map(pad).join(", ")}` : ""}`;
|
|
2382
|
-
const months = cron.month.values.length === 12 ? "" : `; in ${cron.month.values.map((value) => FULL_MONTHS[value - 1]).join(", ")}`;
|
|
2383
|
-
const dom = cron.dayOfMonth.values.length === 31 ? "every day of month" : `day of month ${cron.dayOfMonth.values.join(", ")}`;
|
|
2384
|
-
const dow = cron.dayOfWeek.values.length === 7 ? "every weekday (Sunday\u2013Saturday)" : cron.dayOfWeek.values.map((value) => FULL_WEEKDAYS[value]).join(", ");
|
|
2385
|
-
const days = cron.dayMode === "or" ? `when either ${dom} OR weekday ${dow} matches` : cron.dayOfMonth.values.length === 31 && cron.dayOfWeek.values.length === 7 ? "every day" : cron.dayOfMonth.values.length === 31 ? `on ${dow}` : cron.dayOfWeek.values.length === 7 ? `on ${dom}` : `when both ${dom} AND weekday ${dow} match`;
|
|
2386
|
-
return `${timing}; ${days}${months}.`;
|
|
2651
|
+
function daysInMonth(year, month) {
|
|
2652
|
+
return [31, isGregorianLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
2387
2653
|
}
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
);
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
if (
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2654
|
+
function validateParts(parts) {
|
|
2655
|
+
integer(parts.year, "Year", 1, 9999);
|
|
2656
|
+
integer(parts.month, "Month", 1, 12);
|
|
2657
|
+
integer(parts.day, "Day", 1, daysInMonth(parts.year, parts.month));
|
|
2658
|
+
integer(parts.hour, "Hour", 0, 23);
|
|
2659
|
+
integer(parts.minute, "Minute", 0, 59);
|
|
2660
|
+
integer(parts.second, "Second", 0, 59);
|
|
2661
|
+
integer(parts.millisecond, "Millisecond", 0, 999);
|
|
2662
|
+
}
|
|
2663
|
+
function utcMilliseconds(parts) {
|
|
2664
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
2665
|
+
date.setUTCFullYear(parts.year, parts.month - 1, parts.day);
|
|
2666
|
+
date.setUTCHours(parts.hour ?? 0, parts.minute ?? 0, parts.second ?? 0, parts.millisecond ?? 0);
|
|
2667
|
+
return date.getTime();
|
|
2668
|
+
}
|
|
2669
|
+
function checkedDate(milliseconds) {
|
|
2670
|
+
if (!Number.isFinite(milliseconds)) throw new RangeError("Date or timestamp must be finite and valid.");
|
|
2671
|
+
if (milliseconds < MIN_DATE || milliseconds > MAX_DATE) throw new RangeError("Date must be within Gregorian years 0001\u20139999 in UTC.");
|
|
2672
|
+
return new Date(milliseconds);
|
|
2673
|
+
}
|
|
2674
|
+
function timestampUnit(unit) {
|
|
2675
|
+
if (unit !== "seconds" && unit !== "milliseconds") throw new Error("Timestamp unit must be seconds or milliseconds.");
|
|
2676
|
+
return unit;
|
|
2677
|
+
}
|
|
2678
|
+
function timestampToDate(value, unit = "seconds") {
|
|
2679
|
+
timestampUnit(unit);
|
|
2680
|
+
let number;
|
|
2681
|
+
if (typeof value === "string") {
|
|
2682
|
+
const text2 = inputText(value, "Timestamp");
|
|
2683
|
+
if (!/^[+-]?\d+(?:\.\d+)?$/.test(text2)) throw new Error("Timestamp must be a decimal number, without exponent notation.");
|
|
2684
|
+
number = Number(text2);
|
|
2685
|
+
} else if (typeof value === "number") number = value;
|
|
2686
|
+
else throw new TypeError("Timestamp must be a number or numeric text.");
|
|
2687
|
+
if (!Number.isFinite(number)) throw new RangeError("Timestamp must be finite.");
|
|
2688
|
+
if (unit === "milliseconds" && !Number.isInteger(number)) throw new RangeError("A millisecond timestamp must be an integer.");
|
|
2689
|
+
return checkedDate(unit === "seconds" ? Math.round(number * SECOND) : number);
|
|
2690
|
+
}
|
|
2691
|
+
function zoneFormatter(timeZone) {
|
|
2692
|
+
const zone = inputText(timeZone, "Time zone", 128);
|
|
2693
|
+
if (/^[+-]/.test(zone)) throw new Error("Use an IANA time zone such as America/New_York, Asia/Kolkata, or UTC.");
|
|
2694
|
+
try {
|
|
2695
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
2696
|
+
timeZone: zone,
|
|
2697
|
+
calendar: "gregory",
|
|
2698
|
+
numberingSystem: "latn",
|
|
2699
|
+
era: "short",
|
|
2700
|
+
year: "numeric",
|
|
2701
|
+
month: "2-digit",
|
|
2702
|
+
day: "2-digit",
|
|
2703
|
+
hour: "2-digit",
|
|
2704
|
+
minute: "2-digit",
|
|
2705
|
+
second: "2-digit",
|
|
2706
|
+
hourCycle: "h23"
|
|
2707
|
+
});
|
|
2708
|
+
} catch {
|
|
2709
|
+
throw new Error(`Unknown or unsupported IANA time zone: ${zone}.`);
|
|
2414
2710
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2711
|
+
}
|
|
2712
|
+
function validateTimeZone(timeZone) {
|
|
2713
|
+
return zoneFormatter(timeZone).resolvedOptions().timeZone;
|
|
2714
|
+
}
|
|
2715
|
+
function zoneParts(milliseconds, formatter) {
|
|
2716
|
+
const fields = Object.fromEntries(formatter.formatToParts(new Date(milliseconds)).map((part) => [part.type, part.value]));
|
|
2717
|
+
return {
|
|
2718
|
+
year: fields.era === "BC" ? 1 - Number(fields.year) : Number(fields.year),
|
|
2719
|
+
month: Number(fields.month),
|
|
2720
|
+
day: Number(fields.day),
|
|
2721
|
+
hour: Number(fields.hour),
|
|
2722
|
+
minute: Number(fields.minute),
|
|
2723
|
+
second: Number(fields.second),
|
|
2724
|
+
millisecond: (milliseconds % SECOND + SECOND) % SECOND
|
|
2725
|
+
};
|
|
2726
|
+
}
|
|
2727
|
+
function disambiguation(value = "reject") {
|
|
2728
|
+
if (!["reject", "earlier", "later"].includes(value)) throw new Error("Time disambiguation must be reject, earlier, or later.");
|
|
2729
|
+
return value;
|
|
2730
|
+
}
|
|
2731
|
+
function sameParts(left, right) {
|
|
2732
|
+
return left.year === right.year && left.month === right.month && left.day === right.day && left.hour === right.hour && left.minute === right.minute && left.second === right.second && left.millisecond === right.millisecond;
|
|
2733
|
+
}
|
|
2734
|
+
function localToDate(parts, formatter, choice) {
|
|
2735
|
+
const wall = utcMilliseconds(parts);
|
|
2736
|
+
const offsets = /* @__PURE__ */ new Set();
|
|
2737
|
+
for (let hours = -48; hours <= 48; hours += 12) {
|
|
2738
|
+
const sample = wall + hours * HOUR;
|
|
2739
|
+
offsets.add(utcMilliseconds(zoneParts(sample, formatter)) - sample);
|
|
2425
2740
|
}
|
|
2426
|
-
|
|
2741
|
+
const matches = [...offsets].map((offset) => wall - offset).filter((candidate) => sameParts(zoneParts(candidate, formatter), parts)).sort((a, b) => a - b);
|
|
2742
|
+
const zone = formatter.resolvedOptions().timeZone;
|
|
2743
|
+
if (!matches.length) throw new Error(`This local time does not exist in ${zone} because of a time-zone clock change. Choose another time or an explicit UTC offset.`);
|
|
2744
|
+
if (matches.length > 1 && choice === "reject") throw new Error(`This local time occurs twice in ${zone}. Choose earlier or later, or supply an explicit UTC offset.`);
|
|
2745
|
+
return checkedDate(choice === "later" ? matches[matches.length - 1] : matches[0]);
|
|
2427
2746
|
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
{
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2747
|
+
function offsetMilliseconds(value) {
|
|
2748
|
+
if (/^z$/i.test(value)) return 0;
|
|
2749
|
+
const match = /^([+-])(\d{2}):?(\d{2})$/.exec(value);
|
|
2750
|
+
if (!match) throw new Error("UTC offset must be Z or \xB1HH:mm.");
|
|
2751
|
+
const hours = integer(Number(match[2]), "Offset hour", 0, 23);
|
|
2752
|
+
const minutes = integer(Number(match[3]), "Offset minute", 0, 59);
|
|
2753
|
+
if (match[1] === "-" && hours === 0 && minutes === 0) throw new Error("The unknown UTC offset -00:00 cannot identify an instant. Use Z or a known offset.");
|
|
2754
|
+
return (match[1] === "-" ? -1 : 1) * (hours * HOUR + minutes * MINUTE);
|
|
2755
|
+
}
|
|
2756
|
+
function partsToDate(parts, offset, options) {
|
|
2757
|
+
validateParts(parts);
|
|
2758
|
+
const choice = disambiguation(options.disambiguation);
|
|
2759
|
+
const formatter = zoneFormatter(options.timeZone ?? "UTC");
|
|
2760
|
+
return offset ? checkedDate(utcMilliseconds(parts) - offsetMilliseconds(offset)) : localToDate(parts, formatter, choice);
|
|
2761
|
+
}
|
|
2762
|
+
function parseDateTime(value, options = {}) {
|
|
2763
|
+
timestampUnit(options.timestampUnit ?? "milliseconds");
|
|
2764
|
+
disambiguation(options.disambiguation);
|
|
2765
|
+
if (options.timeZone !== void 0) validateTimeZone(options.timeZone);
|
|
2766
|
+
if (value instanceof Date) return checkedDate(value.getTime());
|
|
2767
|
+
if (typeof value === "number") return timestampToDate(value, options.timestampUnit ?? "milliseconds");
|
|
2768
|
+
const text2 = inputText(value);
|
|
2769
|
+
if (/^[+-]?\d+(?:\.\d+)?$/.test(text2)) return timestampToDate(text2, options.timestampUnit ?? "milliseconds");
|
|
2770
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})(?:[Tt ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?([Zz]|[+-]\d{2}:?\d{2})?)?$/.exec(text2);
|
|
2771
|
+
if (!match) throw new Error("Use YYYY-MM-DD, an ISO date/time with up to 3 fractional digits, or an explicit numeric timestamp.");
|
|
2772
|
+
return partsToDate({
|
|
2773
|
+
year: Number(match[1]),
|
|
2774
|
+
month: Number(match[2]),
|
|
2775
|
+
day: Number(match[3]),
|
|
2776
|
+
hour: Number(match[4] ?? 0),
|
|
2777
|
+
minute: Number(match[5] ?? 0),
|
|
2778
|
+
second: Number(match[6] ?? 0),
|
|
2779
|
+
millisecond: Number((match[7] ?? "").padEnd(3, "0"))
|
|
2780
|
+
}, match[8], options);
|
|
2781
|
+
}
|
|
2782
|
+
function pad(value, length = 2) {
|
|
2783
|
+
return String(value).padStart(length, "0");
|
|
2784
|
+
}
|
|
2785
|
+
function calendarText(parts) {
|
|
2786
|
+
return `${pad(parts.year, 4)}-${pad(parts.month)}-${pad(parts.day)}`;
|
|
2787
|
+
}
|
|
2788
|
+
function clockText(parts) {
|
|
2789
|
+
return `${pad(parts.hour)}:${pad(parts.minute)}:${pad(parts.second)}.${pad(parts.millisecond, 3)}`;
|
|
2790
|
+
}
|
|
2791
|
+
function offsetText(milliseconds) {
|
|
2792
|
+
if (!milliseconds) return "Z";
|
|
2793
|
+
const seconds = Math.abs(milliseconds) / SECOND;
|
|
2794
|
+
const hours = Math.floor(seconds / 3600);
|
|
2795
|
+
const minutes = Math.floor(seconds % 3600 / 60);
|
|
2796
|
+
const remainder = seconds % 60;
|
|
2797
|
+
return `${milliseconds < 0 ? "-" : "+"}${pad(hours)}:${pad(minutes)}${remainder ? `:${pad(remainder)}` : ""}`;
|
|
2798
|
+
}
|
|
2799
|
+
function getZonedDateTime(value, timeZone = "UTC", options = {}) {
|
|
2800
|
+
const date = parseDateTime(value, options);
|
|
2801
|
+
const formatter = zoneFormatter(timeZone);
|
|
2802
|
+
const parts = zoneParts(date.getTime(), formatter);
|
|
2803
|
+
validateParts(parts);
|
|
2804
|
+
const offset = utcMilliseconds(parts) - date.getTime();
|
|
2805
|
+
const renderedOffset = offsetText(offset);
|
|
2806
|
+
return {
|
|
2807
|
+
...parts,
|
|
2808
|
+
timeZone: formatter.resolvedOptions().timeZone,
|
|
2809
|
+
offsetMinutes: offset / MINUTE,
|
|
2810
|
+
offset: renderedOffset,
|
|
2811
|
+
unixMilliseconds: date.getTime(),
|
|
2812
|
+
iso: date.toISOString(),
|
|
2813
|
+
dateTime: `${calendarText(parts)}T${clockText(parts)}${renderedOffset}`
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
function formatRfc3339(value, timeZoneOrOptions = "UTC", options = {}) {
|
|
2817
|
+
const timeZone = typeof timeZoneOrOptions === "string" ? timeZoneOrOptions : timeZoneOrOptions.timeZone ?? "UTC";
|
|
2818
|
+
const parseOptions = typeof timeZoneOrOptions === "string" ? options : timeZoneOrOptions;
|
|
2819
|
+
const zoned = getZonedDateTime(value, timeZone, parseOptions);
|
|
2820
|
+
if (!Number.isInteger(zoned.offsetMinutes)) throw new Error("RFC3339 cannot represent this historical sub-minute UTC offset. Format in UTC instead.");
|
|
2821
|
+
return zoned.dateTime;
|
|
2822
|
+
}
|
|
2823
|
+
function convertTimeZone(value, targetTimeZone, options = {}) {
|
|
2824
|
+
const parseOptions = typeof options === "string" ? { timeZone: options } : options;
|
|
2825
|
+
return formatRfc3339(value, targetTimeZone, parseOptions);
|
|
2826
|
+
}
|
|
2827
|
+
function convertBetweenTimeZones(value, sourceTimeZone, targetTimeZone) {
|
|
2828
|
+
return convertTimeZone(value, targetTimeZone, { timeZone: sourceTimeZone });
|
|
2829
|
+
}
|
|
2830
|
+
var relativeUnits = [
|
|
2831
|
+
{ unit: "year", milliseconds: 365 * DAY },
|
|
2832
|
+
{ unit: "quarter", milliseconds: 91 * DAY },
|
|
2833
|
+
{ unit: "month", milliseconds: 30 * DAY },
|
|
2834
|
+
{ unit: "week", milliseconds: 7 * DAY },
|
|
2835
|
+
{ unit: "day", milliseconds: DAY },
|
|
2836
|
+
{ unit: "hour", milliseconds: HOUR },
|
|
2837
|
+
{ unit: "minute", milliseconds: MINUTE },
|
|
2838
|
+
{ unit: "second", milliseconds: SECOND }
|
|
2839
|
+
];
|
|
2840
|
+
function calendarCompare(left, right) {
|
|
2841
|
+
return utcMilliseconds(left) - utcMilliseconds(right);
|
|
2842
|
+
}
|
|
2843
|
+
function calendarDayNumber(date) {
|
|
2844
|
+
return Math.floor(utcMilliseconds(date) / DAY);
|
|
2845
|
+
}
|
|
2846
|
+
function calendarFromDayNumber(day) {
|
|
2847
|
+
const date = new Date(day * DAY);
|
|
2848
|
+
return { year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() };
|
|
2849
|
+
}
|
|
2850
|
+
function calendarWeekday(date) {
|
|
2851
|
+
return new Date(utcMilliseconds(date)).getUTCDay();
|
|
2852
|
+
}
|
|
2853
|
+
function dateCalendar(value, options) {
|
|
2854
|
+
const zoned = getZonedDateTime(value, options.timeZone ?? "UTC", { timeZone: options.timeZone ?? "UTC" });
|
|
2855
|
+
return { year: zoned.year, month: zoned.month, day: zoned.day };
|
|
2856
|
+
}
|
|
2857
|
+
function weekdaysInclusive(start, end) {
|
|
2858
|
+
if (calendarCompare(start, end) > 0) return -weekdaysInclusive(end, start);
|
|
2859
|
+
const first = calendarDayNumber(start);
|
|
2860
|
+
const total = calendarDayNumber(end) - first + 1;
|
|
2861
|
+
const weeks = Math.floor(total / 7);
|
|
2862
|
+
let count = weeks * 5;
|
|
2863
|
+
for (let day = first + weeks * 7; day <= calendarDayNumber(end); day += 1) {
|
|
2864
|
+
const weekday = new Date(day * DAY).getUTCDay();
|
|
2865
|
+
if (weekday !== 0 && weekday !== 6) count += 1;
|
|
2866
|
+
}
|
|
2867
|
+
return count;
|
|
2868
|
+
}
|
|
2869
|
+
function businessDaysBetween(start, end, options = {}) {
|
|
2870
|
+
const left = dateCalendar(start, options);
|
|
2871
|
+
const right = dateCalendar(end, options);
|
|
2872
|
+
if (calendarCompare(left, right) === 0) return (options.inclusiveStart ?? true) && (options.inclusiveEnd ?? false) && calendarWeekday(left) !== 0 && calendarWeekday(left) !== 6 ? 1 : 0;
|
|
2873
|
+
const direction = calendarCompare(left, right) < 0 ? 1 : -1;
|
|
2874
|
+
const earlier = direction > 0 ? left : right;
|
|
2875
|
+
const later = direction > 0 ? right : left;
|
|
2876
|
+
let first = calendarDayNumber(earlier);
|
|
2877
|
+
let last = calendarDayNumber(later);
|
|
2878
|
+
const includeEarlier = direction > 0 ? options.inclusiveStart ?? true : options.inclusiveEnd ?? false;
|
|
2879
|
+
const includeLater = direction > 0 ? options.inclusiveEnd ?? false : options.inclusiveStart ?? true;
|
|
2880
|
+
if (!includeEarlier) first += 1;
|
|
2881
|
+
if (!includeLater) last -= 1;
|
|
2882
|
+
if (first > last) return 0;
|
|
2883
|
+
return direction * weekdaysInclusive(calendarFromDayNumber(first), calendarFromDayNumber(last));
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
// lib/tools/cron/parser.ts
|
|
2887
|
+
var MONTH_NAMES = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
|
|
2888
|
+
var WEEKDAY_NAMES = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
2889
|
+
var SPECS = [
|
|
2890
|
+
{ name: "second", label: "Second", min: 0, max: 59 },
|
|
2891
|
+
{ name: "minute", label: "Minute", min: 0, max: 59 },
|
|
2892
|
+
{ name: "hour", label: "Hour", min: 0, max: 23 },
|
|
2893
|
+
{ name: "dayOfMonth", label: "Day of month", min: 1, max: 31 },
|
|
2894
|
+
{ name: "month", label: "Month", min: 1, max: 12 },
|
|
2895
|
+
{ name: "dayOfWeek", label: "Day of week", min: 0, max: 7 }
|
|
2896
|
+
];
|
|
2897
|
+
function parseField(expression, spec) {
|
|
2898
|
+
const fail2 = (message) => {
|
|
2899
|
+
throw new Error(`${spec.label}: ${message}`);
|
|
2900
|
+
};
|
|
2901
|
+
if (expression.length > 128) fail2("field exceeds the 128-character limit.");
|
|
2902
|
+
if (!expression) fail2("field cannot be empty.");
|
|
2903
|
+
const endpoint = (text2) => {
|
|
2904
|
+
let value;
|
|
2905
|
+
if (/^\d+$/.test(text2)) value = Number(text2);
|
|
2906
|
+
else if (spec.name === "month" && MONTH_NAMES.includes(text2.toUpperCase())) value = MONTH_NAMES.indexOf(text2.toUpperCase()) + 1;
|
|
2907
|
+
else if (spec.name === "dayOfWeek" && WEEKDAY_NAMES.includes(text2.toUpperCase())) value = WEEKDAY_NAMES.indexOf(text2.toUpperCase());
|
|
2908
|
+
else return fail2("use integer values, permitted month/weekday names, *, ranges, lists or steps.");
|
|
2909
|
+
if (!Number.isSafeInteger(value) || value < spec.min || value > spec.max) fail2(`value must be between ${spec.min} and ${spec.max}.`);
|
|
2910
|
+
return value;
|
|
2911
|
+
};
|
|
2912
|
+
const selected = /* @__PURE__ */ new Set();
|
|
2913
|
+
for (const item of expression.split(",")) {
|
|
2914
|
+
if (!item) fail2("lists cannot contain empty items.");
|
|
2915
|
+
const pieces = item.split("/");
|
|
2916
|
+
if (pieces.length > 2 || !pieces[0]) fail2("malformed step notation.");
|
|
2917
|
+
let step = 1;
|
|
2918
|
+
if (pieces.length === 2) {
|
|
2919
|
+
if (!/^\d+$/.test(pieces[1])) fail2("step must be a positive integer.");
|
|
2920
|
+
step = Number(pieces[1]);
|
|
2921
|
+
if (!Number.isSafeInteger(step) || step < 1 || step > spec.max - spec.min + 1) fail2(`step must be between 1 and ${spec.max - spec.min + 1}.`);
|
|
2481
2922
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
type: "object",
|
|
2495
|
-
properties: {
|
|
2496
|
-
env: { type: "string", description: "Content of environment or configuration file" },
|
|
2497
|
-
example: { type: "string", description: "Optional content of .env.example to compare against" },
|
|
2498
|
-
format: { type: "string", enum: ["report", "json"], default: "report" }
|
|
2499
|
-
},
|
|
2500
|
-
required: ["env"]
|
|
2501
|
-
},
|
|
2502
|
-
outputSchema: {
|
|
2503
|
-
type: "object",
|
|
2504
|
-
properties: {
|
|
2505
|
-
totalVariables: { type: "integer" },
|
|
2506
|
-
findings: { type: "array" },
|
|
2507
|
-
isSecure: { type: "boolean" },
|
|
2508
|
-
summary: { type: "string" }
|
|
2509
|
-
}
|
|
2510
|
-
},
|
|
2511
|
-
cliMetadata: {
|
|
2512
|
-
command: "env-audit",
|
|
2513
|
-
aliases: ["env", "audit-env"],
|
|
2514
|
-
description: "Scan .env files for leaked secrets and diff against .env.example",
|
|
2515
|
-
examples: [
|
|
2516
|
-
"codestation env-audit .env --example .env.example",
|
|
2517
|
-
"codestation env .env --json"
|
|
2518
|
-
]
|
|
2519
|
-
},
|
|
2520
|
-
mcpMetadata: {
|
|
2521
|
-
toolName: "codestation_env_audit",
|
|
2522
|
-
description: "Scan environment variables for secret leaks and validate against .env.example. [Pro Tier]"
|
|
2523
|
-
},
|
|
2524
|
-
routeMetadata: {
|
|
2525
|
-
route: "/tools/env-audit",
|
|
2526
|
-
slug: "env-audit"
|
|
2527
|
-
},
|
|
2528
|
-
execute: async (input) => {
|
|
2529
|
-
const res = auditEnv(input.env, input.example);
|
|
2530
|
-
if (input.format === "json") return res;
|
|
2531
|
-
return { report: formatEnvAuditReport(res), ...res };
|
|
2923
|
+
const base = pieces[0];
|
|
2924
|
+
let first;
|
|
2925
|
+
let last;
|
|
2926
|
+
if (base === "*") {
|
|
2927
|
+
first = spec.min;
|
|
2928
|
+
last = spec.max;
|
|
2929
|
+
} else {
|
|
2930
|
+
const range = base.split("-");
|
|
2931
|
+
if (range.length > 2 || range.some((value) => !value)) fail2("malformed range; negative values are not supported.");
|
|
2932
|
+
first = endpoint(range[0]);
|
|
2933
|
+
last = range.length === 2 ? endpoint(range[1]) : pieces.length === 2 ? spec.max : first;
|
|
2934
|
+
if (last < first) fail2("descending or wrapping ranges are not supported.");
|
|
2532
2935
|
}
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
{
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2936
|
+
for (let value = first; value <= last; value += step) selected.add(spec.name === "dayOfWeek" && value === 7 ? 0 : value);
|
|
2937
|
+
}
|
|
2938
|
+
return { ...spec, expression, values: [...selected].sort((a, b) => a - b), wildcard: expression.startsWith("*") };
|
|
2939
|
+
}
|
|
2940
|
+
function parseCron(expression) {
|
|
2941
|
+
if (typeof expression !== "string" || !expression.trim()) throw new Error("Enter a cron expression.");
|
|
2942
|
+
if (expression.length > 1024) throw new Error("Cron expression exceeds the 1,024-character limit.");
|
|
2943
|
+
if (/[?#]/.test(expression) || /(?:^|[\s,/-])(?:L|LW|\d+[LW]|W|H(?:\([^)]*\))?)(?=$|[\s,/-])/i.test(expression) || /\b(?:cron|rate)\s*\(/i.test(expression)) {
|
|
2944
|
+
throw new Error("Quartz, AWS and Jenkins extensions (?, L, W, # and H) are not supported; use Unix numeric cron notation.");
|
|
2945
|
+
}
|
|
2946
|
+
if (expression.includes("@")) throw new Error("Cron macros are not supported; enter five Unix fields or six seconds-first fields.");
|
|
2947
|
+
const tokens = expression.trim().split(/\s+/);
|
|
2948
|
+
if (tokens.length !== 5 && tokens.length !== 6) throw new Error("Expected five Unix fields or six seconds-first fields; years, commands, comments and environment assignments are not supported.");
|
|
2949
|
+
const hasSeconds = tokens.length === 6;
|
|
2950
|
+
const fields = tokens.map((token, index) => parseField(token, SPECS[index + (hasSeconds ? 0 : 1)]));
|
|
2951
|
+
const second = hasSeconds ? fields[0] : parseField("0", SPECS[0]);
|
|
2952
|
+
const [minute, hour, dayOfMonth, month, dayOfWeek] = fields.slice(hasSeconds ? 1 : 0);
|
|
2953
|
+
return { expression, hasSeconds, fields, second, minute, hour, dayOfMonth, month, dayOfWeek, dayMode: dayOfMonth.wildcard || dayOfWeek.wildcard ? "and" : "or" };
|
|
2954
|
+
}
|
|
2955
|
+
function matchesCronDate(cron, year, month, day) {
|
|
2956
|
+
if (!cron.month.values.includes(month)) return false;
|
|
2957
|
+
const dom = cron.dayOfMonth.values.includes(day);
|
|
2958
|
+
const dow = cron.dayOfWeek.values.includes(new Date(Date.UTC(year, month - 1, day)).getUTCDay());
|
|
2959
|
+
return cron.dayMode === "and" ? dom && dow : dom || dow;
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
// lib/tools/cron/explain.ts
|
|
2963
|
+
var FULL_MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
2964
|
+
var FULL_WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
2965
|
+
var pad2 = (value) => String(value).padStart(2, "0");
|
|
2966
|
+
function explainCron(cron) {
|
|
2967
|
+
let timing;
|
|
2968
|
+
if (cron.hour.values.length === 1 && cron.minute.values.length === 1 && cron.second.values.length === 1) {
|
|
2969
|
+
timing = `At ${pad2(cron.hour.values[0])}:${pad2(cron.minute.values[0])}${cron.hasSeconds ? `:${pad2(cron.second.values[0])}` : ""}`;
|
|
2970
|
+
} else if (cron.hasSeconds && cron.hour.expression === "*" && cron.minute.expression === "*" && cron.second.expression === "*") timing = "Every second";
|
|
2971
|
+
else if (cron.hour.expression === "*" && cron.minute.expression === "*" && !cron.hasSeconds) timing = "Every minute (at second 0)";
|
|
2972
|
+
else if (cron.hour.expression === "*" && /^\*\/\d+$/.test(cron.minute.expression) && !cron.hasSeconds) timing = `Every ${Number(cron.minute.expression.slice(2))} minutes within each hour (at second 0)`;
|
|
2973
|
+
else if (cron.hour.expression === "*" && cron.minute.values.length === 1 && cron.second.values.length === 1) timing = `Every hour at minute ${cron.minute.values[0]}, second ${cron.second.values[0]}`;
|
|
2974
|
+
else timing = `${cron.hasSeconds ? "Seconds-first schedule" : "Unix schedule (at second 0)"}: hours ${cron.hour.expression === "*" ? "every hour" : cron.hour.values.map(pad2).join(", ")}; minutes ${cron.minute.expression === "*" ? "every minute" : cron.minute.values.map(pad2).join(", ")}${cron.hasSeconds ? `; seconds ${cron.second.expression === "*" ? "every second" : cron.second.values.map(pad2).join(", ")}` : ""}`;
|
|
2975
|
+
const months = cron.month.values.length === 12 ? "" : `; in ${cron.month.values.map((value) => FULL_MONTHS[value - 1]).join(", ")}`;
|
|
2976
|
+
const dom = cron.dayOfMonth.values.length === 31 ? "every day of month" : `day of month ${cron.dayOfMonth.values.join(", ")}`;
|
|
2977
|
+
const dow = cron.dayOfWeek.values.length === 7 ? "every weekday (Sunday\u2013Saturday)" : cron.dayOfWeek.values.map((value) => FULL_WEEKDAYS[value]).join(", ");
|
|
2978
|
+
const days = cron.dayMode === "or" ? `when either ${dom} OR weekday ${dow} matches` : cron.dayOfMonth.values.length === 31 && cron.dayOfWeek.values.length === 7 ? "every day" : cron.dayOfMonth.values.length === 31 ? `on ${dow}` : cron.dayOfWeek.values.length === 7 ? `on ${dom}` : `when both ${dom} AND weekday ${dow} match`;
|
|
2979
|
+
return `${timing}; ${days}${months}.`;
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
// lib/tools/cron/next-run.ts
|
|
2983
|
+
var DAY2 = 864e5;
|
|
2984
|
+
var SIX_HOURS = 6 * 36e5;
|
|
2985
|
+
var pad3 = (value, width = 2) => String(value).padStart(width, "0");
|
|
2986
|
+
function parseCronReference(reference) {
|
|
2987
|
+
if (reference.length > 64) throw new Error("Reference exceeds the 64-character limit.");
|
|
2988
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/.exec(reference);
|
|
2989
|
+
if (!match) throw new Error("Reference must be an absolute ISO date/time: YYYY-MM-DDTHH:mm[:ss[.sss]] followed by Z or \xB1HH:mm.");
|
|
2990
|
+
const [year, month, day, hour, minute, second] = [match[1], match[2], match[3], match[4], match[5], match[6] ?? "0"].map(Number);
|
|
2991
|
+
if (year < 1970 || year > 2099) throw new Error("Reference years must be between 1970 and 2099.");
|
|
2992
|
+
const days = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
2993
|
+
if (month < 1 || month > 12 || day < 1 || day > days || hour > 23 || minute > 59 || second > 59) throw new Error("Reference contains an impossible calendar date or time.");
|
|
2994
|
+
const milliseconds = Number((match[7] ?? "").padEnd(3, "0"));
|
|
2995
|
+
let offset = 0;
|
|
2996
|
+
if (match[8] !== "Z") {
|
|
2997
|
+
const offsetHour = Number(match[8].slice(1, 3));
|
|
2998
|
+
const offsetMinute = Number(match[8].slice(4, 6));
|
|
2999
|
+
if (offsetMinute > 59 || offsetHour > 14 || offsetHour === 14 && offsetMinute !== 0) throw new Error("Reference offset must be within \xB114:00, with valid minutes.");
|
|
3000
|
+
offset = (offsetHour * 60 + offsetMinute) * 6e4 * (match[8][0] === "-" ? -1 : 1);
|
|
3001
|
+
}
|
|
3002
|
+
const instant = Date.UTC(year, month - 1, day, hour, minute, second, milliseconds) - offset;
|
|
3003
|
+
const utcYear = new Date(instant).getUTCFullYear();
|
|
3004
|
+
if (utcYear < 1970 || utcYear > 2099) throw new Error("Reference instant must fall within UTC years 1970\u20132099.");
|
|
3005
|
+
return instant;
|
|
3006
|
+
}
|
|
3007
|
+
function zoneFormatter2(timezone) {
|
|
3008
|
+
if (!timezone || timezone !== timezone.trim()) throw new Error("Select a nonempty IANA timezone.");
|
|
3009
|
+
if (timezone.length > 128 || !/^[A-Za-z][A-Za-z0-9_+\-/]*$/.test(timezone)) throw new Error("Enter a valid IANA timezone name; numeric offsets are not timezone names.");
|
|
3010
|
+
try {
|
|
3011
|
+
return new Intl.DateTimeFormat("en-GB-u-ca-gregory-nu-latn", {
|
|
3012
|
+
timeZone: timezone,
|
|
3013
|
+
year: "numeric",
|
|
3014
|
+
month: "2-digit",
|
|
3015
|
+
day: "2-digit",
|
|
3016
|
+
hour: "2-digit",
|
|
3017
|
+
minute: "2-digit",
|
|
3018
|
+
second: "2-digit",
|
|
3019
|
+
hourCycle: "h23"
|
|
3020
|
+
});
|
|
3021
|
+
} catch {
|
|
3022
|
+
throw new Error("Timezone is not a recognized IANA timezone in this runtime.");
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
function wallTime(formatter, instant) {
|
|
3026
|
+
const parts = formatter.formatToParts(instant);
|
|
3027
|
+
const get = (name) => Number(parts.find((part) => part.type === name)?.value);
|
|
3028
|
+
return { year: get("year"), month: get("month"), day: get("day"), hour: get("hour"), minute: get("minute"), second: get("second") };
|
|
3029
|
+
}
|
|
3030
|
+
function offsetAt(formatter, instant) {
|
|
3031
|
+
const wholeSecond = Math.floor(instant / 1e3) * 1e3;
|
|
3032
|
+
const wall = wallTime(formatter, wholeSecond);
|
|
3033
|
+
return Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second) - wholeSecond;
|
|
3034
|
+
}
|
|
3035
|
+
function offsetIntervals(formatter, midnight) {
|
|
3036
|
+
const start = midnight - 2 * DAY2;
|
|
3037
|
+
const end = midnight + 3 * DAY2;
|
|
3038
|
+
const intervals = [];
|
|
3039
|
+
let intervalStart = start;
|
|
3040
|
+
let priorOffset = offsetAt(formatter, start);
|
|
3041
|
+
for (let probe = start + SIX_HOURS; probe <= end; probe += SIX_HOURS) {
|
|
3042
|
+
const nextOffset = offsetAt(formatter, probe);
|
|
3043
|
+
if (nextOffset !== priorOffset) {
|
|
3044
|
+
let low = probe - SIX_HOURS;
|
|
3045
|
+
let high = probe;
|
|
3046
|
+
while (high - low > 1e3) {
|
|
3047
|
+
const middle = Math.floor((low + high) / 2e3) * 1e3;
|
|
3048
|
+
if (offsetAt(formatter, middle) === priorOffset) low = middle;
|
|
3049
|
+
else high = middle;
|
|
3050
|
+
}
|
|
3051
|
+
intervals.push({ start: intervalStart, end: high, offset: priorOffset });
|
|
3052
|
+
intervalStart = high;
|
|
3053
|
+
priorOffset = nextOffset;
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
intervals.push({ start: intervalStart, end, offset: priorOffset });
|
|
3057
|
+
return intervals;
|
|
3058
|
+
}
|
|
3059
|
+
function selectedSecond(cron, lower, upper) {
|
|
3060
|
+
if (lower >= upper || lower >= 86400) return void 0;
|
|
3061
|
+
lower = Math.max(0, Math.ceil(lower));
|
|
3062
|
+
const firstHour = Math.floor(lower / 3600);
|
|
3063
|
+
for (const hour of cron.hour.values) {
|
|
3064
|
+
if (hour < firstHour) continue;
|
|
3065
|
+
const firstMinute = hour === firstHour ? Math.floor(lower % 3600 / 60) : 0;
|
|
3066
|
+
for (const minute of cron.minute.values) {
|
|
3067
|
+
if (minute < firstMinute) continue;
|
|
3068
|
+
const base = hour * 3600 + minute * 60;
|
|
3069
|
+
if (base >= upper) return void 0;
|
|
3070
|
+
const second = cron.second.values.find((value) => base + value >= lower);
|
|
3071
|
+
if (second !== void 0) return base + second < upper ? base + second : void 0;
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
return void 0;
|
|
3075
|
+
}
|
|
3076
|
+
function formatCronDuration(milliseconds) {
|
|
3077
|
+
if (!Number.isSafeInteger(milliseconds)) throw new Error("Duration is outside supported integer precision.");
|
|
3078
|
+
const sign = milliseconds < 0 ? "-" : "+";
|
|
3079
|
+
let remainder = Math.abs(milliseconds);
|
|
3080
|
+
const pieces = [];
|
|
3081
|
+
for (const [size, name] of [[DAY2, "day"], [36e5, "hour"], [6e4, "minute"], [1e3, "second"], [1, "millisecond"]]) {
|
|
3082
|
+
const count = Math.floor(remainder / size);
|
|
3083
|
+
remainder %= size;
|
|
3084
|
+
if (count) pieces.push(`${count} ${name}${count === 1 ? "" : "s"}`);
|
|
3085
|
+
}
|
|
3086
|
+
return sign + (pieces.join(", ") || "0 seconds");
|
|
3087
|
+
}
|
|
3088
|
+
function nextCronRun(expression, reference, timezone) {
|
|
3089
|
+
const cron = typeof expression === "string" ? parseCron(expression) : expression;
|
|
3090
|
+
const instant = parseCronReference(reference);
|
|
3091
|
+
const formatter = zoneFormatter2(timezone);
|
|
3092
|
+
const referenceWall = wallTime(formatter, instant);
|
|
3093
|
+
if (referenceWall.year < 1970 || referenceWall.year > 2099) throw new Error("Reference in the selected timezone must fall within years 1970\u20132099.");
|
|
3094
|
+
const referenceDay = Date.UTC(referenceWall.year, referenceWall.month - 1, referenceWall.day);
|
|
3095
|
+
const firstDay = Math.max(Date.UTC(1970, 0, 1), referenceDay - 2 * DAY2);
|
|
3096
|
+
const searchEnd = Math.min(Date.UTC(2100, 0, 1), Date.UTC(referenceWall.year + 8, referenceWall.month - 1, referenceWall.day + 1));
|
|
3097
|
+
const utcReference = new Date(instant);
|
|
3098
|
+
const eightYearLimit = Date.UTC(utcReference.getUTCFullYear() + 8, utcReference.getUTCMonth(), utcReference.getUTCDate(), utcReference.getUTCHours(), utcReference.getUTCMinutes(), utcReference.getUTCSeconds(), utcReference.getUTCMilliseconds());
|
|
3099
|
+
const absoluteEnd = Math.min(Date.UTC(2100, 0, 1), eightYearLimit + 1);
|
|
3100
|
+
let best;
|
|
3101
|
+
let bestOffset = 0;
|
|
3102
|
+
for (let midnight = firstDay; midnight < searchEnd; midnight += DAY2) {
|
|
3103
|
+
if (best !== void 0 && midnight - DAY2 > best) break;
|
|
3104
|
+
const date = new Date(midnight);
|
|
3105
|
+
const year = date.getUTCFullYear();
|
|
3106
|
+
const month = date.getUTCMonth() + 1;
|
|
3107
|
+
const day = date.getUTCDate();
|
|
3108
|
+
if (!matchesCronDate(cron, year, month, day)) continue;
|
|
3109
|
+
for (const interval of offsetIntervals(formatter, midnight)) {
|
|
3110
|
+
const lowerUtc = Math.max(interval.start, instant + 1, midnight - interval.offset, Date.UTC(1970, 0, 1));
|
|
3111
|
+
const upperUtc = Math.min(interval.end, midnight + DAY2 - interval.offset, absoluteEnd, best ?? Infinity);
|
|
3112
|
+
const second = selectedSecond(cron, (lowerUtc + interval.offset - midnight) / 1e3, (upperUtc + interval.offset - midnight) / 1e3);
|
|
3113
|
+
if (second === void 0) continue;
|
|
3114
|
+
const candidate = midnight + second * 1e3 - interval.offset;
|
|
3115
|
+
const actual = wallTime(formatter, candidate);
|
|
3116
|
+
if (actual.year !== year || actual.month !== month || actual.day !== day || actual.hour !== Math.floor(second / 3600) || actual.minute !== Math.floor(second % 3600 / 60) || actual.second !== second % 60) continue;
|
|
3117
|
+
if (candidate > instant && (best === void 0 || candidate < best)) {
|
|
3118
|
+
best = candidate;
|
|
3119
|
+
bestOffset = interval.offset;
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
if (best === void 0) throw new Error("No occurrence found within eight calendar years after the reference, ending no later than 2099. The expression may select impossible calendar dates.");
|
|
3124
|
+
if (bestOffset % 6e4 !== 0) throw new Error("This historical timezone offset includes seconds and cannot be represented by an RFC 3339 \xB1HH:mm offset; choose a reference after the zone adopted minute-based offsets.");
|
|
3125
|
+
const wall = wallTime(formatter, best);
|
|
3126
|
+
const offsetMinutes = Math.abs(bestOffset / 6e4);
|
|
3127
|
+
const offset = `${bestOffset < 0 ? "-" : "+"}${pad3(Math.floor(offsetMinutes / 60))}:${pad3(offsetMinutes % 60)}`;
|
|
3128
|
+
const dateTime = `${pad3(wall.year, 4)}-${pad3(wall.month)}-${pad3(wall.day)}T${pad3(wall.hour)}:${pad3(wall.minute)}:${pad3(wall.second)}${offset}[${timezone}]`;
|
|
3129
|
+
const durationMilliseconds = best - instant;
|
|
3130
|
+
return { instant: best, dateTime, timezone, durationMilliseconds, duration: formatCronDuration(durationMilliseconds) };
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
// config/shared-registry.ts
|
|
3134
|
+
function checkToolAccess(toolId, license) {
|
|
3135
|
+
const tool = SHARED_TOOLS.find(
|
|
3136
|
+
(t) => t.id === toolId || t.mcpMetadata.toolName === toolId || t.cliMetadata.command === toolId || t.cliMetadata.aliases.includes(toolId)
|
|
3137
|
+
);
|
|
3138
|
+
if (!tool) {
|
|
3139
|
+
return {
|
|
3140
|
+
allowed: false,
|
|
3141
|
+
status: "denied",
|
|
3142
|
+
reason: `Tool "${toolId}" is not registered in Code Station registry.`
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
if (tool.accessLevel === "free" || tool.accessLevel === "local-only") {
|
|
3146
|
+
return { allowed: true, status: "granted" };
|
|
3147
|
+
}
|
|
3148
|
+
if (tool.accessLevel === "pro") {
|
|
3149
|
+
if (license?.isPro) {
|
|
3150
|
+
return { allowed: true, status: "granted" };
|
|
3151
|
+
}
|
|
3152
|
+
return {
|
|
3153
|
+
allowed: false,
|
|
3154
|
+
status: "denied",
|
|
3155
|
+
requiredTier: "pro",
|
|
3156
|
+
reason: `Tool "${tool.name}" requires Code Station Pro. Upgrade at https://codestation.in/pro or launch with --key CS-PRO-YOURKEY.`
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
if (tool.accessLevel === "paid-key") {
|
|
3160
|
+
if (license?.isPro) {
|
|
3161
|
+
return { allowed: true, status: "granted" };
|
|
3162
|
+
}
|
|
3163
|
+
return {
|
|
3164
|
+
allowed: false,
|
|
3165
|
+
status: "denied",
|
|
3166
|
+
requiredTier: "paid-key",
|
|
3167
|
+
reason: `Tool "${tool.name}" requires a valid paid key.`
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
return { allowed: true, status: "granted" };
|
|
3171
|
+
}
|
|
3172
|
+
var SHARED_TOOLS = [
|
|
3173
|
+
// 1. cURL to Any Language Generator
|
|
3174
|
+
{
|
|
3175
|
+
id: "curl-to-any-language",
|
|
3176
|
+
name: "cURL to Any Language Generator",
|
|
3177
|
+
description: "Convert literal cURL commands into idiomatic TypeScript (fetch/axios), Python (requests), or Go (net/http).",
|
|
2539
3178
|
version: "1.2.0",
|
|
2540
3179
|
accessLevel: "pro",
|
|
2541
3180
|
privacyClassification: "memory-only",
|
|
2542
|
-
category: "
|
|
2543
|
-
keywords: ["
|
|
3181
|
+
category: "API",
|
|
3182
|
+
keywords: ["curl", "fetch", "axios", "python", "go", "generator", "api", "converter"],
|
|
2544
3183
|
inputSchema: {
|
|
2545
3184
|
type: "object",
|
|
2546
3185
|
properties: {
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
3186
|
+
curl: { type: "string", description: "cURL command string to convert" },
|
|
3187
|
+
target: {
|
|
3188
|
+
type: "string",
|
|
3189
|
+
enum: ["fetch", "axios", "python", "go"],
|
|
3190
|
+
default: "fetch",
|
|
3191
|
+
description: "Target programming language/library"
|
|
3192
|
+
}
|
|
3193
|
+
},
|
|
3194
|
+
required: ["curl"]
|
|
3195
|
+
},
|
|
3196
|
+
outputSchema: {
|
|
3197
|
+
type: "object",
|
|
3198
|
+
properties: {
|
|
3199
|
+
code: { type: "string" },
|
|
3200
|
+
language: { type: "string" },
|
|
3201
|
+
target: { type: "string" },
|
|
3202
|
+
warnings: { type: "array", items: { type: "string" } }
|
|
3203
|
+
}
|
|
3204
|
+
},
|
|
3205
|
+
cliMetadata: {
|
|
3206
|
+
command: "curl-to-any-language",
|
|
3207
|
+
aliases: ["curl", "curl-to-code"],
|
|
3208
|
+
description: "Convert cURL commands to TypeScript, Python, or Go code",
|
|
3209
|
+
examples: [
|
|
3210
|
+
'codestation curl-to-any-language "curl https://api.example.com" --target fetch',
|
|
3211
|
+
`codestation curl "curl -X POST https://api.example.com -d '{\\"name\\":\\"test\\"}'" --target python`
|
|
3212
|
+
]
|
|
3213
|
+
},
|
|
3214
|
+
mcpMetadata: {
|
|
3215
|
+
toolName: "codestation_curl_to_code",
|
|
3216
|
+
description: "Convert cURL commands to TypeScript fetch/axios, Python requests, or Go net/http. [Pro Tier]"
|
|
3217
|
+
},
|
|
3218
|
+
routeMetadata: {
|
|
3219
|
+
route: "/tools/curl-to-any-language",
|
|
3220
|
+
slug: "curl-to-any-language"
|
|
3221
|
+
},
|
|
3222
|
+
execute: async (input) => {
|
|
3223
|
+
const target = input.target || "fetch";
|
|
3224
|
+
return await curlToCode(input.curl, target);
|
|
3225
|
+
}
|
|
3226
|
+
},
|
|
3227
|
+
// 2. Environment & Secret Leak Scanner
|
|
3228
|
+
{
|
|
3229
|
+
id: "env-audit",
|
|
3230
|
+
name: "Environment & Secret Leak Scanner",
|
|
3231
|
+
description: "Audit .env and configuration files for exposed live secrets (Stripe, AWS, OpenAI, GitHub PAT, private keys) and diff against .env.example.",
|
|
3232
|
+
version: "1.2.0",
|
|
3233
|
+
accessLevel: "pro",
|
|
3234
|
+
privacyClassification: "local-only",
|
|
3235
|
+
category: "Security",
|
|
3236
|
+
keywords: ["env", "audit", "secrets", "scanner", "leak", "security", "credentials"],
|
|
3237
|
+
inputSchema: {
|
|
3238
|
+
type: "object",
|
|
3239
|
+
properties: {
|
|
3240
|
+
env: { type: "string", description: "Content of environment or configuration file" },
|
|
3241
|
+
example: { type: "string", description: "Optional content of .env.example to compare against" },
|
|
3242
|
+
format: { type: "string", enum: ["report", "json"], default: "report" }
|
|
3243
|
+
},
|
|
3244
|
+
required: ["env"]
|
|
3245
|
+
},
|
|
3246
|
+
outputSchema: {
|
|
3247
|
+
type: "object",
|
|
3248
|
+
properties: {
|
|
3249
|
+
totalVariables: { type: "integer" },
|
|
3250
|
+
findings: { type: "array" },
|
|
3251
|
+
isSecure: { type: "boolean" },
|
|
3252
|
+
summary: { type: "string" }
|
|
3253
|
+
}
|
|
3254
|
+
},
|
|
3255
|
+
cliMetadata: {
|
|
3256
|
+
command: "env-audit",
|
|
3257
|
+
aliases: ["env", "audit-env"],
|
|
3258
|
+
description: "Scan .env files for leaked secrets and diff against .env.example",
|
|
3259
|
+
examples: [
|
|
3260
|
+
"codestation env-audit .env --example .env.example",
|
|
3261
|
+
"codestation env .env --json"
|
|
3262
|
+
]
|
|
3263
|
+
},
|
|
3264
|
+
mcpMetadata: {
|
|
3265
|
+
toolName: "codestation_env_audit",
|
|
3266
|
+
description: "Scan environment variables for secret leaks and validate against .env.example. [Pro Tier]"
|
|
3267
|
+
},
|
|
3268
|
+
routeMetadata: {
|
|
3269
|
+
route: "/tools/env-audit",
|
|
3270
|
+
slug: "env-audit"
|
|
3271
|
+
},
|
|
3272
|
+
execute: async (input) => {
|
|
3273
|
+
const res = auditEnv(input.env, input.example);
|
|
3274
|
+
if (input.format === "json") return res;
|
|
3275
|
+
return { report: formatEnvAuditReport(res), ...res };
|
|
3276
|
+
}
|
|
3277
|
+
},
|
|
3278
|
+
// 3. Realistic Mock Data & SQL Seeder
|
|
3279
|
+
{
|
|
3280
|
+
id: "mock-data",
|
|
3281
|
+
name: "Realistic Mock Data & SQL Seeder",
|
|
3282
|
+
description: "Generate realistic mock data records and SQL INSERT seed statements with deterministic seeds.",
|
|
3283
|
+
version: "1.2.0",
|
|
3284
|
+
accessLevel: "pro",
|
|
3285
|
+
privacyClassification: "memory-only",
|
|
3286
|
+
category: "JSON & Data",
|
|
3287
|
+
keywords: ["mock", "data", "seed", "sql", "faker", "testing", "fixtures"],
|
|
3288
|
+
inputSchema: {
|
|
3289
|
+
type: "object",
|
|
3290
|
+
properties: {
|
|
3291
|
+
template: { type: "string", enum: ["users", "products", "orders", "custom"], default: "users" },
|
|
3292
|
+
count: { type: "integer", minimum: 1, maximum: 1e3, default: 10 },
|
|
3293
|
+
format: { type: "string", enum: ["json", "sql", "csv"], default: "json" },
|
|
3294
|
+
tableName: { type: "string", description: "Table name for SQL output" },
|
|
3295
|
+
seed: { type: "integer", description: "Deterministic random seed" },
|
|
3296
|
+
customSchema: { type: "object", description: "Custom field mapping" }
|
|
3297
|
+
}
|
|
3298
|
+
},
|
|
3299
|
+
outputSchema: {
|
|
3300
|
+
type: "object",
|
|
2557
3301
|
properties: {
|
|
2558
3302
|
count: { type: "integer" },
|
|
2559
3303
|
data: { type: "array" },
|
|
@@ -2590,7 +3334,7 @@ var SHARED_TOOLS = [
|
|
|
2590
3334
|
version: "1.2.0",
|
|
2591
3335
|
accessLevel: "pro",
|
|
2592
3336
|
privacyClassification: "local-only",
|
|
2593
|
-
category: "
|
|
3337
|
+
category: "Git & Version Control",
|
|
2594
3338
|
keywords: ["git", "conflict", "merge", "resolver", "diff3", "ours", "theirs"],
|
|
2595
3339
|
inputSchema: {
|
|
2596
3340
|
type: "object",
|
|
@@ -2724,7 +3468,7 @@ var SHARED_TOOLS = [
|
|
|
2724
3468
|
version: "1.2.0",
|
|
2725
3469
|
accessLevel: "pro",
|
|
2726
3470
|
privacyClassification: "local-only",
|
|
2727
|
-
category: "Security
|
|
3471
|
+
category: "Security",
|
|
2728
3472
|
keywords: ["jwt", "token", "decode", "claims", "header", "auth"],
|
|
2729
3473
|
inputSchema: {
|
|
2730
3474
|
type: "object",
|
|
@@ -2856,7 +3600,7 @@ var SHARED_TOOLS = [
|
|
|
2856
3600
|
version: "1.2.0",
|
|
2857
3601
|
accessLevel: "pro",
|
|
2858
3602
|
privacyClassification: "local-only",
|
|
2859
|
-
category: "Security
|
|
3603
|
+
category: "Security",
|
|
2860
3604
|
keywords: ["hash", "sha256", "sha512", "md5", "sha1", "crc32", "digest"],
|
|
2861
3605
|
inputSchema: {
|
|
2862
3606
|
type: "object",
|
|
@@ -2902,7 +3646,7 @@ var SHARED_TOOLS = [
|
|
|
2902
3646
|
version: "1.2.0",
|
|
2903
3647
|
accessLevel: "free",
|
|
2904
3648
|
privacyClassification: "local-only",
|
|
2905
|
-
category: "Security
|
|
3649
|
+
category: "Security",
|
|
2906
3650
|
keywords: ["uuid", "random", "guid", "v4"],
|
|
2907
3651
|
inputSchema: {
|
|
2908
3652
|
type: "object",
|
|
@@ -2972,485 +3716,389 @@ var SHARED_TOOLS = [
|
|
|
2972
3716
|
execute: async (input) => {
|
|
2973
3717
|
return formatJson(input.json, input.indent ?? 2);
|
|
2974
3718
|
}
|
|
3719
|
+
},
|
|
3720
|
+
// 13. Base64 Encode / Decode (Free Tier)
|
|
3721
|
+
{
|
|
3722
|
+
id: "base64-encoder",
|
|
3723
|
+
name: "Base64 Encode / Decode",
|
|
3724
|
+
description: "Encode UTF-8 text to Base64 or URL-safe Base64 and decode back.",
|
|
3725
|
+
version: "1.2.0",
|
|
3726
|
+
accessLevel: "free",
|
|
3727
|
+
privacyClassification: "memory-only",
|
|
3728
|
+
category: "Encoding",
|
|
3729
|
+
keywords: ["base64", "encode", "decode", "base64url"],
|
|
3730
|
+
inputSchema: {
|
|
3731
|
+
type: "object",
|
|
3732
|
+
properties: { text: { type: "string" }, action: { type: "string", enum: ["encode", "decode"] }, urlSafe: { type: "boolean" } },
|
|
3733
|
+
required: ["text", "action"]
|
|
3734
|
+
},
|
|
3735
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3736
|
+
cliMetadata: {
|
|
3737
|
+
command: "base64",
|
|
3738
|
+
aliases: ["b64"],
|
|
3739
|
+
description: "Encode or decode Base64 text",
|
|
3740
|
+
examples: ['codestation base64 "hello"']
|
|
3741
|
+
},
|
|
3742
|
+
mcpMetadata: {
|
|
3743
|
+
toolName: "codestation_base64",
|
|
3744
|
+
description: "Encode or decode Base64 and URL-safe Base64 strings. [Free Tier]"
|
|
3745
|
+
},
|
|
3746
|
+
routeMetadata: { route: "/tools/base64-encoder", slug: "base64-encoder" },
|
|
3747
|
+
execute: async (input) => input.action === "encode" ? input.urlSafe ? encodeBase64Url(input.text) : Buffer.from(input.text, "utf-8").toString("base64") : input.urlSafe ? decodeBase64Url(input.text) : Buffer.from(input.text, "base64").toString("utf-8")
|
|
3748
|
+
},
|
|
3749
|
+
// 14. URL Codec (Free Tier)
|
|
3750
|
+
{
|
|
3751
|
+
id: "url-encoder",
|
|
3752
|
+
name: "URL Component Codec",
|
|
3753
|
+
description: "Encode or decode URI string components locally.",
|
|
3754
|
+
version: "1.2.0",
|
|
3755
|
+
accessLevel: "free",
|
|
3756
|
+
privacyClassification: "memory-only",
|
|
3757
|
+
category: "Encoding",
|
|
3758
|
+
keywords: ["url", "uri", "percent-encode"],
|
|
3759
|
+
inputSchema: { type: "object", properties: { text: { type: "string" }, action: { type: "string", enum: ["encode", "decode"] } }, required: ["text", "action"] },
|
|
3760
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3761
|
+
cliMetadata: { command: "url-codec", aliases: [], description: "URL encode or decode strings", examples: [] },
|
|
3762
|
+
mcpMetadata: { toolName: "codestation_url_codec", description: "URL encode or decode string components. [Free Tier]" },
|
|
3763
|
+
routeMetadata: { route: "/tools/url-encoder", slug: "url-encoder" },
|
|
3764
|
+
execute: async (input) => input.action === "encode" ? encodeUrlComponent(input.text) : decodeUrlComponent(input.text)
|
|
3765
|
+
},
|
|
3766
|
+
// 15. Hexadecimal Codec (Free Tier)
|
|
3767
|
+
{
|
|
3768
|
+
id: "hexadecimal-encoder",
|
|
3769
|
+
name: "Hexadecimal Codec",
|
|
3770
|
+
description: "Encode UTF-8 text to hexadecimal byte pairs or decode hex back to text.",
|
|
3771
|
+
version: "1.2.0",
|
|
3772
|
+
accessLevel: "free",
|
|
3773
|
+
privacyClassification: "memory-only",
|
|
3774
|
+
category: "Encoding",
|
|
3775
|
+
keywords: ["hex", "hexadecimal", "bytes"],
|
|
3776
|
+
inputSchema: { type: "object", properties: { text: { type: "string" }, action: { type: "string", enum: ["encode", "decode"] } }, required: ["text", "action"] },
|
|
3777
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3778
|
+
cliMetadata: { command: "hex-codec", aliases: [], description: "Hex encode or decode text", examples: [] },
|
|
3779
|
+
mcpMetadata: { toolName: "codestation_hex_codec", description: "Encode UTF-8 string to hexadecimal byte pairs or decode hex to text. [Free Tier]" },
|
|
3780
|
+
routeMetadata: { route: "/tools/hexadecimal-encoder", slug: "hexadecimal-encoder" },
|
|
3781
|
+
execute: async (input) => input.action === "encode" ? encodeHexadecimal(input.text) : decodeHexadecimal(input.text)
|
|
3782
|
+
},
|
|
3783
|
+
// 16. JSON Minifier (Free Tier)
|
|
3784
|
+
{
|
|
3785
|
+
id: "json-minifier",
|
|
3786
|
+
name: "JSON Minifier",
|
|
3787
|
+
description: "Minify JSON by stripping all whitespace.",
|
|
3788
|
+
version: "1.2.0",
|
|
3789
|
+
accessLevel: "free",
|
|
3790
|
+
privacyClassification: "memory-only",
|
|
3791
|
+
category: "JSON & Data",
|
|
3792
|
+
keywords: ["json", "minify", "compact"],
|
|
3793
|
+
inputSchema: { type: "object", properties: { json: { type: "string" } }, required: ["json"] },
|
|
3794
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3795
|
+
cliMetadata: { command: "minify-json", aliases: [], description: "Minify JSON", examples: [] },
|
|
3796
|
+
mcpMetadata: { toolName: "codestation_minify_json", description: "Minify JSON by stripping all whitespace. [Free Tier]" },
|
|
3797
|
+
routeMetadata: { route: "/tools/json-minifier", slug: "json-minifier" },
|
|
3798
|
+
execute: async (input) => minifyJson(input.json)
|
|
3799
|
+
},
|
|
3800
|
+
// 17. JSON to YAML (Free Tier)
|
|
3801
|
+
{
|
|
3802
|
+
id: "json-to-yaml",
|
|
3803
|
+
name: "JSON to YAML Converter",
|
|
3804
|
+
description: "Convert JSON to clean YAML format.",
|
|
3805
|
+
version: "1.2.0",
|
|
3806
|
+
accessLevel: "free",
|
|
3807
|
+
privacyClassification: "memory-only",
|
|
3808
|
+
category: "JSON & Data",
|
|
3809
|
+
keywords: ["json", "yaml", "convert"],
|
|
3810
|
+
inputSchema: { type: "object", properties: { json: { type: "string" } }, required: ["json"] },
|
|
3811
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3812
|
+
cliMetadata: { command: "json-to-yaml", aliases: [], description: "Convert JSON to YAML", examples: [] },
|
|
3813
|
+
mcpMetadata: { toolName: "codestation_json_to_yaml", description: "Convert JSON to clean YAML format. [Free Tier]" },
|
|
3814
|
+
routeMetadata: { route: "/tools/json-to-yaml", slug: "json-to-yaml" },
|
|
3815
|
+
execute: async (input) => jsonToYaml(input.json)
|
|
3816
|
+
},
|
|
3817
|
+
// 18. YAML to JSON (Free Tier)
|
|
3818
|
+
{
|
|
3819
|
+
id: "yaml-to-json",
|
|
3820
|
+
name: "YAML to JSON Converter",
|
|
3821
|
+
description: "Convert YAML formatted text to JSON.",
|
|
3822
|
+
version: "1.2.0",
|
|
3823
|
+
accessLevel: "free",
|
|
3824
|
+
privacyClassification: "memory-only",
|
|
3825
|
+
category: "JSON & Data",
|
|
3826
|
+
keywords: ["yaml", "json", "convert"],
|
|
3827
|
+
inputSchema: { type: "object", properties: { yaml: { type: "string" } }, required: ["yaml"] },
|
|
3828
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3829
|
+
cliMetadata: { command: "yaml-to-json", aliases: [], description: "Convert YAML to JSON", examples: [] },
|
|
3830
|
+
mcpMetadata: { toolName: "codestation_yaml_to_json", description: "Convert YAML formatted text to JSON. [Free Tier]" },
|
|
3831
|
+
routeMetadata: { route: "/tools/yaml-to-json", slug: "yaml-to-json" },
|
|
3832
|
+
execute: async (input) => yamlToJson(input.yaml)
|
|
3833
|
+
},
|
|
3834
|
+
// 19. Case Converter (Free Tier)
|
|
3835
|
+
{
|
|
3836
|
+
id: "text-case-converter",
|
|
3837
|
+
name: "Case Converter",
|
|
3838
|
+
description: "Convert text between camelCase, snake_case, kebab-case, PascalCase, and CONSTANT_CASE.",
|
|
3839
|
+
version: "1.2.0",
|
|
3840
|
+
accessLevel: "free",
|
|
3841
|
+
privacyClassification: "memory-only",
|
|
3842
|
+
category: "Text",
|
|
3843
|
+
keywords: ["case", "camel", "snake", "kebab", "pascal"],
|
|
3844
|
+
inputSchema: { type: "object", properties: { text: { type: "string" }, targetCase: { type: "string" } }, required: ["text", "targetCase"] },
|
|
3845
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3846
|
+
cliMetadata: { command: "case-convert", aliases: [], description: "Convert naming conventions", examples: [] },
|
|
3847
|
+
mcpMetadata: { toolName: "codestation_case_convert", description: "Convert text into different naming conventions. [Free Tier]" },
|
|
3848
|
+
routeMetadata: { route: "/tools/text-case-converter", slug: "text-case-converter" },
|
|
3849
|
+
execute: async (input) => convertCase(input.text, input.targetCase)
|
|
3850
|
+
},
|
|
3851
|
+
// 20. Unified Text Diff (Free Tier)
|
|
3852
|
+
{
|
|
3853
|
+
id: "text-diff",
|
|
3854
|
+
name: "Unified Text Diff",
|
|
3855
|
+
description: "Generate a clean line-by-line unified diff between original and modified text.",
|
|
3856
|
+
version: "1.2.0",
|
|
3857
|
+
accessLevel: "free",
|
|
3858
|
+
privacyClassification: "memory-only",
|
|
3859
|
+
category: "Text",
|
|
3860
|
+
keywords: ["diff", "compare", "unified", "patch"],
|
|
3861
|
+
inputSchema: { type: "object", properties: { original: { type: "string" }, modified: { type: "string" } }, required: ["original", "modified"] },
|
|
3862
|
+
outputSchema: { type: "object", properties: { diff: { type: "string" } } },
|
|
3863
|
+
cliMetadata: { command: "diff", aliases: ["text-diff"], description: "Compute unified line diff", examples: [] },
|
|
3864
|
+
mcpMetadata: { toolName: "codestation_text_diff", description: "Generate a clean line-by-line unified diff between original and modified text. [Free Tier]" },
|
|
3865
|
+
routeMetadata: { route: "/tools/text-diff", slug: "text-diff" },
|
|
3866
|
+
execute: async (input) => diffText(input.original, input.modified)
|
|
3867
|
+
},
|
|
3868
|
+
// 21. Slugify (Free Tier)
|
|
3869
|
+
{
|
|
3870
|
+
id: "slug-generator",
|
|
3871
|
+
name: "Slug Generator",
|
|
3872
|
+
description: "Convert strings to clean URL slugs.",
|
|
3873
|
+
version: "1.2.0",
|
|
3874
|
+
accessLevel: "free",
|
|
3875
|
+
privacyClassification: "memory-only",
|
|
3876
|
+
category: "Text",
|
|
3877
|
+
keywords: ["slug", "url", "kebab"],
|
|
3878
|
+
inputSchema: { type: "object", properties: { text: { type: "string" }, separator: { type: "string" } }, required: ["text"] },
|
|
3879
|
+
outputSchema: { type: "object", properties: { slug: { type: "string" } } },
|
|
3880
|
+
cliMetadata: { command: "slugify", aliases: [], description: "Generate URL-safe slugs", examples: [] },
|
|
3881
|
+
mcpMetadata: { toolName: "codestation_slugify", description: "Convert strings to clean, SEO-friendly URL slugs. [Free Tier]" },
|
|
3882
|
+
routeMetadata: { route: "/tools/slug-generator", slug: "slug-generator" },
|
|
3883
|
+
execute: async (input) => slugify(input.text, input.separator ?? "-")
|
|
3884
|
+
},
|
|
3885
|
+
// 22. Structural JSON Diff (Free Tier)
|
|
3886
|
+
{
|
|
3887
|
+
id: "json-diff",
|
|
3888
|
+
name: "JSON Diff",
|
|
3889
|
+
description: "Compute a structural key-by-key diff between two JSON documents.",
|
|
3890
|
+
version: "1.3.0",
|
|
3891
|
+
accessLevel: "free",
|
|
3892
|
+
privacyClassification: "memory-only",
|
|
3893
|
+
category: "JSON & Data",
|
|
3894
|
+
keywords: ["json", "diff", "compare", "structural"],
|
|
3895
|
+
inputSchema: { type: "object", properties: { left: { type: "string" }, right: { type: "string" } }, required: ["left", "right"] },
|
|
3896
|
+
outputSchema: { type: "object", properties: { diff: { type: "string" } } },
|
|
3897
|
+
cliMetadata: { command: "json-diff", aliases: ["jdiff"], description: "Compare two JSON documents structurally", examples: [`codestation json-diff '{"a":1}' '{"a":2}'`] },
|
|
3898
|
+
mcpMetadata: { toolName: "codestation_json_diff", description: "Compute a structural key-by-key diff between two JSON documents. [Free Tier]" },
|
|
3899
|
+
routeMetadata: { route: "/tools/json-diff", slug: "json-diff" },
|
|
3900
|
+
execute: async (input) => jsonDiff(input.left, input.right)
|
|
3901
|
+
},
|
|
3902
|
+
// 23. JSONPath Query Extractor (Free Tier)
|
|
3903
|
+
{
|
|
3904
|
+
id: "jsonpath-tester",
|
|
3905
|
+
name: "JSONPath Query Extractor",
|
|
3906
|
+
description: "Evaluate JSONPath expressions ($.property, $[0], $[*]) against JSON payloads.",
|
|
3907
|
+
version: "1.3.0",
|
|
3908
|
+
accessLevel: "free",
|
|
3909
|
+
privacyClassification: "memory-only",
|
|
3910
|
+
category: "JSON & Data",
|
|
3911
|
+
keywords: ["jsonpath", "query", "extract", "json"],
|
|
3912
|
+
inputSchema: { type: "object", properties: { json: { type: "string" }, expression: { type: "string" } }, required: ["json", "expression"] },
|
|
3913
|
+
outputSchema: { type: "object", properties: { matches: { type: "string" } } },
|
|
3914
|
+
cliMetadata: { command: "jsonpath", aliases: ["json-path"], description: "Extract values using JSONPath", examples: [`codestation jsonpath '{"users":[{"name":"Ada"}]}' "$.users[*].name"`] },
|
|
3915
|
+
mcpMetadata: { toolName: "codestation_json_path", description: "Query and extract values from JSON using JSONPath expressions ($.field, $[0], $[*]). [Free Tier]" },
|
|
3916
|
+
routeMetadata: { route: "/tools/jsonpath-tester", slug: "jsonpath-tester" },
|
|
3917
|
+
execute: async (input) => testJsonPath(input.json, input.expression)
|
|
3918
|
+
},
|
|
3919
|
+
// 24. ULID Generator (Free Tier)
|
|
3920
|
+
{
|
|
3921
|
+
id: "ulid-generator",
|
|
3922
|
+
name: "ULID Generator",
|
|
3923
|
+
description: "Generate Crockford Base32 lexicographically sortable ULIDs.",
|
|
3924
|
+
version: "1.3.0",
|
|
3925
|
+
accessLevel: "free",
|
|
3926
|
+
privacyClassification: "local-only",
|
|
3927
|
+
category: "Security",
|
|
3928
|
+
keywords: ["ulid", "id", "sortable", "unique"],
|
|
3929
|
+
inputSchema: { type: "object", properties: { count: { type: "integer", minimum: 1, maximum: 50 } } },
|
|
3930
|
+
outputSchema: { type: "object", properties: { ulids: { type: "string" } } },
|
|
3931
|
+
cliMetadata: { command: "ulid", aliases: [], description: "Generate sortable ULIDs", examples: ["codestation ulid 5"] },
|
|
3932
|
+
mcpMetadata: { toolName: "codestation_ulid", description: "Generate lexicographically sortable ULID identifiers. [Free Tier]" },
|
|
3933
|
+
routeMetadata: { route: "/tools/ulid-generator", slug: "ulid-generator" },
|
|
3934
|
+
execute: async (input) => Array.from({ length: Math.min(Math.max(input.count ?? 1, 1), 50) }, () => ulid()).join("\n")
|
|
3935
|
+
},
|
|
3936
|
+
// 25. NanoID Generator (Free Tier)
|
|
3937
|
+
{
|
|
3938
|
+
id: "nanoid-generator",
|
|
3939
|
+
name: "NanoID Generator",
|
|
3940
|
+
description: "Generate URL-safe cryptographic NanoID strings.",
|
|
3941
|
+
version: "1.3.0",
|
|
3942
|
+
accessLevel: "free",
|
|
3943
|
+
privacyClassification: "local-only",
|
|
3944
|
+
category: "Security",
|
|
3945
|
+
keywords: ["nanoid", "id", "token"],
|
|
3946
|
+
inputSchema: { type: "object", properties: { length: { type: "integer" }, count: { type: "integer" } } },
|
|
3947
|
+
outputSchema: { type: "object", properties: { ids: { type: "string" } } },
|
|
3948
|
+
cliMetadata: { command: "nanoid", aliases: [], description: "Generate compact NanoIDs", examples: ["codestation nanoid --length 16"] },
|
|
3949
|
+
mcpMetadata: { toolName: "codestation_nanoid", description: "Generate URL-safe cryptographic NanoID strings with custom length. [Free Tier]" },
|
|
3950
|
+
routeMetadata: { route: "/tools/nanoid-generator", slug: "nanoid-generator" },
|
|
3951
|
+
execute: async (input) => Array.from({ length: input.count ?? 1 }, () => nanoid(input.length ?? 21)).join("\n")
|
|
3952
|
+
},
|
|
3953
|
+
// 26. HTML Entity Codec (Free Tier)
|
|
3954
|
+
{
|
|
3955
|
+
id: "html-entity-encoder",
|
|
3956
|
+
name: "HTML Entity Codec",
|
|
3957
|
+
description: "Escape or unescape HTML entities (<, >, &, numeric codes).",
|
|
3958
|
+
version: "1.3.0",
|
|
3959
|
+
accessLevel: "free",
|
|
3960
|
+
privacyClassification: "memory-only",
|
|
3961
|
+
category: "Encoding",
|
|
3962
|
+
keywords: ["html", "entity", "escape", "unescape"],
|
|
3963
|
+
inputSchema: { type: "object", properties: { text: { type: "string" }, action: { type: "string", enum: ["encode", "decode"] } }, required: ["text", "action"] },
|
|
3964
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3965
|
+
cliMetadata: { command: "html-codec", aliases: [], description: "Encode or decode HTML entities", examples: [] },
|
|
3966
|
+
mcpMetadata: { toolName: "codestation_html_codec", description: "Encode or decode HTML character entities safely. [Free Tier]" },
|
|
3967
|
+
routeMetadata: { route: "/tools/html-entity-encoder", slug: "html-entity-encoder" },
|
|
3968
|
+
execute: async (input) => input.action === "encode" ? encodeHtml(input.text) : decodeHtml(input.text)
|
|
3969
|
+
},
|
|
3970
|
+
// 27. CSV <-> JSON Converter (Free Tier)
|
|
3971
|
+
{
|
|
3972
|
+
id: "csv-to-json",
|
|
3973
|
+
name: "CSV <-> JSON Converter",
|
|
3974
|
+
description: "Convert CSV tables with header rows to JSON arrays or JSON arrays to CSV.",
|
|
3975
|
+
version: "1.3.0",
|
|
3976
|
+
accessLevel: "free",
|
|
3977
|
+
privacyClassification: "memory-only",
|
|
3978
|
+
category: "JSON & Data",
|
|
3979
|
+
keywords: ["csv", "json", "table", "convert"],
|
|
3980
|
+
inputSchema: { type: "object", properties: { input: { type: "string" }, direction: { type: "string", enum: ["csv-to-json", "json-to-csv"] } }, required: ["input", "direction"] },
|
|
3981
|
+
outputSchema: { type: "object", properties: { output: { type: "string" } } },
|
|
3982
|
+
cliMetadata: { command: "csv-json", aliases: [], description: "Convert between CSV and JSON", examples: [] },
|
|
3983
|
+
mcpMetadata: { toolName: "codestation_csv_json", description: "Convert CSV tables to JSON or JSON arrays of objects to CSV. [Free Tier]" },
|
|
3984
|
+
routeMetadata: { route: "/tools/csv-to-json", slug: "csv-to-json" },
|
|
3985
|
+
execute: async (input) => input.direction === "csv-to-json" ? csvToJson(input.input) : jsonToCsv(input.input)
|
|
3986
|
+
},
|
|
3987
|
+
// 28. HMAC Signature Generator (Pro Tier)
|
|
3988
|
+
{
|
|
3989
|
+
id: "hmac-generator",
|
|
3990
|
+
name: "HMAC Signature Generator",
|
|
3991
|
+
description: "Compute HMAC-SHA256 or HMAC-SHA512 message signatures.",
|
|
3992
|
+
version: "1.2.0",
|
|
3993
|
+
accessLevel: "pro",
|
|
3994
|
+
privacyClassification: "memory-only",
|
|
3995
|
+
category: "Security",
|
|
3996
|
+
keywords: ["hmac", "signature", "sha256", "sha512"],
|
|
3997
|
+
inputSchema: { type: "object", properties: { text: { type: "string" }, secret: { type: "string" }, algorithm: { type: "string" } }, required: ["text", "secret"] },
|
|
3998
|
+
outputSchema: { type: "object", properties: { signature: { type: "string" } } },
|
|
3999
|
+
cliMetadata: { command: "hmac", aliases: [], description: "Compute HMAC signature", examples: [] },
|
|
4000
|
+
mcpMetadata: { toolName: "codestation_hmac", description: "Compute HMAC signatures using Web Crypto. [Pro Tier: \u20B9199/mo or $2.99/mo]" },
|
|
4001
|
+
routeMetadata: { route: "/tools/hmac-generator", slug: "hmac-generator" },
|
|
4002
|
+
execute: async (input) => input.algorithm?.toUpperCase() === "SHA-512" ? hmacSha512(input.text, input.secret) : hmacSha256(input.text, input.secret)
|
|
4003
|
+
},
|
|
4004
|
+
// 29. IANA Timezone Converter (Pro Tier)
|
|
4005
|
+
{
|
|
4006
|
+
id: "timezone-converter",
|
|
4007
|
+
name: "IANA Timezone Converter",
|
|
4008
|
+
description: "Convert timestamps across runtime IANA timezones.",
|
|
4009
|
+
version: "1.2.0",
|
|
4010
|
+
accessLevel: "pro",
|
|
4011
|
+
privacyClassification: "memory-only",
|
|
4012
|
+
category: "Date & Time",
|
|
4013
|
+
keywords: ["timezone", "iana", "dst", "date"],
|
|
4014
|
+
inputSchema: { type: "object", properties: { dateTime: { type: "string" }, sourceTimeZone: { type: "string" }, targetTimeZone: { type: "string" } }, required: ["dateTime", "sourceTimeZone", "targetTimeZone"] },
|
|
4015
|
+
outputSchema: { type: "object", properties: { converted: { type: "string" } } },
|
|
4016
|
+
cliMetadata: { command: "tz", aliases: [], description: "Convert IANA timezones", examples: [] },
|
|
4017
|
+
mcpMetadata: { toolName: "codestation_timezone_convert", description: "Convert a date/time string between IANA timezones. [Pro Tier: \u20B9199/mo or $2.99/mo]" },
|
|
4018
|
+
routeMetadata: { route: "/tools/timezone-converter", slug: "timezone-converter" },
|
|
4019
|
+
execute: async (input) => convertBetweenTimeZones(input.dateTime, input.sourceTimeZone, input.targetTimeZone)
|
|
4020
|
+
},
|
|
4021
|
+
// 30. Business Days Calculator (Pro Tier)
|
|
4022
|
+
{
|
|
4023
|
+
id: "business-days-calculator",
|
|
4024
|
+
name: "Business Days Calculator",
|
|
4025
|
+
description: "Calculate working days between two dates.",
|
|
4026
|
+
version: "1.2.0",
|
|
4027
|
+
accessLevel: "pro",
|
|
4028
|
+
privacyClassification: "memory-only",
|
|
4029
|
+
category: "Date & Time",
|
|
4030
|
+
keywords: ["business days", "weekends", "date"],
|
|
4031
|
+
inputSchema: { type: "object", properties: { startDate: { type: "string" }, endDate: { type: "string" } }, required: ["startDate", "endDate"] },
|
|
4032
|
+
outputSchema: { type: "object", properties: { days: { type: "number" } } },
|
|
4033
|
+
cliMetadata: { command: "business-days", aliases: [], description: "Count working days between dates", examples: [] },
|
|
4034
|
+
mcpMetadata: { toolName: "codestation_business_days", description: "Calculate exact working/business days between two dates. [Pro Tier: \u20B9199/mo or $2.99/mo]" },
|
|
4035
|
+
routeMetadata: { route: "/tools/business-days-calculator", slug: "business-days-calculator" },
|
|
4036
|
+
execute: async (input) => businessDaysBetween(input.startDate, input.endDate)
|
|
4037
|
+
},
|
|
4038
|
+
// 31. Regex Tester (Pro Tier)
|
|
4039
|
+
{
|
|
4040
|
+
id: "regex-match-inspector",
|
|
4041
|
+
name: "Regex Match Tester",
|
|
4042
|
+
description: "Test JavaScript regular expressions and inspect match groups.",
|
|
4043
|
+
version: "1.2.0",
|
|
4044
|
+
accessLevel: "pro",
|
|
4045
|
+
privacyClassification: "memory-only",
|
|
4046
|
+
category: "Regex",
|
|
4047
|
+
keywords: ["regex", "regexp", "match", "groups"],
|
|
4048
|
+
inputSchema: { type: "object", properties: { pattern: { type: "string" }, text: { type: "string" }, flags: { type: "string" } }, required: ["pattern", "text"] },
|
|
4049
|
+
outputSchema: { type: "object", properties: { matches: { type: "string" } } },
|
|
4050
|
+
cliMetadata: { command: "regex", aliases: [], description: "Test regex against text", examples: [] },
|
|
4051
|
+
mcpMetadata: { toolName: "codestation_regex_test", description: "Test regular expressions and return structured match groups. [Pro Tier: \u20B9199/mo or $2.99/mo]" },
|
|
4052
|
+
routeMetadata: { route: "/tools/regex-match-inspector", slug: "regex-match-inspector" },
|
|
4053
|
+
execute: async (input) => testRegex(input.pattern, input.flags ?? "g", input.text)
|
|
4054
|
+
},
|
|
4055
|
+
// 32. JSON Schema Generator (Pro Tier)
|
|
4056
|
+
{
|
|
4057
|
+
id: "json-schema-generator",
|
|
4058
|
+
name: "JSON Schema Generator",
|
|
4059
|
+
description: "Infer Draft 2020-12 JSON Schema from sample JSON.",
|
|
4060
|
+
version: "1.2.0",
|
|
4061
|
+
accessLevel: "pro",
|
|
4062
|
+
privacyClassification: "memory-only",
|
|
4063
|
+
category: "JSON & Data",
|
|
4064
|
+
keywords: ["json schema", "draft 2020-12", "infer"],
|
|
4065
|
+
inputSchema: { type: "object", properties: { json: { type: "string" } }, required: ["json"] },
|
|
4066
|
+
outputSchema: { type: "object", properties: { schema: { type: "string" } } },
|
|
4067
|
+
cliMetadata: { command: "json-schema", aliases: [], description: "Infer JSON Schema", examples: [] },
|
|
4068
|
+
mcpMetadata: { toolName: "codestation_json_schema", description: "Infer a Draft 2020-12 JSON Schema structure from sample JSON. [Pro Tier: \u20B9199/mo or $2.99/mo]" },
|
|
4069
|
+
routeMetadata: { route: "/tools/json-schema-generator", slug: "json-schema-generator" },
|
|
4070
|
+
execute: async (input) => generateJsonSchema(input.json)
|
|
4071
|
+
},
|
|
4072
|
+
// 33. Cron Next Run Calculator (Pro Tier)
|
|
4073
|
+
{
|
|
4074
|
+
id: "cron-next-run",
|
|
4075
|
+
name: "Cron Next Run Calculator",
|
|
4076
|
+
description: "Compute upcoming cron execution timestamps in any IANA timezone.",
|
|
4077
|
+
version: "1.3.0",
|
|
4078
|
+
accessLevel: "pro",
|
|
4079
|
+
privacyClassification: "memory-only",
|
|
4080
|
+
category: "Cron",
|
|
4081
|
+
keywords: ["cron", "schedule", "next run", "timezone"],
|
|
4082
|
+
inputSchema: { type: "object", properties: { expression: { type: "string" }, count: { type: "integer" }, timeZone: { type: "string" }, startFrom: { type: "string" } }, required: ["expression"] },
|
|
4083
|
+
outputSchema: { type: "object", properties: { runs: { type: "array" } } },
|
|
4084
|
+
cliMetadata: { command: "cron-next", aliases: [], description: "List next cron execution times", examples: ['codestation cron "0 9 * * 1-5"'] },
|
|
4085
|
+
mcpMetadata: { toolName: "codestation_cron_next_runs", description: "Calculate upcoming cron run timestamps in a chosen IANA timezone. [Pro Tier: \u20B9199/mo or $2.99/mo]" },
|
|
4086
|
+
routeMetadata: { route: "/tools/cron-next-run", slug: "cron-next-run" },
|
|
4087
|
+
execute: async (input) => {
|
|
4088
|
+
const parsed = parseCron(input.expression);
|
|
4089
|
+
let cursor = input.startFrom ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
4090
|
+
const runs = [];
|
|
4091
|
+
const limit = Math.min(Math.max(input.count ?? 5, 1), 20);
|
|
4092
|
+
for (let i = 0; i < limit; i += 1) {
|
|
4093
|
+
const next = nextCronRun(parsed, cursor, input.timeZone ?? "UTC");
|
|
4094
|
+
runs.push(next.dateTime);
|
|
4095
|
+
cursor = new Date(next.instant).toISOString();
|
|
4096
|
+
}
|
|
4097
|
+
return runs;
|
|
4098
|
+
}
|
|
2975
4099
|
}
|
|
2976
4100
|
];
|
|
2977
4101
|
|
|
2978
|
-
// lib/tools/text-station.ts
|
|
2979
|
-
var MAX_TEXT_LENGTH = 1e6;
|
|
2980
|
-
var MAX_DIFF_LINES = 2e3;
|
|
2981
|
-
var MAX_DIFF_CELLS = 4e6;
|
|
2982
|
-
var LOREM_WORDS = [
|
|
2983
|
-
"lorem",
|
|
2984
|
-
"ipsum",
|
|
2985
|
-
"dolor",
|
|
2986
|
-
"sit",
|
|
2987
|
-
"amet",
|
|
2988
|
-
"consectetur",
|
|
2989
|
-
"adipiscing",
|
|
2990
|
-
"elit",
|
|
2991
|
-
"sed",
|
|
2992
|
-
"do",
|
|
2993
|
-
"eiusmod",
|
|
2994
|
-
"tempor",
|
|
2995
|
-
"incididunt",
|
|
2996
|
-
"ut",
|
|
2997
|
-
"labore",
|
|
2998
|
-
"et",
|
|
2999
|
-
"dolore",
|
|
3000
|
-
"magna",
|
|
3001
|
-
"aliqua",
|
|
3002
|
-
"enim",
|
|
3003
|
-
"ad",
|
|
3004
|
-
"minim",
|
|
3005
|
-
"veniam",
|
|
3006
|
-
"quis",
|
|
3007
|
-
"nostrud",
|
|
3008
|
-
"exercitation",
|
|
3009
|
-
"ullamco",
|
|
3010
|
-
"laboris",
|
|
3011
|
-
"nisi",
|
|
3012
|
-
"aliquip",
|
|
3013
|
-
"ex",
|
|
3014
|
-
"ea",
|
|
3015
|
-
"commodo",
|
|
3016
|
-
" consequat",
|
|
3017
|
-
"duis",
|
|
3018
|
-
"aute",
|
|
3019
|
-
"irure",
|
|
3020
|
-
"in",
|
|
3021
|
-
"reprehenderit",
|
|
3022
|
-
"voluptate",
|
|
3023
|
-
"velit",
|
|
3024
|
-
"esse",
|
|
3025
|
-
"cillum",
|
|
3026
|
-
"fugiat",
|
|
3027
|
-
"nulla",
|
|
3028
|
-
"pariatur",
|
|
3029
|
-
"excepteur",
|
|
3030
|
-
"sint",
|
|
3031
|
-
"occaecat",
|
|
3032
|
-
"cupidatat",
|
|
3033
|
-
"non",
|
|
3034
|
-
"proident",
|
|
3035
|
-
"sunt",
|
|
3036
|
-
"culpa",
|
|
3037
|
-
"qui",
|
|
3038
|
-
"officia",
|
|
3039
|
-
"deserunt",
|
|
3040
|
-
"mollit",
|
|
3041
|
-
"anim",
|
|
3042
|
-
"id",
|
|
3043
|
-
"est",
|
|
3044
|
-
"laborum"
|
|
3045
|
-
].map((word) => word.trim());
|
|
3046
|
-
function assertText(value, name = "text") {
|
|
3047
|
-
if (typeof value !== "string") throw new TypeError(`${name} must be a string.`);
|
|
3048
|
-
if (value.length > MAX_TEXT_LENGTH) throw new RangeError(`${name} must be at most ${MAX_TEXT_LENGTH.toLocaleString()} characters.`);
|
|
3049
|
-
return value;
|
|
3050
|
-
}
|
|
3051
|
-
function parseLines(value) {
|
|
3052
|
-
assertText(value);
|
|
3053
|
-
const firstCrLf = value.indexOf("\r\n");
|
|
3054
|
-
const firstLf = value.indexOf("\n");
|
|
3055
|
-
const firstCr = value.indexOf("\r");
|
|
3056
|
-
let ending = "\n";
|
|
3057
|
-
if (firstCrLf >= 0 && (firstLf < 0 || firstCrLf <= firstLf)) ending = "\r\n";
|
|
3058
|
-
else if (firstCr >= 0 && (firstLf < 0 || firstCr < firstLf)) ending = "\r";
|
|
3059
|
-
const normalized = value.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3060
|
-
if (!normalized) return { lines: [], ending, trailingBreak: false };
|
|
3061
|
-
const trailingBreak = normalized.endsWith("\n");
|
|
3062
|
-
const body = trailingBreak ? normalized.slice(0, -1) : normalized;
|
|
3063
|
-
return { lines: body ? body.split("\n") : [""], ending, trailingBreak };
|
|
3064
|
-
}
|
|
3065
|
-
function firstCharacterUpper(value, locale) {
|
|
3066
|
-
const characters = Array.from(value);
|
|
3067
|
-
if (!characters.length) return value;
|
|
3068
|
-
return characters[0].toLocaleUpperCase(locale) + characters.slice(1).join("");
|
|
3069
|
-
}
|
|
3070
|
-
function wordsOf(value) {
|
|
3071
|
-
return value.replace(/([\p{Ll}\p{N}])([\p{Lu}])/gu, "$1 $2").match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
3072
|
-
}
|
|
3073
|
-
function convertCase(value, style, options = {}) {
|
|
3074
|
-
assertText(value);
|
|
3075
|
-
const locale = options.locale;
|
|
3076
|
-
if (style === "upper") return value.toLocaleUpperCase(locale);
|
|
3077
|
-
if (style === "lower") return value.toLocaleLowerCase(locale);
|
|
3078
|
-
if (style === "title") {
|
|
3079
|
-
return value.toLocaleLowerCase(locale).replace(/(^|[\s\-_\/.])([\p{L}\p{N}])/gu, (_, separator, character) => `${separator}${character.toLocaleUpperCase(locale)}`);
|
|
3080
|
-
}
|
|
3081
|
-
if (style === "sentence") {
|
|
3082
|
-
const lower = value.toLocaleLowerCase(locale);
|
|
3083
|
-
return lower.replace(/(^|[.!?…。!?]\s+)(\s*)([\p{L}\p{N}])/gu, (_, boundary, whitespace, character) => `${boundary}${whitespace}${character.toLocaleUpperCase(locale)}`);
|
|
3084
|
-
}
|
|
3085
|
-
const words2 = wordsOf(value).map((word) => word.toLocaleLowerCase(locale));
|
|
3086
|
-
if (style === "camel") return words2.map((word, index) => index === 0 ? word : firstCharacterUpper(word, locale)).join("");
|
|
3087
|
-
if (style === "pascal") return words2.map((word) => firstCharacterUpper(word, locale)).join("");
|
|
3088
|
-
if (style === "snake") return words2.join("_");
|
|
3089
|
-
if (style === "kebab") return words2.join("-");
|
|
3090
|
-
if (style === "constant") return words2.map((word) => word.toLocaleUpperCase(locale)).join("_");
|
|
3091
|
-
throw new Error(`Unsupported case style: ${String(style)}.`);
|
|
3092
|
-
}
|
|
3093
|
-
function escapeRegex(value) {
|
|
3094
|
-
return value.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
|
|
3095
|
-
}
|
|
3096
|
-
function diffOperations(left, right) {
|
|
3097
|
-
if (left.length > MAX_DIFF_LINES || right.length > MAX_DIFF_LINES) throw new RangeError(`Text diff supports at most ${MAX_DIFF_LINES.toLocaleString()} lines per side.`);
|
|
3098
|
-
if (left.length * right.length > MAX_DIFF_CELLS) throw new RangeError("Text diff inputs are too large to compare safely; reduce the number of lines.");
|
|
3099
|
-
const table = Array.from({ length: left.length + 1 }, () => new Uint32Array(right.length + 1));
|
|
3100
|
-
for (let i2 = left.length - 1; i2 >= 0; i2 -= 1) {
|
|
3101
|
-
for (let j2 = right.length - 1; j2 >= 0; j2 -= 1) table[i2][j2] = left[i2] === right[j2] ? table[i2 + 1][j2 + 1] + 1 : Math.max(table[i2 + 1][j2], table[i2][j2 + 1]);
|
|
3102
|
-
}
|
|
3103
|
-
const operations = [];
|
|
3104
|
-
let i = 0;
|
|
3105
|
-
let j = 0;
|
|
3106
|
-
while (i < left.length && j < right.length) {
|
|
3107
|
-
if (left[i] === right[j]) {
|
|
3108
|
-
operations.push({ type: "equal", text: left[i] });
|
|
3109
|
-
i += 1;
|
|
3110
|
-
j += 1;
|
|
3111
|
-
} else if (table[i + 1][j] >= table[i][j + 1]) {
|
|
3112
|
-
operations.push({ type: "deletion", text: left[i] });
|
|
3113
|
-
i += 1;
|
|
3114
|
-
} else {
|
|
3115
|
-
operations.push({ type: "addition", text: right[j] });
|
|
3116
|
-
j += 1;
|
|
3117
|
-
}
|
|
3118
|
-
}
|
|
3119
|
-
while (i < left.length) operations.push({ type: "deletion", text: left[i++] });
|
|
3120
|
-
while (j < right.length) operations.push({ type: "addition", text: right[j++] });
|
|
3121
|
-
return operations;
|
|
3122
|
-
}
|
|
3123
|
-
function buildUnified(operations) {
|
|
3124
|
-
let oldLine = 1;
|
|
3125
|
-
let newLine = 1;
|
|
3126
|
-
let added = 0;
|
|
3127
|
-
let removed = 0;
|
|
3128
|
-
const lines = operations.map((operation) => {
|
|
3129
|
-
if (operation.type === "equal") return { type: "context", text: operation.text, oldLine: oldLine++, newLine: newLine++ };
|
|
3130
|
-
if (operation.type === "deletion") {
|
|
3131
|
-
removed += 1;
|
|
3132
|
-
return { type: "deletion", text: operation.text, oldLine: oldLine++, newLine: null };
|
|
3133
|
-
}
|
|
3134
|
-
added += 1;
|
|
3135
|
-
return { type: "addition", text: operation.text, oldLine: null, newLine: newLine++ };
|
|
3136
|
-
});
|
|
3137
|
-
const text2 = ["--- left", "+++ right", ...lines.map((line) => `${line.type === "context" ? " " : line.type === "deletion" ? "-" : "+"}${line.text}`)].join("\n");
|
|
3138
|
-
return { lines, text: text2, added, removed };
|
|
3139
|
-
}
|
|
3140
|
-
function buildSideBySide(operations) {
|
|
3141
|
-
const rows = [];
|
|
3142
|
-
let leftLine = 1;
|
|
3143
|
-
let rightLine = 1;
|
|
3144
|
-
for (let i = 0; i < operations.length; i += 1) {
|
|
3145
|
-
const operation = operations[i];
|
|
3146
|
-
if (operation.type === "equal") {
|
|
3147
|
-
rows.push({ type: "equal", left: { line: leftLine++, text: operation.text }, right: { line: rightLine++, text: operation.text } });
|
|
3148
|
-
continue;
|
|
3149
|
-
}
|
|
3150
|
-
const deleted = [];
|
|
3151
|
-
const added = [];
|
|
3152
|
-
while (i < operations.length && operations[i].type !== "equal") {
|
|
3153
|
-
if (operations[i].type === "deletion") deleted.push(operations[i].text);
|
|
3154
|
-
else added.push(operations[i].text);
|
|
3155
|
-
i += 1;
|
|
3156
|
-
}
|
|
3157
|
-
i -= 1;
|
|
3158
|
-
const width = Math.max(deleted.length, added.length);
|
|
3159
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
3160
|
-
const left = deleted[offset];
|
|
3161
|
-
const right = added[offset];
|
|
3162
|
-
rows.push({
|
|
3163
|
-
type: left !== void 0 && right !== void 0 ? "changed" : left !== void 0 ? "removed" : "added",
|
|
3164
|
-
left: left === void 0 ? null : { line: leftLine++, text: left },
|
|
3165
|
-
right: right === void 0 ? null : { line: rightLine++, text: right }
|
|
3166
|
-
});
|
|
3167
|
-
}
|
|
3168
|
-
}
|
|
3169
|
-
return rows;
|
|
3170
|
-
}
|
|
3171
|
-
function textDiff(left, right) {
|
|
3172
|
-
const leftParsed = parseLines(left);
|
|
3173
|
-
const rightParsed = parseLines(right);
|
|
3174
|
-
const operations = diffOperations(leftParsed.lines, rightParsed.lines);
|
|
3175
|
-
const unified = buildUnified(operations);
|
|
3176
|
-
const sideBySide = buildSideBySide(operations);
|
|
3177
|
-
return {
|
|
3178
|
-
changed: unified.added > 0 || unified.removed > 0,
|
|
3179
|
-
added: unified.added,
|
|
3180
|
-
removed: unified.removed,
|
|
3181
|
-
unified: unified.text,
|
|
3182
|
-
unifiedLines: unified.lines,
|
|
3183
|
-
sideBySide,
|
|
3184
|
-
unifiedData: unified.lines,
|
|
3185
|
-
sideBySideData: sideBySide
|
|
3186
|
-
};
|
|
3187
|
-
}
|
|
3188
|
-
function diffText(left, right) {
|
|
3189
|
-
return textDiff(left, right).unified;
|
|
3190
|
-
}
|
|
3191
|
-
function slugify(value, separator = "-") {
|
|
3192
|
-
assertText(value);
|
|
3193
|
-
assertText(separator, "separator");
|
|
3194
|
-
if (!separator || separator.length > 16 || /[\p{L}\p{N}]/u.test(separator)) throw new Error("Slug separator must be 1\u201316 non-alphanumeric characters.");
|
|
3195
|
-
return value.normalize("NFKD").replace(/[\u0300-\u036f]/gu, "").toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, separator).replace(new RegExp(`(?:${escapeRegex(separator)})+`, "g"), separator).replace(new RegExp(`^${escapeRegex(separator)}|${escapeRegex(separator)}$`, "g"), "");
|
|
3196
|
-
}
|
|
3197
|
-
|
|
3198
|
-
// lib/tools/date-time-station.ts
|
|
3199
|
-
var SECOND = 1e3;
|
|
3200
|
-
var MINUTE = 60 * SECOND;
|
|
3201
|
-
var HOUR = 60 * MINUTE;
|
|
3202
|
-
var DAY = 24 * HOUR;
|
|
3203
|
-
var MIN_DATE = -621355968e5;
|
|
3204
|
-
var MAX_DATE = 253402300799999;
|
|
3205
|
-
function integer(value, name, min, max) {
|
|
3206
|
-
if (!Number.isInteger(value) || value < min || value > max) throw new RangeError(`${name} must be an integer between ${min} and ${max}.`);
|
|
3207
|
-
return value;
|
|
3208
|
-
}
|
|
3209
|
-
function inputText(value, name = "Date", max = 256) {
|
|
3210
|
-
if (typeof value !== "string") throw new TypeError(`${name} must be text.`);
|
|
3211
|
-
const text2 = value.trim();
|
|
3212
|
-
if (!text2) throw new Error(`${name} cannot be empty.`);
|
|
3213
|
-
if (text2.length > max) throw new RangeError(`${name} must be at most ${max} characters.`);
|
|
3214
|
-
return text2;
|
|
3215
|
-
}
|
|
3216
|
-
function isGregorianLeapYear(year) {
|
|
3217
|
-
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
3218
|
-
}
|
|
3219
|
-
function daysInMonth(year, month) {
|
|
3220
|
-
return [31, isGregorianLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
3221
|
-
}
|
|
3222
|
-
function validateParts(parts) {
|
|
3223
|
-
integer(parts.year, "Year", 1, 9999);
|
|
3224
|
-
integer(parts.month, "Month", 1, 12);
|
|
3225
|
-
integer(parts.day, "Day", 1, daysInMonth(parts.year, parts.month));
|
|
3226
|
-
integer(parts.hour, "Hour", 0, 23);
|
|
3227
|
-
integer(parts.minute, "Minute", 0, 59);
|
|
3228
|
-
integer(parts.second, "Second", 0, 59);
|
|
3229
|
-
integer(parts.millisecond, "Millisecond", 0, 999);
|
|
3230
|
-
}
|
|
3231
|
-
function utcMilliseconds(parts) {
|
|
3232
|
-
const date = /* @__PURE__ */ new Date(0);
|
|
3233
|
-
date.setUTCFullYear(parts.year, parts.month - 1, parts.day);
|
|
3234
|
-
date.setUTCHours(parts.hour ?? 0, parts.minute ?? 0, parts.second ?? 0, parts.millisecond ?? 0);
|
|
3235
|
-
return date.getTime();
|
|
3236
|
-
}
|
|
3237
|
-
function checkedDate(milliseconds) {
|
|
3238
|
-
if (!Number.isFinite(milliseconds)) throw new RangeError("Date or timestamp must be finite and valid.");
|
|
3239
|
-
if (milliseconds < MIN_DATE || milliseconds > MAX_DATE) throw new RangeError("Date must be within Gregorian years 0001\u20139999 in UTC.");
|
|
3240
|
-
return new Date(milliseconds);
|
|
3241
|
-
}
|
|
3242
|
-
function timestampUnit(unit) {
|
|
3243
|
-
if (unit !== "seconds" && unit !== "milliseconds") throw new Error("Timestamp unit must be seconds or milliseconds.");
|
|
3244
|
-
return unit;
|
|
3245
|
-
}
|
|
3246
|
-
function timestampToDate(value, unit = "seconds") {
|
|
3247
|
-
timestampUnit(unit);
|
|
3248
|
-
let number;
|
|
3249
|
-
if (typeof value === "string") {
|
|
3250
|
-
const text2 = inputText(value, "Timestamp");
|
|
3251
|
-
if (!/^[+-]?\d+(?:\.\d+)?$/.test(text2)) throw new Error("Timestamp must be a decimal number, without exponent notation.");
|
|
3252
|
-
number = Number(text2);
|
|
3253
|
-
} else if (typeof value === "number") number = value;
|
|
3254
|
-
else throw new TypeError("Timestamp must be a number or numeric text.");
|
|
3255
|
-
if (!Number.isFinite(number)) throw new RangeError("Timestamp must be finite.");
|
|
3256
|
-
if (unit === "milliseconds" && !Number.isInteger(number)) throw new RangeError("A millisecond timestamp must be an integer.");
|
|
3257
|
-
return checkedDate(unit === "seconds" ? Math.round(number * SECOND) : number);
|
|
3258
|
-
}
|
|
3259
|
-
function zoneFormatter(timeZone) {
|
|
3260
|
-
const zone = inputText(timeZone, "Time zone", 128);
|
|
3261
|
-
if (/^[+-]/.test(zone)) throw new Error("Use an IANA time zone such as America/New_York, Asia/Kolkata, or UTC.");
|
|
3262
|
-
try {
|
|
3263
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
3264
|
-
timeZone: zone,
|
|
3265
|
-
calendar: "gregory",
|
|
3266
|
-
numberingSystem: "latn",
|
|
3267
|
-
era: "short",
|
|
3268
|
-
year: "numeric",
|
|
3269
|
-
month: "2-digit",
|
|
3270
|
-
day: "2-digit",
|
|
3271
|
-
hour: "2-digit",
|
|
3272
|
-
minute: "2-digit",
|
|
3273
|
-
second: "2-digit",
|
|
3274
|
-
hourCycle: "h23"
|
|
3275
|
-
});
|
|
3276
|
-
} catch {
|
|
3277
|
-
throw new Error(`Unknown or unsupported IANA time zone: ${zone}.`);
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
function validateTimeZone(timeZone) {
|
|
3281
|
-
return zoneFormatter(timeZone).resolvedOptions().timeZone;
|
|
3282
|
-
}
|
|
3283
|
-
function zoneParts(milliseconds, formatter) {
|
|
3284
|
-
const fields = Object.fromEntries(formatter.formatToParts(new Date(milliseconds)).map((part) => [part.type, part.value]));
|
|
3285
|
-
return {
|
|
3286
|
-
year: fields.era === "BC" ? 1 - Number(fields.year) : Number(fields.year),
|
|
3287
|
-
month: Number(fields.month),
|
|
3288
|
-
day: Number(fields.day),
|
|
3289
|
-
hour: Number(fields.hour),
|
|
3290
|
-
minute: Number(fields.minute),
|
|
3291
|
-
second: Number(fields.second),
|
|
3292
|
-
millisecond: (milliseconds % SECOND + SECOND) % SECOND
|
|
3293
|
-
};
|
|
3294
|
-
}
|
|
3295
|
-
function disambiguation(value = "reject") {
|
|
3296
|
-
if (!["reject", "earlier", "later"].includes(value)) throw new Error("Time disambiguation must be reject, earlier, or later.");
|
|
3297
|
-
return value;
|
|
3298
|
-
}
|
|
3299
|
-
function sameParts(left, right) {
|
|
3300
|
-
return left.year === right.year && left.month === right.month && left.day === right.day && left.hour === right.hour && left.minute === right.minute && left.second === right.second && left.millisecond === right.millisecond;
|
|
3301
|
-
}
|
|
3302
|
-
function localToDate(parts, formatter, choice) {
|
|
3303
|
-
const wall = utcMilliseconds(parts);
|
|
3304
|
-
const offsets = /* @__PURE__ */ new Set();
|
|
3305
|
-
for (let hours = -48; hours <= 48; hours += 12) {
|
|
3306
|
-
const sample = wall + hours * HOUR;
|
|
3307
|
-
offsets.add(utcMilliseconds(zoneParts(sample, formatter)) - sample);
|
|
3308
|
-
}
|
|
3309
|
-
const matches = [...offsets].map((offset) => wall - offset).filter((candidate) => sameParts(zoneParts(candidate, formatter), parts)).sort((a, b) => a - b);
|
|
3310
|
-
const zone = formatter.resolvedOptions().timeZone;
|
|
3311
|
-
if (!matches.length) throw new Error(`This local time does not exist in ${zone} because of a time-zone clock change. Choose another time or an explicit UTC offset.`);
|
|
3312
|
-
if (matches.length > 1 && choice === "reject") throw new Error(`This local time occurs twice in ${zone}. Choose earlier or later, or supply an explicit UTC offset.`);
|
|
3313
|
-
return checkedDate(choice === "later" ? matches[matches.length - 1] : matches[0]);
|
|
3314
|
-
}
|
|
3315
|
-
function offsetMilliseconds(value) {
|
|
3316
|
-
if (/^z$/i.test(value)) return 0;
|
|
3317
|
-
const match = /^([+-])(\d{2}):?(\d{2})$/.exec(value);
|
|
3318
|
-
if (!match) throw new Error("UTC offset must be Z or \xB1HH:mm.");
|
|
3319
|
-
const hours = integer(Number(match[2]), "Offset hour", 0, 23);
|
|
3320
|
-
const minutes = integer(Number(match[3]), "Offset minute", 0, 59);
|
|
3321
|
-
if (match[1] === "-" && hours === 0 && minutes === 0) throw new Error("The unknown UTC offset -00:00 cannot identify an instant. Use Z or a known offset.");
|
|
3322
|
-
return (match[1] === "-" ? -1 : 1) * (hours * HOUR + minutes * MINUTE);
|
|
3323
|
-
}
|
|
3324
|
-
function partsToDate(parts, offset, options) {
|
|
3325
|
-
validateParts(parts);
|
|
3326
|
-
const choice = disambiguation(options.disambiguation);
|
|
3327
|
-
const formatter = zoneFormatter(options.timeZone ?? "UTC");
|
|
3328
|
-
return offset ? checkedDate(utcMilliseconds(parts) - offsetMilliseconds(offset)) : localToDate(parts, formatter, choice);
|
|
3329
|
-
}
|
|
3330
|
-
function parseDateTime(value, options = {}) {
|
|
3331
|
-
timestampUnit(options.timestampUnit ?? "milliseconds");
|
|
3332
|
-
disambiguation(options.disambiguation);
|
|
3333
|
-
if (options.timeZone !== void 0) validateTimeZone(options.timeZone);
|
|
3334
|
-
if (value instanceof Date) return checkedDate(value.getTime());
|
|
3335
|
-
if (typeof value === "number") return timestampToDate(value, options.timestampUnit ?? "milliseconds");
|
|
3336
|
-
const text2 = inputText(value);
|
|
3337
|
-
if (/^[+-]?\d+(?:\.\d+)?$/.test(text2)) return timestampToDate(text2, options.timestampUnit ?? "milliseconds");
|
|
3338
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})(?:[Tt ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?([Zz]|[+-]\d{2}:?\d{2})?)?$/.exec(text2);
|
|
3339
|
-
if (!match) throw new Error("Use YYYY-MM-DD, an ISO date/time with up to 3 fractional digits, or an explicit numeric timestamp.");
|
|
3340
|
-
return partsToDate({
|
|
3341
|
-
year: Number(match[1]),
|
|
3342
|
-
month: Number(match[2]),
|
|
3343
|
-
day: Number(match[3]),
|
|
3344
|
-
hour: Number(match[4] ?? 0),
|
|
3345
|
-
minute: Number(match[5] ?? 0),
|
|
3346
|
-
second: Number(match[6] ?? 0),
|
|
3347
|
-
millisecond: Number((match[7] ?? "").padEnd(3, "0"))
|
|
3348
|
-
}, match[8], options);
|
|
3349
|
-
}
|
|
3350
|
-
function pad2(value, length = 2) {
|
|
3351
|
-
return String(value).padStart(length, "0");
|
|
3352
|
-
}
|
|
3353
|
-
function calendarText(parts) {
|
|
3354
|
-
return `${pad2(parts.year, 4)}-${pad2(parts.month)}-${pad2(parts.day)}`;
|
|
3355
|
-
}
|
|
3356
|
-
function clockText(parts) {
|
|
3357
|
-
return `${pad2(parts.hour)}:${pad2(parts.minute)}:${pad2(parts.second)}.${pad2(parts.millisecond, 3)}`;
|
|
3358
|
-
}
|
|
3359
|
-
function offsetText(milliseconds) {
|
|
3360
|
-
if (!milliseconds) return "Z";
|
|
3361
|
-
const seconds = Math.abs(milliseconds) / SECOND;
|
|
3362
|
-
const hours = Math.floor(seconds / 3600);
|
|
3363
|
-
const minutes = Math.floor(seconds % 3600 / 60);
|
|
3364
|
-
const remainder = seconds % 60;
|
|
3365
|
-
return `${milliseconds < 0 ? "-" : "+"}${pad2(hours)}:${pad2(minutes)}${remainder ? `:${pad2(remainder)}` : ""}`;
|
|
3366
|
-
}
|
|
3367
|
-
function getZonedDateTime(value, timeZone = "UTC", options = {}) {
|
|
3368
|
-
const date = parseDateTime(value, options);
|
|
3369
|
-
const formatter = zoneFormatter(timeZone);
|
|
3370
|
-
const parts = zoneParts(date.getTime(), formatter);
|
|
3371
|
-
validateParts(parts);
|
|
3372
|
-
const offset = utcMilliseconds(parts) - date.getTime();
|
|
3373
|
-
const renderedOffset = offsetText(offset);
|
|
3374
|
-
return {
|
|
3375
|
-
...parts,
|
|
3376
|
-
timeZone: formatter.resolvedOptions().timeZone,
|
|
3377
|
-
offsetMinutes: offset / MINUTE,
|
|
3378
|
-
offset: renderedOffset,
|
|
3379
|
-
unixMilliseconds: date.getTime(),
|
|
3380
|
-
iso: date.toISOString(),
|
|
3381
|
-
dateTime: `${calendarText(parts)}T${clockText(parts)}${renderedOffset}`
|
|
3382
|
-
};
|
|
3383
|
-
}
|
|
3384
|
-
function formatRfc3339(value, timeZoneOrOptions = "UTC", options = {}) {
|
|
3385
|
-
const timeZone = typeof timeZoneOrOptions === "string" ? timeZoneOrOptions : timeZoneOrOptions.timeZone ?? "UTC";
|
|
3386
|
-
const parseOptions = typeof timeZoneOrOptions === "string" ? options : timeZoneOrOptions;
|
|
3387
|
-
const zoned = getZonedDateTime(value, timeZone, parseOptions);
|
|
3388
|
-
if (!Number.isInteger(zoned.offsetMinutes)) throw new Error("RFC3339 cannot represent this historical sub-minute UTC offset. Format in UTC instead.");
|
|
3389
|
-
return zoned.dateTime;
|
|
3390
|
-
}
|
|
3391
|
-
function convertTimeZone(value, targetTimeZone, options = {}) {
|
|
3392
|
-
const parseOptions = typeof options === "string" ? { timeZone: options } : options;
|
|
3393
|
-
return formatRfc3339(value, targetTimeZone, parseOptions);
|
|
3394
|
-
}
|
|
3395
|
-
function convertBetweenTimeZones(value, sourceTimeZone, targetTimeZone) {
|
|
3396
|
-
return convertTimeZone(value, targetTimeZone, { timeZone: sourceTimeZone });
|
|
3397
|
-
}
|
|
3398
|
-
var relativeUnits = [
|
|
3399
|
-
{ unit: "year", milliseconds: 365 * DAY },
|
|
3400
|
-
{ unit: "quarter", milliseconds: 91 * DAY },
|
|
3401
|
-
{ unit: "month", milliseconds: 30 * DAY },
|
|
3402
|
-
{ unit: "week", milliseconds: 7 * DAY },
|
|
3403
|
-
{ unit: "day", milliseconds: DAY },
|
|
3404
|
-
{ unit: "hour", milliseconds: HOUR },
|
|
3405
|
-
{ unit: "minute", milliseconds: MINUTE },
|
|
3406
|
-
{ unit: "second", milliseconds: SECOND }
|
|
3407
|
-
];
|
|
3408
|
-
function calendarCompare(left, right) {
|
|
3409
|
-
return utcMilliseconds(left) - utcMilliseconds(right);
|
|
3410
|
-
}
|
|
3411
|
-
function calendarDayNumber(date) {
|
|
3412
|
-
return Math.floor(utcMilliseconds(date) / DAY);
|
|
3413
|
-
}
|
|
3414
|
-
function calendarFromDayNumber(day) {
|
|
3415
|
-
const date = new Date(day * DAY);
|
|
3416
|
-
return { year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() };
|
|
3417
|
-
}
|
|
3418
|
-
function calendarWeekday(date) {
|
|
3419
|
-
return new Date(utcMilliseconds(date)).getUTCDay();
|
|
3420
|
-
}
|
|
3421
|
-
function dateCalendar(value, options) {
|
|
3422
|
-
const zoned = getZonedDateTime(value, options.timeZone ?? "UTC", { timeZone: options.timeZone ?? "UTC" });
|
|
3423
|
-
return { year: zoned.year, month: zoned.month, day: zoned.day };
|
|
3424
|
-
}
|
|
3425
|
-
function weekdaysInclusive(start, end) {
|
|
3426
|
-
if (calendarCompare(start, end) > 0) return -weekdaysInclusive(end, start);
|
|
3427
|
-
const first = calendarDayNumber(start);
|
|
3428
|
-
const total = calendarDayNumber(end) - first + 1;
|
|
3429
|
-
const weeks = Math.floor(total / 7);
|
|
3430
|
-
let count = weeks * 5;
|
|
3431
|
-
for (let day = first + weeks * 7; day <= calendarDayNumber(end); day += 1) {
|
|
3432
|
-
const weekday = new Date(day * DAY).getUTCDay();
|
|
3433
|
-
if (weekday !== 0 && weekday !== 6) count += 1;
|
|
3434
|
-
}
|
|
3435
|
-
return count;
|
|
3436
|
-
}
|
|
3437
|
-
function businessDaysBetween(start, end, options = {}) {
|
|
3438
|
-
const left = dateCalendar(start, options);
|
|
3439
|
-
const right = dateCalendar(end, options);
|
|
3440
|
-
if (calendarCompare(left, right) === 0) return (options.inclusiveStart ?? true) && (options.inclusiveEnd ?? false) && calendarWeekday(left) !== 0 && calendarWeekday(left) !== 6 ? 1 : 0;
|
|
3441
|
-
const direction = calendarCompare(left, right) < 0 ? 1 : -1;
|
|
3442
|
-
const earlier = direction > 0 ? left : right;
|
|
3443
|
-
const later = direction > 0 ? right : left;
|
|
3444
|
-
let first = calendarDayNumber(earlier);
|
|
3445
|
-
let last = calendarDayNumber(later);
|
|
3446
|
-
const includeEarlier = direction > 0 ? options.inclusiveStart ?? true : options.inclusiveEnd ?? false;
|
|
3447
|
-
const includeLater = direction > 0 ? options.inclusiveEnd ?? false : options.inclusiveStart ?? true;
|
|
3448
|
-
if (!includeEarlier) first += 1;
|
|
3449
|
-
if (!includeLater) last -= 1;
|
|
3450
|
-
if (first > last) return 0;
|
|
3451
|
-
return direction * weekdaysInclusive(calendarFromDayNumber(first), calendarFromDayNumber(last));
|
|
3452
|
-
}
|
|
3453
|
-
|
|
3454
4102
|
// mcp/server.ts
|
|
3455
4103
|
var MCP_TOOLS = [
|
|
3456
4104
|
// ----------------- FREE TOOLS -----------------
|
|
@@ -3611,6 +4259,98 @@ var MCP_TOOLS = [
|
|
|
3611
4259
|
required: ["text"]
|
|
3612
4260
|
}
|
|
3613
4261
|
},
|
|
4262
|
+
{
|
|
4263
|
+
name: "codestation_ulid",
|
|
4264
|
+
description: "Generate lexicographically sortable ULID identifiers (Crockford Base32). [Free Tier]",
|
|
4265
|
+
inputSchema: {
|
|
4266
|
+
type: "object",
|
|
4267
|
+
properties: {
|
|
4268
|
+
count: {
|
|
4269
|
+
type: "integer",
|
|
4270
|
+
description: "Number of ULIDs to generate (1 to 50, default: 1)",
|
|
4271
|
+
minimum: 1,
|
|
4272
|
+
maximum: 50
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
},
|
|
4277
|
+
{
|
|
4278
|
+
name: "codestation_nanoid",
|
|
4279
|
+
description: "Generate compact URL-safe cryptographic NanoIDs with customizable length. [Free Tier]",
|
|
4280
|
+
inputSchema: {
|
|
4281
|
+
type: "object",
|
|
4282
|
+
properties: {
|
|
4283
|
+
length: {
|
|
4284
|
+
type: "integer",
|
|
4285
|
+
description: "Character length (2 to 128, default: 21)",
|
|
4286
|
+
minimum: 2,
|
|
4287
|
+
maximum: 128
|
|
4288
|
+
},
|
|
4289
|
+
count: {
|
|
4290
|
+
type: "integer",
|
|
4291
|
+
description: "Number of IDs to generate (1 to 50, default: 1)",
|
|
4292
|
+
minimum: 1,
|
|
4293
|
+
maximum: 50
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
},
|
|
4298
|
+
{
|
|
4299
|
+
name: "codestation_json_diff",
|
|
4300
|
+
description: "Compute a structural key-by-key diff between two JSON documents. [Free Tier]",
|
|
4301
|
+
inputSchema: {
|
|
4302
|
+
type: "object",
|
|
4303
|
+
properties: {
|
|
4304
|
+
left: { type: "string", description: "Original JSON document" },
|
|
4305
|
+
right: { type: "string", description: "Updated JSON document" }
|
|
4306
|
+
},
|
|
4307
|
+
required: ["left", "right"]
|
|
4308
|
+
}
|
|
4309
|
+
},
|
|
4310
|
+
{
|
|
4311
|
+
name: "codestation_json_path",
|
|
4312
|
+
description: "Query and extract matching nodes from JSON using JSONPath (e.g. $.users[*].name, $[0].id). [Free Tier]",
|
|
4313
|
+
inputSchema: {
|
|
4314
|
+
type: "object",
|
|
4315
|
+
properties: {
|
|
4316
|
+
json: { type: "string", description: "Valid JSON payload to query" },
|
|
4317
|
+
expression: { type: "string", description: "JSONPath expression starting with $" }
|
|
4318
|
+
},
|
|
4319
|
+
required: ["json", "expression"]
|
|
4320
|
+
}
|
|
4321
|
+
},
|
|
4322
|
+
{
|
|
4323
|
+
name: "codestation_html_codec",
|
|
4324
|
+
description: "Encode or decode HTML entities (<, >, &, numeric character references). [Free Tier]",
|
|
4325
|
+
inputSchema: {
|
|
4326
|
+
type: "object",
|
|
4327
|
+
properties: {
|
|
4328
|
+
text: { type: "string", description: "Text or HTML entity string" },
|
|
4329
|
+
action: {
|
|
4330
|
+
type: "string",
|
|
4331
|
+
enum: ["encode", "decode"],
|
|
4332
|
+
description: "Whether to encode or decode HTML entities"
|
|
4333
|
+
}
|
|
4334
|
+
},
|
|
4335
|
+
required: ["text", "action"]
|
|
4336
|
+
}
|
|
4337
|
+
},
|
|
4338
|
+
{
|
|
4339
|
+
name: "codestation_csv_json",
|
|
4340
|
+
description: "Convert CSV tables (with header row) to JSON arrays or JSON arrays of objects to CSV. [Free Tier]",
|
|
4341
|
+
inputSchema: {
|
|
4342
|
+
type: "object",
|
|
4343
|
+
properties: {
|
|
4344
|
+
input: { type: "string", description: "CSV or JSON input text" },
|
|
4345
|
+
direction: {
|
|
4346
|
+
type: "string",
|
|
4347
|
+
enum: ["csv-to-json", "json-to-csv"],
|
|
4348
|
+
description: "Conversion direction"
|
|
4349
|
+
}
|
|
4350
|
+
},
|
|
4351
|
+
required: ["input", "direction"]
|
|
4352
|
+
}
|
|
4353
|
+
},
|
|
3614
4354
|
// ----------------- PRO TOOLS (₹199 / $2.99) -----------------
|
|
3615
4355
|
{
|
|
3616
4356
|
name: "codestation_hash",
|
|
@@ -3686,6 +4426,34 @@ var MCP_TOOLS = [
|
|
|
3686
4426
|
required: ["expression"]
|
|
3687
4427
|
}
|
|
3688
4428
|
},
|
|
4429
|
+
{
|
|
4430
|
+
name: "codestation_cron_next_runs",
|
|
4431
|
+
description: "Calculate upcoming execution timestamps for a cron expression in any IANA timezone. [Pro Tier: \u20B9199/mo or $2.99/mo]",
|
|
4432
|
+
inputSchema: {
|
|
4433
|
+
type: "object",
|
|
4434
|
+
properties: {
|
|
4435
|
+
expression: {
|
|
4436
|
+
type: "string",
|
|
4437
|
+
description: "5-field (or 6-field seconds-first) cron expression"
|
|
4438
|
+
},
|
|
4439
|
+
count: {
|
|
4440
|
+
type: "integer",
|
|
4441
|
+
description: "Number of upcoming runs to return (1 to 20, default: 5)",
|
|
4442
|
+
minimum: 1,
|
|
4443
|
+
maximum: 20
|
|
4444
|
+
},
|
|
4445
|
+
timeZone: {
|
|
4446
|
+
type: "string",
|
|
4447
|
+
description: "IANA timezone (default: 'UTC')"
|
|
4448
|
+
},
|
|
4449
|
+
startFrom: {
|
|
4450
|
+
type: "string",
|
|
4451
|
+
description: "Optional ISO 8601 reference timestamp (e.g. '2026-10-09T14:30:00Z')"
|
|
4452
|
+
}
|
|
4453
|
+
},
|
|
4454
|
+
required: ["expression"]
|
|
4455
|
+
}
|
|
4456
|
+
},
|
|
3689
4457
|
{
|
|
3690
4458
|
name: "codestation_timezone_convert",
|
|
3691
4459
|
description: "Accurately convert a date/time string from one IANA timezone to another using runtime IANA rules. [Pro Tier: \u20B9199/mo or $2.99/mo]",
|
|
@@ -3881,6 +4649,9 @@ async function executeMcpTool(name, args = {}, license) {
|
|
|
3881
4649
|
const text2 = String(args.text ?? "");
|
|
3882
4650
|
const action = String(args.action ?? "encode");
|
|
3883
4651
|
const urlSafe = Boolean(args.urlSafe);
|
|
4652
|
+
if (action !== "encode" && action !== "decode") {
|
|
4653
|
+
throw new Error(`Invalid Base64 action "${action}". Expected "encode" or "decode".`);
|
|
4654
|
+
}
|
|
3884
4655
|
if (action === "encode") {
|
|
3885
4656
|
if (urlSafe) {
|
|
3886
4657
|
outputText = encodeBase64Url(text2);
|
|
@@ -3891,7 +4662,11 @@ async function executeMcpTool(name, args = {}, license) {
|
|
|
3891
4662
|
if (urlSafe) {
|
|
3892
4663
|
outputText = decodeBase64Url(text2);
|
|
3893
4664
|
} else {
|
|
3894
|
-
|
|
4665
|
+
const cleaned = text2.replace(/\s+/g, "");
|
|
4666
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(cleaned)) {
|
|
4667
|
+
throw new Error("Invalid standard Base64 input.");
|
|
4668
|
+
}
|
|
4669
|
+
outputText = Buffer.from(cleaned, "base64").toString("utf-8");
|
|
3895
4670
|
}
|
|
3896
4671
|
}
|
|
3897
4672
|
break;
|
|
@@ -3940,6 +4715,76 @@ async function executeMcpTool(name, args = {}, license) {
|
|
|
3940
4715
|
outputText = slugify(String(args.text ?? ""), String(args.separator ?? "-"));
|
|
3941
4716
|
break;
|
|
3942
4717
|
}
|
|
4718
|
+
case "codestation_ulid": {
|
|
4719
|
+
const count = args.count === void 0 ? 1 : Number(args.count);
|
|
4720
|
+
if (!Number.isInteger(count) || count < 1 || count > 50) {
|
|
4721
|
+
throw new RangeError("count must be an integer between 1 and 50.");
|
|
4722
|
+
}
|
|
4723
|
+
const ulids = Array.from({ length: count }, () => ulid());
|
|
4724
|
+
outputText = count === 1 ? ulids[0] : ulids.join("\n");
|
|
4725
|
+
break;
|
|
4726
|
+
}
|
|
4727
|
+
case "codestation_nanoid": {
|
|
4728
|
+
const length = args.length === void 0 ? 21 : Number(args.length);
|
|
4729
|
+
const count = args.count === void 0 ? 1 : Number(args.count);
|
|
4730
|
+
if (!Number.isInteger(length) || length < 2 || length > 128) {
|
|
4731
|
+
throw new RangeError("length must be an integer between 2 and 128.");
|
|
4732
|
+
}
|
|
4733
|
+
if (!Number.isInteger(count) || count < 1 || count > 50) {
|
|
4734
|
+
throw new RangeError("count must be an integer between 1 and 50.");
|
|
4735
|
+
}
|
|
4736
|
+
const ids = Array.from({ length: count }, () => nanoid(length));
|
|
4737
|
+
outputText = count === 1 ? ids[0] : ids.join("\n");
|
|
4738
|
+
break;
|
|
4739
|
+
}
|
|
4740
|
+
case "codestation_json_diff": {
|
|
4741
|
+
const left = args.left;
|
|
4742
|
+
const right = args.right;
|
|
4743
|
+
if (typeof left !== "string" || typeof right !== "string" || !left.trim() || !right.trim()) {
|
|
4744
|
+
throw new Error("Both left and right JSON strings are required.");
|
|
4745
|
+
}
|
|
4746
|
+
outputText = jsonDiff(left, right);
|
|
4747
|
+
break;
|
|
4748
|
+
}
|
|
4749
|
+
case "codestation_json_path": {
|
|
4750
|
+
const json = args.json;
|
|
4751
|
+
const expression = args.expression;
|
|
4752
|
+
if (typeof json !== "string" || !json.trim()) {
|
|
4753
|
+
throw new Error("A JSON string is required.");
|
|
4754
|
+
}
|
|
4755
|
+
if (typeof expression !== "string" || !expression.trim()) {
|
|
4756
|
+
throw new Error("A JSONPath expression starting with $ is required.");
|
|
4757
|
+
}
|
|
4758
|
+
outputText = testJsonPath(json, expression);
|
|
4759
|
+
break;
|
|
4760
|
+
}
|
|
4761
|
+
case "codestation_html_codec": {
|
|
4762
|
+
const text2 = args.text;
|
|
4763
|
+
const action = String(args.action ?? "");
|
|
4764
|
+
if (typeof text2 !== "string") {
|
|
4765
|
+
throw new Error("A text string is required.");
|
|
4766
|
+
}
|
|
4767
|
+
if (action !== "encode" && action !== "decode") {
|
|
4768
|
+
throw new Error(`Invalid action "${action}". Expected "encode" or "decode".`);
|
|
4769
|
+
}
|
|
4770
|
+
outputText = action === "encode" ? encodeHtml(text2) : decodeHtml(text2);
|
|
4771
|
+
break;
|
|
4772
|
+
}
|
|
4773
|
+
case "codestation_csv_json": {
|
|
4774
|
+
const input = args.input;
|
|
4775
|
+
const direction = String(args.direction ?? "");
|
|
4776
|
+
if (typeof input !== "string" || !input.trim()) {
|
|
4777
|
+
throw new Error("Non-empty CSV or JSON input is required.");
|
|
4778
|
+
}
|
|
4779
|
+
if (direction === "csv-to-json") {
|
|
4780
|
+
outputText = csvToJson(input);
|
|
4781
|
+
} else if (direction === "json-to-csv") {
|
|
4782
|
+
outputText = jsonToCsv(input);
|
|
4783
|
+
} else {
|
|
4784
|
+
throw new Error(`Invalid direction "${direction}". Expected "csv-to-json" or "json-to-csv".`);
|
|
4785
|
+
}
|
|
4786
|
+
break;
|
|
4787
|
+
}
|
|
3943
4788
|
// --- Pro tools ---
|
|
3944
4789
|
case "codestation_hash": {
|
|
3945
4790
|
const text2 = String(args.text ?? "");
|
|
@@ -3990,6 +4835,24 @@ async function executeMcpTool(name, args = {}, license) {
|
|
|
3990
4835
|
outputText = explainCron(parsed);
|
|
3991
4836
|
break;
|
|
3992
4837
|
}
|
|
4838
|
+
case "codestation_cron_next_runs": {
|
|
4839
|
+
const expression = String(args.expression ?? "");
|
|
4840
|
+
const count = args.count === void 0 ? 5 : Number(args.count);
|
|
4841
|
+
if (!Number.isInteger(count) || count < 1 || count > 20) {
|
|
4842
|
+
throw new RangeError("count must be an integer between 1 and 20.");
|
|
4843
|
+
}
|
|
4844
|
+
const timeZone = args.timeZone !== void 0 ? String(args.timeZone) : "UTC";
|
|
4845
|
+
let cursor = args.startFrom !== void 0 ? String(args.startFrom) : (/* @__PURE__ */ new Date()).toISOString();
|
|
4846
|
+
const parsed = parseCron(expression);
|
|
4847
|
+
const runs = [];
|
|
4848
|
+
for (let i = 0; i < count; i += 1) {
|
|
4849
|
+
const next = nextCronRun(parsed, cursor, timeZone);
|
|
4850
|
+
runs.push({ run: i + 1, dateTime: next.dateTime, duration: next.duration });
|
|
4851
|
+
cursor = new Date(next.instant).toISOString();
|
|
4852
|
+
}
|
|
4853
|
+
outputText = JSON.stringify({ expression, timeZone, runs }, null, 2);
|
|
4854
|
+
break;
|
|
4855
|
+
}
|
|
3993
4856
|
case "codestation_timezone_convert": {
|
|
3994
4857
|
const dateTime = String(args.dateTime ?? "");
|
|
3995
4858
|
const sourceZone = String(args.sourceTimeZone ?? "UTC");
|
|
@@ -4082,7 +4945,7 @@ function createMcpServer(cliKey) {
|
|
|
4082
4945
|
const server = new Server(
|
|
4083
4946
|
{
|
|
4084
4947
|
name: "codestation-mcp",
|
|
4085
|
-
version: "1.
|
|
4948
|
+
version: "1.3.0"
|
|
4086
4949
|
},
|
|
4087
4950
|
{
|
|
4088
4951
|
capabilities: {
|
|
@@ -4242,159 +5105,6 @@ async function runAutoSetup(licenseKey) {
|
|
|
4242
5105
|
|
|
4243
5106
|
// mcp/cli-tools.ts
|
|
4244
5107
|
import * as fs3 from "node:fs";
|
|
4245
|
-
|
|
4246
|
-
// lib/tools/cron/next-run.ts
|
|
4247
|
-
var DAY2 = 864e5;
|
|
4248
|
-
var SIX_HOURS = 6 * 36e5;
|
|
4249
|
-
var pad3 = (value, width = 2) => String(value).padStart(width, "0");
|
|
4250
|
-
function parseCronReference(reference) {
|
|
4251
|
-
if (reference.length > 64) throw new Error("Reference exceeds the 64-character limit.");
|
|
4252
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/.exec(reference);
|
|
4253
|
-
if (!match) throw new Error("Reference must be an absolute ISO date/time: YYYY-MM-DDTHH:mm[:ss[.sss]] followed by Z or \xB1HH:mm.");
|
|
4254
|
-
const [year, month, day, hour, minute, second] = [match[1], match[2], match[3], match[4], match[5], match[6] ?? "0"].map(Number);
|
|
4255
|
-
if (year < 1970 || year > 2099) throw new Error("Reference years must be between 1970 and 2099.");
|
|
4256
|
-
const days = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
4257
|
-
if (month < 1 || month > 12 || day < 1 || day > days || hour > 23 || minute > 59 || second > 59) throw new Error("Reference contains an impossible calendar date or time.");
|
|
4258
|
-
const milliseconds = Number((match[7] ?? "").padEnd(3, "0"));
|
|
4259
|
-
let offset = 0;
|
|
4260
|
-
if (match[8] !== "Z") {
|
|
4261
|
-
const offsetHour = Number(match[8].slice(1, 3));
|
|
4262
|
-
const offsetMinute = Number(match[8].slice(4, 6));
|
|
4263
|
-
if (offsetMinute > 59 || offsetHour > 14 || offsetHour === 14 && offsetMinute !== 0) throw new Error("Reference offset must be within \xB114:00, with valid minutes.");
|
|
4264
|
-
offset = (offsetHour * 60 + offsetMinute) * 6e4 * (match[8][0] === "-" ? -1 : 1);
|
|
4265
|
-
}
|
|
4266
|
-
const instant = Date.UTC(year, month - 1, day, hour, minute, second, milliseconds) - offset;
|
|
4267
|
-
const utcYear = new Date(instant).getUTCFullYear();
|
|
4268
|
-
if (utcYear < 1970 || utcYear > 2099) throw new Error("Reference instant must fall within UTC years 1970\u20132099.");
|
|
4269
|
-
return instant;
|
|
4270
|
-
}
|
|
4271
|
-
function zoneFormatter2(timezone) {
|
|
4272
|
-
if (!timezone || timezone !== timezone.trim()) throw new Error("Select a nonempty IANA timezone.");
|
|
4273
|
-
if (timezone.length > 128 || !/^[A-Za-z][A-Za-z0-9_+\-/]*$/.test(timezone)) throw new Error("Enter a valid IANA timezone name; numeric offsets are not timezone names.");
|
|
4274
|
-
try {
|
|
4275
|
-
return new Intl.DateTimeFormat("en-GB-u-ca-gregory-nu-latn", {
|
|
4276
|
-
timeZone: timezone,
|
|
4277
|
-
year: "numeric",
|
|
4278
|
-
month: "2-digit",
|
|
4279
|
-
day: "2-digit",
|
|
4280
|
-
hour: "2-digit",
|
|
4281
|
-
minute: "2-digit",
|
|
4282
|
-
second: "2-digit",
|
|
4283
|
-
hourCycle: "h23"
|
|
4284
|
-
});
|
|
4285
|
-
} catch {
|
|
4286
|
-
throw new Error("Timezone is not a recognized IANA timezone in this runtime.");
|
|
4287
|
-
}
|
|
4288
|
-
}
|
|
4289
|
-
function wallTime(formatter, instant) {
|
|
4290
|
-
const parts = formatter.formatToParts(instant);
|
|
4291
|
-
const get = (name) => Number(parts.find((part) => part.type === name)?.value);
|
|
4292
|
-
return { year: get("year"), month: get("month"), day: get("day"), hour: get("hour"), minute: get("minute"), second: get("second") };
|
|
4293
|
-
}
|
|
4294
|
-
function offsetAt(formatter, instant) {
|
|
4295
|
-
const wholeSecond = Math.floor(instant / 1e3) * 1e3;
|
|
4296
|
-
const wall = wallTime(formatter, wholeSecond);
|
|
4297
|
-
return Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second) - wholeSecond;
|
|
4298
|
-
}
|
|
4299
|
-
function offsetIntervals(formatter, midnight) {
|
|
4300
|
-
const start = midnight - 2 * DAY2;
|
|
4301
|
-
const end = midnight + 3 * DAY2;
|
|
4302
|
-
const intervals = [];
|
|
4303
|
-
let intervalStart = start;
|
|
4304
|
-
let priorOffset = offsetAt(formatter, start);
|
|
4305
|
-
for (let probe = start + SIX_HOURS; probe <= end; probe += SIX_HOURS) {
|
|
4306
|
-
const nextOffset = offsetAt(formatter, probe);
|
|
4307
|
-
if (nextOffset !== priorOffset) {
|
|
4308
|
-
let low = probe - SIX_HOURS;
|
|
4309
|
-
let high = probe;
|
|
4310
|
-
while (high - low > 1e3) {
|
|
4311
|
-
const middle = Math.floor((low + high) / 2e3) * 1e3;
|
|
4312
|
-
if (offsetAt(formatter, middle) === priorOffset) low = middle;
|
|
4313
|
-
else high = middle;
|
|
4314
|
-
}
|
|
4315
|
-
intervals.push({ start: intervalStart, end: high, offset: priorOffset });
|
|
4316
|
-
intervalStart = high;
|
|
4317
|
-
priorOffset = nextOffset;
|
|
4318
|
-
}
|
|
4319
|
-
}
|
|
4320
|
-
intervals.push({ start: intervalStart, end, offset: priorOffset });
|
|
4321
|
-
return intervals;
|
|
4322
|
-
}
|
|
4323
|
-
function selectedSecond(cron, lower, upper) {
|
|
4324
|
-
if (lower >= upper || lower >= 86400) return void 0;
|
|
4325
|
-
lower = Math.max(0, Math.ceil(lower));
|
|
4326
|
-
const firstHour = Math.floor(lower / 3600);
|
|
4327
|
-
for (const hour of cron.hour.values) {
|
|
4328
|
-
if (hour < firstHour) continue;
|
|
4329
|
-
const firstMinute = hour === firstHour ? Math.floor(lower % 3600 / 60) : 0;
|
|
4330
|
-
for (const minute of cron.minute.values) {
|
|
4331
|
-
if (minute < firstMinute) continue;
|
|
4332
|
-
const base = hour * 3600 + minute * 60;
|
|
4333
|
-
if (base >= upper) return void 0;
|
|
4334
|
-
const second = cron.second.values.find((value) => base + value >= lower);
|
|
4335
|
-
if (second !== void 0) return base + second < upper ? base + second : void 0;
|
|
4336
|
-
}
|
|
4337
|
-
}
|
|
4338
|
-
return void 0;
|
|
4339
|
-
}
|
|
4340
|
-
function formatCronDuration(milliseconds) {
|
|
4341
|
-
if (!Number.isSafeInteger(milliseconds)) throw new Error("Duration is outside supported integer precision.");
|
|
4342
|
-
const sign = milliseconds < 0 ? "-" : "+";
|
|
4343
|
-
let remainder = Math.abs(milliseconds);
|
|
4344
|
-
const pieces = [];
|
|
4345
|
-
for (const [size, name] of [[DAY2, "day"], [36e5, "hour"], [6e4, "minute"], [1e3, "second"], [1, "millisecond"]]) {
|
|
4346
|
-
const count = Math.floor(remainder / size);
|
|
4347
|
-
remainder %= size;
|
|
4348
|
-
if (count) pieces.push(`${count} ${name}${count === 1 ? "" : "s"}`);
|
|
4349
|
-
}
|
|
4350
|
-
return sign + (pieces.join(", ") || "0 seconds");
|
|
4351
|
-
}
|
|
4352
|
-
function nextCronRun(expression, reference, timezone) {
|
|
4353
|
-
const cron = typeof expression === "string" ? parseCron(expression) : expression;
|
|
4354
|
-
const instant = parseCronReference(reference);
|
|
4355
|
-
const formatter = zoneFormatter2(timezone);
|
|
4356
|
-
const referenceWall = wallTime(formatter, instant);
|
|
4357
|
-
if (referenceWall.year < 1970 || referenceWall.year > 2099) throw new Error("Reference in the selected timezone must fall within years 1970\u20132099.");
|
|
4358
|
-
const referenceDay = Date.UTC(referenceWall.year, referenceWall.month - 1, referenceWall.day);
|
|
4359
|
-
const firstDay = Math.max(Date.UTC(1970, 0, 1), referenceDay - 2 * DAY2);
|
|
4360
|
-
const searchEnd = Math.min(Date.UTC(2100, 0, 1), Date.UTC(referenceWall.year + 8, referenceWall.month - 1, referenceWall.day + 1));
|
|
4361
|
-
const utcReference = new Date(instant);
|
|
4362
|
-
const eightYearLimit = Date.UTC(utcReference.getUTCFullYear() + 8, utcReference.getUTCMonth(), utcReference.getUTCDate(), utcReference.getUTCHours(), utcReference.getUTCMinutes(), utcReference.getUTCSeconds(), utcReference.getUTCMilliseconds());
|
|
4363
|
-
const absoluteEnd = Math.min(Date.UTC(2100, 0, 1), eightYearLimit + 1);
|
|
4364
|
-
let best;
|
|
4365
|
-
let bestOffset = 0;
|
|
4366
|
-
for (let midnight = firstDay; midnight < searchEnd; midnight += DAY2) {
|
|
4367
|
-
if (best !== void 0 && midnight - DAY2 > best) break;
|
|
4368
|
-
const date = new Date(midnight);
|
|
4369
|
-
const year = date.getUTCFullYear();
|
|
4370
|
-
const month = date.getUTCMonth() + 1;
|
|
4371
|
-
const day = date.getUTCDate();
|
|
4372
|
-
if (!matchesCronDate(cron, year, month, day)) continue;
|
|
4373
|
-
for (const interval of offsetIntervals(formatter, midnight)) {
|
|
4374
|
-
const lowerUtc = Math.max(interval.start, instant + 1, midnight - interval.offset, Date.UTC(1970, 0, 1));
|
|
4375
|
-
const upperUtc = Math.min(interval.end, midnight + DAY2 - interval.offset, absoluteEnd, best ?? Infinity);
|
|
4376
|
-
const second = selectedSecond(cron, (lowerUtc + interval.offset - midnight) / 1e3, (upperUtc + interval.offset - midnight) / 1e3);
|
|
4377
|
-
if (second === void 0) continue;
|
|
4378
|
-
const candidate = midnight + second * 1e3 - interval.offset;
|
|
4379
|
-
const actual = wallTime(formatter, candidate);
|
|
4380
|
-
if (actual.year !== year || actual.month !== month || actual.day !== day || actual.hour !== Math.floor(second / 3600) || actual.minute !== Math.floor(second % 3600 / 60) || actual.second !== second % 60) continue;
|
|
4381
|
-
if (candidate > instant && (best === void 0 || candidate < best)) {
|
|
4382
|
-
best = candidate;
|
|
4383
|
-
bestOffset = interval.offset;
|
|
4384
|
-
}
|
|
4385
|
-
}
|
|
4386
|
-
}
|
|
4387
|
-
if (best === void 0) throw new Error("No occurrence found within eight calendar years after the reference, ending no later than 2099. The expression may select impossible calendar dates.");
|
|
4388
|
-
if (bestOffset % 6e4 !== 0) throw new Error("This historical timezone offset includes seconds and cannot be represented by an RFC 3339 \xB1HH:mm offset; choose a reference after the zone adopted minute-based offsets.");
|
|
4389
|
-
const wall = wallTime(formatter, best);
|
|
4390
|
-
const offsetMinutes = Math.abs(bestOffset / 6e4);
|
|
4391
|
-
const offset = `${bestOffset < 0 ? "-" : "+"}${pad3(Math.floor(offsetMinutes / 60))}:${pad3(offsetMinutes % 60)}`;
|
|
4392
|
-
const dateTime = `${pad3(wall.year, 4)}-${pad3(wall.month)}-${pad3(wall.day)}T${pad3(wall.hour)}:${pad3(wall.minute)}:${pad3(wall.second)}${offset}[${timezone}]`;
|
|
4393
|
-
const durationMilliseconds = best - instant;
|
|
4394
|
-
return { instant: best, dateTime, timezone, durationMilliseconds, duration: formatCronDuration(durationMilliseconds) };
|
|
4395
|
-
}
|
|
4396
|
-
|
|
4397
|
-
// mcp/cli-tools.ts
|
|
4398
5108
|
function stripAnsi(text2) {
|
|
4399
5109
|
return text2.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "");
|
|
4400
5110
|
}
|
|
@@ -4444,7 +5154,7 @@ async function handleCliSubcommand(command, args) {
|
|
|
4444
5154
|
JSON.stringify(
|
|
4445
5155
|
{
|
|
4446
5156
|
name: "Code Station",
|
|
4447
|
-
version: "1.
|
|
5157
|
+
version: "1.3.0",
|
|
4448
5158
|
license: {
|
|
4449
5159
|
tier: license.tier,
|
|
4450
5160
|
isPro: license.isPro,
|
|
@@ -4460,7 +5170,7 @@ async function handleCliSubcommand(command, args) {
|
|
|
4460
5170
|
);
|
|
4461
5171
|
} else {
|
|
4462
5172
|
out("\n=== CODE STATION STATUS ===\n");
|
|
4463
|
-
out("Version: 1.
|
|
5173
|
+
out("Version: 1.3.0\n");
|
|
4464
5174
|
out(`License: ${license.isPro ? "PRO TIER (Active)" : "FREE TIER (Pro key not active)"}
|
|
4465
5175
|
`);
|
|
4466
5176
|
out(`Tools: ${SHARED_TOOLS.length} registered tools across Web, CLI & MCP
|
|
@@ -4867,6 +5577,115 @@ Next run: ${next.dateTime} (${next.duration})
|
|
|
4867
5577
|
return { handled: true, exitCode: 0 };
|
|
4868
5578
|
} catch (e) {
|
|
4869
5579
|
err(`Error: ${e instanceof Error ? e.message : String(e)}
|
|
5580
|
+
`);
|
|
5581
|
+
return { handled: true, exitCode: 1 };
|
|
5582
|
+
}
|
|
5583
|
+
}
|
|
5584
|
+
// -------------------------------------------------------------
|
|
5585
|
+
// ULID Generator
|
|
5586
|
+
// -------------------------------------------------------------
|
|
5587
|
+
case "ulid": {
|
|
5588
|
+
if (isHelp) {
|
|
5589
|
+
out("Usage: codestation ulid [count]\n");
|
|
5590
|
+
return { handled: true, exitCode: 0 };
|
|
5591
|
+
}
|
|
5592
|
+
const count = Math.min(Math.max(parseInt(args[0], 10) || 1, 1), 100);
|
|
5593
|
+
for (let i = 0; i < count; i++) {
|
|
5594
|
+
out(ulid() + "\n");
|
|
5595
|
+
}
|
|
5596
|
+
return { handled: true, exitCode: 0 };
|
|
5597
|
+
}
|
|
5598
|
+
// -------------------------------------------------------------
|
|
5599
|
+
// NanoID Generator
|
|
5600
|
+
// -------------------------------------------------------------
|
|
5601
|
+
case "nanoid": {
|
|
5602
|
+
if (isHelp) {
|
|
5603
|
+
out("Usage: codestation nanoid [count] [--length <2-128>]\n");
|
|
5604
|
+
return { handled: true, exitCode: 0 };
|
|
5605
|
+
}
|
|
5606
|
+
const countArg = args.find((a) => !a.startsWith("-"));
|
|
5607
|
+
const count = Math.min(Math.max(parseInt(countArg ?? "1", 10) || 1, 1), 100);
|
|
5608
|
+
const lenIdx = args.indexOf("--length");
|
|
5609
|
+
const length = lenIdx !== -1 && args[lenIdx + 1] ? parseInt(args[lenIdx + 1], 10) || 21 : 21;
|
|
5610
|
+
for (let i = 0; i < count; i++) {
|
|
5611
|
+
out(nanoid(length) + "\n");
|
|
5612
|
+
}
|
|
5613
|
+
return { handled: true, exitCode: 0 };
|
|
5614
|
+
}
|
|
5615
|
+
// -------------------------------------------------------------
|
|
5616
|
+
// Base64 Encode / Decode
|
|
5617
|
+
// -------------------------------------------------------------
|
|
5618
|
+
case "base64":
|
|
5619
|
+
case "b64": {
|
|
5620
|
+
if (isHelp) {
|
|
5621
|
+
out('Usage: codestation base64 "<text>" [--decode] [--url-safe]\n');
|
|
5622
|
+
return { handled: true, exitCode: 0 };
|
|
5623
|
+
}
|
|
5624
|
+
const input = await readInput(args.find((a) => !a.startsWith("-")));
|
|
5625
|
+
if (!input) {
|
|
5626
|
+
err("Error: Input text is required.\n");
|
|
5627
|
+
return { handled: true, exitCode: 1 };
|
|
5628
|
+
}
|
|
5629
|
+
const decode = args.includes("--decode") || args.includes("-d");
|
|
5630
|
+
const urlSafe = args.includes("--url-safe");
|
|
5631
|
+
try {
|
|
5632
|
+
if (decode) {
|
|
5633
|
+
out((urlSafe ? decodeBase64Url(input) : Buffer.from(input, "base64").toString("utf-8")) + "\n");
|
|
5634
|
+
} else {
|
|
5635
|
+
out((urlSafe ? encodeBase64Url(input) : Buffer.from(input, "utf-8").toString("base64")) + "\n");
|
|
5636
|
+
}
|
|
5637
|
+
return { handled: true, exitCode: 0 };
|
|
5638
|
+
} catch (e) {
|
|
5639
|
+
err(`Error: ${e instanceof Error ? e.message : String(e)}
|
|
5640
|
+
`);
|
|
5641
|
+
return { handled: true, exitCode: 1 };
|
|
5642
|
+
}
|
|
5643
|
+
}
|
|
5644
|
+
// -------------------------------------------------------------
|
|
5645
|
+
// Structural JSON Diff
|
|
5646
|
+
// -------------------------------------------------------------
|
|
5647
|
+
case "json-diff":
|
|
5648
|
+
case "jdiff": {
|
|
5649
|
+
if (isHelp) {
|
|
5650
|
+
out("Usage: codestation json-diff <left_json_or_file> <right_json_or_file>\n");
|
|
5651
|
+
return { handled: true, exitCode: 0 };
|
|
5652
|
+
}
|
|
5653
|
+
const positional = args.filter((a) => !a.startsWith("-"));
|
|
5654
|
+
if (positional.length < 2) {
|
|
5655
|
+
err("Error: Provide both left and right JSON inputs or files.\n");
|
|
5656
|
+
return { handled: true, exitCode: 1 };
|
|
5657
|
+
}
|
|
5658
|
+
try {
|
|
5659
|
+
const left = await readInput(positional[0]);
|
|
5660
|
+
const right = await readInput(positional[1]);
|
|
5661
|
+
out(jsonDiff(left, right) + "\n");
|
|
5662
|
+
return { handled: true, exitCode: 0 };
|
|
5663
|
+
} catch (e) {
|
|
5664
|
+
err(`Error: ${e instanceof Error ? e.message : String(e)}
|
|
5665
|
+
`);
|
|
5666
|
+
return { handled: true, exitCode: 1 };
|
|
5667
|
+
}
|
|
5668
|
+
}
|
|
5669
|
+
// -------------------------------------------------------------
|
|
5670
|
+
// JSONPath Query Extractor
|
|
5671
|
+
// -------------------------------------------------------------
|
|
5672
|
+
case "jsonpath":
|
|
5673
|
+
case "json-path": {
|
|
5674
|
+
if (isHelp) {
|
|
5675
|
+
out('Usage: codestation jsonpath <json_or_file> "<expression>"\n');
|
|
5676
|
+
return { handled: true, exitCode: 0 };
|
|
5677
|
+
}
|
|
5678
|
+
const positional = args.filter((a) => !a.startsWith("-"));
|
|
5679
|
+
if (positional.length < 2) {
|
|
5680
|
+
err("Error: Provide both JSON input and a JSONPath expression starting with $.\n");
|
|
5681
|
+
return { handled: true, exitCode: 1 };
|
|
5682
|
+
}
|
|
5683
|
+
try {
|
|
5684
|
+
const json = await readInput(positional[0]);
|
|
5685
|
+
out(testJsonPath(json, positional[1]) + "\n");
|
|
5686
|
+
return { handled: true, exitCode: 0 };
|
|
5687
|
+
} catch (e) {
|
|
5688
|
+
err(`Error: ${e instanceof Error ? e.message : String(e)}
|
|
4870
5689
|
`);
|
|
4871
5690
|
return { handled: true, exitCode: 1 };
|
|
4872
5691
|
}
|
|
@@ -4876,7 +5695,122 @@ Next run: ${next.dateTime} (${next.duration})
|
|
|
4876
5695
|
}
|
|
4877
5696
|
}
|
|
4878
5697
|
|
|
5698
|
+
// mcp/update-check.ts
|
|
5699
|
+
import * as fs4 from "node:fs";
|
|
5700
|
+
import * as os3 from "node:os";
|
|
5701
|
+
import * as path3 from "node:path";
|
|
5702
|
+
var UPDATE_CHECK_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
5703
|
+
var NPM_LATEST_URL = "https://registry.npmjs.org/codestation-mcp/latest";
|
|
5704
|
+
function defaultCacheFile() {
|
|
5705
|
+
return path3.join(os3.homedir(), ".codestation", "update-check.json");
|
|
5706
|
+
}
|
|
5707
|
+
function parseSemverParts(version) {
|
|
5708
|
+
const cleaned = version.trim().replace(/^v/i, "").split("-")[0];
|
|
5709
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(cleaned);
|
|
5710
|
+
if (!match) return null;
|
|
5711
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
5712
|
+
}
|
|
5713
|
+
function compareSemver(current, latest) {
|
|
5714
|
+
const a = parseSemverParts(current);
|
|
5715
|
+
const b = parseSemverParts(latest);
|
|
5716
|
+
if (!a || !b) return 0;
|
|
5717
|
+
for (let i = 0; i < 3; i += 1) {
|
|
5718
|
+
if (a[i] < b[i]) return -1;
|
|
5719
|
+
if (a[i] > b[i]) return 1;
|
|
5720
|
+
}
|
|
5721
|
+
return 0;
|
|
5722
|
+
}
|
|
5723
|
+
function shouldSkipUpdateCheck(argv = process.argv.slice(2), env = process.env, forceInTest = false) {
|
|
5724
|
+
if (argv.includes("--no-update-check")) return true;
|
|
5725
|
+
const optOut = env.CODESTATION_NO_UPDATE_CHECK?.trim().toLowerCase();
|
|
5726
|
+
if (optOut === "1" || optOut === "true") return true;
|
|
5727
|
+
if (env.NO_UPDATE_NOTIFIER === "1" || env.NO_UPDATE_NOTIFIER === "true") return true;
|
|
5728
|
+
if (env.CI === "1" || env.CI === "true") return true;
|
|
5729
|
+
if (!forceInTest && env.NODE_ENV === "test") return true;
|
|
5730
|
+
return false;
|
|
5731
|
+
}
|
|
5732
|
+
function formatUpdateNotice(currentVersion, latestVersion) {
|
|
5733
|
+
return `
|
|
5734
|
+
[codestation-mcp] Update available: v${currentVersion} -> v${latestVersion} (run: npx -y codestation-mcp@latest). Pass --no-update-check or set CODESTATION_NO_UPDATE_CHECK=1 to disable.
|
|
5735
|
+
`;
|
|
5736
|
+
}
|
|
5737
|
+
function readCache(cacheFile) {
|
|
5738
|
+
try {
|
|
5739
|
+
if (!fs4.existsSync(cacheFile)) return null;
|
|
5740
|
+
const raw = fs4.readFileSync(cacheFile, "utf-8");
|
|
5741
|
+
const parsed = JSON.parse(raw);
|
|
5742
|
+
if (typeof parsed.checkedAt === "number" && typeof parsed.latestVersion === "string") {
|
|
5743
|
+
return { checkedAt: parsed.checkedAt, latestVersion: parsed.latestVersion };
|
|
5744
|
+
}
|
|
5745
|
+
} catch {
|
|
5746
|
+
}
|
|
5747
|
+
return null;
|
|
5748
|
+
}
|
|
5749
|
+
function writeCache(cacheFile, info) {
|
|
5750
|
+
try {
|
|
5751
|
+
const dir = path3.dirname(cacheFile);
|
|
5752
|
+
if (!fs4.existsSync(dir)) {
|
|
5753
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
5754
|
+
}
|
|
5755
|
+
fs4.writeFileSync(cacheFile, JSON.stringify(info, null, 2), "utf-8");
|
|
5756
|
+
} catch {
|
|
5757
|
+
}
|
|
5758
|
+
}
|
|
5759
|
+
async function checkForCliUpdate(options) {
|
|
5760
|
+
const argv = options.argv ?? process.argv.slice(2);
|
|
5761
|
+
const env = options.env ?? process.env;
|
|
5762
|
+
if (shouldSkipUpdateCheck(argv, env, options.forceInTest)) {
|
|
5763
|
+
return { status: "skipped", updateAvailable: false };
|
|
5764
|
+
}
|
|
5765
|
+
const now = options.now ?? Date.now();
|
|
5766
|
+
const cacheFile = options.cacheFile ?? defaultCacheFile();
|
|
5767
|
+
const notify = options.onNotice ?? ((msg) => process.stderr.write(msg));
|
|
5768
|
+
const cached = readCache(cacheFile);
|
|
5769
|
+
if (cached && now - cached.checkedAt >= 0 && now - cached.checkedAt < UPDATE_CHECK_TTL_MS) {
|
|
5770
|
+
const updateAvailable = compareSemver(options.currentVersion, cached.latestVersion) < 0;
|
|
5771
|
+
if (updateAvailable) {
|
|
5772
|
+
notify(formatUpdateNotice(options.currentVersion, cached.latestVersion));
|
|
5773
|
+
}
|
|
5774
|
+
return { status: "cached", updateAvailable, latestVersion: cached.latestVersion };
|
|
5775
|
+
}
|
|
5776
|
+
const fetchImpl = options.fetchFn ?? globalThis.fetch;
|
|
5777
|
+
if (typeof fetchImpl !== "function") {
|
|
5778
|
+
return { status: "error", updateAvailable: false };
|
|
5779
|
+
}
|
|
5780
|
+
const controller = new AbortController();
|
|
5781
|
+
const timeoutMs = options.timeoutMs ?? 1200;
|
|
5782
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
5783
|
+
if (typeof timer.unref === "function") {
|
|
5784
|
+
timer.unref();
|
|
5785
|
+
}
|
|
5786
|
+
try {
|
|
5787
|
+
const response = await fetchImpl(NPM_LATEST_URL, {
|
|
5788
|
+
headers: { Accept: "application/vnd.npm.install-v1+json" },
|
|
5789
|
+
signal: controller.signal
|
|
5790
|
+
});
|
|
5791
|
+
if (!response.ok) {
|
|
5792
|
+
return { status: "error", updateAvailable: false };
|
|
5793
|
+
}
|
|
5794
|
+
const payload = await response.json();
|
|
5795
|
+
const latestVersion = typeof payload.version === "string" ? payload.version.trim() : "";
|
|
5796
|
+
if (!latestVersion || !parseSemverParts(latestVersion)) {
|
|
5797
|
+
return { status: "error", updateAvailable: false };
|
|
5798
|
+
}
|
|
5799
|
+
writeCache(cacheFile, { checkedAt: now, latestVersion });
|
|
5800
|
+
const updateAvailable = compareSemver(options.currentVersion, latestVersion) < 0;
|
|
5801
|
+
if (updateAvailable) {
|
|
5802
|
+
notify(formatUpdateNotice(options.currentVersion, latestVersion));
|
|
5803
|
+
}
|
|
5804
|
+
return { status: "fetched", updateAvailable, latestVersion };
|
|
5805
|
+
} catch {
|
|
5806
|
+
return { status: "error", updateAvailable: false };
|
|
5807
|
+
} finally {
|
|
5808
|
+
clearTimeout(timer);
|
|
5809
|
+
}
|
|
5810
|
+
}
|
|
5811
|
+
|
|
4879
5812
|
// mcp/cli.ts
|
|
5813
|
+
var CLI_VERSION = "1.3.0";
|
|
4880
5814
|
var PRO_ASCII_BADGE = `
|
|
4881
5815
|
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
|
|
4882
5816
|
\u2502 CODE STATION [PRO] \u2022 LOCAL MCP & DEVELOPER TOOLBOX \u2502
|
|
@@ -4907,10 +5841,16 @@ Terminal Subcommands:
|
|
|
4907
5841
|
mock [template] [--count] Generate realistic mock data (users, products, orders)
|
|
4908
5842
|
conflict <file> [--strategy] Parse & resolve Git merge conflicts (ours, theirs, both)
|
|
4909
5843
|
uuid [count] Generate random RFC 4122 v4 UUIDs
|
|
5844
|
+
ulid [count] Generate sortable ULIDs
|
|
5845
|
+
nanoid [count] [--length N] Generate URL-safe NanoIDs
|
|
4910
5846
|
json "<raw_json>" Validate & pretty-print JSON
|
|
5847
|
+
json-diff '<a.json>' '<b.json>' Compute structural JSON diff
|
|
5848
|
+
jsonpath "<json>" "<expr>" Query JSON using JSONPath (e.g. $.users[*].name)
|
|
5849
|
+
base64 "<text>" [--decode] Encode or decode Base64 (--url-safe supported)
|
|
4911
5850
|
|
|
4912
5851
|
Stdio Server Options (for AI Assistants):
|
|
4913
5852
|
--key <license_key> Activate Code Station Pro features
|
|
5853
|
+
--no-update-check Disable npm update check (or set CODESTATION_NO_UPDATE_CHECK=1)
|
|
4914
5854
|
--help, -h Show this help message
|
|
4915
5855
|
--version, -v Show version information
|
|
4916
5856
|
|
|
@@ -4922,17 +5862,31 @@ Pricing:
|
|
|
4922
5862
|
|
|
4923
5863
|
`);
|
|
4924
5864
|
}
|
|
5865
|
+
async function runCliUpdateCheck(args) {
|
|
5866
|
+
await Promise.race([
|
|
5867
|
+
checkForCliUpdate({
|
|
5868
|
+
currentVersion: CLI_VERSION,
|
|
5869
|
+
argv: args,
|
|
5870
|
+
timeoutMs: 800
|
|
5871
|
+
}),
|
|
5872
|
+
new Promise((resolve) => setTimeout(resolve, 250))
|
|
5873
|
+
]);
|
|
5874
|
+
}
|
|
4925
5875
|
async function main() {
|
|
4926
5876
|
const args = process.argv.slice(2);
|
|
4927
|
-
|
|
4928
|
-
|
|
5877
|
+
const cleanArgs = args.filter((a) => a !== "--no-update-check");
|
|
5878
|
+
if (cleanArgs.includes("--version") || cleanArgs.includes("-v")) {
|
|
5879
|
+
process.stderr.write(`codestation-mcp v${CLI_VERSION}
|
|
5880
|
+
`);
|
|
5881
|
+
await runCliUpdateCheck(args);
|
|
4929
5882
|
process.exit(0);
|
|
4930
5883
|
}
|
|
4931
|
-
if (
|
|
5884
|
+
if (cleanArgs[0] === "setup") {
|
|
5885
|
+
const updatePromise = runCliUpdateCheck(args);
|
|
4932
5886
|
let key;
|
|
4933
|
-
const keyIdx =
|
|
4934
|
-
if (keyIdx !== -1 &&
|
|
4935
|
-
key =
|
|
5887
|
+
const keyIdx = cleanArgs.indexOf("--key");
|
|
5888
|
+
if (keyIdx !== -1 && cleanArgs[keyIdx + 1]) {
|
|
5889
|
+
key = cleanArgs[keyIdx + 1];
|
|
4936
5890
|
}
|
|
4937
5891
|
process.stdout.write("\n=== Code Station 1-Click AI Setup ===\n");
|
|
4938
5892
|
if (key) {
|
|
@@ -4952,22 +5906,26 @@ async function main() {
|
|
|
4952
5906
|
}
|
|
4953
5907
|
}
|
|
4954
5908
|
process.stdout.write("\n\u2728 Setup complete! Restart your editor(s) to start using Code Station tools.\n\n");
|
|
5909
|
+
await updatePromise;
|
|
4955
5910
|
process.exit(0);
|
|
4956
5911
|
}
|
|
4957
|
-
if (
|
|
4958
|
-
const
|
|
5912
|
+
if (cleanArgs.length > 0 && !cleanArgs[0].startsWith("-")) {
|
|
5913
|
+
const updatePromise = runCliUpdateCheck(args);
|
|
5914
|
+
const res = await handleCliSubcommand(cleanArgs[0], cleanArgs.slice(1));
|
|
4959
5915
|
if (res.handled) {
|
|
5916
|
+
await updatePromise;
|
|
4960
5917
|
process.exit(res.exitCode);
|
|
4961
5918
|
}
|
|
4962
5919
|
}
|
|
4963
|
-
if (
|
|
5920
|
+
if (cleanArgs.includes("--help") || cleanArgs.includes("-h")) {
|
|
4964
5921
|
printHelp();
|
|
5922
|
+
await runCliUpdateCheck(args);
|
|
4965
5923
|
process.exit(0);
|
|
4966
5924
|
}
|
|
4967
5925
|
let cliKey;
|
|
4968
|
-
const keyIndex =
|
|
4969
|
-
if (keyIndex !== -1 &&
|
|
4970
|
-
cliKey =
|
|
5926
|
+
const keyIndex = cleanArgs.indexOf("--key");
|
|
5927
|
+
if (keyIndex !== -1 && cleanArgs[keyIndex + 1]) {
|
|
5928
|
+
cliKey = cleanArgs[keyIndex + 1];
|
|
4971
5929
|
}
|
|
4972
5930
|
const { server, license } = createMcpServer(cliKey);
|
|
4973
5931
|
if (license.isPro) {
|