Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

Admin: the owner is the app's admin, can name moderators, and every setting lives on one admin page #22

opened this in answer to

Parked 44d 19h ago

This adds an /admin page where the forge's signed admin identity (the app's owner) is the admin. I couldn't run the type check here because bun install fails in this sandbox, so the forge's check is the first type check. The new tests in src/admin.test.ts pass.

Notes

opened this

This adds an /admin page where the forge's signed admin identity (the app's owner) is the admin. I couldn't run the type check here because bun install fails in this sandbox, so the forge's check is the first type check.

The new tests in src/admin.test.ts pass. The full suite shows 7 failures and 5 errors, which I put down to the missing serialport dependency. With my changes stashed, the baseline was 9 failures and 5 errors, so none of the failures are in the admin code.

  • Roles: the admin can add or remove moderators by username (stored lowercase). Moderators can open /admin and see the settings and the change log, but the fields are disabled and a write is refused with 403. Anonymous and plain users get a 404 identical to an unknown path. This applies to POSTs too, and the request body is not read for them.
  • Storage: moderators, setting values and a change log of who, what, from, to and when (last 500 entries) live in $FORGE_APP_DATA/so101/admin.json. The file is written atomically and survives restarts.
  • Settings: they are declared in SETTINGS in src/admin.ts, and later issues add theirs there. There is one placeholder, notice (up to 200 characters), so the page has something editable. Nothing displays it to visitors yet.
  • Page: it is rendered on the server with plain forms and no script, and every value is escaped. Writes also go through the existing same-origin check.
  • Wiring: src/relay.ts routes /admin to src/admin-page.ts and takes a new admin option. bench/fake-serve.ts creates the store, and Software/README.md has a short section.

Things to look at:

  • Local runs with no forge key make every visitor the admin, as they already are the owner today.
  • The tests cover the 404s, the moderator being read-only (403), persistence across a restart with the log, and escaping.

🤖 Generated with Claude Code

Closes #12

7 earlier comments
commented

This adds an /admin page where the forge's signed admin identity (the app's owner) is the admin. I couldn't run the type check here because bun install fails in this sandbox, so the forge's check is the first type check.

The new tests in src/admin.test.ts pass. The full suite shows 7 failures and 5 errors, which I put down to the missing serialport dependency. With my changes stashed, the baseline was 9 failures and 5 errors, so none of the failures are in the admin code.

  • Roles: the admin can add or remove moderators by username (stored lowercase). Moderators can open /admin and see the settings and the change log, but the fields are disabled and a write is refused with 403. Anonymous and plain users get a 404 identical to an unknown path. This applies to POSTs too, and the request body is not read for them.
  • Storage: moderators, setting values and a change log of who, what, from, to and when (last 500 entries) live in $FORGE_APP_DATA/so101/admin.json. The file is written atomically and survives restarts.
  • Settings: they are declared in SETTINGS in src/admin.ts, and later issues add theirs there. There is one placeholder, notice (up to 200 characters), so the page has something editable. Nothing displays it to visitors yet.
  • Page: it is rendered on the server with plain forms and no script, and every value is escaped. Writes also go through the existing same-origin check.
  • Wiring: src/relay.ts routes /admin to src/admin-page.ts and takes a new admin option. bench/fake-serve.ts creates the store, and Software/README.md has a short section.

Things to look at:

  • Local runs with no forge key make every visitor the admin, as they already are the owner today.
  • The tests cover the 404s, the moderator being read-only (403), persistence across a restart with the log, and escaping.

🤖 Generated with Claude Code

commented

I merged main into this branch and pushed it. The type check is clean and all 135 tests pass. I did not run the forge's skipped unix-socket suites; its check runs those.

  • Conflicts: Software/so101/src/relay.ts and Software/so101/bench/fake-serve.ts conflicted, and both sides' changes were additive, so I kept both. /admin is still served ahead of the leader-calibration route. fake-serve.ts now builds one startRelay call that passes both the LeaderCalibrations store and the Admin settings.
  • One extra fix: main turned on erasableSyntaxOnly in tsconfig.json, which rejected the constructor parameter properties in src/admin.ts. I rewrote them as plain fields, with no change in behaviour.

Look at the startRelay call in bench/fake-serve.ts and the /admin branch in src/relay.ts when reviewing.

🤖 Generated with Claude Code

commented

I took your option 2. The page now edits the arm server address, and the relay follows it. The type check is clean and the full suite passed before my last small test edit; after that edit I re-ran only admin.test.ts (4 pass).

  • Arm server setting: notice is gone and SETTINGS now holds arm_server.
    • Validation: values are checked with parseRemote, and a bad value comes back as a 400 with the message escaped.
    • Fallback: an empty value falls back to the ARM_SERVER environment variable, then to the simulation.
    • Live change: the relay follows the setting on every request and every probe tick. A change drops any requests in flight and probes the new address at once. /link reflects it immediately. A new test sets and clears the value on /admin and checks that relay.link() changes.
    • Cameras: with an address set on the page, the cameras use the default ports. The ARM_CAMERA_* overrides still apply only to the environment's server.
  • HEAD /admin: it now returns 200 for the admin and 404 for strangers, and is tested.
  • Error status: AdminError carries a status (400 or 403), so the page no longer matches on message text.
  • Narrow screens: the change log table sits in an overflow-x:auto wrapper.
  • README: the Admin section now says what the setting does and where it shows up.

I did not add a terminal path. There is no src/tty.ts in this app, so there is no terminal here to extend. The README now says settings are web-only. If you want the terminal to show or change settings later, that is a separate change.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The type check is clean and all 170 tests pass.

  • Software/README.md: I kept main's wording for the leader-arm line and put the Admin section after it.
  • Software/so101/src/relay.ts: I kept both sides' imports and options, the admin page and main's shared camera feeds. The camera feeds are new on main, and they were created once from the startup address. That would have left the cameras on the old server after an admin changed the arm server. Now, when the setting changes, the relay closes the two feeds and opens new ones pointed at the new address. Viewers of the old camera streams are disconnected and have to reconnect. I did not add a test for this.

The git status output also listed untracked dotfiles in the clone root (.bashrc, .claude/, .mcp.json and others). I staged only Software/, so they weren't committed.

🤖 Generated with Claude Code

commented

Handed to a person by the crew: the reviewer asked for changes three times with no approval between, so the planner re-scopes it: split, replaced, or one more round with the reviewer's ask restated.

  1. sentinel: The security side is solid. Identity comes from lobby.who, which verifies the forge's signed headers. Writes require the signed admin ro
  2. juniper: Security, tests and escaping look right: identity comes from lobby.who (signed headers), strangers get a 404 before any body is read, writes
  3. juniper: Reviewed from the diff and source; the preview was unreachable from my sandbox, so I could not use it. The design and security are sound: id
commented

I merged main into the branch and pushed it. The type check is clean and the full suite passes (198 tests). I did not run the unix-socket suites the sandbox skips.

main had landed its own owner-only /admin (#30), so my admin.ts, admin-page.ts and admin.test.ts clashed with it as two different files at the same paths. I dropped my versions and kept main's admin, with its settings, log, Lobby wiring and CSP. I then added the two things this pull is for:

  • Arm server: armServer is now a validated setting on main's admin page, checked with parseRemote. It is a new field next to the existing ones. The relay reads it from lobby.admin.settings, falling back to the ARM_SERVER environment variable and then to the simulation.
    • Live change: a change takes effect for every viewer at once. In-flight requests are cut and the new address is probed.
    • Cameras: the camera feeds are reopened at the new address, so camera viewers have to reconnect.
  • Moderators: moderators is a setting too. The owner adds and removes them on /admin. A moderator sees the page read-only: no action buttons, disabled inputs, and any POST gets 403. Anyone else signed in gets 403, and anonymous visitors get main's 401 sign-in page.

Two behaviours differ from my first version:

  • My version of /admin was hidden from non-admins with a 404. main's answers 401 or 403 instead, so I kept that.
  • Settings are still web-only. The terminal doesn't expose the page, and the README says so.

The new tests are in src/admin-relay.test.ts:

  • Validation of the two new settings.
  • The moderator flow, including persistence across a restart.
  • That changing the arm server on /admin changes relay.link().

I also added the two settings to main's Admin section of Software/README.md.

I had to rewrite fake-serve.ts to drop my separate Admin wiring, since Lobby already owns the admin. src/relay.ts and src/admin.ts now import each other. That is safe because each import is only used inside functions, but it is a cycle.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The type check is clean and all 206 tests pass.

The only conflict was in Software/so101/src/relay.ts. main replaced the two fixed camera feeds with an owner-managed CameraHub, so I took its setup. The code I had added to reopen the camera feeds when the arm server changed is gone, because those feeds no longer exist.

One change in behaviour: the arm server setting on /admin still switches the live arm at once. It no longer touches the cameras. They are the owner's list, seeded once from the environment's ARM_SERVER at startup, and the owner edits that list directly. I changed the README line to say so.

🤖 Generated with Claude Code

commented

Closed by the crew: main moved under it 2 times and the branch could not be brought up to date. Conflicting files: Software/so101/src/relay.ts.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs