@dialecte/cli 0.2.0 → 0.2.2

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.
Files changed (4) hide show
  1. package/README.md +65 -17
  2. package/dist/cli.js +1530 -1035
  3. package/dist/lookups.js +291 -177
  4. package/package.json +3 -2
package/dist/lookups.js CHANGED
@@ -123,6 +123,7 @@ import { join as join2 } from "path";
123
123
  // src/lib/skills/skill-file.constants.ts
124
124
  var SKILLS_FOLDER = "skills";
125
125
  var SKILL_NAME_PATTERN = /^(?=.{1,64}$)[a-z0-9]+(-[a-z0-9]+)*$/;
126
+ var CONTRIBUTOR_AUDIENCE = "contributor";
126
127
 
127
128
  // src/lib/skills/sync-skills.ts
128
129
  import {
@@ -134,6 +135,7 @@ import {
134
135
  readFileSync,
135
136
  readlinkSync,
136
137
  rmSync,
138
+ statSync,
137
139
  symlinkSync,
138
140
  unlinkSync,
139
141
  writeFileSync
@@ -143,6 +145,38 @@ import { dirname, join, parse, relative, resolve } from "path";
143
145
  // src/lib/file-system.ts
144
146
  import { lstatSync, realpathSync } from "fs";
145
147
 
148
+ // src/lib/skills/skill-file.ts
149
+ function readFrontmatter(markdown) {
150
+ const block = /^---\n([\s\S]*?)\n---/.exec(withUnixLineEndings(markdown))?.[1];
151
+ if (!block) return { name: void 0, description: void 0 };
152
+ return {
153
+ name: readField({ block, field: "name" }),
154
+ description: readField({ block, field: "description" }),
155
+ audience: readMetadataField({ block, field: "audience" })
156
+ };
157
+ }
158
+ function readMetadataField(params) {
159
+ const lines = /^metadata:[ \t]*\n((?:[ \t]+.*\n?)*)/m.exec(`${params.block}
160
+ `)?.[1];
161
+ if (!lines) return void 0;
162
+ const indent = /^[ \t]+/.exec(lines)?.[0] ?? "";
163
+ const ownLines = lines.split("\n").filter((line) => line.startsWith(indent) && !/^[ \t]/.test(line.slice(indent.length))).map((line) => line.slice(indent.length));
164
+ return readField({ block: ownLines.join("\n"), field: params.field });
165
+ }
166
+ function readField(params) {
167
+ const match = new RegExp(`^${params.field}:[ \\t]*(.*)\\n?((?:[ \\t]+.*\\n?)*)`, "m").exec(
168
+ params.block
169
+ );
170
+ const line = match?.[1]?.trim();
171
+ if (line === void 0) return void 0;
172
+ const value = /^[>|][+-]?$/.test(line) ? (match?.[2] ?? "").split("\n").map((continuation) => continuation.trim()).filter(Boolean).join(" ") : line;
173
+ if (value === "") return void 0;
174
+ return value.replace(/^(['"])(.*)\1$/, "$2");
175
+ }
176
+ function withUnixLineEndings(text) {
177
+ return text.replace(/\r\n/g, "\n");
178
+ }
179
+
146
180
  // src/lib/skills/sync-skills.constants.ts
147
181
  var MANIFEST_FILE = ".dialecte-skills.json";
148
182
  var AGENT_SKILL_FOLDERS = {
@@ -195,15 +229,32 @@ function skillsOf(params) {
195
229
  const skillsFolder = join(params.folder, SKILLS_FOLDER);
196
230
  if (!existsSync(skillsFolder)) return [];
197
231
  const version = packageVersion(params.folder);
198
- return readdirSync(skillsFolder, { withFileTypes: true }).filter(
199
- (entry) => entry.isDirectory() && existsSync(join(skillsFolder, entry.name, "SKILL.md"))
200
- ).map((entry) => ({
232
+ return readdirSync(skillsFolder, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isFile(join(skillsFolder, entry.name, "SKILL.md"))).map((entry) => ({
201
233
  name: entry.name,
202
234
  path: join(skillsFolder, entry.name),
203
235
  origin: params.origin,
204
- ...version === void 0 ? {} : { version }
236
+ ...version === void 0 ? {} : { version },
237
+ audience: audienceOf(join(skillsFolder, entry.name, "SKILL.md"))
205
238
  }));
206
239
  }
240
+ function isFile(path) {
241
+ return existsSync(path) && statSync(path).isFile();
242
+ }
243
+ function audienceOf(skillFile) {
244
+ try {
245
+ const { audience } = readFrontmatter(readFileSync(skillFile, "utf8"));
246
+ return audience === CONTRIBUTOR_AUDIENCE ? "contributor" : "consumer";
247
+ } catch {
248
+ return "consumer";
249
+ }
250
+ }
251
+ function selectAudience(params) {
252
+ if (params.contributing) return { selected: [...params.sources], leftOut: [] };
253
+ return {
254
+ selected: params.sources.filter((source) => source.audience === "consumer"),
255
+ leftOut: params.sources.filter((source) => source.audience === "contributor")
256
+ };
257
+ }
207
258
  function packageVersion(folder) {
208
259
  const path = join(folder, "package.json");
209
260
  if (!existsSync(path)) return void 0;
@@ -227,6 +278,7 @@ function readSyncManifest(targetFolder) {
227
278
  installed,
228
279
  versions,
229
280
  ...typeof manifest.vendor === "string" ? { vendor: manifest.vendor } : {},
281
+ ...manifest.contributing === true ? { contributing: true } : {},
230
282
  ...stationAgents ? { stationAgents } : {},
231
283
  ...manifest.sessionCheck === true ? { sessionCheck: true } : {},
232
284
  ...manifest.settingsCreated === true ? { settingsCreated: true } : {},
@@ -335,7 +387,7 @@ function toJson(value) {
335
387
  }
336
388
 
337
389
  // src/lib/config.ts
338
- import { readFileSync as readFileSync3, existsSync as existsSync3, readdirSync as readdirSync3, statSync } from "fs";
390
+ import { readFileSync as readFileSync3, existsSync as existsSync3, readdirSync as readdirSync3, statSync as statSync2 } from "fs";
339
391
  import { join as join3 } from "path";
340
392
  var getArg = (argv, name) => {
341
393
  const i = argv.indexOf(`--${name}`);
@@ -366,7 +418,7 @@ function discoverNamespace(cwd) {
366
418
  function discoverVersions(cwd) {
367
419
  const src = join3(cwd, "src");
368
420
  if (!existsSync3(src)) return [];
369
- return readdirSync3(src).filter((v) => statSync(join3(src, v)).isDirectory()).filter(
421
+ return readdirSync3(src).filter((v) => statSync2(join3(src, v)).isDirectory()).filter(
370
422
  (v) => existsSync3(join3(src, v, "definition", "constants.generated.ts")) && existsSync3(join3(src, v, "definition", "definition.generated.ts"))
371
423
  ).sort();
372
424
  }
@@ -525,7 +577,7 @@ import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
525
577
  import { join as join6 } from "path";
526
578
 
527
579
  // src/lib/models/remembered-vendor.ts
528
- import { existsSync as existsSync5, statSync as statSync2 } from "fs";
580
+ import { existsSync as existsSync5, statSync as statSync3 } from "fs";
529
581
  import { join as join5 } from "path";
530
582
 
531
583
  // src/lib/models/model-tiers.constants.ts
@@ -592,7 +644,7 @@ function readRememberedVendor(cwd) {
592
644
  entries.push({
593
645
  folder,
594
646
  vendor,
595
- writtenAt: statSync2(join5(cwd, folder, MANIFEST_FILE)).mtimeMs
647
+ writtenAt: statSync3(join5(cwd, folder, MANIFEST_FILE)).mtimeMs
596
648
  });
597
649
  }
598
650
  entries.sort((first, second) => second.writtenAt - first.writtenAt);
@@ -610,133 +662,112 @@ var CLAUDE_MODEL_ALIASES = ["haiku", "sonnet", "opus", "fable"];
610
662
  var READ_TOOLS = ["Read", "Glob", "Grep", "Skill"];
611
663
  var REVIEW_TOOLS = ["Read", "Glob", "Grep", "Bash", "Skill"];
612
664
  var EDIT_TOOLS = ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "Skill"];
613
- var LOAD_SKILLS_LINE = "Load first, with the Skill tool: `dialecte-lot` (your station and its report shape), `dialecte-contributing` (the gates and the code rules), `dialecte` (the API). They are the source of truth; this file only sets your envelope.";
665
+ var CLAUDE_TOOLS_BY_ACCESS = {
666
+ read: READ_TOOLS,
667
+ review: REVIEW_TOOLS,
668
+ edit: EDIT_TOOLS
669
+ };
670
+ var LOAD_SKILLS_LINE = "Read that section first: it says which skills you load (`dialecte-lot`, `dialecte-contributing`, `dialecte`). The skills are the source of truth; this file only sets your envelope.";
614
671
  var NEVER_LINE = "Never: commit, stage (`git add`), push, merge, `git stash`, `git reset`, `git restore`, `git checkout --`, `rm`; nothing outside the worktree your brief names. Your brief is your whole context.";
615
672
  var GENERATED_NOTE = "Generated by `npx @dialecte/cli skills sync` from `dialecte models`; the next sync overwrites it.";
616
673
  var STATIONS = [
617
674
  {
618
675
  name: "test-writer",
619
676
  tier: "standard",
620
- tools: EDIT_TOOLS,
621
- description: "Dialecte lot, test station of one brief step: writes the tests (and stubs) from the brief and the existing code, then proves them red with `dialecte tdd red`. Give it the brief step.",
622
- role: [
623
- "You are the test station of a Dialecte lot (`dialecte-lot`): you write the tests of one brief step from the spec, never the production code.",
624
- "You may add stubs whose body throws `not implemented: <name>` so the tests compile; call them inside `expect(...)`.",
625
- "Run `dialecte tdd red` until every case is red on an assertion, and answer with its output."
626
- ]
677
+ access: "edit",
678
+ description: "Dialecte lot, test station of one brief step: writes the tests (and stubs) from the brief and the existing code, then proves them red with `dialecte tdd red`. Give it the brief step."
627
679
  },
628
680
  {
629
681
  name: "test-reviewer",
630
682
  tier: "strong",
631
- tools: REVIEW_TOOLS,
632
- description: "Dialecte lot, test review before any code: reads only the tests against the brief (does each pin a behaviour, would a plausible wrong implementation fail it). Read-only.",
633
- role: [
634
- "You are the test review of a Dialecte lot (`dialecte-lot`): you read the tests of the step against the brief, before any production code.",
635
- "You modify nothing (`dialecte tdd status` is the one command to run). Answer per test: the behaviour it pins, a plausible wrong implementation it lets through, a verdict."
636
- ]
683
+ access: "review",
684
+ description: "Dialecte lot, test review before any code: reads only the tests against the brief (does each pin a behaviour, would a plausible wrong implementation fail it). Read-only."
637
685
  },
638
686
  {
639
687
  name: "implementer",
640
688
  tier: "standard",
641
- tools: EDIT_TOOLS,
642
- description: "Dialecte lot, Station 1 (implement) on a mechanical or fully specified lot: production code only until `dialecte tdd green`, then the fast gate. Give it the brief.",
643
- role: [
644
- "You are the implementer of a Dialecte lot: Station 1 of `dialecte-lot`, step mode.",
645
- "The tests are written and red: change production code only until `dialecte tdd green` passes; a test you find wrong goes back to the test station with the reason. Run the fast gate, and answer with the implement report shape of the skill."
646
- ]
689
+ access: "edit",
690
+ description: "Dialecte lot, Station 1 (implement) on a mechanical or fully specified lot: production code only until `dialecte tdd green`, then the fast gate. Give it the brief."
647
691
  },
648
692
  {
649
693
  name: "implementer-strong",
650
694
  tier: "strong",
651
- tools: EDIT_TOOLS,
652
- description: "Dialecte lot, Station 1 (implement) on a design-heavy lot: production code only until `dialecte tdd green`, then the fast gate. Give it the brief.",
653
- role: [
654
- "You are the implementer of a design-heavy Dialecte lot: Station 1 of `dialecte-lot`, step mode.",
655
- "The tests are written and red: change production code only until `dialecte tdd green` passes; a test you find wrong goes back to the test station with the reason. Run the fast gate, and answer with the implement report shape of the skill."
656
- ]
695
+ access: "edit",
696
+ description: "Dialecte lot, Station 1 (implement) on a design-heavy lot: production code only until `dialecte tdd green`, then the fast gate. Give it the brief."
657
697
  },
658
698
  {
659
699
  name: "reviewer",
660
700
  tier: "strong",
661
- tools: REVIEW_TOOLS,
662
- description: "Dialecte lot, Station 3 (independent review): pass 1 correctness, pass 2 fit, read-only. Give it the brief and the diff, not the implementer conclusions.",
663
- role: [
664
- "You are the reviewer of a Dialecte lot: Station 3 of `dialecte-lot`, a different agent from the implementer.",
665
- "You modify nothing: you read the diff and run the tests. Answer with the review report shape of the skill (both passes, a verdict)."
666
- ]
701
+ access: "review",
702
+ description: "Dialecte lot, Station 3 (independent review): pass 1 correctness, pass 2 fit, read-only. Give it the brief and the diff, not the implementer conclusions."
667
703
  },
668
704
  {
669
705
  name: "fixer",
670
706
  tier: "standard",
671
- tools: EDIT_TOOLS,
672
- description: "Dialecte lot, Station 4 (fix mode) on wording and naming findings: fixed, disagreed or escalated per finding. Give it the findings.",
673
- role: [
674
- "You are the implementer in fix mode: Station 4 of `dialecte-lot`.",
675
- "For each finding answer fixed, disagreed (one line why) or needs the user; never drop one."
676
- ]
707
+ access: "edit",
708
+ description: "Dialecte lot, Station 4 (fix mode) on wording and naming findings: fixed, disagreed or escalated per finding. Give it the findings."
677
709
  },
678
710
  {
679
711
  name: "eval-runner",
680
712
  tier: "standard",
681
- tools: EDIT_TOOLS,
682
- description: "Runs one skill-eval case of a Dialecte skill, with or without the skill, and leaves the outputs the graders read.",
683
- role: [
684
- "You run one skill-eval case of `dialecte-lot` (a skill text change goes through skill-creator evals).",
685
- "Follow the case prompt exactly, with or without the skill as your brief says, and write only the outputs it names."
686
- ]
713
+ access: "edit",
714
+ description: "Runs one skill-eval case of a Dialecte skill, with or without the skill, and leaves the outputs the graders read."
687
715
  },
688
716
  {
689
717
  name: "grader",
690
- tier: "fast",
691
- tools: READ_TOOLS,
692
- description: "Grades the output of a skill-eval run against one grader file, pass or fail with the evidence. Read-only.",
693
- role: [
694
- "You grade the output of a skill-eval run against the grader files your brief names.",
695
- "You read, never run or change anything: answer pass or fail per grader, with the line that shows it."
696
- ]
718
+ tier: "strong",
719
+ access: "read",
720
+ description: "Grades the output of a skill-eval run against one grader file, pass or fail with the evidence. Read-only."
697
721
  },
698
722
  {
699
723
  name: "standard-reader",
700
724
  tier: "standard",
701
- tools: READ_TOOLS,
702
- description: "Independent reader of the IEC standard markdown for one question, with line references. Read-only.",
703
- role: [
704
- 'You read the standard for one question: "Reading the standard" of `dialecte-contributing`.',
705
- "You read the standard markdown only, answer with line references, and never rely on what another agent concluded."
706
- ]
725
+ access: "read",
726
+ description: "Independent reader of the IEC standard markdown for one question, with line references. Read-only."
707
727
  },
708
728
  {
709
729
  name: "searcher",
710
730
  tier: "fast",
711
- tools: READ_TOOLS,
712
- description: "Finds where something lives in a Dialecte repository (files, symbols, API paths) and answers with paths and line numbers. Read-only.",
713
- role: [
714
- "You locate code, files or documentation for the question your brief asks, in the Dialecte repositories it names.",
715
- "You read, never change anything: answer with absolute paths and line numbers, nothing speculative."
716
- ]
731
+ access: "read",
732
+ description: "Finds where something lives in a Dialecte repository (files, symbols, API paths) and answers with paths and line numbers. Read-only."
717
733
  }
718
734
  ];
735
+ var LOT_SKILL = "dialecte-lot";
736
+ var STATIONS_PAGE_PATH = `${AGENT_SKILL_FOLDERS.claude}/${LOT_SKILL}/references/stations.md`;
737
+ var BRIEF_DEFINED_STATIONS = ["eval-runner", "grader"];
719
738
 
720
739
  // src/lib/stations/render-station-agent.ts
721
740
  function claudeModelAlias(modelName) {
722
741
  const alias = modelName.split(" ")[0].toLowerCase();
723
742
  return CLAUDE_MODEL_ALIASES.includes(alias) ? alias : void 0;
724
743
  }
744
+ function stationLines(params) {
745
+ const { station } = params;
746
+ const play = `You play the \`${station.name}\` station of \`${LOT_SKILL}\`:`;
747
+ if (BRIEF_DEFINED_STATIONS.includes(station.name))
748
+ return [
749
+ `${play} your brief carries your definition and names the only skill text you read; read no other.`,
750
+ ""
751
+ ];
752
+ return [
753
+ `${play} its definition is ${STATIONS_PAGE_PATH}, section \`${station.name}\`.`,
754
+ "",
755
+ LOAD_SKILLS_LINE,
756
+ ""
757
+ ];
758
+ }
725
759
  function renderStationAgent(params) {
726
760
  const { station, model } = params;
727
761
  return [
728
762
  "---",
729
763
  `name: ${STATION_AGENT_PREFIX}${station.name}`,
730
764
  `description: ${JSON.stringify(station.description)}`,
731
- `tools: ${station.tools.join(", ")}`,
765
+ `tools: ${CLAUDE_TOOLS_BY_ACCESS[station.access].join(", ")}`,
732
766
  `model: ${model}`,
733
767
  "---",
734
768
  `<!-- ${GENERATED_NOTE} -->`,
735
769
  "",
736
- ...station.role,
737
- "",
738
- LOAD_SKILLS_LINE,
739
- "",
770
+ ...stationLines({ station }),
740
771
  NEVER_LINE,
741
772
  ""
742
773
  ].join("\n");
@@ -878,7 +909,11 @@ function skills(cwd) {
878
909
  ];
879
910
  return synced.map(function syncLine(folder) {
880
911
  const manifest = readSyncManifest(join7(cwd, folder));
881
- const missing = sources.map((source) => source.name).filter((name) => !manifest.installed.includes(name));
912
+ const expected = selectAudience({
913
+ sources,
914
+ contributing: manifest.contributing === true
915
+ }).selected;
916
+ const missing = expected.map((source) => source.name).filter((name) => !manifest.installed.includes(name));
882
917
  if (missing.length)
883
918
  return {
884
919
  status: "warning",
@@ -886,7 +921,7 @@ function skills(cwd) {
886
921
  detail: `${folder} lacks ${missing.join(", ")}`,
887
922
  fix: SYNC_COMMAND
888
923
  };
889
- const stale = sources.flatMap(function staleCopy(source) {
924
+ const stale = expected.flatMap(function staleCopy(source) {
890
925
  const recorded = manifest.versions[source.name];
891
926
  if (isLink(join7(cwd, folder, source.name)) || source.version === void 0) return [];
892
927
  if (recorded?.version === source.version) return [];
@@ -1092,9 +1127,162 @@ function memberLine(member) {
1092
1127
  return member.summary ? ` ${member.name}() ${shortSummary(member.summary)}` : ` ${member.name}()`;
1093
1128
  }
1094
1129
 
1130
+ // src/lib/namespace-of.ts
1131
+ function namespaceOf(packageName2) {
1132
+ const name = packageName2.split("/").pop() || "dialecte";
1133
+ return name.charAt(0).toUpperCase() + name.slice(1);
1134
+ }
1135
+
1136
+ // src/lib/schema/load-dialectes.ts
1137
+ import { existsSync as existsSync9, readFileSync as readFileSync7 } from "fs";
1138
+ import { createRequire } from "module";
1139
+ import { join as join9 } from "path";
1140
+ import { pathToFileURL } from "url";
1141
+
1142
+ // src/lib/schema/schema.constants.ts
1143
+ var CORE_PACKAGE3 = "@dialecte/core";
1144
+ var CORE_READERS_ENTRY = "@dialecte/core/utils";
1145
+ var CORE_READER_NAMES = [
1146
+ "resolveDefinition",
1147
+ "getAttributeRules",
1148
+ "enumeratedValues",
1149
+ "valuePatterns",
1150
+ "admittedXsiTypes",
1151
+ "childOccurrences",
1152
+ "orderByConfigSequence"
1153
+ ];
1154
+ var SUGGESTION_LIMIT = 5;
1155
+
1156
+ // src/lib/schema/load-dialectes.ts
1157
+ async function loadDialectes(params) {
1158
+ const folders = [
1159
+ params.cwd,
1160
+ ...dependencyNames(params.cwd).flatMap(
1161
+ (name) => findInstalledPackage({ cwd: params.cwd, name }) ?? []
1162
+ )
1163
+ ];
1164
+ const result = { dialectes: [], skipped: [] };
1165
+ for (const folder of folders) {
1166
+ const manifest = readManifest(folder);
1167
+ if (!manifest?.name || !isBuiltOnCore(manifest)) continue;
1168
+ try {
1169
+ const loaded = await loadDialecte({ folder, manifest, packageName: manifest.name });
1170
+ if (loaded) result.dialectes.push(loaded);
1171
+ } catch (error) {
1172
+ result.skipped.push({
1173
+ packageName: manifest.name,
1174
+ reason: error instanceof Error ? error.message : String(error)
1175
+ });
1176
+ }
1177
+ }
1178
+ result.dialectes.sort((left, right) => TEXT_COLLATOR.compare(left.packageName, right.packageName));
1179
+ return result;
1180
+ }
1181
+ async function loadDialecte(params) {
1182
+ let config;
1183
+ for (const file of entryFiles(params)) {
1184
+ const exported = await import(pathToFileURL(file).href);
1185
+ config = Object.values(exported).find(isDialecteConfig);
1186
+ if (config) break;
1187
+ }
1188
+ if (!config) return void 0;
1189
+ const readersFile = createRequire(join9(params.folder, "package.json")).resolve(CORE_READERS_ENTRY);
1190
+ const readers = await import(pathToFileURL(readersFile).href);
1191
+ if (!isCoreReaders(readers))
1192
+ throw new Error(
1193
+ `its core (${readersFile}) lacks ${CORE_READER_NAMES.filter((name) => typeof readers[name] !== "function").join(", ")}: update @dialecte/core`
1194
+ );
1195
+ return { packageName: params.packageName, config, readers };
1196
+ }
1197
+ function readManifest(folder) {
1198
+ const path = join9(folder, "package.json");
1199
+ return existsSync9(path) ? JSON.parse(readFileSync7(path, "utf8")) : void 0;
1200
+ }
1201
+ function isBuiltOnCore(manifest) {
1202
+ return manifest.name !== CORE_PACKAGE3 && (manifest.dependencies?.[CORE_PACKAGE3] !== void 0 || manifest.peerDependencies?.[CORE_PACKAGE3] !== void 0);
1203
+ }
1204
+ function entryFiles(params) {
1205
+ const { exports, main } = params.manifest;
1206
+ const targets = exports === void 0 ? main ? [[".", main]] : [] : typeof exports === "string" ? [[".", exports]] : Object.entries(exports);
1207
+ return targets.filter(([subpath]) => !subpath.split("/").includes("test") && !subpath.includes("*")).flatMap(([, target]) => {
1208
+ const file = fileOf(target);
1209
+ return file && file.endsWith("js") ? [join9(params.folder, file)] : [];
1210
+ }).map(function existingFile(file) {
1211
+ if (!existsSync9(file))
1212
+ throw new Error(`entry file not found: ${file} (is the package built?)`);
1213
+ return file;
1214
+ });
1215
+ }
1216
+ function fileOf(target) {
1217
+ if (typeof target === "string") return target;
1218
+ const file = target.import ?? target.node ?? target.default;
1219
+ return typeof file === "string" ? file : void 0;
1220
+ }
1221
+ function isDialecteConfig(value) {
1222
+ return typeof value === "object" && value !== null && "rootElementName" in value && typeof value.rootElementName === "string" && "definition" in value && typeof value.definition === "object";
1223
+ }
1224
+ function isCoreReaders(module) {
1225
+ return CORE_READER_NAMES.every((name) => typeof module[name] === "function");
1226
+ }
1227
+
1228
+ // src/lib/api/installed-bindings.constants.ts
1229
+ var VERSION_SUBPATH_PATTERN = /^\.\/[^/*]+$/;
1230
+ var TEST_ENTRY = "test";
1231
+ 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";
1232
+
1233
+ // src/lib/api/installed-bindings.ts
1234
+ function findInstalledBindings(params) {
1235
+ return dependencyNames(params.cwd).flatMap(function bindingsOf(name) {
1236
+ const folder = findInstalledPackage({ cwd: params.cwd, name });
1237
+ const manifest = folder ? readManifest(folder) : void 0;
1238
+ if (!manifest?.name || !isBuiltOnCore(manifest)) return [];
1239
+ const packageName2 = manifest.name;
1240
+ return versionsOf(manifest).map((version) => ({
1241
+ packageName: packageName2,
1242
+ version,
1243
+ binding: {
1244
+ kind: "namespace",
1245
+ name: namespaceOf(packageName2),
1246
+ import: `${packageName2}/${version}`
1247
+ }
1248
+ }));
1249
+ });
1250
+ }
1251
+ function versionsOf(manifest) {
1252
+ const subpaths = typeof manifest.exports === "object" ? Object.keys(manifest.exports) : [];
1253
+ return subpaths.filter((subpath) => VERSION_SUBPATH_PATTERN.test(subpath)).filter((subpath) => subpaths.includes(`${subpath}/${TEST_ENTRY}`)).map((subpath) => subpath.slice(2));
1254
+ }
1255
+ function chooseInstalledBinding(params) {
1256
+ if (params.bindings.length === 0) return { kind: "output", message: NO_DIALECTE_INSTALLED };
1257
+ const matching = params.bindings.filter(
1258
+ (binding) => (params.packageName === void 0 || binding.packageName === params.packageName) && (params.version === void 0 || binding.version === params.version)
1259
+ );
1260
+ if (matching.length === 1) return { kind: "binding", binding: matching[0] };
1261
+ if (matching.length === 0) {
1262
+ const named = [
1263
+ ...params.packageName === void 0 ? [] : [`--package ${params.packageName}`],
1264
+ ...params.version === void 0 ? [] : [`--version ${params.version}`]
1265
+ ].join(" ");
1266
+ return {
1267
+ kind: "output",
1268
+ message: `no installed dialecte matches ${named}; installed:
1269
+ ${listLines(params.bindings)}`
1270
+ };
1271
+ }
1272
+ return {
1273
+ kind: "output",
1274
+ message: `several dialectes are installed: pass --package <name> [--version <v>]
1275
+ ${listLines(matching)}`
1276
+ };
1277
+ }
1278
+ function listLines(bindings) {
1279
+ return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}
1280
+ `).join("");
1281
+ }
1282
+
1095
1283
  // src/lib/discover.ts
1096
1284
  import { mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
1097
- import { dirname as dirname4, join as join9, relative as relative2 } from "path";
1285
+ import { dirname as dirname4, join as join10, relative as relative2 } from "path";
1098
1286
 
1099
1287
  // src/lib/discover.constants.ts
1100
1288
  import ts from "typescript";
@@ -1131,12 +1319,12 @@ function renderLink(link) {
1131
1319
  import ts2 from "typescript";
1132
1320
  function discoverMethods(params) {
1133
1321
  const { entrySource, tsconfig, root, maxDepth = 1 } = params;
1134
- const entryPath = join9(root, ENTRY_FOLDER, `discover-entry-${process.pid}.ts`);
1322
+ const entryPath = join10(root, ENTRY_FOLDER, `discover-entry-${process.pid}.ts`);
1135
1323
  mkdirSync2(dirname4(entryPath), { recursive: true });
1136
1324
  writeFileSync2(entryPath, entrySource);
1137
1325
  try {
1138
1326
  const parsed = ts2.parseJsonConfigFileContent(
1139
- ts2.readConfigFile(join9(root, tsconfig), ts2.sys.readFile).config,
1327
+ ts2.readConfigFile(join10(root, tsconfig), ts2.sys.readFile).config,
1140
1328
  ts2.sys,
1141
1329
  root
1142
1330
  );
@@ -1420,12 +1608,13 @@ function discoveryEntry(binding) {
1420
1608
  var MEMBERS_VALUE_OPTIONS = [
1421
1609
  "namespace",
1422
1610
  "entry",
1611
+ "package",
1423
1612
  "version",
1424
1613
  "tsconfig",
1425
1614
  "constants-dir",
1426
1615
  "out"
1427
1616
  ];
1428
- var MEMBERS_USAGE = "usage: dialecte members <expression> [--json] [--version <v>] (in an app: --namespace <Name> --entry <module exporting it>)";
1617
+ var MEMBERS_USAGE = "usage: dialecte members <expression> [--json] [--package <name>] [--version <v>] (in an app the installed dialecte is found; --namespace <Name> --entry <module exporting it> override)";
1429
1618
 
1430
1619
  // src/commands/skills.constants.ts
1431
1620
  var METHOD_DISCOVERY_DEPTH = 3;
@@ -1436,12 +1625,16 @@ function readMemberEntries(params) {
1436
1625
  if (missing) return { kind: "output", output: missing };
1437
1626
  const { argv, cwd } = params;
1438
1627
  const [expression] = positionalArguments({ argv, valueOptions: MEMBERS_VALUE_OPTIONS });
1439
- const [target] = resolveTargets(argv, cwd);
1440
- if (!expression || !target)
1441
- return { kind: "output", output: { output: `${MEMBERS_USAGE}
1442
- `, exitCode: 2 } };
1628
+ const usage = {
1629
+ kind: "output",
1630
+ output: { output: `${MEMBERS_USAGE}
1631
+ `, exitCode: 2 }
1632
+ };
1633
+ if (!expression) return usage;
1634
+ const binding = readBinding({ argv, cwd });
1635
+ if (binding.kind === "output") return binding;
1443
1636
  const entries = discoverMethods({
1444
- entrySource: discoveryEntry(target.binding),
1637
+ entrySource: discoveryEntry(binding.binding),
1445
1638
  tsconfig: tsconfigOf(argv, cwd),
1446
1639
  root: cwd,
1447
1640
  // one level below the expression, so each group it holds is counted
@@ -1449,6 +1642,17 @@ function readMemberEntries(params) {
1449
1642
  });
1450
1643
  return { kind: "entries", entries, expression };
1451
1644
  }
1645
+ function readBinding(params) {
1646
+ const [target] = resolveTargets(params.argv, params.cwd);
1647
+ if (target) return { kind: "binding", binding: target.binding };
1648
+ const choice = chooseInstalledBinding({
1649
+ bindings: findInstalledBindings({ cwd: params.cwd }),
1650
+ packageName: getArg(params.argv, "package"),
1651
+ version: getArg(params.argv, "version")
1652
+ });
1653
+ if (choice.kind === "binding") return { kind: "binding", binding: choice.binding.binding };
1654
+ return { kind: "output", output: { output: choice.message, exitCode: 2 } };
1655
+ }
1452
1656
 
1453
1657
  // src/lib/models/answer-models.ts
1454
1658
  function answerModels(params) {
@@ -1555,20 +1759,6 @@ function typeName(datatype) {
1555
1759
  return "list" in datatype ? "list" : "union";
1556
1760
  }
1557
1761
 
1558
- // src/lib/schema/schema.constants.ts
1559
- var CORE_PACKAGE3 = "@dialecte/core";
1560
- var CORE_READERS_ENTRY = "@dialecte/core/utils";
1561
- var CORE_READER_NAMES = [
1562
- "resolveDefinition",
1563
- "getAttributeRules",
1564
- "enumeratedValues",
1565
- "valuePatterns",
1566
- "admittedXsiTypes",
1567
- "childOccurrences",
1568
- "orderByConfigSequence"
1569
- ];
1570
- var SUGGESTION_LIMIT = 5;
1571
-
1572
1762
  // src/lib/schema/answer-schema.ts
1573
1763
  function answerSchema(params) {
1574
1764
  const { loaded, tagName } = params;
@@ -1629,82 +1819,6 @@ function renderAttribute(attribute) {
1629
1819
  return parts.join(" ");
1630
1820
  }
1631
1821
 
1632
- // src/lib/schema/load-dialectes.ts
1633
- import { existsSync as existsSync9, readFileSync as readFileSync7 } from "fs";
1634
- import { createRequire } from "module";
1635
- import { join as join10 } from "path";
1636
- import { pathToFileURL } from "url";
1637
- async function loadDialectes(params) {
1638
- const folders = [
1639
- params.cwd,
1640
- ...dependencyNames(params.cwd).flatMap(
1641
- (name) => findInstalledPackage({ cwd: params.cwd, name }) ?? []
1642
- )
1643
- ];
1644
- const result = { dialectes: [], skipped: [] };
1645
- for (const folder of folders) {
1646
- const manifest = readManifest(folder);
1647
- if (!manifest?.name || !isBuiltOnCore(manifest)) continue;
1648
- try {
1649
- const loaded = await loadDialecte({ folder, manifest, packageName: manifest.name });
1650
- if (loaded) result.dialectes.push(loaded);
1651
- } catch (error) {
1652
- result.skipped.push({
1653
- packageName: manifest.name,
1654
- reason: error instanceof Error ? error.message : String(error)
1655
- });
1656
- }
1657
- }
1658
- result.dialectes.sort((left, right) => TEXT_COLLATOR.compare(left.packageName, right.packageName));
1659
- return result;
1660
- }
1661
- async function loadDialecte(params) {
1662
- let config;
1663
- for (const file of entryFiles(params)) {
1664
- const exported = await import(pathToFileURL(file).href);
1665
- config = Object.values(exported).find(isDialecteConfig);
1666
- if (config) break;
1667
- }
1668
- if (!config) return void 0;
1669
- const readersFile = createRequire(join10(params.folder, "package.json")).resolve(CORE_READERS_ENTRY);
1670
- const readers = await import(pathToFileURL(readersFile).href);
1671
- if (!isCoreReaders(readers))
1672
- throw new Error(
1673
- `its core (${readersFile}) lacks ${CORE_READER_NAMES.filter((name) => typeof readers[name] !== "function").join(", ")}: update @dialecte/core`
1674
- );
1675
- return { packageName: params.packageName, config, readers };
1676
- }
1677
- function readManifest(folder) {
1678
- const path = join10(folder, "package.json");
1679
- return existsSync9(path) ? JSON.parse(readFileSync7(path, "utf8")) : void 0;
1680
- }
1681
- function isBuiltOnCore(manifest) {
1682
- return manifest.name !== CORE_PACKAGE3 && (manifest.dependencies?.[CORE_PACKAGE3] !== void 0 || manifest.peerDependencies?.[CORE_PACKAGE3] !== void 0);
1683
- }
1684
- function entryFiles(params) {
1685
- const { exports, main } = params.manifest;
1686
- const targets = exports === void 0 ? main ? [[".", main]] : [] : typeof exports === "string" ? [[".", exports]] : Object.entries(exports);
1687
- return targets.filter(([subpath]) => !subpath.split("/").includes("test") && !subpath.includes("*")).flatMap(([, target]) => {
1688
- const file = fileOf(target);
1689
- return file && file.endsWith("js") ? [join10(params.folder, file)] : [];
1690
- }).map(function existingFile(file) {
1691
- if (!existsSync9(file))
1692
- throw new Error(`entry file not found: ${file} (is the package built?)`);
1693
- return file;
1694
- });
1695
- }
1696
- function fileOf(target) {
1697
- if (typeof target === "string") return target;
1698
- const file = target.import ?? target.node ?? target.default;
1699
- return typeof file === "string" ? file : void 0;
1700
- }
1701
- function isDialecteConfig(value) {
1702
- return typeof value === "object" && value !== null && "rootElementName" in value && typeof value.rootElementName === "string" && "definition" in value && typeof value.definition === "object";
1703
- }
1704
- function isCoreReaders(module) {
1705
- return CORE_READER_NAMES.every((name) => typeof module[name] === "function");
1706
- }
1707
-
1708
1822
  // src/commands/schema.constants.ts
1709
1823
  var SCHEMA_VALUE_OPTIONS = ["package"];
1710
1824
  var SCHEMA_USAGE = "usage: dialecte schema <Tag> [--package <name>] [--json]";