v0.5.1
This commit is contained in:
@@ -1,181 +1,425 @@
|
||||
# optimus
|
||||
|
||||
A deliberately small project runtime for initialized modules, settings, named artifacts, and transformer-node helpers.
|
||||
**Optimus is a lightly opinionated framework for organizing pull-driven transformer operations.**
|
||||
|
||||
## Project shape
|
||||
An Optimus project is a team of modules working by a recognizable method. Some modules are transformers that produce durable artifacts. Others may provide services, import data, talk to LLMs or humans, publish results, or coordinate domain-specific work.
|
||||
|
||||
A host project provides JSON settings in `./settings/`:
|
||||
A caller asks for the artifact it wants. The responsible module pulls whatever dependencies it needs. Those modules pull their own dependencies. Existing artifacts are reused when their owning transformers consider them current, and work happens only where the chain requires it.
|
||||
|
||||
Optimus supplies the shared mechanics. Modules own the meaning of the work.
|
||||
|
||||
## The Optimus method
|
||||
|
||||
An Optimus project normally has:
|
||||
|
||||
```text
|
||||
settings/
|
||||
modules.json
|
||||
artifacts.json
|
||||
anything-else.json
|
||||
|
||||
src/
|
||||
some-module/
|
||||
some-transformer/
|
||||
|
||||
artifacts/
|
||||
... durable, inspectable work produced by transformers ...
|
||||
```
|
||||
|
||||
`modules.json` maps semantic module names to initializer modules:
|
||||
`settings/modules.json` names the participants:
|
||||
|
||||
```json
|
||||
{
|
||||
"chatter": "./tree/chatter/index.js",
|
||||
"markdown-builder": "./tree/markdown-builder/index.js"
|
||||
"source": "./src/source/index.js",
|
||||
"translation": "./src/translation/index.js",
|
||||
"publisher": "./src/publisher/index.js"
|
||||
}
|
||||
```
|
||||
|
||||
Each module exports an initializer that receives the same shared `utils` object:
|
||||
Each module is initialized with the shared Optimus `utils` object:
|
||||
|
||||
```js
|
||||
module.exports = utils => {
|
||||
function doSomething() {
|
||||
const chatter = utils.loadModule("chatter");
|
||||
const llm = utils.getSettings("llm");
|
||||
const source = utils.loadModule("source");
|
||||
|
||||
async function buildSomething(name) {
|
||||
const input = await source.loadSomething(name);
|
||||
// Pull more dependencies and do domain work here.
|
||||
}
|
||||
|
||||
return { doSomething };
|
||||
return { buildSomething };
|
||||
};
|
||||
```
|
||||
|
||||
## Utilities
|
||||
Ordinary recursive module calls are the dependency graph. Optimus does not require a second declarative DAG that duplicates the program.
|
||||
|
||||
### `utils.loadModule(name)`
|
||||
### Module boundaries and dependency resolution
|
||||
|
||||
Returns the initialized module registered under that semantic name.
|
||||
`settings/modules.json` is the project's composition map. It tells Optimus where a semantically named module comes from. The consumer should know the module name, not its location.
|
||||
|
||||
### `utils.getSettings(name)`
|
||||
Peer modules therefore load one another through Optimus:
|
||||
|
||||
Returns the parsed contents of `./settings/<name>.json`.
|
||||
```js
|
||||
module.exports = utils => {
|
||||
const segmentation = utils.loadModule("hebrew-segmentation");
|
||||
// ...
|
||||
};
|
||||
```
|
||||
|
||||
### `utils.hashPayload(value)`
|
||||
A module may use ordinary relative imports for private implementation that lives inside that module's own directory:
|
||||
|
||||
Returns a SHA-256 hex hash of `JSON.stringify(value)`. No key sorting or normalization is performed.
|
||||
```js
|
||||
const parser = require("./parser");
|
||||
```
|
||||
|
||||
### `utils.buildNode(payload, sources = {})`
|
||||
A module should not reach sideways into another module by filesystem location:
|
||||
|
||||
Builds a transformer-node packet from a payload and already-loaded source nodes:
|
||||
```js
|
||||
// Avoid: this couples the consumer to today's repository layout.
|
||||
const segmentation = require("../hebrew-segmentation");
|
||||
const helper = require("../shared-lib/agent-transformer");
|
||||
```
|
||||
|
||||
If code in another module directory is a dependency, give it a module identity, register it in `settings/modules.json`, and load it with `utils.loadModule(name)`. If code is truly private implementation, keep it inside the owning module.
|
||||
|
||||
This makes Optimus the single dependency resolver for peer modules. A project's composition mapping may change as modules move, split, are extracted, or are provided differently; consumers remain coupled only to the semantic module contract. The current runtime happens to map names to filesystem entry paths, but peer modules should not depend on that representation.
|
||||
|
||||
This is dependency injection in the ordinary sense: modules declare what collaborator they need by semantic name, while the project decides what implementation satisfies that name. There should not be a second peer-dependency convention based on relative paths unless a concrete, distinct reason requires one.
|
||||
|
||||
## Modules and transformers
|
||||
|
||||
A **module** is any participant in the operation.
|
||||
|
||||
A **transformer** is a module that can be asked for an artifact and can determine whether the artifact it already has is stale according to that transformer's needs.
|
||||
|
||||
All transformers are modules. Not all modules are transformers.
|
||||
|
||||
A transformer does not have to map one-to-one with one tiny transformation. One coherent module may own several genuinely related transformations and artifact layers. An importer, for example, may naturally produce volume-, book-, and chapter-level artifacts.
|
||||
|
||||
Prefer coherent responsibility over artificial micro-machines.
|
||||
|
||||
## Artifacts are an organized warehouse
|
||||
|
||||
Artifacts are durable work products, not opaque cache internals.
|
||||
|
||||
A human should be able to open a transformer's artifact area and directly find the thing they want to inspect. Persisted metadata exists to explain provenance and help determine freshness, but the artifact itself remains useful, discoverable work.
|
||||
|
||||
Artifacts may come from code, LLMs, humans, external systems, or mixtures of them. Optimus does not care who produced the work. The owning transformer cares whether that work remains valid.
|
||||
|
||||
Caching is a benefit of durable artifacts, not their purpose.
|
||||
|
||||
## Pull, don't push
|
||||
|
||||
Optimus is a pull queue.
|
||||
|
||||
If a project asks for D:
|
||||
|
||||
```text
|
||||
request D
|
||||
↓
|
||||
D asks for B and C
|
||||
↓ ↓
|
||||
B asks A C asks A
|
||||
↓ ↓
|
||||
existing/current work is reused where possible
|
||||
```
|
||||
|
||||
There is no requirement for a central controller to push A, then B, then C, then D.
|
||||
|
||||
This matters especially for expensive or nondeterministic work. A resumed project should not repeat an LLM call merely because some downstream artifact is being rebuilt.
|
||||
|
||||
### Ensure dependencies; do not bypass the pull graph
|
||||
|
||||
Across module boundaries, the normal operation is to **ensure** the dependency you need. An ensure means: establish the evergreen artifact, reusing the persisted copy when its owning transformer considers it current and rebuilding it when that transformer considers it genuinely stale.
|
||||
|
||||
A downstream consumer should not read a persisted upstream artifact directly merely to avoid reevaluating it. Doing so bypasses the pull contract: the consumer gets a historical copy without asking the owning transformer whether that copy is still valid.
|
||||
|
||||
If ensuring an expensive artifact causes work that seems unnecessary, ask why its owning transformer considers it stale. Usually the correction belongs in that transformer's freshness rule: depend only on inputs that actually affect the semantic result, preserve accepted expensive work across irrelevant implementation changes, or otherwise make the validity rule match the transformation. A raw read should not be used as a cure for over-sensitive staleness.
|
||||
|
||||
Low-level reads remain useful inside transformer-owned lifecycle logic: custom validity checks, migration/adoption, inspection, repair, and similar cases. They are implementation tools for deciding whether owned work is current, not an alternate dependency mechanism.
|
||||
|
||||
Sometimes the desired behavior really is **not evergreen**. If a project deliberately accepts a finished result as a stable publication or archival product, export/eject it and use that exported file as input to another project. The receiving project can ensure its own input normally, but there is no live dependency edge back to the old producer and therefore no mechanism by which it can accidentally regenerate the accepted edition.
|
||||
|
||||
```text
|
||||
Evergreen dependency:
|
||||
consumer -> ensure producer artifact -> reuse or rebuild according to producer freshness
|
||||
|
||||
Deliberately frozen handoff:
|
||||
project A artifact -> output/file -> project B input/file
|
||||
^ no live edge back to project A
|
||||
```
|
||||
|
||||
These are different semantics and should remain visibly different in the project structure.
|
||||
|
||||
## Transformer-owned freshness
|
||||
|
||||
Optimus provides common services for recording and comparing dependencies, but the transformer owns the semantic definition of its recipe and freshness.
|
||||
|
||||
For the common exact-parent case, `utils.resolveArtifact()` is intentionally small:
|
||||
|
||||
```js
|
||||
const result = await utils.resolveArtifact(
|
||||
"artifacts/example/result.json",
|
||||
{
|
||||
source: sourceNode,
|
||||
recipe: recipeNode,
|
||||
},
|
||||
async () => transformation()
|
||||
);
|
||||
```
|
||||
|
||||
It:
|
||||
|
||||
1. reads the existing artifact if present;
|
||||
2. compares its complete named `sourceHash` set with the supplied sources;
|
||||
3. reuses the artifact when the source names and hashes match;
|
||||
4. otherwise runs the producer;
|
||||
5. hashes and persists the new result with its ancestry.
|
||||
|
||||
That helper expresses one useful freshness policy. It is not a declaration that every transformer in every domain must define staleness exactly this way. A transformer may use `readArtifact()`, `sameSourceHash()`, `fileNode()`, `codeNode()`, or its own domain-specific checks as needed.
|
||||
|
||||
The responsibility is simple:
|
||||
|
||||
**Before returning persisted work as current, a transformer must verify it according to the inputs and rules that actually matter to that transformation.**
|
||||
|
||||
That responsibility is intentionally broader than choosing a hash helper. Each artifact-producing transformer owns the validity, lifecycle, and cleanliness of its own artifacts. It should make freshness decisions with knowledge of the work it performs: cheap versus expensive, deterministic versus flexible/nondeterministic, local computation versus LLM or human work, and any domain-specific signs that an existing payload is unusable.
|
||||
|
||||
There is deliberately no universal Optimus staleness formula. A cheap deterministic transformer may reasonably rebuild at the first inconsistency. An expensive LLM transformer may preserve accepted semantic work across many implementation changes while still rejecting a malformed or otherwise nonviable payload and forcing a fresh call. Changes to a transformer's validity policy are semantic behavior changes and should be discussed deliberately rather than smuggled in through a refactor.
|
||||
|
||||
Named logic revisions and accepted-revision sets are one useful project-level pattern when behavior evolves. They are available tools, not framework requirements. A shared library may expose a revision identity while each consuming transformer decides which revisions it still accepts. This prevents shared code from becoming an accidental invalidation fan-out.
|
||||
|
||||
A transformer also owns cleanup of its artifact area. Durable history may be useful, but a producer should not knowingly accumulate junk artifacts that are no longer valid and are not capable of participating in the active graph.
|
||||
|
||||
## Content identity contains propagation
|
||||
|
||||
`utils.buildNode(payload, sources)` creates a content-addressed node:
|
||||
|
||||
```js
|
||||
const node = utils.buildNode(payload, {
|
||||
hebrew: hebrewNode,
|
||||
source: sourceNode,
|
||||
guidance: guidanceNode,
|
||||
});
|
||||
```
|
||||
|
||||
Result:
|
||||
A persisted JSON artifact commonly looks like:
|
||||
|
||||
```json
|
||||
{
|
||||
"artifact": "artifacts/example/result.json",
|
||||
"sourceHash": {
|
||||
"hebrew": "<hebrewNode.hash>",
|
||||
"guidance": "<guidanceNode.hash>"
|
||||
"source": "<source content hash>",
|
||||
"guidance": "<guidance content hash>"
|
||||
},
|
||||
"hash": "<hash of payload>",
|
||||
"payload": "<payload>"
|
||||
"sourceRef": {
|
||||
"source": "artifacts/source/input.json",
|
||||
"guidance": "src/process/guide.md"
|
||||
},
|
||||
"hash": "<payload content hash>",
|
||||
"payload": "<semantic result>"
|
||||
}
|
||||
```
|
||||
|
||||
Optimus does not persist or validate the node. The owning module decides where its artifacts live and when to rebuild them.
|
||||
`sourceHash` can establish freshness. `sourceRef` makes ancestry easier for humans to follow. Paths are provenance, not identity.
|
||||
|
||||
### `utils.buildBinaryNode(filePath, sources = {})`
|
||||
Children depend on parent content hashes, so a changed parent recipe does not automatically disturb the whole project:
|
||||
|
||||
Builds the binary equivalent of a transformer-node packet. The supplied path is kept as the usable binary payload locator, while `hash` is computed from the file bytes:
|
||||
|
||||
```js
|
||||
const node = utils.buildBinaryNode(resolvedCoverPath);
|
||||
```text
|
||||
parent recipe changes
|
||||
→ parent rebuilds
|
||||
→ rebuilt parent has identical content
|
||||
→ parent content hash is unchanged
|
||||
→ children can remain current
|
||||
```
|
||||
|
||||
Result:
|
||||
This behavior is particularly valuable around nondeterministic work.
|
||||
|
||||
## Expensive and nondeterministic work
|
||||
|
||||
Do not remake an expensive artifact merely to verify it when its actual recipe is unchanged.
|
||||
|
||||
A useful LLM-shaped artifact stack can be:
|
||||
|
||||
```text
|
||||
semantic inputs + formation + model settings
|
||||
↓ cheap/deterministic
|
||||
LLM recipe artifact
|
||||
↓ expensive/nondeterministic
|
||||
LLM response artifact
|
||||
↓ cheap/deterministic
|
||||
parsed / interpreted artifact
|
||||
```
|
||||
|
||||
If only the parser changes, reparse the persisted response. Do not ask the model again.
|
||||
|
||||
Cheap deterministic work does not require the same protection. If rerunning it is simpler than proving freshness, rerun it. The resulting content hash naturally stops propagation when nothing changed.
|
||||
|
||||
## Side effects are not semantic dependencies
|
||||
|
||||
Diagnostics, reasoning traces, API transcripts, timing, retries, token counts, and progress information may be useful to retain. They are not automatically semantic inputs.
|
||||
|
||||
Projects may keep operational residue in locations such as `side-effects/`, but semantic artifacts should not depend on those files merely because they exist.
|
||||
|
||||
A useful test is:
|
||||
|
||||
> Delete diagnostic side effects, request the same top-level artifact, and do not repeat expensive semantic work unless an actual artifact input changed.
|
||||
|
||||
## Named top-level artifacts
|
||||
|
||||
`settings/artifacts.json` gives humans and automation convenient roots into the pull graph:
|
||||
|
||||
```json
|
||||
{
|
||||
"sourceHash": {},
|
||||
"hash": "<SHA-256 of file bytes>",
|
||||
"payloadBin": "<filePath>"
|
||||
}
|
||||
```
|
||||
|
||||
Derived binary artifacts can name source nodes in the same way as `buildNode()`:
|
||||
|
||||
```js
|
||||
return utils.buildBinaryNode(pdfPath, {
|
||||
volume: volumeNode,
|
||||
style: styleNode,
|
||||
});
|
||||
```
|
||||
|
||||
`buildBinaryNode()` does not copy the file, interpret the path, or know what kind of binary it represents. It hashes the bytes currently at `filePath` and returns that path unchanged as `payloadBin`.
|
||||
|
||||
## Artifacts
|
||||
|
||||
`settings/artifacts.json` explicitly names the module and public builder function for each top-level artifact:
|
||||
|
||||
```json
|
||||
{
|
||||
"job.en.md": {
|
||||
"module": "unpointed-hebrew-markdown-builder",
|
||||
"builder": "buildMarkdownOutput",
|
||||
"params": ["job", "en"]
|
||||
"ruth.flavor.json": {
|
||||
"module": "translation",
|
||||
"builder": "buildFlavor",
|
||||
"params": ["ruth"]
|
||||
},
|
||||
"ruth.en.md": {
|
||||
"module": "publisher",
|
||||
"builder": "buildMarkdown",
|
||||
"params": ["ruth", "en"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Build one artifact:
|
||||
Build one named root:
|
||||
|
||||
```bash
|
||||
npx optimus --artifact job.en.md
|
||||
npx optimus --artifact ruth.en.md
|
||||
```
|
||||
|
||||
Build every declared artifact:
|
||||
Build every declared root:
|
||||
|
||||
```bash
|
||||
npx optimus
|
||||
```
|
||||
|
||||
Artifacts are logical requested outcomes. Their modules own filenames, directories, persistence, cache policy, and dependency behavior.
|
||||
A named root does not own all work below it. If multiple products depend on the same investigation artifact, they should pull the same shared artifact rather than duplicating it under whichever root happened to ask first.
|
||||
|
||||
A builder may call `utils.setArtifactOutcome("up to date")` (or another concise outcome) before returning. Optimus prints the requested artifact ID before invoking the builder and prints that outcome afterward; builders that do not report one receive the generic `completed — success` result.
|
||||
## Settings and overlays
|
||||
|
||||
## Invocation setting overlays
|
||||
`utils.getSettings(name)` reads `settings/<name>.json`.
|
||||
|
||||
Optimus loads the project defaults from direct `settings/*.json` files. Each filename remains a free-form settings name available through `utils.getSettings(name)`.
|
||||
Optimus deliberately does not understand what arbitrary project settings mean.
|
||||
|
||||
A process can layer one or more JSON overlays on top of those defaults:
|
||||
|
||||
```bash
|
||||
npx optimus --artifact psalms.en.md --setting settings/overlays/remote.json
|
||||
```
|
||||
|
||||
Multiple overlays are applied left-to-right:
|
||||
Invocation overlays can replace or extend settings for one run:
|
||||
|
||||
```bash
|
||||
npx optimus --artifact psalms.en.md \
|
||||
--setting settings/overlays/remote.json \
|
||||
--setting settings/overlays/experimental-model.json
|
||||
--setting settings/overlays/experiment.json
|
||||
```
|
||||
|
||||
An overlay is one object whose top-level keys are ordinary settings names:
|
||||
If a setting actually matters to a transformation, that transformer should include it in whatever recipe/freshness representation it uses. Unrelated settings should not become dependencies merely because they exist.
|
||||
|
||||
## Framework presentation
|
||||
|
||||
Optimus optionally reads `settings/presentation.json`. The framework recognizes two keys and ignores unrelated application-owned presentation settings:
|
||||
|
||||
```json
|
||||
{
|
||||
"llm": {
|
||||
"host": "remote-box",
|
||||
"model": "remote-model"
|
||||
}
|
||||
"showOnEnsure": false,
|
||||
"showOnBuild": true
|
||||
}
|
||||
```
|
||||
|
||||
Overlay behavior is deliberately small:
|
||||
These are the defaults even when no `presentation.json` exists.
|
||||
|
||||
- object over object: recursively overlay properties;
|
||||
- arrays: replace the previous array;
|
||||
- scalars: replace the previous value;
|
||||
- `null`: replace the previous value with `null`;
|
||||
- omitted properties: inherit the value underneath;
|
||||
- an overlay may introduce a new free-form settings name.
|
||||
`showOnEnsure` shows the artifact checks Optimus performs while walking the pull graph. This is mainly useful for troubleshooting.
|
||||
|
||||
`utils.getSettings("llm")` sees only the resulting effective settings. Modules do not know which values came from defaults versus invocation overlays.
|
||||
`showOnBuild` announces an artifact immediately after Optimus has decided that work actually needs to run. This is the useful normal view and is enabled by default.
|
||||
|
||||
Overlay paths are resolved relative to the project root unless absolute.
|
||||
Presentation is deliberately non-semantic. These settings do not participate in artifact identity, freshness, hashes, or processing generations. Applications may keep additional keys in the same settings block; Optimus only reads the keys it owns.
|
||||
|
||||
## Build-all memory behavior
|
||||
## Artifact utilities
|
||||
|
||||
`buildAll()` awaits each declared artifact sequentially and does not retain prior artifact results. Artifact builders may still return either ordinary values or Promises; the runtime remains compatible with genuinely asynchronous work such as LLM requests.
|
||||
### `utils.buildNode(payload, sources)`
|
||||
|
||||
Build a JSON/content node from a semantic payload and optional named parent nodes.
|
||||
|
||||
### `utils.buildBinaryNode(filePath, sources)`
|
||||
|
||||
Build the binary equivalent using the current file bytes as content identity.
|
||||
|
||||
### `utils.resolveArtifact(filename, sources, producer)`
|
||||
|
||||
Use the standard exact named-parent-hash freshness policy, run the producer when stale/missing, and persist the result.
|
||||
|
||||
### `utils.readArtifact(filename)`
|
||||
|
||||
Read a persisted JSON artifact, or return `null` when no usable artifact exists. This is a low-level lifecycle utility, not an alternative to ensuring a dependency owned by another transformer.
|
||||
|
||||
### `utils.sameSourceHash(node, sources)`
|
||||
|
||||
Compare a persisted node with an exact current named parent-hash set.
|
||||
|
||||
### `utils.invalidateArtifact(filename)`
|
||||
|
||||
Delete one artifact or artifact subtree. Descendants elsewhere are not proactively deleted; the next pull request discovers what actually needs rebuilding.
|
||||
|
||||
### `utils.fileNode(filename)`
|
||||
|
||||
Create a content node from authoritative file bytes.
|
||||
|
||||
### `utils.codeNode(label, value)`
|
||||
|
||||
Create a content node from a function or other code-like value when implementation itself is a meaningful recipe input.
|
||||
|
||||
### `utils.reportEnsure(label)` and `utils.reportBuild(label)`
|
||||
|
||||
Most transformers do not need these because `utils.resolveArtifact()` reports its own ensure/build decisions. A transformer with custom freshness semantics may use them so Optimus still owns console policy:
|
||||
|
||||
```js
|
||||
utils.reportEnsure("dexter/summary");
|
||||
if (needsWork) utils.reportBuild("dexter/summary");
|
||||
```
|
||||
|
||||
The transformer reports the event; Optimus decides whether the configured presentation policy makes it visible.
|
||||
|
||||
### `utils.setArtifactOutcome(message)`
|
||||
|
||||
This older top-level outcome hook remains available for compatibility and troubleshooting output when `showOnEnsure` is enabled. It is presentation state only and does not participate in freshness or identity.
|
||||
|
||||
## Human participation is allowed
|
||||
|
||||
Optimus does not require artifacts to be machine-generated.
|
||||
|
||||
A future transformer may interview a human, present an edit list for acceptance/rejection, collect manually authored guide entries, or allow a human to explicitly stamp prepared data as valid. That interaction belongs to the transformer or another module that owns the experience.
|
||||
|
||||
Optimus does not need a generic human-task system to support human-produced artifacts.
|
||||
|
||||
## What Optimus intentionally does not own
|
||||
|
||||
Optimus does not define:
|
||||
|
||||
- LLM providers or model configuration;
|
||||
- translation semantics;
|
||||
- publishing semantics;
|
||||
- generic approval workflows;
|
||||
- a universal transformer interface;
|
||||
- one-module-per-transformation architecture;
|
||||
- a central declarative DAG;
|
||||
- domain-specific artifact validity.
|
||||
|
||||
It provides services, not restrictions.
|
||||
|
||||
## Regression check
|
||||
|
||||
Optimus ships with a small smoke test:
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
The test covers module/settings behavior, artifact hashing and persistence, content-based propagation containment, targeted invalidation, overlays, binary nodes, and framework presentation defaults/reporting.
|
||||
|
||||
Project-level tests should additionally protect whatever freshness semantics their own transformers consider important.
|
||||
|
||||
## More design context
|
||||
|
||||
See:
|
||||
|
||||
- `AGENTS.md` — development philosophy and framework boundaries;
|
||||
- `docs/intentional-behavior.md` — behavior that should not be casually changed during refactors;
|
||||
- `docs/history.md` — why the current shape exists;
|
||||
- `docs/ideas.md` — possibilities deliberately left unbuilt until evidence requires them.
|
||||
|
||||
Reference in New Issue
Block a user