From 51448b7668cd71e34bdb85f8406556a76cd0c8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Verheij?= <341567+flyon@users.noreply.github.com> Date: Mon, 2 Nov 2026 06:08:27 +0000 Subject: [PATCH 01/25] Describe the host app generically in comments and docs; no app named by its name or domain --- README.md | 4 +- ...ambients-in-packages-that-import-no-css.md | 2 +- ...check-skips-unbuilt-linked-dependencies.md | 2 +- ...tree-app-workspace-members-link-to-main.md | 6 +-- .../012-drop-the-retired-flag-fallback.md | 2 +- .../backlog/013-master-worktrees-remaining.md | 14 ++--- docs/backlog/014-checking-components-index.md | 2 +- docs/backlog/016-branch-key-follow-ups.md | 4 +- ...orktree-link-farm-loads-two-core-copies.md | 22 ++++---- docs/integration-branches-and-worktrees.md | 10 ++-- docs/reports/048-no-host-app-mentions.md | 54 +++++++++++++++++++ src/cli-methods.ts | 8 +-- src/commands/setup-publish.ts | 2 +- src/commands/start.ts | 14 ++--- src/installed-packages.ts | 2 +- src/integration/credentials.ts | 2 +- src/integration/masters.ts | 2 +- src/interfaces.ts | 2 +- src/lifecycle.ts | 6 +-- src/utils/componentsTurtle.ts | 2 +- src/utils/ontologyModules.ts | 2 +- src/utils/ontologyNamespace.ts | 2 +- src/utils/packageFiles.ts | 2 +- src/utils/packageKind.ts | 2 +- src/utils/packageManager.ts | 2 +- src/vite-config.ts | 10 ++-- src/workspace-globs.ts | 2 +- 27 files changed, 119 insertions(+), 65 deletions(-) create mode 100644 docs/reports/048-no-host-app-mentions.md diff --git a/README.md b/README.md index d584ab5a..a6486035 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ its export name, start shape, query shape and query wire format; other exports a `node` process loads the built `package.js`, `shapes/index.js` and `components/index.js` (asset imports such as `.css` and `.svg` stubbed) and calls `componentIndexTurtle(, )` from the `@_linked/react/utils/componentIndex` that the package resolves. The bytes are -deterministic: Create Now stores the file's triples and replaces them when its hash changes. No +deterministic: a host app that stores the file's triples and replaces them when its hash changes can rely on that. No `components/index`, no `@_linked/react` dependency or no linked component gives no file (one left by an earlier build is removed); a react without `utils/componentIndex` warns and writes none; a component whose query does not serialize is left out with a warning; a module that throws fails the @@ -507,7 +507,7 @@ linked release plan # per repo: commits, reports, linked doctor resolve # where Vite and Node load each @_linked package; exit 1 on two copies ``` -**Branch checkouts** (a server making one checkout per project branch, such as Create Now): +**Branch checkouts** (a server making one checkout per project branch, such as a hosting app): `linked checkout ` in a projects root makes one bare base clone per repo (`/.repos//.git`), the app as a worktree on `` (created from `--from` and pushed when the remote lacks it) and each package of `linked.unpublishedPackages` as a diff --git a/docs/backlog/006-css-module-ambients-in-packages-that-import-no-css.md b/docs/backlog/006-css-module-ambients-in-packages-that-import-no-css.md index bce9e122..c322ba88 100644 --- a/docs/backlog/006-css-module-ambients-in-packages-that-import-no-css.md +++ b/docs/backlog/006-css-module-ambients-in-packages-that-import-no-css.md @@ -35,7 +35,7 @@ now, so this is a change to the published type surface and belongs in a coordina in a drive-by sweep. Nobody has measured whether anything actually imports `/types`. That measurement — a search -across the fleet and CN for `from '@_linked/*/types'` — is the first step, and may turn this into +across the fleet and the apps built on it for `from '@_linked/*/types'` — is the first step, and may turn this into a trivially safe removal. ## Scoping note diff --git a/docs/backlog/009-build-check-skips-unbuilt-linked-dependencies.md b/docs/backlog/009-build-check-skips-unbuilt-linked-dependencies.md index db752633..089887b7 100644 --- a/docs/backlog/009-build-check-skips-unbuilt-linked-dependencies.md +++ b/docs/backlog/009-build-check-skips-unbuilt-linked-dependencies.md @@ -10,7 +10,7 @@ status: Open -- the partly stale lib case; the main case is fixed (report 035) # 009 — The build check skips a dependency's register modules its `lib/` lacks -Source: CN plan 070, independent review of `store-inference` (report 025). The unbuilt-dependency +Source: independent review of `store-inference` (report 025). The unbuilt-dependency case is fixed in report 035: `collectShapeCheckInputs` sets `tsLoader` when a dependency has register modules only in `src/`, and the check's child passes core an `importModule` through the cli's TS loader. diff --git a/docs/backlog/011-worktree-app-workspace-members-link-to-main.md b/docs/backlog/011-worktree-app-workspace-members-link-to-main.md index ab653c9c..b43e537f 100644 --- a/docs/backlog/011-worktree-app-workspace-members-link-to-main.md +++ b/docs/backlog/011-worktree-app-workspace-members-link-to-main.md @@ -1,6 +1,6 @@ --- -summary: In an agent worktree the link farm points the app's own workspace members (CN's `packages/*`) at the main checkout, so a change to one of their `package.json` files is invisible to the worktree's server, build-all and tests. Found when step RK changed `linked.kind` in CN's `packages/*`. -source: CN master plan 057, steps LK and RK (cli reports 032, 033), 27 Oct 2026 +summary: In an agent worktree the link farm points the app's own workspace members (e.g. `packages/*`) at the main checkout, so a change to one of their `package.json` files is invisible to the worktree's server, build-all and tests. Found when step RK changed `linked.kind` in the app's `packages/*`. +source: steps LK and RK (cli reports 032, 033), 27 Oct 2026 --- # Worktree: the app's own workspace members link to the main checkout @@ -10,7 +10,7 @@ source: CN master plan 057, steps LK and RK (cli reports 032, 033), 27 Oct 2026 `linked worktree add` links `node_modules/` of the app's own workspace members (`packages/access`, `packages/maps`, `my-app`, …) to the main checkout's entries, which resolve to the main checkout's `packages/`. Report 031 lists it under Limitations. When a worktree -changes one of those directories, the worktree's CN, `build-all` and `discoverLinkedDependencies` +changes one of those directories, the worktree's app server, `build-all` and `discoverLinkedDependencies` read the main checkout's copy instead. Seen in step RK: the worktree's `packages/{access,documents,maps,execution-gateway}` had diff --git a/docs/backlog/012-drop-the-retired-flag-fallback.md b/docs/backlog/012-drop-the-retired-flag-fallback.md index afe512df..68e7079b 100644 --- a/docs/backlog/012-drop-the-retired-flag-fallback.md +++ b/docs/backlog/012-drop-the-retired-flag-fallback.md @@ -8,7 +8,7 @@ packages: [cli, server] # Drop the retired-flag fallback -The release of CN plans 057/070 had to bridge two CLIs: +The release of the `linked.kind` flags and store inference had to bridge two CLIs: - The published CLI (1.57.x) builds a package only with `linkedPackage: true`, and CI and the publish workflow build every package with the published CLI. So this package's own diff --git a/docs/backlog/013-master-worktrees-remaining.md b/docs/backlog/013-master-worktrees-remaining.md index 7428c237..5c5c44a8 100644 --- a/docs/backlog/013-master-worktrees-remaining.md +++ b/docs/backlog/013-master-worktrees-remaining.md @@ -37,20 +37,20 @@ relinks every worktree after an install. What still blocks running them side by worktree's farm links `.bin/linked` to that same unbuilt CLI. The first build there runs the main checkout's bin (`
/node_modules/.bin/linked build`); `worktree add`/`branch start` could print that, or fall back to it. -- **`worktree remove ` does not find a master's step by its agent name** (step SY of CN - plan 282). Run from the app's main checkout: +- **`worktree remove ` does not find a master's step by its agent name** (step SY of a + master). Run from the app's main checkout: `npx linked worktree remove sy` → - ``No worktree of /Users/rene/web/create_now for sy: none on dev--sy, nor at /Users/rene/web/wt/sy. + ``No worktree of
for sy: none on dev--sy, nor at /Users/rene/web/wt/sy. Pass its directory with --dir; `linked worktree list` shows the worktrees.`` while `linked worktree list` showed `step sy /Users/rene/web/wt/hub-imports--sy`. It worked with `npx linked worktree remove sy --dir /Users/rene/web/wt/hub-imports--sy` (and then kept the landed `hub-imports--sy` branches: `@_linked/core: kept hub-imports--sy (not dev--sy).`). `remove` should look up `--` steps as `list` does. -- **A step with its own framework package loads two copies of it.** The link farm points CN's +- **A step with its own framework package loads two copies of it.** The link farm points the app's `@_linked/core` at the step's checkout, while the main install's other `@_linked/*` packages - (`@_linked/fuseki`, `@_linked/access`, …) resolve core from the main checkout. CN's + (`@_linked/fuseki`, `@_linked/access`, …) resolve core from the main checkout. The app's `npm run typecheck:gate` in step SY's worktree reported 117 errors, every one between - `…/hub-imports--sy/packages-local/_linked-core/…` and `…/create_now/packages-local/_linked-core/…` + `…/hub-imports--sy/packages-local/_linked-core/…` and `…/
/packages-local/_linked-core/…` types (e.g. `FusekiStore` not assignable to `IDataset`); with `paths` mapping `@_linked/core` to the step's build, `tsc` gave 0 errors. The farm could link every package that depends on a `--with` package so it resolves the step's copy, or `worktree add` could print the `paths` @@ -58,7 +58,7 @@ relinks every worktree after an install. What still blocks running them side by - **A master with core, server or react needs every localized dependent in it too.** Master `hub-imports` started `--with core,server,react,cli`; its farm linked those to its checkouts while the other localized packages (auth, fuseki, server-utils, schema, …) resolved core from the main - checkout: two cores, and CN's `npm run typecheck:gate` there reported ~117 errors. Fixed by hand + checkout: two cores, and the app's `npm run typecheck:gate` there reported ~117 errors. Fixed by hand with `branch add-package hub-imports` of the 19 localized packages that depend on them (transitively), `linked build-all` in the master (26 packages, 6 min), `worktree relink`: `doctor resolve` then showed every `@_linked/*` but css in the master, and the gate gave `No new type diff --git a/docs/backlog/014-checking-components-index.md b/docs/backlog/014-checking-components-index.md index 1c161b5e..d59913e8 100644 --- a/docs/backlog/014-checking-components-index.md +++ b/docs/backlog/014-checking-components-index.md @@ -10,7 +10,7 @@ status: open `linked build` indexes only the linked components exported from `src/components/index.ts` (`Writing components.ttl`, report 042). A component defined in a module that the index does not -export is silently absent from the component index, so Create Now's builder never offers it. +export is silently absent from the component index, so a host app's builder never offers it. **Idea.** A step `Checking components/index`, next to `Checking shapes/index` (`src/utils/shapesIndex.ts` is the precedent): load each compiled module under diff --git a/docs/backlog/016-branch-key-follow-ups.md b/docs/backlog/016-branch-key-follow-ups.md index f4443111..56560b47 100644 --- a/docs/backlog/016-branch-key-follow-ups.md +++ b/docs/backlog/016-branch-key-follow-ups.md @@ -17,8 +17,8 @@ status: open refusal. 2. **Formatting.** The strip parses `package.json`, deletes the keys and writes it with the file's indent and trailing newline (and CRLF when the file has it). An object the file kept on one line - (`{"repo": "…"}`) comes back expanded. npm and Create Now write `JSON.stringify(…, null, 2)`, so + (`{"repo": "…"}`) comes back expanded. npm and the usual tools write `JSON.stringify(…, null, 2)`, so in practice nothing moves; a text-level edit would keep any layout. -3. **Setting a key.** Nothing in the cli writes a `branch` key; Create Now edits `package.json` +3. **Setting a key.** Nothing in the cli writes a `branch` key; a host app edits `package.json` itself. A `linked use --branch ` (and `--clear`) would give developers the same, if wanted. diff --git a/docs/backlog/017-worktree-link-farm-loads-two-core-copies.md b/docs/backlog/017-worktree-link-farm-loads-two-core-copies.md index e0bddc06..575156ea 100644 --- a/docs/backlog/017-worktree-link-farm-loads-two-core-copies.md +++ b/docs/backlog/017-worktree-link-farm-loads-two-core-copies.md @@ -1,11 +1,11 @@ --- summary: > - A CN worktree made with `linked worktree add ct --with @_linked/core` loads core from the + An app worktree made with `linked worktree add ct --with @_linked/core` loads core from the worktree's checkout, while installed `@_linked/*` packages still resolve the main checkout's - core. CN runs two copies, and `typecheck:gate` reports 118 errors between the two `IDataset` + core. The app runs two copies, and `typecheck:gate` reports 118 errors between the two `IDataset` types, although both `lib` .d.ts trees are identical. May overlap backlog 013 ("Refusing a second copy"). -source: CN master side-225 (step ct), 30 Oct 2026 +source: an app master (step ct), 30 Oct 2026 status: open --- @@ -13,19 +13,19 @@ status: open ## Observed -A CN worktree `wt/ct`, made with `npx linked worktree add ct --with @_linked/core`, during -`npm run test:regular` (log: `ct-regular.log` in the side-225 master's scratchpad): +An app worktree `wt/ct`, made with `npx linked worktree add ct --with @_linked/core`, during +`npm run test:regular` (log: `ct-regular.log` in the master's scratchpad): ``` -[CN-err] [localize] drift: second copy of localized @_linked/core@2.45.0 at node_modules/@_linked/core -[CN-err] [linked] @_linked/core is installed 2 times (2.45.0 at /Users/rene/web/create_now/packages-local/_linked-core, 2.45.0 at /Users/rene/web/wt/ct/packages-local/_linked-core); loaded /Users/rene/web/wt/ct/packages-local/_linked-core. +[app-err] [localize] drift: second copy of localized @_linked/core@2.45.0 at node_modules/@_linked/core +[app-err] [linked] @_linked/core is installed 2 times (2.45.0 at
/packages-local/_linked-core, 2.45.0 at /Users/rene/web/wt/ct/packages-local/_linked-core); loaded /Users/rene/web/wt/ct/packages-local/_linked-core. ``` `typecheck:gate` then failed: ``` NEW type error(s) not in the baseline: 118 - src/backend/people/displayNames.ts: TS2345: Argument of type 'import("/Users/rene/web/wt/ct/packages-local/_linked-core/lib/esm/interfaces/IDataset").IDataset' is not assignable to parameter of type 'import("/Users/rene/web/create_now/packages-local/_linked-core/lib/esm/interfaces/IDataset").… + src/backend/people/displayNames.ts: TS2345: Argument of type 'import("/Users/rene/web/wt/ct/packages-local/_linked-core/lib/esm/interfaces/IDataset").IDataset' is not assignable to parameter of type 'import("
/packages-local/_linked-core/lib/esm/interfaces/IDataset").… src/backend/shapes/BranchProvider.ts: TS2416: Property 'shape' in type 'BranchProvider' is not assignable to the same property in base type 'ShapeProvider'. src/backend/shapes/OntologyTermSearchProvider.ts: TS2322: Type 'FusekiStore' is not assignable to type 'IDataset'. ``` @@ -38,7 +38,7 @@ paths), not from a change in core. The farm links `@_linked/core` to the worktree's checkout, but the other installed `@_linked/*` packages (`server-utils`, `server`, …) are links to their real paths in the main checkout's `node_modules`. Node and `tsc` resolve their own `import '@_linked/core'` from that real path, so -they climb to `create_now/node_modules/@_linked/core`, the main checkout's core. Every package +they climb to `
/node_modules/@_linked/core`, the main checkout's core. Every package that depends on a `--with` package, and is not itself in the worktree, keeps the main copy. ## First questions @@ -52,7 +52,7 @@ that depends on a `--with` package, and is not itself in the worktree, keeps the ## Seen again: master `one-read-method` (core plan 111), 1 Nov 2026 -Evidence in CN report 397 ("Two copies of core: the evidence"). Here the second copy was not a +Here the second copy was not a stale duplicate but an older core: the master changed `IDataset`, and the main checkout's core still had the old read methods, so the failures looked like real bugs. @@ -61,7 +61,7 @@ had the old read methods, so the failures looked like real bugs. `packages-local/`: `@_linked/css`, `dcat`, `dcmi`, `icons`, `npm`, `org`, `owl`, `primitives`, `rdfs`, `s3`, `schema`, `sentry`, `sioc`, `translation`, `xsd`, `@linked.cm/zoho-cpaas` and `@semantu/webid-email`. Their own `import '@_linked/core'` climbs from their real path to - `/Users/rene/web/create_now/packages-local/_linked-core`. + `
/packages-local/_linked-core`. - tsc: `NEW type error(s) not in the baseline: 63`, all of them `IDataset`/`Transaction`/ `FusekiStore` identity errors between the two copies. `tsc --explainFiles` named the importers of the main copy: `_linked-schema` (3038 imports), `_linked-translation` (200), `_linked-dcmi` (113), diff --git a/docs/integration-branches-and-worktrees.md b/docs/integration-branches-and-worktrees.md index 353bd7a4..f417c9ae 100644 --- a/docs/integration-branches-and-worktrees.md +++ b/docs/integration-branches-and-worktrees.md @@ -396,7 +396,7 @@ and `branch..linked-worktree` (that repo's worktree), and in the app repo of a repo, so the records are read from anywhere in the app. The preview port is the first of 4510, 4520, … 4590 no master on this machine holds (outside a -CN's live-app band 4000-4399, inside the 4000-4999 a local webid.email signs clients in from; +host app's live-app band 4000-4399, inside the 4000-4999 a local webid.email signs clients in from; `port + 1` is for the master's test runs, `port + 2` to `port + 9` for its steps), or `--port`. "On this machine" means this app's masters (its git config) and the **port registry** `~/.linked/master-ports.json` (`$LINKED_HOME` overrides `~/.linked`), which maps each port to @@ -504,7 +504,7 @@ target}], relinked: [], messages}`. ## `linked checkout ` A branch checkout of an app and the packages it lists in `linked.unpublishedPackages`, made for a -server that keeps one checkout per project branch (Create Now) — not for a developer's app (one +server that keeps one checkout per project branch (a hosting app) — not for a developer's app (one clone with [`linked localize --listed`](localize.md#commands)) nor an agent's worktree (`linked worktree add`, which shares the main checkout's install). @@ -565,8 +565,8 @@ Re-runs in either pins mode: a detached pinned worktree fast-forwards to `origin a clean worktree whose head origin has moves to its new target when the pins change (`switched`: to another pin, or back to `origin/`); one with uncommitted changes or commits origin lacks is `kept`. In pins mode `--add` reads a package's -name on its default branch. Without a pin (flag or key) and `--pins-only` nothing of this applies. Create Now -passes `--pins-only` and no `--pin`: the app branch's keys are its pins. +name on its default branch. Without a pin (flag or key) and `--pins-only` nothing of this applies. A hosting app +may pass `--pins-only` and no `--pin`: the app branch's keys are its pins. **The list, transitively.** From the app worktree's committed `package.json`, breadth first: each listed package's worktree is made, then its own `package.json` (on its branch, or its @@ -593,7 +593,7 @@ pushed. its npm name is what its `package.json` declares on `` (else on its default branch), its worktree is `packages-local/` by the same branch rule, under its base clone's lock, and the result marks it `"added": true`. It never makes the install run and is never built, so adding it -leaves the app's `package.json` and lock as committed (Create Now edits a workspace ontology the app +leaves the app's `package.json` and lock as committed (a hosting app can edit a workspace ontology the app does not use this way). It is still in the `packages-local/*` glob: an install a later run makes for a listed package links it like every checkout there, and the app's lock-at-rest hook puts the committed lockfile back. Its npm name must be one (a name that would leave `packages-local/` is diff --git a/docs/reports/048-no-host-app-mentions.md b/docs/reports/048-no-host-app-mentions.md new file mode 100644 index 00000000..7a5c85af --- /dev/null +++ b/docs/reports/048-no-host-app-mentions.md @@ -0,0 +1,54 @@ +--- +date: 2026-11-02 +summary: > + Comments in src/, the README and the current docs (backlog, integration-branches-and-worktrees) + no longer name a particular private host app or point at its docs; they describe the host + generically. Comments and docs only, no behaviour change, no changeset. Five user-facing message + strings in the worktree and master commands still name the host's scripts and are left as code. +packages: [cli] +--- + +# 048 — No mentions of a particular host app + +The cli is open source; comments and docs named one private app built on it, cited its backlog +and architecture docs, and used its domain in an example IRI. They now say "a host app", "a +hosting app", "an app that commits through the GitHub API", and the example IRI uses +`example.org`. + +## PR + +**What changed** + +- `src/`: comments in 19 files rewritten generically, meaning kept (`lifecycle.ts`, `vite-config.ts`, + `cli-methods.ts`, `commands/start.ts`, `commands/setup-publish.ts`, `installed-packages.ts`, + `workspace-globs.ts`, `interfaces.ts`, `integration/credentials.ts`, `integration/masters.ts`, + `utils/{componentsTurtle,ontologyModules,ontologyNamespace,packageFiles,packageKind,packageManager}.ts`). + References to another repo's backlog item and architecture section were dropped; the rule they + pointed to is already stated inline. +- `README.md`, `docs/integration-branches-and-worktrees.md` and backlog items 006, 009, 011, 012, + 013, 014, 016, 017: the host named generically; absolute paths of its checkout replaced by + `
`; a citation of its report dropped. +- No changeset: comments and docs only. + +**Verification** + +- `npx linked build` → `✔ Build successful`. +- `npm run test:unit` → `Test Suites: 103 passed, 103 total`, `Tests: 1267 passed, 1267 total`. +- `npm run test:e2e` → `7 passed (1.3m)`. +- A case-insensitive grep for the host's name, abbreviation and domain over `src`, `package.json`, + `README.md` and `docs` (without `docs/reports` and `docs/plans`) finds only the strings below. + +**Deviations from the plan** + +- Left as code, not comments: `src/commands/worktree.ts:632-638` (checks for and prints the host's + `scripts/backup-cn-state.sh` and a `cn-main` dump) and `src/commands/master.ts:242` and `:494` + (the same hint, and "Restart the CN on …"). Changing them changes output, so they need a decision. +- Not touched: `docs/reports/` and `docs/plans/` (historical records of finished work), + `CHANGELOG.md` (published history), and `tests/` (fixtures and comments there also name the host; + outside this pass's scope). + +**Follow-ups** + +- The five message strings above: make the dataset-clone hint generic or configurable by the app + (e.g. read script names from the app), and say "the app server" in the land message. +- `tests/` comments and fixtures: same cleanup, in a separate pass. diff --git a/src/cli-methods.ts b/src/cli-methods.ts index 7a81deca..2e5c51f8 100644 --- a/src/cli-methods.ts +++ b/src/cli-methods.ts @@ -107,7 +107,7 @@ function defaultsDir(...parts: string[]): string { * to import. A new app root has none (it is an app, `linked.kind: "app"`, not a linked package), so * there the import would be broken: refuse instead. Only the file decides: a * app that keeps its shapes at its root with its own `src/package.ts`, as - * create-now does, is served as before. + * a host app may do, is served as before. */ function assertInsidePackage(sourceFolder: string, command: string) { if (fs.existsSync(path.join(sourceFolder, 'package.ts'))) return; @@ -260,8 +260,8 @@ export const createApp = async (name, basePath = process.cwd(), options: {appNam fs.mkdirSync(targetFolder); } - // Scaffold from the canonical template repo (single source of truth; CN's - // server-side createProject clones the same repo). Shallow clone, then drop + // Scaffold from the canonical template repo (single source of truth; a host + // app that creates apps server-side clones the same repo). Shallow clone, then drop // .git so the new app starts with clean history. await execPromise(`git clone --depth 1 https://github.com/linked-fw/app-template.git "${targetFolder}"`, false, false); fs.removeSync(path.join(targetFolder, '.git')); @@ -577,7 +577,7 @@ function setEnvVar(envText: string, key: string, value: string): string { /** * Stamp the new app's identity into the freshly-cloned template. The template - * ships without `${var}` placeholders (so a raw CN clone boots on defaults), so + * ships without `${var}` placeholders (so a raw clone boots on defaults), so * create-app writes the real per-app values here: * - `.env.example` (committed defaults for this app) + `.env` (local): APP_NAME * drives the display name; APP_PREFIX names data files. diff --git a/src/commands/setup-publish.ts b/src/commands/setup-publish.ts index 044737f8..baf788cd 100644 --- a/src/commands/setup-publish.ts +++ b/src/commands/setup-publish.ts @@ -474,7 +474,7 @@ async function ensureLockfile(cwd: string): Promise { // so any existing lockfile is stale. console.log(chalk.magenta(' Running npm install --package-lock-only...')); - // When running inside a yarn workspace (e.g. CN's packages/* layout), npm + // When running inside a yarn workspace (e.g. a monorepo's packages/* layout), npm // climbs up, detects the parent workspace, and writes the lockfile at the // wrong level. Work around by copying the package to a tmpdir, generating // the lockfile in isolation, and copying it back. diff --git a/src/commands/start.ts b/src/commands/start.ts index f8609957..7acf7dd8 100644 --- a/src/commands/start.ts +++ b/src/commands/start.ts @@ -201,8 +201,8 @@ export async function discoverWorkspacePackages(cwd: string): Promise/src/* trigger HMR for - // the app's own providers (e.g. CN's src/backend.ts which registers ~25 - // Express routes). + // the app's own providers (e.g. a host app's src/backend.ts that registers + // its own Express routes). if (pkgJson.name && (await fsExtra.pathExists(path.join(cwd, 'src')))) { out.push({name: pkgJson.name, root: cwd, srcDir: path.join(cwd, 'src')}); } @@ -429,8 +429,8 @@ export async function startWithVite(opts: StartOptions = {}): Promise { // Load the app's own `.env` (Node 20.12+ `process.loadEnvFile`) if present — the // standard, dependency-free env source for a linked app. Node does NOT override - // vars already set in the environment, so CN's injected per-(project,branch) vars - // (PORT, FUSEKI_DATASET, CN_APP_ADMIN_SECRET, …) take precedence over the file. + // vars already set in the environment, so vars a host app injects per + // (project, branch) (PORT, FUSEKI_DATASET, …) take precedence over the file. try { const envPath = path.join(cwd, '.env'); if ( @@ -443,7 +443,7 @@ export async function startWithVite(opts: StartOptions = {}): Promise { // best-effort — a missing/invalid .env never blocks start } - // `--env` still loads env-cmd (`.env-cmdrc.json`) for CN's own start:local flow. + // `--env` still loads env-cmd (`.env-cmdrc.json`) for apps that still use it. const {ensureEnvironmentLoaded} = await import('../lifecycle.js'); await ensureEnvironmentLoaded(); @@ -475,7 +475,7 @@ export async function startWithVite(opts: StartOptions = {}): Promise { // Load the storage config through Vite SSR so it // configures the SAME LinkedStorage instance the rest of the SSR graph - // (LinkedServer, CN providers) uses. Replaces the former Node-direct + // (LinkedServer, the app's providers) uses. Replaces the former Node-direct // `loadBackendStorageConfig()` (which resolved @_linked/core via the // `default`→lib condition, a SEPARATE instance). Safe now that core's lib // `initTree` is idempotent. `loadBackendStorageConfig` stays in @@ -500,7 +500,7 @@ export async function startWithVite(opts: StartOptions = {}): Promise { // Load LinkedServer through Vite SSR so it shares the SAME // module instances as everything else in the SSR call graph. Without - // this, LinkedServer is loaded by Node (→ lib/esm) while CN's App.tsx + + // this, LinkedServer is loaded by Node (→ lib/esm) while the app's App.tsx + // its transitive imports are loaded by Vite (→ src/). React contexts // created in one tree don't reach consumers in the other, causing // "Cannot destructure property 'isNativeApp' of useAppContext()" type diff --git a/src/installed-packages.ts b/src/installed-packages.ts index 81f479a6..9874d08c 100644 --- a/src/installed-packages.ts +++ b/src/installed-packages.ts @@ -37,7 +37,7 @@ export const isFrameworkPkg = (name: string): boolean => * * Declaring the globs is not enough. An app made from the app template lists * `packages-local/*` so it can localize packages standalone; run inside a - * parent workspace (CN's `packages-local/`) with no checkouts of its own, + * parent workspace (a host app's `packages-local/`) with no checkouts of its own, * it has nothing installed and npm hoisted its dependencies to the parent. * Stopping at the app then missed the parent's `node_modules`: no localized * package was registered as source, while Node walked up to the parent's diff --git a/src/integration/credentials.ts b/src/integration/credentials.ts index 26a312f5..f3e00ece 100644 --- a/src/integration/credentials.ts +++ b/src/integration/credentials.ts @@ -1,7 +1,7 @@ /** * Credentials for the git calls that reach a remote, through the environment only. * - * A caller that needs a token (CN, with a short-lived GitHub App installation token) puts it in + * A caller that needs a token (e.g. a host app with a short-lived GitHub App installation token) puts it in * `LINKED_GIT_TOKEN`; the cli never takes it on the command line and never writes it anywhere. * Every `git clone | fetch | push | ls-remote` the cli runs gets `remoteEnv(env)`: * diff --git a/src/integration/masters.ts b/src/integration/masters.ts index 2c3a494b..f02c267e 100644 --- a/src/integration/masters.ts +++ b/src/integration/masters.ts @@ -32,7 +32,7 @@ export interface Master { dataset: string | null; } -/** Preview ports: one slot per master, `45k0` for k = 1..9, outside a CN's live-app band 4000-4399. */ +/** Preview ports: one slot per master, `45k0` for k = 1..9, outside the live-app band 4000-4399 a host app uses. */ export const MASTER_PORTS = [4510, 4520, 4530, 4540, 4550, 4560, 4570, 4580, 4590]; function configGet(run: Run, repoDir: string, key: string): string | null { diff --git a/src/interfaces.ts b/src/interfaces.ts index b43e23fe..af49814d 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -108,7 +108,7 @@ export interface LinkedConfig { * (`sh:NodeShape`) on boot — so its app-data holds the shapes its instances * validate/query against. Runs in LinkedServer.start()/initOnly(). * @default true - * Set `false` for a server whose default dataset is a context-router (e.g. CN), + * Set `false` for a server whose default dataset is a context-router (e.g. a host app that routes data per project), * or an app that manages its own shape/dataset lifecycle. */ syncShapesOnBoot?: boolean; diff --git a/src/lifecycle.ts b/src/lifecycle.ts index f341af12..84dc4388 100644 --- a/src/lifecycle.ts +++ b/src/lifecycle.ts @@ -38,7 +38,7 @@ import {importFile} from './utils/platform.js'; * `.env` going first is what makes migrating a one-step job: add the flat file * and it takes over. The profile file can then be deleted whenever convenient. * - * If neither file exists we skip silently — CN-hosted apps have their env + * If neither file exists we skip silently — apps run by a host app have their env * injected into the child process at spawn time, so there's nothing to read * from disk. */ @@ -113,7 +113,7 @@ export const envDeprecationNotices = (sources: { /** * Legacy loader: reads `.env-cmdrc.json`, merges `_main` plus the profile(s) - * named by `--env a,b` (default `development`). Kept for CN and existing apps + * named by `--env a,b` (default `development`). Kept for existing apps * until they migrate to a flat `.env`. */ const loadEnvCmdrc = async ( @@ -585,7 +585,7 @@ export function orderBuildToolFirst( * * Every discovered package lands in exactly one of `build` or `skipped`, and * `skipped` carries a reason — because the failure mode this replaces was not - * a narrow scan, it was a SILENT one. `@_linked/maps` is a shipped Create Now + * a narrow scan, it was a SILENT one. `@_linked/maps` is a shipped host-app * dependency that never got the linked-package flag; `build-all` dropped it and * printed nothing, so a build covering half the workspace exited 0 and people * acted on it. A skip nobody can see is worse than a failure. diff --git a/src/utils/componentsTurtle.ts b/src/utils/componentsTurtle.ts index b50e2038..de9c843c 100644 --- a/src/utils/componentsTurtle.ts +++ b/src/utils/componentsTurtle.ts @@ -10,7 +10,7 @@ import {ASSET_HOOK} from './shapeReferences.js'; * * A package offers its components through `components/index` (`lib/esm/components/index.js`): per * linked component it exports, the index holds its export name, start shape, query shape and query - * wire format. A host (Create Now) stores the file's triples as they are and hashes its bytes. The + * wire format. A host app stores the file's triples as they are and hashes its bytes. The * Turtle comes from `componentIndexTurtle(packageName, exports)` of the `@_linked/react` the package * resolves, called in a child `node` that has loaded the built `package.js` (sets the package's * publish root), `shapes/index.js` and `components/index.js`, in that order, with asset imports diff --git a/src/utils/ontologyModules.ts b/src/utils/ontologyModules.ts index 7b17a212..af1bfdeb 100644 --- a/src/utils/ontologyModules.ts +++ b/src/utils/ontologyModules.ts @@ -1,6 +1,6 @@ /** * The accessor modules of an ontology, as text: the one generator `linked generate-ontology` and - * create-now's ontology builder share. + * a host app's ontology builder share. * * An ontology with prefix `

` gets three sibling modules in `src/ontologies/`: * diff --git a/src/utils/ontologyNamespace.ts b/src/utils/ontologyNamespace.ts index 26a79a0c..7e556f36 100644 --- a/src/utils/ontologyNamespace.ts +++ b/src/utils/ontologyNamespace.ts @@ -15,7 +15,7 @@ export const LINKED_ONTOLOGY_ROOT = 'https://linked.cm/ont/'; * (`@_linked/server` → `https://linked.cm/ont/server/`) shares the slug of its shapes. * * Private packages do not use this root: they publish under a workspace-scoped one - * (`https://{workspaceSlug}.id.create.now/ont/{ontologySlug}/`), which the caller passes as the + * (e.g. `https://{workspaceSlug}.id.example.org/ont/{ontologySlug}/`), which the caller passes as the * explicit `uriBase` of `create-package` / `create-ontology`. */ export function defaultOntologyNamespace(name: string): string { diff --git a/src/utils/packageFiles.ts b/src/utils/packageFiles.ts index 472b6430..51aae3a2 100644 --- a/src/utils/packageFiles.ts +++ b/src/utils/packageFiles.ts @@ -1,7 +1,7 @@ /** * The files `linked create-package --kind ontology|assets` produces, as data: * package-relative path → content. `createPackage` writes them; a host that - * commits a package elsewhere (Create Now, through the GitHub API) uses the + * commits a package elsewhere (an app that commits through the GitHub API) uses the * same function, so there is one definition of what a new package holds. * * Pure apart from reading the templates in this package's own `defaults/`: diff --git a/src/utils/packageKind.ts b/src/utils/packageKind.ts index 934c36c2..20b1d4a9 100644 --- a/src/utils/packageKind.ts +++ b/src/utils/packageKind.ts @@ -1,7 +1,7 @@ /** * What `linked create-package` scaffolds, decided without touching anything. * - * A linked package is one of two kinds (create-now arch-03 §Package types): + * A linked package is one of two kinds: * * - an **ontology package**, `-ont`: exactly one ontology and nothing * else. Its ontology slug is `` (no `-ont`), so its terms mint diff --git a/src/utils/packageManager.ts b/src/utils/packageManager.ts index a664bb04..6ff564cb 100644 --- a/src/utils/packageManager.ts +++ b/src/utils/packageManager.ts @@ -15,7 +15,7 @@ const NPM_MARKERS = ['package-lock.json', 'npm-shrinkwrap.json']; * plain `npm`/`npx` is the only thing guaranteed to be on PATH next to node. * yarn is only used when the tree actually says so — a `yarn.lock`, * `.yarnrc.yml` or a vendored `.yarn/releases/` in this directory or an - * ancestor. That keeps existing yarn monorepos (create_now pins yarn 3.6.1) + * ancestor. That keeps existing yarn monorepos (some pin yarn 3.x) * working without assuming yarn anywhere else. * * The nearest marker wins, so an npm package checked out inside a yarn diff --git a/src/vite-config.ts b/src/vite-config.ts index 04e80965..6be68f77 100644 --- a/src/vite-config.ts +++ b/src/vite-config.ts @@ -233,7 +233,7 @@ export interface LinkedViteConfigOptions { * * For apps whose linked-package sources live OUTSIDE their own workspace tree * — e.g. an app consumes `packages/lincd.org/modules/*`, which sit one level - * up (`../lincd.org/modules/*`) when the app runs inside the CN monorepo, and under + * up (`../lincd.org/modules/*`) when the app runs inside a host monorepo, and under * `packages/lincd.org/modules/*` when the app runs from its own root. Pass BOTH * candidate layouts; only globs whose parent dir actually exists are scanned, * so the same config works in either checkout. Each glob's packages are @@ -438,7 +438,7 @@ export async function discoverWorkspaces( out.push(entry); }; - // 1. The app's own `workspaces` globs — the monorepo-root case (CN, or any app + // 1. The app's own `workspaces` globs — the monorepo-root case (a host app, or any app // that is itself a workspace root). Only trailing `/*` patterns. const pkgPath = path.join(cwd, 'package.json'); if (await fsExtra.pathExists(pkgPath)) { @@ -635,7 +635,7 @@ export async function resolveSourceSibling( * two loaders, and which copy a file ends up in depends on import order: a file * the module runner has already evaluated is reused, one it has not is loaded * by Node, and Node then loads that file's relative imports itself. Measured in - * CN: `package.js` and `ontologies/lincd-server.js` evaluated once by each + * a host app: `package.js` and `ontologies/lincd-server.js` evaluated once by each * loader, and `LocalFileStore.js` too once the package's `backend` was loaded. * Bundling the package makes Vite the only loader for it. */ @@ -681,7 +681,7 @@ export function ssrNodeShim(id: string): {id: string; code: string} { * start` it never gets here: `ssr.external` names the cli, so Vite externalizes the import to Node * before resolving it. Under Vitest, which inlines `@_linked/*`, it does get here, and handing it * the shim again made the shim re-export itself: an empty module, so a cli helper imported in an - * app's Vitest run was `undefined` (create-now backlog 130). + * app's Vitest run was `undefined`. */ export function ssrNodeShimId( id: string, @@ -831,7 +831,7 @@ export function createViteConfig(opts: LinkedViteConfigOptions = {}): ReturnType // `lincd-*` deps are lib-only). discoverWorkspaces() only registers // packages that ship `src/` on disk, so `length === 0` is the exact // standalone signal used elsewhere in this file. In WORKSPACE mode - // (CN monorepo or its workspace-member clones) this is false and none + // (a host monorepo or its workspace-member clones) this is false and none // of the standalone-gated branches below apply. const isStandalone = isDev && workspaces.length === 0; diff --git a/src/workspace-globs.ts b/src/workspace-globs.ts index 47738117..396def45 100644 --- a/src/workspace-globs.ts +++ b/src/workspace-globs.ts @@ -13,7 +13,7 @@ import {minimatch} from './utils/minimatch.js'; * linked-package scanner, and the dev HMR watcher). They used to each * hand-roll it, and all three ignored NEGATED patterns — so a monorepo that * excludes a directory (`"!packages/core"`) still had that directory treated - * as a workspace member. For CN that meant dev resolving `@_linked/primitives` + * as a workspace member. For one host monorepo that meant dev resolving `@_linked/primitives` * to an untracked sibling checkout under `packages/` whose dependencies npm had * never installed, and the app not booting. Hence one shared helper. * From 7d74971e04bf308e3bd577dbf41cd365b0c6fd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Verheij?= <341567+flyon@users.noreply.github.com> Date: Mon, 2 Nov 2026 06:29:45 +0000 Subject: [PATCH 02/25] worktree add / branch start --worktree --dataset: print the app's clone-dataset script (or datasetCloneScript), warn when it has none; port hint names the app's port Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + docs/integration-branches-and-worktrees.md | 30 +++++- src/cli.ts | 4 +- src/commands/master.ts | 10 +- src/commands/start.ts | 5 +- src/commands/worktree.ts | 75 +++++++++++++-- src/interfaces.ts | 10 ++ tests/unit/datasetCloneHint.test.ts | 102 +++++++++++++++++++++ tests/unit/integration/worktree.test.ts | 25 +++-- 9 files changed, 231 insertions(+), 31 deletions(-) create mode 100644 tests/unit/datasetCloneHint.test.ts diff --git a/README.md b/README.md index a6486035..3fb5ea76 100644 --- a/README.md +++ b/README.md @@ -490,6 +490,7 @@ farm in which the worktree's own checkouts win), and land locally with linked branch start overhaul --target main core # app + packages-local/_linked-core on `overhaul` linked branch status # per repo: branch, target, dirty, ahead/behind, off-branch linked worktree add agent1 --with core --port 4041 # ../wt/agent1 with its own core worktree; Vite, tsc and Node load it +linked worktree add agent2 --dataset wt-agent2 # its own dataset: prints `npm run clone-dataset -- wt-agent2` (or the script linked.config.js names with datasetCloneScript), else warns it starts empty linked worktree relink # in a worktree: rebuild its node_modules link farm (after npm install in the main checkout) linked worktree list # agent worktrees and whether each branch has landed linked worktree remove agent1 # refuses while a branch has not landed (--force, --delete-unlanded) diff --git a/docs/integration-branches-and-worktrees.md b/docs/integration-branches-and-worktrees.md index f417c9ae..202bb8f2 100644 --- a/docs/integration-branches-and-worktrees.md +++ b/docs/integration-branches-and-worktrees.md @@ -264,8 +264,8 @@ when it has none (then agents land straight into that branch). |---|---| | `--with ` | comma-separated `packages-local/` checkouts the agent changes (`@_linked/core`, `core` or `_linked-core`) | | `--app-detached` | check the app out detached at the base tip, for work that changes only packages; needs `--with` | -| `--port ` | the port in the printed start command (default ``; the main checkout uses 4040) | -| `--dataset ` | adds `FUSEKI_DATASET=` to the printed start command, and the clone commands when the app has them | +| `--port ` | the port in the printed start command (default ``; the hint names the main checkout's port: its `.env` `PORT`, else 4040) | +| `--dataset ` | adds `FUSEKI_DATASET=` to the printed start command, and how to clone the app's data into it (see Cloning a dataset) | | `--dir ` | where to put it; default `/wt/`; refused anywhere inside the app root | | `--from ` | a step of master `` (see Masters); implied when run in the master's worktree | @@ -417,10 +417,32 @@ cd ../wt/m1 && PORT=4510 SITE_ROOT=http://localhost:4510 CN_PROJECTS_ROOT=../wt/ `SITE_ROOT` is set when the linked `.env` sets it (the server writes absolute asset URLs from it, so without it a second server serves the first one's bundles; every `worktree add` start command sets it too), `CN_PROJECTS_ROOT` when the `.env` sets it (so the preview's app clones are its -own), `FUSEKI_DATASET` with `--dataset`. Refuses, making nothing, when `` exists in a repo, +own), `FUSEKI_DATASET` with `--dataset` (plus the clone hint, see Cloning a dataset). Refuses, making nothing, when `` exists in a repo, contains `--`, equals a target, the directory exists, the port is another master's, or it runs outside the main checkout. Without `--worktree`, `branch start` is unchanged. +### Cloning a dataset + +A worktree or master started with `--dataset ` runs on a dataset of its own, which starts +empty. The cli does not know the app's store, so the app supplies the copy as an npm script in its +root `package.json` that takes the target dataset as its one argument: `clone-dataset` by +default, or the script `datasetCloneScript` names in the app's `linked.config.js`: + +```js +export default defineConfig({datasetCloneScript: 'data:clone'}); +``` + +`worktree add --dataset` and `branch start --worktree --dataset` then print the command to run +before starting it: + +``` +Clone the data into wt-a1 first (from /path/to/app): npm run clone-dataset -- wt-a1 +``` + +Without the script (or when `datasetCloneScript` names one `package.json` lacks) they print a +warning instead: the dataset starts empty unless it is cloned by hand, and how to add the script. +The script should refuse to overwrite the app's own datasets. + ### Steps: `linked worktree add --from ` A step of master `` (`--from` is implied when run in the master's worktree): the app worktree @@ -718,7 +740,7 @@ Exits 1 when any row is `two-copies`, 0 otherwise. `--json` prints the rows package gets the main checkout's copy in Node and `tsc` (Vite gives it the worktree's). - **Dependency changes** need a worktree with its own install (see Shared install). - **Data is shared.** Worktrees use the same data store unless started with a dataset of their - own (`--dataset`). + own (`--dataset`, filled by the app's clone script: see Cloning a dataset). - **`linked checkout` does not lock.** Concurrent runs on one base clone are the caller's to serialise. - **`linked worktree remove --branch` reads a squash merge as not landed**; use `--force`. diff --git a/src/cli.ts b/src/cli.ts index 6f5b9cb2..1a18a80b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -720,7 +720,7 @@ branch .option('--worktree', "Start a master: in a worktree of its own; the checkouts stay where they are.") .option('--with ', 'With --worktree: comma-separated packages-local/ checkouts to give a worktree on (as the positional packages).') .option('--port ', "With --worktree: the master's preview port.") - .option('--dataset ', "With --worktree: a dataset of the master's own for its preview (FUSEKI_DATASET).") + .option('--dataset ', "With --worktree: a dataset of the master's own for its preview (FUSEKI_DATASET), with the clone command as for worktree add --dataset.") .option('--dir ', "With --worktree: where to put the master's worktree.") .action(async (name: string, packages: string[], options) => { if (options.worktree) { @@ -824,7 +824,7 @@ worktree .option('--with ', 'Comma-separated packages-local/ checkouts to change: @_linked/core, core or _linked-core.') .option('--app-detached', 'Check the app out detached at the base tip: for work that changes only packages.') .option('--port ', 'The port for the printed start command.') - .option('--dataset ', 'A dataset of its own for the printed start command (FUSEKI_DATASET).') + .option('--dataset ', "A dataset of its own for the printed start command (FUSEKI_DATASET), with the command that clones the app's data into it (its clone-dataset npm script, or the one datasetCloneScript names in linked.config.js).") .option('--dir ', 'Where to put the worktree.') .option('--from ', "A step of this master (linked branch start --worktree): branch -- from , default dir /../--, --with from the master's package worktrees, node_modules linking straight into the master's install with the master's packages under the step's own. Implied when run in the master's worktree.") .action(async (agent: string, options) => { diff --git a/src/commands/master.ts b/src/commands/master.ts index 9c422989..35aaa83b 100644 --- a/src/commands/master.ts +++ b/src/commands/master.ts @@ -44,10 +44,10 @@ import {readFarmMarker} from './worktree-node-modules.js'; import { addPackageWorktree, createWorktreeSet, + datasetCloneMessages, defaultWorktreeDir, mainCheckoutOf, realish, - shellQuote, startCommandFor, startEnv, worktreeList, @@ -237,11 +237,7 @@ async function makeMaster( `After each landing into ${name}: npx linked build in each changed package worktree under ${path.join(dir, 'packages-local')}, then restart the preview.`, `When the owner approves: linked branch land ${name}, from ${root}.`, ); - if (options.dataset) { - messages.push( - `Clone the data into ${options.dataset} first (from ${root}): scripts/backup-cn-state.sh --yes, then scripts/restore-fuseki-dataset.sh ${shellQuote(options.dataset)} --yes`, - ); - } + if (options.dataset) messages.push(...(await datasetCloneMessages(root, options.dataset))); result.code = 0; return result; } @@ -491,7 +487,7 @@ export async function branchLand( result.code = trouble ? 5 : 0; result.messages.push( '', - landed.length ? `Landed ${name}${trouble ? ', with the failures above' : ''}. Restart the CN on ${root} so it runs the landed code.` : `Nothing to land: every target has ${name}.`, + landed.length ? `Landed ${name}${trouble ? ', with the failures above' : ''}. Restart the app on ${root} so it runs the landed code.` : `Nothing to land: every target has ${name}.`, `Remove the master once done with it: linked worktree remove ${name}.`, ); return result; diff --git a/src/commands/start.ts b/src/commands/start.ts index 7acf7dd8..aea4db19 100644 --- a/src/commands/start.ts +++ b/src/commands/start.ts @@ -44,6 +44,9 @@ export const VITE_CONFIG_FILES = ['vite.config.ts', 'vite.config.js', 'vite.conf */ export const LINKED_CONFIG_FILES = ['linked.config.js', 'lincd.config.js']; +/** The port an app listens on when neither `PORT` nor its config sets one. */ +export const DEFAULT_APP_PORT = 4040; + /** * Absolute path to the app's linked config. Returns the first name that exists; * when none does, the current name — the caller still `existsSync`-guards the @@ -308,7 +311,7 @@ export function resolveAppUrl( env: Record, configuredPort?: number, ): string { - const port = parseInt(env.PORT ?? '', 10) || configuredPort || 4040; + const port = parseInt(env.PORT ?? '', 10) || configuredPort || DEFAULT_APP_PORT; return `http://localhost:${port}/`; } diff --git a/src/commands/worktree.ts b/src/commands/worktree.ts index fc1463a6..0a972692 100644 --- a/src/commands/worktree.ts +++ b/src/commands/worktree.ts @@ -50,6 +50,7 @@ import { type Master, } from '../integration/masters.js'; import {withMachineLockAsync} from '../integration/repo-lock.js'; +import {importFile} from '../utils/platform.js'; import {findAppRoot} from '../localize/app-root.js'; import {makeRun, type Run} from '../localize/run.js'; import {sharedInstall} from '../localize/shared-install.js'; @@ -61,6 +62,7 @@ import { selectCheckouts, worktreesOf, } from './branch.js'; +import {DEFAULT_APP_PORT, resolveLinkedConfigPath} from './start.js'; import { farmOverlays, linkNodeModules, @@ -401,6 +403,67 @@ export function startEnv(dir: string, port: number | undefined, dataset: string return env; } +/** The port the app at `root` listens on: its `.env` `PORT`, else the default. */ +export function appPort(root: string): number { + return parseInt(envValue(path.join(root, '.env'), 'PORT') ?? '', 10) || DEFAULT_APP_PORT; +} + +/** + * The npm script that clones the app's data into a dataset, when the app's + * linked config names none with `datasetCloneScript`. It takes the target + * dataset as its one argument. + */ +export const DEFAULT_DATASET_CLONE_SCRIPT = 'clone-dataset'; + +/** + * The lines to print for cloning the data of the app at `root` into `dataset` + * (a worktree on a dataset of its own starts on an empty one). `configured` is + * `datasetCloneScript` from the app's linked config. The command when the + * app's `package.json` has the script, else a warning that the dataset starts + * empty and how to add the script. + */ +export function datasetCloneHint(root: string, dataset: string, configured?: string): string[] { + const script = configured || DEFAULT_DATASET_CLONE_SCRIPT; + const ds = shellQuote(dataset); + const pkg = path.join(root, 'package.json'); + const scripts = (readJson(pkg)?.scripts ?? {}) as Record; + if (typeof scripts[script] === 'string') { + return [`Clone the data into ${dataset} first (from ${root}): npm run ${script} -- ${ds}`]; + } + if (configured) { + return [ + `Warning: datasetCloneScript in the linked config names "${configured}", but ${pkg} has no such script, so ${dataset} starts empty unless it is cloned by hand.`, + ` Add a "${configured}" script that copies the app's data into the dataset its argument names (npm run ${configured} -- ${ds}).`, + ]; + } + return [ + `Warning: the app has no ${DEFAULT_DATASET_CLONE_SCRIPT} script, so ${dataset} starts empty unless it is cloned by hand.`, + ` To have one: add a "${DEFAULT_DATASET_CLONE_SCRIPT}" script to ${pkg} that copies the app's data into the dataset its argument names (npm run ${DEFAULT_DATASET_CLONE_SCRIPT} -- ${ds}), or name another script with datasetCloneScript in the linked config.`, + ]; +} + +/** + * `datasetCloneScript` from the linked config of the app at `root`; undefined + * when there is no config, it does not set the key, or it fails to load (the + * hint then looks for the default script). + */ +export async function readDatasetCloneScript(root: string): Promise { + const file = resolveLinkedConfigPath(root); + if (!fs.existsSync(file)) return undefined; + try { + const mod = await importFile(file); + const value: unknown = (mod?.default ?? mod)?.datasetCloneScript; + return typeof value === 'string' && value ? value : undefined; + } catch { + return undefined; + } +} + +/** `datasetCloneHint` with the script the app's linked config names. */ +export async function datasetCloneMessages(root: string, dataset: string): Promise { + return datasetCloneHint(root, dataset, await readDatasetCloneScript(root)); +} + /** `cd

&& npm run start:local` (or `npm start` without that script). */ export function startCommandFor(dir: string, env: string[]): string { const pkgJson = readJson(path.join(dir, 'package.json')); @@ -626,18 +689,10 @@ export async function worktreeAdd( result.messages.push( master?.port ? `(pick a free port: steps of ${master.name} use ${stepPorts(master.port)})` - : '(pick a free port: the main checkout uses 4040)', - ); - } - const backup = path.join(root, 'scripts', 'backup-cn-state.sh'); - const restore = path.join(root, 'scripts', 'restore-fuseki-dataset.sh'); - if (options.dataset && fs.existsSync(backup) && fs.existsSync(restore)) { - result.messages.push( - `Clone the data into ${options.dataset} first (from ${root}):`, - ` scripts/backup-cn-state.sh --yes`, - ` scripts/restore-fuseki-dataset.sh ${shellQuote(options.dataset)} --yes`, + : `(pick a free port: the main checkout uses ${appPort(root)})`, ); } + if (options.dataset) result.messages.push(...(await datasetCloneMessages(root, options.dataset))); result.messages.push( `Don't run npm install in the worktree: node_modules links into ${installRoot === root ? "the main checkout's" : `${installRoot}'s`} install (the git hooks skip it there too).`, 'After an npm install in the main checkout, or a package worktree added by hand: linked worktree relink, from the worktree.', diff --git a/src/interfaces.ts b/src/interfaces.ts index af49814d..b4b5317c 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -112,4 +112,14 @@ export interface LinkedConfig { * or an app that manages its own shape/dataset lifecycle. */ syncShapesOnBoot?: boolean; + + /** + * The npm script in the app's root `package.json` that copies the app's data + * into a dataset, given its name as the one argument + * (`npm run