@flowdular/sdk 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/.ai/skills/test-hardening/SKILL.md +1 -1
  2. package/README.md +69 -12
  3. package/assets/flowdular-banner.png +0 -0
  4. package/modules/agents/package.json +1 -1
  5. package/modules/auth/package.json +1 -1
  6. package/modules/auth/src/client/AuthenticationCore.tsrx +3 -1
  7. package/modules/auth/src/server/endpoints.ts +3 -1
  8. package/modules/auth/src/server/runtime.ts +4 -0
  9. package/modules/automations/package.json +1 -1
  10. package/modules/automations-workflows-integration/package.json +1 -1
  11. package/modules/profile/package.json +1 -1
  12. package/modules/sandbox/package.json +1 -1
  13. package/modules/system/package.json +1 -1
  14. package/modules/users/package.json +1 -1
  15. package/modules/workflows/package.json +1 -1
  16. package/package.json +5 -13
  17. package/packages/ai-provider/package.json +1 -1
  18. package/packages/cli-protocol/package.json +1 -1
  19. package/packages/client/package.json +1 -1
  20. package/packages/client/src/routing.ts +39 -2
  21. package/packages/client/src/shell/BrandMark.tsrx +5 -1
  22. package/packages/client/src/shell/navigation.ts +3 -1
  23. package/packages/client/src/state.ts +6 -2
  24. package/packages/contracts/package.json +1 -1
  25. package/packages/contracts/schemas/project.schema.json +16 -42
  26. package/packages/database/package.json +1 -1
  27. package/packages/database-pglite/package.json +2 -2
  28. package/packages/database-pglite/src/driver.ts +21 -3
  29. package/packages/database-testing/package.json +1 -1
  30. package/packages/dev-console/package.json +1 -1
  31. package/packages/harness/package.json +1 -1
  32. package/packages/kernel/package.json +1 -1
  33. package/packages/server/package.json +1 -1
  34. package/packages/server/src/application-routes.ts +80 -8
  35. package/packages/server/src/index.ts +4 -1
  36. package/packages/server/src/web-html.ts +9 -5
  37. package/packages/server/src/web.ts +59 -7
  38. package/packages/ui/package.json +1 -1
  39. package/packages/coding-agent/package.json +0 -44
  40. package/packages/coding-agent/src/drivers/byok.ts +0 -322
  41. package/packages/coding-agent/src/drivers/claude-code.ts +0 -290
  42. package/packages/coding-agent/src/drivers/codex.ts +0 -281
  43. package/packages/coding-agent/src/index.ts +0 -56
  44. package/packages/coding-agent/src/registry.ts +0 -119
  45. package/packages/coding-agent/src/roles/contract.ts +0 -60
  46. package/packages/coding-agent/src/roles/defaults.ts +0 -134
  47. package/packages/coding-agent/src/roles/handoff.ts +0 -41
  48. package/packages/coding-agent/src/roles/registry.ts +0 -156
  49. package/packages/coding-agent/src/roles/skills.ts +0 -72
  50. package/packages/coding-agent/src/roles/sync.ts +0 -88
  51. package/packages/coding-agent/src/types.ts +0 -102
  52. package/packages/coding-agent/src/workspace.ts +0 -275
  53. package/packages/sandbox/README.md +0 -691
  54. package/packages/sandbox/bin/flowdular-sandbox.mjs +0 -393
  55. package/packages/sandbox/dist/client/assets/App-ClMOrpyg.js +0 -11
  56. package/packages/sandbox/dist/client/assets/PreviewHost-BHiHrfbQ.js +0 -1
  57. package/packages/sandbox/dist/client/assets/auto-buGEq6de.js +0 -3
  58. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  59. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  60. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  61. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  62. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  63. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  64. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  65. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  66. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  67. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  68. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  69. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  70. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  71. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  72. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  73. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  74. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  75. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  76. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  77. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  78. package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  79. package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  80. package/packages/sandbox/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  81. package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  82. package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  83. package/packages/sandbox/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  84. package/packages/sandbox/dist/client/assets/index-CvwhlQ87.js +0 -4
  85. package/packages/sandbox/dist/client/assets/styles-BPWaGf55.js +0 -3
  86. package/packages/sandbox/dist/client/assets/styles-Dx1_KOag.css +0 -1
  87. package/packages/sandbox/dist/client/favicon.svg +0 -1
  88. package/packages/sandbox/dist/server/assets/auto-CVGNYyb3.js +0 -12785
  89. package/packages/sandbox/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +0 -4125
  90. package/packages/sandbox/dist/server/assets/nodefs-DVSI7kG0.js +0 -24
  91. package/packages/sandbox/dist/server/assets/opfs-ahp-D56iokt1.js +0 -388
  92. package/packages/sandbox/dist/server/assets/token-Bvaq7Anz.js +0 -55
  93. package/packages/sandbox/dist/server/assets/token-util-BqSvdIPQ.js +0 -3
  94. package/packages/sandbox/dist/server/assets/token-util-CktFFT4z.js +0 -494
  95. package/packages/sandbox/dist/server/entry.js +0 -91671
  96. package/packages/sandbox/dist/server/favicon.svg +0 -1
  97. package/packages/sandbox/dist/server/index.html +0 -161
  98. package/packages/sandbox/index.html +0 -159
  99. package/packages/sandbox/octane.config.ts +0 -36
  100. package/packages/sandbox/package.json +0 -83
  101. package/packages/sandbox/public/favicon.svg +0 -1
  102. package/packages/sandbox/public/og.png +0 -0
  103. package/packages/sandbox/src/App.tsrx +0 -924
  104. package/packages/sandbox/src/client/ApprovalHandoff.tsrx +0 -39
  105. package/packages/sandbox/src/client/ChatPane.tsrx +0 -694
  106. package/packages/sandbox/src/client/ConnectView.tsrx +0 -86
  107. package/packages/sandbox/src/client/DiffPane.tsrx +0 -150
  108. package/packages/sandbox/src/client/EjectModal.tsrx +0 -571
  109. package/packages/sandbox/src/client/GateResults.tsrx +0 -60
  110. package/packages/sandbox/src/client/GitHubSettingsModal.tsrx +0 -219
  111. package/packages/sandbox/src/client/NewSessionForm.tsrx +0 -214
  112. package/packages/sandbox/src/client/SessionBar.tsrx +0 -151
  113. package/packages/sandbox/src/client/SessionPicker.tsrx +0 -472
  114. package/packages/sandbox/src/client/SpecEditor.tsrx +0 -109
  115. package/packages/sandbox/src/client/SpecReviewCard.tsrx +0 -321
  116. package/packages/sandbox/src/client/WorkCard.tsrx +0 -128
  117. package/packages/sandbox/src/client/WorkbenchModal.tsrx +0 -161
  118. package/packages/sandbox/src/client/WorkspaceMenu.tsrx +0 -100
  119. package/packages/sandbox/src/client/api.ts +0 -797
  120. package/packages/sandbox/src/client/attachments.ts +0 -73
  121. package/packages/sandbox/src/client/dashboard.ts +0 -46
  122. package/packages/sandbox/src/client/github-settings.ts +0 -48
  123. package/packages/sandbox/src/client/highlight.ts +0 -105
  124. package/packages/sandbox/src/client/i18n.ts +0 -32
  125. package/packages/sandbox/src/client/locales/en.json +0 -466
  126. package/packages/sandbox/src/client/locales/pl.json +0 -466
  127. package/packages/sandbox/src/client/session-labels.ts +0 -77
  128. package/packages/sandbox/src/client/state.ts +0 -108
  129. package/packages/sandbox/src/index.ts +0 -10
  130. package/packages/sandbox/src/preview/PreviewHost.tsrx +0 -373
  131. package/packages/sandbox/src/preview/load-module.ts +0 -16
  132. package/packages/sandbox/src/server/attachments.ts +0 -308
  133. package/packages/sandbox/src/server/auto-review.ts +0 -181
  134. package/packages/sandbox/src/server/checkpoints.ts +0 -90
  135. package/packages/sandbox/src/server/config.ts +0 -460
  136. package/packages/sandbox/src/server/dashboard.ts +0 -245
  137. package/packages/sandbox/src/server/delivery/configuration.ts +0 -193
  138. package/packages/sandbox/src/server/delivery/git-pr.ts +0 -1473
  139. package/packages/sandbox/src/server/delivery/index.ts +0 -83
  140. package/packages/sandbox/src/server/delivery/local.ts +0 -151
  141. package/packages/sandbox/src/server/delivery/official-modules.ts +0 -516
  142. package/packages/sandbox/src/server/delivery/plan.ts +0 -218
  143. package/packages/sandbox/src/server/delivery/policies.ts +0 -239
  144. package/packages/sandbox/src/server/delivery/record.ts +0 -41
  145. package/packages/sandbox/src/server/delivery/steps.ts +0 -464
  146. package/packages/sandbox/src/server/delivery/types.ts +0 -158
  147. package/packages/sandbox/src/server/dependencies.ts +0 -88
  148. package/packages/sandbox/src/server/diff.ts +0 -230
  149. package/packages/sandbox/src/server/gates.ts +0 -388
  150. package/packages/sandbox/src/server/index.ts +0 -139
  151. package/packages/sandbox/src/server/path-guard.ts +0 -282
  152. package/packages/sandbox/src/server/planning.ts +0 -749
  153. package/packages/sandbox/src/server/platform-client.ts +0 -189
  154. package/packages/sandbox/src/server/preview-database-host.ts +0 -340
  155. package/packages/sandbox/src/server/preview-database-protocol.ts +0 -163
  156. package/packages/sandbox/src/server/preview-database-proxy.ts +0 -356
  157. package/packages/sandbox/src/server/preview-database.ts +0 -109
  158. package/packages/sandbox/src/server/preview-ipc.ts +0 -15
  159. package/packages/sandbox/src/server/preview-modules.ts +0 -83
  160. package/packages/sandbox/src/server/preview-revision.ts +0 -44
  161. package/packages/sandbox/src/server/preview-runtime.ts +0 -467
  162. package/packages/sandbox/src/server/preview-worker-manager.ts +0 -436
  163. package/packages/sandbox/src/server/preview-worker.ts +0 -168
  164. package/packages/sandbox/src/server/reference.ts +0 -251
  165. package/packages/sandbox/src/server/routes.ts +0 -2258
  166. package/packages/sandbox/src/server/runtime.ts +0 -188
  167. package/packages/sandbox/src/server/session-owner.ts +0 -23
  168. package/packages/sandbox/src/server/sessions.ts +0 -849
  169. package/packages/sandbox/src/server/spec.ts +0 -471
  170. package/packages/sandbox/src/server/turn-lifecycle.ts +0 -56
  171. package/packages/sandbox/src/server/turns.ts +0 -993
  172. package/packages/sandbox/src/server/workspace-install.ts +0 -266
  173. package/packages/sandbox/src/server/workspace-root.ts +0 -73
  174. package/packages/sandbox/src/styles.css +0 -1573
  175. package/packages/sandbox/vite.config.ts +0 -133
@@ -1,516 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import {
3
- mkdtemp,
4
- stat,
5
- readFile,
6
- readdir,
7
- rm,
8
- writeFile,
9
- } from 'node:fs/promises';
10
- import { tmpdir } from 'node:os';
11
- import { join } from 'node:path';
12
- import { inspectAutoReview, moduleReviewRevision } from '../auto-review.ts';
13
- import { modulePathOf, sessionPaths } from '../sessions.ts';
14
- import { gitDeliveryRunner } from './git-pr.ts';
15
- import {
16
- GATES,
17
- assertEjectCapability,
18
- countDeliveredFiles,
19
- planSessionModules,
20
- } from './plan.ts';
21
- import {
22
- DeliveryError,
23
- createStepRecorder,
24
- exists,
25
- runDeliveryGates,
26
- stageModules,
27
- } from './steps.ts';
28
- import type { DeliveryContext, DeliveryTarget } from './types.ts';
29
-
30
- export const OFFICIAL_MODULES_REPOSITORY = 'Flowdular/official-modules';
31
- const REPOSITORY = OFFICIAL_MODULES_REPOSITORY;
32
- const active = new Set<string>();
33
- const ROOT_FILES = new Set([
34
- 'module.json',
35
- 'package.json',
36
- 'README.md',
37
- 'CHANGELOG.md',
38
- 'LICENSE',
39
- 'tsconfig.json',
40
- 'vitest.config.ts',
41
- ]);
42
- const ROOTS = new Set(['src', 'tests', 'migrations', 'translations', 'spec']);
43
-
44
- function fail(message: string): never {
45
- throw new DeliveryError('OFFICIAL_MODULES_BLOCKED', message);
46
- }
47
-
48
- /* Reject extra files rather than silently publishing a subset of what was reviewed. */
49
- export function assertOfficialSourcePaths(files: readonly string[]): void {
50
- if (files.length > 4096) fail('The contribution exceeds 4096 source files.');
51
- for (const file of files) {
52
- const parts = file.split('/');
53
- if (
54
- file.length >= 240 ||
55
- !/^[a-zA-Z0-9_./@+ -]+$/.test(file) ||
56
- parts.some(
57
- (part) =>
58
- !part ||
59
- part.startsWith('.') ||
60
- part === 'node_modules' ||
61
- part === 'dist',
62
- ) ||
63
- !(parts.length === 1 ? ROOT_FILES.has(file) : ROOTS.has(parts[0]!))
64
- ) {
65
- fail(
66
- `Unsupported registry source path: ${file}. Remove private or generated files before review.`,
67
- );
68
- }
69
- }
70
- }
71
-
72
- async function reviewedPlan(context: DeliveryContext) {
73
- assertEjectCapability(context);
74
- if (
75
- context.session.modules.length !== 1 ||
76
- context.session.modules[0]!.kind !== 'new'
77
- )
78
- fail(
79
- 'Submit one new module at a time. Existing registry modules need a contributor branch and compatibility review.',
80
- );
81
- const modules = (await planSessionModules(context)).map((module) => ({
82
- ...module,
83
- enable: false,
84
- }));
85
- const paths = sessionPaths(
86
- context.workspaceRoot,
87
- context.session.id,
88
- context.session.moduleSuffix,
89
- );
90
- for (const module of modules) {
91
- assertOfficialSourcePaths(module.files);
92
- if (
93
- !/^[a-z][a-z0-9-]*$/.test(module.directory) ||
94
- !/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/.test(module.id)
95
- )
96
- fail('Invalid module identity.');
97
- let bytes = 0;
98
- for (const file of module.files) {
99
- bytes += (await stat(join(modulePathOf(paths, module.directory), file)))
100
- .size;
101
- if (bytes > 32 * 1024 * 1024) fail('The contribution exceeds 32 MiB.');
102
- }
103
-
104
- const review = await inspectAutoReview(paths, module);
105
- if (!review.passed) fail(review.output);
106
- }
107
- return modules;
108
- }
109
-
110
- /* This script runs only after the cloned registry's actual verification passes.
111
- It uses its pinned distribution API, so hashing and packaging share a contract. */
112
- const REVIEW_SCRIPT = `
113
- import { mkdir, writeFile } from 'node:fs/promises';
114
- import { readModuleSource, sourceDigest } from 'flowdular/distribution';
115
- const [directory, id, revision] = process.argv.slice(1);
116
- const sourceSha256 = sourceDigest(await readModuleSource(directory));
117
- await mkdir('reviews', {recursive:true});
118
- await writeFile('reviews/' + id + '.json', JSON.stringify({
119
- sourceSha256,
120
- requirements: ['Implement the human-approved specification in ' + directory + '/spec/module.yaml',
121
- 'Pass all sandbox gates and exact-source auto-review ' + revision,
122
- 'Pass the official repository verification against the pinned SDK'],
123
- findings: [],
124
- checks: ['typecheck','test','validate'].map(name => ({name,command:'pnpm ' + name,exitCode:0}))
125
- }, null, '\\t') + '\\n');
126
- `;
127
-
128
- export function createOfficialModulesDeliveryTarget(): DeliveryTarget {
129
- return {
130
- id: 'official-modules',
131
- available: async (context) => {
132
- try {
133
- await reviewedPlan(context);
134
- const run = await gitDeliveryRunner(context);
135
- const result = await run(
136
- 'gh',
137
- ['api', `repos/${REPOSITORY}`, '--jq', '.full_name'],
138
- context.workspaceRoot,
139
- );
140
- if (
141
- result.code !== 0 ||
142
- result.output.trim().toLowerCase() !== REPOSITORY.toLowerCase()
143
- )
144
- return {
145
- available: false,
146
- reason:
147
- 'GitHub authentication and access to Flowdular/official-modules are required.',
148
- };
149
- return { available: true, reason: null };
150
- } catch (error) {
151
- return {
152
- available: false,
153
- reason:
154
- error instanceof Error
155
- ? error.message
156
- : 'A reviewed new module is required.',
157
- };
158
- }
159
- },
160
- plan: async (context) => {
161
- const modules = await reviewedPlan(context);
162
- const primary = modules[0]!;
163
- return {
164
- target: 'official-modules',
165
- deliveredBy: 'official-modules',
166
- moduleId: primary.id,
167
- targetPath: primary.targetPath,
168
- files: primary.files,
169
- overwrites: [],
170
- removes: [],
171
- newPackages: primary.newPackages,
172
- enable: false,
173
- modules,
174
- changedFiles: countDeliveredFiles(modules),
175
- gates: [...GATES],
176
- platformLocal: false,
177
- restartRequired: false,
178
- notes: [
179
- `Open a PR to ${REPOSITORY}/main after sandbox review and registry verification. The module sources, tests and approved specification will be shared with that repository. Maintainers publish the registry after acceptance.`,
180
- ],
181
- applied: false,
182
- };
183
- },
184
- apply: async (context, plan, emit) => {
185
- if (plan.target !== 'official-modules')
186
- fail('The plan targets another repository.');
187
- const key = `${context.workspaceRoot}:${context.session.id}`;
188
- if (active.has(key)) fail('This contribution is already running.');
189
- active.add(key);
190
- let scratch: string | undefined;
191
- try {
192
- const modules = await reviewedPlan(context);
193
- const module = modules[0]!;
194
- const paths = sessionPaths(
195
- context.workspaceRoot,
196
- context.session.id,
197
- context.session.moduleSuffix,
198
- );
199
- const source = modulePathOf(paths, module.directory);
200
- const revision = await moduleReviewRevision(source);
201
- const gates = await runDeliveryGates(context, GATES, emit);
202
- const run = await gitDeliveryRunner(context);
203
- const recorder = createStepRecorder(emit);
204
- const command = async (
205
- id: string,
206
- executable: string,
207
- args: string[],
208
- cwd: string,
209
- ) => {
210
- emit(`${id}.started`, {});
211
- const result = await run(executable, args, cwd);
212
- recorder.record(id, { ok: result.code === 0, output: result.output });
213
- return result.output.trim();
214
- };
215
- scratch = await mkdtemp(join(tmpdir(), 'flowdular-official-'));
216
- const checkout = join(scratch, 'registry');
217
- await command(
218
- 'worktree',
219
- 'git',
220
- [
221
- 'clone',
222
- '--quiet',
223
- '--depth',
224
- '1',
225
- '--branch',
226
- 'main',
227
- `https://github.com/${REPOSITORY}.git`,
228
- checkout,
229
- ],
230
- scratch,
231
- );
232
- if (await exists(join(checkout, module.targetPath)))
233
- fail(
234
- 'That module directory already exists in Official Modules. Use a contributor branch for updates.',
235
- );
236
- for (const entry of await readdir(join(checkout, 'modules'), {
237
- withFileTypes: true,
238
- })) {
239
- if (!entry.isDirectory()) continue;
240
- const manifest = JSON.parse(
241
- await readFile(
242
- join(checkout, 'modules', entry.name, 'module.json'),
243
- 'utf8',
244
- ),
245
- );
246
- if (manifest.id === module.id)
247
- fail('That module ID already exists in Official Modules.');
248
- }
249
- const { copied } = await stageModules(paths, checkout, modules, emit);
250
- const staged = join(checkout, module.targetPath);
251
- if ((await moduleReviewRevision(staged)) !== revision)
252
- fail('Source changed during staging. Repeat review.');
253
- await command(
254
- 'install',
255
- 'pnpm',
256
- ['install', '--no-frozen-lockfile'],
257
- checkout,
258
- );
259
- await command('verify', 'pnpm', ['verify'], checkout);
260
- if (
261
- (await moduleReviewRevision(staged)) !== revision ||
262
- (await moduleReviewRevision(source)) !== revision
263
- )
264
- fail('Verification changed reviewed source. Repeat review.');
265
- await command(
266
- 'review',
267
- 'node',
268
- [
269
- '--input-type=module',
270
- '-e',
271
- REVIEW_SCRIPT,
272
- module.targetPath,
273
- module.id,
274
- revision,
275
- ],
276
- checkout,
277
- );
278
- await command('pack', 'pnpm', ['release:pack', '--local'], checkout);
279
- if ((await moduleReviewRevision(staged)) !== revision)
280
- fail('Packaging changed reviewed source. Repeat review.');
281
- const manifest = JSON.parse(
282
- await readFile(join(staged, 'module.json'), 'utf8'),
283
- );
284
- if (
285
- !/^[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9.-]+)?$/.test(manifest.version)
286
- )
287
- fail('Invalid release version.');
288
- if (manifest.id !== module.id)
289
- fail('Module identity differs from the reviewed session.');
290
- const allowed = [
291
- module.targetPath,
292
- `reviews/${module.id}.json`,
293
- `registry/releases/${module.id}/${manifest.version}.json`,
294
- ];
295
- // Installation may update only the disposable lockfile. Never include it.
296
- await command('commit', 'git', ['add', '--', ...allowed], checkout);
297
- const offending = await command(
298
- 'guardrails',
299
- 'git',
300
- [
301
- 'diff',
302
- '--cached',
303
- '--name-only',
304
- '--',
305
- '.',
306
- ...allowed.map((path) => `:(exclude)${path}`),
307
- ],
308
- checkout,
309
- );
310
- if (offending) fail('Unexpected staged files.');
311
-
312
- const unrelated = await command(
313
- 'guardrails',
314
- 'git',
315
- ['diff', '--name-only', '--', '.', ':(exclude)pnpm-lock.yaml'],
316
- checkout,
317
- );
318
- if (unrelated)
319
- fail('Verification changed files outside the contribution.');
320
- const suffix = createHash('sha256')
321
- .update(key + revision)
322
- .digest('hex')
323
- .slice(0, 24);
324
- const branch = `official-module/${suffix}`;
325
- const login = await command(
326
- 'provider',
327
- 'gh',
328
- ['api', 'user', '--jq', '.login'],
329
- checkout,
330
- );
331
- if (!/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/.test(login))
332
- fail('Invalid GitHub identity.');
333
- const push = await command(
334
- 'provider',
335
- 'gh',
336
- ['api', `repos/${REPOSITORY}`, '--jq', '.permissions.push'],
337
- checkout,
338
- );
339
- const destination =
340
- push === 'true' ? REPOSITORY : `${login}/official-modules`;
341
- const head = `${destination.split('/')[0]}:${branch}`;
342
- const marker = `<!-- flowdular-official:${suffix} -->`;
343
- const previous = await command(
344
- 'provider',
345
- 'gh',
346
- [
347
- 'api',
348
- `repos/${REPOSITORY}/pulls`,
349
- '--method',
350
- 'GET',
351
- '-f',
352
- `head=${head}`,
353
- '-f',
354
- 'state=open',
355
- '--jq',
356
- '[.[] | {url: .html_url, body: (.body // "")}]',
357
- ],
358
- checkout,
359
- );
360
-
361
- const prs = JSON.parse(previous) as { url: string; body: string }[];
362
- let url = prs.find((pr) => pr.body.includes(marker))?.url;
363
- await command(
364
- 'branch',
365
- 'git',
366
- ['switch', '--quiet', '-c', branch],
367
- checkout,
368
- );
369
- await command(
370
- 'commit',
371
- 'git',
372
- ['commit', '--quiet', '-m', `Add ${module.id} to Official Modules`],
373
- checkout,
374
- );
375
- if (url) {
376
- await command(
377
- 'fetch',
378
- 'git',
379
- [
380
- 'fetch',
381
- '--quiet',
382
- `https://github.com/${destination}.git`,
383
- `refs/heads/${branch}`,
384
- ],
385
- checkout,
386
- );
387
- const remoteTree = await command(
388
- 'guardrails',
389
- 'git',
390
- ['rev-parse', 'FETCH_HEAD^{tree}'],
391
- checkout,
392
- );
393
- const reviewedTree = await command(
394
- 'guardrails',
395
- 'git',
396
- ['rev-parse', 'HEAD^{tree}'],
397
- checkout,
398
- );
399
- if (remoteTree !== reviewedTree)
400
- fail(
401
- 'The existing PR contains different source. Review it before retrying.',
402
- );
403
- }
404
- if (!url) {
405
- if (push !== 'true') {
406
- await command(
407
- 'fork',
408
- 'gh',
409
- ['repo', 'fork', REPOSITORY, '--clone=false', '--remote=false'],
410
- checkout,
411
- );
412
- const parent = await command(
413
- 'provider',
414
- 'gh',
415
- ['api', `repos/${destination}`, '--jq', '.parent.full_name'],
416
- checkout,
417
- );
418
- if (parent.toLowerCase() !== REPOSITORY.toLowerCase())
419
- fail('The destination is not a fork of Official Modules.');
420
- }
421
- // A retry after push/PR failure may reuse only byte-identical source.
422
- const remote = `https://github.com/${destination}.git`;
423
- const existing = await command(
424
- 'provider',
425
- 'git',
426
- ['ls-remote', '--heads', remote, `refs/heads/${branch}`],
427
- checkout,
428
- );
429
- if (existing) {
430
- await command(
431
- 'fetch',
432
- 'git',
433
- ['fetch', '--quiet', remote, `refs/heads/${branch}`],
434
- checkout,
435
- );
436
- const before = await command(
437
- 'guardrails',
438
- 'git',
439
- ['rev-parse', 'FETCH_HEAD^{tree}'],
440
- checkout,
441
- );
442
- const after = await command(
443
- 'guardrails',
444
- 'git',
445
- ['rev-parse', 'HEAD^{tree}'],
446
- checkout,
447
- );
448
- if (before !== after)
449
- fail(
450
- 'The contribution branch has different source. It was preserved; review it before retrying.',
451
- );
452
- } else {
453
- await command(
454
- 'push',
455
- 'git',
456
- [
457
- 'push',
458
- '--quiet',
459
- `--force-with-lease=refs/heads/${branch}:`,
460
- remote,
461
- `HEAD:refs/heads/${branch}`,
462
- ],
463
- checkout,
464
- );
465
- }
466
-
467
- const body = join(scratch, 'pr.md');
468
- await writeFile(
469
- body,
470
- `Adds ${module.id}@${manifest.version} from the sandbox.\n\nApproved specification: ${module.targetPath}/spec/module.yaml (SHA256 ${context.session.modules[0]!.specHash}; operator approval at ${context.session.modules[0]!.specApprovedAt}).\nReviewed source revision: ${revision}.\n\nEvidence: all sandbox gates, exact-source auto-review, registry pnpm verify and pnpm release:pack --local passed. See reviews/${module.id}.json. PostgreSQL CI and maintainer review remain required before publication.\n\nNo registry index publication or application activation is performed.\n\n${marker}\n`,
471
- );
472
- url = await command(
473
- 'pr',
474
- 'gh',
475
- [
476
- 'pr',
477
- 'create',
478
- '--repo',
479
- REPOSITORY,
480
- '--base',
481
- 'main',
482
- '--head',
483
- push === 'true' ? branch : head,
484
- '--title',
485
- `Add ${module.id} to Official Modules`,
486
- '--body-file',
487
- body,
488
- ],
489
- checkout,
490
- );
491
- }
492
- if (
493
- !/^https:\/\/github\.com\/Flowdular\/official-modules\/pull\/\d+$/i.test(
494
- url,
495
- )
496
- )
497
- fail('GitHub did not return an Official Modules pull request URL.');
498
- return {
499
- moduleId: module.id,
500
- targetPath: module.targetPath,
501
- files: copied,
502
- removed: 0,
503
- enabled: false,
504
- gates,
505
- steps: recorder.steps,
506
- restartRequired: false,
507
- branch,
508
- pullRequestUrl: url,
509
- };
510
- } finally {
511
- active.delete(key);
512
- if (scratch) await rm(scratch, { recursive: true, force: true });
513
- }
514
- },
515
- };
516
- }