@owlmeans/server-planning 0.1.18-rc.34 → 0.1.18-rc.36

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 (44) hide show
  1. package/README.md +2 -2
  2. package/agent-meta/manifest.json +105 -4
  3. package/agent-meta/skills/server-planning/SKILL.md +12 -278
  4. package/agent-meta/skills/server-planning/parts/auxiliary.md +52 -0
  5. package/agent-meta/skills/server-planning/parts/executor.md +82 -0
  6. package/agent-meta/skills/server-planning/parts/schemas.md +26 -0
  7. package/agent-meta/skills/server-planning/parts/serving.md +88 -0
  8. package/agent-meta/skills/server-planning/parts/stores.md +84 -0
  9. package/build/conformance/cases.d.ts.map +1 -1
  10. package/build/conformance/cases.js +46 -2
  11. package/build/conformance/cases.js.map +1 -1
  12. package/build/conformance/consts.d.ts +5 -0
  13. package/build/conformance/consts.d.ts.map +1 -1
  14. package/build/conformance/consts.js +15 -0
  15. package/build/conformance/consts.js.map +1 -1
  16. package/build/definitions.d.ts +2 -1
  17. package/build/definitions.d.ts.map +1 -1
  18. package/build/definitions.js +5 -3
  19. package/build/definitions.js.map +1 -1
  20. package/build/registry.d.ts +3 -1
  21. package/build/registry.d.ts.map +1 -1
  22. package/build/registry.js +12 -9
  23. package/build/registry.js.map +1 -1
  24. package/build/types.d.ts +13 -3
  25. package/build/types.d.ts.map +1 -1
  26. package/package.json +18 -18
  27. package/src/conformance/cases.ts +52 -2
  28. package/src/conformance/consts.ts +16 -0
  29. package/src/definitions.ts +5 -3
  30. package/src/registry.ts +13 -8
  31. package/src/types.ts +13 -4
  32. package/tests/app.spec.ts +112 -0
  33. package/build/actions/cards.d.ts +0 -16
  34. package/build/actions/cards.d.ts.map +0 -1
  35. package/build/actions/cards.js +0 -32
  36. package/build/actions/cards.js.map +0 -1
  37. package/build/actions/schemas.d.ts +0 -30
  38. package/build/actions/schemas.d.ts.map +0 -1
  39. package/build/actions/schemas.js +0 -69
  40. package/build/actions/schemas.js.map +0 -1
  41. package/build/actions/specs.d.ts +0 -10
  42. package/build/actions/specs.d.ts.map +0 -1
  43. package/build/actions/specs.js +0 -14
  44. package/build/actions/specs.js.map +0 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@ the `@owlmeans/server-planning/store` subpath.
10
10
  ## Installation
11
11
 
12
12
  ```sh
13
- bun add @owlmeans/server-planning@^0.1.18-rc.34 @owlmeans/planning@^0.1.18-rc.28 ajv
13
+ bun add @owlmeans/server-planning@^0.1.18-rc.36 @owlmeans/planning@^0.1.18-rc.30 ajv
14
14
  ```
15
15
 
16
16
  ## Concepts
@@ -214,7 +214,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
214
214
  your project's skill store (`.agents/skills/`):
215
215
 
216
216
  ```sh
217
- npx @owlmeans/agent-skills@^0.1.18-rc.56
217
+ npx @owlmeans/agent-skills@^0.1.18-rc.57
218
218
  ```
219
219
 
220
220
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
- "schemaVersion": 2,
2
+ "schemaVersion": 3,
3
3
  "package": "@owlmeans/server-planning",
4
- "version": "0.1.18-rc.34",
5
- "generatedAt": "2026-10-17T00:00:32.694Z",
4
+ "version": "0.1.18-rc.36",
5
+ "generatedAt": "2026-10-24T21:07:16.895Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -10,7 +10,108 @@
10
10
  "name": "server-planning",
11
11
  "category": "package-specific",
12
12
  "file": "skills/server-planning/SKILL.md",
13
- "canonicalPath": ".agents/skills/server-planning/SKILL.md"
13
+ "canonicalPath": ".agents/skills/server-planning/SKILL.md",
14
+ "parts": [
15
+ {
16
+ "name": "auxiliary",
17
+ "file": "skills/server-planning/parts/auxiliary.md",
18
+ "description": "Assignees, teams, comments and mentions on native store ports, the reply projection, hierarchy admission and project purge.",
19
+ "purposes": [
20
+ "planning",
21
+ "data"
22
+ ],
23
+ "mentions": [
24
+ "facade.assignees",
25
+ "facade.teams",
26
+ "facade.comments",
27
+ "facade.mentions",
28
+ "manageAssignees",
29
+ "manageTeams",
30
+ "defaultAssigneeId",
31
+ "makePlanningAuth",
32
+ "guardHelper.reply"
33
+ ]
34
+ },
35
+ {
36
+ "name": "executor",
37
+ "file": "skills/server-planning/parts/executor.md",
38
+ "description": "The transition executor step by step (refusal order, actor and createdBy stamping) and the plugin seam (registration, order, store routing, before/after hooks).",
39
+ "purposes": [
40
+ "planning",
41
+ "server-api"
42
+ ],
43
+ "mentions": [
44
+ "executeTransition",
45
+ "creatorHelper",
46
+ "makePluginRegistry",
47
+ "ensurePlanningService",
48
+ "PlanningRefused",
49
+ "mintCode",
50
+ "WorkcardConflict"
51
+ ]
52
+ },
53
+ {
54
+ "name": "schemas",
55
+ "file": "skills/server-planning/parts/schemas.md",
56
+ "description": "Data-defined card types and flows — the resolved layer per organization and project, the facade's definitions, retiring a flow.",
57
+ "purposes": [
58
+ "data",
59
+ "planning",
60
+ "config"
61
+ ],
62
+ "mentions": [
63
+ "makeDefinitions",
64
+ "makeSchemaViews",
65
+ "schemasFor",
66
+ "scopedSchemaHelper",
67
+ "definitions",
68
+ "SchemaInUse"
69
+ ]
70
+ },
71
+ {
72
+ "name": "serving",
73
+ "file": "skills/server-planning/parts/serving.md",
74
+ "description": "The commit feed, request scope and security, the access resolver (projects, writes, grants), and mounting the handlers in a target.",
75
+ "purposes": [
76
+ "server-api",
77
+ "auth",
78
+ "planning"
79
+ ],
80
+ "mentions": [
81
+ "servePlanningEntrypoints",
82
+ "planningHandlerOf",
83
+ "PlanningAccessResolver",
84
+ "makeRequestScope",
85
+ "makePlanningAccessModel",
86
+ "guardHelper",
87
+ "executionHelper",
88
+ "PlanningForbidden"
89
+ ]
90
+ },
91
+ {
92
+ "name": "stores",
93
+ "file": "skills/server-planning/parts/stores.md",
94
+ "description": "The in-memory store, writing a durable or foreign store (ports, foldHelper.foldPending, the commit hub, the conformance suite), and testing against the memory store.",
95
+ "purposes": [
96
+ "data",
97
+ "planning",
98
+ "test"
99
+ ],
100
+ "mentions": [
101
+ "makeMemoryPlanningStore",
102
+ "PlanningStore",
103
+ "foldHelper",
104
+ "makeCommitHub",
105
+ "makeCompositeStore",
106
+ "planningConformance",
107
+ "conformanceCasesFor",
108
+ "planningConformancePlugin",
109
+ "makeProjectionProcessor",
110
+ "@owlmeans/server-planning/store",
111
+ "@owlmeans/server-planning/conformance"
112
+ ]
113
+ }
114
+ ]
14
115
  }
15
116
  ]
16
117
  }
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/server-planning
9
9
 
10
10
  **Layer:** Server
11
- **Install:** `"@owlmeans/server-planning": "^0.1.18-rc.34"` in `dependencies` (`ajv` is a peer)
11
+ **Install:** `"@owlmeans/server-planning": "^0.1.18-rc.36"` in `dependencies` (`ajv` is a peer)
12
12
 
13
13
  The general implementation of `@owlmeans/planning`: the planning service (a plugin host), the
14
14
  scoped facade, the executor every write goes through, the in-memory reference store, the commit
@@ -22,7 +22,7 @@ reuses the `./store` subpath (`foldHelper.foldPending`, `makeCommitHub`) without
22
22
  | `appendPlanningService(ctx, opts?, alias?)` | Registers the lazy host service and `ctx.planning()` |
23
23
  | `ensurePlanningService(ctx, alias?)` | Idempotent — what a plugin package calls before `use` |
24
24
  | `makePlanningService(opts?, alias?)`, `planningServiceApi(opts, self)` | The service, and its body for a specialised service |
25
- | `PlanningServiceOptions` | `{ store?, plugins?, schemas?, hooks?, ids?, now? }` |
25
+ | `PlanningServiceOptions` | `{ store?, plugins?, schemas?, hooks?, ids?, now? }` — `schemas.app` is the first source the plugins' `schemas.app` merge over |
26
26
  | `makePluginRegistry`, `makeStoreFacade`, `executeTransition` | The pieces the service is made of |
27
27
  | `creatorHelper` — `.creatorOf(scope)`, `.withCreator(exec, scope)`, `.assertCreatorFixed(exec)` | The subject a create is stamped with as `createdBy`, the defaulting the executor applies, and its refusal of any later move |
28
28
  | `servePlanningEntrypoints(protocols, opts?)` | One binding per protocol of a `makePlanningProtocols` tree (`schema.define` too when declared) |
@@ -119,6 +119,7 @@ await planning.definitions!.define({
119
119
  | `execute({ …, wait: true })` | in process the key is ignored: the receipt returns before the commit, with no `card` — hidden while an inline-folding store (`planning-postgres`) lands at once, exposed the first time another process holds the card's fold | `execute({ … }, { wait: true })` — only the wire body (`ExecuteRequest`) carries `wait` inside |
120
120
  | `ctx.planning().for(…)` in a target | `ctx.planning is not a function` | `ctx.service<PlanningHostService>(PLANNING_SERVICE).for(…)` |
121
121
  | `{ id, name: 'Repair', … }` on a flow, `{ key, name, … }` on a type | `define` refuses with `SchemaInvalid` (closed schemas); a code plugin's registry does not validate, so the key is silently dropped | a flow's key is `id`, a type's is `type`, the display name is `label` on both |
122
+ | `{ …, description: '…' }` on a type or a flow | `SchemaInvalid` (closed schemas) | `app: { description }`, with `schemas.app.type` / `.flow` declaring `description` (`planning` → types part) |
122
123
  | `action: 'create'` | a type error — `TransitionAction` is an enum | `action: TransitionAction.Create` |
123
124
 
124
125
  Every wrong form is a compile error against the typed facade (`PlanningFacade`,
@@ -126,54 +127,6 @@ Every wrong form is a compile error against the typed facade (`PlanningFacade`,
126
127
  typed `any`, so never type one that way. `tests/create-example.spec.ts` runs this example and each
127
128
  wrong form as written.
128
129
 
129
- ## The executor, step by step
130
-
131
- Nothing is appended before step 11 — every refusal leaves the log untouched.
132
-
133
- 1. **Normalize** — deep copy, trimmed text, `parents ∋ parent` (first); a create's draft without
134
- `createdBy` gets `creatorHelper.creatorOf(scope)` (below).
135
- 2. **Scope** — `entityId` must be present.
136
- 3. **Idempotency** — a `key` already in the entity's log answers ITS receipt, before any
137
- validation or middleware.
138
- 4. **Resolve** — the card (`WorkcardNotFound`; another entity's card is `PlanningScopeMismatch`;
139
- one outside the scope's `projects` is `WorkcardNotFound`), its type and flow, every draft parent
140
- (`ParentNotFound` — loaded through the facade, so an invisible parent is absent) and the parent
141
- project's `cardTypes`/`projectTypes` (`CardTypeNotAllowed`), the specification slot. Where the
142
- default store holds data-defined schemas, the card's project is found first and everything
143
- after reads that project's resolved layer (`Resolved.schemas`): a data-defined type of a
144
- project with `scopedCardTypes` is admitted, a retired type creates nothing
145
- (`UnknownWorkcardType('retired:…')`). Without the port `Resolved.schemas` IS the code registry.
146
- 5. **`before` chain** — in plugin order; re-resolved once when it changed the card, type or parent.
147
- 6. **Validate** — shape (`planning:malformed:*`), the flow rule (`IllegalTransition`), immutables
148
- (`planning:immutable:*`, `createdBy` among them — `creatorHelper.assertCreatorFixed`), merged `fields` (`FieldsInvalid`), labels (`LabelNotAllowed`), a moved
149
- parent, the slot (`SpecificationSlotUnknown`, `SpecificationRevisionConflict`, JSON body schema
150
- → `FieldsInvalid`), relationships (`RelationshipRefused`: undeclared type, `from` not the card,
151
- missing target, type constraints, `single`, unlinking an absent edge).
152
- 7. **Card id** — `store.newId?.() ?? options.ids?.() ?? idHelper.uuid()`. Ids are the store's.
153
- 8. **Code** — a supplied code is checked; else the plugins' `mintCode` (first answer wins, checked);
154
- else the type's `CodePolicy` (a slug policy derives from the title) → `CodeTaken`.
155
- 9. **Changes** — `changesHelper.computeChanges`. An `update` that changes nothing answers the card's latest
156
- receipt and appends nothing.
157
- 10. **Seq** — `transitions.nextSeq(card, expectSeq)`, a CAS against `head` (`WorkcardConflict`).
158
- 11. **Append** — `commit: pending`. A lost race on the key answers the winner's receipt.
159
- 12. **Project** — `store.cards.project(card)`: a sync store folds now, a queued one enqueues.
160
- 13. **Receipt** — `{ transition, card? (once committed), committed(opts) }`.
161
- 14. **`wait: true`** — `committed()` before returning (`CommitTimeout`, `CommitFailed`).
162
-
163
- `actor` is the SCOPE's: `profileId`/`userId`/`service`/`channel` come from the scope only; an
164
- in-process caller may add `agent`/`runId` on the execution. A handler never passes a wire `actor`.
165
-
166
- A create's `createdBy` is the scope's subject too — `creatorHelper.creatorOf(scope)`: `profileId`, else `userId`,
167
- else the same two of `scope.actor`. The executor stamps it on every path, so an in-process facade
168
- create and the HTTP `execute` produce the same owner. An in-process draft that names `createdBy`
169
- keeps it (explicit wins — a manager creating on someone's behalf); a scope naming nobody (a service
170
- or system scope) leaves it unset; the wire drops a draft's `createdBy` before the stamp.
171
-
172
- `createdBy` never moves after the create (the rule is `planning` → The record model). The executor
173
- enforces it itself with `creatorHelper.assertCreatorFixed` at step 6, after the `before` chain, so a wire body, an
174
- in-process caller and a plugin are refused alike, whatever `@owlmeans/planning` build the host
175
- resolves. The conformance suite checks a store folds a stored row naming it as the pure fold does.
176
-
177
130
  ## Idempotency and `expectSeq`
178
131
 
179
132
  - Give every retried or replayed write a `key` (`import:<source>:<n>`). The key is unique per entity
@@ -182,231 +135,6 @@ resolves. The conformance suite checks a store folds a stored row naming it as t
182
135
  see the same `seq` but only one wins the head. `null` or omitted opts out; a model fills it from
183
136
  its record.
184
137
 
185
- ## The plugin seam
186
-
187
- | Concern | Rule |
188
- |---|---|
189
- | Registration | `use(plugin)` replaces by `name`; schemas are contributed at `use` time (later type/flow id wins) |
190
- | Order | `order ?? 50` ascending, registration order among equals |
191
- | Store routing | `store(type)` = the first plugin whose `owns(type)` is true AND that supplies a `store`; else the default store. A store factory is resolved once |
192
- | Reads | By id: the default store, then each owned store. A list naming one owned type (or several owned by one store) goes there; any other list — a cross-type query — is the default store's alone |
193
- | `mintCode` | First non-`undefined` answer wins |
194
- | `before` | Every plugin in order; may return a replaced execution; a `ResilientError` passes through, anything else becomes `PlanningRefused('<plugin>:<message>')` |
195
- | `after` | Every plugin in order, once per COMMITTED transition; errors logged, never rethrown |
196
-
197
- **Where `after` runs.** The service's `committed(event)` runs the chain, and it is called by the
198
- process that FOLDS the transition — the memory store inside `project()`, a queued store's projection
199
- job after marking the commit. Never subscribe a process to the commit bus to run hooks: that fires
200
- once per subscribed process. Every process that folds registers the same plugins; each commit is
201
- folded by one of them, so each hook fires once. `hooks: false` makes a process fold without running
202
- them. A hook sees `ctx.transition` (read back, so `actor.channel` is available) and a facade scoped
203
- to the event's entity acting as this process's `cfg.service`.
204
-
205
- The service hands `committed` to a store through `store.bind?.(listener)` the first time it resolves
206
- the store; `bind` replaces the listener, so a store has exactly one.
207
-
208
- ## The memory store
209
-
210
- `makeMemoryPlanningStore({ sync?, ids?, now?, seed?, onCommitted?, alias?, schemas? })`
211
-
212
- - Cards and projects in one map, specifications in their own, relationships in a third; every read
213
- goes through the `@owlmeans/resource` query engine. A card list includes specifications only when
214
- the criteria asks for `kind: specification` or a `category` (`wantsSpecifications`, the rule every
215
- store routes by).
216
- - `schemas: true` adds the data-defined schema port (records per layer, a revision per
217
- organization, synchronous `watch`); off by default — without it every type and flow resolves
218
- from code.
219
- - `sync` (default) folds, publishes and runs `committed` inside `project()`, serialized per card.
220
- `sync: false` folds nothing until `flush(card?)` — a queued store's shape, for tests that need a
221
- commit to stay pending.
222
- - A project `delete` purges the project, everything whose `parents` reach it, their specifications,
223
- links and log; the commit hub remembers the settled event so the waiter still gets its answer.
224
- - **It is wrong for more than one process or a restart** — the log, the cards and the commit feed
225
- are this process's heap. Use it for tests, tools and single-process demos.
226
-
227
- ## Writing a durable store
228
-
229
- - Implement `PlanningStore` (`transitions`, `cards`, `specs`, `links`, `commits`, `newId`). `newId`
230
- answers the id format the host's references need (ObjectId hex for Mongo).
231
- - `transitions.list` treats `sinceSeq` as `seq > sinceSeq`; `nextSeq` is the CAS against `head` and
232
- answers 1 for a card that has no log.
233
- - The projection body is `foldHelper.foldPending(store, cardId, entityId, { onCommitted, publish, touch, limit })`:
234
- it applies pending transitions with `applyHelper.applyTransition` only, marks each committed or failed,
235
- publishes, then runs `onCommitted`. The caller owns single flight per card. Strip `record` from
236
- the event before a cross-process bus.
237
- - **A failed transition never blocks the card.** The fold marks it `failed`, publishes a failed
238
- event, and goes PAST it: the card's `seq` advances to that transition with every other value as
239
- it was, and the next transition folds normally. Without that, every later transition fails as
240
- out of order and the card is stuck for good. Only two cases stop short: a failed `create` leaves
241
- no card to advance, and a store that refuses the advancing write stops the fold with `followUp`,
242
- leaving the rest pending for a retry. `foldHelper.revisionsFromLog` replays past failed transitions the same
243
- way.
244
- - A transactional store passes `FoldOptions.unit` — it wraps each transition's writes (a
245
- savepoint), so a write the database refuses is undone whole and the fold marks that transition
246
- failed and goes past it. `foldHelper.foldPending` folds PAST a failure it produces; a row that is ALREADY
247
- failed at the cursor, or a gap in the seqs, is the store's to step over before calling it
248
- (`planning-postgres` does it in a prelude).
249
- - `foldHelper.failPending` is what a dead projection job must do, or waiters hang to their timeout.
250
- - The data-defined schema port (`schemas`) is optional; `makeCompositeStore` passes the default
251
- store's through. A store that has it must purge a project's layer with the project.
252
- - **Run the conformance suite.** `@owlmeans/server-planning/conformance` exports
253
- `planningConformance` — named cases with no test runner inside (each throws
254
- `ConformanceFailure`) — and `conformanceCasesFor(store)`, which drops the data-defined cases for a
255
- store without the port. Boot a service with `planningConformancePlugin` and `conformanceClock()`
256
- and hand each case `{ service, store, facade }`; every case works in its own organization, so one
257
- boot serves them all.
258
- - `makeCommitHub({ status, remember?, ladder? })` is the `CommitSource`: feed `publish` from the bus,
259
- answer `status` from transition rows. `wait` subscribes first, polls once, then climbs the ladder.
260
- - `foldHelper.revisionsFromLog(transitions, limit?)` answers `specs.revisions`.
261
- - `makeProjectionProcessor(ctx)` + `makePlanningQueueHooks(ctx)` are the store-agnostic job body and
262
- `onJobDead`; a store with an admission CAS wraps its own around them.
263
-
264
- ## A foreign provider
265
-
266
- Only `cards` is required. A plugin that `owns` its types and supplies a store without
267
- `transitions` can be read through the facade; writes to it refuse with `PlanningUnsupported` —
268
- mapping external records (`mappers`) belongs to that plugin's own store adapter.
269
-
270
- ## The commit feed
271
-
272
- - **Poll** — `commit.get` answers the status; with `?wait=<s>` (clamped to `maxPoll`, default 55)
273
- it subscribes, re-polls, and holds until the commit settles or the time is up, answering `pending`
274
- then — never an error.
275
- - **Notify** — `commit.events` pushes `planning-commit` frames (or `opts.event`) filtered by the
276
- authenticated entity and optional `project`/`card` query values; a frame without `record` gets the
277
- card as it reads now. The subscription is released on the socket's `close` frame.
278
- - `execute` with `wait: true` holds at most `maxPoll` seconds whatever `timeout` the body asked for.
279
-
280
- ## Scope and security
281
-
282
- - Without `opts.access`: `entityId` is `makeEntityScope(req).requireEntityKey()`; `opts.scope(req, ctx)` adds a
283
- `channel` or `service` and can never replace the entity. `actor` and a create's `createdBy` come
284
- from the request, never the body (`executionHelper.wireExecution` drops a draft's claim, `creatorHelper.withCreator` stamps the
285
- subject, `creatorHelper.assertCreatorFixed` refuses a body naming `createdBy` — an update never re-owns a card).
286
- - The organization of a scope is the one the request ACTS IN. `makeEntityScope(req).requireEntityKey()` answers
287
- `req.entity.id`, the stable record id (the token's `entitySlug` only where no entity resolver is
288
- registered). Behind an OIDC relying party (`@owlmeans/server-oidc-rp`) the acting organization is
289
- session state: the guard attaches `req.entity` with `id` = the organization claim's frozen
290
- `entityKey`, so the tenant key survives a rename and follows a switch. Take it in the handler and
291
- pass it down; never read it from the context or from a body.
292
- - Another entity's card, specification or transition answers `WorkcardNotFound` — the same as an
293
- absent id — on reads and writes alike (`guardHelper.concealed`).
294
- - Queries arrive in their wire form and are decoded with `wireHelper.decode*Query` before `queryHelper.criteriaOf`, which
295
- always adds the scope's `entityId`.
296
-
297
- ### The access resolver
298
-
299
- `opts.access: (req, ctx) => Promise<{ entityId, projects?, writes?, grants? }>` is the hosting app's
300
- decision per request; a throw is the request's answer (an `AuthForbidden` answers 403).
301
-
302
- - `entityId` is the resolver's — never the token's, never `opts.scope`'s.
303
- - `projects` becomes `PlanningScope.projects`, which the server facade enforces on reads and
304
- writes. A card is visible when at least one project reached through its recursive parent paths
305
- is allowed; specifications follow their containing cards. Anything else reads as absent
306
- (`WorkcardNotFound`, `null`, an empty list); a create under an invisible parent is
307
- `ParentNotFound`. Links, transitions and commits use current endpoint/card ancestry, with a
308
- cached project fallback only for purged records. Subscriptions and commit waits enforce the
309
- same visibility.
310
- - **Narrowed lists, counts and summaries use the allowed recursive descendant IDs before paging.**
311
- A specification is admitted through the same containing-card hierarchy as a single read.
312
- Do not replace this with a direct-parent query or a filter applied after pagination.
313
- `tests/narrowing.spec.ts` and shared hierarchy conformance pin this behavior.
314
- - A person who may see only SOME projects of their organization (a tool-shed volunteer given one
315
- shed) is expressed here: the resolver answers the project ids the person's grants list as
316
- `projects`, and omits the key when a grant covers every project — never a hand-written filter in
317
- each handler.
318
- - `writes` is the subset of projects the person may WRITE in (`projects` are the ones they VIEW).
319
- `execute` on a card, specification or link needs it to be writable — the recursive ancestor
320
- rule over `writes`: a card admitted directly or through a writable parent path. A create needs
321
- every named parent writable; reparenting checks every supplied destination parent. A create at the root
322
- (no parent, not a project) is refused. `schema.define` of a project layer needs the project in
323
- `writes`. A refusal is `PlanningForbidden` (403, `forbidden:writes:<id>`), checked before the grants
324
- and before the executor. NOT governed by it: a project create (`grants.createProjects` alone) and
325
- the organization layer (`grants.defineSchemas`). A card the scope cannot see is still answered
326
- as absent by the executor. Omitted — every visible project is writable.
327
- `tests/writes.spec.ts` pins viewer, writer and omitted.
328
- - `grants` gates the stock handlers' writes: `createProjects` (a project create — `true` for the
329
- root, a list names the parent projects), `deleteProjects` (the delete of a project card — a list
330
- names the projects), `defineSchemas` (`schema.define` — `true` for the organization's layer, a
331
- list names project layers). A `grants` object refuses every flag it leaves out with
332
- `PlanningForbidden` (403); no `grants` gates nothing. In-process facade writes are not gated.
333
-
334
- ## Mounting in a target
335
-
336
- The api half of the target mount (the common tree and the kit literals: `planning` → Mounting in a
337
- target).
338
-
339
- - Bind `servePlanningEntrypoints(tree, { access })` WITHOUT the commit socket —
340
- `.filter(entrypoint => entrypoint.protocol !== tree.commit.events)`: nothing authenticates a
341
- target's socket after it opens, so the client long-polls (`commit.get` with `wait`, `execute`
342
- with `wait: true`). Never write card, transition or schema routes beside it.
343
- - The resolver maps container permissions onto the access: `projects` = the containers the person
344
- may view, `writes` = those they may modify, `grants` = `createProjects` / `deleteProjects` /
345
- `defineSchemas` from their create and admin rights. A creator sees what they created — stamp
346
- ownership in a `before` hook and add the card to both lists.
347
-
348
- ## Data-defined types and flows
349
-
350
- Where the default store has the schema port, `runtime.schemasFor(entityId, project?)` answers the
351
- resolved layer (`scopedSchemaHelper.resolveScopedBundle` over the code bundle and the organization's and project's
352
- records), cached per (organization, project) and keyed by the store's `revision()` and the plugin
353
- registry's version — a write anywhere moves the revision the next lookup reads, so a cached layer is
354
- never stale; a store's `watch` evicts early. Without the port it answers the code registry itself.
355
- `makeDefinitions` gives the facade `definitions`: every write checks the project (a project card the
356
- scope can see), the seal, the closed-form checks (a type's flows resolve in its layer, counting flows
357
- written beside it), then the store's compare-and-set. `retire` of a flow refuses with `SchemaInUse`
358
- while a live type of the layer — or of any project layer, for an organization record — still runs
359
- it. `facade.model(card)` builds over the layer of the card's own project, and `schema.list` answers
360
- the scoped bundle (`?project=`) where `definitions` exists, the code bundle otherwise.
361
-
362
- ## Testing
363
-
364
- Category A. Build one real context with `makeBasicContext` + `appendPlanningService({ store:
365
- makeMemoryPlanningStore({ now }), plugins: [fixtures] })`, and run a handler through
366
- `handler.bind({ ref: { ctx } })(req, res)` with a request carrying `auth` and `entity`. A monotonic
367
- `now` keeps log order deterministic; `sync: false` + `flush()` pins pending and hook-count cases.
368
- `tests/conformance.spec.ts` runs the conformance suite against the memory store with and without
369
- `schemas: true`; a durable store's own tests run the same cases against a real database.
370
-
371
- ## Auxiliary resources and hierarchy admission
372
-
373
- `facade.assignees`, `.teams`, `.comments`, `.mentions` use native versioned ports of
374
- `PlanningStore`. The stock memory, PostgreSQL and Mongo stores implement them. Mutations run
375
- inside the store's organization `unit`; CAS, nickname/authentication uniqueness, schema layers,
376
- canonical links and mentions are validated there. Missing ports raise `PlanningUnsupported`. Assignee type changes recheck incoming typed card
377
- references against the proposed type; a change cannot invalidate a persisted assignment.
378
- Do not add a second host-specific planning resource CRUD layer.
379
-
380
- `assignees.list({ retired: false })` means every identity not explicitly retired, including
381
- records with an absent or null retirement flag. The facade translates it to `{ retired: { $ne: true } }`
382
- before the native port reads; `retired: true` selects historical identities and an omitted filter
383
- retains both. Keep this predicate consistent with client mirrors and run its shared conformance
384
- case against memory, PostgreSQL and Mongo; a bare equality to false hides newly created identities.
385
-
386
- The request scope supplies trusted `assigneeId` for comment authors and optional
387
- `defaultAssigneeId` for newly created cards. HTTP handlers stamp actor/organization context;
388
- `makePlanningAuth(...).scopeFor` resolves OwlMeans identities when that integration is enabled.
389
- Access resolvers can grant `manageAssignees` and `manageTeams` separately from card writes.
390
- Comments and project/team attachment require writable containing cards/projects. Auxiliary
391
- organization lists require authenticated organization scope; do not infer ACLs from project mode.
392
-
393
- All stock HTTP replies use `guardHelper.reply`, which conceals scope failures and applies the
394
- typed planning reply projection. Socket commits use the same projection. Organization `entityId`
395
- stays in native records and verified scopes, and never leaves through records, schema scopes or
396
- nested receipts. Keep business fields and schema definitions unchanged when projecting replies.
397
-
398
- Admission and native projection recheck hierarchy, schema fields and endpoint types. Recursive
399
- visibility follows every project ancestor and filters before paging. Definition record reads
400
- use the same recursive visibility as cards. Reparenting validates all
401
- descendants under the prospective schema layer. Ordinary parent deletion refuses existing
402
- children; project purge removes its descendants, comments, mentions, scoped schemas and links,
403
- while retaining organization assignees and reusable teams. Field-backed edges are reconciled in
404
- the persistence unit; named inverse edges are derived read views, never duplicate persisted rows.
405
-
406
- Run shared conformance with `resources` and `schemas` capabilities against each native provider;
407
- cover version races, stable mentions, reusable teams, field references, hierarchy and narrowed ACLs.
408
-
409
-
410
138
  ## Related
411
139
 
412
140
  - `planning` — records, flows, the fold, the query language, the protocol tree, the models
@@ -415,6 +143,12 @@ cover version races, stable mentions, reusable teams, field references, hierarch
415
143
  - `server-job`, `queue` — the declare/serve/feed pattern and the projection queue
416
144
  - `resource` — the criteria engine every memory read goes through
417
145
 
418
- Project purge uses current card ancestry as ownership. A surviving reparented card retains its
419
- complete transition history, documents and edges even when their cached project id names its former
420
- project. Cached project values may select orphaned records, but must never delete surviving records.
146
+ ## Parts
147
+
148
+ | Part | Load it when |
149
+ |---|---|
150
+ | [executor](parts/executor.md) | writing a planning plugin, or diagnosing why a transition was refused or never committed |
151
+ | [stores](parts/stores.md) | choosing or writing a store, or testing planning code |
152
+ | [serving](parts/serving.md) | binding the planning handlers, writing an access resolver, or narrowing what a person sees or writes |
153
+ | [schemas](parts/schemas.md) | defining or retiring types and flows as data |
154
+ | [auxiliary](parts/auxiliary.md) | working with assignees, teams, comments or mentions, or with reparenting and purge |
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: auxiliary
3
+ description: Assignees, teams, comments and mentions on native store ports, the reply projection, hierarchy admission and project purge.
4
+ metadata:
5
+ purposes: planning, data
6
+ mentions: facade.assignees, facade.teams, facade.comments, facade.mentions, manageAssignees, manageTeams, defaultAssigneeId, makePlanningAuth, guardHelper.reply
7
+ ---
8
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
9
+
10
+ # @owlmeans/server-planning — Auxiliary resources and hierarchy admission
11
+
12
+ ## Auxiliary resources and hierarchy admission
13
+
14
+ `facade.assignees`, `.teams`, `.comments`, `.mentions` use native versioned ports of
15
+ `PlanningStore`. The stock memory, PostgreSQL and Mongo stores implement them. Mutations run
16
+ inside the store's organization `unit`; CAS, nickname/authentication uniqueness, schema layers,
17
+ canonical links and mentions are validated there. Missing ports raise `PlanningUnsupported`. Assignee type changes recheck incoming typed card
18
+ references against the proposed type; a change cannot invalidate a persisted assignment.
19
+ Do not add a second host-specific planning resource CRUD layer.
20
+
21
+ `assignees.list({ retired: false })` means every identity not explicitly retired, including
22
+ records with an absent or null retirement flag. The facade translates it to `{ retired: { $ne: true } }`
23
+ before the native port reads; `retired: true` selects historical identities and an omitted filter
24
+ retains both. Keep this predicate consistent with client mirrors and run its shared conformance
25
+ case against memory, PostgreSQL and Mongo; a bare equality to false hides newly created identities.
26
+
27
+ The request scope supplies trusted `assigneeId` for comment authors and optional
28
+ `defaultAssigneeId` for newly created cards. HTTP handlers stamp actor/organization context;
29
+ `makePlanningAuth(...).scopeFor` resolves OwlMeans identities when that integration is enabled.
30
+ Access resolvers can grant `manageAssignees` and `manageTeams` separately from card writes.
31
+ Comments and project/team attachment require writable containing cards/projects. Auxiliary
32
+ organization lists require authenticated organization scope; do not infer ACLs from project mode.
33
+
34
+ All stock HTTP replies use `guardHelper.reply`, which conceals scope failures and applies the
35
+ typed planning reply projection. Socket commits use the same projection. Organization `entityId`
36
+ stays in native records and verified scopes, and never leaves through records, schema scopes or
37
+ nested receipts. Keep business fields and schema definitions unchanged when projecting replies.
38
+
39
+ Admission and native projection recheck hierarchy, schema fields and endpoint types. Recursive
40
+ visibility follows every project ancestor and filters before paging. Definition record reads
41
+ use the same recursive visibility as cards. Reparenting validates all
42
+ descendants under the prospective schema layer. Ordinary parent deletion refuses existing
43
+ children; project purge removes its descendants, comments, mentions, scoped schemas and links,
44
+ while retaining organization assignees and reusable teams. Field-backed edges are reconciled in
45
+ the persistence unit; named inverse edges are derived read views, never duplicate persisted rows.
46
+
47
+ Run shared conformance with `resources` and `schemas` capabilities against each native provider;
48
+ cover version races, stable mentions, reusable teams, field references, hierarchy and narrowed ACLs.
49
+
50
+ Project purge uses current card ancestry as ownership. A surviving reparented card retains its
51
+ complete transition history, documents and edges even when their cached project id names its former
52
+ project. Cached project values may select orphaned records, but must never delete surviving records.
@@ -0,0 +1,82 @@
1
+ ---
2
+ name: executor
3
+ description: The transition executor step by step (refusal order, actor and createdBy stamping) and the plugin seam (registration, order, store routing, before/after hooks).
4
+ metadata:
5
+ purposes: planning, server-api
6
+ mentions: executeTransition, creatorHelper, makePluginRegistry, ensurePlanningService, PlanningRefused, mintCode, WorkcardConflict
7
+ ---
8
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
9
+
10
+ # @owlmeans/server-planning — The executor and the plugin seam
11
+
12
+ ## The executor, step by step
13
+
14
+ Nothing is appended before step 11 — every refusal leaves the log untouched.
15
+
16
+ 1. **Normalize** — deep copy, trimmed text, `parents ∋ parent` (first); a create's draft without
17
+ `createdBy` gets `creatorHelper.creatorOf(scope)` (below).
18
+ 2. **Scope** — `entityId` must be present.
19
+ 3. **Idempotency** — a `key` already in the entity's log answers ITS receipt, before any
20
+ validation or middleware.
21
+ 4. **Resolve** — the card (`WorkcardNotFound`; another entity's card is `PlanningScopeMismatch`;
22
+ one outside the scope's `projects` is `WorkcardNotFound`), its type and flow, every draft parent
23
+ (`ParentNotFound` — loaded through the facade, so an invisible parent is absent) and the parent
24
+ project's `cardTypes`/`projectTypes` (`CardTypeNotAllowed`), the specification slot. Where the
25
+ default store holds data-defined schemas, the card's project is found first and everything
26
+ after reads that project's resolved layer (`Resolved.schemas`): a data-defined type of a
27
+ project with `scopedCardTypes` is admitted, a retired type creates nothing
28
+ (`UnknownWorkcardType('retired:…')`). Without the port `Resolved.schemas` IS the code registry.
29
+ 5. **`before` chain** — in plugin order; re-resolved once when it changed the card, type or parent.
30
+ 6. **Validate** — shape (`planning:malformed:*`), the flow rule (`IllegalTransition`), immutables
31
+ (`planning:immutable:*`, `createdBy` among them — `creatorHelper.assertCreatorFixed`), merged `fields` against the
32
+ type's `fieldsSchema` — its own `fields` plus the app's base card fields (`FieldsInvalid`; the fold re-checks it), labels (`LabelNotAllowed`), a moved
33
+ parent, the slot (`SpecificationSlotUnknown`, `SpecificationRevisionConflict`, JSON body schema
34
+ → `FieldsInvalid`), relationships (`RelationshipRefused`: undeclared type, `from` not the card,
35
+ missing target, type constraints, `single`, unlinking an absent edge).
36
+ 7. **Card id** — `store.newId?.() ?? options.ids?.() ?? idHelper.uuid()`. Ids are the store's.
37
+ 8. **Code** — a supplied code is checked; else the plugins' `mintCode` (first answer wins, checked);
38
+ else the type's `CodePolicy` (a slug policy derives from the title) → `CodeTaken`.
39
+ 9. **Changes** — `changesHelper.computeChanges`. An `update` that changes nothing answers the card's latest
40
+ receipt and appends nothing.
41
+ 10. **Seq** — `transitions.nextSeq(card, expectSeq)`, a CAS against `head` (`WorkcardConflict`).
42
+ 11. **Append** — `commit: pending`. A lost race on the key answers the winner's receipt.
43
+ 12. **Project** — `store.cards.project(card)`: a sync store folds now, a queued one enqueues.
44
+ 13. **Receipt** — `{ transition, card? (once committed), committed(opts) }`.
45
+ 14. **`wait: true`** — `committed()` before returning (`CommitTimeout`, `CommitFailed`).
46
+
47
+ `actor` is the SCOPE's: `profileId`/`userId`/`service`/`channel` come from the scope only; an
48
+ in-process caller may add `agent`/`runId` on the execution. A handler never passes a wire `actor`.
49
+
50
+ A create's `createdBy` is the scope's subject too — `creatorHelper.creatorOf(scope)`: `profileId`, else `userId`,
51
+ else the same two of `scope.actor`. The executor stamps it on every path, so an in-process facade
52
+ create and the HTTP `execute` produce the same owner. An in-process draft that names `createdBy`
53
+ keeps it (explicit wins — a manager creating on someone's behalf); a scope naming nobody (a service
54
+ or system scope) leaves it unset; the wire drops a draft's `createdBy` before the stamp.
55
+
56
+ `createdBy` never moves after the create (the rule is `planning` → The record model). The executor
57
+ enforces it itself with `creatorHelper.assertCreatorFixed` at step 6, after the `before` chain, so a wire body, an
58
+ in-process caller and a plugin are refused alike, whatever `@owlmeans/planning` build the host
59
+ resolves. The conformance suite checks a store folds a stored row naming it as the pure fold does.
60
+
61
+ ## The plugin seam
62
+
63
+ | Concern | Rule |
64
+ |---|---|
65
+ | Registration | `use(plugin)` replaces by `name`; schemas are contributed at `use` time (later type/flow id wins); `schemas.app` is re-merged from the service's own and every registered plugin's in plugin order on each `use` (`appSchemaHelper.merge`) — a malformed one refuses the plugin (`SchemaInvalid`) and changes nothing |
66
+ | Order | `order ?? 50` ascending, registration order among equals |
67
+ | Store routing | `store(type)` = the first plugin whose `owns(type)` is true AND that supplies a `store`; else the default store. A store factory is resolved once |
68
+ | Reads | By id: the default store, then each owned store. A list naming one owned type (or several owned by one store) goes there; any other list — a cross-type query — is the default store's alone |
69
+ | `mintCode` | First non-`undefined` answer wins |
70
+ | `before` | Every plugin in order; may return a replaced execution; a `ResilientError` passes through, anything else becomes `PlanningRefused('<plugin>:<message>')` |
71
+ | `after` | Every plugin in order, once per COMMITTED transition; errors logged, never rethrown |
72
+
73
+ **Where `after` runs.** The service's `committed(event)` runs the chain, and it is called by the
74
+ process that FOLDS the transition — the memory store inside `project()`, a queued store's projection
75
+ job after marking the commit. Never subscribe a process to the commit bus to run hooks: that fires
76
+ once per subscribed process. Every process that folds registers the same plugins; each commit is
77
+ folded by one of them, so each hook fires once. `hooks: false` makes a process fold without running
78
+ them. A hook sees `ctx.transition` (read back, so `actor.channel` is available) and a facade scoped
79
+ to the event's entity acting as this process's `cfg.service`.
80
+
81
+ The service hands `committed` to a store through `store.bind?.(listener)` the first time it resolves
82
+ the store; `bind` replaces the listener, so a store has exactly one.
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: schemas
3
+ description: Data-defined card types and flows — the resolved layer per organization and project, the facade's definitions, retiring a flow.
4
+ metadata:
5
+ purposes: data, planning, config
6
+ mentions: makeDefinitions, makeSchemaViews, schemasFor, scopedSchemaHelper, definitions, SchemaInUse
7
+ ---
8
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
9
+
10
+ # @owlmeans/server-planning — Data-defined types and flows
11
+
12
+ ## Data-defined types and flows
13
+
14
+ Where the default store has the schema port, `runtime.schemasFor(entityId, project?)` answers the
15
+ resolved layer (`scopedSchemaHelper.resolveScopedBundle` over the code bundle and the organization's and project's
16
+ records), cached per (organization, project) and keyed by the store's `revision()` and the plugin
17
+ registry's version — a write anywhere moves the revision the next lookup reads, so a cached layer is
18
+ never stale; a store's `watch` evicts early. Without the port it answers the code registry itself.
19
+ `makeDefinitions` gives the facade `definitions`: every write checks the project (a project card the
20
+ scope can see), the seal, the closed-form checks (a type's flows resolve in its layer, counting flows
21
+ written beside it; a type's and a flow's `app` bag against the code registry's `app()`), then the
22
+ store's compare-and-set. A layer's registry carries the code declarations, so a data-defined card
23
+ type validates the app's base card fields too. `retire` of a flow refuses with `SchemaInUse`
24
+ while a live type of the layer — or of any project layer, for an organization record — still runs
25
+ it. `facade.model(card)` builds over the layer of the card's own project, and `schema.list` answers
26
+ the scoped bundle (`?project=`) where `definitions` exists, the code bundle otherwise.