@agentrules/core 0.0.11 → 0.2.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/README.md +80 -54
- package/dist/index.d.ts +666 -397
- package/dist/index.js +577 -375
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Shared types and utilities for the AGENT_RULES ecosystem.
|
|
4
4
|
|
|
5
|
-
**This package is for developers building custom registries or alternative clients.** If you just want to install or publish
|
|
5
|
+
**This package is for developers building custom registries or alternative clients.** If you just want to install or publish rules, use the [CLI](../cli) instead.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -14,9 +14,9 @@ npm install @agentrules/core
|
|
|
14
14
|
|
|
15
15
|
| Module | Description |
|
|
16
16
|
|--------|-------------|
|
|
17
|
-
| **Types & Schemas** | TypeScript types and Zod schemas for
|
|
18
|
-
| **Registry Builder** | Build registry artifacts from
|
|
19
|
-
| **Registry Client** | Fetch and resolve
|
|
17
|
+
| **Types & Schemas** | TypeScript types and Zod schemas for rules, bundles, configs |
|
|
18
|
+
| **Registry Builder** | Build registry artifacts from rule inputs |
|
|
19
|
+
| **Registry Client** | Fetch and resolve rules from registries |
|
|
20
20
|
| **Bundle Utilities** | Encode/decode bundles, verify checksums |
|
|
21
21
|
| **Platform Config** | Platform IDs and directory paths |
|
|
22
22
|
|
|
@@ -24,65 +24,91 @@ This package contains **pure functions with no environment assumptions**. It doe
|
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
|
-
### Validating
|
|
27
|
+
### Validating Rule Config
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
normalizePlatformEntry,
|
|
32
|
+
ruleConfigSchema,
|
|
33
|
+
validateRule,
|
|
34
|
+
} from "@agentrules/core";
|
|
31
35
|
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
console.error(
|
|
36
|
+
// Parse/validate user-provided JSON (agentrules.json)
|
|
37
|
+
const parsed = ruleConfigSchema.safeParse(jsonData);
|
|
38
|
+
if (!parsed.success) {
|
|
39
|
+
console.error(parsed.error.issues);
|
|
40
|
+
} else {
|
|
41
|
+
// Normalize platform entries (string shorthand → object form)
|
|
42
|
+
const config = {
|
|
43
|
+
...parsed.data,
|
|
44
|
+
platforms: parsed.data.platforms.map(normalizePlatformEntry),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Additional cross-field checks (platform/type compatibility, placeholders, etc.)
|
|
48
|
+
const result = validateRule(config);
|
|
49
|
+
if (!result.valid) {
|
|
50
|
+
console.error(result.errors);
|
|
51
|
+
}
|
|
36
52
|
}
|
|
37
|
-
|
|
38
|
-
// Or use the helper (throws on error)
|
|
39
|
-
const config = validatePresetConfig(jsonData, "my-preset");
|
|
40
53
|
```
|
|
41
54
|
|
|
55
|
+
Note: `description` and `tags` are optional in `agentrules.json` (they default to `""` and `[]`).
|
|
56
|
+
|
|
42
57
|
### Building Registry Artifacts
|
|
43
58
|
|
|
44
59
|
```ts
|
|
45
|
-
import {
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
import { buildRegistry, type RuleInput } from "@agentrules/core";
|
|
61
|
+
|
|
62
|
+
const rules: RuleInput[] = [
|
|
63
|
+
{
|
|
64
|
+
name: "my-rule",
|
|
65
|
+
config: {
|
|
66
|
+
name: "my-rule",
|
|
67
|
+
title: "My Rule",
|
|
68
|
+
description: "A helpful rule",
|
|
69
|
+
license: "MIT",
|
|
70
|
+
// Optional metadata
|
|
71
|
+
tags: ["starter"],
|
|
72
|
+
features: ["Fast install"],
|
|
73
|
+
// Platforms (object form)
|
|
74
|
+
platforms: [{ platform: "opencode" }, { platform: "claude" }],
|
|
75
|
+
},
|
|
76
|
+
platformFiles: [
|
|
77
|
+
{
|
|
58
78
|
platform: "opencode",
|
|
59
|
-
path: "
|
|
79
|
+
files: [{ path: "AGENTS.md", content: "# Rules\n" }],
|
|
60
80
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
81
|
+
{
|
|
82
|
+
platform: "claude",
|
|
83
|
+
files: [{ path: "CLAUDE.md", content: "# Rules\n" }],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const result = await buildRegistry({ rules, bundleBase: "https://example.com" });
|
|
67
90
|
|
|
68
|
-
// result.
|
|
69
|
-
// result.
|
|
70
|
-
// result.bundles → PresetBundle[] with encoded files
|
|
91
|
+
// result.rules → ResolvedRule[] (metadata + bundle URLs)
|
|
92
|
+
// result.bundles → RuleBundle[] (per-platform bundles)
|
|
71
93
|
```
|
|
72
94
|
|
|
73
95
|
### Fetching from a Registry
|
|
74
96
|
|
|
75
97
|
```ts
|
|
76
|
-
import {
|
|
98
|
+
import { fetchBundle, resolveSlug } from "@agentrules/core";
|
|
77
99
|
|
|
78
|
-
// Resolve
|
|
79
|
-
const
|
|
100
|
+
// Resolve metadata + variant bundle URLs
|
|
101
|
+
const resolved = await resolveSlug(
|
|
80
102
|
"https://agentrules.directory/",
|
|
81
|
-
"my-
|
|
82
|
-
"opencode"
|
|
103
|
+
"my-rule" // or "username/my-rule" for namespaced registries
|
|
83
104
|
);
|
|
84
105
|
|
|
85
|
-
|
|
106
|
+
if (!resolved) throw new Error("Rule not found");
|
|
107
|
+
|
|
108
|
+
// Pick a variant bundle URL (example: first variant of latest version)
|
|
109
|
+
const bundleUrl = resolved.versions[0].variants[0].bundleUrl;
|
|
110
|
+
|
|
111
|
+
// Fetch the per-platform bundle
|
|
86
112
|
const bundle = await fetchBundle(bundleUrl);
|
|
87
113
|
```
|
|
88
114
|
|
|
@@ -119,8 +145,8 @@ console.log(PLATFORM_IDS); // ["opencode", "claude", "cursor", "codex"]
|
|
|
119
145
|
|
|
120
146
|
// Get paths for a platform
|
|
121
147
|
const opencode = PLATFORMS.opencode;
|
|
122
|
-
console.log(opencode.
|
|
123
|
-
console.log(opencode.globalDir);
|
|
148
|
+
console.log(opencode.platformDir); // ".opencode"
|
|
149
|
+
console.log(opencode.globalDir); // "~/.config/opencode"
|
|
124
150
|
```
|
|
125
151
|
|
|
126
152
|
## Types
|
|
@@ -129,16 +155,16 @@ Key types exported:
|
|
|
129
155
|
|
|
130
156
|
```ts
|
|
131
157
|
import type {
|
|
132
|
-
//
|
|
133
|
-
|
|
158
|
+
// Rule configuration (agentrules.json)
|
|
159
|
+
RuleConfig,
|
|
134
160
|
|
|
135
161
|
// What clients send to publish
|
|
136
|
-
|
|
162
|
+
RulePublishInput,
|
|
137
163
|
|
|
138
164
|
// What registries store and return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
165
|
+
RuleBundle,
|
|
166
|
+
Rule,
|
|
167
|
+
RuleIndex,
|
|
142
168
|
|
|
143
169
|
// Bundle file structure
|
|
144
170
|
BundledFile,
|
|
@@ -155,11 +181,11 @@ Zod schemas for validation:
|
|
|
155
181
|
|
|
156
182
|
```ts
|
|
157
183
|
import {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
184
|
+
ruleConfigSchema,
|
|
185
|
+
ruleBundleSchema,
|
|
186
|
+
rulePublishInputSchema,
|
|
161
187
|
platformIdSchema,
|
|
162
|
-
|
|
188
|
+
nameSchema,
|
|
163
189
|
titleSchema,
|
|
164
190
|
descriptionSchema,
|
|
165
191
|
} from "@agentrules/core";
|