Make CLI success output copy-paste-safe; add --serve, docs hub, key hygiene

A successful clone printed a bare, timestamped app path that wrapped mid-word
in the terminal, so users' `cd` failed and `npm install && npm run dev` ran in
the wrong directory — a confusing failure from a successful clone. Plus there
was no first-party "see it locally" path, no central docs page, "clone" was
conflated with `git clone`, and key hygiene wasn't stated.

CLI (compiler):
- Add compiler/src/cliSummary.ts: a copy-paste-safe success block on stderr — a
  single QUOTED `cd "<app>" && npm install && npm run dev` line that survives
  terminal wrapping — plus the AGENTS.md safe-to-edit pointers (content.ts,
  components/). The machine-readable {"event":"done",...} JSON stays on stdout.
- Add --serve (npm install + npm run dev in the generated app) and --open
  (also open the browser at the detected dev URL). Wired into single + multi.
- Add writeLatestPointer(): refresh a runs/<site>/latest symlink to the newest
  run so there's a stable, timestamp-free cd/script target. The reuse/regen
  scanners already filter to digit-prefixed run dirs, so `latest` is ignored.
- Tests: cliSummary (quoting, single-line command, Next/Vite roots, stable-path
  preference, --serve/--open hint) and runsLayout (symlink write + in-place
  refresh, timestamp-free stable path).

Docs:
- Add docs/README.md as a central documentation index.
- State prominently that ditto "cloning" = generating a codebase from a live
  URL, NOT `git clone` (no source repo required), in README + docs hub.
- Add "keys are secrets: use $DITTO_API_KEY, never inline/commit, rotate
  anytime" beside the key/auth examples in README + docs/SERVICE.md.
- Document --serve/--open and the latest symlink in README + compiler/README.

Note: the live ditto.site/docs web route and the dashboard's inline-token
snippet live in the marketing-site repo and still need a change there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Michael Cole
2026-07-01 17:10:02 -04:00
co-authored by Claude Opus 4.8
parent 638a0516c5
commit 63df38105d
10 changed files with 364 additions and 11 deletions
+31
View File
@@ -0,0 +1,31 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, mkdirSync, existsSync, readlinkSync, realpathSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { writeLatestPointer } from "../src/cli.js";
describe("writeLatestPointer", () => {
it("writes latest.json and a `latest` symlink to the newest run, refreshing it in place", () => {
const runs = mkdtempSync(join(tmpdir(), "ditto-runs-"));
const siteId = "example.com";
const run1 = join(runs, siteId, "20260701-100000");
mkdirSync(join(run1, "generated", "app"), { recursive: true });
const stable1 = writeLatestPointer(runs, siteId, run1);
assert.ok(existsSync(join(runs, siteId, "latest.json")), "writes latest.json breadcrumb");
assert.ok(stable1 && existsSync(stable1), "returned stable app path resolves through the symlink");
assert.equal(realpathSync(readlinkSync(join(runs, siteId, "latest"))), realpathSync(run1));
// A second run must re-point the existing symlink, not throw on the collision.
const run2 = join(runs, siteId, "20260701-200000");
mkdirSync(join(run2, "generated", "app"), { recursive: true });
const stable2 = writeLatestPointer(runs, siteId, run2);
assert.equal(realpathSync(readlinkSync(join(runs, siteId, "latest"))), realpathSync(run2));
assert.ok(stable2 && existsSync(stable2));
// The stable path is timestamp-free (goes through `latest`, not the run's timestamp).
assert.match(stable2!, /example\.com\/latest\/generated\/app$/);
});
});