ruleloom 0.0.0-stage → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +17 -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 +73 -0
  45. package/dist/config.d.ts.map +1 -0
  46. package/dist/config.js +205 -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/issues.d.ts +6 -0
  57. package/dist/issues.d.ts.map +1 -0
  58. package/dist/issues.js +31 -0
  59. package/dist/issues.js.map +1 -0
  60. package/dist/project.d.ts +73 -0
  61. package/dist/project.d.ts.map +1 -0
  62. package/dist/project.js +103 -0
  63. package/dist/project.js.map +1 -0
  64. package/dist/prompt.d.ts +62 -0
  65. package/dist/prompt.d.ts.map +1 -0
  66. package/dist/prompt.js +91 -0
  67. package/dist/prompt.js.map +1 -0
  68. package/dist/resources.d.ts +39 -0
  69. package/dist/resources.d.ts.map +1 -0
  70. package/dist/resources.js +118 -0
  71. package/dist/resources.js.map +1 -0
  72. package/dist/select.d.ts +14 -0
  73. package/dist/select.d.ts.map +1 -0
  74. package/dist/select.js +25 -0
  75. package/dist/select.js.map +1 -0
  76. package/dist/slots.d.ts +35 -0
  77. package/dist/slots.d.ts.map +1 -0
  78. package/dist/slots.js +86 -0
  79. package/dist/slots.js.map +1 -0
  80. package/docs/agent-definition.md +86 -0
  81. package/docs/api.md +65 -0
  82. package/docs/architecture.md +47 -0
  83. package/docs/cli.md +28 -0
  84. package/docs/errors.md +76 -0
  85. package/docs/targets.md +49 -0
  86. package/package.json +51 -4
@@ -0,0 +1,73 @@
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<{
15
+ claude: "claude";
16
+ codex: "codex";
17
+ copilot: "copilot";
18
+ }>;
19
+ export type Target = z.infer<typeof TargetSchema>;
20
+ /** A shared referential: a local directory, or a Git repository pinned to a ref. */
21
+ export declare const ResourceSchema: z.ZodUnion<readonly [z.ZodObject<{
22
+ path: z.ZodString;
23
+ }, z.core.$strict>, z.ZodObject<{
24
+ git: z.ZodString;
25
+ ref: z.ZodString;
26
+ commit: z.ZodOptional<z.ZodString>;
27
+ path: z.ZodDefault<z.ZodString>;
28
+ }, z.core.$strict>]>;
29
+ export type Resource = z.infer<typeof ResourceSchema>;
30
+ export declare const ProjectFileSchema: z.ZodObject<{
31
+ agentsDir: z.ZodDefault<z.ZodString>;
32
+ sharedDir: z.ZodDefault<z.ZodString>;
33
+ exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
34
+ namePrefix: z.ZodDefault<z.ZodString>;
35
+ constraints: z.ZodOptional<z.ZodString>;
36
+ blocksDir: z.ZodDefault<z.ZodString>;
37
+ blockNumberFloor: z.ZodDefault<z.ZodNumber>;
38
+ targets: z.ZodDefault<z.ZodArray<z.ZodEnum<{
39
+ claude: "claude";
40
+ codex: "codex";
41
+ copilot: "copilot";
42
+ }>>>;
43
+ resources: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
44
+ path: z.ZodString;
45
+ }, z.core.$strict>, z.ZodObject<{
46
+ git: z.ZodString;
47
+ ref: z.ZodString;
48
+ commit: z.ZodOptional<z.ZodString>;
49
+ path: z.ZodDefault<z.ZodString>;
50
+ }, z.core.$strict>]>>>;
51
+ cacheDir: z.ZodDefault<z.ZodString>;
52
+ }, z.core.$strict>;
53
+ export type ProjectFile = z.infer<typeof ProjectFileSchema>;
54
+ /** A project with every path made absolute. */
55
+ export interface Project {
56
+ root: string;
57
+ agentsRoot: string;
58
+ sharedRoot: string;
59
+ blocksRoot: string;
60
+ exclude: string[];
61
+ namePrefix: string;
62
+ constraintsFile?: string;
63
+ blockNumberFloor: number;
64
+ targets: Target[];
65
+ resources: Record<string, Resource>;
66
+ cacheRoot: string;
67
+ }
68
+ export declare const PROJECT_FILE = "ruleloom.json";
69
+ /** A project from options, every path resolved against `root`. */
70
+ export declare function defineProject(root: string, options?: Partial<z.input<typeof ProjectFileSchema>>): Project;
71
+ /** `ruleloom.json` in `root`, or the defaults when there is none. */
72
+ export declare function loadProject(root: string): Project;
73
+ //# 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;AAIxB;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,OAAO,yCAA0C,CAAC;AAC/D,eAAO,MAAM,YAAY;;;;EAAkB,CAAC;AAC5C,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,oFAAoF;AACpF,eAAO,MAAM,cAAc;;;;;;;oBAazB,CAAC;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAItD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;kBA2BnB,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,103 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
3
+ import { z } from 'zod';
4
+ import { formatIssues } from './issues.js';
5
+ import { RuleLoomError } from './errors.js';
6
+ /**
7
+ * The project around the agents: where they live, what they share, and the
8
+ * few conventions a generated file needs — `ruleloom.json`, all optional.
9
+ *
10
+ * agents/ agentsDir
11
+ * shared/ sharedDir: rules every agent may inherit,
12
+ * rules/ run blocks, the constraints paragraph
13
+ * blocks/
14
+ * reviewer/agent.json one agent per directory
15
+ * writer/agent.json
16
+ */
17
+ export const TARGETS = ['claude', 'codex', 'copilot'];
18
+ export const TargetSchema = z.enum(TARGETS);
19
+ /** A shared referential: a local directory, or a Git repository pinned to a ref. */
20
+ export const ResourceSchema = z.union([
21
+ z.object({ path: z.string().min(1) }).strict(),
22
+ z
23
+ .object({
24
+ git: z.string().min(1),
25
+ /** A tag or a commit. A branch moves, and a moving source is not reproducible. */
26
+ ref: z.string().min(1),
27
+ /** Expected commit: compilation refuses a ref that resolves elsewhere. */
28
+ commit: z.string().regex(/^[0-9a-f]{7,40}$/).optional(),
29
+ /** Sub-directory of the repository that holds the resources. */
30
+ path: z.string().default('.'),
31
+ })
32
+ .strict(),
33
+ ]);
34
+ const RESOURCE_ALIAS = /^[a-z][a-z0-9-]*$/;
35
+ export const ProjectFileSchema = z
36
+ .object({
37
+ /** Directory holding one sub-directory per agent. Relative to the project file. */
38
+ agentsDir: z.string().default('.'),
39
+ /** Shared rules, blocks and constraints. Relative to `agentsDir`. */
40
+ sharedDir: z.string().default('shared'),
41
+ /** Sub-directories of `agentsDir` that are never agents. */
42
+ exclude: z.array(z.string()).default([]),
43
+ /** Prefix of every generated agent name: `acme-` turns `reviewer` into `acme-reviewer`. */
44
+ namePrefix: z.string().regex(/^[a-z0-9-]*$/, 'NAME_PREFIX_INVALID').default(''),
45
+ /**
46
+ * A paragraph every agent file ends on, relative to `sharedDir`. Said out
47
+ * loud because rule loading is invisible: a model that cannot see where
48
+ * its rules came from must not conclude they are optional.
49
+ */
50
+ constraints: z.string().optional(),
51
+ /** Run-supplied prompt blocks: `<number>_<NAME>.md` templates, relative to `sharedDir`. */
52
+ blocksDir: z.string().default('blocks'),
53
+ /** Block files start at this number; hand-written modules stay below it. */
54
+ blockNumberFloor: z.number().int().positive().default(100),
55
+ /** Targets compiled when none is named. */
56
+ targets: z.array(TargetSchema).min(1).default(['claude']),
57
+ /** Shared referentials, cited in module paths as `@<alias>/…`. */
58
+ resources: z.record(z.string().regex(RESOURCE_ALIAS, 'RESOURCE_ALIAS_INVALID'), ResourceSchema).default({}),
59
+ /** Where Git resources are fetched. Relative to the project file. */
60
+ cacheDir: z.string().default('.ruleloom/cache'),
61
+ })
62
+ .strict();
63
+ export const PROJECT_FILE = 'ruleloom.json';
64
+ const absolute = (base, path) => (isAbsolute(path) ? path : resolve(base, path));
65
+ /** A project from options, every path resolved against `root`. */
66
+ export function defineProject(root, options = {}) {
67
+ const parsed = ProjectFileSchema.safeParse(options);
68
+ if (!parsed.success) {
69
+ throw new RuleLoomError('PROJECT_CONFIG_INVALID', formatIssues(parsed.error.issues));
70
+ }
71
+ const file = parsed.data;
72
+ const base = resolve(root);
73
+ const agentsRoot = absolute(base, file.agentsDir);
74
+ const sharedRoot = absolute(agentsRoot, file.sharedDir);
75
+ return {
76
+ root: base,
77
+ agentsRoot,
78
+ sharedRoot,
79
+ blocksRoot: absolute(sharedRoot, file.blocksDir),
80
+ exclude: file.exclude,
81
+ namePrefix: file.namePrefix,
82
+ ...(file.constraints ? { constraintsFile: absolute(sharedRoot, file.constraints) } : {}),
83
+ blockNumberFloor: file.blockNumberFloor,
84
+ targets: file.targets,
85
+ resources: file.resources,
86
+ cacheRoot: absolute(base, file.cacheDir),
87
+ };
88
+ }
89
+ /** `ruleloom.json` in `root`, or the defaults when there is none. */
90
+ export function loadProject(root) {
91
+ const path = join(resolve(root), PROJECT_FILE);
92
+ if (!existsSync(path))
93
+ return defineProject(root);
94
+ let raw;
95
+ try {
96
+ raw = JSON.parse(readFileSync(path, 'utf8'));
97
+ }
98
+ catch (error) {
99
+ throw new RuleLoomError('PROJECT_CONFIG_UNREADABLE', `${path} — ${error.message}`);
100
+ }
101
+ return defineProject(dirname(path), raw);
102
+ }
103
+ //# 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,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AAC/D,MAAM,CAAC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AC,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,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,mFAAmF;IACnF,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAID,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,cAAc,CAoF3E"}
package/dist/prompt.js ADDED
@@ -0,0 +1,91 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { join } from 'node:path';
3
+ import { readAgentConfig } from './config.js';
4
+ import { loadBlockTemplates, renderBlock } from './blocks.js';
5
+ import { RuleLoomError } from './errors.js';
6
+ import { ModuleReader } from './resources.js';
7
+ import { selectModules } from './select.js';
8
+ import { bindSlots, resolveAgentSlots, usedSlots } from './slots.js';
9
+ const sha256 = (value) => createHash('sha256').update(value, 'utf8').digest('hex');
10
+ export function compilePrompt(options) {
11
+ const { project } = options;
12
+ const agentDir = join(project.agentsRoot, options.agent);
13
+ const config = readAgentConfig(agentDir);
14
+ const reader = new ModuleReader(project);
15
+ const blocks = loadBlockTemplates(project.blocksRoot, {
16
+ floor: project.blockNumberFloor,
17
+ ...(options.expectedBlocks ? { expected: options.expectedBlocks } : {}),
18
+ });
19
+ const blockNames = blocks.map((block) => block.name);
20
+ // Inherited rules open the prompt: their absence changes what the model
21
+ // produces, not how well.
22
+ const inherited = config.sharedRules.map((name) => ({
23
+ path: `shared/rules/${name}`, tags: [], always: true, trailing: false, modes: [],
24
+ }));
25
+ const selected = [
26
+ ...inherited,
27
+ ...selectModules(config, {
28
+ ...(options.mode ? { mode: options.mode } : {}),
29
+ ...(options.failedCodes ? { failedCodes: options.failedCodes } : {}),
30
+ }),
31
+ ];
32
+ if (selected.length === 0)
33
+ throw new RuleLoomError('PROMPT_NO_MODULES', `nothing selected for ${config.name}`);
34
+ const slots = resolveAgentSlots(config, {
35
+ ...(options.random ? { random: options.random } : {}),
36
+ ...(options.data ? { data: options.data } : {}),
37
+ });
38
+ const used = new Set();
39
+ const modules = [];
40
+ const parts = [];
41
+ if (config.preamble.length > 0) {
42
+ parts.push(bindSlots(config.preamble.join('\n').trim(), slots, { where: 'the preamble', used, blocks: blockNames }));
43
+ }
44
+ const read = (module) => {
45
+ // Hashed after binding: the record describes what was compiled.
46
+ const body = bindSlots(reader.read(agentDir, module.path), slots, { where: module.path, used, blocks: blockNames });
47
+ modules.push({ path: module.path, sha256: sha256(body), bytes: Buffer.byteLength(body, 'utf8') });
48
+ return body;
49
+ };
50
+ for (const module of selected.filter((m) => !m.trailing))
51
+ parts.push('---', read(module));
52
+ const staticText = `${parts.join('\n\n')}\n`;
53
+ const trailingText = selected
54
+ .filter((module) => module.trailing)
55
+ .map((module) => `---\n\n${read(module)}`)
56
+ .join('\n\n');
57
+ const values = options.values ?? {};
58
+ const cited = blockNames.filter((name) => staticText.includes(`{{${name}}}`) || trailingText.includes(`{{${name}}}`));
59
+ const unresolved = cited.filter((name) => values[name] === undefined);
60
+ const unknownValues = Object.keys(values).filter((name) => !blockNames.includes(name));
61
+ if (unknownValues.length > 0) {
62
+ throw new RuleLoomError('PROMPT_VALUE_UNKNOWN', `${unknownValues.join(', ')} — blocks: ${blockNames.join(', ') || '(none)'}`);
63
+ }
64
+ const dynamicParts = [];
65
+ for (const block of blocks) {
66
+ const value = values[block.name];
67
+ if (value === undefined || value === '')
68
+ continue;
69
+ dynamicParts.push(`---\n\n${renderBlock(block, value)}`);
70
+ }
71
+ const runText = dynamicParts.length > 0 ? `${dynamicParts.join('\n\n')}\n` : '';
72
+ if (trailingText)
73
+ dynamicParts.push(trailingText);
74
+ const dynamicText = dynamicParts.length > 0 ? `${dynamicParts.join('\n\n')}\n` : '';
75
+ return {
76
+ agent: config.name,
77
+ version: config.version,
78
+ static: staticText,
79
+ dynamic: dynamicText,
80
+ runBlocks: runText,
81
+ trailing: trailingText ? `${trailingText}\n` : '',
82
+ text: dynamicText ? `${staticText}\n${dynamicText}` : staticText,
83
+ staticSha256: sha256(staticText),
84
+ modules,
85
+ unresolvedBlocks: unresolved,
86
+ cited: usedSlots(slots, used),
87
+ slots,
88
+ selection: options.failedCodes && options.failedCodes.length > 0 ? 'retry' : 'full',
89
+ };
90
+ }
91
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiErE,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAA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,UAAU,KAAK,WAAW,EAAE,CAAC,CAAC,CAAC,UAAU;QAChE,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC;QAChC,OAAO;QACP,gBAAgB,EAAE,UAAU;QAC5B,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC;QAC7B,KAAK;QACL,SAAS,EAAE,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;KACpF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Project } from './project.js';
2
+ /**
3
+ * Where a module path points, and what it resolved to.
4
+ *
5
+ * Three roots, stated by the path itself so a reader can tell where a rule
6
+ * comes from without opening a manifest:
7
+ *
8
+ * source/rules/10_X.md the agent's own directory
9
+ * shared/rules/00_X.md the project's shared directory
10
+ * @common/rules/00_X.md a declared resource — a local referential or a
11
+ * Git repository pinned to a ref
12
+ */
13
+ export interface ResolvedResource {
14
+ alias: string;
15
+ root: string;
16
+ /** Present for a Git resource: the commit actually read. */
17
+ git?: {
18
+ url: string;
19
+ ref: string;
20
+ commit: string;
21
+ };
22
+ }
23
+ /** One declared resource, resolved to a directory. */
24
+ export declare function resolveResource(project: Project, alias: string): ResolvedResource;
25
+ /** Resolves module paths against the agent, the shared directory and the resources, caching each resource. */
26
+ export declare class ModuleReader {
27
+ private readonly project;
28
+ private readonly resolved;
29
+ constructor(project: Project);
30
+ /** The resources this reader touched, for the build manifest. */
31
+ used(): ResolvedResource[];
32
+ /** Absolute file a module path names, refused if it escapes its root. */
33
+ locate(agentDir: string, path: string): string;
34
+ /** A module's text, trimmed. */
35
+ read(agentDir: string, path: string): string;
36
+ /** A shared rule by file name, with the names known when it is missing. */
37
+ readSharedRule(name: string): string;
38
+ }
39
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,cAAc,CAAC;AAEtD;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,GAAG,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAsDD,sDAAsD;AACtD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAYjF;AAED,8GAA8G;AAC9G,qBAAa,YAAY;IAGX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;gBAEnC,OAAO,EAAE,OAAO;IAE7C,iEAAiE;IACjE,IAAI,IAAI,gBAAgB,EAAE;IAI1B,yEAAyE;IACzE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAyB9C,gCAAgC;IAChC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAM5C,2EAA2E;IAC3E,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CASrC"}
@@ -0,0 +1,118 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { execFileSync } from 'node:child_process';
3
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync } from 'node:fs';
4
+ import { join, relative, resolve, sep } from 'node:path';
5
+ import { RuleLoomError } from './errors.js';
6
+ const SHARED_PREFIX = 'shared/';
7
+ const RESOURCE_PREFIX = /^@([a-z][a-z0-9-]*)\/(.+)$/;
8
+ /** True when `child` is `parent` or inside it. */
9
+ function inside(parent, child) {
10
+ const rel = relative(parent, child);
11
+ return rel === '' || (!rel.startsWith(`..${sep}`) && rel !== '..' && !resolve(rel).startsWith(sep + '..'));
12
+ }
13
+ const git = (args, cwd) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
14
+ /**
15
+ * A Git resource, fetched once into the cache at the pinned ref.
16
+ *
17
+ * Fetched by ref rather than cloned by branch so a tag and a commit work the
18
+ * same way. The commit read is returned and recorded in every bundle
19
+ * manifest: a ref is a name, the commit is what was compiled.
20
+ */
21
+ function fetchGit(project, alias, resource) {
22
+ const key = createHash('sha256').update(`${resource.git}#${resource.ref}`).digest('hex').slice(0, 16);
23
+ const dir = join(project.cacheRoot, `${alias}-${key}`);
24
+ if (!existsSync(join(dir, '.git'))) {
25
+ rmSync(dir, { recursive: true, force: true });
26
+ mkdirSync(dir, { recursive: true });
27
+ try {
28
+ git(['init', '--quiet'], dir);
29
+ git(['remote', 'add', 'origin', resource.git], dir);
30
+ git(['fetch', '--quiet', '--depth', '1', 'origin', resource.ref], dir);
31
+ git(['checkout', '--quiet', '--detach', 'FETCH_HEAD'], dir);
32
+ }
33
+ catch (error) {
34
+ rmSync(dir, { recursive: true, force: true });
35
+ throw new RuleLoomError('RESOURCE_GIT_FETCH_FAILED', `@${alias} — ${resource.git}#${resource.ref}: ${error.message.split('\n')[0]}`);
36
+ }
37
+ }
38
+ const commit = git(['rev-parse', 'HEAD'], dir);
39
+ if (resource.commit && !commit.startsWith(resource.commit)) {
40
+ throw new RuleLoomError('RESOURCE_COMMIT_MISMATCH', `@${alias} — ${resource.ref} resolves to ${commit}, the project pins ${resource.commit}`);
41
+ }
42
+ const root = resolve(dir, resource.path);
43
+ if (!inside(dir, root)) {
44
+ throw new RuleLoomError('RESOURCE_PATH_OUTSIDE', `@${alias} — path ${resource.path} leaves the repository`);
45
+ }
46
+ return { alias, root, git: { url: resource.git, ref: resource.ref, commit } };
47
+ }
48
+ /** One declared resource, resolved to a directory. */
49
+ export function resolveResource(project, alias) {
50
+ const resource = project.resources[alias];
51
+ if (!resource) {
52
+ throw new RuleLoomError('RESOURCE_UNKNOWN', `@${alias} — the project declares ${Object.keys(project.resources).join(', ') || '(no resource)'}`);
53
+ }
54
+ if ('git' in resource)
55
+ return fetchGit(project, alias, resource);
56
+ const root = resolve(project.root, resource.path);
57
+ if (!existsSync(root))
58
+ throw new RuleLoomError('RESOURCE_MISSING', `@${alias} — ${root} does not exist`);
59
+ return { alias, root };
60
+ }
61
+ /** Resolves module paths against the agent, the shared directory and the resources, caching each resource. */
62
+ export class ModuleReader {
63
+ project;
64
+ resolved = new Map();
65
+ constructor(project) {
66
+ this.project = project;
67
+ }
68
+ /** The resources this reader touched, for the build manifest. */
69
+ used() {
70
+ return [...this.resolved.values()].sort((a, b) => a.alias.localeCompare(b.alias));
71
+ }
72
+ /** Absolute file a module path names, refused if it escapes its root. */
73
+ locate(agentDir, path) {
74
+ let root;
75
+ let rest;
76
+ const resource = RESOURCE_PREFIX.exec(path);
77
+ if (resource) {
78
+ const alias = resource[1];
79
+ let entry = this.resolved.get(alias);
80
+ if (!entry) {
81
+ entry = resolveResource(this.project, alias);
82
+ this.resolved.set(alias, entry);
83
+ }
84
+ root = entry.root;
85
+ rest = resource[2];
86
+ }
87
+ else if (path.startsWith(SHARED_PREFIX)) {
88
+ root = this.project.sharedRoot;
89
+ rest = path.slice(SHARED_PREFIX.length);
90
+ }
91
+ else {
92
+ root = agentDir;
93
+ rest = path;
94
+ }
95
+ const file = resolve(root, rest);
96
+ if (!inside(root, file))
97
+ throw new RuleLoomError('MODULE_PATH_OUTSIDE', `${path} leaves its root ${root}`);
98
+ return file;
99
+ }
100
+ /** A module's text, trimmed. */
101
+ read(agentDir, path) {
102
+ const file = this.locate(agentDir, path);
103
+ if (!existsSync(file))
104
+ throw new RuleLoomError('AGENT_MODULE_MISSING', `${path} (agent ${agentDir})`);
105
+ return readFileSync(file, 'utf8').trim();
106
+ }
107
+ /** A shared rule by file name, with the names known when it is missing. */
108
+ readSharedRule(name) {
109
+ const dir = join(this.project.sharedRoot, 'rules');
110
+ const file = join(dir, name);
111
+ if (!inside(dir, resolve(file)) || !existsSync(file)) {
112
+ const known = existsSync(dir) ? readdirSync(dir).sort().join(', ') : '(none)';
113
+ throw new RuleLoomError('SHARED_RULE_MISSING', `${name} — known: ${known}`);
114
+ }
115
+ return readFileSync(file, 'utf8').trim();
116
+ }
117
+ }
118
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsB5C,MAAM,aAAa,GAAG,SAAS,CAAC;AAChC,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAErD,kDAAkD;AAClD,SAAS,MAAM,CAAC,MAAc,EAAE,KAAa;IAC3C,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC;AAC7G,CAAC;AAED,MAAM,GAAG,GAAG,CAAC,IAAc,EAAE,GAAY,EAAU,EAAE,CACnD,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,E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,CAAC;IAC3C,CAAC;IAED,2EAA2E;IAC3E,cAAc,CAAC,IAAY;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC9E,MAAM,IAAI,aAAa,CAAC,qBAAqB,EAAE,GAAG,IAAI,aAAa,KAAK,EAAE,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import type { AgentConfig, AgentModule } from './config.js';
2
+ /** The mode a compilation is for: the one asked, or the agent's first. */
3
+ export declare function resolveMode(config: AgentConfig, requested?: string): string | undefined;
4
+ /** Modules of a mode: those bound to no mode, and that mode's. */
5
+ export declare function modulesForMode(config: AgentConfig, mode?: string): AgentModule[];
6
+ export interface SelectOptions {
7
+ /** One of the agent's `modes`; absent is its default. */
8
+ mode?: string;
9
+ /** Retry: keep only the modules tagged with one of these codes, and every `always` module. */
10
+ failedCodes?: readonly string[];
11
+ }
12
+ /** Modules kept for a mode and, on a retry, for the codes that failed. */
13
+ export declare function selectModules(config: AgentConfig, options?: SelectOptions): AgentModule[];
14
+ //# sourceMappingURL=select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../src/select.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5D,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASvF;AAED,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAIhF;AAED,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,aAAkB,GAAG,WAAW,EAAE,CAK7F"}
package/dist/select.js ADDED
@@ -0,0 +1,25 @@
1
+ import { RuleLoomError } from './errors.js';
2
+ /** The mode a compilation is for: the one asked, or the agent's first. */
3
+ export function resolveMode(config, requested) {
4
+ if (requested === undefined)
5
+ return config.modes[0];
6
+ if (!config.modes.includes(requested)) {
7
+ throw new RuleLoomError('AGENT_MODE_UNKNOWN', `${config.name} does not declare mode ${requested} — declared: ${config.modes.join(', ') || '(none)'}`);
8
+ }
9
+ return requested;
10
+ }
11
+ /** Modules of a mode: those bound to no mode, and that mode's. */
12
+ export function modulesForMode(config, mode) {
13
+ const resolved = resolveMode(config, mode);
14
+ return config.modules.filter((module) => module.modes.length === 0
15
+ || (resolved !== undefined && module.modes.includes(resolved)));
16
+ }
17
+ /** Modules kept for a mode and, on a retry, for the codes that failed. */
18
+ export function selectModules(config, options = {}) {
19
+ const eligible = modulesForMode(config, options.mode);
20
+ if (!options.failedCodes || options.failedCodes.length === 0)
21
+ return eligible;
22
+ const wanted = new Set(options.failedCodes);
23
+ return eligible.filter((module) => module.always || module.tags.some((tag) => wanted.has(tag)));
24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,CAAC;IAC9E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { AgentConfig } from './config.js';
2
+ /** One `NAME=value` override, trimmed and validated. */
3
+ export declare function resolveDataOverride(name: string, value: string): string;
4
+ /**
5
+ * The value each `${{NAME}}` an agent declares takes for one compilation.
6
+ *
7
+ * `data` is copied as written, then overridden by `given.data`. `random` takes
8
+ * the drawn value from `given.random`, or its first value when nothing was
9
+ * drawn — deterministic on purpose, so two compilations compare byte for byte.
10
+ * Both `given` maps are pools: a run carries every value it drew for every
11
+ * agent, so a name this agent does not declare is ignored. A drawn *value*
12
+ * outside the declared list is refused: a typo or a stale pin.
13
+ */
14
+ export declare function resolveAgentSlots(config: AgentConfig, given?: {
15
+ random?: Record<string, string>;
16
+ data?: Record<string, string>;
17
+ }): Record<string, string>;
18
+ export interface BindOptions {
19
+ /** Where the text comes from, for the error message. */
20
+ where?: string;
21
+ /** Collects the agent slots the text cited. */
22
+ used?: Set<string>;
23
+ /** Run block names left in place as `{{NAME}}`. */
24
+ blocks?: Iterable<string>;
25
+ }
26
+ /**
27
+ * Binds the agent's slots in a text and refuses any slot nobody knows.
28
+ *
29
+ * One pass with a function replacer: a value is inserted once, never re-read
30
+ * as a template, and `$` sequences in it stay text.
31
+ */
32
+ export declare function bindSlots(text: string, slots: Record<string, string>, options?: BindOptions): string;
33
+ /** The slots a text actually cited, with their values, sorted by name. */
34
+ export declare function usedSlots(slots: Record<string, string>, used: Set<string>): Record<string, string>;
35
+ //# sourceMappingURL=slots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../src/slots.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA0B/C,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CASvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,KAAK,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,GAC7E,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB;AAED,MAAM,WAAW,WAAW;IAC1B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,mDAAmD;IACnD,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM,CAuBxG;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAElG"}