@nuucognition/flint-cli 0.2.0-beta.0 → 0.2.0-beta.1

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/bin/flint-prod.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { fileURLToPath } from 'node:url';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { dirname, join } from 'node:path';
5
5
 
6
6
  const __dirname = dirname(fileURLToPath(import.meta.url));
7
- await import(join(__dirname, '..', 'dist', 'index.js'));
7
+ await import(pathToFileURL(join(__dirname, '..', 'dist', 'index.js')).href);
package/bin/flint.js CHANGED
File without changes
@@ -1,4 +1,4 @@
1
- // ../../packages/flint/src/mesh-config.ts
1
+ // ../../packages/flint/dist/chunk-OXC4WBGK.js
2
2
  import { readFile, writeFile, stat } from "fs/promises";
3
3
  import { join } from "path";
4
4
 
@@ -828,8 +828,17 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
828
828
  return str;
829
829
  }
830
830
 
831
- // ../../packages/flint/src/mesh-config.ts
831
+ // ../../packages/flint/dist/chunk-OXC4WBGK.js
832
832
  import { randomUUID } from "crypto";
833
+ function resolveShardMode(decl) {
834
+ if (decl.mode) return decl.mode;
835
+ if (decl.dev) return "dev";
836
+ return void 0;
837
+ }
838
+ function isLocalShard(decl) {
839
+ const mode = resolveShardMode(decl);
840
+ return mode === "dev" || mode === "custom";
841
+ }
833
842
  var FLINT_CONFIG_FILENAME = "flint.toml";
834
843
  var FLINT_JSON_FILENAME = "flint.json";
835
844
  var FLINT_VERSION = "0.2.0";
@@ -964,26 +973,49 @@ async function readFlintToml(flintPath) {
964
973
  throw error;
965
974
  }
966
975
  }
976
+ function tv(v) {
977
+ if (typeof v === "string") return `"${v}"`;
978
+ if (typeof v === "boolean") return v ? "true" : "false";
979
+ if (typeof v === "number") return String(v);
980
+ if (Array.isArray(v)) return `[${v.map(tv).join(", ")}]`;
981
+ return String(v);
982
+ }
983
+ function inlineTable(obj) {
984
+ const parts = Object.entries(obj).filter(([, v]) => v !== void 0 && v !== null).map(([k, v]) => `${k} = ${tv(v)}`);
985
+ return `{ ${parts.join(", ")} }`;
986
+ }
987
+ function inlineTableArray(items) {
988
+ return [
989
+ "[",
990
+ ...items.map((item) => ` ${inlineTable(item)},`),
991
+ "]"
992
+ ];
993
+ }
994
+ function stringArray(items) {
995
+ return [
996
+ "[",
997
+ ...items.map((s) => ` "${s}",`),
998
+ "]"
999
+ ];
1000
+ }
967
1001
  function formatFlintToml(config) {
968
1002
  const lines = [];
969
1003
  lines.push("[flint]");
970
- lines.push(`name = "${config.flint.name}"`);
971
- if (config.flint.type) {
972
- lines.push(`type = "${config.flint.type}"`);
973
- }
974
- if (config.flint.description) {
975
- lines.push(`description = "${config.flint.description}"`);
976
- }
977
- if (config.flint.tags && config.flint.tags.length > 0) {
978
- lines.push(`tags = [${config.flint.tags.map((t) => `"${t}"`).join(", ")}]`);
979
- }
1004
+ lines.push(`name = ${tv(config.flint.name)}`);
1005
+ if (config.flint.type) lines.push(`type = ${tv(config.flint.type)}`);
1006
+ if (config.flint.description) lines.push(`description = ${tv(config.flint.description)}`);
1007
+ if (config.flint.tags?.length) lines.push(`tags = ${tv(config.flint.tags)}`);
1008
+ if (config.flint.org) lines.push(`org = ${tv(config.flint.org)}`);
980
1009
  lines.push("");
981
1010
  if (config.shards) {
982
1011
  const declarations = getShardDeclarationsFromConfig(config);
983
1012
  if (Object.keys(declarations).length > 0) {
984
1013
  lines.push("[shards]");
985
1014
  for (const [shorthand, decl] of Object.entries(declarations)) {
986
- lines.push(`${shorthand} = { source = "${decl.source}"${decl.dev ? ", dev = true" : ""} }`);
1015
+ const mode = resolveShardMode(decl);
1016
+ const fields = { source: decl.source };
1017
+ if (mode) fields.mode = mode;
1018
+ lines.push(`${shorthand} = ${inlineTable(fields)}`);
987
1019
  }
988
1020
  lines.push("");
989
1021
  }
@@ -993,68 +1025,65 @@ function formatFlintToml(config) {
993
1025
  if (Object.keys(modDeclarations).length > 0) {
994
1026
  lines.push("[mods]");
995
1027
  for (const [name, decl] of Object.entries(modDeclarations)) {
996
- lines.push(`${name} = { source = "${decl.source}"${decl.dev ? ", dev = true" : ""} }`);
1028
+ const fields = { source: decl.source };
1029
+ if (decl.dev) fields.dev = true;
1030
+ lines.push(`${name} = ${inlineTable(fields)}`);
997
1031
  }
998
1032
  lines.push("");
999
1033
  }
1000
1034
  }
1001
- if (config.imports?.required && config.imports.required.length > 0) {
1035
+ if (config.exports?.required?.length) {
1036
+ lines.push("[exports]");
1037
+ const items = config.exports.required.map((e) => {
1038
+ const fields = { name: e.name, file: e.file, mode: e.mode };
1039
+ if (e.depth !== void 0 && e.depth !== 1) fields.depth = e.depth;
1040
+ return fields;
1041
+ });
1042
+ lines.push(`required = ${inlineTableArray(items).join("\n")}`);
1043
+ lines.push("");
1044
+ }
1045
+ const flintImports = config.imports?.flints || config.imports?.required || [];
1046
+ if (flintImports.length) {
1002
1047
  lines.push("[imports]");
1003
- lines.push("required = [");
1004
- for (const ref of config.imports.required) {
1005
- lines.push(` "${ref}",`);
1006
- }
1007
- lines.push("]");
1048
+ lines.push(`flints = ${stringArray(flintImports).join("\n")}`);
1008
1049
  lines.push("");
1009
1050
  }
1010
- const hasReferences = config.workspace?.references && config.workspace.references.length > 0;
1011
- const hasRepositories = config.workspace?.repositories && config.workspace.repositories.length > 0;
1012
- const hasSourceRepositories = config.workspace?.sources?.repositories && config.workspace.sources.repositories.length > 0;
1013
- if (hasReferences || hasRepositories || hasSourceRepositories) {
1051
+ const hasRefs = config.workspace?.references?.length;
1052
+ const hasRepos = config.workspace?.repositories?.length;
1053
+ const hasSrcRepos = config.workspace?.sources?.repositories?.length;
1054
+ if (hasRefs || hasRepos) {
1014
1055
  lines.push("[workspace]");
1015
- if (hasReferences) {
1016
- lines.push("references = [");
1017
- for (const ref of config.workspace.references) {
1018
- lines.push(` { name = "${ref.name}", type = "${ref.type}" },`);
1019
- }
1020
- lines.push("]");
1056
+ if (hasRefs) {
1057
+ const items = config.workspace.references.map((r) => ({ name: r.name, type: r.type }));
1058
+ lines.push(`references = ${inlineTableArray(items).join("\n")}`);
1021
1059
  }
1022
- if (hasRepositories) {
1023
- lines.push("repositories = [");
1024
- for (const repo of config.workspace.repositories) {
1025
- lines.push(` { name = "${repo.name}", url = "${repo.url}" },`);
1026
- }
1027
- lines.push("]");
1060
+ if (hasRepos) {
1061
+ const items = config.workspace.repositories.map((r) => ({ name: r.name, url: r.url }));
1062
+ lines.push(`repositories = ${inlineTableArray(items).join("\n")}`);
1028
1063
  }
1029
1064
  lines.push("");
1030
1065
  }
1031
- if (hasSourceRepositories) {
1066
+ if (hasSrcRepos) {
1032
1067
  lines.push("[workspace.sources]");
1033
- lines.push("repositories = [");
1034
- for (const repo of config.workspace.sources.repositories) {
1035
- lines.push(` { name = "${repo.name}", url = "${repo.url}" },`);
1036
- }
1037
- lines.push("]");
1068
+ const items = config.workspace.sources.repositories.map((r) => ({ name: r.name, url: r.url }));
1069
+ lines.push(`repositories = ${inlineTableArray(items).join("\n")}`);
1038
1070
  lines.push("");
1039
1071
  }
1040
- if (config.connections?.flints && config.connections.flints.length > 0) {
1072
+ if (config.connections?.flints?.length) {
1041
1073
  lines.push("[connections]");
1042
- lines.push("flints = [");
1043
- for (const conn of config.connections.flints) {
1044
- lines.push(` { name = "${conn.name}" },`);
1045
- }
1046
- lines.push("]");
1074
+ const items = config.connections.flints.map((c) => ({ name: c.name }));
1075
+ lines.push(`flints = ${inlineTableArray(items).join("\n")}`);
1047
1076
  lines.push("");
1048
1077
  }
1049
- if (config.lattices && config.lattices.length > 0) {
1078
+ if (config.lattices?.length) {
1050
1079
  for (const lattice of config.lattices) {
1051
1080
  lines.push("[[lattices]]");
1052
- lines.push(`name = "${lattice.name}"`);
1053
- lines.push(`path = "${lattice.path}"`);
1081
+ lines.push(`name = ${tv(lattice.name)}`);
1082
+ lines.push(`path = ${tv(lattice.path)}`);
1054
1083
  lines.push("");
1055
1084
  }
1056
1085
  }
1057
- const knownKeys = /* @__PURE__ */ new Set(["flint", "shards", "mods", "imports", "workspace", "connections", "lattices"]);
1086
+ const knownKeys = /* @__PURE__ */ new Set(["flint", "shards", "mods", "exports", "imports", "workspace", "connections", "lattices"]);
1058
1087
  const unknownKeys = Object.keys(config).filter((k) => !knownKeys.has(k));
1059
1088
  if (unknownKeys.length > 0) {
1060
1089
  const unknownConfig = {};
@@ -1089,7 +1118,8 @@ async function addShardToConfig(flintPath, shardName, source, options = {}) {
1089
1118
  const effectiveSource = source || kebabName;
1090
1119
  if (!existing || existing.source !== effectiveSource) {
1091
1120
  const decl = { source: effectiveSource };
1092
- if (options.dev) decl.dev = true;
1121
+ const effectiveMode = options.mode || (options.dev ? "dev" : void 0);
1122
+ if (effectiveMode) decl.mode = effectiveMode;
1093
1123
  config.shards[kebabName] = decl;
1094
1124
  await writeFlintToml(flintPath, config);
1095
1125
  }
@@ -1378,41 +1408,95 @@ async function getLatticeReference(flintPath, name) {
1378
1408
  const normalizedName = name.toLowerCase();
1379
1409
  return config?.lattices?.find((entry) => entry.name.toLowerCase() === normalizedName) || null;
1380
1410
  }
1381
- async function addImportToConfig(flintPath, ref) {
1411
+ async function addExportToConfig(flintPath, declaration) {
1382
1412
  let config = await readFlintToml(flintPath);
1383
1413
  if (!config) {
1384
1414
  throw new Error("flint.toml not found");
1385
1415
  }
1416
+ if (!config.exports) {
1417
+ config.exports = { required: [] };
1418
+ }
1419
+ if (!config.exports.required) {
1420
+ config.exports.required = [];
1421
+ }
1422
+ const existing = config.exports.required.find(
1423
+ (e) => e.name.toLowerCase() === declaration.name.toLowerCase()
1424
+ );
1425
+ if (existing) {
1426
+ throw new Error(`Export "${declaration.name}" already declared`);
1427
+ }
1428
+ config.exports.required.push({
1429
+ name: declaration.name,
1430
+ file: declaration.file,
1431
+ mode: declaration.mode,
1432
+ ...declaration.depth !== void 0 ? { depth: declaration.depth } : {}
1433
+ });
1434
+ await writeFlintToml(flintPath, config);
1435
+ }
1436
+ async function removeExportFromConfig(flintPath, exportName) {
1437
+ let config = await readFlintToml(flintPath);
1438
+ if (!config?.exports?.required) return false;
1439
+ const index = config.exports.required.findIndex(
1440
+ (e) => e.name.toLowerCase() === exportName.toLowerCase()
1441
+ );
1442
+ if (index === -1) return false;
1443
+ config.exports.required.splice(index, 1);
1444
+ await writeFlintToml(flintPath, config);
1445
+ return true;
1446
+ }
1447
+ async function getExportDeclarations(flintPath) {
1448
+ const config = await readFlintToml(flintPath);
1449
+ return config?.exports?.required || [];
1450
+ }
1451
+ function resolveFlintImports(config) {
1452
+ return config.imports?.flints || config.imports?.required || [];
1453
+ }
1454
+ function ensureFlintImports(config) {
1386
1455
  if (!config.imports) {
1387
- config.imports = { required: [] };
1456
+ config.imports = { flints: [] };
1457
+ }
1458
+ if (config.imports.required && !config.imports.flints) {
1459
+ config.imports.flints = config.imports.required;
1460
+ }
1461
+ delete config.imports.required;
1462
+ if (!config.imports.flints) {
1463
+ config.imports.flints = [];
1388
1464
  }
1389
- if (!config.imports.required) {
1390
- config.imports.required = [];
1465
+ return config.imports.flints;
1466
+ }
1467
+ async function addImportToConfig(flintPath, ref) {
1468
+ let config = await readFlintToml(flintPath);
1469
+ if (!config) {
1470
+ throw new Error("flint.toml not found");
1391
1471
  }
1392
- if (!config.imports.required.includes(ref)) {
1393
- config.imports.required.push(ref);
1472
+ const flints = ensureFlintImports(config);
1473
+ if (!flints.includes(ref)) {
1474
+ flints.push(ref);
1394
1475
  await writeFlintToml(flintPath, config);
1395
1476
  }
1396
1477
  }
1397
1478
  async function removeImportFromConfig(flintPath, ref) {
1398
1479
  let config = await readFlintToml(flintPath);
1399
- if (!config?.imports?.required) return false;
1400
- const index = config.imports.required.indexOf(ref);
1480
+ if (!config) return false;
1481
+ const flints = ensureFlintImports(config);
1482
+ const index = flints.indexOf(ref);
1401
1483
  if (index === -1) {
1402
1484
  const lowerRef = ref.toLowerCase();
1403
- const foundIndex = config.imports.required.findIndex((r) => r.toLowerCase() === lowerRef);
1485
+ const foundIndex = flints.findIndex((r) => r.toLowerCase() === lowerRef);
1404
1486
  if (foundIndex === -1) return false;
1405
- config.imports.required.splice(foundIndex, 1);
1487
+ flints.splice(foundIndex, 1);
1406
1488
  } else {
1407
- config.imports.required.splice(index, 1);
1489
+ flints.splice(index, 1);
1408
1490
  }
1409
1491
  await writeFlintToml(flintPath, config);
1410
1492
  return true;
1411
1493
  }
1412
- async function getRequiredImports(flintPath) {
1494
+ async function getFlintImports(flintPath) {
1413
1495
  const config = await readFlintToml(flintPath);
1414
- return config?.imports?.required || [];
1496
+ if (!config) return [];
1497
+ return resolveFlintImports(config);
1415
1498
  }
1499
+ var getRequiredImports = getFlintImports;
1416
1500
  async function addWorkspaceEntry(flintPath, name, path) {
1417
1501
  console.warn("addWorkspaceEntry is deprecated, use addWorkspaceReference instead");
1418
1502
  }
@@ -1428,6 +1512,9 @@ async function getWorkspaceEntry(flintPath, name) {
1428
1512
 
1429
1513
  export {
1430
1514
  parse,
1515
+ stringify,
1516
+ resolveShardMode,
1517
+ isLocalShard,
1431
1518
  FLINT_CONFIG_FILENAME,
1432
1519
  FLINT_JSON_FILENAME,
1433
1520
  FLINT_VERSION,
@@ -1475,8 +1562,12 @@ export {
1475
1562
  removeLatticeReference,
1476
1563
  getLatticeReferences,
1477
1564
  getLatticeReference,
1565
+ addExportToConfig,
1566
+ removeExportFromConfig,
1567
+ getExportDeclarations,
1478
1568
  addImportToConfig,
1479
1569
  removeImportFromConfig,
1570
+ getFlintImports,
1480
1571
  getRequiredImports,
1481
1572
  addWorkspaceEntry,
1482
1573
  removeWorkspaceEntry,
@@ -1,10 +1,10 @@
1
- // ../../packages/flint/src/registry.ts
1
+ // ../../packages/flint/dist/chunk-CJE24DAP.js
2
2
  import { mkdir, readFile, writeFile } from "fs/promises";
3
3
  import { homedir } from "os";
4
4
  import { join, resolve } from "path";
5
5
  var REGISTRY_VERSION = 1;
6
6
  function getGlobalFlintDir() {
7
- return join(homedir(), ".flint");
7
+ return join(homedir(), ".nuucognition", "flint");
8
8
  }
9
9
  function getFlintRegistryPath() {
10
10
  return join(getGlobalFlintDir(), "registry.json");
@@ -184,7 +184,7 @@ async function cleanRegistryFile() {
184
184
  return result;
185
185
  }
186
186
  async function registerFlintByPath(path, options) {
187
- const { readFlintToml, hasFlintToml } = await import("./mesh-config-O3UKKKAO.js");
187
+ const { readFlintToml, hasFlintToml } = await import("./mesh-config-VGFSHC2G-YCC4ZIAT.js");
188
188
  const isFlint = await hasFlintToml(path);
189
189
  if (!isFlint) {
190
190
  throw new Error(`Not a valid flint: ${path}
@@ -1,4 +1,4 @@
1
- // ../../packages/flint/src/exports.ts
1
+ // ../../packages/flint/dist/chunk-E7CDAGZD.js
2
2
  import { readdir, readFile, mkdir, writeFile, rm, stat } from "fs/promises";
3
3
  import { join, basename, dirname, resolve, relative, sep } from "path";
4
4
  async function exists(path) {
@@ -224,6 +224,31 @@ function getDisambiguatedExportName(flintPath, sourcePath, baseName) {
224
224
  return `${baseName} (${dirLabel})`;
225
225
  }
226
226
  async function scanExports(flintPath) {
227
+ const { readFlintToml } = await import("./mesh-config-VGFSHC2G-YCC4ZIAT.js");
228
+ const config = await readFlintToml(flintPath);
229
+ const declarations = config?.exports?.required;
230
+ if (declarations && declarations.length > 0) {
231
+ return scanExportsFromConfig(flintPath, declarations);
232
+ }
233
+ return scanExportsLegacy(flintPath);
234
+ }
235
+ async function scanExportsFromConfig(flintPath, declarations) {
236
+ const manifests = [];
237
+ for (const decl of declarations) {
238
+ const sourcePath = await resolveDocument(decl.file.replace(/\.md$/, ""), flintPath);
239
+ if (!sourcePath) continue;
240
+ try {
241
+ const content = await readFile(sourcePath, "utf-8");
242
+ const depth = decl.depth ?? (decl.mode === "mesh" ? 1 : 1);
243
+ const manifest = parseExportDocument(content, decl.name, sourcePath);
244
+ manifest.depth = depth;
245
+ manifests.push(manifest);
246
+ } catch {
247
+ }
248
+ }
249
+ return manifests;
250
+ }
251
+ async function scanExportsLegacy(flintPath) {
227
252
  const meshDir = join(flintPath, "Mesh");
228
253
  if (!await exists(meshDir)) {
229
254
  return [];
@@ -242,9 +267,49 @@ async function scanExports(flintPath) {
242
267
  }
243
268
  return manifests;
244
269
  }
270
+ async function scanExportEligible(flintPath) {
271
+ const meshDir = join(flintPath, "Mesh");
272
+ if (!await exists(meshDir)) return [];
273
+ const { readFlintToml } = await import("./mesh-config-VGFSHC2G-YCC4ZIAT.js");
274
+ const config = await readFlintToml(flintPath);
275
+ const declared = new Set(
276
+ (config?.exports?.required || []).map((d) => d.file.replace(/\.md$/, "").toLowerCase())
277
+ );
278
+ const eligible = [];
279
+ await findExportTaggedFiles(meshDir, flintPath, declared, eligible);
280
+ return eligible;
281
+ }
282
+ async function findExportTaggedFiles(dir, flintPath, declared, results) {
283
+ try {
284
+ const entries = await readdir(dir, { withFileTypes: true });
285
+ for (const entry of entries) {
286
+ const fullPath = join(dir, entry.name);
287
+ if (entry.isDirectory()) {
288
+ await findExportTaggedFiles(fullPath, flintPath, declared, results);
289
+ } else if (entry.isFile() && entry.name.endsWith(".md")) {
290
+ try {
291
+ const content = await readFile(fullPath, "utf-8");
292
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
293
+ if (!fmMatch || !fmMatch[1]) continue;
294
+ const hasExportTag = /["']#export["']/.test(fmMatch[1]);
295
+ if (!hasExportTag) continue;
296
+ const fileName = basename(fullPath, ".md");
297
+ if (declared.has(fileName.toLowerCase())) continue;
298
+ results.push({
299
+ filePath: fullPath,
300
+ fileName: entry.name,
301
+ name: fileName
302
+ });
303
+ } catch {
304
+ }
305
+ }
306
+ }
307
+ } catch {
308
+ }
309
+ }
245
310
  async function buildExport(manifest, flintPath) {
246
311
  const exportsDir = join(flintPath, "Exports");
247
- const outputDir = join(exportsDir, manifest.name);
312
+ const outputDir = join(exportsDir, `(Mesh) ${manifest.name}`);
248
313
  if (await exists(outputDir)) {
249
314
  await rm(outputDir, { recursive: true });
250
315
  }
@@ -345,11 +410,12 @@ async function cleanupStaleExports(flintPath) {
345
410
  return removed;
346
411
  }
347
412
  const manifests = await scanExports(flintPath);
348
- const validExportNames = new Set(manifests.map((m) => m.name));
413
+ const validFolderNames = new Set(manifests.map((m) => `(Mesh) ${m.name}`));
414
+ const validLegacyNames = new Set(manifests.map((m) => m.name));
349
415
  const entries = await readdir(exportsDir, { withFileTypes: true });
350
416
  for (const entry of entries) {
351
417
  if (entry.isDirectory()) {
352
- if (!validExportNames.has(entry.name)) {
418
+ if (!validFolderNames.has(entry.name) && !validLegacyNames.has(entry.name)) {
353
419
  try {
354
420
  await rm(join(exportsDir, entry.name), { recursive: true });
355
421
  removed.push(entry.name);
@@ -379,6 +445,7 @@ async function buildAllExports(flintPath) {
379
445
 
380
446
  export {
381
447
  scanExports,
448
+ scanExportEligible,
382
449
  buildExport,
383
450
  buildExportByName,
384
451
  cleanupStaleExports,
@@ -3,12 +3,14 @@ import {
3
3
  buildExport,
4
4
  buildExportByName,
5
5
  cleanupStaleExports,
6
+ scanExportEligible,
6
7
  scanExports
7
- } from "./chunk-BVYUS7NX.js";
8
+ } from "./chunk-VO4ZYDCW.js";
8
9
  export {
9
10
  buildAllExports,
10
11
  buildExport,
11
12
  buildExportByName,
12
13
  cleanupStaleExports,
14
+ scanExportEligible,
13
15
  scanExports
14
16
  };