@dialecte/cli 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +221 -27
- package/dist/cli.js +25294 -21660
- package/dist/lookups.d.ts +13 -7
- package/dist/lookups.js +1929 -1176
- package/package.json +1 -1
package/dist/lookups.js
CHANGED
|
@@ -63,6 +63,22 @@ var STOP_WORDS = /* @__PURE__ */ new Set([
|
|
|
63
63
|
]);
|
|
64
64
|
var CORE_PACKAGE_NAME = "@dialecte/core";
|
|
65
65
|
|
|
66
|
+
// src/lib/api/source-functions.constants.ts
|
|
67
|
+
var SOURCE_INDEX_FILE = "dialecte-source-index.json";
|
|
68
|
+
var SOURCE_INDEX_SCHEMA = 1;
|
|
69
|
+
var SOURCE_FOLDER = "src";
|
|
70
|
+
var SOURCE_FILE_PATTERN = /(?<!\.d)\.ts$/;
|
|
71
|
+
var SOURCE_PATH_MARK = "#";
|
|
72
|
+
var INTENT_TAG = "intent";
|
|
73
|
+
var NO_SOURCE_FOLDER_NOTE = "no src/ folder in {root}";
|
|
74
|
+
var NOT_PARSED_NOTE = "{file}: not parsed ({why})";
|
|
75
|
+
var NO_SUMMARY_TEXT = "(no summary)";
|
|
76
|
+
var NOTE_LINE_PREFIX = "note: ";
|
|
77
|
+
var SOURCE_SUGGESTION_LIMIT = 5;
|
|
78
|
+
var UNKNOWN_SOURCE_CLOSEST_TEXT = 'no source function "{path}" in {root} - closest: {closest}';
|
|
79
|
+
var UNKNOWN_SOURCE_TEXT = 'no source function "{path}" in {root}: `npx @dialecte/cli api find --source "<what you need>"` lists them';
|
|
80
|
+
var NO_PACKAGE_TEXT = "{command}: no package at {cwd}: run it inside a package (a folder holding a package.json, or below one)";
|
|
81
|
+
|
|
66
82
|
// src/lib/api/find-methods.ts
|
|
67
83
|
function findMethods(params) {
|
|
68
84
|
const needWords = new Set(wordsOf(params.need));
|
|
@@ -91,8 +107,9 @@ function isDefined(value) {
|
|
|
91
107
|
function scoreMethod(params) {
|
|
92
108
|
const { method, needWords } = params;
|
|
93
109
|
const intentMatches = method.intents.map((intent) => sharedCount({ text: intent, needWords }));
|
|
110
|
+
const intentText = method.root === "source" && method.intents.length === 0 ? `${method.summary ?? ""} ${routeName(method)}` : method.intents.join(" ");
|
|
94
111
|
const hits = {
|
|
95
|
-
intent: sharedCount({ text:
|
|
112
|
+
intent: sharedCount({ text: intentText, needWords }),
|
|
96
113
|
summary: sharedCount({ text: method.summary ?? "", needWords }),
|
|
97
114
|
name: sharedCount({ text: routeName(method), needWords })
|
|
98
115
|
};
|
|
@@ -108,12 +125,14 @@ function sharedCount(params) {
|
|
|
108
125
|
return new Set(wordsOf(params.text).filter((word) => params.needWords.has(word))).size;
|
|
109
126
|
}
|
|
110
127
|
function routeName(method) {
|
|
128
|
+
if (method.root === "source")
|
|
129
|
+
return method.path.slice(method.path.indexOf(SOURCE_PATH_MARK) + SOURCE_PATH_MARK.length);
|
|
111
130
|
if (method.entry !== void 0 && method.path.startsWith(`${method.entry}.`))
|
|
112
131
|
return method.path.slice(method.entry.length + 1);
|
|
113
132
|
return method.path.replace(/^(doc\.query|tx|doc|project)\./, "");
|
|
114
133
|
}
|
|
115
134
|
function compareFound(left, right) {
|
|
116
|
-
return right.hits.intent - left.hits.intent || right.hits.summary - left.hits.summary || right.hits.name - left.hits.name || Number(left.packageName === CORE_PACKAGE_NAME) - Number(right.packageName === CORE_PACKAGE_NAME) || TEXT_COLLATOR.compare(left.method.path, right.method.path);
|
|
135
|
+
return right.hits.intent - left.hits.intent || right.hits.summary - left.hits.summary || right.hits.name - left.hits.name || Number(left.method.root === "source") - Number(right.method.root === "source") || Number(left.packageName === CORE_PACKAGE_NAME) - Number(right.packageName === CORE_PACKAGE_NAME) || TEXT_COLLATOR.compare(left.method.path, right.method.path);
|
|
117
136
|
}
|
|
118
137
|
|
|
119
138
|
// src/lib/api/read-api-indexes.ts
|
|
@@ -145,6 +164,13 @@ import { dirname as dirname2, join as join2, parse, relative as relative2, resol
|
|
|
145
164
|
// src/lib/file-system.ts
|
|
146
165
|
import { lstatSync, realpathSync, statSync } from "fs";
|
|
147
166
|
import { basename, dirname, isAbsolute, join, relative, sep } from "path";
|
|
167
|
+
function isFolder(path) {
|
|
168
|
+
try {
|
|
169
|
+
return statSync(path).isDirectory();
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
148
174
|
|
|
149
175
|
// src/lib/skills/skill-file.ts
|
|
150
176
|
function readFrontmatter(markdown) {
|
|
@@ -373,9 +399,12 @@ function endedOf(text) {
|
|
|
373
399
|
|
|
374
400
|
// src/lib/api/short-summary.ts
|
|
375
401
|
function shortSummary(summary) {
|
|
376
|
-
const sentence = summary
|
|
402
|
+
const sentence = firstSentence(summary);
|
|
377
403
|
return sentence.length > SHORT_SUMMARY_MAX_LENGTH ? `${sentence.slice(0, SHORT_SUMMARY_MAX_LENGTH - 1)}\u2026` : sentence;
|
|
378
404
|
}
|
|
405
|
+
function firstSentence(text) {
|
|
406
|
+
return text.match(/^.*?[.!?](?=\s|$)/)?.[0] ?? text;
|
|
407
|
+
}
|
|
379
408
|
|
|
380
409
|
// src/lib/api/render-api.ts
|
|
381
410
|
function renderFound(params) {
|
|
@@ -384,23 +413,33 @@ function renderFound(params) {
|
|
|
384
413
|
jsonOf(
|
|
385
414
|
{
|
|
386
415
|
need: params.need,
|
|
387
|
-
methods: params.found.map(
|
|
388
|
-
|
|
389
|
-
root: found.method.root,
|
|
390
|
-
package: found.packageName,
|
|
391
|
-
hits: found.hits,
|
|
392
|
-
intent: found.matchingIntent,
|
|
393
|
-
summary: found.method.summary
|
|
394
|
-
}))
|
|
416
|
+
methods: params.found.map(foundJsonOf),
|
|
417
|
+
...params.notes === void 0 ? {} : { notes: params.notes }
|
|
395
418
|
},
|
|
396
419
|
" "
|
|
397
420
|
)
|
|
398
421
|
);
|
|
399
|
-
return endedTextOf(
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
422
|
+
return endedTextOf([...params.found.map(foundRowOf), ...noteLinesOf(params.notes)]);
|
|
423
|
+
}
|
|
424
|
+
function foundJsonOf(found) {
|
|
425
|
+
const row = {
|
|
426
|
+
path: found.method.path,
|
|
427
|
+
root: found.method.root,
|
|
428
|
+
package: found.packageName,
|
|
429
|
+
hits: found.hits,
|
|
430
|
+
intent: found.matchingIntent,
|
|
431
|
+
summary: found.method.summary
|
|
432
|
+
};
|
|
433
|
+
return found.method.root === "source" ? { ...row, declaredAt: found.method.declaredAt } : row;
|
|
434
|
+
}
|
|
435
|
+
function foundRowOf(found) {
|
|
436
|
+
const { method } = found;
|
|
437
|
+
if (method.root === "source")
|
|
438
|
+
return `${method.path} source ${method.declaredAt} ${found.matchingIntent ?? (method.summary === void 0 ? NO_SUMMARY_TEXT : shortSummary(method.summary))} ${found.packageName}`;
|
|
439
|
+
return `${method.path} ${method.root} ${found.matchingIntent ?? shortSummary(method.summary ?? "-")} ${found.packageName}`;
|
|
440
|
+
}
|
|
441
|
+
function noteLinesOf(notes) {
|
|
442
|
+
return (notes ?? []).map((note) => `${NOTE_LINE_PREFIX}${note}`);
|
|
404
443
|
}
|
|
405
444
|
function renderShown(params) {
|
|
406
445
|
if (params.json)
|
|
@@ -410,17 +449,19 @@ function renderShown(params) {
|
|
|
410
449
|
methods: params.methods.map(({ method, packageName: packageName2 }) => ({
|
|
411
450
|
package: packageName2,
|
|
412
451
|
...method
|
|
413
|
-
}))
|
|
452
|
+
})),
|
|
453
|
+
...params.notes === void 0 ? {} : { notes: params.notes }
|
|
414
454
|
},
|
|
415
455
|
" "
|
|
416
456
|
)
|
|
417
457
|
);
|
|
418
|
-
return endedTextOf(
|
|
419
|
-
params.methods.flatMap((packaged, index) => [
|
|
458
|
+
return endedTextOf([
|
|
459
|
+
...params.methods.flatMap((packaged, index) => [
|
|
420
460
|
...index === 0 ? [] : [""],
|
|
421
461
|
...renderMethod(packaged)
|
|
422
|
-
])
|
|
423
|
-
|
|
462
|
+
]),
|
|
463
|
+
...noteLinesOf(params.notes)
|
|
464
|
+
]);
|
|
424
465
|
}
|
|
425
466
|
function renderMethod({ method, packageName: packageName2 }) {
|
|
426
467
|
const lines = [`${method.path} (${packageName2})`, method.signature];
|
|
@@ -435,1306 +476,2018 @@ function endedTextOf(lines) {
|
|
|
435
476
|
return textOf(lines.length === 0 ? [] : [...lines, ""]);
|
|
436
477
|
}
|
|
437
478
|
|
|
438
|
-
// src/lib/
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
coreAlias: "Core",
|
|
449
|
-
coreImport: "@/index",
|
|
450
|
-
configType: "TestDialecteConfig",
|
|
451
|
-
configImport: "@/test/config"
|
|
452
|
-
},
|
|
453
|
-
constantsDir: "./src/test/generated",
|
|
454
|
-
outDir: "./benchmarks/types/generated"
|
|
455
|
-
};
|
|
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}`);
|
|
479
|
+
// src/lib/closest-names.ts
|
|
480
|
+
function closestNames(params) {
|
|
481
|
+
const name = params.name.toLowerCase();
|
|
482
|
+
const threshold = Math.max(2, Math.floor(name.length / 3));
|
|
483
|
+
return params.candidates.map((candidate) => ({
|
|
484
|
+
candidate,
|
|
485
|
+
distance: candidate.toLowerCase().includes(name) ? 0 : editDistance({ from: name, to: candidate.toLowerCase() })
|
|
486
|
+
})).filter(({ distance }) => distance <= threshold).sort(
|
|
487
|
+
(left, right) => left.distance - right.distance || TEXT_COLLATOR.compare(left.candidate, right.candidate)
|
|
488
|
+
).slice(0, params.limit).map(({ candidate }) => candidate);
|
|
464
489
|
}
|
|
465
|
-
function
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
490
|
+
function editDistance(params) {
|
|
491
|
+
const { from, to } = params;
|
|
492
|
+
let previous = Array.from({ length: to.length + 1 }, (_, index) => index);
|
|
493
|
+
for (let row = 1; row <= from.length; row++) {
|
|
494
|
+
const current = [row];
|
|
495
|
+
for (let column = 1; column <= to.length; column++)
|
|
496
|
+
current[column] = Math.min(
|
|
497
|
+
previous[column] + 1,
|
|
498
|
+
current[column - 1] + 1,
|
|
499
|
+
previous[column - 1] + (from[row - 1] === to[column - 1] ? 0 : 1)
|
|
500
|
+
);
|
|
501
|
+
previous = current;
|
|
471
502
|
}
|
|
472
|
-
return
|
|
473
|
-
}
|
|
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")) : {};
|
|
503
|
+
return previous[to.length];
|
|
480
504
|
}
|
|
481
|
-
|
|
482
|
-
|
|
505
|
+
|
|
506
|
+
// src/lib/mutation/run-store.ts
|
|
507
|
+
import { randomBytes } from "crypto";
|
|
508
|
+
import {
|
|
509
|
+
existsSync as existsSync10,
|
|
510
|
+
mkdirSync as mkdirSync4,
|
|
511
|
+
readdirSync as readdirSync8,
|
|
512
|
+
readFileSync as readFileSync8,
|
|
513
|
+
renameSync as renameSync3,
|
|
514
|
+
writeFileSync as writeFileSync3
|
|
515
|
+
} from "fs";
|
|
516
|
+
import { basename as basename5, join as join13 } from "path";
|
|
517
|
+
|
|
518
|
+
// src/lib/git.ts
|
|
519
|
+
import { spawnSync } from "child_process";
|
|
520
|
+
import { realpathSync as realpathSync2 } from "fs";
|
|
521
|
+
import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute2, join as join4, resolve as resolve2 } from "path";
|
|
522
|
+
|
|
523
|
+
// src/lib/git.constants.ts
|
|
524
|
+
var GIT_READ_ENVIRONMENT = { GIT_OPTIONAL_LOCKS: "0" };
|
|
525
|
+
|
|
526
|
+
// src/lib/git.ts
|
|
527
|
+
function readGit(params) {
|
|
528
|
+
const result = spawnSync("git", ["-c", "core.quotePath=false", ...params.args], {
|
|
529
|
+
cwd: params.root,
|
|
530
|
+
encoding: "utf8",
|
|
531
|
+
input: params.input,
|
|
532
|
+
maxBuffer: 1e8,
|
|
533
|
+
// a status or diff never refreshes the index behind a commit running at the same time
|
|
534
|
+
env: { ...process.env, ...GIT_READ_ENVIRONMENT, ...params.environment }
|
|
535
|
+
});
|
|
536
|
+
if (result.status !== 0)
|
|
537
|
+
throw new Error(`git ${params.args.join(" ")}: ${(result.stderr || result.stdout).trim()}`);
|
|
538
|
+
return result.stdout;
|
|
483
539
|
}
|
|
484
|
-
function
|
|
485
|
-
|
|
540
|
+
function tryReadGit(params) {
|
|
541
|
+
try {
|
|
542
|
+
return readGit(params);
|
|
543
|
+
} catch {
|
|
544
|
+
return void 0;
|
|
545
|
+
}
|
|
486
546
|
}
|
|
487
|
-
function
|
|
488
|
-
return
|
|
489
|
-
|
|
490
|
-
|
|
547
|
+
function listRepositoryFiles(params) {
|
|
548
|
+
return readGit({
|
|
549
|
+
root: params.root,
|
|
550
|
+
args: ["ls-files", "--cached", "--others", "--exclude-standard", "--", params.folder]
|
|
551
|
+
}).split("\n").filter(Boolean).sort();
|
|
491
552
|
}
|
|
492
|
-
function
|
|
493
|
-
const
|
|
494
|
-
|
|
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"))
|
|
497
|
-
).sort();
|
|
553
|
+
function gitFolderOf(root) {
|
|
554
|
+
const folder = readGit({ root, args: ["rev-parse", "--git-dir"] }).trim();
|
|
555
|
+
return isAbsolute2(folder) ? folder : join4(root, folder);
|
|
498
556
|
}
|
|
499
|
-
function
|
|
500
|
-
|
|
501
|
-
return [
|
|
502
|
-
{
|
|
503
|
-
...CORE_TEST_DIALECT,
|
|
504
|
-
version: getArg(argv, "version") ?? CORE_TEST_DIALECT.version,
|
|
505
|
-
constantsDir: getArg(argv, "constants-dir") ?? CORE_TEST_DIALECT.constantsDir,
|
|
506
|
-
outDir: getArg(argv, "out") ?? CORE_TEST_DIALECT.outDir
|
|
507
|
-
}
|
|
508
|
-
];
|
|
509
|
-
const cfg = pkgConfig(cwd);
|
|
510
|
-
const namespace = getArg(argv, "namespace") ?? cfg.namespace ?? discoverNamespace(cwd);
|
|
511
|
-
const only = getArg(argv, "version");
|
|
512
|
-
let versions = discoverVersions(cwd);
|
|
513
|
-
if (only) versions = versions.filter((v) => v === only);
|
|
514
|
-
if (!versions.length && (getArg(argv, "constants-dir") || getArg(argv, "entry")))
|
|
515
|
-
versions = [only ?? "default"];
|
|
516
|
-
return versions.map((version) => {
|
|
517
|
-
const entry = getArg(argv, "entry") ?? cfg.entry ?? `@/${version}`;
|
|
518
|
-
return {
|
|
519
|
-
version,
|
|
520
|
-
binding: { kind: "namespace", name: namespace, import: entry },
|
|
521
|
-
constantsDir: getArg(argv, "constants-dir") ?? cfg.constantsDir ?? `./src/${version}/definition`,
|
|
522
|
-
outDir: getArg(argv, "out") ?? cfg.out ?? `./benchmarks/types/${version}/generated`
|
|
523
|
-
};
|
|
524
|
-
});
|
|
557
|
+
function isInWorkTree(root) {
|
|
558
|
+
return tryReadGit({ root, args: ["rev-parse", "--is-inside-work-tree"] })?.trim() === "true";
|
|
525
559
|
}
|
|
526
560
|
|
|
527
|
-
// src/lib/
|
|
528
|
-
import { existsSync as
|
|
561
|
+
// src/lib/package-json.ts
|
|
562
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
529
563
|
import { join as join5 } from "path";
|
|
530
|
-
function
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
`no package.json in ${params.cwd}: run dialecte in your package's folder`,
|
|
534
|
-
""
|
|
535
|
-
]),
|
|
536
|
-
exitCode: 2
|
|
537
|
-
};
|
|
564
|
+
function readPackageJson(root) {
|
|
565
|
+
const path = join5(root, "package.json");
|
|
566
|
+
return existsSync3(path) ? JSON.parse(readFileSync3(path, "utf8")) : {};
|
|
538
567
|
}
|
|
539
568
|
|
|
540
|
-
// src/
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const missing = missingPackage({ cwd: params.cwd });
|
|
549
|
-
if (missing) return missing;
|
|
550
|
-
const [subcommand, ...rest] = params.argv;
|
|
551
|
-
const words = positionalArguments({ argv: rest, valueOptions: API_VALUE_OPTIONS });
|
|
552
|
-
const limit = Number(getArg([...rest], "limit") ?? DEFAULT_FIND_LIMIT);
|
|
553
|
-
if (!isSubcommand(subcommand) || words.length === 0 || !Number.isInteger(limit) || limit < 1)
|
|
554
|
-
return { output: textOf([API_USAGE, ""]), exitCode: 2 };
|
|
555
|
-
const packageName2 = getArg([...rest], "package");
|
|
556
|
-
const indexes = readApiIndexes({ cwd: params.cwd }).filter(
|
|
557
|
-
(index) => packageName2 === void 0 || index.package === packageName2
|
|
558
|
-
);
|
|
559
|
-
const json = hasFlag([...rest], "json");
|
|
560
|
-
return subcommand === "find" ? find({ indexes, need: words.join(" "), limit, json }) : show({ indexes, path: words[0], json });
|
|
561
|
-
}
|
|
562
|
-
function isSubcommand(value) {
|
|
563
|
-
return API_SUBCOMMANDS.some((subcommand) => subcommand === value);
|
|
564
|
-
}
|
|
565
|
-
function find(params) {
|
|
566
|
-
const found = findMethods(params);
|
|
567
|
-
if (found.length === 0 && !params.json)
|
|
568
|
-
return {
|
|
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
|
-
]),
|
|
573
|
-
exitCode: 1
|
|
574
|
-
};
|
|
575
|
-
return {
|
|
576
|
-
output: renderFound({ need: params.need, found, json: params.json }),
|
|
577
|
-
exitCode: found.length ? 0 : 1
|
|
578
|
-
};
|
|
569
|
+
// src/lib/process-alive.ts
|
|
570
|
+
function isProcessAlive(pid) {
|
|
571
|
+
try {
|
|
572
|
+
process.kill(pid, 0);
|
|
573
|
+
return true;
|
|
574
|
+
} catch (error) {
|
|
575
|
+
return error.code === "EPERM";
|
|
576
|
+
}
|
|
579
577
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
578
|
+
|
|
579
|
+
// src/lib/process-start-time.ts
|
|
580
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
581
|
+
|
|
582
|
+
// src/lib/review-rounds/worktree-state.ts
|
|
583
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
584
|
+
import { existsSync as existsSync9, lstatSync as lstatSync4, readdirSync as readdirSync7, statSync as statSync4 } from "fs";
|
|
585
|
+
import { dirname as dirname7, join as join12 } from "path";
|
|
586
|
+
|
|
587
|
+
// src/lib/store/lot-folder.ts
|
|
588
|
+
import { existsSync as existsSync8, realpathSync as realpathSync3 } from "fs";
|
|
589
|
+
import { basename as basename4, dirname as dirname6, join as join11, resolve as resolve4 } from "path";
|
|
590
|
+
|
|
591
|
+
// src/lib/store/store-folder.ts
|
|
592
|
+
import {
|
|
593
|
+
existsSync as existsSync7,
|
|
594
|
+
mkdirSync as mkdirSync3,
|
|
595
|
+
readdirSync as readdirSync6,
|
|
596
|
+
readFileSync as readFileSync7,
|
|
597
|
+
renameSync as renameSync2,
|
|
598
|
+
rmSync as rmSync3,
|
|
599
|
+
statSync as statSync3
|
|
600
|
+
} from "fs";
|
|
601
|
+
import { dirname as dirname5, join as join10, resolve as resolve3 } from "path";
|
|
602
|
+
|
|
603
|
+
// src/lib/handover/handover-store-read.ts
|
|
604
|
+
import { existsSync as existsSync4, readdirSync as readdirSync3, readFileSync as readFileSync4 } from "fs";
|
|
605
|
+
import { join as join6, sep as sep2 } from "path";
|
|
606
|
+
|
|
607
|
+
// src/lib/store/identity.ts
|
|
608
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
609
|
+
import { join as join7 } from "path";
|
|
610
|
+
|
|
611
|
+
// src/lib/store/store.constants.ts
|
|
612
|
+
var TEMPORARY_INFIX = ".tmp-";
|
|
613
|
+
var TEMPORARY_FILE_SUFFIX_PATTERN = /^\.tmp-(\d+)-\d+$/;
|
|
614
|
+
var WRITABLE_MODE = 420;
|
|
615
|
+
var PERMISSION_BITS = 511;
|
|
616
|
+
var REPLACED_LINK_REFUSAL = "refused to replace a symbolic link";
|
|
617
|
+
|
|
618
|
+
// src/lib/store/publish.ts
|
|
619
|
+
import {
|
|
620
|
+
chmodSync,
|
|
621
|
+
closeSync,
|
|
622
|
+
existsSync as existsSync5,
|
|
623
|
+
fsyncSync,
|
|
624
|
+
linkSync,
|
|
625
|
+
lstatSync as lstatSync3,
|
|
626
|
+
openSync,
|
|
627
|
+
readdirSync as readdirSync4,
|
|
628
|
+
renameSync,
|
|
629
|
+
rmSync as rmSync2,
|
|
630
|
+
writeFileSync as writeFileSync2
|
|
631
|
+
} from "fs";
|
|
632
|
+
import { basename as basename3, dirname as dirname4, join as join8 } from "path";
|
|
633
|
+
var temporaryCounter = 0;
|
|
634
|
+
function replaceWhole(params) {
|
|
635
|
+
const existing = lstatSync3(params.path, { throwIfNoEntry: false });
|
|
636
|
+
if (existing?.isSymbolicLink()) throw new Error(`${REPLACED_LINK_REFUSAL}: ${params.path}`);
|
|
637
|
+
const mode = existing ? existing.mode & PERMISSION_BITS : WRITABLE_MODE;
|
|
638
|
+
const temporary = writeTemporary({ path: params.path, text: params.text, mode });
|
|
639
|
+
params.afterTemporaryWritten?.(temporary);
|
|
640
|
+
try {
|
|
641
|
+
renameSync(temporary, params.path);
|
|
642
|
+
} catch (error) {
|
|
643
|
+
throw vanishedOr({ error, temporary });
|
|
644
|
+
}
|
|
591
645
|
}
|
|
592
|
-
function
|
|
593
|
-
|
|
646
|
+
function removeDeadLeftovers(params) {
|
|
647
|
+
if (!existsSync5(params.folder)) return;
|
|
648
|
+
const folders = params.kind === "folders";
|
|
649
|
+
for (const entry of readdirSync4(params.folder, { withFileTypes: true })) {
|
|
650
|
+
const pid = params.pidOf(entry.name);
|
|
651
|
+
if (pid === void 0 || isProcessAlive(Number(pid))) continue;
|
|
652
|
+
if (entry.isDirectory() !== folders) continue;
|
|
653
|
+
rmSync2(join8(params.folder, entry.name), { recursive: folders, force: true });
|
|
654
|
+
}
|
|
594
655
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const exitCode = params.lines.some((line) => line.status !== "ok") ? 1 : 0;
|
|
599
|
-
if (params.json) return { output: endedOf(jsonOf({ lines: params.lines }, " ")), exitCode };
|
|
600
|
-
return { output: endedTextOf2(params.lines.map(renderLine)), exitCode };
|
|
656
|
+
function temporaryPidOf(params) {
|
|
657
|
+
if (!params.name.startsWith(params.finalName)) return void 0;
|
|
658
|
+
return TEMPORARY_FILE_SUFFIX_PATTERN.exec(params.name.slice(params.finalName.length))?.[1];
|
|
601
659
|
}
|
|
602
|
-
function
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
660
|
+
function writeTemporary(params) {
|
|
661
|
+
const finalName = basename3(params.path);
|
|
662
|
+
removeDeadLeftovers({
|
|
663
|
+
folder: dirname4(params.path),
|
|
664
|
+
pidOf: (name) => temporaryPidOf({ name, finalName }),
|
|
665
|
+
kind: "files"
|
|
666
|
+
});
|
|
667
|
+
temporaryCounter += 1;
|
|
668
|
+
const temporary = `${params.path}${TEMPORARY_INFIX}${process.pid}-${temporaryCounter}`;
|
|
669
|
+
const descriptor = openSync(temporary, "w");
|
|
670
|
+
try {
|
|
671
|
+
writeFileSync2(descriptor, params.text);
|
|
672
|
+
fsyncSync(descriptor);
|
|
673
|
+
} finally {
|
|
674
|
+
closeSync(descriptor);
|
|
675
|
+
}
|
|
676
|
+
chmodSync(temporary, params.mode);
|
|
677
|
+
return temporary;
|
|
607
678
|
}
|
|
608
|
-
function
|
|
609
|
-
|
|
679
|
+
function vanishedOr(params) {
|
|
680
|
+
if (isErrorCode({ error: params.error, code: "ENOENT" }) && !existsSync5(params.temporary))
|
|
681
|
+
return new Error(`the temporary file ${params.temporary} vanished before it was published`);
|
|
682
|
+
rmSync2(params.temporary, { force: true });
|
|
683
|
+
return params.error;
|
|
610
684
|
}
|
|
611
|
-
function
|
|
612
|
-
|
|
613
|
-
const fix = line.fix ? ` - fix: ${line.fix}` : "";
|
|
614
|
-
return line.status === "error" ? `\u274C ${line.subject} ${line.detail}${fix}` : `\u26A0\uFE0F ${line.subject} ${line.detail}${fix}`;
|
|
685
|
+
function isErrorCode(params) {
|
|
686
|
+
return params.error?.code === params.code;
|
|
615
687
|
}
|
|
616
688
|
|
|
617
|
-
// src/lib/
|
|
618
|
-
import { existsSync as
|
|
619
|
-
import {
|
|
689
|
+
// src/lib/store/transitions.ts
|
|
690
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync2, readdirSync as readdirSync5, readFileSync as readFileSync6 } from "fs";
|
|
691
|
+
import { join as join9 } from "path";
|
|
620
692
|
|
|
621
|
-
// src/lib/
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
693
|
+
// src/lib/review-rounds/review-rounds.constants.ts
|
|
694
|
+
var DECISION_STATES = [
|
|
695
|
+
"open",
|
|
696
|
+
"fix-to-verify",
|
|
697
|
+
"fixed <round> [note]",
|
|
698
|
+
"accepted <reason>",
|
|
699
|
+
"logged <where>"
|
|
700
|
+
];
|
|
701
|
+
var CHOICE_OPTIONS = ["by"];
|
|
702
|
+
var DECIDE_USAGE = `lot decide: expected <id|folder> <finding> <state...>; states: ${DECISION_STATES.join(", ")}`;
|
|
703
|
+
var SNAPSHOT_OPTIONS = ["round", "by", "reason"];
|
|
704
|
+
var VERIFY_OPTIONS = ["by", "note"];
|
|
705
|
+
var FINDING_OPTIONS = ["round", "severity", "at"];
|
|
706
|
+
var ROUND_OPTIONS = ["round"];
|
|
707
|
+
var REVIEW_ROUND_VALUE_OPTIONS = [
|
|
708
|
+
.../* @__PURE__ */ new Set([
|
|
709
|
+
...FINDING_OPTIONS,
|
|
710
|
+
...CHOICE_OPTIONS,
|
|
711
|
+
...ROUND_OPTIONS,
|
|
712
|
+
...SNAPSHOT_OPTIONS,
|
|
713
|
+
...VERIFY_OPTIONS
|
|
714
|
+
])
|
|
715
|
+
];
|
|
716
|
+
|
|
717
|
+
// src/lib/review-rounds/worktree-state.ts
|
|
718
|
+
function listTreeFiles(folder) {
|
|
719
|
+
const found = [];
|
|
720
|
+
walkFolder({ folder, relative: "", found });
|
|
721
|
+
return found.sort();
|
|
722
|
+
}
|
|
723
|
+
function walkFolder(params) {
|
|
724
|
+
for (const name of readdirSync7(join12(params.folder, params.relative))) {
|
|
725
|
+
const path = params.relative ? `${params.relative}/${name}` : name;
|
|
726
|
+
if (lstatSync4(join12(params.folder, path)).isDirectory())
|
|
727
|
+
walkFolder({ folder: params.folder, relative: path, found: params.found });
|
|
728
|
+
else params.found.push(path);
|
|
729
|
+
}
|
|
627
730
|
}
|
|
628
731
|
|
|
629
|
-
// src/lib/
|
|
630
|
-
var
|
|
631
|
-
|
|
632
|
-
|
|
732
|
+
// src/lib/mutation/mutation.constants.ts
|
|
733
|
+
var MUTANTS_USAGE_LINES = [
|
|
734
|
+
"usage: dialecte mutants run [--mode changed|audit] [--base <ref>]",
|
|
735
|
+
" dialecte mutants status [--json]",
|
|
736
|
+
" dialecte mutants schedule <follow-up> <survivor key>... | schedule <follow-up> --all-new [--json]",
|
|
737
|
+
" dialecte mutants abandon <run id> [--json]",
|
|
738
|
+
" dialecte mutants migrate [--json]",
|
|
739
|
+
" dialecte mutants judge [--file <file>] [--json]",
|
|
740
|
+
" dialecte mutants record (--key <survivor key>... | --file <file>) --family <family> --reason <text> [--removable] [--json]",
|
|
741
|
+
" dialecte mutants drop <run id> [--json]"
|
|
742
|
+
];
|
|
743
|
+
var MUTANTS_USAGE = MUTANTS_USAGE_LINES.join("\n");
|
|
633
744
|
|
|
634
|
-
// src/lib/
|
|
635
|
-
function
|
|
636
|
-
|
|
637
|
-
if (declared === void 0) return DEFAULT_PROFILE;
|
|
638
|
-
const profile = PROFILES.find((known) => known === declared);
|
|
639
|
-
if (!profile) throw new Error(INVALID_PROFILE.replace("{value}", JSON.stringify(declared)));
|
|
640
|
-
return profile;
|
|
745
|
+
// src/lib/mutation/run-store.ts
|
|
746
|
+
function packageNameOf(root) {
|
|
747
|
+
return readPackageJson(root).name ?? basename5(root);
|
|
641
748
|
}
|
|
642
749
|
|
|
643
|
-
// src/lib/
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
{
|
|
651
|
-
from: [0, 7],
|
|
652
|
-
name: "0.7",
|
|
653
|
-
says: "import inside the store (project.importFile answers { documentId, diagnostics }), per-file IO hook session, createTestHelpers"
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
from: [0, 0],
|
|
657
|
-
name: "0.6",
|
|
658
|
-
says: "import and IO hooks before the store owned them: read the skills of this version, not the latest docs"
|
|
750
|
+
// src/lib/package-root.ts
|
|
751
|
+
import { existsSync as existsSync11 } from "fs";
|
|
752
|
+
import { dirname as dirname8, join as join14 } from "path";
|
|
753
|
+
function packageRootOf(cwd) {
|
|
754
|
+
for (let folder = cwd; ; folder = dirname8(folder)) {
|
|
755
|
+
if (existsSync11(join14(folder, "package.json"))) return folder;
|
|
756
|
+
if (dirname8(folder) === folder) return void 0;
|
|
659
757
|
}
|
|
660
|
-
|
|
661
|
-
var CHECKOUT_LIST_LIMIT = 8;
|
|
662
|
-
var STATION_AGENTS_SUBJECT = "station agents";
|
|
663
|
-
var PROFILE_SUBJECT = "profile";
|
|
664
|
-
var CONSUMER_ALLOWS_REFERENCES = "allowReferences is the consumer default: remove it";
|
|
665
|
-
var CONTRIBUTOR_GATE_STEPS = "dialecte.gate.full holds {steps}: dialecte contrib runs them, move them to dialecte.contrib.steps (or drop them for the defaults)";
|
|
666
|
-
var CONTRIBUTOR_SKILLS_NOT_SYNCED = "{folder} lacks the contributor skills: dialecte skills sync installs them in a contributor";
|
|
758
|
+
}
|
|
667
759
|
|
|
668
|
-
// src/lib/
|
|
669
|
-
import { existsSync as
|
|
670
|
-
import { join as
|
|
760
|
+
// src/lib/api/source-functions.ts
|
|
761
|
+
import { existsSync as existsSync13 } from "fs";
|
|
762
|
+
import { join as join18 } from "path";
|
|
671
763
|
|
|
672
|
-
// src/lib/
|
|
673
|
-
var
|
|
674
|
-
{ name: "docs", run: "npm run doc:build", restoresGeneratedDocs: true },
|
|
675
|
-
{ name: "type-bench", run: "npm run type-bench:check" }
|
|
676
|
-
];
|
|
764
|
+
// src/lib/tdd/tdd.constants.ts
|
|
765
|
+
var TEST_FILE_PATTERN = /\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
677
766
|
|
|
678
|
-
// src/lib/
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
const dialecte = readPackageJson(cwd).dialecte;
|
|
688
|
-
if (profile === "consumer") {
|
|
689
|
-
const declared = dialecte?.profile === void 0 ? "consumer (default)" : "consumer";
|
|
690
|
-
return [
|
|
691
|
-
{ status: "ok", subject: PROFILE_SUBJECT, detail: declared },
|
|
692
|
-
...dialecte?.allowReferences === void 0 ? [] : [
|
|
693
|
-
{
|
|
694
|
-
status: "warning",
|
|
695
|
-
subject: PROFILE_SUBJECT,
|
|
696
|
-
detail: CONSUMER_ALLOWS_REFERENCES
|
|
697
|
-
}
|
|
698
|
-
]
|
|
699
|
-
];
|
|
700
|
-
}
|
|
701
|
-
const full = Array.isArray(dialecte?.gate?.full) ? dialecte.gate.full : [];
|
|
702
|
-
const contributorSteps = DEFAULT_CONTRIB_STEPS.map((step) => step.name);
|
|
703
|
-
const moved = full.map((step) => step.name).filter((name) => contributorSteps.includes(name));
|
|
704
|
-
const unsynced = Object.values(AGENT_SKILL_FOLDERS).filter(
|
|
705
|
-
(folder) => existsSync6(join7(cwd, folder, MANIFEST_FILE)) && readSyncManifest(join7(cwd, folder)).contributing !== true
|
|
706
|
-
);
|
|
707
|
-
return [
|
|
708
|
-
{ status: "ok", subject: PROFILE_SUBJECT, detail: "contributor" },
|
|
709
|
-
...moved.length ? [
|
|
710
|
-
{
|
|
711
|
-
status: "warning",
|
|
712
|
-
subject: PROFILE_SUBJECT,
|
|
713
|
-
detail: CONTRIBUTOR_GATE_STEPS.replace("{steps}", moved.join(", "))
|
|
714
|
-
}
|
|
715
|
-
] : [],
|
|
716
|
-
...unsynced.map((folder) => ({
|
|
717
|
-
status: "warning",
|
|
718
|
-
subject: PROFILE_SUBJECT,
|
|
719
|
-
detail: CONTRIBUTOR_SKILLS_NOT_SYNCED.replace("{folder}", folder)
|
|
720
|
-
}))
|
|
721
|
-
];
|
|
722
|
-
}
|
|
767
|
+
// src/lib/discover.constants.ts
|
|
768
|
+
import ts from "typescript";
|
|
769
|
+
var ENTRY_FOLDER = "node_modules/.cache/dialecte";
|
|
770
|
+
var ROOTS = ["q", "tx", "doc", "project"];
|
|
771
|
+
var PRIMITIVE_LIKE = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.ESSymbolLike | ts.TypeFlags.VoidLike | ts.TypeFlags.Null | ts.TypeFlags.BigIntLike;
|
|
772
|
+
var SIGNATURE_FORMAT = ts.TypeFormatFlags.WriteArrowStyleSignature | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
773
|
+
var FENCED_CODE_PATTERN = /^[ \t]*```[a-z]*[ \t]*\n([\s\S]*?)^[ \t]*```/m;
|
|
774
|
+
var SIGNATURE_PRINTER = ts.createPrinter({ removeComments: true });
|
|
723
775
|
|
|
724
|
-
// src/lib/
|
|
725
|
-
import {
|
|
726
|
-
import { join as
|
|
776
|
+
// src/lib/discover.ts
|
|
777
|
+
import { mkdirSync as mkdirSync5, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
778
|
+
import { dirname as dirname9, join as join15, relative as relative3 } from "path";
|
|
727
779
|
|
|
728
|
-
// src/lib/
|
|
729
|
-
|
|
730
|
-
|
|
780
|
+
// src/lib/render-jsdoc-text.ts
|
|
781
|
+
function renderJsDocText(parts) {
|
|
782
|
+
let text = "";
|
|
783
|
+
let link;
|
|
784
|
+
for (const part of parts ?? []) {
|
|
785
|
+
if (part.kind === "link" && part.text.startsWith("{@link"))
|
|
786
|
+
link = { name: void 0, label: "" };
|
|
787
|
+
else if (link && part.kind === "linkName") link.name = part.text;
|
|
788
|
+
else if (link && part.kind === "linkText") link.label += part.text;
|
|
789
|
+
else if (link && part.kind === "link") {
|
|
790
|
+
text += renderLink(link);
|
|
791
|
+
link = void 0;
|
|
792
|
+
} else text += part.text;
|
|
793
|
+
}
|
|
794
|
+
return text;
|
|
795
|
+
}
|
|
796
|
+
function renderLink(link) {
|
|
797
|
+
if (link.name !== void 0) return link.label.trim() || `\`${link.name}\``;
|
|
798
|
+
const [target = "", ...label] = link.label.trim().split(/\s+/);
|
|
799
|
+
return label.join(" ") || `\`${target}\``;
|
|
800
|
+
}
|
|
731
801
|
|
|
732
|
-
// src/lib/
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
802
|
+
// src/lib/discover.ts
|
|
803
|
+
import ts2 from "typescript";
|
|
804
|
+
function discoverMethods(params) {
|
|
805
|
+
const { entrySource, tsconfig, root, maxDepth = 1 } = params;
|
|
806
|
+
const entryPath = join15(root, ENTRY_FOLDER, `discover-entry-${process.pid}.ts`);
|
|
807
|
+
mkdirSync5(dirname9(entryPath), { recursive: true });
|
|
808
|
+
writeFileSync4(entryPath, entrySource);
|
|
809
|
+
try {
|
|
810
|
+
const parsed = ts2.parseJsonConfigFileContent(
|
|
811
|
+
ts2.readConfigFile(join15(root, tsconfig), ts2.sys.readFile).config,
|
|
812
|
+
ts2.sys,
|
|
813
|
+
root
|
|
814
|
+
);
|
|
815
|
+
const program = ts2.createProgram([entryPath], {
|
|
816
|
+
...parsed.options,
|
|
817
|
+
noEmit: true,
|
|
818
|
+
rootDir: root
|
|
819
|
+
});
|
|
820
|
+
const checker = program.getTypeChecker();
|
|
821
|
+
const sourceFile = program.getSourceFile(entryPath);
|
|
822
|
+
if (!sourceFile) return [];
|
|
823
|
+
const exportsByName = new Map(
|
|
824
|
+
checker.getExportsOfModule(checker.getSymbolAtLocation(sourceFile)).map((symbol) => [symbol.getName(), symbol])
|
|
825
|
+
);
|
|
826
|
+
const entries = [];
|
|
827
|
+
for (const rootName of ROOTS) {
|
|
828
|
+
const symbol = exportsByName.get(rootName);
|
|
829
|
+
if (symbol)
|
|
830
|
+
walkMembers({
|
|
831
|
+
checker,
|
|
832
|
+
sourceFile,
|
|
833
|
+
type: checker.getTypeOfSymbolAtLocation(symbol, sourceFile),
|
|
834
|
+
path: rootName,
|
|
835
|
+
depth: 0,
|
|
836
|
+
maxDepth,
|
|
837
|
+
root,
|
|
838
|
+
entries
|
|
839
|
+
});
|
|
768
840
|
}
|
|
841
|
+
return entries;
|
|
842
|
+
} finally {
|
|
843
|
+
rmSync4(entryPath, { force: true });
|
|
769
844
|
}
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
// src/lib/models/vendor-id.ts
|
|
773
|
-
function isVendorId(value) {
|
|
774
|
-
return VENDOR_IDS.includes(value);
|
|
775
845
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
846
|
+
function walkMembers(params) {
|
|
847
|
+
const { checker, sourceFile, type, path, depth, maxDepth } = params;
|
|
848
|
+
for (const property of type.getProperties()) {
|
|
849
|
+
if (!isPublic(property)) continue;
|
|
850
|
+
const propertyType = checker.getTypeOfSymbolAtLocation(
|
|
851
|
+
property,
|
|
852
|
+
declarationOf(property) ?? sourceFile
|
|
853
|
+
);
|
|
854
|
+
const propertyPath = `${path}.${property.getName()}`;
|
|
855
|
+
if (propertyType.getCallSignatures().length > 0) {
|
|
856
|
+
const { documentation, declaringSymbol } = documentationOf({
|
|
857
|
+
checker,
|
|
858
|
+
symbol: property,
|
|
859
|
+
root: params.root
|
|
860
|
+
});
|
|
861
|
+
params.entries.push({
|
|
862
|
+
path: propertyPath,
|
|
863
|
+
signature: signatureOf({ checker, boundType: propertyType, declaringSymbol }),
|
|
864
|
+
...documentation
|
|
865
|
+
});
|
|
866
|
+
} else if (depth < maxDepth && !(propertyType.flags & PRIMITIVE_LIKE) && propertyType.getProperties().some(
|
|
867
|
+
(member) => isPublic(member) && !isTypeScriptLibrary(member) && checker.getTypeOfSymbolAtLocation(member, declarationOf(member) ?? sourceFile).getCallSignatures().length > 0
|
|
868
|
+
))
|
|
869
|
+
walkMembers({ ...params, type: propertyType, path: propertyPath, depth: depth + 1 });
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function signatureOf(params) {
|
|
873
|
+
const { checker } = params;
|
|
874
|
+
const boundSignatures = params.boundType.getCallSignatures();
|
|
875
|
+
const declarations = callableDeclarations(params.declaringSymbol);
|
|
876
|
+
if (declarations.length === 0)
|
|
877
|
+
return boundSignatures.map(
|
|
878
|
+
(signature) => checker.signatureToString(signature, void 0, SIGNATURE_FORMAT, ts2.SignatureKind.Call)
|
|
879
|
+
).join("\n");
|
|
880
|
+
const boundParameterCount = Math.max(
|
|
881
|
+
...boundSignatures.map((signature) => parameterCount({ checker, signature }))
|
|
781
882
|
);
|
|
883
|
+
return declarations.map((declaration) => declaredSignatureText({ checker, declaration, boundParameterCount })).join("\n");
|
|
782
884
|
}
|
|
783
|
-
function
|
|
784
|
-
const
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
885
|
+
function parameterCount(params) {
|
|
886
|
+
const { checker } = params;
|
|
887
|
+
const parameters = params.signature.getParameters();
|
|
888
|
+
const last = parameters.at(-1);
|
|
889
|
+
if (!last) return 0;
|
|
890
|
+
const lastType = checker.getTypeOfSymbol(last);
|
|
891
|
+
return checker.isTupleType(lastType) ? parameters.length - 1 + checker.getTypeArguments(lastType).length : parameters.length;
|
|
892
|
+
}
|
|
893
|
+
function callableDeclarations(symbol) {
|
|
894
|
+
const declarations = (symbol?.declarations ?? []).flatMap(
|
|
895
|
+
(declaration) => {
|
|
896
|
+
if (ts2.isFunctionDeclaration(declaration) || ts2.isMethodDeclaration(declaration))
|
|
897
|
+
return [declaration];
|
|
898
|
+
if (ts2.isVariableDeclaration(declaration) && declaration.initializer && (ts2.isArrowFunction(declaration.initializer) || ts2.isFunctionExpression(declaration.initializer)))
|
|
899
|
+
return [declaration.initializer];
|
|
900
|
+
return [];
|
|
792
901
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
writtenAt: statSync4(join8(cwd, folder, MANIFEST_FILE)).mtimeMs
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
entries.sort((first, second) => second.writtenAt - first.writtenAt);
|
|
800
|
-
if (new Set(entries.map((entry) => entry.vendor)).size > 1)
|
|
801
|
-
warnings.push(
|
|
802
|
-
`manifests disagree on the vendor (${entries.map((entry) => `${entry.folder}: ${entry.vendor}`).join(", ")}): using the most recent, ${entries[0].vendor}`
|
|
803
|
-
);
|
|
804
|
-
return { vendor: entries[0]?.vendor, warnings };
|
|
902
|
+
);
|
|
903
|
+
const overloads = declarations.filter((declaration) => !hasBody(declaration));
|
|
904
|
+
return overloads.length > 0 ? overloads : declarations;
|
|
805
905
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
var STATION_AGENT_PREFIX = "dialecte-";
|
|
809
|
-
var CLAUDE_AGENTS_FOLDER = ".claude/agents";
|
|
810
|
-
var CLAUDE_MODEL_ALIASES = ["haiku", "sonnet", "opus", "fable"];
|
|
811
|
-
var READ_TOOLS = ["Read", "Glob", "Grep", "Skill"];
|
|
812
|
-
var REVIEW_TOOLS = ["Read", "Glob", "Grep", "Bash", "Skill"];
|
|
813
|
-
var EDIT_TOOLS = ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "Skill"];
|
|
814
|
-
var CLAUDE_TOOLS_BY_ACCESS = {
|
|
815
|
-
read: READ_TOOLS,
|
|
816
|
-
review: REVIEW_TOOLS,
|
|
817
|
-
edit: EDIT_TOOLS
|
|
818
|
-
};
|
|
819
|
-
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.";
|
|
820
|
-
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.";
|
|
821
|
-
var GENERATED_NOTE = "Generated by `npx @dialecte/cli skills sync` from `dialecte models`; the next sync overwrites it.";
|
|
822
|
-
var STATIONS = [
|
|
823
|
-
{
|
|
824
|
-
name: "test-writer",
|
|
825
|
-
tier: "standard",
|
|
826
|
-
access: "edit",
|
|
827
|
-
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."
|
|
828
|
-
},
|
|
829
|
-
{
|
|
830
|
-
name: "test-reviewer",
|
|
831
|
-
tier: "strong",
|
|
832
|
-
access: "review",
|
|
833
|
-
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."
|
|
834
|
-
},
|
|
835
|
-
{
|
|
836
|
-
name: "implementer",
|
|
837
|
-
tier: "standard",
|
|
838
|
-
access: "edit",
|
|
839
|
-
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."
|
|
840
|
-
},
|
|
841
|
-
{
|
|
842
|
-
name: "implementer-strong",
|
|
843
|
-
tier: "strong",
|
|
844
|
-
access: "edit",
|
|
845
|
-
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."
|
|
846
|
-
},
|
|
847
|
-
{
|
|
848
|
-
name: "reviewer",
|
|
849
|
-
tier: "strong",
|
|
850
|
-
access: "review",
|
|
851
|
-
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."
|
|
852
|
-
},
|
|
853
|
-
{
|
|
854
|
-
name: "fixer",
|
|
855
|
-
tier: "standard",
|
|
856
|
-
access: "edit",
|
|
857
|
-
description: "Dialecte lot, Station 4 (fix mode) on wording and naming findings: fixed, disagreed or escalated per finding. Give it the findings."
|
|
858
|
-
},
|
|
859
|
-
{
|
|
860
|
-
name: "eval-runner",
|
|
861
|
-
tier: "standard",
|
|
862
|
-
access: "edit",
|
|
863
|
-
description: "Runs one skill-eval case of a Dialecte skill, with or without the skill, and leaves the outputs the graders read."
|
|
864
|
-
},
|
|
865
|
-
{
|
|
866
|
-
name: "grader",
|
|
867
|
-
tier: "strong",
|
|
868
|
-
access: "read",
|
|
869
|
-
description: "Grades the output of a skill-eval run against one grader file, pass or fail with the evidence. Read-only."
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
name: "standard-reader",
|
|
873
|
-
tier: "standard",
|
|
874
|
-
access: "read",
|
|
875
|
-
description: "Independent reader of the IEC standard markdown for one question, with line references. Read-only."
|
|
876
|
-
},
|
|
877
|
-
{
|
|
878
|
-
name: "searcher",
|
|
879
|
-
tier: "fast",
|
|
880
|
-
access: "read",
|
|
881
|
-
description: "Finds where something lives in a Dialecte repository (files, symbols, API paths) and answers with paths and line numbers. Read-only."
|
|
882
|
-
}
|
|
883
|
-
];
|
|
884
|
-
var LOT_SKILL = "dialecte-lot";
|
|
885
|
-
var STATIONS_PAGE_PATH = `${AGENT_SKILL_FOLDERS.claude}/${LOT_SKILL}/references/stations.md`;
|
|
886
|
-
var BRIEF_DEFINED_STATIONS = ["eval-runner", "grader"];
|
|
887
|
-
|
|
888
|
-
// src/lib/stations/render-station-agent.ts
|
|
889
|
-
function claudeModelAlias(modelName) {
|
|
890
|
-
const alias = modelName.split(" ")[0].toLowerCase();
|
|
891
|
-
return CLAUDE_MODEL_ALIASES.includes(alias) ? alias : void 0;
|
|
906
|
+
function hasBody(declaration) {
|
|
907
|
+
return "body" in declaration && declaration.body !== void 0;
|
|
892
908
|
}
|
|
893
|
-
function
|
|
894
|
-
const {
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
909
|
+
function declaredSignatureText(params) {
|
|
910
|
+
const { checker, declaration } = params;
|
|
911
|
+
const sourceFile = declaration.getSourceFile();
|
|
912
|
+
const signature = checker.getSignatureFromDeclaration(declaration);
|
|
913
|
+
const parameters = declaration.parameters;
|
|
914
|
+
const skipped = Math.max(0, parameters.length - params.boundParameterCount);
|
|
915
|
+
const typeParameters = declaration.typeParameters?.length ? `<${declaration.typeParameters.map((typeParameter) => printed({ node: typeParameter, sourceFile })).join(", ")}>` : "";
|
|
916
|
+
const parameterTexts = parameters.slice(skipped).map(function parameterText(parameter) {
|
|
917
|
+
const optional = parameter.questionToken || parameter.initializer ? "?" : "";
|
|
918
|
+
const rest = parameter.dotDotDotToken ? "..." : "";
|
|
919
|
+
const type = parameter.type ? printed({ node: parameter.type, sourceFile }) : checker.typeToString(checker.getTypeAtLocation(parameter), declaration, SIGNATURE_FORMAT);
|
|
920
|
+
return `${rest}${printed({ node: parameter.name, sourceFile })}${optional}: ${type}`;
|
|
921
|
+
});
|
|
922
|
+
const returnType = declaration.type ? printed({ node: declaration.type, sourceFile }) : signature ? checker.typeToString(signature.getReturnType(), declaration, SIGNATURE_FORMAT) : "unknown";
|
|
923
|
+
return `${typeParameters}(${parameterTexts.join(", ")}) => ${returnType}`;
|
|
907
924
|
}
|
|
908
|
-
function
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
`tools: ${CLAUDE_TOOLS_BY_ACCESS[station.access].join(", ")}`,
|
|
915
|
-
`model: ${model}`,
|
|
916
|
-
"---",
|
|
917
|
-
`<!-- ${GENERATED_NOTE} -->`,
|
|
918
|
-
"",
|
|
919
|
-
...stationLines({ station }),
|
|
920
|
-
NEVER_LINE,
|
|
921
|
-
""
|
|
922
|
-
].join("\n");
|
|
925
|
+
function printed(params) {
|
|
926
|
+
return SIGNATURE_PRINTER.printNode(
|
|
927
|
+
ts2.EmitHint.Unspecified,
|
|
928
|
+
params.node,
|
|
929
|
+
params.sourceFile
|
|
930
|
+
).replace(/\s*\n\s*/g, " ");
|
|
923
931
|
}
|
|
924
|
-
function
|
|
925
|
-
const {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
if (model === void 0)
|
|
932
|
+
function documentationOf(params) {
|
|
933
|
+
const { checker } = params;
|
|
934
|
+
const visited = /* @__PURE__ */ new Set();
|
|
935
|
+
const queue = [params.symbol];
|
|
936
|
+
let declaringSymbol;
|
|
937
|
+
while (queue.length) {
|
|
938
|
+
const symbol = queue.shift();
|
|
939
|
+
if (!symbol || visited.has(symbol)) continue;
|
|
940
|
+
visited.add(symbol);
|
|
941
|
+
if (symbol.flags & ts2.SymbolFlags.Alias) {
|
|
942
|
+
queue.push(checker.getAliasedSymbol(symbol));
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
declaringSymbol ??= symbol;
|
|
946
|
+
const comment = renderJsDocText(symbol.getDocumentationComment(checker));
|
|
947
|
+
if (comment) {
|
|
948
|
+
const tags2 = symbol.getJsDocTags(checker);
|
|
942
949
|
return {
|
|
943
|
-
|
|
944
|
-
|
|
950
|
+
documentation: {
|
|
951
|
+
summary: firstParagraph(comment),
|
|
952
|
+
intents: intentsOf(tags2),
|
|
953
|
+
example: exampleOf(tags2),
|
|
954
|
+
definedInPackage: isDeclaredInPackage({ symbol, root: params.root }),
|
|
955
|
+
internal: tags2.some((tag) => tag.name === "internal"),
|
|
956
|
+
declaredAt: declarationKey({ symbol, root: params.root })
|
|
957
|
+
},
|
|
958
|
+
declaringSymbol: symbol
|
|
945
959
|
};
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
960
|
+
}
|
|
961
|
+
for (const declaration of symbol.declarations ?? []) {
|
|
962
|
+
if (ts2.isShorthandPropertyAssignment(declaration))
|
|
963
|
+
queue.push(checker.getShorthandAssignmentValueSymbol(declaration));
|
|
964
|
+
else if (ts2.isPropertyAssignment(declaration))
|
|
965
|
+
queue.push(assignedSymbol({ checker, initializer: declaration.initializer }));
|
|
966
|
+
else if (ts2.isExportSpecifier(declaration))
|
|
967
|
+
queue.push(checker.getExportSpecifierLocalTargetSymbol(declaration));
|
|
968
|
+
}
|
|
950
969
|
}
|
|
951
|
-
|
|
970
|
+
const declaringFunction = lastDeclared(visited) ?? declaringSymbol;
|
|
971
|
+
const tags = declaringFunction?.getJsDocTags(checker) ?? [];
|
|
972
|
+
return {
|
|
973
|
+
documentation: {
|
|
974
|
+
summary: void 0,
|
|
975
|
+
intents: intentsOf(tags),
|
|
976
|
+
example: exampleOf(tags),
|
|
977
|
+
internal: tags.some((tag) => tag.name === "internal"),
|
|
978
|
+
definedInPackage: isDeclaredInPackage({ symbol: declaringFunction, root: params.root }),
|
|
979
|
+
declaredAt: declarationKey({ symbol: declaringFunction, root: params.root })
|
|
980
|
+
},
|
|
981
|
+
declaringSymbol: declaringFunction
|
|
982
|
+
};
|
|
952
983
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const
|
|
961
|
-
if (
|
|
962
|
-
const
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
984
|
+
function firstParagraph(comment) {
|
|
985
|
+
return comment.split(/\n\s*\n/)[0].replace(/\s+/g, " ").trim();
|
|
986
|
+
}
|
|
987
|
+
function intentsOf(tags) {
|
|
988
|
+
return tags.filter((tag) => tag.name === "intent").flatMap((tag) => parseIntentText(renderJsDocText(tag.text)));
|
|
989
|
+
}
|
|
990
|
+
function exampleOf(tags) {
|
|
991
|
+
const tag = tags.find((candidate) => candidate.name === "example");
|
|
992
|
+
if (!tag) return void 0;
|
|
993
|
+
const text = renderJsDocText(tag.text);
|
|
994
|
+
const fenced = text.match(FENCED_CODE_PATTERN);
|
|
995
|
+
const code = (fenced ? fenced[1] : text).trim();
|
|
996
|
+
return code || void 0;
|
|
997
|
+
}
|
|
998
|
+
function parseIntentText(text) {
|
|
999
|
+
const intents = [];
|
|
1000
|
+
let depth = 0;
|
|
1001
|
+
let current = "";
|
|
1002
|
+
for (const character of text.split(/\n\s*\n/)[0]) {
|
|
1003
|
+
if (character === "(") depth++;
|
|
1004
|
+
else if (character === ")") depth = Math.max(0, depth - 1);
|
|
1005
|
+
if (character === "," && depth === 0) {
|
|
1006
|
+
intents.push(current);
|
|
1007
|
+
current = "";
|
|
1008
|
+
} else current += character;
|
|
969
1009
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1010
|
+
intents.push(current);
|
|
1011
|
+
return intents.map((intent) => intent.replace(/\s+/g, " ").trim()).filter(Boolean);
|
|
1012
|
+
}
|
|
1013
|
+
function assignedSymbol(params) {
|
|
1014
|
+
const { checker, initializer } = params;
|
|
1015
|
+
if (ts2.isIdentifier(initializer)) return checker.getSymbolAtLocation(initializer);
|
|
1016
|
+
if (ts2.isPropertyAccessExpression(initializer))
|
|
1017
|
+
return checker.getSymbolAtLocation(initializer.name);
|
|
1018
|
+
return void 0;
|
|
1019
|
+
}
|
|
1020
|
+
function lastDeclared(symbols) {
|
|
1021
|
+
return [...symbols].reverse().find((symbol) => (symbol.declarations ?? []).some(declaresFunction));
|
|
1022
|
+
}
|
|
1023
|
+
function declaresFunction(declaration) {
|
|
1024
|
+
if (ts2.isFunctionDeclaration(declaration) || ts2.isMethodDeclaration(declaration)) return true;
|
|
1025
|
+
if (!ts2.isVariableDeclaration(declaration) || !declaration.initializer) return false;
|
|
1026
|
+
return ts2.isArrowFunction(declaration.initializer) || ts2.isFunctionExpression(declaration.initializer);
|
|
1027
|
+
}
|
|
1028
|
+
function declarationKey(params) {
|
|
1029
|
+
const declaration = params.symbol?.declarations?.[0];
|
|
1030
|
+
if (!declaration) return void 0;
|
|
1031
|
+
return `${relative3(params.root, declaration.getSourceFile().fileName)}:${declaration.getStart()}`;
|
|
1032
|
+
}
|
|
1033
|
+
function isDeclaredInPackage(params) {
|
|
1034
|
+
const fileName = params.symbol?.declarations?.[0]?.getSourceFile().fileName;
|
|
1035
|
+
if (!fileName) return false;
|
|
1036
|
+
const path = relative3(params.root, fileName);
|
|
1037
|
+
return !path.startsWith("..") && !path.split(/[\\/]/).includes("node_modules");
|
|
1038
|
+
}
|
|
1039
|
+
function declarationOf(symbol) {
|
|
1040
|
+
return symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
1041
|
+
}
|
|
1042
|
+
function isPublic(symbol) {
|
|
1043
|
+
const declaration = declarationOf(symbol);
|
|
1044
|
+
return !declaration || !(ts2.getCombinedModifierFlags(declaration) & (ts2.ModifierFlags.Private | ts2.ModifierFlags.Protected));
|
|
1045
|
+
}
|
|
1046
|
+
function isTypeScriptLibrary(symbol) {
|
|
1047
|
+
return (declarationOf(symbol)?.getSourceFile()?.fileName ?? "").includes(
|
|
1048
|
+
"/node_modules/typescript/"
|
|
1049
|
+
);
|
|
984
1050
|
}
|
|
985
1051
|
|
|
986
|
-
// src/lib/
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1052
|
+
// src/lib/first-syntax-error.constants.ts
|
|
1053
|
+
import ts3 from "typescript";
|
|
1054
|
+
var SYNTAX_CHECK_OPTIONS = {
|
|
1055
|
+
noLib: true,
|
|
1056
|
+
noResolve: true,
|
|
1057
|
+
isolatedModules: true,
|
|
1058
|
+
allowNonTsExtensions: true,
|
|
1059
|
+
target: ts3.ScriptTarget.Latest
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
// src/lib/first-syntax-error.ts
|
|
1063
|
+
import ts4 from "typescript";
|
|
1064
|
+
function firstSyntaxErrorOf(params) {
|
|
1065
|
+
const { source } = params;
|
|
1066
|
+
const program = ts4.createProgram({
|
|
1067
|
+
rootNames: [source.fileName],
|
|
1068
|
+
options: SYNTAX_CHECK_OPTIONS,
|
|
1069
|
+
host: singleFileHost(source)
|
|
1070
|
+
});
|
|
1071
|
+
const [first] = program.getSyntacticDiagnostics(source);
|
|
1072
|
+
if (first === void 0) return void 0;
|
|
1073
|
+
const position = source.getLineAndCharacterOfPosition(first.start ?? 0);
|
|
1074
|
+
return {
|
|
1075
|
+
line: position.line + 1,
|
|
1076
|
+
column: position.character + 1,
|
|
1077
|
+
message: ts4.flattenDiagnosticMessageText(first.messageText, " ")
|
|
1078
|
+
};
|
|
997
1079
|
}
|
|
998
|
-
function
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1080
|
+
function singleFileHost(source) {
|
|
1081
|
+
return {
|
|
1082
|
+
getSourceFile: function sourceNamed(name) {
|
|
1083
|
+
return name === source.fileName ? source : void 0;
|
|
1084
|
+
},
|
|
1085
|
+
fileExists: function isTheFile(name) {
|
|
1086
|
+
return name === source.fileName;
|
|
1087
|
+
},
|
|
1088
|
+
readFile: function readNothing() {
|
|
1089
|
+
return void 0;
|
|
1090
|
+
},
|
|
1091
|
+
writeFile: function writeNothing() {
|
|
1092
|
+
},
|
|
1093
|
+
getDefaultLibFileName: function noLibrary() {
|
|
1094
|
+
return "";
|
|
1095
|
+
},
|
|
1096
|
+
getCurrentDirectory: function noDirectory() {
|
|
1097
|
+
return "";
|
|
1098
|
+
},
|
|
1099
|
+
getCanonicalFileName: function sameName(name) {
|
|
1100
|
+
return name;
|
|
1101
|
+
},
|
|
1102
|
+
useCaseSensitiveFileNames: function caseSensitive() {
|
|
1103
|
+
return true;
|
|
1104
|
+
},
|
|
1105
|
+
getNewLine: function newLine() {
|
|
1106
|
+
return "\n";
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/lib/api/source-file-functions.ts
|
|
1112
|
+
import ts5 from "typescript";
|
|
1113
|
+
function parseSourceFile(params) {
|
|
1114
|
+
const { file, text } = params;
|
|
1115
|
+
const source = ts5.createSourceFile(file, text, ts5.ScriptTarget.Latest, true);
|
|
1116
|
+
const syntaxError = firstSyntaxErrorOf({ source });
|
|
1117
|
+
if (syntaxError !== void 0)
|
|
1118
|
+
return {
|
|
1119
|
+
entries: [],
|
|
1120
|
+
note: NOT_PARSED_NOTE.replace("{file}", file).replace("{why}", syntaxError.message)
|
|
1121
|
+
};
|
|
1122
|
+
return {
|
|
1123
|
+
entries: exportedFunctionsOf(source).map(function entryOfFunction(found) {
|
|
1124
|
+
return sourceEntry({ file, source, found });
|
|
1125
|
+
})
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
function exportedFunctionsOf(source) {
|
|
1129
|
+
const listed = locallyExportedNames(source);
|
|
1130
|
+
return topLevelFunctionsOf(source).flatMap(function exportsOfFunction(found) {
|
|
1131
|
+
const names = [...found.exported ? [found.name] : [], ...listed.get(found.name) ?? []];
|
|
1132
|
+
return [...new Set(names)].map(function exportedAs(name) {
|
|
1006
1133
|
return {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1134
|
+
name,
|
|
1135
|
+
node: found.node,
|
|
1136
|
+
declaration: found.declaration,
|
|
1137
|
+
documented: found.documented
|
|
1011
1138
|
};
|
|
1012
|
-
|
|
1139
|
+
});
|
|
1013
1140
|
});
|
|
1014
1141
|
}
|
|
1015
|
-
function
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1142
|
+
function locallyExportedNames(source) {
|
|
1143
|
+
const names = /* @__PURE__ */ new Map();
|
|
1144
|
+
for (const statement of source.statements) {
|
|
1145
|
+
if (!ts5.isExportDeclaration(statement) || statement.moduleSpecifier !== void 0) continue;
|
|
1146
|
+
if (statement.isTypeOnly || statement.exportClause === void 0) continue;
|
|
1147
|
+
if (!ts5.isNamedExports(statement.exportClause)) continue;
|
|
1148
|
+
for (const element of statement.exportClause.elements) {
|
|
1149
|
+
if (element.isTypeOnly) continue;
|
|
1150
|
+
const local = (element.propertyName ?? element.name).text;
|
|
1151
|
+
names.set(local, [...names.get(local) ?? [], element.name.text]);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return names;
|
|
1155
|
+
}
|
|
1156
|
+
function topLevelFunctionsOf(source) {
|
|
1157
|
+
const found = [];
|
|
1158
|
+
const overloads = /* @__PURE__ */ new Map();
|
|
1159
|
+
for (const statement of source.statements) {
|
|
1160
|
+
if (ts5.isFunctionDeclaration(statement) && statement.name !== void 0) {
|
|
1161
|
+
const name = statement.name.text;
|
|
1162
|
+
const set = [...overloads.get(name) ?? [], statement];
|
|
1163
|
+
if (statement.body === void 0) {
|
|
1164
|
+
overloads.set(name, set);
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
overloads.delete(name);
|
|
1168
|
+
found.push({
|
|
1169
|
+
name,
|
|
1170
|
+
node: statement,
|
|
1171
|
+
declaration: set[0],
|
|
1172
|
+
documented: set.find(hasJsDoc) ?? statement,
|
|
1173
|
+
exported: set.some(isExported)
|
|
1174
|
+
});
|
|
1175
|
+
} else if (ts5.isVariableStatement(statement) && statement.declarationList.flags & ts5.NodeFlags.Const)
|
|
1176
|
+
found.push(...constFunctionsOf(statement));
|
|
1177
|
+
}
|
|
1178
|
+
return found;
|
|
1179
|
+
}
|
|
1180
|
+
function constFunctionsOf(statement) {
|
|
1181
|
+
const exported = isExported(statement);
|
|
1182
|
+
return statement.declarationList.declarations.flatMap(
|
|
1183
|
+
function functionOfDeclaration(declaration) {
|
|
1184
|
+
const { initializer, name } = declaration;
|
|
1185
|
+
if (!ts5.isIdentifier(name) || initializer === void 0) return [];
|
|
1186
|
+
if (!ts5.isArrowFunction(initializer) && !ts5.isFunctionExpression(initializer)) return [];
|
|
1187
|
+
return [{ name: name.text, node: initializer, declaration, documented: statement, exported }];
|
|
1188
|
+
}
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
function hasJsDoc(node) {
|
|
1192
|
+
return ts5.getJSDocCommentsAndTags(node).some(ts5.isJSDoc);
|
|
1193
|
+
}
|
|
1194
|
+
function isExported(statement) {
|
|
1195
|
+
return ts5.canHaveModifiers(statement) && (ts5.getModifiers(statement) ?? []).some(function isExportKeyword(modifier) {
|
|
1196
|
+
return modifier.kind === ts5.SyntaxKind.ExportKeyword;
|
|
1019
1197
|
});
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1198
|
+
}
|
|
1199
|
+
function sourceEntry(params) {
|
|
1200
|
+
const { file, source, found } = params;
|
|
1201
|
+
const jsDoc = ts5.getJSDocCommentsAndTags(found.documented).filter(ts5.isJSDoc).at(-1);
|
|
1202
|
+
const line = source.getLineAndCharacterOfPosition(found.declaration.getStart(source)).line + 1;
|
|
1203
|
+
return {
|
|
1204
|
+
path: `${file}#${found.name}`,
|
|
1205
|
+
root: "source",
|
|
1206
|
+
entry: void 0,
|
|
1207
|
+
otherRoutes: [],
|
|
1208
|
+
signature: signatureOf2({ source, node: found.node }),
|
|
1209
|
+
summary: summaryOf(jsDoc),
|
|
1210
|
+
intents: intentsOf2(jsDoc),
|
|
1211
|
+
declaredAt: `${file}:${line}`,
|
|
1212
|
+
example: void 0
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
function summaryOf(jsDoc) {
|
|
1216
|
+
const text = (ts5.getTextOfJSDocComment(jsDoc?.comment) ?? "").replace(/\s+/g, " ").trim();
|
|
1217
|
+
return text === "" ? void 0 : firstSentence(text);
|
|
1218
|
+
}
|
|
1219
|
+
function intentsOf2(jsDoc) {
|
|
1220
|
+
return (jsDoc?.tags ?? []).filter(function isIntentTag(tag) {
|
|
1221
|
+
return tag.tagName.text === INTENT_TAG;
|
|
1222
|
+
}).flatMap(function intentsOfTag(tag) {
|
|
1223
|
+
return parseIntentText(ts5.getTextOfJSDocComment(tag.comment) ?? "");
|
|
1042
1224
|
});
|
|
1043
1225
|
}
|
|
1044
|
-
function
|
|
1045
|
-
const {
|
|
1046
|
-
|
|
1047
|
-
return
|
|
1048
|
-
|
|
1049
|
-
|
|
1226
|
+
function signatureOf2(params) {
|
|
1227
|
+
const { source, node } = params;
|
|
1228
|
+
function print(part) {
|
|
1229
|
+
return oneLine(SIGNATURE_PRINTER.printNode(ts5.EmitHint.Unspecified, part, source));
|
|
1230
|
+
}
|
|
1231
|
+
const typeParameters = node.typeParameters ? `<${node.typeParameters.map(print).join(", ")}>` : "";
|
|
1232
|
+
const returnType = node.type ? `: ${print(node.type)}` : "";
|
|
1233
|
+
return `${typeParameters}(${node.parameters.map(print).join(", ")})${returnType}`;
|
|
1234
|
+
}
|
|
1235
|
+
function oneLine(printed2) {
|
|
1236
|
+
const scanner = ts5.createScanner(
|
|
1237
|
+
ts5.ScriptTarget.Latest,
|
|
1238
|
+
false,
|
|
1239
|
+
ts5.LanguageVariant.Standard,
|
|
1240
|
+
printed2
|
|
1050
1241
|
);
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1242
|
+
const tokens = [];
|
|
1243
|
+
const open = [];
|
|
1244
|
+
let spaced = false;
|
|
1245
|
+
for (let kind = scanner.scan(); kind !== ts5.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
|
|
1246
|
+
if (kind === ts5.SyntaxKind.WhitespaceTrivia || kind === ts5.SyntaxKind.NewLineTrivia) {
|
|
1247
|
+
spaced = tokens.length > 0;
|
|
1248
|
+
continue;
|
|
1249
|
+
}
|
|
1250
|
+
if (kind === ts5.SyntaxKind.CloseBraceToken && open.at(-1) === ts5.SyntaxKind.TemplateHead) {
|
|
1251
|
+
kind = scanner.reScanTemplateToken(false);
|
|
1252
|
+
if (kind === ts5.SyntaxKind.TemplateTail) open.pop();
|
|
1253
|
+
} else if (kind === ts5.SyntaxKind.OpenBraceToken || kind === ts5.SyntaxKind.TemplateHead)
|
|
1254
|
+
open.push(kind);
|
|
1255
|
+
else if (kind === ts5.SyntaxKind.CloseBraceToken) open.pop();
|
|
1256
|
+
tokens.push({ kind, text: scanner.getTokenText(), spaced });
|
|
1257
|
+
spaced = false;
|
|
1258
|
+
}
|
|
1259
|
+
return tokens.filter(function keptToken(token, index) {
|
|
1260
|
+
return !(token.kind === ts5.SyntaxKind.SemicolonToken && tokens[index + 1]?.kind === ts5.SyntaxKind.CloseBraceToken);
|
|
1261
|
+
}).map(function textOfToken(token) {
|
|
1262
|
+
return token.spaced ? ` ${token.text}` : token.text;
|
|
1263
|
+
}).join("");
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// src/lib/api/source-index.ts
|
|
1267
|
+
import { createHash } from "crypto";
|
|
1268
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
1269
|
+
import { join as join17 } from "path";
|
|
1270
|
+
|
|
1271
|
+
// src/lib/read-cli-version.ts
|
|
1272
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
|
|
1273
|
+
import { dirname as dirname10, join as join16 } from "path";
|
|
1274
|
+
import { fileURLToPath } from "url";
|
|
1275
|
+
function readCliVersion(params = {}) {
|
|
1276
|
+
const startFolder = params.startFolder ?? dirname10(fileURLToPath(import.meta.url));
|
|
1277
|
+
let folder = startFolder;
|
|
1278
|
+
while (!existsSync12(join16(folder, "package.json"))) {
|
|
1279
|
+
const parent = dirname10(folder);
|
|
1280
|
+
if (parent === folder)
|
|
1281
|
+
throw new Error(`no package.json above ${startFolder}: cannot read the cli version`);
|
|
1282
|
+
folder = parent;
|
|
1283
|
+
}
|
|
1284
|
+
const { version } = JSON.parse(readFileSync9(join16(folder, "package.json"), "utf8"));
|
|
1285
|
+
return version;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// src/lib/api/source-index.ts
|
|
1289
|
+
function indexSourceFiles(params) {
|
|
1290
|
+
const { root, files, parse: parse2 } = params;
|
|
1291
|
+
if (!isInWorkTree(root))
|
|
1292
|
+
return files.map(function parseFile(file) {
|
|
1293
|
+
return parse2({ file, text: readFileSync10(join17(root, file), "utf8") });
|
|
1082
1294
|
});
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1295
|
+
const cacheFile = join17(gitFolderOf(root), SOURCE_INDEX_FILE);
|
|
1296
|
+
const reader = readCliVersion();
|
|
1297
|
+
const prefix = readGit({ root, args: ["rev-parse", "--show-prefix"] }).trim();
|
|
1298
|
+
const cached = readCache({ cacheFile, reader });
|
|
1299
|
+
let changed = cached === void 0;
|
|
1300
|
+
const next = {
|
|
1301
|
+
schema: SOURCE_INDEX_SCHEMA,
|
|
1302
|
+
reader,
|
|
1303
|
+
files: othersFiles({ cached, prefix, files })
|
|
1304
|
+
};
|
|
1305
|
+
const answer = files.map(function parseChangedFile(file) {
|
|
1306
|
+
const key = `${prefix}${file}`;
|
|
1307
|
+
const bytes = readFileSync10(join17(root, file));
|
|
1308
|
+
const hash = createHash("sha256").update(bytes).digest("hex");
|
|
1309
|
+
const known = cached?.files[key];
|
|
1310
|
+
if (known !== void 0 && known.hash === hash) {
|
|
1311
|
+
next.files[key] = known;
|
|
1312
|
+
return parsedOf(known);
|
|
1313
|
+
}
|
|
1314
|
+
changed = true;
|
|
1315
|
+
const parsed = parse2({ file, text: bytes.toString("utf8") });
|
|
1316
|
+
next.files[key] = { hash, ...parsed };
|
|
1317
|
+
return parsed;
|
|
1091
1318
|
});
|
|
1319
|
+
if (cached !== void 0 && Object.keys(cached.files).length !== Object.keys(next.files).length)
|
|
1320
|
+
changed = true;
|
|
1321
|
+
if (changed) writeCache({ cacheFile, cache: next });
|
|
1322
|
+
return answer;
|
|
1323
|
+
}
|
|
1324
|
+
function othersFiles(params) {
|
|
1325
|
+
const { prefix } = params;
|
|
1326
|
+
const folders = new Set(params.files.map(topFolderOf));
|
|
1327
|
+
return Object.fromEntries(
|
|
1328
|
+
Object.entries(params.cached?.files ?? {}).filter(function isOthers([key]) {
|
|
1329
|
+
return !(key.startsWith(prefix) && folders.has(topFolderOf(key.slice(prefix.length))));
|
|
1330
|
+
})
|
|
1331
|
+
);
|
|
1092
1332
|
}
|
|
1093
|
-
function
|
|
1333
|
+
function topFolderOf(path) {
|
|
1334
|
+
return path.split("/", 1)[0];
|
|
1335
|
+
}
|
|
1336
|
+
function readCache(params) {
|
|
1337
|
+
let value;
|
|
1094
1338
|
try {
|
|
1095
|
-
|
|
1339
|
+
value = JSON.parse(readFileSync10(params.cacheFile, "utf8"));
|
|
1096
1340
|
} catch {
|
|
1097
|
-
return
|
|
1341
|
+
return void 0;
|
|
1098
1342
|
}
|
|
1343
|
+
return isCache(value) && value.reader === params.reader ? value : void 0;
|
|
1344
|
+
}
|
|
1345
|
+
function isCache(value) {
|
|
1346
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1347
|
+
const { schema, files } = value;
|
|
1348
|
+
if (schema !== SOURCE_INDEX_SCHEMA || typeof files !== "object" || files === null) return false;
|
|
1349
|
+
return Object.values(files).every(function isCachedFile(file) {
|
|
1350
|
+
if (typeof file !== "object" || file === null) return false;
|
|
1351
|
+
const { hash, entries, note } = file;
|
|
1352
|
+
return typeof hash === "string" && Array.isArray(entries) && entries.every(isCachedEntry) && (note === void 0 || typeof note === "string");
|
|
1353
|
+
});
|
|
1099
1354
|
}
|
|
1100
|
-
function
|
|
1355
|
+
function isCachedEntry(value) {
|
|
1356
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1357
|
+
const entry = value;
|
|
1358
|
+
return typeof entry.path === "string" && entry.root === "source" && typeof entry.signature === "string" && typeof entry.declaredAt === "string" && isStringList(entry.otherRoutes) && isStringList(entry.intents) && (entry.summary === void 0 || typeof entry.summary === "string");
|
|
1359
|
+
}
|
|
1360
|
+
function isStringList(value) {
|
|
1361
|
+
return Array.isArray(value) && value.every(function isString(item) {
|
|
1362
|
+
return typeof item === "string";
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
function parsedOf(known) {
|
|
1366
|
+
return known.note === void 0 ? { entries: known.entries } : { entries: known.entries, note: known.note };
|
|
1367
|
+
}
|
|
1368
|
+
function writeCache(params) {
|
|
1101
1369
|
try {
|
|
1102
|
-
|
|
1370
|
+
replaceWhole({ path: params.cacheFile, text: JSON.stringify(params.cache) });
|
|
1103
1371
|
} catch {
|
|
1104
|
-
return false;
|
|
1105
1372
|
}
|
|
1106
1373
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1374
|
+
|
|
1375
|
+
// src/lib/api/source-functions.ts
|
|
1376
|
+
function readSourceFunctions(params) {
|
|
1377
|
+
const { root } = params;
|
|
1378
|
+
const folder = join18(root, SOURCE_FOLDER);
|
|
1379
|
+
if (!isFolder(folder))
|
|
1380
|
+
return { entries: [], notes: [NO_SOURCE_FOLDER_NOTE.replace("{root}", root)] };
|
|
1381
|
+
const parsedFiles = indexSourceFiles({
|
|
1382
|
+
root,
|
|
1383
|
+
files: listSourceFiles(root),
|
|
1384
|
+
parse: params.parse ?? parseSourceFile
|
|
1385
|
+
});
|
|
1386
|
+
return {
|
|
1387
|
+
entries: parsedFiles.flatMap(function entriesOfFile(parsed) {
|
|
1388
|
+
return parsed.entries;
|
|
1389
|
+
}),
|
|
1390
|
+
notes: parsedFiles.flatMap(function noteOfFile(parsed) {
|
|
1391
|
+
return parsed.note === void 0 ? [] : [parsed.note];
|
|
1392
|
+
})
|
|
1393
|
+
};
|
|
1110
1394
|
}
|
|
1111
|
-
function
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1395
|
+
function listSourceFiles(root) {
|
|
1396
|
+
const files = isInWorkTree(root) ? listRepositoryFiles({ root, folder: SOURCE_FOLDER }).filter(function isOnDisk(file) {
|
|
1397
|
+
return existsSync13(join18(root, file));
|
|
1398
|
+
}) : listTreeFiles(join18(root, SOURCE_FOLDER)).map(function pathFromRoot(file) {
|
|
1399
|
+
return `${SOURCE_FOLDER}/${file}`;
|
|
1400
|
+
});
|
|
1401
|
+
return files.filter(function isSourceFile(file) {
|
|
1402
|
+
return SOURCE_FILE_PATTERN.test(file) && !TEST_FILE_PATTERN.test(file);
|
|
1403
|
+
}).sort(TEXT_COLLATOR.compare);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/lib/api/source-lookup.ts
|
|
1407
|
+
function isSourcePath(path) {
|
|
1408
|
+
return path.includes(SOURCE_PATH_MARK);
|
|
1409
|
+
}
|
|
1410
|
+
function sourceRootOf(params) {
|
|
1411
|
+
const root = packageRootOf(params.cwd);
|
|
1412
|
+
if (root !== void 0) return { root };
|
|
1413
|
+
return {
|
|
1414
|
+
refusal: {
|
|
1415
|
+
output: textOf([
|
|
1416
|
+
NO_PACKAGE_TEXT.replace("{command}", params.command).replace("{cwd}", params.cwd),
|
|
1417
|
+
""
|
|
1418
|
+
]),
|
|
1419
|
+
exitCode: 2
|
|
1420
|
+
}
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
function searchedIndexesOf(params) {
|
|
1424
|
+
const { indexes } = params;
|
|
1425
|
+
const source = readSourceIndex(params);
|
|
1426
|
+
if (source === void 0) return { indexes, notes: [] };
|
|
1427
|
+
return {
|
|
1428
|
+
indexes: [...indexes, withoutIndexed({ source: source.index, indexes })],
|
|
1429
|
+
notes: source.notes
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
function showSource(params) {
|
|
1433
|
+
const source = readSourceIndex(params);
|
|
1434
|
+
const notes = source?.notes ?? [];
|
|
1435
|
+
const methods = findByPath({ indexes: source ? [source.index] : [], path: params.path });
|
|
1436
|
+
if (methods.length === 0 && !params.json)
|
|
1117
1437
|
return {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1438
|
+
output: textOf([
|
|
1439
|
+
unknownSourceText({
|
|
1440
|
+
path: params.path,
|
|
1441
|
+
root: params.root,
|
|
1442
|
+
methods: source?.index.methods ?? []
|
|
1443
|
+
}),
|
|
1444
|
+
...noteLinesOf(notes),
|
|
1445
|
+
""
|
|
1446
|
+
]),
|
|
1447
|
+
exitCode: 1
|
|
1448
|
+
};
|
|
1449
|
+
return {
|
|
1450
|
+
output: renderShown({ methods, json: params.json, notes }),
|
|
1451
|
+
exitCode: methods.length ? 0 : 1
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
function readSourceIndex(params) {
|
|
1455
|
+
const ownName = packageNameOf(params.root);
|
|
1456
|
+
if (params.packageName !== void 0 && params.packageName !== ownName) return void 0;
|
|
1457
|
+
const { entries, notes } = readSourceFunctions({ root: params.root });
|
|
1458
|
+
return { index: { package: ownName, methods: entries }, notes };
|
|
1459
|
+
}
|
|
1460
|
+
function withoutIndexed(params) {
|
|
1461
|
+
const { source } = params;
|
|
1462
|
+
const indexedAt = new Set(
|
|
1463
|
+
params.indexes.filter(function isSamePackage(index) {
|
|
1464
|
+
return index.package === source.package;
|
|
1465
|
+
}).flatMap(function declaredAtOfIndex(index) {
|
|
1466
|
+
return index.methods.flatMap(function declaredAtOfMethod(method) {
|
|
1467
|
+
return method.declaredAt === void 0 ? [] : [method.declaredAt];
|
|
1468
|
+
});
|
|
1469
|
+
})
|
|
1470
|
+
);
|
|
1471
|
+
return {
|
|
1472
|
+
package: source.package,
|
|
1473
|
+
methods: source.methods.filter(function isNotIndexed(method) {
|
|
1474
|
+
return method.declaredAt === void 0 || !indexedAt.has(method.declaredAt);
|
|
1475
|
+
})
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
function unknownSourceText(params) {
|
|
1479
|
+
const closest = closestSourcePaths(params);
|
|
1480
|
+
const text = closest.length ? UNKNOWN_SOURCE_CLOSEST_TEXT : UNKNOWN_SOURCE_TEXT;
|
|
1481
|
+
return text.replace("{path}", params.path).replace("{root}", params.root).replace("{closest}", closest.join(", "));
|
|
1482
|
+
}
|
|
1483
|
+
function closestSourcePaths(params) {
|
|
1484
|
+
const paths = params.methods.map(function pathOfMethod(method) {
|
|
1485
|
+
return method.path;
|
|
1486
|
+
});
|
|
1487
|
+
const mark = params.path.lastIndexOf(SOURCE_PATH_MARK);
|
|
1488
|
+
const filePrefix = params.path.slice(0, mark + SOURCE_PATH_MARK.length);
|
|
1489
|
+
const names = paths.filter(function isOfTheFile(path) {
|
|
1490
|
+
return path.startsWith(filePrefix);
|
|
1491
|
+
}).map(function nameOfPath(path) {
|
|
1492
|
+
return path.slice(filePrefix.length);
|
|
1493
|
+
});
|
|
1494
|
+
if (names.length === 0)
|
|
1495
|
+
return closestNames({ name: params.path, candidates: paths, limit: SOURCE_SUGGESTION_LIMIT });
|
|
1496
|
+
const close = closestNames({
|
|
1497
|
+
name: params.path.slice(filePrefix.length),
|
|
1498
|
+
candidates: names,
|
|
1499
|
+
limit: SOURCE_SUGGESTION_LIMIT
|
|
1500
|
+
});
|
|
1501
|
+
const others = names.filter(function isNotClose(name) {
|
|
1502
|
+
return !close.includes(name);
|
|
1503
|
+
});
|
|
1504
|
+
return [...close, ...others].slice(0, SOURCE_SUGGESTION_LIMIT).map(function pathOfName(name) {
|
|
1505
|
+
return `${filePrefix}${name}`;
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// src/lib/config.ts
|
|
1510
|
+
import { readFileSync as readFileSync11, existsSync as existsSync14, readdirSync as readdirSync9, statSync as statSync5 } from "fs";
|
|
1511
|
+
import { join as join19 } from "path";
|
|
1512
|
+
|
|
1513
|
+
// src/lib/config.constants.ts
|
|
1514
|
+
var CORE_PACKAGE = "@dialecte/core";
|
|
1515
|
+
var CORE_TEST_DIALECT = {
|
|
1516
|
+
version: "core",
|
|
1517
|
+
binding: {
|
|
1518
|
+
kind: "core",
|
|
1519
|
+
coreAlias: "Core",
|
|
1520
|
+
coreImport: "@/index",
|
|
1521
|
+
configType: "TestDialecteConfig",
|
|
1522
|
+
configImport: "@/test/config"
|
|
1523
|
+
},
|
|
1524
|
+
constantsDir: "./src/test/generated",
|
|
1525
|
+
outDir: "./benchmarks/types/generated"
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
// src/lib/config.ts
|
|
1529
|
+
function getArg(argv, name) {
|
|
1530
|
+
const index = argv.indexOf(`--${name}`);
|
|
1531
|
+
return index >= 0 ? argv[index + 1] : void 0;
|
|
1532
|
+
}
|
|
1533
|
+
function hasFlag(argv, name) {
|
|
1534
|
+
return argv.includes(`--${name}`);
|
|
1535
|
+
}
|
|
1536
|
+
function positionalArguments(params) {
|
|
1537
|
+
const words = [];
|
|
1538
|
+
for (let index = 0; index < params.argv.length; index++) {
|
|
1539
|
+
const argument = params.argv[index];
|
|
1540
|
+
if (!argument.startsWith("--")) words.push(argument);
|
|
1541
|
+
else if (params.valueOptions.includes(argument.slice(2))) index++;
|
|
1542
|
+
}
|
|
1543
|
+
return words;
|
|
1544
|
+
}
|
|
1545
|
+
function tsconfigOf(argv, cwd = process.cwd()) {
|
|
1546
|
+
return getArg(argv, "tsconfig") ?? pkgConfig(cwd).tsconfig ?? "tsconfig.build.json";
|
|
1547
|
+
}
|
|
1548
|
+
function readPkg(cwd) {
|
|
1549
|
+
const packageJson = join19(cwd, "package.json");
|
|
1550
|
+
return existsSync14(packageJson) ? JSON.parse(readFileSync11(packageJson, "utf8")) : {};
|
|
1551
|
+
}
|
|
1552
|
+
function pkgConfig(cwd) {
|
|
1553
|
+
return readPkg(cwd).dialecte ?? {};
|
|
1554
|
+
}
|
|
1555
|
+
function capitalize(word) {
|
|
1556
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
1557
|
+
}
|
|
1558
|
+
function discoverNamespace(cwd) {
|
|
1559
|
+
return capitalize(
|
|
1560
|
+
String(readPkg(cwd).name ?? "dialecte").split("/").pop() ?? "dialecte"
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
function discoverVersions(cwd) {
|
|
1564
|
+
const src = join19(cwd, "src");
|
|
1565
|
+
if (!existsSync14(src)) return [];
|
|
1566
|
+
return readdirSync9(src).filter((v) => statSync5(join19(src, v)).isDirectory()).filter(
|
|
1567
|
+
(v) => existsSync14(join19(src, v, "definition", "constants.generated.ts")) && existsSync14(join19(src, v, "definition", "definition.generated.ts"))
|
|
1568
|
+
).sort();
|
|
1569
|
+
}
|
|
1570
|
+
function resolveTargets(argv, cwd = process.cwd()) {
|
|
1571
|
+
if (readPkg(cwd).name === CORE_PACKAGE)
|
|
1572
|
+
return [
|
|
1573
|
+
{
|
|
1574
|
+
...CORE_TEST_DIALECT,
|
|
1575
|
+
version: getArg(argv, "version") ?? CORE_TEST_DIALECT.version,
|
|
1576
|
+
constantsDir: getArg(argv, "constants-dir") ?? CORE_TEST_DIALECT.constantsDir,
|
|
1577
|
+
outDir: getArg(argv, "out") ?? CORE_TEST_DIALECT.outDir
|
|
1578
|
+
}
|
|
1579
|
+
];
|
|
1580
|
+
const cfg = pkgConfig(cwd);
|
|
1581
|
+
const namespace = getArg(argv, "namespace") ?? cfg.namespace ?? discoverNamespace(cwd);
|
|
1582
|
+
const only = getArg(argv, "version");
|
|
1583
|
+
let versions = discoverVersions(cwd);
|
|
1584
|
+
if (only) versions = versions.filter((v) => v === only);
|
|
1585
|
+
if (!versions.length && (getArg(argv, "constants-dir") || getArg(argv, "entry")))
|
|
1586
|
+
versions = [only ?? "default"];
|
|
1587
|
+
return versions.map((version) => {
|
|
1588
|
+
const entry = getArg(argv, "entry") ?? cfg.entry ?? `@/${version}`;
|
|
1589
|
+
return {
|
|
1590
|
+
version,
|
|
1591
|
+
binding: { kind: "namespace", name: namespace, import: entry },
|
|
1592
|
+
constantsDir: getArg(argv, "constants-dir") ?? cfg.constantsDir ?? `./src/${version}/definition`,
|
|
1593
|
+
outDir: getArg(argv, "out") ?? cfg.out ?? `./benchmarks/types/${version}/generated`
|
|
1121
1594
|
};
|
|
1122
1595
|
});
|
|
1123
1596
|
}
|
|
1124
|
-
function declaredVersions(cwd) {
|
|
1125
|
-
const manifest = JSON.parse(readFileSync6(join10(cwd, "package.json"), "utf8"));
|
|
1126
|
-
const names = dependencyNames(cwd);
|
|
1127
|
-
return Object.fromEntries(
|
|
1128
|
-
names.map((name) => [
|
|
1129
|
-
name,
|
|
1130
|
-
String(
|
|
1131
|
-
manifest.dependencies?.[name] ?? manifest.devDependencies?.[name] ?? manifest.peerDependencies?.[name]
|
|
1132
|
-
)
|
|
1133
|
-
])
|
|
1134
|
-
);
|
|
1135
|
-
}
|
|
1136
|
-
function installedVersion(params) {
|
|
1137
|
-
const folder = findInstalledPackage(params);
|
|
1138
|
-
if (!folder || !existsSync9(join10(folder, "package.json"))) return void 0;
|
|
1139
|
-
const version = JSON.parse(readFileSync6(join10(folder, "package.json"), "utf8")).version;
|
|
1140
|
-
return typeof version === "string" ? version : void 0;
|
|
1141
|
-
}
|
|
1142
|
-
function packageName(folder) {
|
|
1143
|
-
const path = join10(folder, "package.json");
|
|
1144
|
-
if (!existsSync9(path)) return void 0;
|
|
1145
|
-
const name = JSON.parse(readFileSync6(path, "utf8")).name;
|
|
1146
|
-
return typeof name === "string" ? name : void 0;
|
|
1147
|
-
}
|
|
1148
|
-
function isDefined2(value) {
|
|
1149
|
-
return value !== void 0;
|
|
1150
|
-
}
|
|
1151
1597
|
|
|
1152
|
-
// src/lib/
|
|
1153
|
-
import { existsSync as
|
|
1154
|
-
import {
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
folder = parent;
|
|
1164
|
-
}
|
|
1165
|
-
const { version } = JSON.parse(readFileSync7(join11(folder, "package.json"), "utf8"));
|
|
1166
|
-
return version;
|
|
1598
|
+
// src/lib/missing-package.ts
|
|
1599
|
+
import { existsSync as existsSync15 } from "fs";
|
|
1600
|
+
import { join as join20 } from "path";
|
|
1601
|
+
function missingPackage(params) {
|
|
1602
|
+
return existsSync15(join20(params.cwd, "package.json")) ? void 0 : {
|
|
1603
|
+
output: textOf([
|
|
1604
|
+
`no package.json in ${params.cwd}: run dialecte in your package's folder`,
|
|
1605
|
+
""
|
|
1606
|
+
]),
|
|
1607
|
+
exitCode: 2
|
|
1608
|
+
};
|
|
1167
1609
|
}
|
|
1168
1610
|
|
|
1169
|
-
// src/commands/
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
);
|
|
1185
|
-
} catch {
|
|
1186
|
-
return { output: textOf([]), exitCode: 0 };
|
|
1611
|
+
// src/commands/api.constants.ts
|
|
1612
|
+
var API_SUBCOMMANDS = ["find", "show"];
|
|
1613
|
+
var API_VALUE_OPTIONS = ["package", "limit"];
|
|
1614
|
+
var DEFAULT_FIND_LIMIT = 5;
|
|
1615
|
+
var SOURCE_FLAG = "source";
|
|
1616
|
+
var API_USAGE = 'usage: dialecte api find "<need>" [--source] [--package <name>] [--limit 5] [--json] | dialecte api show <path> [--json] | dialecte api show <file>#<name> [--json]';
|
|
1617
|
+
|
|
1618
|
+
// src/commands/api.ts
|
|
1619
|
+
function runApi(params) {
|
|
1620
|
+
const [subcommand, ...rest] = params.argv;
|
|
1621
|
+
const words = positionalArguments({ argv: rest, valueOptions: API_VALUE_OPTIONS });
|
|
1622
|
+
const sourceFlag = hasFlag([...rest], SOURCE_FLAG);
|
|
1623
|
+
const reachesSource = sourceFlag || subcommand === "show" && isSourcePath(words[0] ?? "");
|
|
1624
|
+
if (!reachesSource) {
|
|
1625
|
+
const missing = missingPackage({ cwd: params.cwd });
|
|
1626
|
+
if (missing) return missing;
|
|
1187
1627
|
}
|
|
1628
|
+
const limit = Number(getArg([...rest], "limit") ?? DEFAULT_FIND_LIMIT);
|
|
1629
|
+
if (!isSubcommand(subcommand) || words.length === 0 || !Number.isInteger(limit) || limit < 1)
|
|
1630
|
+
return { output: textOf([API_USAGE, ""]), exitCode: 2 };
|
|
1631
|
+
const packageName2 = getArg([...rest], "package");
|
|
1632
|
+
const json = hasFlag([...rest], "json");
|
|
1633
|
+
const sourceRoot = reachesSource ? sourceRootOf({
|
|
1634
|
+
cwd: params.cwd,
|
|
1635
|
+
command: ["api", subcommand, ...sourceFlag ? [`--${SOURCE_FLAG}`] : []].join(" ")
|
|
1636
|
+
}) : { root: params.cwd };
|
|
1637
|
+
if ("refusal" in sourceRoot) return sourceRoot.refusal;
|
|
1638
|
+
const { root } = sourceRoot;
|
|
1639
|
+
if (reachesSource && subcommand === "show" && isSourcePath(words[0]))
|
|
1640
|
+
return showSource({ root, packageName: packageName2, path: words[0], json });
|
|
1641
|
+
const installed = readApiIndexes({ cwd: root }).filter(
|
|
1642
|
+
(index) => packageName2 === void 0 || index.package === packageName2
|
|
1643
|
+
);
|
|
1644
|
+
const { indexes, notes } = reachesSource ? searchedIndexesOf({ root, packageName: packageName2, indexes: installed }) : { indexes: installed, notes: void 0 };
|
|
1645
|
+
return subcommand === "find" ? find({ indexes, need: words.join(" "), limit, json, notes }) : show({ indexes, path: words[0], json, notes });
|
|
1188
1646
|
}
|
|
1189
|
-
function
|
|
1190
|
-
return
|
|
1647
|
+
function isSubcommand(value) {
|
|
1648
|
+
return API_SUBCOMMANDS.some((subcommand) => subcommand === value);
|
|
1191
1649
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1650
|
+
function find(params) {
|
|
1651
|
+
const found = findMethods(params);
|
|
1652
|
+
if (found.length === 0 && !params.json)
|
|
1653
|
+
return {
|
|
1654
|
+
output: textOf([
|
|
1655
|
+
`no method found for "${params.need}" in ${packagesText(params.indexes)}: try other words, or \`npx @dialecte/cli members <expression>\` for the live types`,
|
|
1656
|
+
...noteLinesOf(params.notes),
|
|
1657
|
+
""
|
|
1658
|
+
]),
|
|
1659
|
+
exitCode: 1
|
|
1660
|
+
};
|
|
1661
|
+
return {
|
|
1662
|
+
output: renderFound({ need: params.need, found, json: params.json, notes: params.notes }),
|
|
1663
|
+
exitCode: found.length ? 0 : 1
|
|
1664
|
+
};
|
|
1203
1665
|
}
|
|
1204
|
-
function
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1666
|
+
function show(params) {
|
|
1667
|
+
const methods = findByPath(params);
|
|
1668
|
+
if (methods.length === 0 && !params.json)
|
|
1669
|
+
return {
|
|
1670
|
+
output: textOf([
|
|
1671
|
+
`no method "${params.path}" in ${packagesText(params.indexes)}: \`npx @dialecte/cli api find "<what you need>"\` lists the routes`,
|
|
1672
|
+
...noteLinesOf(params.notes),
|
|
1673
|
+
""
|
|
1674
|
+
]),
|
|
1675
|
+
exitCode: 1
|
|
1676
|
+
};
|
|
1677
|
+
return {
|
|
1678
|
+
output: renderShown({ methods, json: params.json, notes: params.notes }),
|
|
1679
|
+
exitCode: methods.length ? 0 : 1
|
|
1680
|
+
};
|
|
1218
1681
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
function listMembers(params) {
|
|
1222
|
-
const path = discoveryPath(params.expression);
|
|
1223
|
-
const exact = params.entries.find((entry) => entry.path === path);
|
|
1224
|
-
if (exact) return [methodMember({ entry: exact, name: lastSegment(path) })];
|
|
1225
|
-
const methods = [];
|
|
1226
|
-
const methodCountByGroup = /* @__PURE__ */ new Map();
|
|
1227
|
-
for (const entry of params.entries) {
|
|
1228
|
-
if (!entry.path.startsWith(`${path}.`)) continue;
|
|
1229
|
-
const [name, ...below] = entry.path.slice(path.length + 1).split(".");
|
|
1230
|
-
if (below.length === 0) methods.push(methodMember({ entry, name }));
|
|
1231
|
-
else methodCountByGroup.set(name, (methodCountByGroup.get(name) ?? 0) + 1);
|
|
1232
|
-
}
|
|
1233
|
-
const groups = [...methodCountByGroup].map(([name, methodCount]) => ({
|
|
1234
|
-
kind: "group",
|
|
1235
|
-
name,
|
|
1236
|
-
methodCount
|
|
1237
|
-
}));
|
|
1238
|
-
return [...methods.sort(byName), ...groups.sort(byName)];
|
|
1682
|
+
function packagesText(indexes) {
|
|
1683
|
+
return indexes.length ? [...new Set(indexes.map((index) => index.package))].join(", ") : "no installed package (none ships skills/<name>/references/api.json)";
|
|
1239
1684
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1685
|
+
|
|
1686
|
+
// src/lib/doctor/answer-doctor.ts
|
|
1687
|
+
function answerDoctor(params) {
|
|
1688
|
+
const exitCode = params.lines.some((line) => line.status !== "ok") ? 1 : 0;
|
|
1689
|
+
if (params.json) return { output: endedOf(jsonOf({ lines: params.lines }, " ")), exitCode };
|
|
1690
|
+
return { output: endedTextOf2(params.lines.map(renderLine)), exitCode };
|
|
1242
1691
|
}
|
|
1243
|
-
function
|
|
1692
|
+
function answerDoctorBrief(lines) {
|
|
1244
1693
|
return {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
summary: params.entry.summary,
|
|
1248
|
-
intents: params.entry.intents
|
|
1694
|
+
output: endedTextOf2(lines.filter((line) => line.status !== "ok").map(renderLine)),
|
|
1695
|
+
exitCode: 0
|
|
1249
1696
|
};
|
|
1250
1697
|
}
|
|
1251
|
-
function
|
|
1252
|
-
return
|
|
1698
|
+
function endedTextOf2(lines) {
|
|
1699
|
+
return textOf(lines.length === 0 ? [] : [...lines, ""]);
|
|
1253
1700
|
}
|
|
1254
|
-
function
|
|
1255
|
-
|
|
1701
|
+
function renderLine(line) {
|
|
1702
|
+
if (line.status === "ok") return `\u2705 ${line.subject} ${line.detail}`;
|
|
1703
|
+
const fix = line.fix ? ` - fix: ${line.fix}` : "";
|
|
1704
|
+
return line.status === "error" ? `\u274C ${line.subject} ${line.detail}${fix}` : `\u26A0\uFE0F ${line.subject} ${line.detail}${fix}`;
|
|
1256
1705
|
}
|
|
1257
1706
|
|
|
1258
|
-
// src/lib/
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
limit: MEMBER_SUGGESTION_LIMIT
|
|
1275
|
-
});
|
|
1276
|
-
const hint = parent ? ` - under ${parent}: ${(closest.length ? closest : neighbours).join(", ") || "nothing"}` : "";
|
|
1277
|
-
return { output: textOf([`nothing at ${expression}${hint}`, ""]), exitCode: 1 };
|
|
1278
|
-
}
|
|
1279
|
-
function memberLine(member) {
|
|
1280
|
-
if (member.kind === "group")
|
|
1281
|
-
return ` ${member.name}. ${member.methodCount} method${member.methodCount === 1 ? "" : "s"}`;
|
|
1282
|
-
return member.summary ? ` ${member.name}() ${shortSummary(member.summary)}` : ` ${member.name}()`;
|
|
1707
|
+
// src/lib/doctor/diagnose.ts
|
|
1708
|
+
import { existsSync as existsSync19, lstatSync as lstatSync5, readdirSync as readdirSync10, readFileSync as readFileSync13 } from "fs";
|
|
1709
|
+
import { dirname as dirname11, join as join24, resolve as resolve5 } from "path";
|
|
1710
|
+
|
|
1711
|
+
// src/lib/profile/profile.constants.ts
|
|
1712
|
+
var PROFILES = ["contributor", "consumer"];
|
|
1713
|
+
var DEFAULT_PROFILE = "consumer";
|
|
1714
|
+
var INVALID_PROFILE = "dialecte.profile: {value} is not a profile; profiles: contributor, consumer";
|
|
1715
|
+
|
|
1716
|
+
// src/lib/profile/profile.ts
|
|
1717
|
+
function readProfile(root) {
|
|
1718
|
+
const declared = readPackageJson(root).dialecte?.profile;
|
|
1719
|
+
if (declared === void 0) return DEFAULT_PROFILE;
|
|
1720
|
+
const profile = PROFILES.find((known) => known === declared);
|
|
1721
|
+
if (!profile) throw new Error(INVALID_PROFILE.replace("{value}", JSON.stringify(declared)));
|
|
1722
|
+
return profile;
|
|
1283
1723
|
}
|
|
1284
1724
|
|
|
1285
|
-
// src/lib/
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1725
|
+
// src/lib/doctor/doctor.constants.ts
|
|
1726
|
+
var DIALECTE_SCOPE = "@dialecte/";
|
|
1727
|
+
var CORE_PACKAGE2 = "@dialecte/core";
|
|
1728
|
+
var SYNC_COMMAND = "npx @dialecte/cli skills sync";
|
|
1729
|
+
var INSTALL_COMMAND = "npm install";
|
|
1730
|
+
var ALIGN_CORE_FIX = "align @dialecte/core with the version the dialecte pins (or upgrade the dialecte), then npm install";
|
|
1731
|
+
var CORE_API_GENERATIONS = [
|
|
1732
|
+
{
|
|
1733
|
+
from: [0, 7],
|
|
1734
|
+
name: "0.7",
|
|
1735
|
+
says: "import inside the store (project.importFile answers { documentId, diagnostics }), per-file IO hook session, createTestHelpers"
|
|
1736
|
+
},
|
|
1737
|
+
{
|
|
1738
|
+
from: [0, 0],
|
|
1739
|
+
name: "0.6",
|
|
1740
|
+
says: "import and IO hooks before the store owned them: read the skills of this version, not the latest docs"
|
|
1741
|
+
}
|
|
1742
|
+
];
|
|
1743
|
+
var CHECKOUT_LIST_LIMIT = 8;
|
|
1744
|
+
var STATION_AGENTS_SUBJECT = "station agents";
|
|
1745
|
+
var PROFILE_SUBJECT = "profile";
|
|
1746
|
+
var CONSUMER_ALLOWS_REFERENCES = "allowReferences is the consumer default: remove it";
|
|
1747
|
+
var CONTRIBUTOR_GATE_STEPS = "dialecte.gate.full holds {steps}: dialecte contrib runs them, move them to dialecte.contrib.steps (or drop them for the defaults)";
|
|
1748
|
+
var CONTRIBUTOR_SKILLS_NOT_SYNCED = "{folder} lacks the contributor skills: dialecte skills sync installs them in a contributor";
|
|
1749
|
+
|
|
1750
|
+
// src/lib/doctor/profile-lines.ts
|
|
1751
|
+
import { existsSync as existsSync16 } from "fs";
|
|
1752
|
+
import { join as join21 } from "path";
|
|
1753
|
+
|
|
1754
|
+
// src/lib/contrib/contrib.constants.ts
|
|
1755
|
+
var DEFAULT_CONTRIB_STEPS = [
|
|
1756
|
+
{ name: "docs", run: "npm run doc:build", restoresGeneratedDocs: true },
|
|
1757
|
+
{ name: "type-bench", run: "npm run type-bench:check" }
|
|
1758
|
+
];
|
|
1759
|
+
|
|
1760
|
+
// src/lib/doctor/profile-lines.ts
|
|
1761
|
+
function profileLines(cwd) {
|
|
1762
|
+
let profile;
|
|
1763
|
+
try {
|
|
1764
|
+
profile = readProfile(cwd);
|
|
1765
|
+
} catch (error) {
|
|
1766
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1767
|
+
return [{ status: "error", subject: PROFILE_SUBJECT, detail }];
|
|
1768
|
+
}
|
|
1769
|
+
const dialecte = readPackageJson(cwd).dialecte;
|
|
1770
|
+
if (profile === "consumer") {
|
|
1771
|
+
const declared = dialecte?.profile === void 0 ? "consumer (default)" : "consumer";
|
|
1772
|
+
return [
|
|
1773
|
+
{ status: "ok", subject: PROFILE_SUBJECT, detail: declared },
|
|
1774
|
+
...dialecte?.allowReferences === void 0 ? [] : [
|
|
1775
|
+
{
|
|
1776
|
+
status: "warning",
|
|
1777
|
+
subject: PROFILE_SUBJECT,
|
|
1778
|
+
detail: CONSUMER_ALLOWS_REFERENCES
|
|
1779
|
+
}
|
|
1780
|
+
]
|
|
1781
|
+
];
|
|
1782
|
+
}
|
|
1783
|
+
const full = Array.isArray(dialecte?.gate?.full) ? dialecte.gate.full : [];
|
|
1784
|
+
const contributorSteps = DEFAULT_CONTRIB_STEPS.map((step) => step.name);
|
|
1785
|
+
const moved = full.map((step) => step.name).filter((name) => contributorSteps.includes(name));
|
|
1786
|
+
const unsynced = Object.values(AGENT_SKILL_FOLDERS).filter(
|
|
1787
|
+
(folder) => existsSync16(join21(cwd, folder, MANIFEST_FILE)) && readSyncManifest(join21(cwd, folder)).contributing !== true
|
|
1788
|
+
);
|
|
1789
|
+
return [
|
|
1790
|
+
{ status: "ok", subject: PROFILE_SUBJECT, detail: "contributor" },
|
|
1791
|
+
...moved.length ? [
|
|
1792
|
+
{
|
|
1793
|
+
status: "warning",
|
|
1794
|
+
subject: PROFILE_SUBJECT,
|
|
1795
|
+
detail: CONTRIBUTOR_GATE_STEPS.replace("{steps}", moved.join(", "))
|
|
1796
|
+
}
|
|
1797
|
+
] : [],
|
|
1798
|
+
...unsynced.map((folder) => ({
|
|
1799
|
+
status: "warning",
|
|
1800
|
+
subject: PROFILE_SUBJECT,
|
|
1801
|
+
detail: CONTRIBUTOR_SKILLS_NOT_SYNCED.replace("{folder}", folder)
|
|
1802
|
+
}))
|
|
1803
|
+
];
|
|
1289
1804
|
}
|
|
1290
1805
|
|
|
1291
|
-
// src/lib/
|
|
1292
|
-
import { existsSync as
|
|
1293
|
-
import {
|
|
1294
|
-
import { join as join12 } from "path";
|
|
1295
|
-
import { pathToFileURL } from "url";
|
|
1806
|
+
// src/lib/doctor/station-agent-lines.ts
|
|
1807
|
+
import { existsSync as existsSync18, readFileSync as readFileSync12 } from "fs";
|
|
1808
|
+
import { join as join23 } from "path";
|
|
1296
1809
|
|
|
1297
|
-
// src/lib/
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
var CORE_READER_NAMES = [
|
|
1301
|
-
"resolveDefinition",
|
|
1302
|
-
"getAttributeRules",
|
|
1303
|
-
"enumeratedValues",
|
|
1304
|
-
"valuePatterns",
|
|
1305
|
-
"admittedXsiTypes",
|
|
1306
|
-
"childOccurrences",
|
|
1307
|
-
"orderByConfigSequence"
|
|
1308
|
-
];
|
|
1309
|
-
var SUGGESTION_LIMIT = 5;
|
|
1810
|
+
// src/lib/models/remembered-vendor.ts
|
|
1811
|
+
import { existsSync as existsSync17, statSync as statSync6 } from "fs";
|
|
1812
|
+
import { join as join22 } from "path";
|
|
1310
1813
|
|
|
1311
|
-
// src/lib/
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1814
|
+
// src/lib/models/model-tiers.constants.ts
|
|
1815
|
+
var VENDOR_IDS = ["anthropic", "openai", "google"];
|
|
1816
|
+
var TIER_NAMES = ["fast", "standard", "strong", "frontier"];
|
|
1817
|
+
var TIER_DEFINITIONS = {
|
|
1818
|
+
fast: 'search and locate, graders with a schema, log and diff summaries, format and shape checks, "does file X say Y"',
|
|
1819
|
+
standard: "implementer on a mechanical or well-specified lot, fix mode on wording and rename findings, skill-eval runs, independent readers of a standard",
|
|
1820
|
+
strong: "the orchestrator, an implementer on a design-heavy lot, the review (one agent, both passes), adjudicating a disagreement, the retro",
|
|
1821
|
+
frontier: "rare: a plan challenge, a cross-repo architecture decision, a stuck lot after the 3-round cap"
|
|
1822
|
+
};
|
|
1823
|
+
var MODEL_TIERS = {
|
|
1824
|
+
checkedAt: "2026-10-28",
|
|
1825
|
+
vendors: {
|
|
1826
|
+
anthropic: {
|
|
1827
|
+
tiers: {
|
|
1828
|
+
fast: { model: "Haiku 5.5" },
|
|
1829
|
+
standard: { model: "Sonnet 5.5" },
|
|
1830
|
+
strong: { model: "Opus 5.5" },
|
|
1831
|
+
frontier: { model: "Fable 5.1" }
|
|
1832
|
+
}
|
|
1833
|
+
},
|
|
1834
|
+
openai: {
|
|
1835
|
+
tiers: {
|
|
1836
|
+
fast: { model: "Luna" },
|
|
1837
|
+
standard: { model: "Sol" },
|
|
1838
|
+
strong: { model: "Sol", effort: "high" },
|
|
1839
|
+
frontier: { model: "Astra" }
|
|
1840
|
+
}
|
|
1841
|
+
},
|
|
1842
|
+
google: {
|
|
1843
|
+
note: "frontier: check Google's own model page for the current flagship (4 Argon, if generally available)",
|
|
1844
|
+
tiers: {
|
|
1845
|
+
fast: { model: "Flash-Lite" },
|
|
1846
|
+
standard: { model: "Flash" },
|
|
1847
|
+
strong: { model: "Pro" },
|
|
1848
|
+
frontier: { model: "the current flagship" }
|
|
1849
|
+
}
|
|
1331
1850
|
}
|
|
1332
1851
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1852
|
+
};
|
|
1853
|
+
|
|
1854
|
+
// src/lib/models/vendor-id.ts
|
|
1855
|
+
function isVendorId(value) {
|
|
1856
|
+
return VENDOR_IDS.includes(value);
|
|
1335
1857
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
if (config) break;
|
|
1343
|
-
}
|
|
1344
|
-
if (!config) return void 0;
|
|
1345
|
-
const readersFile = createRequire(join12(params.folder, "package.json")).resolve(CORE_READERS_ENTRY);
|
|
1346
|
-
const readers = await import(pathToFileURL(readersFile).href);
|
|
1347
|
-
if (!isCoreReaders(readers))
|
|
1348
|
-
throw new Error(
|
|
1349
|
-
`its core (${readersFile}) lacks ${CORE_READER_NAMES.filter((name) => typeof readers[name] !== "function").join(", ")}: update @dialecte/core`
|
|
1350
|
-
);
|
|
1351
|
-
return { packageName: params.packageName, config, readers, standard };
|
|
1858
|
+
|
|
1859
|
+
// src/lib/models/remembered-vendor.ts
|
|
1860
|
+
function listManifestFolders(cwd) {
|
|
1861
|
+
return Object.values(AGENT_SKILL_FOLDERS).filter(
|
|
1862
|
+
(folder) => existsSync17(join22(cwd, folder, MANIFEST_FILE))
|
|
1863
|
+
);
|
|
1352
1864
|
}
|
|
1353
|
-
function
|
|
1354
|
-
const
|
|
1355
|
-
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1865
|
+
function readRememberedVendor(cwd) {
|
|
1866
|
+
const warnings = [];
|
|
1867
|
+
const entries = [];
|
|
1868
|
+
for (const folder of listManifestFolders(cwd)) {
|
|
1869
|
+
const { vendor } = readSyncManifest(join22(cwd, folder));
|
|
1870
|
+
if (vendor === void 0) continue;
|
|
1871
|
+
if (!isVendorId(vendor)) {
|
|
1872
|
+
warnings.push(`${folder}/${MANIFEST_FILE}: unknown vendor "${vendor}" ignored`);
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
entries.push({
|
|
1876
|
+
folder,
|
|
1877
|
+
vendor,
|
|
1878
|
+
writtenAt: statSync6(join22(cwd, folder, MANIFEST_FILE)).mtimeMs
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
entries.sort((first, second) => second.writtenAt - first.writtenAt);
|
|
1882
|
+
if (new Set(entries.map((entry) => entry.vendor)).size > 1)
|
|
1883
|
+
warnings.push(
|
|
1884
|
+
`manifests disagree on the vendor (${entries.map((entry) => `${entry.folder}: ${entry.vendor}`).join(", ")}): using the most recent, ${entries[0].vendor}`
|
|
1360
1885
|
);
|
|
1361
|
-
return
|
|
1362
|
-
}
|
|
1363
|
-
function readManifest(folder) {
|
|
1364
|
-
const path = join12(folder, "package.json");
|
|
1365
|
-
return existsSync11(path) ? JSON.parse(readFileSync8(path, "utf8")) : void 0;
|
|
1366
|
-
}
|
|
1367
|
-
function isBuiltOnCore(manifest) {
|
|
1368
|
-
return manifest.name !== CORE_PACKAGE3 && (manifest.dependencies?.[CORE_PACKAGE3] !== void 0 || manifest.peerDependencies?.[CORE_PACKAGE3] !== void 0);
|
|
1369
|
-
}
|
|
1370
|
-
function entryFiles(params) {
|
|
1371
|
-
const { exports, main } = params.manifest;
|
|
1372
|
-
const targets = exports === void 0 ? main ? [[".", main]] : [] : typeof exports === "string" ? [[".", exports]] : Object.entries(exports);
|
|
1373
|
-
return targets.filter(([subpath]) => !subpath.split("/").includes("test") && !subpath.includes("*")).flatMap(([, target]) => {
|
|
1374
|
-
const file = fileOf(target);
|
|
1375
|
-
return file && file.endsWith("js") ? [join12(params.folder, file)] : [];
|
|
1376
|
-
}).map(function existingFile(file) {
|
|
1377
|
-
if (!existsSync11(file))
|
|
1378
|
-
throw new Error(`entry file not found: ${file} (is the package built?)`);
|
|
1379
|
-
return file;
|
|
1380
|
-
});
|
|
1381
|
-
}
|
|
1382
|
-
function fileOf(target) {
|
|
1383
|
-
if (typeof target === "string") return target;
|
|
1384
|
-
const file = target.import ?? target.node ?? target.default;
|
|
1385
|
-
return typeof file === "string" ? file : void 0;
|
|
1386
|
-
}
|
|
1387
|
-
function isDialecteConfig(value) {
|
|
1388
|
-
return typeof value === "object" && value !== null && "rootElementName" in value && typeof value.rootElementName === "string" && "definition" in value && typeof value.definition === "object";
|
|
1389
|
-
}
|
|
1390
|
-
function isCoreReaders(module) {
|
|
1391
|
-
return CORE_READER_NAMES.every((name) => typeof module[name] === "function");
|
|
1886
|
+
return { vendor: entries[0]?.vendor, warnings };
|
|
1392
1887
|
}
|
|
1393
1888
|
|
|
1394
|
-
// src/lib/
|
|
1395
|
-
var
|
|
1396
|
-
var
|
|
1397
|
-
var
|
|
1889
|
+
// src/lib/stations/station-agents.constants.ts
|
|
1890
|
+
var STATION_AGENT_PREFIX = "dialecte-";
|
|
1891
|
+
var CLAUDE_AGENTS_FOLDER = ".claude/agents";
|
|
1892
|
+
var CLAUDE_MODEL_ALIASES = ["haiku", "sonnet", "opus", "fable"];
|
|
1893
|
+
var READ_TOOLS = ["Read", "Glob", "Grep", "Skill"];
|
|
1894
|
+
var REVIEW_TOOLS = ["Read", "Glob", "Grep", "Bash", "Skill"];
|
|
1895
|
+
var EDIT_TOOLS = ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "Skill"];
|
|
1896
|
+
var CLAUDE_TOOLS_BY_ACCESS = {
|
|
1897
|
+
read: READ_TOOLS,
|
|
1898
|
+
review: REVIEW_TOOLS,
|
|
1899
|
+
edit: EDIT_TOOLS
|
|
1900
|
+
};
|
|
1901
|
+
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.";
|
|
1902
|
+
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.";
|
|
1903
|
+
var GENERATED_NOTE = "Generated by `npx @dialecte/cli skills sync` from `dialecte models`; the next sync overwrites it.";
|
|
1904
|
+
var STATIONS = [
|
|
1905
|
+
{
|
|
1906
|
+
name: "test-writer",
|
|
1907
|
+
tier: "standard",
|
|
1908
|
+
access: "edit",
|
|
1909
|
+
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."
|
|
1910
|
+
},
|
|
1911
|
+
{
|
|
1912
|
+
name: "test-reviewer",
|
|
1913
|
+
tier: "strong",
|
|
1914
|
+
access: "review",
|
|
1915
|
+
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."
|
|
1916
|
+
},
|
|
1917
|
+
{
|
|
1918
|
+
name: "implementer",
|
|
1919
|
+
tier: "standard",
|
|
1920
|
+
access: "edit",
|
|
1921
|
+
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."
|
|
1922
|
+
},
|
|
1923
|
+
{
|
|
1924
|
+
name: "implementer-strong",
|
|
1925
|
+
tier: "strong",
|
|
1926
|
+
access: "edit",
|
|
1927
|
+
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."
|
|
1928
|
+
},
|
|
1929
|
+
{
|
|
1930
|
+
name: "reviewer",
|
|
1931
|
+
tier: "strong",
|
|
1932
|
+
access: "review",
|
|
1933
|
+
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."
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
name: "fixer",
|
|
1937
|
+
tier: "standard",
|
|
1938
|
+
access: "edit",
|
|
1939
|
+
description: "Dialecte lot, Station 4 (fix mode) on wording and naming findings: fixed, disagreed or escalated per finding. Give it the findings."
|
|
1940
|
+
},
|
|
1941
|
+
{
|
|
1942
|
+
name: "eval-runner",
|
|
1943
|
+
tier: "standard",
|
|
1944
|
+
access: "edit",
|
|
1945
|
+
description: "Runs one skill-eval case of a Dialecte skill, with or without the skill, and leaves the outputs the graders read."
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
name: "grader",
|
|
1949
|
+
tier: "strong",
|
|
1950
|
+
access: "read",
|
|
1951
|
+
description: "Grades the output of a skill-eval run against one grader file, pass or fail with the evidence. Read-only."
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
name: "standard-reader",
|
|
1955
|
+
tier: "standard",
|
|
1956
|
+
access: "read",
|
|
1957
|
+
description: "Independent reader of the IEC standard markdown for one question, with line references. Read-only."
|
|
1958
|
+
},
|
|
1959
|
+
{
|
|
1960
|
+
name: "searcher",
|
|
1961
|
+
tier: "fast",
|
|
1962
|
+
access: "read",
|
|
1963
|
+
description: "Finds where something lives in a Dialecte repository (files, symbols, API paths) and answers with paths and line numbers. Read-only."
|
|
1964
|
+
}
|
|
1965
|
+
];
|
|
1966
|
+
var LOT_SKILL = "dialecte-lot";
|
|
1967
|
+
var STATIONS_PAGE_PATH = `${AGENT_SKILL_FOLDERS.claude}/${LOT_SKILL}/references/stations.md`;
|
|
1968
|
+
var BRIEF_DEFINED_STATIONS = ["eval-runner", "grader"];
|
|
1398
1969
|
|
|
1399
|
-
// src/lib/
|
|
1400
|
-
function
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
const manifest = folder ? readManifest(folder) : void 0;
|
|
1404
|
-
if (!manifest?.name || !isBuiltOnCore(manifest)) return [];
|
|
1405
|
-
const packageName2 = manifest.name;
|
|
1406
|
-
return versionsOf(manifest).map((version) => ({
|
|
1407
|
-
packageName: packageName2,
|
|
1408
|
-
version,
|
|
1409
|
-
binding: {
|
|
1410
|
-
kind: "namespace",
|
|
1411
|
-
name: namespaceOf(packageName2),
|
|
1412
|
-
import: `${packageName2}/${version}`
|
|
1413
|
-
}
|
|
1414
|
-
}));
|
|
1415
|
-
});
|
|
1970
|
+
// src/lib/stations/render-station-agent.ts
|
|
1971
|
+
function claudeModelAlias(modelName) {
|
|
1972
|
+
const alias = modelName.split(" ")[0].toLowerCase();
|
|
1973
|
+
return CLAUDE_MODEL_ALIASES.includes(alias) ? alias : void 0;
|
|
1416
1974
|
}
|
|
1417
|
-
function
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1975
|
+
function stationLines(params) {
|
|
1976
|
+
const { station } = params;
|
|
1977
|
+
const play = `You play the \`${station.name}\` station of \`${LOT_SKILL}\`:`;
|
|
1978
|
+
if (BRIEF_DEFINED_STATIONS.includes(station.name))
|
|
1979
|
+
return [
|
|
1980
|
+
`${play} your brief carries your definition and names the only skill text you read; read no other.`,
|
|
1981
|
+
""
|
|
1982
|
+
];
|
|
1983
|
+
return [
|
|
1984
|
+
`${play} its definition is ${STATIONS_PAGE_PATH}, section \`${station.name}\`.`,
|
|
1985
|
+
"",
|
|
1986
|
+
LOAD_SKILLS_LINE,
|
|
1987
|
+
""
|
|
1988
|
+
];
|
|
1420
1989
|
}
|
|
1421
|
-
function
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1990
|
+
function renderStationAgent(params) {
|
|
1991
|
+
const { station, model } = params;
|
|
1992
|
+
return [
|
|
1993
|
+
"---",
|
|
1994
|
+
`name: ${STATION_AGENT_PREFIX}${station.name}`,
|
|
1995
|
+
`description: ${JSON.stringify(station.description)}`,
|
|
1996
|
+
`tools: ${CLAUDE_TOOLS_BY_ACCESS[station.access].join(", ")}`,
|
|
1997
|
+
`model: ${model}`,
|
|
1998
|
+
"---",
|
|
1999
|
+
`<!-- ${GENERATED_NOTE} -->`,
|
|
2000
|
+
"",
|
|
2001
|
+
...stationLines({ station }),
|
|
2002
|
+
NEVER_LINE,
|
|
2003
|
+
""
|
|
2004
|
+
].join("\n");
|
|
2005
|
+
}
|
|
2006
|
+
function planStationAgents(params) {
|
|
2007
|
+
const { vendor } = params;
|
|
2008
|
+
if (vendor === void 0)
|
|
1433
2009
|
return {
|
|
1434
|
-
kind: "
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
2010
|
+
kind: "skipped",
|
|
2011
|
+
reason: "no model vendor known for this project, so no Claude Code station agents: run `skills sync --vendor anthropic`"
|
|
2012
|
+
};
|
|
2013
|
+
if (vendor !== "anthropic")
|
|
2014
|
+
return {
|
|
2015
|
+
kind: "skipped",
|
|
2016
|
+
reason: `no Claude Code station agents: the project's vendor is ${vendor}, whose tiers are named by \`dialecte models\``
|
|
1440
2017
|
};
|
|
2018
|
+
const tiers = MODEL_TIERS.vendors[vendor].tiers;
|
|
2019
|
+
const files = [];
|
|
2020
|
+
for (const station of STATIONS) {
|
|
2021
|
+
const modelName = tiers[station.tier].model;
|
|
2022
|
+
const model = claudeModelAlias(modelName);
|
|
2023
|
+
if (model === void 0)
|
|
2024
|
+
return {
|
|
2025
|
+
kind: "skipped",
|
|
2026
|
+
reason: `no Claude Code station agents: "${modelName}" (${station.tier}) is not a model name Claude Code accepts`
|
|
2027
|
+
};
|
|
2028
|
+
files.push({
|
|
2029
|
+
name: `${STATION_AGENT_PREFIX}${station.name}.md`,
|
|
2030
|
+
content: renderStationAgent({ station, model })
|
|
2031
|
+
});
|
|
1441
2032
|
}
|
|
1442
|
-
return {
|
|
1443
|
-
kind: "output",
|
|
1444
|
-
message: textOf([
|
|
1445
|
-
"several dialectes are installed: pass --package <name> [--version <v>]",
|
|
1446
|
-
...listLines(matching),
|
|
1447
|
-
""
|
|
1448
|
-
])
|
|
1449
|
-
};
|
|
1450
|
-
}
|
|
1451
|
-
function listLines(bindings) {
|
|
1452
|
-
return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}`);
|
|
2033
|
+
return { kind: "files", files };
|
|
1453
2034
|
}
|
|
1454
2035
|
|
|
1455
|
-
// src/lib/
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
let text = "";
|
|
1471
|
-
let link;
|
|
1472
|
-
for (const part of parts ?? []) {
|
|
1473
|
-
if (part.kind === "link" && part.text.startsWith("{@link"))
|
|
1474
|
-
link = { name: void 0, label: "" };
|
|
1475
|
-
else if (link && part.kind === "linkName") link.name = part.text;
|
|
1476
|
-
else if (link && part.kind === "linkText") link.label += part.text;
|
|
1477
|
-
else if (link && part.kind === "link") {
|
|
1478
|
-
text += renderLink(link);
|
|
1479
|
-
link = void 0;
|
|
1480
|
-
} else text += part.text;
|
|
2036
|
+
// src/lib/doctor/station-agent-lines.ts
|
|
2037
|
+
function stationAgentLines(cwd) {
|
|
2038
|
+
const manifestFolder = join23(cwd, AGENT_SKILL_FOLDERS.claude);
|
|
2039
|
+
if (!existsSync18(join23(manifestFolder, MANIFEST_FILE))) return [];
|
|
2040
|
+
const listed = readSyncManifest(manifestFolder).stationAgents ?? [];
|
|
2041
|
+
if (listed.length === 0) return [];
|
|
2042
|
+
const plan = planStationAgents({ vendor: readRememberedVendor(cwd).vendor });
|
|
2043
|
+
if (plan.kind !== "files") return [];
|
|
2044
|
+
const missing = [];
|
|
2045
|
+
const stale = [];
|
|
2046
|
+
for (const file of plan.files) {
|
|
2047
|
+
const path = join23(cwd, CLAUDE_AGENTS_FOLDER, file.name);
|
|
2048
|
+
if (!existsSync18(path)) missing.push(file.name);
|
|
2049
|
+
else if (listed.includes(file.name) && readFileSync12(path, "utf8") !== file.content)
|
|
2050
|
+
stale.push(file.name);
|
|
1481
2051
|
}
|
|
1482
|
-
|
|
2052
|
+
if (missing.length === 0 && stale.length === 0)
|
|
2053
|
+
return [{ status: "ok", subject: STATION_AGENTS_SUBJECT, detail: `${CLAUDE_AGENTS_FOLDER} in sync` }];
|
|
2054
|
+
const parts = [
|
|
2055
|
+
...stale.length ? [`holds stale ${stale.join(", ")}`] : [],
|
|
2056
|
+
...missing.length ? [`lacks ${missing.join(", ")}`] : []
|
|
2057
|
+
];
|
|
2058
|
+
return [
|
|
2059
|
+
{
|
|
2060
|
+
status: "warning",
|
|
2061
|
+
subject: STATION_AGENTS_SUBJECT,
|
|
2062
|
+
detail: `${CLAUDE_AGENTS_FOLDER} ${parts.join("; ")}`,
|
|
2063
|
+
fix: SYNC_COMMAND
|
|
2064
|
+
}
|
|
2065
|
+
];
|
|
1483
2066
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
return
|
|
2067
|
+
|
|
2068
|
+
// src/lib/doctor/diagnose.ts
|
|
2069
|
+
function diagnose(context) {
|
|
2070
|
+
return [
|
|
2071
|
+
{ status: "ok", subject: "dialecte", detail: `cli ${context.cliVersion} running` },
|
|
2072
|
+
...installedPackages(context.cwd),
|
|
2073
|
+
...profileLines(context.cwd),
|
|
2074
|
+
...coreGenerations(context.cwd),
|
|
2075
|
+
...skills(context.cwd),
|
|
2076
|
+
...stationAgentLines(context.cwd),
|
|
2077
|
+
...context.brief ? [] : localCheckouts(context)
|
|
2078
|
+
];
|
|
2079
|
+
}
|
|
2080
|
+
function installedPackages(cwd) {
|
|
2081
|
+
const declared = declaredVersions(cwd);
|
|
2082
|
+
return Object.keys(declared).filter((name) => name.startsWith(DIALECTE_SCOPE)).sort(TEXT_COLLATOR.compare).map(function packageLine(name) {
|
|
2083
|
+
const version = installedVersion({ cwd, name });
|
|
2084
|
+
if (version === void 0)
|
|
2085
|
+
return { status: "warning", subject: name, detail: "not installed", fix: INSTALL_COMMAND };
|
|
2086
|
+
const pinned = declared[name];
|
|
2087
|
+
if (/^\d/.test(pinned) && pinned !== version)
|
|
2088
|
+
return {
|
|
2089
|
+
status: "warning",
|
|
2090
|
+
subject: name,
|
|
2091
|
+
detail: `${version} installed, ${pinned} declared`,
|
|
2092
|
+
fix: INSTALL_COMMAND
|
|
2093
|
+
};
|
|
2094
|
+
return { status: "ok", subject: name, detail: version };
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
function coreGenerations(cwd) {
|
|
2098
|
+
const dialectes = dependencyNames(cwd).sort(TEXT_COLLATOR.compare).flatMap(function dialecteOnCore(name) {
|
|
2099
|
+
const folder = findInstalledPackage({ cwd, name });
|
|
2100
|
+
return folder && dependsOnCore(folder) ? [{ name, folder }] : [];
|
|
2101
|
+
});
|
|
2102
|
+
const appCore = installedVersion({ cwd, name: CORE_PACKAGE2 });
|
|
2103
|
+
const owners = dialectes.length ? dialectes : [{ name: void 0, folder: cwd }];
|
|
2104
|
+
return owners.flatMap(function generationLine({ name, folder }) {
|
|
2105
|
+
const version = installedVersion({ cwd: folder, name: CORE_PACKAGE2 });
|
|
2106
|
+
if (version === void 0) return [];
|
|
2107
|
+
const [major = 0, minor = 0] = version.split(".").map(Number);
|
|
2108
|
+
const generation = CORE_API_GENERATIONS.find(
|
|
2109
|
+
({ from }) => major > from[0] || major === from[0] && minor >= from[1]
|
|
2110
|
+
);
|
|
2111
|
+
if (!generation) return [];
|
|
2112
|
+
const says = `${generation.name}: ${generation.says}`;
|
|
2113
|
+
if (name && appCore !== void 0 && appCore !== version)
|
|
2114
|
+
return [
|
|
2115
|
+
{
|
|
2116
|
+
status: "warning",
|
|
2117
|
+
subject: "core API",
|
|
2118
|
+
detail: `${name} on core ${version}, your app on core ${appCore}: two cores side by side (${says})`,
|
|
2119
|
+
fix: ALIGN_CORE_FIX
|
|
2120
|
+
}
|
|
2121
|
+
];
|
|
2122
|
+
const owner = name ? `${name} on core ${version}` : `core ${version}`;
|
|
2123
|
+
return [{ status: "ok", subject: "core API", detail: `${owner} - ${says}` }];
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
function skills(cwd) {
|
|
2127
|
+
const { sources } = discoverSkillSources({ cwd });
|
|
2128
|
+
if (sources.length === 0)
|
|
2129
|
+
return [{ status: "ok", subject: "skills", detail: "no dependency ships skills" }];
|
|
2130
|
+
const synced = Object.values(AGENT_SKILL_FOLDERS).filter(
|
|
2131
|
+
(folder) => existsSync19(join24(cwd, folder, MANIFEST_FILE))
|
|
2132
|
+
);
|
|
2133
|
+
if (synced.length === 0)
|
|
2134
|
+
return [
|
|
2135
|
+
{
|
|
2136
|
+
status: "warning",
|
|
2137
|
+
subject: "skills",
|
|
2138
|
+
detail: `not installed for your agents (${sources.map((source) => source.name).join(", ")} shipped)`,
|
|
2139
|
+
fix: SYNC_COMMAND
|
|
2140
|
+
}
|
|
2141
|
+
];
|
|
2142
|
+
const contributor = isContributor(cwd);
|
|
2143
|
+
return synced.map(function syncLine(folder) {
|
|
2144
|
+
const manifest = readSyncManifest(join24(cwd, folder));
|
|
2145
|
+
const expected = selectAudience({
|
|
2146
|
+
sources,
|
|
2147
|
+
contributing: contributor || manifest.contributing === true
|
|
2148
|
+
}).selected;
|
|
2149
|
+
const missing = expected.map((source) => source.name).filter((name) => !manifest.installed.includes(name));
|
|
2150
|
+
if (missing.length)
|
|
2151
|
+
return {
|
|
2152
|
+
status: "warning",
|
|
2153
|
+
subject: "skills",
|
|
2154
|
+
detail: `${folder} lacks ${missing.join(", ")}`,
|
|
2155
|
+
fix: SYNC_COMMAND
|
|
2156
|
+
};
|
|
2157
|
+
const stale = expected.flatMap(function staleCopy(source) {
|
|
2158
|
+
const recorded = manifest.versions[source.name];
|
|
2159
|
+
if (isLink(join24(cwd, folder, source.name)) || source.version === void 0) return [];
|
|
2160
|
+
if (recorded?.version === source.version) return [];
|
|
2161
|
+
return [
|
|
2162
|
+
`${source.name} of ${source.origin} ${recorded?.version ?? "an unknown version"}, ${source.version} installed`
|
|
2163
|
+
];
|
|
2164
|
+
});
|
|
2165
|
+
if (stale.length)
|
|
2166
|
+
return {
|
|
2167
|
+
status: "warning",
|
|
2168
|
+
subject: "skills",
|
|
2169
|
+
detail: `${folder} holds ${stale.join("; ")}`,
|
|
2170
|
+
fix: SYNC_COMMAND
|
|
2171
|
+
};
|
|
2172
|
+
return { status: "ok", subject: "skills", detail: `${folder} in sync with node_modules` };
|
|
2173
|
+
});
|
|
1488
2174
|
}
|
|
1489
|
-
|
|
1490
|
-
// src/lib/discover.ts
|
|
1491
|
-
import ts2 from "typescript";
|
|
1492
|
-
function discoverMethods(params) {
|
|
1493
|
-
const { entrySource, tsconfig, root, maxDepth = 1 } = params;
|
|
1494
|
-
const entryPath = join13(root, ENTRY_FOLDER, `discover-entry-${process.pid}.ts`);
|
|
1495
|
-
mkdirSync2(dirname5(entryPath), { recursive: true });
|
|
1496
|
-
writeFileSync2(entryPath, entrySource);
|
|
2175
|
+
function isContributor(cwd) {
|
|
1497
2176
|
try {
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
root
|
|
1502
|
-
);
|
|
1503
|
-
const program = ts2.createProgram([entryPath], {
|
|
1504
|
-
...parsed.options,
|
|
1505
|
-
noEmit: true,
|
|
1506
|
-
rootDir: root
|
|
1507
|
-
});
|
|
1508
|
-
const checker = program.getTypeChecker();
|
|
1509
|
-
const sourceFile = program.getSourceFile(entryPath);
|
|
1510
|
-
if (!sourceFile) return [];
|
|
1511
|
-
const exportsByName = new Map(
|
|
1512
|
-
checker.getExportsOfModule(checker.getSymbolAtLocation(sourceFile)).map((symbol) => [symbol.getName(), symbol])
|
|
1513
|
-
);
|
|
1514
|
-
const entries = [];
|
|
1515
|
-
for (const rootName of ROOTS) {
|
|
1516
|
-
const symbol = exportsByName.get(rootName);
|
|
1517
|
-
if (symbol)
|
|
1518
|
-
walkMembers({
|
|
1519
|
-
checker,
|
|
1520
|
-
sourceFile,
|
|
1521
|
-
type: checker.getTypeOfSymbolAtLocation(symbol, sourceFile),
|
|
1522
|
-
path: rootName,
|
|
1523
|
-
depth: 0,
|
|
1524
|
-
maxDepth,
|
|
1525
|
-
root,
|
|
1526
|
-
entries
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
return entries;
|
|
1530
|
-
} finally {
|
|
1531
|
-
rmSync2(entryPath, { force: true });
|
|
2177
|
+
return readProfile(cwd) === "contributor";
|
|
2178
|
+
} catch {
|
|
2179
|
+
return false;
|
|
1532
2180
|
}
|
|
1533
2181
|
}
|
|
1534
|
-
function
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
property,
|
|
1540
|
-
declarationOf(property) ?? sourceFile
|
|
1541
|
-
);
|
|
1542
|
-
const propertyPath = `${path}.${property.getName()}`;
|
|
1543
|
-
if (propertyType.getCallSignatures().length > 0) {
|
|
1544
|
-
const { documentation, declaringSymbol } = documentationOf({
|
|
1545
|
-
checker,
|
|
1546
|
-
symbol: property,
|
|
1547
|
-
root: params.root
|
|
1548
|
-
});
|
|
1549
|
-
params.entries.push({
|
|
1550
|
-
path: propertyPath,
|
|
1551
|
-
signature: signatureOf({ checker, boundType: propertyType, declaringSymbol }),
|
|
1552
|
-
...documentation
|
|
1553
|
-
});
|
|
1554
|
-
} else if (depth < maxDepth && !(propertyType.flags & PRIMITIVE_LIKE) && propertyType.getProperties().some(
|
|
1555
|
-
(member) => isPublic(member) && !isTypeScriptLibrary(member) && checker.getTypeOfSymbolAtLocation(member, declarationOf(member) ?? sourceFile).getCallSignatures().length > 0
|
|
1556
|
-
))
|
|
1557
|
-
walkMembers({ ...params, type: propertyType, path: propertyPath, depth: depth + 1 });
|
|
2182
|
+
function isLink(path) {
|
|
2183
|
+
try {
|
|
2184
|
+
return lstatSync5(path).isSymbolicLink();
|
|
2185
|
+
} catch {
|
|
2186
|
+
return false;
|
|
1558
2187
|
}
|
|
1559
2188
|
}
|
|
1560
|
-
function
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1563
|
-
const declarations = callableDeclarations(params.declaringSymbol);
|
|
1564
|
-
if (declarations.length === 0)
|
|
1565
|
-
return boundSignatures.map(
|
|
1566
|
-
(signature) => checker.signatureToString(signature, void 0, SIGNATURE_FORMAT, ts2.SignatureKind.Call)
|
|
1567
|
-
).join("\n");
|
|
1568
|
-
const boundParameterCount = Math.max(
|
|
1569
|
-
...boundSignatures.map((signature) => parameterCount({ checker, signature }))
|
|
1570
|
-
);
|
|
1571
|
-
return declarations.map((declaration) => declaredSignatureText({ checker, declaration, boundParameterCount })).join("\n");
|
|
2189
|
+
function dependsOnCore(folder) {
|
|
2190
|
+
const manifest = JSON.parse(readFileSync13(join24(folder, "package.json"), "utf8"));
|
|
2191
|
+
return manifest.name !== CORE_PACKAGE2 && (manifest.dependencies?.[CORE_PACKAGE2] !== void 0 || manifest.peerDependencies?.[CORE_PACKAGE2] !== void 0);
|
|
1572
2192
|
}
|
|
1573
|
-
function
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
2193
|
+
function localCheckouts(context) {
|
|
2194
|
+
const roots = [
|
|
2195
|
+
...new Set([context.dialecteRoot, dirname11(resolve5(context.cwd))].filter(isDefined2))
|
|
2196
|
+
];
|
|
2197
|
+
return roots.map(function checkoutLine(root) {
|
|
2198
|
+
const names = existsSync19(root) ? readdirSync10(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && join24(root, entry.name) !== resolve5(context.cwd)).filter((entry) => packageName(join24(root, entry.name))?.startsWith(DIALECTE_SCOPE)).map((entry) => entry.name).sort(TEXT_COLLATOR.compare) : [];
|
|
2199
|
+
return {
|
|
2200
|
+
status: "ok",
|
|
2201
|
+
subject: "checkouts",
|
|
2202
|
+
detail: names.length ? `${root}: ${names.slice(0, CHECKOUT_LIST_LIMIT).join(", ")}${names.length > CHECKOUT_LIST_LIMIT ? ` and ${names.length - CHECKOUT_LIST_LIMIT} more` : ""}` : `none in ${root} (the installed packages are the source)`
|
|
2203
|
+
};
|
|
2204
|
+
});
|
|
1580
2205
|
}
|
|
1581
|
-
function
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
2206
|
+
function declaredVersions(cwd) {
|
|
2207
|
+
const manifest = JSON.parse(readFileSync13(join24(cwd, "package.json"), "utf8"));
|
|
2208
|
+
const names = dependencyNames(cwd);
|
|
2209
|
+
return Object.fromEntries(
|
|
2210
|
+
names.map((name) => [
|
|
2211
|
+
name,
|
|
2212
|
+
String(
|
|
2213
|
+
manifest.dependencies?.[name] ?? manifest.devDependencies?.[name] ?? manifest.peerDependencies?.[name]
|
|
2214
|
+
)
|
|
2215
|
+
])
|
|
1590
2216
|
);
|
|
1591
|
-
const overloads = declarations.filter((declaration) => !hasBody(declaration));
|
|
1592
|
-
return overloads.length > 0 ? overloads : declarations;
|
|
1593
2217
|
}
|
|
1594
|
-
function
|
|
1595
|
-
|
|
2218
|
+
function installedVersion(params) {
|
|
2219
|
+
const folder = findInstalledPackage(params);
|
|
2220
|
+
if (!folder || !existsSync19(join24(folder, "package.json"))) return void 0;
|
|
2221
|
+
const version = JSON.parse(readFileSync13(join24(folder, "package.json"), "utf8")).version;
|
|
2222
|
+
return typeof version === "string" ? version : void 0;
|
|
1596
2223
|
}
|
|
1597
|
-
function
|
|
1598
|
-
const
|
|
1599
|
-
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
2224
|
+
function packageName(folder) {
|
|
2225
|
+
const path = join24(folder, "package.json");
|
|
2226
|
+
if (!existsSync19(path)) return void 0;
|
|
2227
|
+
const name = JSON.parse(readFileSync13(path, "utf8")).name;
|
|
2228
|
+
return typeof name === "string" ? name : void 0;
|
|
2229
|
+
}
|
|
2230
|
+
function isDefined2(value) {
|
|
2231
|
+
return value !== void 0;
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// src/commands/doctor.ts
|
|
2235
|
+
function runDoctor(params) {
|
|
2236
|
+
const { argv, cliVersion, ...rest } = params;
|
|
2237
|
+
if (hasFlag([...argv], "brief")) return runBrief({ ...rest, cliVersion });
|
|
2238
|
+
const missing = missingPackage({ cwd: params.cwd });
|
|
2239
|
+
if (missing) return missing;
|
|
2240
|
+
return answerDoctor({
|
|
2241
|
+
lines: diagnose({ ...rest, cliVersion: resolveVersion(cliVersion) }),
|
|
2242
|
+
json: hasFlag([...argv], "json")
|
|
1609
2243
|
});
|
|
1610
|
-
const returnType = declaration.type ? printed({ node: declaration.type, sourceFile }) : signature ? checker.typeToString(signature.getReturnType(), declaration, SIGNATURE_FORMAT) : "unknown";
|
|
1611
|
-
return `${typeParameters}(${parameterTexts.join(", ")}) => ${returnType}`;
|
|
1612
2244
|
}
|
|
1613
|
-
function
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
2245
|
+
function runBrief(context) {
|
|
2246
|
+
try {
|
|
2247
|
+
return answerDoctorBrief(
|
|
2248
|
+
diagnose({ ...context, cliVersion: resolveVersion(context.cliVersion), brief: true })
|
|
2249
|
+
);
|
|
2250
|
+
} catch {
|
|
2251
|
+
return { output: textOf([]), exitCode: 0 };
|
|
2252
|
+
}
|
|
1619
2253
|
}
|
|
1620
|
-
function
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
const tags2 = symbol.getJsDocTags(checker);
|
|
1637
|
-
return {
|
|
1638
|
-
documentation: {
|
|
1639
|
-
summary: firstParagraph(comment),
|
|
1640
|
-
intents: intentsOf(tags2),
|
|
1641
|
-
example: exampleOf(tags2),
|
|
1642
|
-
definedInPackage: isDeclaredInPackage({ symbol, root: params.root }),
|
|
1643
|
-
internal: tags2.some((tag) => tag.name === "internal"),
|
|
1644
|
-
declaredAt: declarationKey({ symbol, root: params.root })
|
|
1645
|
-
},
|
|
1646
|
-
declaringSymbol: symbol
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
for (const declaration of symbol.declarations ?? []) {
|
|
1650
|
-
if (ts2.isShorthandPropertyAssignment(declaration))
|
|
1651
|
-
queue.push(checker.getShorthandAssignmentValueSymbol(declaration));
|
|
1652
|
-
else if (ts2.isPropertyAssignment(declaration))
|
|
1653
|
-
queue.push(assignedSymbol({ checker, initializer: declaration.initializer }));
|
|
1654
|
-
else if (ts2.isExportSpecifier(declaration))
|
|
1655
|
-
queue.push(checker.getExportSpecifierLocalTargetSymbol(declaration));
|
|
1656
|
-
}
|
|
2254
|
+
function resolveVersion(cliVersion) {
|
|
2255
|
+
return typeof cliVersion === "string" ? cliVersion : cliVersion();
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
// src/lib/api/list-members.ts
|
|
2259
|
+
function listMembers(params) {
|
|
2260
|
+
const path = discoveryPath(params.expression);
|
|
2261
|
+
const exact = params.entries.find((entry) => entry.path === path);
|
|
2262
|
+
if (exact) return [methodMember({ entry: exact, name: lastSegment(path) })];
|
|
2263
|
+
const methods = [];
|
|
2264
|
+
const methodCountByGroup = /* @__PURE__ */ new Map();
|
|
2265
|
+
for (const entry of params.entries) {
|
|
2266
|
+
if (!entry.path.startsWith(`${path}.`)) continue;
|
|
2267
|
+
const [name, ...below] = entry.path.slice(path.length + 1).split(".");
|
|
2268
|
+
if (below.length === 0) methods.push(methodMember({ entry, name }));
|
|
2269
|
+
else methodCountByGroup.set(name, (methodCountByGroup.get(name) ?? 0) + 1);
|
|
1657
2270
|
}
|
|
1658
|
-
const
|
|
1659
|
-
|
|
2271
|
+
const groups = [...methodCountByGroup].map(([name, methodCount]) => ({
|
|
2272
|
+
kind: "group",
|
|
2273
|
+
name,
|
|
2274
|
+
methodCount
|
|
2275
|
+
}));
|
|
2276
|
+
return [...methods.sort(byName), ...groups.sort(byName)];
|
|
2277
|
+
}
|
|
2278
|
+
function discoveryPath(expression) {
|
|
2279
|
+
return expression.replace(/^(doc\.query|query)(?=\.|$)/, "q");
|
|
2280
|
+
}
|
|
2281
|
+
function methodMember(params) {
|
|
1660
2282
|
return {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
internal: tags.some((tag) => tag.name === "internal"),
|
|
1666
|
-
definedInPackage: isDeclaredInPackage({ symbol: declaringFunction, root: params.root }),
|
|
1667
|
-
declaredAt: declarationKey({ symbol: declaringFunction, root: params.root })
|
|
1668
|
-
},
|
|
1669
|
-
declaringSymbol: declaringFunction
|
|
2283
|
+
kind: "method",
|
|
2284
|
+
name: params.name,
|
|
2285
|
+
summary: params.entry.summary,
|
|
2286
|
+
intents: params.entry.intents
|
|
1670
2287
|
};
|
|
1671
2288
|
}
|
|
1672
|
-
function
|
|
1673
|
-
return
|
|
2289
|
+
function lastSegment(path) {
|
|
2290
|
+
return path.slice(path.lastIndexOf(".") + 1);
|
|
1674
2291
|
}
|
|
1675
|
-
function
|
|
1676
|
-
return
|
|
2292
|
+
function byName(left, right) {
|
|
2293
|
+
return TEXT_COLLATOR.compare(left.name, right.name);
|
|
1677
2294
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
const
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
2295
|
+
|
|
2296
|
+
// src/lib/api/answer-members.ts
|
|
2297
|
+
function answerMembers(params) {
|
|
2298
|
+
const { expression } = params;
|
|
2299
|
+
const members = listMembers(params);
|
|
2300
|
+
if (params.json)
|
|
2301
|
+
return {
|
|
2302
|
+
output: endedOf(jsonOf({ expression, members }, " ")),
|
|
2303
|
+
exitCode: members.length ? 0 : 1
|
|
2304
|
+
};
|
|
2305
|
+
if (members.length)
|
|
2306
|
+
return { output: textOf([expression, ...members.map(memberLine), ""]), exitCode: 0 };
|
|
2307
|
+
const parent = expression.slice(0, Math.max(0, expression.lastIndexOf(".")));
|
|
2308
|
+
const neighbours = parent ? listMembers({ entries: params.entries, expression: parent }).map((member) => member.name) : [];
|
|
2309
|
+
const closest = closestNames({
|
|
2310
|
+
name: expression.slice(expression.lastIndexOf(".") + 1),
|
|
2311
|
+
candidates: neighbours,
|
|
2312
|
+
limit: MEMBER_SUGGESTION_LIMIT
|
|
2313
|
+
});
|
|
2314
|
+
const hint = parent ? ` - under ${parent}: ${(closest.length ? closest : neighbours).join(", ") || "nothing"}` : "";
|
|
2315
|
+
return { output: textOf([`nothing at ${expression}${hint}`, ""]), exitCode: 1 };
|
|
1685
2316
|
}
|
|
1686
|
-
function
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
2317
|
+
function memberLine(member) {
|
|
2318
|
+
if (member.kind === "group")
|
|
2319
|
+
return ` ${member.name}. ${member.methodCount} method${member.methodCount === 1 ? "" : "s"}`;
|
|
2320
|
+
return member.summary ? ` ${member.name}() ${shortSummary(member.summary)}` : ` ${member.name}()`;
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
// src/lib/namespace-of.ts
|
|
2324
|
+
function namespaceOf(packageName2) {
|
|
2325
|
+
const name = packageName2.split("/").pop() || "dialecte";
|
|
2326
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
// src/lib/schema/load-dialectes.ts
|
|
2330
|
+
import { existsSync as existsSync20, readFileSync as readFileSync14 } from "fs";
|
|
2331
|
+
import { createRequire } from "module";
|
|
2332
|
+
import { join as join25 } from "path";
|
|
2333
|
+
import { pathToFileURL } from "url";
|
|
2334
|
+
|
|
2335
|
+
// src/lib/schema/schema.constants.ts
|
|
2336
|
+
var CORE_PACKAGE3 = "@dialecte/core";
|
|
2337
|
+
var CORE_READERS_ENTRY = "@dialecte/core/utils";
|
|
2338
|
+
var CORE_READER_NAMES = [
|
|
2339
|
+
"resolveDefinition",
|
|
2340
|
+
"getAttributeRules",
|
|
2341
|
+
"enumeratedValues",
|
|
2342
|
+
"valuePatterns",
|
|
2343
|
+
"admittedXsiTypes",
|
|
2344
|
+
"childOccurrences",
|
|
2345
|
+
"orderByConfigSequence"
|
|
2346
|
+
];
|
|
2347
|
+
var SUGGESTION_LIMIT = 5;
|
|
2348
|
+
|
|
2349
|
+
// src/lib/schema/load-dialectes.ts
|
|
2350
|
+
async function loadDialectes(params) {
|
|
2351
|
+
const folders = [
|
|
2352
|
+
params.cwd,
|
|
2353
|
+
...dependencyNames(params.cwd).flatMap(
|
|
2354
|
+
(name) => findInstalledPackage({ cwd: params.cwd, name }) ?? []
|
|
2355
|
+
)
|
|
2356
|
+
];
|
|
2357
|
+
const result = { dialectes: [], skipped: [] };
|
|
2358
|
+
for (const folder of folders) {
|
|
2359
|
+
const manifest = readManifest(folder);
|
|
2360
|
+
if (!manifest?.name || !isBuiltOnCore(manifest)) continue;
|
|
2361
|
+
try {
|
|
2362
|
+
const loaded = await loadDialecte({ folder, manifest, packageName: manifest.name });
|
|
2363
|
+
if (loaded) result.dialectes.push(loaded);
|
|
2364
|
+
} catch (error) {
|
|
2365
|
+
result.skipped.push({
|
|
2366
|
+
packageName: manifest.name,
|
|
2367
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
1697
2370
|
}
|
|
1698
|
-
|
|
1699
|
-
return
|
|
2371
|
+
result.dialectes.sort((left, right) => TEXT_COLLATOR.compare(left.packageName, right.packageName));
|
|
2372
|
+
return result;
|
|
1700
2373
|
}
|
|
1701
|
-
function
|
|
1702
|
-
const
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
2374
|
+
async function loadDialecte(params) {
|
|
2375
|
+
const standard = readStandard(params.manifest);
|
|
2376
|
+
let config;
|
|
2377
|
+
for (const file of entryFiles(params)) {
|
|
2378
|
+
const exported = await import(pathToFileURL(file).href);
|
|
2379
|
+
config = Object.values(exported).find(isDialecteConfig);
|
|
2380
|
+
if (config) break;
|
|
2381
|
+
}
|
|
2382
|
+
if (!config) return void 0;
|
|
2383
|
+
const readersFile = createRequire(join25(params.folder, "package.json")).resolve(CORE_READERS_ENTRY);
|
|
2384
|
+
const readers = await import(pathToFileURL(readersFile).href);
|
|
2385
|
+
if (!isCoreReaders(readers))
|
|
2386
|
+
throw new Error(
|
|
2387
|
+
`its core (${readersFile}) lacks ${CORE_READER_NAMES.filter((name) => typeof readers[name] !== "function").join(", ")}: update @dialecte/core`
|
|
2388
|
+
);
|
|
2389
|
+
return { packageName: params.packageName, config, readers, standard };
|
|
1707
2390
|
}
|
|
1708
|
-
function
|
|
1709
|
-
|
|
2391
|
+
function readStandard(manifest) {
|
|
2392
|
+
const field = manifest.dialecte;
|
|
2393
|
+
if (typeof field !== "object" || field === null || !("standard" in field)) return void 0;
|
|
2394
|
+
const { standard } = field;
|
|
2395
|
+
if (typeof standard !== "string" || standard.trim() === "")
|
|
2396
|
+
throw new Error(
|
|
2397
|
+
`dialecte.standard must be a non-empty string, found ${JSON.stringify(standard) ?? String(standard)}`
|
|
2398
|
+
);
|
|
2399
|
+
return standard;
|
|
1710
2400
|
}
|
|
1711
|
-
function
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
return ts2.isArrowFunction(declaration.initializer) || ts2.isFunctionExpression(declaration.initializer);
|
|
2401
|
+
function readManifest(folder) {
|
|
2402
|
+
const path = join25(folder, "package.json");
|
|
2403
|
+
return existsSync20(path) ? JSON.parse(readFileSync14(path, "utf8")) : void 0;
|
|
1715
2404
|
}
|
|
1716
|
-
function
|
|
1717
|
-
|
|
1718
|
-
if (!declaration) return void 0;
|
|
1719
|
-
return `${relative3(params.root, declaration.getSourceFile().fileName)}:${declaration.getStart()}`;
|
|
2405
|
+
function isBuiltOnCore(manifest) {
|
|
2406
|
+
return manifest.name !== CORE_PACKAGE3 && (manifest.dependencies?.[CORE_PACKAGE3] !== void 0 || manifest.peerDependencies?.[CORE_PACKAGE3] !== void 0);
|
|
1720
2407
|
}
|
|
1721
|
-
function
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
2408
|
+
function entryFiles(params) {
|
|
2409
|
+
const { exports, main } = params.manifest;
|
|
2410
|
+
const targets = exports === void 0 ? main ? [[".", main]] : [] : typeof exports === "string" ? [[".", exports]] : Object.entries(exports);
|
|
2411
|
+
return targets.filter(([subpath]) => !subpath.split("/").includes("test") && !subpath.includes("*")).flatMap(([, target]) => {
|
|
2412
|
+
const file = fileOf(target);
|
|
2413
|
+
return file && file.endsWith("js") ? [join25(params.folder, file)] : [];
|
|
2414
|
+
}).map(function existingFile(file) {
|
|
2415
|
+
if (!existsSync20(file))
|
|
2416
|
+
throw new Error(`entry file not found: ${file} (is the package built?)`);
|
|
2417
|
+
return file;
|
|
2418
|
+
});
|
|
1726
2419
|
}
|
|
1727
|
-
function
|
|
1728
|
-
|
|
2420
|
+
function fileOf(target) {
|
|
2421
|
+
if (typeof target === "string") return target;
|
|
2422
|
+
const file = target.import ?? target.node ?? target.default;
|
|
2423
|
+
return typeof file === "string" ? file : void 0;
|
|
1729
2424
|
}
|
|
1730
|
-
function
|
|
1731
|
-
|
|
1732
|
-
return !declaration || !(ts2.getCombinedModifierFlags(declaration) & (ts2.ModifierFlags.Private | ts2.ModifierFlags.Protected));
|
|
2425
|
+
function isDialecteConfig(value) {
|
|
2426
|
+
return typeof value === "object" && value !== null && "rootElementName" in value && typeof value.rootElementName === "string" && "definition" in value && typeof value.definition === "object";
|
|
1733
2427
|
}
|
|
1734
|
-
function
|
|
1735
|
-
return (
|
|
1736
|
-
|
|
2428
|
+
function isCoreReaders(module) {
|
|
2429
|
+
return CORE_READER_NAMES.every((name) => typeof module[name] === "function");
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
// src/lib/api/installed-bindings.constants.ts
|
|
2433
|
+
var VERSION_SUBPATH_PATTERN = /^\.\/[^/*]+$/;
|
|
2434
|
+
var TEST_ENTRY = "test";
|
|
2435
|
+
var NO_DIALECTE_INSTALLED = "no dialecte installed here (a dependency built on @dialecte/core exporting ./<version> with ./<version>/test): pass --namespace <Name> --entry <module>";
|
|
2436
|
+
|
|
2437
|
+
// src/lib/api/installed-bindings.ts
|
|
2438
|
+
function findInstalledBindings(params) {
|
|
2439
|
+
return dependencyNames(params.cwd).flatMap(function bindingsOf(name) {
|
|
2440
|
+
const folder = findInstalledPackage({ cwd: params.cwd, name });
|
|
2441
|
+
const manifest = folder ? readManifest(folder) : void 0;
|
|
2442
|
+
if (!manifest?.name || !isBuiltOnCore(manifest)) return [];
|
|
2443
|
+
const packageName2 = manifest.name;
|
|
2444
|
+
return versionsOf(manifest).map((version) => ({
|
|
2445
|
+
packageName: packageName2,
|
|
2446
|
+
version,
|
|
2447
|
+
binding: {
|
|
2448
|
+
kind: "namespace",
|
|
2449
|
+
name: namespaceOf(packageName2),
|
|
2450
|
+
import: `${packageName2}/${version}`
|
|
2451
|
+
}
|
|
2452
|
+
}));
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
function versionsOf(manifest) {
|
|
2456
|
+
const subpaths = typeof manifest.exports === "object" ? Object.keys(manifest.exports) : [];
|
|
2457
|
+
return subpaths.filter((subpath) => VERSION_SUBPATH_PATTERN.test(subpath)).filter((subpath) => subpaths.includes(`${subpath}/${TEST_ENTRY}`)).map((subpath) => subpath.slice(2));
|
|
2458
|
+
}
|
|
2459
|
+
function chooseInstalledBinding(params) {
|
|
2460
|
+
if (params.bindings.length === 0)
|
|
2461
|
+
return { kind: "output", message: textOf([NO_DIALECTE_INSTALLED, ""]) };
|
|
2462
|
+
const matching = params.bindings.filter(
|
|
2463
|
+
(binding) => (params.packageName === void 0 || binding.packageName === params.packageName) && (params.version === void 0 || binding.version === params.version)
|
|
1737
2464
|
);
|
|
2465
|
+
if (matching.length === 1) return { kind: "binding", binding: matching[0] };
|
|
2466
|
+
if (matching.length === 0) {
|
|
2467
|
+
const named = [
|
|
2468
|
+
...params.packageName === void 0 ? [] : [`--package ${params.packageName}`],
|
|
2469
|
+
...params.version === void 0 ? [] : [`--version ${params.version}`]
|
|
2470
|
+
].join(" ");
|
|
2471
|
+
return {
|
|
2472
|
+
kind: "output",
|
|
2473
|
+
message: textOf([
|
|
2474
|
+
`no installed dialecte matches ${named}; installed:`,
|
|
2475
|
+
...listLines(params.bindings),
|
|
2476
|
+
""
|
|
2477
|
+
])
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
return {
|
|
2481
|
+
kind: "output",
|
|
2482
|
+
message: textOf([
|
|
2483
|
+
"several dialectes are installed: pass --package <name> [--version <v>]",
|
|
2484
|
+
...listLines(matching),
|
|
2485
|
+
""
|
|
2486
|
+
])
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
function listLines(bindings) {
|
|
2490
|
+
return bindings.map((binding) => ` ${binding.packageName} --version ${binding.version}`);
|
|
1738
2491
|
}
|
|
1739
2492
|
|
|
1740
2493
|
// src/lib/binding-refs.ts
|