@dialecte/cli 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lookups.js CHANGED
@@ -118,7 +118,7 @@ function compareFound(left, right) {
118
118
 
119
119
  // src/lib/api/read-api-indexes.ts
120
120
  import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
121
- import { join as join2 } from "path";
121
+ import { join as join3 } from "path";
122
122
 
123
123
  // src/lib/skills/skill-file.constants.ts
124
124
  var SKILLS_FOLDER = "skills";
@@ -135,15 +135,16 @@ import {
135
135
  readFileSync,
136
136
  readlinkSync,
137
137
  rmSync,
138
- statSync,
138
+ statSync as statSync2,
139
139
  symlinkSync,
140
140
  unlinkSync,
141
141
  writeFileSync
142
142
  } from "fs";
143
- import { dirname, join, parse, relative, resolve } from "path";
143
+ import { dirname as dirname2, join as join2, parse, relative as relative2, resolve } from "path";
144
144
 
145
145
  // src/lib/file-system.ts
146
- import { lstatSync, realpathSync } from "fs";
146
+ import { lstatSync, realpathSync, statSync } from "fs";
147
+ import { basename, dirname, isAbsolute, join, relative, sep } from "path";
147
148
 
148
149
  // src/lib/skills/skill-file.ts
149
150
  function readFrontmatter(markdown) {
@@ -189,7 +190,7 @@ var AGENT_SKILL_FOLDERS = {
189
190
  function discoverSkillSources(params) {
190
191
  const missingDependencies = [];
191
192
  const { from } = params;
192
- const origins = from ? readdirSync(from, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => ({ origin: entry.name, folder: join(from, entry.name) })) : dependencyNames(params.cwd).flatMap((name) => {
193
+ const origins = from ? readdirSync(from, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => ({ origin: entry.name, folder: join2(from, entry.name) })) : dependencyNames(params.cwd).flatMap((name) => {
193
194
  const folder = findInstalledPackage({ cwd: params.cwd, name });
194
195
  if (folder) return [{ origin: name, folder }];
195
196
  missingDependencies.push(name);
@@ -206,7 +207,7 @@ function discoverSkillSources(params) {
206
207
  return { sources, missingDependencies };
207
208
  }
208
209
  function dependencyNames(cwd) {
209
- const manifest = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
210
+ const manifest = JSON.parse(readFileSync(join2(cwd, "package.json"), "utf8"));
210
211
  return [
211
212
  .../* @__PURE__ */ new Set([
212
213
  ...Object.keys(manifest.dependencies ?? {}),
@@ -219,26 +220,26 @@ function findInstalledPackage(params) {
219
220
  let folder = params.cwd;
220
221
  const { root } = parse(folder);
221
222
  for (; ; ) {
222
- const candidate = join(folder, "node_modules", params.name);
223
+ const candidate = join2(folder, "node_modules", params.name);
223
224
  if (existsSync(candidate)) return candidate;
224
225
  if (folder === root) return void 0;
225
- folder = dirname(folder);
226
+ folder = dirname2(folder);
226
227
  }
227
228
  }
228
229
  function skillsOf(params) {
229
- const skillsFolder = join(params.folder, SKILLS_FOLDER);
230
+ const skillsFolder = join2(params.folder, SKILLS_FOLDER);
230
231
  if (!existsSync(skillsFolder)) return [];
231
232
  const version = packageVersion(params.folder);
232
- return readdirSync(skillsFolder, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isFile(join(skillsFolder, entry.name, "SKILL.md"))).map((entry) => ({
233
+ return readdirSync(skillsFolder, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isFile(join2(skillsFolder, entry.name, "SKILL.md"))).map((entry) => ({
233
234
  name: entry.name,
234
- path: join(skillsFolder, entry.name),
235
+ path: join2(skillsFolder, entry.name),
235
236
  origin: params.origin,
236
237
  ...version === void 0 ? {} : { version },
237
- audience: audienceOf(join(skillsFolder, entry.name, "SKILL.md"))
238
+ audience: audienceOf(join2(skillsFolder, entry.name, "SKILL.md"))
238
239
  }));
239
240
  }
240
241
  function isFile(path) {
241
- return existsSync(path) && statSync(path).isFile();
242
+ return existsSync(path) && statSync2(path).isFile();
242
243
  }
243
244
  function audienceOf(skillFile) {
244
245
  try {
@@ -256,13 +257,13 @@ function selectAudience(params) {
256
257
  };
257
258
  }
258
259
  function packageVersion(folder) {
259
- const path = join(folder, "package.json");
260
+ const path = join2(folder, "package.json");
260
261
  if (!existsSync(path)) return void 0;
261
262
  const version = JSON.parse(readFileSync(path, "utf8")).version;
262
263
  return typeof version === "string" ? version : void 0;
263
264
  }
264
265
  function readSyncManifest(targetFolder) {
265
- const path = join(targetFolder, MANIFEST_FILE);
266
+ const path = join2(targetFolder, MANIFEST_FILE);
266
267
  if (!existsSync(path)) return { installed: [], versions: {} };
267
268
  const manifest = JSON.parse(readFileSync(path, "utf8"));
268
269
  const installed = Array.isArray(manifest.installed) ? manifest.installed.filter(
@@ -304,7 +305,7 @@ function readApiIndexes(params) {
304
305
  ];
305
306
  const byPackage = /* @__PURE__ */ new Map();
306
307
  for (const folder of skillFolders) {
307
- const path = join2(folder, API_JSON_FOLDER, API_JSON_FILE);
308
+ const path = join3(folder, API_JSON_FOLDER, API_JSON_FILE);
308
309
  if (!existsSync2(path)) continue;
309
310
  const index = readApiJson(path);
310
311
  if (!byPackage.has(index.package)) byPackage.set(index.package, index);
@@ -314,9 +315,9 @@ function readApiIndexes(params) {
314
315
  );
315
316
  }
316
317
  function ownSkillFolders(cwd) {
317
- const skillsRoot = join2(cwd, SKILLS_FOLDER);
318
+ const skillsRoot = join3(cwd, SKILLS_FOLDER);
318
319
  if (!existsSync2(skillsRoot)) return [];
319
- return readdirSync2(skillsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join2(skillsRoot, entry.name)).sort();
320
+ return readdirSync2(skillsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join3(skillsRoot, entry.name)).sort();
320
321
  }
321
322
  function readApiJson(path) {
322
323
  const fix = "reinstall the package, or run `dialecte skills generate` in its repository";
@@ -336,6 +337,40 @@ function isApiJson(value) {
336
337
  return typeof value === "object" && value !== null && "package" in value && typeof value.package === "string" && "methods" in value && Array.isArray(value.methods);
337
338
  }
338
339
 
340
+ // src/lib/print/print.ts
341
+ import { writeSync } from "fs";
342
+
343
+ // src/lib/print/print.constants.ts
344
+ var DISPLAY_ESCAPED_RANGES = [
345
+ [0, 31],
346
+ [127, 159],
347
+ [1564, 1564],
348
+ [8206, 8207],
349
+ [8232, 8233],
350
+ [8234, 8238],
351
+ [8294, 8297]
352
+ ];
353
+ var ESCAPE_RADIX = 16;
354
+ var LINE_FEED = "\n";
355
+
356
+ // src/lib/print/print.ts
357
+ function escapeControlCharacters(params) {
358
+ return Array.from(params.text, function escapeOf(character) {
359
+ const code = character.codePointAt(0) ?? 0;
360
+ const escaped = DISPLAY_ESCAPED_RANGES.some(([first, last]) => code >= first && code <= last);
361
+ return escaped ? `\\u{${code.toString(ESCAPE_RADIX)}}` : character;
362
+ }).join("");
363
+ }
364
+ function textOf(lines) {
365
+ return lines.map((line) => escapeControlCharacters({ text: line })).join(LINE_FEED);
366
+ }
367
+ function jsonOf(value, indent) {
368
+ return JSON.stringify(value, null, indent);
369
+ }
370
+ function endedOf(text) {
371
+ return `${text}${LINE_FEED}`;
372
+ }
373
+
339
374
  // src/lib/api/short-summary.ts
340
375
  function shortSummary(summary) {
341
376
  const sentence = summary.match(/^.*?[.!?](?=\s|$)/)?.[0] ?? summary;
@@ -345,31 +380,47 @@ function shortSummary(summary) {
345
380
  // src/lib/api/render-api.ts
346
381
  function renderFound(params) {
347
382
  if (params.json)
348
- return toJson({
349
- need: params.need,
350
- methods: params.found.map((found) => ({
351
- path: found.method.path,
352
- root: found.method.root,
353
- package: found.packageName,
354
- hits: found.hits,
355
- intent: found.matchingIntent,
356
- summary: found.method.summary
357
- }))
358
- });
359
- return params.found.map(
360
- (found) => `${found.method.path} ${found.method.root} ${found.matchingIntent ?? shortSummary(found.method.summary ?? "-")} ${found.packageName}
361
- `
362
- ).join("");
383
+ return endedOf(
384
+ jsonOf(
385
+ {
386
+ need: params.need,
387
+ methods: params.found.map((found) => ({
388
+ path: found.method.path,
389
+ root: found.method.root,
390
+ package: found.packageName,
391
+ hits: found.hits,
392
+ intent: found.matchingIntent,
393
+ summary: found.method.summary
394
+ }))
395
+ },
396
+ " "
397
+ )
398
+ );
399
+ return endedTextOf(
400
+ params.found.map(
401
+ (found) => `${found.method.path} ${found.method.root} ${found.matchingIntent ?? shortSummary(found.method.summary ?? "-")} ${found.packageName}`
402
+ )
403
+ );
363
404
  }
364
405
  function renderShown(params) {
365
406
  if (params.json)
366
- return toJson({
367
- methods: params.methods.map(({ method, packageName: packageName2 }) => ({
368
- package: packageName2,
369
- ...method
370
- }))
371
- });
372
- return params.methods.map(renderMethod).join("\n");
407
+ return endedOf(
408
+ jsonOf(
409
+ {
410
+ methods: params.methods.map(({ method, packageName: packageName2 }) => ({
411
+ package: packageName2,
412
+ ...method
413
+ }))
414
+ },
415
+ " "
416
+ )
417
+ );
418
+ return endedTextOf(
419
+ params.methods.flatMap((packaged, index) => [
420
+ ...index === 0 ? [] : [""],
421
+ ...renderMethod(packaged)
422
+ ])
423
+ );
373
424
  }
374
425
  function renderMethod({ method, packageName: packageName2 }) {
375
426
  const lines = [`${method.path} (${packageName2})`, method.signature];
@@ -378,22 +429,39 @@ function renderMethod({ method, packageName: packageName2 }) {
378
429
  if (method.otherRoutes.length) lines.push(`also: ${method.otherRoutes.join(", ")}`);
379
430
  if (method.declaredAt) lines.push(`source (repository): ${method.declaredAt}`);
380
431
  if (method.example) lines.push(`example: ${method.example}`);
381
- return `${lines.join("\n")}
382
- `;
432
+ return lines;
383
433
  }
384
- function toJson(value) {
385
- return `${JSON.stringify(value, null, " ")}
386
- `;
434
+ function endedTextOf(lines) {
435
+ return textOf(lines.length === 0 ? [] : [...lines, ""]);
387
436
  }
388
437
 
389
438
  // src/lib/config.ts
390
- import { readFileSync as readFileSync3, existsSync as existsSync3, readdirSync as readdirSync3, statSync as statSync2 } from "fs";
391
- import { join as join3 } from "path";
392
- var getArg = (argv, name) => {
393
- const i = argv.indexOf(`--${name}`);
394
- return i >= 0 ? argv[i + 1] : void 0;
439
+ import { readFileSync as readFileSync3, existsSync as existsSync3, readdirSync as readdirSync3, statSync as statSync3 } from "fs";
440
+ import { join as join4 } from "path";
441
+
442
+ // src/lib/config.constants.ts
443
+ var CORE_PACKAGE = "@dialecte/core";
444
+ var CORE_TEST_DIALECT = {
445
+ version: "core",
446
+ binding: {
447
+ kind: "core",
448
+ coreAlias: "Core",
449
+ coreImport: "@/index",
450
+ configType: "TestDialecteConfig",
451
+ configImport: "@/test/config"
452
+ },
453
+ constantsDir: "./src/test/generated",
454
+ outDir: "./benchmarks/types/generated"
395
455
  };
396
- var hasFlag = (argv, name) => argv.includes(`--${name}`);
456
+
457
+ // src/lib/config.ts
458
+ function getArg(argv, name) {
459
+ const index = argv.indexOf(`--${name}`);
460
+ return index >= 0 ? argv[index + 1] : void 0;
461
+ }
462
+ function hasFlag(argv, name) {
463
+ return argv.includes(`--${name}`);
464
+ }
397
465
  function positionalArguments(params) {
398
466
  const words = [];
399
467
  for (let index = 0; index < params.argv.length; index++) {
@@ -403,38 +471,31 @@ function positionalArguments(params) {
403
471
  }
404
472
  return words;
405
473
  }
406
- var tsconfigOf = (argv, cwd = process.cwd()) => getArg(argv, "tsconfig") ?? pkgConfig(cwd).tsconfig ?? "tsconfig.build.json";
407
- var readPkg = (cwd) => {
408
- const p = join3(cwd, "package.json");
409
- return existsSync3(p) ? JSON.parse(readFileSync3(p, "utf8")) : {};
410
- };
411
- var pkgConfig = (cwd) => readPkg(cwd).dialecte ?? {};
412
- var capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
474
+ function tsconfigOf(argv, cwd = process.cwd()) {
475
+ return getArg(argv, "tsconfig") ?? pkgConfig(cwd).tsconfig ?? "tsconfig.build.json";
476
+ }
477
+ function readPkg(cwd) {
478
+ const packageJson = join4(cwd, "package.json");
479
+ return existsSync3(packageJson) ? JSON.parse(readFileSync3(packageJson, "utf8")) : {};
480
+ }
481
+ function pkgConfig(cwd) {
482
+ return readPkg(cwd).dialecte ?? {};
483
+ }
484
+ function capitalize(word) {
485
+ return word.charAt(0).toUpperCase() + word.slice(1);
486
+ }
413
487
  function discoverNamespace(cwd) {
414
488
  return capitalize(
415
489
  String(readPkg(cwd).name ?? "dialecte").split("/").pop() ?? "dialecte"
416
490
  );
417
491
  }
418
492
  function discoverVersions(cwd) {
419
- const src = join3(cwd, "src");
493
+ const src = join4(cwd, "src");
420
494
  if (!existsSync3(src)) return [];
421
- return readdirSync3(src).filter((v) => statSync2(join3(src, v)).isDirectory()).filter(
422
- (v) => existsSync3(join3(src, v, "definition", "constants.generated.ts")) && existsSync3(join3(src, v, "definition", "definition.generated.ts"))
495
+ return readdirSync3(src).filter((v) => statSync3(join4(src, v)).isDirectory()).filter(
496
+ (v) => existsSync3(join4(src, v, "definition", "constants.generated.ts")) && existsSync3(join4(src, v, "definition", "definition.generated.ts"))
423
497
  ).sort();
424
498
  }
425
- var CORE_PACKAGE = "@dialecte/core";
426
- var CORE_TEST_DIALECT = {
427
- version: "core",
428
- binding: {
429
- kind: "core",
430
- coreAlias: "Core",
431
- coreImport: "@/index",
432
- configType: "TestDialecteConfig",
433
- configImport: "@/test/config"
434
- },
435
- constantsDir: "./src/test/generated",
436
- outDir: "./benchmarks/types/generated"
437
- };
438
499
  function resolveTargets(argv, cwd = process.cwd()) {
439
500
  if (readPkg(cwd).name === CORE_PACKAGE)
440
501
  return [
@@ -465,11 +526,13 @@ function resolveTargets(argv, cwd = process.cwd()) {
465
526
 
466
527
  // src/lib/missing-package.ts
467
528
  import { existsSync as existsSync4 } from "fs";
468
- import { join as join4 } from "path";
529
+ import { join as join5 } from "path";
469
530
  function missingPackage(params) {
470
- return existsSync4(join4(params.cwd, "package.json")) ? void 0 : {
471
- output: `no package.json in ${params.cwd}: run dialecte in your package's folder
472
- `,
531
+ return existsSync4(join5(params.cwd, "package.json")) ? void 0 : {
532
+ output: textOf([
533
+ `no package.json in ${params.cwd}: run dialecte in your package's folder`,
534
+ ""
535
+ ]),
473
536
  exitCode: 2
474
537
  };
475
538
  }
@@ -488,8 +551,7 @@ function runApi(params) {
488
551
  const words = positionalArguments({ argv: rest, valueOptions: API_VALUE_OPTIONS });
489
552
  const limit = Number(getArg([...rest], "limit") ?? DEFAULT_FIND_LIMIT);
490
553
  if (!isSubcommand(subcommand) || words.length === 0 || !Number.isInteger(limit) || limit < 1)
491
- return { output: `${API_USAGE}
492
- `, exitCode: 2 };
554
+ return { output: textOf([API_USAGE, ""]), exitCode: 2 };
493
555
  const packageName2 = getArg([...rest], "package");
494
556
  const indexes = readApiIndexes({ cwd: params.cwd }).filter(
495
557
  (index) => packageName2 === void 0 || index.package === packageName2
@@ -504,8 +566,10 @@ function find(params) {
504
566
  const found = findMethods(params);
505
567
  if (found.length === 0 && !params.json)
506
568
  return {
507
- output: `no method found for "${params.need}" in ${packagesText(params.indexes)}: try other words, or \`npx @dialecte/cli members <expression>\` for the live types
508
- `,
569
+ output: textOf([
570
+ `no method found for "${params.need}" in ${packagesText(params.indexes)}: try other words, or \`npx @dialecte/cli members <expression>\` for the live types`,
571
+ ""
572
+ ]),
509
573
  exitCode: 1
510
574
  };
511
575
  return {
@@ -517,8 +581,10 @@ function show(params) {
517
581
  const methods = findByPath(params);
518
582
  if (methods.length === 0 && !params.json)
519
583
  return {
520
- output: `no method "${params.path}" in ${packagesText(params.indexes)}: \`npx @dialecte/cli api find "<what you need>"\` lists the routes
521
- `,
584
+ output: textOf([
585
+ `no method "${params.path}" in ${packagesText(params.indexes)}: \`npx @dialecte/cli api find "<what you need>"\` lists the routes`,
586
+ ""
587
+ ]),
522
588
  exitCode: 1
523
589
  };
524
590
  return { output: renderShown({ methods, json: params.json }), exitCode: methods.length ? 0 : 1 };
@@ -530,35 +596,33 @@ function packagesText(indexes) {
530
596
  // src/lib/doctor/answer-doctor.ts
531
597
  function answerDoctor(params) {
532
598
  const exitCode = params.lines.some((line) => line.status !== "ok") ? 1 : 0;
533
- if (params.json)
534
- return { output: `${JSON.stringify({ lines: params.lines }, null, " ")}
535
- `, exitCode };
536
- return { output: params.lines.map(renderLine).join(""), exitCode };
599
+ if (params.json) return { output: endedOf(jsonOf({ lines: params.lines }, " ")), exitCode };
600
+ return { output: endedTextOf2(params.lines.map(renderLine)), exitCode };
537
601
  }
538
602
  function answerDoctorBrief(lines) {
539
603
  return {
540
- output: lines.filter((line) => line.status !== "ok").map(renderLine).join(""),
604
+ output: endedTextOf2(lines.filter((line) => line.status !== "ok").map(renderLine)),
541
605
  exitCode: 0
542
606
  };
543
607
  }
608
+ function endedTextOf2(lines) {
609
+ return textOf(lines.length === 0 ? [] : [...lines, ""]);
610
+ }
544
611
  function renderLine(line) {
545
- if (line.status === "ok") return `\u2705 ${line.subject} ${line.detail}
546
- `;
612
+ if (line.status === "ok") return `\u2705 ${line.subject} ${line.detail}`;
547
613
  const fix = line.fix ? ` - fix: ${line.fix}` : "";
548
- return line.status === "error" ? `\u274C ${line.subject} ${line.detail}${fix}
549
- ` : `\u26A0\uFE0F ${line.subject} ${line.detail}${fix}
550
- `;
614
+ return line.status === "error" ? `\u274C ${line.subject} ${line.detail}${fix}` : `\u26A0\uFE0F ${line.subject} ${line.detail}${fix}`;
551
615
  }
552
616
 
553
617
  // src/lib/doctor/diagnose.ts
554
618
  import { existsSync as existsSync9, lstatSync as lstatSync3, readdirSync as readdirSync4, readFileSync as readFileSync6 } from "fs";
555
- import { dirname as dirname2, join as join9, resolve as resolve2 } from "path";
619
+ import { dirname as dirname3, join as join10, resolve as resolve2 } from "path";
556
620
 
557
621
  // src/lib/package-json.ts
558
622
  import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
559
- import { join as join5 } from "path";
623
+ import { join as join6 } from "path";
560
624
  function readPackageJson(root) {
561
- const path = join5(root, "package.json");
625
+ const path = join6(root, "package.json");
562
626
  return existsSync5(path) ? JSON.parse(readFileSync4(path, "utf8")) : {};
563
627
  }
564
628
 
@@ -603,7 +667,7 @@ var CONTRIBUTOR_SKILLS_NOT_SYNCED = "{folder} lacks the contributor skills: dial
603
667
 
604
668
  // src/lib/doctor/profile-lines.ts
605
669
  import { existsSync as existsSync6 } from "fs";
606
- import { join as join6 } from "path";
670
+ import { join as join7 } from "path";
607
671
 
608
672
  // src/lib/contrib/contrib.constants.ts
609
673
  var DEFAULT_CONTRIB_STEPS = [
@@ -638,7 +702,7 @@ function profileLines(cwd) {
638
702
  const contributorSteps = DEFAULT_CONTRIB_STEPS.map((step) => step.name);
639
703
  const moved = full.map((step) => step.name).filter((name) => contributorSteps.includes(name));
640
704
  const unsynced = Object.values(AGENT_SKILL_FOLDERS).filter(
641
- (folder) => existsSync6(join6(cwd, folder, MANIFEST_FILE)) && readSyncManifest(join6(cwd, folder)).contributing !== true
705
+ (folder) => existsSync6(join7(cwd, folder, MANIFEST_FILE)) && readSyncManifest(join7(cwd, folder)).contributing !== true
642
706
  );
643
707
  return [
644
708
  { status: "ok", subject: PROFILE_SUBJECT, detail: "contributor" },
@@ -659,11 +723,11 @@ function profileLines(cwd) {
659
723
 
660
724
  // src/lib/doctor/station-agent-lines.ts
661
725
  import { existsSync as existsSync8, readFileSync as readFileSync5 } from "fs";
662
- import { join as join8 } from "path";
726
+ import { join as join9 } from "path";
663
727
 
664
728
  // src/lib/models/remembered-vendor.ts
665
- import { existsSync as existsSync7, statSync as statSync3 } from "fs";
666
- import { join as join7 } from "path";
729
+ import { existsSync as existsSync7, statSync as statSync4 } from "fs";
730
+ import { join as join8 } from "path";
667
731
 
668
732
  // src/lib/models/model-tiers.constants.ts
669
733
  var VENDOR_IDS = ["anthropic", "openai", "google"];
@@ -713,14 +777,14 @@ function isVendorId(value) {
713
777
  // src/lib/models/remembered-vendor.ts
714
778
  function listManifestFolders(cwd) {
715
779
  return Object.values(AGENT_SKILL_FOLDERS).filter(
716
- (folder) => existsSync7(join7(cwd, folder, MANIFEST_FILE))
780
+ (folder) => existsSync7(join8(cwd, folder, MANIFEST_FILE))
717
781
  );
718
782
  }
719
783
  function readRememberedVendor(cwd) {
720
784
  const warnings = [];
721
785
  const entries = [];
722
786
  for (const folder of listManifestFolders(cwd)) {
723
- const { vendor } = readSyncManifest(join7(cwd, folder));
787
+ const { vendor } = readSyncManifest(join8(cwd, folder));
724
788
  if (vendor === void 0) continue;
725
789
  if (!isVendorId(vendor)) {
726
790
  warnings.push(`${folder}/${MANIFEST_FILE}: unknown vendor "${vendor}" ignored`);
@@ -729,7 +793,7 @@ function readRememberedVendor(cwd) {
729
793
  entries.push({
730
794
  folder,
731
795
  vendor,
732
- writtenAt: statSync3(join7(cwd, folder, MANIFEST_FILE)).mtimeMs
796
+ writtenAt: statSync4(join8(cwd, folder, MANIFEST_FILE)).mtimeMs
733
797
  });
734
798
  }
735
799
  entries.sort((first, second) => second.writtenAt - first.writtenAt);
@@ -889,8 +953,8 @@ function planStationAgents(params) {
889
953
 
890
954
  // src/lib/doctor/station-agent-lines.ts
891
955
  function stationAgentLines(cwd) {
892
- const manifestFolder = join8(cwd, AGENT_SKILL_FOLDERS.claude);
893
- if (!existsSync8(join8(manifestFolder, MANIFEST_FILE))) return [];
956
+ const manifestFolder = join9(cwd, AGENT_SKILL_FOLDERS.claude);
957
+ if (!existsSync8(join9(manifestFolder, MANIFEST_FILE))) return [];
894
958
  const listed = readSyncManifest(manifestFolder).stationAgents ?? [];
895
959
  if (listed.length === 0) return [];
896
960
  const plan = planStationAgents({ vendor: readRememberedVendor(cwd).vendor });
@@ -898,7 +962,7 @@ function stationAgentLines(cwd) {
898
962
  const missing = [];
899
963
  const stale = [];
900
964
  for (const file of plan.files) {
901
- const path = join8(cwd, CLAUDE_AGENTS_FOLDER, file.name);
965
+ const path = join9(cwd, CLAUDE_AGENTS_FOLDER, file.name);
902
966
  if (!existsSync8(path)) missing.push(file.name);
903
967
  else if (listed.includes(file.name) && readFileSync5(path, "utf8") !== file.content)
904
968
  stale.push(file.name);
@@ -982,7 +1046,7 @@ function skills(cwd) {
982
1046
  if (sources.length === 0)
983
1047
  return [{ status: "ok", subject: "skills", detail: "no dependency ships skills" }];
984
1048
  const synced = Object.values(AGENT_SKILL_FOLDERS).filter(
985
- (folder) => existsSync9(join9(cwd, folder, MANIFEST_FILE))
1049
+ (folder) => existsSync9(join10(cwd, folder, MANIFEST_FILE))
986
1050
  );
987
1051
  if (synced.length === 0)
988
1052
  return [
@@ -995,7 +1059,7 @@ function skills(cwd) {
995
1059
  ];
996
1060
  const contributor = isContributor(cwd);
997
1061
  return synced.map(function syncLine(folder) {
998
- const manifest = readSyncManifest(join9(cwd, folder));
1062
+ const manifest = readSyncManifest(join10(cwd, folder));
999
1063
  const expected = selectAudience({
1000
1064
  sources,
1001
1065
  contributing: contributor || manifest.contributing === true
@@ -1010,7 +1074,7 @@ function skills(cwd) {
1010
1074
  };
1011
1075
  const stale = expected.flatMap(function staleCopy(source) {
1012
1076
  const recorded = manifest.versions[source.name];
1013
- if (isLink(join9(cwd, folder, source.name)) || source.version === void 0) return [];
1077
+ if (isLink(join10(cwd, folder, source.name)) || source.version === void 0) return [];
1014
1078
  if (recorded?.version === source.version) return [];
1015
1079
  return [
1016
1080
  `${source.name} of ${source.origin} ${recorded?.version ?? "an unknown version"}, ${source.version} installed`
@@ -1041,15 +1105,15 @@ function isLink(path) {
1041
1105
  }
1042
1106
  }
1043
1107
  function dependsOnCore(folder) {
1044
- const manifest = JSON.parse(readFileSync6(join9(folder, "package.json"), "utf8"));
1108
+ const manifest = JSON.parse(readFileSync6(join10(folder, "package.json"), "utf8"));
1045
1109
  return manifest.name !== CORE_PACKAGE2 && (manifest.dependencies?.[CORE_PACKAGE2] !== void 0 || manifest.peerDependencies?.[CORE_PACKAGE2] !== void 0);
1046
1110
  }
1047
1111
  function localCheckouts(context) {
1048
1112
  const roots = [
1049
- ...new Set([context.dialecteRoot, dirname2(resolve2(context.cwd))].filter(isDefined2))
1113
+ ...new Set([context.dialecteRoot, dirname3(resolve2(context.cwd))].filter(isDefined2))
1050
1114
  ];
1051
1115
  return roots.map(function checkoutLine(root) {
1052
- const names = existsSync9(root) ? readdirSync4(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && join9(root, entry.name) !== resolve2(context.cwd)).filter((entry) => packageName(join9(root, entry.name))?.startsWith(DIALECTE_SCOPE)).map((entry) => entry.name).sort(TEXT_COLLATOR.compare) : [];
1116
+ const names = existsSync9(root) ? readdirSync4(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && join10(root, entry.name) !== resolve2(context.cwd)).filter((entry) => packageName(join10(root, entry.name))?.startsWith(DIALECTE_SCOPE)).map((entry) => entry.name).sort(TEXT_COLLATOR.compare) : [];
1053
1117
  return {
1054
1118
  status: "ok",
1055
1119
  subject: "checkouts",
@@ -1058,7 +1122,7 @@ function localCheckouts(context) {
1058
1122
  });
1059
1123
  }
1060
1124
  function declaredVersions(cwd) {
1061
- const manifest = JSON.parse(readFileSync6(join9(cwd, "package.json"), "utf8"));
1125
+ const manifest = JSON.parse(readFileSync6(join10(cwd, "package.json"), "utf8"));
1062
1126
  const names = dependencyNames(cwd);
1063
1127
  return Object.fromEntries(
1064
1128
  names.map((name) => [
@@ -1071,12 +1135,12 @@ function declaredVersions(cwd) {
1071
1135
  }
1072
1136
  function installedVersion(params) {
1073
1137
  const folder = findInstalledPackage(params);
1074
- if (!folder || !existsSync9(join9(folder, "package.json"))) return void 0;
1075
- const version = JSON.parse(readFileSync6(join9(folder, "package.json"), "utf8")).version;
1138
+ if (!folder || !existsSync9(join10(folder, "package.json"))) return void 0;
1139
+ const version = JSON.parse(readFileSync6(join10(folder, "package.json"), "utf8")).version;
1076
1140
  return typeof version === "string" ? version : void 0;
1077
1141
  }
1078
1142
  function packageName(folder) {
1079
- const path = join9(folder, "package.json");
1143
+ const path = join10(folder, "package.json");
1080
1144
  if (!existsSync9(path)) return void 0;
1081
1145
  const name = JSON.parse(readFileSync6(path, "utf8")).name;
1082
1146
  return typeof name === "string" ? name : void 0;
@@ -1087,18 +1151,18 @@ function isDefined2(value) {
1087
1151
 
1088
1152
  // src/lib/read-cli-version.ts
1089
1153
  import { existsSync as existsSync10, readFileSync as readFileSync7 } from "fs";
1090
- import { dirname as dirname3, join as join10 } from "path";
1154
+ import { dirname as dirname4, join as join11 } from "path";
1091
1155
  import { fileURLToPath } from "url";
1092
1156
  function readCliVersion(params = {}) {
1093
- const startFolder = params.startFolder ?? dirname3(fileURLToPath(import.meta.url));
1157
+ const startFolder = params.startFolder ?? dirname4(fileURLToPath(import.meta.url));
1094
1158
  let folder = startFolder;
1095
- while (!existsSync10(join10(folder, "package.json"))) {
1096
- const parent = dirname3(folder);
1159
+ while (!existsSync10(join11(folder, "package.json"))) {
1160
+ const parent = dirname4(folder);
1097
1161
  if (parent === folder)
1098
1162
  throw new Error(`no package.json above ${startFolder}: cannot read the cli version`);
1099
1163
  folder = parent;
1100
1164
  }
1101
- const { version } = JSON.parse(readFileSync7(join10(folder, "package.json"), "utf8"));
1165
+ const { version } = JSON.parse(readFileSync7(join11(folder, "package.json"), "utf8"));
1102
1166
  return version;
1103
1167
  }
1104
1168
 
@@ -1119,7 +1183,7 @@ function runBrief(context) {
1119
1183
  diagnose({ ...context, cliVersion: resolveVersion(context.cliVersion), brief: true })
1120
1184
  );
1121
1185
  } catch {
1122
- return { output: "", exitCode: 0 };
1186
+ return { output: textOf([]), exitCode: 0 };
1123
1187
  }
1124
1188
  }
1125
1189
  function resolveVersion(cliVersion) {
@@ -1197,13 +1261,11 @@ function answerMembers(params) {
1197
1261
  const members = listMembers(params);
1198
1262
  if (params.json)
1199
1263
  return {
1200
- output: `${JSON.stringify({ expression, members }, null, " ")}
1201
- `,
1264
+ output: endedOf(jsonOf({ expression, members }, " ")),
1202
1265
  exitCode: members.length ? 0 : 1
1203
1266
  };
1204
1267
  if (members.length)
1205
- return { output: `${[expression, ...members.map(memberLine)].join("\n")}
1206
- `, exitCode: 0 };
1268
+ return { output: textOf([expression, ...members.map(memberLine), ""]), exitCode: 0 };
1207
1269
  const parent = expression.slice(0, Math.max(0, expression.lastIndexOf(".")));
1208
1270
  const neighbours = parent ? listMembers({ entries: params.entries, expression: parent }).map((member) => member.name) : [];
1209
1271
  const closest = closestNames({
@@ -1212,8 +1274,7 @@ function answerMembers(params) {
1212
1274
  limit: MEMBER_SUGGESTION_LIMIT
1213
1275
  });
1214
1276
  const hint = parent ? ` - under ${parent}: ${(closest.length ? closest : neighbours).join(", ") || "nothing"}` : "";
1215
- return { output: `nothing at ${expression}${hint}
1216
- `, exitCode: 1 };
1277
+ return { output: textOf([`nothing at ${expression}${hint}`, ""]), exitCode: 1 };
1217
1278
  }
1218
1279
  function memberLine(member) {
1219
1280
  if (member.kind === "group")
@@ -1230,7 +1291,7 @@ function namespaceOf(packageName2) {
1230
1291
  // src/lib/schema/load-dialectes.ts
1231
1292
  import { existsSync as existsSync11, readFileSync as readFileSync8 } from "fs";
1232
1293
  import { createRequire } from "module";
1233
- import { join as join11 } from "path";
1294
+ import { join as join12 } from "path";
1234
1295
  import { pathToFileURL } from "url";
1235
1296
 
1236
1297
  // src/lib/schema/schema.constants.ts
@@ -1273,6 +1334,7 @@ async function loadDialectes(params) {
1273
1334
  return result;
1274
1335
  }
1275
1336
  async function loadDialecte(params) {
1337
+ const standard = readStandard(params.manifest);
1276
1338
  let config;
1277
1339
  for (const file of entryFiles(params)) {
1278
1340
  const exported = await import(pathToFileURL(file).href);
@@ -1280,16 +1342,26 @@ async function loadDialecte(params) {
1280
1342
  if (config) break;
1281
1343
  }
1282
1344
  if (!config) return void 0;
1283
- const readersFile = createRequire(join11(params.folder, "package.json")).resolve(CORE_READERS_ENTRY);
1345
+ const readersFile = createRequire(join12(params.folder, "package.json")).resolve(CORE_READERS_ENTRY);
1284
1346
  const readers = await import(pathToFileURL(readersFile).href);
1285
1347
  if (!isCoreReaders(readers))
1286
1348
  throw new Error(
1287
1349
  `its core (${readersFile}) lacks ${CORE_READER_NAMES.filter((name) => typeof readers[name] !== "function").join(", ")}: update @dialecte/core`
1288
1350
  );
1289
- return { packageName: params.packageName, config, readers };
1351
+ return { packageName: params.packageName, config, readers, standard };
1352
+ }
1353
+ function readStandard(manifest) {
1354
+ const field = manifest.dialecte;
1355
+ if (typeof field !== "object" || field === null || !("standard" in field)) return void 0;
1356
+ const { standard } = field;
1357
+ if (typeof standard !== "string" || standard.trim() === "")
1358
+ throw new Error(
1359
+ `dialecte.standard must be a non-empty string, found ${JSON.stringify(standard) ?? String(standard)}`
1360
+ );
1361
+ return standard;
1290
1362
  }
1291
1363
  function readManifest(folder) {
1292
- const path = join11(folder, "package.json");
1364
+ const path = join12(folder, "package.json");
1293
1365
  return existsSync11(path) ? JSON.parse(readFileSync8(path, "utf8")) : void 0;
1294
1366
  }
1295
1367
  function isBuiltOnCore(manifest) {
@@ -1300,7 +1372,7 @@ function entryFiles(params) {
1300
1372
  const targets = exports === void 0 ? main ? [[".", main]] : [] : typeof exports === "string" ? [[".", exports]] : Object.entries(exports);
1301
1373
  return targets.filter(([subpath]) => !subpath.split("/").includes("test") && !subpath.includes("*")).flatMap(([, target]) => {
1302
1374
  const file = fileOf(target);
1303
- return file && file.endsWith("js") ? [join11(params.folder, file)] : [];
1375
+ return file && file.endsWith("js") ? [join12(params.folder, file)] : [];
1304
1376
  }).map(function existingFile(file) {
1305
1377
  if (!existsSync11(file))
1306
1378
  throw new Error(`entry file not found: ${file} (is the package built?)`);
@@ -1322,7 +1394,7 @@ function isCoreReaders(module) {
1322
1394
  // src/lib/api/installed-bindings.constants.ts
1323
1395
  var VERSION_SUBPATH_PATTERN = /^\.\/[^/*]+$/;
1324
1396
  var TEST_ENTRY = "test";
1325
- var NO_DIALECTE_INSTALLED = "no dialecte installed here (a dependency built on @dialecte/core exporting ./<version> with ./<version>/test): pass --namespace <Name> --entry <module>\n";
1397
+ var NO_DIALECTE_INSTALLED = "no dialecte installed here (a dependency built on @dialecte/core exporting ./<version> with ./<version>/test): pass --namespace <Name> --entry <module>";
1326
1398
 
1327
1399
  // src/lib/api/installed-bindings.ts
1328
1400
  function findInstalledBindings(params) {
@@ -1347,7 +1419,8 @@ function versionsOf(manifest) {
1347
1419
  return subpaths.filter((subpath) => VERSION_SUBPATH_PATTERN.test(subpath)).filter((subpath) => subpaths.includes(`${subpath}/${TEST_ENTRY}`)).map((subpath) => subpath.slice(2));
1348
1420
  }
1349
1421
  function chooseInstalledBinding(params) {
1350
- if (params.bindings.length === 0) return { kind: "output", message: NO_DIALECTE_INSTALLED };
1422
+ if (params.bindings.length === 0)
1423
+ return { kind: "output", message: textOf([NO_DIALECTE_INSTALLED, ""]) };
1351
1424
  const matching = params.bindings.filter(
1352
1425
  (binding) => (params.packageName === void 0 || binding.packageName === params.packageName) && (params.version === void 0 || binding.version === params.version)
1353
1426
  );
@@ -1359,24 +1432,29 @@ function chooseInstalledBinding(params) {
1359
1432
  ].join(" ");
1360
1433
  return {
1361
1434
  kind: "output",
1362
- message: `no installed dialecte matches ${named}; installed:
1363
- ${listLines(params.bindings)}`
1435
+ message: textOf([
1436
+ `no installed dialecte matches ${named}; installed:`,
1437
+ ...listLines(params.bindings),
1438
+ ""
1439
+ ])
1364
1440
  };
1365
1441
  }
1366
1442
  return {
1367
1443
  kind: "output",
1368
- message: `several dialectes are installed: pass --package <name> [--version <v>]
1369
- ${listLines(matching)}`
1444
+ message: textOf([
1445
+ "several dialectes are installed: pass --package <name> [--version <v>]",
1446
+ ...listLines(matching),
1447
+ ""
1448
+ ])
1370
1449
  };
1371
1450
  }
1372
1451
  function listLines(bindings) {
1373
- return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}
1374
- `).join("");
1452
+ return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}`);
1375
1453
  }
1376
1454
 
1377
1455
  // src/lib/discover.ts
1378
1456
  import { mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
1379
- import { dirname as dirname4, join as join12, relative as relative2 } from "path";
1457
+ import { dirname as dirname5, join as join13, relative as relative3 } from "path";
1380
1458
 
1381
1459
  // src/lib/discover.constants.ts
1382
1460
  import ts from "typescript";
@@ -1413,12 +1491,12 @@ function renderLink(link) {
1413
1491
  import ts2 from "typescript";
1414
1492
  function discoverMethods(params) {
1415
1493
  const { entrySource, tsconfig, root, maxDepth = 1 } = params;
1416
- const entryPath = join12(root, ENTRY_FOLDER, `discover-entry-${process.pid}.ts`);
1417
- mkdirSync2(dirname4(entryPath), { recursive: true });
1494
+ const entryPath = join13(root, ENTRY_FOLDER, `discover-entry-${process.pid}.ts`);
1495
+ mkdirSync2(dirname5(entryPath), { recursive: true });
1418
1496
  writeFileSync2(entryPath, entrySource);
1419
1497
  try {
1420
1498
  const parsed = ts2.parseJsonConfigFileContent(
1421
- ts2.readConfigFile(join12(root, tsconfig), ts2.sys.readFile).config,
1499
+ ts2.readConfigFile(join13(root, tsconfig), ts2.sys.readFile).config,
1422
1500
  ts2.sys,
1423
1501
  root
1424
1502
  );
@@ -1638,12 +1716,12 @@ function declaresFunction(declaration) {
1638
1716
  function declarationKey(params) {
1639
1717
  const declaration = params.symbol?.declarations?.[0];
1640
1718
  if (!declaration) return void 0;
1641
- return `${relative2(params.root, declaration.getSourceFile().fileName)}:${declaration.getStart()}`;
1719
+ return `${relative3(params.root, declaration.getSourceFile().fileName)}:${declaration.getStart()}`;
1642
1720
  }
1643
1721
  function isDeclaredInPackage(params) {
1644
1722
  const fileName = params.symbol?.declarations?.[0]?.getSourceFile().fileName;
1645
1723
  if (!fileName) return false;
1646
- const path = relative2(params.root, fileName);
1724
+ const path = relative3(params.root, fileName);
1647
1725
  return !path.startsWith("..") && !path.split(/[\\/]/).includes("node_modules");
1648
1726
  }
1649
1727
  function declarationOf(symbol) {
@@ -1721,8 +1799,7 @@ function readMemberEntries(params) {
1721
1799
  const [expression] = positionalArguments({ argv, valueOptions: MEMBERS_VALUE_OPTIONS });
1722
1800
  const usage = {
1723
1801
  kind: "output",
1724
- output: { output: `${MEMBERS_USAGE}
1725
- `, exitCode: 2 }
1802
+ output: { output: textOf([MEMBERS_USAGE, ""]), exitCode: 2 }
1726
1803
  };
1727
1804
  if (!expression) return usage;
1728
1805
  const binding = readBinding({ argv, cwd });
@@ -1753,31 +1830,35 @@ function answerModels(params) {
1753
1830
  const knownIds = VENDOR_IDS;
1754
1831
  if (params.vendor === void 0)
1755
1832
  return {
1756
- output: `dialecte models: no vendor known for this project. Run \`dialecte skills sync --vendor <${knownIds.join("|")}>\`, or pass \`--vendor <id>\`.
1757
- `,
1833
+ output: textOf([
1834
+ `dialecte models: no vendor known for this project. Run \`dialecte skills sync --vendor <${knownIds.join("|")}>\`, or pass \`--vendor <id>\`.`,
1835
+ ""
1836
+ ]),
1758
1837
  exitCode: 2
1759
1838
  };
1760
1839
  if (!isVendorId(params.vendor))
1761
1840
  return {
1762
- output: `dialecte models: unknown vendor "${params.vendor}" (known: ${knownIds.join(", ")})
1763
- `,
1841
+ output: textOf([
1842
+ `dialecte models: unknown vendor "${params.vendor}" (known: ${knownIds.join(", ")})`,
1843
+ ""
1844
+ ]),
1764
1845
  exitCode: 1
1765
1846
  };
1766
1847
  const models = MODEL_TIERS.vendors[params.vendor];
1767
1848
  if (params.json)
1768
1849
  return {
1769
- output: `${JSON.stringify(
1770
- {
1771
- vendor: params.vendor,
1772
- checkedAt: MODEL_TIERS.checkedAt,
1773
- tiers: models.tiers,
1774
- ...models.note === void 0 ? {} : { note: models.note },
1775
- definitions: TIER_DEFINITIONS
1776
- },
1777
- null,
1778
- " "
1779
- )}
1780
- `,
1850
+ output: endedOf(
1851
+ jsonOf(
1852
+ {
1853
+ vendor: params.vendor,
1854
+ checkedAt: MODEL_TIERS.checkedAt,
1855
+ tiers: models.tiers,
1856
+ ...models.note === void 0 ? {} : { note: models.note },
1857
+ definitions: TIER_DEFINITIONS
1858
+ },
1859
+ " "
1860
+ )
1861
+ ),
1781
1862
  exitCode: 0
1782
1863
  };
1783
1864
  const width = Math.max(...TIER_NAMES.map((tier) => tier.length)) + 2;
@@ -1788,8 +1869,7 @@ function answerModels(params) {
1788
1869
  "",
1789
1870
  ...TIER_NAMES.map((tier) => `${tier.padEnd(width)}${TIER_DEFINITIONS[tier]}`)
1790
1871
  ];
1791
- return { output: `${lines.join("\n")}
1792
- `, exitCode: 0 };
1872
+ return { output: textOf([...lines, ""]), exitCode: 0 };
1793
1873
  }
1794
1874
  function renderModel(tierModel) {
1795
1875
  return tierModel.effort === void 0 ? tierModel.model : `${tierModel.model} (${tierModel.effort})`;
@@ -1798,22 +1878,102 @@ function renderModel(tierModel) {
1798
1878
  // src/commands/models.ts
1799
1879
  function runModels(params) {
1800
1880
  const missing = missingPackage({ cwd: params.cwd });
1801
- if (missing) return { ...missing, warnings: "" };
1881
+ if (missing) return { ...missing, warnings: textOf([]) };
1802
1882
  const argv = [...params.argv];
1803
1883
  const remembered = readRememberedVendor(params.cwd);
1804
1884
  const answer = answerModels({
1805
1885
  vendor: getArg(argv, "vendor") ?? remembered.vendor,
1806
1886
  json: hasFlag(argv, "json")
1807
1887
  });
1808
- return { ...answer, warnings: remembered.warnings.map((warning) => `\u26A0\uFE0F ${warning}
1809
- `).join("") };
1888
+ const warnings = remembered.warnings.map((warning) => `\u26A0\uFE0F ${warning}`);
1889
+ return { ...answer, warnings: textOf(warnings.length === 0 ? [] : [...warnings, ""]) };
1890
+ }
1891
+
1892
+ // src/lib/schema/resolve-declaration.ts
1893
+ function resolveDeclaration(params) {
1894
+ const tagLevel = params.definition[params.tagName];
1895
+ if (tagLevel === void 0) return void 0;
1896
+ const declarations = tagLevel.declarations;
1897
+ if (declarations === void 0) return { declarations: 1, resolved: true, id: void 0 };
1898
+ const id = singleHeldId({
1899
+ definition: params.definition,
1900
+ tagName: params.tagName,
1901
+ parent: params.parent
1902
+ });
1903
+ const known = id !== void 0 && declarations[id] !== void 0;
1904
+ return {
1905
+ declarations: Object.keys(declarations).length,
1906
+ resolved: known,
1907
+ id: known ? id : void 0
1908
+ };
1909
+ }
1910
+ function heldDeclarationIds(params) {
1911
+ const held = heldByNamespace(params);
1912
+ return held === void 0 ? [] : [...new Set(Object.values(held).flat())];
1913
+ }
1914
+ function declarationParents(params) {
1915
+ const { definition, tagName, id } = params;
1916
+ return (definition[tagName]?.parents ?? []).filter(function holdsDeclaration(parent) {
1917
+ return heldDeclarationIds({ definition, tagName, parent }).includes(id);
1918
+ });
1919
+ }
1920
+ function singleHeldId(params) {
1921
+ const held = heldByNamespace(params);
1922
+ if (held === void 0) return void 0;
1923
+ const namespaces = Object.keys(held);
1924
+ if (namespaces.length !== 1) return void 0;
1925
+ const ids = held[namespaces[0]];
1926
+ return ids?.length === 1 ? ids[0] : void 0;
1927
+ }
1928
+ function heldByNamespace(params) {
1929
+ if (params.parent === void 0) return void 0;
1930
+ return params.definition[params.parent]?.children.details[params.tagName]?.declarations;
1810
1931
  }
1811
1932
 
1812
1933
  // src/lib/schema/describe-element.ts
1813
1934
  function describeElement(params) {
1935
+ const { dialecte, tagName, parent } = params;
1936
+ const { definition, elements } = dialecte.config;
1937
+ const tagLevel = definition[tagName];
1938
+ if (!elements.includes(tagName) || tagLevel === void 0) return void 0;
1939
+ if (parent !== void 0 && !tagLevel.parents.includes(parent)) return void 0;
1940
+ const resolution = resolveDeclaration({ definition, tagName, parent });
1941
+ if (resolution === void 0) return void 0;
1942
+ if (resolution.id !== void 0)
1943
+ return describeDeclaration({ dialecte, tagName, id: resolution.id });
1944
+ return describeDefinition({
1945
+ dialecte,
1946
+ tagName,
1947
+ declaration: void 0,
1948
+ declarations: resolution.declarations,
1949
+ resolved: resolution.resolved
1950
+ });
1951
+ }
1952
+ function describeDeclaration(params) {
1953
+ const { dialecte, tagName, id } = params;
1954
+ const declarations = dialecte.config.definition[tagName]?.declarations;
1955
+ if (declarations?.[id] === void 0) return void 0;
1956
+ return describeDefinition({
1957
+ dialecte: { ...dialecte, config: declarationView({ config: dialecte.config, tagName, id }) },
1958
+ tagName,
1959
+ declaration: id,
1960
+ declarations: Object.keys(declarations).length,
1961
+ resolved: true
1962
+ });
1963
+ }
1964
+ function declarationView(params) {
1965
+ const { config, tagName, id } = params;
1966
+ const tagLevel = config.definition[tagName];
1967
+ const declaration = tagLevel.declarations?.[id];
1968
+ if (declaration === void 0) return config;
1969
+ const parents = declarationParents({ definition: config.definition, tagName, id });
1970
+ const element = { ...declaration, tag: tagLevel.tag, parents };
1971
+ return { ...config, definition: { ...config.definition, [tagName]: element } };
1972
+ }
1973
+ function describeDefinition(params) {
1814
1974
  const { config, readers, packageName: packageName2 } = params.dialecte;
1815
1975
  const record = { tagName: params.tagName, parent: null, attributes: [] };
1816
- const definition = config.elements.includes(params.tagName) ? readers.resolveDefinition({ dialecteConfig: config, record }) : void 0;
1976
+ const definition = readers.resolveDefinition({ dialecteConfig: config, record });
1817
1977
  if (definition === void 0) return void 0;
1818
1978
  const occurrences = readers.childOccurrences({ definition });
1819
1979
  const children = readers.orderByConfigSequence({
@@ -1844,7 +2004,12 @@ function describeElement(params) {
1844
2004
  };
1845
2005
  }),
1846
2006
  text: definition.textContent ? typeName(definition.textContent.type) ?? "string" : void 0,
1847
- xsiTypes: readers.admittedXsiTypes({ dialecteConfig: config, record })
2007
+ xsiTypes: readers.admittedXsiTypes({ dialecteConfig: config, record }),
2008
+ type: definition.type,
2009
+ documentation: definition.documentation,
2010
+ declaration: params.declaration,
2011
+ declarations: params.declarations,
2012
+ resolved: params.resolved
1848
2013
  };
1849
2014
  }
1850
2015
  function typeName(datatype) {
@@ -1853,24 +2018,104 @@ function typeName(datatype) {
1853
2018
  return "list" in datatype ? "list" : "union";
1854
2019
  }
1855
2020
 
2021
+ // src/lib/schema/describe-declarations.ts
2022
+ function describeDeclarations(params) {
2023
+ const { dialecte, tagName, ids } = params;
2024
+ const { definition, elements } = dialecte.config;
2025
+ const declarations = elements.includes(tagName) ? definition[tagName]?.declarations : void 0;
2026
+ const kept = Object.entries(declarations ?? {}).filter(
2027
+ ([id]) => ids === void 0 || ids.includes(id)
2028
+ );
2029
+ return kept.flatMap(function describeWay([id, declaration]) {
2030
+ const element = describeDeclaration({ dialecte, tagName, id });
2031
+ if (element === void 0) return [];
2032
+ return [
2033
+ {
2034
+ id,
2035
+ parents: declarationParents({ definition, tagName, id }),
2036
+ global: declaration.global === true,
2037
+ element
2038
+ }
2039
+ ];
2040
+ });
2041
+ }
2042
+
1856
2043
  // src/lib/schema/answer-schema.ts
1857
2044
  function answerSchema(params) {
1858
- const { loaded, tagName } = params;
1859
- const elements = loaded.dialectes.flatMap(
1860
- (dialecte) => describeElement({ dialecte, tagName }) ?? []
2045
+ const { loaded, tagName, under } = params;
2046
+ const answers = loaded.dialectes.flatMap(
2047
+ (dialecte) => answerOf({ dialecte, tagName, under }) ?? []
1861
2048
  );
1862
2049
  if (params.json)
1863
2050
  return {
1864
- output: `${JSON.stringify({ elements, skipped: loaded.skipped }, null, " ")}
1865
- `,
1866
- exitCode: elements.length ? 0 : 1
2051
+ output: endedOf(
2052
+ jsonOf({ elements: answers.map(jsonElementOf), skipped: loaded.skipped }, " ")
2053
+ ),
2054
+ exitCode: answers.length ? 0 : 1
1867
2055
  };
1868
- if (elements.length) return { output: elements.map(renderElement).join("\n"), exitCode: 0 };
2056
+ if (answers.length)
2057
+ return {
2058
+ output: textOf([
2059
+ ...answers.flatMap((answer, index) => [
2060
+ ...index === 0 ? [] : [""],
2061
+ ...renderAnswer(answer)
2062
+ ]),
2063
+ ""
2064
+ ]),
2065
+ exitCode: 0
2066
+ };
2067
+ return { output: textOf([...missingLines({ loaded, tagName, under }), ""]), exitCode: 1 };
2068
+ }
2069
+ function answerOf(params) {
2070
+ const { dialecte, tagName, under } = params;
2071
+ const element = describeElement({ dialecte, tagName, parent: under });
2072
+ if (element === void 0) return void 0;
2073
+ const ways = element.resolved ? [] : describeDeclarations({ dialecte, tagName, ids: openIds({ dialecte, tagName, under }) });
2074
+ return { element, ways, under };
2075
+ }
2076
+ function openIds(params) {
2077
+ const { dialecte, tagName, under } = params;
2078
+ if (under === void 0) return void 0;
2079
+ const held = heldDeclarationIds({
2080
+ definition: dialecte.config.definition,
2081
+ tagName,
2082
+ parent: under
2083
+ });
2084
+ return held.length ? held : void 0;
2085
+ }
2086
+ function jsonElementOf(answer) {
2087
+ return answer.element.resolved ? answer.element : { ...answer.element, ways: answer.ways };
2088
+ }
2089
+ function renderAnswer(answer) {
2090
+ const { element, under } = answer;
2091
+ if (element.resolved && (element.declaration === void 0 || under === void 0))
2092
+ return renderElement(element);
2093
+ if (element.resolved)
2094
+ return [
2095
+ `${element.tag} under ${under}: declaration ${element.declaration}, one of ${element.declarations} ways`,
2096
+ ...renderElement(element)
2097
+ ];
2098
+ const heading = under === void 0 ? `${element.tag} is declared ${element.declarations} ways - pick one with --under <Parent>` : `${element.tag} under ${under}: declarations ${listOf(answer.ways.map((way) => way.id))} of ${element.declarations}, the parent does not decide`;
2099
+ return [
2100
+ heading,
2101
+ ...answer.ways.flatMap((way, index) => [...index === 0 ? [] : [""], ...renderWay(way)])
2102
+ ];
2103
+ }
2104
+ function renderWay(way) {
2105
+ return [`declaration ${way.id}${way.global ? " global" : ""}`, ...renderElement(way.element)];
2106
+ }
2107
+ function listOf(words) {
2108
+ if (words.length < 2) return words.join("");
2109
+ return `${words.slice(0, -1).join(", ")} and ${words[words.length - 1]}`;
2110
+ }
2111
+ function missingLines(params) {
2112
+ const { loaded, tagName, under } = params;
1869
2113
  const skipped = loaded.skipped.length ? ` (skipped ${loaded.skipped.map((entry) => `${entry.packageName}: ${entry.reason}`).join("; ")})` : "";
1870
- if (loaded.dialectes.length === 0)
1871
- return { output: `no installed dialecte holds "${tagName}"${skipped}
1872
- `, exitCode: 1 };
1873
- const suggestions = loaded.dialectes.map((dialecte) => {
2114
+ if (loaded.dialectes.length === 0) return [`no installed dialecte holds "${tagName}"${skipped}`];
2115
+ const lines = loaded.dialectes.map(function missingLine(dialecte) {
2116
+ const tagLevel = dialecte.config.elements.includes(tagName) ? dialecte.config.definition[tagName] : void 0;
2117
+ if (tagLevel !== void 0 && under !== void 0)
2118
+ return `no ${tagName} under ${under} - its parents: ${tagLevel.parents.join(", ") || "none (the root)"}`;
1874
2119
  const closest = closestNames({
1875
2120
  name: tagName,
1876
2121
  candidates: dialecte.config.elements,
@@ -1878,14 +2123,14 @@ function answerSchema(params) {
1878
2123
  });
1879
2124
  return `no element "${tagName}" in ${dialecte.packageName}${closest.length ? ` - closest: ${closest.join(", ")}` : ""}`;
1880
2125
  });
1881
- return { output: `${suggestions.join("\n")}${skipped}
1882
- `, exitCode: 1 };
2126
+ const lastIndex = lines.length - 1;
2127
+ return lines.map((line, index) => index === lastIndex ? `${line}${skipped}` : line);
1883
2128
  }
1884
2129
  function renderElement(element) {
1885
- const lines = [
1886
- `${element.tag} ${element.packageName} {${element.namespace}}`,
1887
- `parents: ${element.parents.join(", ") || "none (the root)"}`
1888
- ];
2130
+ const lines = [`${element.tag} ${element.packageName} {${element.namespace}}`];
2131
+ if (element.documentation !== void 0) lines.push(`documentation: ${element.documentation}`);
2132
+ if (element.type !== void 0) lines.push(`type: ${element.type}`);
2133
+ lines.push(`parents: ${element.parents.join(", ") || "none (the root)"}`);
1889
2134
  if (element.children.length || element.anyChild) lines.push("children, in order:");
1890
2135
  else lines.push("children: none");
1891
2136
  for (const child of element.children)
@@ -1895,8 +2140,7 @@ function renderElement(element) {
1895
2140
  for (const attribute of element.attributes) lines.push(` ${renderAttribute(attribute)}`);
1896
2141
  lines.push(`text: ${element.text ?? "none"}`);
1897
2142
  if (element.xsiTypes.length) lines.push(`xsi:type: ${element.xsiTypes.join(", ")}`);
1898
- return `${lines.join("\n")}
1899
- `;
2143
+ return lines;
1900
2144
  }
1901
2145
  function renderAttribute(attribute) {
1902
2146
  const parts = [
@@ -1914,21 +2158,24 @@ function renderAttribute(attribute) {
1914
2158
  }
1915
2159
 
1916
2160
  // src/commands/schema.constants.ts
1917
- var SCHEMA_VALUE_OPTIONS = ["package"];
1918
- var SCHEMA_USAGE = "usage: dialecte schema <Tag> [--package <name>] [--json]";
2161
+ var SCHEMA_VALUE_OPTIONS = ["package", "under"];
2162
+ var SCHEMA_USAGE = "usage: dialecte schema <Tag> [--under <Parent>] [--package <name>] [--json]";
1919
2163
 
1920
2164
  // src/commands/schema.ts
1921
2165
  async function readSchemaDialectes(params) {
1922
2166
  const missing = missingPackage({ cwd: params.cwd });
1923
2167
  if (missing) return { kind: "output", output: missing };
1924
2168
  const [tagName] = positionalArguments({ argv: params.argv, valueOptions: SCHEMA_VALUE_OPTIONS });
1925
- if (!tagName) return { kind: "output", output: { output: `${SCHEMA_USAGE}
1926
- `, exitCode: 2 } };
2169
+ const under = getArg(params.argv, "under");
2170
+ const underWithoutValue = hasFlag(params.argv, "under") && (under === void 0 || under === "" || under.startsWith("--"));
2171
+ if (!tagName || underWithoutValue)
2172
+ return { kind: "output", output: { output: textOf([SCHEMA_USAGE, ""]), exitCode: 2 } };
1927
2173
  const packageName2 = getArg(params.argv, "package");
1928
2174
  const loaded = await loadDialectes({ cwd: params.cwd });
1929
2175
  return {
1930
2176
  kind: "dialectes",
1931
2177
  tagName,
2178
+ under,
1932
2179
  packageName: packageName2,
1933
2180
  installed: loaded.dialectes.map((dialecte) => dialecte.packageName),
1934
2181
  loaded: {
@@ -1942,6 +2189,7 @@ async function readSchemaDialectes(params) {
1942
2189
  export {
1943
2190
  answerMembers,
1944
2191
  answerSchema,
2192
+ describeElement,
1945
2193
  packagesText,
1946
2194
  readApiIndexes,
1947
2195
  readCliVersion,