@aigile/core 0.2.1 → 0.4.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 (176) hide show
  1. package/dist/agent-config.d.ts +850 -0
  2. package/dist/agent-config.d.ts.map +1 -0
  3. package/dist/agent-config.js +111 -0
  4. package/dist/agent-config.js.map +1 -0
  5. package/dist/collections.d.ts +33 -1
  6. package/dist/collections.d.ts.map +1 -1
  7. package/dist/collections.js +33 -1
  8. package/dist/collections.js.map +1 -1
  9. package/dist/config-sections.d.ts +78 -0
  10. package/dist/config-sections.d.ts.map +1 -0
  11. package/dist/config-sections.js +42 -0
  12. package/dist/config-sections.js.map +1 -0
  13. package/dist/config.d.ts +6795 -445
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +724 -87
  16. package/dist/config.js.map +1 -1
  17. package/dist/domain/action-item.d.ts +409 -0
  18. package/dist/domain/action-item.d.ts.map +1 -0
  19. package/dist/domain/action-item.js +155 -0
  20. package/dist/domain/action-item.js.map +1 -0
  21. package/dist/domain/ai-call.d.ts +15 -11
  22. package/dist/domain/ai-call.d.ts.map +1 -1
  23. package/dist/domain/ai-call.js +2 -0
  24. package/dist/domain/ai-call.js.map +1 -1
  25. package/dist/domain/build.d.ts +47 -5
  26. package/dist/domain/build.d.ts.map +1 -1
  27. package/dist/domain/build.js +6 -0
  28. package/dist/domain/build.js.map +1 -1
  29. package/dist/domain/change-set.d.ts +216 -0
  30. package/dist/domain/change-set.d.ts.map +1 -0
  31. package/dist/domain/change-set.js +48 -0
  32. package/dist/domain/change-set.js.map +1 -0
  33. package/dist/domain/common.d.ts +6 -3
  34. package/dist/domain/common.d.ts.map +1 -1
  35. package/dist/domain/common.js +4 -1
  36. package/dist/domain/common.js.map +1 -1
  37. package/dist/domain/conflict.d.ts +8 -8
  38. package/dist/domain/conversation.d.ts +78 -8
  39. package/dist/domain/conversation.d.ts.map +1 -1
  40. package/dist/domain/conversation.js +2 -0
  41. package/dist/domain/conversation.js.map +1 -1
  42. package/dist/domain/deliverable.d.ts +235 -0
  43. package/dist/domain/deliverable.d.ts.map +1 -0
  44. package/dist/domain/deliverable.js +76 -0
  45. package/dist/domain/deliverable.js.map +1 -0
  46. package/dist/domain/index.d.ts +4 -1
  47. package/dist/domain/index.d.ts.map +1 -1
  48. package/dist/domain/index.js +4 -1
  49. package/dist/domain/index.js.map +1 -1
  50. package/dist/domain/message.d.ts +7 -7
  51. package/dist/domain/milestone.d.ts +11 -11
  52. package/dist/domain/organization.d.ts +2 -2
  53. package/dist/domain/project.d.ts +524 -3
  54. package/dist/domain/project.d.ts.map +1 -1
  55. package/dist/domain/project.js +38 -1
  56. package/dist/domain/project.js.map +1 -1
  57. package/dist/domain/question.d.ts +238 -26
  58. package/dist/domain/question.d.ts.map +1 -1
  59. package/dist/domain/question.js +49 -4
  60. package/dist/domain/question.js.map +1 -1
  61. package/dist/domain/reassignment.d.ts +23 -18
  62. package/dist/domain/reassignment.d.ts.map +1 -1
  63. package/dist/domain/reassignment.js +14 -6
  64. package/dist/domain/reassignment.js.map +1 -1
  65. package/dist/domain/reference.d.ts +595 -0
  66. package/dist/domain/reference.d.ts.map +1 -0
  67. package/dist/domain/reference.js +180 -0
  68. package/dist/domain/reference.js.map +1 -0
  69. package/dist/domain/release.d.ts +246 -10
  70. package/dist/domain/release.d.ts.map +1 -1
  71. package/dist/domain/release.js +6 -0
  72. package/dist/domain/release.js.map +1 -1
  73. package/dist/domain/review.d.ts +11 -11
  74. package/dist/domain/role-assignment.d.ts +5 -5
  75. package/dist/domain/role-assignment.js +1 -1
  76. package/dist/domain/role.d.ts +41 -6
  77. package/dist/domain/role.d.ts.map +1 -1
  78. package/dist/domain/role.js +12 -0
  79. package/dist/domain/role.js.map +1 -1
  80. package/dist/domain/spec.d.ts +197 -6
  81. package/dist/domain/spec.d.ts.map +1 -1
  82. package/dist/domain/spec.js +73 -1
  83. package/dist/domain/spec.js.map +1 -1
  84. package/dist/domain/sweep.d.ts +11 -11
  85. package/dist/domain/sweep.d.ts.map +1 -1
  86. package/dist/domain/sweep.js +1 -1
  87. package/dist/domain/sweep.js.map +1 -1
  88. package/dist/domain/track.d.ts +16 -16
  89. package/dist/domain/user.d.ts +50 -2
  90. package/dist/domain/user.d.ts.map +1 -1
  91. package/dist/domain/user.js +13 -0
  92. package/dist/domain/user.js.map +1 -1
  93. package/dist/domain/verification.d.ts +4 -4
  94. package/dist/id.d.ts +114 -0
  95. package/dist/id.d.ts.map +1 -0
  96. package/dist/id.js +204 -0
  97. package/dist/id.js.map +1 -0
  98. package/dist/ids.d.ts +0 -2
  99. package/dist/ids.d.ts.map +1 -1
  100. package/dist/ids.js +0 -5
  101. package/dist/ids.js.map +1 -1
  102. package/dist/index.d.ts +7 -0
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +7 -0
  105. package/dist/index.js.map +1 -1
  106. package/dist/jira.d.ts +26 -0
  107. package/dist/jira.d.ts.map +1 -0
  108. package/dist/jira.js +37 -0
  109. package/dist/jira.js.map +1 -0
  110. package/dist/outline.d.ts +64 -0
  111. package/dist/outline.d.ts.map +1 -0
  112. package/dist/outline.js +127 -0
  113. package/dist/outline.js.map +1 -0
  114. package/dist/plugins/action-source.d.ts +44 -0
  115. package/dist/plugins/action-source.d.ts.map +1 -0
  116. package/dist/plugins/action-source.js +2 -0
  117. package/dist/plugins/action-source.js.map +1 -0
  118. package/dist/plugins/ai.d.ts +5 -0
  119. package/dist/plugins/ai.d.ts.map +1 -1
  120. package/dist/plugins/blob-store.d.ts +36 -0
  121. package/dist/plugins/blob-store.d.ts.map +1 -0
  122. package/dist/plugins/blob-store.js +11 -0
  123. package/dist/plugins/blob-store.js.map +1 -0
  124. package/dist/plugins/datastore.d.ts +6 -0
  125. package/dist/plugins/datastore.d.ts.map +1 -1
  126. package/dist/plugins/design.d.ts +62 -0
  127. package/dist/plugins/design.d.ts.map +1 -0
  128. package/dist/plugins/design.js +2 -0
  129. package/dist/plugins/design.js.map +1 -0
  130. package/dist/plugins/git-host.d.ts +35 -0
  131. package/dist/plugins/git-host.d.ts.map +1 -0
  132. package/dist/plugins/git-host.js +2 -0
  133. package/dist/plugins/git-host.js.map +1 -0
  134. package/dist/plugins/index.d.ts +9 -0
  135. package/dist/plugins/index.d.ts.map +1 -1
  136. package/dist/plugins/index.js +9 -0
  137. package/dist/plugins/index.js.map +1 -1
  138. package/dist/plugins/registry.d.ts +360 -0
  139. package/dist/plugins/registry.d.ts.map +1 -0
  140. package/dist/plugins/registry.js +218 -0
  141. package/dist/plugins/registry.js.map +1 -0
  142. package/dist/plugins/release-gate.d.ts +53 -0
  143. package/dist/plugins/release-gate.d.ts.map +1 -0
  144. package/dist/plugins/release-gate.js +2 -0
  145. package/dist/plugins/release-gate.js.map +1 -0
  146. package/dist/plugins/spec-cache.d.ts +23 -0
  147. package/dist/plugins/spec-cache.d.ts.map +1 -0
  148. package/dist/plugins/spec-cache.js +2 -0
  149. package/dist/plugins/spec-cache.js.map +1 -0
  150. package/dist/plugins/spec-source.d.ts +177 -0
  151. package/dist/plugins/spec-source.d.ts.map +1 -0
  152. package/dist/plugins/spec-source.js +31 -0
  153. package/dist/plugins/spec-source.js.map +1 -0
  154. package/dist/plugins/test-runner.d.ts +68 -0
  155. package/dist/plugins/test-runner.d.ts.map +1 -0
  156. package/dist/plugins/test-runner.js +14 -0
  157. package/dist/plugins/test-runner.js.map +1 -0
  158. package/dist/preamble.d.ts +11 -0
  159. package/dist/preamble.d.ts.map +1 -0
  160. package/dist/preamble.js +12 -0
  161. package/dist/preamble.js.map +1 -0
  162. package/dist/prompts.d.ts +8 -0
  163. package/dist/prompts.d.ts.map +1 -0
  164. package/dist/prompts.js +13 -0
  165. package/dist/prompts.js.map +1 -0
  166. package/dist/settings.d.ts +90 -0
  167. package/dist/settings.d.ts.map +1 -0
  168. package/dist/settings.js +120 -0
  169. package/dist/settings.js.map +1 -0
  170. package/dist/template.d.ts +89 -0
  171. package/dist/template.d.ts.map +1 -0
  172. package/dist/template.js +9 -0
  173. package/dist/template.js.map +1 -0
  174. package/package.json +9 -3
  175. package/prompts/mission.md +3 -0
  176. package/prompts/preamble.md +37 -0
package/dist/config.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
- import { dirname, resolve } from 'node:path';
2
+ import { delimiter, dirname, isAbsolute, resolve } from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { getListenPort } from './mode.js';
5
5
  import { AI_EFFORTS } from './plugins/ai.js';
6
+ import { agentsOverrideSchema, agentsSectionsSchema } from './agent-config.js';
7
+ export { NEUTRAL_ALLOW, engineerConfigSchema, sandboxConfigSchema } from './config-sections.js';
8
+ export * from './agent-config.js';
6
9
  /**
7
10
  * Application configuration. Resolved by merging (in increasing precedence):
8
11
  * 1. schema defaults
@@ -28,53 +31,468 @@ export const gitFsConfigSchema = z.object({
28
31
  user: z.string().optional(),
29
32
  token: z.string().optional(),
30
33
  });
34
+ /**
35
+ * A database as the datastore (`@aigile/datastore-sql`): sqlite through
36
+ * node's own module (the file from `url`), postgres through `pg` loaded from
37
+ * the installation (the connection string from the environment variable
38
+ * `urlEnv` names). One `records` table and an append-only `revisions` table
39
+ * per installation; `tablePrefix` keeps several installations apart in one
40
+ * database.
41
+ */
42
+ export const sqlDatastoreConfigSchema = z.object({
43
+ engine: z.enum(['sqlite', 'postgres']).default('sqlite'),
44
+ /** A connection string with no secret in it (a sqlite file path). */
45
+ url: z.string().min(1).optional(),
46
+ urlEnv: z.string().min(1).default('AIGILE_DATASTORE_URL'),
47
+ tablePrefix: z.string().regex(/^[a-z_][a-z0-9_]*$/i, 'letters, digits and underscores').default('aigile_'),
48
+ authorName: z.string().default('aigile'),
49
+ authorEmail: z.string().default('aigile@localhost'),
50
+ });
51
+ /**
52
+ * MongoDB as the datastore (documentation/datastore.md "mongodb"): the
53
+ * connection string comes from the environment variable `urlEnv` names, never
54
+ * the config file; `database` and `collectionPrefix` keep installations apart.
55
+ */
56
+ export const mongoDatastoreConfigSchema = z.object({
57
+ urlEnv: z.string().min(1).default('AIGILE_DATASTORE_URL'),
58
+ database: z.string().min(1).default('aigile'),
59
+ collectionPrefix: z.string().regex(/^[a-z_][a-z0-9_]*$/i, 'letters, digits and underscores').default('aigile_'),
60
+ authorName: z.string().default('aigile'),
61
+ authorEmail: z.string().default('aigile@localhost'),
62
+ });
31
63
  export const oidcConfigSchema = z.object({
64
+ /** The provider's issuer URL (its discovery document is at `<issuer>/.well-known/openid-configuration`). */
32
65
  issuer: z.string(),
33
66
  clientId: z.string(),
34
- clientSecret: z.string(),
67
+ /** From the environment (AIGILE_OIDC_CLIENT_SECRET), never the config file; empty for a public client with PKCE only. */
68
+ clientSecret: z.string().default(''),
35
69
  scopes: z.array(z.string()).default(['openid', 'profile', 'email']),
70
+ /** Create the user on their first sign-in (by the token's email); off means only people already in the datastore may sign in. */
71
+ autoCreateUsers: z.boolean().default(true),
72
+ /** The app's public base URL for the callback (`<base>/api/auth/oidc/callback`); the request's own host when unset. */
73
+ redirectBaseUrl: z.string().optional(),
74
+ });
75
+ /**
76
+ * A Git repository of Markdown as a spec source (documentation/sources.md):
77
+ * every `*.md` under `path` on `branch` is mirrored as a spec, titled from its
78
+ * front matter `title` or its first heading, mapped by default to these
79
+ * organizations and projects (ids), overridable per file in its front matter
80
+ * (`organizations`, `projects`, `roles`). A private repository's token is read
81
+ * from the environment variable `tokenEnv` names, never from here.
82
+ */
83
+ export const gitSourceConfigSchema = z.object({
84
+ kind: z.literal('git'),
85
+ id: z.string().min(1).regex(/^[a-z0-9][a-z0-9._-]*$/i, 'a source id is letters, digits, dots, dashes and underscores'),
86
+ url: z.string().min(1),
87
+ branch: z.string().min(1).default('main'),
88
+ path: z.string().default(''),
89
+ organizationIds: z.array(z.string().min(1)).default([]),
90
+ projectIds: z.array(z.string().min(1)).default([]),
91
+ tokenEnv: z.string().min(1).default('AIGILE_SOURCE_TOKEN'),
92
+ /** The username git sends with the token; Bitbucket's repository access tokens use `x-token-auth`. */
93
+ user: z.string().min(1).default('x-token-auth'),
94
+ /** Never save to this repository from the workspace (edits stay drafts). */
95
+ readOnly: z.boolean().default(false),
96
+ });
97
+ /**
98
+ * A Confluence Cloud space as a spec source: every current page in the space
99
+ * (or those carrying one of `labels`) is mirrored as a spec, its page version
100
+ * the version, its body (storage format) rendered to Markdown. The API token
101
+ * and the account email come from the environment variables named here.
102
+ */
103
+ export const confluenceSourceConfigSchema = z.object({
104
+ kind: z.literal('confluence'),
105
+ id: z.string().min(1).regex(/^[a-z0-9][a-z0-9._-]*$/i, 'a source id is letters, digits, dots, dashes and underscores'),
106
+ /** The wiki's base, e.g. `https://acme.atlassian.net/wiki`. */
107
+ baseUrl: z.string().url(),
108
+ /**
109
+ * The Atlassian site's cloud id. Set it for a scoped API token (or a
110
+ * service account's), which Atlassian accepts only through its gateway
111
+ * (`https://api.atlassian.com/ex/<product>/<cloudId>`); `baseUrl` stays the
112
+ * site, for the links people follow.
113
+ */
114
+ cloudId: z.string().uuid().optional(),
115
+ spaceKey: z.string().min(1),
116
+ /** Only pages with at least one of these labels; every page in the space when empty. */
117
+ labels: z.array(z.string().min(1)).default([]),
118
+ /** Only these pages and everything under them (page or folder ids); the whole space when empty. */
119
+ rootPageIds: z.array(z.string().regex(/^\d+$/, 'a Confluence page id is digits')).default([]),
120
+ /** Leave out these pages and everything under them (an out-of-scope branch, a page holding credentials). */
121
+ excludePageIds: z.array(z.string().regex(/^\d+$/, 'a Confluence page id is digits')).default([]),
122
+ /** The spec this source's top documents sit under: a document of another source (its source id and external id, a Confluence page id), or a spec written in aigile (`{ specId }`, a heading for the source). */
123
+ under: z.union([z.object({ sourceId: z.string().min(1), externalId: z.string().min(1) }), z.object({ specId: z.string().min(1) })]).optional(),
124
+ /** Where the source's top pages apply (the roots, when given); the pages under them inherit. */
125
+ organizationIds: z.array(z.string().min(1)).default([]),
126
+ projectIds: z.array(z.string().min(1)).default([]),
127
+ /** Where Jira is, for the issue macros on pages (`https://acme.atlassian.net`); the wiki's own site (its base without `/wiki`) when unset, as on Atlassian Cloud. */
128
+ jiraBaseUrl: z.string().url().optional(),
129
+ tokenEnv: z.string().min(1).default('AIGILE_CONFLUENCE_TOKEN'),
130
+ /** The Atlassian account the token belongs to (Basic auth); a bearer token when unset (Data Center). */
131
+ emailEnv: z.string().min(1).default('AIGILE_CONFLUENCE_EMAIL'),
132
+ });
133
+ const sourceIdSchema = z.string().min(1).regex(/^[a-z0-9][a-z0-9._-]*$/i, 'a source id is letters, digits, dots, dashes and underscores');
134
+ const mappingDefaults = {
135
+ organizationIds: z.array(z.string().min(1)).default([]),
136
+ projectIds: z.array(z.string().min(1)).default([]),
137
+ under: z.union([z.object({ sourceId: z.string().min(1), externalId: z.string().min(1) }), z.object({ specId: z.string().min(1) })]).optional(),
138
+ };
139
+ /** Jira Cloud issues as a spec source: every issue the JQL returns (an epic's or a story's description) is a document. */
140
+ export const jiraSourceConfigSchema = z.object({
141
+ kind: z.literal('jira'),
142
+ id: sourceIdSchema,
143
+ /** The site, e.g. `https://acme.atlassian.net`. */
144
+ baseUrl: z.string().url(),
145
+ /**
146
+ * The Atlassian site's cloud id. Set it for a scoped API token (or a
147
+ * service account's), which Atlassian accepts only through its gateway
148
+ * (`https://api.atlassian.com/ex/<product>/<cloudId>`); `baseUrl` stays the
149
+ * site, for the links people follow.
150
+ */
151
+ cloudId: z.string().uuid().optional(),
152
+ /** Which issues are specs, e.g. `project = WF AND issuetype in (Epic, Story) AND statusCategory != Done`. */
153
+ jql: z.string().min(1),
154
+ /** The custom field holding an issue's feature flag key (e.g. `customfield_11893`), kept on the spec and given to a deliverable built from the epic. */
155
+ flagField: z.string().regex(/^customfield_\d+$/).optional(),
156
+ /** The project keys whose issue keys in an issue's text are references (`WF-123`); the ones the JQL names (`project = WF`, `project in (WF, TH)`) when empty. */
157
+ projectKeys: z.array(z.string().regex(/^[A-Z][A-Z0-9_]+$/, 'a Jira project key is upper-case letters and digits')).default([]),
158
+ /** Where Confluence is, to recognise links to its pages (`https://acme.atlassian.net/wiki`); the same site's `/wiki` when unset. */
159
+ confluenceBaseUrl: z.string().url().optional(),
160
+ ...mappingDefaults,
161
+ tokenEnv: z.string().min(1).default('AIGILE_JIRA_TOKEN'),
162
+ emailEnv: z.string().min(1).default('AIGILE_JIRA_EMAIL'),
163
+ });
164
+ /** Jira issues as action items: every issue the JQL returns is a task (or the type named), kept in step each tick. */
165
+ export const jiraActionSourceConfigSchema = z.object({
166
+ kind: z.literal('jira'),
167
+ id: sourceIdSchema,
168
+ baseUrl: z.string().url(),
169
+ cloudId: z.string().uuid().optional(),
170
+ /** Which issues are work to track, e.g. `project = WF AND sprint in openSprints()`. */
171
+ jql: z.string().min(1),
172
+ /** The action type the issues become (default `task`; a template's own type may be named). */
173
+ type: z.string().min(1).default('task'),
174
+ /** The aigile project the items belong to, if any. */
175
+ projectId: z.string().min(1).nullable().default(null),
176
+ /**
177
+ * The agent the items are for (e.g. `engineer`): each arrives as that agent's
178
+ * task, held until a person queues it. Null: nobody, until a person takes it
179
+ * or hands it on. Jira's own assignees are not carried over.
180
+ */
181
+ agentKey: z.string().min(1).nullable().default(null),
182
+ /**
183
+ * Resolving an item in aigile moves its issue through this transition and
184
+ * adds the resolution as a comment. Off by default (Ryan, 2026-11-28: built,
185
+ * not enabled yet).
186
+ */
187
+ writeBack: z
188
+ .object({
189
+ enabled: z.boolean().default(false),
190
+ /** The transition's name, e.g. `Done`. */
191
+ transition: z.string().min(1).default('Done'),
192
+ comment: z.boolean().default(true),
193
+ })
194
+ .default({}),
195
+ tokenEnv: z.string().min(1).default('AIGILE_JIRA_TOKEN'),
196
+ emailEnv: z.string().min(1).default('AIGILE_JIRA_EMAIL'),
197
+ });
198
+ /**
199
+ * Any service as a spec source over one HTTP endpoint that speaks aigile's
200
+ * own document contract (documentation/sources.md "The HTTP source"): a JSON
201
+ * array of documents, or `{ items, removed, cursor, full }` when the service
202
+ * can say what changed since the cursor it was given (`?since=`).
203
+ */
204
+ export const httpSourceConfigSchema = z.object({
205
+ kind: z.literal('http'),
206
+ id: sourceIdSchema,
207
+ url: z.string().url(),
208
+ ...mappingDefaults,
209
+ /** Sent as `Authorization: Bearer` when the variable is set. */
210
+ tokenEnv: z.string().min(1).default('AIGILE_HTTP_SOURCE_TOKEN'),
211
+ /** Extra request headers (never a secret: those come from `tokenEnv`). */
212
+ headers: z.record(z.string()).default({}),
213
+ });
214
+ /**
215
+ * An OpenAPI 3.x document (JSON) as specs (`@aigile/source-openapi`,
216
+ * documentation/sources.md "OpenAPI and Postman"): an overview spec and one
217
+ * spec per operation (or per tag), each rewritten only when what it renders
218
+ * changes.
219
+ */
220
+ export const openApiSourceConfigSchema = z.object({
221
+ kind: z.literal('openapi'),
222
+ id: sourceIdSchema,
223
+ /** Where the document is served (JSON). */
224
+ url: z.string().url(),
225
+ /** One spec per operation (default), or one per tag with its operations. */
226
+ groupBy: z.enum(['operation', 'tag']).default('operation'),
227
+ ...mappingDefaults,
228
+ /** Sent as `Authorization: Bearer` when the variable is set. */
229
+ tokenEnv: z.string().min(1).default('AIGILE_OPENAPI_TOKEN'),
230
+ /** Extra request headers (never a secret). */
231
+ headers: z.record(z.string()).default({}),
232
+ });
233
+ /** A Postman collection (v2.1 JSON) as specs: an overview, a spec per folder, and one per request (`@aigile/source-openapi`). */
234
+ export const postmanSourceConfigSchema = z.object({
235
+ kind: z.literal('postman'),
236
+ id: sourceIdSchema,
237
+ /** The collection's JSON: an exported file's URL, or the Postman API (`https://api.getpostman.com/collections/<uid>`). */
238
+ url: z.string().url(),
239
+ ...mappingDefaults,
240
+ /** A Postman API key, sent as `X-Api-Key` when the variable is set. */
241
+ tokenEnv: z.string().min(1).default('AIGILE_POSTMAN_API_KEY'),
242
+ headers: z.record(z.string()).default({}),
243
+ });
244
+ /**
245
+ * A database query as a spec source (`@aigile/source-sql`). sqlite needs no
246
+ * driver; postgres and mysql load `pg` and `mysql2` from the installation.
247
+ * The connection string comes from the environment variable `urlEnv` names,
248
+ * or from `url` when it holds no secret (a sqlite file).
249
+ */
250
+ export const sqlSourceConfigSchema = z.object({
251
+ kind: z.literal('sql'),
252
+ id: sourceIdSchema,
253
+ engine: z.enum(['postgres', 'mysql', 'sqlite']),
254
+ urlEnv: z.string().min(1).default('AIGILE_SQL_SOURCE_URL'),
255
+ /** A connection string with no secret in it (a sqlite file path); otherwise use `urlEnv`. */
256
+ url: z.string().min(1).optional(),
257
+ /** One read-only SELECT whose rows are documents. */
258
+ query: z.string().min(1),
259
+ /** Which columns carry what; `version` falls back to `updatedAt`, then to a hash of title and content. */
260
+ columns: z
261
+ .object({
262
+ id: z.string().min(1).default('id'),
263
+ title: z.string().min(1).default('title'),
264
+ content: z.string().min(1).default('content'),
265
+ updatedAt: z.string().min(1).default('updated_at'),
266
+ version: z.string().nullable().default(null),
267
+ authorName: z.string().nullable().default(null),
268
+ authorEmail: z.string().nullable().default(null),
269
+ url: z.string().nullable().default(null),
270
+ /** A column of project ids (a JSON array, an array, or comma-separated): the row then owns its mappings. */
271
+ projects: z.string().nullable().default(null),
272
+ organizations: z.string().nullable().default(null),
273
+ })
274
+ .default({}),
275
+ ...mappingDefaults,
36
276
  });
277
+ /**
278
+ * A MongoDB query as a spec source (`@aigile/source-documents`, documentation/sources.md
279
+ * "MongoDB"): every document the filter returns, read through `fields` like the SQL
280
+ * source's columns. The `mongodb` driver is loaded from the installation.
281
+ */
282
+ export const mongodbSourceConfigSchema = z.object({
283
+ kind: z.literal('mongodb'),
284
+ id: sourceIdSchema,
285
+ urlEnv: z.string().min(1).default('AIGILE_MONGODB_SOURCE_URL'),
286
+ database: z.string().min(1),
287
+ collection: z.string().min(1),
288
+ /** A filter document, as JSON. */
289
+ filter: z.record(z.unknown()).default({}),
290
+ /** Which fields carry what (dotted paths reach into subdocuments); `version` falls back to `updatedAt`, then to a hash of title and content. */
291
+ fields: z
292
+ .object({
293
+ id: z.string().default('_id'),
294
+ title: z.string().default('title'),
295
+ content: z.string().default('content'),
296
+ updatedAt: z.string().default('updatedAt'),
297
+ version: z.string().nullable().default(null),
298
+ authorName: z.string().nullable().default(null),
299
+ authorEmail: z.string().nullable().default(null),
300
+ url: z.string().nullable().default(null),
301
+ /** A field of project ids (an array, or comma-separated): the document then owns its mappings. */
302
+ projects: z.string().nullable().default(null),
303
+ organizations: z.string().nullable().default(null),
304
+ })
305
+ .default({}),
306
+ ...mappingDefaults,
307
+ });
308
+ /** The Markdown objects under an S3 prefix as a spec source (`@aigile/source-documents`); the object's ETag as the version, the default AWS credential chain. */
309
+ export const s3SourceConfigSchema = z.object({
310
+ kind: z.literal('s3'),
311
+ id: sourceIdSchema,
312
+ bucket: z.string().min(1),
313
+ prefix: z.string().default(''),
314
+ region: z.string().optional(),
315
+ /** The object key endings read as documents; other objects a document links to are its attachments. */
316
+ suffixes: z.array(z.string().min(1)).default(['.md', '.markdown']),
317
+ ...mappingDefaults,
318
+ });
319
+ /**
320
+ * A SharePoint site's pages and a library's Word and Markdown documents as a spec
321
+ * source, through Microsoft Graph (`@aigile/source-documents`): an Entra application's
322
+ * client id and secret (application permissions), or a token issued elsewhere.
323
+ */
324
+ export const sharepointSourceConfigSchema = z.object({
325
+ kind: z.literal('sharepoint'),
326
+ id: sourceIdSchema,
327
+ siteUrl: z.string().url(),
328
+ /** The folder of the library to read (and everything under it). */
329
+ folder: z.string().default('/'),
330
+ /** The document library's name (`Documents`, `Specs`); the site's default library when unset. */
331
+ library: z.string().min(1).optional(),
332
+ /** The Entra tenant (id or domain) the application is registered in. */
333
+ tenantId: z.string().min(1).optional(),
334
+ /** The site's pages (Site Pages) as specs. */
335
+ pages: z.boolean().default(true),
336
+ /** The library's Word (.docx) and Markdown documents as specs. */
337
+ documents: z.boolean().default(true),
338
+ ...mappingDefaults,
339
+ /** A Graph access token issued elsewhere, used as is (no refresh); the client credentials otherwise. */
340
+ tokenEnv: z.string().min(1).default('AIGILE_SHAREPOINT_TOKEN'),
341
+ clientIdEnv: z.string().min(1).default('AIGILE_SHAREPOINT_CLIENT_ID'),
342
+ clientSecretEnv: z.string().min(1).default('AIGILE_SHAREPOINT_CLIENT_SECRET'),
343
+ });
344
+ /** A Dropbox folder's Markdown files and Paper documents as a spec source (`@aigile/source-documents`); the file's `rev` as the version. */
345
+ export const dropboxSourceConfigSchema = z.object({
346
+ kind: z.literal('dropbox'),
347
+ id: sourceIdSchema,
348
+ folder: z.string().default('/'),
349
+ ...mappingDefaults,
350
+ /** A short-lived access token, used as is; the refresh token and app key otherwise. */
351
+ tokenEnv: z.string().min(1).default('AIGILE_DROPBOX_TOKEN'),
352
+ refreshTokenEnv: z.string().min(1).default('AIGILE_DROPBOX_REFRESH_TOKEN'),
353
+ appKeyEnv: z.string().min(1).default('AIGILE_DROPBOX_APP_KEY'),
354
+ /** The app secret, for an app whose refresh token was not issued with PKCE. */
355
+ appSecretEnv: z.string().min(1).default('AIGILE_DROPBOX_APP_SECRET'),
356
+ });
357
+ /** A Notion database's pages, or a page and its sub-pages, as a spec source (`@aigile/source-documents`); an internal integration's token. */
358
+ export const notionSourceConfigSchema = z.object({
359
+ kind: z.literal('notion'),
360
+ id: sourceIdSchema,
361
+ /** A database whose pages are specs (one of this or `rootPageId`). */
362
+ databaseId: z.string().min(1).optional(),
363
+ /** A page that, with every page under it, is specs. */
364
+ rootPageId: z.string().min(1).optional(),
365
+ /** A database query filter, as Notion's API takes it. */
366
+ filter: z.record(z.unknown()).optional(),
367
+ /** The `Notion-Version` header. */
368
+ notionVersion: z.string().min(1).default('2022-06-28'),
369
+ ...mappingDefaults,
370
+ tokenEnv: z.string().min(1).default('AIGILE_NOTION_TOKEN'),
371
+ });
372
+ /** A Google Drive folder of Google Docs as a spec source (`@aigile/source-documents`); the file's `version` as the version, each document exported as Markdown. */
373
+ export const googleDocsSourceConfigSchema = z.object({
374
+ kind: z.literal('google-docs'),
375
+ id: sourceIdSchema,
376
+ folderId: z.string().min(1),
377
+ /** Read the folders under it too. */
378
+ recursive: z.boolean().default(true),
379
+ /** Drive's own Markdown export, or HTML converted to Markdown here. */
380
+ format: z.enum(['markdown', 'html']).default('markdown'),
381
+ /** A user a service account acts as (domain-wide delegation). */
382
+ subject: z.string().min(1).optional(),
383
+ ...mappingDefaults,
384
+ /** A service account's JSON key, or an authorized user's JSON (a refresh token), in the environment. */
385
+ credentialsEnv: z.string().min(1).default('AIGILE_GOOGLE_CREDENTIALS'),
386
+ });
387
+ /** An AsyncAPI 2.x or 3.x document (JSON or YAML) as specs: an overview and one spec per channel or operation (`@aigile/source-openapi`). */
388
+ export const asyncApiSourceConfigSchema = z.object({
389
+ kind: z.literal('asyncapi'),
390
+ id: sourceIdSchema,
391
+ url: z.string().url(),
392
+ groupBy: z.enum(['channel', 'operation']).default('channel'),
393
+ ...mappingDefaults,
394
+ tokenEnv: z.string().min(1).default('AIGILE_ASYNCAPI_TOKEN'),
395
+ headers: z.record(z.string()).default({}),
396
+ });
397
+ /** A GraphQL schema (introspected from an endpoint, or an SDL file) as specs: an overview and one spec per root field or per type (`@aigile/source-openapi`). */
398
+ export const graphqlSourceConfigSchema = z.object({
399
+ kind: z.literal('graphql'),
400
+ id: sourceIdSchema,
401
+ /** The endpoint to introspect, or an SDL file's URL. */
402
+ url: z.string().url(),
403
+ /** `auto`: SDL when the URL ends in .graphql, .graphqls, .gql or .sdl, else introspection. */
404
+ mode: z.enum(['auto', 'introspection', 'sdl']).default('auto'),
405
+ groupBy: z.enum(['field', 'type']).default('field'),
406
+ ...mappingDefaults,
407
+ tokenEnv: z.string().min(1).default('AIGILE_GRAPHQL_TOKEN'),
408
+ headers: z.record(z.string()).default({}),
409
+ });
410
+ /**
411
+ * A repository's (or a list of URLs') `.proto` files as contract specs: an overview and one spec per
412
+ * service with its RPCs and their messages (`@aigile/source-openapi`, documentation/sources.md "Protocol Buffers").
413
+ * One of `repository` or `urls`.
414
+ */
415
+ export const protobufSourceConfigSchema = z.object({
416
+ kind: z.literal('protobuf'),
417
+ id: sourceIdSchema,
418
+ /** A git remote whose `.proto` files under `path` on `branch` are read (cloned without a working tree, as the git source does). */
419
+ repository: z.string().min(1).optional(),
420
+ branch: z.string().min(1).default('main'),
421
+ /** The folder of the repository to read ('' for all of it). */
422
+ path: z.string().default(''),
423
+ /** The username git sends with the token; Bitbucket's repository access tokens use `x-token-auth`. */
424
+ user: z.string().min(1).default('x-token-auth'),
425
+ /** Raw `.proto` file URLs, in place of a repository. */
426
+ urls: z.array(z.string().url()).default([]),
427
+ ...mappingDefaults,
428
+ /** A repository token (over HTTPS), or a bearer token sent with each URL. */
429
+ tokenEnv: z.string().min(1).default('AIGILE_PROTOBUF_TOKEN'),
430
+ headers: z.record(z.string()).default({}),
431
+ });
432
+ /** A Box folder's Word, Markdown and Box Notes documents as a spec source (`@aigile/source-documents`); a JWT application's config or a developer token. */
433
+ export const boxSourceConfigSchema = z.object({
434
+ kind: z.literal('box'),
435
+ id: sourceIdSchema,
436
+ folderId: z.string().min(1),
437
+ /** Read the folders under it too. */
438
+ recursive: z.boolean().default(true),
439
+ ...mappingDefaults,
440
+ /** The JWT application's JSON config (the file the Developer Console downloads, with its private key) in the environment. */
441
+ jwtConfigEnv: z.string().min(1).default('AIGILE_BOX_JWT_CONFIG'),
442
+ /** A developer token (60 minutes), used as is: for a trial. */
443
+ tokenEnv: z.string().min(1).default('AIGILE_BOX_TOKEN'),
444
+ });
445
+ export const sourceConfigSchema = z.discriminatedUnion('kind', [gitSourceConfigSchema, confluenceSourceConfigSchema, jiraSourceConfigSchema, httpSourceConfigSchema, openApiSourceConfigSchema, postmanSourceConfigSchema, sqlSourceConfigSchema, mongodbSourceConfigSchema, s3SourceConfigSchema, sharepointSourceConfigSchema, dropboxSourceConfigSchema, notionSourceConfigSchema, googleDocsSourceConfigSchema, asyncApiSourceConfigSchema, graphqlSourceConfigSchema, protobufSourceConfigSchema, boxSourceConfigSchema]);
446
+ /** The kinds the runtime can run today. */
447
+ export const BUILT_SOURCE_KINDS = ['git', 'confluence', 'jira', 'http', 'openapi', 'postman', 'sql', 'mongodb', 's3', 'sharepoint', 'dropbox', 'notion', 'google-docs', 'asyncapi', 'graphql', 'protobuf', 'box'];
37
448
  export const agentAiConfigSchema = z.object({
38
449
  model: z.string().optional(),
39
450
  effort: z.enum(AI_EFFORTS).optional(),
40
451
  });
41
452
  /** What the Engineer agent may do in a checkout (documentation/agents.md §5). */
42
- export const engineerConfigSchema = z.object({
43
- /** First words of commands it may run; anything else is refused. `git push` is refused whatever the list says. */
44
- allow: z.array(z.string()).default(['ls', 'cat', 'head', 'tail', 'grep', 'find', 'wc', 'diff', 'sed', 'awk', 'sort', 'uniq', 'echo', 'pwd', 'test', 'tree', 'git', 'npm', 'npx', 'node', 'yarn', 'pnpm', 'make', 'cargo', 'go', 'python3', 'pytest', 'mvn', 'gradle']),
45
- /** Output tokens across the whole build; the run stops gracefully at it. */
46
- budgetTokens: z.number().int().positive().default(200_000),
47
- /** Wall clock for one command and for the whole build. */
48
- commandTimeoutMs: z.number().int().positive().default(10 * 60 * 1000),
49
- buildTimeoutMs: z.number().int().positive().default(60 * 60 * 1000),
50
- /** Start a build on its own once spec revisions settle; off, since every build spends money. */
51
- autoBuild: z.boolean().default(false),
52
- /** The Engineer proposes a plan first and builds only after a person approves it. */
53
- planGate: z.boolean().default(true),
54
- });
55
453
  /**
56
454
  * Where the agents' commands run. `auto` uses a container when podman or
57
455
  * docker is on PATH, else the host with one warning; `container` never falls
58
456
  * back. The installation's `.aigile/work` is mounted at the same absolute
59
457
  * path, with no network and bounded memory, cpus and processes.
60
458
  */
61
- export const sandboxConfigSchema = z.object({
62
- runtime: z.enum(['auto', 'host', 'container']).default('auto'),
63
- engine: z.enum(['auto', 'podman', 'docker']).default('auto'),
64
- image: z.string().min(1).default('node:22-bookworm'),
65
- /** Project id → image, for a project whose checks need another toolchain. */
66
- imageByProject: z.record(z.string().min(1)).default({}),
67
- memory: z.string().min(1).default('2g'),
68
- cpus: z.number().positive().default(2),
69
- pids: z.number().int().positive().default(512),
70
- /** More `run` arguments (a `--network` for a project that must reach a registry, say). */
71
- extraArgs: z.array(z.string()).default([]),
72
- });
73
459
  export const configSchema = z.object({
460
+ /**
461
+ * Who may change a project's deliverables (documentation/agents.md
462
+ * "Deliverables"), by role name, beside the installation's owners and
463
+ * admins: who sets their order and starts or pauses them, and who marks
464
+ * them done.
465
+ */
466
+ deliverables: z
467
+ .object({
468
+ prioritizeRoles: z.array(z.string().min(1)).default(['Project Manager']),
469
+ completeRoles: z.array(z.string().min(1)).default(['Product Manager']),
470
+ })
471
+ .default({}),
472
+ /**
473
+ * Live updates over gatecast (documentation/events.md "Live updates"): the
474
+ * web server attaches it when the optional `gatecast` package is installed.
475
+ * `relayFrom` is a deployed aigile whose webhooks a local one takes in, with
476
+ * an API token of an admin there in `AIGILE_RELAY_TOKEN`.
477
+ */
478
+ /**
479
+ * The older place of the software template's settings (documentation/tests.md
480
+ * "Settings"), kept so a file that has it still parses and still works: read
481
+ * by the software template under `templateSettings.software`, which wins.
482
+ */
483
+ tests: z.record(z.unknown()).optional(),
484
+ realtime: z
485
+ .object({
486
+ enabled: z.boolean().default(true),
487
+ relayFrom: z.string().url().nullable().default(null),
488
+ })
489
+ .default({}),
74
490
  dataStore: z
75
491
  .object({
76
492
  plugin: z.string().default('git-fs'),
77
493
  gitFs: gitFsConfigSchema.default({}),
494
+ sql: sqlDatastoreConfigSchema.default({}),
495
+ mongodb: mongoDatastoreConfigSchema.default({}),
78
496
  })
79
497
  .default({}),
80
498
  auth: z
@@ -103,80 +521,227 @@ export const configSchema = z.object({
103
521
  roles: z.record(agentAiConfigSchema).default({}),
104
522
  })
105
523
  .default({}),
106
- /** The agents' permission policy. */
107
- agents: z
524
+ /** The agents' permission policy: the installation's sections, and per-template overrides (`templates.<id>`); a project's own overrides live on the project. */
525
+ agents: agentsSectionsSchema
526
+ .extend({
527
+ templates: z.record(agentsOverrideSchema).default({}),
528
+ })
529
+ .default({}),
530
+ server: z
108
531
  .object({
109
- engineer: engineerConfigSchema.default({}),
110
- sandbox: sandboxConfigSchema.default({}),
111
- /** Open a pull request on the host when a build is approved (tokens from the environment: AIGILE_<HOST>_TOKEN). */
112
- pullRequests: z.object({ enabled: z.boolean().default(true) }).default({}),
113
- /** The project's checks, run by aigile on every proposed build in a clean worktree (empty: skipped). */
114
- verifier: z
115
- .object({
116
- checks: z.array(z.string().min(1)).default([]),
117
- checksByProject: z.record(z.array(z.string().min(1))).default({}),
118
- timeoutMs: z.number().int().positive().default(20 * 60 * 1000),
119
- /** The Verifier agent adds tests that prove a build's change (where checks exist to run them). */
120
- writeTests: z.boolean().default(true),
121
- /** Where it may write: directory prefixes or `*.ext` patterns, relative to the checkout. */
122
- testPaths: z.array(z.string().min(1)).default(['test/', 'tests/', '__tests__/', 'spec/', '*.test.*', '*.spec.*']),
123
- })
124
- .default({}),
125
- /** The Monitor: the installation's read-only probes, swept on a cadence and after each merge. */
126
- monitor: z
532
+ port: z.number().int().positive().default(3000),
533
+ })
534
+ .default({}),
535
+ /**
536
+ * Where the installation's working files live (the Engineer's checkouts under
537
+ * `.aigile/work`, the reviewers' worktrees): the config file's directory by
538
+ * default. A pod whose config is baked into the image points this at its volume.
539
+ */
540
+ workRoot: z.string().optional(),
541
+ /**
542
+ * The spec cache (documentation/sources.md "The model"): where the versions
543
+ * read from the sources are kept. `memory` for one process; `file` for a
544
+ * directory on a volume (`.aigile/cache` under the install root by default);
545
+ * `redis` for a cluster (`AIGILE_REDIS_URL`); `datastore` to reuse the
546
+ * datastore as configured, with nothing more to set.
547
+ */
548
+ cache: z
549
+ .object({
550
+ plugin: z.enum(['memory', 'file', 'redis', 'datastore']).default('memory'),
551
+ memory: z.object({ maxEntries: z.number().int().positive().default(5000) }).default({}),
552
+ file: z.object({ dir: z.string().optional() }).default({}),
553
+ redis: z.object({ urlEnv: z.string().min(1).default('AIGILE_REDIS_URL'), keyPrefix: z.string().default('aigile:') }).default({}),
554
+ })
555
+ .default({}),
556
+ /** Where a spec written in the workspace is saved: a writable source's id, or null for the datastore itself. */
557
+ specs: z
558
+ .object({
559
+ source: z.string().min(1).nullable().default(null),
560
+ })
561
+ .default({}),
562
+ /** The spec sources mirrored into the datastore (documentation/sources.md); ids are unique. */
563
+ sources: z
564
+ .array(sourceConfigSchema)
565
+ .default([])
566
+ .refine((list) => new Set(list.map((s) => s.id)).size === list.length, 'source ids must be unique'),
567
+ /**
568
+ * Files attached to or referenced by mirrored documents
569
+ * (documentation/sources.md "Links and attachments"): downloaded through the
570
+ * source's credentials at the sync, their text extracted by code (PDF, Word,
571
+ * Excel, PowerPoint, HTML, text), kept in `attachments`. Nothing above
572
+ * `maxBytes` is downloaded; the original bytes are kept only under
573
+ * `keepOriginalsUnderBytes` (0: never); `mediaTypes` is the allowlist
574
+ * (`type/*` matches a whole type), others are kept as metadata only.
575
+ */
576
+ attachments: z
577
+ .object({
578
+ enabled: z.boolean().default(true),
579
+ maxBytes: z.number().int().nonnegative().default(50 * 1024 * 1024),
580
+ keepOriginalsUnderBytes: z.number().int().nonnegative().default(0),
581
+ mediaTypes: z
582
+ .array(z.string().min(1))
583
+ .default([
584
+ 'application/pdf',
585
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
586
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
587
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
588
+ 'text/*',
589
+ 'application/json',
590
+ 'application/xml',
591
+ 'image/*',
592
+ ]),
593
+ })
594
+ .default({}),
595
+ /**
596
+ * Where outside work comes in as action items (documentation/action-items.md
597
+ * "Action sources"): a Jira query's issues as tasks, synced each tick. Ids are
598
+ * unique. Writing back to the source is off unless `writeBack.enabled`.
599
+ */
600
+ actionSources: z
601
+ .array(jiraActionSourceConfigSchema)
602
+ .default([])
603
+ .refine((list) => new Set(list.map((s) => s.id)).size === list.length, 'action source ids must be unique'),
604
+ /** Where people reach this workspace (e.g. https://aigile.example.com), for links in notices and in Jira; none: notices carry no link. */
605
+ publicUrl: z.string().url().nullable().default(null),
606
+ /**
607
+ * Plugins (documentation/plugins.md): the installation's own plugin modules
608
+ * (npm packages, or paths relative to the config file, each exporting
609
+ * `plugins`), and the instances to start, each with its settings (checked
610
+ * against the plugin's schema) and the environment variables its secrets
611
+ * are read from. Built-in plugins need no module.
612
+ */
613
+ plugins: z
614
+ .object({
615
+ modules: z.array(z.string().min(1)).default([]),
616
+ /** Find plugin modules at start (documentation/plugins.md "Discovery"): the files in `folder`, and the node_modules packages whose package.json names a module in `aigile.plugins`. Off: only the built-in plugins and `modules`. */
617
+ discover: z.boolean().default(true),
618
+ /** The plugins folder, relative to the installation's root: each `*.mjs`/`*.js` file, or folder with an index, is a plugin module. */
619
+ folder: z.string().min(1).default('plugins'),
620
+ /** Plugins folders that replace `folder` (`--plugins <folder>`, AIGILE_PLUGINS_FOLDER): absolute, or relative to the installation's root. Each is read even with `discover` off, since it was named. */
621
+ folders: z.array(z.string().min(1)).default([]),
622
+ /** Minutes after which configuration sources are read again (0: only at start); a test run reads them again when older than a minute. */
623
+ configRefreshMinutes: z.number().int().min(0).default(15),
624
+ instances: z
625
+ .array(z.object({
626
+ plugin: z.string().min(1),
627
+ id: z.string().min(1).regex(/^[a-z0-9][a-z0-9-]*$/),
628
+ config: z.record(z.string(), z.unknown()).default({}),
629
+ secrets: z.record(z.string(), z.string().min(1)).default({}),
630
+ /** A configuration source for one test target (qa, stage): its values go only to test runs against it. */
631
+ target: z.string().min(1).nullable().default(null),
632
+ }))
633
+ .default([]),
634
+ })
635
+ .default({}),
636
+ /**
637
+ * Design sources (documentation/designs.md): where specs' design links point,
638
+ * rendered for people and the Code Reviewer to compare with the build. Each
639
+ * plugin finds its own links; rendering needs its token. Ids are unique.
640
+ */
641
+ designs: z
642
+ .array(z.object({
643
+ kind: z.literal('figma'),
644
+ id: z.string().min(1).regex(/^[a-z0-9][a-z0-9-]*$/),
645
+ /** The environment variable holding a Figma personal access token (read-only file access is enough). */
646
+ tokenEnv: z.string().min(1).default('AIGILE_FIGMA_TOKEN'),
647
+ /** Render scale, 0.5 to 4 (default 1: a frame at its own size). */
648
+ scale: z.number().min(0.5).max(4).default(1),
649
+ /** The longest outline (inspect_design) in characters; deeper layers are cut with a note saying how to see them. */
650
+ outlineMaxChars: z.number().int().min(2000).max(400_000).default(40_000),
651
+ }))
652
+ .default([{ kind: 'figma', id: 'figma', tokenEnv: 'AIGILE_FIGMA_TOKEN', scale: 1, outlineMaxChars: 40_000 }])
653
+ .refine((list) => new Set(list.map((s) => s.id)).size === list.length, 'design source ids must be unique'),
654
+ /**
655
+ * A feature's Jira tickets follow the feature (documentation/action-items.md
656
+ * "Jira"): a comment on each ticket linking it to the feature, then comments
657
+ * and transitions as the feature moves. Every one is a write to Jira, so it
658
+ * is off until an installation switches it on.
659
+ */
660
+ jira: z
661
+ .object({
662
+ featureSync: z
127
663
  .object({
128
- probes: z.array(z.object({ name: z.string().min(1), command: z.string().min(1), projectId: z.string().min(1).nullable().default(null) })).default([]),
129
- cadenceMinutes: z.number().int().positive().default(60),
130
- auditDelaysMinutes: z.array(z.number().int().positive()).default([15, 180]),
131
- /** Probes need the network: the host by default; `sandbox` runs them through the agents' runner. */
132
- runtime: z.enum(['host', 'sandbox']).default('host'),
133
- timeoutMs: z.number().int().positive().default(2 * 60 * 1000),
134
- /** Who gets an incident when the project has no ranked approver. */
135
- notifyUserId: z.string().min(1).nullable().default(null),
664
+ enabled: z.boolean().default(false),
665
+ /** The Jira spec source or action source whose site and credentials to use (its id); the first Jira one when null. */
666
+ connection: z.string().min(1).nullable().default(null),
667
+ /**
668
+ * The status to move a feature's tickets to at each event, by the target
669
+ * status's name in the Jira workflow (matched against each issue's available
670
+ * transitions; skipped when the issue has none to it). Ryan's mapping for the
671
+ * WF workflow by default: a build starts → In Progress; a build is up for
672
+ * review → Under Review; a person approved it, not merged yet → Pending Merge;
673
+ * merged → QA. A configured object replaces the whole mapping; an event left
674
+ * out only comments. aigile never moves a ticket to a done status (Resolved,
675
+ * Closed) on its own: a target in `ticketStates.done` is refused.
676
+ */
677
+ transitions: z
678
+ .object({
679
+ started: z.string().min(1).optional(),
680
+ proposed: z.string().min(1).optional(),
681
+ approved: z.string().min(1).optional(),
682
+ merged: z.string().min(1).optional(),
683
+ done: z.string().min(1).optional(),
684
+ })
685
+ .default({ started: 'In Progress', proposed: 'Under Review', approved: 'Pending Merge', merged: 'QA' }),
686
+ /** Releases to these environments are noted on the tickets (e.g. ["prod"]); empty: every environment. */
687
+ environments: z.array(z.string().min(1)).default([]),
688
+ /** The workspace's address, for the link to the feature's dashboard (e.g. https://aigile.example.com); the feature's title only when unset. */
689
+ publicUrl: z.string().url().nullable().default(null),
136
690
  })
137
691
  .default({}),
138
- /** The Release Manager: the environments in order and how a release reaches each (commands the installation configures). */
139
- release: z
692
+ /**
693
+ * What a ticket's Jira status means for aigile's agents (documentation/action-items.md
694
+ * "Ticket states"), by status name first (case-insensitive), then by status category
695
+ * (its name or key). `actionable`: the Engineer may work on it. `inFlight`: a person
696
+ * owns it; nobody changes its code and aigile never transitions it. `done`: may be
697
+ * checked for completeness, never changed without a person's approval. Defaults: Final
698
+ * Draft's WF workflow.
699
+ */
700
+ ticketStates: z
140
701
  .object({
141
- environments: z
142
- .array(z.object({
143
- name: z.string().min(1),
144
- deploy: z.string().min(1),
145
- verify: z.string().min(1).nullable().default(null),
146
- rollback: z.string().min(1).nullable().default(null),
147
- /** A person's go before the deploy; always true for now (nothing deploys on the clock). */
148
- requiresGo: z.boolean().default(true),
149
- /** Have the Monitor audit after the deploy at agents.monitor.auditDelaysMinutes. */
150
- auditAfter: z.boolean().default(false),
151
- }))
152
- .default([]),
153
- /** Deploy commands need credentials and the network: the host by default. */
154
- runtime: z.enum(['host', 'sandbox']).default('host'),
155
- timeoutMs: z.number().int().positive().default(30 * 60 * 1000),
156
- notifyUserId: z.string().min(1).nullable().default(null),
702
+ actionable: z.array(z.string().min(1)).default(['Open', 'To Do', 'Reopened']),
703
+ inFlight: z.array(z.string().min(1)).default(['In Progress', 'Pending Review', 'Under Review', 'Pending Merge', 'QA', 'Needs Test', 'Blocked For Testing']),
704
+ done: z.array(z.string().min(1)).default(['Resolved', 'Closed']),
705
+ /** By status category, for a status none of the lists name: Jira's category names and keys. */
706
+ categories: z
707
+ .object({
708
+ actionable: z.array(z.string().min(1)).default(['To Do', 'new']),
709
+ inFlight: z.array(z.string().min(1)).default(['In Progress', 'indeterminate']),
710
+ done: z.array(z.string().min(1)).default(['Done', 'done']),
711
+ })
712
+ .default({}),
713
+ /** How old a feature's ticket statuses may be before a build reads them again (minutes). */
714
+ maxAgeMinutes: z.number().int().min(0).default(5),
157
715
  })
158
716
  .default({}),
159
- /** The Orchestrator's clock: the merge sync every tick, and automatic builds (engineer.autoBuild) once revisions settle for quietSeconds. */
160
- schedule: z
717
+ /**
718
+ * The software template's QA queue (documentation/tests.md "QA queue"): the Jira tickets
719
+ * waiting for testing, with their automated tests, and "Mark complete".
720
+ */
721
+ qa: z
161
722
  .object({
162
- enabled: z.boolean().default(true),
163
- tickSeconds: z.number().int().positive().default(60),
164
- quietSeconds: z.number().int().nonnegative().default(300),
723
+ /** The statuses that put a ticket in the queue. */
724
+ statuses: z.array(z.string().min(1)).default(['QA', 'Needs Test']),
725
+ /** The JQL the queue narrows (e.g. `project = WF AND parent = WF-4090`); null: `project = <key>` of the Jira connection's JQL. */
726
+ jql: z.string().min(1).nullable().default(null),
727
+ /** The Jira spec source or action source to read and write through (its id); `featureSync.connection`, else the first Jira one, when null. */
728
+ connection: z.string().min(1).nullable().default(null),
729
+ /** The status "Mark complete" moves a ticket to (a person's action, never aigile's own). */
730
+ completeStatus: z.string().min(1).default('Resolved'),
731
+ /** "Mark complete" writes to Jira (a transition and a comment); off until an installation switches it on. */
732
+ writeBack: z.boolean().default(false),
165
733
  })
166
734
  .default({}),
167
735
  })
168
736
  .default({}),
169
- server: z
737
+ /** The installed templates: which one a project gets when none is chosen, and whose Monitor and Release Manager serve the installation. */
738
+ templates: z
170
739
  .object({
171
- port: z.number().int().positive().default(3000),
740
+ default: z.string().min(1).default('software'),
172
741
  })
173
742
  .default({}),
174
- /**
175
- * Where the installation's working files live (the Engineer's checkouts under
176
- * `.aigile/work`, the reviewers' worktrees): the config file's directory by
177
- * default. A pod whose config is baked into the image points this at its volume.
178
- */
179
- workRoot: z.string().optional(),
743
+ /** Each template's own settings, by template id (documentation/templates.md "What a template adds"), checked by the template's schema when it loads. */
744
+ templateSettings: z.record(z.unknown()).default({}),
180
745
  /**
181
746
  * An installation's identity in the UI. `logo` and `favicon` are paths
182
747
  * relative to the config file (inside the repository); the web app serves
@@ -202,7 +767,7 @@ function readConfigFile(path) {
202
767
  return parsed;
203
768
  }
204
769
  catch (err) {
205
- throw new Error(`Failed to read AIGILE_CONFIG at "${path}": ${err.message}`);
770
+ throw new Error(`Failed to read AIGILE_CONFIG at "${path}": ${err.message}`, { cause: err });
206
771
  }
207
772
  }
208
773
  function bool(raw) {
@@ -226,10 +791,20 @@ function envOverrides(env) {
226
791
  set(gitFs, 'authorEmail', env.AIGILE_GITFS_AUTHOR_EMAIL);
227
792
  set(gitFs, 'user', env.AIGILE_GITFS_USER);
228
793
  set(gitFs, 'token', env.AIGILE_GITFS_TOKEN);
794
+ const sql = {};
795
+ set(sql, 'engine', env.AIGILE_DATASTORE_ENGINE);
796
+ set(sql, 'tablePrefix', env.AIGILE_DATASTORE_TABLE_PREFIX);
229
797
  const dataStore = {};
230
798
  set(dataStore, 'plugin', env.AIGILE_DATASTORE_PLUGIN);
231
799
  if (Object.keys(gitFs).length > 0)
232
800
  dataStore.gitFs = gitFs;
801
+ if (Object.keys(sql).length > 0)
802
+ dataStore.sql = sql;
803
+ const mongodb = {};
804
+ set(mongodb, 'database', env.AIGILE_DATASTORE_DATABASE);
805
+ set(mongodb, 'collectionPrefix', env.AIGILE_DATASTORE_COLLECTION_PREFIX);
806
+ if (Object.keys(mongodb).length > 0)
807
+ dataStore.mongodb = mongodb;
233
808
  const auth = {};
234
809
  set(auth, 'plugin', env.AIGILE_AUTH_PLUGIN);
235
810
  set(auth, 'sessionSecret', env.AIGILE_SESSION_SECRET);
@@ -237,6 +812,16 @@ function envOverrides(env) {
237
812
  if (env.AIGILE_SESSION_TTL !== undefined) {
238
813
  set(auth, 'sessionTtlSeconds', Number.parseInt(env.AIGILE_SESSION_TTL, 10));
239
814
  }
815
+ const oidc = {};
816
+ set(oidc, 'issuer', env.AIGILE_OIDC_ISSUER);
817
+ set(oidc, 'clientId', env.AIGILE_OIDC_CLIENT_ID);
818
+ set(oidc, 'clientSecret', env.AIGILE_OIDC_CLIENT_SECRET);
819
+ if (env.AIGILE_OIDC_SCOPES)
820
+ set(oidc, 'scopes', env.AIGILE_OIDC_SCOPES.split(/[\s,]+/).filter(Boolean));
821
+ set(oidc, 'autoCreateUsers', bool(env.AIGILE_OIDC_AUTO_CREATE_USERS));
822
+ set(oidc, 'redirectBaseUrl', env.AIGILE_OIDC_REDIRECT_BASE_URL);
823
+ if (Object.keys(oidc).length > 0)
824
+ auth.oidc = oidc;
240
825
  const ai = {};
241
826
  set(ai, 'plugin', env.AIGILE_AI_PLUGIN);
242
827
  set(ai, 'model', env.AIGILE_AI_MODEL);
@@ -250,15 +835,30 @@ function envOverrides(env) {
250
835
  const agents = {};
251
836
  if (Object.keys(sandbox).length > 0)
252
837
  agents.sandbox = sandbox;
838
+ const cache = {};
839
+ set(cache, 'plugin', env.AIGILE_CACHE_PLUGIN);
840
+ if (env.AIGILE_CACHE_DIR)
841
+ cache.file = { dir: env.AIGILE_CACHE_DIR };
253
842
  const top = {};
254
843
  set(top, 'workRoot', env.AIGILE_WORK_ROOT);
844
+ set(top, 'publicUrl', env.AIGILE_PUBLIC_URL);
845
+ if (Object.keys(cache).length > 0)
846
+ top.cache = cache;
847
+ if (env.AIGILE_SPECS_SOURCE !== undefined)
848
+ top.specs = { source: env.AIGILE_SPECS_SOURCE || null };
255
849
  const server = {};
256
850
  const port = getListenPort(env);
257
851
  if (port !== null)
258
852
  server.port = port;
853
+ const realtime = {};
854
+ set(realtime, 'enabled', bool(env.AIGILE_REALTIME));
855
+ if (env.AIGILE_RELAY_FROM !== undefined)
856
+ realtime.relayFrom = env.AIGILE_RELAY_FROM || null;
259
857
  const out = {};
260
858
  if (Object.keys(dataStore).length > 0)
261
859
  out.dataStore = dataStore;
860
+ if (Object.keys(realtime).length > 0)
861
+ out.realtime = realtime;
262
862
  if (Object.keys(auth).length > 0)
263
863
  out.auth = auth;
264
864
  if (Object.keys(ai).length > 0)
@@ -322,6 +922,7 @@ export function loadConfig(env = process.env, cwd = process.cwd()) {
322
922
  if (path !== null && env.AIGILE_GITFS_ROOT === undefined) {
323
923
  config.dataStore.gitFs.root = resolve(dirname(path), config.dataStore.gitFs.root);
324
924
  }
925
+ applyPluginEnv(config, env, cwd);
325
926
  if (path !== null) {
326
927
  const base = dirname(path);
327
928
  if (config.branding.logo)
@@ -333,4 +934,40 @@ export function loadConfig(env = process.env, cwd = process.cwd()) {
333
934
  }
334
935
  return config;
335
936
  }
937
+ /**
938
+ * The plugin folders and modules named on the command line or in the
939
+ * environment (`--plugins`/`--plugin`, documentation/plugins.md "Discovery"):
940
+ * AIGILE_PLUGINS_FOLDER replaces `plugins.folder` with its folders, and
941
+ * AIGILE_PLUGIN_MODULES adds its modules after `plugins.modules`; both are
942
+ * lists separated by the OS path delimiter (`:`, `;` on Windows). A relative
943
+ * folder is relative to `cwd`; a module that is a path (it starts with `.` or
944
+ * `/`, or names something that exists under `cwd`) is made absolute, anything
945
+ * else is a package name.
946
+ */
947
+ export function applyPluginEnv(config, env = process.env, cwd = process.cwd()) {
948
+ const folders = splitPathList(env.AIGILE_PLUGINS_FOLDER);
949
+ if (folders.length)
950
+ config.plugins.folders = folders.map((f) => resolve(cwd, f));
951
+ const modules = splitPathList(env.AIGILE_PLUGIN_MODULES).map((m) => pluginModuleSpec(m, cwd));
952
+ for (const m of modules)
953
+ if (!config.plugins.modules.includes(m))
954
+ config.plugins.modules.push(m);
955
+ return config;
956
+ }
957
+ /** A `--plugin` value as `plugins.modules` names it: an absolute path for a file or folder, the name for a package. */
958
+ export function pluginModuleSpec(value, cwd = process.cwd()) {
959
+ if (isAbsolute(value))
960
+ return value;
961
+ if (value.startsWith('.') || existsSync(resolve(cwd, value)))
962
+ return resolve(cwd, value);
963
+ return value;
964
+ }
965
+ function splitPathList(raw) {
966
+ return raw ? raw.split(delimiter).map((s) => s.trim()).filter(Boolean) : [];
967
+ }
968
+ /** The config file's own values, before defaults and the environment: what the Settings window shows as "from the file". */
969
+ export function configFileValues(env = process.env, cwd = process.cwd()) {
970
+ const path = resolveConfigPath(env, cwd);
971
+ return path ? readConfigFile(path) : {};
972
+ }
336
973
  //# sourceMappingURL=config.js.map