Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
3bd3820
refactor: remove all use of singletons within the runner package!
seefeldb May 28, 2025
fed0824
expose run and runSynced in Runtime directly + fix warnings
seefeldb May 28, 2025
8ce3b8b
de-singletonify builder tests
seefeldb May 28, 2025
f31046e
inject createCell implementation at runtime -- first step towards doi…
seefeldb May 28, 2025
f4eb35d
dedupe ICodeHarness and Harness
seefeldb May 28, 2025
2ebf45a
only declare createCell in builder
seefeldb May 28, 2025
56205df
some temporary singleton remnants
seefeldb May 28, 2025
8105969
no more temporary singleton exports
seefeldb May 28, 2025
c0bd715
Refactor storage configuration to use URL-based setup
seefeldb May 28, 2025
b71ccb0
Fix runner tests after storage URL refactoring
seefeldb May 28, 2025
1ef5913
Fix storage space mismatches and test structure issues
seefeldb May 28, 2025
00eb22f
remove fake singletons again (claude keeps putting them back), also r…
seefeldb May 28, 2025
269b876
export createCell type
seefeldb May 28, 2025
a81e168
remove singleton in html tests
seefeldb May 28, 2025
6a06bd1
make storage url required again, with no default logic inside here ->…
seefeldb May 28, 2025
3d286f7
and fix test to use createCellFactory
seefeldb May 28, 2025
1af5bea
Eliminate all singleton usage in jumble package
seefeldb May 28, 2025
3a1da01
Format storage.ts (linting changes)
seefeldb May 28, 2025
55dbe4a
fix schema-lineage test and reenable it
seefeldb May 28, 2025
1367a93
restored original console signature + other regressions
seefeldb May 28, 2025
d967746
declare createCell in a way that makes it clear that the environment …
seefeldb May 28, 2025
844babb
actually, this seems better
seefeldb May 28, 2025
bfcb70a
refactor: complete singleton removal in CLI and background-charm-serv…
seefeldb May 28, 2025
6e1997a
refactor: remove singleton usage from toolshed package
seefeldb May 28, 2025
a54c806
revert to getEntityId to original signature
seefeldb May 28, 2025
8d1baa6
Various post-rebase fixes
seefeldb May 28, 2025
1379458
refactor: move id property from Storage to Runtime
seefeldb May 28, 2025
a4450d2
fix linter error
seefeldb May 28, 2025
0a2e6f3
remove unused blobby storage
seefeldb May 28, 2025
d4e1c34
use runtime blobby url in recipe manager
seefeldb May 28, 2025
20d5fa9
fix: standardize volatile:// URLs to not include path arguments
seefeldb May 28, 2025
944ddf5
no default space for loadRecipe
seefeldb May 28, 2025
5e642d6
switch back to old harness (upstream change didn't actually switch, t…
seefeldb May 28, 2025
b075fa1
use source in recipe generation
seefeldb May 28, 2025
bdb0be0
don't fail here if browser didn't make it up before an error occured
seefeldb May 28, 2025
7836705
fix blobby urls
seefeldb May 28, 2025
21f1ac3
fix writing for blobby, waiting for recipe to be saved
seefeldb May 28, 2025
29787e6
catch missing recipe ids (for debugging)
seefeldb May 28, 2025
3aa5261
refactoring regression: somehow lost getCell and thus schema
seefeldb May 29, 2025
82b3fb4
await storage cell so recipe has time to load
seefeldb May 29, 2025
c7fd397
show error that caused recipe not to load
seefeldb May 29, 2025
d9709de
extra await sync isn't necessasry, getRecipeMetaCell already does that
seefeldb May 29, 2025
2f4a6da
refactor accidentlally switched to volatile storage
seefeldb May 29, 2025
e1fad87
use actual recipeEnvironment
seefeldb May 29, 2025
095db5a
remove extraneous comment
seefeldb May 29, 2025
b74a554
docs: update runner README to reflect singleton removal refactoring
seefeldb May 29, 2025
7dbee4c
fix: await CharmManager.ready in background services
seefeldb May 29, 2025
28a05e9
await charmmanager ready, just in case
seefeldb May 29, 2025
e39ff99
await charmmanager, remove extraneous comment
seefeldb May 29, 2025
c7796fe
use passed in runtime
seefeldb May 29, 2025
7a8b768
cancel via this.stop call, not directly accessing the cancels
seefeldb May 29, 2025
57f59b2
remove newly duplicated methods and functions
seefeldb May 29, 2025
73e5935
remove redundant & newly added unused functionality
seefeldb May 29, 2025
06ea4b0
various simplifications around runner
seefeldb May 29, 2025
b29d375
minor cleanups
seefeldb May 29, 2025
0d76781
restore original pathAffected and compactifyPaths
seefeldb May 29, 2025
790a353
make sure there aren't extraneous sinks left
seefeldb May 29, 2025
5e2eb3a
some minor doc -> cell changes
seefeldb May 29, 2025
1e8cbda
remove unused extra methods
seefeldb May 29, 2025
f3c385e
small revertions back to the original
seefeldb May 29, 2025
7f19c0b
Make runtime parameter required for createDoc
seefeldb May 29, 2025
d7010a8
- removed enableCache, since it didn't do anything (we deprecated non…
seefeldb May 29, 2025
1e277a4
remove storage/shared, instead
seefeldb May 29, 2025
6f5299f
fixed refactor omitting `context` in id generation!
seefeldb May 29, 2025
8af03b0
restore tests and assertions refactor removed
seefeldb May 29, 2025
0ab4cdf
cosmetic changes to tests
seefeldb May 29, 2025
5981ef4
fix: seeder was using volatile storage
seefeldb May 29, 2025
182f5e6
removed unsed functionallity from module registry, add guards
seefeldb May 29, 2025
00d2abc
remove syncCellById from storage, better to get cells via getCellFrom…
seefeldb May 29, 2025
c4c89bc
disable multi harness for now
seefeldb May 29, 2025
56c9941
pass runtime around, not charmmanager, when runtime is all we need
seefeldb May 29, 2025
1a5df4f
straggler charmmanager -> runtime
seefeldb May 29, 2025
e961b98
revert to previous way of generating these ids
seefeldb May 29, 2025
0369115
nit: entityId is no longer optional
seefeldb May 29, 2025
78a4b85
id generation can subtly change. so read actually create id instead o…
seefeldb May 29, 2025
248a8ef
fix useRuntime use
seefeldb May 29, 2025
ea91556
remove extraneous console.log, add comments for others
seefeldb May 30, 2025
0f0c1c2
runtime.dispose is async, so let's return the promise
seefeldb May 30, 2025
c754c13
update vite config to serve static from toolshed
seefeldb May 30, 2025
67fe5f3
remove redundant blobby url
seefeldb May 30, 2025
7aa81ef
removed redundant runtime.documentMap
seefeldb May 30, 2025
00ee85d
no longer need maybePromise for debugging
seefeldb May 30, 2025
2d00bc8
more redundant blobby urls
seefeldb May 30, 2025
f567122
removed unnecessary comment
seefeldb May 30, 2025
679f243
use runtime directly
seefeldb May 30, 2025
0d65f25
blobbyServerUrl can't be undefined
seefeldb May 30, 2025
8b61a8c
fix blobbyserverurl can't be undefined in class as well
seefeldb May 30, 2025
ed8f99f
deno fmt change
seefeldb May 30, 2025
f69db8a
re-apply change after rebase
seefeldb May 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions packages/background-charm-service/cast-admin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { parseArgs } from "@std/cli/parse-args";
import { CharmManager, compileRecipe } from "@commontools/charm";
import {
getCell,
getEntityId,
setBlobbyServerUrl,
storage,
} from "@commontools/runner";
import { getEntityId, Runtime } from "@commontools/runner";
import { type DID } from "@commontools/identity";
import { createAdminSession } from "@commontools/identity";
import {
Expand Down Expand Up @@ -42,16 +37,13 @@ const identity = await getIdentity(
Deno.env.get("OPERATOR_PASS"),
);

storage.setRemoteStorage(new URL(toolshedUrl));
setBlobbyServerUrl(toolshedUrl);
// Storage and blobby server URL are now configured in Runtime constructor

async function castRecipe() {
const spaceId = BG_SYSTEM_SPACE_ID;
const cause = BG_CELL_CAUSE;
console.log(`Casting recipe from ${recipePath} in space ${spaceId}`);

storage.setSigner(identity);

console.log("params:", {
spaceId,
recipePath,
Expand All @@ -60,6 +52,12 @@ async function castRecipe() {
quit,
});

// Create runtime with proper configuration
const runtime = new Runtime({
storageUrl: toolshedUrl,
signer: identity,
});

try {
// Load and compile the recipe first
console.log("Loading recipe...");
Expand All @@ -69,15 +67,15 @@ async function castRecipe() {
throw new Error("Cell ID is required");
}

const targetCell = getCell(
const targetCell = runtime.getCell(
spaceId as DID,
cause,
BGCharmEntriesSchema,
);

// Ensure the cell is synced
await storage.syncCell(targetCell, true);
await storage.synced();
await runtime.storage.syncCell(targetCell, true);
await runtime.storage.synced();

console.log("Getting cell...");

Expand All @@ -92,8 +90,9 @@ async function castRecipe() {
});

// Create charm manager for the specified space
const charmManager = new CharmManager(session);
const recipe = await compileRecipe(recipeSrc, "recipe", charmManager);
const charmManager = new CharmManager(session, runtime);
await charmManager.ready;
const recipe = await compileRecipe(recipeSrc, "recipe", runtime, spaceId);
console.log("Recipe compiled successfully");

const charm = await charmManager.runPersistent(
Expand All @@ -104,13 +103,13 @@ async function castRecipe() {
console.log("Recipe cast successfully!");
console.log("Result charm ID:", getEntityId(charm));

await storage.synced();
await runtime.storage.synced();
console.log("Storage synced, exiting");
Deno.exit(0);
} catch (error) {
console.error("Error casting recipe:", error);
if (quit) {
await storage.synced();
await runtime.storage.synced();
Deno.exit(1);
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/background-charm-service/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseArgs } from "@std/cli/parse-args";
import { storage } from "@commontools/runner";
import { Runtime } from "@commontools/runner";
import { BackgroundCharmService } from "./service.ts";
import { getIdentity, log } from "./utils.ts";
import { env } from "./env.ts";
Expand All @@ -24,10 +24,14 @@ const workerTimeoutMs = (() => {
})();

const identity = await getIdentity(env.IDENTITY, env.OPERATOR_PASS);
const runtime = new Runtime({
storageUrl: env.TOOLSHED_API_URL,
signer: identity,
});
const service = new BackgroundCharmService({
identity,
toolshedUrl: env.TOOLSHED_API_URL,
storage,
runtime,
workerTimeoutMs,
});

Expand Down
17 changes: 8 additions & 9 deletions packages/background-charm-service/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Identity } from "@commontools/identity";
import { type Cell, type Storage } from "@commontools/runner";
import { type Cell, type Runtime } from "@commontools/runner";
import {
BG_CELL_CAUSE,
BG_SYSTEM_SPACE_ID,
Expand All @@ -12,7 +12,7 @@ import { useCancelGroup } from "@commontools/runner";
export interface BackgroundCharmServiceOptions {
identity: Identity;
toolshedUrl: string;
storage: Storage;
runtime: Runtime;
bgSpace?: string;
bgCause?: string;
workerTimeoutMs?: number;
Expand All @@ -24,30 +24,29 @@ export class BackgroundCharmService {
private charmSchedulers: Map<string, SpaceManager> = new Map();
private identity: Identity;
private toolshedUrl: string;
private storage: Storage;
private runtime: Runtime;
private bgSpace: string;
private bgCause: string;
private workerTimeoutMs?: number;

constructor(options: BackgroundCharmServiceOptions) {
this.identity = options.identity;
this.toolshedUrl = options.toolshedUrl;
this.storage = options.storage;
this.runtime = options.runtime;
this.bgSpace = options.bgSpace ?? BG_SYSTEM_SPACE_ID;
this.bgCause = options.bgCause ?? BG_CELL_CAUSE;
this.workerTimeoutMs = options.workerTimeoutMs;
}

async initialize() {
this.storage.setRemoteStorage(new URL(this.toolshedUrl));
this.storage.setSigner(this.identity);
// Storage URL and signer are already configured in the Runtime
this.charmsCell = await getBGCharms({
bgSpace: this.bgSpace,
bgCause: this.bgCause,
storage: this.storage,
runtime: this.runtime,
});
await this.storage.syncCell(this.charmsCell, true);
await this.storage.synced();
await this.runtime.storage.syncCell(this.charmsCell, true);
await this.runtime.storage.synced();

if (this.isRunning) {
log("Service is already running");
Expand Down
32 changes: 12 additions & 20 deletions packages/background-charm-service/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Charm } from "@commontools/charm";
import {
type Cell,
getCell,
getEntityId,
type Storage,
} from "@commontools/runner";
import { type Cell, getEntityId, type Runtime } from "@commontools/runner";
import { Identity, type IdentityCreateConfig } from "@commontools/identity";
import { ID, type JSONSchema } from "@commontools/builder";
import {
Expand Down Expand Up @@ -104,21 +99,21 @@ export async function setBGCharm({
space,
charmId,
integration,
storage,
runtime,
bgSpace,
bgCause,
}: {
space: string;
charmId: string;
integration: string;
storage: Storage;
runtime: Runtime;
bgSpace?: string;
bgCause?: string;
}): Promise<boolean> {
const charmsCell = await getBGCharms({
bgSpace,
bgCause,
storage,
runtime,
});

console.log(
Expand Down Expand Up @@ -148,7 +143,7 @@ export async function setBGCharm({
} as unknown as Cell<BGCharmEntry>);

// Ensure changes are synced
await storage.synced();
await runtime.storage.synced();

return true;
} else {
Expand All @@ -160,31 +155,28 @@ export async function setBGCharm({
status: "Re-initializing",
});

await storage.synced();
await runtime.storage.synced();

return false;
}
}

export async function getBGCharms(
{ bgSpace, bgCause, storage }: {
{ bgSpace, bgCause, runtime }: {
bgSpace?: string;
bgCause?: string;
storage: Storage;
runtime: Runtime;
},
): Promise<
Cell<Cell<BGCharmEntry>[]>
> {
bgSpace = bgSpace ?? BG_SYSTEM_SPACE_ID;
bgCause = bgCause ?? BG_CELL_CAUSE;

if (!storage.hasSigner()) {
if (!runtime.storage.hasSigner()) {
throw new Error("Storage has no signer");
}

if (!storage.hasRemoteStorage()) {
throw new Error("Storage has no remote storage");
}
const schema = {
type: "array",
items: {
Expand All @@ -194,7 +186,7 @@ export async function getBGCharms(
default: [],
} as const satisfies JSONSchema;

const charmsCell = getCell(bgSpace, bgCause, schema);
const charmsCell = runtime.getCell(bgSpace, bgCause, schema);

// Ensure the cell is synced
// FIXME(ja): does True do the right thing here? Does this mean: I REALLY REALLY
Expand All @@ -207,8 +199,8 @@ export async function getBGCharms(
schema: privilegedSchema,
rootSchema: privilegedSchema,
};
await storage.syncCell(charmsCell, true, schemaContext);
await storage.synced();
await runtime.storage.syncCell(charmsCell, true, schemaContext);
await runtime.storage.synced();

return charmsCell;
}
Loading