Repository navigation
Commit c9e0d77
feat(cli): os init scaffolds a starter app and list view, so a new project opens in the Console with its own object (#32291)
Fixes #32212
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:`os init` 默认的 `app` 模板现在多写一个入门应用
`src/apps/main.app.ts`(导航里只有一项,打开模板自带的对象)和该对象的列表视图
`src/views/NAMESPACE_item.view.ts`;`plugin` 模板只多写列表视图,不带应用;`empty` 模板不变。
- 为什么改:以前 `os init` 出来的项目启动后,对象能通过 REST/MCP 访问,但没有任何应用列出它,新用户按启动横幅打开
Console 只看到平台自带的应用,看不到自己的项目。这与 #32209 对 `npm create objectstack`
的修复是同一个问题的另一个脚手架。
- 风险与回滚:只影响新生成的项目,已有项目不受影响。一个可见后果:`app` 类型的包最多只能有一个应用(ADR-0019
D3),所以新项目里再跑 `os g app` 会被拒绝,作者应往入门应用里加导航项(与 #32209 的 blank 模板相同);目录里已有
`src/apps/index.ts` 或 `src/views/index.ts` 时保留原文件、只追加一行导出,不覆盖。回滚即还原
`packages/cli/src/commands/init.ts`。
- 先看:`packages/cli/src/commands/init.ts`(`wiredBarrelExporting` 与
`writeTemplateSrcFiles`
里新增的追加分支,最有风险的一段);`packages/cli/test/generate-scaffold-wiring.test.ts` 第
5
节(新的行为钉子);`packages/cli/test/init-template-comments-self-contained.test.ts`(`../`
规则改为按深度判断)。
- 两分钟验证:在任意空目录运行 `objectstack init demo --no-install && cd demo &&
objectstack validate`,预期输出 `UI: 1 Apps 1 Views` 且校验通过、无警告。
- 需要你做的:无,席位落地。
## What changes
`os init` scaffolds its objects and, until now, no app, so a project
booted with its object served over REST and MCP and nothing of its own
in the Console, which lists an object only where an app's navigation
names it.
- **`app` template** (the default): writes `src/apps/main.app.ts`, an
app named `NAMESPACE_main_app` labelled with the project's title, whose
one navigation entry opens the starter object, and
`src/views/NAMESPACE_item.view.ts`, that object's list view (a grid of
every field it declares, sorted by its title field). Each is exported
from its directory's `index.ts`, which the config already wires. The
files are what `os g app main --object NAMESPACE_item` and `os g view
NAMESPACE_item` write, and the barrels are the empty barrel plus the
line those generators append: the apps barrel is byte-identical to the
one `create-objectstack`'s blank starter ships since #32209.
- **`plugin` template**: writes the list view and **no app**. Judgment,
with the reason: a view travels with its object, so a host that names
the object in its own navigation opens this list; navigation is the
host's to compose, and an app shipped in a metadata package would land
in the app switcher of every stack that loads it. The template also has
no `dev` or `start` script, so there is no Console of its own for an app
to fill.
- **`empty` template**: unchanged. It declares no object, so there is
nothing for an app entry or a view to name (`os g app` itself refuses
without an object).
- **The route the card asked to be named**: the object is referenced
through an import of its module (`ITEM.name`), never as a typed-out
name, as #32209 does with `Note.name`. Renaming the object in its own
file moves the app entry and the view with it. The other route, teaching
`create-objectstack`'s rename to move `objectName`/`object` literals,
lives outside this card's surface and is not needed for `os init`, which
renders the names per project.
- **One consequence, stated rather than hidden**: a package whose
manifest type is `app` holds at most one app (ADR-0019 D3, enforced by
`defineStack`). With the starter app in place, `os g app NAME --object
OBJECT` in a fresh `os init` project is refused (exit 1, "must define at
most one app … Fold them into one app with multiple tabs", and the
command takes its write back out). Before this change the first `os g
app` succeeded. The starter app's own comment therefore tells the author
to add a navigation entry to it (a `group` entry nests them) rather than
a second app, and the nightly reach e2e now pins that refusal before it
removes the starter app and runs every generator as before. This is the
same shape #32209 shipped for the blank starter.
- **Scaffolding into a non-empty directory** (`os init` with no name):
an existing `src/apps/index.ts` or `src/views/index.ts` is kept, and the
template's export line is appended once if the file lacks it, the way
`os generate` appends to a barrel it finds. Empty barrels keep the
existing rule (never written over an existing file).
The producer is `packages/cli/src/commands/init.ts`, as the card named.
`generate.ts` and `packages/create-objectstack/**` are untouched.
## Tests
- `packages/cli/test/generate-scaffold-wiring.test.ts`, new top-level
describe `[#32212] a scaffolded project lists its objects in an app,
each with a list view`: scaffolds each template through the real emitter
and loads its config the way `os validate` does; asserts every object
has exactly one list view binding it with the object's own fields as
columns, the `app` template's app navigates to every scaffolded object,
the `plugin` template ships no app, `empty` ships nothing, and renaming
the object's `name:` in its own file moves the app entry and the view
with it (with no `'NAMESPACE_item'` literal in any app or view file).
- Same file: the empty-barrel probes moved from the views barrel (now
non-empty) to the flows barrel; a new case pins the append-once
behaviour on an existing views barrel, including a file with no trailing
newline and a second run that writes nothing.
- `packages/cli/test/create-objectstack-wiring-parity.test.ts`: the
compared `os init` barrel is the rendered barrel minus the generator
export lines, i.e. the empty barrel. One export-line pattern serves both
this and the #32209 assertions.
- `packages/cli/test/init-template-comments-self-contained.test.ts`: the
`../` entry now judges depth, as its own comment prescribed for this
exact condition and as `create-objectstack`'s copy does since #32209.
`../objects/NAMESPACE_item.object` from `src/apps/` stays inside the
project; a climb above the project root still reddens.
- `packages/cli/test/generate-scaffolds-reach-stack.e2e.test.ts`
(nightly): first `os g app` beside the starter app must be refused by
the one-app rule with nothing written; then the starter app is removed
(file and barrel line) and every generator runs as before. `os validate`
counts 1 App and 2 Views (the starter's list view plus the generated
one).
- `packages/cli/test/starter-field-consumers.e2e.test.ts` needs no
change: since #32209 its control unwires any view a starter ships, which
now includes this one.
## Acceptance notes
- `os validate` on a `-t plugin` scaffold prints the advisory "No apps
or plugins defined — this stack may not do much". It printed the same
before this change (the plugin template never had an app), and it
follows from the plugin judgment above; noted, not changed.
- The starter list view's label is `All NAMESPACE_TITLE Items` and the
app entry's `NAMESPACE_TITLE Items`, where `os g view` would print the
object's singular label (`All My App Item`): the object declares no
plural label, so the scaffold spells the plural itself.
- Found beside this card, reported to the seat for filing (not fixed
here, outside the surface): the blank starter's `src/apps/main.app.ts`
comment, its README and
`content/docs/getting-started/your-first-project.mdx` tell the author to
"generate an app of its own" with `objectstack generate app NAME
--object OBJECT`; in that project the command is refused by the same
one-app rule (measured on a copy of the template at this head: exit 1,
"An 'app' package must define at most one app, but found 2").
- The docs page `content/docs/deployment/cli.mdx` describes `-t plugin`
as writing "`objectstack.config.ts` … plus `src/objects/*.object.ts`";
it does not list views. Still true as far as it goes; not edited here
(outside this card's surface).
## Verification
All readings below are on this branch at `fe206cab5` unless a line names
another head (each named head differs from `fe206cab5` only by the
starter app's comment text and the changeset).
<details><summary>Targeted tests at fe206ca: 13 files, 264 tests,
green</summary>
- `pnpm --filter @objectstack/cli exec vitest run --project unit
--maxWorkers=2` over the 12 unit-tier files that pin `os init` (init,
init-scaffold-authoring-rules, init-template-comments-self-contained,
init-scaffold-file-name-registry-parity,
create-objectstack-wiring-parity, generate-scaffold-wiring,
scaffold-emission-typechecks, scaffold-test-script-passes,
scaffold-object-declaration-shape, scaffold-manifest-schema,
starter-field-consumers, init-manifest-id): `Test Files 12 passed (12)`,
`Tests 256 passed (256)`.
- `--project integration test/generate-stack-reach.test.ts
test/scaffold-test-script-passes.test.ts`: `Test Files 1 passed (1)`,
`Tests 8 passed (8)`.
- Nightly, `OS_TEST_TIERS=nightly …
test/generate-scaffolds-reach-stack.e2e.test.ts`: `Test Files 1 passed
(1)`, `Tests 14 passed (14)`, including the new one-app refusal case.
</details>
<details><summary>Package suite and typecheck</summary>
- `pnpm --filter @objectstack/cli typecheck` (tsc plus
`check:test-typecheck`) at `fe206cab5`: exit 0, "test layer compiles … 3
file(s) / 28 error(s) / 6 pinned signature(s) held".
- `pnpm --filter @objectstack/cli exec vitest run --project unit
--maxWorkers=2` at `7122465ff`: `Test Files 2 failed | 410 passed
(412)`, `Tests 5857 passed | 29 skipped`. The two files
(`published-subpath-console.pin`, `published-subpath-hook-body.pin`)
refused before running because `packages/cli` itself was not built
("packages/cli is not built … Run: pnpm --filter @objectstack/cli
build"); after that build both ran: `Test Files 2 passed (2)`, `Tests 29
passed (29)`. The `integration` layer is declared to CI apart from the
files named above.
- Nightly `starter-field-consumers.e2e` and
`init-created-files-summary.e2e` at `7122465ff`: both passed (2 of the 3
files in that run; the third, the reach e2e, was then adapted to the
one-app rule and is green above).
</details>
<details><summary>Ablation (one-shot, not kept)</summary>
With the app entry's `objectName: ITEM.name` replaced by a typed-out
`'NAMESPACE_item'` (via `scripts/ablation-replace.mjs`, anchor 1 to 0,
blob `d3dd3002` to `23d6bffd`), `generate-scaffold-wiring.test.ts` went
red on exactly one test: "`app`: renaming the object in its own file
moves the app entry and the view with it" (`Tests 1 failed | 46
passed`). Restored: `git hash-object` equals the HEAD blob `d3dd3002`,
`git diff HEAD` empty.
</details>
<details><summary>Boot: a real os init project in the Console's
API</summary>
`os init demo --no-install` then `os validate`: "Validation passed",
`UI: 1 Apps 1 Views`, no warnings; `os lint`: "All checks passed". `os
compile` then `os serve --dev` on a random port, signed in as the dev
admin:
- `GET /api/v1/meta/app` answered 200 with `demo_main_app` (navigation:
`demo_item`) beside `setup` and `account`.
- `GET /api/v1/meta/view` answered 200 with `demo_item.default`,
`object: demo_item`, label "All Demo Items", columns
name/description/status, `_diagnostics.valid: true`.
- `GET /api/v1/data/demo_item` answered 200, `total: 0`.
The server was stopped by its recorded pid and the port was free
afterwards. `os init pkg -t plugin`: `os validate` passed with `UI: 1
Views`.
</details>
<details><summary>Local gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands` (derived at `a5af54126`,
same 68 families re-derived at the final diff): 63 exit 0; 5 NOT
MEASURED, each exit 3 PREREQUISITE NOT MET because they read the build
of packages outside the CLI's closure (`check:dual-build-cjs-loads`,
`check:i18n`, `check:i18n-coverage`, `check:i18n-walk-parity`,
`check:type-check-debt`); CI runs them. `dispatch-gates --ran`: "68
derived famil(ies) accounted for — 63 run, 5 NOT-MEASURED". Re-run at
`fe206cab5` after the last changeset edit:
`check-adr-0087-registration`, `check-changeset-no-major`,
`check-empty-changeset`, `check:issue-citations`, `check:doc-authoring`,
`check:nul-bytes`, `check:scaffold-emission-policy`,
`check-closing-keyword-parity`, all exit 0. `eslint --no-inline-config`
over the changed source and test files: exit 0, no findings.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYm8sWjp2Pk76warN7w)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 49bc3be commit c9e0d77
6 files changed
Lines changed: 428 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
793 | 889 | | |
794 | 890 | | |
795 | 891 | | |
| |||
937 | 1033 | | |
938 | 1034 | | |
939 | 1035 | | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
940 | 1089 | | |
941 | 1090 | | |
942 | 1091 | | |
| |||
1018 | 1167 | | |
1019 | 1168 | | |
1020 | 1169 | | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1021 | 1188 | | |
1022 | 1189 | | |
1023 | 1190 | | |
| |||
1188 | 1355 | | |
1189 | 1356 | | |
1190 | 1357 | | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
1191 | 1375 | | |
1192 | 1376 | | |
1193 | 1377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
123 | | - | |
| 131 | + | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| |||
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
144 | | - | |
145 | | - | |
| 152 | + | |
| 153 | + | |
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| |||
0 commit comments