create-nisc 0.2.0
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.
- package/LICENSE +202 -0
- package/README.md +72 -0
- package/bin/create-nisc.js +5 -0
- package/dist/chunk-A4727PE2.js +174 -0
- package/dist/chunk-A4727PE2.js.map +1 -0
- package/dist/chunk-TEYNNEJA.js +173 -0
- package/dist/chunk-TEYNNEJA.js.map +1 -0
- package/dist/cli.js +113 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
- package/templates/moss-dom/.turbo/turbo-build.log +32 -0
- package/templates/moss-dom/.turbo/turbo-test.log +15 -0
- package/templates/moss-dom/.turbo/turbo-typecheck.log +4 -0
- package/templates/moss-dom/README.md +15 -0
- package/templates/moss-dom/index.html +12 -0
- package/templates/moss-dom/nisc.config.ts +19 -0
- package/templates/moss-dom/package.json +39 -0
- package/templates/moss-dom/src/app/action-catalog.ts +8 -0
- package/templates/moss-dom/src/app/actions/surfaces/welcome.action.ts +13 -0
- package/templates/moss-dom/src/app/actions/surfaces/welcome.layout.ts +27 -0
- package/templates/moss-dom/src/app/app.ts +10 -0
- package/templates/moss-dom/src/app/charter/assignments.ts +3 -0
- package/templates/moss-dom/src/app/charter/charter.ts +8 -0
- package/templates/moss-dom/src/app/shell/frame.layout.ts +5 -0
- package/templates/moss-dom/src/app/shell/shell.ts +10 -0
- package/templates/moss-dom/src/dev/all-checks.ts +20 -0
- package/templates/moss-dom/src/dev/artifacts-check.ts +56 -0
- package/templates/moss-dom/src/dev/strata.ts +28 -0
- package/templates/moss-dom/src/dev/welcome-check.ts +43 -0
- package/templates/moss-dom/src/main.ts +22 -0
- package/templates/moss-dom/src/server/boot.ts +9 -0
- package/templates/moss-dom/src/server/document.ts +15 -0
- package/templates/moss-dom/src/server/runtime.ts +21 -0
- package/templates/moss-dom/src/ui/kit.css +42 -0
- package/templates/moss-dom/src/ui/kit.ts +41 -0
- package/templates/moss-dom/src/ui/registry.ts +16 -0
- package/templates/moss-dom/strata.lock.json +6 -0
- package/templates/moss-dom/tsconfig.json +27 -0
- package/templates/moss-dom/vite.config.ts +8 -0
- package/templates/moss-react/.turbo/turbo-build.log +32 -0
- package/templates/moss-react/.turbo/turbo-test.log +15 -0
- package/templates/moss-react/.turbo/turbo-typecheck.log +4 -0
- package/templates/moss-react/README.md +15 -0
- package/templates/moss-react/index.html +12 -0
- package/templates/moss-react/nisc.config.ts +19 -0
- package/templates/moss-react/package.json +42 -0
- package/templates/moss-react/src/app/action-catalog.ts +8 -0
- package/templates/moss-react/src/app/actions/surfaces/welcome.action.ts +13 -0
- package/templates/moss-react/src/app/actions/surfaces/welcome.layout.ts +27 -0
- package/templates/moss-react/src/app/app.ts +10 -0
- package/templates/moss-react/src/app/charter/assignments.ts +3 -0
- package/templates/moss-react/src/app/charter/charter.ts +8 -0
- package/templates/moss-react/src/app/shell/frame.layout.ts +5 -0
- package/templates/moss-react/src/app/shell/shell.ts +10 -0
- package/templates/moss-react/src/dev/all-checks.ts +20 -0
- package/templates/moss-react/src/dev/artifacts-check.ts +56 -0
- package/templates/moss-react/src/dev/strata.ts +28 -0
- package/templates/moss-react/src/dev/welcome-check.ts +43 -0
- package/templates/moss-react/src/main.tsx +20 -0
- package/templates/moss-react/src/server/boot.ts +9 -0
- package/templates/moss-react/src/server/document.ts +12 -0
- package/templates/moss-react/src/server/runtime.ts +21 -0
- package/templates/moss-react/src/ui/kit.css +42 -0
- package/templates/moss-react/src/ui/kit.tsx +49 -0
- package/templates/moss-react/src/ui/registry.ts +14 -0
- package/templates/moss-react/strata.lock.json +6 -0
- package/templates/moss-react/tsconfig.json +17 -0
- package/templates/moss-react/vite.config.ts +11 -0
- package/templates/shell-dom/.turbo/turbo-build.log +31 -0
- package/templates/shell-dom/.turbo/turbo-test.log +12 -0
- package/templates/shell-dom/.turbo/turbo-typecheck.log +4 -0
- package/templates/shell-dom/README.md +16 -0
- package/templates/shell-dom/index.html +12 -0
- package/templates/shell-dom/nisc.config.ts +19 -0
- package/templates/shell-dom/package.json +35 -0
- package/templates/shell-dom/src/app/action-catalog.ts +8 -0
- package/templates/shell-dom/src/app/actions/surfaces/welcome.action.ts +12 -0
- package/templates/shell-dom/src/app/actions/surfaces/welcome.layout.ts +27 -0
- package/templates/shell-dom/src/app/shell/frame.layout.ts +5 -0
- package/templates/shell-dom/src/app/shell/shell.ts +10 -0
- package/templates/shell-dom/src/boot.ts +18 -0
- package/templates/shell-dom/src/dev/all-checks.ts +20 -0
- package/templates/shell-dom/src/dev/artifacts-check.ts +52 -0
- package/templates/shell-dom/src/dev/strata.ts +28 -0
- package/templates/shell-dom/src/dev/welcome-check.ts +26 -0
- package/templates/shell-dom/src/main.ts +14 -0
- package/templates/shell-dom/src/ui/kit.css +42 -0
- package/templates/shell-dom/src/ui/kit.ts +41 -0
- package/templates/shell-dom/src/ui/registry.ts +16 -0
- package/templates/shell-dom/src/ui/screen.ts +16 -0
- package/templates/shell-dom/strata.lock.json +6 -0
- package/templates/shell-dom/tsconfig.json +27 -0
- package/templates/shell-dom/vite.config.ts +6 -0
- package/templates/shell-react/.turbo/turbo-build.log +31 -0
- package/templates/shell-react/.turbo/turbo-test.log +12 -0
- package/templates/shell-react/.turbo/turbo-typecheck.log +4 -0
- package/templates/shell-react/README.md +16 -0
- package/templates/shell-react/index.html +12 -0
- package/templates/shell-react/nisc.config.ts +19 -0
- package/templates/shell-react/package.json +40 -0
- package/templates/shell-react/src/app/action-catalog.ts +8 -0
- package/templates/shell-react/src/app/actions/surfaces/welcome.action.ts +12 -0
- package/templates/shell-react/src/app/actions/surfaces/welcome.layout.ts +27 -0
- package/templates/shell-react/src/app/shell/frame.layout.ts +5 -0
- package/templates/shell-react/src/app/shell/shell.ts +10 -0
- package/templates/shell-react/src/boot.ts +18 -0
- package/templates/shell-react/src/dev/all-checks.ts +20 -0
- package/templates/shell-react/src/dev/artifacts-check.ts +52 -0
- package/templates/shell-react/src/dev/strata.ts +28 -0
- package/templates/shell-react/src/dev/welcome-check.ts +26 -0
- package/templates/shell-react/src/main.tsx +25 -0
- package/templates/shell-react/src/ui/kit.css +42 -0
- package/templates/shell-react/src/ui/kit.tsx +49 -0
- package/templates/shell-react/src/ui/registry.ts +14 -0
- package/templates/shell-react/src/ui/screen.tsx +15 -0
- package/templates/shell-react/strata.lock.json +6 -0
- package/templates/shell-react/tsconfig.json +28 -0
- package/templates/shell-react/vite.config.ts +9 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LayoutNode } from '@niscorp/nova';
|
|
2
|
+
|
|
3
|
+
// JSON, bound to the action's data. Every component name is one the kit in
|
|
4
|
+
// src/ui registers; `ref` is what the action's trigger catches.
|
|
5
|
+
export const welcomeLayout: LayoutNode = {
|
|
6
|
+
component: 'Page',
|
|
7
|
+
children: [
|
|
8
|
+
{ component: 'Heading', children: '{{$.name}}' },
|
|
9
|
+
{
|
|
10
|
+
component: 'Text',
|
|
11
|
+
props: { tone: 'muted' },
|
|
12
|
+
children: 'A nisc app behind moss. This screen is an action on a canvas, served from a shell on the server; the page arrived drawn, and the browser picked it up. Nobody is signed in, so this shell lasts as long as your connection — reload, and the count starts again.',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
component: 'Row',
|
|
16
|
+
children: [
|
|
17
|
+
{ component: 'Button', ref: 'press', props: { label: 'Press' } },
|
|
18
|
+
{ component: 'Text', children: 'Presses: {{$.presses}}' },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
component: 'Text',
|
|
23
|
+
props: { tone: 'muted' },
|
|
24
|
+
children: 'Start in PLAN.md. The rules this app is built by are in AGENTS.md.',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineApp } from '@niscorp/moss';
|
|
2
|
+
import { actions } from './action-catalog';
|
|
3
|
+
import { assignments } from './charter/assignments';
|
|
4
|
+
import { charter } from './charter/charter';
|
|
5
|
+
import { shell } from './shell/shell';
|
|
6
|
+
|
|
7
|
+
// The manifest moss serves. One import per field; every field is data
|
|
8
|
+
// (AGENTS.md, "Layout of an app"). What it grows next — entries for the data
|
|
9
|
+
// layer, behaviors, pages — is in PLAN.md.
|
|
10
|
+
export const app = defineApp({ charter, assignments, actions, shell });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Charter } from '@niscorp/charter';
|
|
2
|
+
|
|
3
|
+
// The policy document: role names → the action ids that exist for them (and,
|
|
4
|
+
// once there is data, `data: ['table.verb', …]`). `public` is whoever has not
|
|
5
|
+
// signed in — today, everybody.
|
|
6
|
+
export const charter: Charter = {
|
|
7
|
+
public: ['welcome'],
|
|
8
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LayoutNode } from '@niscorp/nova';
|
|
2
|
+
|
|
3
|
+
// The frame around the canvases — chrome lives here, as layout, never as a
|
|
4
|
+
// wrapper component. One canvas for now: `main`, drawn where its slot is.
|
|
5
|
+
export const frameLayout: LayoutNode = { component: 'CanvasSlot', props: { canvasId: 'main' } };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ShellManifest } from '@niscorp/moss';
|
|
2
|
+
import { frameLayout } from './frame.layout';
|
|
3
|
+
|
|
4
|
+
// The shell: one canvas, the action it opens with, and the frame around it.
|
|
5
|
+
// Shells host canvases, canvases host action instances, actions render JSON
|
|
6
|
+
// layouts.
|
|
7
|
+
export const shell: ShellManifest = {
|
|
8
|
+
canvases: [{ id: 'main', initial: 'welcome' }],
|
|
9
|
+
layout: frameLayout,
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
// Every check, each in its own process over its own fresh database: a check ships the app a
|
|
4
|
+
// history, and a shared one would make the order of the suite part of its
|
|
5
|
+
// meaning. `nisc check` runs this. A new feature adds its check here.
|
|
6
|
+
const CHECKS: readonly (readonly [name: string, what: string, args?: readonly string[]])[] = [
|
|
7
|
+
['artifacts-check', 'src/app is data: pure JSON, and every artifact parses its schema'],
|
|
8
|
+
['strata', 'the source is written at the installed grammars (strata.lock.json)', ['status', '--check']],
|
|
9
|
+
['welcome-check', 'the welcome screen: served, drawn, and pressed'],
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
let failed = 0;
|
|
13
|
+
for (const [name, what, args = []] of CHECKS) {
|
|
14
|
+
console.log(`\n── ${name} — ${what}`);
|
|
15
|
+
const run = spawnSync(process.execPath, ['--import', 'tsx', `src/dev/${name}.ts`, ...args], { stdio: 'inherit' });
|
|
16
|
+
if (run.status !== 0) failed += 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log(failed === 0 ? `\nAll ${CHECKS.length} checks pass.` : `\n${failed} of ${CHECKS.length} checks failed.`);
|
|
20
|
+
process.exit(failed === 0 ? 0 : 1);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The artifacts check — what makes `src/app/` a tree of DATA: everything in it
|
|
2
|
+
// is pure JSON (no function, no Date, no undefined, no class instance) and
|
|
3
|
+
// parses through its own schema, so a code file cannot pass for an artifact
|
|
4
|
+
// (AGENTS.md, review item 6a). It also holds rule 14: an action's `input`
|
|
5
|
+
// declares only keys its `data` has.
|
|
6
|
+
import { ActionDefinitionSchema, LayoutNodeSchema } from '@niscorp/nova';
|
|
7
|
+
import { actions } from '../app/action-catalog';
|
|
8
|
+
import { assignments } from '../app/charter/assignments';
|
|
9
|
+
import { charter } from '../app/charter/charter';
|
|
10
|
+
import { shell } from '../app/shell/shell';
|
|
11
|
+
|
|
12
|
+
let failures = 0;
|
|
13
|
+
const check = (name: string, passed: boolean, detail = ''): void => {
|
|
14
|
+
console.log(`${passed ? '[pass]' : '[fail]'} ${name}${!passed && detail !== '' ? ` — ${detail}` : ''}`);
|
|
15
|
+
if (!passed) failures += 1;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// The first thing in a value that is not JSON, as a path — or '' when all of it is.
|
|
19
|
+
const impurity = (value: unknown, path: string): string => {
|
|
20
|
+
if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return '';
|
|
21
|
+
if (Array.isArray(value)) return value.map((item, at) => impurity(item, `${path}[${at}]`)).find((found) => found !== '') ?? '';
|
|
22
|
+
if (typeof value !== 'object') return `${path} is a ${typeof value}`;
|
|
23
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) return `${path} is not a plain object`;
|
|
24
|
+
return Object.entries(value).map(([key, inner]) => impurity(inner, path === '' ? key : `${path}.${key}`)).find((found) => found !== '') ?? '';
|
|
25
|
+
};
|
|
26
|
+
const pure = (name: string, value: unknown): void => {
|
|
27
|
+
const found = impurity(value, '');
|
|
28
|
+
check(`${name} is pure JSON`, found === '', found);
|
|
29
|
+
};
|
|
30
|
+
const parses = (name: string, parse: () => unknown): void => {
|
|
31
|
+
try {
|
|
32
|
+
parse();
|
|
33
|
+
check(`${name} parses its schema`, true);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
check(`${name} parses its schema`, false, error instanceof Error ? error.message.slice(0, 300) : String(error));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
39
|
+
|
|
40
|
+
pure('the action catalog', actions);
|
|
41
|
+
pure('the charter', charter);
|
|
42
|
+
pure('the assignments', assignments);
|
|
43
|
+
pure('the shell', shell);
|
|
44
|
+
if (shell.layout !== undefined) parses('the shell’s frame', () => LayoutNodeSchema.parse(shell.layout));
|
|
45
|
+
|
|
46
|
+
for (const [id, definition] of Object.entries(actions)) {
|
|
47
|
+
check(`action "${id}" is catalogued under its own id`, definition.id === id, `its id is "${definition.id}"`);
|
|
48
|
+
parses(`action "${id}"`, () => ActionDefinitionSchema.parse(definition));
|
|
49
|
+
// rule 14: what an opener may seed is a subset of the action's data
|
|
50
|
+
const properties = isRecord(definition.input) && isRecord(definition.input['properties']) ? Object.keys(definition.input['properties']) : [];
|
|
51
|
+
const unknown = properties.filter((key) => !(key in (definition.data ?? {})));
|
|
52
|
+
check(`action "${id}" declares only inputs its data has`, unknown.length === 0, unknown.join(', '));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log(failures === 0 ? '[pass] artifacts: all checks passed' : `[fail] artifacts: ${failures} check(s) failed`);
|
|
56
|
+
process.exit(failures === 0 ? 0 : 1);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// strata for this app's SOURCE artifacts — which version of each grammar
|
|
2
|
+
// (nova's, Prism's) the actions in src/app are written in, recorded in
|
|
3
|
+
// strata.lock.json, and how they are brought forward when a grammar moves
|
|
4
|
+
// (AGENTS.md rule 20).
|
|
5
|
+
//
|
|
6
|
+
// npm run strata status where the source stands (`-- --check` to fail when behind)
|
|
7
|
+
// npm run strata upgrade the exact expected JSON + a report of what to edit
|
|
8
|
+
// npm run strata verify holds the edit to that JSON, then moves the lock
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { NOVA_SCHEMAS, NOVA_SEQUENCE } from '@niscorp/nova/migrations';
|
|
11
|
+
import { PRISM_SCHEMAS, PRISM_SEQUENCE, prismTransform } from '@niscorp/prism/migrations';
|
|
12
|
+
import { runSourceUpgrade } from '@niscorp/strata/node';
|
|
13
|
+
import { actions } from '../app/action-catalog';
|
|
14
|
+
|
|
15
|
+
const root = fileURLToPath(new URL('../..', import.meta.url));
|
|
16
|
+
|
|
17
|
+
process.exit(
|
|
18
|
+
await runSourceUpgrade(
|
|
19
|
+
{
|
|
20
|
+
root,
|
|
21
|
+
grammars: [NOVA_SEQUENCE, PRISM_SEQUENCE],
|
|
22
|
+
transform: prismTransform,
|
|
23
|
+
schemas: { ...NOVA_SCHEMAS, ...PRISM_SCHEMAS },
|
|
24
|
+
documents: async () => Object.values(actions).map((document) => ({ kind: 'nisc.nova/action', id: document.id, document })),
|
|
25
|
+
},
|
|
26
|
+
process.argv.slice(2),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { renderDocument } from '@niscorp/moss';
|
|
2
|
+
import { boot } from '../server/boot';
|
|
3
|
+
import { drawing } from '../server/document';
|
|
4
|
+
|
|
5
|
+
// The welcome screen, end to end with no browser: the real server boots, the
|
|
6
|
+
// screen is served to nobody in particular, the page is drawn on the server,
|
|
7
|
+
// and a press reaches the shell. One `[pass]`/`[fail]` line per assertion; any
|
|
8
|
+
// failure exits non-zero (AGENTS.md, "Verification").
|
|
9
|
+
|
|
10
|
+
let failures = 0;
|
|
11
|
+
const check = (name: string, passed: boolean, detail = ''): void => {
|
|
12
|
+
console.log(`${passed ? '[pass]' : '[fail]'} ${name}${!passed && detail !== '' ? ` — ${detail}` : ''}`);
|
|
13
|
+
if (!passed) failures += 1;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const tick = (ms = 20): Promise<void> => new Promise((done) => setTimeout(done, ms));
|
|
17
|
+
|
|
18
|
+
const { server } = await boot();
|
|
19
|
+
try {
|
|
20
|
+
const shells = server.shells;
|
|
21
|
+
if (shells === undefined) throw new Error('the manifest has no shell');
|
|
22
|
+
const snapshot = await shells.snapshot(null, null);
|
|
23
|
+
const main = JSON.stringify(snapshot.trees['main'] ?? []);
|
|
24
|
+
check('the anonymous principal is served the welcome action', main.includes('"definitionId":"welcome"'), main.slice(0, 200));
|
|
25
|
+
check('its screen has a button to press', main.includes('"ref":"press"'));
|
|
26
|
+
|
|
27
|
+
const template = '<!doctype html><html><head></head><body><div id="root"></div></body></html>';
|
|
28
|
+
const page = await renderDocument({ ...drawing, server, template, request: { path: '/', cookie: null } });
|
|
29
|
+
check('the page arrives drawn', page.drawn && page.html.includes('k-heading'), page.html.slice(0, 200));
|
|
30
|
+
check('a page drawn for nobody may be kept by a cache', page.headers['cache-control'] === 'no-cache');
|
|
31
|
+
|
|
32
|
+
const session = await shells.session(null, null);
|
|
33
|
+
session.dispatch('main', { type: 'ui:click', ref: 'press' });
|
|
34
|
+
await tick();
|
|
35
|
+
const active = session.shell.getState().canvases['main']?.active?.id ?? '';
|
|
36
|
+
const presses = session.shell.getRuntime(active)?.getData()['presses'];
|
|
37
|
+
check('a press reaches the shell on the server', presses === 1, `presses is ${String(presses)}`);
|
|
38
|
+
} finally {
|
|
39
|
+
server.close();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(failures === 0 ? '[pass] welcome: all checks passed' : `[fail] welcome: ${failures} check(s) failed`);
|
|
43
|
+
process.exit(failures === 0 ? 0 : 1);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { browserEnv, createWire, readDocumentSnapshot } from '@niscorp/moss/client';
|
|
2
|
+
import { createTerminal } from '@niscorp/moss/terminal';
|
|
3
|
+
import { reactTarget } from '@niscorp/moss/terminal/react';
|
|
4
|
+
import { buildRegistry } from './ui/registry';
|
|
5
|
+
import './ui/kit.css';
|
|
6
|
+
|
|
7
|
+
// The browser: the kit, handed to moss's terminal. It knows nothing about the
|
|
8
|
+
// app — it draws the trees the socket sends and sends back what was pressed.
|
|
9
|
+
//
|
|
10
|
+
// The page arrives with the first screen already in it (src/server/document.ts)
|
|
11
|
+
// and the snapshot it was drawn from beside it; the wire starts from that
|
|
12
|
+
// snapshot, so the first render adopts the elements already there. `cookie`
|
|
13
|
+
// keeps a copy of the session token where a page request can carry it, which
|
|
14
|
+
// is how the server will know whose screen to draw once people can sign in.
|
|
15
|
+
const root = document.getElementById('root');
|
|
16
|
+
if (root === null) throw new Error('index.html has no #root');
|
|
17
|
+
|
|
18
|
+
const drawn = readDocumentSnapshot();
|
|
19
|
+
const wire = createWire({ env: browserEnv({ cookie: true }), ...(drawn !== undefined ? { initial: drawn } : {}) });
|
|
20
|
+
createTerminal({ target: reactTarget({ root, registry: buildRegistry() }), wire });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createServer } from '@niscorp/moss';
|
|
2
|
+
import type { MossServer } from '@niscorp/moss';
|
|
3
|
+
import { app } from '../app/app';
|
|
4
|
+
import { runtime } from './runtime';
|
|
5
|
+
|
|
6
|
+
// The one composition: the app's artifacts plus an environment → the server.
|
|
7
|
+
// The dev server, `nisc build`, `nisc start` and every check boot through here.
|
|
8
|
+
// moss refuses to boot an incoherent charter — a refusal is a finding.
|
|
9
|
+
export const boot = async (): Promise<{ server: MossServer }> => ({ server: await createServer(app, await runtime()) });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ShellSnapshot } from '@niscorp/moss';
|
|
2
|
+
import { renderSnapshot } from '@niscorp/moss/terminal/react/server';
|
|
3
|
+
import { buildRegistry } from '../ui/registry';
|
|
4
|
+
|
|
5
|
+
// HOW A SCREEN IS DRAWN on the server: the kit the browser draws with, handed
|
|
6
|
+
// to moss. A page request is answered with the screen the socket would have
|
|
7
|
+
// streamed a moment later, and the browser's terminal adopts it (src/main.tsx).
|
|
8
|
+
const registry = buildRegistry();
|
|
9
|
+
|
|
10
|
+
export const drawing = {
|
|
11
|
+
draw: (snapshot: ShellSnapshot): string => renderSnapshot({ snapshot, registry }),
|
|
12
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
2
|
+
import { createPostgresCache } from '@niscorp/vex';
|
|
3
|
+
import { createPglitePool, RAW_DATE_PARSERS } from '@niscorp/vex/pglite';
|
|
4
|
+
import type { NiscRuntime } from '@niscorp/moss';
|
|
5
|
+
|
|
6
|
+
// The environment (D2): what the app is handed to run on. An in-memory Postgres
|
|
7
|
+
// (PGlite) — every boot starts empty, which is what development and the checks
|
|
8
|
+
// want. A deployment hands moss a real Postgres pool here instead; nothing else
|
|
9
|
+
// in the app changes (see PLAN.md).
|
|
10
|
+
//
|
|
11
|
+
// `sessions`: moss verifies session tokens against its own table. Nobody can
|
|
12
|
+
// sign in yet — signing in is an application of its own, the anonymous
|
|
13
|
+
// principal's (AGENTS.md rule 12) — so every request is `public` for now.
|
|
14
|
+
export const runtime = async (): Promise<NiscRuntime> => {
|
|
15
|
+
const db = new PGlite();
|
|
16
|
+
// App queries get raw date strings (Prism formats them); the cache keeps
|
|
17
|
+
// Dates. One database, two pools.
|
|
18
|
+
const cache = createPostgresCache({ pool: createPglitePool(db) });
|
|
19
|
+
await cache.init();
|
|
20
|
+
return { db, pool: createPglitePool(db, RAW_DATE_PARSERS), cache, session: 'sessions' };
|
|
21
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* The look — the only place it lives. A different look is a different
|
|
2
|
+
stylesheet over the same layouts. */
|
|
3
|
+
|
|
4
|
+
:root {
|
|
5
|
+
--k-bg: #f6f4ef;
|
|
6
|
+
--k-ink: #1d1d1f;
|
|
7
|
+
--k-muted: #6b6a66;
|
|
8
|
+
--k-accent: #2f5bea;
|
|
9
|
+
--k-accent-ink: #ffffff;
|
|
10
|
+
--k-radius: 10px;
|
|
11
|
+
font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
|
|
12
|
+
color: var(--k-ink);
|
|
13
|
+
background: var(--k-bg);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
html, body, #root { margin: 0; min-height: 100%; }
|
|
17
|
+
|
|
18
|
+
.k-page {
|
|
19
|
+
max-width: 640px;
|
|
20
|
+
margin: 0 auto;
|
|
21
|
+
padding: 64px 24px;
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
gap: 16px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.k-row { display: flex; align-items: center; gap: 16px; }
|
|
28
|
+
.k-heading { margin: 0; font-size: 32px; letter-spacing: -0.01em; }
|
|
29
|
+
.k-text { margin: 0; line-height: 1.55; }
|
|
30
|
+
.k-muted { color: var(--k-muted); }
|
|
31
|
+
|
|
32
|
+
.k-button {
|
|
33
|
+
border: 0;
|
|
34
|
+
border-radius: var(--k-radius);
|
|
35
|
+
padding: 10px 18px;
|
|
36
|
+
font: inherit;
|
|
37
|
+
font-weight: 600;
|
|
38
|
+
background: var(--k-accent);
|
|
39
|
+
color: var(--k-accent-ink);
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
}
|
|
42
|
+
.k-button:active { transform: translateY(1px); }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { useNovaDispatch } from '@niscorp/nova/adapters/react';
|
|
3
|
+
import type { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
4
|
+
|
|
5
|
+
// ═══════════════════════════════════════════════════════════
|
|
6
|
+
// The kit: domain-blind primitives. Props in, events out. Each one is
|
|
7
|
+
// CONFIGURED, never styled — it reads what a thing is (a tone, a level) from a
|
|
8
|
+
// closed set of names, and anything it does not know falls back to the default.
|
|
9
|
+
// The look lives in kit.css alone.
|
|
10
|
+
//
|
|
11
|
+
// Every prop a layout passes is parsed here, at the boundary (rule 13); a
|
|
12
|
+
// layout that names an unknown value gets the default, never a crash.
|
|
13
|
+
// ═══════════════════════════════════════════════════════════
|
|
14
|
+
|
|
15
|
+
const parsed = <T,>(schema: z.ZodType<T>, props: unknown, fallback: T): T => {
|
|
16
|
+
const result = schema.safeParse(props);
|
|
17
|
+
return result.success ? result.data : fallback;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const PageProps = z.object({}).describe('The page: a centred column with the app’s background.');
|
|
21
|
+
export const Page: NovaComponent = ({ children }) => <main className="k-page">{children}</main>;
|
|
22
|
+
Page.meta = { description: 'The page: a centred column.', propsSchema: PageProps };
|
|
23
|
+
|
|
24
|
+
const RowProps = z.object({}).describe('Children side by side, centred.');
|
|
25
|
+
export const Row: NovaComponent = ({ children }) => <div className="k-row">{children}</div>;
|
|
26
|
+
Row.meta = { description: 'Children side by side.', propsSchema: RowProps };
|
|
27
|
+
|
|
28
|
+
const HeadingProps = z.object({}).describe('The page’s title.');
|
|
29
|
+
export const Heading: NovaComponent = ({ children }) => <h1 className="k-heading">{children}</h1>;
|
|
30
|
+
Heading.meta = { description: 'The page’s title.', propsSchema: HeadingProps };
|
|
31
|
+
|
|
32
|
+
const TextProps = z.object({ tone: z.enum(['default', 'muted']).optional().describe('default | muted') });
|
|
33
|
+
export const Text: NovaComponent = ({ children, novaRef: _ref, novaModel: _model, ...props }) => {
|
|
34
|
+
const { tone } = parsed(TextProps, props, {});
|
|
35
|
+
return <p className={tone === 'muted' ? 'k-text k-muted' : 'k-text'}>{children}</p>;
|
|
36
|
+
};
|
|
37
|
+
Text.meta = { description: 'A paragraph.', propsSchema: TextProps };
|
|
38
|
+
|
|
39
|
+
const ButtonProps = z.object({ label: z.string().optional().describe('What the button says; falls back to its children.') });
|
|
40
|
+
export const Button: NovaComponent = ({ children, novaRef, novaModel: _model, ...props }) => {
|
|
41
|
+
const dispatch = useNovaDispatch();
|
|
42
|
+
const { label } = parsed(ButtonProps, props, {});
|
|
43
|
+
return (
|
|
44
|
+
<button type="button" className="k-button" data-ref={novaRef} onClick={() => dispatch({ type: 'ui:click', ...(novaRef !== undefined ? { ref: novaRef } : {}) })}>
|
|
45
|
+
{label ?? children}
|
|
46
|
+
</button>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
Button.meta = { description: 'A button; dispatches ui:click with its ref.', propsSchema: ButtonProps };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createComponentRegistry } from '@niscorp/nova';
|
|
2
|
+
import type { ComponentRegistry } from '@niscorp/nova';
|
|
3
|
+
import { ActionSlot, CanvasSlot } from '@niscorp/nova/adapters/react/components';
|
|
4
|
+
import type { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
5
|
+
import { Button, Heading, Page, Row, Text } from './kit';
|
|
6
|
+
|
|
7
|
+
// The one registry, assembled once (rule 2): nova's two slot markers, then the
|
|
8
|
+
// kit. Every component a layout may name is here, and nothing else is.
|
|
9
|
+
export const buildRegistry = (): ComponentRegistry<NovaComponent> => {
|
|
10
|
+
const registry = createComponentRegistry<NovaComponent>();
|
|
11
|
+
registry.registerAll({ CanvasSlot, ActionSlot });
|
|
12
|
+
registry.registerAll({ Page, Row, Heading, Text, Button });
|
|
13
|
+
return registry;
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"types": ["node", "vite/client"]
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "nisc.config.ts", "vite.config.ts"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A default export, which the style guide otherwise bans: vite reads its config
|
|
2
|
+
// from one, so this file has to match vite's shape (AGENTS.md rule 16, a shim).
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
import react from '@vitejs/plugin-react';
|
|
5
|
+
|
|
6
|
+
// The browser's bundle: React and nothing else. The app server runs inside
|
|
7
|
+
// vite's dev process too, but that is `nisc dev`'s doing (moss's dev plugin,
|
|
8
|
+
// fed from nisc.config.ts) — nothing about it belongs here.
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [react()],
|
|
11
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
> nisc-template-shell-dom@0.0.0 build /Users/max/Development/niscorp/.claude/worktrees/prerender/packages/create-nisc/templates/shell-dom
|
|
3
|
+
> tsc --noEmit && nisc build
|
|
4
|
+
|
|
5
|
+
vite v7.3.2 building client environment for production...
|
|
6
|
+
transforming...
|
|
7
|
+
../../../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/core/regexes.js (74:0): A comment
|
|
8
|
+
|
|
9
|
+
"/** Anchors a pattern source. The interpolation lives here rather than at the call site because
|
|
10
|
+
* esbuild will not drop a `@__PURE__` call whose own argument interpolates a variable, but it
|
|
11
|
+
* will drop `anchor(dateSource)`. Keeping it inline pinned `date` into every bundle. */"
|
|
12
|
+
|
|
13
|
+
in "../../../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/core/regexes.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.
|
|
14
|
+
../../../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/core/util.js (400:0): A comment
|
|
15
|
+
|
|
16
|
+
"// Wrapped in a `@__PURE__` IIFE: esbuild never tree-shakes a top-level initializer that contains a member access on `Number`, so the bare object literal survived into every bundle."
|
|
17
|
+
|
|
18
|
+
in "../../../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/core/util.js" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.
|
|
19
|
+
✓ 141 modules transformed.
|
|
20
|
+
rendering chunks...
|
|
21
|
+
computing gzip size...
|
|
22
|
+
dist/index.html 0.41 kB │ gzip: 0.28 kB
|
|
23
|
+
dist/assets/index-DALMMv7I.css 0.74 kB │ gzip: 0.43 kB
|
|
24
|
+
dist/assets/index-xeXwGVAt.js 228.66 kB │ gzip: 69.82 kB
|
|
25
|
+
✓ built in 5.17s
|
|
26
|
+
|
|
27
|
+
Route First screen
|
|
28
|
+
○ / drawn · whole · same twice · adopted (welcome)
|
|
29
|
+
|
|
30
|
+
○ a file: the first screen, drawn for nobody in particular; the page’s own shell picks it up
|
|
31
|
+
✗ not written: a check did not hold
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
> nisc-template-shell-dom@0.0.0 test /Users/max/Development/niscorp/.claude/worktrees/prerender/packages/create-nisc/templates/shell-dom
|
|
3
|
+
> nisc check
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
── welcome-check — the welcome screen: whole, and pressed
|
|
7
|
+
[pass] the first screen is whole
|
|
8
|
+
[pass] the welcome action opens on the main canvas
|
|
9
|
+
[pass] a press reaches the shell
|
|
10
|
+
[pass] welcome: all checks passed
|
|
11
|
+
|
|
12
|
+
All 1 checks pass.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# nisc-template-shell-dom
|
|
2
|
+
|
|
3
|
+
A [nisc](https://github.com/moccadroid/niscorp) application with its own shell — it runs in the page, with no server.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `npm run dev` | the app, in vite |
|
|
8
|
+
| `npm run build` | typecheck, bundle, draw every path and say how it is served |
|
|
9
|
+
| `npm run export` | write the site as a folder (`out/`) — any static host serves it |
|
|
10
|
+
| `npm start` | serve the built app, each first screen drawn per request |
|
|
11
|
+
| `npm run check` | the checks in `src/dev/` |
|
|
12
|
+
| `npm run strata status` | which grammar versions the source is written at |
|
|
13
|
+
|
|
14
|
+
**Before building anything:** [PLAN.md](PLAN.md) — what was decided when this app
|
|
15
|
+
was made and what is still open — and [AGENTS.md](AGENTS.md), which says where
|
|
16
|
+
the rules are.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>nisc-template-shell-dom</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
import type { NiscShellProject } from '@niscorp/cli';
|
|
3
|
+
import { boot } from './src/boot';
|
|
4
|
+
import { adopt, draw } from './src/ui/screen';
|
|
5
|
+
|
|
6
|
+
// What this app tells the `nisc` command. It has no server: the shell runs in
|
|
7
|
+
// the page. So it hands over its own boot (the one src/main.ts runs) and the
|
|
8
|
+
// two ends of a drawn screen — drawn to markup at build (in a DOM jsdom
|
|
9
|
+
// provides), picked up in the page.
|
|
10
|
+
//
|
|
11
|
+
// npm run dev the app in vite
|
|
12
|
+
// npm run build bundle, draw every path, and check what was drawn
|
|
13
|
+
// npm run export …and write each path as a file: the site as a folder
|
|
14
|
+
// npm run check the checks in src/dev
|
|
15
|
+
export const project: NiscShellProject = {
|
|
16
|
+
shell: async () => ({ shell: boot() }),
|
|
17
|
+
draw: (shell) => draw(shell, new JSDOM('').window),
|
|
18
|
+
adopt,
|
|
19
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nisc-template-shell-dom",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22.12"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "nisc dev",
|
|
11
|
+
"build": "tsc --noEmit && nisc build",
|
|
12
|
+
"export": "nisc export",
|
|
13
|
+
"start": "nisc start",
|
|
14
|
+
"check": "nisc check",
|
|
15
|
+
"test": "nisc check",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"strata": "tsx src/dev/strata.ts"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@niscorp/nova": "workspace:^",
|
|
21
|
+
"@niscorp/prism": "workspace:^",
|
|
22
|
+
"@niscorp/strata": "workspace:^",
|
|
23
|
+
"zod": "^4.6.5"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@niscorp/cli": "workspace:^",
|
|
27
|
+
"@niscorp/nisc": "workspace:^",
|
|
28
|
+
"@types/jsdom": "^30.0.0",
|
|
29
|
+
"@types/node": "^26.6.4",
|
|
30
|
+
"jsdom": "^25.0.1",
|
|
31
|
+
"tsx": "^4.23.1",
|
|
32
|
+
"typescript": "^6.0.2",
|
|
33
|
+
"vite": "^7.1.12"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActionDefinition } from '@niscorp/nova';
|
|
2
|
+
import { welcomeAction } from './actions/surfaces/welcome.action';
|
|
3
|
+
|
|
4
|
+
// Ring 1: every action the app ships, by id. Which of them exist for a given
|
|
5
|
+
// principal is the charter's answer, not this file's.
|
|
6
|
+
export const actions: Record<string, ActionDefinition> = {
|
|
7
|
+
[welcomeAction.id]: welcomeAction,
|
|
8
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ActionDefinition } from '@niscorp/nova';
|
|
2
|
+
import { welcomeLayout } from './welcome.layout';
|
|
3
|
+
|
|
4
|
+
// The first action: data with defaults, a JSON layout, and one trigger. The
|
|
5
|
+
// press is counted in the shell — which lives in this page, with no server.
|
|
6
|
+
export const welcomeAction: ActionDefinition = {
|
|
7
|
+
id: 'welcome',
|
|
8
|
+
title: 'Welcome',
|
|
9
|
+
data: { name: 'nisc-template-shell-dom', presses: 0 },
|
|
10
|
+
layout: welcomeLayout,
|
|
11
|
+
triggers: [{ event: 'ui:click', ref: 'press', do: [{ increment: 'presses' }] }],
|
|
12
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LayoutNode } from '@niscorp/nova';
|
|
2
|
+
|
|
3
|
+
// JSON, bound to the action's data. Every component name is one the kit in
|
|
4
|
+
// src/ui registers; `ref` is what the action's trigger catches.
|
|
5
|
+
export const welcomeLayout: LayoutNode = {
|
|
6
|
+
component: 'Page',
|
|
7
|
+
children: [
|
|
8
|
+
{ component: 'Heading', children: '{{$.name}}' },
|
|
9
|
+
{
|
|
10
|
+
component: 'Text',
|
|
11
|
+
props: { tone: 'muted' },
|
|
12
|
+
children: 'A nisc app with its own shell, drawn with plain DOM — no server. This screen is an action on a canvas; the page arrived drawn (nisc export wrote it), and the shell in this page picked it up.',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
component: 'Row',
|
|
16
|
+
children: [
|
|
17
|
+
{ component: 'Button', ref: 'press', props: { label: 'Press' } },
|
|
18
|
+
{ component: 'Text', children: 'Presses: {{$.presses}}' },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
component: 'Text',
|
|
23
|
+
props: { tone: 'muted' },
|
|
24
|
+
children: 'Start in PLAN.md. The rules this app is built by are in AGENTS.md.',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LayoutNode } from '@niscorp/nova';
|
|
2
|
+
|
|
3
|
+
// The frame around the canvases — chrome lives here, as layout, never as a
|
|
4
|
+
// wrapper component. One canvas for now: `main`, drawn where its slot is.
|
|
5
|
+
export const frameLayout: LayoutNode = { component: 'CanvasSlot', props: { canvasId: 'main' } };
|