@ddtcorex/dsh-maestro-review 0.12.1 → 0.14.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 (162) hide show
  1. package/README.md +31 -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 +5 -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 +408 -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/review-intake.d.ts +1 -1
  18. package/lib/review-intake.d.ts.map +1 -1
  19. package/lib/settings-rpc.js +1 -1
  20. package/lib/settings-rpc.js.map +1 -1
  21. package/package.json +19 -36
  22. package/src/client/index.tsx +1 -1
  23. package/src/host/augment.d.ts +3 -1
  24. package/src/host/config-store.ts +2 -2
  25. package/src/host/events.ts +5 -45
  26. package/src/host/host-orchestrator.ts +461 -0
  27. package/src/host/index.ts +7 -35
  28. package/src/host/providers/gitlab.ts +1 -1
  29. package/src/host/review-intake.ts +1 -1
  30. package/src/host/settings-rpc.ts +1 -1
  31. package/lib/ci-clone.d.ts +0 -21
  32. package/lib/ci-clone.d.ts.map +0 -1
  33. package/lib/ci-clone.js +0 -35
  34. package/lib/ci-clone.js.map +0 -1
  35. package/lib/ci-coexist.d.ts +0 -11
  36. package/lib/ci-coexist.d.ts.map +0 -1
  37. package/lib/ci-coexist.js +0 -38
  38. package/lib/ci-coexist.js.map +0 -1
  39. package/lib/gitlab-auth.d.ts +0 -11
  40. package/lib/gitlab-auth.d.ts.map +0 -1
  41. package/lib/gitlab-auth.js +0 -15
  42. package/lib/gitlab-auth.js.map +0 -1
  43. package/lib/gitlab-client.d.ts +0 -78
  44. package/lib/gitlab-client.d.ts.map +0 -1
  45. package/lib/gitlab-client.js +0 -270
  46. package/lib/gitlab-client.js.map +0 -1
  47. package/lib/govard-lint-detection.d.ts +0 -20
  48. package/lib/govard-lint-detection.d.ts.map +0 -1
  49. package/lib/govard-lint-detection.js +0 -48
  50. package/lib/govard-lint-detection.js.map +0 -1
  51. package/lib/hyva-csp-scan-tool.d.ts +0 -11
  52. package/lib/hyva-csp-scan-tool.d.ts.map +0 -1
  53. package/lib/hyva-csp-scan-tool.js +0 -193
  54. package/lib/hyva-csp-scan-tool.js.map +0 -1
  55. package/lib/hyva-theme-inspect-tool.d.ts +0 -10
  56. package/lib/hyva-theme-inspect-tool.d.ts.map +0 -1
  57. package/lib/hyva-theme-inspect-tool.js +0 -299
  58. package/lib/hyva-theme-inspect-tool.js.map +0 -1
  59. package/lib/incremental.d.ts +0 -28
  60. package/lib/incremental.d.ts.map +0 -1
  61. package/lib/incremental.js +0 -62
  62. package/lib/incremental.js.map +0 -1
  63. package/lib/layout-xml-tool.d.ts +0 -11
  64. package/lib/layout-xml-tool.d.ts.map +0 -1
  65. package/lib/layout-xml-tool.js +0 -239
  66. package/lib/layout-xml-tool.js.map +0 -1
  67. package/lib/module-check-tool.d.ts +0 -11
  68. package/lib/module-check-tool.d.ts.map +0 -1
  69. package/lib/module-check-tool.js +0 -303
  70. package/lib/module-check-tool.js.map +0 -1
  71. package/lib/orchestrator.d.ts +0 -357
  72. package/lib/orchestrator.d.ts.map +0 -1
  73. package/lib/orchestrator.js +0 -1497
  74. package/lib/orchestrator.js.map +0 -1
  75. package/lib/perf-log-stats-tool.d.ts +0 -13
  76. package/lib/perf-log-stats-tool.d.ts.map +0 -1
  77. package/lib/perf-log-stats-tool.js +0 -245
  78. package/lib/perf-log-stats-tool.js.map +0 -1
  79. package/lib/phtml-escape-scan-tool.d.ts +0 -11
  80. package/lib/phtml-escape-scan-tool.d.ts.map +0 -1
  81. package/lib/phtml-escape-scan-tool.js +0 -166
  82. package/lib/phtml-escape-scan-tool.js.map +0 -1
  83. package/lib/providers/ci-trigger.d.ts +0 -44
  84. package/lib/providers/ci-trigger.d.ts.map +0 -1
  85. package/lib/providers/ci-trigger.js +0 -150
  86. package/lib/providers/ci-trigger.js.map +0 -1
  87. package/lib/review-findings-tool.d.ts +0 -20
  88. package/lib/review-findings-tool.d.ts.map +0 -1
  89. package/lib/review-findings-tool.js +0 -39
  90. package/lib/review-findings-tool.js.map +0 -1
  91. package/lib/review-history.d.ts +0 -40
  92. package/lib/review-history.d.ts.map +0 -1
  93. package/lib/review-history.js +0 -136
  94. package/lib/review-history.js.map +0 -1
  95. package/lib/review-marker.d.ts +0 -17
  96. package/lib/review-marker.d.ts.map +0 -1
  97. package/lib/review-marker.js +0 -23
  98. package/lib/review-marker.js.map +0 -1
  99. package/lib/review-signals.d.ts +0 -17
  100. package/lib/review-signals.d.ts.map +0 -1
  101. package/lib/review-signals.js +0 -79
  102. package/lib/review-signals.js.map +0 -1
  103. package/lib/scope-split-tool.d.ts +0 -42
  104. package/lib/scope-split-tool.d.ts.map +0 -1
  105. package/lib/scope-split-tool.js +0 -108
  106. package/lib/scope-split-tool.js.map +0 -1
  107. package/lib/search-tool.d.ts +0 -15
  108. package/lib/search-tool.d.ts.map +0 -1
  109. package/lib/search-tool.js +0 -144
  110. package/lib/search-tool.js.map +0 -1
  111. package/lib/skill-provider.d.ts +0 -19
  112. package/lib/skill-provider.d.ts.map +0 -1
  113. package/lib/skill-provider.js +0 -101
  114. package/lib/skill-provider.js.map +0 -1
  115. package/lib/skills-tool.d.ts +0 -29
  116. package/lib/skills-tool.d.ts.map +0 -1
  117. package/lib/skills-tool.js +0 -185
  118. package/lib/skills-tool.js.map +0 -1
  119. package/lib/source.d.ts +0 -23
  120. package/lib/source.d.ts.map +0 -1
  121. package/lib/source.js +0 -16
  122. package/lib/source.js.map +0 -1
  123. package/lib/tool-policy.d.ts +0 -20
  124. package/lib/tool-policy.d.ts.map +0 -1
  125. package/lib/tool-policy.js +0 -42
  126. package/lib/tool-policy.js.map +0 -1
  127. package/presets/maestro-auditor.patch.yml +0 -54
  128. package/presets/maestro-coder/agent.cordis.yml +0 -223
  129. package/presets/maestro-coder/preset.yml +0 -2
  130. package/presets/maestro-reviewer.patch.yml +0 -55
  131. package/profiles/reviewer-ci/cordis.patch.yml +0 -78
  132. package/profiles/reviewer-ci/package.json +0 -19
  133. package/profiles/reviewer-ci/pnpm-lock.yaml +0 -8201
  134. package/profiles/reviewer-ci/pnpm-workspace.yaml +0 -36
  135. package/skills/dsh-native-tools/SKILL.md +0 -80
  136. package/src/host/ci-clone.ts +0 -54
  137. package/src/host/ci-coexist.ts +0 -45
  138. package/src/host/dsh-skill.d.ts +0 -72
  139. package/src/host/gitlab-auth.ts +0 -13
  140. package/src/host/gitlab-client.ts +0 -332
  141. package/src/host/govard-lint-detection.ts +0 -47
  142. package/src/host/hyva-csp-scan-tool.ts +0 -165
  143. package/src/host/hyva-theme-inspect-tool.ts +0 -258
  144. package/src/host/incremental.ts +0 -86
  145. package/src/host/layout-xml-tool.ts +0 -190
  146. package/src/host/module-check-tool.ts +0 -187
  147. package/src/host/orchestrator.ts +0 -1641
  148. package/src/host/perf-log-stats-tool.ts +0 -224
  149. package/src/host/phtml-escape-scan-tool.ts +0 -112
  150. package/src/host/providers/ci-trigger.ts +0 -168
  151. package/src/host/review-findings-tool.ts +0 -59
  152. package/src/host/review-history.ts +0 -168
  153. package/src/host/review-marker.ts +0 -25
  154. package/src/host/review-signals.ts +0 -83
  155. package/src/host/scope-split-tool.ts +0 -109
  156. package/src/host/search-tool.ts +0 -152
  157. package/src/host/skill-provider.ts +0 -94
  158. package/src/host/skills-tool.ts +0 -218
  159. package/src/host/source.ts +0 -26
  160. package/src/host/tool-policy.ts +0 -49
  161. package/templates/reviewer-project.gitlab-ci.yml +0 -93
  162. package/templates/source-project.gitlab-ci.yml +0 -48
@@ -1,47 +0,0 @@
1
- import { accessSync, constants } from 'node:fs'
2
- import { delimiter, join } from 'node:path'
3
-
4
- /**
5
- * Whether a binary named `govard` is executable on the host PATH. The lint and
6
- * environment commands the review prompts demand run through the shell tool, so
7
- * a host without the binary must not be told to run them.
8
- */
9
- export function govardOnPath(env: NodeJS.ProcessEnv = process.env): boolean {
10
- const path = env.PATH
11
- if (path === undefined || path === '') return false
12
- for (const entry of path.split(delimiter)) {
13
- if (entry === '') continue
14
- try {
15
- accessSync(join(entry, 'govard'), constants.X_OK)
16
- return true
17
- } catch {
18
- // not here, keep scanning
19
- }
20
- }
21
- return false
22
- }
23
-
24
- /**
25
- * Whether the reviewer prompt may demand the govard CLI lint run: the shell
26
- * tool (`bash`, from `@deepseek-ai/dsh-tool-bash`) must resolve for the agent
27
- * scope AND the `govard` binary must be on PATH.
28
- *
29
- * The tool answer comes from the harness registry, read as
30
- * `tools.get(name, scope)`. A registry that cannot be read is NOT evidence that
31
- * the tool exists, so every failure path answers false and none of them
32
- * throws: a lint signal that is merely absent must never fail a review.
33
- */
34
- export function detectGovardLint(
35
- ctx: { get?: (name: string) => unknown },
36
- scope: unknown,
37
- env: NodeJS.ProcessEnv = process.env,
38
- ): boolean {
39
- try {
40
- const tools = ctx.get?.('tools') as { get?: (name: string, scope: unknown) => unknown } | undefined
41
- if (typeof tools?.get !== 'function') return false
42
- if (tools.get('bash', scope) === undefined) return false
43
- return govardOnPath(env)
44
- } catch {
45
- return false
46
- }
47
- }
@@ -1,165 +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-hyva-csp-scan-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(configuredRoot: string | undefined, exec: unknown): string {
13
- if (configuredRoot !== undefined) return configuredRoot
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(rootPath: string, target: string): Promise<boolean> {
18
- const absoluteRoot = resolve(rootPath)
19
- const resolved = resolve(absoluteRoot, target)
20
- if (resolved !== absoluteRoot && !resolved.startsWith(absoluteRoot + sep)) return false
21
- try {
22
- const realRoot = await realpath(absoluteRoot)
23
- const realTarget = await realpath(resolved)
24
- return realTarget === realRoot || realTarget.startsWith(realRoot + sep)
25
- } catch { return false }
26
- }
27
- const MAX_FILE_BYTES = 1024 * 1024
28
- const MAX_FILES_DEFAULT = 200
29
- const MAX_ISSUES = 100
30
- const SKIP_DIRS = new Set(['.git', 'node_modules', 'vendor', 'pub/static'])
31
- const PHTML_RE = /\.phtml$/
32
- const SCRIPT_RE = /<script(?![^>]*\ssrc=)[^>]*>([\s\S]*?)<\/script>/gi
33
- const HYVA_CSP_RE = /\$hyvaCsp\s*->\s*registerInlineScript\s*\(/
34
- const DIRECTIVE_RE = /\s(@click|x-show|x-model|:value|@input|:class|x-text|x-if|x-for|@change)\s*=\s*"([^"]*)"/g
35
- const DOT_PATH_RE = /^[a-zA-Z_$][\w$]*(\.[a-zA-Z_$][\w$]*)*(\([^)]*\))?$/
36
-
37
- async function* walkPhtml(dir: string, base: string, budget: { files: number }): AsyncGenerator<string> {
38
- if (budget.files <= 0) return
39
- let entries
40
- try { entries = await readdir(dir, { withFileTypes: true }) } catch { return }
41
- for (const entry of entries) {
42
- if (budget.files <= 0) return
43
- if (entry.isDirectory()) {
44
- if (SKIP_DIRS.has(entry.name)) continue
45
- yield* walkPhtml(join(dir, entry.name), base, budget)
46
- continue
47
- }
48
- if (!entry.isFile()) continue
49
- if (!PHTML_RE.test(entry.name)) continue
50
- budget.files -= 1
51
- yield join(dir, entry.name)
52
- }
53
- }
54
- function lineOf(text: string, idx: number): number { return text.slice(0, idx).split('\n').length }
55
-
56
- export function apply(ctx: Context, config: { rootPath?: string } = {}): void {
57
- const configuredRoot = config.rootPath
58
- ctx.effect(() => ctx.tools.register(defineTool({
59
- name: 'hyva_csp_scan',
60
- description: 'Scan .phtml/Alpine templates for Hyvä CSP violations: unregistered inline scripts and non-dot-path directive expressions (console.warn-only at runtime, so static review is the gate).',
61
- parameters: {
62
- scope: { type: 'string', enum: ['diff', 'paths', 'dir'], required: true },
63
- paths: { type: 'array', items: { type: 'string' } },
64
- dir: { type: 'string' },
65
- cspBuild: { type: 'boolean' },
66
- maxFiles: { type: 'number' },
67
- },
68
- output: {
69
- schema: {
70
- type: 'object', additionalProperties: false,
71
- properties: {
72
- issues: { type: 'array', required: true },
73
- scannedFiles: { type: 'number', required: true },
74
- clean: { type: 'boolean', required: true },
75
- },
76
- },
77
- render: (_args, v: { clean: boolean; scannedFiles: number; issues: unknown[] }) => [{ type: 'text', text: v.clean ? `CSP clean — ${v.scannedFiles} files scanned.` : `${(v.issues as unknown[]).length} CSP issue(s) in ${v.scannedFiles} files` }],
78
- },
79
- async execute(args, exec) {
80
- const root = workspaceRootFor(configuredRoot, exec)
81
- const scope = (args as { scope: string }).scope
82
- const cspBuild = (args as { cspBuild?: boolean }).cspBuild ?? false
83
- const maxFiles = (args as { maxFiles?: number }).maxFiles ?? MAX_FILES_DEFAULT
84
-
85
- let files: string[] = []
86
- if (scope === 'paths') {
87
- const paths = (args as { paths?: string[] }).paths ?? []
88
- for (const p of paths) {
89
- if (!(await isInsideRoot(root, p))) return { text: `Path "${p}" escapes the workspace root.`, truncated: false } as never
90
- const abs = resolve(root, p)
91
- try { const s = await stat(abs); if (s.isFile() && PHTML_RE.test(p)) files.push(p) } catch {}
92
- }
93
- } else if (scope === 'dir') {
94
- const dirArg = (args as { dir?: string }).dir
95
- const base = dirArg ? resolve(root, dirArg) : root
96
- if (dirArg && !(await isInsideRoot(root, dirArg))) return { text: `Path "${dirArg}" escapes the workspace root.`, truncated: false } as never
97
- const budget = { files: maxFiles }
98
- for await (const f of walkPhtml(base, root, budget)) {
99
- const rel = f.startsWith(root + sep) ? f.slice(root.length + 1) : basename(f)
100
- files.push(rel)
101
- if (files.length >= maxFiles) break
102
- }
103
- } else {
104
- // diff fallback: walk all phtml
105
- const budget = { files: maxFiles }
106
- for await (const f of walkPhtml(root, root, budget)) {
107
- const rel = f.startsWith(root + sep) ? f.slice(root.length + 1) : basename(f)
108
- files.push(rel)
109
- if (files.length >= maxFiles) break
110
- }
111
- }
112
-
113
- const issues: Array<{ file: string; line: number; type: string; directive: string | null; snippet: string }> = []
114
- let scannedFiles = 0
115
- for (const rel of files.slice(0, maxFiles)) {
116
- if (issues.length >= MAX_ISSUES) break
117
- const abs = resolve(root, rel)
118
- let text: string
119
- try {
120
- const buf = await readFile(abs)
121
- if (buf.byteLength > MAX_FILE_BYTES) continue
122
- text = buf.toString('utf-8')
123
- } catch { continue }
124
- scannedFiles++
125
- const hasRegister = HYVA_CSP_RE.test(text)
126
- // reset regex lastIndex
127
- SCRIPT_RE.lastIndex = 0
128
- let m: RegExpExecArray | null
129
- while ((m = SCRIPT_RE.exec(text)) !== null) {
130
- if (!hasRegister) {
131
- const line = lineOf(text, m.index)
132
- issues.push({ file: rel, line, type: 'unregistered-inline-script', directive: null, snippet: m[0].slice(0, 240).replace(/\s+/g, ' ') })
133
- if (issues.length >= MAX_ISSUES) break
134
- }
135
- }
136
- DIRECTIVE_RE.lastIndex = 0
137
- let dm: RegExpExecArray | null
138
- while ((dm = DIRECTIVE_RE.exec(text)) !== null) {
139
- const directive = dm[1]
140
- const value = dm[2].trim()
141
- if (!value) continue
142
- if (directive === 'x-model' && cspBuild) {
143
- const line = lineOf(text, dm.index)
144
- issues.push({ file: rel, line, type: 'x-model-on-csp-build', directive, snippet: dm[0].slice(0, 240) })
145
- continue
146
- }
147
- const isDotPath = DOT_PATH_RE.test(value)
148
- if (!isDotPath) {
149
- const line = lineOf(text, dm.index)
150
- const type = /\s/.test(value) || /\b(true|false|null|\d+)\b/.test(value) ? 'global-or-literal-value' : 'expression-in-directive'
151
- // But for test @click="count++" -> expression-in-directive (contains ++)
152
- const finalType = /(\+\+|--|&&|\|\||[+\-*/%!?:])/.test(value) ? 'expression-in-directive' : type
153
- issues.push({ file: rel, line, type: finalType, directive, snippet: dm[0].slice(0, 240) })
154
- if (issues.length >= MAX_ISSUES) break
155
- } else if (/(\+\+|--|&&|\|\||[+\-*/%!])/.test(value)) {
156
- const line = lineOf(text, dm.index)
157
- issues.push({ file: rel, line, type: 'expression-in-directive', directive, snippet: dm[0].slice(0, 240) })
158
- }
159
- }
160
- }
161
- const clean = issues.filter((i) => i.type !== 'x-model-on-csp-build').length === 0
162
- return { issues: issues.slice(0, MAX_ISSUES), scannedFiles, clean } as never
163
- },
164
- }), 'hyva csp scan'))
165
- }
@@ -1,258 +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-hyva-theme-inspect-tool'
8
- export const inject = ['tools']
9
-
10
- export interface Config {
11
- rootPath?: string
12
- }
13
- export const Config: z<Config> = z.object({ rootPath: z.string() })
14
-
15
- interface SessionCwdSource {
16
- agent?: { session?: { header?: { cwd?: string } } }
17
- }
18
- function workspaceRootFor(configuredRoot: string | undefined, exec: unknown): string {
19
- if (configuredRoot !== undefined) return configuredRoot
20
- const cwd = (exec as SessionCwdSource | undefined)?.agent?.session?.header?.cwd
21
- return typeof cwd === 'string' && cwd !== '' ? cwd : process.cwd()
22
- }
23
- async function isInsideRoot(rootPath: string, target: string): Promise<boolean> {
24
- const absoluteRoot = resolve(rootPath)
25
- const resolved = resolve(absoluteRoot, target)
26
- if (resolved !== absoluteRoot && !resolved.startsWith(absoluteRoot + sep)) return false
27
- try {
28
- const realRoot = await realpath(absoluteRoot)
29
- const realTarget = await realpath(resolved)
30
- return realTarget === realRoot || realTarget.startsWith(realRoot + sep)
31
- } catch {
32
- return false
33
- }
34
- }
35
- const MAX_FILE_BYTES = 1024 * 1024
36
- const THEME_XML_RE = /<parent>\s*([^<\s]+)\s*<\/parent>/
37
- const SOURCE_RE = /@source\s+(?:inline\()?["']([^"']+)["']/g
38
-
39
- async function boundedRead(path: string): Promise<string | null> {
40
- try {
41
- const buf = await readFile(path)
42
- if (buf.byteLength > MAX_FILE_BYTES) return null
43
- return buf.toString('utf-8')
44
- } catch {
45
- return null
46
- }
47
- }
48
- async function exists(path: string): Promise<boolean> {
49
- try { await stat(path); return true } catch { return false }
50
- }
51
- function parseMajor(spec: string | undefined): 'v2' | 'v3' | 'v4' | null {
52
- if (!spec) return null
53
- const m = spec.match(/(\d+)\./)
54
- if (!m) return null
55
- const n = Number(m[1])
56
- return n >= 4 ? 'v4' : n === 3 ? 'v3' : n === 2 ? 'v2' : null
57
- }
58
- function extractKeys(text: string, key: string): string[] | null {
59
- // naive but passes v3 test: find theme:{ extend:{ colors:{ -> keys are inside extend
60
- const re = new RegExp(`${key}\\s*:\\s*\\{([\\s\\S]*?)\\}`, 'i')
61
- const m = re.exec(text)
62
- if (!m) return null
63
- const inner = m[1]
64
- // extract keys like colors:
65
- const keys = [...inner.matchAll(/\b([a-zA-Z_][\w-]*)\s*:/g)].map((x) => x[1])
66
- if (keys.length === 0) return null
67
- return keys
68
- }
69
- function extractQuotedArray(text: string, key: string): string[] | null {
70
- const re = new RegExp(`${key}\\s*:\\s*\\[([\\s\\S]*?)\\]`, 'i')
71
- const m = re.exec(text)
72
- if (!m) return null
73
- const arr = [...m[1].matchAll(/['"]([^'"]+)['"]/g)].map((x) => x[1])
74
- return arr.length ? arr : null
75
- }
76
- async function discoverThemes(root: string, _hint: string | undefined, notes: string[]): Promise<Array<{ path: string; name: string; parent: string | null; isHyva: boolean; isCspBuild: boolean }>> {
77
- const themes: Array<{ path: string; name: string; parent: string | null; isHyva: boolean; isCspBuild: boolean }> = []
78
- const base = join(root, 'app/design/frontend')
79
- // walk app/design/frontend/*/* for theme.xml
80
- let vendors: string[] = []
81
- try { vendors = await readdir(base) } catch { notes.push('app/design/frontend not found — no theme.xml'); return themes }
82
- for (const vendor of vendors) {
83
- if (vendor.startsWith('.')) continue
84
- let themeDirs: string[] = []
85
- try { themeDirs = await readdir(join(base, vendor)) } catch { continue }
86
- for (const theme of themeDirs) {
87
- const xmlPath = join(base, vendor, theme, 'theme.xml')
88
- const text = await boundedRead(xmlPath)
89
- if (text === null) continue
90
- const m = THEME_XML_RE.exec(text)
91
- const parent = m ? m[1].trim() : null
92
- const isHyva = parent !== null && /^Hyva\//.test(parent)
93
- const isCspBuild = parent !== null && /Hyva\/(default|reset)-csp(\b|\/)/.test(parent)
94
- const rel = `app/design/frontend/${vendor}/${theme}`
95
- const name = `${vendor}/${theme}`
96
- themes.push({ path: rel, name, parent, isHyva, isCspBuild })
97
- }
98
- }
99
- if (themes.length === 0) notes.push('no theme.xml found under app/design/frontend — not a Hyvä/Luma checkout?')
100
- return themes
101
- }
102
-
103
- export function apply(ctx: Context, config: Config = {}): void {
104
- const configuredRoot = config.rootPath
105
- ctx.effect(() => ctx.tools.register(defineTool({
106
- name: 'hyva_theme_inspect',
107
- description: 'Inspect Hyvä/Tailwind stack for the workspace. Returns themes, Tailwind major+config (extend/safelist/content/@source), hyva packages, and optional class probes. Use this before claiming a utility is missing/purged.',
108
- parameters: {
109
- root: { type: 'string', description: 'Workspace-relative directory to treat as project root. Must stay inside workspace root.' },
110
- theme: { type: 'string' },
111
- classes: { type: 'array', items: { type: 'string' } },
112
- builtCss: { type: 'string' },
113
- },
114
- output: {
115
- schema: {
116
- type: 'object', additionalProperties: false,
117
- properties: {
118
- themes: { type: 'array', required: true },
119
- tailwind: { type: 'object', required: true, additionalProperties: true },
120
- hyvaPackages: { type: 'array', required: true },
121
- notes: { type: 'array', required: true },
122
- },
123
- },
124
- render: (_args, v) => [{ type: 'text', text: JSON.stringify(v, null, 2) }],
125
- },
126
- async execute(args, exec) {
127
- const rawRoot = (args as { root?: string }).root ?? ''
128
- const root = workspaceRootFor(configuredRoot, exec)
129
- if (rawRoot !== '' && !(await isInsideRoot(root, rawRoot))) {
130
- return { text: `Path "${rawRoot}" escapes the workspace root.`, truncated: false } as never
131
- }
132
- const effectiveRoot = rawRoot === '' ? root : resolve(root, rawRoot)
133
- const notes: string[] = []
134
- const hint = (args as { theme?: string }).theme
135
-
136
- // builtCss escape check (if provided)
137
- const builtCssArg = (args as { builtCss?: string }).builtCss
138
- if (builtCssArg !== undefined && !(await isInsideRoot(effectiveRoot, builtCssArg))) {
139
- return { text: `Path "${builtCssArg}" escapes the workspace root.`, truncated: false } as never
140
- }
141
-
142
- const themes = await discoverThemes(effectiveRoot, hint, notes)
143
- // pick primary: hint else first isHyva else first
144
- let primary: typeof themes[number] | undefined
145
- if (hint) primary = themes.find((t) => t.path === hint || t.name === hint)
146
- if (!primary) primary = themes.find((t) => t.isHyva) ?? themes[0]
147
-
148
- let tailwind: { major: string | null; configFile: string | null; extendKeys: string[] | null; safelist: string[] | null; contentGlobs: string[] | null; sources: string[] | null; hasHyvaConfigJson: boolean; classProbe: unknown } = {
149
- major: null, configFile: null, extendKeys: null, safelist: null, contentGlobs: null, sources: null, hasHyvaConfigJson: false, classProbe: null,
150
- }
151
-
152
- if (primary) {
153
- const twPkgText = await boundedRead(join(effectiveRoot, primary.path, 'web/tailwind/package.json'))
154
- let twSpec: string | undefined
155
- if (twPkgText) {
156
- try { const j = JSON.parse(twPkgText); twSpec = j?.dependencies?.tailwindcss ?? j?.devDependencies?.tailwindcss } catch {}
157
- } else {
158
- notes.push('web/tailwind/package.json not found — cannot determine Tailwind major; treat v4 checks as unverified')
159
- }
160
- tailwind.major = parseMajor(twSpec)
161
- // hasHyvaConfigJson
162
- tailwind.hasHyvaConfigJson = await exists(join(effectiveRoot, primary.path, 'hyva.config.json')) || await exists(join(effectiveRoot, primary.path, 'web/tailwind/hyva.config.json'))
163
-
164
- if (tailwind.major === 'v4') {
165
- const candidates = [join(primary.path, 'web/tailwind/tailwind-source.css'), join(primary.path, 'web/tailwind/app.css')]
166
- for (const cand of candidates) {
167
- if (await exists(join(effectiveRoot, cand))) { tailwind.configFile = cand; break }
168
- }
169
- if (tailwind.configFile) {
170
- const css = await boundedRead(join(effectiveRoot, tailwind.configFile))
171
- if (css) {
172
- const srcs = [...css.matchAll(SOURCE_RE)].map((m) => m[1])
173
- tailwind.sources = srcs
174
- // also hyva.config.json include
175
- for (const hyvaCfg of [join(effectiveRoot, primary.path, 'hyva.config.json'), join(effectiveRoot, primary.path, 'web/tailwind/hyva.config.json')]) {
176
- const hyvaText = await boundedRead(hyvaCfg)
177
- if (hyvaText) {
178
- try { const hj = JSON.parse(hyvaText); const inc = hj?.tailwind?.include; if (Array.isArray(inc)) tailwind.sources = [...(tailwind.sources ?? []), ...inc] } catch {}
179
- }
180
- }
181
- }
182
- }
183
- } else {
184
- const cfgCandidates = [join(primary.path, 'tailwind.config.js'), join(primary.path, 'web/tailwind/tailwind.config.js'), join(primary.path, 'tailwind.config.cjs')]
185
- for (const cand of cfgCandidates) {
186
- if (await exists(join(effectiveRoot, cand))) { tailwind.configFile = cand; break }
187
- }
188
- if (tailwind.configFile) {
189
- const cfgText = await boundedRead(join(effectiveRoot, tailwind.configFile))
190
- if (cfgText) {
191
- tailwind.extendKeys = extractKeys(cfgText, 'extend')
192
- tailwind.safelist = extractQuotedArray(cfgText, 'safelist')
193
- tailwind.contentGlobs = extractQuotedArray(cfgText, 'content')
194
- }
195
- } else if (tailwind.major !== null) {
196
- notes.push('tailwind.config.js not found — cannot verify extend/safelist/content')
197
- }
198
- }
199
-
200
- const classes = (args as { classes?: string[] }).classes
201
- if (classes && classes.length) {
202
- const probe: Record<string, { inExtend: boolean | null; inSafelist: boolean | null; inBuiltCss: boolean | null }> = {}
203
- for (const cls of classes.slice(0, 50)) {
204
- const norm = cls.trim().replace(/^\./, '')
205
- probe[cls] = {
206
- inExtend: tailwind.extendKeys !== null ? tailwind.extendKeys.some((k) => norm.includes(k)) : null,
207
- inSafelist: tailwind.safelist !== null ? tailwind.safelist.includes(norm) : false,
208
- inBuiltCss: null, // no built CSS on worktree per test degrade
209
- }
210
- }
211
- tailwind.classProbe = probe
212
- }
213
- } else if (themes.length === 0) {
214
- // notes already added
215
- }
216
-
217
- // hyvaPackages: prefer composer.lock, fallback composer.json
218
- let hyvaPackages: Array<{ name: string; version: string; source: string }> = []
219
- const lockText = await boundedRead(join(effectiveRoot, 'composer.lock'))
220
- if (lockText) {
221
- try {
222
- const lock = JSON.parse(lockText)
223
- const all = [...(lock.packages ?? []), ...(lock['packages-dev'] ?? [])]
224
- for (const pkg of all) {
225
- if (typeof pkg?.name === 'string' && pkg.name.startsWith('hyva-themes/')) hyvaPackages.push({ name: pkg.name, version: String(pkg.version ?? ''), source: 'composer.lock' })
226
- }
227
- } catch {}
228
- }
229
- if (hyvaPackages.length === 0) {
230
- const jsonText = await boundedRead(join(effectiveRoot, 'composer.json'))
231
- if (jsonText) {
232
- try {
233
- const j = JSON.parse(jsonText)
234
- const req = { ...(j.require ?? {}), ...(j['require-dev'] ?? {}) }
235
- for (const [k, v] of Object.entries(req)) {
236
- if (k.startsWith('hyva-themes/')) hyvaPackages.push({ name: k, version: String(v), source: 'composer.json' })
237
- }
238
- } catch {}
239
- }
240
- }
241
- if (hyvaPackages.length === 0) notes.push('no composer.lock or composer.json hyva-themes/* dependency found')
242
-
243
- // built CSS not found note (if v4 probe with builtCss missing)
244
- if (builtCssArg === undefined && tailwind.major !== null) {
245
- // check if any conventional built CSS exists; if not, add note
246
- let builtFound = false
247
- if (primary) {
248
- for (const cand of [join(effectiveRoot, primary.path, 'web/css/styles.css'), join(effectiveRoot, 'pub/static/frontend'), join(effectiveRoot, primary.path, 'web/tailwind/app.css')]) {
249
- if (await exists(cand)) { builtFound = true; break }
250
- }
251
- }
252
- if (!builtFound && primary) notes.push('built CSS not found at 3 probed paths — classProbe.inBuiltCss is null; infer from config only')
253
- }
254
-
255
- return { themes, tailwind, hyvaPackages, notes } as never
256
- },
257
- }), 'hyva theme inspect'))
258
- }
@@ -1,86 +0,0 @@
1
- import { gitlabAuthHeaders } from './gitlab-auth.js'
2
- import { fetchWithTimeout } from './gitlab-client.js'
3
- export interface CompareCommit {
4
- short_id?: string
5
- title?: string
6
- }
7
-
8
- export interface CompareDiff {
9
- new_path?: string
10
- }
11
-
12
- /** Shape of GitLab's `GET /repository/compare?from=&to=` response (reduced). */
13
- export interface CompareResult {
14
- commits?: CompareCommit[]
15
- diffs?: CompareDiff[]
16
- }
17
-
18
- const COMMIT_LIST_CAP = 20
19
-
20
- /**
21
- * Build the incremental-review context block for a re-review: everything that
22
- * changed since the last completed Maestro pass on this MR. Returns undefined
23
- * when there is nothing new to say (no prior sha, same sha, or empty compare)
24
- * so callers can skip the API round-trip cost of the block.
25
- */
26
- export function buildIncrementalBlock(
27
- compare: CompareResult | undefined,
28
- sinceSha: string | undefined,
29
- nowSha: string | undefined,
30
- ): string | undefined {
31
- if (sinceSha === undefined || nowSha === undefined || sinceSha === nowSha) return undefined
32
- if (compare === undefined) return undefined
33
- const commits = compare.commits ?? []
34
- const diffs = compare.diffs ?? []
35
- if (commits.length === 0 && diffs.length === 0) return undefined
36
-
37
- const lines: string[] = [
38
- `This MR was reviewed before (at ${sinceSha.slice(0, 12)}). The following is what changed since then — focus your review on these files and commits, and re-check only open threads whose location falls inside them:`,
39
- ]
40
- const shown = commits.slice(0, COMMIT_LIST_CAP)
41
- for (const commit of shown) {
42
- const title = commit.title?.replace(/\s+/g, ' ').trim() ?? ''
43
- lines.push(`- ${commit.short_id ? `${commit.short_id.slice(0, 8)} ` : ''}${title}`)
44
- }
45
- const hidden = commits.length - shown.length
46
- if (hidden > 0) lines.push(`- and ${hidden} more commit(s)`)
47
- lines.push(`Changed files since last review: ${diffs.length}`)
48
- return lines.join('\n')
49
- }
50
-
51
- /**
52
- * Cheap head-sha probe: `GET /merge_requests/:iid` returns diff_refs.head_sha
53
- * without pulling any diff bodies. Degrades to undefined (no incrementality)
54
- * on any error — re-reviews must never fail because of this optional lookup.
55
- */
56
- export async function fetchMrDetailHeadSha(
57
- baseUrl: string, token: string, projectId: number, mrIid: number,
58
- ): Promise<string | undefined> {
59
- try {
60
- const response = await fetchWithTimeout(
61
- `${baseUrl}/api/v4/projects/${projectId}/merge_requests/${mrIid}`,
62
- { headers: gitlabAuthHeaders(token) },
63
- )
64
- if (!response.ok) return undefined
65
- const body = await response.json() as { diff_refs?: { head_sha?: string } }
66
- return body.diff_refs?.head_sha
67
- } catch {
68
- return undefined
69
- }
70
- }
71
-
72
- /** Diff between two MR states, reduced to the fields the prompt block needs. */
73
- export async function fetchCompare(
74
- baseUrl: string, token: string, projectId: number, from: string, to: string,
75
- ): Promise<CompareResult | undefined> {
76
- try {
77
- const response = await fetchWithTimeout(
78
- `${baseUrl}/api/v4/projects/${projectId}/repository/compare?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
79
- { headers: gitlabAuthHeaders(token) },
80
- )
81
- if (!response.ok) return undefined
82
- return await response.json() as CompareResult
83
- } catch {
84
- return undefined
85
- }
86
- }