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 #529

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 fe12c54

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.

Why #520's preview failed, and the fix: the preview's database applied forge_setting as migration 40. Then the merge with main renumbered it to 41, behind fleet operations' 40. On the next boot, 40 was skipped as already applied, so the database never got the fleet-operation tables, and 41 stopped with SQLiteError: table forge_setting already exists. Migration 41 now creates fleet_operation, its index, fleet_operation_row and forge_setting only if they are missing, the same way migration 37 handles share. On a normal database it does nothing extra; on that preview's database it adds what was missing. A new test in test/slider.test.ts builds a database the way the preview's was (1–39, then forge_setting as 40), saves a position, and boots it with today's migrations. It checks that all the tables exist and the saved row survives.

What the branch adds:

  • 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 and parseMarginPct (whole numbers only) and policyWords, which describes the policy in words.
  • Runtime constants: SLEEP_AFTER_MS and IDLE_PULL_DAYS = 3 are exported from src/apps/runtime.ts, with values unchanged. A test checks that position 50 matches them.
  • Storage: src/core/economics.ts reads and writes the forge_setting key/value table. An empty table means position 50 and margin 0, and a row edited into nonsense reads as the default.
  • Admins only: 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.
  • Settings → Economics (/settings/economics): a server-rendered page with the slider, the margin and the policy in words, saved by a same-origin POST. It has its own module like the other forge-wide admin pages, not settings.ts, which holds per-repository settings.
  • API: GET and PUT /api/v1/forge/economics, with the same validation. An invalid value refuses the whole change with a 422.

Not done:

  • The words don't update while you drag the slider; they change after you save. Making them live would mean copying the formula into the client.
  • docs/PROFIT.md arrives with #513.
  • The app was not booted by hand against a copy of the preview's database; the migration test covers that path, and the preview deploy is the real check.

Check: the full forge.json check ran: tsc was clean and 660 of 661 tests passed. The one failure was apps that are busy > an app whose child is still working survives the sweep…, in a file this pull doesn't touch; run alone, it passed 3 of 3.

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

🤖 Generated with Claude Code

Closes #504

Closes #504

commented

The forge rejected the check because check.run in forge.json was over its 1000-character limit; it is now 793. The command still lists every test file, but by bare name (crew.test.ts rather than test/crew.test.ts).

  • scripts/shards.ts: a new testPath function reads a bare name as a file in test/ and leaves any name with a directory in it as given. scripts/test-shards.ts runs every file name it is given through it, so the shard runner still finds the files.
  • test/shards.test.ts: one test covers testPath. Another reads the repository's own forge.json through the manifest parser the forge uses (parseCheck) and checks that every test file it names exists. That catches both a check over the length limit and a misspelled file name before a push.

Testing: a full run of the check command gave 663 tests across 43 files with 1 failure: "apps that are busy > an app whose child is still working survives the sweep, then sleeps once it is done". It passes when test/apps-busy.test.ts runs on its own, and nothing it touches changed here, so it looks like a timing flake when the shards run together. No test was changed to get a pass.

To try: bun scripts/test-shards.ts shards.test.ts, or run check.run from forge.json directly.

🤖 Generated with Claude Code

commented

Parked by the crew: main moved under it 3 times and the branch could not be brought up to date (forge.json, scripts/shards.ts, scripts/test-shards.ts, src/core/schema.ts, test/shards.test.ts)

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs