create-nisc 0.8.1 → 0.8.2

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.
Files changed (163) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +89 -13
  3. package/dist/chunk-B3L4UJDN.js +316 -0
  4. package/dist/chunk-B3L4UJDN.js.map +1 -0
  5. package/dist/cli.js +86 -42
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.d.ts +61 -6
  8. package/dist/index.js +1 -1
  9. package/package.json +1 -1
  10. package/templates/base/files/src/ui/kit.css +232 -0
  11. package/templates/base/item.json +31 -0
  12. package/templates/{moss-dom → classic/files}/src/app/actions/surfaces/welcome.action.ts +1 -1
  13. package/templates/classic/item.json +32 -0
  14. package/templates/{moss-dom → dom/files}/index.html +1 -1
  15. package/templates/dom/files/src/ui/kit.ts +109 -0
  16. package/templates/{shell-dom → dom/files}/src/ui/registry.ts +2 -2
  17. package/templates/{shell-dom → dom/files}/tsconfig.json +3 -14
  18. package/templates/dom/item.json +24 -0
  19. package/templates/model-first/agents-section.md +42 -0
  20. package/templates/model-first/files/src/app/action-catalog.ts +10 -0
  21. package/templates/model-first/files/src/app/actions/answer/text.action.ts +17 -0
  22. package/templates/model-first/files/src/app/actions/answer/text.layout.ts +3 -0
  23. package/templates/model-first/files/src/app/actions/ask/dock.action.ts +58 -0
  24. package/templates/model-first/files/src/app/actions/ask/dock.layout.ts +59 -0
  25. package/templates/model-first/files/src/app/actions/guide/checklist.action.ts +24 -0
  26. package/templates/model-first/files/src/app/actions/guide/checklist.layout.ts +17 -0
  27. package/templates/model-first/files/src/app/actions/guide/counter.action.ts +22 -0
  28. package/templates/model-first/files/src/app/actions/guide/counter.layout.ts +19 -0
  29. package/templates/model-first/files/src/app/actions/guide/guide.actions.ts +144 -0
  30. package/templates/model-first/files/src/app/actions/guide/guide.layouts.ts +31 -0
  31. package/templates/model-first/files/src/app/actions/guide/quiz.action.ts +25 -0
  32. package/templates/model-first/files/src/app/actions/guide/quiz.layout.ts +33 -0
  33. package/templates/model-first/files/src/app/app.ts +11 -0
  34. package/templates/model-first/files/src/app/arrangements.ts +17 -0
  35. package/templates/model-first/files/src/app/charter/assignments.ts +1 -0
  36. package/templates/model-first/files/src/app/charter/charter.ts +10 -0
  37. package/templates/model-first/files/src/app/screens.ts +87 -0
  38. package/templates/model-first/files/src/app/shell/areas.ts +3 -0
  39. package/templates/model-first/files/src/app/shell/frame.layout.ts +6 -0
  40. package/templates/model-first/files/src/app/shell/shell.ts +20 -0
  41. package/templates/model-first/files/src/app/vex/index.ts +3 -0
  42. package/templates/model-first/files/src/db/schema.ts +3 -0
  43. package/templates/{moss-react → model-first/files}/src/dev/all-checks.ts +3 -2
  44. package/templates/model-first/files/src/dev/artifacts-check.ts +95 -0
  45. package/templates/model-first/files/src/dev/checks.ts +13 -0
  46. package/templates/model-first/files/src/dev/compose-check.ts +191 -0
  47. package/templates/model-first/files/src/dev/guide-check.ts +90 -0
  48. package/templates/model-first/files/src/dev/live-ask.ts +185 -0
  49. package/templates/model-first/files/src/dev/scripted.ts +208 -0
  50. package/templates/{shell-dom → model-first/files}/src/dev/strata.ts +7 -1
  51. package/templates/model-first/files/src/server/boot.ts +24 -0
  52. package/templates/model-first/files/src/server/compose/answer.ts +145 -0
  53. package/templates/model-first/files/src/server/compose/catalog.ts +46 -0
  54. package/templates/model-first/files/src/server/compose/composer.agent.ts +18 -0
  55. package/templates/model-first/files/src/server/compose/history.ts +45 -0
  56. package/templates/model-first/files/src/server/compose/index.ts +170 -0
  57. package/templates/model-first/files/src/server/compose/knowledge.ts +57 -0
  58. package/templates/model-first/files/src/server/compose/layout.ts +70 -0
  59. package/templates/model-first/files/src/server/compose/pick.ts +44 -0
  60. package/templates/model-first/files/src/server/compose/plan.ts +45 -0
  61. package/templates/model-first/files/src/server/compose/record.ts +3 -0
  62. package/templates/model-first/files/src/server/compose/reply.schema.ts +70 -0
  63. package/templates/model-first/files/src/server/compose/screen.ts +40 -0
  64. package/templates/model-first/files/src/server/models/index.ts +35 -0
  65. package/templates/model-first/files/src/server/runs/index.ts +20 -0
  66. package/templates/model-first/item.json +84 -0
  67. package/templates/{moss-dom → moss/files}/README.md +1 -1
  68. package/templates/moss/item.json +40 -0
  69. package/templates/{shell-dom → page/files}/README.md +1 -1
  70. package/templates/page/item.json +37 -0
  71. package/templates/questions.json +5 -0
  72. package/templates/{moss-react → react/files}/index.html +1 -1
  73. package/templates/react/files/src/ui/kit.tsx +221 -0
  74. package/templates/{moss-react → react/files}/src/ui/registry.ts +2 -2
  75. package/templates/react/item.json +31 -0
  76. package/dist/chunk-6FL5A3LS.js +0 -174
  77. package/dist/chunk-6FL5A3LS.js.map +0 -1
  78. package/templates/moss-dom/package.json +0 -39
  79. package/templates/moss-dom/src/app/actions/surfaces/welcome.layout.ts +0 -25
  80. package/templates/moss-dom/src/ui/kit.css +0 -42
  81. package/templates/moss-dom/src/ui/kit.ts +0 -35
  82. package/templates/moss-dom/src/ui/registry.ts +0 -15
  83. package/templates/moss-dom/tsconfig.json +0 -27
  84. package/templates/moss-react/README.md +0 -15
  85. package/templates/moss-react/nisc.config.ts +0 -11
  86. package/templates/moss-react/package.json +0 -42
  87. package/templates/moss-react/src/app/action-catalog.ts +0 -6
  88. package/templates/moss-react/src/app/actions/surfaces/welcome.action.ts +0 -10
  89. package/templates/moss-react/src/app/app.ts +0 -7
  90. package/templates/moss-react/src/app/charter/assignments.ts +0 -2
  91. package/templates/moss-react/src/app/charter/charter.ts +0 -5
  92. package/templates/moss-react/src/app/shell/frame.layout.ts +0 -3
  93. package/templates/moss-react/src/app/shell/shell.ts +0 -7
  94. package/templates/moss-react/src/dev/artifacts-check.ts +0 -49
  95. package/templates/moss-react/src/dev/strata.ts +0 -21
  96. package/templates/moss-react/src/dev/welcome-check.ts +0 -38
  97. package/templates/moss-react/src/server/boot.ts +0 -6
  98. package/templates/moss-react/src/server/runtime.ts +0 -13
  99. package/templates/moss-react/src/ui/kit.css +0 -42
  100. package/templates/moss-react/src/ui/kit.tsx +0 -39
  101. package/templates/moss-react/strata.lock.json +0 -6
  102. package/templates/shell-dom/index.html +0 -12
  103. package/templates/shell-dom/package.json +0 -35
  104. package/templates/shell-dom/src/app/action-catalog.ts +0 -6
  105. package/templates/shell-dom/src/app/actions/surfaces/welcome.action.ts +0 -10
  106. package/templates/shell-dom/src/app/actions/surfaces/welcome.layout.ts +0 -32
  107. package/templates/shell-dom/src/app/shell/frame.layout.ts +0 -3
  108. package/templates/shell-dom/src/ui/kit.css +0 -42
  109. package/templates/shell-dom/src/ui/kit.ts +0 -35
  110. package/templates/shell-dom/strata.lock.json +0 -6
  111. package/templates/shell-dom/vite.config.ts +0 -5
  112. package/templates/shell-react/README.md +0 -16
  113. package/templates/shell-react/index.html +0 -12
  114. package/templates/shell-react/package.json +0 -40
  115. package/templates/shell-react/src/app/action-catalog.ts +0 -6
  116. package/templates/shell-react/src/app/actions/surfaces/welcome.action.ts +0 -10
  117. package/templates/shell-react/src/app/shell/frame.layout.ts +0 -3
  118. package/templates/shell-react/src/app/shell/shell.ts +0 -7
  119. package/templates/shell-react/src/boot.ts +0 -13
  120. package/templates/shell-react/src/dev/all-checks.ts +0 -17
  121. package/templates/shell-react/src/dev/artifacts-check.ts +0 -45
  122. package/templates/shell-react/src/dev/strata.ts +0 -21
  123. package/templates/shell-react/src/dev/welcome-check.ts +0 -21
  124. package/templates/shell-react/src/ui/kit.css +0 -42
  125. package/templates/shell-react/src/ui/kit.tsx +0 -39
  126. package/templates/shell-react/src/ui/registry.ts +0 -12
  127. package/templates/shell-react/strata.lock.json +0 -6
  128. package/templates/shell-react/tsconfig.json +0 -28
  129. package/templates/shell-react/vite.config.ts +0 -8
  130. /package/templates/{moss-dom → base/files}/strata.lock.json +0 -0
  131. /package/templates/{moss-dom → classic/files}/src/app/action-catalog.ts +0 -0
  132. /package/templates/{moss-dom → classic/files}/src/app/shell/frame.layout.ts +0 -0
  133. /package/templates/{moss-dom → classic/files}/src/dev/strata.ts +0 -0
  134. /package/templates/{moss-react → classic/with/moss}/src/app/actions/surfaces/welcome.layout.ts +0 -0
  135. /package/templates/{moss-dom → classic/with/moss}/src/app/app.ts +0 -0
  136. /package/templates/{moss-dom → classic/with/moss}/src/app/charter/assignments.ts +0 -0
  137. /package/templates/{moss-dom → classic/with/moss}/src/app/charter/charter.ts +0 -0
  138. /package/templates/{moss-dom → classic/with/moss}/src/app/shell/shell.ts +0 -0
  139. /package/templates/{moss-dom → classic/with/moss}/src/dev/all-checks.ts +0 -0
  140. /package/templates/{moss-dom → classic/with/moss}/src/dev/artifacts-check.ts +0 -0
  141. /package/templates/{moss-dom → classic/with/moss}/src/dev/welcome-check.ts +0 -0
  142. /package/templates/{moss-dom → classic/with/moss}/src/server/boot.ts +0 -0
  143. /package/templates/{shell-react → classic/with/page}/src/app/actions/surfaces/welcome.layout.ts +0 -0
  144. /package/templates/{shell-dom → classic/with/page}/src/app/shell/shell.ts +0 -0
  145. /package/templates/{shell-dom → classic/with/page}/src/boot.ts +0 -0
  146. /package/templates/{shell-dom → classic/with/page}/src/dev/all-checks.ts +0 -0
  147. /package/templates/{shell-dom → classic/with/page}/src/dev/artifacts-check.ts +0 -0
  148. /package/templates/{shell-dom → classic/with/page}/src/dev/welcome-check.ts +0 -0
  149. /package/templates/{moss-dom → dom/files}/vite.config.ts +0 -0
  150. /package/templates/{moss-dom → dom/with/moss}/src/main.ts +0 -0
  151. /package/templates/{moss-dom → dom/with/moss}/src/server/document.ts +0 -0
  152. /package/templates/{shell-dom → dom/with/page}/nisc.config.ts +0 -0
  153. /package/templates/{shell-dom → dom/with/page}/src/main.ts +0 -0
  154. /package/templates/{shell-dom → dom/with/page}/src/ui/screen.ts +0 -0
  155. /package/templates/{moss-dom → moss/files}/nisc.config.ts +0 -0
  156. /package/templates/{moss-dom → moss/files}/src/server/runtime.ts +0 -0
  157. /package/templates/{moss-react → react/files}/tsconfig.json +0 -0
  158. /package/templates/{moss-react → react/files}/vite.config.ts +0 -0
  159. /package/templates/{moss-react → react/with/moss}/src/main.tsx +0 -0
  160. /package/templates/{moss-react → react/with/moss}/src/server/document.ts +0 -0
  161. /package/templates/{shell-react → react/with/page}/nisc.config.ts +0 -0
  162. /package/templates/{shell-react → react/with/page}/src/main.tsx +0 -0
  163. /package/templates/{shell-react → react/with/page}/src/ui/screen.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # create-nisc
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 49a4766: `npm create nisc` makes an app from items instead of four whole templates. Each answer is a folder under `templates/` — `moss` or `page`, `react` or `dom`, and the kind of app — with its files, its files for another item (`with/<item>/`), its `package.json` fragment, the keys it asks for and its lines in AGENTS.md and PLAN.md; the questions are `templates/questions.json`. The command names no item, so a new kit, shell or kind of app is a new folder, and its flag follows from it. The four apps it made before come out as they were, but for a sentence: the welcome screen no longer says which kit draws it, PLAN.md's scaffold step says "the files `npm create nisc` wrote", and AGENTS.md's line for `nisc.config.ts` is one sentence for both shells.
8
+
9
+ An item that needs keys asks for them masked, after the questions, and writes them to `.env` (`.env.example` gets the names); with no terminal they are read from the environment, never from a flag. `--workspace` keeps `workspace:^` ranges, for an app made inside the nisc repository.
10
+
11
+ - 49a4766: `npm create nisc` asks who leads. **Model-first** (`--model-first`) is a moss app where a person types a message and the answer is a screen: up to six canvases, each an action opened with an input, on the areas of an arrangement (`src/app/arrangements.ts`) or a grid the model writes. One dock at the bottom holds the screens, a chip naming the answer shown with back, forward and every answer to go back to, and the line to ask in.
12
+
13
+ Jev, a fast decision model, reads the message and the open screen and says which actions likely belong; gpt-oss-120b on Groq composes the screen as a cortex agent, naming only the areas that change, and its reply is checked against the app's actions, their input schemas and the arrangements, and corrected inside the run when it does not hold. The answer streams in. What a person presses, ticks and picks stays on the screen, the model sees it, and an answer gone back to shows it as it was left. A card's link opens a screen at once; only what is typed, or a thing to ask pressed, goes to the model. Every message is recorded as a run for each model it went to, through `session.recordRun`. It asks for its keys — Groq, and TypeSafe for Jev — and writes them to `.env`.
14
+
15
+ The app starts as a tour of nisc: five screens of cards to read, and a counter, a checklist and a quick check to use, which the model can fill in too. Its AGENTS.md says how to remove the tour — a folder, a check, and edits in five files — and what to build next. The checks run the loop offline with a scripted decision model and chat model, and `src/dev/live-ask.ts` asks the real models a run of cases.
16
+
17
+ Both kits gain the components it uses — a frame, the dock, a menu, a grid and its areas, a card, code, points, steps, a checkbox, an input and the line to ask in — and a classic app has them too. The stylesheet gains their look. `src/dev/strata.ts` is each kind's own: a model-first app's also records its frame and arrangements.
18
+
3
19
  ## 0.8.1
4
20
 
5
21
  No changes in this release.
package/README.md CHANGED
@@ -6,25 +6,36 @@ A new [nisc](https://github.com/moccadroid/niscorp) application.
6
6
  npm create nisc
7
7
  ```
8
8
 
9
- Three questions, because they are what shape the files:
9
+ Four questions, because they are what shape the files:
10
10
 
11
11
  1. **Where should it go?** The folder's name becomes the app's name.
12
- 2. **Where does the shell run?** On a server — moss: one shell per person on
12
+ 2. **Who leads?** You — classic: you build the screens, and a first one that
13
+ works is there. Or a model — model-first: there is no navigation; a person
14
+ types a message, and the answer is a screen composed from the app's actions
15
+ (below).
16
+ 3. **Where does the shell run?** On a server — moss: one shell per person on
13
17
  the server, the charter enforced there. Or in the page — no server: offline,
14
- static hosting, and the charter is not a security boundary.
15
- 3. **What draws the screen?** React, or plain DOM (no framework in the page).
18
+ static hosting, and the charter is not a security boundary. A model-first
19
+ app is behind moss, and is not asked.
20
+ 4. **What draws the screen?** React, or plain DOM (no framework in the page).
21
+
22
+ A model-first app then asks for its keys, masked (see "Keys" below): Groq for
23
+ gpt-oss-120b, and TypeSafe for Jev.
16
24
 
17
25
  ```bash
18
26
  npm create nisc my-app -- --page --dom # flags answer the questions
19
- npm create nisc my-app -- --yes # the defaults: moss, React
27
+ npm create nisc my-app -- --model-first # a model leads; the keys are asked
28
+ npm create nisc my-app -- --yes # the defaults: classic, moss, React
20
29
  ```
21
30
 
22
31
  | | |
23
32
  |---|---|
24
33
  | `dir` | where the app goes (default `my-nisc-app`) |
34
+ | `--classic` / `--model-first` | you build the screens (the default), or a model composes one for every message |
25
35
  | `--moss` / `--page` | the shell on a server (the default), or in the page |
26
36
  | `--react` / `--dom` | React draws the screen (the default), or plain DOM |
27
37
  | `--yes` | take the defaults for anything not given, and ask nothing |
38
+ | `--workspace` | depend on the nisc packages of the workspace it is made in (`workspace:^`) — for an app inside the nisc repository |
28
39
  | `--help`, `-h` | this list |
29
40
 
30
41
  With no terminal to ask in, the flags are all there is and the rest takes the
@@ -35,9 +46,9 @@ not quietly make a different app.
35
46
 
36
47
  The structure the rulebook describes, and a first screen that works:
37
48
 
38
- - one action on a canvas, a kit of five primitives with its stylesheet, and an
39
- entry — the first screen **arrives as markup** (drawn by the server, or
40
- written at build) and is picked up by the page;
49
+ - one action on a canvas, a kit with its stylesheet, and an entry — the first
50
+ screen **arrives as markup** (drawn by the server, or written at build) and
51
+ is picked up by the page;
41
52
  - `npm run dev`, `build`, `check` and `start` — and, with the shell in the
42
53
  page, `export` — all the `nisc` command; `nisc dev` runs a moss app's server inside vite, so its
43
54
  `vite.config.ts` holds nothing but the framework's plugin;
@@ -49,6 +60,27 @@ The structure the rulebook describes, and a first screen that works:
49
60
  whatever is newest — and `@niscorp/nisc` itself, which pins that set
50
61
  exactly and carries the rulebook.
51
62
 
63
+ A model-first app has, instead of the welcome screen:
64
+
65
+ - a frame: the answer, six areas laid out in an arrangement, and one dock at
66
+ the bottom — the screens, a chip naming the answer shown with back, forward
67
+ and every answer to go back to, and the line to ask in;
68
+ - **the message loop** (`src/server/compose/`): Jev reads the message and the
69
+ open screen and says which actions likely belong; gpt-oss-120b composes the
70
+ screen as a cortex agent, naming only the areas that change, checked against
71
+ the app's actions and their input schemas and corrected inside the run when
72
+ it does not hold. The answer streams in. What a person pressed, ticked or
73
+ picked stays, the model sees it, and an answer gone back to shows it as it
74
+ was left;
75
+ - **a tour of nisc** to start from: five screens of cards to read, and a
76
+ counter, a checklist and a quick check to use, which the model can fill in
77
+ too. A card's link opens a screen at once; only what is typed, or a thing to
78
+ ask pressed, goes to the model. Its `AGENTS.md` says how to remove the tour —
79
+ a folder, a check, and edits in five files — and what to build next;
80
+ - checks that run the loop offline with a scripted decision model and chat
81
+ model, one for the loop and one for the tour, and `src/dev/live-ask.ts`,
82
+ which asks the real models a run of cases.
83
+
52
84
  And two documents:
53
85
 
54
86
  - **`PLAN.md`** — what was decided when it was made (the posture with its
@@ -69,13 +101,57 @@ the files; make the app in a subfolder instead:
69
101
  npm create nisc site -- --page --dom
70
102
  ```
71
103
 
104
+ ## How an app is put together
105
+
106
+ An app is made of **items**, one for each answer, plus the ones every app has.
107
+ Each is a folder under `templates/`, and the questions are
108
+ `templates/questions.json`: the command's code names no item, so a new kit, a
109
+ new shell or a new kind of app is a new folder, and its flag and its place in
110
+ the questions follow from it.
111
+
112
+ ```
113
+ templates/
114
+ questions.json [{ id, message }], in the order they are asked
115
+ <item>/
116
+ item.json what it answers, and what it adds
117
+ files/ written into every app made with it
118
+ with/<other item>/ written only when that other item is chosen too
119
+ agents-section.md a section added to the app's AGENTS.md
120
+ ```
121
+
122
+ `item.json`:
123
+
124
+ | field | |
125
+ |---|---|
126
+ | `id` | the folder's name, and its flag: `--<id>` |
127
+ | `answers` | the question it answers; absent, every app has it |
128
+ | `label`, `hint`, `usage`, `summary` | what the question offers, the flag's line in `--help`, and its words in the line said once it is made |
129
+ | `default` | the answer taken when nobody gives one: exactly one per question |
130
+ | `requires` | `{ question: item }` — what another question must be answered with; that question is then not asked |
131
+ | `package` | a `package.json` fragment: fields, `scripts`, `dependencies`, `devDependencies` (`workspace:^` for a nisc package) |
132
+ | `env` | the keys it asks for: `{ name, message, required? }`, or `{ choose, message, options: [{ value, label, keys? }] }` |
133
+ | `docs` | its lines in AGENTS.md and PLAN.md: `is`, `where`, `runs`, `decisions`, `answered`, `open`, `order` |
134
+ | `with` | `{ <other item>: { package, env, docs } }` — added only when that other item is chosen too |
135
+
136
+ Two items that write the same file, or disagree about a field, a script or a
137
+ dependency, is a mistake in the templates: it is refused before anything is
138
+ written. In every file, `nisc-template-app` becomes the app's name.
139
+
140
+ ## Keys
141
+
142
+ An item that needs keys asks for them after the questions, masked, and they go
143
+ into `.env`; `.env.example` gets the names alone. A key left empty is filled in
144
+ `.env` later. Keys are never flags — a flag stays in the shell's history — so
145
+ with no terminal to ask in, they are read from the environment. A `.env` that
146
+ is already there keeps what it holds and gains only the lines it lacks.
147
+
72
148
  ## Why it can be trusted to work
73
149
 
74
- The four templates are real apps in the nisc repository: typechecked, built and
75
- checked by its CI on every change. And CI makes each kind of app with the built
76
- `create-nisc`, outside the repository, installs it from the packed packages
77
- under pnpm's strict resolution, and typechecks, checks and builds it
78
- (`pnpm check:create`). A new app starts from something that works today.
150
+ CI makes every kind of app with the built `create-nisc`, outside the
151
+ repository, installs it from the packed packages under pnpm's strict
152
+ resolution, and typechecks, checks, builds and serves it (`pnpm check:create`);
153
+ its tests make every combination the questions allow and refuse any two items
154
+ that collide. A new app starts from something that works today.
79
155
 
80
156
  ## License
81
157
 
@@ -0,0 +1,316 @@
1
+ import { readdirSync, existsSync, statSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
2
+ import { join, extname, dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ // <define:__NISC_SET__>
6
+ var define_NISC_SET_default = { "@niscorp/charter": "0.1.4", "@niscorp/cli": "0.8.1", "@niscorp/cortex": "0.1.4", "@niscorp/loom": "0.5.0", "@niscorp/moss": "0.8.1", "@niscorp/nisc": "0.8.2", "@niscorp/nova": "0.5.0", "@niscorp/prism": "0.3.1", "@niscorp/signal": "0.1.5", "@niscorp/solid": "0.1.2", "@niscorp/strata": "0.1.7", "@niscorp/tide": "0.1.7", "@niscorp/vex": "0.4.1" };
7
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
8
+ var json = (path) => {
9
+ try {
10
+ return JSON.parse(readFileSync(path, "utf8"));
11
+ } catch (error) {
12
+ throw new Error(`create-nisc: ${path} is not JSON \u2014 ${error instanceof Error ? error.message : String(error)}`);
13
+ }
14
+ };
15
+ var isChoice = (spec) => "choose" in spec;
16
+ var readCatalog = (root) => {
17
+ const questions = json(join(root, "questions.json"));
18
+ if (!Array.isArray(questions) || !questions.every((q) => isRecord(q) && typeof q["id"] === "string" && typeof q["message"] === "string")) {
19
+ throw new Error(`create-nisc: ${root}/questions.json is not a list of { id, message }`);
20
+ }
21
+ const items = readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(join(root, entry.name, "item.json"))).map((entry) => {
22
+ const item = json(join(root, entry.name, "item.json"));
23
+ if (!isRecord(item) || item["id"] !== entry.name) throw new Error(`create-nisc: ${entry.name}/item.json must say "id": "${entry.name}"`);
24
+ return item;
25
+ });
26
+ const asked = new Set(questions.map((q) => q.id));
27
+ const known = new Set(items.map((item) => item.id));
28
+ const answering = (question) => items.filter((item) => item.answers === question);
29
+ for (const item of items) {
30
+ if (item.answers !== void 0 && !asked.has(item.answers)) throw new Error(`create-nisc: item "${item.id}" answers "${item.answers}", which questions.json does not ask`);
31
+ if (item.answers !== void 0 && item.label === void 0) throw new Error(`create-nisc: item "${item.id}" answers a question but has no label to offer`);
32
+ for (const [question, wanted] of Object.entries(item.requires ?? {})) {
33
+ if (!answering(question).some((other) => other.id === wanted)) throw new Error(`create-nisc: item "${item.id}" requires "${wanted}" for "${question}", which no item answering it is`);
34
+ }
35
+ for (const other of Object.keys(item.with ?? {})) if (!known.has(other)) throw new Error(`create-nisc: item "${item.id}" has a part for "${other}", which is no item`);
36
+ }
37
+ for (const question of questions) {
38
+ const offered2 = answering(question.id);
39
+ if (offered2.length === 0) throw new Error(`create-nisc: nothing answers "${question.id}"`);
40
+ if (offered2.filter((item) => item.default === true).length !== 1) throw new Error(`create-nisc: exactly one item answering "${question.id}" is its default`);
41
+ }
42
+ return { root, questions, items };
43
+ };
44
+
45
+ // src/catalog/choose.ts
46
+ var itemNamed = (catalog, id) => catalog.items.find((item) => item.id === id);
47
+ var impliedBy = (catalog, picks) => {
48
+ const implied = {};
49
+ for (const id of Object.values(picks)) Object.assign(implied, itemNamed(catalog, id)?.requires ?? {});
50
+ return implied;
51
+ };
52
+ var offered = (catalog, question, picks) => {
53
+ const implied = impliedBy(catalog, picks)[question];
54
+ return catalog.items.filter(
55
+ (item) => item.answers === question && (implied === void 0 || implied === item.id) && Object.entries(item.requires ?? {}).every(([other, wanted]) => picks[other] === void 0 || picks[other] === wanted)
56
+ );
57
+ };
58
+ var completed = (catalog, picks) => {
59
+ const done = { ...picks };
60
+ for (const question of catalog.questions) {
61
+ if (done[question.id] !== void 0) continue;
62
+ const choices = offered(catalog, question.id, done);
63
+ const chosen = choices.find((item) => item.default === true) ?? choices[0];
64
+ if (chosen === void 0) throw new Error(`create-nisc: nothing can answer "${question.message}" beside ${Object.values(done).join(", ")}`);
65
+ done[question.id] = chosen.id;
66
+ }
67
+ return done;
68
+ };
69
+ var itemsOf = (catalog, picks) => {
70
+ const answering = catalog.questions.map((question) => {
71
+ const id = picks[question.id];
72
+ const item = id === void 0 ? void 0 : itemNamed(catalog, id);
73
+ if (item === void 0 || item.answers !== question.id) throw new Error(`create-nisc: "${question.message}" has no answer${id === void 0 ? "" : ` \u2014 "${id}" does not answer it`}`);
74
+ return item;
75
+ });
76
+ for (const item of answering) {
77
+ for (const [question, wanted] of Object.entries(item.requires ?? {})) {
78
+ if (picks[question] !== wanted) throw new Error(`create-nisc: "${item.id}" needs "${wanted}", not "${picks[question] ?? "nothing"}"`);
79
+ }
80
+ }
81
+ return [...answering, ...catalog.items.filter((item) => item.answers === void 0)];
82
+ };
83
+ var partsOf = (items) => {
84
+ const ids = new Set(items.map((item) => item.id));
85
+ return items.flatMap((item) => [item, ...Object.entries(item.with ?? {}).flatMap(([other, part]) => ids.has(other) ? [part] : [])]);
86
+ };
87
+ var envOf = (items) => partsOf(items).flatMap((part) => part.env ?? []);
88
+
89
+ // src/docs.ts
90
+ var all = (parts, key) => parts.flatMap((part) => {
91
+ const value = part.docs?.[key];
92
+ return value === void 0 ? [] : typeof value === "string" ? [value] : [...value];
93
+ });
94
+ var decisionNumber = (row) => Number(/^\| D(\d+) /.exec(row)?.[1] ?? Number.POSITIVE_INFINITY);
95
+ var sections = (texts) => texts.map((text) => `
96
+ ${text.trim()}
97
+ `).join("");
98
+ var agentsDoc = (facts) => {
99
+ const [first = "a nisc application", ...rest] = all(facts.parts, "is");
100
+ return `# ${facts.name}
101
+
102
+ A nisc application. **The rules it is built by are \`node_modules/@niscorp/nisc/AGENTS.md\`** \u2014 read all of it before changing anything here (it is there once the app's dependencies are installed). It is the rulebook for the nisc version this app has installed, and \`STYLE_GUIDE.md\` sits beside it. The grammars it names \u2014 a layout node, an \`ActionDefinition\`, a Prism config, a charter, a Vex DSL \u2014 are in each package's own \`README.md\` and \`DESIGN.md\`, under \`node_modules/@niscorp/<name>/\`.
103
+
104
+ What is particular to this app:
105
+
106
+ - **Its decisions are in PLAN.md.** What was answered when it was made, what was derived, and what is still open. An open decision point is asked before anything is built on it, never resolved silently.
107
+ - **It is ${first}**${rest.map((clause) => `, ${clause}`).join("")}.
108
+ - **Where things go:**
109
+
110
+ \`\`\`
111
+ ${all(facts.parts, "where").join("\n")}
112
+ \`\`\`
113
+
114
+ - **How it runs:** ${all(facts.parts, "runs").join(", ")} \u2014 all of them the \`nisc\` command \u2014 and \`npm run strata status\` for the grammars.
115
+ ${sections(facts.agents)}`;
116
+ };
117
+ var planDoc = (facts) => `# PLAN \u2014 ${facts.name}
118
+
119
+ Made ${facts.today} by \`npm create nisc\`, on nisc ${facts.nisc}. This is the record AGENTS.md's interview asks for ("Before any code"). The walkthrough asked what shapes the files; everything else is **open**, and an open decision blocks the build that depends on it until it is answered by the user or delegated by name. A blanket "go" delegates nothing.
120
+
121
+ ## Decision points
122
+
123
+ | | Tier | |
124
+ |---|---|---|
125
+ ${all(facts.parts, "decisions").sort((a, b) => decisionNumber(a) - decisionNumber(b)).join("\n")}
126
+
127
+ ## Answered when it was made
128
+
129
+ ${all(facts.parts, "answered").map((line) => `- ${line}`).join("\n")}
130
+
131
+ ## The dial-in \u2014 open
132
+
133
+ ${all(facts.parts, "open").map((line) => `- ${line}`).join("\n")}
134
+
135
+ ## Order of work
136
+
137
+ ${all(facts.parts, "order").map((line, at) => `${at + 1}. ${line}`).join("\n")}
138
+ `;
139
+ var gitignoreLines = ["node_modules/", "dist/", "out/", ".strata/", "*.tsbuildinfo", ".env", ".env.*", "!.env.example"];
140
+
141
+ // src/generate.ts
142
+ var TEMPLATES = fileURLToPath(new URL("../templates", import.meta.url));
143
+ var TOKEN = "nisc-template-app";
144
+ var SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "out", ".turbo"]);
145
+ var TEXT = /* @__PURE__ */ new Set([".ts", ".tsx", ".json", ".html", ".css", ".md"]);
146
+ var KEEP_THEIRS = /* @__PURE__ */ new Set(["README.md"]);
147
+ var validName = (name) => /^[a-z0-9][a-z0-9._-]*$/.test(name) && name.length <= 214;
148
+ var filesIn = (dir, base = "") => existsSync(join(dir, base)) ? readdirSync(join(dir, base), { withFileTypes: true }).flatMap((entry) => {
149
+ if (SKIP.has(entry.name)) return [];
150
+ const rel = base === "" ? entry.name : `${base}/${entry.name}`;
151
+ return entry.isDirectory() ? filesIn(dir, rel) : [rel];
152
+ }) : [];
153
+ var isRecord2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
154
+ var sourcesOf = (root, items) => {
155
+ const ids = new Set(items.map((item) => item.id));
156
+ const sources = /* @__PURE__ */ new Map();
157
+ for (const item of items) {
158
+ const withDir = join(root, item.id, "with");
159
+ const others = existsSync(withDir) ? readdirSync(withDir) : [];
160
+ for (const other of others) if (!existsSync(join(root, other, "item.json"))) throw new Error(`create-nisc: ${item.id}/with/${other} is for "${other}", which is no item`);
161
+ const dirs = [join(root, item.id, "files"), ...others.filter((other) => ids.has(other)).map((other) => join(withDir, other))];
162
+ for (const dir of dirs) {
163
+ for (const rel of filesIn(dir)) {
164
+ const there = sources.get(rel);
165
+ if (there !== void 0) throw new Error(`create-nisc: ${rel} is written by both "${there.item}" and "${item.id}"`);
166
+ sources.set(rel, { item: item.id, from: join(dir, rel) });
167
+ }
168
+ }
169
+ }
170
+ return sources;
171
+ };
172
+ var pin = (name, spec, options) => {
173
+ if (!spec.startsWith("workspace:") || options.workspace === true) return spec;
174
+ const version = options.versions[name];
175
+ if (version === void 0) throw new Error(`create-nisc: the nisc release has no ${name} \u2014 the set it was given is incomplete`);
176
+ return `^${version}`;
177
+ };
178
+ var manifestOf = (parts, options) => {
179
+ const fields = {};
180
+ const scripts = {};
181
+ const deps = { dependencies: {}, devDependencies: {} };
182
+ const agree = (where, key, have, value) => {
183
+ if (have !== void 0 && JSON.stringify(have) !== JSON.stringify(value)) throw new Error(`create-nisc: two items disagree about ${where} "${key}"`);
184
+ };
185
+ for (const fragment of parts.map((part) => part.package ?? {})) {
186
+ for (const [key, value] of Object.entries(fragment)) {
187
+ if (key === "scripts" || key === "dependencies" || key === "devDependencies") {
188
+ if (!isRecord2(value)) throw new Error(`create-nisc: a package fragment's ${key} is not an object`);
189
+ const into = key === "scripts" ? scripts : deps[key];
190
+ for (const [name, spec] of Object.entries(value)) {
191
+ if (typeof spec !== "string") throw new Error(`create-nisc: ${name} in ${key} is not a string`);
192
+ agree(key, name, into[name], spec);
193
+ into[name] = spec;
194
+ }
195
+ } else {
196
+ agree("the package field", key, fields[key], value);
197
+ fields[key] = value;
198
+ }
199
+ }
200
+ }
201
+ const sorted = (from) => Object.fromEntries(
202
+ Object.keys(from).sort().map((name) => [name, pin(name, from[name] ?? "", options)])
203
+ );
204
+ return {
205
+ name: options.name,
206
+ ...fields,
207
+ ...Object.keys(scripts).length > 0 ? { scripts } : {},
208
+ dependencies: sorted(deps.dependencies),
209
+ devDependencies: sorted(deps.devDependencies)
210
+ };
211
+ };
212
+ var envValue = (name, options) => {
213
+ const value = (options.env?.[name] ?? "").trim();
214
+ if (/\s/.test(value)) throw new Error(`create-nisc: the value given for ${name} has a space or a line break in it`);
215
+ return value;
216
+ };
217
+ var envFiles = (specs, options) => {
218
+ const env = [];
219
+ const example = [];
220
+ const assigned = [];
221
+ const key = (spec) => {
222
+ const comment = `# ${spec.message}${spec.required === true ? " (required)" : ""}`;
223
+ const line = `${spec.name}=${envValue(spec.name, options)}`;
224
+ env.push(comment, line);
225
+ example.push(comment, `${spec.name}=`);
226
+ assigned.push(line);
227
+ };
228
+ for (const spec of specs) {
229
+ if (!isChoice(spec)) {
230
+ key(spec);
231
+ continue;
232
+ }
233
+ const value = envValue(spec.choose, options) || (spec.options[0]?.value ?? "");
234
+ const option = spec.options.find((candidate) => candidate.value === value);
235
+ if (option === void 0) throw new Error(`create-nisc: ${spec.choose} is one of ${spec.options.map((candidate) => candidate.value).join(", ")} \u2014 not "${value}"`);
236
+ const comment = `# ${spec.message} (${spec.options.map((candidate) => candidate.value).join(" | ")})`;
237
+ env.push(comment, `${spec.choose}=${value}`);
238
+ example.push(comment, `${spec.choose}=${value}`);
239
+ assigned.push(`${spec.choose}=${value}`);
240
+ for (const inner of option.keys ?? []) key(inner);
241
+ }
242
+ return { env: `${env.join("\n")}
243
+ `, example: `${example.join("\n")}
244
+ `, assigned };
245
+ };
246
+ var generate = (options) => {
247
+ const catalog = readCatalog(options.templates ?? TEMPLATES);
248
+ const items = itemsOf(catalog, options.picks);
249
+ const parts = partsOf(items);
250
+ if (!validName(options.name)) throw new Error(`create-nisc: "${options.name}" is not a package name (lowercase letters, digits, - . _)`);
251
+ if (existsSync(options.dir) && !statSync(options.dir).isDirectory()) throw new Error(`create-nisc: ${options.dir} is a file`);
252
+ const planned = /* @__PURE__ */ new Map();
253
+ for (const [rel, { from }] of sourcesOf(catalog.root, items)) {
254
+ planned.set(rel, TEXT.has(extname(rel)) ? readFileSync(from, "utf8").split(TOKEN).join(options.name) : readFileSync(from));
255
+ }
256
+ planned.set("package.json", `${JSON.stringify(manifestOf(parts, options), null, 2)}
257
+ `);
258
+ const sections2 = items.flatMap((item) => {
259
+ const path = join(catalog.root, item.id, "agents-section.md");
260
+ return existsSync(path) ? [readFileSync(path, "utf8").split(TOKEN).join(options.name)] : [];
261
+ });
262
+ const facts = { name: options.name, today: options.today, nisc: options.versions["@niscorp/nisc"] ?? "unknown", parts, agents: sections2 };
263
+ planned.set("AGENTS.md", agentsDoc(facts));
264
+ planned.set("PLAN.md", planDoc(facts));
265
+ const specs = envOf(items);
266
+ const envs = specs.length > 0 ? envFiles(specs, options) : void 0;
267
+ if (envs !== void 0) planned.set(".env.example", envs.example);
268
+ const there = (rel) => existsSync(join(options.dir, rel));
269
+ const kept = [...planned.keys()].filter((rel) => KEEP_THEIRS.has(rel) && there(rel));
270
+ const collisions = [...planned.keys()].filter((rel) => !KEEP_THEIRS.has(rel) && there(rel)).sort();
271
+ if (collisions.length > 0) {
272
+ throw new Error(
273
+ `create-nisc: ${options.dir} already has ${collisions.length === 1 ? "a file" : "files"} a new app would write \u2014 nothing was written:
274
+ ${collisions.join("\n ")}
275
+ Make the app in an empty folder, or in a subfolder of this one.`
276
+ );
277
+ }
278
+ for (const rel of kept) planned.delete(rel);
279
+ const extended = [];
280
+ const addTo = (rel, fresh, lines, has) => {
281
+ const path = join(options.dir, rel);
282
+ if (!existsSync(path)) {
283
+ planned.set(rel, fresh);
284
+ return;
285
+ }
286
+ const theirs = readFileSync(path, "utf8");
287
+ const have = new Set(theirs.split("\n").map((line) => line.trim()));
288
+ const missing = lines.filter((line) => !has(line, have));
289
+ if (missing.length === 0) return;
290
+ planned.set(rel, `${theirs.replace(/\n*$/, "\n")}${missing.join("\n")}
291
+ `);
292
+ extended.push(rel);
293
+ };
294
+ addTo(".gitignore", `${gitignoreLines.join("\n")}
295
+ `, gitignoreLines, (line, have) => have.has(line));
296
+ if (envs !== void 0) {
297
+ const named = (line) => line.slice(0, line.indexOf("=") + 1);
298
+ addTo(".env", envs.env, envs.assigned, (line, have) => [...have].some((theirs) => theirs.startsWith(named(line))));
299
+ }
300
+ for (const [rel, content] of planned) {
301
+ const to = join(options.dir, rel);
302
+ mkdirSync(dirname(to), { recursive: true });
303
+ writeFileSync(to, content);
304
+ }
305
+ return { files: [...planned.keys()].filter((rel) => !extended.includes(rel)).sort(), kept, extended };
306
+ };
307
+
308
+ // src/set.ts
309
+ var testedSet = () => {
310
+ if (typeof define_NISC_SET_default === "undefined") throw new Error("create-nisc: this copy was not built \u2014 it carries no nisc release to pin a new app to");
311
+ return define_NISC_SET_default;
312
+ };
313
+
314
+ export { TEMPLATES, completed, envOf, generate, isChoice, itemsOf, offered, readCatalog, testedSet, validName };
315
+ //# sourceMappingURL=chunk-B3L4UJDN.js.map
316
+ //# sourceMappingURL=chunk-B3L4UJDN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["%3Cdefine:__NISC_SET__%3E","../src/catalog/items.ts","../src/catalog/choose.ts","../src/docs.ts","../src/generate.ts","../src/set.ts"],"names":["offered","existsSync","join","readdirSync","isRecord","readFileSync","sections"],"mappings":";;;;;AAAA,IAAA,uBAAA,GAAA,EAAC,kBAAA,EAAmB,OAAA,EAAQ,cAAA,EAAe,OAAA,EAAQ,iBAAA,EAAkB,SAAQ,eAAA,EAAgB,OAAA,EAAQ,eAAA,EAAgB,OAAA,EAAQ,eAAA,EAAgB,OAAA,EAAQ,iBAAgB,OAAA,EAAQ,gBAAA,EAAiB,OAAA,EAAQ,iBAAA,EAAkB,OAAA,EAAQ,gBAAA,EAAiB,OAAA,EAAQ,iBAAA,EAAkB,OAAA,EAAQ,eAAA,EAAgB,OAAA,EAAQ,cAAA,EAAe,OAAA,EAAO;ACwCjU,IAAM,QAAA,GAAW,CAAC,KAAA,KAAqD,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAE1I,IAAM,IAAA,GAAO,CAAC,IAAA,KAA0B;AACtC,EAAA,IAAI;AACF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0\",\"@niscorp/moss\":\"0.8.1\",\"@niscorp/nisc\":\"0.8.2\",\"@niscorp/nova\":\"0.5.0\",\"@niscorp/prism\":\"0.3.1\",\"@niscorp/signal\":\"0.1.5\",\"@niscorp/solid\":\"0.1.2\",\"@niscorp/strata\":\"0.1.7\",\"@niscorp/tide\":\"0.1.7\",\"@niscorp/vex\":\"0.4.1\"}","import { existsSync, readdirSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport type EnvKey = { name: string; message: string; required?: boolean };\nexport type EnvOption = { value: string; label: string; hint?: string; keys?: readonly EnvKey[] };\nexport type EnvChoice = { choose: string; message: string; options: readonly EnvOption[] };\nexport type EnvSpec = EnvKey | EnvChoice;\n\nexport type Docs = {\n is?: string;\n where?: readonly string[];\n runs?: readonly string[];\n decisions?: readonly string[];\n answered?: readonly string[];\n open?: readonly string[];\n order?: readonly string[];\n};\n\nexport type Part = {\n package?: Readonly<Record<string, unknown>>;\n env?: readonly EnvSpec[];\n docs?: Docs;\n};\n\nexport type Item = Part & {\n id: string;\n answers?: string;\n label?: string;\n hint?: string;\n usage?: string;\n summary?: string;\n default?: boolean;\n requires?: Readonly<Record<string, string>>;\n with?: Readonly<Record<string, Part>>;\n};\n\nexport type Question = { id: string; message: string };\n\nexport type Catalog = { root: string; questions: readonly Question[]; items: readonly Item[] };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst json = (path: string): unknown => {\n try {\n return JSON.parse(readFileSync(path, 'utf8'));\n } catch (error) {\n throw new Error(`create-nisc: ${path} is not JSON — ${error instanceof Error ? error.message : String(error)}`);\n }\n};\n\nexport const isChoice = (spec: EnvSpec): spec is EnvChoice => 'choose' in spec;\n\n// The templates are ours, so a mistake in them is a bug: it is refused here with a sentence, before anything is written.\nexport const readCatalog = (root: string): Catalog => {\n const questions = json(join(root, 'questions.json'));\n if (!Array.isArray(questions) || !questions.every((q) => isRecord(q) && typeof q['id'] === 'string' && typeof q['message'] === 'string')) {\n throw new Error(`create-nisc: ${root}/questions.json is not a list of { id, message }`);\n }\n const items: Item[] = readdirSync(root, { withFileTypes: true })\n .filter((entry) => entry.isDirectory() && existsSync(join(root, entry.name, 'item.json')))\n .map((entry) => {\n const item = json(join(root, entry.name, 'item.json'));\n if (!isRecord(item) || item['id'] !== entry.name) throw new Error(`create-nisc: ${entry.name}/item.json must say \"id\": \"${entry.name}\"`);\n return item as Item;\n });\n\n const asked = new Set((questions as Question[]).map((q) => q.id));\n const known = new Set(items.map((item) => item.id));\n const answering = (question: string): Item[] => items.filter((item) => item.answers === question);\n for (const item of items) {\n if (item.answers !== undefined && !asked.has(item.answers)) throw new Error(`create-nisc: item \"${item.id}\" answers \"${item.answers}\", which questions.json does not ask`);\n if (item.answers !== undefined && item.label === undefined) throw new Error(`create-nisc: item \"${item.id}\" answers a question but has no label to offer`);\n for (const [question, wanted] of Object.entries(item.requires ?? {})) {\n if (!answering(question).some((other) => other.id === wanted)) throw new Error(`create-nisc: item \"${item.id}\" requires \"${wanted}\" for \"${question}\", which no item answering it is`);\n }\n for (const other of Object.keys(item.with ?? {})) if (!known.has(other)) throw new Error(`create-nisc: item \"${item.id}\" has a part for \"${other}\", which is no item`);\n }\n for (const question of questions as Question[]) {\n const offered = answering(question.id);\n if (offered.length === 0) throw new Error(`create-nisc: nothing answers \"${question.id}\"`);\n if (offered.filter((item) => item.default === true).length !== 1) throw new Error(`create-nisc: exactly one item answering \"${question.id}\" is its default`);\n }\n return { root, questions: questions as Question[], items };\n};\n","import type { Catalog, EnvSpec, Item, Part } from './items';\n\n// Question id → the id of the item that answers it.\nexport type Picks = Readonly<Record<string, string>>;\n\nconst itemNamed = (catalog: Catalog, id: string): Item | undefined => catalog.items.find((item) => item.id === id);\n\n// What the items picked so far say other questions must be answered with.\nexport const impliedBy = (catalog: Catalog, picks: Picks): Record<string, string> => {\n const implied: Record<string, string> = {};\n for (const id of Object.values(picks)) Object.assign(implied, itemNamed(catalog, id)?.requires ?? {});\n return implied;\n};\n\n// The items that can still answer a question, beside what is picked.\nexport const offered = (catalog: Catalog, question: string, picks: Picks): Item[] => {\n const implied = impliedBy(catalog, picks)[question];\n return catalog.items.filter(\n (item) =>\n item.answers === question &&\n (implied === undefined || implied === item.id) &&\n Object.entries(item.requires ?? {}).every(([other, wanted]) => picks[other] === undefined || picks[other] === wanted),\n );\n};\n\n// Answers every question the picks leave open the way a person who takes the defaults would.\nexport const completed = (catalog: Catalog, picks: Picks): Record<string, string> => {\n const done: Record<string, string> = { ...picks };\n for (const question of catalog.questions) {\n if (done[question.id] !== undefined) continue;\n const choices = offered(catalog, question.id, done);\n const chosen = choices.find((item) => item.default === true) ?? choices[0];\n if (chosen === undefined) throw new Error(`create-nisc: nothing can answer \"${question.message}\" beside ${Object.values(done).join(', ')}`);\n done[question.id] = chosen.id;\n }\n return done;\n};\n\n// The items an app is made of: the one answering each question, in the order they are asked, then the ones every\n// app has. Refused when a question is unanswered or an item's requirement is not met.\nexport const itemsOf = (catalog: Catalog, picks: Picks): Item[] => {\n const answering = catalog.questions.map((question) => {\n const id = picks[question.id];\n const item = id === undefined ? undefined : itemNamed(catalog, id);\n if (item === undefined || item.answers !== question.id) throw new Error(`create-nisc: \"${question.message}\" has no answer${id === undefined ? '' : ` — \"${id}\" does not answer it`}`);\n return item;\n });\n for (const item of answering) {\n for (const [question, wanted] of Object.entries(item.requires ?? {})) {\n if (picks[question] !== wanted) throw new Error(`create-nisc: \"${item.id}\" needs \"${wanted}\", not \"${picks[question] ?? 'nothing'}\"`);\n }\n }\n return [...answering, ...catalog.items.filter((item) => item.answers === undefined)];\n};\n\n// Each item's own part, followed by its part for every other item the app is made of.\nexport const partsOf = (items: readonly Item[]): Part[] => {\n const ids = new Set(items.map((item) => item.id));\n return items.flatMap((item) => [item, ...Object.entries(item.with ?? {}).flatMap(([other, part]) => (ids.has(other) ? [part] : []))]);\n};\n\nexport const envOf = (items: readonly Item[]): EnvSpec[] => partsOf(items).flatMap((part) => part.env ?? []);\n","import type { Part } from './catalog';\n\nexport type DocFacts = {\n name: string;\n today: string;\n nisc: string;\n parts: readonly Part[];\n // The sections items add to AGENTS.md, each from its own agents-section.md.\n agents: readonly string[];\n};\n\nconst all = <K extends 'is' | 'where' | 'runs' | 'decisions' | 'answered' | 'open' | 'order'>(parts: readonly Part[], key: K): string[] =>\n parts.flatMap((part) => {\n const value = part.docs?.[key];\n return value === undefined ? [] : typeof value === 'string' ? [value] : [...value];\n });\n\nconst decisionNumber = (row: string): number => Number(/^\\| D(\\d+) /.exec(row)?.[1] ?? Number.POSITIVE_INFINITY);\n\nconst sections = (texts: readonly string[]): string => texts.map((text) => `\\n${text.trim()}\\n`).join('');\n\nexport const agentsDoc = (facts: DocFacts): string => {\n const [first = 'a nisc application', ...rest] = all(facts.parts, 'is');\n return `# ${facts.name}\n\nA nisc application. **The rules it is built by are \\`node_modules/@niscorp/nisc/AGENTS.md\\`** — read all of it before changing anything here (it is there once the app's dependencies are installed). It is the rulebook for the nisc version this app has installed, and \\`STYLE_GUIDE.md\\` sits beside it. The grammars it names — a layout node, an \\`ActionDefinition\\`, a Prism config, a charter, a Vex DSL — are in each package's own \\`README.md\\` and \\`DESIGN.md\\`, under \\`node_modules/@niscorp/<name>/\\`.\n\nWhat is particular to this app:\n\n- **Its decisions are in PLAN.md.** What was answered when it was made, what was derived, and what is still open. An open decision point is asked before anything is built on it, never resolved silently.\n- **It is ${first}**${rest.map((clause) => `, ${clause}`).join('')}.\n- **Where things go:**\n\n\\`\\`\\`\n${all(facts.parts, 'where').join('\\n')}\n\\`\\`\\`\n\n- **How it runs:** ${all(facts.parts, 'runs').join(', ')} — all of them the \\`nisc\\` command — and \\`npm run strata status\\` for the grammars.\n${sections(facts.agents)}`;\n};\n\nexport const planDoc = (facts: DocFacts): string => `# PLAN — ${facts.name}\n\nMade ${facts.today} by \\`npm create nisc\\`, on nisc ${facts.nisc}. This is the record AGENTS.md's interview asks for (\"Before any code\"). The walkthrough asked what shapes the files; everything else is **open**, and an open decision blocks the build that depends on it until it is answered by the user or delegated by name. A blanket \"go\" delegates nothing.\n\n## Decision points\n\n| | Tier | |\n|---|---|---|\n${all(facts.parts, 'decisions')\n .sort((a, b) => decisionNumber(a) - decisionNumber(b))\n .join('\\n')}\n\n## Answered when it was made\n\n${all(facts.parts, 'answered')\n .map((line) => `- ${line}`)\n .join('\\n')}\n\n## The dial-in — open\n\n${all(facts.parts, 'open')\n .map((line) => `- ${line}`)\n .join('\\n')}\n\n## Order of work\n\n${all(facts.parts, 'order')\n .map((line, at) => `${at + 1}. ${line}`)\n .join('\\n')}\n`;\n\nexport const gitignoreLines = ['node_modules/', 'dist/', 'out/', '.strata/', '*.tsbuildinfo', '.env', '.env.*', '!.env.example'];\n","import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';\nimport { dirname, extname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { envOf, isChoice, itemsOf, partsOf, readCatalog } from './catalog';\nimport type { EnvKey, EnvSpec, Item, Part, Picks } from './catalog';\nimport { agentsDoc, gitignoreLines, planDoc } from './docs';\n\nexport type CreateOptions = {\n dir: string;\n name: string;\n picks: Picks;\n // The values given for the keys the items ask for, by variable name. A key left out is written empty.\n env?: Readonly<Record<string, string>>;\n versions: Readonly<Record<string, string>>;\n // Depend on the nisc packages of the workspace the app is made in, for an app inside the nisc repository.\n workspace?: boolean;\n // YYYY-MM-DD\n today: string;\n templates?: string;\n};\n\nexport type Created = {\n files: string[];\n kept: string[];\n extended: string[];\n};\n\nexport const TEMPLATES = fileURLToPath(new URL('../templates', import.meta.url));\n\nconst TOKEN = 'nisc-template-app';\nconst SKIP = new Set(['node_modules', 'dist', 'out', '.turbo']);\nconst TEXT = new Set(['.ts', '.tsx', '.json', '.html', '.css', '.md']);\nconst KEEP_THEIRS = new Set(['README.md']);\nconst DEPENDENCIES = ['dependencies', 'devDependencies'] as const;\n\n// npm's rule for a package name.\nexport const validName = (name: string): boolean => /^[a-z0-9][a-z0-9._-]*$/.test(name) && name.length <= 214;\n\nconst filesIn = (dir: string, base = ''): string[] =>\n existsSync(join(dir, base))\n ? readdirSync(join(dir, base), { withFileTypes: true }).flatMap((entry) => {\n if (SKIP.has(entry.name)) return [];\n const rel = base === '' ? entry.name : `${base}/${entry.name}`;\n return entry.isDirectory() ? filesIn(dir, rel) : [rel];\n })\n : [];\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);\n\n// An item's files, then its files for each other item the app is made of (`with/<other>/`).\nconst sourcesOf = (root: string, items: readonly Item[]): Map<string, { item: string; from: string }> => {\n const ids = new Set(items.map((item) => item.id));\n const sources = new Map<string, { item: string; from: string }>();\n for (const item of items) {\n const withDir = join(root, item.id, 'with');\n const others = existsSync(withDir) ? readdirSync(withDir) : [];\n for (const other of others) if (!existsSync(join(root, other, 'item.json'))) throw new Error(`create-nisc: ${item.id}/with/${other} is for \"${other}\", which is no item`);\n const dirs = [join(root, item.id, 'files'), ...others.filter((other) => ids.has(other)).map((other) => join(withDir, other))];\n for (const dir of dirs) {\n for (const rel of filesIn(dir)) {\n const there = sources.get(rel);\n if (there !== undefined) throw new Error(`create-nisc: ${rel} is written by both \"${there.item}\" and \"${item.id}\"`);\n sources.set(rel, { item: item.id, from: join(dir, rel) });\n }\n }\n }\n return sources;\n};\n\nconst pin = (name: string, spec: string, options: CreateOptions): string => {\n if (!spec.startsWith('workspace:') || options.workspace === true) return spec;\n const version = options.versions[name];\n if (version === undefined) throw new Error(`create-nisc: the nisc release has no ${name} — the set it was given is incomplete`);\n return `^${version}`;\n};\n\n// The parts' package fragments as one manifest: fields in the order they come, then the scripts, then the\n// dependencies sorted. Two parts that disagree about one field, script or dependency is a mistake in the templates.\nconst manifestOf = (parts: readonly Part[], options: CreateOptions): Record<string, unknown> => {\n const fields: Record<string, unknown> = {};\n const scripts: Record<string, string> = {};\n const deps: Record<(typeof DEPENDENCIES)[number], Record<string, string>> = { dependencies: {}, devDependencies: {} };\n const agree = (where: string, key: string, have: unknown, value: unknown): void => {\n if (have !== undefined && JSON.stringify(have) !== JSON.stringify(value)) throw new Error(`create-nisc: two items disagree about ${where} \"${key}\"`);\n };\n for (const fragment of parts.map((part) => part.package ?? {})) {\n for (const [key, value] of Object.entries(fragment)) {\n if (key === 'scripts' || key === 'dependencies' || key === 'devDependencies') {\n if (!isRecord(value)) throw new Error(`create-nisc: a package fragment's ${key} is not an object`);\n const into = key === 'scripts' ? scripts : deps[key];\n for (const [name, spec] of Object.entries(value)) {\n if (typeof spec !== 'string') throw new Error(`create-nisc: ${name} in ${key} is not a string`);\n agree(key, name, into[name], spec);\n into[name] = spec;\n }\n } else {\n agree('the package field', key, fields[key], value);\n fields[key] = value;\n }\n }\n }\n const sorted = (from: Record<string, string>): Record<string, string> =>\n Object.fromEntries(\n Object.keys(from)\n .sort()\n .map((name) => [name, pin(name, from[name] ?? '', options)]),\n );\n return {\n name: options.name,\n ...fields,\n ...(Object.keys(scripts).length > 0 ? { scripts } : {}),\n dependencies: sorted(deps.dependencies),\n devDependencies: sorted(deps.devDependencies),\n };\n};\n\nconst envValue = (name: string, options: CreateOptions): string => {\n const value = (options.env?.[name] ?? '').trim();\n if (/\\s/.test(value)) throw new Error(`create-nisc: the value given for ${name} has a space or a line break in it`);\n return value;\n};\n\n// `.env` with the values given, `.env.example` with the names alone. A choice keeps its value in both: it is not a\n// secret, and it says which keys follow.\nconst envFiles = (specs: readonly EnvSpec[], options: CreateOptions): { env: string; example: string; assigned: string[] } => {\n const env: string[] = [];\n const example: string[] = [];\n const assigned: string[] = [];\n const key = (spec: EnvKey): void => {\n const comment = `# ${spec.message}${spec.required === true ? ' (required)' : ''}`;\n const line = `${spec.name}=${envValue(spec.name, options)}`;\n env.push(comment, line);\n example.push(comment, `${spec.name}=`);\n assigned.push(line);\n };\n for (const spec of specs) {\n if (!isChoice(spec)) {\n key(spec);\n continue;\n }\n const value = envValue(spec.choose, options) || (spec.options[0]?.value ?? '');\n const option = spec.options.find((candidate) => candidate.value === value);\n if (option === undefined) throw new Error(`create-nisc: ${spec.choose} is one of ${spec.options.map((candidate) => candidate.value).join(', ')} — not \"${value}\"`);\n const comment = `# ${spec.message} (${spec.options.map((candidate) => candidate.value).join(' | ')})`;\n env.push(comment, `${spec.choose}=${value}`);\n example.push(comment, `${spec.choose}=${value}`);\n assigned.push(`${spec.choose}=${value}`);\n for (const inner of option.keys ?? []) key(inner);\n }\n return { env: `${env.join('\\n')}\\n`, example: `${example.join('\\n')}\\n`, assigned };\n};\n\nexport const generate = (options: CreateOptions): Created => {\n const catalog = readCatalog(options.templates ?? TEMPLATES);\n const items = itemsOf(catalog, options.picks);\n const parts = partsOf(items);\n if (!validName(options.name)) throw new Error(`create-nisc: \"${options.name}\" is not a package name (lowercase letters, digits, - . _)`);\n if (existsSync(options.dir) && !statSync(options.dir).isDirectory()) throw new Error(`create-nisc: ${options.dir} is a file`);\n\n const planned = new Map<string, string | Buffer>();\n for (const [rel, { from }] of sourcesOf(catalog.root, items)) {\n planned.set(rel, TEXT.has(extname(rel)) ? readFileSync(from, 'utf8').split(TOKEN).join(options.name) : readFileSync(from));\n }\n planned.set('package.json', `${JSON.stringify(manifestOf(parts, options), null, 2)}\\n`);\n\n const sections = items.flatMap((item) => {\n const path = join(catalog.root, item.id, 'agents-section.md');\n return existsSync(path) ? [readFileSync(path, 'utf8').split(TOKEN).join(options.name)] : [];\n });\n const facts = { name: options.name, today: options.today, nisc: options.versions['@niscorp/nisc'] ?? 'unknown', parts, agents: sections };\n planned.set('AGENTS.md', agentsDoc(facts));\n planned.set('PLAN.md', planDoc(facts));\n\n const specs = envOf(items);\n const envs = specs.length > 0 ? envFiles(specs, options) : undefined;\n if (envs !== undefined) planned.set('.env.example', envs.example);\n\n const there = (rel: string): boolean => existsSync(join(options.dir, rel));\n const kept = [...planned.keys()].filter((rel) => KEEP_THEIRS.has(rel) && there(rel));\n const collisions = [...planned.keys()].filter((rel) => !KEEP_THEIRS.has(rel) && there(rel)).sort();\n if (collisions.length > 0) {\n throw new Error(\n `create-nisc: ${options.dir} already has ${collisions.length === 1 ? 'a file' : 'files'} a new app would write — nothing was written:\\n ${collisions.join('\\n ')}\\nMake the app in an empty folder, or in a subfolder of this one.`,\n );\n }\n for (const rel of kept) planned.delete(rel);\n\n // A .gitignore or .env that is there is added to, never replaced: what it holds is theirs.\n const extended: string[] = [];\n const addTo = (rel: string, fresh: string, lines: readonly string[], has: (line: string, theirs: ReadonlySet<string>) => boolean): void => {\n const path = join(options.dir, rel);\n if (!existsSync(path)) {\n planned.set(rel, fresh);\n return;\n }\n const theirs = readFileSync(path, 'utf8');\n const have = new Set(theirs.split('\\n').map((line) => line.trim()));\n const missing = lines.filter((line) => !has(line, have));\n if (missing.length === 0) return;\n planned.set(rel, `${theirs.replace(/\\n*$/, '\\n')}${missing.join('\\n')}\\n`);\n extended.push(rel);\n };\n addTo('.gitignore', `${gitignoreLines.join('\\n')}\\n`, gitignoreLines, (line, have) => have.has(line));\n if (envs !== undefined) {\n const named = (line: string): string => line.slice(0, line.indexOf('=') + 1);\n addTo('.env', envs.env, envs.assigned, (line, have) => [...have].some((theirs) => theirs.startsWith(named(line))));\n }\n\n for (const [rel, content] of planned) {\n const to = join(options.dir, rel);\n mkdirSync(dirname(to), { recursive: true });\n writeFileSync(to, content);\n }\n return { files: [...planned.keys()].filter((rel) => !extended.includes(rel)).sort(), kept, extended };\n};\n","// Written in when this package is built (tsup.config.ts), never looked up:\n// \"whatever is newest on npm\" would be a set nobody tested the templates with.\ndeclare const __NISC_SET__: Readonly<Record<string, string>> | undefined;\n\nexport const testedSet = (): Readonly<Record<string, string>> => {\n if (typeof __NISC_SET__ === 'undefined') throw new Error('create-nisc: this copy was not built — it carries no nisc release to pin a new app to');\n return __NISC_SET__;\n};\n"]}