@astrale-os/adapter-cloudflare 0.1.9 → 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.
Files changed (81) hide show
  1. package/package.json +1 -1
  2. package/template/.agents/skills/astrale-cli/SKILL.md +1 -1
  3. package/template/.agents/skills/astrale-domain/SKILL.md +5 -5
  4. package/template/.env.example +5 -7
  5. package/template/README.md +2 -2
  6. package/template/client/README.md +81 -62
  7. package/template/client/__tests__/app.test.tsx +143 -98
  8. package/template/client/__tests__/harness.ts +62 -12
  9. package/template/client/__tests__/kernel.test.ts +40 -51
  10. package/template/client/__tests__/seam.test.tsx +115 -0
  11. package/template/client/index.html +1 -1
  12. package/template/client/package.json +1 -0
  13. package/template/client/src/app.tsx +34 -83
  14. package/template/client/src/main.tsx +2 -2
  15. package/template/client/src/shell/client.ts +67 -0
  16. package/template/client/src/shell/index.ts +20 -0
  17. package/template/client/src/shell/invoke.ts +35 -0
  18. package/template/client/src/shell/transformers.ts +72 -0
  19. package/template/client/src/shell/use-async.ts +56 -0
  20. package/template/client/src/shell/use-capability.ts +59 -0
  21. package/template/client/src/shell/use-node.ts +61 -0
  22. package/template/client/src/shell/use-shell.ts +91 -0
  23. package/template/client/src/shell/view-router.tsx +97 -0
  24. package/template/client/src/status/components/StatusCard.tsx +50 -0
  25. package/template/client/src/status/components/index.ts +1 -0
  26. package/template/client/src/status/hooks/index.ts +3 -0
  27. package/template/client/src/status/hooks/useCheck.mutation.ts +16 -0
  28. package/template/client/src/status/hooks/useCheckable.query.ts +64 -0
  29. package/template/client/src/status/index.ts +7 -0
  30. package/template/client/src/status/status.api.ts +12 -0
  31. package/template/client/src/status/status.mappers.ts +19 -0
  32. package/template/client/src/status/status.types.ts +11 -0
  33. package/template/client/src/styles.css +182 -4
  34. package/template/client/src/ui/StatusBadge.tsx +31 -0
  35. package/template/client/src/ui/format.ts +24 -0
  36. package/template/client/src/ui/index.ts +13 -0
  37. package/template/client/src/ui/surface.tsx +56 -0
  38. package/template/client/src/ui/value.tsx +32 -0
  39. package/template/client/src/views/status.tsx +28 -0
  40. package/template/client/tsconfig.json +2 -1
  41. package/template/client/vite.config.ts +11 -13
  42. package/template/client/vitest.config.ts +11 -5
  43. package/template/core/monitor/health.ts +34 -0
  44. package/template/core/monitor/index.ts +9 -0
  45. package/template/core/monitor/keys.ts +41 -0
  46. package/template/core/monitor/node.ts +57 -0
  47. package/template/deps.ts +10 -9
  48. package/template/domain.ts +1 -1
  49. package/template/env.ts +2 -9
  50. package/template/integrations/prober/http.ts +32 -0
  51. package/template/integrations/prober/mock.ts +18 -0
  52. package/template/integrations/prober/port.ts +26 -0
  53. package/template/integrations/prober/registry.ts +65 -0
  54. package/template/package.json +1 -1
  55. package/template/pnpm-lock.yaml +2766 -0
  56. package/template/runtime/index.ts +63 -34
  57. package/template/runtime/monitor/check.ts +29 -0
  58. package/template/runtime/monitor/index.ts +9 -0
  59. package/template/runtime/monitor/seed.ts +95 -0
  60. package/template/runtime/monitor/watch.ts +31 -0
  61. package/template/runtime/shared.ts +21 -0
  62. package/template/runtime/status-page/add.ts +21 -0
  63. package/template/runtime/status-page/check.ts +50 -0
  64. package/template/runtime/status-page/create.ts +24 -0
  65. package/template/runtime/status-page/index.ts +8 -0
  66. package/template/schema/index.ts +11 -4
  67. package/template/schema/monitor.ts +94 -0
  68. package/template/views/index.ts +8 -2
  69. package/template/views/status-page.ts +16 -0
  70. package/template/client/src/lib/kernel.ts +0 -135
  71. package/template/client/src/lib/shell.ts +0 -197
  72. package/template/client/src/lib/use-node.ts +0 -66
  73. package/template/client/src/lib/use-shell.ts +0 -85
  74. package/template/core/keys.ts +0 -28
  75. package/template/core/note.ts +0 -148
  76. package/template/integrations/summary/heuristic.ts +0 -25
  77. package/template/integrations/summary/http.ts +0 -69
  78. package/template/integrations/summary/port.ts +0 -21
  79. package/template/integrations/summary/registry.ts +0 -52
  80. package/template/schema/note.ts +0 -67
  81. package/template/views/note.ts +0 -21
@@ -1,62 +1,91 @@
1
1
  /**
2
2
  * Runtime composition root — the ONLY place request context (kernel/self/params/
3
- * auth) and `deps` meet the per-feature logic. Each `execute` resolves the port
4
- * it needs (`deps.summarizer()`, on-request) and delegates to the transport-
5
- * agnostic functions in `core/`. No business logic lives here.
3
+ * auth) and `deps` meet the per-feature logic. Each `execute` resolves what it
4
+ * needs (the `Prober` port, the self node) and delegates to the per-operation I/O
5
+ * functions in `runtime/monitor/` and `runtime/status-page/`. No business logic
6
+ * lives here.
6
7
  *
7
- * - `createNote` is interface-hosted (static) `remoteInterfaceMethods`.
8
- * - `reference` is class-hosted (instance) `remoteMethod` + `remoteClassMethods`.
9
- * - `seed` is class-hosted (static) — the `postInstall` bootstrap.
8
+ * `check` is the `Checkable` interface method, declared `abstract`, so it is
9
+ * implemented PER CLASS (Monitor probes; StatusPage rolls up) wired under
10
+ * `class.Monitor` / `class.StatusPage`, NOT a shared `interface` block. The
11
+ * kernel dispatches `@<node>::check` to the impl for that node's class.
10
12
  *
11
13
  * SDK-level `authorize` is an additive throw-to-deny check (returns void). For
12
14
  * finer worker checks see `assertPerm` / `requireOwnership` from `@astrale-os/sdk`.
13
- *
14
- * Exports the `methods` map the domain definition (`domain.ts`) wires in.
15
15
  */
16
- import {
17
- remoteClassMethods,
18
- remoteInterfaceMethods,
19
- remoteMethod,
20
- type SchemaMethodsImpl,
21
- } from '@astrale-os/sdk'
22
-
23
- import { createNote, reference, seed } from '../core/note'
16
+ import { remoteClassMethods, remoteMethod, type SchemaMethodsImpl } from '@astrale-os/sdk'
17
+
24
18
  import type { Deps } from '../deps'
19
+
20
+ import { MONITOR_KEYS } from '../core/monitor'
25
21
  import { schema } from '../schema'
22
+ import { check as monitorCheck, seed, watch } from './monitor'
23
+ import { add, check as pageCheck, create } from './status-page'
26
24
 
27
25
  const method = remoteMethod<Deps>()
28
- const interfaceMethods = remoteInterfaceMethods<Deps>()
29
26
  const classMethods = remoteClassMethods<Deps>()
30
27
 
31
- const NoteOpsMethods = interfaceMethods(schema, 'NoteOps', {
32
- createNote: {
33
- authorize: async () => undefined,
34
- execute: ({ kernel, params, deps }) => {
35
- if (!kernel) throw new Error('createNote requires a kernel credential')
36
- return createNote(kernel, deps.summarizer(), params)
37
- },
28
+ // ── Monitor ─────────────────────────────────────────────────────────
29
+
30
+ const monitorCheckMethod = method(schema, 'Monitor', 'check', {
31
+ authorize: async () => undefined,
32
+ execute: async ({ kernel, self, deps }) => {
33
+ const node = await self.node()
34
+ const url = node.props[MONITOR_KEYS.url]
35
+ if (typeof url !== 'string') throw new Error('Monitor node is missing its url property')
36
+ // Pass the node to the picker — the prober is chosen FOR this monitor.
37
+ return monitorCheck(kernel, deps.prober({ class: node.class.raw, url }), self.path.raw, url)
38
38
  },
39
39
  })
40
40
 
41
- const referenceMethod = method(schema, 'Note', 'reference', {
41
+ const watchMethod = method(schema, 'Monitor', 'watch', {
42
42
  authorize: async () => undefined,
43
- execute: ({ kernel, self, params }) => {
44
- if (!kernel) throw new Error('reference requires a kernel credential')
45
- return reference(kernel, self.path.raw, params)
43
+ execute: ({ kernel, params }) => {
44
+ return watch(kernel, params)
46
45
  },
47
46
  })
48
47
 
49
- const seedMethod = method(schema, 'Note', 'seed', {
48
+ const seedMethod = method(schema, 'Monitor', 'seed', {
50
49
  authorize: async () => undefined,
51
50
  execute: ({ kernel, deps }) => {
52
- if (!kernel) throw new Error('seed requires a kernel credential')
53
- return seed(kernel, deps.summarizer())
51
+ return seed(kernel, deps.prober())
52
+ },
53
+ })
54
+
55
+ // ── StatusPage ──────────────────────────────────────────────────────
56
+
57
+ const pageCheckMethod = method(schema, 'StatusPage', 'check', {
58
+ authorize: async () => undefined,
59
+ execute: ({ kernel, self }) => {
60
+ return pageCheck(kernel, self.path.raw)
61
+ },
62
+ })
63
+
64
+ const createMethod = method(schema, 'StatusPage', 'create', {
65
+ authorize: async () => undefined,
66
+ execute: ({ kernel, params }) => {
67
+ return create(kernel, params)
54
68
  },
55
69
  })
56
70
 
57
- const NoteMethods = classMethods(schema, 'Note', { reference: referenceMethod, seed: seedMethod })
71
+ const addMethod = method(schema, 'StatusPage', 'add', {
72
+ authorize: async () => undefined,
73
+ execute: ({ kernel, self, params }) => {
74
+ return add(kernel, self.path.raw, params)
75
+ },
76
+ })
58
77
 
59
78
  export const methods: SchemaMethodsImpl<typeof schema, Deps> = {
60
- interface: { NoteOps: NoteOpsMethods },
61
- class: { Note: NoteMethods },
79
+ class: {
80
+ Monitor: classMethods(schema, 'Monitor', {
81
+ check: monitorCheckMethod,
82
+ watch: watchMethod,
83
+ seed: seedMethod,
84
+ }),
85
+ StatusPage: classMethods(schema, 'StatusPage', {
86
+ check: pageCheckMethod,
87
+ create: createMethod,
88
+ add: addMethod,
89
+ }),
90
+ },
62
91
  }
@@ -0,0 +1,29 @@
1
+ import type { Prober } from '../../integrations/prober/port'
2
+ import type { CallableKernel } from '../shared'
3
+
4
+ /**
5
+ * `Monitor.check` (instance) — implements `Checkable.check` for a single endpoint:
6
+ * probe the target via the resolved `Prober` port, classify (pure, `core/monitor`),
7
+ * record status/latency on the node, and return the verdict. `url` + `prober` are
8
+ * resolved by the wiring (`runtime/index.ts`) from `self.node()`.
9
+ */
10
+ import { classify, MONITOR_KEYS } from '../../core/monitor'
11
+
12
+ export async function check(
13
+ kernel: CallableKernel,
14
+ prober: Prober,
15
+ selfPathRaw: string,
16
+ url: string,
17
+ ): Promise<{ status: string }> {
18
+ const result = await prober.probe(url)
19
+ const status = classify(result.statusCode)
20
+ await kernel.call(`${selfPathRaw}::update`, {
21
+ props: {
22
+ [MONITOR_KEYS.status]: status,
23
+ [MONITOR_KEYS.statusCode]: result.statusCode,
24
+ [MONITOR_KEYS.latencyMs]: result.latencyMs,
25
+ [MONITOR_KEYS.lastCheckedAt]: new Date().toISOString(),
26
+ },
27
+ })
28
+ return { status }
29
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Monitor operations — one file per method, assembled here for the composition
3
+ * root (`runtime/index.ts`). Each is transport-agnostic logic over a
4
+ * `CallableKernel` (+ the `Prober` port where it probes), delegating pure
5
+ * decisions to `core/monitor` — so all are unit-testable with fakes.
6
+ */
7
+ export { check } from './check'
8
+ export { seed } from './seed'
9
+ export { watch } from './watch'
@@ -0,0 +1,95 @@
1
+ import type { Prober } from '../../integrations/prober/port'
2
+
3
+ /**
4
+ * `Monitor.seed` (static) — the domain's post-install bootstrap. The kernel calls
5
+ * it ONCE after install, as __SYSTEM__ (see `postInstall` in `domain.ts`), so the
6
+ * domain comes up demonstrable: a `/monitors` folder + starter Monitors (each
7
+ * probed once), and a `/status-pages` folder + one StatusPage that `watches` them
8
+ * (its initial status rolled up from the probes). Idempotent: node creates swallow
9
+ * `PATH_CONFLICT` (fixed paths) and re-linking a `watches` edge is a graph no-op.
10
+ * It grants nothing — the installing owner reaches these nodes via root-propagated
11
+ * perms; grant explicitly here for non-owner access.
12
+ */
13
+ import {
14
+ classify,
15
+ FOLDER_CLASS,
16
+ MONITOR_CLASS,
17
+ MONITOR_KEYS,
18
+ MONITORS_PARENT,
19
+ NAME_KEY,
20
+ NODE_CREATE,
21
+ rollup,
22
+ STARTER_PAGE,
23
+ STARTERS,
24
+ STATUS_PAGE_CLASS,
25
+ STATUS_PAGES_PARENT,
26
+ PAGE_KEYS,
27
+ WATCHES_EDGE,
28
+ WATCHES_KEYS,
29
+ } from '../../core/monitor'
30
+ import { type CallableKernel, isPathConflict } from '../shared'
31
+
32
+ /** Create a node, swallowing a re-seed's `PATH_CONFLICT`. Returns true if newly created. */
33
+ async function ensure(kernel: CallableKernel, params: unknown): Promise<boolean> {
34
+ try {
35
+ await kernel.call(NODE_CREATE, params)
36
+ return true
37
+ } catch (e) {
38
+ if (!isPathConflict(e)) throw e
39
+ return false
40
+ }
41
+ }
42
+
43
+ export async function seed(kernel: CallableKernel, prober: Prober): Promise<{ seeded: number }> {
44
+ await ensure(kernel, {
45
+ class: FOLDER_CLASS,
46
+ path: MONITORS_PARENT,
47
+ props: { [NAME_KEY]: 'monitors' },
48
+ })
49
+
50
+ // Probe + create each starter Monitor; collect the verdict for the page roll-up.
51
+ const members: { status: string; critical: boolean }[] = []
52
+ let seeded = 0
53
+ for (const s of STARTERS) {
54
+ const result = await prober.probe(s.url)
55
+ const status = classify(result.statusCode)
56
+ members.push({ status, critical: s.critical })
57
+ const created = await ensure(kernel, {
58
+ class: MONITOR_CLASS,
59
+ path: `${MONITORS_PARENT}/${s.slug}`,
60
+ props: {
61
+ [NAME_KEY]: s.name,
62
+ [MONITOR_KEYS.url]: s.url,
63
+ [MONITOR_KEYS.status]: status,
64
+ [MONITOR_KEYS.statusCode]: result.statusCode,
65
+ [MONITOR_KEYS.latencyMs]: result.latencyMs,
66
+ [MONITOR_KEYS.lastCheckedAt]: new Date().toISOString(),
67
+ },
68
+ })
69
+ if (created) seeded++
70
+ }
71
+
72
+ // A StatusPage watching every starter, its status rolled up from the probes.
73
+ await ensure(kernel, {
74
+ class: FOLDER_CLASS,
75
+ path: STATUS_PAGES_PARENT,
76
+ props: { [NAME_KEY]: 'status-pages' },
77
+ })
78
+ const pagePath = `${STATUS_PAGES_PARENT}/${STARTER_PAGE.slug}`
79
+ await ensure(kernel, {
80
+ class: STATUS_PAGE_CLASS,
81
+ path: pagePath,
82
+ props: { [NAME_KEY]: STARTER_PAGE.name, [PAGE_KEYS.status]: rollup(members) },
83
+ })
84
+ // Re-linking the same (page, monitor) `watches` edge is a graph no-op, so this
85
+ // needs no conflict guard.
86
+ for (const s of STARTERS) {
87
+ await kernel.call(`${pagePath}::link`, {
88
+ edgeClass: WATCHES_EDGE,
89
+ target: `${MONITORS_PARENT}/${s.slug}`,
90
+ props: { [WATCHES_KEYS.critical]: s.critical },
91
+ })
92
+ }
93
+
94
+ return { seeded }
95
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `Monitor.watch` (static) — create a Monitor node under `/monitors`. The slug
3
+ * format is pure (`core/monitor`'s `uniqueSlug`); the entropy suffix (impure,
4
+ * clock/RNG) comes from `runtime/shared`, keeping core deterministic.
5
+ */
6
+ import {
7
+ MONITOR_CLASS,
8
+ MONITOR_KEYS,
9
+ MONITORS_PARENT,
10
+ NAME_KEY,
11
+ NODE_CREATE,
12
+ uniqueSlug,
13
+ } from '../../core/monitor'
14
+ import { type CallableKernel, randomSuffix } from '../shared'
15
+
16
+ export async function watch(
17
+ kernel: CallableKernel,
18
+ params: { url: string; name?: string },
19
+ ): Promise<{ id: string; path: string }> {
20
+ const path = `${MONITORS_PARENT}/${uniqueSlug(params.url, randomSuffix())}`
21
+ const created = (await kernel.call(NODE_CREATE, {
22
+ class: MONITOR_CLASS,
23
+ path,
24
+ props: {
25
+ [NAME_KEY]: params.name ?? params.url,
26
+ [MONITOR_KEYS.url]: params.url,
27
+ [MONITOR_KEYS.status]: 'unknown',
28
+ },
29
+ })) as { id: string }
30
+ return { id: created.id, path }
31
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Runtime-internal helpers shared across the context's operations. Not exported
3
+ * from the domain — just the seam the operation files agree on.
4
+ */
5
+
6
+ /**
7
+ * The minimal kernel surface the operations need — kept narrow so each is
8
+ * unit-testable with a fake `{ call }`. The SDK hands the real client at the
9
+ * `runtime/index.ts` seam.
10
+ */
11
+ export type CallableKernel = { call(path: string, params: unknown): Promise<unknown> }
12
+
13
+ /** True for the kernel's create-collision error — lets `seed` stay idempotent. */
14
+ export function isPathConflict(e: unknown): boolean {
15
+ return e instanceof Error && e.message.includes('PATH_CONFLICT')
16
+ }
17
+
18
+ /** Short clock+RNG entropy to dodge same-ms / same-stem slug collisions (impure). */
19
+ export function randomSuffix(): string {
20
+ return `${Date.now().toString(36).slice(-4)}${Math.random().toString(36).slice(2, 6)}`
21
+ }
@@ -0,0 +1,21 @@
1
+ import type { CallableKernel } from '../shared'
2
+
3
+ /**
4
+ * `StatusPage.add` (instance) — watch a Monitor: create a `watches` edge from
5
+ * this page to `monitor`, tagged `critical` (default false). `monitor` is any
6
+ * node address (a tree path or `@<id>`).
7
+ */
8
+ import { WATCHES_EDGE, WATCHES_KEYS } from '../../core/monitor'
9
+
10
+ export async function add(
11
+ kernel: CallableKernel,
12
+ selfPathRaw: string,
13
+ params: { monitor: string; critical?: boolean },
14
+ ): Promise<{ watched: string }> {
15
+ await kernel.call(`${selfPathRaw}::link`, {
16
+ edgeClass: WATCHES_EDGE,
17
+ target: params.monitor,
18
+ props: { [WATCHES_KEYS.critical]: params.critical ?? false },
19
+ })
20
+ return { watched: params.monitor }
21
+ }
@@ -0,0 +1,50 @@
1
+ import type { CallableKernel } from '../shared'
2
+
3
+ /**
4
+ * `StatusPage.check` (instance) — implements `Checkable.check` for a page: walk
5
+ * the `watches` edges, re-check each monitor (a cross-node `@<id>::check` call),
6
+ * roll the verdicts up (pure, `core/monitor`), record the page status, return it.
7
+ *
8
+ * `getLinks` returns raw `Edge`s whose endpoint/prop accessors aren't typed yet
9
+ * (an SDK gap) — `parseWatches` is the small cast that bridges it.
10
+ */
11
+ import { PAGE_KEYS, rollup, WATCHES_EDGE, WATCHES_KEYS } from '../../core/monitor'
12
+
13
+ /** A raw `watches` edge as `getLinks` returns it (endpoints are string-or-`{raw}`). */
14
+ type RawEdge = {
15
+ class?: string | { raw: string }
16
+ target?: string | { raw: string }
17
+ props?: Record<string, unknown>
18
+ }
19
+
20
+ function rawOf(p: RawEdge['target']): string | undefined {
21
+ if (typeof p === 'string') return p
22
+ return typeof p?.raw === 'string' ? p.raw : undefined
23
+ }
24
+
25
+ /** The monitors this page watches: each target ref + its `critical` flag. */
26
+ function parseWatches(raw: unknown): { monitor: string; critical: boolean }[] {
27
+ const edges = (Array.isArray(raw) ? raw : []) as RawEdge[]
28
+ const out: { monitor: string; critical: boolean }[] = []
29
+ for (const e of edges) {
30
+ if (rawOf(e.class) !== WATCHES_EDGE) continue
31
+ const monitor = rawOf(e.target)
32
+ if (monitor) out.push({ monitor, critical: e.props?.[WATCHES_KEYS.critical] === true })
33
+ }
34
+ return out
35
+ }
36
+
37
+ export async function check(
38
+ kernel: CallableKernel,
39
+ selfPathRaw: string,
40
+ ): Promise<{ status: string }> {
41
+ const links = await kernel.call(`${selfPathRaw}::getLinks`, { direction: 'out' })
42
+ const members = []
43
+ for (const w of parseWatches(links)) {
44
+ const { status } = (await kernel.call(`${w.monitor}::check`, {})) as { status: string }
45
+ members.push({ status, critical: w.critical })
46
+ }
47
+ const status = rollup(members)
48
+ await kernel.call(`${selfPathRaw}::update`, { props: { [PAGE_KEYS.status]: status } })
49
+ return { status }
50
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `StatusPage.create` (static) — create a StatusPage node under `/status-pages`.
3
+ */
4
+ import {
5
+ NAME_KEY,
6
+ NODE_CREATE,
7
+ STATUS_PAGE_CLASS,
8
+ STATUS_PAGES_PARENT,
9
+ uniqueSlug,
10
+ } from '../../core/monitor'
11
+ import { type CallableKernel, randomSuffix } from '../shared'
12
+
13
+ export async function create(
14
+ kernel: CallableKernel,
15
+ params: { name: string },
16
+ ): Promise<{ id: string; path: string }> {
17
+ const path = `${STATUS_PAGES_PARENT}/${uniqueSlug(params.name, randomSuffix())}`
18
+ const created = (await kernel.call(NODE_CREATE, {
19
+ class: STATUS_PAGE_CLASS,
20
+ path,
21
+ props: { [NAME_KEY]: params.name },
22
+ })) as { id: string }
23
+ return { id: created.id, path }
24
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * StatusPage operations — one file per method, assembled here for the
3
+ * composition root (`runtime/index.ts`). Transport-agnostic logic over a
4
+ * `CallableKernel`, delegating the roll-up decision to `core/monitor`.
5
+ */
6
+ export { add } from './add'
7
+ export { check } from './check'
8
+ export { create } from './create'
@@ -11,13 +11,20 @@
11
11
  import { defineSchema, KernelSchema } from '@astrale-os/kernel-core'
12
12
  import { compileDomain, type Domain } from '@astrale-os/kernel-core/domain'
13
13
 
14
- import { Note, NoteOps, references } from './note'
14
+ import { Checkable, Monitor, StatusPage, watches } from './monitor'
15
15
 
16
16
  export const schema = defineSchema('astrale-domain.example.dev', {
17
- interfaces: { NoteOps },
18
- classes: { Note, references },
17
+ interfaces: { Checkable },
18
+ classes: { Monitor, StatusPage, watches },
19
19
  imports: [KernelSchema],
20
20
  })
21
+
22
+ /**
23
+ * The compiled domain — resolved class/interface paths + qualified prop keys.
24
+ * `compileDomain` is pure (no env), so this is safe to import from the worker
25
+ * and from build tooling alike. `core/monitor/keys.ts` re-exports it as the single
26
+ * source of graph-facing strings (class paths, prop keys) — never hand-write those.
27
+ */
21
28
  export const D: Domain<typeof schema> = compileDomain(schema)
22
29
 
23
- export * from './note'
30
+ export * from './monitor'
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Monitoring context — the domain's single bounded slice: a `Checkable` contract
3
+ * implemented by two classes, plus the edge that binds them.
4
+ *
5
+ * - Interface `Checkable` one `abstract` method, `check()`. Abstract → each
6
+ * implementing class brings its OWN body, and the
7
+ * kernel dispatches by the node's class.
8
+ * - Class `Monitor` a single HTTP check. `check()` probes `url`;
9
+ * `watch` creates one; `seed` lays down the demo set.
10
+ * - Class `StatusPage` a roll-up. `check()` re-checks the monitors it
11
+ * `watches` and aggregates; `create` makes a page;
12
+ * `add` watches a monitor.
13
+ * - Edge `watches` StatusPage → Monitor, with a `critical` flag.
14
+ */
15
+ import { edgeClass, nodeClass, nodeInterface } from '@astrale-os/kernel-core'
16
+ import { fn } from '@astrale-os/kernel-dsl'
17
+ import { z } from 'zod'
18
+
19
+ /** Thin ref to a created node — what the static factories return (a full Node
20
+ * value does not round-trip over the worker wire). */
21
+ export const NodeRef = z.object({ id: z.string(), path: z.string() })
22
+
23
+ /** What `check()` reports — the subject's current health verdict. */
24
+ export const CheckResult = z.object({ status: z.string() })
25
+
26
+ export const Checkable = nodeInterface({
27
+ methods: {
28
+ // `abstract` → no shared body; every implementer supplies its own `check`,
29
+ // wired per-class in `runtime/`. `@<node>::check` dispatches by the node's class.
30
+ check: fn({ inheritance: 'abstract', returns: CheckResult }),
31
+ },
32
+ })
33
+
34
+ export const Monitor = nodeClass({
35
+ implements: [Checkable],
36
+ props: {
37
+ /** The target URL this monitor probes. */
38
+ url: z.string(),
39
+ // Live status, written by `check`. PLAIN STRING, not `z.enum()`: `::update`
40
+ // silently drops `z.enum()` props. Values: 'up' | 'down' | 'unknown'.
41
+ status: z.string().optional(),
42
+ /** Last observed HTTP status code (0 = host unreachable). */
43
+ statusCode: z.number().int().optional(),
44
+ /** Last observed round-trip latency, in ms. */
45
+ latencyMs: z.number().int().optional(),
46
+ /** ISO timestamp of the last check. */
47
+ lastCheckedAt: z.string().optional(),
48
+ },
49
+ methods: {
50
+ // Implements `Checkable.check` for a single endpoint (probe `url`). Redeclared
51
+ // here — a concrete class must declare each abstract method it implements, so
52
+ // the compiler materializes Monitor's OWN `check` node for per-class dispatch.
53
+ // The body lives in `runtime/monitor/check.ts`.
54
+ check: fn({ returns: CheckResult }),
55
+ /** Create a Monitor under `/monitors`. */
56
+ watch: fn({
57
+ static: true,
58
+ params: { url: z.string(), name: z.string().optional() },
59
+ returns: NodeRef,
60
+ }),
61
+ // Post-install bootstrap (wired as `postInstall` in domain.ts). Static: the
62
+ // kernel calls it ONCE after install, as __SYSTEM__. Must stay idempotent.
63
+ seed: fn({ static: true, returns: z.object({ seeded: z.number().int() }) }),
64
+ },
65
+ })
66
+
67
+ export const StatusPage = nodeClass({
68
+ implements: [Checkable],
69
+ props: {
70
+ /** Rolled-up status, written by `check`. 'up' | 'degraded' | 'down' | 'unknown'. */
71
+ status: z.string().optional(),
72
+ },
73
+ methods: {
74
+ // Implements `Checkable.check` for a page (roll up the watched monitors).
75
+ // Redeclared so StatusPage materializes its OWN `check` node. Body in
76
+ // `runtime/status-page/check.ts`.
77
+ check: fn({ returns: CheckResult }),
78
+ /** Create a StatusPage under `/status-pages`. */
79
+ create: fn({ static: true, params: { name: z.string() }, returns: NodeRef }),
80
+ /** Watch a monitor (a `watches` edge); `critical` decides the roll-up weight. */
81
+ add: fn({
82
+ params: { monitor: z.string(), critical: z.boolean().optional() },
83
+ returns: z.object({ watched: z.string() }),
84
+ }),
85
+ },
86
+ })
87
+
88
+ export const watches = edgeClass(
89
+ { as: 'page', types: [StatusPage] },
90
+ { as: 'monitor', types: [Monitor] },
91
+ // `critical` drives the roll-up: a critical monitor down ⇒ page `down`; a
92
+ // non-critical one down ⇒ `degraded`.
93
+ { props: { critical: z.boolean() } },
94
+ )
@@ -3,8 +3,14 @@
3
3
  * key; each becomes a View node at `/<origin>/core/views/<slug>` whose iframe
4
4
  * binding the SDK stamps with the worker's live serving URL when it builds the
5
5
  * install bundle.
6
+ *
7
+ * `welcome` is a worker-rendered inline-HTML view (no SPA). `ui-status-page` is
8
+ * the `client/` SPA (mounted at `/ui/status-page`, offered for any StatusPage).
6
9
  */
7
- import { note } from './note'
10
+ import { statusPage } from './status-page'
8
11
  import { welcome } from './welcome'
9
12
 
10
- export const views = { welcome, 'ui-note': note }
13
+ export const views = {
14
+ welcome,
15
+ 'ui-status-page': statusPage,
16
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `ui-status-page` — the domain's SPA view, mounted at `/ui/status-page` and
3
+ * served from the `client/` bundle. `viewFor: selfOf(StatusPage)` attaches a
4
+ * `view_for` edge to the `StatusPage` class meta-node, so the GUI offers this
5
+ * view for any StatusPage instance.
6
+ */
7
+ import { selfOf } from '@astrale-os/kernel-dsl'
8
+ import { defineView } from '@astrale-os/sdk'
9
+
10
+ import { StatusPage } from '../schema/monitor'
11
+
12
+ export const statusPage = defineView({
13
+ auth: 'public',
14
+ mount: '/ui/status-page',
15
+ viewFor: selfOf(StatusPage),
16
+ })