Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1d60fe0
fix(server-core): keep the server running when the watcher cannot rea…
Exeloo Nov 23, 2026
b0c31eb
fix(server-core): skip an unreadable subfolder in a recursive listing
Exeloo Nov 23, 2026
608da40
fix(server-core): stream a folder zip without hashing its files first
Exeloo Nov 23, 2026
fee7cbd
fix(server-core): check nf_modules on the real path so a link cannot …
Exeloo Nov 23, 2026
ecd0ee4
fix(server-core): keep the mode of a saved file and save through a li…
Exeloo Nov 23, 2026
45433cb
fix(server-core): never root a gateway project in the clone's .git fo…
Exeloo Nov 23, 2026
ab9c7dd
fix(server-core): keep config paths in the project and serve runtime …
Exeloo Nov 23, 2026
757a196
fix(server-core): reveal a folder in finder without opening it
Exeloo Nov 23, 2026
6598720
fix(server-core): never write the editor gitignore through a dangling…
Exeloo Nov 23, 2026
bd13645
docs(server-core): document the path, link and runtime limits of the …
Exeloo Nov 23, 2026
7e3f29d
fix(server-core): never copy through a link in the destination
Exeloo Nov 23, 2026
d3b0fb8
fix(server-core): restore only plain trash entries and never out of n…
Exeloo Nov 23, 2026
e4f153b
fix(server-core): never keep the setuid or setgid bit of a saved file
Exeloo Nov 23, 2026
4e67158
fix(server-core): log the subfolders a recursive listing skips
Exeloo Nov 23, 2026
0a1616e
docs(server-core): date the adr notes on project path checks
Exeloo Nov 23, 2026
0bede59
fix(server-core): copy entry by entry without following links in the …
Exeloo Nov 23, 2026
591c891
fix(server-core): run the changes of a project one at a time
Exeloo Nov 23, 2026
e595bb7
fix(server-core): check out links as plain files in a hosted editor
Exeloo Nov 23, 2026
ea23d2c
fix(server-core): copy a link only when it still leads inside the pro…
Exeloo Nov 23, 2026
507978b
fix(server-core): check a copied link by the real path it leads to
Exeloo Nov 23, 2026
c77ea7c
fix(server-core): copy links once the tree is copied and undo a faile…
Exeloo Nov 23, 2026
c59626d
fix(server-core): copy a named link as a link and never copy into a link
Exeloo Nov 23, 2026
274d977
fix(server-core): name the entry in the way when a copy meets one
Exeloo Nov 23, 2026
6120dcc
fix(server-core): check every entry a copy makes against nf_modules a…
Exeloo Nov 23, 2026
58505e1
fix(server-core): share the change lock of a folder between its insta…
Exeloo Nov 23, 2026
c0e3818
fix(server-core): stop a copy when a folder it writes into is swapped…
Exeloo Nov 23, 2026
01b3694
perf(server-core): copy sixteen entries at a time
Exeloo Nov 23, 2026
2705d73
docs(server-core): describe how a copy treats links and how hosted gi…
Exeloo Nov 23, 2026
5099de0
fix(server-core): never clean up a failed copy through a folder swapp…
Exeloo Nov 23, 2026
ddcef84
fix(server-core): check a copied link where the system really leads i…
Exeloo Nov 23, 2026
4e5f970
fix(server-core): remove the folders a failed copy made to hold its d…
Exeloo Nov 23, 2026
e2a2a61
fix(server-core): stop a copy at its first failure, in name order
Exeloo Nov 23, 2026
1f7d2e4
fix(server-core): remove only the empty folders a failed copy made
Exeloo Nov 23, 2026
51ddb11
fix(server-core): never replace a link already in a copy's destination
Exeloo Nov 23, 2026
9d1fb3f
fix(server-core): remove every copied link that leads outside, not on…
Exeloo Nov 23, 2026
8167a08
fix(server-core): refuse nf_modules whatever its case
Exeloo Nov 23, 2026
df20e74
docs(server-core): describe the copy's order, cleanup and link checks
Exeloo Nov 23, 2026
2af144f
test(server-core): name the copy tests for what they check, and stop …
Exeloo Nov 23, 2026
f412e8a
fix(server-core): roll back a failed folder of a copy and check each …
Exeloo Nov 23, 2026
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
8 changes: 5 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pnpm e2e:last-failure # error-context.md of the last failed test, its last fra
- The editor server answers only to loopback host names and `ALLOWED_HOSTS` (DNS rebinding guard): a dev server reached by another name needs it.
- `EDITOR_TOKEN` (off by default; `random` makes one per start): a local editor then answers only to a browser that opened the link it prints (`?token=`, which sets an HttpOnly cookie). Dev server and e2e run without it.
- The editor's page has a Content Security Policy (`packages/server-core/src/http/shell-csp.ts`; inline scripts by hash, read from `index.html`). A local editor allows `'unsafe-eval'` (the engine's ECS is Emscripten WebAssembly, whose bindings compile strings); a hosted one does not. The e2e fixture fails a test on any CSP violation: a new kind of resource (another origin, a worker type) needs the policy changed with it.
- Hosted sessions: project grants belong to the user who opened the project (a new user or a sign-out drops them); refused tokens are not re-checked for a minute; API calls time out after 15 s; over the session cap, anonymous sessions go first. `/rpc` bodies are capped at 100 MiB, folder zips are streamed (no trash, no `nf_modules`, 1 GiB at most), and trash entries older than 30 days go when a project opens.
- Hosted sessions: project grants belong to the user who opened the project (a new user or a sign-out drops them); refused tokens are not re-checked for a minute; API calls time out after 15 s; over the session cap, anonymous sessions go first. `/rpc` bodies are capped at 100 MiB, folder zips are streamed (no trash, no `nf_modules`, 1 GiB at most), and trash entries older than 30 days go when a project opens. A hosted editor's git runs with `core.symlinks=false`: what it clones or pulls holds no link (a committed link becomes a plain file; a clone made before keeps its links).
- To debug a failed e2e test, `pnpm e2e:last-failure` (or read `test-results/<test>/error-context.md`, and the last frame of `trace.zip`). A minified Monaco stack: rebuild code-editor with `npx vite build --sourcemap --outDir <scratch>` (same file hashes) and map the frames with `@jridgewell/trace-mapping`.
- The CLI repo needs `pnpm --filter @nanoforge-dev/config build` before `pnpm build`, and `pnpm --filter @nanoforge-dev/schematics build` for `nf new` (its root build leaves the schematics out).

Expand Down Expand Up @@ -178,8 +178,10 @@ Everything in our registry has a `nanoforge.manifest.json` and a name `@scope/na
### Folder trust (local editors)

- A local project's code runs only in a **trusted folder** (`TrustStore`, `DATA_DIR/trusted-folders.json`, by real path; seeded with the recent projects when first created). Trusted: `nanoforge.config.ts` is executed, project plugins load and their server entries run, builds, games, dependency installs, the project's Prettier and its git hooks run.
- An untrusted folder opens in **restricted mode**: the config is read statically (as in a hosted editor), project plugins stay out, Play explains why, git runs with the hosted hardening, formatting uses the bundled Prettier. A sticky notification and `project.trust` offer **Trust this folder** (`projects.trust`, then the project reopens).
- An untrusted folder opens in **restricted mode**: the config is read statically (as in a hosted editor), project plugins stay out, Play explains why, git runs with the hosted hardening (without `core.symlinks=false`: the user's own checkout keeps its links), formatting uses the bundled Prettier. A sticky notification and `project.trust` offer **Trust this folder** (`projects.trust`, then the project reopens).
- Server gates go through `ProjectRegistry.assertTrusted(project, what)`; `OpenProject.trusted` and `ClientProject.trusted` carry the state. A new code path that runs project code needs the gate.
- `/runtime/<project>/…` (the build output) is served to trusted projects only, and only files that really lie inside the project (the output folder may be a link out of it).
- A `nanoforge.config` path (`dir.*`, `entryFile`, `editor.entryFile`, `out.dir`) must stay inside the project: an absolute path or one that leaves it drops that app, with an error diagnostic (the config of an untrusted folder chooses these).
- `plugins.list` never runs anything: the client calls `plugins.runProjectServers` with the project plugins that loaded.
- The editor shell is served with `frame-ancestors 'self'` / `X-Frame-Options: SAMEORIGIN`, so another site cannot frame it and get a click on **Trust and open**.

Expand Down Expand Up @@ -315,6 +317,6 @@ Everything in our registry has a `nanoforge.manifest.json` and a name `@scope/na

1. **Items (decided, ADR 0003).** See "Manifests: packages and plugins" above. Still open there: engine libs shipping items, inspector value hints, headless meta generation (imports, collisions, the packages list and sub-packages were settled by ADR 0004 and 0005).
2. **`nf_modules` / install (decided, ADR 0005).** The editor server installs packages read-only into `nf_modules/@scope/name`, side by side, one version each, from `nanoforge.packages.json` and its lock; plugins go to `~/.nanoforge/editor/plugins` or `<project>/.nanoforge/plugins`. To change a package, the user copies it into their own components.
- The editor treats `nf_modules` as read-only (server, file manager, code editor): installing is the only way to change it.
- The editor treats `nf_modules` as read-only (server, file manager, code editor): installing is the only way to change it. The rule follows links: a link to `nf_modules` (or to `.git`) cannot be written, renamed or deleted through the file API either.
- Discovery goes through a catalog with providers (project packages and apps, `nf_modules`), never folder scans.
- Still open: the real registry (contract handed off in `docs/api/registry.md`; the editor runs on a folder with `REGISTRY_DIR`, and calls the API's only with `API_FEATURES=registry`), whether engine libs stay on npm. The registry package moved to the CLI repository (`libs/registry`): the editor, `nf install` and `nf publish` use the same one.
3 changes: 2 additions & 1 deletion docs/adr/0002-editor-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ The previous editor ran all server logic through SvelteKit form actions and hook
- Every RPC call and WebSocket upgrade is checked against the `Origin` header, so a web page on
another origin cannot drive a local editor. OFFLINE editors bind to `127.0.0.1` by default.
- Project paths are jailed to `FS_ROOT`, and file paths to the project root, including through
symlinks. Deletes go to `.nanoforge/editor/trash`.
symlinks. Deletes go to `.nanoforge/editor/trash`. Update 2026-11-23: config paths (`dir.*`, entry files, `out.dir`) must
stay inside the project, and `/runtime/` serves only trusted projects' files that lie inside it.
- **Config loading**:
- OFFLINE executes `nanoforge.config.*` with `unrun`, like the CLI does. Everything but Node
built-ins is bundled (unrun imports from `<cwd>/node_modules/.unrun`), and
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/0005-package-installs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Date: 2026-10-01. Status: accepted. It settles the install questions ADR 0003 le
## Decisions

1. **Who installs.** The editor server, with a package that has no editor dependency (`@nanoforge-dev/registry`). It is meant to move to the CLI repository, where `nf install` will use it too. Update 2026-11-08: done, it is `libs/registry` in the CLI repository, used by the editor, `nf install` and `nf publish`.
2. **The project's list.** `nanoforge.packages.json` holds the packages a project asks for, with version ranges. `nanoforge.packages.lock.json` holds what is installed: exact versions, archive hashes, and each package's own dependencies. `nf_modules` can be restored from the lock, so it may be left out of git. The editor does not edit the project's `.gitignore`: that choice is the project's.
2. **The project's list.** `nanoforge.packages.json` holds the packages a project asks for, with version ranges. `nanoforge.packages.lock.json` holds what is installed: exact versions, archive hashes, and each package's own dependencies. `nf_modules` can be restored from the lock, so it may be left out of git. The editor does not edit the project's `.gitignore`: that choice is the project's. Update 2026-11-23: it only writes its own `.nanoforge/editor/.gitignore`, and never through a link.
3. **Sub-packages.** Each package is published on its own and can be installed alone. A package that needs others lists them in `dependencies` (`{ "@scope/name": "^1.0.0" }`); they are installed side by side in `nf_modules/@scope/name`, one version each. `include` stays for folders inside one published package.
4. **Version conflicts.** One version of a package per project. When two ranges have no version in common, the install is refused and names both.
5. **Name collisions of items.** Plain names stay. The app's own item wins over a package's and the editor warns. Refusing installs on collisions between two packages is left for when the registry knows item names.
Expand Down
15 changes: 13 additions & 2 deletions docs/specs/file-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,21 @@ Browse and organize a game's files: a folder tree, plus a grid of the selected f
## Core and server additions

- `fs.delete` returns the trash location, and `fs.restore` brings it back (undo).
- `fs.reveal` (local only) opens the OS file manager.
- `fs.reveal` (local only) opens the OS file manager (`open -R` on macOS, which selects the file).
- `GET /files/<project>/<path>` serves a project file (thumbnails, downloads); on a folder with `?download` it serves a `.zip`.
- `.nfignore` is read by the server: listings and watch events skip it.
- `nf_modules/**` is read-only for every write.
- `nf_modules/**` is read-only for every write, and so is a link that leads there (the check uses where a path really leads; `.git` is refused the same way).
- A write through a link goes to the link's real target and keeps the file's mode.
- A subfolder the server cannot read (permission denied) is skipped in listings and does not stop the watcher; the rest of the project still shows.
- Changes through the file API (write, create a folder, rename, copy, delete, restore, empty the trash) run one at a time per project folder.
- `fs.copy` never writes through a link:
- a link in the destination where a folder goes is refused, and a destination that is a link is refused;
- a file already there is replaced (with `overwrite`) or is a conflict that names that entry; a link already there is always a conflict (replacing it could change where other links lead);
- no entry goes into `nf_modules` (in any case) or `.git`, even from a copy into the project root, and `.git` folders of the source are left out;
- entries are started in name order, 16 at a time, and the copy stops at the first failure (entries already under way still finish); the error reported is one of the failing entries;
- links are copied as links, after the rest of the tree, and only when they lead inside the project from their new place, as the system follows them; they are all checked again at the end, and every one that no longer leads inside is removed; a link that leads nowhere is refused; a link named by the copy stays a link;
- a copy to a new place that fails removes what it made, and the folders it made to hold it if they are still empty; one into an existing folder keeps what it had copied;
- a folder swapped for a link by another program during the copy stops it, and the cleanup checks that the folder is the same before removing.

## Done when

Expand Down
8 changes: 3 additions & 5 deletions packages/server-core/src/fs/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const LEFT_OUT = [TRASH_DIR, PACKAGES_DIR];
/** From this size on, a file is compressed in a worker (as fflate's `zip()` does). */
const ASYNC_FROM_BYTES = 160_000;

const leftOut = (path: string) =>
LEFT_OUT.some((folder) => path === folder || path.startsWith(`${folder}/`));

/**
* Zips a folder of the project as a stream: one file read at a time, as the reader asks for
* more (the next once the last is zipped), so a large folder is never held in memory. A file
Expand All @@ -28,8 +25,9 @@ export const archiveFolder = async (
maxBytes = MAX_ARCHIVE_BYTES,
): Promise<ReadableStream<Uint8Array>> => {
const prefix = path ? `${path}/` : '';
const files = (await fs.list(path, true)).filter(
(entry) => entry.kind === 'file' && !leftOut(entry.path),
/** Sizes only: the zip never uses the hashes, and its first byte would wait for them. */
const files = (await fs.list(path, true, { hash: false, leaveOut: LEFT_OUT })).filter(
(entry) => entry.kind === 'file',
);
const total = files.reduce((sum, entry) => sum + entry.size, 0);
if (total > maxBytes)
Expand Down
Loading
Loading