@riotprompt/riotprompt 0.0.1 → 0.0.3
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/README.md +54 -470
- package/dist/builder.d.ts +3 -3
- package/dist/builder.js +7 -2
- package/dist/builder.js.map +1 -1
- package/dist/chat.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/formatter.js.map +1 -1
- package/dist/items/content.js.map +1 -1
- package/dist/items/context.js.map +1 -1
- package/dist/items/instruction.js.map +1 -1
- package/dist/items/parameters.js.map +1 -1
- package/dist/items/section.js.map +1 -1
- package/dist/items/trait.js.map +1 -1
- package/dist/items/weighted.js.map +1 -1
- package/dist/loader.js +1 -0
- package/dist/loader.js.map +1 -1
- package/dist/logger.js +4 -2
- package/dist/logger.js.map +1 -1
- package/dist/override.d.ts +5 -5
- package/dist/override.js +47 -30
- package/dist/override.js.map +1 -1
- package/dist/parse/markdown.js.map +1 -1
- package/dist/parse/text.js.map +1 -1
- package/dist/parser.js.map +1 -1
- package/dist/prompt.js.map +1 -1
- package/dist/recipes.d.ts +405 -0
- package/dist/recipes.js +424 -0
- package/dist/recipes.js.map +1 -0
- package/dist/riotprompt.cjs +586 -132
- package/dist/riotprompt.cjs.map +1 -1
- package/dist/riotprompt.d.ts +3 -0
- package/dist/riotprompt.js +3 -0
- package/dist/riotprompt.js.map +1 -1
- package/dist/util/general.js.map +1 -1
- package/dist/util/markdown.js.map +1 -1
- package/dist/util/storage.js.map +1 -1
- package/dist/util/text.js.map +1 -1
- package/package.json +35 -28
- package/.gitcarve/config.yaml +0 -10
- package/.gitcarve/context/content.md +0 -11
- package/.markdown-doctest-setup.mjs +0 -23
- package/.nvmrc +0 -1
- package/dist/builder.cjs +0 -152
- package/dist/builder.cjs.map +0 -1
- package/dist/chat.cjs +0 -26
- package/dist/chat.cjs.map +0 -1
- package/dist/constants.cjs +0 -34
- package/dist/constants.cjs.map +0 -1
- package/dist/formatter.cjs +0 -139
- package/dist/formatter.cjs.map +0 -1
- package/dist/items/content.cjs +0 -14
- package/dist/items/content.cjs.map +0 -1
- package/dist/items/context.cjs +0 -13
- package/dist/items/context.cjs.map +0 -1
- package/dist/items/instruction.cjs +0 -13
- package/dist/items/instruction.cjs.map +0 -1
- package/dist/items/parameters.cjs +0 -53
- package/dist/items/parameters.cjs.map +0 -1
- package/dist/items/section.cjs +0 -120
- package/dist/items/section.cjs.map +0 -1
- package/dist/items/trait.cjs +0 -13
- package/dist/items/trait.cjs.map +0 -1
- package/dist/items/weighted.cjs +0 -27
- package/dist/items/weighted.cjs.map +0 -1
- package/dist/loader.cjs +0 -167
- package/dist/loader.cjs.map +0 -1
- package/dist/logger.cjs +0 -51
- package/dist/logger.cjs.map +0 -1
- package/dist/override.cjs +0 -109
- package/dist/override.cjs.map +0 -1
- package/dist/parse/markdown.cjs +0 -114
- package/dist/parse/markdown.cjs.map +0 -1
- package/dist/parse/text.cjs +0 -33
- package/dist/parse/text.cjs.map +0 -1
- package/dist/parser.cjs +0 -99
- package/dist/parser.cjs.map +0 -1
- package/dist/prompt.cjs +0 -15
- package/dist/prompt.cjs.map +0 -1
- package/dist/util/general.cjs +0 -52
- package/dist/util/general.cjs.map +0 -1
- package/dist/util/markdown.cjs +0 -115
- package/dist/util/markdown.cjs.map +0 -1
- package/dist/util/storage.cjs +0 -155
- package/dist/util/storage.cjs.map +0 -1
- package/dist/util/text.cjs +0 -42
- package/dist/util/text.cjs.map +0 -1
- package/docs/loader.md +0 -237
- package/docs/override.md +0 -323
- package/docs/parser.md +0 -130
- package/eslint.config.mjs +0 -82
- package/nodemon.json +0 -14
- package/vite.config.ts +0 -114
- package/vitest.config.ts +0 -25
package/docs/parser.md
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
# riotprompt Parser Utility
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The **Parser** utility in riotprompt allows you to convert Markdown content into riotprompt's structured prompt format. This means you can write prompt sections, instructions, and context in a Markdown file (using headings, lists, etc.) and then use the Parser to turn that into riotprompt Section objects. By using the Parser, you focus on writing clear prompt text in Markdown, while riotprompt handles building the internal structure (sections and items) for you.
|
|
6
|
-
|
|
7
|
-
Key capabilities of the Parser include:
|
|
8
|
-
|
|
9
|
-
* **Markdown to Sections**: Automatically interpreting markdown headers as section titles and text as section content.
|
|
10
|
-
* **Nested Structure**: Handling nested headers (e.g. `#`, `##`, `###`) by creating nested Section structures.
|
|
11
|
-
* **List Items**: Treating bullet or numbered list items as individual items in a section.
|
|
12
|
-
* **Paragraph Separation**: Treating separate paragraphs (separated by blank lines) as distinct items.
|
|
13
|
-
|
|
14
|
-
This makes it easy to draft complex prompts in a markdown document and programmatically load them into your application.
|
|
15
|
-
|
|
16
|
-
## Creating a Parser
|
|
17
|
-
|
|
18
|
-
To use the Parser, import it from the riotprompt library and create an instance. riotprompt uses a factory method pattern; you create a Parser via the static `Parser.create()` method. The `create` method can accept an optional configuration object to adjust parsing behavior.
|
|
19
|
-
|
|
20
|
-
**Syntax:**
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
const parser = Parser.create(options?);
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
If no options are provided, the parser will use default behavior that suits most use cases (detailed below).
|
|
27
|
-
|
|
28
|
-
### Parser.create Options
|
|
29
|
-
|
|
30
|
-
When calling `Parser.create`, you can supply an object to customize its behavior. All options are optional. Here are the options available for the Parser's creation:
|
|
31
|
-
|
|
32
|
-
* **`logger`** (Logger): An optional logger object for receiving information about the parsing process.
|
|
33
|
-
* **`parameters`** (Parameters object): A **Parameters** object containing placeholder values to substitute into the text while parsing. If provided, any placeholders in the form `{{variable}}` found in the markdown content will be replaced with the corresponding values from this object as the parser constructs the items.
|
|
34
|
-
|
|
35
|
-
### Using the Parser
|
|
36
|
-
|
|
37
|
-
Once you have a Parser instance, use the `parse` method to convert a markdown string (or file content) into a Section structure. The result of `parser.parse(...)` is usually a `Section` object representing the top-level section (or a container section) of the parsed content.
|
|
38
|
-
|
|
39
|
-
**Example:** Parse a markdown string with multiple sections.
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { Parser, Section } from '@riotprompt';
|
|
43
|
-
|
|
44
|
-
const markdownContent = `
|
|
45
|
-
# Instructions
|
|
46
|
-
Follow these guidelines when writing code.
|
|
47
|
-
|
|
48
|
-
## Best Practices
|
|
49
|
-
- Keep functions small and focused
|
|
50
|
-
- Use meaningful variable names
|
|
51
|
-
|
|
52
|
-
## Documentation
|
|
53
|
-
- Comment complex logic
|
|
54
|
-
- Document public APIs thoroughly
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
// Create a Parser (with default options)
|
|
58
|
-
const parser = Parser.create();
|
|
59
|
-
|
|
60
|
-
// Parse the markdown into a Section structure
|
|
61
|
-
const rootSection: Section = parser.parse(markdownContent);
|
|
62
|
-
|
|
63
|
-
// The rootSection now represents "Instructions" with two subsections inside.
|
|
64
|
-
console.log(rootSection.title);
|
|
65
|
-
// Output: "Instructions"
|
|
66
|
-
|
|
67
|
-
// Accessing subsections by index:
|
|
68
|
-
const bestPractices = rootSection.items[1] as Section;
|
|
69
|
-
console.log(bestPractices.title);
|
|
70
|
-
// Output: "Best Practices"
|
|
71
|
-
|
|
72
|
-
// Items within a section:
|
|
73
|
-
for (const item of bestPractices.items) {
|
|
74
|
-
console.log(item.text);
|
|
75
|
-
}
|
|
76
|
-
// Output:
|
|
77
|
-
// "Keep functions small and focused"
|
|
78
|
-
// "Use meaningful variable names"
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
In this example:
|
|
82
|
-
|
|
83
|
-
* The top-level `# Instructions` became a Section titled "Instructions" (`rootSection`).
|
|
84
|
-
* The content under "Instructions" before any sub-heading (`"Follow these guidelines when writing code."`) became the first item of `rootSection`.
|
|
85
|
-
* The `## Best Practices` line created a subsection (another Section) within Instructions.
|
|
86
|
-
* Each bullet point under "Best Practices" became a separate item in that subsection.
|
|
87
|
-
* Similarly, `## Documentation` became another subsection with its own list of items.
|
|
88
|
-
|
|
89
|
-
You can now manipulate these sections in code. For instance, you might add another item:
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
bestPractices.add("- Write tests for your code");
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
This appends a new bullet item under "Best Practices". The parser makes it easy to initialize complex structures, which you can then modify or combine with other sections.
|
|
96
|
-
|
|
97
|
-
### Parsing Files Directly
|
|
98
|
-
|
|
99
|
-
The Parser provides a convenient `parseFile` method to directly parse Markdown files from disk:
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
const section = parser.parseFile('./prompts/instructions/code-style.md');
|
|
103
|
-
console.log(`Parsed section titled: ${section.title}`);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
This method handles reading the file and parsing its content in a single step, making it easier to load prompt content from files.
|
|
107
|
-
|
|
108
|
-
If you prefer to read files manually, you can still use the standard `parse` method:
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
import * as fs from 'fs';
|
|
112
|
-
const fileText = fs.readFileSync('./prompts/instructions/code-style.md', 'utf-8');
|
|
113
|
-
const parser = Parser.create({
|
|
114
|
-
logger: console
|
|
115
|
-
});
|
|
116
|
-
const section = parser.parse(fileText);
|
|
117
|
-
console.log(`Parsed section titled: ${section.title}`);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
This will read a markdown file from the filesystem and parse it into a Section. The example provides a simple logger to track the parsing process.
|
|
121
|
-
|
|
122
|
-
## Notes and Tips
|
|
123
|
-
|
|
124
|
-
* **Headings as Structure**: The Parser treats Markdown headings (`#`, `##`, etc.) as structural markers. Ensure your markdown content uses headings for logical sections you want to separate in the prompt. Text that is not under any heading will be grouped under an implicit section.
|
|
125
|
-
* **Lists and Paragraphs**: Bullet lists (`- ` or `* ` or numbered lists) are split into individual items. Normal paragraphs separated by blank lines are also treated as separate items. This means in the final Section object, each bullet or paragraph is one `Instruction`, `Content` or `Context` item (depending on usage).
|
|
126
|
-
* **Markdown Formatting**: The parser handles basic Markdown syntax, converting it into an internal structure. The formatting style (whether using tags or markdown) will be handled by the Formatter when producing the final prompt string.
|
|
127
|
-
* **Combining with Formatter**: The Parser simply builds the internal representation. To get a prompt string to send to an LLM, you would pass the resulting Section into a `Formatter`. Formatter will apply formatting options (like using XML-style tags or Markdown headings) to produce the final prompt text. For example, `Formatter.create().format(section)`.
|
|
128
|
-
|
|
129
|
-
Using the Parser utility, you can maintain your prompt content in easy-to-edit markdown files or strings, and reliably construct structured prompt objects for further manipulation or formatting.
|
|
130
|
-
|
package/eslint.config.mjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
3
|
-
import importPlugin from "eslint-plugin-import";
|
|
4
|
-
import globals from "globals";
|
|
5
|
-
import tsParser from "@typescript-eslint/parser";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import js from "@eslint/js";
|
|
9
|
-
import { FlatCompat } from "@eslint/eslintrc";
|
|
10
|
-
|
|
11
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
-
const __dirname = path.dirname(__filename);
|
|
13
|
-
const compat = new FlatCompat({
|
|
14
|
-
baseDirectory: __dirname,
|
|
15
|
-
recommendedConfig: js.configs.recommended,
|
|
16
|
-
allConfig: js.configs.all
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export default defineConfig([
|
|
20
|
-
globalIgnores([
|
|
21
|
-
"dist/**",
|
|
22
|
-
"node_modules/**",
|
|
23
|
-
"**/*.test.ts",
|
|
24
|
-
]),
|
|
25
|
-
{
|
|
26
|
-
extends: compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"),
|
|
27
|
-
|
|
28
|
-
plugins: {
|
|
29
|
-
"@typescript-eslint": typescriptEslint,
|
|
30
|
-
"import": importPlugin,
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
languageOptions: {
|
|
34
|
-
globals: {
|
|
35
|
-
...globals.node,
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
parser: tsParser,
|
|
39
|
-
ecmaVersion: "latest",
|
|
40
|
-
sourceType: "module",
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
rules: {
|
|
44
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
45
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
46
|
-
|
|
47
|
-
"@typescript-eslint/no-unused-vars": ["warn", {
|
|
48
|
-
argsIgnorePattern: "^_",
|
|
49
|
-
}],
|
|
50
|
-
|
|
51
|
-
indent: ["error", 4, {
|
|
52
|
-
SwitchCase: 1,
|
|
53
|
-
}],
|
|
54
|
-
|
|
55
|
-
"import/extensions": ["error", "never", {
|
|
56
|
-
ignorePackages: true,
|
|
57
|
-
pattern: {
|
|
58
|
-
"js": "never",
|
|
59
|
-
"ts": "never",
|
|
60
|
-
"d": "always"
|
|
61
|
-
}
|
|
62
|
-
}],
|
|
63
|
-
|
|
64
|
-
"import/no-extraneous-dependencies": ["error", {
|
|
65
|
-
devDependencies: true,
|
|
66
|
-
optionalDependencies: false,
|
|
67
|
-
peerDependencies: false,
|
|
68
|
-
}],
|
|
69
|
-
|
|
70
|
-
"no-console": ["error"],
|
|
71
|
-
|
|
72
|
-
"no-restricted-imports": ["error", {
|
|
73
|
-
paths: ["dayjs", "fs", "moment-timezone"],
|
|
74
|
-
patterns: [
|
|
75
|
-
{
|
|
76
|
-
group: ["src/**"],
|
|
77
|
-
message: "Use absolute imports instead of relative imports"
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
}]
|
|
81
|
-
},
|
|
82
|
-
}]);
|
package/nodemon.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import { VitePluginNode } from 'vite-plugin-node';
|
|
3
|
-
import replace from '@rollup/plugin-replace';
|
|
4
|
-
// import { visualizer } from 'rollup-plugin-visualizer';
|
|
5
|
-
import { execSync } from 'child_process';
|
|
6
|
-
import shebang from 'rollup-plugin-preserve-shebang';
|
|
7
|
-
import dts from 'vite-plugin-dts';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
|
|
10
|
-
let gitInfo = {
|
|
11
|
-
branch: '',
|
|
12
|
-
commit: '',
|
|
13
|
-
tags: '',
|
|
14
|
-
commitDate: '',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
gitInfo = {
|
|
19
|
-
branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
|
|
20
|
-
commit: execSync('git rev-parse --short HEAD').toString().trim(),
|
|
21
|
-
tags: '',
|
|
22
|
-
commitDate: execSync('git log -1 --format=%cd --date=iso').toString().trim(),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
gitInfo.tags = execSync('git tag --points-at HEAD | paste -sd "," -').toString().trim();
|
|
27
|
-
} catch {
|
|
28
|
-
gitInfo.tags = '';
|
|
29
|
-
}
|
|
30
|
-
} catch {
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
console.log('Directory does not have a Git repository, skipping git info');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export default defineConfig({
|
|
37
|
-
server: {
|
|
38
|
-
port: 3000
|
|
39
|
-
},
|
|
40
|
-
resolve: {
|
|
41
|
-
alias: {
|
|
42
|
-
'@': path.resolve(__dirname, './src')
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
plugins: [
|
|
46
|
-
...VitePluginNode({
|
|
47
|
-
adapter: 'express',
|
|
48
|
-
appPath: './src/riotprompt.ts',
|
|
49
|
-
exportName: 'viteNodeApp',
|
|
50
|
-
tsCompiler: 'swc',
|
|
51
|
-
swcOptions: {
|
|
52
|
-
sourceMaps: true,
|
|
53
|
-
},
|
|
54
|
-
}),
|
|
55
|
-
// visualizer({
|
|
56
|
-
// template: 'network',
|
|
57
|
-
// filename: 'network.html',
|
|
58
|
-
// projectRoot: process.cwd(),
|
|
59
|
-
// }),
|
|
60
|
-
replace({
|
|
61
|
-
'__VERSION__': process.env.npm_package_version,
|
|
62
|
-
'__GIT_BRANCH__': gitInfo.branch,
|
|
63
|
-
'__GIT_COMMIT__': gitInfo.commit,
|
|
64
|
-
'__GIT_TAGS__': gitInfo.tags === '' ? '' : `T:${gitInfo.tags}`,
|
|
65
|
-
'__GIT_COMMIT_DATE__': gitInfo.commitDate,
|
|
66
|
-
'__SYSTEM_INFO__': `${process.platform} ${process.arch} ${process.version}`,
|
|
67
|
-
preventAssignment: true,
|
|
68
|
-
}),
|
|
69
|
-
dts({
|
|
70
|
-
entryRoot: 'src',
|
|
71
|
-
outDir: 'dist',
|
|
72
|
-
exclude: ['**/*.test.ts'],
|
|
73
|
-
include: ['**/*.ts'],
|
|
74
|
-
}),
|
|
75
|
-
],
|
|
76
|
-
build: {
|
|
77
|
-
target: 'esnext',
|
|
78
|
-
outDir: 'dist',
|
|
79
|
-
lib: {
|
|
80
|
-
entry: './src/riotprompt.ts',
|
|
81
|
-
formats: ['es', 'cjs'],
|
|
82
|
-
fileName: (format) => `riotprompt.${format === 'es' ? 'js' : 'cjs'}`,
|
|
83
|
-
},
|
|
84
|
-
rollupOptions: {
|
|
85
|
-
external: [
|
|
86
|
-
'@riotprompt',
|
|
87
|
-
'@riotprompt/formatter',
|
|
88
|
-
'@riotprompt/chat'
|
|
89
|
-
],
|
|
90
|
-
output: [
|
|
91
|
-
{
|
|
92
|
-
format: 'esm',
|
|
93
|
-
entryFileNames: '[name].js',
|
|
94
|
-
preserveModules: true,
|
|
95
|
-
exports: 'named',
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
format: 'cjs',
|
|
99
|
-
entryFileNames: '[name].cjs',
|
|
100
|
-
preserveModules: true,
|
|
101
|
-
exports: 'named',
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
plugins: [
|
|
105
|
-
shebang({
|
|
106
|
-
shebang: '#!/usr/bin/env node',
|
|
107
|
-
}),
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
modulePreload: false,
|
|
111
|
-
minify: false,
|
|
112
|
-
sourcemap: true
|
|
113
|
-
},
|
|
114
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
test: {
|
|
6
|
-
environment: 'node',
|
|
7
|
-
setupFiles: ['./tests/setup.ts'],
|
|
8
|
-
coverage: {
|
|
9
|
-
provider: 'v8', // or 'istanbul'
|
|
10
|
-
reporter: ['text', 'json', 'html'],
|
|
11
|
-
thresholds: {
|
|
12
|
-
lines: 80,
|
|
13
|
-
functions: 80,
|
|
14
|
-
branches: 80,
|
|
15
|
-
statements: 80
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
resolve: {
|
|
20
|
-
alias: {
|
|
21
|
-
'@': path.resolve(__dirname, './src')
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|