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

The profit slider's position: one number per forge, and the pure function from position to policy #520

Closed opened this
Closed without merging

Each forge now stores one profit-slider position (a whole number 0–100), and a pure policyAt(position) turns it into sleep windows, how long a quiet pull keeps its preview, and when cloud takes work. Position 50 gives exactly today's values, and nothing reads the position yet, so landing this changes nothing.

Notes

stopped closed without shipping deploy 7b0c7ff

opened this

Each forge now stores one profit-slider position (a whole number 0–100), and a pure policyAt(position) turns it into sleep windows, how long a quiet pull keeps its preview, and when cloud takes work. Position 50 gives exactly today's values, and nothing reads the position yet, so landing this changes nothing.

  • src/core/slider.ts: policyAt interpolates in a straight line between the 0 / 50 / 100 rows of docs/PROFIT.md. On the way to 100, "never" counts as 7 days, so 99 still sleeps and only 100 returns null. The same file has parsePosition/parseMarginPct (whole numbers only) and policyWords. At 50 it reads: "production sleeps after 24 h idle · previews after 30 min · cloud takes work above 85% of owned capacity · a quiet pull's preview stops after 3 days".
  • Runtime constants: SLEEP_AFTER_MS and a new IDLE_PULL_DAYS = 3 are now exported from src/apps/runtime.ts, and src/main.ts uses that constant. The values haven't changed; a test checks that position 50 matches them.
  • Storage: migration 40 adds a forge_setting key/value table, read and written by src/core/economics.ts. An empty table means position 50 and margin 0. Reads go back through the same parsers, so a row edited into nonsense reads as the default.
  • Admin check and event: src/actions/economics.ts lets only a forge admin read or set the numbers; anyone else gets not_found. Each change records a forge.economics_updated event with the values before and after. forge.* events are now admin-only in event_audience.ts.
  • Settings → Economics (/settings/economics, admins only): a range input, a margin field and the policy in words, posted to the same origin. A table shows what positions 0 / 25 / 50 / 75 / 100 mean, so you can choose before saving without any JavaScript.
  • API: GET and PUT /api/v1/forge/economics. PUT takes position and/or marginPct; a field you leave out keeps its value, and any invalid value refuses the whole change with a 422.

What to look at:

  • Page location: the page is in its own module, src/web/pages/economics.ts, not settings.ts as the issue says. settings.ts holds per-repository settings; forge-wide admin pages each have their own module, like secrets.ts and cloud.ts.
  • docs/PROFIT.md isn't in this branch. It arrives with #513, which this follows.
  • Words don't update while dragging. They change after you save; making them live would mean copying the formula into the client.

test/slider.test.ts is new and added to the forge.json check. It covers the three anchors, 25 and 75 worked out by hand, 99, 50 against the runtime constants, refusal of out-of-range, fractional and non-numeric positions, admin-only access, the same-origin rule, and the event. The full check ran tsc cleanly and 630 of 632 tests passed. The two failures are in code this pull doesn't touch:

  • checks > when a slot frees… passes when run alone.
  • fork-flow > a mirror whose git is not ready yet… failed once more alone, then passed 3 of 3 on this branch and passed on main. #513 already noted it as flaky under load.

To try it: sign in as the admin, open Settings → Economics, move the slider and save. Or run curl -X PUT -H "authorization: Bearer $TOKEN" -d '{"position":75}' $URL/api/v1/forge/economics.

🤖 Generated with Claude Code

Closes #504

commented

Parked by the crew: the preview's deploy failed and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs