@wildo-ai/dev-companion 1.1.14 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/claude-cli/models/coding-agent-dispatch.models.d.ts +68 -1
- package/dist/esm/claude-cli/models/coding-agent-dispatch.models.d.ts.map +1 -1
- package/dist/esm/claude-cli/models/coding-agent-dispatch.models.js +77 -5
- package/dist/esm/claude-cli/models/coding-agent-dispatch.models.js.map +1 -1
- package/dist/esm/claude-cli/models/concurrent-coding-runs.models.d.ts +46 -1
- package/dist/esm/claude-cli/models/concurrent-coding-runs.models.d.ts.map +1 -1
- package/dist/esm/claude-cli/models/concurrent-coding-runs.models.js +39 -2
- package/dist/esm/claude-cli/models/concurrent-coding-runs.models.js.map +1 -1
- package/dist/esm/claude-cli/models/shared-tree-reconciliation.models.d.ts +6 -0
- package/dist/esm/claude-cli/models/shared-tree-reconciliation.models.d.ts.map +1 -1
- package/dist/esm/claude-cli/models/shared-tree-reconciliation.models.js.map +1 -1
- package/dist/esm/claude-cli/models/verification-tool-availability.models.d.ts +19 -5
- package/dist/esm/claude-cli/models/verification-tool-availability.models.d.ts.map +1 -1
- package/dist/esm/claude-cli/models/verification-tool-availability.models.js +17 -5
- package/dist/esm/claude-cli/models/verification-tool-availability.models.js.map +1 -1
- package/dist/esm/claude-cli/services/accepted-change-commit.companion.service.d.ts +16 -1
- package/dist/esm/claude-cli/services/accepted-change-commit.companion.service.d.ts.map +1 -1
- package/dist/esm/claude-cli/services/accepted-change-commit.companion.service.js +44 -4
- package/dist/esm/claude-cli/services/accepted-change-commit.companion.service.js.map +1 -1
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.d.ts +79 -6
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.d.ts.map +1 -1
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js +291 -40
- package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js.map +1 -1
- package/dist/esm/claude-cli/services/research-evidence-store.companion.d.ts +14 -0
- package/dist/esm/claude-cli/services/research-evidence-store.companion.d.ts.map +1 -1
- package/dist/esm/claude-cli/services/research-evidence-store.companion.js +35 -0
- package/dist/esm/claude-cli/services/research-evidence-store.companion.js.map +1 -1
- package/dist/esm/claude-cli/services/unrecorded-provider-directories.companion.d.ts +36 -0
- package/dist/esm/claude-cli/services/unrecorded-provider-directories.companion.d.ts.map +1 -0
- package/dist/esm/claude-cli/services/unrecorded-provider-directories.companion.js +134 -0
- package/dist/esm/claude-cli/services/unrecorded-provider-directories.companion.js.map +1 -0
- package/dist/esm/core/introspection/services/translation-placement.companion.service.d.ts +3 -2
- package/dist/esm/core/introspection/services/translation-placement.companion.service.d.ts.map +1 -1
- package/dist/esm/core/introspection/services/translation-placement.companion.service.js.map +1 -1
- package/dist/esm/core/introspection/subprocess/companion-introspection-behavior-handlers.d.ts.map +1 -1
- package/dist/esm/core/introspection/subprocess/companion-introspection-behavior-handlers.js +24 -14
- package/dist/esm/core/introspection/subprocess/companion-introspection-behavior-handlers.js.map +1 -1
- package/dist/esm/core/introspection/workspace-element-index.companion.d.ts +42 -0
- package/dist/esm/core/introspection/workspace-element-index.companion.d.ts.map +1 -1
- package/dist/esm/core/introspection/workspace-element-index.companion.js +42 -0
- package/dist/esm/core/introspection/workspace-element-index.companion.js.map +1 -1
- package/dist/esm/core/runtime/dev-compile-quiet.companion.d.ts +53 -0
- package/dist/esm/core/runtime/dev-compile-quiet.companion.d.ts.map +1 -1
- package/dist/esm/core/runtime/dev-compile-quiet.companion.js +119 -2
- package/dist/esm/core/runtime/dev-compile-quiet.companion.js.map +1 -1
- package/dist/esm/core/runtime/services/start-companion-application.service.d.ts.map +1 -1
- package/dist/esm/core/runtime/services/start-companion-application.service.js +13 -1
- package/dist/esm/core/runtime/services/start-companion-application.service.js.map +1 -1
- package/dist/esm/core/runtime/utils/companion-platform-config.companion.d.ts +2 -2
- package/dist/esm/core/runtime/utils/companion-platform-config.companion.d.ts.map +1 -1
- package/dist/esm/core/runtime/utils/companion-platform-config.companion.js +6 -6
- package/dist/esm/core/runtime/utils/companion-platform-config.companion.js.map +1 -1
- package/dist/esm/email/services/email-template.companion.service.d.ts +5 -0
- package/dist/esm/email/services/email-template.companion.service.d.ts.map +1 -1
- package/dist/esm/email/services/email-template.companion.service.js +44 -11
- package/dist/esm/email/services/email-template.companion.service.js.map +1 -1
- package/dist/esm/email/utils/email-template-fs-discovery.utils.d.ts +26 -2
- package/dist/esm/email/utils/email-template-fs-discovery.utils.d.ts.map +1 -1
- package/dist/esm/email/utils/email-template-fs-discovery.utils.js +41 -2
- package/dist/esm/email/utils/email-template-fs-discovery.utils.js.map +1 -1
- package/dist/esm/email/utils/email-template-scanner-calls.companion.utils.d.ts +19 -0
- package/dist/esm/email/utils/email-template-scanner-calls.companion.utils.d.ts.map +1 -0
- package/dist/esm/email/utils/email-template-scanner-calls.companion.utils.js +171 -0
- package/dist/esm/email/utils/email-template-scanner-calls.companion.utils.js.map +1 -0
- package/dist/esm/email/utils/module-email-root.companion.utils.d.ts +75 -0
- package/dist/esm/email/utils/module-email-root.companion.utils.d.ts.map +1 -0
- package/dist/esm/email/utils/module-email-root.companion.utils.js +162 -0
- package/dist/esm/email/utils/module-email-root.companion.utils.js.map +1 -0
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.en.d.ts +1 -0
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.en.d.ts.map +1 -1
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.en.js +1 -0
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.en.js.map +1 -1
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.fr.d.ts +1 -0
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.fr.d.ts.map +1 -1
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.fr.js +1 -0
- package/dist/esm/i18n/components/LOW_LEVEL_AI_AGENT_CONFIG.fr.js.map +1 -1
- package/dist/esm/i18n/resources/workbenchAspects.en.d.ts.map +1 -1
- package/dist/esm/i18n/resources/workbenchAspects.en.js +4 -0
- package/dist/esm/i18n/resources/workbenchAspects.en.js.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts +35 -0
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js +12 -0
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.d.ts +536 -531
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.d.ts.map +1 -1
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.js +536 -531
- package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.fr.js.map +1 -1
- package/dist/esm/i18n/system_enums/workbench-build.en.d.ts +2 -2
- package/dist/esm/i18n/system_enums/workbench-build.en.js +2 -2
- package/dist/esm/i18n/system_enums/workbench-build.en.js.map +1 -1
- package/dist/esm/i18n-labelling/services/email-template-labelling-units.companion.service.d.ts.map +1 -1
- package/dist/esm/i18n-labelling/services/email-template-labelling-units.companion.service.js +7 -3
- package/dist/esm/i18n-labelling/services/email-template-labelling-units.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/models/creation-journey-timeline.models.d.ts +9 -0
- package/dist/esm/meta-workflows/models/creation-journey-timeline.models.d.ts.map +1 -1
- package/dist/esm/meta-workflows/models/creation-journey-timeline.models.js +18 -2
- package/dist/esm/meta-workflows/models/creation-journey-timeline.models.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts +33 -6
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js +97 -19
- package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.d.ts +21 -8
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.js +65 -12
- package/dist/esm/meta-workflows/services/application-build-follow-up-derivation.companion.js.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.d.ts +1 -1
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.js +48 -26
- package/dist/esm/meta-workflows/services/application-build-task-coding-policy.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/build-task-brief-application-facts.companion.d.ts +12 -0
- package/dist/esm/meta-workflows/services/build-task-brief-application-facts.companion.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/build-task-brief-application-facts.companion.js +30 -1
- package/dist/esm/meta-workflows/services/build-task-brief-application-facts.companion.js.map +1 -1
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.js +12 -1
- package/dist/esm/meta-workflows/services/creation-run-report.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts +7 -0
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.js +81 -4
- package/dist/esm/meta-workflows/services/playbook-run.companion.service.js.map +1 -1
- package/dist/esm/meta-workflows/services/provider-registry-brief.companion.utils.d.ts +55 -1
- package/dist/esm/meta-workflows/services/provider-registry-brief.companion.utils.d.ts.map +1 -1
- package/dist/esm/meta-workflows/services/provider-registry-brief.companion.utils.js +157 -10
- package/dist/esm/meta-workflows/services/provider-registry-brief.companion.utils.js.map +1 -1
- package/dist/esm/module-layout/module-layout-convention.companion.d.ts +158 -0
- package/dist/esm/module-layout/module-layout-convention.companion.d.ts.map +1 -0
- package/dist/esm/module-layout/module-layout-convention.companion.js +272 -0
- package/dist/esm/module-layout/module-layout-convention.companion.js.map +1 -0
- package/dist/esm/module-layout/module-layout-inspection.companion.d.ts +42 -0
- package/dist/esm/module-layout/module-layout-inspection.companion.d.ts.map +1 -0
- package/dist/esm/module-layout/module-layout-inspection.companion.js +290 -0
- package/dist/esm/module-layout/module-layout-inspection.companion.js.map +1 -0
- package/dist/esm/module-layout/module-source-files.companion.d.ts +3 -0
- package/dist/esm/module-layout/module-source-files.companion.d.ts.map +1 -0
- package/dist/esm/module-layout/module-source-files.companion.js +45 -0
- package/dist/esm/module-layout/module-source-files.companion.js.map +1 -0
- package/package.json +17 -17
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `check:module-layout` (#3904): every business module's conventional files, read from the working tree, held to the
|
|
3
|
+
* places `module-layout-convention.companion.ts` says the framework reads them from.
|
|
4
|
+
*
|
|
5
|
+
* A finding is a CORRECTION, not a description: the file that is out of place, the `mv` that puts it where it is
|
|
6
|
+
* read (renaming the folder when the whole folder is the misplaced unit, as `email/` → `emails/` is), and every relative
|
|
7
|
+
* import in the package that names the moved path, with the specifier it must become. The coding run that placed it
|
|
8
|
+
* receives the findings with its retry, so it moves the file instead of re-deriving where it should go.
|
|
9
|
+
*
|
|
10
|
+
* Application-wide, like `check:resources-registry-init` and `check:specification-exports`: every module of every
|
|
11
|
+
* module package is read (a few hundred file names and a handful of parses). A misplacement that was already in the tree
|
|
12
|
+
* before a run is NOT that run's: each finding carries its own identity (`failureFindings`), and the dispatch forgives a
|
|
13
|
+
* check red at baseline for exactly the findings it named then (`verificationFailureIsCarried`), so a new misplacement in
|
|
14
|
+
* an already-red tree is still charged to the run that made it. Scoping to the run's changed files instead was rejected:
|
|
15
|
+
* the check would then be blind to a move that breaks an import elsewhere, and a reader would need the change set,
|
|
16
|
+
* which the verification executor does not have.
|
|
17
|
+
*
|
|
18
|
+
* Never throws for an absent package or module: an application without a frontend has nothing to hold there. A file
|
|
19
|
+
* that cannot be read is skipped (it cannot be classified by content, and its name is still classified).
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
22
|
+
import { dirname, join, posix, relative, resolve, sep } from 'node:path';
|
|
23
|
+
import ts from 'typescript';
|
|
24
|
+
import { mayCallEmailTemplateScanner, readEmailTemplateScannerCalls } from '../email/utils/email-template-scanner-calls.companion.utils.js';
|
|
25
|
+
import { classifyModuleFile, MODULE_EMAIL_DIRECTORY, MODULE_PACKAGES, MODULE_RESOURCES_DIRECTORY, MODULES_SOURCE_DIRECTORY, moduleFolderPath, ModuleConventionalFileKind, } from './module-layout-convention.companion.js';
|
|
26
|
+
import { listModuleSourceFiles } from './module-source-files.companion.js';
|
|
27
|
+
function listModuleFolders(packageModulesRoot) {
|
|
28
|
+
try {
|
|
29
|
+
return readdirSync(packageModulesRoot)
|
|
30
|
+
.filter((entry) => !entry.startsWith('.') && entry !== '__tests__' && entry !== 'node_modules')
|
|
31
|
+
.filter((entry) => {
|
|
32
|
+
try {
|
|
33
|
+
return statSync(join(packageModulesRoot, entry)).isDirectory();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
.sort();
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The resources a module has, read from every module package: each folder under `<package>/src/modules/<module>/resources/`,
|
|
47
|
+
* and the stem of each `<resource>.resource.specification.ts` and `<resource>.resources-config.ts` anywhere in the module.
|
|
48
|
+
* What makes `deals.schemas.ts` outside `resources/` a misplaced resource schema rather than a helper's fragment.
|
|
49
|
+
*/
|
|
50
|
+
function readKnownResourceStems(saasRoot, moduleRef) {
|
|
51
|
+
const known = new Set();
|
|
52
|
+
for (const modulePackage of MODULE_PACKAGES) {
|
|
53
|
+
const moduleDirectory = join(saasRoot, moduleFolderPath(modulePackage, moduleRef));
|
|
54
|
+
for (const folder of listModuleFolders(join(moduleDirectory, MODULE_RESOURCES_DIRECTORY)))
|
|
55
|
+
known.add(folder);
|
|
56
|
+
for (const file of listModuleSourceFiles(moduleDirectory)) {
|
|
57
|
+
const name = posix.basename(file);
|
|
58
|
+
for (const suffix of ['.resource.specification.ts', '.resources-config.ts']) {
|
|
59
|
+
if (name.endsWith(suffix) && name.length > suffix.length)
|
|
60
|
+
known.add(name.slice(0, -suffix.length));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return known;
|
|
65
|
+
}
|
|
66
|
+
/** The folders under `root` that hold an email template (`template.tsx`, `template.ts`), relative to it (POSIX). */
|
|
67
|
+
function listTemplateDirectories(root) {
|
|
68
|
+
return [...new Set(listModuleSourceFiles(root)
|
|
69
|
+
.filter((file) => /(?:^|\/)template\.tsx?$/u.test(file))
|
|
70
|
+
.map((file) => posix.dirname(file)))]
|
|
71
|
+
.filter((folder) => folder !== '.')
|
|
72
|
+
.sort();
|
|
73
|
+
}
|
|
74
|
+
function readText(path) {
|
|
75
|
+
try {
|
|
76
|
+
return readFileSync(path, 'utf8');
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Inspect every module of every module package under `saasRoot`. */
|
|
83
|
+
export function inspectModuleLayout(saasRoot) {
|
|
84
|
+
let modulesInspected = 0;
|
|
85
|
+
let conventionalFilesSeen = 0;
|
|
86
|
+
const findings = [];
|
|
87
|
+
const knownResourceStemsByModule = new Map();
|
|
88
|
+
const knownResourceStemsOf = (moduleRef) => {
|
|
89
|
+
const known = knownResourceStemsByModule.get(moduleRef) ?? readKnownResourceStems(saasRoot, moduleRef);
|
|
90
|
+
knownResourceStemsByModule.set(moduleRef, known);
|
|
91
|
+
return known;
|
|
92
|
+
};
|
|
93
|
+
for (const modulePackage of MODULE_PACKAGES) {
|
|
94
|
+
const modulesRoot = join(saasRoot, modulePackage, MODULES_SOURCE_DIRECTORY);
|
|
95
|
+
for (const moduleRef of listModuleFolders(modulesRoot)) {
|
|
96
|
+
modulesInspected += 1;
|
|
97
|
+
const moduleDirectory = join(modulesRoot, moduleRef);
|
|
98
|
+
for (const fileInModule of listModuleSourceFiles(moduleDirectory)) {
|
|
99
|
+
const text = mayCallEmailTemplateScannerPath(moduleDirectory, fileInModule);
|
|
100
|
+
const scannerCalls = text === undefined ? [] : readEmailTemplateScannerCalls(text, fileInModule);
|
|
101
|
+
const callsEmailScanner = scannerCalls.length > 0;
|
|
102
|
+
const classification = classifyModuleFile({ modulePackage, moduleRef, fileInModule, facts: { callsEmailScanner, knownResourceStems: knownResourceStemsOf(moduleRef) } });
|
|
103
|
+
if (classification === undefined)
|
|
104
|
+
continue;
|
|
105
|
+
conventionalFilesSeen += 1;
|
|
106
|
+
if (classification.conventional)
|
|
107
|
+
continue;
|
|
108
|
+
findings.push(buildFinding({
|
|
109
|
+
saasRoot,
|
|
110
|
+
modulePackage,
|
|
111
|
+
moduleRef,
|
|
112
|
+
fileInModule,
|
|
113
|
+
conventionalPath: classification.conventionalPath,
|
|
114
|
+
convention: classification.convention,
|
|
115
|
+
scannedSubdirs: scannerCalls.map((call) => call.subdir),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { modulesInspected, conventionalFilesSeen, findings };
|
|
121
|
+
}
|
|
122
|
+
/** The file's text when it may call the email scanner (only backend module files can, and only those naming it). */
|
|
123
|
+
function mayCallEmailTemplateScannerPath(moduleDirectory, fileInModule) {
|
|
124
|
+
const text = readText(join(moduleDirectory, fileInModule));
|
|
125
|
+
return text !== undefined && mayCallEmailTemplateScanner(text) ? text : undefined;
|
|
126
|
+
}
|
|
127
|
+
function buildFinding(input) {
|
|
128
|
+
const moduleFolder = moduleFolderPath(input.modulePackage, input.moduleRef);
|
|
129
|
+
const path = `${moduleFolder}/${input.fileInModule}`;
|
|
130
|
+
const conventionalPath = `${moduleFolder}/${input.conventionalPath}`;
|
|
131
|
+
const moves = [];
|
|
132
|
+
const currentFolder = posix.dirname(input.fileInModule);
|
|
133
|
+
const emailFolderExists = existsSync(join(input.saasRoot, moduleFolder, MODULE_EMAIL_DIRECTORY));
|
|
134
|
+
let unscannedSubdirs = false;
|
|
135
|
+
if (input.convention.kind === ModuleConventionalFileKind.EMAIL_TEMPLATE_DEFINITIONS) {
|
|
136
|
+
if (currentFolder !== '.' && !currentFolder.includes('/') && !emailFolderExists) {
|
|
137
|
+
/*
|
|
138
|
+
* The improvised case (`email/` instead of `emails/`): the definitions file and the templates it scans share one
|
|
139
|
+
* folder, and the scanner reads its `subdir` RELATIVE to itself, so the folder is the unit that moves. Moving the
|
|
140
|
+
* file alone would leave its templates behind and register nothing.
|
|
141
|
+
*/
|
|
142
|
+
moves.push([`${moduleFolder}/${currentFolder}`, `${moduleFolder}/${MODULE_EMAIL_DIRECTORY}`]);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
moves.push([path, conventionalPath]);
|
|
146
|
+
for (const subdir of input.scannedSubdirs) {
|
|
147
|
+
if (subdir === null) {
|
|
148
|
+
unscannedSubdirs = true;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (subdir === '.')
|
|
152
|
+
continue;
|
|
153
|
+
const from = posix.join(moduleFolder, currentFolder, subdir);
|
|
154
|
+
if (!existsSync(join(input.saasRoot, from)))
|
|
155
|
+
continue;
|
|
156
|
+
if (currentFolder === '.') {
|
|
157
|
+
/*
|
|
158
|
+
* A scanner at the module's root scans a MODULE folder (`resources/` holds the module's operations too), so
|
|
159
|
+
* only its template folders (each holding a `template.*`) move, one by one; the folder itself stays.
|
|
160
|
+
*/
|
|
161
|
+
for (const templateDirectory of listTemplateDirectories(join(input.saasRoot, from))) {
|
|
162
|
+
moves.push([posix.join(from, templateDirectory), posix.join(moduleFolder, MODULE_EMAIL_DIRECTORY, subdir, templateDirectory)]);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
moves.push([from, posix.join(moduleFolder, MODULE_EMAIL_DIRECTORY, subdir)]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
moves.push([path, conventionalPath]);
|
|
173
|
+
}
|
|
174
|
+
const destinationExists = moves.some(([from, to]) => from !== to && existsSync(join(input.saasRoot, to)));
|
|
175
|
+
// `mv` does not create a destination's parent: each missing one is created first (`mkdir -p`, parents included).
|
|
176
|
+
const foldersToCreate = [...new Set(moves.map(([, to]) => posix.dirname(to)))]
|
|
177
|
+
.filter((folder) => !existsSync(join(input.saasRoot, folder)))
|
|
178
|
+
.sort()
|
|
179
|
+
.filter((folder, index, all) => !all.slice(index + 1).some((deeper) => deeper.startsWith(`${folder}/`)));
|
|
180
|
+
const importUpdates = planImportUpdates(input.saasRoot, input.modulePackage, moves);
|
|
181
|
+
const identity = `module-layout:${input.convention.kind}:${path}`;
|
|
182
|
+
const correction = describeCorrection({ path, conventionalPath, convention: input.convention, moves, foldersToCreate, importUpdates, destinationExists, unscannedSubdirs });
|
|
183
|
+
return { kind: input.convention.kind, path, conventionalPath, moves, importUpdates, destinationExists, identity, correction };
|
|
184
|
+
}
|
|
185
|
+
function describeCorrection(input) {
|
|
186
|
+
const where = posix.dirname(input.conventionalPath);
|
|
187
|
+
const commands = [
|
|
188
|
+
...(input.foldersToCreate.length === 0 ? [] : [`\`mkdir -p ${input.foldersToCreate.join(' ')}\``]),
|
|
189
|
+
/*
|
|
190
|
+
* `mv`, not `git mv` (#3904 review F1): a dispatched worker never commits, so the files a failing run created are
|
|
191
|
+
* UNTRACKED when its retry reads this, and `git mv` refuses an untracked source ("source directory is empty"). A
|
|
192
|
+
* plain move works on both, and git sees a committed file's move as a rename by its content.
|
|
193
|
+
*/
|
|
194
|
+
...input.moves.map(([from, to]) => `\`mv ${from} ${to}\``),
|
|
195
|
+
].join(', then ');
|
|
196
|
+
const imports = input.importUpdates.length === 0
|
|
197
|
+
? 'no relative import in the package names it'
|
|
198
|
+
: `then update the imports: ${input.importUpdates.map((update) => `${update.importer}:${update.line} '${update.specifier}' → '${update.replacement}'`).join('; ')}`;
|
|
199
|
+
return `${input.path} is a module ${input.convention.kind.replace(/-/g, ' ')} file outside \`${where}/\`, where ${input.convention.reliedOnBy}. `
|
|
200
|
+
+ `Move it: ${commands}; ${imports}.`
|
|
201
|
+
+ (input.unscannedSubdirs ? ' Its scanner reads a `subdir` that is not a literal: move every folder it scans into the same place, and write the `subdir` as a literal.' : '')
|
|
202
|
+
+ (input.destinationExists ? ' A destination already exists, so a move would overwrite it or nest inside it: merge the files into it by hand.' : '')
|
|
203
|
+
+ ' Do not create a second folder of this kind beside the conventional one.';
|
|
204
|
+
}
|
|
205
|
+
const IMPORTABLE_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.js', '.mjs', '.cjs'];
|
|
206
|
+
/** `./a/b.js` → the candidate source paths (absolute) it can resolve to, extension and `/index` included. */
|
|
207
|
+
function resolveRelativeSpecifier(importerDirectory, specifier) {
|
|
208
|
+
const absolute = resolve(importerDirectory, specifier);
|
|
209
|
+
const extension = /\.[cm]?[jt]sx?$/u.exec(absolute)?.[0] ?? '';
|
|
210
|
+
return { base: extension === '' ? absolute : absolute.slice(0, -extension.length), extension };
|
|
211
|
+
}
|
|
212
|
+
function sourceExtensionOf(path) {
|
|
213
|
+
return IMPORTABLE_EXTENSIONS.find((candidate) => path.endsWith(candidate)) ?? '';
|
|
214
|
+
}
|
|
215
|
+
function withoutSourceExtension(path) {
|
|
216
|
+
const extension = IMPORTABLE_EXTENSIONS.find((candidate) => path.endsWith(candidate));
|
|
217
|
+
return extension === undefined ? path : path.slice(0, -extension.length);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Every relative import in the package (`<package>/src`) that names a moved path, with the specifier it must become.
|
|
221
|
+
* Read from each file's syntax tree (import and export declarations, `import()` with a literal), so a path in a comment
|
|
222
|
+
* is not taken for an import. The extension style of the original specifier is kept (`.js` stays `.js`).
|
|
223
|
+
*/
|
|
224
|
+
export function planImportUpdates(saasRoot, modulePackage, moves) {
|
|
225
|
+
const packageSource = join(saasRoot, modulePackage, 'src');
|
|
226
|
+
const absoluteMoves = moves.map(([from, to]) => {
|
|
227
|
+
const fromAbsolute = join(saasRoot, from);
|
|
228
|
+
const isFile = IMPORTABLE_EXTENSIONS.some((extension) => from.endsWith(extension));
|
|
229
|
+
return { from: isFile ? withoutSourceExtension(fromAbsolute) : fromAbsolute, to: isFile ? withoutSourceExtension(join(saasRoot, to)) : join(saasRoot, to), isFile };
|
|
230
|
+
});
|
|
231
|
+
const movedTarget = (base) => {
|
|
232
|
+
for (const move of absoluteMoves) {
|
|
233
|
+
if (move.isFile) {
|
|
234
|
+
if (base === move.from)
|
|
235
|
+
return move.to;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (base === move.from)
|
|
239
|
+
return move.to;
|
|
240
|
+
if (base.startsWith(`${move.from}${sep}`))
|
|
241
|
+
return `${move.to}${base.slice(move.from.length)}`;
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
};
|
|
245
|
+
const updates = [];
|
|
246
|
+
for (const file of listModuleSourceFiles(packageSource)) {
|
|
247
|
+
const absoluteImporter = join(packageSource, file);
|
|
248
|
+
const text = readText(absoluteImporter);
|
|
249
|
+
if (text === undefined || !text.includes('.'))
|
|
250
|
+
continue;
|
|
251
|
+
// The importer itself may be moving: its own relative imports are then read from where it will be.
|
|
252
|
+
const importerAfter = movedTarget(withoutSourceExtension(absoluteImporter));
|
|
253
|
+
const importerDirectoryAfter = importerAfter === undefined ? dirname(absoluteImporter) : dirname(importerAfter);
|
|
254
|
+
const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
255
|
+
const visit = (node) => {
|
|
256
|
+
let specifierNode;
|
|
257
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier !== undefined && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
258
|
+
specifierNode = node.moduleSpecifier;
|
|
259
|
+
}
|
|
260
|
+
else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments[0] !== undefined && ts.isStringLiteralLike(node.arguments[0])) {
|
|
261
|
+
specifierNode = node.arguments[0];
|
|
262
|
+
}
|
|
263
|
+
if (specifierNode !== undefined && specifierNode.text.startsWith('.')) {
|
|
264
|
+
const specifier = specifierNode.text;
|
|
265
|
+
const { base, extension } = resolveRelativeSpecifier(dirname(absoluteImporter), specifier);
|
|
266
|
+
const target = movedTarget(base);
|
|
267
|
+
if (target !== undefined || importerAfter !== undefined) {
|
|
268
|
+
const finalTarget = target ?? base;
|
|
269
|
+
let replacement = relative(importerDirectoryAfter, finalTarget).split(sep).join('/');
|
|
270
|
+
if (!replacement.startsWith('.'))
|
|
271
|
+
replacement = `./${replacement}`;
|
|
272
|
+
replacement = `${replacement}${extension}`;
|
|
273
|
+
if (replacement !== specifier) {
|
|
274
|
+
updates.push({
|
|
275
|
+
// Named where it will be once the moves are made, which is where the agent edits it.
|
|
276
|
+
importer: relative(saasRoot, importerAfter === undefined ? absoluteImporter : `${importerAfter}${sourceExtensionOf(absoluteImporter)}`).split(sep).join('/'),
|
|
277
|
+
line: sourceFile.getLineAndCharacterOfPosition(specifierNode.getStart(sourceFile)).line + 1,
|
|
278
|
+
specifier,
|
|
279
|
+
replacement,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
ts.forEachChild(node, visit);
|
|
285
|
+
};
|
|
286
|
+
visit(sourceFile);
|
|
287
|
+
}
|
|
288
|
+
return updates;
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=module-layout-inspection.companion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-layout-inspection.companion.js","sourceRoot":"","sources":["../../../src/module-layout/module-layout-inspection.companion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,MAAM,6DAA6D,CAAC;AACzI,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,0BAA0B,EAC1B,wBAAwB,EACxB,gBAAgB,EAChB,0BAA0B,GAG3B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAqCxE,SAAS,iBAAiB,CAAC,kBAA0B;IACnD,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,kBAAkB,CAAC;aACnC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,cAAc,CAAC;aAC9F,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,CAAC;gBACH,OAAO,QAAQ,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;YACjE,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC,CAAC;aACD,IAAI,EAAE,CAAC;IACZ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F,KAAK,CAAC,UAAU,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * `check:module-layout` (#3904): every business module's conventional files, read from the working tree, held to the\n * places `module-layout-convention.companion.ts` says the framework reads them from.\n *\n * A finding is a CORRECTION, not a description: the file that is out of place, the `mv` that puts it where it is\n * read (renaming the folder when the whole folder is the misplaced unit, as `email/` → `emails/` is), and every relative\n * import in the package that names the moved path, with the specifier it must become. The coding run that placed it\n * receives the findings with its retry, so it moves the file instead of re-deriving where it should go.\n *\n * Application-wide, like `check:resources-registry-init` and `check:specification-exports`: every module of every\n * module package is read (a few hundred file names and a handful of parses). A misplacement that was already in the tree\n * before a run is NOT that run's: each finding carries its own identity (`failureFindings`), and the dispatch forgives a\n * check red at baseline for exactly the findings it named then (`verificationFailureIsCarried`), so a new misplacement in\n * an already-red tree is still charged to the run that made it. Scoping to the run's changed files instead was rejected:\n * the check would then be blind to a move that breaks an import elsewhere, and a reader would need the change set,\n * which the verification executor does not have.\n *\n * Never throws for an absent package or module: an application without a frontend has nothing to hold there. A file\n * that cannot be read is skipped (it cannot be classified by content, and its name is still classified).\n */\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join, posix, relative, resolve, sep } from 'node:path';\nimport ts from 'typescript';\n\nimport { mayCallEmailTemplateScanner, readEmailTemplateScannerCalls } from '../email/utils/email-template-scanner-calls.companion.utils';\nimport {\n classifyModuleFile,\n MODULE_EMAIL_DIRECTORY,\n MODULE_PACKAGES,\n MODULE_RESOURCES_DIRECTORY,\n MODULES_SOURCE_DIRECTORY,\n moduleFolderPath,\n ModuleConventionalFileKind,\n type ModuleLayoutConvention,\n type ModulePackage,\n} from './module-layout-convention.companion';\nimport { listModuleSourceFiles } from './module-source-files.companion';\n\n/** One relative import that must change when a file or folder moves. */\nexport interface ModuleLayoutImportUpdate {\n /** Application-relative importing file. */\n readonly importer: string;\n readonly line: number;\n readonly specifier: string;\n readonly replacement: string;\n}\n\n/** One file of a conventional kind outside its conventional place, and how to put it back. */\nexport interface ModuleLayoutFinding {\n readonly kind: ModuleConventionalFileKind;\n /** Application-relative path of the misplaced file. */\n readonly path: string;\n /** Application-relative path it belongs at. */\n readonly conventionalPath: string;\n /** The moves, in order: `[from, to]`, application-relative; a folder move when the whole folder is the unit. */\n readonly moves: ReadonlyArray<readonly [string, string]>;\n readonly importUpdates: readonly ModuleLayoutImportUpdate[];\n /** A destination that already exists, which a move would overwrite or nest into: the files must be merged by hand. */\n readonly destinationExists: boolean;\n /** The finding's identity, for carrying a red the tree already had (`failureFindings`). */\n readonly identity: string;\n /** The whole correction in one sentence, as the coding agent receives it. */\n readonly correction: string;\n}\n\nexport interface ModuleLayoutInspection {\n /** How many module folders were read, across every module package. */\n readonly modulesInspected: number;\n /** How many files a convention recognized. */\n readonly conventionalFilesSeen: number;\n readonly findings: readonly ModuleLayoutFinding[];\n}\n\nfunction listModuleFolders(packageModulesRoot: string): string[] {\n try {\n return readdirSync(packageModulesRoot)\n .filter((entry) => !entry.startsWith('.') && entry !== '__tests__' && entry !== 'node_modules')\n .filter((entry) => {\n try {\n return statSync(join(packageModulesRoot, entry)).isDirectory();\n } catch {\n return false;\n }\n })\n .sort();\n } catch {\n return [];\n }\n}\n\n/**\n * The resources a module has, read from every module package: each folder under `<package>/src/modules/<module>/resources/`,\n * and the stem of each `<resource>.resource.specification.ts` and `<resource>.resources-config.ts` anywhere in the module.\n * What makes `deals.schemas.ts` outside `resources/` a misplaced resource schema rather than a helper's fragment.\n */\nfunction readKnownResourceStems(saasRoot: string, moduleRef: string): ReadonlySet<string> {\n const known = new Set<string>();\n for (const modulePackage of MODULE_PACKAGES) {\n const moduleDirectory = join(saasRoot, moduleFolderPath(modulePackage, moduleRef));\n for (const folder of listModuleFolders(join(moduleDirectory, MODULE_RESOURCES_DIRECTORY))) known.add(folder);\n for (const file of listModuleSourceFiles(moduleDirectory)) {\n const name = posix.basename(file);\n for (const suffix of ['.resource.specification.ts', '.resources-config.ts']) {\n if (name.endsWith(suffix) && name.length > suffix.length) known.add(name.slice(0, -suffix.length));\n }\n }\n }\n return known;\n}\n\n/** The folders under `root` that hold an email template (`template.tsx`, `template.ts`), relative to it (POSIX). */\nfunction listTemplateDirectories(root: string): string[] {\n return [...new Set(listModuleSourceFiles(root)\n .filter((file) => /(?:^|\\/)template\\.tsx?$/u.test(file))\n .map((file) => posix.dirname(file)))]\n .filter((folder) => folder !== '.')\n .sort();\n}\n\nfunction readText(path: string): string | undefined {\n try {\n return readFileSync(path, 'utf8');\n } catch {\n return undefined;\n }\n}\n\n/** Inspect every module of every module package under `saasRoot`. */\nexport function inspectModuleLayout(saasRoot: string): ModuleLayoutInspection {\n let modulesInspected = 0;\n let conventionalFilesSeen = 0;\n const findings: ModuleLayoutFinding[] = [];\n const knownResourceStemsByModule = new Map<string, ReadonlySet<string>>();\n const knownResourceStemsOf = (moduleRef: string): ReadonlySet<string> => {\n const known = knownResourceStemsByModule.get(moduleRef) ?? readKnownResourceStems(saasRoot, moduleRef);\n knownResourceStemsByModule.set(moduleRef, known);\n return known;\n };\n for (const modulePackage of MODULE_PACKAGES) {\n const modulesRoot = join(saasRoot, modulePackage, MODULES_SOURCE_DIRECTORY);\n for (const moduleRef of listModuleFolders(modulesRoot)) {\n modulesInspected += 1;\n const moduleDirectory = join(modulesRoot, moduleRef);\n for (const fileInModule of listModuleSourceFiles(moduleDirectory)) {\n const text = mayCallEmailTemplateScannerPath(moduleDirectory, fileInModule);\n const scannerCalls = text === undefined ? [] : readEmailTemplateScannerCalls(text, fileInModule);\n const callsEmailScanner = scannerCalls.length > 0;\n const classification = classifyModuleFile({ modulePackage, moduleRef, fileInModule, facts: { callsEmailScanner, knownResourceStems: knownResourceStemsOf(moduleRef) } });\n if (classification === undefined) continue;\n conventionalFilesSeen += 1;\n if (classification.conventional) continue;\n findings.push(buildFinding({\n saasRoot,\n modulePackage,\n moduleRef,\n fileInModule,\n conventionalPath: classification.conventionalPath,\n convention: classification.convention,\n scannedSubdirs: scannerCalls.map((call) => call.subdir),\n }));\n }\n }\n }\n return { modulesInspected, conventionalFilesSeen, findings };\n}\n\n/** The file's text when it may call the email scanner (only backend module files can, and only those naming it). */\nfunction mayCallEmailTemplateScannerPath(moduleDirectory: string, fileInModule: string): string | undefined {\n const text = readText(join(moduleDirectory, fileInModule));\n return text !== undefined && mayCallEmailTemplateScanner(text) ? text : undefined;\n}\n\nfunction buildFinding(input: {\n readonly saasRoot: string;\n readonly modulePackage: ModulePackage;\n readonly moduleRef: string;\n readonly fileInModule: string;\n readonly conventionalPath: string;\n readonly convention: ModuleLayoutConvention;\n readonly scannedSubdirs: ReadonlyArray<string | null>;\n}): ModuleLayoutFinding {\n const moduleFolder = moduleFolderPath(input.modulePackage, input.moduleRef);\n const path = `${moduleFolder}/${input.fileInModule}`;\n const conventionalPath = `${moduleFolder}/${input.conventionalPath}`;\n const moves: Array<readonly [string, string]> = [];\n const currentFolder = posix.dirname(input.fileInModule);\n const emailFolderExists = existsSync(join(input.saasRoot, moduleFolder, MODULE_EMAIL_DIRECTORY));\n let unscannedSubdirs = false;\n if (input.convention.kind === ModuleConventionalFileKind.EMAIL_TEMPLATE_DEFINITIONS) {\n if (currentFolder !== '.' && !currentFolder.includes('/') && !emailFolderExists) {\n /*\n * The improvised case (`email/` instead of `emails/`): the definitions file and the templates it scans share one\n * folder, and the scanner reads its `subdir` RELATIVE to itself, so the folder is the unit that moves. Moving the\n * file alone would leave its templates behind and register nothing.\n */\n moves.push([`${moduleFolder}/${currentFolder}`, `${moduleFolder}/${MODULE_EMAIL_DIRECTORY}`]);\n } else {\n moves.push([path, conventionalPath]);\n for (const subdir of input.scannedSubdirs) {\n if (subdir === null) {\n unscannedSubdirs = true;\n continue;\n }\n if (subdir === '.') continue;\n const from = posix.join(moduleFolder, currentFolder, subdir);\n if (!existsSync(join(input.saasRoot, from))) continue;\n if (currentFolder === '.') {\n /*\n * A scanner at the module's root scans a MODULE folder (`resources/` holds the module's operations too), so\n * only its template folders (each holding a `template.*`) move, one by one; the folder itself stays.\n */\n for (const templateDirectory of listTemplateDirectories(join(input.saasRoot, from))) {\n moves.push([posix.join(from, templateDirectory), posix.join(moduleFolder, MODULE_EMAIL_DIRECTORY, subdir, templateDirectory)]);\n }\n } else {\n moves.push([from, posix.join(moduleFolder, MODULE_EMAIL_DIRECTORY, subdir)]);\n }\n }\n }\n } else {\n moves.push([path, conventionalPath]);\n }\n const destinationExists = moves.some(([from, to]) => from !== to && existsSync(join(input.saasRoot, to)));\n // `mv` does not create a destination's parent: each missing one is created first (`mkdir -p`, parents included).\n const foldersToCreate = [...new Set(moves.map(([, to]) => posix.dirname(to)))]\n .filter((folder) => !existsSync(join(input.saasRoot, folder)))\n .sort()\n .filter((folder, index, all) => !all.slice(index + 1).some((deeper) => deeper.startsWith(`${folder}/`)));\n const importUpdates = planImportUpdates(input.saasRoot, input.modulePackage, moves);\n const identity = `module-layout:${input.convention.kind}:${path}`;\n const correction = describeCorrection({ path, conventionalPath, convention: input.convention, moves, foldersToCreate, importUpdates, destinationExists, unscannedSubdirs });\n return { kind: input.convention.kind, path, conventionalPath, moves, importUpdates, destinationExists, identity, correction };\n}\n\nfunction describeCorrection(input: {\n readonly path: string;\n readonly conventionalPath: string;\n readonly convention: ModuleLayoutConvention;\n readonly moves: ReadonlyArray<readonly [string, string]>;\n readonly foldersToCreate: readonly string[];\n readonly importUpdates: readonly ModuleLayoutImportUpdate[];\n readonly destinationExists: boolean;\n readonly unscannedSubdirs: boolean;\n}): string {\n const where = posix.dirname(input.conventionalPath);\n const commands = [\n ...(input.foldersToCreate.length === 0 ? [] : [`\\`mkdir -p ${input.foldersToCreate.join(' ')}\\``]),\n /*\n * `mv`, not `git mv` (#3904 review F1): a dispatched worker never commits, so the files a failing run created are\n * UNTRACKED when its retry reads this, and `git mv` refuses an untracked source (\"source directory is empty\"). A\n * plain move works on both, and git sees a committed file's move as a rename by its content.\n */\n ...input.moves.map(([from, to]) => `\\`mv ${from} ${to}\\``),\n ].join(', then ');\n const imports = input.importUpdates.length === 0\n ? 'no relative import in the package names it'\n : `then update the imports: ${input.importUpdates.map((update) => `${update.importer}:${update.line} '${update.specifier}' → '${update.replacement}'`).join('; ')}`;\n return `${input.path} is a module ${input.convention.kind.replace(/-/g, ' ')} file outside \\`${where}/\\`, where ${input.convention.reliedOnBy}. `\n + `Move it: ${commands}; ${imports}.`\n + (input.unscannedSubdirs ? ' Its scanner reads a `subdir` that is not a literal: move every folder it scans into the same place, and write the `subdir` as a literal.' : '')\n + (input.destinationExists ? ' A destination already exists, so a move would overwrite it or nest inside it: merge the files into it by hand.' : '')\n + ' Do not create a second folder of this kind beside the conventional one.';\n}\n\nconst IMPORTABLE_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.js', '.mjs', '.cjs'];\n\n/** `./a/b.js` → the candidate source paths (absolute) it can resolve to, extension and `/index` included. */\nfunction resolveRelativeSpecifier(importerDirectory: string, specifier: string): { base: string; extension: string } {\n const absolute = resolve(importerDirectory, specifier);\n const extension = /\\.[cm]?[jt]sx?$/u.exec(absolute)?.[0] ?? '';\n return { base: extension === '' ? absolute : absolute.slice(0, -extension.length), extension };\n}\n\nfunction sourceExtensionOf(path: string): string {\n return IMPORTABLE_EXTENSIONS.find((candidate) => path.endsWith(candidate)) ?? '';\n}\n\nfunction withoutSourceExtension(path: string): string {\n const extension = IMPORTABLE_EXTENSIONS.find((candidate) => path.endsWith(candidate));\n return extension === undefined ? path : path.slice(0, -extension.length);\n}\n\n/**\n * Every relative import in the package (`<package>/src`) that names a moved path, with the specifier it must become.\n * Read from each file's syntax tree (import and export declarations, `import()` with a literal), so a path in a comment\n * is not taken for an import. The extension style of the original specifier is kept (`.js` stays `.js`).\n */\nexport function planImportUpdates(\n saasRoot: string,\n modulePackage: ModulePackage,\n moves: ReadonlyArray<readonly [string, string]>,\n): ModuleLayoutImportUpdate[] {\n const packageSource = join(saasRoot, modulePackage, 'src');\n const absoluteMoves = moves.map(([from, to]) => {\n const fromAbsolute = join(saasRoot, from);\n const isFile = IMPORTABLE_EXTENSIONS.some((extension) => from.endsWith(extension));\n return { from: isFile ? withoutSourceExtension(fromAbsolute) : fromAbsolute, to: isFile ? withoutSourceExtension(join(saasRoot, to)) : join(saasRoot, to), isFile };\n });\n const movedTarget = (base: string): string | undefined => {\n for (const move of absoluteMoves) {\n if (move.isFile) {\n if (base === move.from) return move.to;\n continue;\n }\n if (base === move.from) return move.to;\n if (base.startsWith(`${move.from}${sep}`)) return `${move.to}${base.slice(move.from.length)}`;\n }\n return undefined;\n };\n const updates: ModuleLayoutImportUpdate[] = [];\n for (const file of listModuleSourceFiles(packageSource)) {\n const absoluteImporter = join(packageSource, file);\n const text = readText(absoluteImporter);\n if (text === undefined || !text.includes('.')) continue;\n // The importer itself may be moving: its own relative imports are then read from where it will be.\n const importerAfter = movedTarget(withoutSourceExtension(absoluteImporter));\n const importerDirectoryAfter = importerAfter === undefined ? dirname(absoluteImporter) : dirname(importerAfter);\n const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);\n const visit = (node: ts.Node): void => {\n let specifierNode: ts.StringLiteralLike | undefined;\n if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier !== undefined && ts.isStringLiteral(node.moduleSpecifier)) {\n specifierNode = node.moduleSpecifier;\n } else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments[0] !== undefined && ts.isStringLiteralLike(node.arguments[0])) {\n specifierNode = node.arguments[0];\n }\n if (specifierNode !== undefined && specifierNode.text.startsWith('.')) {\n const specifier = specifierNode.text;\n const { base, extension } = resolveRelativeSpecifier(dirname(absoluteImporter), specifier);\n const target = movedTarget(base);\n if (target !== undefined || importerAfter !== undefined) {\n const finalTarget = target ?? base;\n let replacement = relative(importerDirectoryAfter, finalTarget).split(sep).join('/');\n if (!replacement.startsWith('.')) replacement = `./${replacement}`;\n replacement = `${replacement}${extension}`;\n if (replacement !== specifier) {\n updates.push({\n // Named where it will be once the moves are made, which is where the agent edits it.\n importer: relative(saasRoot, importerAfter === undefined ? absoluteImporter : `${importerAfter}${sourceExtensionOf(absoluteImporter)}`).split(sep).join('/'),\n line: sourceFile.getLineAndCharacterOfPosition(specifierNode.getStart(sourceFile)).line + 1,\n specifier,\n replacement,\n });\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n }\n return updates;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-source-files.companion.d.ts","sourceRoot":"","sources":["../../../src/module-layout/module-source-files.companion.ts"],"names":[],"mappings":"AAaA,mHAAmH;AACnH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAyBjE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The source files of a module folder (or of a package's `src/`), as `check:module-layout` and the companion's module email
|
|
3
|
+
* root read them (#3904). Its own file, with no TypeScript import, because the email root is also read inside the
|
|
4
|
+
* application's introspection subprocess.
|
|
5
|
+
*/
|
|
6
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
7
|
+
import { join, relative, sep } from 'node:path';
|
|
8
|
+
const SOURCE_FILE = /\.(?:ts|tsx|mts|cts|js|mjs|cjs)$/u;
|
|
9
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
10
|
+
/** Deep enough for any layout seen (`resources/<resource>/<sub>/…`), bounded against a pathological tree. */
|
|
11
|
+
const MAXIMUM_DEPTH = 12;
|
|
12
|
+
/** Every source file under `directory`, relative to it (POSIX), tests, dot-folders and `node_modules` excluded. */
|
|
13
|
+
export function listModuleSourceFiles(directory) {
|
|
14
|
+
const files = [];
|
|
15
|
+
const visit = (current, depth) => {
|
|
16
|
+
if (depth > MAXIMUM_DEPTH)
|
|
17
|
+
return;
|
|
18
|
+
let entries;
|
|
19
|
+
try {
|
|
20
|
+
entries = readdirSync(current);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const entry of entries.sort()) {
|
|
26
|
+
if (entry === 'node_modules' || entry === '__tests__' || entry.startsWith('.'))
|
|
27
|
+
continue;
|
|
28
|
+
const fullPath = join(current, entry);
|
|
29
|
+
let isDirectory = false;
|
|
30
|
+
try {
|
|
31
|
+
isDirectory = statSync(fullPath).isDirectory();
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (isDirectory)
|
|
37
|
+
visit(fullPath, depth + 1);
|
|
38
|
+
else if (SOURCE_FILE.test(entry) && !TEST_FILE.test(entry) && !entry.endsWith('.d.ts'))
|
|
39
|
+
files.push(relative(directory, fullPath).split(sep).join('/'));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
visit(directory, 0);
|
|
43
|
+
return files;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=module-source-files.companion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-source-files.companion.js","sourceRoot":"","sources":["../../../src/module-layout/module-source-files.companion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,GAAG,mCAAmC,CAAC;AACxD,MAAM,SAAS,GAAG,iCAAiC,CAAC;AACpD,6GAA6G;AAC7G,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,mHAAmH;AACnH,MAAM,UAAU,qBAAqB,CAAC,SAAiB;IACrD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,KAAa,EAAQ,EAAE;QACrD,IAAI,KAAK,GAAG,aAAa;YAAE,OAAO;QAClC,IAAI,OAAiB,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACnC,IAAI,KAAK,KAAK,cAAc,IAAI,KAAK,KAAK,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;gBAAE,SAAS;YACzF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACtC,IAAI,WAAW,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC;gBACH,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;YACD,IAAI,WAAW;gBAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;iBACvC,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACzJ,CAAC;IACH,CAAC,CAAC;IACF,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * The source files of a module folder (or of a package's `src/`), as `check:module-layout` and the companion's module email\n * root read them (#3904). Its own file, with no TypeScript import, because the email root is also read inside the\n * application's introspection subprocess.\n */\nimport { readdirSync, statSync } from 'node:fs';\nimport { join, relative, sep } from 'node:path';\n\nconst SOURCE_FILE = /\\.(?:ts|tsx|mts|cts|js|mjs|cjs)$/u;\nconst TEST_FILE = /\\.(?:test|spec)\\.[cm]?[jt]sx?$/u;\n/** Deep enough for any layout seen (`resources/<resource>/<sub>/…`), bounded against a pathological tree. */\nconst MAXIMUM_DEPTH = 12;\n\n/** Every source file under `directory`, relative to it (POSIX), tests, dot-folders and `node_modules` excluded. */\nexport function listModuleSourceFiles(directory: string): string[] {\n const files: string[] = [];\n const visit = (current: string, depth: number): void => {\n if (depth > MAXIMUM_DEPTH) return;\n let entries: string[];\n try {\n entries = readdirSync(current);\n } catch {\n return;\n }\n for (const entry of entries.sort()) {\n if (entry === 'node_modules' || entry === '__tests__' || entry.startsWith('.')) continue;\n const fullPath = join(current, entry);\n let isDirectory = false;\n try {\n isDirectory = statSync(fullPath).isDirectory();\n } catch {\n continue;\n }\n if (isDirectory) visit(fullPath, depth + 1);\n else if (SOURCE_FILE.test(entry) && !TEST_FILE.test(entry) && !entry.endsWith('.d.ts')) files.push(relative(directory, fullPath).split(sep).join('/'));\n }\n };\n visit(directory, 0);\n return files;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildo-ai/dev-companion",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "Wildo.ai Dev Companion — local development management and introspection service. Canonical source home; applications receive only the built dist below their .wildo-saas/wildo-dev-companion drop.",
|
|
5
5
|
"author": "Wildo AI",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -46,22 +46,22 @@
|
|
|
46
46
|
"@radix-ui/react-tooltip": "^1.2.8",
|
|
47
47
|
"@react-email/components": "^1.0.8",
|
|
48
48
|
"@react-email/render": "^2.0.4",
|
|
49
|
-
"@wildo-ai/application-creation-runtime": "1.1.
|
|
50
|
-
"@wildo-ai/external-connectors-models": "1.1.
|
|
51
|
-
"@wildo-ai/framework-knowledge": "1.1.
|
|
52
|
-
"@wildo-ai/platform-config-lib": "1.1.
|
|
53
|
-
"@wildo-ai/platform-core-backend": "1.1.
|
|
54
|
-
"@wildo-ai/platform-core-shared": "1.1.
|
|
55
|
-
"@wildo-ai/platform-shared-lib": "1.1.
|
|
56
|
-
"@wildo-ai/presets-components-models": "1.1.
|
|
57
|
-
"@wildo-ai/saas-backend-lib": "1.1.
|
|
58
|
-
"@wildo-ai/saas-frontend-lib": "1.1.
|
|
59
|
-
"@wildo-ai/saas-models": "1.1.
|
|
60
|
-
"@wildo-ai/saas-specifications": "1.1.
|
|
61
|
-
"@wildo-ai/saas-technical-doc": "1.1.
|
|
62
|
-
"@wildo-ai/saas-website": "1.1.
|
|
63
|
-
"@wildo-ai/wildo-module-client": "1.1.
|
|
64
|
-
"@wildo-ai/zod-decorators": "1.1.
|
|
49
|
+
"@wildo-ai/application-creation-runtime": "1.1.15",
|
|
50
|
+
"@wildo-ai/external-connectors-models": "1.1.15",
|
|
51
|
+
"@wildo-ai/framework-knowledge": "1.1.15",
|
|
52
|
+
"@wildo-ai/platform-config-lib": "1.1.15",
|
|
53
|
+
"@wildo-ai/platform-core-backend": "1.1.15",
|
|
54
|
+
"@wildo-ai/platform-core-shared": "1.1.15",
|
|
55
|
+
"@wildo-ai/platform-shared-lib": "1.1.15",
|
|
56
|
+
"@wildo-ai/presets-components-models": "1.1.15",
|
|
57
|
+
"@wildo-ai/saas-backend-lib": "1.1.15",
|
|
58
|
+
"@wildo-ai/saas-frontend-lib": "1.1.15",
|
|
59
|
+
"@wildo-ai/saas-models": "1.1.15",
|
|
60
|
+
"@wildo-ai/saas-specifications": "1.1.15",
|
|
61
|
+
"@wildo-ai/saas-technical-doc": "1.1.15",
|
|
62
|
+
"@wildo-ai/saas-website": "1.1.15",
|
|
63
|
+
"@wildo-ai/wildo-module-client": "1.1.15",
|
|
64
|
+
"@wildo-ai/zod-decorators": "1.1.15",
|
|
65
65
|
"@xyflow/react": "^12.9.3",
|
|
66
66
|
"big.js": "^6.2.2",
|
|
67
67
|
"cors": "^2.8.5",
|