@ddtcorex/dsh-maestro-review 0.12.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.
Files changed (167) hide show
  1. package/README.md +37 -58
  2. package/cordis.patch.yml +13 -18
  3. package/lib/config-store.d.ts +9 -1
  4. package/lib/config-store.d.ts.map +1 -1
  5. package/lib/config-store.js +1 -1
  6. package/lib/config-store.js.map +1 -1
  7. package/lib/events.d.ts +8 -45
  8. package/lib/events.d.ts.map +1 -1
  9. package/lib/host-orchestrator.d.ts +128 -0
  10. package/lib/host-orchestrator.d.ts.map +1 -0
  11. package/lib/host-orchestrator.js +500 -0
  12. package/lib/host-orchestrator.js.map +1 -0
  13. package/lib/index.d.ts +7 -2
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +7 -43
  16. package/lib/index.js.map +1 -1
  17. package/lib/providers/gitlab.d.ts.map +1 -1
  18. package/lib/providers/gitlab.js +8 -1
  19. package/lib/providers/gitlab.js.map +1 -1
  20. package/lib/review-intake.d.ts +8 -1
  21. package/lib/review-intake.d.ts.map +1 -1
  22. package/lib/review-intake.js +22 -0
  23. package/lib/review-intake.js.map +1 -1
  24. package/lib/settings-rpc.js +1 -1
  25. package/lib/settings-rpc.js.map +1 -1
  26. package/package.json +19 -36
  27. package/src/client/index.tsx +1 -1
  28. package/src/host/augment.d.ts +3 -1
  29. package/src/host/config-store.ts +2 -2
  30. package/src/host/events.ts +8 -45
  31. package/src/host/host-orchestrator.ts +549 -0
  32. package/src/host/index.ts +7 -35
  33. package/src/host/providers/gitlab.ts +8 -2
  34. package/src/host/review-intake.ts +20 -1
  35. package/src/host/settings-rpc.ts +1 -1
  36. package/lib/ci-clone.d.ts +0 -21
  37. package/lib/ci-clone.d.ts.map +0 -1
  38. package/lib/ci-clone.js +0 -35
  39. package/lib/ci-clone.js.map +0 -1
  40. package/lib/ci-coexist.d.ts +0 -11
  41. package/lib/ci-coexist.d.ts.map +0 -1
  42. package/lib/ci-coexist.js +0 -38
  43. package/lib/ci-coexist.js.map +0 -1
  44. package/lib/gitlab-auth.d.ts +0 -11
  45. package/lib/gitlab-auth.d.ts.map +0 -1
  46. package/lib/gitlab-auth.js +0 -15
  47. package/lib/gitlab-auth.js.map +0 -1
  48. package/lib/gitlab-client.d.ts +0 -78
  49. package/lib/gitlab-client.d.ts.map +0 -1
  50. package/lib/gitlab-client.js +0 -270
  51. package/lib/gitlab-client.js.map +0 -1
  52. package/lib/govard-lint-detection.d.ts +0 -20
  53. package/lib/govard-lint-detection.d.ts.map +0 -1
  54. package/lib/govard-lint-detection.js +0 -48
  55. package/lib/govard-lint-detection.js.map +0 -1
  56. package/lib/hyva-csp-scan-tool.d.ts +0 -11
  57. package/lib/hyva-csp-scan-tool.d.ts.map +0 -1
  58. package/lib/hyva-csp-scan-tool.js +0 -193
  59. package/lib/hyva-csp-scan-tool.js.map +0 -1
  60. package/lib/hyva-theme-inspect-tool.d.ts +0 -10
  61. package/lib/hyva-theme-inspect-tool.d.ts.map +0 -1
  62. package/lib/hyva-theme-inspect-tool.js +0 -299
  63. package/lib/hyva-theme-inspect-tool.js.map +0 -1
  64. package/lib/incremental.d.ts +0 -28
  65. package/lib/incremental.d.ts.map +0 -1
  66. package/lib/incremental.js +0 -62
  67. package/lib/incremental.js.map +0 -1
  68. package/lib/layout-xml-tool.d.ts +0 -11
  69. package/lib/layout-xml-tool.d.ts.map +0 -1
  70. package/lib/layout-xml-tool.js +0 -239
  71. package/lib/layout-xml-tool.js.map +0 -1
  72. package/lib/module-check-tool.d.ts +0 -11
  73. package/lib/module-check-tool.d.ts.map +0 -1
  74. package/lib/module-check-tool.js +0 -303
  75. package/lib/module-check-tool.js.map +0 -1
  76. package/lib/orchestrator.d.ts +0 -357
  77. package/lib/orchestrator.d.ts.map +0 -1
  78. package/lib/orchestrator.js +0 -1497
  79. package/lib/orchestrator.js.map +0 -1
  80. package/lib/perf-log-stats-tool.d.ts +0 -13
  81. package/lib/perf-log-stats-tool.d.ts.map +0 -1
  82. package/lib/perf-log-stats-tool.js +0 -245
  83. package/lib/perf-log-stats-tool.js.map +0 -1
  84. package/lib/phtml-escape-scan-tool.d.ts +0 -11
  85. package/lib/phtml-escape-scan-tool.d.ts.map +0 -1
  86. package/lib/phtml-escape-scan-tool.js +0 -166
  87. package/lib/phtml-escape-scan-tool.js.map +0 -1
  88. package/lib/providers/ci-trigger.d.ts +0 -44
  89. package/lib/providers/ci-trigger.d.ts.map +0 -1
  90. package/lib/providers/ci-trigger.js +0 -150
  91. package/lib/providers/ci-trigger.js.map +0 -1
  92. package/lib/review-findings-tool.d.ts +0 -20
  93. package/lib/review-findings-tool.d.ts.map +0 -1
  94. package/lib/review-findings-tool.js +0 -39
  95. package/lib/review-findings-tool.js.map +0 -1
  96. package/lib/review-history.d.ts +0 -40
  97. package/lib/review-history.d.ts.map +0 -1
  98. package/lib/review-history.js +0 -136
  99. package/lib/review-history.js.map +0 -1
  100. package/lib/review-marker.d.ts +0 -17
  101. package/lib/review-marker.d.ts.map +0 -1
  102. package/lib/review-marker.js +0 -23
  103. package/lib/review-marker.js.map +0 -1
  104. package/lib/review-signals.d.ts +0 -17
  105. package/lib/review-signals.d.ts.map +0 -1
  106. package/lib/review-signals.js +0 -79
  107. package/lib/review-signals.js.map +0 -1
  108. package/lib/scope-split-tool.d.ts +0 -42
  109. package/lib/scope-split-tool.d.ts.map +0 -1
  110. package/lib/scope-split-tool.js +0 -108
  111. package/lib/scope-split-tool.js.map +0 -1
  112. package/lib/search-tool.d.ts +0 -15
  113. package/lib/search-tool.d.ts.map +0 -1
  114. package/lib/search-tool.js +0 -144
  115. package/lib/search-tool.js.map +0 -1
  116. package/lib/skill-provider.d.ts +0 -19
  117. package/lib/skill-provider.d.ts.map +0 -1
  118. package/lib/skill-provider.js +0 -101
  119. package/lib/skill-provider.js.map +0 -1
  120. package/lib/skills-tool.d.ts +0 -29
  121. package/lib/skills-tool.d.ts.map +0 -1
  122. package/lib/skills-tool.js +0 -185
  123. package/lib/skills-tool.js.map +0 -1
  124. package/lib/source.d.ts +0 -23
  125. package/lib/source.d.ts.map +0 -1
  126. package/lib/source.js +0 -16
  127. package/lib/source.js.map +0 -1
  128. package/lib/tool-policy.d.ts +0 -20
  129. package/lib/tool-policy.d.ts.map +0 -1
  130. package/lib/tool-policy.js +0 -42
  131. package/lib/tool-policy.js.map +0 -1
  132. package/presets/maestro-auditor.patch.yml +0 -54
  133. package/presets/maestro-coder/agent.cordis.yml +0 -223
  134. package/presets/maestro-coder/preset.yml +0 -2
  135. package/presets/maestro-reviewer.patch.yml +0 -55
  136. package/profiles/reviewer-ci/cordis.patch.yml +0 -78
  137. package/profiles/reviewer-ci/package.json +0 -19
  138. package/profiles/reviewer-ci/pnpm-lock.yaml +0 -8201
  139. package/profiles/reviewer-ci/pnpm-workspace.yaml +0 -36
  140. package/skills/dsh-native-tools/SKILL.md +0 -80
  141. package/src/host/ci-clone.ts +0 -54
  142. package/src/host/ci-coexist.ts +0 -45
  143. package/src/host/dsh-skill.d.ts +0 -72
  144. package/src/host/gitlab-auth.ts +0 -13
  145. package/src/host/gitlab-client.ts +0 -332
  146. package/src/host/govard-lint-detection.ts +0 -47
  147. package/src/host/hyva-csp-scan-tool.ts +0 -165
  148. package/src/host/hyva-theme-inspect-tool.ts +0 -258
  149. package/src/host/incremental.ts +0 -86
  150. package/src/host/layout-xml-tool.ts +0 -190
  151. package/src/host/module-check-tool.ts +0 -187
  152. package/src/host/orchestrator.ts +0 -1641
  153. package/src/host/perf-log-stats-tool.ts +0 -224
  154. package/src/host/phtml-escape-scan-tool.ts +0 -112
  155. package/src/host/providers/ci-trigger.ts +0 -168
  156. package/src/host/review-findings-tool.ts +0 -59
  157. package/src/host/review-history.ts +0 -168
  158. package/src/host/review-marker.ts +0 -25
  159. package/src/host/review-signals.ts +0 -83
  160. package/src/host/scope-split-tool.ts +0 -109
  161. package/src/host/search-tool.ts +0 -152
  162. package/src/host/skill-provider.ts +0 -94
  163. package/src/host/skills-tool.ts +0 -218
  164. package/src/host/source.ts +0 -26
  165. package/src/host/tool-policy.ts +0 -49
  166. package/templates/reviewer-project.gitlab-ci.yml +0 -93
  167. package/templates/source-project.gitlab-ci.yml +0 -48
@@ -1,190 +0,0 @@
1
- import { join, resolve, sep, basename } from 'node:path'
2
- import { readFile, readdir, realpath, stat } from 'node:fs/promises'
3
- import type { Context } from '@deepseek-ai/cordis'
4
- import z from '@deepseek-ai/schemastery'
5
- import { defineTool } from '@deepseek-ai/dsh-tools'
6
-
7
- export const name = 'maestro-layout-xml-tool'
8
- export const inject = ['tools']
9
- export const Config: z<{ rootPath?: string }> = z.object({ rootPath: z.string() })
10
-
11
- interface SessionCwdSource { agent?: { session?: { header?: { cwd?: string } } } }
12
- function workspaceRootFor(c:string|undefined, exec:unknown):string{
13
- if(c!==undefined) return c
14
- const cwd=(exec as SessionCwdSource|undefined)?.agent?.session?.header?.cwd
15
- return typeof cwd==='string' && cwd!=='' ? cwd : process.cwd()
16
- }
17
- async function isInsideRoot(root:string, target:string):Promise<boolean>{
18
- const ar=resolve(root); const rs=resolve(ar,target)
19
- if(rs!==ar && !rs.startsWith(ar+sep)) return false
20
- try{ const rr=await realpath(ar); const rt=await realpath(rs); return rt===rr || rt.startsWith(rr+sep)}catch{return false}
21
- }
22
- const MAX_FILE_BYTES=1024*1024
23
- const MAX_FILES=2000
24
- const SKIP_DIRS=new Set(['.git','node_modules','vendor','pub/static'])
25
-
26
- // tiny helpers
27
- function parseAttrs(s:string):Record<string,string>{
28
- const out:Record<string,string>={}
29
- let m:RegExpExecArray|null
30
- const re=/(\w+)="([^"]*)"/g
31
- while((m=re.exec(s))!==null) out[m[1]]=m[2]
32
- return out
33
- }
34
- async function exists(p:string):Promise<boolean>{ try{await stat(p); return true}catch{return false}}
35
- async function* walkLayout(dir:string, root:string, budget:{files:number}):AsyncGenerator<string>{
36
- if(budget.files<=0) return
37
- let entries
38
- try{ entries=await readdir(dir,{withFileTypes:true})}catch{return}
39
- for(const e of entries){
40
- if(budget.files<=0) return
41
- if(e.isDirectory()){
42
- if(SKIP_DIRS.has(e.name)) continue
43
- yield* walkLayout(join(dir,e.name), root, budget)
44
- continue
45
- }
46
- if(!e.isFile()) continue
47
- if(!e.name.endsWith('.xml')) continue
48
- if(!join(dir,e.name).includes('/layout/')) continue
49
- budget.files-=1
50
- yield join(dir,e.name)
51
- }
52
- }
53
-
54
- export function apply(ctx:Context, config:{rootPath?:string}={}):void{
55
- const configuredRoot=config.rootPath
56
- ctx.effect(()=>ctx.tools.register(defineTool({
57
- name:'layout_xml_extract',
58
- description:'Extract Magento layout handles/blocks/moves/head from layout XML under workspace. Use before claiming layout is correct.',
59
- parameters:{
60
- root:{type:'string'},
61
- changedFiles:{type:'array', items:{type:'string'}},
62
- },
63
- output:{
64
- schema:{
65
- type:'object', additionalProperties:false,
66
- properties:{
67
- handles:{type:'array', required:true},
68
- handleCount:{type:'number', required:true},
69
- blockCount:{type:'number', required:true},
70
- scannedFiles:{type:'number', required:true},
71
- truncated:{type:'boolean', required:true},
72
- }
73
- },
74
- render:(_args,v)=>[{type:'text', text: JSON.stringify(v,null,2)}],
75
- },
76
- async execute(args, exec){
77
- const rawRoot=(args as {root?:string}).root ?? ''
78
- const root=workspaceRootFor(configuredRoot, exec)
79
- if(rawRoot!=='' && !(await isInsideRoot(root, rawRoot))) return {text:`Path "${rawRoot}" escapes the workspace root.`, truncated:false} as never
80
- const effectiveRoot = rawRoot==='' ? root : resolve(root, rawRoot)
81
- const changedFiles=(args as {changedFiles?:string[]}).changedFiles
82
- if(changedFiles){
83
- for(const p of changedFiles){
84
- if(!(await isInsideRoot(effectiveRoot, p))) return {text:`Path "${p}" escapes the workspace root.`, truncated:false} as never
85
- }
86
- }
87
- // collect files
88
- const budget={files:MAX_FILES}
89
- const all:string[]=[]
90
- for await(const f of walkLayout(effectiveRoot, effectiveRoot, budget)){
91
- const rel=f.startsWith(effectiveRoot+sep)? f.slice(effectiveRoot.length+1): basename(f)
92
- all.push(rel)
93
- }
94
- let files=all
95
- if(changedFiles && changedFiles.length>0){
96
- const set=new Set(changedFiles.map(p=>p.endsWith('.xml')?p:p))
97
- files=all.filter(p=> set.has(p) || changedFiles.some(cf=> p.endsWith(basename(cf))))
98
- // also if allow-list contains files not discovered via walk (e.g., outside layout but still layout), include them if they exist and are layout
99
- for(const cf of changedFiles){
100
- if(!files.includes(cf)){
101
- const abs=resolve(effectiveRoot, cf)
102
- if(await exists(abs) && cf.includes('/layout/') && cf.endsWith('.xml') && !(all.includes(cf))) files.push(cf)
103
- }
104
- }
105
- }
106
- const truncated = budget.files<=0
107
- const handles:Array<{file:string,handle:string,layoutType:string,blocks:Array<{name:string|null,type:string,class:string|null,template:string|null,templateExists:boolean|null,as:string|null,cacheable:boolean|null,remove:boolean,refs:string[]}>,moves:Array<{element:string,destination:string|null,as:string|null,before:string|null,after:string|null}>,references:Array<{kind:string,name:string,attrs:Record<string,string>}>,head:{scripts:Array<{src:string}>,css:Array<{src:string}>,metas:Array<Record<string,string>>,removes:Array<string>},parseError:string|null}>=[]
108
- let blockCount=0
109
- for(const rel of files){
110
- const abs=resolve(effectiveRoot, rel)
111
- let text:string
112
- try{
113
- const buf=await readFile(abs)
114
- if(buf.byteLength>MAX_FILE_BYTES) continue
115
- text=buf.toString('utf-8')
116
- }catch{continue}
117
- const handle=basename(rel,'.xml')
118
- const layoutType=/<page\b/.test(text)?'page':'generic'
119
- // quick parseError heuristic: mismatched < vs > or unclosed tag
120
- let parseError:string|null=null
121
- const openCount=(text.match(/</g)||[]).length
122
- const closeCount=(text.match(/>/g)||[]).length
123
- if(openCount!==closeCount) parseError=`mismatched < (${openCount}) vs > (${closeCount})`
124
- // also detect block tag without closing >
125
- if(/<block[^>]*$/m.test(text) || /<block[^>]*<\/body/.test(text)) parseError=parseError ?? 'malformed block tag'
126
- if(parseError){
127
- handles.push({file:rel,handle,layoutType,blocks:[],moves:[],references:[],head:{scripts:[],css:[],metas:[],removes:[]},parseError})
128
- continue
129
- }
130
- const blocks:Array<{name:string|null,type:string,class:string|null,template:string|null,templateExists:boolean|null,as:string|null,cacheable:boolean|null,remove:boolean,refs:string[]}>=[]
131
- const moves:Array<{element:string,destination:string|null,as:string|null,before:string|null,after:string|null}>=[]
132
- const references:Array<{kind:string,name:string,attrs:Record<string,string>}>=[]
133
- const head={scripts:[] as Array<{src:string}>, css:[] as Array<{src:string}>, metas:[] as Array<Record<string,string>>, removes:[] as string[]}
134
- // blocks/containers (only concrete)
135
- const tagRe=/<(block|container)\b([^>]*?)(?:\/>|>)/g
136
- let m:RegExpExecArray|null
137
- while((m=tagRe.exec(text))!==null){
138
- const type=m[1]; const attrStr=m[2]; const attrs=parseAttrs(attrStr)
139
- const name=attrs.name ?? null
140
- const klass=attrs.class ?? null
141
- const template=attrs.template ?? null
142
- let templateExists:boolean|null=null
143
- if(template!==null){
144
- if(template.includes('::')){
145
- const [modPart, filePart]=template.split('::')
146
- const [vendor, mod]=modPart.split('_')
147
- if(vendor && mod && filePart){
148
- const cand=join(effectiveRoot, `app/code/${vendor}/${mod}/view/frontend/templates/${filePart}`)
149
- templateExists=await exists(cand)
150
- if(!templateExists){
151
- templateExists=false
152
- }
153
- } else templateExists=false
154
- } else {
155
- templateExists=await exists(join(effectiveRoot, template))
156
- }
157
- }
158
- const as=attrs.as ?? null
159
- const cacheable=attrs.cacheable ? attrs.cacheable==='true' : null
160
- const remove=attrs.remove==='true'
161
- blocks.push({name, type, class:klass, template, templateExists, as, cacheable, remove, refs:[]})
162
- }
163
- // references
164
- const refRe=/(<(referenceBlock|referenceContainer)\b([^>]*?)(?:\/>|>))/g
165
- while((m=refRe.exec(text))!==null){
166
- const type=m[2]; const attrs=parseAttrs(m[3])
167
- references.push({kind:type, name: attrs.name ?? '', attrs})
168
- }
169
- // moves
170
- const moveRe=/<move\b([^>]*?)\/>/g
171
- while((m=moveRe.exec(text))!==null){
172
- const attrs=parseAttrs(m[1])
173
- moves.push({element:attrs.element ?? '', destination:attrs.destination ?? null, as:attrs.as ?? null, before:attrs.before ?? null, after:attrs.after ?? null})
174
- }
175
- // head css/scripts
176
- const cssRe=/<css\b([^>]*?)\/>/g
177
- while((m=cssRe.exec(text))!==null){ const a=parseAttrs(m[1]); if(a.src) head.css.push({src:a.src}) }
178
- const scriptRe=/<script\b([^>]*?)\/>/g
179
- while((m=scriptRe.exec(text))!==null){ const a=parseAttrs(m[1]); if(a.src) head.scripts.push({src:a.src}) }
180
- // also <remove src=>
181
- const removeRe=/<remove\b([^>]*?)\/>/g
182
- while((m=removeRe.exec(text))!==null){ const a=parseAttrs(m[1]); if(a.src) head.removes.push(a.src) }
183
-
184
- blockCount+=blocks.length
185
- handles.push({file:rel,handle,layoutType,blocks,moves,references,head,parseError:null})
186
- }
187
- return {handles, handleCount:handles.length, blockCount, scannedFiles:files.length, truncated} as never
188
- },
189
- }), 'layout xml'))
190
- }
@@ -1,187 +0,0 @@
1
- import { join, resolve, sep } from 'node:path'
2
- import { readFile, readdir, realpath, stat } from 'node:fs/promises'
3
- import type { Context } from '@deepseek-ai/cordis'
4
- import z from '@deepseek-ai/schemastery'
5
- import { defineTool } from '@deepseek-ai/dsh-tools'
6
-
7
- export const name='maestro-module-check-tool'
8
- export const inject=['tools']
9
- export const Config:z<{rootPath?:string}>=z.object({rootPath:z.string()})
10
- interface SC{agent?:{session?:{header?:{cwd?:string}}}}
11
- function workspaceRootFor(c:string|undefined,e:unknown):string{
12
- if(c!==undefined) return c
13
- const cwd=(e as SC|undefined)?.agent?.session?.header?.cwd
14
- return typeof cwd==='string'&&cwd!==''?cwd:process.cwd()
15
- }
16
- async function isInsideRoot(r:string,t:string):Promise<boolean>{
17
- const ar=resolve(r); const rs=resolve(ar,t)
18
- if(rs!==ar && !rs.startsWith(ar+sep)) return false
19
- try{ const rr=await realpath(ar); const rt=await realpath(rs); return rt===rr||rt.startsWith(rr+sep)}catch{return false}
20
- }
21
- const MAX_FILE_BYTES=1024*1024
22
- const MAX_MODULES=100
23
- async function exists(p:string):Promise<boolean>{ try{await stat(p); return true}catch{return false}}
24
- async function boundedRead(p:string):Promise<string|null>{
25
- try{ const b=await readFile(p); if(b.byteLength>MAX_FILE_BYTES) return null; return b.toString('utf-8')}catch{return null}
26
- }
27
- function parseRegistrationName(text:string):string|null{
28
- const re=/(?:\\?[\w\\]*ComponentRegistrar)::register\s*\(\s*(?:\\?[\w\\]*ComponentRegistrar::)?MODULE\s*,\s*['"]([^'"]+)['"]/
29
- const m=re.exec(text); return m?m[1]:null
30
- }
31
- function parseModuleXml(text:string):{name:string|null, sequence:string[]}{
32
- const nameRe=/<module\b[^>]*name="([^"]+)"/
33
- const nm=nameRe.exec(text); const name=nm?nm[1]:null
34
- const seq:string[]=[]; const seqRe=/<module\s+name="([^"]+)"\s*\/>/g; let m:RegExpExecArray|null
35
- // only inside <sequence> block
36
- const seqBlock=/<sequence>([\s\S]*?)<\/sequence>/.exec(text)
37
- if(seqBlock){ const inner=seqBlock[1]; while((m=seqRe.exec(inner))!==null) seq.push(m[1]) }
38
- return {name, sequence:seq}
39
- }
40
-
41
- export function apply(ctx:Context, config:{rootPath?:string}={}):void{
42
- const configuredRoot=config.rootPath
43
- ctx.effect(()=>ctx.tools.register(defineTool({
44
- name:'magento_module_check',
45
- description:'Validate Magento 2 module structure (registration, module.xml, composer, db_schema, acl, routes, Hyva compat).',
46
- parameters:{
47
- modulePath:{type:'string'},
48
- },
49
- output:{
50
- schema:{
51
- type:'object', additionalProperties:false,
52
- properties:{
53
- modules:{type:'array', required:true},
54
- scannedModules:{type:'number', required:true},
55
- truncated:{type:'boolean', required:true},
56
- }
57
- },
58
- render:(_a,v)=>[{type:'text', text: JSON.stringify(v,null,2)}],
59
- },
60
- async execute(args, exec){
61
- const rawPath=(args as {modulePath?:string}).modulePath
62
- const root=workspaceRootFor(configuredRoot, exec)
63
- if(rawPath!==undefined && !(await isInsideRoot(root, rawPath))) return {text:`Path "${rawPath}" escapes the workspace root.`, truncated:false} as never
64
- let candidates:string[]=[]
65
- if(rawPath!==undefined){
66
- // must contain registration.php or etc/module.xml to be considered a module; otherwise empty
67
- candidates=[rawPath]
68
- } else {
69
- const base=join(root,'app/code')
70
- let vendors:string[]=[]
71
- try{ vendors=await readdir(base)}catch{ vendors=[]}
72
- for(const vendor of vendors){
73
- if(vendor.startsWith('.')) continue
74
- let mods:string[]=[]
75
- try{ mods=await readdir(join(base,vendor))}catch{continue}
76
- for(const mod of mods){
77
- if(mod.startsWith('.')) continue
78
- candidates.push(join('app/code',vendor,mod))
79
- if(candidates.length>=MAX_MODULES) break
80
- }
81
- if(candidates.length>=MAX_MODULES) break
82
- }
83
- }
84
- const truncated=candidates.length>=MAX_MODULES
85
- const modules:Array<{
86
- path:string,
87
- module:{name:string|null,sequence:string[],hasRegistration:boolean,registrationValid:boolean|null,hasEtcModuleXml:boolean,hasDbSchema:boolean,dbSchemaTables:string[],hasAcl:boolean,aclResources:string[],hasRoutes:boolean,routes:Array<{area:string,frontName:string}>,hasObserverEvents:string[],hasCron:boolean,hasWebapi:boolean,apiInterfaces:string[],composerName:string|null,psr4:Record<string,string>|null},
88
- issues:Array<{severity:string,rule:string,message:string,file:string,line:number|null}>,
89
- isHyvaCompatible:boolean|null, compatNotes:string[]
90
- }>=[]
91
- for(const rel of candidates.slice(0,MAX_MODULES)){
92
- const abs=resolve(root, rel)
93
- let isDir=false; try{ const s=await stat(abs); isDir=s.isDirectory()}catch{ continue}
94
- if(!isDir) continue
95
- const issues: Array<{severity:string,rule:string,message:string,file:string,line:number|null}>=[]
96
- const regText=await boundedRead(join(abs,'registration.php'))
97
- const hasRegistration=regText!==null
98
- let regName:string|null=null
99
- let registrationValid:boolean|null=null
100
- if(hasRegistration){
101
- regName=parseRegistrationName(regText!)
102
- registrationValid=regName!==null
103
- if(!registrationValid) issues.push({severity:'high', rule:'registration-invalid', message:'registration.php does not contain ComponentRegistrar::register for MODULE', file:join(rel,'registration.php'), line:null})
104
- } else {
105
- issues.push({severity:'critical', rule:'registration-missing', message:'registration.php missing', file:join(rel,'registration.php'), line:null})
106
- }
107
- const modXmlText=await boundedRead(join(abs,'etc/module.xml'))
108
- const hasEtcModuleXml=modXmlText!==null
109
- let modName:string|null=null
110
- let sequence:string[]=[]
111
- if(hasEtcModuleXml){
112
- const parsed=parseModuleXml(modXmlText!)
113
- modName=parsed.name; sequence=parsed.sequence
114
- if(!modName) issues.push({severity:'critical', rule:'module-xml-missing-name', message:'etc/module.xml missing module name', file:join(rel,'etc/module.xml'), line:null})
115
- } else {
116
- issues.push({severity:'high', rule:'module-xml-missing', message:'etc/module.xml missing', file:join(rel,'etc/module.xml'), line:null})
117
- }
118
- if(regName && modName && regName!==modName){
119
- issues.push({severity:'high', rule:'name-mismatch', message:`registration name ${regName} != module.xml ${modName}`, file:join(rel,'etc/module.xml'), line:null})
120
- }
121
- // composer
122
- const composerText=await boundedRead(join(abs,'composer.json'))
123
- let composerName:string|null=null; let psr4:Record<string,string>|null=null
124
- if(composerText){
125
- try{ const j=JSON.parse(composerText); composerName=j.name??null; psr4=j.autoload?.['psr-4']??null }catch{}
126
- if(composerName && modName){
127
- // psr-4 cross-check not strict for test
128
- }
129
- }
130
- // db_schema
131
- const hasDbSchema=await exists(join(abs,'etc/db_schema.xml'))
132
- let dbSchemaTables:string[]=[]
133
- if(hasDbSchema){
134
- const dbText=await boundedRead(join(abs,'etc/db_schema.xml'))
135
- if(dbText){ const re=/<table\s+name="([^"]+)"/g; let m:RegExpExecArray|null; while((m=re.exec(dbText))!==null) dbSchemaTables.push(m[1])}
136
- }
137
- // acl
138
- const hasAcl=await exists(join(abs,'etc/acl.xml'))
139
- let aclResources:string[]=[]
140
- if(hasAcl){ const t=await boundedRead(join(abs,'etc/acl.xml')); if(t){ const re=/<resource\s+id="([^"]+)"/g; let m:RegExpExecArray|null; while((m=re.exec(t))!==null) aclResources.push(m[1])}}
141
- // routes
142
- let hasRoutes=false; const routes:Array<{area:string,frontName:string}>=[]
143
- for(const area of ['frontend','adminhtml']){
144
- const rp=join(abs,`etc/${area}/routes.xml`); if(await exists(rp)){ hasRoutes=true; const rt=await boundedRead(rp); if(rt){ const re=/<route\s+[^>]*frontName="([^"]+)"/g; let m:RegExpExecArray|null; while((m=re.exec(rt))!==null) routes.push({area, frontName:m[1]}) } }
145
- }
146
- if(await exists(join(abs,'etc/routes.xml'))){ hasRoutes=true }
147
- // events
148
- let hasObserverEvents:string[]=[]
149
- const evText=await boundedRead(join(abs,'etc/events.xml'))
150
- if(evText){ const re=/<event\s+name="([^"]+)"/g; let m:RegExpExecArray|null; while((m=re.exec(evText))!==null) hasObserverEvents.push(m[1])}
151
- // cron/webapi
152
- const hasCron=await exists(join(abs,'etc/crontab.xml')) || await exists(join(abs,'etc/cron_groups.xml'))
153
- const hasWebapi=await exists(join(abs,'etc/webapi.xml'))
154
- let apiInterfaces:string[]=[]
155
- if(hasWebapi){ const t=await boundedRead(join(abs,'etc/webapi.xml')); if(t){ const re=/<service\s+class="([^"]+)"/g; let m:RegExpExecArray|null; while((m=re.exec(t))!==null) apiInterfaces.push(m[1])}}
156
-
157
- // Hyva compat: scan phtml for data-bind vs x-data
158
- let isHyvaCompatible:boolean|null=null
159
- const compatNotes:string[]=[]
160
- let hasPhtml=false; let hasDataBind=false; let hasXData=false
161
- async function scanPhtml(dir:string){
162
- let entries; try{entries=await readdir(dir,{withFileTypes:true})}catch{return}
163
- for(const e of entries){
164
- if(e.isDirectory()) await scanPhtml(join(dir,e.name))
165
- else if(e.isFile() && e.name.endsWith('.phtml')){
166
- hasPhtml=true
167
- const txt=await boundedRead(join(dir,e.name))
168
- if(!txt) continue
169
- if(/data-bind\s*=/.test(txt)) hasDataBind=true
170
- if(/x-data\s*=/.test(txt)) hasXData=true
171
- }
172
- }
173
- }
174
- await scanPhtml(join(abs,'view/frontend/templates'))
175
- if(hasPhtml){
176
- if(hasDataBind){ isHyvaCompatible=false; compatNotes.push('knockout data-bind found — not Hyva compatible')}
177
- else if(hasXData){ isHyvaCompatible=true; compatNotes.push('Alpine x-data found — Hyva compatible')}
178
- else { isHyvaCompatible=null }
179
- }
180
-
181
- const moduleInfo={name: modName ?? regName, sequence, hasRegistration, registrationValid, hasEtcModuleXml, hasDbSchema, dbSchemaTables, hasAcl, aclResources, hasRoutes, routes, hasObserverEvents, hasCron, hasWebapi, apiInterfaces, composerName, psr4}
182
- modules.push({path:rel, module:moduleInfo, issues, isHyvaCompatible, compatNotes})
183
- }
184
- return {modules, scannedModules: modules.length, truncated} as never
185
- },
186
- }), 'module check'))
187
- }