adula 0.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE.md +10 -0
  2. package/README.md +38 -2
  3. package/build/agent/AGENTS.template.md +28 -0
  4. package/build/agent/capabilities.md +60 -0
  5. package/build/agent/skills/adula-frontend-design/SKILL.md +59 -0
  6. package/build/agent/skills/idea-review/SKILL.md +31 -0
  7. package/build/agent/skills/module-review/SKILL.md +22 -0
  8. package/build/agent/skills/perf-review/SKILL.md +24 -0
  9. package/build/agent/skills/schema-review/SKILL.md +22 -0
  10. package/build/agent/skills/security-review/SKILL.md +24 -0
  11. package/build/agent/skills/ui-review/SKILL.md +22 -0
  12. package/build/commands/capabilities.d.ts +10 -0
  13. package/build/commands/capabilities.js +40 -0
  14. package/build/commands/doctor.d.ts +9 -0
  15. package/build/commands/doctor.js +72 -0
  16. package/build/commands/gaps.d.ts +12 -0
  17. package/build/commands/gaps.js +62 -0
  18. package/build/commands/install.d.ts +9 -0
  19. package/build/commands/install.js +105 -0
  20. package/build/commands/main.d.ts +8 -0
  21. package/build/commands/main.js +33 -0
  22. package/build/commands/module_add.d.ts +8 -0
  23. package/build/commands/module_add.js +57 -0
  24. package/build/commands/module_remove.d.ts +10 -0
  25. package/build/commands/module_remove.js +94 -0
  26. package/build/commands/resource.d.ts +8 -0
  27. package/build/commands/resource.js +29 -0
  28. package/build/commands/resource_snapshot.d.ts +15 -0
  29. package/build/commands/resource_snapshot.js +61 -0
  30. package/build/commands/storage_migrate.d.ts +12 -0
  31. package/build/commands/storage_migrate.js +39 -0
  32. package/build/commands/ui.d.ts +11 -0
  33. package/build/commands/ui.js +210 -0
  34. package/build/commands/upgrade.d.ts +15 -0
  35. package/build/commands/upgrade.js +34 -0
  36. package/build/configure.d.ts +2 -0
  37. package/build/configure.js +79 -0
  38. package/build/database/migrations/1770000000000_core.d.ts +5 -0
  39. package/build/database/migrations/1770000000000_core.js +10 -0
  40. package/build/database/migrations/1770000000001_attachments.d.ts +5 -0
  41. package/build/database/migrations/1770000000001_attachments.js +10 -0
  42. package/build/database/migrations/1770000000002_saved_views.d.ts +5 -0
  43. package/build/database/migrations/1770000000002_saved_views.js +10 -0
  44. package/build/database/migrations/1770000000003_user_invitations.d.ts +5 -0
  45. package/build/database/migrations/1770000000003_user_invitations.js +18 -0
  46. package/build/database/migrations/1770000000004_collaboration.d.ts +5 -0
  47. package/build/database/migrations/1770000000004_collaboration.js +10 -0
  48. package/build/database/migrations/1770000000005_assignments.d.ts +5 -0
  49. package/build/database/migrations/1770000000005_assignments.js +10 -0
  50. package/build/database/migrations/1770000000006_messaging.d.ts +5 -0
  51. package/build/database/migrations/1770000000006_messaging.js +10 -0
  52. package/build/database/migrations/1770000000007_webhooks.d.ts +5 -0
  53. package/build/database/migrations/1770000000007_webhooks.js +10 -0
  54. package/build/database/migrations/1770000000008_imports.d.ts +5 -0
  55. package/build/database/migrations/1770000000008_imports.js +10 -0
  56. package/build/database/migrations/1770000000010_workflows.d.ts +5 -0
  57. package/build/database/migrations/1770000000010_workflows.js +10 -0
  58. package/build/database/migrations/1770000000011_managed_assignments.d.ts +5 -0
  59. package/build/database/migrations/1770000000011_managed_assignments.js +10 -0
  60. package/build/database/migrations/1770000000012_role_keys.d.ts +5 -0
  61. package/build/database/migrations/1770000000012_role_keys.js +10 -0
  62. package/build/database/migrations/1770000000013_notification_targets.d.ts +5 -0
  63. package/build/database/migrations/1770000000013_notification_targets.js +10 -0
  64. package/build/database/migrations/1770000000014_upload_grants.d.ts +5 -0
  65. package/build/database/migrations/1770000000014_upload_grants.js +10 -0
  66. package/build/database/migrations/1770000000015_inbound_webhooks.d.ts +5 -0
  67. package/build/database/migrations/1770000000015_inbound_webhooks.js +10 -0
  68. package/build/database/migrations/1770000000016_adulajs_names.d.ts +6 -0
  69. package/build/database/migrations/1770000000016_adulajs_names.js +11 -0
  70. package/build/index.d.ts +80 -0
  71. package/build/index.js +49 -0
  72. package/build/providers/adula_provider.d.ts +6 -0
  73. package/build/providers/adula_provider.js +10 -0
  74. package/build/src/admin/contracts.d.ts +19 -0
  75. package/build/src/admin/contracts.js +115 -0
  76. package/build/src/admin/controller.d.ts +32 -0
  77. package/build/src/admin/controller.js +167 -0
  78. package/build/src/admin/errors.d.ts +5 -0
  79. package/build/src/admin/errors.js +9 -0
  80. package/build/src/admin/presentation.d.ts +28 -0
  81. package/build/src/admin/presentation.js +1 -0
  82. package/build/src/admin/record_title.d.ts +14 -0
  83. package/build/src/admin/record_title.js +50 -0
  84. package/build/src/admin/resource_service.d.ts +376 -0
  85. package/build/src/admin/resource_service.js +1448 -0
  86. package/build/src/attachments/attachment_service.d.ts +100 -0
  87. package/build/src/attachments/attachment_service.js +270 -0
  88. package/build/src/attachments/doctor.d.ts +4 -0
  89. package/build/src/attachments/doctor.js +28 -0
  90. package/build/src/attachments/storage_migrate.d.ts +39 -0
  91. package/build/src/attachments/storage_migrate.js +64 -0
  92. package/build/src/attachments/upload_grants.d.ts +44 -0
  93. package/build/src/attachments/upload_grants.js +105 -0
  94. package/build/src/auth/ability.d.ts +24 -0
  95. package/build/src/auth/ability.js +34 -0
  96. package/build/src/auth/actor_store.d.ts +14 -0
  97. package/build/src/auth/actor_store.js +70 -0
  98. package/build/src/auth/conditions.d.ts +26 -0
  99. package/build/src/auth/conditions.js +117 -0
  100. package/build/src/auth/packed_rules.d.ts +4 -0
  101. package/build/src/auth/packed_rules.js +13 -0
  102. package/build/src/auth/sql.d.ts +11 -0
  103. package/build/src/auth/sql.js +118 -0
  104. package/build/src/collaboration/assignments.d.ts +129 -0
  105. package/build/src/collaboration/assignments.js +333 -0
  106. package/build/src/collaboration/record_collaboration.d.ts +86 -0
  107. package/build/src/collaboration/record_collaboration.js +348 -0
  108. package/build/src/commands/agent_assets.d.ts +7 -0
  109. package/build/src/commands/agent_assets.js +66 -0
  110. package/build/src/commands/capabilities.d.ts +19 -0
  111. package/build/src/commands/capabilities.js +179 -0
  112. package/build/src/commands/doctor.d.ts +42 -0
  113. package/build/src/commands/doctor.js +375 -0
  114. package/build/src/commands/gap_report.d.ts +56 -0
  115. package/build/src/commands/gap_report.js +110 -0
  116. package/build/src/commands/generator.d.ts +1 -0
  117. package/build/src/commands/generator.js +70 -0
  118. package/build/src/commands/snapshot.d.ts +28 -0
  119. package/build/src/commands/snapshot.js +48 -0
  120. package/build/src/commands/source_markers.d.ts +11 -0
  121. package/build/src/commands/source_markers.js +41 -0
  122. package/build/src/core/activity.d.ts +43 -0
  123. package/build/src/core/activity.js +77 -0
  124. package/build/src/core/administration_guard.d.ts +3 -0
  125. package/build/src/core/administration_guard.js +39 -0
  126. package/build/src/core/health.d.ts +42 -0
  127. package/build/src/core/health.js +44 -0
  128. package/build/src/core/mail_test.d.ts +18 -0
  129. package/build/src/core/mail_test.js +88 -0
  130. package/build/src/core/message_templates.d.ts +83 -0
  131. package/build/src/core/message_templates.js +293 -0
  132. package/build/src/core/module_seed.d.ts +15 -0
  133. package/build/src/core/module_seed.js +31 -0
  134. package/build/src/core/notifications.d.ts +42 -0
  135. package/build/src/core/notifications.js +91 -0
  136. package/build/src/core/org_units.d.ts +30 -0
  137. package/build/src/core/org_units.js +123 -0
  138. package/build/src/core/roles.d.ts +98 -0
  139. package/build/src/core/roles.js +447 -0
  140. package/build/src/core/saved_views.d.ts +37 -0
  141. package/build/src/core/saved_views.js +164 -0
  142. package/build/src/core/settings.d.ts +29 -0
  143. package/build/src/core/settings.js +113 -0
  144. package/build/src/core/setup.d.ts +14 -0
  145. package/build/src/core/setup.js +89 -0
  146. package/build/src/core/ui_preferences.d.ts +12 -0
  147. package/build/src/core/ui_preferences.js +30 -0
  148. package/build/src/core/user_invitations.d.ts +23 -0
  149. package/build/src/core/user_invitations.js +144 -0
  150. package/build/src/core/users.d.ts +44 -0
  151. package/build/src/core/users.js +182 -0
  152. package/build/src/database/configure.d.ts +3 -0
  153. package/build/src/database/configure.js +41 -0
  154. package/build/src/database/schema.d.ts +52 -0
  155. package/build/src/database/schema.js +538 -0
  156. package/build/src/eslint/index.d.ts +3 -0
  157. package/build/src/eslint/index.js +90 -0
  158. package/build/src/events/adonis_jobs.d.ts +9 -0
  159. package/build/src/events/adonis_jobs.js +13 -0
  160. package/build/src/events/outbox.d.ts +19 -0
  161. package/build/src/events/outbox.js +33 -0
  162. package/build/src/events/record_mutation.d.ts +24 -0
  163. package/build/src/events/record_mutation.js +62 -0
  164. package/build/src/integrations/imports.d.ts +74 -0
  165. package/build/src/integrations/imports.js +333 -0
  166. package/build/src/integrations/inbound_webhooks.d.ts +94 -0
  167. package/build/src/integrations/inbound_webhooks.js +276 -0
  168. package/build/src/integrations/openapi.d.ts +39 -0
  169. package/build/src/integrations/openapi.js +323 -0
  170. package/build/src/integrations/print.d.ts +37 -0
  171. package/build/src/integrations/print.js +124 -0
  172. package/build/src/integrations/webhooks.d.ts +98 -0
  173. package/build/src/integrations/webhooks.js +298 -0
  174. package/build/src/mcp/tools.d.ts +8 -0
  175. package/build/src/mcp/tools.js +156 -0
  176. package/build/src/org/org_service.d.ts +2 -0
  177. package/build/src/org/org_service.js +16 -0
  178. package/build/src/resource/define_resource.d.ts +5 -0
  179. package/build/src/resource/define_resource.js +68 -0
  180. package/build/src/resource/registry.d.ts +12 -0
  181. package/build/src/resource/registry.js +101 -0
  182. package/build/src/resource/types.d.ts +155 -0
  183. package/build/src/resource/types.js +1 -0
  184. package/build/src/resource/values.d.ts +5 -0
  185. package/build/src/resource/values.js +88 -0
  186. package/build/src/services/backup.d.ts +14 -0
  187. package/build/src/services/backup.js +59 -0
  188. package/build/src/services/settings.d.ts +21 -0
  189. package/build/src/services/settings.js +30 -0
  190. package/build/src/upgrade/legacy.d.ts +27 -0
  191. package/build/src/upgrade/legacy.js +58 -0
  192. package/build/src/upgrade/rename.d.ts +17 -0
  193. package/build/src/upgrade/rename.js +94 -0
  194. package/build/src/version.d.ts +1 -0
  195. package/build/src/version.js +2 -0
  196. package/build/src/workflows/define_workflow.d.ts +124 -0
  197. package/build/src/workflows/define_workflow.js +123 -0
  198. package/build/src/workflows/engine.d.ts +141 -0
  199. package/build/src/workflows/engine.js +752 -0
  200. package/build/stubs/README.md +6 -0
  201. package/build/stubs/controller.stub +8 -0
  202. package/build/stubs/main.d.ts +5 -0
  203. package/build/stubs/main.js +5 -0
  204. package/build/stubs/main.ts +5 -0
  205. package/build/stubs/modules.stub +6 -0
  206. package/build/stubs/resource_contract.stub +1 -0
  207. package/build/stubs/resource_contract.txt +452 -0
  208. package/build/stubs/routes.stub +16 -0
  209. package/build/stubs/service.stub +9 -0
  210. package/package.json +95 -6
@@ -0,0 +1,141 @@
1
+ import type { Knex } from 'knex';
2
+ import type { Actor } from '../auth/ability.js';
3
+ import type { ResourceService } from '../admin/resource_service.js';
4
+ import type { ResourceRegistry } from '../resource/registry.js';
5
+ import type { JsonValue } from '../resource/types.js';
6
+ import type { DomainEvent, Listener } from '../events/outbox.js';
7
+ import type { HttpPoster } from '../integrations/webhooks.js';
8
+ import type { Assignments } from '../collaboration/assignments.js';
9
+ import { type WorkflowDefinition } from './define_workflow.js';
10
+ export type WorkflowRunStatus = 'pending_definition' | 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled';
11
+ export type WorkflowRun = {
12
+ id: string;
13
+ resource: string;
14
+ resourceLabel: string;
15
+ recordId: number;
16
+ /** The record title for the approver (#32); null in admin views or when not readable. */
17
+ recordTitle: string | null;
18
+ definition: string;
19
+ label: string;
20
+ version: number;
21
+ status: WorkflowRunStatus;
22
+ step: string | null;
23
+ stepLabel: string | null;
24
+ outcome: string | null;
25
+ attempts: number;
26
+ lastError: string | null;
27
+ wakeAt: string | null;
28
+ createdAt: string;
29
+ completedAt: string | null;
30
+ history: {
31
+ step: string | null;
32
+ event: string;
33
+ actorName: string | null;
34
+ detail: {
35
+ [key: string]: JsonValue;
36
+ };
37
+ at: string;
38
+ }[];
39
+ /** Open approval assigned to the viewer for this run, if any. */
40
+ myApproval: {
41
+ assignmentId: number;
42
+ title: string;
43
+ /** Set at a decision step: its outcomes in declaration order (#42). */
44
+ decision?: WorkflowDecisionForm;
45
+ } | null;
46
+ };
47
+ /** What an approver needs to take a decision at a decision step. */
48
+ export type WorkflowDecisionForm = {
49
+ outcomes: {
50
+ key: string;
51
+ label: string;
52
+ comment: 'optional' | 'required';
53
+ }[];
54
+ };
55
+ export type WorkflowOptions = {
56
+ post?: HttpPoster;
57
+ /** Test hook simulating a crash after a step's effect and before its commit. */
58
+ beforeCommit?: (run: {
59
+ id: string;
60
+ step: string;
61
+ }) => void | Promise<void>;
62
+ now?: () => Date;
63
+ };
64
+ /**
65
+ * Durable workflow engine over workflow_runs. Every step runs inside the run's
66
+ * row lock (FOR UPDATE); its database effects and the transition commit together,
67
+ * so a crash repeats at most the step's external calls (HTTP carries a stable
68
+ * Idempotency-Key). Failed steps retry with growing delays up to maxAttempts.
69
+ */
70
+ export declare class WorkflowEngine {
71
+ #private;
72
+ private db;
73
+ private registry;
74
+ private resources;
75
+ private actors;
76
+ private assignments;
77
+ private options;
78
+ constructor(db: Knex, registry: ResourceRegistry, resources: ResourceService, actors: {
79
+ load(id: number): Promise<Actor>;
80
+ }, assignments: Assignments, definitions: readonly WorkflowDefinition[], options?: WorkflowOptions);
81
+ register(definition: WorkflowDefinition): this;
82
+ /** The newest version of each workflow attached to a resource. */
83
+ private latestFor;
84
+ private definition;
85
+ /** Listeners: submitted documents start their workflow; cancelled ones stop it. */
86
+ listeners(): Listener[];
87
+ /** Claims the submission envelope written in the submit transaction. */
88
+ start(trx: Knex.Transaction, event: DomainEvent): Promise<void>;
89
+ /** Worker step: advances due runs, each under its own row lock. */
90
+ tick(limit?: number): Promise<number>;
91
+ /**
92
+ * Runs steps until the run waits, ends, fails or is scheduled later. The caller
93
+ * holds the row lock. Each step executes in a savepoint so a failing step leaves
94
+ * no partial effects behind.
95
+ */
96
+ private advance;
97
+ private execute;
98
+ /**
99
+ * Records an approver's decision. Only an open approval assigned to the actor
100
+ * counts, and the run is locked so concurrent decisions cannot both apply.
101
+ */
102
+ decide(runId: string, actor: Actor, decision: string, comment?: unknown): Promise<WorkflowRun>;
103
+ /** Administrators put a failed run back to its failed step. */
104
+ retry(runId: string, actorId: number): Promise<void>;
105
+ /**
106
+ * Explicit version migration for runs that have not finished: `mapStep` returns
107
+ * the equivalent step name in the new version.
108
+ */
109
+ migrateRuns(name: string, from: number, to: number, mapStep: (step: string) => string): Promise<number>;
110
+ runsFor(name: string, id: number, actor: Actor): Promise<WorkflowRun[]>;
111
+ run(runId: string, actor: Actor): Promise<WorkflowRun>;
112
+ /** Runs waiting for the actor's decision, newest first, on records they can still read. */
113
+ /**
114
+ * Runs waiting for this user's decision, newest first (at most 100). `runIds` narrows the
115
+ * inbox to those runs, for pages that list their own rows (My tasks).
116
+ */
117
+ inbox(actor: Actor, options?: {
118
+ runIds?: readonly string[];
119
+ }): Promise<WorkflowRun[]>;
120
+ failed(limit?: number): Promise<WorkflowRun[]>;
121
+ private present;
122
+ /** The outcomes an approver can choose at a decision step. */
123
+ private decisionForm;
124
+ private fail;
125
+ private cancelRuns;
126
+ private context;
127
+ /** Workflow writes are system writes attributed to the submitter, with history. */
128
+ private updateRecord;
129
+ private cancelDocument;
130
+ private recipients;
131
+ /** A role reference is its stable key; for compatibility a display name also matches. */
132
+ private roleId;
133
+ private canView;
134
+ private log;
135
+ private now;
136
+ }
137
+ /**
138
+ * Listeners resolved per call, so hosts can build the engine lazily (for example
139
+ * per request) while the listener list is fixed at boot from the registry.
140
+ */
141
+ export declare function workflowListeners(registry: ResourceRegistry, engine: () => WorkflowEngine): Listener[];