@ctxo/cli 0.13.1 → 0.15.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.
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DOCUMENT_SEARCH_CONFIG,
4
+ SearchEngine,
5
+ buildGraphFromIndices
6
+ } from "./chunk-IT426P3F.js";
7
+ import {
8
+ SimpleGitAdapter,
9
+ SymbolTokenizer,
10
+ TEST_FRAMEWORK_ANNOTATIONS,
11
+ createTestFileClassifier,
12
+ filesWithTestAnnotations,
13
+ hasCSharpAnnotations,
14
+ indexTestPatterns,
15
+ loadConfig,
16
+ makeGlobMatcher,
17
+ resolveCoChangeConfig,
18
+ selectWindow,
19
+ windowCutoff
20
+ } from "./chunk-I7RPXT6L.js";
21
+ import {
22
+ getVersion,
23
+ locateGitRoot
24
+ } from "./chunk-72CEQEQD.js";
25
+ import {
26
+ JsonIndexReader
27
+ } from "./chunk-EC6INGPV.js";
28
+ import {
29
+ createLogger
30
+ } from "./chunk-5DSKZJNN.js";
31
+
32
+ // src/cli/module-host.ts
33
+ import { join } from "path";
34
+ import { DATA_RESOURCE_KINDS } from "@ctxo/plugin-api";
35
+ var log = createLogger("ctxo:module-host");
36
+ async function readCoChangeWindow(projectRoot, config) {
37
+ try {
38
+ const coChange = resolveCoChangeConfig(config);
39
+ const changeLog = await new SimpleGitAdapter(projectRoot).getChangeLog(coChange.maxCommits);
40
+ if (changeLog === void 0) return void 0;
41
+ return {
42
+ head: changeLog.head,
43
+ headCommittedAt: changeLog.headCommittedAt,
44
+ commits: selectWindow(changeLog.commits, coChange.maxCommits, windowCutoff(coChange, changeLog.headCommittedAt))
45
+ };
46
+ } catch (err) {
47
+ log.warn(`Co-change window unavailable: ${err.message}`);
48
+ return void 0;
49
+ }
50
+ }
51
+ var HOST_SERVICES = Object.freeze({
52
+ createLogger,
53
+ loadConfig,
54
+ // The CLI matcher takes a mutable array; the module API hands out readonly ones.
55
+ makeGlobMatcher: (patterns) => makeGlobMatcher([...patterns]),
56
+ // Decided exactly as the contexts view decides it (index-contexts-view.ts), so both agree on every file.
57
+ createTestFileCheck: (config, indices) => createTestFileClassifier(indexTestPatterns(config), filesWithTestAnnotations(indices), {
58
+ annotationAware: hasCSharpAnnotations(indices)
59
+ }),
60
+ createGit: (projectRoot) => new SimpleGitAdapter(projectRoot),
61
+ readIndex: (ctxoRoot) => new JsonIndexReader(ctxoRoot).readAll(),
62
+ buildGraph: buildGraphFromIndices,
63
+ readCoChangeWindow,
64
+ findGitRoot: (dir) => locateGitRoot(dir) ?? void 0,
65
+ testFrameworkAnnotations: TEST_FRAMEWORK_ANNOTATIONS,
66
+ dataResourceKinds: DATA_RESOURCE_KINDS,
67
+ createDocumentSearch: (documents) => {
68
+ const engine = new SearchEngine(DOCUMENT_SEARCH_CONFIG);
69
+ engine.buildDocumentIndex(documents);
70
+ return { search: (query, limit) => engine.search(query, limit) };
71
+ },
72
+ splitIdentifier: (name) => SymbolTokenizer.splitName(name)
73
+ });
74
+ function createModuleHost(options) {
75
+ return {
76
+ cliVersion: options.cliVersion ?? getVersion(),
77
+ mode: options.mode,
78
+ projectRoot: options.projectRoot,
79
+ ctxoRoot: join(options.projectRoot, ".ctxo"),
80
+ services: HOST_SERVICES
81
+ };
82
+ }
83
+
84
+ export {
85
+ createModuleHost
86
+ };
87
+ //# sourceMappingURL=chunk-JDL6GGTO.js.map
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ resolvePackageCandidates
4
+ } from "./chunk-2Q76LH2H.js";
5
+ import {
6
+ createLogger
7
+ } from "./chunk-5DSKZJNN.js";
8
+
9
+ // src/adapters/modules/module-loader.ts
10
+ var log = createLogger("ctxo:modules");
11
+ var DOMAIN_MODULE_PACKAGE = "@ctxo/domain";
12
+ function sameMinor(a, b) {
13
+ const pa = /^(\d+)\.(\d+)/.exec(a);
14
+ const pb = /^(\d+)\.(\d+)/.exec(b);
15
+ if (!pa || !pb) return false;
16
+ return Number(pa[1]) === Number(pb[1]) && Number(pa[2]) === Number(pb[2]);
17
+ }
18
+ var memo = /* @__PURE__ */ new Map();
19
+ async function loadCandidate(candidate, host) {
20
+ const base = { name: DOMAIN_MODULE_PACKAGE, version: candidate.version, source: candidate.source };
21
+ const failed = (reason) => {
22
+ log.warn(`${DOMAIN_MODULE_PACKAGE} failed to load: ${reason}; domain features are off.`);
23
+ return { kind: "stop", report: { ...base, status: "load-failed", reason } };
24
+ };
25
+ try {
26
+ const mod = await import(candidate.entryUrl);
27
+ if (typeof mod.register !== "function") return failed("missing register export");
28
+ const registration = await mod.register(host);
29
+ if (registration === void 0) {
30
+ return { kind: "stop", report: { ...base, status: "inactive" } };
31
+ }
32
+ if (registration === null || typeof registration !== "object" || registration.id !== "domain") {
33
+ return failed("register returned a registration with an unexpected id");
34
+ }
35
+ return {
36
+ kind: "active",
37
+ loaded: { name: DOMAIN_MODULE_PACKAGE, version: candidate.version, registration },
38
+ report: { ...base, status: "active" }
39
+ };
40
+ } catch (err) {
41
+ return failed(err.message);
42
+ }
43
+ }
44
+ async function resolveModules(host, cliAnchor) {
45
+ const candidates = resolvePackageCandidates(DOMAIN_MODULE_PACKAGE, host.projectRoot, cliAnchor);
46
+ if (candidates.length === 0) {
47
+ return { modules: [], reports: [{ name: DOMAIN_MODULE_PACKAGE, status: "not-installed" }] };
48
+ }
49
+ let firstMismatch;
50
+ for (const candidate of candidates) {
51
+ if (!sameMinor(candidate.version, host.cliVersion)) {
52
+ firstMismatch ??= candidate;
53
+ continue;
54
+ }
55
+ const outcome = await loadCandidate(candidate, host);
56
+ if (outcome.kind === "active") {
57
+ return { modules: [outcome.loaded], reports: [outcome.report] };
58
+ }
59
+ return { modules: [], reports: [outcome.report] };
60
+ }
61
+ const mismatch = firstMismatch;
62
+ log.warn(
63
+ `${DOMAIN_MODULE_PACKAGE} ${mismatch.version} does not match @ctxo/cli ${host.cliVersion}; domain features are off. Install ${DOMAIN_MODULE_PACKAGE}@${host.cliVersion} next to the CLI you run.`
64
+ );
65
+ return {
66
+ modules: [],
67
+ reports: [
68
+ {
69
+ name: DOMAIN_MODULE_PACKAGE,
70
+ status: "version-mismatch",
71
+ version: mismatch.version,
72
+ source: mismatch.source,
73
+ reason: `cli ${host.cliVersion}`
74
+ }
75
+ ]
76
+ };
77
+ }
78
+ function loadCtxoModules(host, options = {}) {
79
+ const key = `${host.projectRoot}|${host.mode}|${options.cliAnchor ?? ""}`;
80
+ if (!options.refresh) {
81
+ const cached = memo.get(key);
82
+ if (cached) return cached;
83
+ }
84
+ const pending = resolveModules(host, options.cliAnchor).catch((err) => {
85
+ const reason = err.message;
86
+ log.warn(`${DOMAIN_MODULE_PACKAGE} failed to load: ${reason}; domain features are off.`);
87
+ return { modules: [], reports: [{ name: DOMAIN_MODULE_PACKAGE, status: "load-failed", reason }] };
88
+ });
89
+ memo.set(key, pending);
90
+ return pending;
91
+ }
92
+
93
+ export {
94
+ DOMAIN_MODULE_PACKAGE,
95
+ sameMinor,
96
+ loadCtxoModules
97
+ };
98
+ //# sourceMappingURL=chunk-LAX6VVBU.js.map