@ddtcorex/dsh-maestro-review 0.1.2 → 0.2.1
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/lib/govard-audit-lint-tool.d.ts.map +1 -1
- package/lib/govard-audit-lint-tool.js +29 -5
- package/lib/govard-audit-lint-tool.js.map +1 -1
- package/lib/orchestrator.d.ts +1 -0
- package/lib/orchestrator.d.ts.map +1 -1
- package/lib/orchestrator.js +64 -12
- package/lib/orchestrator.js.map +1 -1
- package/lib/providers/gitlab.d.ts +1 -1
- package/lib/providers/gitlab.d.ts.map +1 -1
- package/lib/providers/gitlab.js +24 -28
- package/lib/providers/gitlab.js.map +1 -1
- package/lib/skills-tool.d.ts +2 -2
- package/lib/skills-tool.d.ts.map +1 -1
- package/lib/skills-tool.js +17 -2
- package/lib/skills-tool.js.map +1 -1
- package/package.json +2 -2
- package/src/host/govard-audit-lint-tool.ts +24 -4
- package/src/host/orchestrator.ts +57 -12
- package/src/host/providers/gitlab.ts +26 -74
- package/src/host/skills-tool.ts +18 -3
- package/lib/gitlab-webhook.d.ts +0 -17
- package/lib/gitlab-webhook.d.ts.map +0 -1
- package/lib/gitlab-webhook.js +0 -144
- package/lib/gitlab-webhook.js.map +0 -1
- package/src/host/gitlab-webhook.ts +0 -166
package/lib/skills-tool.js
CHANGED
|
@@ -19,10 +19,25 @@ export const REVIEW_PROFILE_SKILLS = {
|
|
|
19
19
|
'magento2-security-scan',
|
|
20
20
|
'magento2-performance-audit',
|
|
21
21
|
],
|
|
22
|
+
laravel: [
|
|
23
|
+
'govard-toolbox',
|
|
24
|
+
'govard-laravel',
|
|
25
|
+
'php-dev-core',
|
|
26
|
+
],
|
|
27
|
+
symfony: [
|
|
28
|
+
'govard-toolbox',
|
|
29
|
+
'govard-symfony',
|
|
30
|
+
'php-dev-core',
|
|
31
|
+
],
|
|
32
|
+
wordpress: [
|
|
33
|
+
'govard-toolbox',
|
|
34
|
+
'govard-wordpress',
|
|
35
|
+
'php-dev-core',
|
|
36
|
+
],
|
|
22
37
|
/** Diff review against general best practices; no project skill set required. */
|
|
23
38
|
generic: [],
|
|
24
39
|
};
|
|
25
|
-
export const MAESTRO_SKILLS_INSTALL_COMMAND = 'curl -fsSL https://raw.githubusercontent.com/ddtcorex/maestro-skills/master/install.sh | bash -s -- --scope personal --target dsh --skills govard-toolbox,govard-magento,magento2-dev-core,magento2-frontend-dev,magento2-hyva-dev,magento2-code-review,magento2-linter,magento2-security-scan,magento2-performance-audit -y';
|
|
40
|
+
export const MAESTRO_SKILLS_INSTALL_COMMAND = 'curl -fsSL https://raw.githubusercontent.com/ddtcorex/maestro-skills/master/install.sh | bash -s -- --scope personal --target dsh --skills govard-toolbox,govard-magento,govard-laravel,govard-symfony,govard-wordpress,php-dev-core,magento2-dev-core,magento2-frontend-dev,magento2-hyva-dev,magento2-code-review,magento2-linter,magento2-security-scan,magento2-performance-audit -y';
|
|
26
41
|
// This is deliberately process-local and keyed by the reviewer Agent object,
|
|
27
42
|
// which every Cordis child context inherits. Preset mounting inserts child
|
|
28
43
|
// contexts, so keying on the plugin's context would make a successful load
|
|
@@ -105,7 +120,7 @@ export function apply(ctx) {
|
|
|
105
120
|
name: 'maestro_load_review_profile',
|
|
106
121
|
description: 'Load the complete, exact skill set required for a configured review profile. Fails if any required skill is unavailable.',
|
|
107
122
|
parameters: {
|
|
108
|
-
profile: { type: 'string', required: true, description: 'Review profile configured for the project. Supported: "magento2" (full Magento skill set), "generic" (no skills required).' },
|
|
123
|
+
profile: { type: 'string', required: true, description: 'Review profile configured for the project. Supported: "magento2" (full Magento skill set), "laravel" (Govard Laravel + PHP), "symfony" (Govard Symfony + PHP), "wordpress" (Govard WordPress + PHP), "generic" (no skills required).' },
|
|
109
124
|
},
|
|
110
125
|
output: {
|
|
111
126
|
schema: {
|
package/lib/skills-tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skills-tool.js","sourceRoot":"","sources":["../src/host/skills-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGnD,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAA;AACzC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAIzC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAkD;IAClF,QAAQ,EAAE;QACR,gBAAgB;QAChB,gBAAgB;QAChB,mBAAmB;QACnB,yEAAyE;QACzE,+EAA+E;QAC/E,uBAAuB;QACvB,mBAAmB;QACnB,sBAAsB;QACtB,iBAAiB;QACjB,wBAAwB;QACxB,4BAA4B;KAC7B;IACD,iFAAiF;IACjF,OAAO,EAAE,EAAE;CACZ,CAAA;AAED,MAAM,CAAC,MAAM,8BAA8B,GAAG,
|
|
1
|
+
{"version":3,"file":"skills-tool.js","sourceRoot":"","sources":["../src/host/skills-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGnD,MAAM,CAAC,MAAM,IAAI,GAAG,qBAAqB,CAAA;AACzC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAIzC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAkD;IAClF,QAAQ,EAAE;QACR,gBAAgB;QAChB,gBAAgB;QAChB,mBAAmB;QACnB,yEAAyE;QACzE,+EAA+E;QAC/E,uBAAuB;QACvB,mBAAmB;QACnB,sBAAsB;QACtB,iBAAiB;QACjB,wBAAwB;QACxB,4BAA4B;KAC7B;IACD,OAAO,EAAE;QACP,gBAAgB;QAChB,gBAAgB;QAChB,cAAc;KACf;IACD,OAAO,EAAE;QACP,gBAAgB;QAChB,gBAAgB;QAChB,cAAc;KACf;IACD,SAAS,EAAE;QACT,gBAAgB;QAChB,kBAAkB;QAClB,cAAc;KACf;IACD,iFAAiF;IACjF,OAAO,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
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "Maestro Review — pluggable ReviewProvider (GitLab/GitHub) + orchestrator for automated MR review",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./lib/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@deepseek-ai/schemastery": "^3.0.0",
|
|
27
|
-
"@ddtcorex/dsh-maestro-config-lib": "^0.1.
|
|
27
|
+
"@ddtcorex/dsh-maestro-config-lib": "^0.1.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
@@ -40,7 +40,9 @@ async function isInsideRoot(r:string,t:string):Promise<boolean>{
|
|
|
40
40
|
export function cleanJson(raw:string):string{
|
|
41
41
|
return raw.replace(/\n\s*ERROR audit run.*$/s, '').replace(/\s{2,}ERROR audit run.*$/s, '').trimEnd()
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
// Govard 1.67 auto timeout: 90s-30m framework-aware (15m floor for wordpress/magento2 → 22.5m auto)
|
|
44
|
+
// Keep kill timeout above the largest auto value so the outer watchdog doesn't cancel a valid auto run.
|
|
45
|
+
const DEFAULT_TIMEOUT=900_000
|
|
44
46
|
|
|
45
47
|
function run(cmd:string, args:string[], cwd:string, timeoutMs:number):Promise<{code:number|null, stdout:string, stderr:string, timedOut:boolean}>{
|
|
46
48
|
return new Promise((resolvePromise)=>{
|
|
@@ -60,7 +62,7 @@ export function apply(ctx:Context, config:{rootPath?:string, timeoutMs?:number}=
|
|
|
60
62
|
const defaultTimeout=config.timeoutMs ?? DEFAULT_TIMEOUT
|
|
61
63
|
ctx.effect(()=>ctx.tools.register(defineTool({
|
|
62
64
|
name:'govard_audit_lint',
|
|
63
|
-
description:'Run govard audit --checks lint --format json and return structured phpcs/phpstan results. Use before hand-parsing text.',
|
|
65
|
+
description:'Run govard audit --checks lint --format json and return structured phpcs/phpstan results. Use before hand-parsing text. Govard 1.67+ uses --timeout auto (framework-aware 90s-30m, 22.5m for wordpress/magento2) by default.',
|
|
64
66
|
parameters:{
|
|
65
67
|
worktreePath:{type:'string'},
|
|
66
68
|
checks:{type:'array', items:{type:'string'}},
|
|
@@ -68,6 +70,11 @@ export function apply(ctx:Context, config:{rootPath?:string, timeoutMs?:number}=
|
|
|
68
70
|
phpVersions:{type:'array', items:{type:'string'}},
|
|
69
71
|
noLintResultCache:{type:'boolean'},
|
|
70
72
|
timeoutMs:{type:'number'},
|
|
73
|
+
// New in 1.67/2.7: framework-aware timeout and native lint provider
|
|
74
|
+
timeout:{type:'string', description:'Govard --timeout (e.g. auto, 300s, 15m, 0 for no timeout). Default auto.'},
|
|
75
|
+
lintProvider:{type:'string', description:'--lint-provider (govard or external). Default govard.'},
|
|
76
|
+
scope:{type:'string', enum:['project','diff']},
|
|
77
|
+
base:{type:'string', description:'--base ref for diff scope'},
|
|
71
78
|
},
|
|
72
79
|
output:{
|
|
73
80
|
schema:{
|
|
@@ -95,9 +102,22 @@ export function apply(ctx:Context, config:{rootPath?:string, timeoutMs?:number}=
|
|
|
95
102
|
const checkPath= rawPath ?? ''
|
|
96
103
|
if(checkPath!=='' && !(await isInsideRoot(root, checkPath))) return {text:`Path "${checkPath}" escapes the workspace root.`, truncated:false} as never
|
|
97
104
|
const timeoutMs=(args as {timeoutMs?:number}).timeoutMs ?? defaultTimeout
|
|
98
|
-
if(timeoutMs<5000 || timeoutMs>
|
|
105
|
+
if(timeoutMs<5000 || timeoutMs>1_800_000) return {text:'timeoutMs out of range 5000-1800000 (5s-30m). Use --timeout auto for framework-aware estimation.', truncated:false} as never
|
|
99
106
|
|
|
100
|
-
const
|
|
107
|
+
const a = args as {checks?:string[]; mode?:string; scope?:string; base?:string; phpVersions?:string[]; noLintResultCache?:boolean; timeout?:string; lintProvider?:string}
|
|
108
|
+
const checks = a.checks && a.checks.length ? a.checks.join(',') : 'lint'
|
|
109
|
+
const mode = a.mode ?? 'auto'
|
|
110
|
+
const scope = a.scope
|
|
111
|
+
const base = a.base
|
|
112
|
+
const phpVersionsArg = a.phpVersions
|
|
113
|
+
const noLintResultCache = a.noLintResultCache
|
|
114
|
+
const timeout = a.timeout ?? 'auto'
|
|
115
|
+
const lintProvider = a.lintProvider ?? 'govard'
|
|
116
|
+
const cliArgs=['audit','run','--checks',checks,'--format','json','--mode',mode,'--timeout',timeout,'--lint-provider',lintProvider]
|
|
117
|
+
if(scope) cliArgs.push('--scope', scope)
|
|
118
|
+
if(base) cliArgs.push('--base', base)
|
|
119
|
+
if(phpVersionsArg && phpVersionsArg.length) cliArgs.push('--php', phpVersionsArg.join(','))
|
|
120
|
+
if(noLintResultCache) cliArgs.push('--no-lint-result-cache')
|
|
101
121
|
const result=await run('govard', cliArgs, worktreePath, timeoutMs)
|
|
102
122
|
if(result.timedOut){
|
|
103
123
|
return {ok:false, exitCode: result.code ?? 124, timedOut:true, worktreePath, lint:{phpcs:{violations:[]}, phpstan:{errors:[]}, pubMediaGuard:{violations:[]}}, summary:{status:null, phpVersions:[], matrixComplete:false, findingCount:0, truncated:false}, rawJson:{}, errors:[{code:'timeout', message:`timed out after ${timeoutMs}ms` }], diagnostics:result.stderr.slice(0,4000)} as never
|
package/src/host/orchestrator.ts
CHANGED
|
@@ -146,7 +146,7 @@ export const Config: z<Config> = z.object({
|
|
|
146
146
|
projectMappings: z.array(z.object({
|
|
147
147
|
projectPath: z.string().required(),
|
|
148
148
|
localRepoPath: z.string().required(),
|
|
149
|
-
reviewProfile: z.union([z.const('magento2'), z.const('generic')]).default('magento2'),
|
|
149
|
+
reviewProfile: z.union([z.const('magento2'), z.const('laravel'), z.const('symfony'), z.const('wordpress'), z.const('generic')]).default('magento2'),
|
|
150
150
|
})).required(),
|
|
151
151
|
gitlabBaseUrl: z.string().required(),
|
|
152
152
|
gitlabToken: z.string().role('secret'),
|
|
@@ -497,6 +497,21 @@ function assertSafeBranchName(sourceBranch: string): void {
|
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
+
export function isBranchNotFoundError(err: unknown): boolean {
|
|
501
|
+
const rawStderr = (err as { stderr?: unknown })?.stderr
|
|
502
|
+
const rawMsg = (err as { message?: unknown })?.message
|
|
503
|
+
const toText = (v: unknown): string => {
|
|
504
|
+
if (typeof v === 'string') return v
|
|
505
|
+
if (v instanceof Uint8Array || (typeof Buffer !== 'undefined' && Buffer.isBuffer(v as unknown))) return Buffer.from(v as Uint8Array).toString('utf8')
|
|
506
|
+
if (typeof v === 'object' && v !== null && 'toString' in v) try { return String(v) } catch {}
|
|
507
|
+
return ''
|
|
508
|
+
}
|
|
509
|
+
const stderrText = toText(rawStderr)
|
|
510
|
+
const msgText = toText(rawMsg)
|
|
511
|
+
const text = stderrText !== '' ? stderrText : msgText !== '' ? msgText : String(err ?? '')
|
|
512
|
+
return text.includes("couldn't find remote ref") || text.includes('could not find remote branch') || text.includes('unknown revision or path')
|
|
513
|
+
}
|
|
514
|
+
|
|
500
515
|
/**
|
|
501
516
|
* Keep a Govard audit worktree isolated from the developer's primary checkout.
|
|
502
517
|
* Without this local override, both checkouts inherit the same `project_name`
|
|
@@ -510,7 +525,17 @@ export function govardWorktreeOverride(projectId: number, mrIid: number, keySuff
|
|
|
510
525
|
export async function ensureWorktree(localRepoPath: string, sourceBranch: string, projectId: number, mrIid: number, keySuffix?: string): Promise<string> {
|
|
511
526
|
assertSafeBranchName(sourceBranch)
|
|
512
527
|
const worktreePath = join('/tmp', `maestro-mr-${projectId}-${mrIid}${keySuffix === undefined ? '' : `-${keySuffix}`}`)
|
|
513
|
-
|
|
528
|
+
try {
|
|
529
|
+
await execFileAsync('git', ['fetch', '--', 'origin', sourceBranch], { cwd: localRepoPath, timeout: GIT_TIMEOUT_MS })
|
|
530
|
+
} catch (err) {
|
|
531
|
+
if (isBranchNotFoundError(err)) {
|
|
532
|
+
const e = new Error(`branch not found on origin: ${sourceBranch}`)
|
|
533
|
+
;(e as unknown as { code: string }).code = 'BRANCH_NOT_FOUND'
|
|
534
|
+
;(e as unknown as { cause: unknown }).cause = err
|
|
535
|
+
throw e
|
|
536
|
+
}
|
|
537
|
+
throw err
|
|
538
|
+
}
|
|
514
539
|
// A host restart can interrupt an active review before its `finally` cleanup.
|
|
515
540
|
// Recover only this deterministic Maestro-owned path so the next delivery can
|
|
516
541
|
// retry; an unrelated worktree is never targeted.
|
|
@@ -831,16 +856,36 @@ export function apply(ctx: Context, config: Config): void {
|
|
|
831
856
|
await signals?.finish('completed')
|
|
832
857
|
return
|
|
833
858
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
859
|
+
let fullBody: string
|
|
860
|
+
try {
|
|
861
|
+
fullBody = await runReviewAndAudit(payload, {
|
|
862
|
+
localRepoPath: mapping.localRepoPath,
|
|
863
|
+
ensureWorktree,
|
|
864
|
+
removeWorktree,
|
|
865
|
+
runReviewer: (worktreePath, p) => runReviewer(worktreePath, p, resolved, mapping.reviewProfile ?? 'magento2', reviewModelSelection, incrementalBlock),
|
|
866
|
+
runAuditor: (worktreePath, p) => runAuditor(worktreePath, p, resolved, reviewModelSelection),
|
|
867
|
+
postComment,
|
|
868
|
+
replyToDiscussion,
|
|
869
|
+
writeFailedReport,
|
|
870
|
+
})
|
|
871
|
+
} catch (err) {
|
|
872
|
+
const isBranchNotFound = (err as { code?: string })?.code === 'BRANCH_NOT_FOUND' || isBranchNotFoundError(err)
|
|
873
|
+
if (isBranchNotFound) {
|
|
874
|
+
const diffBody = await runDiffOnlyReview(payload, {
|
|
875
|
+
runReviewer: (p) => runReviewer(undefined, p, resolved, undefined, reviewModelSelection, incrementalBlock),
|
|
876
|
+
postComment,
|
|
877
|
+
replyToDiscussion,
|
|
878
|
+
writeFailedReport,
|
|
879
|
+
})
|
|
880
|
+
const summary = summarize(diffBody)
|
|
881
|
+
const branchNote = `fallback diff-only: branch ${payload.sourceBranch} not found on origin — ${summary ?? ''}`.trim()
|
|
882
|
+
await recordReviewFinish(historyId, { status: 'completed', summary: branchNote })
|
|
883
|
+
notifyTelegram('completed', branchNote)
|
|
884
|
+
await signals?.finish('completed')
|
|
885
|
+
return
|
|
886
|
+
}
|
|
887
|
+
throw err
|
|
888
|
+
}
|
|
844
889
|
await recordReviewFinish(historyId, { status: 'completed', summary: summarize(fullBody) })
|
|
845
890
|
notifyTelegram('completed', summarize(fullBody))
|
|
846
891
|
await signals?.finish('completed')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
2
2
|
import type { Context } from '@deepseek-ai/cordis'
|
|
3
3
|
import z from '@deepseek-ai/schemastery'
|
|
4
4
|
import { loadUserConfig } from '../config-store.js'
|
|
@@ -8,15 +8,13 @@ import { routeGitlabReviewRequest } from '../review-intake.js'
|
|
|
8
8
|
import type { ReviewProvider, ReviewRequest } from './interface.js'
|
|
9
9
|
|
|
10
10
|
export const name = 'maestro-review-webhook'
|
|
11
|
+
export const inject = ['webServer'] as const
|
|
11
12
|
|
|
12
13
|
export interface Config {
|
|
13
|
-
port: number
|
|
14
14
|
botUsername?: string
|
|
15
15
|
secret?: string
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
export const Config: z<Config> = z.object({
|
|
19
|
-
port: z.natural().max(65535).required(),
|
|
20
18
|
botUsername: z.string(),
|
|
21
19
|
secret: z.string().role('secret'),
|
|
22
20
|
})
|
|
@@ -108,83 +106,37 @@ export function apply(ctx: Context, config: Config): void {
|
|
|
108
106
|
const userConfig = await loadUserConfig()
|
|
109
107
|
const expected = userConfig.webhookSecret ?? config.secret
|
|
110
108
|
if (expected === undefined) {
|
|
111
|
-
if (!warnedUnconfigured) {
|
|
112
|
-
warnedUnconfigured = true
|
|
113
|
-
console.error('maestro-review-webhook: no webhook secret configured — set one in Maestro Settings or MAESTRO_GITLAB_WEBHOOK_SECRET; rejecting all requests until then')
|
|
114
|
-
}
|
|
109
|
+
if (!warnedUnconfigured) { warnedUnconfigured = true; console.error('maestro-review-webhook: no webhook secret configured — set one in Maestro Settings or MAESTRO_GITLAB_WEBHOOK_SECRET; rejecting all requests until then') }
|
|
115
110
|
return false
|
|
116
111
|
}
|
|
117
112
|
return secretsMatch(headerValue, expected)
|
|
118
113
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
res.writeHead(404).end()
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
res.writeHead(413).end()
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
if (req.url === '/hooks/gitlab-mr/trigger') {
|
|
136
|
-
let parsed: unknown
|
|
137
|
-
try {
|
|
138
|
-
parsed = JSON.parse(raw)
|
|
139
|
-
} catch {
|
|
140
|
-
res.writeHead(400).end()
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
if (!isValidMrOpenedPayload(parsed)) {
|
|
144
|
-
res.writeHead(400).end()
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
const request: OrchestratorReviewRequest = {
|
|
148
|
-
...parsed,
|
|
149
|
-
trigger: 'mention',
|
|
150
|
-
mode: 'quick',
|
|
151
|
-
scope: { kind: 'mr' },
|
|
152
|
-
}
|
|
153
|
-
ctx.emit('maestro/review-request', request)
|
|
154
|
-
res.writeHead(200).end()
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (req.url !== '/hooks/gitlab-mr') {
|
|
159
|
-
res.writeHead(404).end()
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
let body: GitlabMrWebhookBody
|
|
163
|
-
try {
|
|
164
|
-
body = JSON.parse(raw)
|
|
165
|
-
} catch {
|
|
166
|
-
res.writeHead(400).end()
|
|
167
|
-
return
|
|
114
|
+
function makeHandler(expectedPath: string) {
|
|
115
|
+
return (req: IncomingMessage, res: ServerResponse) => {
|
|
116
|
+
if (req.method !== 'POST') { res.writeHead(404).end(); return }
|
|
117
|
+
if (req.url !== expectedPath) { res.writeHead(404).end(); return }
|
|
118
|
+
void requestAuthorized(req.headers['x-gitlab-token']).then(async (authorized) => {
|
|
119
|
+
if (!authorized) { res.writeHead(401).end(); return }
|
|
120
|
+
const raw = await readBody(req)
|
|
121
|
+
if (raw === undefined) { res.writeHead(413).end(); return }
|
|
122
|
+
if (expectedPath === '/hooks/gitlab-mr/trigger') {
|
|
123
|
+
let parsed: unknown; try { parsed = JSON.parse(raw) } catch { res.writeHead(400).end(); return }
|
|
124
|
+
if (!isValidMrOpenedPayload(parsed)) { res.writeHead(400).end(); return }
|
|
125
|
+
const request: OrchestratorReviewRequest = { ...(parsed as any), trigger: 'mention', mode: 'quick', scope: { kind: 'mr' } }
|
|
126
|
+
ctx.emit('maestro/review-request', request); res.writeHead(200).end(); return
|
|
168
127
|
}
|
|
128
|
+
let body: GitlabMrWebhookBody; try { body = JSON.parse(raw) } catch { res.writeHead(400).end(); return }
|
|
169
129
|
const userConfig = await loadUserConfig()
|
|
170
|
-
if ((body.object_kind === 'merge_request' || body.object_kind === 'note') && !hasValidGitlabMrIdentity(body)) {
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
}
|
|
174
|
-
const request = routeGitlabReviewRequest(
|
|
175
|
-
body,
|
|
176
|
-
userConfig.botUsername ?? config.botUsername ?? 'maestro',
|
|
177
|
-
{ pushEnabled: userConfig.autoRereviewOnPush === true },
|
|
178
|
-
)
|
|
130
|
+
if ((body.object_kind === 'merge_request' || body.object_kind === 'note') && !hasValidGitlabMrIdentity(body)) { res.writeHead(400).end(); return }
|
|
131
|
+
const request = routeGitlabReviewRequest(body, userConfig.botUsername ?? config.botUsername ?? 'maestro', { pushEnabled: userConfig.autoRereviewOnPush === true })
|
|
179
132
|
if (request !== undefined) ctx.emit('maestro/review-request', request)
|
|
180
133
|
res.writeHead(200).end()
|
|
181
134
|
})
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ctx.
|
|
188
|
-
|
|
189
|
-
}, 'gitlab-webhook teardown')
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const h1 = makeHandler('/hooks/gitlab-mr')
|
|
138
|
+
const h2 = makeHandler('/hooks/gitlab-mr/trigger')
|
|
139
|
+
const dispose1 = (ctx as any).webServer.register({ kind: 'exact', path: '/hooks/gitlab-mr', handler: h1 })
|
|
140
|
+
const dispose2 = (ctx as any).webServer.register({ kind: 'exact', path: '/hooks/gitlab-mr/trigger', handler: h2 })
|
|
141
|
+
ctx.effect(() => () => { dispose1(); dispose2() }, 'gitlab-webhook teardown')
|
|
190
142
|
}
|
package/src/host/skills-tool.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {} from '@deepseek-ai/dsh-agent'
|
|
|
5
5
|
export const name = 'maestro-skills-tool'
|
|
6
6
|
export const inject = ['skills', 'tools']
|
|
7
7
|
|
|
8
|
-
export type ReviewSkillProfile = 'magento2' | 'generic'
|
|
8
|
+
export type ReviewSkillProfile = 'magento2' | 'laravel' | 'symfony' | 'wordpress' | 'generic'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Exact skill names rather than a fuzzy search: a review must not silently
|
|
@@ -25,11 +25,26 @@ export const REVIEW_PROFILE_SKILLS: Record<ReviewSkillProfile, readonly string[]
|
|
|
25
25
|
'magento2-security-scan',
|
|
26
26
|
'magento2-performance-audit',
|
|
27
27
|
],
|
|
28
|
+
laravel: [
|
|
29
|
+
'govard-toolbox',
|
|
30
|
+
'govard-laravel',
|
|
31
|
+
'php-dev-core',
|
|
32
|
+
],
|
|
33
|
+
symfony: [
|
|
34
|
+
'govard-toolbox',
|
|
35
|
+
'govard-symfony',
|
|
36
|
+
'php-dev-core',
|
|
37
|
+
],
|
|
38
|
+
wordpress: [
|
|
39
|
+
'govard-toolbox',
|
|
40
|
+
'govard-wordpress',
|
|
41
|
+
'php-dev-core',
|
|
42
|
+
],
|
|
28
43
|
/** Diff review against general best practices; no project skill set required. */
|
|
29
44
|
generic: [],
|
|
30
45
|
}
|
|
31
46
|
|
|
32
|
-
export const MAESTRO_SKILLS_INSTALL_COMMAND = 'curl -fsSL https://raw.githubusercontent.com/ddtcorex/maestro-skills/master/install.sh | bash -s -- --scope personal --target dsh --skills govard-toolbox,govard-magento,magento2-dev-core,magento2-frontend-dev,magento2-hyva-dev,magento2-code-review,magento2-linter,magento2-security-scan,magento2-performance-audit -y'
|
|
47
|
+
export const MAESTRO_SKILLS_INSTALL_COMMAND = 'curl -fsSL https://raw.githubusercontent.com/ddtcorex/maestro-skills/master/install.sh | bash -s -- --scope personal --target dsh --skills govard-toolbox,govard-magento,govard-laravel,govard-symfony,govard-wordpress,php-dev-core,magento2-dev-core,magento2-frontend-dev,magento2-hyva-dev,magento2-code-review,magento2-linter,magento2-security-scan,magento2-performance-audit -y'
|
|
33
48
|
|
|
34
49
|
// This is deliberately process-local and keyed by the reviewer Agent object,
|
|
35
50
|
// which every Cordis child context inherits. Preset mounting inserts child
|
|
@@ -139,7 +154,7 @@ export function apply(ctx: Context): void {
|
|
|
139
154
|
name: 'maestro_load_review_profile',
|
|
140
155
|
description: 'Load the complete, exact skill set required for a configured review profile. Fails if any required skill is unavailable.',
|
|
141
156
|
parameters: {
|
|
142
|
-
profile: { type: 'string', required: true, description: 'Review profile configured for the project. Supported: "magento2" (full Magento skill set), "generic" (no skills required).' },
|
|
157
|
+
profile: { type: 'string', required: true, description: 'Review profile configured for the project. Supported: "magento2" (full Magento skill set), "laravel" (Govard Laravel + PHP), "symfony" (Govard Symfony + PHP), "wordpress" (Govard WordPress + PHP), "generic" (no skills required).' },
|
|
143
158
|
},
|
|
144
159
|
output: {
|
|
145
160
|
schema: {
|
package/lib/gitlab-webhook.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
-
import z from '@deepseek-ai/schemastery';
|
|
3
|
-
export declare const name = "maestro-gitlab-webhook";
|
|
4
|
-
export interface Config {
|
|
5
|
-
port: number;
|
|
6
|
-
/** Username of the GitLab service account used for reviewer assignments. */
|
|
7
|
-
botUsername?: string;
|
|
8
|
-
/**
|
|
9
|
-
* Fallback when Maestro Settings has no webhook secret; optional so a
|
|
10
|
-
* deployment that configures everything through Settings boots without env
|
|
11
|
-
* vars. With neither source set, every request is rejected (fail closed).
|
|
12
|
-
*/
|
|
13
|
-
secret?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare const Config: z<Config>;
|
|
16
|
-
export declare function apply(ctx: Context, config: Config): void;
|
|
17
|
-
//# sourceMappingURL=gitlab-webhook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gitlab-webhook.d.ts","sourceRoot":"","sources":["../src/host/gitlab-webhook.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAMxC,eAAO,MAAM,IAAI,2BAA2B,CAAA;AAE5C,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAI3B,CAAA;AAkDF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAyFxD"}
|
package/lib/gitlab-webhook.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http';
|
|
2
|
-
import z from '@deepseek-ai/schemastery';
|
|
3
|
-
import { loadUserConfig } from './config-store.js';
|
|
4
|
-
import { secretsMatch } from './secure-compare.js';
|
|
5
|
-
import { routeGitlabReviewRequest } from './review-intake.js';
|
|
6
|
-
export const name = 'maestro-gitlab-webhook';
|
|
7
|
-
export const Config = z.object({
|
|
8
|
-
port: z.natural().max(65535).required(),
|
|
9
|
-
botUsername: z.string(),
|
|
10
|
-
secret: z.string().role('secret'),
|
|
11
|
-
});
|
|
12
|
-
/** GitLab payloads are small; 5 MB is generous and stops unbounded buffering. */
|
|
13
|
-
const MAX_WEBHOOK_BODY_BYTES = 5 * 1024 * 1024;
|
|
14
|
-
function readBody(req, limit = MAX_WEBHOOK_BODY_BYTES) {
|
|
15
|
-
return new Promise((resolvePromise) => {
|
|
16
|
-
let raw = '';
|
|
17
|
-
let settled = false;
|
|
18
|
-
req.on('data', (chunk) => {
|
|
19
|
-
if (settled)
|
|
20
|
-
return;
|
|
21
|
-
if (raw.length + chunk.length > limit) {
|
|
22
|
-
settled = true;
|
|
23
|
-
req.resume();
|
|
24
|
-
resolvePromise(undefined);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
raw += chunk.toString();
|
|
28
|
-
});
|
|
29
|
-
req.on('end', () => { if (!settled) {
|
|
30
|
-
settled = true;
|
|
31
|
-
resolvePromise(raw);
|
|
32
|
-
} });
|
|
33
|
-
req.on('error', () => { if (!settled) {
|
|
34
|
-
settled = true;
|
|
35
|
-
resolvePromise(undefined);
|
|
36
|
-
} });
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function isValidMrOpenedPayload(value) {
|
|
40
|
-
if (typeof value !== 'object' || value === null)
|
|
41
|
-
return false;
|
|
42
|
-
const v = value;
|
|
43
|
-
return typeof v.projectPath === 'string'
|
|
44
|
-
&& typeof v.projectId === 'number'
|
|
45
|
-
&& typeof v.mrIid === 'number'
|
|
46
|
-
&& typeof v.sourceBranch === 'string';
|
|
47
|
-
}
|
|
48
|
-
function hasValidGitlabMrIdentity(value) {
|
|
49
|
-
if (typeof value !== 'object' || value === null)
|
|
50
|
-
return false;
|
|
51
|
-
const body = value;
|
|
52
|
-
const project = body.project;
|
|
53
|
-
const attributes = body.object_attributes;
|
|
54
|
-
const mergeRequest = body.merge_request;
|
|
55
|
-
const source = body.object_kind === 'note' ? mergeRequest : attributes;
|
|
56
|
-
return typeof project?.id === 'number' && typeof project.path_with_namespace === 'string'
|
|
57
|
-
&& typeof source?.iid === 'number' && typeof source.source_branch === 'string';
|
|
58
|
-
}
|
|
59
|
-
export function apply(ctx, config) {
|
|
60
|
-
// Settings wins over the boot secret, re-read per request so a change in the
|
|
61
|
-
// UI takes effect without a restart. With neither source set, every token
|
|
62
|
-
// fails the comparison (a header string never equals `undefined`), so the
|
|
63
|
-
// server stays closed until a secret is configured.
|
|
64
|
-
let warnedUnconfigured = false;
|
|
65
|
-
async function requestAuthorized(headerValue) {
|
|
66
|
-
const userConfig = await loadUserConfig();
|
|
67
|
-
const expected = userConfig.webhookSecret ?? config.secret;
|
|
68
|
-
if (expected === undefined) {
|
|
69
|
-
if (!warnedUnconfigured) {
|
|
70
|
-
warnedUnconfigured = true;
|
|
71
|
-
console.error('maestro-gitlab-webhook: no webhook secret configured — set one in Maestro Settings or MAESTRO_GITLAB_WEBHOOK_SECRET; rejecting all requests until then');
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return secretsMatch(headerValue, expected);
|
|
76
|
-
}
|
|
77
|
-
const server = createServer((req, res) => {
|
|
78
|
-
if (req.method !== 'POST') {
|
|
79
|
-
res.writeHead(404).end();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
void requestAuthorized(req.headers['x-gitlab-token']).then(async (authorized) => {
|
|
83
|
-
if (!authorized) {
|
|
84
|
-
res.writeHead(401).end();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
readBody(req).then(async (raw) => {
|
|
88
|
-
if (raw === undefined) {
|
|
89
|
-
res.writeHead(413).end();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (req.url === '/hooks/gitlab-mr/trigger') {
|
|
93
|
-
let parsed;
|
|
94
|
-
try {
|
|
95
|
-
parsed = JSON.parse(raw);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
res.writeHead(400).end();
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (!isValidMrOpenedPayload(parsed)) {
|
|
102
|
-
res.writeHead(400).end();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const request = {
|
|
106
|
-
...parsed,
|
|
107
|
-
trigger: 'mention',
|
|
108
|
-
mode: 'quick',
|
|
109
|
-
scope: { kind: 'mr' },
|
|
110
|
-
};
|
|
111
|
-
ctx.emit('maestro/review-request', request);
|
|
112
|
-
res.writeHead(200).end();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (req.url !== '/hooks/gitlab-mr') {
|
|
116
|
-
res.writeHead(404).end();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
let body;
|
|
120
|
-
try {
|
|
121
|
-
body = JSON.parse(raw);
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
res.writeHead(400).end();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const userConfig = await loadUserConfig();
|
|
128
|
-
if ((body.object_kind === 'merge_request' || body.object_kind === 'note') && !hasValidGitlabMrIdentity(body)) {
|
|
129
|
-
res.writeHead(400).end();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const request = routeGitlabReviewRequest(body, userConfig.botUsername ?? config.botUsername ?? 'maestro', { pushEnabled: userConfig.autoRereviewOnPush === true });
|
|
133
|
-
if (request !== undefined)
|
|
134
|
-
ctx.emit('maestro/review-request', request);
|
|
135
|
-
res.writeHead(200).end();
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
server.listen(config.port);
|
|
140
|
-
ctx.effect(() => async () => {
|
|
141
|
-
await new Promise((resolve) => { server.close(() => resolve()); });
|
|
142
|
-
}, 'gitlab-webhook teardown');
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=gitlab-webhook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gitlab-webhook.js","sourceRoot":"","sources":["../src/host/gitlab-webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwB,MAAM,WAAW,CAAA;AAE9D,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,MAAM,CAAC,MAAM,IAAI,GAAG,wBAAwB,CAAA;AAc5C,MAAM,CAAC,MAAM,MAAM,GAAc,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACvC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;CAClC,CAAC,CAAA;AAQF,iFAAiF;AACjF,MAAM,sBAAsB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AAE9C,SAAS,QAAQ,CAAC,GAAoB,EAAE,KAAK,GAAG,sBAAsB;IACpE,OAAO,IAAI,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;QACpC,IAAI,GAAG,GAAG,EAAE,CAAA;QACZ,IAAI,OAAO,GAAG,KAAK,CAAA;QACnB,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YAC/B,IAAI,OAAO;gBAAE,OAAM;YACnB,IAAI,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,K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