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
@@ -0,0 +1,47 @@
1
+ # Architecture
2
+
3
+ RuleLoom is the second of four stages. It does not run agents; it produces what a platform needs to run one, and records exactly what it produced.
4
+
5
+ ```
6
+ 1 Referentials 2 Compiler 3 Dedicated workspaces 4 Orchestration
7
+ ─────────────── ───────────── ────────────────────── ───────────────
8
+ shared rules, skills, resolve references Claude Code .claude/ CI/CD: build, test,
9
+ MCP servers assemble modules, Codex AGENTS.md review, docs
10
+ local dirs, Git repos slots, MCP Copilot .github/ LangGraph: chaining,
11
+ agent.json per agent adapt native format parallelism,
12
+ validate limits, names one agent, its own validation, retry
13
+ permissions; secrets
14
+ injected at runtime
15
+ ```
16
+
17
+ ## 1. Referentials
18
+
19
+ Everything an agent is made of is a file under version control:
20
+
21
+ - `agents/<name>/agent.json` — the agent: its modules in order, slots, modes, MCP servers, per-target settings.
22
+ - `agents/shared/` — rules several agents inherit (`sharedRules`), run block templates, the constraints paragraph.
23
+ - Resources declared in `ruleloom.json` — a local directory or a Git repository at a pinned ref, cited as `@alias/…`. The commit actually read is recorded in each build manifest, so a ref that moves cannot change a build unnoticed (`commit` pins it hard).
24
+
25
+ ## 2. Compiler
26
+
27
+ | Step | What happens | Fails with |
28
+ |---|---|---|
29
+ | Resolve | `agent.json` and `ruleloom.json` validated; module paths located in the agent, `shared/` or a resource; Git resources fetched at their ref | `AGENT_CONFIG_INVALID`, `RESOURCE_*`, `MODULE_PATH_OUTSIDE` |
30
+ | Assemble | modules selected for the mode (and, for a prompt, the failed codes); `${{slots}}` bound; rules, skills and the mission named | `AGENT_SLOT_UNKNOWN`, `PROMPT_SLOT_UNKNOWN`, `AGENT_MODE_UNKNOWN`, `AGENT_PRELOAD_SKILL_UNKNOWN` |
31
+ | Adapt | one adapter per target writes the platform's files | `TARGET_OVERRIDE_*`, `COPILOT_AGENT_TOO_LARGE` |
32
+ | Validate | names and sizes every target accepts; a checksum over every emitted file | `SKILL_NAME_INVALID`, `SKILL_DESCRIPTION_TOO_LONG` |
33
+
34
+ Two outputs:
35
+
36
+ - **A bundle** (`compileBundle`): a directory the platform loads by itself. Rules stay one file each where the platform supports it, because a separate file is what lets a human see which rule an agent followed.
37
+ - **A prompt** (`compilePrompt`): one string for a completion API, split into a static half (cacheable) and a dynamic half (the run blocks, then the trailing modules).
38
+
39
+ ## 3. Dedicated workspaces
40
+
41
+ `materialiseAgent` lays a bundle out as the whole configuration of a directory, with a `workspace/` for inputs and deliverables. It refuses a root that has platform configuration above it: Claude Code and Codex both walk up the tree and load what they find, so an agent launched under a repository would also read that repository's instructions.
42
+
43
+ Secrets are not part of a workspace. MCP servers reference variables (`${TOKEN}` for Claude Code and Copilot, `env_vars` for Codex); the launcher provides them.
44
+
45
+ ## 4. Orchestration
46
+
47
+ Outside RuleLoom. An orchestrator (a CI job, a LangGraph graph) compiles or materialises an agent, launches it, checks its output, and on failure recompiles the prompt with `failedCodes` — only the modules tagged with what failed, so a retry costs a fraction of the first attempt. Build manifests make every run attributable to exact sources.
package/docs/cli.md ADDED
@@ -0,0 +1,28 @@
1
+ # CLI
2
+
3
+ ```
4
+ ruleloom validate [--project dir] [--target t]...
5
+ ruleloom compile [--project dir] [--target t]... [--agent name] [--out dir] [--check]
6
+ [--mode m] [--data NAME=value]... [--random NAME=value]...
7
+ ruleloom prompt --agent name [--project dir] [--mode m] [--failed CODE,CODE]
8
+ [--value NAME=file]... [--data NAME=value]... [--random NAME=value]...
9
+ ruleloom materialise --agent name --root dir [--project dir] [--target t] [--mode m]
10
+ ruleloom list [--project dir]
11
+ ruleloom --version
12
+ ```
13
+
14
+ `--project` is the directory holding `ruleloom.json` (default: the current directory). `--target` may be repeated; without it, the project's `targets` are used.
15
+
16
+ | Command | What it does | Exit code |
17
+ |---|---|---|
18
+ | `validate` | Compiles every agent for every target in memory; prints checksums and notes. | 1 on the first error |
19
+ | `compile` | Writes `<out>/<target>/<agent>/` (default `.ruleloom/build`), removing files no bundle produces any more. With `--check`, writes nothing and reports drift. | 1 on drift under `--check` |
20
+ | `prompt` | Prints one agent's compiled prompt. `--value BRIEF=brief.md` fills a run block from a file; `--failed` compiles a retry. | 0; unresolved blocks are listed on stderr |
21
+ | `materialise` | Lays one bundle out as a dedicated workspace under `--root`; refuses a root with platform configuration above it. Prints `cwd`, `workspace`, `agentName`, `checksum`. | 1 if the root is not isolated |
22
+ | `list` | Prints the project's agents. | 0 |
23
+
24
+ In CI:
25
+
26
+ ```bash
27
+ npx ruleloom compile --check --out generated
28
+ ```
package/docs/errors.md ADDED
@@ -0,0 +1,76 @@
1
+ # Error codes
2
+
3
+ Every failure is a `RuleLoomError` whose `code` is one of these and whose message starts with it. Schema codes (marked *schema*) appear inside `AGENT_CONFIG_INVALID` or `PROJECT_CONFIG_INVALID`, after the field path.
4
+
5
+ ## Definitions
6
+
7
+ | Code | Cause |
8
+ |---|---|
9
+ | `AGENT_CONFIG_UNREADABLE` / `AGENT_CONFIG_INVALID` | `agent.json` is not JSON, or fails the schema; the message lists every issue. |
10
+ | `PROJECT_CONFIG_UNREADABLE` / `PROJECT_CONFIG_INVALID` | Same, for `ruleloom.json`. |
11
+ | `RANDOM_NAME_INVALID`, `DATA_NAME_INVALID` *schema* | A slot name that is not `UPPER_SNAKE`. |
12
+ | `RANDOM_VALUE_INVALID`, `DATA_VALUE_INVALID` *schema* | A value that could carry a brace into the text, or too long. |
13
+ | `AGENT_SLOT_DUPLICATED` *schema* | One name in both `random` and `data`. |
14
+ | `MODE_INVALID`, `AGENT_MODE_DUPLICATED`, `AGENT_MODE_UNKNOWN` *schema* | A malformed mode, a repeated one, or a module bound to a mode the agent does not declare. |
15
+ | `MCP_NAME_INVALID`, `MCP_TRANSPORT_INVALID`, `MCP_ENV_NAME_INVALID` *schema* | An MCP server with a bad name, both or neither of `command` / `url`, or an `env` entry that is not a variable name (a value would be a secret in every generated file). |
16
+ | `TARGET_KEY_INVALID`, `TARGET_VALUE_MULTILINE` *schema* | A per-target setting that cannot be written as one frontmatter line. |
17
+ | `SUMMARY_MULTILINE` *schema* | The summary becomes a one-line description. |
18
+ | `NAME_PREFIX_INVALID`, `RESOURCE_ALIAS_INVALID` *schema* | Project naming. |
19
+
20
+ ## Resolution
21
+
22
+ | Code | Cause |
23
+ |---|---|
24
+ | `AGENTS_ROOT_MISSING`, `AGENT_NOT_FOUND` | No such directory, or no `agent.json` in it. |
25
+ | `AGENT_MODULE_MISSING` | A module path names no file. |
26
+ | `MODULE_PATH_OUTSIDE` | A module path leaves its root (`../`). |
27
+ | `SHARED_RULE_MISSING` | A `sharedRules` entry not in `<shared>/rules/`; the message lists the known ones. |
28
+ | `CONSTRAINTS_MISSING` | The project's `constraints` file does not exist. |
29
+ | `RESOURCE_UNKNOWN`, `RESOURCE_MISSING`, `RESOURCE_PATH_OUTSIDE` | An `@alias` the project does not declare, a local resource that does not exist, a resource `path` that leaves its repository. |
30
+ | `RESOURCE_GIT_FETCH_FAILED` | The repository or the ref could not be fetched. |
31
+ | `RESOURCE_COMMIT_MISMATCH` | The ref resolves to another commit than the one pinned. |
32
+
33
+ ## Assembly and slots
34
+
35
+ | Code | Cause |
36
+ |---|---|
37
+ | `AGENT_SLOT_UNKNOWN` | `${{NAME}}` the agent declares in neither `data` nor `random`. |
38
+ | `PROMPT_SLOT_UNKNOWN` | `{{NAME}}` that is not a run block; the hint names `${{NAME}}` when the agent declares it. |
39
+ | `RANDOM_VALUE_UNKNOWN` | A drawn value outside the declared list. |
40
+ | `DATA_OVERRIDE_INVALID` | An override that is not a short name. |
41
+ | `AGENT_PRELOAD_SKILL_UNKNOWN` | `runtime.skills` names a skill the agent does not have. |
42
+ | `AGENT_MULTIPLE_MISSIONS` | More than one `mission` module. |
43
+ | `RULE_SLUG_COLLISION`, `SKILL_SLUG_COLLISION` | Two modules with the same file name. |
44
+ | `PROMPT_NO_MODULES` | Nothing selected — usually a retry whose codes match no tag and no `always` module. |
45
+ | `PROMPT_VALUE_UNKNOWN` | A value for a block that has no template. |
46
+
47
+ ## Run blocks
48
+
49
+ | Code | Cause |
50
+ |---|---|
51
+ | `PROMPT_BLOCKS_MISSING` | Blocks are expected and the directory does not exist. |
52
+ | `PROMPT_BLOCK_NAME` | A file not named `<number>_<NAME>.md`. |
53
+ | `PROMPT_BLOCK_UNKNOWN`, `PROMPT_BLOCK_MISSING` | Against `expectedBlocks`: an extra block, or a missing one. |
54
+ | `PROMPT_BLOCK_DUPLICATE` | Two files for one block. |
55
+ | `PROMPT_BLOCK_NUMBER_RANGE` | A number below the floor. |
56
+ | `PROMPT_BLOCK_NUMBER_MISMATCH` | The heading's `[n]` differs from the file number. |
57
+ | `PROMPT_BLOCK_SLOT`, `PROMPT_BLOCK_FOREIGN_SLOT` | The template cites its own slot not exactly once, or cites another. |
58
+
59
+ ## Targets
60
+
61
+ | Code | Cause |
62
+ |---|---|
63
+ | `SKILL_NAME_INVALID`, `SKILL_DESCRIPTION_TOO_LONG` | A skill every target would not accept. |
64
+ | `AGENT_NAME_INVALID` | An agent name Copilot cannot use as a file name. |
65
+ | `TARGET_OVERRIDE_RESERVED` | A per-target key RuleLoom writes itself (`name`, `description`…). |
66
+ | `TARGET_OVERRIDE_UNKNOWN` | A Codex key outside the documented ones. |
67
+ | `TARGET_OVERRIDE_FORBIDDEN` | `permissionMode: bypassPermissions` (Claude Code), `sandbox_mode: danger-full-access` (Codex). |
68
+ | `COPILOT_AGENT_TOO_LARGE` | Agent body over 30,000 characters. |
69
+ | `ADAPTER_RESERVED_PATH` | An adapter tried to write `build-manifest.json`. |
70
+ | `RUNTIME_ROOT_NOT_ISOLATED` | `materialiseAgent` under a root with platform configuration above it. |
71
+
72
+ ## CLI
73
+
74
+ | Code | Cause |
75
+ |---|---|
76
+ | `CLI_USAGE`, `CLI_PAIR_INVALID`, `TARGET_UNKNOWN` | A missing flag, a `NAME=value` without `=`, an unknown target. |
@@ -0,0 +1,49 @@
1
+ # Targets
2
+
3
+ Each adapter writes what its platform documents, and nothing it does not. Sources checked 2026-11-30.
4
+
5
+ ## Claude Code — `claude`
6
+
7
+ | File | Content |
8
+ |---|---|
9
+ | `.claude/agents/<name>.md` | Frontmatter `name`, `description` (the summary), `skills` (the preload, comma-separated), then `targets.claude` keys. Body: preamble, mission, constraints. |
10
+ | `.claude/rules/<slug>.md` | One per rule, shared rules first. No `paths` frontmatter: loaded at launch. |
11
+ | `.claude/skills/<slug>/SKILL.md` | Frontmatter `name` (= directory), `description` (first heading). |
12
+ | `.mcp.json` | `mcpServers`: stdio `{type, command, args, env}` with `env` values written as `${NAME}`; HTTP `{type: "http", url}`. |
13
+
14
+ `targets.claude` accepts any subagent frontmatter key (`tools`, `model`, `permissionMode`, `maxTurns`…), written as given. `name`, `description` and `skills` are RuleLoom's. `permissionMode: bypassPermissions` is refused.
15
+
16
+ Notes: Claude Code asks the user to approve project MCP servers. `.claude/` and `CLAUDE.md` are inherited from parent directories — see `materialiseAgent`.
17
+
18
+ Sources: <https://code.claude.com/docs/en/memory>, <https://code.claude.com/docs/en/skills>, <https://code.claude.com/docs/en/sub-agents>, <https://code.claude.com/docs/en/mcp>.
19
+
20
+ ## OpenAI Codex — `codex`
21
+
22
+ | File | Content |
23
+ |---|---|
24
+ | `AGENTS.md` | `# <name>`, the summary, preamble, mission, constraints, then every rule, separated by `---`. Codex has no modular rules directory. |
25
+ | `.agents/skills/<slug>/SKILL.md` | Frontmatter `name`, `description`. |
26
+ | `.codex/config.toml` | `targets.codex` keys; `project_doc_max_bytes` when `AGENTS.md` exceeds 32 KiB; `[mcp_servers.<name>]` with `command`, `args`, `env_vars` (names forwarded from Codex's environment) or `url`. |
27
+
28
+ `targets.codex` accepts `model`, `model_reasoning_effort`, `sandbox_mode`, `approval_policy` (strings). `sandbox_mode: danger-full-access` is refused.
29
+
30
+ Notes: Codex stops reading instructions at `project_doc_max_bytes` (32 KiB by default); RuleLoom raises it rather than letting the file be cut. A project `.codex/config.toml` is loaded only for a project the user trusts — the build manifest says so. Codex has no skill preload and no project-level prompt files.
31
+
32
+ Sources: <https://learn.chatgpt.com/docs/agent-configuration/agents-md>, <https://learn.chatgpt.com/docs/build-skills>, <https://learn.chatgpt.com/docs/extend/mcp>, <https://learn.chatgpt.com/docs/config-file/config-reference>.
33
+
34
+ ## GitHub Copilot — `copilot`
35
+
36
+ | File | Content |
37
+ |---|---|
38
+ | `.github/agents/<name>.agent.md` | Frontmatter `name`, `description`, then `targets.copilot` keys (`tools` as a list). Body: preamble, mission, constraints — at most 30,000 characters. |
39
+ | `.github/instructions/<slug>.instructions.md` | One per rule, `applyTo: "**"`. |
40
+ | `.github/skills/<slug>/SKILL.md` | Frontmatter `name` (= directory, lowercase, ≤ 64), `description` (≤ 1024). |
41
+ | `.mcp.json` | Same shape as Claude Code's: the Copilot harness in VS Code reads it. |
42
+
43
+ Notes: the cloud coding agent reads MCP servers from the repository settings, not from a file — the manifest says so. A body over 30,000 characters is refused (`COPILOT_AGENT_TOO_LARGE`): move text from the mission into rules.
44
+
45
+ Sources: <https://docs.github.com/en/copilot/reference/custom-agents-configuration>, <https://code.visualstudio.com/docs/agents/reference/custom-instructions-reference>, <https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/create-skills>, <https://code.visualstudio.com/docs/agents/reference/mcp-configuration>.
46
+
47
+ ## Limits every target shares
48
+
49
+ Skill names are validated against the strictest platform (Copilot): lowercase letters, digits and hyphens, at most 64 characters (`SKILL_NAME_INVALID`). Descriptions at most 1024 characters. Frontmatter values are quoted whenever plain YAML would misread them — a platform that cannot parse a file skips it without a word.
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "ruleloom",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Define an AI agent once — rules, skills, MCP servers, variables — and compile it into the native configuration of Claude Code, OpenAI Codex and GitHub Copilot.",
5
+ "keywords": [
6
+ "ai-agents",
7
+ "claude-code",
8
+ "codex",
9
+ "github-copilot",
10
+ "agents-md",
11
+ "prompt-engineering",
12
+ "mcp",
13
+ "compiler"
14
+ ],
15
+ "license": "MIT",
16
+ "type": "module",
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "bin": {
30
+ "ruleloom": "dist/cli.js"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "README.md",
35
+ "CHANGELOG.md",
36
+ "LICENSE",
37
+ "docs"
38
+ ],
39
+ "scripts": {
40
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/cli.js",
41
+ "typecheck": "tsc --noEmit",
42
+ "test": "vitest run",
43
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "zod": "^3.24.1"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^22.10.0",
50
+ "typescript": "^5.7.3",
51
+ "vitest": "^3.0.5"
52
+ }
53
+ }