@agentrules/core 0.1.0 → 0.2.1

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.
Files changed (4) hide show
  1. package/README.md +80 -54
  2. package/dist/index.d.ts +613 -786
  3. package/dist/index.js +318 -314
  4. 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 presets, use the [CLI](../cli) instead.
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 presets, bundles, configs |
18
- | **Registry Builder** | Build registry artifacts from preset inputs |
19
- | **Registry Client** | Fetch and resolve presets from registries |
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 Preset Config
27
+ ### Validating Rule Config
28
28
 
29
29
  ```ts
30
- import { presetConfigSchema, validatePresetConfig } from "@agentrules/core";
30
+ import {
31
+ normalizePlatformEntry,
32
+ ruleConfigSchema,
33
+ validateRule,
34
+ } from "@agentrules/core";
31
35
 
32
- // Using Zod schema directly
33
- const result = presetConfigSchema.safeParse(jsonData);
34
- if (!result.success) {
35
- console.error(result.error.issues);
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 { buildPresetRegistry } from "@agentrules/core";
46
-
47
- const result = await buildPresetRegistry({
48
- presets: [
49
- {
50
- slug: "my-preset",
51
- config: {
52
- name: "my-preset",
53
- title: "My Preset",
54
- version: 1,
55
- description: "A helpful preset",
56
- tags: ["starter"],
57
- license: "MIT",
58
- platforms: ["opencode", "claude"], // or use `platform: "opencode"` for single platform
59
- path: "files",
60
- },
61
- files: [
62
- { path: "AGENT_RULES.md", contents: "# Rules\n" },
63
- ],
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" }],
64
75
  },
65
- ],
66
- });
76
+ platformFiles: [
77
+ {
78
+ platform: "opencode",
79
+ files: [{ path: "AGENTS.md", content: "# Rules\n" }],
80
+ },
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.entries Preset[] for registry listing
69
- // result.index PresetIndex for lookups
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 { resolvePreset, fetchBundle } from "@agentrules/core";
98
+ import { fetchBundle, resolveSlug } from "@agentrules/core";
77
99
 
78
- // Resolve a preset (gets metadata and bundle URL)
79
- const { preset, bundleUrl } = await resolvePreset(
100
+ // Resolve metadata + variant bundle URLs
101
+ const resolved = await resolveSlug(
80
102
  "https://agentrules.directory/",
81
- "my-preset",
82
- "opencode"
103
+ "my-rule" // or "username/my-rule" for namespaced registries
83
104
  );
84
105
 
85
- // Fetch the bundle
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.projectDir); // ".opencode"
123
- console.log(opencode.globalDir); // "~/.config/opencode"
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
- // Preset configuration (agentrules.json)
133
- PresetConfig,
158
+ // Rule configuration (agentrules.json)
159
+ RuleConfig,
134
160
 
135
161
  // What clients send to publish
136
- PresetPublishInput,
162
+ RulePublishInput,
137
163
 
138
164
  // What registries store and return
139
- PresetBundle,
140
- Preset,
141
- PresetIndex,
165
+ RuleBundle,
166
+ Rule,
167
+ RuleIndex,
142
168
 
143
169
  // Bundle file structure
144
170
  BundledFile,
@@ -155,9 +181,9 @@ Zod schemas for validation:
155
181
 
156
182
  ```ts
157
183
  import {
158
- presetConfigSchema,
159
- presetBundleSchema,
160
- presetPublishInputSchema,
184
+ ruleConfigSchema,
185
+ ruleBundleSchema,
186
+ rulePublishInputSchema,
161
187
  platformIdSchema,
162
188
  nameSchema,
163
189
  titleSchema,