Own retained Eve Ink playback sidecar

This commit is contained in:
Meta Vens 2026-07-10 07:27:53 +01:00
commit 826200184c
9 changed files with 321 additions and 1 deletions

View file

@ -154,6 +154,9 @@ future renderers can consume the same tree and send back `story.*` or
See [docs/eve.md](docs/eve.md).
Sai also publishes a retained Ink playback sidecar for runtime-independent Eve
clients. See [docs/eve-sidecar.md](docs/eve-sidecar.md).
## Development
```powershell

28
docs/eve-sidecar.md Normal file
View file

@ -0,0 +1,28 @@
# Sai Eve Sidecar
Sai owns retained Ink playback sessions behind the Eve plugin ABI. The sidecar
loads compiled Ink with `inkjs`, applies story commands, and projects the live
session through Sai's `gamecult.eve.surface.v1` module.
The sidecar does not render a runtime, accept provider commands on a provider's
behalf, or execute Norn or TeX semantics. It advertises `norn.graph` and
`tex.math` only as independent optional nested plugins.
## Transport
`src/eve-sidecar.cjs` is a long-running NDJSON process. Each input line is a
`gamecult.eve.plugin_abi.request.v1`; each output line is the correlated
`gamecult.eve.plugin_abi.response.v1`.
The retained operations are:
- `open`: create or replace a named Ink session and advance it to its first line.
- `apply`: apply `story.continue`, `story.choose`, or `story.jump` to that session.
- `project`: derive a Sai Eve surface from current session state.
- `describe`: report the sidecar's owned and optional capabilities.
Run the owner-side conformance witness with:
```powershell
powershell -ExecutionPolicy Bypass -File scripts/run-eve-plugin-witness.ps1
```

View file

@ -8,6 +8,7 @@
"dist",
"src",
"docs",
"plugins",
"examples",
"scripts",
"README.md",
@ -20,13 +21,19 @@
"./eve.js": "./dist/eve.js",
"./ink.js": "./dist/ink.js"
},
"bin": {
"sai-eve-sidecar": "./src/eve-sidecar.cjs"
},
"scripts": {
"build": "node scripts/build.mjs",
"check": "node scripts/check.mjs",
"check:eve-plugin": "powershell -ExecutionPolicy Bypass -File scripts/run-eve-plugin-witness.ps1",
"compile:example": "inkjs-compiler examples/static-site/story.ink -o examples/static-site/story.ink.json"
},
"dependencies": {
"inkjs": "^2.4.0"
},
"devDependencies": {
"inkjs": "^2.4.0",
"prettier": "^3.5.3"
},
"keywords": [

View file

@ -0,0 +1,55 @@
{
"schema": "gamecult.eve.plugin_abi_fixture.v1",
"fixtureId": "sai-vn-live-playback",
"pluginId": "sai.vn",
"ownerRepo": "Sai",
"contract": "gamecult.eve.plugin_abi.v1",
"requestSchema": "gamecult.eve.plugin_abi.request.v1",
"responseSchema": "gamecult.eve.plugin_abi.response.v1",
"operations": [
{
"operation": "describe",
"expect": {
"sessionAuthority": "sai-sidecar",
"optionalPlugins": ["norn.graph", "tex.math"]
}
},
{
"operation": "open",
"input": { "sessionId": "witness", "storyId": "sai-example", "storyPath": "examples/static-site/story.ink.json" },
"expect": {
"sessionId": "witness",
"line": "Ink is not alive by itself. A page gives it a body.",
"revision": 0
}
},
{
"operation": "apply",
"input": { "sessionId": "witness", "command": "story.choose", "index": 0 },
"expect": {
"line": "Then the story should feel like it belongs here, not like a widget escaped from somewhere else.",
"revision": 1,
"command": "story.choose"
}
},
{
"operation": "project",
"input": { "sessionId": "witness", "providerId": "sai.witness" },
"expect": {
"projectionKind": "semantic-surface",
"delegatedPlugins": ["norn.graph", "tex.math"],
"sessionId": "witness",
"revision": 1
}
},
{
"operation": "apply",
"input": { "sessionId": "witness", "command": "story.jump", "targetPath": "gather" },
"expect": {
"line": "Good. The brush moves. The scene answers.",
"revision": 2,
"command": "story.jump"
}
}
]
}

View file

@ -0,0 +1,23 @@
{
"schema": "gamecult.eve.plugin_advertisement.v1",
"pluginId": "sai.vn",
"ownerService": "sai",
"version": "0.1.0",
"manifestAddress": "file://plugins/sai-vn.plugin.json",
"runtime": {
"invocationModel": "executable-sidecar",
"contract": "gamecult.eve.plugin_abi.v1",
"transports": ["stdio"],
"sidecar": {
"processKind": "long-running-daemon",
"protocol": "stdio-ndjson",
"requestSchema": "gamecult.eve.plugin_abi.request.v1",
"responseSchema": "gamecult.eve.plugin_abi.response.v1",
"operations": ["describe", "open", "apply", "project"],
"launch": { "command": "node", "artifact": "src/eve-sidecar.cjs" },
"stateAuthority": "sai-sidecar-owns-story-session-provider-owns-command-acceptance"
}
},
"componentKinds": ["vn.stage", "panel.dialogue", "text.dialogue", "rail.actions"],
"commands": ["story.continue", "story.choose", "story.jump"]
}

View file

@ -0,0 +1,31 @@
{
"schema": "gamecult.eve.plugin.v1",
"pluginId": "sai.vn",
"title": "Sai Visual Novel",
"owner": "Sai",
"componentKinds": ["vn.stage", "panel.dialogue", "text.dialogue", "rail.actions"],
"commands": [
{ "command": "story.continue", "schema": "sai.vn.story_command.v1", "effect": "advance-story" },
{ "command": "story.choose", "schema": "sai.vn.story_command.v1", "effect": "choose-branch" },
{ "command": "story.jump", "schema": "sai.vn.story_command.v1", "effect": "jump-to-knot" }
],
"runtime": {
"invocationModel": "executable-sidecar",
"contract": "gamecult.eve.plugin_abi.v1",
"transports": ["stdio"],
"sidecar": {
"processKind": "long-running-daemon",
"protocol": "stdio-ndjson",
"operations": ["describe", "open", "apply", "project"],
"stateAuthority": "sai-sidecar-owns-story-session-provider-owns-command-acceptance"
}
},
"stateSchemas": ["sai.vn.story_session.v1", "sai.vn.visual_manifest.v1"],
"capabilities": {
"requires": ["vn.stage", "story.choose", "story.continue", "story.jump"],
"optionalPlugins": [
{ "pluginId": "norn.graph", "relationship": "optional-nested-composition" },
{ "pluginId": "tex.math", "relationship": "optional-nested-composition" }
]
}
}

View file

@ -8,6 +8,10 @@ const required = [
"dist/eve.js",
"examples/static-site/index.html",
"docs/manifest.md",
"plugins/sai-vn.plugin.json",
"plugins/sai-vn.plugin-advertisement.json",
"plugins/sai-vn.plugin-abi-fixture.json",
"src/eve-sidecar.cjs",
];
for (const file of required) {

View file

@ -0,0 +1,22 @@
param(
[string] $EveRoot = "E:\Projects\Eve",
[string] $OutputPath = "artifacts\eve-plugin\runtime-witness.json",
[string] $NodePath = "node"
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$output = if ([IO.Path]::IsPathRooted($OutputPath)) { $OutputPath } else { Join-Path $repoRoot $OutputPath }
$launcher = Join-Path $EveRoot "tools\plugins\run-sidecar-witness.mjs"
& $NodePath $launcher `
--advertisement (Join-Path $repoRoot "plugins\sai-vn.plugin-advertisement.json") `
--fixture (Join-Path $repoRoot "plugins\sai-vn.plugin-abi-fixture.json") `
--output $output `
--witness-id "sai.vn.owner-sidecar" `
--cwd $repoRoot `
--command $NodePath `
-- "src/eve-sidecar.cjs"
if ($LASTEXITCODE -ne 0) { throw "Sai Eve plugin witness failed with exit code $LASTEXITCODE" }
Write-Host "Sai Eve plugin witness: $output"

147
src/eve-sidecar.cjs Normal file
View file

@ -0,0 +1,147 @@
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const readline = require("node:readline");
const { Story } = require("inkjs");
const SaiEve = require("./eve.js");
const sessions = new Map();
const pluginId = "sai.vn";
const operations = ["describe", "open", "apply", "project"];
readline.createInterface({ input: process.stdin }).on("line", (line) => {
if (!line.trim()) return;
let request;
try {
request = JSON.parse(line.replace(/^\uFEFF/, ""));
respond(request, dispatch(request));
} catch (error) {
respond(request, {}, "rejected", error.message);
}
});
function dispatch(request) {
if (request?.schema !== "gamecult.eve.plugin_abi.request.v1") throw new Error("Unsupported request schema.");
if (request.pluginId !== pluginId) throw new Error(`Expected plugin ${pluginId}.`);
if (!operations.includes(request.operation)) throw new Error(`Unsupported operation ${request.operation}.`);
if (request.operation === "describe") return describe();
if (request.operation === "open") return openSession(request.input);
if (request.operation === "apply") return applyCommand(request.input);
return projectSession(request.input);
}
function describe() {
return {
pluginId,
componentKinds: ["vn.stage", "panel.dialogue", "text.dialogue", "rail.actions"],
commands: ["story.continue", "story.choose", "story.jump"],
capabilities: ["vn.stage", "story.choose", "story.continue", "story.jump"],
operations,
optionalPlugins: ["norn.graph", "tex.math"],
sessionAuthority: "sai-sidecar",
};
}
function openSession(input) {
const sessionId = requiredString(input.sessionId, "sessionId");
const storyPath = path.resolve(process.cwd(), requiredString(input.storyPath, "storyPath"));
const story = new Story(parseJson(fs.readFileSync(storyPath, "utf8")));
const session = { sessionId, storyId: input.storyId || path.basename(storyPath, ".ink.json"), story, revision: 0, line: "", tags: [] };
sessions.set(sessionId, session);
advance(session);
return snapshot(session);
}
function applyCommand(input) {
const session = getSession(input.sessionId);
const command = requiredString(input.command, "command");
if (command === "story.continue") {
advance(session);
} else if (command === "story.choose") {
const index = Number(input.index);
if (!Number.isInteger(index) || index < 0 || index >= session.story.currentChoices.length) throw new Error("Choice index is unavailable.");
session.story.ChooseChoiceIndex(index);
advance(session);
} else if (command === "story.jump") {
session.story.ChoosePathString(requiredString(input.targetPath, "targetPath"));
advance(session);
} else {
throw new Error(`Unsupported Sai command ${command}.`);
}
session.revision += 1;
return { ...snapshot(session), command, receiptSchema: "gamecult.eve.command_receipt.v1" };
}
function projectSession(input) {
const session = getSession(input.sessionId);
return {
projectionKind: "semantic-surface",
ownedComponentKinds: ["vn.stage", "panel.dialogue", "text.dialogue", "rail.actions"],
delegatedPlugins: ["norn.graph", "tex.math"],
surface: SaiEve.createVisualNovelSurface({
providerId: input.providerId || pluginId,
storyId: session.storyId,
version: session.revision + 1,
metadata: tagMap(session.tags),
speaker: tagMap(session.tags).speaker,
line: session.line,
choices: choices(session.story),
}),
...snapshot(session),
};
}
function advance(session) {
session.line = "";
session.tags = [];
while (session.story.canContinue && !session.line) {
session.line = session.story.Continue().trim();
session.tags = [...session.story.currentTags];
}
}
function snapshot(session) {
return {
sessionId: session.sessionId,
storyId: session.storyId,
revision: session.revision,
line: session.line,
choices: choices(session.story),
canContinue: session.story.canContinue,
currentTags: session.tags,
};
}
function choices(story) {
return story.currentChoices.map((choice, index) => ({ index, text: choice.text.trim(), targetPath: choice.targetPath }));
}
function tagMap(tags) {
return Object.fromEntries(tags.map((tag) => tag.split(/:\s*/, 2)).filter((parts) => parts.length === 2));
}
function getSession(sessionId) {
const session = sessions.get(requiredString(sessionId, "sessionId"));
if (!session) throw new Error(`Unknown Sai session ${sessionId}.`);
return session;
}
function requiredString(value, field) {
if (typeof value !== "string" || !value.trim()) throw new Error(`${field} is required.`);
return value;
}
function parseJson(value) { return JSON.parse(value.replace(/^\uFEFF/, "")); }
function respond(request, output, status = "accepted", message) {
process.stdout.write(`${JSON.stringify({
schema: "gamecult.eve.plugin_abi.response.v1",
pluginId,
operation: request?.operation || "unknown",
requestId: request?.requestId || "unknown",
status,
output,
...(message ? { diagnostics: [{ message }] } : {}),
})}\n`);
}