@sentry/warden 0.0.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.
- package/.agents/skills/find-bugs/SKILL.md +75 -0
- package/.agents/skills/vercel-react-best-practices/AGENTS.md +2934 -0
- package/.agents/skills/vercel-react-best-practices/SKILL.md +136 -0
- package/.agents/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/.agents/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
- package/.agents/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
- package/.agents/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
- package/.agents/skills/vercel-react-best-practices/rules/async-defer-await.md +80 -0
- package/.agents/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
- package/.agents/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
- package/.agents/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/.agents/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/.agents/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
- package/.agents/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/.agents/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/.agents/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
- package/.agents/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
- package/.agents/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/.agents/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/.agents/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/.agents/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/.agents/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
- package/.agents/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/.agents/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
- package/.claude/settings.json +57 -0
- package/.claude/settings.local.json +88 -0
- package/.claude/skills/agent-prompt/SKILL.md +54 -0
- package/.claude/skills/agent-prompt/references/agentic-patterns.md +94 -0
- package/.claude/skills/agent-prompt/references/anti-patterns.md +140 -0
- package/.claude/skills/agent-prompt/references/context-design.md +124 -0
- package/.claude/skills/agent-prompt/references/core-principles.md +75 -0
- package/.claude/skills/agent-prompt/references/model-guidance.md +118 -0
- package/.claude/skills/agent-prompt/references/output-formats.md +98 -0
- package/.claude/skills/agent-prompt/references/skill-structure.md +115 -0
- package/.claude/skills/agent-prompt/references/system-prompts.md +115 -0
- package/.claude/skills/notseer/SKILL.md +131 -0
- package/.claude/skills/skill-writer/SKILL.md +140 -0
- package/.claude/skills/testing-guidelines/SKILL.md +132 -0
- package/.claude/skills/warden-skill/SKILL.md +250 -0
- package/.claude/skills/warden-skill/references/config-schema.md +133 -0
- package/.dex/config.toml +2 -0
- package/.github/workflows/ci.yml +33 -0
- package/.github/workflows/release.yml +54 -0
- package/.github/workflows/warden.yml +40 -0
- package/AGENTS.md +89 -0
- package/CONTRIBUTING.md +60 -0
- package/LICENSE +105 -0
- package/README.md +43 -0
- package/SPEC.md +263 -0
- package/action.yml +87 -0
- package/assets/favicon.png +0 -0
- package/assets/warden-icon-bw.svg +5 -0
- package/assets/warden-icon-purple.png +0 -0
- package/assets/warden-icon-purple.svg +5 -0
- package/docs/.claude/settings.local.json +11 -0
- package/docs/astro.config.mjs +43 -0
- package/docs/package.json +19 -0
- package/docs/pnpm-lock.yaml +4000 -0
- package/docs/public/favicon.svg +5 -0
- package/docs/src/components/Code.astro +141 -0
- package/docs/src/components/PackageManagerTabs.astro +183 -0
- package/docs/src/components/Terminal.astro +212 -0
- package/docs/src/layouts/Base.astro +380 -0
- package/docs/src/pages/cli.astro +167 -0
- package/docs/src/pages/config.astro +394 -0
- package/docs/src/pages/guide.astro +449 -0
- package/docs/src/pages/index.astro +490 -0
- package/docs/src/styles/global.css +551 -0
- package/docs/tsconfig.json +3 -0
- package/docs/vercel.json +5 -0
- package/eslint.config.js +33 -0
- package/package.json +73 -0
- package/src/action/index.ts +1 -0
- package/src/action/main.ts +868 -0
- package/src/cli/args.test.ts +477 -0
- package/src/cli/args.ts +415 -0
- package/src/cli/commands/add.ts +447 -0
- package/src/cli/commands/init.test.ts +136 -0
- package/src/cli/commands/init.ts +132 -0
- package/src/cli/commands/setup-app/browser.ts +38 -0
- package/src/cli/commands/setup-app/credentials.ts +45 -0
- package/src/cli/commands/setup-app/manifest.ts +48 -0
- package/src/cli/commands/setup-app/server.ts +172 -0
- package/src/cli/commands/setup-app.ts +156 -0
- package/src/cli/commands/sync.ts +114 -0
- package/src/cli/context.ts +131 -0
- package/src/cli/files.test.ts +155 -0
- package/src/cli/files.ts +89 -0
- package/src/cli/fix.test.ts +310 -0
- package/src/cli/fix.ts +387 -0
- package/src/cli/git.test.ts +119 -0
- package/src/cli/git.ts +318 -0
- package/src/cli/index.ts +14 -0
- package/src/cli/main.ts +672 -0
- package/src/cli/output/box.ts +235 -0
- package/src/cli/output/formatters.test.ts +187 -0
- package/src/cli/output/formatters.ts +269 -0
- package/src/cli/output/icons.ts +13 -0
- package/src/cli/output/index.ts +44 -0
- package/src/cli/output/ink-runner.tsx +337 -0
- package/src/cli/output/jsonl.test.ts +347 -0
- package/src/cli/output/jsonl.ts +126 -0
- package/src/cli/output/reporter.ts +435 -0
- package/src/cli/output/tasks.ts +374 -0
- package/src/cli/output/tty.test.ts +117 -0
- package/src/cli/output/tty.ts +60 -0
- package/src/cli/output/verbosity.test.ts +40 -0
- package/src/cli/output/verbosity.ts +31 -0
- package/src/cli/terminal.test.ts +148 -0
- package/src/cli/terminal.ts +301 -0
- package/src/config/index.ts +3 -0
- package/src/config/loader.test.ts +313 -0
- package/src/config/loader.ts +103 -0
- package/src/config/schema.ts +168 -0
- package/src/config/writer.test.ts +119 -0
- package/src/config/writer.ts +84 -0
- package/src/diff/classify.test.ts +162 -0
- package/src/diff/classify.ts +92 -0
- package/src/diff/coalesce.test.ts +208 -0
- package/src/diff/coalesce.ts +133 -0
- package/src/diff/context.test.ts +226 -0
- package/src/diff/context.ts +201 -0
- package/src/diff/index.ts +4 -0
- package/src/diff/parser.test.ts +212 -0
- package/src/diff/parser.ts +149 -0
- package/src/event/context.ts +132 -0
- package/src/event/index.ts +2 -0
- package/src/event/schedule-context.ts +101 -0
- package/src/examples/examples.integration.test.ts +66 -0
- package/src/examples/index.test.ts +101 -0
- package/src/examples/index.ts +122 -0
- package/src/examples/setup.ts +25 -0
- package/src/index.ts +115 -0
- package/src/output/dedup.test.ts +419 -0
- package/src/output/dedup.ts +607 -0
- package/src/output/github-checks.test.ts +300 -0
- package/src/output/github-checks.ts +476 -0
- package/src/output/github-issues.ts +329 -0
- package/src/output/index.ts +5 -0
- package/src/output/issue-renderer.ts +197 -0
- package/src/output/renderer.test.ts +727 -0
- package/src/output/renderer.ts +217 -0
- package/src/output/stale.test.ts +375 -0
- package/src/output/stale.ts +155 -0
- package/src/output/types.ts +34 -0
- package/src/sdk/index.ts +1 -0
- package/src/sdk/runner.test.ts +806 -0
- package/src/sdk/runner.ts +1232 -0
- package/src/skills/index.ts +36 -0
- package/src/skills/loader.test.ts +300 -0
- package/src/skills/loader.ts +423 -0
- package/src/skills/remote.test.ts +704 -0
- package/src/skills/remote.ts +604 -0
- package/src/triggers/matcher.test.ts +277 -0
- package/src/triggers/matcher.ts +152 -0
- package/src/types/index.ts +194 -0
- package/src/utils/async.ts +18 -0
- package/src/utils/index.test.ts +84 -0
- package/src/utils/index.ts +50 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +8 -0
- package/vitest.integration.config.ts +11 -0
- package/warden.toml +19 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified diff parser - extracts hunks from patch strings
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface DiffHunk {
|
|
6
|
+
/** Original file start line */
|
|
7
|
+
oldStart: number;
|
|
8
|
+
/** Original file line count */
|
|
9
|
+
oldCount: number;
|
|
10
|
+
/** New file start line */
|
|
11
|
+
newStart: number;
|
|
12
|
+
/** New file line count */
|
|
13
|
+
newCount: number;
|
|
14
|
+
/** Optional header (function/class name) */
|
|
15
|
+
header?: string;
|
|
16
|
+
/** The raw hunk content including the @@ line */
|
|
17
|
+
content: string;
|
|
18
|
+
/** Just the changed lines (without @@ header) */
|
|
19
|
+
lines: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ParsedDiff {
|
|
23
|
+
/** File path */
|
|
24
|
+
filename: string;
|
|
25
|
+
/** File status */
|
|
26
|
+
status: 'added' | 'removed' | 'modified' | 'renamed';
|
|
27
|
+
/** Individual hunks in this file */
|
|
28
|
+
hunks: DiffHunk[];
|
|
29
|
+
/** The full patch string */
|
|
30
|
+
rawPatch: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Parse a unified diff hunk header.
|
|
35
|
+
* Format: @@ -oldStart,oldCount +newStart,newCount @@ optional header
|
|
36
|
+
*/
|
|
37
|
+
function parseHunkHeader(line: string): Omit<DiffHunk, 'content' | 'lines'> | null {
|
|
38
|
+
const match = line.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);
|
|
39
|
+
if (!match || !match[1] || !match[3]) return null;
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
oldStart: parseInt(match[1], 10),
|
|
43
|
+
oldCount: parseInt(match[2] ?? '1', 10),
|
|
44
|
+
newStart: parseInt(match[3], 10),
|
|
45
|
+
newCount: parseInt(match[4] ?? '1', 10),
|
|
46
|
+
header: match[5]?.trim() || undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Intermediate hunk structure for parsing */
|
|
51
|
+
interface HunkBuilder {
|
|
52
|
+
oldStart: number;
|
|
53
|
+
oldCount: number;
|
|
54
|
+
newStart: number;
|
|
55
|
+
newCount: number;
|
|
56
|
+
header?: string;
|
|
57
|
+
contentParts: string[];
|
|
58
|
+
lines: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Parse a unified diff patch into hunks.
|
|
63
|
+
*/
|
|
64
|
+
export function parsePatch(patch: string): DiffHunk[] {
|
|
65
|
+
const lines = patch.split('\n');
|
|
66
|
+
const hunks: DiffHunk[] = [];
|
|
67
|
+
let currentHunk: HunkBuilder | null = null;
|
|
68
|
+
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
const header = parseHunkHeader(line);
|
|
71
|
+
|
|
72
|
+
if (header) {
|
|
73
|
+
// Save previous hunk if exists
|
|
74
|
+
if (currentHunk) {
|
|
75
|
+
hunks.push({
|
|
76
|
+
...currentHunk,
|
|
77
|
+
content: currentHunk.contentParts.join('\n'),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Start new hunk with array-based content builder
|
|
82
|
+
currentHunk = {
|
|
83
|
+
...header,
|
|
84
|
+
contentParts: [line],
|
|
85
|
+
lines: [],
|
|
86
|
+
};
|
|
87
|
+
} else if (currentHunk) {
|
|
88
|
+
// Add line to current hunk (skip diff metadata lines)
|
|
89
|
+
if (!line.startsWith('diff --git') &&
|
|
90
|
+
!line.startsWith('index ') &&
|
|
91
|
+
!line.startsWith('--- ') &&
|
|
92
|
+
!line.startsWith('+++ ') &&
|
|
93
|
+
!line.startsWith('\\ No newline')) {
|
|
94
|
+
currentHunk.contentParts.push(line);
|
|
95
|
+
currentHunk.lines.push(line);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Don't forget the last hunk
|
|
101
|
+
if (currentHunk) {
|
|
102
|
+
hunks.push({
|
|
103
|
+
...currentHunk,
|
|
104
|
+
content: currentHunk.contentParts.join('\n'),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return hunks;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Parse a file's patch into a structured diff object.
|
|
113
|
+
*/
|
|
114
|
+
export function parseFileDiff(
|
|
115
|
+
filename: string,
|
|
116
|
+
patch: string,
|
|
117
|
+
status: 'added' | 'removed' | 'modified' | 'renamed' = 'modified'
|
|
118
|
+
): ParsedDiff {
|
|
119
|
+
return {
|
|
120
|
+
filename,
|
|
121
|
+
status,
|
|
122
|
+
hunks: parsePatch(patch),
|
|
123
|
+
rawPatch: patch,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get the line range covered by a hunk (in the new file).
|
|
129
|
+
*/
|
|
130
|
+
export function getHunkLineRange(hunk: DiffHunk): { start: number; end: number } {
|
|
131
|
+
return {
|
|
132
|
+
start: hunk.newStart,
|
|
133
|
+
end: hunk.newStart + hunk.newCount - 1,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get an expanded line range for context.
|
|
139
|
+
*/
|
|
140
|
+
export function getExpandedLineRange(
|
|
141
|
+
hunk: DiffHunk,
|
|
142
|
+
contextLines = 20
|
|
143
|
+
): { start: number; end: number } {
|
|
144
|
+
const range = getHunkLineRange(hunk);
|
|
145
|
+
return {
|
|
146
|
+
start: Math.max(1, range.start - contextLines),
|
|
147
|
+
end: range.end + contextLines,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import {
|
|
4
|
+
EventContextSchema,
|
|
5
|
+
type EventContext,
|
|
6
|
+
type FileChange,
|
|
7
|
+
type PullRequestContext,
|
|
8
|
+
type RepositoryContext,
|
|
9
|
+
} from '../types/index.js';
|
|
10
|
+
|
|
11
|
+
// GitHub Action event payload schemas
|
|
12
|
+
const GitHubUserSchema = z.object({
|
|
13
|
+
login: z.string(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const GitHubRepoSchema = z.object({
|
|
17
|
+
name: z.string(),
|
|
18
|
+
full_name: z.string(),
|
|
19
|
+
default_branch: z.string(),
|
|
20
|
+
owner: GitHubUserSchema,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const GitHubPullRequestSchema = z.object({
|
|
24
|
+
number: z.number(),
|
|
25
|
+
title: z.string(),
|
|
26
|
+
body: z.string().nullable(),
|
|
27
|
+
user: GitHubUserSchema,
|
|
28
|
+
base: z.object({
|
|
29
|
+
ref: z.string(),
|
|
30
|
+
}),
|
|
31
|
+
head: z.object({
|
|
32
|
+
ref: z.string(),
|
|
33
|
+
sha: z.string(),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const GitHubEventPayloadSchema = z.object({
|
|
38
|
+
action: z.string(),
|
|
39
|
+
repository: GitHubRepoSchema,
|
|
40
|
+
pull_request: GitHubPullRequestSchema.optional(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export class EventContextError extends Error {
|
|
44
|
+
constructor(message: string, options?: { cause?: unknown }) {
|
|
45
|
+
super(message, options);
|
|
46
|
+
this.name = 'EventContextError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function buildEventContext(
|
|
51
|
+
eventName: string,
|
|
52
|
+
eventPayload: unknown,
|
|
53
|
+
repoPath: string,
|
|
54
|
+
octokit: Octokit
|
|
55
|
+
): Promise<EventContext> {
|
|
56
|
+
const payloadResult = GitHubEventPayloadSchema.safeParse(eventPayload);
|
|
57
|
+
if (!payloadResult.success) {
|
|
58
|
+
throw new EventContextError('Invalid event payload', { cause: payloadResult.error });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const payload = payloadResult.data;
|
|
62
|
+
|
|
63
|
+
const repository: RepositoryContext = {
|
|
64
|
+
owner: payload.repository.owner.login,
|
|
65
|
+
name: payload.repository.name,
|
|
66
|
+
fullName: payload.repository.full_name,
|
|
67
|
+
defaultBranch: payload.repository.default_branch,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let pullRequest: PullRequestContext | undefined;
|
|
71
|
+
|
|
72
|
+
if (eventName === 'pull_request' && payload.pull_request) {
|
|
73
|
+
const pr = payload.pull_request;
|
|
74
|
+
|
|
75
|
+
// Fetch files changed in the PR
|
|
76
|
+
const files = await fetchPullRequestFiles(
|
|
77
|
+
octokit,
|
|
78
|
+
repository.owner,
|
|
79
|
+
repository.name,
|
|
80
|
+
pr.number
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
pullRequest = {
|
|
84
|
+
number: pr.number,
|
|
85
|
+
title: pr.title,
|
|
86
|
+
body: pr.body,
|
|
87
|
+
author: pr.user.login,
|
|
88
|
+
baseBranch: pr.base.ref,
|
|
89
|
+
headBranch: pr.head.ref,
|
|
90
|
+
headSha: pr.head.sha,
|
|
91
|
+
files,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const context: EventContext = {
|
|
96
|
+
eventType: eventName as EventContext['eventType'],
|
|
97
|
+
action: payload.action,
|
|
98
|
+
repository,
|
|
99
|
+
pullRequest,
|
|
100
|
+
repoPath,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Validate the final context
|
|
104
|
+
const result = EventContextSchema.safeParse(context);
|
|
105
|
+
if (!result.success) {
|
|
106
|
+
throw new EventContextError('Failed to build valid event context', { cause: result.error });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return result.data;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function fetchPullRequestFiles(
|
|
113
|
+
octokit: Octokit,
|
|
114
|
+
owner: string,
|
|
115
|
+
repo: string,
|
|
116
|
+
pullNumber: number
|
|
117
|
+
): Promise<FileChange[]> {
|
|
118
|
+
const { data: files } = await octokit.pulls.listFiles({
|
|
119
|
+
owner,
|
|
120
|
+
repo,
|
|
121
|
+
pull_number: pullNumber,
|
|
122
|
+
per_page: 100,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return files.map((file) => ({
|
|
126
|
+
filename: file.filename,
|
|
127
|
+
status: file.status as FileChange['status'],
|
|
128
|
+
additions: file.additions,
|
|
129
|
+
deletions: file.deletions,
|
|
130
|
+
patch: file.patch,
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { EventContext, FileChange } from '../types/index.js';
|
|
2
|
+
import { expandAndCreateFileChanges } from '../cli/files.js';
|
|
3
|
+
import { matchGlob } from '../triggers/matcher.js';
|
|
4
|
+
|
|
5
|
+
export interface ScheduleContextOptions {
|
|
6
|
+
/** Glob patterns from trigger's filters.paths */
|
|
7
|
+
patterns: string[];
|
|
8
|
+
/** Glob patterns from trigger's filters.ignorePaths */
|
|
9
|
+
ignorePatterns?: string[];
|
|
10
|
+
/** Repository root path (GITHUB_WORKSPACE) */
|
|
11
|
+
repoPath: string;
|
|
12
|
+
/** Repository owner (from GITHUB_REPOSITORY) */
|
|
13
|
+
owner: string;
|
|
14
|
+
/** Repository name */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Default branch name */
|
|
17
|
+
defaultBranch: string;
|
|
18
|
+
/** Current commit SHA */
|
|
19
|
+
headSha: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Build an EventContext for scheduled runs.
|
|
24
|
+
*
|
|
25
|
+
* Creates a synthetic pullRequest context from file globs using real repo info.
|
|
26
|
+
* The runner processes this normally because the files have patch data.
|
|
27
|
+
*/
|
|
28
|
+
export async function buildScheduleEventContext(
|
|
29
|
+
options: ScheduleContextOptions
|
|
30
|
+
): Promise<EventContext> {
|
|
31
|
+
const {
|
|
32
|
+
patterns,
|
|
33
|
+
ignorePatterns,
|
|
34
|
+
repoPath,
|
|
35
|
+
owner,
|
|
36
|
+
name,
|
|
37
|
+
defaultBranch,
|
|
38
|
+
headSha,
|
|
39
|
+
} = options;
|
|
40
|
+
|
|
41
|
+
// Expand glob patterns and create FileChange objects with full content as patch
|
|
42
|
+
let fileChanges = await expandAndCreateFileChanges(patterns, repoPath);
|
|
43
|
+
|
|
44
|
+
// Filter out ignored patterns
|
|
45
|
+
if (ignorePatterns && ignorePatterns.length > 0) {
|
|
46
|
+
fileChanges = fileChanges.filter((file) => {
|
|
47
|
+
const isIgnored = ignorePatterns.some((pattern) =>
|
|
48
|
+
matchGlob(pattern, file.filename)
|
|
49
|
+
);
|
|
50
|
+
return !isIgnored;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
eventType: 'schedule',
|
|
56
|
+
action: 'scheduled',
|
|
57
|
+
repository: {
|
|
58
|
+
owner,
|
|
59
|
+
name,
|
|
60
|
+
fullName: `${owner}/${name}`,
|
|
61
|
+
defaultBranch,
|
|
62
|
+
},
|
|
63
|
+
// Synthetic pullRequest context for runner compatibility
|
|
64
|
+
pullRequest: {
|
|
65
|
+
number: 0, // No actual PR
|
|
66
|
+
title: 'Scheduled Analysis',
|
|
67
|
+
body: null,
|
|
68
|
+
author: 'warden',
|
|
69
|
+
baseBranch: defaultBranch,
|
|
70
|
+
headBranch: defaultBranch,
|
|
71
|
+
headSha,
|
|
72
|
+
files: fileChanges,
|
|
73
|
+
},
|
|
74
|
+
repoPath,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Filter file changes to only include files matching the given patterns.
|
|
80
|
+
* Used when a schedule trigger has specific path filters.
|
|
81
|
+
*/
|
|
82
|
+
export function filterFilesByPatterns(
|
|
83
|
+
files: FileChange[],
|
|
84
|
+
patterns: string[],
|
|
85
|
+
ignorePatterns?: string[]
|
|
86
|
+
): FileChange[] {
|
|
87
|
+
let filtered = files.filter((file) =>
|
|
88
|
+
patterns.some((pattern) => matchGlob(pattern, file.filename))
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (ignorePatterns && ignorePatterns.length > 0) {
|
|
92
|
+
filtered = filtered.filter((file) => {
|
|
93
|
+
const isIgnored = ignorePatterns.some((pattern) =>
|
|
94
|
+
matchGlob(pattern, file.filename)
|
|
95
|
+
);
|
|
96
|
+
return !isIgnored;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return filtered;
|
|
101
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
2
|
+
import { discoverExamples, loadExample, getExampleFiles } from './index.js';
|
|
3
|
+
import { runSkill } from '../sdk/runner.js';
|
|
4
|
+
import { buildFileEventContext } from '../cli/context.js';
|
|
5
|
+
import { resolveSkillAsync } from '../skills/loader.js';
|
|
6
|
+
|
|
7
|
+
describe('examples', () => {
|
|
8
|
+
const apiKey = process.env['WARDEN_ANTHROPIC_API_KEY'] ?? process.env['ANTHROPIC_API_KEY'];
|
|
9
|
+
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error('ANTHROPIC_API_KEY (or WARDEN_ANTHROPIC_API_KEY) required for integration tests');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const examples = discoverExamples();
|
|
17
|
+
|
|
18
|
+
if (examples.length === 0) {
|
|
19
|
+
it.skip('no examples found', () => {
|
|
20
|
+
// Placeholder for when no examples exist
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for (const exampleDir of examples) {
|
|
25
|
+
const meta = loadExample(exampleDir);
|
|
26
|
+
// Create a readable name from the path (e.g., "security-review/sql-injection")
|
|
27
|
+
const name = exampleDir.split('/').slice(-2).join('/');
|
|
28
|
+
|
|
29
|
+
it(`${name}: ${meta.description}`, { timeout: 60000 }, async () => {
|
|
30
|
+
const files = getExampleFiles(exampleDir);
|
|
31
|
+
const context = await buildFileEventContext({
|
|
32
|
+
patterns: files,
|
|
33
|
+
cwd: exampleDir,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const skill = await resolveSkillAsync(meta.skill);
|
|
37
|
+
const report = await runSkill(skill, context, { apiKey });
|
|
38
|
+
|
|
39
|
+
// Validate each expected finding
|
|
40
|
+
for (const expected of meta.expected) {
|
|
41
|
+
const pattern = new RegExp(expected.pattern, 'i');
|
|
42
|
+
const found = report.findings.some((f) => {
|
|
43
|
+
// Check severity matches
|
|
44
|
+
if (f.severity !== expected.severity) return false;
|
|
45
|
+
|
|
46
|
+
// Check pattern matches title or description
|
|
47
|
+
const text = `${f.title} ${f.description}`;
|
|
48
|
+
if (!pattern.test(text)) return false;
|
|
49
|
+
|
|
50
|
+
// If file specified, check location matches
|
|
51
|
+
if (expected.file && f.location) {
|
|
52
|
+
if (!f.location.path.endsWith(expected.file)) return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(
|
|
59
|
+
found,
|
|
60
|
+
`Expected ${expected.severity} finding matching "${expected.pattern}"${expected.file ? ` in ${expected.file}` : ''}. ` +
|
|
61
|
+
`Got ${report.findings.length} findings: ${report.findings.map((f) => `[${f.severity}] ${f.title}`).join(', ') || 'none'}`
|
|
62
|
+
).toBe(true);
|
|
63
|
+
}
|
|
64
|
+
}); // LLM calls can be slow
|
|
65
|
+
}
|
|
66
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { discoverExamples, loadExample, getExampleFiles, ExampleMetaSchema } from './index.js';
|
|
4
|
+
|
|
5
|
+
const examplesDir = join(import.meta.dirname, '..', '..', 'examples');
|
|
6
|
+
|
|
7
|
+
describe('discoverExamples', () => {
|
|
8
|
+
it('returns array of example directories', () => {
|
|
9
|
+
const examples = discoverExamples(examplesDir);
|
|
10
|
+
|
|
11
|
+
// All discovered paths should contain _meta.json
|
|
12
|
+
for (const dir of examples) {
|
|
13
|
+
expect(dir).toContain('examples');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('returns empty array for non-existent directory', () => {
|
|
18
|
+
const examples = discoverExamples('/non/existent/path');
|
|
19
|
+
expect(examples).toEqual([]);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('loadExample', () => {
|
|
24
|
+
it('loads and validates _meta.json', () => {
|
|
25
|
+
const examples = discoverExamples(examplesDir);
|
|
26
|
+
if (examples.length === 0) {
|
|
27
|
+
// Skip test when no examples exist
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const meta = loadExample(examples[0]!);
|
|
32
|
+
expect(meta).toHaveProperty('skill');
|
|
33
|
+
expect(meta).toHaveProperty('description');
|
|
34
|
+
expect(meta).toHaveProperty('expected');
|
|
35
|
+
expect(Array.isArray(meta.expected)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('throws for missing _meta.json', () => {
|
|
39
|
+
expect(() => loadExample('/non/existent')).toThrow('No _meta.json found');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('getExampleFiles', () => {
|
|
44
|
+
it('returns source files excluding _meta.json', () => {
|
|
45
|
+
const examples = discoverExamples(examplesDir);
|
|
46
|
+
if (examples.length === 0) {
|
|
47
|
+
// Skip test when no examples exist
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const files = getExampleFiles(examples[0]!);
|
|
52
|
+
expect(files.length).toBeGreaterThan(0);
|
|
53
|
+
|
|
54
|
+
// None of the files should be _meta.json
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
expect(file).not.toContain('_meta.json');
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('ExampleMetaSchema', () => {
|
|
62
|
+
it('validates correct _meta.json', () => {
|
|
63
|
+
const valid = {
|
|
64
|
+
skill: 'security-review',
|
|
65
|
+
description: 'Test example',
|
|
66
|
+
expected: [{ severity: 'critical', pattern: 'test' }],
|
|
67
|
+
};
|
|
68
|
+
const result = ExampleMetaSchema.safeParse(valid);
|
|
69
|
+
expect(result.success).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('validates with optional file field', () => {
|
|
73
|
+
const valid = {
|
|
74
|
+
skill: 'security-review',
|
|
75
|
+
description: 'Test example',
|
|
76
|
+
expected: [{ severity: 'high', pattern: 'test', file: 'test.ts' }],
|
|
77
|
+
};
|
|
78
|
+
const result = ExampleMetaSchema.safeParse(valid);
|
|
79
|
+
expect(result.success).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('rejects invalid severity', () => {
|
|
83
|
+
const invalid = {
|
|
84
|
+
skill: 'security-review',
|
|
85
|
+
description: 'Test example',
|
|
86
|
+
expected: [{ severity: 'invalid', pattern: 'test' }],
|
|
87
|
+
};
|
|
88
|
+
const result = ExampleMetaSchema.safeParse(invalid);
|
|
89
|
+
expect(result.success).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('rejects missing required fields', () => {
|
|
93
|
+
const invalid = {
|
|
94
|
+
skill: 'security-review',
|
|
95
|
+
// missing description
|
|
96
|
+
expected: [],
|
|
97
|
+
};
|
|
98
|
+
const result = ExampleMetaSchema.safeParse(invalid);
|
|
99
|
+
expect(result.success).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { SeveritySchema } from '../types/index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Schema for expected findings in _meta.json
|
|
8
|
+
*/
|
|
9
|
+
export const ExpectedFindingSchema = z.object({
|
|
10
|
+
severity: SeveritySchema,
|
|
11
|
+
pattern: z.string(),
|
|
12
|
+
file: z.string().optional(),
|
|
13
|
+
});
|
|
14
|
+
export type ExpectedFinding = z.infer<typeof ExpectedFindingSchema>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Schema for _meta.json files
|
|
18
|
+
*/
|
|
19
|
+
export const ExampleMetaSchema = z.object({
|
|
20
|
+
skill: z.string(),
|
|
21
|
+
description: z.string(),
|
|
22
|
+
expected: z.array(ExpectedFindingSchema),
|
|
23
|
+
});
|
|
24
|
+
export type ExampleMeta = z.infer<typeof ExampleMetaSchema>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get the default examples directory path.
|
|
28
|
+
*/
|
|
29
|
+
function getExamplesDir(): string {
|
|
30
|
+
// This file is at src/examples/index.ts, so we need to go up to repo root
|
|
31
|
+
return join(import.meta.dirname, '..', '..', 'examples');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Discover all examples with _meta.json files.
|
|
36
|
+
* Returns an array of absolute paths to example directories.
|
|
37
|
+
*/
|
|
38
|
+
export function discoverExamples(baseDir?: string): string[] {
|
|
39
|
+
const examplesDir = baseDir ?? getExamplesDir();
|
|
40
|
+
const examples: string[] = [];
|
|
41
|
+
|
|
42
|
+
if (!existsSync(examplesDir)) {
|
|
43
|
+
return examples;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Recursively find directories containing _meta.json
|
|
47
|
+
function scanDir(dir: string): void {
|
|
48
|
+
const entries = readdirSync(dir);
|
|
49
|
+
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
const entryPath = join(dir, entry);
|
|
52
|
+
const stat = statSync(entryPath);
|
|
53
|
+
|
|
54
|
+
if (stat.isDirectory()) {
|
|
55
|
+
const metaPath = join(entryPath, '_meta.json');
|
|
56
|
+
if (existsSync(metaPath)) {
|
|
57
|
+
examples.push(entryPath);
|
|
58
|
+
}
|
|
59
|
+
// Continue scanning subdirectories
|
|
60
|
+
scanDir(entryPath);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
scanDir(examplesDir);
|
|
66
|
+
return examples;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Load and validate a _meta.json file from an example directory.
|
|
71
|
+
*/
|
|
72
|
+
export function loadExample(dir: string): ExampleMeta {
|
|
73
|
+
const metaPath = join(dir, '_meta.json');
|
|
74
|
+
|
|
75
|
+
if (!existsSync(metaPath)) {
|
|
76
|
+
throw new Error(`No _meta.json found in ${dir}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let content: string;
|
|
80
|
+
try {
|
|
81
|
+
content = readFileSync(metaPath, 'utf-8');
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error(`Failed to read ${metaPath}: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let parsed: unknown;
|
|
87
|
+
try {
|
|
88
|
+
parsed = JSON.parse(content);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw new Error(`Failed to parse ${metaPath}: ${error}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const validated = ExampleMetaSchema.safeParse(parsed);
|
|
94
|
+
if (!validated.success) {
|
|
95
|
+
const issues = validated.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join(', ');
|
|
96
|
+
throw new Error(`Invalid _meta.json in ${dir}: ${issues}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return validated.data;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get all source files in an example directory (excludes _meta.json).
|
|
104
|
+
* Returns relative paths suitable for use with buildFileEventContext.
|
|
105
|
+
*/
|
|
106
|
+
export function getExampleFiles(dir: string): string[] {
|
|
107
|
+
const files: string[] = [];
|
|
108
|
+
|
|
109
|
+
const entries = readdirSync(dir);
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
if (entry === '_meta.json') continue;
|
|
112
|
+
|
|
113
|
+
const entryPath = join(dir, entry);
|
|
114
|
+
const stat = statSync(entryPath);
|
|
115
|
+
|
|
116
|
+
if (stat.isFile()) {
|
|
117
|
+
files.push(entryPath);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return files;
|
|
122
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { config as dotenvConfig } from 'dotenv';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Load environment variables for integration tests.
|
|
7
|
+
* Loads in order (later files override earlier):
|
|
8
|
+
* 1. .env (base config)
|
|
9
|
+
* 2. .env.local (local overrides)
|
|
10
|
+
* 3. .env.test (test-specific overrides)
|
|
11
|
+
*/
|
|
12
|
+
function loadTestEnv(): void {
|
|
13
|
+
const root = join(import.meta.dirname, '..', '..');
|
|
14
|
+
|
|
15
|
+
const envFiles = ['.env', '.env.local', '.env.test'];
|
|
16
|
+
|
|
17
|
+
for (const file of envFiles) {
|
|
18
|
+
const path = join(root, file);
|
|
19
|
+
if (existsSync(path)) {
|
|
20
|
+
dotenvConfig({ path, override: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
loadTestEnv();
|