@moskala/oneagent-templates 0.2.2
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/package.json +22 -0
- package/src/index.ts +62 -0
- package/src/templates/default/instructions.md +3 -0
- package/src/templates/default/template.yml +3 -0
- package/src/templates/react/instructions.md +15 -0
- package/src/templates/react/template.yml +5 -0
- package/src/templates/react-native/instructions.md +15 -0
- package/src/templates/react-native/template.yml +3 -0
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moskala/oneagent-templates",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Built-in templates for oneagent",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"module": "./src/index.ts",
|
|
8
|
+
"main": "./src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/bun": "latest",
|
|
20
|
+
"typescript": "^5"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
|
|
4
|
+
export interface TemplateDefinition {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
skills: string[];
|
|
8
|
+
instructions: string;
|
|
9
|
+
rules: Array<{ name: string; content: string }>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type BuiltinTemplateName = "default" | "react" | "react-native";
|
|
13
|
+
|
|
14
|
+
const TEMPLATE_NAMES: BuiltinTemplateName[] = ["default", "react", "react-native"];
|
|
15
|
+
|
|
16
|
+
async function loadTemplate(name: BuiltinTemplateName): Promise<TemplateDefinition> {
|
|
17
|
+
const templateDir = path.join(import.meta.dir, "templates", name);
|
|
18
|
+
|
|
19
|
+
const [yamlText, instructions] = await Promise.all([
|
|
20
|
+
Bun.file(path.join(templateDir, "template.yml")).text(),
|
|
21
|
+
Bun.file(path.join(templateDir, "instructions.md")).text(),
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
// Minimal YAML parsing for our simple structure
|
|
25
|
+
const descMatch = yamlText.match(/^description:\s*(.+)$/m);
|
|
26
|
+
const description = descMatch?.[1]?.trim() ?? "";
|
|
27
|
+
|
|
28
|
+
const skills: string[] = [];
|
|
29
|
+
const skillsBlockMatch = yamlText.match(/^skills:\s*\n((?: - .+\n?)*)/m);
|
|
30
|
+
if (skillsBlockMatch) {
|
|
31
|
+
const lines = skillsBlockMatch[1]!.split("\n").filter(Boolean);
|
|
32
|
+
for (const line of lines) {
|
|
33
|
+
const skill = line.replace(/^\s*-\s*/, "").trim();
|
|
34
|
+
if (skill) skills.push(skill);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const rulesDir = path.join(templateDir, "rules");
|
|
39
|
+
let rules: Array<{ name: string; content: string }> = [];
|
|
40
|
+
try {
|
|
41
|
+
const ruleFiles = await fs.readdir(rulesDir);
|
|
42
|
+
rules = await Promise.all(
|
|
43
|
+
ruleFiles
|
|
44
|
+
.filter((f) => f.endsWith(".md"))
|
|
45
|
+
.map(async (f) => ({
|
|
46
|
+
name: path.basename(f, ".md"),
|
|
47
|
+
content: await Bun.file(path.join(rulesDir, f)).text(),
|
|
48
|
+
})),
|
|
49
|
+
);
|
|
50
|
+
} catch {
|
|
51
|
+
// No rules directory — fine
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { name, description, skills, instructions, rules };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function resolveBuiltinTemplate(name: string): Promise<TemplateDefinition | null> {
|
|
58
|
+
if (!TEMPLATE_NAMES.includes(name as BuiltinTemplateName)) return null;
|
|
59
|
+
return loadTemplate(name as BuiltinTemplateName);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const BUILTIN_TEMPLATE_NAMES: readonly string[] = TEMPLATE_NAMES;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Project Instructions
|
|
2
|
+
|
|
3
|
+
This is a React project. Follow modern React best practices.
|
|
4
|
+
|
|
5
|
+
## Stack
|
|
6
|
+
|
|
7
|
+
- React 18+
|
|
8
|
+
- TypeScript
|
|
9
|
+
- Prefer functional components and hooks
|
|
10
|
+
|
|
11
|
+
## Guidelines
|
|
12
|
+
|
|
13
|
+
- Use composition over inheritance
|
|
14
|
+
- Keep components small and focused
|
|
15
|
+
- Colocate state as close to where it's used as possible
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Project Instructions
|
|
2
|
+
|
|
3
|
+
This is a React Native project. Target both iOS and Android.
|
|
4
|
+
|
|
5
|
+
## Stack
|
|
6
|
+
|
|
7
|
+
- React Native with Expo
|
|
8
|
+
- TypeScript
|
|
9
|
+
- Prefer functional components and hooks
|
|
10
|
+
|
|
11
|
+
## Guidelines
|
|
12
|
+
|
|
13
|
+
- Use `StyleSheet.create` for styles
|
|
14
|
+
- Avoid platform-specific code unless necessary; use `Platform.select` when needed
|
|
15
|
+
- Prefer Expo SDK APIs over bare React Native APIs
|