create-flowdular 0.4.1 → 0.5.1

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 (66) hide show
  1. package/README.md +9 -6
  2. package/agent-template/.agents/skills/auth-security-review/SKILL.md +1 -1
  3. package/agent-template/.agents/skills/bug-hunt/SKILL.md +1 -1
  4. package/agent-template/.agents/skills/module-new/SKILL.md +20 -19
  5. package/agent-template/.agents/skills/module-update/SKILL.md +4 -2
  6. package/agent-template/.agents/skills/spec-interview/SKILL.md +21 -20
  7. package/agent-template/.agents/skills/ux-design/SKILL.md +24 -2
  8. package/agent-template/.ai/README.md +5 -3
  9. package/agent-template/.ai/agents/README.md +1 -1
  10. package/agent-template/.ai/agents/sandbox/agentic-engineer.md +1 -0
  11. package/agent-template/.ai/agents/sandbox/backend-engineer.md +1 -0
  12. package/agent-template/.ai/agents/sandbox/frontend-engineer.md +1 -0
  13. package/agent-template/.ai/blueprints/add-migration/README.md +1 -1
  14. package/agent-template/.ai/examples/bad/client-imports-server/README.md +1 -1
  15. package/agent-template/.ai/examples/bad/missing-acl/README.md +1 -1
  16. package/agent-template/.ai/examples/bad/tenant-from-body/README.md +1 -1
  17. package/agent-template/.ai/guides/application-development.md +7 -5
  18. package/agent-template/.ai/platform-capabilities.md +10 -4
  19. package/agent-template/.ai/policies/capabilities.yaml +1 -0
  20. package/agent-template/.ai/policies/task-budgets.yaml +1 -1
  21. package/agent-template/.ai/rules/flowdular.md +3 -2
  22. package/agent-template/.ai/skills/auth-security-review/SKILL.md +1 -1
  23. package/agent-template/.ai/skills/bug-hunt/SKILL.md +1 -1
  24. package/agent-template/.ai/skills/module-new/SKILL.md +20 -19
  25. package/agent-template/.ai/skills/module-update/SKILL.md +4 -2
  26. package/agent-template/.ai/skills/spec-interview/SKILL.md +21 -20
  27. package/agent-template/.ai/skills/ux-design/SKILL.md +24 -2
  28. package/agent-template/.ai/subagents/module-executor.md +25 -0
  29. package/agent-template/.ai/subagents/reviewer.md +23 -0
  30. package/agent-template/.ai/subagents/spec-author.md +23 -0
  31. package/agent-template/.claude/agents/module-executor.md +22 -0
  32. package/agent-template/.claude/agents/reviewer.md +24 -0
  33. package/agent-template/.claude/agents/spec-author.md +20 -0
  34. package/agent-template/.claude/skills/auth-security-review/SKILL.md +1 -1
  35. package/agent-template/.claude/skills/bug-hunt/SKILL.md +1 -1
  36. package/agent-template/.claude/skills/module-new/SKILL.md +20 -19
  37. package/agent-template/.claude/skills/module-update/SKILL.md +4 -2
  38. package/agent-template/.claude/skills/spec-interview/SKILL.md +21 -20
  39. package/agent-template/.claude/skills/ux-design/SKILL.md +24 -2
  40. package/agent-template/.codex/agents/module-executor.toml +17 -0
  41. package/agent-template/.codex/agents/reviewer.toml +14 -0
  42. package/agent-template/.codex/agents/spec-author.toml +15 -0
  43. package/agent-template/AGENTS.md +3 -2
  44. package/agent-template/CLAUDE.md +3 -2
  45. package/agent-template/docs/cli.md +3 -0
  46. package/agent-template/docs/configuration.md +44 -0
  47. package/agent-template/docs/design-system.md +10 -3
  48. package/agent-template/docs/module-web-surfaces.md +31 -3
  49. package/agent-template/docs/modules.md +6 -0
  50. package/agent-template/docs/sandbox.md +117 -6
  51. package/agent-template/rulesync.jsonc +1 -1
  52. package/dist/bin.js +9 -0
  53. package/package.json +2 -2
  54. package/template/default/.env.example +7 -0
  55. package/template/default/.prettierignore +2 -0
  56. package/template/default/README.md +6 -4
  57. package/template/default/modules/example/module.json +1 -1
  58. package/template/default/modules/example/package.json +1 -1
  59. package/template/default/modules/example/spec/module.yaml +1 -1
  60. package/template/default/package.json +3 -2
  61. package/template/default/platform/index.html +7 -19
  62. package/template/default/platform/octane.config.ts +26 -2
  63. package/template/default/platform/package.json +1 -1
  64. package/template/default/platform/public/favicon.svg +1 -1
  65. package/template/default/platform/src/App.tsrx +25 -1
  66. package/template/default/platform/src/generated/modules.server.ts +2 -0
package/README.md CHANGED
@@ -50,12 +50,15 @@ The generator installs dependencies and initializes Git by default. Local develo
50
50
 
51
51
  ## Ready for coding agents
52
52
 
53
- Every app includes `.ai` rules, skills, role prompts, blueprints, policies and
54
- reference examples, plus `AGENTS.md`, `CLAUDE.md`, `.agents/skills` and
55
- `.claude/skills`. These files are bundled with the generator and are available
56
- with `--no-install`. Personal agent settings and credentials are never copied.
57
-
58
- Edit `.ai/rules` or `.ai/skills`, then run `pnpm rules:generate`. `pnpm verify`
53
+ Every app includes `.ai` rules, skills, role prompts, subagents, blueprints,
54
+ policies and reference examples, plus `AGENTS.md`, `CLAUDE.md`, `.agents/skills`,
55
+ `.claude/skills` and the spec author, module executor and reviewer as subagents in
56
+ `.claude/agents` and `.codex/agents`. The chat-first sandbox is installed with the
57
+ app, so `pnpm sandbox` starts it without a download. These files are bundled with
58
+ the generator and are available with `--no-install`. Personal agent settings and
59
+ credentials are never copied.
60
+
61
+ Edit `.ai/rules`, `.ai/skills` or `.ai/subagents`, then run `pnpm rules:generate`. `pnpm verify`
59
62
  checks that the generated instructions are in sync. The instructions explain
60
63
  where to find the installed SDK and how to extend the application's modules.
61
64
 
@@ -74,7 +74,7 @@ Report each finding as: severity (`blocker`, `should-fix`, `taste`), claim, `fil
74
74
  ```text
75
75
  blocker Tenant id read from body modules/inventory/src/api/endpoints.ts:41
76
76
  A member of tenant A posts { tenantId: "B" } and creates a location in B.
77
- AGENTS.md 6. Fix: principalFromContext(octane)!.tenantId; drop the field.
77
+ AGENTS.md 4. Fix: principalFromContext(octane)!.tenantId; drop the field.
78
78
  ```
79
79
 
80
80
  ## 8. Known platform gaps to keep in mind (not module defects)
@@ -29,7 +29,7 @@ description: >-
29
29
  | View falls back to the dashboard | `ApplicationShell.tsrx` renders `overview` for a view id that no visible navigation or account menu entry reaches |
30
30
  | Icon renders as a grid | `glyph` or `Icon name` is not an `ICON_PATHS` key (`packages/ui/src/icons/Icon.tsrx` falls back to `modules`) |
31
31
  | Stale data after a change | each component owns a store instance (`useMemo(() => createXClientState(), [])`); check the `store.act` that should have written it. `store.commits(cb)` and `store.stats()` from `segment-state` show what was committed |
32
- | Schema error on start | `runModuleMigrations`: `CHECKSUM_MISMATCH` means applied SQL bytes changed; `PARTIAL_OBJECTS` means only part of a pending migration exists. Never delete or bypass the database to hide either condition; restore the shipped bytes or diagnose the partial schema |
32
+ | Schema error on start | `runDatabaseMigrations`: `CHECKSUM_MISMATCH` means applied SQL bytes changed; `PARTIAL_MIGRATION` means only part of a pending migration exists. Never delete or bypass the database to hide either condition; restore the shipped bytes or diagnose the partial schema |
33
33
 
34
34
  ## 2b. Reproduction snippets
35
35
 
@@ -20,25 +20,26 @@ Every `acceptanceScenarios[]` entry maps to at least one test in `tests/`. A sce
20
20
 
21
21
  Each spec element maps to files:
22
22
 
23
- | Spec element | Files it produces |
24
- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
25
- | `entities[]` | `src/domain/types.ts`, `migrations/000N_<module>_<name>.{up,down}.sql`, `src/services/migration.ts`, `src/services/{repository,database-repository}.ts` |
26
- | `entities[].fields[]` | the columns and row mapping above, the validation bounds in `src/api/endpoints.ts`, the form field and table cell in `src/client/*.tsrx` |
27
- | `fields[].unique: tenant` | a `(tenant_id, <field>)` unique index in the migration plus the stable conflict code in the service |
28
- | `entities[].states` | the status column, the transition guard in the service, the `Tag` tone in the view |
29
- | `screens[]` | `src/client/<Pascal>View.tsrx`, a `views` entry and a `navigation` entry in `src/client/contribution.tsrx`, `translations/*.json` |
30
- | `screens[].columns`/`filters` | the `TableColumn[]` outside the component, and the controls inside the `Filters` dropdown |
31
- | `screens[].navigationGroup` | the navigation entry's `group` |
32
- | `actions[]` | the service method with its error code, the `defineEndpoint` route, the fetch in `src/client/api.ts` |
33
- | `widgets[]` | a widget component plus a `widgets` entry with its `slot` in `src/client/contribution.tsrx` |
34
- | `settings[]` | `src/settings.ts` (`defineModuleSettings`) and `settings:` in `src/platform.ts` |
35
- | `agentTools[]` | `src/agent/tools.ts` and the `context.agentTools.register` call, as a separate `agent-tool-design` phase |
36
- | `research` | `src/research.ts`, `research-fixtures.json`, `requires` of the capabilities, the evidence attach where the `evidenceOwner` record is written |
37
- | `adapters[]` | `src/adapters/<name>.ts`, the port, the adapter registration, `adapters/<name>.recorded.json`, as a separate `integration-adapter` phase |
38
- | `templates[]` | `templates/<name>.md`, `templates` in `package.json` `files`, `src/templates.ts` registered through `documents.templates.v1` in `src/platform.ts` |
39
- | `permissions[]` | `src/acl/permissions.ts`, the endpoint `access.permission`, the client `scope` |
40
- | `acceptanceScenarios[]` | `tests/module.test.ts` and its siblings, at least one case each |
41
- | `outOfScope[]`, `decisions[]` | no code. Read them so you do not rebuild a decision or implement a deferred feature. |
23
+ | Spec element | Files it produces |
24
+ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25
+ | `entities[]` | `src/domain/types.ts`, `migrations/000N_<module>_<name>.{up,down}.sql`, `src/services/migration.ts`, `src/services/{repository,database-repository}.ts` |
26
+ | `entities[].fields[]` | the columns and row mapping above, the validation bounds in `src/api/endpoints.ts`, the form field and table cell in `src/client/*.tsrx` |
27
+ | `fields[].unique: tenant` | a `(tenant_id, <field>)` unique index in the migration plus the stable conflict code in the service |
28
+ | `entities[].states` | the status column, the transition guard in the service, the `Tag` tone in the view |
29
+ | `screens[]` | `src/client/<Pascal>View.tsrx`, a `views` entry and a `navigation` entry in `src/client/contribution.tsrx`, `translations/*.json` |
30
+ | `design/<screen>.html` | the approved look of that screen: mirror its structure and keep its copy. Render it with `pnpm ui:preview <path>`; absent, design it first with `ux-design` |
31
+ | `screens[].columns`/`filters` | the `TableColumn[]` outside the component, and the controls inside the `Filters` dropdown |
32
+ | `screens[].navigationGroup` | the navigation entry's `group` |
33
+ | `actions[]` | the service method with its error code, the `defineEndpoint` route, the fetch in `src/client/api.ts` |
34
+ | `widgets[]` | a widget component plus a `widgets` entry with its `slot` in `src/client/contribution.tsrx` |
35
+ | `settings[]` | `src/settings.ts` (`defineModuleSettings`) and `settings:` in `src/platform.ts`; a `kind: flag` entry keeps `kind: 'flag'` there, so owners switch it on the Flags tab of Administration, Modules |
36
+ | `agentTools[]` | `src/agent/tools.ts` and the `context.agentTools.register` call, as a separate `agent-tool-design` phase |
37
+ | `research` | `src/research.ts`, `research-fixtures.json`, `requires` of the capabilities, the evidence attach where the `evidenceOwner` record is written |
38
+ | `adapters[]` | `src/adapters/<name>.ts`, the port, the adapter registration, `adapters/<name>.recorded.json`, as a separate `integration-adapter` phase |
39
+ | `templates[]` | `templates/<name>.md`, `templates` in `package.json` `files`, `src/templates.ts` registered through `documents.templates.v1` in `src/platform.ts` |
40
+ | `permissions[]` | `src/acl/permissions.ts`, the endpoint `access.permission`, the client `scope` |
41
+ | `acceptanceScenarios[]` | `tests/module.test.ts` and its siblings, at least one case each |
42
+ | `outOfScope[]`, `decisions[]` | no code. Read them so you do not rebuild a decision or implement a deferred feature. |
42
43
 
43
44
  A v1 spec stays valid and carries none of these arrays. Then the requirements are `invariants`, `permissions` and `acceptanceScenarios`, and everything the spec leaves open is still a question rather than a guess.
44
45
 
@@ -16,7 +16,7 @@ The spec-element to file mapping is the table in `module-new`; the change classe
16
16
 
17
17
  ## 1. Read first
18
18
 
19
- Read the whole module before changing it: `spec/module.yaml`, `src/index.ts`, `src/acl/permissions.ts`, `src/api/endpoints.ts`, `src/services/*`, `src/client/*`, `tests/`. Keep every exported name in `src/index.ts`, `src/server/index.ts` and `src/client/index.ts` stable: other modules import them (`modules/users` uses `AuthRuntime` from `@flowdular/sdk/modules/auth/server`), and the generated composition imports `createServerComposition` and `createClientContribution`.
19
+ Read the whole module before changing it: `spec/module.yaml`, `design/*.html` when the change touches a screen, `src/index.ts`, `src/acl/permissions.ts`, `src/api/endpoints.ts`, `src/services/*`, `src/client/*`, `tests/`. Keep every exported name in `src/index.ts`, `src/server/index.ts` and `src/client/index.ts` stable: other modules import them (`modules/users` uses `AuthRuntime` from `@flowdular/sdk/modules/auth/server`), and the generated composition imports `createServerComposition` and `createClientContribution`.
20
20
 
21
21
  Sandbox facts for an edit session (`packages/sandbox/src/server/sessions.ts`): the module is copied to `workspace/modules/<dir>` and a pristine copy to `base/modules/<dir>`; the diff shown to the operator and the eject plan compare the two. The workspace is a pnpm workspace of its own (declared dependencies install for real; a `package.json` change triggers a reinstall that counts as the `dependencies` gate). The business manager updates the spec before implementation. The operator approves the exact spec hash for every affected module; editing that spec, requesting changes, or adding another module reopens its approval gate. A sandbox specialist never writes `status: approved`; a host agent may invoke approval only after an explicit current user request through `spec-approval`. Delivery checks the recorded hash again.
22
22
 
@@ -55,9 +55,11 @@ New screen or widget:
55
55
  3. `src/client/index.ts`: re-export the view.
56
56
  4. Add user-facing copy to every declared `translations/*.json` bundle and resolve it with fully qualified `t()` keys. Navigation copy uses getters because contributions exist before bundles are registered.
57
57
 
58
+ New feature flag: a setting with `kind: 'flag'`, `type: 'boolean'`, `scope: 'tenant'` and a `defaultValue`. It reads like any other setting, `context.settings.get<boolean>(tenantId, '<module>.core', 'key')`, and appears on the Flags tab of Administration, Modules beside the module's other flags; a change is audited as `settings.flag.changed`. Declare it in the spec as `kind: flag` too, and state in an invariant what the module does while it is off. Before changing behaviour a workspace already relies on, removing a step, or adding an outward-facing or costly path, propose a flag and let the operator decide: ship the new path behind it, default off, and keep the old path working while it is off. A flag is on or off for one workspace; there is no percentage rollout and no targeting.
59
+
58
60
  New setting:
59
61
 
60
- 1. `src/settings.ts`: `export const X_MODULE_SETTINGS = defineModuleSettings({ moduleId: '<module>.core', settings: { key: { type: 'string' | 'number' | 'boolean', defaultValue, visibility: 'private' | 'shared', client: boolean, scope: 'tenant' | 'platform', labelKey, label, descriptionKey, description, min?, max?, enum?, secret? } } })` from `@flowdular/sdk/kernel` (`packages/kernel/src/module-settings.ts`; setting keys match `^[a-z][a-zA-Z0-9]*$`). `labelKey` and `descriptionKey` are fully qualified module translation keys present in every locale. Keep the English literals as compatibility fallbacks; values, ids and secrets are never translated.
62
+ 1. `src/settings.ts`: `export const X_MODULE_SETTINGS = defineModuleSettings({ moduleId: '<module>.core', settings: { key: { type: 'string' | 'number' | 'boolean', kind?: 'flag', defaultValue, visibility: 'private' | 'shared', client: boolean, scope: 'tenant' | 'platform', labelKey, label, descriptionKey, description, min?, max?, enum?, secret? } } })` from `@flowdular/sdk/kernel` (`packages/kernel/src/module-settings.ts`; setting keys match `^[a-z][a-zA-Z0-9]*$`). `labelKey` and `descriptionKey` are fully qualified module translation keys present in every locale. Keep the English literals as compatibility fallbacks; values, ids and secrets are never translated.
61
63
  2. `src/platform.ts`: return `settings: X_MODULE_SETTINGS` next to `routes`; the platform declares it at boot and Administration, Modules renders it in the module's drawer (`modules/system/src/client/ModuleSettingsSection.tsrx`, behind `system.settings.read` and `system.settings.manage`; the API is `GET /api/settings` and `POST /api/settings/update` in `modules/system/src/server/endpoints.ts`).
62
64
  3. Read it live where it is used: `context.settings.get<number>(tenantId, '<module>.core', 'key')` at request time, never cached at boot; pass `context.settings` into the runtime or service that needs it (`modules/agents/src/settings.ts`, `agentSettings`, shows the pattern with an environment fallback).
63
65
  4. `spec/module.yaml`: an invariant or scenario naming the setting and its bounds; `specVersion` bump. Cross-module reads of a setting need `visibility: 'shared'` and a declared dependency.
@@ -23,25 +23,26 @@ For an edit, also read the module's current `spec/module.yaml` and write the sma
23
23
 
24
24
  One pass, in this order. For each row, write the default from the card into the spec and record it as a `decisions[]` entry with `decidedBy: default`. Ask only where the answer is a business fact that no default can supply.
25
25
 
26
- | Decision | Default to propose | Lands in |
27
- | ---------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------- |
28
- | Actors | Owner manages, member reads | `permissions`, `invariants` |
29
- | Entities and fields | One primary entity; `name` required, `maxLength` 120; no field the request did not name | `entities[]` |
30
- | Uniqueness | The human-facing code is `unique: tenant`; everything else `none` | `entities[].fields[].unique` |
31
- | States and transitions | `active` and `archived`, every transition behind the manage permission | `entities[].states` |
32
- | Who sees what | Both permissions in the same navigation entry; the manage action hidden without the scope | `permissions`, `screens[]`, `invariants` |
33
- | What is denied | Unauthenticated 401, missing permission 403, cross-tenant read returns nothing | `acceptanceScenarios` |
34
- | Failure behaviour | A duplicate returns a stable conflict and changes nothing; bounds return 400 | `invariants`, `acceptanceScenarios` |
35
- | Cross-module reads | None. A read of another module goes through its public capability and a declared dependency | `dependencies`, `dataOwnership` |
36
- | Screens | One `list` screen with the entity's identifying columns | `screens[]` |
37
- | Widgets | None. A count belongs on `dashboard.metrics` only when the request asks for it | `widgets[]` |
38
- | Settings | None. A number the business may change later is `scope: tenant` with a stated default | `settings[]` |
39
- | Agent tools | None. A tool is a later phase and `risk` may only be `read` or `workspace-write` | `agentTools[]` |
40
- | Outside sources | None. A named public source is `research`, with the entity its findings attach to | `research` |
41
- | Other systems | None. A named system is one `source` adapter per record kind, run on demand | `adapters[]` |
42
- | Documents | None. A named document is one `templates[]` entry on the record it describes | `templates[]` |
43
- | Reports | None. There is no export, no PDF and no search; a report is a screen or it is out of scope | `outOfScope[]` |
44
- | Out of scope | Every item from the card's gap list the request touched, each with its business decision | `outOfScope[]`, `decisions[]` |
26
+ | Decision | Default to propose | Lands in |
27
+ | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
28
+ | Actors | Owner manages, member reads | `permissions`, `invariants` |
29
+ | Entities and fields | One primary entity; `name` required, `maxLength` 120; no field the request did not name | `entities[]` |
30
+ | Uniqueness | The human-facing code is `unique: tenant`; everything else `none` | `entities[].fields[].unique` |
31
+ | States and transitions | `active` and `archived`, every transition behind the manage permission | `entities[].states` |
32
+ | Who sees what | Both permissions in the same navigation entry; the manage action hidden without the scope | `permissions`, `screens[]`, `invariants` |
33
+ | What is denied | Unauthenticated 401, missing permission 403, cross-tenant read returns nothing | `acceptanceScenarios` |
34
+ | Failure behaviour | A duplicate returns a stable conflict and changes nothing; bounds return 400 | `invariants`, `acceptanceScenarios` |
35
+ | Cross-module reads | None. A read of another module goes through its public capability and a declared dependency | `dependencies`, `dataOwnership` |
36
+ | Screens | One `list` screen with the entity's identifying columns | `screens[]` |
37
+ | Widgets | None. A count belongs on `dashboard.metrics` only when the request asks for it | `widgets[]` |
38
+ | Settings | None. A number the business may change later is `scope: tenant` with a stated default | `settings[]` |
39
+ | Feature flags | Ask for one whenever a change alters behaviour a workspace already relies on, or is hard to undo: `kind: flag`, boolean, `scope: tenant`, a stated default, and the behaviour named in an invariant | `settings[]` |
40
+ | Agent tools | None. A tool is a later phase and `risk` may only be `read` or `workspace-write` | `agentTools[]` |
41
+ | Outside sources | None. A named public source is `research`, with the entity its findings attach to | `research` |
42
+ | Other systems | None. A named system is one `source` adapter per record kind, run on demand | `adapters[]` |
43
+ | Documents | None. A named document is one `templates[]` entry on the record it describes | `templates[]` |
44
+ | Reports | A named report is one provider on `reports.v1` returning tiles and series; a named list export is one `defineListExport`; named records are findable through `search.providers.v1`. None of the three has a specification key, so each needs a decision naming the screen or the `actions[]` entry that registers it | `actions[]`, `invariants` |
45
+ | Out of scope | Every item from the card's gap list the request touched, each with its business decision | `outOfScope[]`, `decisions[]` |
45
46
 
46
47
  A default you propose is still a decision: it goes into `decisions[]` so the operator can see and overturn it, and so the next agent never re-derives it.
47
48
 
@@ -89,7 +90,7 @@ A number the case needs (a score, a premium, a price per square metre) is an `ac
89
90
  - `screens[]`: `{ id, kind: list|record|form|dashboard, entity?, title?, columns?, filters?, navigationGroup? }`. `navigationGroup` is one of the six values on the card.
90
91
  - `actions[]`: `{ id, entity?, permission, kind: create|update|delete|custom, risk, idempotent, description }`. `risk: external` is refused by the platform, so an action may not declare it.
91
92
  - `widgets[]`: `{ id, slot, entity?, description }`; `slot` is one of the four workspace slots.
92
- - `settings[]`: `{ key, type: string|integer|boolean|enum, scope: tenant|platform, default?, values?, description }`.
93
+ - `settings[]`: `{ key, type: string|integer|boolean|enum, scope: tenant|platform, kind?: setting|flag, default?, values?, description }`. A `flag` is boolean, `scope: tenant` and carries a default; owners switch it per workspace on the Flags tab of Administration, Modules, and every change is audited. Ask whether the new behaviour ships behind one: a change to something a workspace already does, an outward-facing action, a costly or slow path, or anything a business would want to turn off without a deployment. Say what the module does with the flag off, as an invariant.
93
94
  - `agentTools[]`: `{ id, permission, description, risk: read|workspace-write }`.
94
95
  - `outOfScope[]`: plain sentences, each naming the gap and the decision taken instead.
95
96
  - `decisions[]`: `{ id, question, answer, decidedBy: user|default }`; ids match `^[A-Z][A-Z0-9-]+$`, for example `D-UNIQUE-SKU`.
@@ -81,7 +81,7 @@ Read-only master-detail (runs, playground) keeps `ui-two-col` (+ `--wide-aside`)
81
81
  - `Alert`: `tone` danger (default), warning, info.
82
82
  - `Avatar`: `name`, `square` (organizations), `large`.
83
83
  - `Icon`: `name`, `size` (18 default, 16 in controls, 14 in `Button size="sm"`), `strokeWidth`.
84
- - `BrandMark`: `size`, `signature`, `tone`; brand moments only.
84
+ - `BrandMark`: `size`, `tone`; three bars with a copper accent bar, brand moments only.
85
85
 
86
86
  Icon keys (`ICON_PATHS`, `packages/ui/src/icons/Icon.tsrx`): `dashboard`, `parties`, `catalog`, `user`, `users`, `shield`, `code`, `modules`, `file-text`, `play`, `bot`, `flask`, `activity`, `plug`, `search`, `chevron-down`, `chevron-left`, `chevron-right`, `chevrons-up-down`, `sort`, `calendar`, `plus`, `panel-left`, `check`, `filter`, `download`, `more`, `external`, `alert`, `x`, `sign-out`, `refresh`, `help`, `info`, `key`, `settings`, `braces`, `copy`. An unknown name renders `modules` silently, so check the list.
87
87
 
@@ -93,7 +93,28 @@ Layout `ui-view`, `ui-two-col` (+`--wide-aside`), `ui-grid-2`, `ui-kpi-grid`, `u
93
93
 
94
94
  User-facing copy lives in every declared `translations/*.json` bundle and is read with fully qualified `t()` keys. Eyebrow names the domain, title names the records, and description is one sentence. Table headers say what the value is. Buttons start with a verb. Loading text ends with `…`. Drawer footer states the constraint the user cannot see. Write natural copy in each locale, with no exclamation marks or database jargon.
95
95
 
96
- ## 7. Inspect the rendered screen
96
+ ## 7. Design the screen as a preview first
97
+
98
+ A design is a file, not a description: `modules/<dir>/design/<screen>.html`, beside the spec. It is markup only, dressed by the platform's own stylesheets, so it shows what the screen will look like before a component exists and long before the application boots. An implementation phase reads it the way it reads the spec.
99
+
100
+ ```bash
101
+ pnpm ui:preview modules/<dir>/design/<screen>.html --scaffold # the record recipe in all five states
102
+ pnpm ui:preview modules/<dir>/design/<screen>.html # renders it, prints a file:// address
103
+ pnpm ui:preview modules/<dir>/design/<screen>.html --shot .flowdular/ui-preview/<screen>.png
104
+ pnpm ui:preview modules/<dir>/design/<screen>.html --open # shows it to the person asking
105
+ ```
106
+
107
+ Rules that keep a preview honest:
108
+
109
+ - Markup only. No `<style>`, no CSS rule, no `<html>` or `<body>`; the command refuses a fragment that carries one. Every visual decision comes from `packages/ui`, which is what stops a preview from becoming a second source of truth.
110
+ - One `<section class="ui-view" data-state="...">` per state: `populated`, `loading`, `empty`, `error`, `denied`. The command labels each one, so a single page answers for all five.
111
+ - Real content. The longest realistic name, a real identifier, the copy the screen will actually carry. A preview of `Lorem ipsum` proves nothing about overflow or alignment.
112
+ - Only classes a stylesheet declares. `pnpm ui-classes:check` fails on a class nothing defines, in a preview and in a `.tsrx` alike, which is the one mistake that compiles, passes its tests and renders unstyled. A class a module needs and the design system lacks is declared in the module's own CSS, as rule 4 says.
113
+ - `--shot` writes a PNG, which is how an agent with no browser looks at its own work. `--open` opens the preview in the person's browser, which is how a design is shown for approval; a correction loop renders without it rather than throwing a window at whoever is at the keyboard.
114
+
115
+ Hand off the path, not a description. An implementation phase opens the preview, mirrors its structure with the components in section 4, and keeps the copy.
116
+
117
+ ## 8. Inspect the rendered screen
97
118
 
98
119
  A screen is not finished until it has been looked at. Typecheck and tests say nothing about overflow, alignment, a duplicate label or a column that collapses.
99
120
 
@@ -117,6 +138,7 @@ Check the drawer form in the same pass: one label per field, fields top-aligned,
117
138
 
118
139
  ## Pitfalls
119
140
 
141
+ - A preview that renders unstyled is a class nothing declares, not a broken harness; run `pnpm ui-classes:check`.
120
142
  - `Kpi value={items.length}` does not typecheck; use `String(items.length)`.
121
143
  - A `Tag` for a lifecycle state uses `success` for active and `neutral` for archived, with `dot`.
122
144
  - An `Icon` inside `Button size="sm"` is 14, not 18.
@@ -10,6 +10,7 @@ Flowdular is an agentic foundation framework. The platform under `packages/`, `m
10
10
  | `rules/*.md` | Canonical cross-agent instructions. RuleSync generates the root `AGENTS.md` and `CLAUDE.md` from these files; `pnpm rules:check` rejects drift. |
11
11
  | `agents/sandbox/*.md` | Loaded at sandbox start by `packages/coding-agent/src/roles/registry.ts` (`loadAgentRoles`); `gates`, `handoff` and `allowedPaths` are enforced. `dependencies` always runs, a `HANDOFF:` line must name a role from the list and never the role itself, and writes outside the active role allowlist are quarantined and restored before validation. Defaults in `packages/coding-agent/src/roles/defaults.ts` are regenerated from these files by `pnpm --filter @flowdular/coding-agent sync-roles`, and `tests/sync.test.ts` fails when they drift. |
12
12
  | `agents/{module-executor,reviewer,spec-author}.md` | Read by people and coding tools at the repository root; named in `blueprints/*/blueprint.json`. Not loaded by code. |
13
+ | `subagents/*.md` | The same three root roles as delegable subagents. RuleSync generates `.claude/agents/<name>.md` and `.codex/agents/<name>.toml` from them, so Claude Code and Codex can hand a phase to the role; each body points at its `agents/<id>.md` prompt and its one task skill. |
13
14
  | `skills/*/SKILL.md` | Canonical cross-agent procedures. They are copied into every sandbox session as `reference/skills/` (`packages/sandbox/src/server/reference.ts`) and RuleSync generates the discovery copies under `.agents/skills` and `.claude/skills`. |
14
15
  | `blueprints/*/blueprint.json` | `pnpm flowdular blueprint list` and `blueprint validate --all` (`packages/cli/src/runner.ts`, discovery in `packages/cli/src/validation.ts` `findNamedFiles`) validate every `blueprint.json` against `packages/contracts/schemas/blueprint.schema.json` and check the companion files exist; `pnpm validate` runs it in CI. The sandbox labels sessions `new-module@1.0.0` and `edit-module@1.0.0`. |
15
16
  | `blueprints/*/*.yaml`, `*.schema.json`, `examples/` | Existence-checked by `validateBlueprint`; otherwise documentation for agents and reviewers. Nothing executes `steps.yaml` or `gates.yaml`. |
@@ -17,7 +18,7 @@ Flowdular is an agentic foundation framework. The platform under `packages/`, `m
17
18
  | `policies/task-budgets.yaml`, `policies/path-ownership.yaml` | Read by the `git-pr` delivery target (`packages/sandbox/src/server/delivery/policies.ts`): the changed-file and new-dependency budget per session kind, and path owners plus `crossOwnerChanges.requireReviewer` for the pull request body. Review guidance otherwise. |
18
19
  | `examples/**` | Reference shapes for agents; not compiled or tested. |
19
20
 
20
- `AGENTS.md` and `docs/design-system.md` are copied into each session's `reference/` as well (`packages/sandbox/src/server/reference.ts`). `AGENTS.md`, `CLAUDE.md`, `.agents/skills` and `.claude/skills` are generated compatibility outputs. Edit `.ai/rules` or `.ai/skills`, then run `pnpm rules:generate`.
21
+ `AGENTS.md` and `docs/design-system.md` are copied into each session's `reference/` as well (`packages/sandbox/src/server/reference.ts`). `AGENTS.md`, `CLAUDE.md`, `.agents/skills`, `.claude/skills`, `.claude/agents` and `.codex/agents` are generated compatibility outputs. Edit `.ai/rules`, `.ai/skills` or `.ai/subagents`, then run `pnpm rules:generate`.
21
22
 
22
23
  ## Using the skills from your own tool
23
24
 
@@ -27,8 +28,8 @@ sandbox turn receives one Task skill from `packages/coding-agent/src/roles/skill
27
28
  not the entire catalog. Character-budget and routing tests guard against prompt
28
29
  growth; characters are a stable size proxy, not a tokenizer-specific cost estimate.
29
30
 
30
- - Claude Code reads the generated `CLAUDE.md` and discovers the generated `.claude/skills` copies.
31
- - Codex reads the generated `AGENTS.md` and discovers the generated `.agents/skills` copies.
31
+ - Claude Code reads the generated `CLAUDE.md` and discovers the generated `.claude/skills` copies and the `.claude/agents` subagents.
32
+ - Codex reads the generated `AGENTS.md` and discovers the generated `.agents/skills` copies and the `.codex/agents` subagents.
32
33
  - Any other tool: paste `AGENTS.md` and the skill into the instruction.
33
34
 
34
35
  Both paths land the same way: gates, then `pnpm flowdular module enable <id> --apply` for a new module (it grants the module's scopes as its last step; `auth sync-scopes` re-grants later), `pnpm verify`, pull request (`skills/release-eject-pr`). A sandbox session is a pnpm workspace of its own with the draft modules as projects, so declared dependencies resolve for real and the `dependencies` gate runs after every turn.
@@ -39,6 +40,7 @@ Both paths land the same way: gates, then `pnpm flowdular module enable <id> --a
39
40
  - Skill: edit `skills/<kebab-name>/SKILL.md` with `name`, `description`, `roles`, `when`; keep it focused, verify API claims against the cited code, add a row in `skills/README.md`, then run `pnpm rules:generate`.
40
41
  - Blueprint: a directory under `blueprints/` with `blueprint.json` valid against `packages/contracts/schemas/blueprint.schema.json` plus `README.md`, `input.schema.json`, `plan.schema.json`, `spec-requirements.yaml`, `allowed-paths.yaml`, `required-files.yaml`, `steps.yaml`, `gates.yaml` (all required by `validateBlueprint`), and `examples/valid`, `examples/invalid` (`input*.json` validate against `input.schema.json`, `plan*.json` against `plan.schema.json`). `agentRoles` use the role ids from `agents/`; `executorProfiles` use the profile ids in `policies/model-routing.yaml`; gate ids for module blueprints come from `packages/sandbox/src/server/gates.ts`.
41
42
  - Sandbox role: `agents/sandbox/<id>.md` with the front matter `id`, `name`, `purpose`, `allowedPaths`, `gates`, `handoff` (see `agents/README.md`), then regenerate the bundled defaults: `pnpm --filter @flowdular/coding-agent sync-roles` (the script provided by `packages/coding-agent`; it rewrites `src/roles/defaults.ts` from these files) and run `pnpm --filter @flowdular/coding-agent test`.
43
+ - Root subagent: `subagents/<name>.md` with the front matter `name`, `targets`, `description` and an optional `claudecode` block, a body that names the `agents/<id>.md` prompt and the one task skill, then `pnpm rules:generate`. Keep the procedure in the role prompt; the subagent file stays a pointer so the two cannot drift.
42
44
  - Policy: keep it truthful about what code enforces; name the file that does.
43
45
 
44
46
  Formatting: `npx prettier --write .ai docs`, then `pnpm rules:generate`. No em or en dashes anywhere.
@@ -17,7 +17,7 @@ The five roles and who takes the first turn: `business-manager` for both a new m
17
17
 
18
18
  ## Root roles run at the repository root
19
19
 
20
- `module-executor.md`, `reviewer.md`, `spec-author.md` describe the same jobs for an agent working in a checkout with a shell (Claude Code, Codex, a person). No code loads them; `.ai/blueprints/*/blueprint.json` names them in `agentRoles` and `requiredReviewers`. Their `allowedPaths` are relative to the repository root and they run the gates themselves with the commands listed in each blueprint's `gates.yaml`.
20
+ `module-executor.md`, `reviewer.md`, `spec-author.md` describe the same jobs for an agent working in a checkout with a shell (Claude Code, Codex, a person). No code loads them; `.ai/blueprints/*/blueprint.json` names them in `agentRoles` and `requiredReviewers`, and `.ai/subagents/<id>.md` exposes each one as a delegable subagent that points back here (RuleSync writes `.claude/agents` and `.codex/agents`). Their `allowedPaths` are relative to the repository root and they run the gates themselves with the commands listed in each blueprint's `gates.yaml`.
21
21
 
22
22
  ## Adding or changing a role
23
23
 
@@ -13,6 +13,7 @@ gates:
13
13
  - spec-schema
14
14
  - module-schema
15
15
  - dependencies
16
+ - module-rules
16
17
  - typecheck
17
18
  - tests
18
19
  handoff:
@@ -24,6 +24,7 @@ allowedPaths:
24
24
  gates:
25
25
  - module-schema
26
26
  - dependencies
27
+ - module-rules
27
28
  - typecheck
28
29
  - tests
29
30
  - format
@@ -8,6 +8,7 @@ allowedPaths:
8
8
  - 'package.json'
9
9
  gates:
10
10
  - dependencies
11
+ - module-rules
11
12
  - typecheck
12
13
  - tests
13
14
  - format
@@ -1,5 +1,5 @@
1
1
  # add-migration
2
2
 
3
- Add a table, column, index or constraint through the numbered migration runner. The `.up.sql` file is the source, `src/services/migration.ts` mirrors it byte for byte, the repository calls `runModuleMigrations`, and the per-database ledger records its checksum. Existing databases adopt complete pre-ledger schema without replaying it. Procedure: `.ai/skills/migration-authoring/SKILL.md`.
3
+ Add a table, column, index or constraint through the numbered migration runner. The `.up.sql` file is the source, `src/services/migration.ts` mirrors it byte for byte, the repository calls `runDatabaseMigrations`, and the per-database ledger records its checksum. Existing databases adopt complete pre-ledger schema without replaying it. Procedure: `.ai/skills/migration-authoring/SKILL.md`.
4
4
 
5
5
  Additive only. A destructive change (drop, type change, tightened check) is refused by this blueprint's input schema and needs an operator decision.
@@ -2,7 +2,7 @@
2
2
 
3
3
  `api.ts` sits under `src/client` and imports `../services/database-repository.ts`, which pulls in `@flowdular/sdk/database` and its `node:fs`, `node:path` and `node:async_hooks` imports. The Vite client build fails on the Node built-ins, and even where it compiled the browser would hold a database handle and a `tenantId` parameter chosen by the caller, bypassing every endpoint check.
4
4
 
5
- Violated rules: `AGENTS.md` 5 and 6 (data reaches the client only through an endpoint that resolves identity and takes the tenant from the principal) and the layering in `.ai/skills/core-extend/SKILL.md` (client code imports `@flowdular/sdk/client`, `@flowdular/sdk/ui`, `octane`, `segment-state`, and the module's own `src/client` and `src/domain` types; never `src/services` or `src/server`).
5
+ Violated rules: `AGENTS.md` 3 and 4 (data reaches the client only through an endpoint that resolves identity and takes the tenant from the principal) and the layering in `.ai/skills/core-extend/SKILL.md` (client code imports `@flowdular/sdk/client`, `@flowdular/sdk/ui`, `octane`, `segment-state`, and the module's own `src/client` and `src/domain` types; never `src/services` or `src/server`).
6
6
 
7
7
  Repair with the `bug-fix` blueprint: replace the import with a `fetch` in `src/client/api.ts` as in `.ai/references/catalog/src/client/api.ts`:
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  `endpoints.ts` mounts `/api/customers` with `new ServerRoute` from `@octanejs/app-core`. Nothing resolves an identity, nothing checks a permission, and `listAll()` has no tenant. Anyone who can reach the server reads every tenant's customers.
4
4
 
5
- Violated rules: `AGENTS.md` 5 (every endpoint is `defineEndpoint` with `access: { kind: 'permission' }` and `resolveIdentity: endpointIdentityFromContext`) and 6 (tenant id from the principal). The security skill's first grep (`grep -rn "new ServerRoute" modules/*/src | grep -v modules/auth`) finds it.
5
+ Violated rules: `AGENTS.md` 3 (every endpoint is `defineEndpoint` with `access: { kind: 'permission' }` and `resolveIdentity: endpointIdentityFromContext`) and 4 (tenant id from the principal). The security skill's first grep (`grep -rn "new ServerRoute" modules/*/src | grep -v modules/auth`) finds it.
6
6
 
7
7
  Repair with the `bug-fix` blueprint (or `edit-module`, change class `endpoint`):
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  `endpoints.ts` has a permission and an identity resolver, and still lets a member of tenant A create a customer in tenant B by posting `{ "tenantId": "B", "name": "..." }`. The permission check passes because the principal holds `customers.records.manage` in its own tenant; the body decides where the row lands. The mutation also skips `sessionMutationDenial`, so a cross-site form post with a valid cookie would be accepted.
4
4
 
5
- Violated rules: `AGENTS.md` 6 (tenant id only from `principalFromContext(octane)!.tenantId`) and 7 (`sessionMutationDenial(octane, auth)` first on every mutation). The security skill's grep `grep -rn tenantId modules/*/src/api | grep -v principalFromContext` finds it.
5
+ Violated rules: `AGENTS.md` 4 (tenant id only from `principalFromContext(octane)!.tenantId`) and 3 (an explicit permission and an identity resolver on every endpoint). The security skill's grep `grep -rn tenantId modules/*/src/api | grep -v principalFromContext` finds it.
6
6
 
7
7
  Repair with the `bug-fix` blueprint: remove the body field, take `auth: AuthRuntime` in `createCustomerRoutes`, and write
8
8
 
@@ -84,11 +84,13 @@ spec approval or production access.
84
84
 
85
85
  ## Maintain the agent guidance
86
86
 
87
- Edit `.ai/rules` and `.ai/skills`, then run `pnpm rules:generate` and
88
- `pnpm rules:check`. Codex reads `AGENTS.md` and `.agents/skills`; Claude Code reads
89
- `CLAUDE.md` and `.claude/skills`. Keep generated copies synchronized. `.ai/agents`
90
- contains reusable role instructions; `.ai/blueprints` and `.ai/policies` are
91
- project-local inputs referenced by `flowdular.json`.
87
+ Edit `.ai/rules`, `.ai/skills` and `.ai/subagents`, then run `pnpm rules:generate`
88
+ and `pnpm rules:check`. Codex reads `AGENTS.md`, `.agents/skills` and
89
+ `.codex/agents`; Claude Code reads `CLAUDE.md`, `.claude/skills` and
90
+ `.claude/agents`. Keep generated copies synchronized. `.ai/agents` contains
91
+ reusable role instructions, and `.ai/subagents` exposes the root roles as
92
+ delegable subagents; `.ai/blueprints` and `.ai/policies` are project-local inputs
93
+ referenced by `flowdular.json`.
92
94
 
93
95
  Split a skill when it contains independent procedures with different owning
94
96
  files, write scopes or verification commands. Keep shared requirements in the
@@ -8,7 +8,11 @@ Read this file before writing or implementing a spec. It replaces scanning `modu
8
8
 
9
9
  **Tenant identity.** Every request carries a principal resolved by `modules/auth`. `principalFromContext(octane)!.tenantId` is the only tenant authority; a tenant id from a body, query or header is a defect. Row-level security binds the same id inside the transaction.
10
10
 
11
- **Authorization.** `defineEndpoint` (`packages/server/src/endpoint.ts`) takes `id`, `path`, `methods`, `handler` and `access`. `access` is either `{ kind: 'public' }` or `{ kind: 'permission', permission }` with `resolveIdentity: endpointIdentityFromContext`. A protected endpoint answers 401 `UNAUTHENTICATED` without an identity and 403 `FORBIDDEN` without the permission. Permission ids match `^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$` and are declared in the spec `permissions`, in `src/acl/permissions.ts` and on the endpoint. CSRF and input bounds are not endpoint options: mutations call `sessionMutationDenial(octane, auth)` first (`modules/auth/src/server/session-security.ts`) and parse the body through `readJsonObject`, `requiredString`, `optionalString`, `requiredInteger` (`packages/server/src/http.ts`, 415 without JSON, 413 over 16 KB).
11
+ **Authorization.** `defineEndpoint` (`packages/server/src/endpoint.ts`) takes `id`, `path`, `methods`, `handler` and `access`. `access` is either `{ kind: 'public' }` or `{ kind: 'permission', permission }` with `resolveIdentity: endpointIdentityFromContext`. A protected endpoint answers 401 `UNAUTHENTICATED` without an identity and 403 `FORBIDDEN` without the permission. Permission ids match `^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$` and are declared in the spec `permissions`, in `src/acl/permissions.ts` and on the endpoint. CSRF and input bounds are not endpoint options: mutations call `sessionMutationDenial(octane, auth)` first (`modules/auth/src/server/session-security.ts`) and parse the body through `readJsonObject`, `requiredString`, `optionalString`, `requiredInteger` (`packages/server/src/http.ts`, 415 without JSON, 413 over 16 KB). That same guard is what admits a machine caller: it passes a browser session with a same origin and a valid CSRF token, or an API token the workspace issued with writes allowed, and answers 403 `TOKEN_MUTATION_DENIED` to a token issued without them. A mutation that shapes who may reach the workspace calls `browserSessionMutationDenial` instead, which refuses every token; auth.core's own routes are the ones that do.
12
+
13
+ **External API.** Every endpoint records itself in the process endpoint catalogue as it is defined (`packages/server/src/endpoint-catalog.ts`), so a module is described without declaring anything twice. `defineEndpoint` takes an optional `documentation` with `summary`, `description`, `parameters`, `body` and `responses`, validated at definition time and bounded (160-character summary, 32 parameters, 16 responses, 16 KB per JSON Schema); an endpoint that declares none is still described by its address, its methods and the permission it demands. `GET /api/openapi.json` (`platform/src/server/openapi.ts`) answers OpenAPI 3.1 built for the presented credential: it needs a browser session or an API token, and leaves out every operation whose permission the caller does not hold and every operation of a module inactive in its workspace. Each operation carries `x-flowdular-module`, `x-flowdular-permission` and `x-flowdular-token-write`. The Administration screen `system.core` API lists the same document. A module adds nothing to be included; it is in the document as soon as it composes.
14
+
15
+ **API tokens and cross-origin access.** A workspace owner issues a token in Administration, API tokens, with the scopes it may use, an optional expiry, whether it may write, and the browser origins it may be presented from (`modules/auth/src/server/token-endpoints.ts`). Its authority is the intersection of its recorded scopes with the live membership at every request. Writes are off unless the owner asked; a token that names no origin is refused from every browser origin and is meant for a server-side caller; a token that names some is refused from anywhere else with 403 `TOKEN_ORIGIN_DENIED`. A cross-origin preflight carries no credential, so `createCorsMiddleware` (`packages/server/src/cors.ts`, composed in `platform/octane.config.ts`) answers it from the union of the origins the deployment's live tokens declare, and never sends `access-control-allow-credentials`, so no cross-origin page can read an API response with the dashboard's session cookie. A token also carries the requests per minute it may spend, and one issued with none spends the platform setting `auth.core.apiTokenRateLimit` (default 600, 0 removes the ceiling); the request over it is answered 429 `TOKEN_RATE_LIMITED` with `retry-after`, every answer to a limited token carries `x-ratelimit-limit`, `-remaining` and `-reset`, and every request a token made, refused ones included, plus the refused subset, are counted as auth.core module metrics on `/api/metrics`. The window is a fixed minute per token in each process (`modules/auth/src/middleware/rate-limit.ts`), bounded to 4096 credentials, so it guards against one integration running away rather than accounting for usage. Nothing here is an environment variable; issuing or revoking a token, or changing the setting, takes effect live.
12
16
 
13
17
  **Record policies.** A permission answers who may act on a kind of record; a policy answers whether this record allows it. `definePolicy` (`packages/kernel/src/acl.ts`) declares `{ id, permission, evaluate }`, where `evaluate({ principal, permission, record, action })` returns `{ allowed: true }` or `{ allowed: false, reason, requiresApproval? }`; `requiresApproval.requirement` carries `roleKey`, `scope`, `decisions` and `expiresInDays`, and nothing more: resolving a role to people, collecting their decisions and keeping the receipt belong to `approvals.core`, described below. Policies are registered into a `createPolicyRegistry()` while the module composes, at most 256, one registration per id, and the registry is sealed before requests run. An endpoint calls `authorizeRecord(registry, principal, permission, record, action?)`, which checks the permission scope first and then the policies of that permission in registration order, answering the first denial. A permission with no policy is allowed by the scope alone, and a policy that throws denies. The platform does not hand a module a shared registry yet, so a module that wants record conditions today owns its registry inside its own composition.
14
18
 
@@ -22,7 +26,9 @@ Read this file before writing or implementing a spec. It replaces scanning `modu
22
26
 
23
27
  **Module settings.** `defineModuleSettings` (`packages/kernel/src/module-settings.ts`) declares `{ moduleId, settings }`. A setting has `type: 'string' | 'number' | 'boolean'`, `defaultValue`, `visibility: 'private' | 'shared'`, `client: boolean`, and optionally `kind: 'flag'`, `scope: 'platform' | 'tenant'`, `secret`, `labelKey`, `descriptionKey`, `label`, `description`, `enum` (string type only), `min`, `max`, `pattern`, `multiline`. Keys match `^[a-z][a-zA-Z0-9]*$`. The allowed-values field is `enum`, not `values`. A `secret` setting can be neither `client: true` nor `visibility: 'shared'`. Values are read live with `context.settings.get(tenantId, moduleId, key)` and edited in Administration, Modules behind `system.settings.read` and `system.settings.manage` (`GET /api/settings`, `POST /api/settings/update`, `modules/system/src/server/endpoints.ts`). A read needs the tenant primed first (`await context.settings.prime(tenantId)`): the authenticated request path and the platform composition prime, a background path primes itself, and `set` is awaited.
24
28
 
25
- **Feature flags.** A flag is a module setting declared `kind: 'flag'`: a non-secret `boolean` with a `defaultValue`, a `label`, a `description` and `scope: 'tenant'`, which is the default and the only scope a flag may take; `defineModuleSettings` refuses anything else, a platform-scoped flag included. There is no flag store, no flag endpoint and no flag registry. A module reads one on the request path with the ordinary settings read, `context.settings.get<boolean>(tenantId, moduleId, key)`: a lookup of the declaration, a lookup of the cached per `(tenant, module)` value set under a key the read builds, the touch that keeps that entry at the head of the cache, the property read and one `typeof` check. No query of its own, and nothing beyond what any setting already costs: a declared `pattern` is compiled once with the declaration, never per read. There is deliberately no `context.flags`; the read is the settings read, and the module id is the one the module already knows. An override is per workspace behind `system.settings.manage` on the Flags tab of Administration, Modules, which groups every declared flag by its owning module and links the audit trail. Every change appends one `settings.flag.changed` auth audit event with the module, the key, the previous and next values and the actor (`settings.updated` stays the event for every other setting). No percentage rollout and no targeting: a flag is on or off for a workspace.
29
+ **Feature flags.** A flag is a module setting declared `kind: 'flag'`: a non-secret `boolean` with a `defaultValue`, a `label`, a `description` and `scope: 'tenant'`, which is the default and the only scope a flag may take; `defineModuleSettings` refuses anything else, a platform-scoped flag included. There is no flag store, no flag endpoint and no flag registry. A module reads one on the request path with the ordinary settings read, `context.settings.get<boolean>(tenantId, moduleId, key)`: a lookup of the declaration, a lookup of the cached per `(tenant, module)` value set under a key the read builds, the touch that keeps that entry at the head of the cache, the property read and one `typeof` check. No query of its own, and nothing beyond what any setting already costs: a declared `pattern` is compiled once with the declaration, never per read. There is deliberately no `context.flags`; the read is the settings read, and the module id is the one the module already knows. An override is per workspace behind `system.settings.manage` on the Flags tab of Administration, Modules, which groups every declared flag by its owning module and links the audit trail. Every change appends one `settings.flag.changed` auth audit event with the module, the key, the previous and next values and the actor (`settings.updated` stays the event for every other setting). No percentage rollout and no targeting: a flag is on or off for a workspace. A specification declares one as a `settings[]` entry with `kind: flag`, which `spec validate` holds to boolean, `scope: tenant` and a stated default; `research.core` ships the first one, `allowAgents`.
30
+
31
+ **Branding.** The identity one deployment is served with is seven platform-scoped `system.core` settings (`appName`, `documentTitle`, `description`, `ogImageUrl`, `faviconUrl`, `themeColor`, `logoUrl`, `modules/system/src/settings.ts`), edited by a principal with `system.settings.manage` on the Administration screen `branding` and audited like any other setting. They are one value for the whole installation, because the sign-in screen and a shared link are rendered before a workspace is known. The application route resolves them once per request through the provider `system.core` installs with `installApplicationBranding` (`packages/server/src/application-branding.ts`), hands the server render page state and the browser one JSON data block, and the client reads both with `configureBrandingFromPage` plus `applicationBranding` (`packages/client/src/branding.ts`); the shell wordmark, the mobile header, the sign-in screen, the boot splash, the document title, the description, the icon, the theme colour, the social image and the label an authenticator lists a TOTP enrolment under all come from that one read, so no module fetches branding and nothing disagrees. Every value is bounded by its declaration: a name carries no markup or quote, an address is a same-origin absolute path or an https URL (`javascript:`, `data:` and protocol-relative values are refused at the write), a colour is six hex digits, and a stored value that no longer fits falls back to the product's own. Every https branding image origin an operator stores is added to `img-src` of the content security policy for that deployment, so the icon, the logo and the screen's own preview load. A logo is an address, never an upload, and there is no per-workspace branding, no colour theme and no custom CSS. An application whose own entry predates this and renders none of it, or still declares a static icon or theme colour beside the rendered one, is reported by `pnpm flowdular doctor` as the `platform.branding` check.
26
32
 
27
33
  **Module activation.** The composed module set is CLI-owned and baked at build; what an owner changes from Administration, Modules is per-workspace activation of the modules the application already composes. `system.core` keeps it in `system_module_activations` (a composed module without a row is active), lists it through `GET /api/system/modules` (every catalog row with `active`, `optional` and `dependents`) and `GET /api/system/modules/active` (the active composed ids, for any member holding `system.workspace.access`), and changes it through `POST /api/system/modules/activate` and `/api/system/modules/deactivate` behind `system.settings.manage` with CSRF first. `system.core`, `auth.core`, `users.core` and `profile.core` (`REQUIRED_MODULE_IDS` in `@flowdular/sdk/contracts`) are never deactivated; a module another active module depends on, through a declared module dependency or a required capability, is refused with 409 `MODULE_HAS_ACTIVE_DEPENDENTS` naming the dependents, a required one with 409 `MODULE_REQUIRED`, and activating a module whose dependency is inactive with 409 `MODULE_DEPENDENCY_INACTIVE`. Every change appends one `system.module.activated` or `system.module.deactivated` auth audit event. The state is one per-tenant snapshot memoised for 30 seconds and published as the public capability `system.modules.v1` (`isActive(tenantId, moduleId)`, `activeIds(tenantId)`, `modules/system/src/server/capability.ts`). Enforcement costs a module nothing: the generated composition binds every route to its module id (`bindModuleCompositions`, `packages/server/src/module-activation.ts`), `defineEndpoint` answers 403 `MODULE_INACTIVE` after the permission check for an endpoint of an inactive module in the principal's workspace (`EndpointIdentity.tenantId` comes from `endpointIdentityFromContext`), and the application shell reads the active ids before it renders and hides the navigation, views, widgets and command search of an inactive module (`contributionsForActiveModules`, `packages/client/src/shell/modules.ts`; a failed read shows everything). Not covered yet: the agent tools of an inactive module are still offered, because the harness registry has no per-tenant module hook.
28
34
 
@@ -56,13 +62,13 @@ Read this file before writing or implementing a spec. It replaces scanning `modu
56
62
 
57
63
  **Translations.** The shipped locales are `en` and `pl`. A module keeps a flat bundle per locale in `translations/<locale>.json`, imports them in `src/client/contribution.tsrx` and returns `translations: { en, pl }`. Keys resolve fully qualified as `<first module segment>.<key>` through `t()`. A count is a plural family (`<key>.one`/`.other` in `en`, `<key>.one`/`.few`/`.many`/`.other` in `pl`) read as `t(key, { count })`. `flowdular module validate` reports `TRANSLATION_FILE_MISSING`, `TRANSLATION_PARSE_ERROR`, `TRANSLATION_KEYS_MISMATCH`, `TRANSLATION_PLURAL_INCOMPLETE` and `TRANSLATION_KEY_MISSING`.
58
64
 
59
- **Web surfaces.** A module may own public, server-rendered website pages separate from the authenticated shell (`packages/server/src/web.ts`). `defineWebSurface` declares `{ id, pages }` with at most 128 pages; a page has `id`, `path`, `entry`, optional `layout`, a `load` function and `access`, which is one of `{ kind: 'public' }`, `{ kind: 'authenticated' }` or `{ kind: 'permission', permission }`. The operator, not the module, mounts a surface at a tenant-scoped path; `setup`, `health`, `ready`, `assets`, `app`, `api`, `auth`, `sign-in`, `sign-up`, `forgot-password`, `reset-password` and `accept-invitation` are reserved.
65
+ **Web surfaces.** A module may own public, server-rendered website pages separate from the authenticated shell (`packages/server/src/web.ts`). `defineWebSurface` declares `{ id, pages }` with at most 128 pages; a page has `id`, `path`, `entry`, optional `layout`, a `load` function and `access`, which is one of `{ kind: 'public' }`, `{ kind: 'authenticated' }` or `{ kind: 'permission', permission }`. The operator, not the module, mounts a surface at a tenant-scoped path with `pnpm flowdular web mount <module id> <surface id> --path <path> --tenant <id> --apply`, which writes `flowdular.json` and regenerates the composition (`web list` and `web unmount <mount id>` are its siblings); `setup`, `health`, `ready`, `assets`, `app`, `api`, `auth`, `sign-in`, `sign-up`, `forgot-password`, `reset-password` and `accept-invitation` are reserved (`RESERVED_WEB_SEGMENTS` in `@flowdular/sdk/contracts`), and a mount naming a surface its module does not declare stops the composition rather than answering 404.
60
66
 
61
67
  **Public capabilities registry.** Cross-module access goes through `context.capabilities.register(id, value)` in the owning module and `context.capabilities.get<T>(id)` in the consumer (`packages/kernel/src/capability-registry.ts`). The owning module lists the id under `provides` in `module.json`; the consumer lists it under `requires` (`{ "id", "optional": true }` when it handles a null `get`). The composition gives each module a registry view that accepts only its declared ids, the kernel orders required providers first and refuses a missing provider, and the installer resolves a required capability to a release that provides it. A type import from the provider's package still needs the module and package dependency (`"range": "^0.11.0"`). A module never opens another module's database or imports its `src/` path.
62
68
 
63
69
  **Notifications.** `notifications.core` (optional, enabled by default) owns a per-member in-app inbox with preferences, per-tenant outbound webhook subscriptions signed with the inbound automations scheme, and e-mail delivery of inbox items, all three sharing one delivery ledger with bounded retry and a dead letter. A module publishes through the public capability `notifications.publish.v1` obtained lazily with `context.capabilities.get` and tolerates its absence; the input is `{ tenantId, kind, sourceModule, sourceRef, title, body?, recipients }` with the kinds `agent-run-completed`, `agent-run-failed`, `workflow-run-completed`, `workflow-run-failed`, `webhook-dead-letter` (`modules/notifications/src/domain/publish.ts`). A new kind is a `notifications.core` spec edit, not a publisher's decision. A publisher never chooses a channel: the member does, with the per-kind switch that decides whether an item exists at all and the `emailDelivery` switch (off by default) that also mails the items they receive, through the platform mail port and the address `auth.core` holds. `ToastHost` and `toasts` remain the in-screen confirmation for what the reader just did.
64
70
 
65
- **Mail.** A module sends through `context.mail` (`packages/server/src/mail/`) and never selects a transport, a relay or a provider SDK. `send({ to, subject, text, html?, locale?, headers? })` takes at most 16 recipients, a 200 character single-line subject, 64 KB of text, 256 KB of HTML and 16 extra headers whose names the envelope does not own; CR and LF are refused everywhere a header could be opened, so header injection is the port's problem and not each sender's. It rejects with a `MailError` carrying `MAIL_NOT_CONFIGURED` (no transport composed), `MAIL_MESSAGE_REJECTED` (a bound) or `MAIL_DELIVERY_FAILED` (the relay, whose words never travel with it); `mail.configured` is the flag a feature gates on instead of provoking a refusal. `renderMailTemplate({ subject, text, html? }, values)` fills `{{ name }}` holes in one pass and escapes every value for the HTML part. The deployment picks the adapter with `FD_MAIL_TRANSPORT`: `none` (refuses), `development` (an in-memory outbox of the last 100 messages, refused in production) or `smtp` (`FD_MAIL_SMTP_URL`, `FD_MAIL_FROM`; the retired `FD_AUTH_MAIL_*` names still work with a deprecation line). `auth.core` sends invitations, resets and confirmations through it, `notifications.core` mails inbox items; a module that wants to reach a person publishes a notification rather than composing mail of its own.
71
+ **Mail.** A module sends through `context.mail` (`packages/server/src/mail/`) and never selects a transport, a relay or a provider SDK. `send({ to, subject, text, html?, locale?, headers? })` takes at most 16 recipients, a 200 character single-line subject, 64 KB of text, 256 KB of HTML and 16 extra headers whose names the envelope does not own; CR and LF are refused everywhere a header could be opened, so header injection is the port's problem and not each sender's. It rejects with a `MailError` carrying `MAIL_NOT_CONFIGURED` (no transport composed), `MAIL_MESSAGE_REJECTED` (a bound) or `MAIL_DELIVERY_FAILED` (the relay, whose words never travel with it); `mail.configured` is the flag a feature gates on instead of provoking a refusal. `renderMailTemplate({ subject, text, html? }, values)` fills `{{ name }}` holes in one pass and escapes every value for the HTML part. The deployment picks the adapter with `FD_MAIL_TRANSPORT`: `none` (refuses), `development` (an in-memory outbox of the last 100 messages, refused in production) or `smtp` (`FD_MAIL_SMTP_URL`, `FD_MAIL_FROM`; the retired `FD_AUTH_MAIL_*` names still work with a deprecation line). An installation may instead store the relay in the platform-scoped `auth.core` settings `mailTransport`, `mailSmtpUrl` (secret), `mailFrom`, `mailRequireTls` and `mailRejectUnauthorized`; a stored transport of `none` or `smtp` wins over the environment for every sender and is resolved per message, while the default `environment` leaves `FD_MAIL_*` in effect and is the only way to reach the development adapter. `auth.core` sends invitations, resets and confirmations through it, `notifications.core` mails inbox items; a module that wants to reach a person publishes a notification rather than composing mail of its own.
66
72
 
67
73
  **Object storage.** A module writes files through `context.storage` (`packages/storage/src/index.ts`) and never sees an adapter, a bucket or a path. `put`, `get`, `delete`, `stat` and `readUrl` take `{ tenantId, moduleId, objectId }`; the key is `<tenantId>/<moduleId>/<objectId>` and the tenant id comes from the principal, never from the request, because no row-level security reaches an object store. Development and test use a local directory, a deployment uses an S3-compatible bucket (`FD_STORAGE_ADAPTER=local|s3`, `local` refused in production). Every object is encrypted with AES-256-GCM under `FD_STORAGE_ENCRYPTION_KEY` before it is written, with the key id and the metadata authenticated alongside it. An object is at most 25 MB (`FD_STORAGE_MAX_OBJECT_BYTES`) and must be one of PDF, PNG, JPEG, GIF, WebP, plain text, CSV, `.docx`, `.xlsx`, `.pptx`, `application/msword` or `application/vnd.ms-excel`, verified against the bytes; archives and executables are refused. A malware scanner is a deployment seam, so the stored verdict is `clean`, `infected` (refused) or `unscanned` (the default). `readUrl` returns `/api/storage/objects/<token>`, a signed platform route that expires in at most an hour and streams the decrypted body as an attachment, never a presigned URL to the ciphertext. Upload, metadata and the attachment table belong to `documents.core`, described next; a module never puts bytes of its own through `context.storage` when a document fits.
68
74
 
@@ -104,6 +104,7 @@ commandsWithoutDescriptor:
104
104
  - pnpm flowdular capability list|describe <id>|run <id>
105
105
  - pnpm flowdular blueprint list
106
106
  - pnpm flowdular module list
107
+ - pnpm flowdular web list
107
108
  - pnpm flowdular module sync [--apply]
108
109
  - pnpm flowdular module enable <id> [--apply] (with --apply also runs auth.scopes.sync; result field scopes, failure code MODULE_SCOPES_SYNC_FAILED)
109
110
  - pnpm flowdular module disable <id> [--apply]
@@ -33,7 +33,7 @@ sandbox:
33
33
  messageLength: 1 to 20000 characters (packages/sandbox/src/server/turns.ts)
34
34
  briefLength: at least 8 characters (planning.ts assertBrief)
35
35
  gateTimeout: 5 minutes per gate, output capped at 12000 characters (gates.ts)
36
- gateFailure: the same role repairs; no automatic limit on repair turns
36
+ gateFailure: the same role repairs; at most maxRepairLoops consecutive repair turns per chain, then the chain returns to the operator
37
37
  byokReads: 400 listed files, 128 KB per read (packages/coding-agent/src/drivers/byok.ts)
38
38
  review:
39
39
  chainedTurns: stop and read the transcript after four automatic handoffs on one brief
@@ -87,5 +87,6 @@ made in the Flowdular repository and released before this application uses it.
87
87
  The skills and examples use @flowdular/sdk subpath imports. For pnpm --filter,
88
88
  read the actual module package name from its package.json. Use pnpm verify and
89
89
  pnpm build for this application. Root .ai files are editable project guidance;
90
- run pnpm rules:generate after changing rules or skills, then pnpm rules:check.
91
- AGENTS.md, CLAUDE.md, .agents/skills and .claude/skills are generated copies.
90
+ run pnpm rules:generate after changing rules, skills or subagents, then pnpm
91
+ rules:check. AGENTS.md, CLAUDE.md, .agents/skills, .claude/skills, .claude/agents
92
+ and .codex/agents are generated copies.
@@ -80,7 +80,7 @@ Report each finding as: severity (`blocker`, `should-fix`, `taste`), claim, `fil
80
80
  ```text
81
81
  blocker Tenant id read from body modules/inventory/src/api/endpoints.ts:41
82
82
  A member of tenant A posts { tenantId: "B" } and creates a location in B.
83
- AGENTS.md 6. Fix: principalFromContext(octane)!.tenantId; drop the field.
83
+ AGENTS.md 4. Fix: principalFromContext(octane)!.tenantId; drop the field.
84
84
  ```
85
85
 
86
86
  ## 8. Known platform gaps to keep in mind (not module defects)
@@ -35,7 +35,7 @@ when: A report, failing gate, wrong status code, blank screen, or unexpected 4xx
35
35
  | View falls back to the dashboard | `ApplicationShell.tsrx` renders `overview` for a view id that no visible navigation or account menu entry reaches |
36
36
  | Icon renders as a grid | `glyph` or `Icon name` is not an `ICON_PATHS` key (`packages/ui/src/icons/Icon.tsrx` falls back to `modules`) |
37
37
  | Stale data after a change | each component owns a store instance (`useMemo(() => createXClientState(), [])`); check the `store.act` that should have written it. `store.commits(cb)` and `store.stats()` from `segment-state` show what was committed |
38
- | Schema error on start | `runModuleMigrations`: `CHECKSUM_MISMATCH` means applied SQL bytes changed; `PARTIAL_OBJECTS` means only part of a pending migration exists. Never delete or bypass the database to hide either condition; restore the shipped bytes or diagnose the partial schema |
38
+ | Schema error on start | `runDatabaseMigrations`: `CHECKSUM_MISMATCH` means applied SQL bytes changed; `PARTIAL_MIGRATION` means only part of a pending migration exists. Never delete or bypass the database to hide either condition; restore the shipped bytes or diagnose the partial schema |
39
39
 
40
40
  ## 2b. Reproduction snippets
41
41