ruleloom 0.0.0-stage → 0.1.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +151 -2
  4. package/dist/adapters/claude.d.ts +3 -0
  5. package/dist/adapters/claude.d.ts.map +1 -0
  6. package/dist/adapters/claude.js +59 -0
  7. package/dist/adapters/claude.js.map +1 -0
  8. package/dist/adapters/codex.d.ts +3 -0
  9. package/dist/adapters/codex.d.ts.map +1 -0
  10. package/dist/adapters/codex.js +84 -0
  11. package/dist/adapters/codex.js.map +1 -0
  12. package/dist/adapters/copilot.d.ts +3 -0
  13. package/dist/adapters/copilot.d.ts.map +1 -0
  14. package/dist/adapters/copilot.js +53 -0
  15. package/dist/adapters/copilot.js.map +1 -0
  16. package/dist/adapters/format.d.ts +27 -0
  17. package/dist/adapters/format.d.ts.map +1 -0
  18. package/dist/adapters/format.js +55 -0
  19. package/dist/adapters/format.js.map +1 -0
  20. package/dist/adapters/index.d.ts +10 -0
  21. package/dist/adapters/index.d.ts.map +1 -0
  22. package/dist/adapters/index.js +11 -0
  23. package/dist/adapters/index.js.map +1 -0
  24. package/dist/adapters/types.d.ts +19 -0
  25. package/dist/adapters/types.d.ts.map +1 -0
  26. package/dist/adapters/types.js +2 -0
  27. package/dist/adapters/types.js.map +1 -0
  28. package/dist/assemble.d.ts +61 -0
  29. package/dist/assemble.d.ts.map +1 -0
  30. package/dist/assemble.js +133 -0
  31. package/dist/assemble.js.map +1 -0
  32. package/dist/blocks.d.ts +32 -0
  33. package/dist/blocks.d.ts.map +1 -0
  34. package/dist/blocks.js +59 -0
  35. package/dist/blocks.js.map +1 -0
  36. package/dist/bundle.d.ts +121 -0
  37. package/dist/bundle.d.ts.map +1 -0
  38. package/dist/bundle.js +157 -0
  39. package/dist/bundle.js.map +1 -0
  40. package/dist/cli.d.ts +3 -0
  41. package/dist/cli.d.ts.map +1 -0
  42. package/dist/cli.js +141 -0
  43. package/dist/cli.js.map +1 -0
  44. package/dist/config.d.ts +360 -0
  45. package/dist/config.d.ts.map +1 -0
  46. package/dist/config.js +207 -0
  47. package/dist/config.js.map +1 -0
  48. package/dist/errors.d.ts +12 -0
  49. package/dist/errors.d.ts.map +1 -0
  50. package/dist/errors.js +16 -0
  51. package/dist/errors.js.map +1 -0
  52. package/dist/index.d.ts +12 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +12 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/project.d.ts +149 -0
  57. package/dist/project.d.ts.map +1 -0
  58. package/dist/project.js +102 -0
  59. package/dist/project.js.map +1 -0
  60. package/dist/prompt.d.ts +62 -0
  61. package/dist/prompt.d.ts.map +1 -0
  62. package/dist/prompt.js +91 -0
  63. package/dist/prompt.js.map +1 -0
  64. package/dist/resources.d.ts +39 -0
  65. package/dist/resources.d.ts.map +1 -0
  66. package/dist/resources.js +118 -0
  67. package/dist/resources.js.map +1 -0
  68. package/dist/select.d.ts +14 -0
  69. package/dist/select.d.ts.map +1 -0
  70. package/dist/select.js +25 -0
  71. package/dist/select.js.map +1 -0
  72. package/dist/slots.d.ts +35 -0
  73. package/dist/slots.d.ts.map +1 -0
  74. package/dist/slots.js +86 -0
  75. package/dist/slots.js.map +1 -0
  76. package/docs/agent-definition.md +86 -0
  77. package/docs/api.md +65 -0
  78. package/docs/architecture.md +47 -0
  79. package/docs/cli.md +28 -0
  80. package/docs/errors.md +76 -0
  81. package/docs/targets.md +49 -0
  82. package/package.json +51 -4
package/dist/config.js ADDED
@@ -0,0 +1,207 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { z } from 'zod';
4
+ import { RuleLoomError } from './errors.js';
5
+ /**
6
+ * What an agent declares about itself: `<agentsRoot>/<name>/agent.json`.
7
+ *
8
+ * It is the only place that says which files an agent is made of and in what
9
+ * order they stack. The compiler reads it rather than globbing a directory, so
10
+ * adding a file to `source/rules/` is a deliberate act and never something
11
+ * that silently changes a published prompt.
12
+ */
13
+ /** A mode name: lower case, like `web-template`. */
14
+ const MODE_NAME = /^[a-z][a-z0-9-]*$/;
15
+ /** An agent slot name: upper case, like the `${{NAME}}` it fills. */
16
+ const SLOT_NAME = /^[A-Z][A-Z0-9_]*$/;
17
+ /**
18
+ * A drawn value: a bare name, never a sentence. No `{` or `}`, so a value
19
+ * written into the agent's text can never smuggle a slot into it.
20
+ */
21
+ const RANDOM_VALUE = /^[\p{L}\p{N}](?:[\p{L}\p{N}_.-]{0,30}[\p{L}\p{N}])?$/u;
22
+ /** A `data` value: free text, one line or several, never a slot. */
23
+ const DATA_VALUE = /^[^{}]{1,2000}$/s;
24
+ /** An MCP server name, as every target writes it as a key. */
25
+ const SERVER_NAME = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
26
+ /** An environment variable name. Values never live in a definition. */
27
+ const ENV_NAME = /^[A-Z_][A-Z0-9_]*$/;
28
+ /** One rule, skill or mission file, with the codes it speaks to. */
29
+ export const AgentModuleSchema = z.object({
30
+ /**
31
+ * Path relative to the agent directory (`source/rules/10_COMMON.md`), or
32
+ * relative to the shared directory when it starts with `shared/`, or to a
33
+ * declared resource when it starts with `@<resource>/`.
34
+ */
35
+ path: z.string().min(1),
36
+ /**
37
+ * Verification codes this file helps fix. A retry recompiles with only the
38
+ * modules whose tags match what failed: a contrast failure has no business
39
+ * reloading the layout rules, and paying for them again on every attempt is
40
+ * the largest avoidable cost of a generate-verify loop.
41
+ */
42
+ tags: z.array(z.string().min(1)).default([]),
43
+ /** Kept on every retry, whatever failed: the output contract, above all. */
44
+ always: z.boolean().default(false),
45
+ /**
46
+ * In a compiled prompt, placed after the run-supplied blocks rather than
47
+ * before them, so the output contract is the last thing the model reads.
48
+ * Ignored by bundles, which have no run blocks.
49
+ */
50
+ trailing: z.boolean().default(false),
51
+ /**
52
+ * What the file becomes. Inferred from the path when absent: anything
53
+ * under a `skills/` directory is a skill, everything else a rule. `mission`
54
+ * is the agent's own prompt — its role and deliverables — and an agent
55
+ * declares at most one.
56
+ */
57
+ kind: z.enum(['rule', 'skill', 'mission']).optional(),
58
+ /**
59
+ * The modes this module belongs to, from the agent's `modes`. Empty means
60
+ * every mode. A module bound to modes is compiled only for one of them: a
61
+ * procedure for one kind of input says nothing to a run that has another.
62
+ */
63
+ modes: z.array(z.string().regex(MODE_NAME, 'MODE_INVALID')).default([]),
64
+ });
65
+ /** What a module becomes when `kind` is left out. */
66
+ export function moduleKind(module) {
67
+ if (module.kind)
68
+ return module.kind;
69
+ return module.path.includes('/skills/') ? 'skill' : 'rule';
70
+ }
71
+ /**
72
+ * One MCP server the agent may use.
73
+ *
74
+ * `env` lists variable *names*. Their values are injected at runtime by
75
+ * whoever launches the agent; a definition that carried a secret would put
76
+ * it in every generated file and every commit of them.
77
+ */
78
+ export const McpServerSchema = z
79
+ .object({
80
+ /** stdio transport: the command to launch. */
81
+ command: z.string().min(1).optional(),
82
+ args: z.array(z.string()).default([]),
83
+ /** Remote transport: the server URL. */
84
+ url: z.string().url().optional(),
85
+ env: z.array(z.string().regex(ENV_NAME, 'MCP_ENV_NAME_INVALID')).default([]),
86
+ })
87
+ .strict()
88
+ .superRefine((server, ctx) => {
89
+ if (Boolean(server.command) === Boolean(server.url)) {
90
+ ctx.addIssue({
91
+ code: 'custom',
92
+ message: 'MCP_TRANSPORT_INVALID: exactly one of `command` (stdio) or `url` (http) is required',
93
+ });
94
+ }
95
+ });
96
+ /**
97
+ * Settings that only one target understands, passed through as written.
98
+ *
99
+ * The mapping layer between platforms: a tool name or a model id means
100
+ * something on one platform only, so it is stated per target rather than
101
+ * translated by a table that would be wrong the week a platform renames a
102
+ * tool. Values are strings or string lists, written into the target's
103
+ * frontmatter under the same key.
104
+ */
105
+ const TargetOverridesSchema = z.record(z.string().regex(/^[a-z][a-zA-Z0-9_-]*$/, 'TARGET_KEY_INVALID'), z.union([z.string().regex(/^[^\n]*$/, 'TARGET_VALUE_MULTILINE'), z.array(z.string())]));
106
+ export const AgentConfigSchema = z
107
+ .object({
108
+ name: z.string().min(1),
109
+ version: z.string().min(1),
110
+ /** One line: what the agent turns into what. Becomes its description. */
111
+ summary: z.string().min(1).regex(/^[^\n]*$/, 'SUMMARY_MULTILINE'),
112
+ /** Artefact names this agent reads and writes, for the orchestrator. */
113
+ inputs: z.array(z.string().min(1)).default([]),
114
+ outputs: z.array(z.string().min(1)).default([]),
115
+ /**
116
+ * Choices the agent's text leaves open, cited as `${{NAME}}`. A rule
117
+ * that offers a menu is answered the same way every time; a slot drawn
118
+ * by the run gets a different answer. The compiler takes the first value
119
+ * when nobody draws, so a compilation stays deterministic.
120
+ */
121
+ random: z
122
+ .record(z.string().regex(SLOT_NAME, 'RANDOM_NAME_INVALID'), z.array(z.string().regex(RANDOM_VALUE, 'RANDOM_VALUE_INVALID')).min(2))
123
+ .default({}),
124
+ /** Constants the agent's text cites as `${{NAME}}`, one value each. */
125
+ data: z
126
+ .record(z.string().regex(SLOT_NAME, 'DATA_NAME_INVALID'), z.string().regex(DATA_VALUE, 'DATA_VALUE_INVALID'))
127
+ .default({}),
128
+ /** Lines that open every compiled prompt and every agent file. */
129
+ preamble: z.array(z.string()).default([]),
130
+ /**
131
+ * Shared rules this agent inherits, by file name in `<shared>/rules/`.
132
+ * Declared, never globbed: a shared rule reaches an agent because that
133
+ * agent asked for it.
134
+ */
135
+ sharedRules: z.array(z.string().min(1)).default([]),
136
+ runtime: z
137
+ .object({
138
+ /**
139
+ * Skills preloaded into the agent's context rather than fetched on
140
+ * demand, by skill slug. Only targets with a preload mechanism use
141
+ * it; the others expose every skill for discovery.
142
+ */
143
+ skills: z.array(z.string().min(1)).default([]),
144
+ })
145
+ .default({ skills: [] }),
146
+ /** The modes the agent may be compiled for, the first being the default. */
147
+ modes: z.array(z.string().regex(MODE_NAME, 'MODE_INVALID')).default([]),
148
+ /** MCP servers the agent may use, by name. */
149
+ mcp: z.record(z.string().regex(SERVER_NAME, 'MCP_NAME_INVALID'), McpServerSchema).default({}),
150
+ /** Per-target settings: `{ "claude": { "tools": "Read, Grep" } }`. */
151
+ targets: z
152
+ .object({
153
+ claude: TargetOverridesSchema.optional(),
154
+ codex: TargetOverridesSchema.optional(),
155
+ copilot: TargetOverridesSchema.optional(),
156
+ })
157
+ .strict()
158
+ .default({}),
159
+ modules: z.array(AgentModuleSchema).min(1),
160
+ })
161
+ .superRefine((config, ctx) => {
162
+ const declared = new Set(config.modes);
163
+ if (declared.size !== config.modes.length) {
164
+ ctx.addIssue({ code: 'custom', path: ['modes'], message: `AGENT_MODE_DUPLICATED: ${config.modes.join(', ')}` });
165
+ }
166
+ for (const [index, module] of config.modules.entries()) {
167
+ const unknown = module.modes.filter((mode) => !declared.has(mode));
168
+ if (unknown.length > 0) {
169
+ ctx.addIssue({
170
+ code: 'custom',
171
+ path: ['modules', index, 'modes'],
172
+ message: `AGENT_MODE_UNKNOWN: ${module.path} cites ${unknown.join(', ')} — `
173
+ + `the agent declares ${config.modes.join(', ') || '(no mode)'}`,
174
+ });
175
+ }
176
+ }
177
+ // One name, one source: a slot in both blocks would have two values.
178
+ for (const name of Object.keys(config.data)) {
179
+ if (Object.hasOwn(config.random, name)) {
180
+ ctx.addIssue({
181
+ code: 'custom',
182
+ path: ['data', name],
183
+ message: `AGENT_SLOT_DUPLICATED: ${name} is declared in both random and data`,
184
+ });
185
+ }
186
+ }
187
+ });
188
+ /** Reads and validates `<agentDir>/agent.json`. */
189
+ export function readAgentConfig(agentDir) {
190
+ const path = join(agentDir, 'agent.json');
191
+ let raw;
192
+ try {
193
+ raw = JSON.parse(readFileSync(path, 'utf8'));
194
+ }
195
+ catch (error) {
196
+ throw new RuleLoomError('AGENT_CONFIG_UNREADABLE', `${path} — ${error.message}`);
197
+ }
198
+ const parsed = AgentConfigSchema.safeParse(raw);
199
+ if (!parsed.success) {
200
+ const issues = parsed.error.issues
201
+ .map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`)
202
+ .join(' | ');
203
+ throw new RuleLoomError('AGENT_CONFIG_INVALID', `${path} — ${issues}`);
204
+ }
205
+ return parsed.data;
206
+ }
207
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;GAOG;AAEH,oDAAoD;AACpD,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC,qEAAqE;AACrE,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC;;;GAGG;AACH,MAAM,YAAY,GAAG,uDAAuD,CAAC;AAE7E,oEAAoE;AACpE,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC,8DAA8D;AAC9D,MAAM,WAAW,GAAG,kCAAkC,CAAC;AAEvD,uEAAuE;AACvE,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AAEtC,oEAAoE;AACpE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC;;;;OAIG;IACH,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB;;;;;OAKG;IACH,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC5C,4EAA4E;IAC5E,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAClC;;;;OAIG;IACH,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACpC;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AI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;aACvE,IAAI,CAAC,KAAK,CAAC,CAAC;QACf,MAAM,IAAI,aAAa,CAAC,sBAAsB,EAAE,GAAG,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Every failure RuleLoom reports carries a stable code first, then a sentence
3
+ * naming the culprit: `AGENT_SLOT_UNKNOWN: rules/10.md cites ${{THEM}} …`.
4
+ *
5
+ * Callers match on the code — `error.code`, or the message prefix for those
6
+ * who only see text — never on the sentence, which may be reworded.
7
+ */
8
+ export declare class RuleLoomError extends Error {
9
+ readonly code: string;
10
+ constructor(code: string, detail: string);
11
+ }
12
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAKzC"}
package/dist/errors.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Every failure RuleLoom reports carries a stable code first, then a sentence
3
+ * naming the culprit: `AGENT_SLOT_UNKNOWN: rules/10.md cites ${{THEM}} …`.
4
+ *
5
+ * Callers match on the code — `error.code`, or the message prefix for those
6
+ * who only see text — never on the sentence, which may be reworded.
7
+ */
8
+ export class RuleLoomError extends Error {
9
+ code;
10
+ constructor(code, detail) {
11
+ super(`${code}: ${detail}`);
12
+ this.name = 'RuleLoomError';
13
+ this.code = code;
14
+ }
15
+ }
16
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,MAAc;QACtC,KAAK,CAAC,GAAG,IAAI,KAAK,MAAM,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ export { RuleLoomError } from './errors.js';
2
+ export { AgentConfigSchema, AgentModuleSchema, McpServerSchema, moduleKind, readAgentConfig, type AgentConfig, type AgentModule, type McpServer, } from './config.js';
3
+ export { PROJECT_FILE, ProjectFileSchema, ResourceSchema, TARGETS, TargetSchema, defineProject, loadProject, type Project, type ProjectFile, type Resource, type Target, } from './project.js';
4
+ export { ModuleReader, resolveResource, type ResolvedResource } from './resources.js';
5
+ export { bindSlots, resolveAgentSlots, resolveDataOverride, usedSlots, type BindOptions } from './slots.js';
6
+ export { loadBlockTemplates, renderBlock, type BlockTemplate, type LoadBlocksOptions } from './blocks.js';
7
+ export { modulesForMode, resolveMode, selectModules, type SelectOptions } from './select.js';
8
+ export { compilePrompt, type CompilePromptOptions, type CompiledModule, type CompiledPrompt, } from './prompt.js';
9
+ export { assembleAgent, moduleSlug, moduleTitle, type AssembleOptions, type AssembledAgent, type AssembledFile, type AssembledSkill, } from './assemble.js';
10
+ export { BUILD_MANIFEST, compileAllBundles, compileBundle, discoverAgents, inheritedConfig, materialiseAgent, writeBundles, type AgentBundle, type BuildManifest, type BuildManifestFile, type BundleScope, type CompileBundleOptions, type MaterialiseOptions, type MaterialisedAgent, type WriteBundlesOptions, type WriteReport, } from './bundle.js';
11
+ export { ADAPTERS, claudeAdapter, codexAdapter, copilotAdapter, frontmatter, mcpJson, yamlScalar, type Adapter, type AdapterOutput, } from './adapters/index.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @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,EACtB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACX,OAAO,EACP,UAAU,EACV,KAAK,OAAO,EACZ,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export { RuleLoomError } from './errors.js';
2
+ export { AgentConfigSchema, AgentModuleSchema, McpServerSchema, moduleKind, readAgentConfig, } from './config.js';
3
+ export { PROJECT_FILE, ProjectFileSchema, ResourceSchema, TARGETS, TargetSchema, defineProject, loadProject, } from './project.js';
4
+ export { ModuleReader, resolveResource } from './resources.js';
5
+ export { bindSlots, resolveAgentSlots, resolveDataOverride, usedSlots } from './slots.js';
6
+ export { loadBlockTemplates, renderBlock } from './blocks.js';
7
+ export { modulesForMode, resolveMode, selectModules } from './select.js';
8
+ export { compilePrompt, } from './prompt.js';
9
+ export { assembleAgent, moduleSlug, moduleTitle, } from './assemble.js';
10
+ export { BUILD_MANIFEST, compileAllBundles, compileBundle, discoverAgents, inheritedConfig, materialiseAgent, writeBundles, } from './bundle.js';
11
+ export { ADAPTERS, claudeAdapter, codexAdapter, copilotAdapter, frontmatter, mcpJson, yamlScalar, } from './adapters/index.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,aAAa,EACb,WAAW,GAKZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAyB,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,SAAS,EAAoB,MAAM,YAAY,CAAC;AAC5G,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAC;AAC1G,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAsB,MAAM,aAAa,CAAC;AAC7F,OAAO,EACL,aAAa,GAId,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,GAKZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,YAAY,GAUb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACX,OAAO,EACP,UAAU,GAGX,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,149 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The project around the agents: where they live, what they share, and the
4
+ * few conventions a generated file needs — `ruleloom.json`, all optional.
5
+ *
6
+ * agents/ agentsDir
7
+ * shared/ sharedDir: rules every agent may inherit,
8
+ * rules/ run blocks, the constraints paragraph
9
+ * blocks/
10
+ * reviewer/agent.json one agent per directory
11
+ * writer/agent.json
12
+ */
13
+ export declare const TARGETS: readonly ["claude", "codex", "copilot"];
14
+ export declare const TargetSchema: z.ZodEnum<["claude", "codex", "copilot"]>;
15
+ export type Target = z.infer<typeof TargetSchema>;
16
+ /** A shared referential: a local directory, or a Git repository pinned to a ref. */
17
+ export declare const ResourceSchema: z.ZodUnion<[z.ZodObject<{
18
+ path: z.ZodString;
19
+ }, "strict", z.ZodTypeAny, {
20
+ path: string;
21
+ }, {
22
+ path: string;
23
+ }>, z.ZodObject<{
24
+ git: z.ZodString;
25
+ /** A tag or a commit. A branch moves, and a moving source is not reproducible. */
26
+ ref: z.ZodString;
27
+ /** Expected commit: compilation refuses a ref that resolves elsewhere. */
28
+ commit: z.ZodOptional<z.ZodString>;
29
+ /** Sub-directory of the repository that holds the resources. */
30
+ path: z.ZodDefault<z.ZodString>;
31
+ }, "strict", z.ZodTypeAny, {
32
+ path: string;
33
+ git: string;
34
+ ref: string;
35
+ commit?: string | undefined;
36
+ }, {
37
+ git: string;
38
+ ref: string;
39
+ path?: string | undefined;
40
+ commit?: string | undefined;
41
+ }>]>;
42
+ export type Resource = z.infer<typeof ResourceSchema>;
43
+ export declare const ProjectFileSchema: z.ZodObject<{
44
+ /** Directory holding one sub-directory per agent. Relative to the project file. */
45
+ agentsDir: z.ZodDefault<z.ZodString>;
46
+ /** Shared rules, blocks and constraints. Relative to `agentsDir`. */
47
+ sharedDir: z.ZodDefault<z.ZodString>;
48
+ /** Sub-directories of `agentsDir` that are never agents. */
49
+ exclude: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
50
+ /** Prefix of every generated agent name: `acme-` turns `reviewer` into `acme-reviewer`. */
51
+ namePrefix: z.ZodDefault<z.ZodString>;
52
+ /**
53
+ * A paragraph every agent file ends on, relative to `sharedDir`. Said out
54
+ * loud because rule loading is invisible: a model that cannot see where
55
+ * its rules came from must not conclude they are optional.
56
+ */
57
+ constraints: z.ZodOptional<z.ZodString>;
58
+ /** Run-supplied prompt blocks: `<number>_<NAME>.md` templates, relative to `sharedDir`. */
59
+ blocksDir: z.ZodDefault<z.ZodString>;
60
+ /** Block files start at this number; hand-written modules stay below it. */
61
+ blockNumberFloor: z.ZodDefault<z.ZodNumber>;
62
+ /** Targets compiled when none is named. */
63
+ targets: z.ZodDefault<z.ZodArray<z.ZodEnum<["claude", "codex", "copilot"]>, "many">>;
64
+ /** Shared referentials, cited in module paths as `@<alias>/…`. */
65
+ resources: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
66
+ path: z.ZodString;
67
+ }, "strict", z.ZodTypeAny, {
68
+ path: string;
69
+ }, {
70
+ path: string;
71
+ }>, z.ZodObject<{
72
+ git: z.ZodString;
73
+ /** A tag or a commit. A branch moves, and a moving source is not reproducible. */
74
+ ref: z.ZodString;
75
+ /** Expected commit: compilation refuses a ref that resolves elsewhere. */
76
+ commit: z.ZodOptional<z.ZodString>;
77
+ /** Sub-directory of the repository that holds the resources. */
78
+ path: z.ZodDefault<z.ZodString>;
79
+ }, "strict", z.ZodTypeAny, {
80
+ path: string;
81
+ git: string;
82
+ ref: string;
83
+ commit?: string | undefined;
84
+ }, {
85
+ git: string;
86
+ ref: string;
87
+ path?: string | undefined;
88
+ commit?: string | undefined;
89
+ }>]>>>;
90
+ /** Where Git resources are fetched. Relative to the project file. */
91
+ cacheDir: z.ZodDefault<z.ZodString>;
92
+ }, "strict", z.ZodTypeAny, {
93
+ targets: ("claude" | "codex" | "copilot")[];
94
+ agentsDir: string;
95
+ sharedDir: string;
96
+ exclude: string[];
97
+ namePrefix: string;
98
+ blocksDir: string;
99
+ blockNumberFloor: number;
100
+ resources: Record<string, {
101
+ path: string;
102
+ } | {
103
+ path: string;
104
+ git: string;
105
+ ref: string;
106
+ commit?: string | undefined;
107
+ }>;
108
+ cacheDir: string;
109
+ constraints?: string | undefined;
110
+ }, {
111
+ targets?: ("claude" | "codex" | "copilot")[] | undefined;
112
+ agentsDir?: string | undefined;
113
+ sharedDir?: string | undefined;
114
+ exclude?: string[] | undefined;
115
+ namePrefix?: string | undefined;
116
+ constraints?: string | undefined;
117
+ blocksDir?: string | undefined;
118
+ blockNumberFloor?: number | undefined;
119
+ resources?: Record<string, {
120
+ path: string;
121
+ } | {
122
+ git: string;
123
+ ref: string;
124
+ path?: string | undefined;
125
+ commit?: string | undefined;
126
+ }> | undefined;
127
+ cacheDir?: string | undefined;
128
+ }>;
129
+ export type ProjectFile = z.infer<typeof ProjectFileSchema>;
130
+ /** A project with every path made absolute. */
131
+ export interface Project {
132
+ root: string;
133
+ agentsRoot: string;
134
+ sharedRoot: string;
135
+ blocksRoot: string;
136
+ exclude: string[];
137
+ namePrefix: string;
138
+ constraintsFile?: string;
139
+ blockNumberFloor: number;
140
+ targets: Target[];
141
+ resources: Record<string, Resource>;
142
+ cacheRoot: string;
143
+ }
144
+ export declare const PROJECT_FILE = "ruleloom.json";
145
+ /** A project from options, every path resolved against `root`. */
146
+ export declare function defineProject(root: string, options?: Partial<z.input<typeof ProjectFileSchema>>): Project;
147
+ /** `ruleloom.json` in `root`, or the defaults when there is none. */
148
+ export declare function loadProject(root: string): Project;
149
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,OAAO,yCAA0C,CAAC;AAC/D,eAAO,MAAM,YAAY,2CAAkB,CAAC;AAC5C,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,oFAAoF;AACpF,eAAO,MAAM,cAAc;;;;;;;;IAKrB,kFAAkF;;IAElF,0EAA0E;;IAE1E,gEAAgE;;;;;;;;;;;;IAIpE,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAItD,eAAO,MAAM,iBAAiB;IAE1B,mFAAmF;;IAEnF,qEAAqE;;IAErE,4DAA4D;;IAE5D,2FAA2F;;IAE3F;;;;OAIG;;IAEH,2FAA2F;;IAE3F,4EAA4E;;IAE5E,2CAA2C;;IAE3C,kEAAkE;;;;;;;;;QAnChE,kFAAkF;;QAElF,0EAA0E;;QAE1E,gEAAgE;;;;;;;;;;;;;IAiClE,qEAAqE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG9D,CAAC;AACZ,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,+CAA+C;AAC/C,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,YAAY,kBAAkB,CAAC;AAI5C,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAM,GAAG,OAAO,CAyB7G;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUjD"}
@@ -0,0 +1,102 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
3
+ import { z } from 'zod';
4
+ import { RuleLoomError } from './errors.js';
5
+ /**
6
+ * The project around the agents: where they live, what they share, and the
7
+ * few conventions a generated file needs — `ruleloom.json`, all optional.
8
+ *
9
+ * agents/ agentsDir
10
+ * shared/ sharedDir: rules every agent may inherit,
11
+ * rules/ run blocks, the constraints paragraph
12
+ * blocks/
13
+ * reviewer/agent.json one agent per directory
14
+ * writer/agent.json
15
+ */
16
+ export const TARGETS = ['claude', 'codex', 'copilot'];
17
+ export const TargetSchema = z.enum(TARGETS);
18
+ /** A shared referential: a local directory, or a Git repository pinned to a ref. */
19
+ export const ResourceSchema = z.union([
20
+ z.object({ path: z.string().min(1) }).strict(),
21
+ z
22
+ .object({
23
+ git: z.string().min(1),
24
+ /** A tag or a commit. A branch moves, and a moving source is not reproducible. */
25
+ ref: z.string().min(1),
26
+ /** Expected commit: compilation refuses a ref that resolves elsewhere. */
27
+ commit: z.string().regex(/^[0-9a-f]{7,40}$/).optional(),
28
+ /** Sub-directory of the repository that holds the resources. */
29
+ path: z.string().default('.'),
30
+ })
31
+ .strict(),
32
+ ]);
33
+ const RESOURCE_ALIAS = /^[a-z][a-z0-9-]*$/;
34
+ export const ProjectFileSchema = z
35
+ .object({
36
+ /** Directory holding one sub-directory per agent. Relative to the project file. */
37
+ agentsDir: z.string().default('.'),
38
+ /** Shared rules, blocks and constraints. Relative to `agentsDir`. */
39
+ sharedDir: z.string().default('shared'),
40
+ /** Sub-directories of `agentsDir` that are never agents. */
41
+ exclude: z.array(z.string()).default([]),
42
+ /** Prefix of every generated agent name: `acme-` turns `reviewer` into `acme-reviewer`. */
43
+ namePrefix: z.string().regex(/^[a-z0-9-]*$/, 'NAME_PREFIX_INVALID').default(''),
44
+ /**
45
+ * A paragraph every agent file ends on, relative to `sharedDir`. Said out
46
+ * loud because rule loading is invisible: a model that cannot see where
47
+ * its rules came from must not conclude they are optional.
48
+ */
49
+ constraints: z.string().optional(),
50
+ /** Run-supplied prompt blocks: `<number>_<NAME>.md` templates, relative to `sharedDir`. */
51
+ blocksDir: z.string().default('blocks'),
52
+ /** Block files start at this number; hand-written modules stay below it. */
53
+ blockNumberFloor: z.number().int().positive().default(100),
54
+ /** Targets compiled when none is named. */
55
+ targets: z.array(TargetSchema).min(1).default(['claude']),
56
+ /** Shared referentials, cited in module paths as `@<alias>/…`. */
57
+ resources: z.record(z.string().regex(RESOURCE_ALIAS, 'RESOURCE_ALIAS_INVALID'), ResourceSchema).default({}),
58
+ /** Where Git resources are fetched. Relative to the project file. */
59
+ cacheDir: z.string().default('.ruleloom/cache'),
60
+ })
61
+ .strict();
62
+ export const PROJECT_FILE = 'ruleloom.json';
63
+ const absolute = (base, path) => (isAbsolute(path) ? path : resolve(base, path));
64
+ /** A project from options, every path resolved against `root`. */
65
+ export function defineProject(root, options = {}) {
66
+ const parsed = ProjectFileSchema.safeParse(options);
67
+ if (!parsed.success) {
68
+ throw new RuleLoomError('PROJECT_CONFIG_INVALID', parsed.error.issues.map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`).join(' | '));
69
+ }
70
+ const file = parsed.data;
71
+ const base = resolve(root);
72
+ const agentsRoot = absolute(base, file.agentsDir);
73
+ const sharedRoot = absolute(agentsRoot, file.sharedDir);
74
+ return {
75
+ root: base,
76
+ agentsRoot,
77
+ sharedRoot,
78
+ blocksRoot: absolute(sharedRoot, file.blocksDir),
79
+ exclude: file.exclude,
80
+ namePrefix: file.namePrefix,
81
+ ...(file.constraints ? { constraintsFile: absolute(sharedRoot, file.constraints) } : {}),
82
+ blockNumberFloor: file.blockNumberFloor,
83
+ targets: file.targets,
84
+ resources: file.resources,
85
+ cacheRoot: absolute(base, file.cacheDir),
86
+ };
87
+ }
88
+ /** `ruleloom.json` in `root`, or the defaults when there is none. */
89
+ export function loadProject(root) {
90
+ const path = join(resolve(root), PROJECT_FILE);
91
+ if (!existsSync(path))
92
+ return defineProject(root);
93
+ let raw;
94
+ try {
95
+ raw = JSON.parse(readFileSync(path, 'utf8'));
96
+ }
97
+ catch (error) {
98
+ throw new RuleLoomError('PROJECT_CONFIG_UNREADABLE', `${path} — ${error.message}`);
99
+ }
100
+ return defineProject(dirname(path), raw);
101
+ }
102
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OA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,IAAI,CAAC,QAAQ,CAAC;KACzC,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,aAAa,CAAC,2BAA2B,EAAE,GAAG,IAAI,MAAO,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAiD,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,62 @@
1
+ import type { Project } from './project.js';
2
+ /**
3
+ * One agent compiled to one string, for a completion API that takes a single
4
+ * system prompt.
5
+ *
6
+ * `static` then `dynamic`, never interleaved. `static` is the preamble, the
7
+ * shared rules and the agent's modules: the same bytes for every run, so a
8
+ * provider's prompt cache can serve it. `dynamic` is what the run supplies —
9
+ * its blocks, in block order — followed by the `trailing` modules, so the
10
+ * output contract is the last thing read.
11
+ *
12
+ * Deterministic: same inputs, same bytes, same sha256. No timestamp, no
13
+ * globbing, module order from `agent.json`.
14
+ */
15
+ export interface CompilePromptOptions {
16
+ project: Project;
17
+ /** Agent directory name under the project's agents root. */
18
+ agent: string;
19
+ /** Values for the run blocks, by block name. */
20
+ values?: Record<string, string>;
21
+ /** Overrides for the agent's `data` slots; a pool. */
22
+ data?: Record<string, string>;
23
+ /** Drawn values for the agent's `random` slots; a pool. */
24
+ random?: Record<string, string>;
25
+ /** Retry: keep only the modules tagged with these codes, and the `always` ones. */
26
+ failedCodes?: readonly string[];
27
+ /** One of the agent's `modes`. */
28
+ mode?: string;
29
+ /** Block names the project requires; see `loadBlockTemplates`. */
30
+ expectedBlocks?: readonly string[];
31
+ }
32
+ export interface CompiledModule {
33
+ path: string;
34
+ sha256: string;
35
+ bytes: number;
36
+ }
37
+ export interface CompiledPrompt {
38
+ agent: string;
39
+ version: string;
40
+ /** Preamble, shared rules and leading modules. Byte-stable for one selection. */
41
+ static: string;
42
+ /** Run blocks, then trailing modules. Empty when neither. */
43
+ dynamic: string;
44
+ /** The run blocks alone. */
45
+ runBlocks: string;
46
+ /** The trailing modules alone. */
47
+ trailing: string;
48
+ /** What to send: `static`, then `dynamic`. */
49
+ text: string;
50
+ /** Hash of the static half: the cache key worth tracking. */
51
+ staticSha256: string;
52
+ modules: CompiledModule[];
53
+ /** Blocks cited by a module but left without a value. */
54
+ unresolvedBlocks: string[];
55
+ /** The agent slots the text cited, with their values. */
56
+ cited: Record<string, string>;
57
+ /** The value every declared slot took. */
58
+ slots: Record<string, string>;
59
+ selection: 'full' | 'retry';
60
+ }
61
+ export declare function compilePrompt(options: CompilePromptOptions): CompiledPrompt;
62
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,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