spfn 0.3.0-beta.5 → 0.3.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,7 +55,7 @@ with `--pm`. In a pnpm workspace, `create` installs from the workspace root.
55
55
 
56
56
  Registered top-level commands: `create`, `init`, `add`, `dev`, `build`, `start`,
57
57
  `provision`, `codegen`, `contract`, `key`, `setup`, `db`, `env`, `ops`, `secret`,
58
- `cloud`.
58
+ `cloud`, `kit`.
59
59
 
60
60
  ### `spfn create <name>`
61
61
 
@@ -118,7 +118,14 @@ its backend as Vercel Functions:
118
118
  |------|------------|
119
119
  | `src/app/api/backend/[[...route]]/route.ts` | `hono/vercel` adapter, mounts the SPFN app under `/api/backend` |
120
120
  | `vercel.json` | build config (`pnpm spfn:build`) |
121
- | `.npmrc` | `@spfn` registry auth, reading `GITEA_NPM_TOKEN` from the environment never committed |
121
+ | `.npmrc` | which registry the `@spfn` scope resolves to a mapping, not a credential |
122
+
123
+ The registry token does **not** go in that `.npmrc`. pnpm 10 and later refuse to expand an
124
+ environment variable in a registry credential that came from a project `.npmrc` — the file is
125
+ committed, and a hostile edit could redirect the secret to a registry nobody chose. pnpm drops
126
+ the line with a warning and the install fails as unauthorized. So the credential goes in Vercel's
127
+ `NPM_RC` environment variable, which Vercel writes to the build container's user-level `~/.npmrc`,
128
+ where pnpm still expands it. `spfn add vercel` prints the exact block to paste.
122
129
 
123
130
  Existing files are never overwritten; they are reported and skipped. The runtime behind
124
131
  the adapter is `createServerlessApp()` from `@spfn/core/server`. Afterwards, point
@@ -138,9 +145,15 @@ no pre-build needed.
138
145
  | `-p, --port <port>` | SPFN server port (sets `SPFN_PORT`) | `spfn.config.js` `ports.server`, then `8790` |
139
146
  | `-H, --host <host>` | SPFN server host (sets `SPFN_HOST`) | `spfn.config.js` `host`, then `localhost` |
140
147
  | `--allow-pending-migrations` | Start even when migrations are pending (they are listed as a warning) | off |
148
+ | `--no-agent-files` | Do not write the SPFN instruction block into `AGENTS.md` (same as `SPFN_AGENT_FILES=0`) | writes on |
141
149
 
142
150
  Note: hot reload is **off by default** — pass `--watch` to restart on file changes.
143
151
 
152
+ On startup `spfn dev` refreshes a marked block of SPFN conventions in the project's
153
+ `AGENTS.md` (creating the file, and a `CLAUDE.md` that references it, when absent) so
154
+ coding agents read the right idioms. Only the marked region is rewritten, and only when
155
+ its content actually changed.
156
+
144
157
  Pending migrations stop the boot — see [Database](#spfn-db) for what the refusal looks
145
158
  like and how to override it.
146
159
 
@@ -263,7 +276,7 @@ loaded `.env` chain.
263
276
  | `db generate` (`g`) | Generate migrations from schema changes (timestamp-prefixed) |
264
277
  | `db push` | Diff with Drizzle Kit's current PostgreSQL engine and apply the selected DDL atomically. Destructive changes need confirmation; `--force` applies them, `--dry-run` previews |
265
278
  | `db migrate` (`m`) | Run pending migrations. `--with-backup` snapshots first |
266
- | `db status` | Show which migrations are applied and which are pending, for the project and for each installed function package |
279
+ | `db status` | Show which migrations are applied and which are pending, for the project and for each installed function package. `--json` prints one machine-readable report instead |
267
280
  | `db studio` | Open Drizzle Studio. `-p, --port` (auto-finds a free port) |
268
281
  | `db check` | Verify the database connection |
269
282
  | `db drop` | Drop all tables — **destructive**, double-prompts (see [Pitfalls](#pitfalls)) |
@@ -508,6 +521,162 @@ Because the package is the app's, it is resolved **from the directory the comman
508
521
  Run `spfn ops token` from the app's root; running it elsewhere reports the package as
509
522
  missing, and the message names the directory it looked in.
510
523
 
524
+ ### `spfn kit`
525
+
526
+ Install, verify and update a **Superfunction Kit** — a licensed product that ships as a
527
+ signed release: an SPFN scaffold, an exact dependency graph, files the Kit manages on the
528
+ customer's behalf, and its own tooling. `spfn kit` is the generic installer for all of
529
+ them. It hard-codes no product: which Kit, which packages and which files are managed all
530
+ come from the signed setup descriptor and release manifest, and every judgement specific to
531
+ a product comes from that product's own `/tooling` entry, which the CLI *discovers* among
532
+ the packages the manifest installs.
533
+
534
+ There is one binary and one command group. No Kit gets its own CLI.
535
+
536
+ | Subcommand | Description |
537
+ |------------|-------------|
538
+ | `kit install <setup-url> <dir>` | Install the newest entitled stable release into a new or empty directory: verify the setup link, activate the license, create the SPFN base, materialize the managed files, install the exact graph, run migrations, run the gates, write the lock and make the first commit |
539
+ | `kit restore` | Reinstall the exact release a clean clone records, using the committed lock and this machine's credential. Rewrites no source file |
540
+ | `kit status` | Read-only report: installed release, activation, credential, managed drift, migrations, open operation. Anything the CLI could not determine is reported as `unknown` |
541
+ | `kit check` | Read-only contract check with stable diagnostic codes, the path each is about, and the command that would fix it |
542
+ | `kit plan [--to <release>]` | What an update would change, with the approval digest. Writes nothing |
543
+ | `kit update [--to <release>] [--approve-plan <digest>]` | Update through the signed update edges, then gates, lock and commit |
544
+ | `kit resume [operation-id]` | Continue an operation that stopped — after re-reading the project and confirming the recorded checkpoints still hold |
545
+ | `kit abandon [operation-id]` | Record that an operation will not be finished, and report what it left behind. Deletes and rolls back nothing |
546
+
547
+ **Secrets never travel as arguments.** There is no `--license-key <value>` option, by
548
+ design: a secret on a command line is in the process table, the shell history and every log
549
+ that records an argv. A key arrives either through a masked prompt or through
550
+ `--license-key-stdin`. Once activation succeeds the key is discarded and only the local
551
+ credential the server issued remains, in the OS keychain under its own service
552
+ (`superfunction.spfn.kit`), separate from the env secrets `spfn secret` manages. The
553
+ short-lived registry session is handed to the package-manager child process in its
554
+ environment and nowhere else, as npm configuration addressed to the registry it opens
555
+ (`npm_config_//host/npm/:_authToken`). The committed `.npmrc` maps the release's scopes to
556
+ that registry and carries no credential at all — not a value, and not a variable naming
557
+ one: pnpm 10 and later ignore a credential that reaches them from a project `.npmrc`, because that
558
+ file is committed and a hostile edit could send the secret to another registry.
559
+
560
+ **`--json` is the agent surface.** Every subcommand takes it, prints newline-delimited
561
+ events with a stable `code`, `phase` and safe next command, and never opens a prompt. A
562
+ JSON-mode command that needs a secret exits `2` and reports `input: masked-stdin`.
563
+
564
+ | Exit | Meaning |
565
+ |-----:|---------|
566
+ | `0` | Completed, or an idempotent no-op |
567
+ | `2` | Waiting for a person: a secret on stdin, or an exact plan approval |
568
+ | `3` | Recoverable failure — `spfn kit resume` can continue it |
569
+ | `4` | Refused before any write: drift, compatibility, entitlement or a busy project |
570
+ | `5` | An external service could not be reached |
571
+ | `10` | This CLI and the release speak different protocol versions |
572
+
573
+ **What an install does not do.** It stops at a verified local repository: no cloud account
574
+ is linked, nothing is pushed, nothing is deployed. That is a checkpoint for the agent to
575
+ continue from, not a finished product install.
576
+
577
+ **Approval is exact.** A breaking release or an external effect requires the digest of the
578
+ very plan being run (`--approve-plan`), which can only be obtained by reading the plan.
579
+ There is no blanket `--yes`.
580
+
581
+ **One operation at a time.** A project holds a filesystem lock while a write operation
582
+ runs. A lock left behind by a dead process is not simply deleted — it is reconciled against
583
+ the operation journal, and reclaimed only when that journal agrees the work is over or the
584
+ caller is resuming exactly the operation it belongs to.
585
+
586
+ Generated state lives under `.spfn/`: `license.json` and `kit-lock.json` are committed and
587
+ hold public identifiers only; `operations/` is per-machine and gitignored.
588
+
589
+ **Exactness is proved, not assumed.** Before the package manager runs, every package the
590
+ signed manifest names is fetched through the licensed registry proxy and checked twice: the
591
+ version's integrity against the digest the manifest pinned, then the bytes that actually
592
+ arrived against that same digest. The first says the registry agrees with the release; only
593
+ the second says the file on this disk is the file the release described. The project's base
594
+ arrives the same way — one scaffold archive, verified against the manifest's integrity
595
+ before a single file is expanded, and refused outright if it names a path that would leave
596
+ the project directory or overwrite a file that is already there.
597
+
598
+ **An artifact is written as what it is.** A managed bridge is a file, and its
599
+ bytes are the file. The scaffold and the Agent Pack are archives, and the CLI expands them —
600
+ the pack into `.spfn/agent-pack/`, because a release's guides, schemas and checklists are a
601
+ directory and belong to the release rather than among customer source. Both are proven
602
+ against the manifest's digest before they are opened, and both refuse an entry that is a
603
+ symlink or that would be written outside the project. What the pack expanded to is recorded
604
+ in `.spfn/agent-pack.json` so drift can compare the tree file by file.
605
+
606
+ **A materialize that stopped can be resumed.** Coming back to a half-written tree compares
607
+ rather than overwrites: a file already holding exactly the bytes the release would write
608
+ counts as done and the resume continues past it, and a file holding anything else is refused
609
+ with that file left exactly as it was found. An update is the one operation that replaces —
610
+ and only after drift has already been refused, so every managed file is known to hold the
611
+ previous release's bytes rather than somebody's edit.
612
+
613
+ **Release files are paid content, and are fetched as such.** Managed files, agent packs and
614
+ the scaffold archive go out with the same bearer the private registry takes, and a refusal
615
+ comes back in the same vocabulary — so "this machine's credential has been replaced" never
616
+ arrives disguised as "that file is missing". The setup descriptor, the release catalog and
617
+ the manifests stay public and carry no bearer: they are locators and promises about a
618
+ release, and nothing anyone paid for is inside them.
619
+
620
+ **Credentials rotate before they expire, not after.** A local credential opens the registry
621
+ for a limited window. When that window is close to closing, the CLI asks the control plane
622
+ for a replacement and writes it to the keychain *before* using it — a rotation that was not
623
+ recorded can never have happened. A credential another machine has already replaced is
624
+ reported as stale rather than as missing: the two mean different things, and only one of
625
+ them means someone else's machine changed.
626
+
627
+ **Nothing secret is ever an argument.** That now includes the keychain write itself: the
628
+ `security` command goes in on stdin and the value goes in hex-encoded, so a local `ps` sees
629
+ `security -i` and nothing else. It also means a keychain item can hold a value a quoted
630
+ command line could not have carried at all, such as a multi-line key.
631
+
632
+ **Machine-local state stays local.** `spfn kit` writes `.spfn/.gitignore` covering
633
+ `operations/` the moment it creates that directory — in its own directory, never in the
634
+ project's root `.gitignore`, which belongs to the customer. Without it a release whose
635
+ scaffold forgot the rule would commit an operation journal and a lock naming the machine's
636
+ hostname and process id.
637
+
638
+ All ten places `spfn kit` touches the outside world are real implementations now. Six reach
639
+ the network or a release artifact — signed catalogs and manifests, licence activation,
640
+ credential rotation, the registry proxy, release artifacts and the scaffold — and four run
641
+ something on this machine: `pnpm install --frozen-lockfile`, the migrations through
642
+ `spfn db status --json` and `spfn db migrate`, the release's gates as the project's own
643
+ scripts, and Git for `init`, `status` and the first commit. Nothing else: no remote is
644
+ added and nothing is pushed.
645
+
646
+ What still stops a real install is the trust root. The list of keys this CLI will accept a
647
+ signed release from is **empty in this build**, because the release signing key is not
648
+ published yet — so every signed document fails verification with `KIT_MANIFEST_INVALID`,
649
+ which is the correct behaviour for a CLI that cannot yet tell a real release from a forged
650
+ one. `SPFN_KIT_TRUSTED_KEYS` supplies a list for a staging run or a release rehearsal, as a
651
+ JSON array of `{ "keyId", "publicKey" }` with base64 SPKI keys. It *replaces* the built-in
652
+ list rather than adding to it.
653
+
654
+ `SPFN_KIT_SETUP_ALLOWLIST` names the origins a setup link may be fetched from, as a
655
+ comma-separated list of bare origins. It follows the same rule as the key list — it
656
+ *replaces* the shipped one, so it can only ever narrow what this CLI will fetch a descriptor
657
+ from — and it is the one place plain `http` is accepted, for `localhost` and `127.0.0.1`
658
+ only, matched literally so a name like `127.0.0.1.example.test` is not one of them. A path,
659
+ a query, a fragment, userinfo, or a non-loopback `http` entry makes the whole variable
660
+ invalid rather than being quietly trimmed. A setup link may carry an explicit port, which is
661
+ what lets a certification environment serve one; the link itself must still be `https`
662
+ unless its origin is loopback *and* on the list.
663
+
664
+ `SPFN_KIT_CONTROL_PLANE_URL` and `SPFN_KIT_REGISTRY_URL` point a project that has *not yet
665
+ been activated* at a staging or local control plane. They are ignored once it has: the
666
+ addresses a checkout recorded when it was licensed are the addresses it keeps, so a stray
667
+ shell variable cannot move an activated project onto another service.
668
+
669
+ `status` and `check` never depend on any of it: an unreachable remote must not hide local
670
+ state, so they read the lock, the license file, the drift and the open operation from disk
671
+ and report everything else as `unknown`.
672
+
673
+ The command surface, journal, lock, keychain, verification and the whole install →
674
+ activation → exact frozen install → restore path are exercised in `test/kit/`: the remote
675
+ half against a loopback HTTP fixture answering with the licence service's and the registry
676
+ proxy's own statuses and error bodies, the scaffold against real archives on real temporary
677
+ directories, and one integration case that runs the whole install with pnpm resolving from
678
+ a registry on 127.0.0.1, the gate as a real child process and a real Git commit at the end.
679
+
511
680
  ---
512
681
 
513
682
  ## Scaffold structure