@rolealpha/n8n-nodes-rolealpha 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,6 +48,8 @@ next run follows. You don't edit code and you don't republish anything.
48
48
  - **Workflows that follow the organisation.** When a step is created or changed in roleALPHA,
49
49
  or an entity a workflow is bound to changes or is removed, a model proposes what that means for the n8n workflows. The
50
50
  proposal becomes an inactive draft, and only a person filling the deciding role can apply it.
51
+ How far it may go without a click is set in roleALPHA too: an autonomy policy on a value stream
52
+ lets low-risk changes run at once, with an undo link in one digest mail per run.
51
53
  - **Memory that belongs to the role.** What an agent learns is kept for its role, without
52
54
  approval. Give the role to another agent and the memory goes with it. Who decides and who
53
55
  fills a role is never kept: it is read from roleALPHA on every run.
@@ -59,8 +61,10 @@ next run follows. You don't edit code and you don't republish anything.
59
61
  - **Limits you can change without republishing.** Retries, wait times, run time and tool
60
62
  calls come from a settings table and are clamped to fixed bounds.
61
63
 
62
- > **In use, not on npm.** The package runs in production on a self-hosted n8n. It is marked
63
- > `private` and installed from a tarball. See [Installation](#installation-self-hosted-n8n).
64
+ > **One package, one installation per organisation.** Every organisation runs its own n8n and
65
+ > connects it to its own tenant in roleALPHA. Nothing in the package knows a tenant, an
66
+ > instance or a system: organisation, endpoints, credentials, internal hosts and the route table
67
+ > are set in each installation. See [Installation](#installation-self-hosted-n8n).
64
68
 
65
69
  ## Why it works
66
70
 
@@ -165,20 +169,27 @@ deciders on every run. What roleALPHA cannot know is technology: a new step need
165
169
  schedule or a mapping of (collection, status) to its custom ID. The **roleALPHA Workflow
166
170
  Builder** closes that gap without letting a model change production on its own.
167
171
 
172
+ Where this is going, so that a change in roleALPHA needs ever less work in n8n:
173
+ [Roadmap: n8n follows roleALPHA, along the whole chain](docs/ROADMAP-adaptation.md).
174
+
168
175
  ```
169
176
  Scheduler (every 15 min)
170
177
  └ Workflow Builder: Detect Changes list_changes since the last run: new / changed
171
178
  │ steps, changed / removed bound entities
172
- └ per change: Workflow Builder: Propose rule first, else ← chat model; checks the answer
173
- ├ Create Draft inactive, tagged rolealpha-draft, with what changes
174
- │ └ roleALPHA: Get Decider (governing step; for Code nodes the code step)
175
- │ └ per person: Issue Approval Tokens → e-mail with approve / reject link
179
+ └ per change: Workflow Builder: Propose rule first, else ← chat model; checks the answer;
180
+ │ risk class + autonomy level from roleALPHA
181
+ ├ Create Draft inactive, tagged rolealpha-draft, with what changes;
182
+ │ │ applied at once (with undo record) where the level allows
183
+ │ ├ code → roleALPHA: Get Decider (code step) → per person: approval e-mail
184
+ │ └ rest → all of the run → Get Decider (governing step)
185
+ │ └ per person: Build Digest → one e-mail: applied (undo) + to approve
176
186
  └ nothing usable → e-mail to the same people; model away → again next run
177
187
 
178
- Approval link (GET) → Verify Approval Token → page with a confirm button
188
+ Link (GET) → Verify Approval Token → page with a confirm button
179
189
  Confirm button (POST)
180
- └ Verify Approval Token → Read Draft → roleALPHA: Check Approver (that step, fail-closed)
190
+ └ Verify Approval Token → (draft: Read Draft) → roleALPHA: Check Approver (that step, fail-closed)
181
191
  ├ approve → Workflow Builder: Apply Draft only with the hash in the token
192
+ ├ undo → Workflow Builder: Undo only while the workflow is as applied
182
193
  └ reject → Workflow Builder: Discard Draft
183
194
  ```
184
195
 
@@ -214,6 +225,10 @@ for again next run. A failed read of the feed fails the run and keeps the old cu
214
225
  | `scheduled` | The step has a frequency and the generic scheduler starts it (**Scheduler Covers Frequency**, on by default; switch it off without such a scheduler). |
215
226
  | `retired` | The step is archived or retired. |
216
227
 
228
+ Two more rules decide a deactivation without a model: `removed` and `retired` when the step is
229
+ gone or retired and **exactly one** active workflow exists for nothing but that step. Anything
230
+ less clear (a workflow shared with other entities, several workflows) still goes to the model.
231
+
217
232
  **For the rest it asks the model**, and gives it the change, the entity as roleALPHA shows it now
218
233
  (a step with its roles, never persons), the managed workflows, which of them the change
219
234
  affects (bound to the entity, or to a step right before, after, above or below it), the
@@ -235,8 +250,11 @@ writes itself.
235
250
  - no e-mail address and no UUID in any parameter: those are read from roleALPHA at run time,
236
251
  - no expression that reaches `$env`, `$secrets`, `$vars`, `process`, `require` or `constructor`,
237
252
  or reads a node that is not in the workflow,
238
- - no call to an internal address: this instance over `localhost`, the containers behind it, or the
239
- internal workflows `zammad-proxy` and `kb-quellen`, which lend out a credential,
253
+ - no call to an internal address: loopback, the host of this n8n (from the n8n API credential),
254
+ and whatever else only this installation reaches, named in **Internal Hosts** on *Propose*
255
+ (e.g. the public host of this n8n and the containers behind it, `*` as wildcard). Their webhooks
256
+ and APIs may lend out credentials. Neither may a URL whose host hides in an expression lead to
257
+ a webhook,
240
258
  - only credentials already used by managed workflows, plus the roleALPHA credential of Propose
241
259
  itself; a node that stays keeps its own credentials, IDs and webhook IDs,
242
260
  - updates and deactivations only of managed workflows, connections only between existing nodes,
@@ -315,7 +333,10 @@ once by hand. No data table is needed; *Detect Changes* keeps its cursor in the
315
333
  second workflow also set `governingStep` and `codeGoverningStep`.
316
334
  5. **Set up the governing step in roleALPHA**, as described in the next section. Without it
317
335
  nobody may approve, and every draft stays a draft.
318
- 6. **Activate** *Approve workflow drafts* first, then *Workflows follow the organisation*. The
336
+ 6. **Optional: set an autonomy level** for a value stream in roleALPHA (see
337
+ [How far it goes without a click](#how-far-it-goes-without-a-click)). Without it every change
338
+ waits for approval.
339
+ 7. **Activate** *Approve workflow drafts* first, then *Workflows follow the organisation*. The
319
340
  first run starts now and only checks that the bound entities still exist; changes are
320
341
  reported from the second run on. The cursor is kept only by runs of the active workflow:
321
342
  a manual test run starts afresh each time.
@@ -353,6 +374,97 @@ Changing who approves later needs no change in n8n: give the role to someone els
353
374
  no longer fills the role do nothing. A person who fills two deciding roles of the step gets
354
375
  one mail per role.
355
376
 
377
+ ### How far it goes without a click
378
+
379
+ Every approval is work, and most changes are not risky: deactivating the workflow of a retired
380
+ step, or a ready template for a new step. So how far the builder may go on its own is set in
381
+ roleALPHA, per value stream, by the people who own it, and it follows the model like everything
382
+ else.
383
+
384
+ **The autonomy level.** Create a policy with the custom ID `automation:autonomie-3` (or `-4`) and
385
+ draw `APPLIES_TO` from it to a process: a value chain, a value stream or a single step. It holds
386
+ for everything below it along `HAS_SUBPROCESS`; the nearest policy wins, and of two at the same
387
+ distance the lower level. A policy in status draft, retired or archived does not count. Without
388
+ such a policy, or when roleALPHA cannot be read, nothing is applied without asking: the builder
389
+ behaves exactly as before. The levels are the company's autonomy levels for AI:
390
+
391
+ | Level | Meaning | What runs without a click |
392
+ |---|---|---|
393
+ | 1, 2 | Assistance, preparation: a person decides | nothing |
394
+ | 3 | Limited execution: clearly defined actions, a person watches | `narrowing` (deactivations) and `template` (a ready schedule or event workflow) |
395
+ | 4 | Extensive: acts within set limits | also `model` (a free model answer) |
396
+
397
+ `code` (new or changed Code nodes) and `new_credential` (a credential that still has to be set)
398
+ always wait for approval. A change that touches a workflow bound to several entities takes the
399
+ lowest level of them; a removed entity no longer counts. **Autonomy Policy Prefix** on *Propose*
400
+ changes the prefix; empty switches it off.
401
+
402
+ **Propose** returns `risk`, `autonomy` (`level`, `policy`, `appliesTo`, `reason`) and `autoApply`
403
+ with `autoReason`. Two limits hold per run: if anything in the run could not be read, nothing is
404
+ applied by itself; and at most **Max Changes Applied by Themselves** (default 3) are, the rest
405
+ waits for approval.
406
+
407
+ **Create Draft** with **Apply When Allowed** applies a draft with `autoApply` at once and activates
408
+ a new workflow. It decides the class again from the draft itself, so an edited proposal gains
409
+ nothing. Before it changes anything it leaves an **undo record**: an inactive workflow tagged
410
+ `rolealpha-undo`, which for an update holds the nodes before. It returns `applied`, `workflowId`,
411
+ `undoId` and `appliedHash`, or `applyError`, and the draft then waits for approval as usual.
412
+
413
+ **Undo** puts back what was there before (removes a created workflow, restores the nodes of an
414
+ update, activates a deactivated workflow), only while the workflow still has `appliedHash`. If
415
+ a person changed it since, Undo refuses and changes nothing. A record works once; only the newest
416
+ record of a workflow is kept, and **Prune Undo Records** removes those older than 14 days.
417
+
418
+ **One mail per run.** **Build Digest** turns the drafts of a run into one mail per person who
419
+ decides: what was applied without asking, each with an **undo link**, and what waits, each with
420
+ **approve** and **reject** links. All links are signed one-time tokens for that person, handled by
421
+ the approval workflow; whether the person may decide is checked when they confirm, also for undo.
422
+ Drafts that change Code nodes still go one by one to the code governing step.
423
+
424
+ After an undo, the next change of the same step is proposed again, and at the same level applied
425
+ again. If a change should not run by itself, lower the level in roleALPHA or fix the step.
426
+
427
+ ### The whole chain
428
+
429
+ A workflow that follows a step is not enough if the step after it never starts. **Check Chain**
430
+ looks at a value stream as a whole: its steps in order (`HAS_SUBPROCESS`, `DEPENDS_ON`), and for
431
+ each step what starts it in n8n, who does it and where it goes on. It needs no model, gives the
432
+ same answer every time, and knows no system and no tenant: a system is whatever the step is
433
+ `SUPPORTED_BY` in roleALPHA, an event is `<object>:<state>` in your own notation, and routes come
434
+ from any store.
435
+
436
+ | A step is started by | Seen as |
437
+ |---|---|
438
+ | its `frequency`, when the generic scheduler covers it | `schedule` |
439
+ | a row of your route table (event → step custom ID, `run`) | `route` |
440
+ | a row that asks people to decide (`decide`, `card`, `approval`) | `decision` |
441
+ | an active workflow bound to it, or naming its custom ID | `workflow` |
442
+ | the exit of its predecessor being its entry (`SUPPORTED_BY.ausgang` = `SUPPORTED_BY.eingang`) | `handover` |
443
+ | `on_demand`, when a person can ask for it | `on_demand` |
444
+
445
+ Per step it names what is missing, as `error` or `warning`:
446
+
447
+ - **Nothing starts it:** `no_entry`; or `handover_unverified` when it only follows another
448
+ step and nothing proves the hand-over.
449
+ - **An event roleALPHA names but no route leads to:** `event_not_routed`.
450
+ - **Nobody does it:** `no_responsible_role`, or `no_executor` (no active agent and no person with
451
+ an address). `route_without_agent` when a route starts the runner but only people fill the role.
452
+ - **A gate:** `no_decider`, `no_deciding_person` (agents never decide), `gate_not_requested`
453
+ (nobody is asked), `outcomes_not_modelled` (no `DEPENDS_ON.ausgang` on its exits).
454
+ - **Workflows that drift:** `unbound_workflow` (a hand-built workflow a change in roleALPHA does
455
+ not reach), `inactive_workflow`, `draft_waiting`.
456
+ - **Leftovers:** `route_to_retired`, `workflow_for_retired`.
457
+
458
+ Each item carries `steps` (entries, executors, next, gaps), `gaps`, `ok`, `errors`, `warnings`
459
+ and `report`: Markdown in English or German, fit as the text of a task for whoever builds the
460
+ workflows, or as a note to the owner of the value stream. Name value streams by UUID or custom ID;
461
+ pass the changes of *Detect Changes* to check only the value streams they touch; leave both empty
462
+ to check every value stream of the organisation. If none can be seen (none modelled yet, or the
463
+ process module not released for AI), the item says so.
464
+
465
+ **Get Value Stream** (roleALPHA node, Responsibility) returns the same chain without the check:
466
+ steps in order, gates with the outcomes of their exits, roles with who fills them, systems.
467
+
356
468
  ### The builder's own steps
357
469
 
358
470
  The builder may be modelled in roleALPHA like any other value chain: a process with the steps
@@ -557,6 +669,7 @@ Select Pages again with all of them.
557
669
  | Responsibility | Get Duties | Lists the steps the agent's roles are `RESPONSIBLE_FOR`, with the circle. | MCP OAuth2 |
558
670
  | Responsibility | Find Step by Custom ID | Looks up a step by an exact custom ID. | MCP OAuth2 |
559
671
  | Responsibility | Get Step | Returns a step with its predecessors, successors, parent and child steps, responsible, deciding and accountable roles (with their holders), and policies. With **Role Details** also purpose, accountabilities and domains of each responsible role. | MCP OAuth2 |
672
+ | Responsibility | Get Value Stream | A value stream as a chain: steps in order (`HAS_SUBPROCESS`, `DEPENDS_ON`), gates with the outcomes of their exits (`DEPENDS_ON.ausgang`), responsible and deciding roles with who fills them, systems (`SUPPORTED_BY` with `eingang` and `ausgang`). | MCP OAuth2 |
560
673
  | Responsibility | Get Decider | Returns the `DECIDES_ON` role. If there is none, it returns the `ACCOUNTABLE_FOR` role. | MCP OAuth2 |
561
674
  | Responsibility | Check Approver | **Fail-closed.** Is the acting person filling the deciding role? Only persons count; agents never do. | MCP OAuth2 |
562
675
  | Responsibility | Check Responsibility | Is one of the agent's roles responsible for this step? | MCP OAuth2 |
@@ -587,13 +700,17 @@ Select Pages again with all of them.
587
700
  |---|---|---|
588
701
  | Detect Changes | Reads `list_changes` from the cursor kept in the workflow (or the **Cursor** option). Returns `changes` (`created`, `changed`, `removed`, each with `relationships` and the bound `workflows`), `cursor`, `hasMore`, `started`, `checked`, `unreadable` and `skipped`. | MCP OAuth2, n8n API |
589
702
  | List Workflows | The managed workflows with their bound entities and the credentials they use. | n8n API |
590
- | Propose | Needs a chat model on its **Model** input. Returns `ok`, `action` (`create`, `update`, `deactivate`, `none`), `reason`, `workflow`, `contentHash`, `problems`, `notes`, `decidedBy` (`rule`, `model`, `failed`), and where they apply `rule`, `template`, `code` and `retry`. | MCP OAuth2, n8n API |
591
- | Create Draft | Stores a proposal with `ok = true` as an inactive draft and replaces an older draft of the same entity. Returns `draftId`, `contentHash`, `diff`, `codeChanged`, `codeNodes`, `reviewHtml` and `replacedDrafts`. | n8n API |
703
+ | Propose | Needs a chat model on its **Model** input. Returns `ok`, `action` (`create`, `update`, `deactivate`, `none`), `reason`, `workflow`, `contentHash`, `problems`, `notes`, `decidedBy` (`rule`, `model`, `failed`), `risk`, `autonomy`, `autoApply`, `autoReason`, and where they apply `rule`, `template`, `code`, `missingCredentials` and `retry`. | MCP OAuth2, n8n API |
704
+ | Create Draft | Stores a proposal with `ok = true` as an inactive draft and replaces an older draft of the same entity. With **Apply When Allowed** it applies a draft with `autoApply` at once and leaves an undo record. Returns `draftId`, `contentHash`, `diff`, `codeChanged`, `codeNodes`, `reviewHtml`, `replacedDrafts`, `applied`, and when applied `workflowId`, `undoId`, `appliedHash`, `activated`, else `applyError`. | n8n API |
592
705
  | Read Draft | What a draft changes against its target: `action`, `contentHash`, `diff`, `codeChanged` and `codeNodes`. | n8n API |
593
706
  | Apply Draft | Applies a draft given the approved hash. Optionally activates a new workflow. Refuses changed Code nodes without **Code Approved**. | n8n API |
594
707
  | Discard Draft | Deletes a draft; refuses any workflow that is not a draft. | n8n API |
595
708
  | Issue Approval Tokens | `approveToken` and `rejectToken` for one person, bound to `draftId` and `contentHash`, plus `tokenExpiresAt`. Keeps the input fields. | Approval Seal API |
596
- | Verify Approval Token | Returns `draftId`, `contentHash`, `approver`, `decision` and `expiresAt` of a valid token; fails on a changed, foreign or expired one. | Approval Seal API |
709
+ | Verify Approval Token | Returns `draftId`, `contentHash`, `approver`, `decision` (`approve`, `reject`, `undo`) and `expiresAt` of a valid token, and `undoId` for an undo token; fails on a changed, foreign or expired one. | Approval Seal API |
710
+ | Build Digest | One mail for one person from the drafts of a run (**Changes**, e.g. from an Aggregate node): `subject`, `html`, `applied`, `waiting`, `expiresAt`. | Approval Seal API |
711
+ | Undo | Takes back a change applied without asking, given `undoId` and `appliedHash` of a verified undo token. Refuses once the workflow changed. | n8n API |
712
+ | Prune Undo Records | Removes undo records older than **Older Than (Hours)** (default 336). | n8n API |
713
+ | Check Chain | One item per value stream: whether n8n runs its whole chain, with the gaps per step and a Markdown `report`. **Routes** take the rows of your route table from any store. | MCP OAuth2, n8n API |
597
714
 
598
715
  ### Approval Seal (`approvalSeal`)
599
716
 
@@ -625,6 +742,91 @@ under the agent → *Context & Access*.
625
742
  Agent keys and webhook secrets are issued in the roleALPHA interface and shown only once.
626
743
  Store them nowhere except in these credentials.
627
744
 
745
+ ### Setting up the roleALPHA credential
746
+
747
+ n8n talks to roleALPHA through a **service account** (*Funktionskonto*): a client of its own with a
748
+ client ID and secret, not a person's login. Create one per n8n installation: every organisation
749
+ runs its own n8n against its own tenant, and two installations never share an account.
750
+
751
+ **1. In roleALPHA** (as tenant admin)
752
+
753
+ 1. **Allow external access.** Under *Settings → AI → External applications*, switch on **Allow
754
+ external applications**. While it is off, no service account gets access.
755
+ 2. **Release the data.** Under *Settings → AI → Data & knowledge*, release the modules the
756
+ workflows read, at least processes (value creation), roles, agents and policies. A module that
757
+ is not released is invisible to n8n, and *Detect Changes* fails instead of reporting nothing.
758
+ 3. **Create the account.** On the card **Service accounts** (same page), choose **New** and fill
759
+ in three fields:
760
+
761
+ | Field | Value |
762
+ |---|---|
763
+ | **Name** | How it appears in the log and in drafts, e.g. *n8n*. |
764
+ | **Acts for** | An agent or a person of the tenant. The account sees exactly what this agent or person may see. |
765
+ | **Roles** | What the account may do. *Observer* is enough to read: traversals, Check Chain. Proposing changes needs a role that allows drafts. |
766
+
767
+ 4. **Let it run agents** (only for the runner, *Start Run* and **Connect As: Agent**):
768
+ - Give one of its roles the right **Run AI agents** (`agent:run`).
769
+ - In the account's dialog, under **May run these agents**, pick the agents. Or tick **All
770
+ agents of this organisation, also future ones**, so a new agent runs without touching the
771
+ account.
772
+ 5. **Copy the access details.** After saving, roleALPHA shows them **once**: client ID, client
773
+ secret, token URL and MCP URL. Copy them straight into n8n (next part); only a fingerprint of
774
+ the secret is kept.
775
+
776
+ **2. In n8n**
777
+
778
+ 1. Under *Credentials → Add credential*, choose **MCP OAuth2 API** and fill it in:
779
+
780
+ | Field | Value |
781
+ |---|---|
782
+ | **Use Dynamic Client Registration** | off |
783
+ | **Grant Type** | *Client Credentials* |
784
+ | **Access Token URL** | the token URL from roleALPHA, e.g. `https://rolealpha.app/api/auth/oauth/token` |
785
+ | **Client ID**, **Client Secret** | from roleALPHA |
786
+ | **Scope** | empty |
787
+ | **Authentication** | *Header* (*Body* works too) |
788
+
789
+ 2. **Save.** n8n fetches a token itself and renews it every 60 minutes.
790
+ 3. **In every roleALPHA node** (and in *Settings* of the example workflows):
791
+ - **MCP Endpoint URL**: the MCP URL from roleALPHA (default `https://rolealpha.app/api/mcp`).
792
+ - **Organisation**: the name or ID of the tenant.
793
+ - The credential: the one just made.
794
+
795
+ The same credential serves both: **Function Account** reads with the account's own view;
796
+ **Connect As: Agent** swaps it for a run token of one agent. That swap needs exactly this kind
797
+ of credential (*Client Credentials*), and the nodes refuse any other.
798
+
799
+ **Checking it.** Run a **roleALPHA → Agent → List Agents** node once:
800
+ - It lists the agents of the tenant: the credential works.
801
+ - n8n reports *"The client is not authorized …"*: the account is deactivated, *Allow external
802
+ applications* is off, or the agent or person it acts for was deleted.
803
+ - HTTP 503 *"The installation of this organisation is not responding"*: nothing is wrong with the
804
+ account, roleALPHA is briefly unreachable. Turn on *Retry On Fail*.
805
+
806
+ **Changing the secret without downtime.**
807
+ 1. Create **New secret** on the account; the old one keeps working.
808
+ 2. Enter the new one in the n8n credential.
809
+ 3. **Revoke** the old one; revoking takes effect at once.
810
+
811
+ Service accounts are not part of a tenant backup: after a restore, create the account again.
812
+
813
+ **The other credentials**
814
+
815
+ - **roleALPHA Agent Keys API** (optional, only for the source *Agent Keys*):
816
+ - Each agent's keys are under the agent → tab *Context & access* → **Agent access keys**.
817
+ - **Data Node URL** is the host shown there under *Connection*.
818
+ - **Agent Keys** is `{"<agent uuid>": "agt_…"}`.
819
+ - **roleALPHA Webhook API** (for the *roleALPHA Trigger*):
820
+ 1. Under the agent → *Context & access* → **Context webhooks**, register the production URL of
821
+ the trigger node.
822
+ 2. Paste the signing secret roleALPHA shows once into the credential.
823
+ - **Approval Seal API**:
824
+ - A random key of at least 32 characters, e.g. from `openssl rand -base64 48`.
825
+ - Keep it in this credential only: whoever has it can make approval links.
826
+ - **n8n API** (for the Workflow Builder):
827
+ - An API key from *Settings → n8n API* of this n8n.
828
+ - As base URL, `http://localhost:5678/api/v1` works when the nodes run in the same instance.
829
+
628
830
  ## Settings
629
831
 
630
832
  The runner reads its limits from a table with the columns `scope, target, key, value`. A row
@@ -669,10 +871,12 @@ record_keys, event, run_id, attempts, progress, at`.
669
871
  - The prompt marks trigger payloads as data. Guardrails take precedence over event content.
670
872
  - Keep `requireActive` and `requireGuardrails` on in production.
671
873
  - Settings are clamped to fixed bounds.
672
- - The Workflow Builder never activates or changes a workflow by itself. A proposal is an
673
- inactive draft; Apply needs the hash that was sent to the approver and a target that did not
674
- change since. The approval link is a signed one-time token for one person and one decision;
675
- Check Approver decides at use whether that person may still decide.
874
+ - The Workflow Builder changes a workflow by itself only where an autonomy policy in roleALPHA
875
+ allows the class of the change, never code and never a credential still to be set, and then
876
+ leaves an undo record first. Everything else is an inactive draft; Apply needs the hash that
877
+ was sent to the approver and a target that did not change since. Approval and undo links are
878
+ signed one-time tokens for one person and one decision; Check Approver decides at use whether
879
+ that person may still decide.
676
880
  - Duplicate runs are blocked by leases, and wake-ups are claimed before they fire.
677
881
  - Memory belongs to roles the agent fills in the run; secrets are never kept, and what else is
678
882
  never kept each company sets itself. Remembered facts reach the prompt as data, with limits.
@@ -691,9 +895,14 @@ asks for a contact, and roleALPHA GmbH will get back to you.
691
895
 
692
896
  ### Requirements
693
897
 
694
- - A self-hosted n8n that allows community nodes
898
+ - A self-hosted n8n that allows community nodes, one per organisation
695
899
  - A roleALPHA organisation and an MCP OAuth2 credential for it
696
900
 
901
+ Each installation sets its own values: **Organisation** and endpoint in every node (the examples
902
+ say `Your organisation`), the credentials, **Internal Hosts** on *Propose*, its own route table
903
+ for **Check Chain**, and its own governing step and autonomy policies in its tenant. Two
904
+ organisations never share a credential, a seal key or a data table.
905
+
697
906
  ### Install
698
907
 
699
908
  In n8n, open **Settings → Community Nodes → Install** and enter
@@ -8,8 +8,11 @@
8
8
  * expires. It can be used once: applying or discarding removes the draft, and a second
9
9
  * use finds no draft any more. Whether the person may still decide is checked at use,
10
10
  * not when the token is issued.
11
+ *
12
+ * An undo token works the same way for a change applied without asking: draftId names the
13
+ * undo record and contentHash the hash the workflow got at apply.
11
14
  */
12
- export type Decision = 'approve' | 'reject';
15
+ export type Decision = 'approve' | 'reject' | 'undo';
13
16
  export interface TokenClaims {
14
17
  draftId: string;
15
18
  contentHash: string;
@@ -9,6 +9,9 @@
9
9
  * expires. It can be used once: applying or discarding removes the draft, and a second
10
10
  * use finds no draft any more. Whether the person may still decide is checked at use,
11
11
  * not when the token is issued.
12
+ *
13
+ * An undo token works the same way for a change applied without asking: draftId names the
14
+ * undo record and contentHash the hash the workflow got at apply.
12
15
  */
13
16
  Object.defineProperty(exports, "__esModule", { value: true });
14
17
  exports.TOKEN_PATTERN = void 0;
@@ -17,6 +20,7 @@ exports.verifyToken = verifyToken;
17
20
  const crypto_1 = require("crypto");
18
21
  const seal_1 = require("./seal");
19
22
  const graph_1 = require("./graph");
23
+ const DECISIONS = ['approve', 'reject', 'undo'];
20
24
  const PREFIX = 'at1';
21
25
  /** Keeps a token signature from ever matching a seal made with the same key. */
22
26
  const PURPOSE = 'rolealpha-approval-token';
@@ -41,8 +45,8 @@ function issueToken(key, input, opts = {}) {
41
45
  throw new Error('A token needs the content hash of the draft');
42
46
  if (!approver.includes('@'))
43
47
  throw new Error('A token needs the approver address');
44
- if (input.decision !== 'approve' && input.decision !== 'reject')
45
- throw new Error('The decision is approve or reject');
48
+ if (!DECISIONS.includes(input.decision))
49
+ throw new Error('The decision is approve, reject or undo');
46
50
  const hours = Math.min(Math.max(Number(opts.validHours ?? 168) || 168, 1), MAX_HOURS);
47
51
  const exp = Math.floor((opts.now ?? new Date()).getTime() / 1000) + Math.round(hours * 3600);
48
52
  const claims = { draftId, contentHash, approver, decision: input.decision, exp };
@@ -73,7 +77,7 @@ function verifyToken(key, token, opts = {}) {
73
77
  decision: raw.decision,
74
78
  exp: Number(raw.exp),
75
79
  };
76
- if (!claims.draftId || !claims.contentHash || !claims.approver.includes('@') || !['approve', 'reject'].includes(claims.decision) || !Number.isFinite(claims.exp)) {
80
+ if (!claims.draftId || !claims.contentHash || !claims.approver.includes('@') || !DECISIONS.includes(claims.decision) || !Number.isFinite(claims.exp)) {
77
81
  return { valid: false, reason: 'The token is incomplete', claims: null };
78
82
  }
79
83
  if (claims.exp * 1000 <= (opts.now ?? new Date()).getTime())
@@ -1 +1 @@
1
- {"version":3,"file":"approvalToken.js","sourceRoot":"","sources":["../../lib/approvalToken.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAsCH,gCAkBC;AAED,kCA0BC;AAlFD,mCAAqD;AACrD,iCAAuC;AACvC,mCAAyC;AAmBzC,MAAM,MAAM,GAAG,KAAK,CAAC;AACrB,gFAAgF;AAChF,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAC3C,sFAAsF;AAC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G,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,CAAC;IAC7H,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC;AACzD,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Release by risk. How far the Workflow Builder may act without a click is not set in n8n but
3
+ * in roleALPHA: a policy with the custom ID `automation:autonomie-<1..4>` that APPLIES_TO a
4
+ * process (a value stream, a step) sets the level for it and, down HAS_SUBPROCESS, for all its
5
+ * steps. The levels follow the company's autonomy levels for AI:
6
+ *
7
+ * 1 assistance the system proposes, a person decides and acts
8
+ * 2 preparation the system prepares, a person checks and approves (the default)
9
+ * 3 limited the system carries out clearly defined actions, a person watches
10
+ * 4 extensive the system decides and acts within set limits, a person sets the limits
11
+ *
12
+ * Each checked proposal gets a risk class, and each class a level from which it is applied
13
+ * without asking first. Code and credentials still to be set never are. Fail-closed: whatever
14
+ * cannot be read counts as "no policy", and then every change waits for approval as before.
15
+ */
16
+ import type { EntityChange } from './changes';
17
+ import type { GraphSource } from './graph';
18
+ import type { ManagedWorkflow, PlanCheck } from './workflows';
19
+ export declare const AUTONOMY_PREFIX = "automation:autonomie-";
20
+ export type AutonomyLevel = 1 | 2 | 3 | 4;
21
+ export type RiskClass = 'narrowing' | 'template' | 'model' | 'code' | 'new_credential';
22
+ /** From which level a class is applied without asking; null: never. */
23
+ export declare const AUTO_FROM_LEVEL: Record<RiskClass, AutonomyLevel | null>;
24
+ export declare const DEFAULT_MAX_AUTO_PER_PASS = 3;
25
+ export interface Autonomy {
26
+ /** null: no policy applies, or it could not be read. Nothing is applied without asking then. */
27
+ level: AutonomyLevel | null;
28
+ policy: {
29
+ uuid: string;
30
+ name: string;
31
+ customId: string;
32
+ } | null;
33
+ /** The entity the policy applies to: the step itself or a process above it. */
34
+ appliesTo: {
35
+ uuid: string;
36
+ name: string;
37
+ } | null;
38
+ reason: string;
39
+ /** Something could not be read; the pass then applies nothing by itself. */
40
+ readFailed?: boolean;
41
+ }
42
+ /** The level a custom ID names, if it is an autonomy policy of this prefix. */
43
+ export declare function levelOf(customId: unknown, prefix?: string): AutonomyLevel | null;
44
+ /**
45
+ * The autonomy level of one entity: the nearest policy on the entity or on a process above it
46
+ * (HAS_SUBPROCESS, upwards). Two policies at the same distance: the lower level wins.
47
+ */
48
+ export declare function autonomyFor(src: GraphSource, entityUuid: string, opts?: {
49
+ prefix?: string;
50
+ }): Promise<Autonomy>;
51
+ /** The level for a change that touches several entities: the lowest of them, and none if one has none. */
52
+ export declare function autonomyForAll(src: GraphSource, entityUuids: string[], opts?: {
53
+ prefix?: string;
54
+ }): Promise<Autonomy>;
55
+ /**
56
+ * The entities whose level counts for a proposal: what the workflow is and will be bound to.
57
+ * A removed entity no longer exists, so it cannot count.
58
+ */
59
+ export declare function autonomyEntities(plan: Pick<PlanCheck, 'action' | 'targetWorkflowId' | 'bindEntity'>, change: Pick<EntityChange, 'uuid' | 'change'>, workflows: Pick<ManagedWorkflow, 'id' | 'entities'>[]): string[];
60
+ /** The risk class of a checked proposal; null when it changes nothing. */
61
+ export declare function classifyRisk(plan: Pick<PlanCheck, 'ok' | 'action' | 'template' | 'code' | 'missingCredentials'>): RiskClass | null;
62
+ export interface AutoDecision {
63
+ autoApply: boolean;
64
+ autoReason: string;
65
+ }
66
+ /** Whether a proposal of this class may be applied without asking at this level. */
67
+ export declare function decideAuto(risk: RiskClass | null, autonomy: Pick<Autonomy, 'level' | 'reason'>): AutoDecision;
68
+ /**
69
+ * The limits of one pass, after all its proposals are known: a pass in which anything failed
70
+ * to read applies nothing by itself, and at most `max` changes are applied by themselves; the
71
+ * rest wait for approval.
72
+ */
73
+ export declare function limitPass<T extends Partial<AutoDecision> & {
74
+ decidedBy?: string;
75
+ error?: unknown;
76
+ autonomy?: {
77
+ readFailed?: boolean;
78
+ } | null;
79
+ }>(results: T[], max?: number): T[];