create-nisc 0.8.0 → 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 +20 -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-RU5ATATK.js +0 -174
  77. package/dist/chunk-RU5ATATK.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
@@ -0,0 +1,90 @@
1
+ import { GUIDE } from '../app/actions/guide/guide.actions';
2
+ import { SCREENS } from '../app/screens';
3
+ import { recordOf } from '../server/compose/record';
4
+ import { checks } from './checks';
5
+ import { scriptedModels, settle, startApp, until } from './scripted';
6
+ import type { Script } from './scripted';
7
+
8
+ const card = (action: string) => ({ action, input: {}, intent: action });
9
+ const counter = (title: string, count: number) => ({ action: 'guide.counter', input: { title, count }, intent: 'a counter' });
10
+ const checklist = (title: string, todo: string[]) => ({ action: 'guide.checklist', input: { title, todo }, intent: 'a checklist' });
11
+
12
+ const SCRIPT: Script = {
13
+ 'What is the charter?': [{ response: 'Put the charter where the nisc card was; the rest stays.', title: 'The charter', areas: [{ area: 'e', ...card('guide.charter') }] }],
14
+ 'A counter that starts at 100': [{ areas: [{ area: 'b', ...counter('From 100', 100) }] }],
15
+ 'A checklist with no steps': [{ areas: [{ area: 'd', ...checklist('Empty', []) }] }, { areas: [{ area: 'd', ...checklist('Mine', ['One step']) }] }],
16
+ 'the nisc card at the top too': [{ areas: [{ area: 'a', ...card('guide.nisc') }] }, { areas: [] }],
17
+ 'a counter at 5, no title': [{ areas: [{ area: 'b', action: 'guide.counter', input: { title: null, count: 5 }, intent: 'a counter' }] }],
18
+ };
19
+
20
+ const { check, finish } = checks('guide');
21
+
22
+ const nowhere = GUIDE.flatMap((action) => (Array.isArray(action.data?.['links']) ? action.data['links'] : []).map((link: unknown) => recordOf(link)['screen'])).filter((screen) => !SCREENS.some((one) => one.id === screen));
23
+ check('every link on a card opens a screen there is', nowhere.length === 0, nowhere.join(', '));
24
+
25
+ const scripted = scriptedModels(SCRIPT);
26
+ const { prompts } = scripted;
27
+ const lastPrompt = (): string => prompts[prompts.length - 1] ?? '';
28
+ const app = await startApp(scripted.models);
29
+ const { on, rows, ids, without, current, drawn, areas, ask, session } = app;
30
+ try {
31
+ app.draw();
32
+ session.dispatch('b', { type: 'ui:click', ref: 'up' });
33
+ session.dispatch('b', { type: 'ui:click', ref: 'up' });
34
+ session.dispatch('b', { type: 'ui:click', ref: 'down' });
35
+ session.dispatch('b', { type: 'ui:click', ref: 'up' });
36
+ check('the counter counts what is pressed, up and down', await until(() => on('b').data['count'] === 2), JSON.stringify(on('b').data));
37
+ session.dispatch('c', { type: 'ui:click', ref: 'pick', payload: 1 });
38
+ check('the quick check, picked right, says so and why', await until(() => drawn().includes('Right. Links act at once')), JSON.stringify(on('c').data));
39
+ session.dispatch('d', { type: 'ui:click', ref: 'tick', payload: 0 });
40
+ check('a step ticked off moves from the steps to do to the ones done', await until(() => rows('d', 'done').join() === 'Press the counter' && rows('d', 'todo').length === 4), JSON.stringify(on('d').data));
41
+ app.draw();
42
+ session.dispatch('d', { type: 'ui:model', ref: 'adding', payload: 'Read the charter' });
43
+ session.dispatch('d', { type: 'ui:click', ref: 'add' });
44
+ check('a step typed and added goes last among the steps to do, and the line empties', await until(() => rows('d', 'todo').at(-1) === 'Read the charter' && on('d').data['adding'] === ''), JSON.stringify(on('d').data));
45
+
46
+ const startIds = ids();
47
+ await ask('What is the charter?');
48
+ check(
49
+ 'the model is given each card as the person left it: the count pressed, the steps ticked and added, the pick made',
50
+ lastPrompt().includes('input {"title":"Press me","count":2}') && lastPrompt().includes('"done":["Press the counter"]') && lastPrompt().includes('"Ask the model to change a card","Read the charter"]') && lastPrompt().includes('"picked":1}'),
51
+ lastPrompt().slice(0, 1600),
52
+ );
53
+ check('a card the model puts on the screen goes where it says, and nothing else moves', without('e', ids()) === without('e', startIds) && on('e').action === 'guide.charter', `${ids()} vs ${startIds}`);
54
+ check('a card the answer leaves alone keeps what the person did to it', on('b').data['count'] === 2 && rows('d', 'done').length === 1 && on('c').data['picked'] === 1, JSON.stringify(on('b').data));
55
+ check('a guide card holds its own text: its lead, its example, and where it leads', on('e').data['title'] === 'The charter' && String(on('e').data['example']).includes('"public"') && rows('e', 'links').length === 1, JSON.stringify(on('e').data).slice(0, 200));
56
+
57
+ const link = recordOf(rows('e', 'links')[0]);
58
+ const promptsBeforeLink = prompts.length;
59
+ session.dispatch('e', { type: 'ui:click', ref: 'link', payload: link['screen'] });
60
+ check(
61
+ 'a card’s link opens its screen at once, and asks nothing of the model',
62
+ (await until(() => current().screen === link['screen'])) && prompts.length === promptsBeforeLink && areas() === 'guide.yours guide.checklist',
63
+ `${String(current().screen)} — ${areas()}`,
64
+ );
65
+ await settle();
66
+ await app.openScreen('start');
67
+ check('a screen gone back to is as the person left it', on('b').data['count'] === 2 && rows('d', 'done').join() === 'Press the counter' && on('c').data['picked'] === 1, `${JSON.stringify(on('b').data)} ${JSON.stringify(on('d').data)}`);
68
+ await app.openScreen('asking');
69
+ check('another quick check where an answered one was opens unanswered', on('c').action === 'guide.quiz' && on('c').data['picked'] === -1, JSON.stringify(on('c').data));
70
+ await app.openScreen('start');
71
+
72
+ const counterId = on('b').id;
73
+ await ask('A counter that starts at 100');
74
+ check('a card the model opens again with another input keeps its place and its instance, and takes the input', on('b').id === counterId && on('b').data['count'] === 100 && on('b').data['title'] === 'From 100', JSON.stringify(on('b').data));
75
+ session.dispatch('b', { type: 'ui:click', ref: 'reset' });
76
+ check('Reset sets the counter back to zero, whatever it was opened with', await until(() => on('b').data['count'] === 0), JSON.stringify(on('b').data));
77
+ prompts.length = 0;
78
+ await ask('A checklist with no steps');
79
+ check('a checklist with no steps is sent back saying so', (prompts[1] ?? '').includes('input.todo') && on('d').data['title'] === 'Mine', prompts[1]?.slice(-300) ?? '');
80
+ check('a checklist the model writes where another was keeps none of its ticks', rows('d', 'done').length === 0 && rows('d', 'todo').join() === 'One step', JSON.stringify(on('d').data));
81
+ prompts.length = 0;
82
+ await ask('the nisc card at the top too');
83
+ check('the same card in two areas is sent back saying so', (prompts[1] ?? '').includes('areas a and e would show the same thing; show it once'), prompts[1]?.slice(-300) ?? '');
84
+ await ask('a counter at 5, no title');
85
+ check('a value the model says is null is its card’s default', on('b').data['count'] === 5 && on('b').data['title'] === 'Press me', JSON.stringify(on('b').data));
86
+ } finally {
87
+ app.server.close();
88
+ }
89
+
90
+ finish();
@@ -0,0 +1,185 @@
1
+ import { existsSync } from 'node:fs';
2
+ import type { SignalClient } from '@niscorp/cortex';
3
+ import { AREAS } from '../app/shell/areas';
4
+ import type { Chat, Jev } from '../server/compose';
5
+ import { modelsFromEnv } from '../server/models';
6
+ import { startApp } from './scripted';
7
+
8
+ type Shown = { area: string; id: string; action: string; title: string; data: Record<string, unknown> };
9
+ type Screen = { canvases: Shown[]; arrangement: string; screen: string; said: string; response: string; title: string };
10
+ type Step = { ask: string; want?: (now: Screen, before: Screen) => string | undefined } | { open: string };
11
+
12
+ const at = (screen: Screen, area: string): Shown | undefined => screen.canvases.find((shown) => shown.area === area);
13
+ const is = (shown: Shown | undefined, action: string): boolean => shown?.action === action;
14
+ const has = (screen: Screen, action: string): boolean => screen.canvases.some((shown) => is(shown, action));
15
+
16
+ // Two areas showing the same card with the same content is never the screen a message wants.
17
+ const twice = (now: Screen): string | undefined => {
18
+ const seen = now.canvases.filter((shown) => shown.action !== 'answer.text').map((shown) => JSON.stringify([shown.action, shown.data]));
19
+ return new Set(seen).size === seen.length ? undefined : 'the same card is shown twice';
20
+ };
21
+
22
+ const shows = (action: string) => (now: Screen): string | undefined => (has(now, action) ? undefined : `want ${action}`);
23
+ const listOf = (value: unknown): unknown[] => (Array.isArray(value) ? value : []);
24
+ const tour = (screen: Screen): Shown | undefined => screen.canvases.find((shown) => is(shown, 'guide.checklist'));
25
+
26
+ const RUN: readonly Step[] = [
27
+ { open: 'start' },
28
+ { ask: 'What is an action?', want: shows('guide.actions') },
29
+ { open: 'start' },
30
+ { ask: 'Who may do what?', want: shows('guide.charter') },
31
+ { open: 'start' },
32
+ { ask: 'How does my message become a screen?', want: shows('guide.answers') },
33
+ { open: 'start' },
34
+ { ask: 'A counter that starts at 100', want: (now) => (now.canvases.some((shown) => is(shown, 'guide.counter') && shown.data['count'] === 100) ? undefined : 'want a counter at 100') },
35
+ { open: 'start' },
36
+ { ask: 'A checklist for my first nisc app', want: (now) => (now.canvases.some((shown) => is(shown, 'guide.checklist') && shown.title !== 'Your tour' && listOf(shown.data['todo']).length > 0) ? undefined : 'want a checklist of its own, with steps') },
37
+ { open: 'start' },
38
+ {
39
+ ask: 'Quiz me on the charter',
40
+ want: (now, before) => {
41
+ const asked = new Set(before.canvases.filter((shown) => is(shown, 'guide.quiz')).map((shown) => String(shown.data['question'])));
42
+ return now.canvases.some((shown) => is(shown, 'guide.quiz') && !asked.has(String(shown.data['question']))) ? undefined : 'want a new quick check';
43
+ },
44
+ },
45
+ { open: 'start' },
46
+ {
47
+ ask: 'tick off the first step of my tour',
48
+ want: (now, before) => (tour(now)?.id === tour(before)?.id && listOf(tour(now)?.data['done']).includes('Press the counter') ? undefined : 'want "Press the counter" ticked off, on the same checklist'),
49
+ },
50
+ { ask: 'add "Read the charter" to the tour', want: (now) => (listOf(tour(now)?.data['todo']).some((step) => /charter/i.test(String(step))) ? undefined : 'want the step added to the tour') },
51
+ { open: 'start' },
52
+ {
53
+ ask: 'Put the charter beside the counter',
54
+ want: (now, before) => {
55
+ const counter = before.canvases.find((shown) => is(shown, 'guide.counter'));
56
+ return counter !== undefined && at(now, counter.area)?.id === counter.id && has(now, 'guide.charter') ? undefined : 'want the counter where it was, and the charter';
57
+ },
58
+ },
59
+ { open: 'start' },
60
+ { ask: 'What can you do?', want: (now) => (has(now, 'answer.text') || has(now, 'guide.welcome') ? undefined : 'want words, or the welcome') },
61
+ { open: 'asking' },
62
+ { ask: 'Only the steps, please', want: (now) => (now.canvases.length === 1 && is(now.canvases[0], 'guide.answers') ? undefined : 'want the steps alone') },
63
+ { open: 'start' },
64
+ { ask: 'What are layouts?', want: shows('guide.layouts') },
65
+ {
66
+ ask: 'and the shell beside it',
67
+ want: (now, before) => {
68
+ const layouts = before.canvases.find((shown) => shown.action === 'guide.layouts');
69
+ return layouts !== undefined && at(now, layouts.area)?.id === layouts.id && has(now, 'guide.shell') ? undefined : 'want the layouts card where it was, and the shell';
70
+ },
71
+ },
72
+ {
73
+ ask: 'now the charter instead of the shell',
74
+ want: (now, before) => {
75
+ const shell = before.canvases.find((shown) => shown.action === 'guide.shell');
76
+ const layouts = before.canvases.find((shown) => shown.action === 'guide.layouts');
77
+ const there = shell === undefined ? undefined : at(now, shell.area);
78
+ return is(there, 'guide.charter') && (layouts === undefined || at(now, layouts.area)?.id === layouts.id) ? undefined : 'want the charter where the shell was, and the layouts card untouched';
79
+ },
80
+ },
81
+ { ask: 'Show me the rules lesson', want: (now) => (now.screen === 'rules' ? undefined : 'want the rules screen') },
82
+ { open: 'start' },
83
+ { ask: 'How do I make this app mine?', want: shows('guide.yours') },
84
+ ];
85
+
86
+ const prompts = process.argv.includes('--prompts');
87
+ const why = prompts || process.argv.includes('--why');
88
+ const runs = Number(process.argv.find((arg) => arg.startsWith('--runs='))?.slice('--runs='.length) ?? 1);
89
+ const noJev = process.argv.includes('--no-jev');
90
+ const own = process.argv.slice(2).filter((arg) => !arg.startsWith('--') || arg.startsWith('--screen='));
91
+ const steps: readonly Step[] = own.length > 0 ? own.map((arg): Step => (arg.startsWith('--screen=') ? { open: arg.slice('--screen='.length) } : { ask: arg })) : RUN;
92
+
93
+ if (existsSync('.env')) process.loadEnvFile('.env');
94
+ const models = modelsFromEnv(process.env);
95
+ const said: string[] = [];
96
+ const jevWith = noJev ? undefined : models.jev;
97
+ const jev: Jev | undefined = jevWith && {
98
+ ...jevWith,
99
+ decide: async (state, questions) => {
100
+ const answered = await jevWith.decide(state, questions);
101
+ const picked = answered.picked;
102
+ if (prompts) said.push(`──── JEV STATE
103
+ ${JSON.stringify(state, null, 2)}
104
+ ──── JEV QUESTIONS
105
+ ${JSON.stringify(questions, null, 2)}
106
+ ──── JEV ANSWERED
107
+ ${JSON.stringify(picked, null, 2)}`);
108
+ const yes = Object.entries(picked).flatMap(([name, one]) => (one.yes ? [name] : []));
109
+ said.push(` Jev: ${yes.join(' ')}`);
110
+ return answered;
111
+ },
112
+ };
113
+ const told = (llm: SignalClient): SignalClient => ({
114
+ ...llm,
115
+ stepStream: (request, options) =>
116
+ (async function* () {
117
+ if (prompts) said.push(request.messages.map((message) => `──── ${message.role.toUpperCase()}\n${typeof message.content === 'string' ? message.content : JSON.stringify(message.content)}`).join('\n'));
118
+ for await (const event of llm.stepStream(request, options)) {
119
+ if (event.type === 'done') said.push(` model: ${event.result.content}`);
120
+ yield event;
121
+ }
122
+ })(),
123
+ });
124
+ const chat: Chat | undefined = models.chat && { ...models.chat, llm: told(models.chat.llm) };
125
+
126
+ const times: number[] = [];
127
+ const scores: number[] = [];
128
+ const misses = new Map<string, number>();
129
+ for (let run = 1; run <= runs; run += 1) {
130
+ const app = await startApp({ missing: models.missing, ...(jev !== undefined ? { jev } : {}), ...(chat !== undefined ? { chat } : {}) }, 60_000);
131
+ const screenOf = (): Screen => ({
132
+ canvases: AREAS.flatMap((area): Shown[] => {
133
+ const { id, action, data } = app.on(area);
134
+ return id === '' ? [] : [{ area, id, action, title: String(data['title'] ?? ''), data }];
135
+ }),
136
+ arrangement: app.current().arrangement ?? '',
137
+ screen: app.current().screen ?? '',
138
+ said: app.said(),
139
+ response: app.current().response ?? '',
140
+ title: app.current().label ?? '',
141
+ });
142
+ const print = (screen: Screen): string => screen.canvases.map((shown) => ` ${shown.area}: ${shown.action} — ${shown.title}`).join('\n');
143
+
144
+ let right = 0;
145
+ let scored = 0;
146
+ console.log(`\n═══ run ${run}`);
147
+ try {
148
+ for (const step of steps) {
149
+ if ('open' in step) {
150
+ await app.openScreen(step.open);
151
+ console.log(`» opened "${step.open}"`);
152
+ continue;
153
+ }
154
+ const before = screenOf();
155
+ const took = await app.ask(step.ask);
156
+ if (took !== undefined) times.push(took);
157
+ const screen = screenOf();
158
+ const miss = took === undefined ? 'no answer in 60 s' : screen.said !== '' ? `the line says: ${screen.said}` : (twice(screen) ?? step.want?.(screen, before));
159
+ if (step.want !== undefined) {
160
+ scored += 1;
161
+ if (miss === undefined) right += 1;
162
+ else misses.set(step.ask, (misses.get(step.ask) ?? 0) + 1);
163
+ }
164
+ const verdict = step.want === undefined ? '' : miss === undefined ? ' ✓' : ` ✗ ${miss}`;
165
+ console.log(`» "${step.ask}" — ${Math.round(took ?? 0)} ms ·${screen.arrangement}${verdict}${screen.said !== '' ? ` · the line says: ${screen.said}` : ''}\n title: ${screen.title} · response: ${screen.response}\n${print(screen)}`);
166
+ if (why) console.log(said.join('\n'));
167
+ said.length = 0;
168
+ }
169
+ } finally {
170
+ app.server.close();
171
+ }
172
+ if (scored > 0) {
173
+ scores.push(right);
174
+ console.log(`run ${run}: ${right}/${scored} right`);
175
+ }
176
+ }
177
+
178
+ const sorted = [...times].sort((one, other) => one - other);
179
+ console.log(`\n${times.length} messages · median ${Math.round(sorted[Math.floor(sorted.length / 2)] ?? 0)} ms · slowest ${Math.round(sorted[sorted.length - 1] ?? 0)} ms`);
180
+ if (scores.length > 0) {
181
+ const scoredSteps = steps.filter((step) => 'ask' in step && step.want !== undefined).length;
182
+ console.log(`right: ${scores.join(', ')} of ${scoredSteps} · ${scores.reduce((sum, score) => sum + score, 0)}/${scoredSteps * scores.length} in all`);
183
+ for (const [ask, count] of misses) console.log(` missed ${count}×: "${ask}"`);
184
+ }
185
+ process.exit(0);
@@ -0,0 +1,208 @@
1
+ import type { SignalClient, Usage } from '@niscorp/cortex';
2
+ import type { MossServer, RunRecord } from '@niscorp/moss';
3
+ import { routeResponse } from '@niscorp/signal';
4
+ import type { StepRequest, StepResult } from '@niscorp/signal';
5
+ import { z } from 'zod';
6
+ import { AREAS } from '../app/shell/areas';
7
+ import { boot } from '../server/boot';
8
+ import type { Decide, Models } from '../server/compose';
9
+ import { recordOf } from '../server/compose/record';
10
+
11
+ // Each message, and the replies the chat model gives it, one a call: the last one again and again.
12
+ export type Script = Record<string, Record<string, unknown>[]>;
13
+
14
+ export const until = async (condition: () => boolean, ms = 5000): Promise<boolean> => {
15
+ const deadline = Date.now() + ms;
16
+ while (!condition()) {
17
+ if (Date.now() > deadline) return false;
18
+ await new Promise((done) => setTimeout(done, 10));
19
+ }
20
+ return true;
21
+ };
22
+ export const settle = (): Promise<void> => new Promise((done) => setTimeout(done, 150));
23
+
24
+ const SPENT: Usage = { inputTokens: 100, outputTokens: 10, totalTokens: 110, reported: true };
25
+
26
+ export type Scripted = {
27
+ models: Models;
28
+ prompts: string[];
29
+ asked: { state: Record<string, unknown>; questions: Record<string, unknown> }[];
30
+ likely: (ids: readonly string[]) => void;
31
+ unreachable: (is: boolean) => void;
32
+ };
33
+
34
+ // Offline, and the same every run: a decision model that finds likely only the ids it is told to, and a chat model that
35
+ // answers each message in the run's input with its script.
36
+ export const scriptedModels = (script: Script, options: { jevFails?: boolean; keyless?: boolean } = {}): Scripted => {
37
+ let likely: readonly string[] = [];
38
+ let unreachable = false;
39
+ const prompts: string[] = [];
40
+ const asked: Scripted['asked'] = [];
41
+ const turns = new Map<string, number>();
42
+
43
+ const decide: Decide = async (state, questions) => {
44
+ if (options.jevFails === true) throw new Error('Jev did not answer');
45
+ asked.push({ state, questions });
46
+ const answer = (instructions: string): { yes: boolean; probability: number } => (likely.some((id) => instructions.includes(`"${id}"`)) ? { yes: true, probability: 0.9 } : { yes: false, probability: 0.1 });
47
+ return { picked: Object.fromEntries(Object.entries(questions).map(([key, question]) => [key, answer(question.instructions)])), usage: SPENT };
48
+ };
49
+
50
+ const scripted = (request: StepRequest): StepResult => {
51
+ const user = request.messages.map((message) => (typeof message.content === 'string' ? message.content : '')).join('\n\n');
52
+ prompts.push(user);
53
+ if (unreachable) throw new Error('the provider did not answer');
54
+ const message = /^MESSAGE: (.*)$/m.exec(user)?.[1] ?? '';
55
+ const turn = turns.get(message) ?? 0;
56
+ turns.set(message, turn + 1);
57
+ const replies = script[message] ?? [{ areas: [] }];
58
+ const { response = 'Scripted.', ...data } = replies[Math.min(turn, replies.length - 1)] ?? {};
59
+ const content = JSON.stringify({ response, data: { title: 'Scripted', ...data } });
60
+ const base: StepResult = { content, toolCalls: [], usage: SPENT, finishReason: 'stop', raw: null };
61
+ if (request.output === undefined) return base;
62
+ const routed = routeResponse({ content, toolCalls: [], declared: new Set(), accept: request.output.accept, responseStrategies: [] });
63
+ return { ...base, outcome: routed.outcome, wire: routed.wire };
64
+ };
65
+ const chat: SignalClient = {
66
+ step: async (request) => scripted(request),
67
+ stepStream: (request) => {
68
+ const result = scripted(request);
69
+ // In pieces, as a provider streams it, so the reply is read while it is written.
70
+ return (async function* () {
71
+ for (let at = 0; at < result.content.length; at += 24) {
72
+ yield { type: 'text' as const, text: result.content.slice(at, at + 24) };
73
+ await new Promise((done) => setTimeout(done, 1));
74
+ }
75
+ yield { type: 'done' as const, result };
76
+ })();
77
+ },
78
+ count: async () => 1,
79
+ describe: () => ({ provider: 'scripted', model: 'chat', kind: 'chat', modelKnown: false, capabilities: { nativeTools: true, nativeJsonSchema: false, nativeJsonMode: true, toolsWithStructuredOutput: false, validatesToolArgs: true, manglesNestedToolArgs: false, multimodal: false, supportsEmbedding: false } }),
80
+ };
81
+
82
+ const models: Models = options.keyless === true ? { missing: ['GROQ_API_KEY'] } : { jev: { provider: 'scripted', model: 'jev', decide }, chat: { provider: 'scripted', model: 'chat', llm: chat, timeoutMs: 5000 }, missing: [] };
83
+ return { models, prompts, asked, likely: (ids) => void (likely = ids), unreachable: (is) => void (unreachable = is) };
84
+ };
85
+
86
+ const ShownSchema = z.looseObject({
87
+ question: z.string().optional(),
88
+ response: z.string().optional(),
89
+ label: z.string().optional(),
90
+ screen: z.string().optional(),
91
+ arrangement: z.string().optional(),
92
+ position: z.number().optional(),
93
+ total: z.number().optional(),
94
+ stack: z.array(z.looseObject({ position: z.number(), label: z.string() })).optional(),
95
+ });
96
+
97
+ type Session = Awaited<ReturnType<NonNullable<MossServer['shells']>['session']>>;
98
+ type Canvas = { action: string; id: string; data: Record<string, unknown> };
99
+
100
+ export type App = {
101
+ server: MossServer;
102
+ session: Session;
103
+ runs: RunRecord[];
104
+ on: (canvas: string) => Canvas;
105
+ current: () => z.infer<typeof ShownSchema>;
106
+ draw: () => void;
107
+ answered: () => number;
108
+ streamed: () => number;
109
+ areas: () => string;
110
+ ids: () => string;
111
+ without: (area: string, of: string) => string;
112
+ rows: (canvas: string, key: string) => unknown[];
113
+ total: () => number;
114
+ said: () => string;
115
+ drawn: () => string;
116
+ grid: () => string;
117
+ marked: () => string;
118
+ ask: (text: string) => Promise<number | undefined>;
119
+ openScreen: (id: string) => Promise<void>;
120
+ };
121
+
122
+ // The app booted with the models given, driven as a terminal drives it: what the dock is typed, pressed and sent.
123
+ export const startApp = async (models: Models, answerWithinMs = 5000): Promise<App> => {
124
+ const runs: RunRecord[] = [];
125
+ const { server } = await boot({ models, runs: (run) => runs.push(run) });
126
+ const shells = server.shells;
127
+ if (shells === undefined) throw new Error('the manifest has no shell');
128
+ const session = await shells.session(null, null);
129
+ const shell = session.shell;
130
+
131
+ let answered = 0;
132
+ let moves = 0;
133
+ let movesWhenAnswered = 0;
134
+ shell.onEndpoint((event) => {
135
+ if (event.canvasId !== 'dock') return;
136
+ if (event.name === 'current') moves += 1;
137
+ if (event.name === 'ask') {
138
+ answered += 1;
139
+ movesWhenAnswered = moves;
140
+ }
141
+ });
142
+
143
+ const on = (canvas: string): Canvas => {
144
+ const active = shell.getState().canvases[canvas]?.active;
145
+ return { action: active?.definitionId ?? '', id: active?.id ?? '', data: active === undefined ? {} : (shell.getRuntime(active.id)?.getData() ?? {}) };
146
+ };
147
+ const nodesOf = (value: unknown): Record<string, unknown>[] => (Array.isArray(value) ? value.map(recordOf) : []);
148
+ const named = (name: string, nodes: unknown): Record<string, unknown>[] => nodesOf(nodes).flatMap((node) => (node['name'] === name ? [node] : named(name, node['children'])));
149
+ const current = (): z.infer<typeof ShownSchema> => ShownSchema.safeParse(on('dock').data['current']).data ?? {};
150
+ // An input takes what is typed into it once it has been drawn.
151
+ const draw = (): void => void shell.flattenRenderTree(shell.getShellRenderTree());
152
+ let streamed = 0;
153
+
154
+ return {
155
+ server,
156
+ session,
157
+ runs,
158
+ on,
159
+ current,
160
+ draw,
161
+ answered: () => answered,
162
+ streamed: () => streamed,
163
+ areas: () => AREAS.map((area) => on(area).action).filter((action) => action !== '').join(' '),
164
+ ids: () => AREAS.map((area) => `${area}:${on(area).id}`).join(' '),
165
+ without: (area, of) => of.replace(new RegExp(`${area}:\\S*`), ''),
166
+ rows: (canvas, key) => {
167
+ const value = on(canvas).data[key];
168
+ return Array.isArray(value) ? value : [];
169
+ },
170
+ total: () => Number(current().total),
171
+ said: () => String(on('dock').data['error'] ?? ''),
172
+ drawn: () => JSON.stringify(shell.flattenRenderTree(shell.getShellRenderTree())),
173
+ // The frame's `answers` region as the shell draws it: its columns, and each area's name and span.
174
+ grid: () => {
175
+ const answers = named('Grid', shell.getShellRenderTree())[0] ?? {};
176
+ const held = nodesOf(answers['children']).map((area) => {
177
+ const own = recordOf(area['props']);
178
+ return `${String(own['name'])}${Number(own['span'] ?? 1) > 1 ? `×${String(own['span'])}` : ''}`;
179
+ });
180
+ return `${String(recordOf(answers['props'])['columns'])}: ${held.join(' ')}`;
181
+ },
182
+ marked: () =>
183
+ named('Area', shell.getShellRenderTree())
184
+ .map((area) => recordOf(area['props']))
185
+ .filter((props) => props['changed'] === true)
186
+ .map((props) => String(props['name']))
187
+ .join(' '),
188
+ // A message is answered when the line's `ask` call ends, whatever it leaves on screen: how long that took, if it did.
189
+ ask: async (text) => {
190
+ draw();
191
+ const seen = answered;
192
+ const movesBefore = moves;
193
+ const started = performance.now();
194
+ session.dispatch('dock', { type: 'ui:model', ref: 'text', payload: text });
195
+ session.dispatch('dock', { type: 'ui:key', ref: 'text', key: 'Enter' });
196
+ const done = await until(() => answered > seen, answerWithinMs);
197
+ const took = performance.now() - started;
198
+ streamed = movesWhenAnswered - movesBefore;
199
+ await settle();
200
+ return done ? took : undefined;
201
+ },
202
+ openScreen: async (id) => {
203
+ session.dispatch('dock', { type: 'ui:click', ref: 'screen', payload: id });
204
+ await until(() => current().screen === id);
205
+ await settle();
206
+ },
207
+ };
208
+ };
@@ -4,6 +4,8 @@ import { evaluate } from '@niscorp/prism';
4
4
  import { PRISM_SCHEMAS, PRISM_SEQUENCE } from '@niscorp/prism/migrations';
5
5
  import { runSourceUpgrade } from '@niscorp/strata/node';
6
6
  import { actions } from '../app/action-catalog';
7
+ import { ARRANGEMENTS } from '../app/arrangements';
8
+ import { frameLayout } from '../app/shell/frame.layout';
7
9
 
8
10
  const root = fileURLToPath(new URL('../..', import.meta.url));
9
11
 
@@ -14,7 +16,11 @@ process.exit(
14
16
  grammars: [NOVA_SEQUENCE, PRISM_SEQUENCE],
15
17
  transform: evaluate,
16
18
  schemas: { ...NOVA_SCHEMAS, ...PRISM_SCHEMAS },
17
- documents: async () => Object.values(actions).map((document) => ({ kind: 'nisc.nova/action', id: document.id, document })),
19
+ documents: async () => [
20
+ ...Object.values(actions).map((document) => ({ kind: 'nisc.nova/action', id: document.id, document })),
21
+ { kind: 'nisc.nova/layout', id: 'shell.frame', document: frameLayout },
22
+ ...ARRANGEMENTS.map((arrangement) => ({ kind: 'nisc.nova/layout', id: `arrangement.${arrangement.id}`, document: arrangement.layout })),
23
+ ],
18
24
  },
19
25
  process.argv.slice(2),
20
26
  ),
@@ -0,0 +1,24 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { createServer } from '@niscorp/moss';
3
+ import type { MossServer, RunSink } from '@niscorp/moss';
4
+ import { buildApp } from '../app/app';
5
+ import { APP_SEQUENCE } from '../db/schema';
6
+ import { composer } from './compose';
7
+ import type { Models } from './compose';
8
+ import { modelsFromEnv } from './models';
9
+ import { logRun } from './runs';
10
+ import { runtime } from './runtime';
11
+
12
+ const fromEnvFile = (): Models => {
13
+ if (existsSync('.env')) process.loadEnvFile('.env');
14
+ const models = modelsFromEnv(process.env);
15
+ console.log(`[app] ${models.summary}`);
16
+ if (models.missing.length > 0) console.log(`[app] ${models.missing.join(', ')} is empty in .env: until it is set, a message is answered with a notice saying so.`);
17
+ return models;
18
+ };
19
+
20
+ export type BootConfig = { models?: Models; runs?: RunSink };
21
+
22
+ export const boot = async (config: BootConfig = {}): Promise<{ server: MossServer }> => ({
23
+ server: await createServer(buildApp({ functions: composer(config.models ?? fromEnvFile()), runs: config.runs ?? logRun }), { ...(await runtime()), tables: [APP_SEQUENCE] }),
24
+ });