Skip to content

Commit dbea582

Browse files
committed
feat: spec templates — security-audit, code-review, api-build, data-analysis, documentation, bug-fix
1 parent ee49542 commit dbea582

2 files changed

Lines changed: 260 additions & 0 deletions

File tree

sdk/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export {
1616
hashVerificationResult,
1717
validateSpec,
1818
} from './spec'
19+
export {
20+
getTemplate,
21+
listTemplates,
22+
applyTemplate,
23+
} from './templates'
24+
export type { TemplateId, SpecTemplate } from './templates'
1925
export type {
2026
TaskForestSpec,
2127
AcceptanceCriterion,

sdk/src/templates.ts

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
import type { TaskForestSpec } from './spec'
2+
3+
export type TemplateId =
4+
| 'security-audit'
5+
| 'code-review'
6+
| 'api-build'
7+
| 'data-analysis'
8+
| 'documentation'
9+
| 'bug-fix'
10+
11+
export interface SpecTemplate {
12+
id: TemplateId
13+
name: string
14+
description: string
15+
tags: string[]
16+
spec: TaskForestSpec
17+
}
18+
19+
const securityAudit: SpecTemplate = {
20+
id: 'security-audit',
21+
name: 'Security Audit',
22+
description: 'Smart contract or application security review',
23+
tags: ['security', 'audit'],
24+
spec: {
25+
version: 1,
26+
metadata: {
27+
title: '',
28+
tags: ['security', 'audit'],
29+
difficulty: 'hard',
30+
estimated_duration: '4h',
31+
},
32+
description: '',
33+
acceptance_criteria: [
34+
{ id: 'ac-1', description: 'Check for reentrancy vulnerabilities', type: 'coverage', required: true, weight: 20 },
35+
{ id: 'ac-2', description: 'Check for integer overflow/underflow', type: 'coverage', required: true, weight: 15 },
36+
{ id: 'ac-3', description: 'Check for access control issues', type: 'coverage', required: true, weight: 20 },
37+
{ id: 'ac-4', description: 'Check for input validation gaps', type: 'coverage', required: true, weight: 15 },
38+
{ id: 'ac-5', description: 'Produce a findings report with severity ratings', type: 'output', required: true, weight: 20 },
39+
{ id: 'ac-6', description: 'All critical findings include fix recommendations', type: 'output', required: true, weight: 10 },
40+
],
41+
constraints: [],
42+
inputs: [{ type: 'file', description: 'Source code to audit', encrypted: true }],
43+
outputs: [
44+
{ type: 'file', description: 'Audit report', format: 'markdown' },
45+
{ type: 'structured', description: 'Machine-readable findings', format: 'json' },
46+
],
47+
verification: {
48+
mode: 'judge',
49+
config: {
50+
pass_threshold: 70,
51+
rubric: 'Score each criterion 0-100 based on thoroughness. Missing critical vulnerabilities = automatic fail for that criterion.',
52+
required_criteria_must_pass: true,
53+
},
54+
},
55+
},
56+
}
57+
58+
const codeReview: SpecTemplate = {
59+
id: 'code-review',
60+
name: 'Code Review',
61+
description: 'Code quality, best practices, and architecture review',
62+
tags: ['code-review', 'quality'],
63+
spec: {
64+
version: 1,
65+
metadata: {
66+
title: '',
67+
tags: ['code-review', 'quality'],
68+
difficulty: 'medium',
69+
estimated_duration: '2h',
70+
},
71+
description: '',
72+
acceptance_criteria: [
73+
{ id: 'ac-1', description: 'Review code structure and organization', type: 'coverage', required: true, weight: 20 },
74+
{ id: 'ac-2', description: 'Check for common anti-patterns and code smells', type: 'coverage', required: true, weight: 20 },
75+
{ id: 'ac-3', description: 'Verify error handling completeness', type: 'coverage', required: true, weight: 20 },
76+
{ id: 'ac-4', description: 'Check type safety and null handling', type: 'coverage', required: true, weight: 15 },
77+
{ id: 'ac-5', description: 'Produce a review summary with actionable feedback', type: 'output', required: true, weight: 25 },
78+
],
79+
constraints: [],
80+
inputs: [{ type: 'file', description: 'Source code to review', encrypted: true }],
81+
outputs: [{ type: 'file', description: 'Review report with inline comments', format: 'markdown' }],
82+
verification: {
83+
mode: 'judge',
84+
config: {
85+
pass_threshold: 65,
86+
rubric: 'Score each criterion 0-100 based on depth and actionability of feedback.',
87+
required_criteria_must_pass: true,
88+
},
89+
},
90+
},
91+
}
92+
93+
const apiBuild: SpecTemplate = {
94+
id: 'api-build',
95+
name: 'API Build',
96+
description: 'Build REST/GraphQL API endpoints with tests',
97+
tags: ['backend', 'api'],
98+
spec: {
99+
version: 1,
100+
metadata: {
101+
title: '',
102+
tags: ['backend', 'api'],
103+
difficulty: 'medium',
104+
estimated_duration: '4h',
105+
},
106+
description: '',
107+
acceptance_criteria: [
108+
{ id: 'ac-1', description: 'All specified endpoints implemented and return correct status codes', type: 'test', required: true, weight: 30 },
109+
{ id: 'ac-2', description: 'Input validation on all endpoints', type: 'test', required: true, weight: 20 },
110+
{ id: 'ac-3', description: 'Error responses follow consistent format', type: 'test', required: true, weight: 15 },
111+
{ id: 'ac-4', description: 'Test suite included with >80% coverage', type: 'test', required: true, weight: 25 },
112+
{ id: 'ac-5', description: 'API documentation or OpenAPI spec produced', type: 'output', required: false, weight: 10 },
113+
],
114+
constraints: [],
115+
inputs: [{ type: 'text', description: 'API requirements and existing project context', encrypted: false }],
116+
outputs: [
117+
{ type: 'file', description: 'Source code', format: 'typescript' },
118+
{ type: 'file', description: 'Test suite', format: 'typescript' },
119+
],
120+
verification: {
121+
mode: 'test_suite',
122+
config: { test_command: 'npm test', required_criteria_must_pass: true },
123+
},
124+
},
125+
}
126+
127+
const dataAnalysis: SpecTemplate = {
128+
id: 'data-analysis',
129+
name: 'Data Analysis',
130+
description: 'Analyze datasets and produce insights',
131+
tags: ['data', 'analysis'],
132+
spec: {
133+
version: 1,
134+
metadata: {
135+
title: '',
136+
tags: ['data', 'analysis'],
137+
difficulty: 'medium',
138+
estimated_duration: '3h',
139+
},
140+
description: '',
141+
acceptance_criteria: [
142+
{ id: 'ac-1', description: 'Data cleaned and validated', type: 'coverage', required: true, weight: 20 },
143+
{ id: 'ac-2', description: 'Key metrics computed and explained', type: 'output', required: true, weight: 25 },
144+
{ id: 'ac-3', description: 'Visualizations produced for key findings', type: 'output', required: true, weight: 20 },
145+
{ id: 'ac-4', description: 'Summary report with actionable insights', type: 'output', required: true, weight: 25 },
146+
{ id: 'ac-5', description: 'Methodology documented and reproducible', type: 'coverage', required: false, weight: 10 },
147+
],
148+
constraints: [],
149+
inputs: [{ type: 'file', description: 'Dataset to analyze', encrypted: true }],
150+
outputs: [
151+
{ type: 'file', description: 'Analysis report', format: 'markdown' },
152+
{ type: 'structured', description: 'Computed metrics', format: 'json' },
153+
],
154+
verification: {
155+
mode: 'judge',
156+
config: {
157+
pass_threshold: 65,
158+
rubric: 'Score based on insight depth, accuracy of metrics, and clarity of presentation.',
159+
required_criteria_must_pass: true,
160+
},
161+
},
162+
},
163+
}
164+
165+
const documentation: SpecTemplate = {
166+
id: 'documentation',
167+
name: 'Documentation',
168+
description: 'Write or improve technical documentation',
169+
tags: ['docs', 'writing'],
170+
spec: {
171+
version: 1,
172+
metadata: {
173+
title: '',
174+
tags: ['docs', 'writing'],
175+
difficulty: 'easy',
176+
estimated_duration: '2h',
177+
},
178+
description: '',
179+
acceptance_criteria: [
180+
{ id: 'ac-1', description: 'All public APIs or features documented', type: 'coverage', required: true, weight: 30 },
181+
{ id: 'ac-2', description: 'Code examples included for key features', type: 'output', required: true, weight: 25 },
182+
{ id: 'ac-3', description: 'Getting started guide included', type: 'output', required: true, weight: 20 },
183+
{ id: 'ac-4', description: 'No broken links or references', type: 'test', required: true, weight: 15 },
184+
{ id: 'ac-5', description: 'Consistent formatting and style', type: 'coverage', required: false, weight: 10 },
185+
],
186+
constraints: [],
187+
inputs: [{ type: 'file', description: 'Source code or existing docs', encrypted: false }],
188+
outputs: [{ type: 'file', description: 'Documentation files', format: 'markdown' }],
189+
verification: {
190+
mode: 'poster_review',
191+
config: { required_criteria_must_pass: true },
192+
},
193+
},
194+
}
195+
196+
const bugFix: SpecTemplate = {
197+
id: 'bug-fix',
198+
name: 'Bug Fix',
199+
description: 'Diagnose and fix a specific bug',
200+
tags: ['bugfix', 'debugging'],
201+
spec: {
202+
version: 1,
203+
metadata: {
204+
title: '',
205+
tags: ['bugfix', 'debugging'],
206+
difficulty: 'medium',
207+
estimated_duration: '2h',
208+
},
209+
description: '',
210+
acceptance_criteria: [
211+
{ id: 'ac-1', description: 'Root cause identified and documented', type: 'output', required: true, weight: 25 },
212+
{ id: 'ac-2', description: 'Fix implemented with minimal changes', type: 'coverage', required: true, weight: 25 },
213+
{ id: 'ac-3', description: 'Existing tests still pass', type: 'test', required: true, weight: 20 },
214+
{ id: 'ac-4', description: 'Regression test added for the bug', type: 'test', required: true, weight: 20 },
215+
{ id: 'ac-5', description: 'No unrelated changes in the diff', type: 'coverage', required: true, weight: 10 },
216+
],
217+
constraints: ['Fix must be minimal — no refactoring alongside the bugfix'],
218+
inputs: [{ type: 'text', description: 'Bug report with reproduction steps', encrypted: false }],
219+
outputs: [
220+
{ type: 'file', description: 'Code changes (patch or branch)', format: 'typescript' },
221+
{ type: 'file', description: 'Root cause analysis', format: 'markdown' },
222+
],
223+
verification: {
224+
mode: 'test_suite',
225+
config: { test_command: 'npm test', required_criteria_must_pass: true },
226+
},
227+
},
228+
}
229+
230+
const TEMPLATES: Record<TemplateId, SpecTemplate> = {
231+
'security-audit': securityAudit,
232+
'code-review': codeReview,
233+
'api-build': apiBuild,
234+
'data-analysis': dataAnalysis,
235+
'documentation': documentation,
236+
'bug-fix': bugFix,
237+
}
238+
239+
export function getTemplate(id: TemplateId): SpecTemplate {
240+
const template = TEMPLATES[id]
241+
if (!template) throw new Error(`Unknown template: ${id}`)
242+
return JSON.parse(JSON.stringify(template)) as SpecTemplate
243+
}
244+
245+
export function listTemplates(): SpecTemplate[] {
246+
return Object.values(TEMPLATES).map((t) => JSON.parse(JSON.stringify(t)) as SpecTemplate)
247+
}
248+
249+
export function applyTemplate(id: TemplateId, title: string, description: string): TaskForestSpec {
250+
const template = getTemplate(id)
251+
template.spec.metadata.title = title
252+
template.spec.description = description
253+
return template.spec
254+
}

0 commit comments

Comments
 (0)