@mostra/runtime 0.7.0 → 0.8.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.
- package/dist/bin.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{instance-CYPYPCIb.js → instance-BRfg27Rg.js} +134 -45
- package/dist/instance-BRfg27Rg.js.map +1 -0
- package/package.json +5 -5
- package/src/live/index.ts +14 -1
- package/src/publish/publisher.ts +77 -44
- package/src/publish/scaffold.ts +82 -0
- package/dist/instance-CYPYPCIb.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as uninstallService, i as serviceStatus, n as startInstance, o as checkPlatform, r as installService, s as resolveHomePath, t as runtimeVersion } from "./instance-
|
|
2
|
+
import { a as uninstallService, i as serviceStatus, n as startInstance, o as checkPlatform, r as installService, s as resolveHomePath, t as runtimeVersion } from "./instance-BRfg27Rg.js";
|
|
3
3
|
import { s as realPath } from "./files-FygSJIzK.js";
|
|
4
4
|
import { mkdirSync } from "node:fs";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as startInstance, t as runtimeVersion } from "./instance-
|
|
1
|
+
import { n as startInstance, t as runtimeVersion } from "./instance-BRfg27Rg.js";
|
|
2
2
|
import { t as connectToSupervisor } from "./child-Chiavhdx.js";
|
|
3
3
|
export { connectToSupervisor, runtimeVersion, startInstance };
|
|
@@ -11925,7 +11925,15 @@ function createLive(options) {
|
|
|
11925
11925
|
try {
|
|
11926
11926
|
const handle = await pool.acquire(version);
|
|
11927
11927
|
described.set(versionId, handle.started.live);
|
|
11928
|
-
|
|
11928
|
+
const source = handle.started.live.find((info) => info.key === key);
|
|
11929
|
+
if (!source) return;
|
|
11930
|
+
if (source.load === false) bus.publishLive(artifactId, {
|
|
11931
|
+
kind: "live",
|
|
11932
|
+
live: {
|
|
11933
|
+
key,
|
|
11934
|
+
awaiting: false
|
|
11935
|
+
}
|
|
11936
|
+
});
|
|
11929
11937
|
running.set(id, {
|
|
11930
11938
|
artifactId,
|
|
11931
11939
|
key,
|
|
@@ -12006,6 +12014,8 @@ function createLive(options) {
|
|
|
12006
12014
|
const stateOf = (db, artifactId, key, window) => {
|
|
12007
12015
|
const row = db.get("SELECT revision, value_json, at FROM live_value WHERE artifact_id = ? AND key = ?", artifactId, key);
|
|
12008
12016
|
const failure = failures.get(keyOf(artifactId, key));
|
|
12017
|
+
const latest = options.latest(artifactId);
|
|
12018
|
+
const producing = latest?.sources.some((source) => source.key === key) === true && (described.get(latest.versionId)?.find((source) => source.key === key)?.load ?? true);
|
|
12009
12019
|
const ring = window === void 0 ? void 0 : db.all("SELECT revision, value_json, at FROM live_ring WHERE artifact_id = ? AND key = ? ORDER BY revision DESC LIMIT ?", artifactId, key, window).reverse().map((entry) => ({
|
|
12010
12020
|
revision: String(entry.revision),
|
|
12011
12021
|
at: entry.at,
|
|
@@ -12019,7 +12029,8 @@ function createLive(options) {
|
|
|
12019
12029
|
value: JSON.parse(row.value_json)
|
|
12020
12030
|
} : {},
|
|
12021
12031
|
...ring ? { ring } : {},
|
|
12022
|
-
...failure ? { error: failure } : {}
|
|
12032
|
+
...failure ? { error: failure } : {},
|
|
12033
|
+
...!row && !failure && producing ? { awaiting: true } : {}
|
|
12023
12034
|
};
|
|
12024
12035
|
};
|
|
12025
12036
|
return {
|
|
@@ -14395,6 +14406,74 @@ function extractManifest(file, text) {
|
|
|
14395
14406
|
return file.endsWith(".mdx") ? extractFrontmatter(file, text) : extractScript(file, text);
|
|
14396
14407
|
}
|
|
14397
14408
|
//#endregion
|
|
14409
|
+
//#region src/publish/scaffold.ts
|
|
14410
|
+
/** The files a new artifact gets, in the order `artifact/create` reports them. */
|
|
14411
|
+
const SCAFFOLD_PATHS = [
|
|
14412
|
+
"index.tsx",
|
|
14413
|
+
"AGENTS.md",
|
|
14414
|
+
"CLAUDE.md"
|
|
14415
|
+
];
|
|
14416
|
+
function entry({ artifactId, title }) {
|
|
14417
|
+
return [
|
|
14418
|
+
"import { defineArtifact } from \"@mostra/react\";",
|
|
14419
|
+
"",
|
|
14420
|
+
"export const artifact = defineArtifact({",
|
|
14421
|
+
` id: ${JSON.stringify(artifactId)},`,
|
|
14422
|
+
` title: ${JSON.stringify(title)},`,
|
|
14423
|
+
"});",
|
|
14424
|
+
"",
|
|
14425
|
+
"export default function Page() {",
|
|
14426
|
+
" return (",
|
|
14427
|
+
" <main className=\"mx-auto max-w-2xl p-8\">",
|
|
14428
|
+
" <h1 className=\"text-2xl font-semibold\">{artifact.title}</h1>",
|
|
14429
|
+
" </main>",
|
|
14430
|
+
" );",
|
|
14431
|
+
"}",
|
|
14432
|
+
""
|
|
14433
|
+
].join("\n");
|
|
14434
|
+
}
|
|
14435
|
+
/** A Markdown heading's text: one line, nothing that reads as Markdown syntax at its start. */
|
|
14436
|
+
function headingText(title) {
|
|
14437
|
+
const line = title.replace(/\s+/g, " ").trim();
|
|
14438
|
+
return line === "" ? "Mostra artifact" : line;
|
|
14439
|
+
}
|
|
14440
|
+
function agents({ title, version }) {
|
|
14441
|
+
return [
|
|
14442
|
+
`# ${headingText(title)}`,
|
|
14443
|
+
"",
|
|
14444
|
+
"This directory is a Mostra artifact: a page people open from a private link, read, answer and act on. Their answers come back to you as results.",
|
|
14445
|
+
"",
|
|
14446
|
+
"## Work on it",
|
|
14447
|
+
"",
|
|
14448
|
+
"1. Edit `index.tsx`: ordinary React 19 and TypeScript with Tailwind CSS 4, with no `package.json` or build configuration.",
|
|
14449
|
+
"2. Run `mostra verify .` until it reports `pass`, and look at both screenshots it lists (`--screenshots always` lists them every time).",
|
|
14450
|
+
"3. Run `mostra publish .`. It prints the private link: whoever holds it can use the page.",
|
|
14451
|
+
"4. Give the link to the person, saying who is asking and why. Then run `mostra wait . --until submitted` and `mostra results .`.",
|
|
14452
|
+
"",
|
|
14453
|
+
`Where \`mostra\` isn't installed, run \`npx -y @mostra/cli@${version}\` in its place.`,
|
|
14454
|
+
"",
|
|
14455
|
+
"## Keep in mind",
|
|
14456
|
+
"",
|
|
14457
|
+
"- Every answer is a field with an ID that stays the same on every render and in every version: `useField(\"budget\", 0, { label: \"Budget\" })`, or a template on your data's own ID for a list. Answers carry over to a new version by ID.",
|
|
14458
|
+
"- Keep the `id` in `defineArtifact`: it is this artifact's identity. Manifest values are literals.",
|
|
14459
|
+
"- Code that must run on this machine (send, save, call an API) goes in a module that starts with `\"use server\"`; live data in `live.ts`; static files in `public/`.",
|
|
14460
|
+
"- Imports stay inside this directory, or name an npm package.",
|
|
14461
|
+
"",
|
|
14462
|
+
"## More",
|
|
14463
|
+
"",
|
|
14464
|
+
"`mostra docs guide` is the full guide to writing artifacts, and `mostra docs <CODE>` explains any diagnostic. The same guide is the Mostra Agent Skill: `npx skills add mostra-dev/mostra`.",
|
|
14465
|
+
""
|
|
14466
|
+
].join("\n");
|
|
14467
|
+
}
|
|
14468
|
+
/** The files of a new artifact, by path. */
|
|
14469
|
+
function scaffoldFiles(input) {
|
|
14470
|
+
return /* @__PURE__ */ new Map([
|
|
14471
|
+
["index.tsx", entry(input)],
|
|
14472
|
+
["AGENTS.md", agents(input)],
|
|
14473
|
+
["CLAUDE.md", "@AGENTS.md\n"]
|
|
14474
|
+
]);
|
|
14475
|
+
}
|
|
14476
|
+
//#endregion
|
|
14398
14477
|
//#region src/publish/source.ts
|
|
14399
14478
|
/**
|
|
14400
14479
|
* Artifact sources (INTERFACES §2.1, DATA_MODEL §2): finding an artifact's entry, listing its files
|
|
@@ -14766,46 +14845,40 @@ async function archiveSnapshot(source, files, target) {
|
|
|
14766
14845
|
fsyncPath(dirname(target), true);
|
|
14767
14846
|
return true;
|
|
14768
14847
|
}
|
|
14769
|
-
/** The
|
|
14770
|
-
function
|
|
14771
|
-
|
|
14772
|
-
|
|
14773
|
-
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
` title: ${JSON.stringify(title)},`,
|
|
14777
|
-
"});",
|
|
14778
|
-
"",
|
|
14779
|
-
"export default function Page() {",
|
|
14780
|
-
" return (",
|
|
14781
|
-
" <main className=\"mx-auto max-w-2xl p-8\">",
|
|
14782
|
-
" <h1 className=\"text-2xl font-semibold\">{artifact.title}</h1>",
|
|
14783
|
-
" </main>",
|
|
14784
|
-
" );",
|
|
14785
|
-
"}",
|
|
14786
|
-
""
|
|
14787
|
-
].join("\n");
|
|
14848
|
+
/** The text of each of `paths` (of {@link scaffoldFiles}) for `input`. */
|
|
14849
|
+
function scaffoldText(paths, input) {
|
|
14850
|
+
const all = scaffoldFiles(input);
|
|
14851
|
+
return Object.fromEntries(paths.flatMap((path) => {
|
|
14852
|
+
const text = all.get(path);
|
|
14853
|
+
return text === void 0 ? [] : [[path, text]];
|
|
14854
|
+
}));
|
|
14788
14855
|
}
|
|
14789
14856
|
/**
|
|
14790
|
-
* Writes `artifact/create`'s
|
|
14791
|
-
*
|
|
14792
|
-
*
|
|
14857
|
+
* Writes `artifact/create`'s files (`files`, path to text) into `dir`, completing an interrupted
|
|
14858
|
+
* write: an existing file whose bytes are the expected text's or a prefix of them (a write cut
|
|
14859
|
+
* short, even inside a character) ends as the expected text, and anything else the author has
|
|
14860
|
+
* written since is left alone.
|
|
14793
14861
|
*/
|
|
14794
|
-
async function writeScaffold(dir,
|
|
14795
|
-
const expected = scaffold(artifactId, title);
|
|
14796
|
-
const file = join(dir, "index.tsx");
|
|
14862
|
+
async function writeScaffold(dir, files) {
|
|
14797
14863
|
await mkdir(dir, { recursive: true });
|
|
14798
|
-
let
|
|
14799
|
-
|
|
14800
|
-
|
|
14801
|
-
|
|
14802
|
-
current
|
|
14864
|
+
let wrote = false;
|
|
14865
|
+
for (const [path, text] of Object.entries(files)) {
|
|
14866
|
+
const expected = Buffer.from(text, "utf8");
|
|
14867
|
+
const file = join(dir, path);
|
|
14868
|
+
let current;
|
|
14869
|
+
try {
|
|
14870
|
+
current = await readFile(file);
|
|
14871
|
+
} catch {
|
|
14872
|
+
current = void 0;
|
|
14873
|
+
}
|
|
14874
|
+
if (current !== void 0) {
|
|
14875
|
+
if (!(current.length <= expected.length && expected.subarray(0, current.length).equals(current)) || current.length === expected.length) continue;
|
|
14876
|
+
}
|
|
14877
|
+
await writeFile(file, expected);
|
|
14878
|
+
fsyncPath(file);
|
|
14879
|
+
wrote = true;
|
|
14803
14880
|
}
|
|
14804
|
-
if (
|
|
14805
|
-
if (current === expected) return;
|
|
14806
|
-
await writeFile(file, expected);
|
|
14807
|
-
fsyncPath(file);
|
|
14808
|
-
fsyncPath(dir, true);
|
|
14881
|
+
if (wrote) fsyncPath(dir, true);
|
|
14809
14882
|
}
|
|
14810
14883
|
/**
|
|
14811
14884
|
* What is wrong with a stored version directory, or `undefined` when it is intact: its
|
|
@@ -15216,10 +15289,18 @@ function createPublisher(options) {
|
|
|
15216
15289
|
async function create(params) {
|
|
15217
15290
|
const key = requestKey("artifact/create", params);
|
|
15218
15291
|
if (key !== void 0) {
|
|
15219
|
-
const
|
|
15220
|
-
if (
|
|
15221
|
-
|
|
15222
|
-
|
|
15292
|
+
const recorded = ledger.read((db) => recordedResult(db, key));
|
|
15293
|
+
if (recorded !== void 0) {
|
|
15294
|
+
if ("result" in recorded) {
|
|
15295
|
+
await writeScaffold(recorded.result.dir, recorded.scaffold.files);
|
|
15296
|
+
return recorded.result;
|
|
15297
|
+
}
|
|
15298
|
+
await writeScaffold(recorded.dir, scaffoldText(recorded.files, {
|
|
15299
|
+
artifactId: recorded.artifactId,
|
|
15300
|
+
title: params.title ?? basename(recorded.dir),
|
|
15301
|
+
version: options.runtimeVersion
|
|
15302
|
+
}));
|
|
15303
|
+
return recorded;
|
|
15223
15304
|
}
|
|
15224
15305
|
}
|
|
15225
15306
|
if (params.template !== void 0) throw new RpcError(createDiagnostic("MOSTRA_ARTIFACT_TEMPLATE_UNKNOWN", { message: `This Mostra release provides no template "${params.template}"; create the artifact without one.` }));
|
|
@@ -15231,11 +15312,19 @@ function createPublisher(options) {
|
|
|
15231
15312
|
const result = {
|
|
15232
15313
|
artifactId: ArtifactId.create(),
|
|
15233
15314
|
dir,
|
|
15234
|
-
files: [
|
|
15315
|
+
files: [...SCAFFOLD_PATHS]
|
|
15235
15316
|
};
|
|
15236
|
-
|
|
15317
|
+
const files = scaffoldText(result.files, {
|
|
15318
|
+
artifactId: result.artifactId,
|
|
15319
|
+
title: params.title ?? basename(dir),
|
|
15320
|
+
version: options.runtimeVersion
|
|
15321
|
+
});
|
|
15322
|
+
record(key, {
|
|
15323
|
+
result,
|
|
15324
|
+
scaffold: { files }
|
|
15325
|
+
});
|
|
15237
15326
|
faults.at("create:after-record");
|
|
15238
|
-
await writeScaffold(dir,
|
|
15327
|
+
await writeScaffold(dir, files);
|
|
15239
15328
|
return result;
|
|
15240
15329
|
}
|
|
15241
15330
|
}
|
|
@@ -18844,4 +18933,4 @@ function sourceDirectory(path) {
|
|
|
18844
18933
|
//#endregion
|
|
18845
18934
|
export { uninstallService as a, serviceStatus as i, startInstance as n, checkPlatform as o, installService as r, resolveHomePath as s, runtimeVersion as t };
|
|
18846
18935
|
|
|
18847
|
-
//# sourceMappingURL=instance-
|
|
18936
|
+
//# sourceMappingURL=instance-BRfg27Rg.js.map
|