@nuucognition/flint-cli 0.4.0-alpha.2 → 0.5.0-alpha.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.
@@ -1,4 +1,4 @@
1
- // ../../packages/flint/dist/chunk-JGOCUBLW.js
1
+ // ../../packages/flint/dist/chunk-53NZQOGM.js
2
2
  import { mkdir, readFile, writeFile } from "fs/promises";
3
3
  import { homedir } from "os";
4
4
  import { join, resolve } from "path";
@@ -182,7 +182,7 @@ async function cleanRegistryFile() {
182
182
  return result;
183
183
  }
184
184
  async function registerFlintByPath(path, options) {
185
- const { readFlintToml, hasFlintToml } = await import("./mesh-config-TEPKR6QZ-TINWSM6H.js");
185
+ const { readFlintToml, hasFlintToml } = await import("./mesh-config-BAIYF4KD-QNNQOBSL.js");
186
186
  const isFlint = await hasFlintToml(path);
187
187
  if (!isFlint) {
188
188
  throw new Error(`Not a valid flint: ${path}
@@ -2,9 +2,9 @@ import {
2
2
  getMeshExportSources,
3
3
  getSourceRepositories,
4
4
  nameFormats
5
- } from "./chunk-GQSLJAUU.js";
5
+ } from "./chunk-XCVQLFHY.js";
6
6
 
7
- // ../../packages/flint/dist/chunk-Q3TNNVO6.js
7
+ // ../../packages/flint/dist/chunk-S7VC3H7U.js
8
8
  import { readFile, writeFile, mkdir, stat, readdir, unlink } from "fs/promises";
9
9
  import { join } from "path";
10
10
  import { randomUUID } from "crypto";
@@ -824,11 +824,40 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
824
824
  return str;
825
825
  }
826
826
 
827
- // ../../packages/flint/dist/chunk-2MJMC5SY.js
828
- import { readFile, writeFile, stat, mkdir } from "fs/promises";
829
- import { join as pathJoin } from "path";
827
+ // ../../packages/flint/dist/chunk-RYEBTVPB.js
828
+ import { readFile, writeFile, stat as stat2, mkdir } from "fs/promises";
829
+ import { join as join2 } from "path";
830
830
  import { randomUUID } from "crypto";
831
- var join = pathJoin;
831
+ import { stat } from "fs/promises";
832
+ import { join, dirname, basename } from "path";
833
+ var FLINT_DIR = ".flint";
834
+ function getFlintConfigDir(flintPath) {
835
+ return join(flintPath, FLINT_DIR);
836
+ }
837
+ async function isInsideMesh(dir) {
838
+ let current = dir;
839
+ while (current !== dirname(current)) {
840
+ try {
841
+ const tomlPath = join(current, "flint.toml");
842
+ await stat(tomlPath);
843
+ return current;
844
+ } catch {
845
+ current = dirname(current);
846
+ }
847
+ }
848
+ return null;
849
+ }
850
+ function getTypePrefix() {
851
+ return "(Flint)";
852
+ }
853
+ function getFlintName(flintPath) {
854
+ const folderName = basename(flintPath);
855
+ const match = folderName.match(/^\((Mesh|Flint)\)\s+(.+)$/);
856
+ if (match && match[2]) {
857
+ return match[2];
858
+ }
859
+ return folderName;
860
+ }
832
861
  function resolveShardMode(decl) {
833
862
  return decl.mode;
834
863
  }
@@ -853,35 +882,25 @@ function nameFormats(name) {
853
882
  };
854
883
  }
855
884
  function getFlintConfigPath(flintPath) {
856
- return join(flintPath, FLINT_CONFIG_FILENAME);
885
+ return join2(flintPath, FLINT_CONFIG_FILENAME);
857
886
  }
858
887
  function getFlintJsonPath(flintPath) {
859
- return join(flintPath, FLINT_JSON_FILENAME);
888
+ return join2(flintPath, FLINT_JSON_FILENAME);
860
889
  }
861
890
  async function exists(path) {
862
891
  try {
863
- await stat(path);
892
+ await stat2(path);
864
893
  return true;
865
894
  } catch {
866
895
  return false;
867
896
  }
868
897
  }
869
- var DEFAULT_SHARD_SOURCES = {
870
- increments: "NUU-Cognition/shard-increments",
871
- plan: "NUU-Cognition/shard-plan",
872
- notepad: "NUU-Cognition/shard-notepad",
873
- reports: "NUU-Cognition/shard-reports",
874
- comments: "NUU-Cognition/shard-comments",
875
- learn: "NUU-Cognition/shard-learn",
876
- flint: "NUU-Cognition/shard-flint",
877
- knap: "NUU-Cognition/shard-knap",
878
- orbcode: "NUU-Cognition/shard-orbcode",
879
- projects: "NUU-Cognition/shard-projects"
880
- };
881
898
  function createFlintToml(name, shards = []) {
882
899
  const shardDeclarations = {};
883
- for (const shard of shards) {
884
- shardDeclarations[shard] = { source: DEFAULT_SHARD_SOURCES[shard] || shard };
900
+ for (const source of shards) {
901
+ const repo = source.includes("/") ? source.split("/").pop() : source;
902
+ const key = repo.replace(/^shard-/, "");
903
+ shardDeclarations[key] = { source };
885
904
  }
886
905
  const config = {
887
906
  flint: {
@@ -949,12 +968,14 @@ async function stampVersion(flintPath) {
949
968
  await writeFlintJson(flintPath, json);
950
969
  }
951
970
  async function stampSynced(flintPath) {
952
- let json = await readFlintJson(flintPath);
953
- if (!json) {
954
- json = createFlintJson();
971
+ const syncPath = join2(getFlintConfigDir(flintPath), "sync.json");
972
+ let data = {};
973
+ try {
974
+ data = JSON.parse(await readFile(syncPath, "utf-8"));
975
+ } catch {
955
976
  }
956
- json.synced = (/* @__PURE__ */ new Date()).toISOString();
957
- await writeFlintJson(flintPath, json);
977
+ data.synced = (/* @__PURE__ */ new Date()).toISOString();
978
+ await writeFile(syncPath, JSON.stringify(data, null, 2) + "\n", "utf-8");
958
979
  }
959
980
  async function readFlintToml(flintPath) {
960
981
  const configPath = getFlintConfigPath(flintPath);
@@ -1045,6 +1066,20 @@ function formatFlintToml(config) {
1045
1066
  lines.push(`repositories = ${inlineTableArray(items).join("\n")}`);
1046
1067
  lines.push("");
1047
1068
  }
1069
+ {
1070
+ const plateDecls = getPlateDeclarationsFromConfig(config);
1071
+ if (Object.keys(plateDecls).length > 0) {
1072
+ lines.push("[plates]");
1073
+ for (const [name, decl] of Object.entries(plateDecls)) {
1074
+ const fields = {};
1075
+ if (decl.title) fields.title = decl.title;
1076
+ fields.path = decl.path;
1077
+ if (decl.repo) fields.repo = decl.repo;
1078
+ lines.push(`${name} = ${inlineTable(fields)}`);
1079
+ }
1080
+ lines.push("");
1081
+ }
1082
+ }
1048
1083
  const hasRefCodebases = config.references?.codebases?.length;
1049
1084
  const hasRefFlints = config.references?.flints?.length;
1050
1085
  if (hasRefCodebases || hasRefFlints) {
@@ -1065,7 +1100,7 @@ function formatFlintToml(config) {
1065
1100
  lines.push(`references = ${inlineTableArray(items).join("\n")}`);
1066
1101
  lines.push("");
1067
1102
  }
1068
- const knownKeys = /* @__PURE__ */ new Set(["flint", "shards", "exports", "imports", "sources", "workspace", "connections", "references", "lattices"]);
1103
+ const knownKeys = /* @__PURE__ */ new Set(["flint", "shards", "exports", "imports", "sources", "workspace", "plates", "connections", "references", "lattices"]);
1069
1104
  const unknownKeys = Object.keys(config).filter((k) => !knownKeys.has(k));
1070
1105
  if (unknownKeys.length > 0) {
1071
1106
  const unknownConfig = {};
@@ -1215,6 +1250,61 @@ async function getWorkspaceRepository(flintPath, name) {
1215
1250
  const normalizedName = name.toLowerCase();
1216
1251
  return config?.workspace?.repositories?.find((r) => r.name.toLowerCase() === normalizedName) || null;
1217
1252
  }
1253
+ async function addPlateDeclaration(flintPath, name, platePath, options = {}) {
1254
+ const config = await readFlintToml(flintPath);
1255
+ if (!config) {
1256
+ throw new Error("flint.toml not found");
1257
+ }
1258
+ if (!config.plates) {
1259
+ config.plates = {};
1260
+ }
1261
+ const decl = { path: platePath };
1262
+ if (options.title) decl.title = options.title;
1263
+ config.plates[name] = decl;
1264
+ await writeFlintToml(flintPath, config);
1265
+ }
1266
+ async function removePlateDeclaration(flintPath, name) {
1267
+ const config = await readFlintToml(flintPath);
1268
+ if (!config?.plates?.[name]) {
1269
+ return false;
1270
+ }
1271
+ delete config.plates[name];
1272
+ await writeFlintToml(flintPath, config);
1273
+ return true;
1274
+ }
1275
+ async function getPlateDeclarations(flintPath) {
1276
+ const config = await readFlintToml(flintPath);
1277
+ return getPlateDeclarationsFromConfig(config);
1278
+ }
1279
+ function getPlateDeclarationsFromConfig(config) {
1280
+ if (!config?.plates) return {};
1281
+ const declarations = {};
1282
+ for (const [key, value] of Object.entries(config.plates)) {
1283
+ if (value && typeof value === "object" && "path" in value) {
1284
+ declarations[key] = value;
1285
+ }
1286
+ }
1287
+ return declarations;
1288
+ }
1289
+ async function setPlateRepo(flintPath, name, url) {
1290
+ const config = await readFlintToml(flintPath);
1291
+ if (!config) {
1292
+ throw new Error("flint.toml not found");
1293
+ }
1294
+ if (!config.plates) {
1295
+ config.plates = {};
1296
+ }
1297
+ const existing = config.plates[name];
1298
+ if (!existing) {
1299
+ throw new Error(`Plate "${name}" not found in flint.toml`);
1300
+ }
1301
+ config.plates[name] = { ...existing, repo: url };
1302
+ await writeFlintToml(flintPath, config);
1303
+ }
1304
+ async function getPlateDeclaration(flintPath, name) {
1305
+ const declarations = await getPlateDeclarations(flintPath);
1306
+ return declarations[name] ?? null;
1307
+ }
1218
1308
  async function addSourceRepository(flintPath, name, url) {
1219
1309
  const config = await readFlintToml(flintPath);
1220
1310
  if (!config) {
@@ -1253,7 +1343,7 @@ async function getSourceRepository(flintPath, name) {
1253
1343
  return config?.sources?.repositories?.find((r) => r.name.toLowerCase() === normalizedName) || null;
1254
1344
  }
1255
1345
  function getLatticesStatePath(flintPath) {
1256
- return pathJoin(flintPath, ".flint", "lattices.json");
1346
+ return join2(flintPath, ".flint", "lattices.json");
1257
1347
  }
1258
1348
  async function readLatticesState(flintPath) {
1259
1349
  const statePath = getLatticesStatePath(flintPath);
@@ -1266,7 +1356,7 @@ async function readLatticesState(flintPath) {
1266
1356
  }
1267
1357
  async function writeLatticesState(flintPath, state) {
1268
1358
  const statePath = getLatticesStatePath(flintPath);
1269
- const dir = pathJoin(flintPath, ".flint");
1359
+ const dir = join2(flintPath, ".flint");
1270
1360
  await mkdir(dir, { recursive: true });
1271
1361
  await writeFile(statePath, JSON.stringify(state, null, 2) + "\n");
1272
1362
  }
@@ -1343,10 +1433,6 @@ async function getLatticeFulfillment(flintPath, name) {
1343
1433
  (l) => l.name.toLowerCase() === name.toLowerCase()
1344
1434
  ) || null;
1345
1435
  }
1346
- var addLatticeReference = async (flintPath, name, _path) => addLatticeDeclaration(flintPath, name);
1347
- var removeLatticeReference = async (flintPath, name) => removeLatticeDeclaration(flintPath, name);
1348
- var getLatticeReferences = async (flintPath) => getLatticeDeclarations(flintPath);
1349
- var getLatticeReference = async (flintPath, name) => getLatticeDeclaration(flintPath, name);
1350
1436
  async function addExportToConfig(flintPath, declaration) {
1351
1437
  let config = await readFlintToml(flintPath);
1352
1438
  if (!config) {
@@ -1427,6 +1513,10 @@ async function removeMeshExportFromConfig(flintPath, ref) {
1427
1513
  export {
1428
1514
  parse,
1429
1515
  stringify,
1516
+ getFlintConfigDir,
1517
+ isInsideMesh,
1518
+ getTypePrefix,
1519
+ getFlintName,
1430
1520
  resolveShardMode,
1431
1521
  isLocalShard,
1432
1522
  FLINT_CONFIG_FILENAME,
@@ -1461,6 +1551,12 @@ export {
1461
1551
  removeWorkspaceRepository,
1462
1552
  getWorkspaceRepositories,
1463
1553
  getWorkspaceRepository,
1554
+ addPlateDeclaration,
1555
+ removePlateDeclaration,
1556
+ getPlateDeclarations,
1557
+ getPlateDeclarationsFromConfig,
1558
+ setPlateRepo,
1559
+ getPlateDeclaration,
1464
1560
  addSourceRepository,
1465
1561
  removeSourceRepository,
1466
1562
  getSourceRepositories,
@@ -1472,10 +1568,6 @@ export {
1472
1568
  getLatticeDeclarations,
1473
1569
  getLatticeDeclaration,
1474
1570
  getLatticeFulfillment,
1475
- addLatticeReference,
1476
- removeLatticeReference,
1477
- getLatticeReferences,
1478
- getLatticeReference,
1479
1571
  addExportToConfig,
1480
1572
  removeExportFromConfig,
1481
1573
  getExportDeclarations,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  readFlintToml
3
- } from "./chunk-GQSLJAUU.js";
3
+ } from "./chunk-XCVQLFHY.js";
4
4
 
5
- // ../../packages/flint/dist/chunk-RLEEB7QI.js
5
+ // ../../packages/flint/dist/chunk-ZN66KTQR.js
6
6
  import { readdir, readFile, mkdir, writeFile, rm, stat, copyFile } from "fs/promises";
7
7
  import { join, basename, dirname, resolve, relative, sep, extname } from "path";
8
8
  async function exists(path) {
@@ -212,7 +212,7 @@ function getDisambiguatedExportName(flintPath, sourcePath, baseName) {
212
212
  return `${baseName} (${dirLabel})`;
213
213
  }
214
214
  async function scanExports(flintPath) {
215
- const { readFlintToml: readFlintToml2 } = await import("./mesh-config-TEPKR6QZ-TINWSM6H.js");
215
+ const { readFlintToml: readFlintToml2 } = await import("./mesh-config-BAIYF4KD-QNNQOBSL.js");
216
216
  const config = await readFlintToml2(flintPath);
217
217
  const declarations = config?.exports?.required;
218
218
  if (!declarations || declarations.length === 0) {
@@ -239,7 +239,7 @@ async function scanExportsFromConfig(flintPath, declarations) {
239
239
  async function scanExportEligible(flintPath) {
240
240
  const meshDir = join(flintPath, "Mesh");
241
241
  if (!await exists(meshDir)) return [];
242
- const { readFlintToml: readFlintToml2 } = await import("./mesh-config-TEPKR6QZ-TINWSM6H.js");
242
+ const { readFlintToml: readFlintToml2 } = await import("./mesh-config-BAIYF4KD-QNNQOBSL.js");
243
243
  const config = await readFlintToml2(flintPath);
244
244
  const declared = new Set(
245
245
  (config?.exports?.required || []).map((d) => d.file.replace(/\.md$/, "").toLowerCase())
@@ -449,6 +449,7 @@ async function buildAllExports(flintPath) {
449
449
  }
450
450
 
451
451
  export {
452
+ resolveDocument,
452
453
  scanExports,
453
454
  scanExportEligible,
454
455
  buildExport,