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

Adapter app shape: sync an external system into the forge, with a contract the forge can audit #459

Closed opened this
Closed without merging

This adds the adapter app shape: an optional adapter block in forge.json, a forge-scheduled idempotent POST /pull that is recorded as a run, a template adapter to copy, and the adapter state on the app page. Everything is pushed. I did not get a full bun test result.

Notes

stopped closed without shipping deploy 48d3f0b

opened this

This adds the adapter app shape: an optional adapter block in forge.json, a forge-scheduled idempotent POST /pull that is recorded as a run, a template adapter to copy, and the adapter state on the app page. Everything is pushed.

I did not get a full bun test result. In this sandbox test/apps.test.ts hangs, and it hangs the same way on the parent commit, so the change didn't cause it. The new test files pass on their own, and so do the template's own tests. The adapter test files are test/adapter.test.ts (9), test/pull.test.ts (8), test/adapter-page.test.ts (3) and examples/adapter-template/test/adapter.test.ts (10). The one edit I made to apps.test.ts is adapter: null added to a fixture; I couldn't run that file here.

What changed

  • Manifest: src/apps/adapter.ts validates the block at the boundary. It covers source (name and host allowlist), schedule (interval), and config (named, typed fields). A secret is a reference only, so a value is rejected. The manifest carries it as adapter, null when absent.
  • Scheduled pull: src/apps/pull.ts calls the adapter's /pull on its interval and checks the {pulled, skipped, cursor, errors} response. Each pull is stored as a run with counts, cursor and duration. Failed and repeated pulls are recorded as runs too. The run and schema changes are in src/core/runs.ts and src/core/schema.ts.
  • Template: examples/adapter-template holds the cursor and records in bun:sqlite under FORGE_APP_DATA, so a replay of the same cursor writes nothing. Its fetch refuses any host outside the declared source. Its README says how to use it.
  • Docs: docs/ADAPTERS.md states the contract (docs/APPS.md and docs/CONTRACT.md link to it). The tests prove a repeated pull doesn't double-write, a failing pull is recorded, and another host is refused.
  • App page: src/web/studio/adapter.ts shows last pull, next pull and cursor.

Left out

  • Any real external system (the adapters issue).
  • Spawn.
  • Any new dependency.

To try it

  • Run bun test test/adapter.test.ts test/pull.test.ts test/adapter-page.test.ts.
  • In examples/adapter-template, run bun test.
  • To see it live, copy the template into an app, add its forge.json adapter block, and open the app page.

🤖 Generated with Claude Code

Closes #437

4 earlier comments · 1 event
commented

The check failed because check.run in forge.json had grown to 1035 characters, over the 1000 limit. I shortened it to 962 and pushed. I haven't seen the forge's check go green on the new push yet.

The only change is in forge.json. Three groups of test files are now named with shell globs that match exactly the same files as before:

  • test/studio*.test.ts
  • test/fork*.test.ts
  • test/adapter*.test.ts

bun x tsc --noEmit passes locally. I didn't re-run the full check here, because test/apps.test.ts hangs in this sandbox, as it did on the parent commit. The new adapter tests pass on their own.

The rest of the pull description is unchanged. It adds an optional adapter block to forge.json. The forge calls /pull on the schedule and records each pull as a run. Outbound hosts are limited to the declared source. A copyable template adapter and docs/ADAPTERS.md are included. The app page shows last pull, next pull and cursor.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was in forge.json, in check.run. The forge.json check ran clean locally: tsc, 614 tests across 43 files in the sharded run, and the 10 adapter-template tests.

  • Conflict: main added test/spawn.test.ts to the check list. This branch had turned the list into globs (test/studio*.test.ts, test/fork*.test.ts) and added test/adapter*.test.ts, test/pull.test.ts and the adapter-template run.
  • Resolution: I kept this branch's glob form and added test/spawn.test.ts next to test/spawn-plan.test.ts. The check.run string is 981 characters, under the 1000 limit.

The adapter app shape from #437 is unchanged by the merge.

🤖 Generated with Claude Code

Changes requested — before the latest push

Fix first, both doors: the adapter card (last pull, next pull, cursor) is drawn only by the web app page (src/web/studio/adapter.ts). Nothing in the diff adds it to the TUI, so someone on SSH cannot see an adapter state. Add it to the TUI app screen, reading the same lastPull and nextPullAt, gated as the page is, with a test, and a README line.

Clean: hostAllowed in src/apps/adapter.ts is not called by the forge code in the diff (the template has its own copy), and its doc comment is cut off mid-sentence. Remove it, or make it the one tested copy.

Also the preview root answered 404 for me, so I could not see the card working; please confirm it boots and answers. Last, the new pull kind adds a run every interval to run lists (board, feed, usage); add a test that they do not crowd out deploys and agent runs.

commented

I merged main into the branch and pushed. The only conflict was forge.json, in the check.run list.

  • Resolution: I kept this branch's globs and the adapter tests. I added test/web-apps.test.ts, which main brought in. The adapter template's own bun test still runs after the shards.
  • Length: That combined command came to 1003 characters, over the forge's 1000 limit. I replaced test/pulls.test.ts test/pull.test.ts with test/pull*.test.ts, which matches exactly those two files. The command is now 985 characters.
  • Checks run: tsc --noEmit is clean. The adapter, pull and web-apps tests pass (38 tests, 0 failures). I did not run the full check command or the whole suite to completion: bun test over everything hit the shell timeout and I moved on to the targeted run.
commented

main is merged into the branch and pushed, and the branch now merges cleanly. The full check passed except two tests, and I fixed one of them and reran it green. The other passed when I reran it alone.

  • Conflicts: main brought fleet operations, which also took migration 40, so the pull migration is now 41 in src/core/schema.ts. In forge.json the check list keeps the adapter and pull test globs, test/fleet-ops.test.ts and the adapter-template step.
  • Test fixed: the migration test in test/adapter.test.ts was asserting the old number. It now builds the schema up to migration 40, applies 41 and checks the rebuild. The test was wrong, not the code.
  • Flaky test: test/apps-busy.test.ts ("child still working survives the sweep") failed once under three-shard load but passed alone, so I left it. It looks timing-sensitive; I did not rerun the full check after the merge push.

To try it, run the command in the forge.json check, or run bun test test/adapter.test.ts.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs