// AGENTIC PROGRAMMING
// Provider and council topology. No paid API call is made in this offline demo.
provider DeepSeek {
type: "deepseek";
model: "deepseek-chat";
api_key: env("DEEPSEEK_API_KEY");
}
provider OpenAI {
type: "openai";
model: "gpt-4o";
api_key: env("OPENAI_API_KEY");
}
provider Anthropic {
type: "anthropic";
model: "claude-3-5-sonnet-20241022";
api_key: env("ANTHROPIC_API_KEY");
}
provider Kimi {
type: "kimi";
model: "moonshot-v1-8k";
api_key: env("KIMI_API_KEY");
}
agent Planner {
role: "planner";
intent: "Turn the question into an evidence-backed plan";
provider: DeepSeek;
}
agent Critic {
role: "critic";
intent: "Find unsupported assumptions and failure modes";
provider: Anthropic;
}
agent Implementer {
role: "implementer";
intent: "Produce the smallest verifiable implementation";
provider: OpenAI;
}
agent Judge {
role: "judge";
intent: "Compare evidence and issue the final verdict";
provider: Kimi;
}
let council_members = ["Planner", "Critic", "Implementer", "Judge"];
let quorum_required = 3;
council ModelCouncil {
quorum: quorum_required;
members: council_members;
rules: ["cite-evidence", "critic-must-review", "three-votes-required"];
}
let question = "How should we ship a safe parser change?";
let roles = [Planner.role, Critic.role, Implementer.role, Judge.role];
let provider_types = [
DeepSeek.type,
Anthropic.type,
OpenAI.type,
Kimi.type
];
print("Question: " + question);
print("Council members: " + council_members.length);
print("Council quorum: " + quorum_required);
print("Flow: " + roles[0] + " -> " + roles[1] + " -> " + roles[2] + " -> " + roles[3]);
print("Providers: " + provider_types[0] + ", " + provider_types[1] + ", " + provider_types[2] + ", " + provider_types[3]);
Agentic: 4 providers (DeepSeek, OpenAI, Anthropic, Kimi). ModelCouncil with Planner, Critic, Implementer, Judge agents.
// AGENTIC DEVELOPMENT
// Real files and tool evidence. No loop or chain is used.
agent Architect {
role: "architect";
intent: "Define the smallest testable change";
}
agent Developer {
role: "developer";
intent: "Apply an exact atomic patch";
}
agent Reviewer {
role: "reviewer";
intent: "Inspect the real source diff and final file";
}
let allowed_tools = [
"file.write",
"file.read",
"fs.patch_apply",
"exec.output"
];
let workspace_record = Temp.dir("hudhud-agentic-dev-");
let workspace = workspace_record.path;
let source_file = workspace + "/calculator.hud";
let baseline_source = "fn add(left, right) {\n return left - right;\n}\n";
let expected_source = "fn add(left, right) {\n return left + right;\n}\n";
// Temp.dir supplies the path; no user-controlled string reaches exec.output.
file.write(source_file, baseline_source);
exec.output("git -C " + workspace + " init -q");
exec.output("git -C " + workspace + " add calculator.hud");
let patch_result = fs.patch_apply(
source_file,
"return left - right;",
"return left + right;"
);
let final_source = file.read(source_file);
let source_diff = exec.output(
"git -C " + workspace + " diff --no-ext-diff -- calculator.hud"
);
let verified = patch_result.modified
&& patch_result.replacements == 1
&& final_source == expected_source
&& source_diff.length > 0;
print("Architect: " + Architect.intent);
print("Allowlisted tools: " + allowed_tools.length);
print("Developer replacements: " + patch_result.replacements);
print("Reviewer verified:");
print(verified);
print("File: " + source_file);
print(source_diff);
Agentic Development: agents write a real source file, apply one atomic patch, verify final content, and print the real Git diff without loops or chains.
// LOOP PRIMITIVES
// Repetition, convergence, retry, done, and fail gates.
let builds = 0;
loop RepeatBuild mode: times(3) {
step build_once {
builds = builds + 1;
gate build_gate {
when true -> continue
else -> fail
}
}
}
let defects = 3;
loop FixUntilClean mode: until(defects == 0) {
step patch_once {
defects = defects - 1;
gate defect_gate {
when true -> continue
else -> fail
}
}
}
let recovery_attempts = 0;
loop BoundedRecovery {
step connect {
recovery_attempts = recovery_attempts + 1;
gate recovery_gate {
when true -> done
else -> retry
}
}
}
run loop RepeatBuild;
run loop FixUntilClean;
run loop BoundedRecovery;
print("Builds: " + builds);
print("Defects: " + defects);
print("Recovery attempts: " + recovery_attempts);
Loop: times, until, retry, done and fail gates with measured state.
// LOOP ENGINEERING
// Observe -> patch -> run again -> accept only measured evidence.
let workspace_record = Temp.dir("hudhud-loop-eng-");
let workspace = workspace_record.path;
let source_file = workspace + "/calculator.js";
let broken_source = "function add(left, right) {\n return left - right;\n}\nconsole.log(add(2, 3));\n";
let fixed_source = "function add(left, right) {\n return left + right;\n}\nconsole.log(add(2, 3));\n";
let expected_output = "5\n";
file.write(source_file, broken_source);
exec.output("git -C " + workspace + " init -q");
exec.output("git -C " + workspace + " add calculator.js");
let attempts = 0;
let test_runs = 0;
let failures = 1;
let replacements = 0;
loop RepairAndRetest goal(target: failures == 0) {
step observe_patch_verify {
attempts = attempts + 1;
test_runs = test_runs + 1;
let failing_output = exec.output("node " + source_file);
let patch_result = fs.patch_apply(
source_file,
"return left - right;",
"return left + right;"
);
replacements = replacements + patch_result.replacements;
test_runs = test_runs + 1;
let passing_output = exec.output("node " + source_file);
failures = passing_output.length - expected_output.length;
print("Before patch: " + failing_output);
print("After patch: " + passing_output);
gate evidence_gate {
when failures == 0 -> done
else -> fail
}
}
}
run loop RepairAndRetest;
let final_source = file.read(source_file);
let final_output = exec.output("node " + source_file);
let source_diff = exec.output(
"git -C " + workspace + " diff --no-ext-diff -- calculator.js"
);
let verified = final_source == fixed_source
&& final_output.length == expected_output.length
&& source_diff.length > 0;
print("Attempts: " + attempts);
print("Test runs: " + test_runs);
print("Patch replacements: " + replacements);
print("Final program output: " + final_output);
print("Verified:");
print(verified);
print(source_diff);
chain ProductDelivery {
loop Scope {
step write_specification {
let stage = Temp.dir("hudhud-scope-");
let spec_file = stage.path + "/requirements.md";
let spec = "# Calculator\n\n- add(left, right)\n- output must be 5\n";
file.write(spec_file, spec);
result.bytes = file.read(spec_file).length;
print("Specification bytes: " + result.bytes);
gate scope_gate {
when result.bytes == spec.length -> done
else -> fail
}
}
}
on_done: next
on_fail: fail
loop Build {
step generate_and_execute {
let stage = Temp.dir("hudhud-build-");
let app_file = stage.path + "/app.js";
file.write(app_file, "console.log(2 + 3);\n");
result.output = exec.output("node " + app_file);
print("Build output: " + result.output);
gate build_gate {
when result.output.length == 2 -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop Review {
step inspect_real_diff {
let stage = Temp.dir("hudhud-review-");
let app_file = stage.path + "/app.js";
file.write(app_file, "console.log(2 - 3);\n");
exec.output("git -C " + stage.path + " init -q");
exec.output("git -C " + stage.path + " add app.js");
let patch_result = fs.patch_apply(app_file, "2 - 3", "2 + 3");
result.diff = exec.output(
"git -C " + stage.path + " diff --no-ext-diff -- app.js"
);
print(result.diff);
gate review_gate {
when patch_result.replacements == 1
&& result.diff.length > 0 -> done
else -> fail
}
}
}
on_done: next
on_fail: fail
loop Publish {
step publish_artifact {
let release = Temp.dir("hudhud-publish-");
let artifact = release.path + "/calculator.js";
file.write(artifact, "console.log(2 + 3);\n");
result.output = exec.output("node " + artifact);
result.artifact = artifact;
print("Published: " + result.artifact);
gate publish_gate {
when result.output.length == 2
&& file.exists(result.artifact) -> done
else -> fail
}
}
}
on_done: done
on_fail: fail
}
run chain ProductDelivery;
Runs broken generated code, patches the real file, reruns the test, verifies output, and prints the source diff.
// LOOPCHAIN
// Every delivery stage leaves real file, execution, patch, or diff evidence.
chain DeliveryPipeline {
loop Plan {
step write_plan {
let stage = Temp.dir("hudhud-plan-");
let plan_file = stage.path + "/plan.md";
let plan = "# Plan\n1. Generate code\n2. Run tests\n3. Review diff\n";
file.write(plan_file, plan);
result.bytes = file.read(plan_file).length;
print("Plan: " + plan_file);
gate plan_gate {
when result.bytes == plan.length -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop Build {
step generate_program {
let stage = Temp.dir("hudhud-compile-");
let app_file = stage.path + "/app.js";
file.write(app_file, "console.log(['lexer', 'parser', 'vm'].length);\n");
result.output = exec.output("node " + app_file);
print("Compiled module count: " + result.output);
gate build_gate {
when result.output.length == 2 -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop UnitTest {
step run_generated_test {
let stage = Temp.dir("hudhud-unit-");
let test_file = stage.path + "/unit.js";
file.write(
test_file,
"const checks = [2 + 3 === 5, 3 * 3 === 9, 8 / 2 === 4];\nconsole.log(checks.filter(Boolean).length);\n"
);
result.passed = exec.output("node " + test_file);
print("Unit tests passed: " + result.passed);
gate unit_gate {
when result.passed.length == 2 -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop IntegrationTest {
step test_contract {
let stage = Temp.dir("hudhud-integration-");
let contract_file = stage.path + "/contract.js";
file.write(
contract_file,
"const response = {status: 200, body: {ready: true}};\nconsole.log(response.status === 200 && response.body.ready);\n"
);
result.output = exec.output("node " + contract_file);
print("Integration contract: " + result.output);
gate integration_gate {
when result.output.length == 5 -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop Review {
step patch_and_show_diff {
let stage = Temp.dir("hudhud-diff-");
let app_file = stage.path + "/app.js";
file.write(app_file, "const timeout = 5;\nconsole.log(timeout);\n");
exec.output("git -C " + stage.path + " init -q");
exec.output("git -C " + stage.path + " add app.js");
let patch_result = fs.patch_apply(
app_file,
"const timeout = 5;",
"const timeout = 30;"
);
result.diff = exec.output(
"git -C " + stage.path + " diff --no-ext-diff -- app.js"
);
print(result.diff);
gate review_gate {
when patch_result.replacements == 1
&& result.diff.length > 0 -> done
else -> fail
}
}
}
on_done: next
on_fail: fail
loop Deploy {
step deploy_and_probe {
let release = Temp.dir("hudhud-deploy-");
let artifact = release.path + "/app.js";
file.write(artifact, "console.log('healthy');\n");
result.health = exec.output("node " + artifact);
print("Deployed artifact: " + artifact);
print("Health probe: " + result.health);
gate deploy_gate {
when file.exists(artifact)
&& result.health.length == 8 -> done
else -> fail
}
}
}
on_done: done
on_fail: fail
}
run chain DeliveryPipeline;
Plan, build, unit, integration, review, and deploy stages produce real files, executions, patches, and diffs.
// MULTICHAIN SOFTWARE FACTORY
// Discovery, Build, and Git Release have independent failure boundaries.
chain DiscoveryChain {
loop Requirements {
step write_requirements {
let stage = Temp.dir("hudhud-discovery-");
let requirements_file = stage.path + "/requirements.json";
let requirements = Web.json({
stories: ["auth", "billing", "audit"],
acceptance: "all tests green"
});
file.write(requirements_file, requirements.body);
result.bytes = file.read(requirements_file).length;
print("Requirements: " + requirements_file);
gate requirements_gate {
when result.bytes > 0 -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop Architecture {
step write_threat_model {
let stage = Temp.dir("hudhud-architecture-");
let threat_file = stage.path + "/threats.md";
let threats = "- secret leak\n- path traversal\n- process spawn\n";
file.write(threat_file, threats);
result.bytes = file.read(threat_file).length;
print("Threat model bytes: " + result.bytes);
gate architecture_gate {
when result.bytes == threats.length -> done
else -> fail
}
}
}
on_done: done
on_fail: fail
}
chain BuildChain {
loop Implementation {
step generate_patch_and_diff {
let stage = Temp.dir("hudhud-implementation-");
let app_file = stage.path + "/app.js";
file.write(app_file, "console.log('not-ready');\n");
exec.output("git -C " + stage.path + " init -q");
exec.output("git -C " + stage.path + " add app.js");
let patch_result = fs.patch_apply(
app_file,
"'not-ready'",
"'ready'"
);
result.diff = exec.output(
"git -C " + stage.path + " diff --no-ext-diff -- app.js"
);
result.output = exec.output("node " + app_file);
print(result.diff);
gate implementation_gate {
when patch_result.replacements == 1
&& result.output.length == 6
&& result.diff.length > 0 -> done
else -> retry
}
}
}
on_done: next
on_fail: fail
loop Integration {
step run_integration_suite {
let stage = Temp.dir("hudhud-build-integration-");
let suite_file = stage.path + "/integration.js";
file.write(
suite_file,
"const services = ['database', 'queue', 'http'];\nconsole.log(services.length);\n"
);
result.passed = exec.output("node " + suite_file);
print("Integration checks passed: " + result.passed);
gate integration_gate {
when result.passed.length == 2 -> done
else -> retry
}
}
}
on_done: done
on_fail: fail
}
chain ReleaseChain {
loop Approval {
step count_votes {
let votes = [1, 1, 0, 1];
let approvals = votes[0] + votes[1] + votes[2] + votes[3];
result.approvals = approvals;
result.total = votes.length;
print("Release approval: " + result.approvals + "/" + result.total);
gate approval_gate {
when result.approvals >= 3 -> done
else -> fail
}
}
}
on_done: next
on_fail: fail
loop Deploy {
step push_to_git_remote {
let work = Temp.dir("hudhud-release-work-");
let remote = Temp.dir("hudhud-release-remote-");
let artifact = work.path + "/app.js";
exec.output("git -C " + work.path + " init -q -b main");
exec.output("git -C " + work.path + " config user.name HudHudRelease");
exec.output(
"git -C " + work.path + " config user.email release@hudhud.local"
);
file.write(artifact, "console.log('release-0.7.358');\n");
exec.output("git -C " + work.path + " add app.js");
exec.output(
"git -c core.hooksPath=/dev/null -C "
+ work.path
+ " commit -qm release-0.7.358"
);
exec.output("git init --bare -q " + remote.path);
exec.output(
"git -C "
+ work.path
+ " remote add deploy "
+ remote.path
);
exec.output("git -C " + work.path + " push -q deploy main");
let local_revision = exec.output(
"git -C " + work.path + " rev-parse HEAD"
);
let deployed_revision = exec.output(
"git --git-dir="
+ remote.path
+ " rev-parse refs/heads/main"
);
result.deployed = local_revision == deployed_revision;
result.revision = local_revision.substring(0, 12);
print("Git deployed revision: " + result.revision);
gate deploy_gate {
when result.deployed -> done
else -> fail
}
}
}
on_done: done
on_fail: fail
}
run chain DiscoveryChain;
run chain BuildChain;
run chain ReleaseChain;
Independent Discovery, Build, and Release chains end with a real commit pushed to a temporary Git remote.
// GOVERNANCE AS LANGUAGE PRIMITIVES
// Constitution -> laws -> rules -> subjects -> council -> swarm -> community.
law ProtectSecrets {
description: "Credentials and private data must never enter output";
enforcement: mandatory;
rules: ["redact-secrets", "deny-credential-export"];
}
law AuthorizeEffects {
description: "Network, MCP, process, and publish actions require approval";
enforcement: mandatory;
rules: ["capability-check", "human-approval-for-publish"];
}
law RequireEvidence {
description: "A release decision must include test evidence";
enforcement: mandatory;
rules: ["tests-pass", "three-votes-required"];
}
constitution TrustedDelivery {
description: "Policy for governed software delivery";
laws: [
{ name: "ProtectSecrets", enforcement: "mandatory" },
{ name: "AuthorizeEffects", enforcement: "mandatory" },
{ name: "RequireEvidence", enforcement: "mandatory" }
];
}
rule ReleaseQuorum {
description: "At least three of four reviewers must approve";
threshold: 3;
action: "release";
}
role Judge { can review, can vote }
role Auditor { can inspect, can report }
role Executor { can stage, can publish }
subject LegalReviewer has Judge {
state vote: true;
on review(self, proposal) { self.vote = proposal != ""; }
on vote(self) { return self.vote; }
}
subject SecurityAuditor has Auditor {
state vote: true;
on inspect(self, evidence) { self.vote = evidence == "tests-pass"; }
on report(self) { return self.vote; }
}
subject ReleaseOperator has Executor {
state staged: false;
state published: false;
on stage(self) { self.staged = true; }
on publish(self) { self.published = self.staged; }
}
let council_members = ["LegalReviewer", "SecurityAuditor", "ReleaseOperator", "HumanOwner"];
let quorum_required = 3;
let community_councils = ["ReleaseCouncil"];
council ReleaseCouncil {
constitution: "TrustedDelivery";
quorum: quorum_required;
members: council_members;
rules: ["ReleaseQuorum", "RequireEvidence"];
}
swarm AuditSwarm {
agents: ["LegalReviewer", "SecurityAuditor"];
strategy: "parallel";
}
community DeliveryCommunity {
councils: community_councils;
members: council_members;
}
let votes = [true, true, true, false];
let approvals = 0;
let i = 0;
while (i < votes.length) {
if (votes[i]) {
approvals = approvals + 1;
}
i = i + 1;
}
let approved = approvals >= quorum_required;
print("Constitution: " + TrustedDelivery.description);
print("Laws: " + TrustedDelivery.laws.length);
print("Council members: " + council_members.length);
print("Council quorum: " + quorum_required);
print("Approvals: " + approvals);
print("Release approved:");
print(approved);
print("Audit strategy: " + AuditSwarm.strategy);
print("Community councils: " + community_councils.length);
print("Community members: " + council_members.length);
Constitution, laws, rules, role-bearing subjects, council quorum, swarm and community.
// TOKENOMICS
// Cost-aware iteration using runtime session measurements.
let initial_cost = tokenomics.session_cost();
let budget_health = tokenomics.budget_health();
let tasks = ["validate", "transform", "export"];
let completed = 0;
let i = 0;
while (i < tasks.length) {
let current_cost = tokenomics.session_cost();
if (current_cost > 1.0) {
break;
}
completed = completed + 1;
i = i + 1;
}
let final_cost = tokenomics.session_cost();
print("Initial cost: " + initial_cost);
print("Budget health: " + budget_health);
print("Tasks available: " + tasks.length);
print("Tasks completed: " + completed);
print("Final cost: " + final_cost);
Tokenomics: session_cost(), budget_health(). Cost-aware autonomous loops with budget-threshold break.
// MODEL CONTEXT PROTOCOL
// The offline sample models the same typed server/tool manifest without
// starting a process. Live `mcp` declarations require sandbox permission.
let workspace = {
name: "Workspace",
transport: "stdio",
command: "npx",
tools: [
{ name: "read_file", input: "path:string" },
{ name: "write_file", input: "path:string,content:string" }
]
};
let issue_tracker = {
name: "IssueTracker",
transport: "sse",
url: "http://127.0.0.1:8081/mcp",
tools: [
{ name: "get_issue", input: "id:string" }
]
};
let servers = [workspace, issue_tracker];
let tool_count = workspace.tools.length + issue_tracker.tools.length;
agent Maintainer {
role: "maintainer";
intent: "Inspect source, implement a patch, and update its issue";
}
print("Servers: " + servers.length);
print("Tools: " + tool_count);
print("Workspace transport: " + workspace.transport);
print("Issue tracker transport: " + issue_tracker.transport);
print("Agent role: " + Maintainer.role);
// Live syntax, intentionally not executed by the public website:
// mcp Workspace {
// transport: "stdio";
// command: "npx";
// tool read_file(path: string) { return path; }
// }
Safe offline server and tool manifest; live declarations remain sandbox-gated.
// WEB RUNTIME
// Response builders and route matching without starting an infinite server loop.
let html = Web.html("<h1>HudHudScript</h1>", 200);
let json = Web.json({ name: "HudHud", active: true }, 200);
print("HTML status: " + html.status);
print("JSON content type: " + json.content_type);
// Live mode:
// let app = Web.serve({ host: "127.0.0.1", port: 8080, reuse_port: true });
// let request = Web.accept(app);
// Web.respond(request, html);
Real HTML and JSON response builders without an infinite server loop.
// TERMINAL UI
// Uses ratatui on a real terminal and the same state model in headless runners.
use tui;
let active_agents = 4;
let completed_tasks = 3;
let total_tasks = 5;
let progress = completed_tasks * 100 / total_tasks;
let agents = [
"planner: done",
"builder: active",
"reviewer: waiting",
"judge: waiting"
];
let interactive = Terminal.isatty();
if (interactive) {
tui.init();
tui.block({
title: "HudHudScript Agent Monitor",
borders: "all",
area: { x: 0, y: 0, width: 48, height: 3 }
});
tui.paragraph({
text: "Agents: " + active_agents + " | Tasks: " + completed_tasks + "/" + total_tasks,
style: { fg: "green", bold: 1 },
area: { x: 1, y: 1, width: 46, height: 1 }
});
tui.list({
items: agents,
area: { x: 0, y: 4, width: 48, height: 5 }
});
tui.gauge({
value: progress,
max: 100,
label: "Pipeline Progress",
style: { fg: "cyan" },
area: { x: 0, y: 10, width: 48, height: 1 }
});
tui.draw();
let event = tui.poll_event(2000);
tui.restore();
} else {
print("HudHudScript Agent Monitor");
print("Agents: " + active_agents + " | Tasks: " + completed_tasks + "/" + total_tasks);
print(agents);
}
print("Completed tasks: " + completed_tasks);
print("Progress: " + progress);
TTY-aware TUI: renders block, paragraph, list, and gauge widgets in a terminal; uses the same state model for safe headless output in web runners.
// OBJECT-ORIENTED PROGRAMMING
// Private/protected members, constructors, super, inheritance,
// method overriding, traits, and fluent method chaining.
trait Describable {
function describe();
}
class Account implements Describable {
private let balance = 0;
protected let owner = "";
constructor(owner, opening_balance) {
this.owner = owner;
this.balance = opening_balance;
}
private normalize(amount) {
if (amount < 0) {
return 0;
}
return amount;
}
protected apply_bonus(rate) {
this.balance = this.balance + (this.balance * rate);
}
public deposit(amount) {
let safe_amount = this.normalize(amount);
this.balance = this.balance + safe_amount;
return this;
}
public value() {
return this.balance;
}
public describe() {
return this.owner + " account";
}
}
class SavingsAccount extends Account implements Describable {
constructor(owner, opening_balance) {
super(owner, opening_balance);
}
public grow(rate) {
this.apply_bonus(rate);
return this;
}
public describe() {
return "Savings: " + this.owner;
}
}
let account = new SavingsAccount("Ada", 100);
account.deposit(50).grow(0.10);
let final_balance = account.value();
let label = account.describe();
print("Description: " + label);
print("Balance: " + final_balance);
Private and protected members, constructors, super, inheritance, traits, overriding and fluent chaining.
// SUBJECT-ORIENTED PROGRAMMING
// Fantasy combat composed from roles, subjects, a view, effects, and relations.
role Fighter { can attack, can defend }
role Caster { can cast, can channel }
role Bearer { can wield, can resist }
subject Knight has Fighter {
state health: 120;
state power: 25;
on attack(self) {
let amount = PhysicalDamage(self.power);
self.mark_hit(amount);
return amount;
}
on defend(self) {
self.health = self.health + 5;
}
}
subject KnightLog of Knight {
state hits: 0;
state damage_dealt: 0;
on mark_hit(self, amount) {
self.hits = self.hits + 1;
self.damage_dealt = self.damage_dealt + amount;
}
}
subject Mage has Caster {
state mana: 100;
state power: 40;
on cast(self) {
self.mana = self.mana - 15;
return MagicalDamage(self.power + 10);
}
on channel(self) {
self.mana = self.mana + 20;
}
}
subject RingBearer has Bearer {
state health: 90;
state resolve: 30;
on wield(self) {
self.resolve = self.resolve - 5;
return MagicalDamage(35);
}
on resist(self) {
self.resolve = self.resolve + 10;
}
}
subject Wraith has Fighter {
state health: 150;
state power: 20;
on attack(self) {
return PhysicalDamage(self.power);
}
on defend(self) {
self.health = self.health + 5;
}
}
effect on PhysicalDamage(amount) {
return amount;
}
effect on MagicalDamage(amount) {
return amount;
}
compose Knight {
on attack: combine [KnightLog]
}
relation Knight <-> RingBearer { loyalty: 90 }
relation RingBearer <-> Wraith { hostility: 100 }
let knight = spawn Knight;
let mage = spawn Mage;
let bearer = spawn RingBearer;
let wraith = spawn Wraith;
let fellowship = get_relation(knight, bearer);
let enemy = get_relation(bearer, wraith);
knight.attack();
mage.cast();
bearer.wield();
wraith.attack();
let knight_damage = knight.power;
let mage_damage = mage.power + 10;
let bearer_damage = 35;
let wraith_damage = wraith.power;
let wraith_remaining = wraith.health - knight_damage - mage_damage - bearer_damage;
let bearer_remaining = bearer.health - wraith_damage;
print("Knight hits: " + knight.hits);
print("Knight damage: " + knight.damage_dealt);
print("Mage mana: " + mage.mana);
print("Bearer health: " + bearer_remaining);
print("Bearer resolve: " + bearer.resolve);
print("Loyalty: " + fellowship.loyalty);
print("Hostility: " + enemy.hostility);
print("Wraith health: " + wraith_remaining);
SOP: roles, subjects, view composition, relations and stateful fantasy combat.
Visual: Drag nodes to rearrange. provider → council → agent → tasks → tools. n8n-style.