edsger 0.42.1 → 0.44.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 (98) hide show
  1. package/.claude/settings.local.json +23 -3
  2. package/.env.local +12 -0
  3. package/dist/api/release-test-cases.d.ts +7 -0
  4. package/dist/api/release-test-cases.js +21 -0
  5. package/dist/api/releases.d.ts +41 -0
  6. package/dist/api/releases.js +31 -0
  7. package/dist/api/web-deploy.d.ts +8 -1
  8. package/dist/api/web-deploy.js +2 -1
  9. package/dist/commands/release-sync/index.d.ts +5 -0
  10. package/dist/commands/release-sync/index.js +38 -0
  11. package/dist/commands/smoke-test/index.d.ts +5 -0
  12. package/dist/commands/smoke-test/index.js +40 -0
  13. package/dist/commands/workflow/phase-orchestrator.js +3 -1
  14. package/dist/index.js +40 -0
  15. package/dist/phases/app-store-generation/__tests__/screenshot-composer.test.js +1 -0
  16. package/dist/phases/app-store-generation/index.js +3 -1
  17. package/dist/phases/app-store-generation/screenshot-composer.js +34 -10
  18. package/dist/phases/branch-planning/index.js +3 -1
  19. package/dist/phases/bug-fixing/analyzer.js +3 -1
  20. package/dist/phases/code-implementation/index.js +3 -1
  21. package/dist/phases/code-refine/index.js +3 -1
  22. package/dist/phases/code-review/__tests__/diff-utils.test.js +11 -11
  23. package/dist/phases/code-review/index.js +3 -1
  24. package/dist/phases/code-testing/analyzer.js +3 -1
  25. package/dist/phases/feature-analysis/index.js +3 -1
  26. package/dist/phases/functional-testing/analyzer.js +3 -1
  27. package/dist/phases/growth-analysis/index.js +3 -1
  28. package/dist/phases/intelligence-analysis/__tests__/orchestration.test.js +12 -12
  29. package/dist/phases/intelligence-analysis/agent.js +2 -0
  30. package/dist/phases/intelligence-analysis/index.js +1 -0
  31. package/dist/phases/intelligence-analysis/prompts.js +11 -1
  32. package/dist/phases/output-contracts.js +1 -0
  33. package/dist/phases/pr-execution/__tests__/file-assigner.test.js +22 -13
  34. package/dist/phases/pr-execution/context.js +4 -2
  35. package/dist/phases/pr-execution/file-assigner.js +1 -0
  36. package/dist/phases/pr-resolve/__tests__/checklist-learner.test.js +11 -11
  37. package/dist/phases/pr-resolve/__tests__/prompts.test.js +12 -12
  38. package/dist/phases/pr-resolve/__tests__/resolve-mapping.test.js +6 -6
  39. package/dist/phases/pr-resolve/__tests__/types.test.js +11 -11
  40. package/dist/phases/pr-resolve/__tests__/workspace.test.js +13 -13
  41. package/dist/phases/pr-resolve/checklist-learner.js +34 -9
  42. package/dist/phases/pr-resolve/index.js +29 -13
  43. package/dist/phases/pr-resolve/prompts.js +2 -1
  44. package/dist/phases/pr-resolve/workspace.d.ts +12 -2
  45. package/dist/phases/pr-resolve/workspace.js +6 -4
  46. package/dist/phases/pr-review/__tests__/prompts.test.js +9 -9
  47. package/dist/phases/pr-review/__tests__/review-comments.test.js +6 -6
  48. package/dist/phases/pr-review/index.js +1 -0
  49. package/dist/phases/pr-shared/__tests__/agent-utils.test.js +17 -17
  50. package/dist/phases/pr-shared/__tests__/context.test.js +12 -12
  51. package/dist/phases/pr-splitting/import-dep-validator.js +14 -6
  52. package/dist/phases/pr-splitting/index.js +3 -1
  53. package/dist/phases/release-sync/__tests__/github.test.d.ts +9 -0
  54. package/dist/phases/release-sync/__tests__/github.test.js +123 -0
  55. package/dist/phases/release-sync/__tests__/snapshot.test.d.ts +8 -0
  56. package/dist/phases/release-sync/__tests__/snapshot.test.js +93 -0
  57. package/dist/phases/release-sync/github.d.ts +54 -0
  58. package/dist/phases/release-sync/github.js +101 -0
  59. package/dist/phases/release-sync/index.d.ts +24 -0
  60. package/dist/phases/release-sync/index.js +147 -0
  61. package/dist/phases/release-sync/snapshot.d.ts +27 -0
  62. package/dist/phases/release-sync/snapshot.js +159 -0
  63. package/dist/phases/smoke-test/__tests__/agent.test.d.ts +4 -0
  64. package/dist/phases/smoke-test/__tests__/agent.test.js +85 -0
  65. package/dist/phases/smoke-test/agent.d.ts +12 -0
  66. package/dist/phases/smoke-test/agent.js +94 -0
  67. package/dist/phases/smoke-test/index.d.ts +22 -0
  68. package/dist/phases/smoke-test/index.js +233 -0
  69. package/dist/phases/smoke-test/prompts.d.ts +15 -0
  70. package/dist/phases/smoke-test/prompts.js +35 -0
  71. package/dist/phases/technical-design/index.js +3 -1
  72. package/dist/phases/test-cases-analysis/index.js +3 -1
  73. package/dist/phases/user-stories-analysis/index.js +3 -1
  74. package/dist/services/phase-hooks/__tests__/hook-executor.test.js +7 -4
  75. package/dist/services/phase-hooks/__tests__/hook-runner.test.js +22 -21
  76. package/dist/services/phase-hooks/hook-executor.js +1 -0
  77. package/dist/services/phase-hooks/plugin-loader.js +3 -0
  78. package/dist/services/video/screenshot-generator.js +8 -2
  79. package/dist/skills/phase/smoke-test/SKILL.md +80 -0
  80. package/dist/utils/json-extract.d.ts +6 -0
  81. package/dist/utils/json-extract.js +44 -0
  82. package/dist/workspace/__tests__/workspace-manager.test.d.ts +7 -0
  83. package/dist/workspace/__tests__/workspace-manager.test.js +52 -0
  84. package/dist/workspace/workspace-manager.d.ts +31 -0
  85. package/dist/workspace/workspace-manager.js +96 -10
  86. package/package.json +1 -1
  87. package/dist/services/lifecycle-agent/__tests__/phase-criteria.test.d.ts +0 -4
  88. package/dist/services/lifecycle-agent/__tests__/phase-criteria.test.js +0 -133
  89. package/dist/services/lifecycle-agent/__tests__/transition-rules.test.d.ts +0 -4
  90. package/dist/services/lifecycle-agent/__tests__/transition-rules.test.js +0 -336
  91. package/dist/services/lifecycle-agent/index.d.ts +0 -24
  92. package/dist/services/lifecycle-agent/index.js +0 -25
  93. package/dist/services/lifecycle-agent/phase-criteria.d.ts +0 -57
  94. package/dist/services/lifecycle-agent/phase-criteria.js +0 -335
  95. package/dist/services/lifecycle-agent/transition-rules.d.ts +0 -60
  96. package/dist/services/lifecycle-agent/transition-rules.js +0 -184
  97. package/dist/services/lifecycle-agent/types.d.ts +0 -190
  98. package/dist/services/lifecycle-agent/types.js +0 -12
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Unit tests for smoke-test github helpers.
3
+ *
4
+ * Covers the pure functions that shape GitHub compare data into a
5
+ * prompt-ready digest. Network-facing functions (fetchLatestTwoReleases,
6
+ * fetchCompare) are exercised only indirectly — their output shape is
7
+ * fed through buildDiffDigest / summariseStats here.
8
+ */
9
+ import assert from 'node:assert';
10
+ import { describe, it } from 'node:test';
11
+ import { buildDiffDigest, summariseStats, } from '../github.js';
12
+ function makeCompare(over = {}) {
13
+ return {
14
+ total_commits: 2,
15
+ commits: [
16
+ {
17
+ sha: '1111111aaaaaaaa',
18
+ commit: {
19
+ message: 'feat: add checkout flow\n\nmore body',
20
+ author: null,
21
+ },
22
+ },
23
+ {
24
+ sha: '2222222bbbbbbbb',
25
+ commit: { message: 'fix: null deref', author: { name: 'Ada' } },
26
+ },
27
+ ],
28
+ files: [
29
+ {
30
+ filename: 'src/checkout.ts',
31
+ status: 'modified',
32
+ additions: 10,
33
+ deletions: 2,
34
+ changes: 12,
35
+ patch: '@@ -1 +1 @@\n-old\n+new',
36
+ },
37
+ {
38
+ filename: 'src/util.ts',
39
+ status: 'added',
40
+ additions: 5,
41
+ deletions: 0,
42
+ changes: 5,
43
+ },
44
+ ],
45
+ ...over,
46
+ };
47
+ }
48
+ void describe('summariseStats', () => {
49
+ void it('sums additions, deletions, and file count', () => {
50
+ const stats = summariseStats(makeCompare());
51
+ assert.deepStrictEqual(stats, {
52
+ files_changed: 2,
53
+ additions: 15,
54
+ deletions: 2,
55
+ total_commits: 2,
56
+ });
57
+ });
58
+ void it('handles an empty diff', () => {
59
+ const stats = summariseStats({
60
+ total_commits: 0,
61
+ commits: [],
62
+ files: [],
63
+ });
64
+ assert.deepStrictEqual(stats, {
65
+ files_changed: 0,
66
+ additions: 0,
67
+ deletions: 0,
68
+ total_commits: 0,
69
+ });
70
+ });
71
+ });
72
+ void describe('buildDiffDigest', () => {
73
+ void it('includes commit subjects, file list, and patches', () => {
74
+ const digest = buildDiffDigest(makeCompare());
75
+ assert.match(digest, /Total commits: 2/);
76
+ assert.match(digest, /1111111 feat: add checkout flow/);
77
+ assert.match(digest, /2222222 fix: null deref/);
78
+ assert.match(digest, /modified src\/checkout\.ts \(\+10\/-2\)/);
79
+ assert.match(digest, /added src\/util\.ts \(\+5\/-0\)/);
80
+ assert.match(digest, /--- src\/checkout\.ts ---/);
81
+ assert.match(digest, /\+new/);
82
+ });
83
+ void it('truncates only the subject line of multi-line commit messages', () => {
84
+ const digest = buildDiffDigest(makeCompare());
85
+ // "more body" from the first commit's message body must not leak in.
86
+ assert.ok(!digest.includes('more body'));
87
+ });
88
+ void it('caps the patch budget and appends a truncation marker', () => {
89
+ const huge = 'x'.repeat(200_000);
90
+ const compare = makeCompare({
91
+ files: [
92
+ {
93
+ filename: 'src/big.ts',
94
+ status: 'modified',
95
+ additions: 1,
96
+ deletions: 0,
97
+ changes: 1,
98
+ patch: huge,
99
+ },
100
+ ],
101
+ });
102
+ const digest = buildDiffDigest(compare);
103
+ assert.match(digest, /\[truncated\]/);
104
+ // Even with a 200k patch, digest stays bounded by the internal budget.
105
+ assert.ok(digest.length < 200_000);
106
+ });
107
+ void it('skips files without patches in the patches section', () => {
108
+ const compare = makeCompare({
109
+ files: [
110
+ {
111
+ filename: 'vendored.min.js',
112
+ status: 'added',
113
+ additions: 1,
114
+ deletions: 0,
115
+ changes: 1,
116
+ },
117
+ ],
118
+ });
119
+ const digest = buildDiffDigest(compare);
120
+ assert.ok(digest.includes('== Patches (truncated) =='));
121
+ assert.ok(!digest.includes('--- vendored.min.js ---'));
122
+ });
123
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Unit tests for snapshot-detection pure helpers.
3
+ *
4
+ * The network / SDK path (`detectSnapshotVersion`) is not covered here
5
+ * — it's exercised end-to-end when the CLI runs — but the parser and
6
+ * the plausibility check are critical and easy to cover.
7
+ */
8
+ export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Unit tests for snapshot-detection pure helpers.
3
+ *
4
+ * The network / SDK path (`detectSnapshotVersion`) is not covered here
5
+ * — it's exercised end-to-end when the CLI runs — but the parser and
6
+ * the plausibility check are critical and easy to cover.
7
+ */
8
+ import assert from 'node:assert';
9
+ import { describe, it } from 'node:test';
10
+ import { buildSnapshotDetectionPrompt, isPlausibleSnapshotTag, parseSnapshotDetection, } from '../snapshot.js';
11
+ void describe('parseSnapshotDetection', () => {
12
+ void it('parses a clean JSON object', () => {
13
+ const raw = '{"snapshot_tag":"v2.0.0","source":"package.json","reasoning":"next ver"}';
14
+ const parsed = parseSnapshotDetection(raw);
15
+ assert.strictEqual(parsed.snapshot_tag, 'v2.0.0');
16
+ assert.strictEqual(parsed.source, 'package.json');
17
+ assert.match(parsed.reasoning, /next ver/);
18
+ });
19
+ void it('strips ```json fences', () => {
20
+ const raw = '```json\n{"snapshot_tag":"v1.0.1","source":"VERSION","reasoning":"x"}\n```';
21
+ const parsed = parseSnapshotDetection(raw);
22
+ assert.strictEqual(parsed.snapshot_tag, 'v1.0.1');
23
+ });
24
+ void it('tolerates leading and trailing prose', () => {
25
+ const raw = `I checked package.json:
26
+ {"snapshot_tag":"v3.0.0","source":"package.json","reasoning":"bumped"}
27
+ Done.`;
28
+ const parsed = parseSnapshotDetection(raw);
29
+ assert.strictEqual(parsed.snapshot_tag, 'v3.0.0');
30
+ });
31
+ void it('returns null snapshot_tag when model reports no snapshot', () => {
32
+ const raw = '{"snapshot_tag": null, "source": null, "reasoning": "version matches latest release"}';
33
+ const parsed = parseSnapshotDetection(raw);
34
+ assert.strictEqual(parsed.snapshot_tag, null);
35
+ assert.strictEqual(parsed.source, null);
36
+ });
37
+ void it('treats empty string snapshot_tag as null', () => {
38
+ const raw = '{"snapshot_tag":"","source":null,"reasoning":"nothing found"}';
39
+ const parsed = parseSnapshotDetection(raw);
40
+ assert.strictEqual(parsed.snapshot_tag, null);
41
+ });
42
+ void it('falls back to balanced-brace extraction for surrounding prose', () => {
43
+ const raw = 'Analysis: { could be v1 } — but the real answer is ' +
44
+ '{"snapshot_tag":"v1.2.0","source":"CHANGELOG","reasoning":"unreleased section present"}';
45
+ const parsed = parseSnapshotDetection(raw);
46
+ assert.strictEqual(parsed.snapshot_tag, 'v1.2.0');
47
+ assert.strictEqual(parsed.source, 'CHANGELOG');
48
+ });
49
+ void it('throws when no JSON object is present', () => {
50
+ assert.throws(() => parseSnapshotDetection('no json at all'), /JSON/);
51
+ });
52
+ void it('supplies default reasoning when missing', () => {
53
+ const raw = '{"snapshot_tag":"v1","source":"package.json"}';
54
+ const parsed = parseSnapshotDetection(raw);
55
+ assert.strictEqual(parsed.snapshot_tag, 'v1');
56
+ assert.strictEqual(parsed.reasoning, '(no reasoning given)');
57
+ });
58
+ });
59
+ void describe('isPlausibleSnapshotTag', () => {
60
+ void it('accepts normal version tags', () => {
61
+ assert.strictEqual(isPlausibleSnapshotTag('v2.0.0', 'v1.9.0'), true);
62
+ assert.strictEqual(isPlausibleSnapshotTag('2.0.0-rc.1', '1.9.0'), true);
63
+ assert.strictEqual(isPlausibleSnapshotTag('v1.2.3-SNAPSHOT', 'v1.2.2'), true);
64
+ assert.strictEqual(isPlausibleSnapshotTag('release/2.0', 'release/1.9'), true);
65
+ });
66
+ void it('rejects tags identical to the latest release', () => {
67
+ assert.strictEqual(isPlausibleSnapshotTag('v1.0.0', 'v1.0.0'), false);
68
+ });
69
+ void it('rejects empty or overlong tags', () => {
70
+ assert.strictEqual(isPlausibleSnapshotTag('', 'v1'), false);
71
+ assert.strictEqual(isPlausibleSnapshotTag('x'.repeat(101), 'v1'), false);
72
+ });
73
+ void it('rejects whitespace and shell metacharacters', () => {
74
+ assert.strictEqual(isPlausibleSnapshotTag('v 2', 'v1'), false);
75
+ assert.strictEqual(isPlausibleSnapshotTag('v2;rm -rf', 'v1'), false);
76
+ assert.strictEqual(isPlausibleSnapshotTag('v2$PATH', 'v1'), false);
77
+ });
78
+ void it('rejects leading dot or dash, double dot, @{ reflog', () => {
79
+ assert.strictEqual(isPlausibleSnapshotTag('.v2', 'v1'), false);
80
+ assert.strictEqual(isPlausibleSnapshotTag('-v2', 'v1'), false);
81
+ assert.strictEqual(isPlausibleSnapshotTag('v2..rc', 'v1'), false);
82
+ assert.strictEqual(isPlausibleSnapshotTag('v2@{1}', 'v1'), false);
83
+ });
84
+ });
85
+ void describe('buildSnapshotDetectionPrompt', () => {
86
+ void it('injects the latest release tag into the prompt', () => {
87
+ const prompt = buildSnapshotDetectionPrompt('v1.4.2');
88
+ assert.match(prompt, /v1\.4\.2/);
89
+ // Must ask for JSON output
90
+ assert.match(prompt, /JSON/);
91
+ assert.match(prompt, /snapshot_tag/);
92
+ });
93
+ });
@@ -0,0 +1,54 @@
1
+ /**
2
+ * GitHub release helpers for smoke-test generation, implemented on top of
3
+ * @octokit/rest so we share retry / rate-limit / User-Agent behavior with the
4
+ * rest of the packages/edsger codebase.
5
+ */
6
+ export interface GithubRelease {
7
+ id: number;
8
+ tag_name: string;
9
+ name: string | null;
10
+ body: string | null;
11
+ html_url: string;
12
+ published_at: string | null;
13
+ draft: boolean;
14
+ prerelease: boolean;
15
+ }
16
+ export interface CompareFile {
17
+ filename: string;
18
+ status: string;
19
+ additions: number;
20
+ deletions: number;
21
+ changes: number;
22
+ patch?: string;
23
+ }
24
+ export interface CompareCommit {
25
+ sha: string;
26
+ commit: {
27
+ message: string;
28
+ author?: {
29
+ name?: string;
30
+ } | null;
31
+ };
32
+ }
33
+ export interface CompareResponse {
34
+ total_commits: number;
35
+ files: CompareFile[];
36
+ commits: CompareCommit[];
37
+ }
38
+ export interface ReleasePair {
39
+ latest: GithubRelease;
40
+ previous: GithubRelease | null;
41
+ }
42
+ export declare function fetchLatestTwoReleases(owner: string, repo: string, token: string): Promise<ReleasePair>;
43
+ export declare function getDefaultBranchHead(owner: string, repo: string, token: string): Promise<{
44
+ branch: string;
45
+ sha: string;
46
+ }>;
47
+ export declare function fetchCompare(owner: string, repo: string, base: string, head: string, token: string): Promise<CompareResponse>;
48
+ export declare function buildDiffDigest(compare: CompareResponse): string;
49
+ export declare function summariseStats(compare: CompareResponse): {
50
+ files_changed: number;
51
+ additions: number;
52
+ deletions: number;
53
+ total_commits: number;
54
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * GitHub release helpers for smoke-test generation, implemented on top of
3
+ * @octokit/rest so we share retry / rate-limit / User-Agent behavior with the
4
+ * rest of the packages/edsger codebase.
5
+ */
6
+ import { Octokit } from '@octokit/rest';
7
+ const MAX_PATCH_CHARS = 60_000;
8
+ const MAX_COMMITS_INCLUDED = 40;
9
+ function octokit(token) {
10
+ return new Octokit({ auth: token, userAgent: 'edsger-cli' });
11
+ }
12
+ export async function fetchLatestTwoReleases(owner, repo, token) {
13
+ const gh = octokit(token);
14
+ const { data } = await gh.repos.listReleases({ owner, repo, per_page: 10 });
15
+ const real = data.filter((r) => !r.draft);
16
+ if (real.length === 0) {
17
+ throw new Error(`Repository ${owner}/${repo} has no releases yet. Publish one first.`);
18
+ }
19
+ return { latest: real[0], previous: real[1] ?? null };
20
+ }
21
+ export async function getDefaultBranchHead(owner, repo, token) {
22
+ const gh = octokit(token);
23
+ const { data: repoInfo } = await gh.repos.get({ owner, repo });
24
+ const branch = repoInfo.default_branch;
25
+ const { data: branchInfo } = await gh.repos.getBranch({
26
+ owner,
27
+ repo,
28
+ branch,
29
+ });
30
+ return { branch, sha: branchInfo.commit.sha };
31
+ }
32
+ export async function fetchCompare(owner, repo, base, head, token) {
33
+ const gh = octokit(token);
34
+ const { data } = await gh.repos.compareCommits({
35
+ owner,
36
+ repo,
37
+ base,
38
+ head,
39
+ });
40
+ // Octokit returns a richer shape; narrow to the subset we consume.
41
+ return {
42
+ total_commits: data.total_commits ?? 0,
43
+ files: (data.files ?? []).map((f) => ({
44
+ filename: f.filename,
45
+ status: f.status,
46
+ additions: f.additions ?? 0,
47
+ deletions: f.deletions ?? 0,
48
+ changes: f.changes ?? 0,
49
+ patch: f.patch,
50
+ })),
51
+ commits: (data.commits ?? []).map((c) => ({
52
+ sha: c.sha,
53
+ commit: {
54
+ message: c.commit?.message ?? '',
55
+ author: c.commit?.author
56
+ ? { name: c.commit.author.name ?? undefined }
57
+ : null,
58
+ },
59
+ })),
60
+ };
61
+ }
62
+ export function buildDiffDigest(compare) {
63
+ const lines = [];
64
+ lines.push(`Total commits: ${compare.total_commits}`);
65
+ lines.push('\n== Commits ==');
66
+ for (const c of compare.commits.slice(0, MAX_COMMITS_INCLUDED)) {
67
+ const subject = (c.commit.message || '').split('\n')[0].slice(0, 200);
68
+ lines.push(`- ${c.sha.slice(0, 7)} ${subject}`);
69
+ }
70
+ lines.push('\n== Files ==');
71
+ for (const f of compare.files) {
72
+ lines.push(`- ${f.status} ${f.filename} (+${f.additions}/-${f.deletions})`);
73
+ }
74
+ lines.push('\n== Patches (truncated) ==');
75
+ let budget = MAX_PATCH_CHARS;
76
+ for (const f of compare.files) {
77
+ if (budget <= 0 || !f.patch) {
78
+ continue;
79
+ }
80
+ const header = `\n--- ${f.filename} ---\n`;
81
+ const piece = header + f.patch;
82
+ if (piece.length > budget) {
83
+ lines.push(piece.slice(0, budget));
84
+ lines.push('\n...[truncated]');
85
+ budget = 0;
86
+ }
87
+ else {
88
+ lines.push(piece);
89
+ budget -= piece.length;
90
+ }
91
+ }
92
+ return lines.join('\n');
93
+ }
94
+ export function summariseStats(compare) {
95
+ return {
96
+ files_changed: compare.files.length,
97
+ additions: compare.files.reduce((s, f) => s + f.additions, 0),
98
+ deletions: compare.files.reduce((s, f) => s + f.deletions, 0),
99
+ total_commits: compare.total_commits,
100
+ };
101
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Release sync: reconcile the `releases` table with GitHub releases for a
3
+ * product. Writes a `pending` row for each release we discover (latest +
4
+ * previous + any unreleased snapshot version). Does NOT generate smoke-test
5
+ * cases — that is handled per-release by `phases/smoke-test` once the user
6
+ * opts in from the release detail page.
7
+ */
8
+ import { type EdsgerConfig } from '../../types/index.js';
9
+ export interface ReleaseSyncOptions {
10
+ productId: string;
11
+ verbose?: boolean;
12
+ }
13
+ export interface ReleaseSyncResult {
14
+ status: 'success' | 'error';
15
+ productId: string;
16
+ summary: string;
17
+ /** Releases that were created or updated during this sync. */
18
+ syncedReleases?: {
19
+ id: string;
20
+ tag: string;
21
+ isSnapshot: boolean;
22
+ }[];
23
+ }
24
+ export declare function runReleaseSync(options: ReleaseSyncOptions, _config: EdsgerConfig): Promise<ReleaseSyncResult>;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Release sync: reconcile the `releases` table with GitHub releases for a
3
+ * product. Writes a `pending` row for each release we discover (latest +
4
+ * previous + any unreleased snapshot version). Does NOT generate smoke-test
5
+ * cases — that is handled per-release by `phases/smoke-test` once the user
6
+ * opts in from the release detail page.
7
+ */
8
+ import { getGitHubConfigByProduct } from '../../api/github.js';
9
+ import { getReleaseByTag, upsertRelease, } from '../../api/releases.js';
10
+ import { logInfo, logSuccess, logWarning } from '../../utils/logger.js';
11
+ import { cloneFeatureRepo, ensureWorkspaceDir, syncRepoToRef, } from '../../workspace/workspace-manager.js';
12
+ import { fetchLatestTwoReleases, getDefaultBranchHead, } from './github.js';
13
+ import { detectSnapshotVersion, isPlausibleSnapshotTag } from './snapshot.js';
14
+ /**
15
+ * Upsert a release row as `pending` only when it doesn't already exist.
16
+ * Preserves `ready` / `failed` / `generating` status on existing rows so
17
+ * repeated syncs don't clobber smoke-test progress.
18
+ */
19
+ async function ensureReleaseRow(args, verbose) {
20
+ const existing = await getReleaseByTag(args.productId, args.tag, verbose);
21
+ if (existing) {
22
+ return { release: existing, created: false };
23
+ }
24
+ const release = await upsertRelease({
25
+ product_id: args.productId,
26
+ tag: args.tag,
27
+ name: args.githubRelease?.name ?? null,
28
+ body: args.githubRelease?.body ?? null,
29
+ url: args.githubRelease?.html_url ?? null,
30
+ published_at: args.githubRelease?.published_at ?? null,
31
+ previous_tag: args.previousTag,
32
+ previous_published_at: args.previousPublishedAt,
33
+ status: 'pending',
34
+ }, verbose);
35
+ return { release, created: true };
36
+ }
37
+ // eslint-disable-next-line complexity -- orchestration across GitHub + DB + snapshot
38
+ export async function runReleaseSync(options, _config) {
39
+ const { productId, verbose } = options;
40
+ if (verbose) {
41
+ logInfo(`Starting release sync for product: ${productId}`);
42
+ }
43
+ const gh = await getGitHubConfigByProduct(productId, verbose);
44
+ if (!gh.configured || !gh.token || !gh.owner || !gh.repo) {
45
+ return {
46
+ status: 'error',
47
+ productId,
48
+ summary: gh.message ||
49
+ 'Product is not connected to a GitHub repository. Connect it in Product Settings.',
50
+ };
51
+ }
52
+ const releases = await fetchLatestTwoReleases(gh.owner, gh.repo, gh.token);
53
+ const { latest, previous } = releases;
54
+ if (verbose) {
55
+ logInfo(`Latest GitHub release: ${latest.tag_name}, previous: ${previous?.tag_name ?? '(none)'}`);
56
+ }
57
+ const synced = [];
58
+ // Always reflect the latest GitHub release.
59
+ const latestRow = await ensureReleaseRow({
60
+ productId,
61
+ tag: latest.tag_name,
62
+ previousTag: previous?.tag_name ?? null,
63
+ previousPublishedAt: previous?.published_at ?? null,
64
+ githubRelease: latest,
65
+ }, verbose);
66
+ synced.push({
67
+ id: latestRow.release.id,
68
+ tag: latestRow.release.tag,
69
+ isSnapshot: false,
70
+ });
71
+ if (latestRow.created) {
72
+ logInfo(`Synced release ${latest.tag_name}`);
73
+ }
74
+ // Reflect the previous GitHub release so the UI can show history, even
75
+ // if smoke-test was never run against it.
76
+ if (previous) {
77
+ const previousRow = await ensureReleaseRow({
78
+ productId,
79
+ tag: previous.tag_name,
80
+ previousTag: null,
81
+ previousPublishedAt: null,
82
+ githubRelease: previous,
83
+ }, verbose);
84
+ synced.push({
85
+ id: previousRow.release.id,
86
+ tag: previousRow.release.tag,
87
+ isSnapshot: false,
88
+ });
89
+ if (previousRow.created) {
90
+ logInfo(`Synced release ${previous.tag_name}`);
91
+ }
92
+ }
93
+ // Snapshot detection: clone the repo at the default branch tip and ask
94
+ // the agent whether there's an unreleased version ahead of `latest`.
95
+ let cwd;
96
+ try {
97
+ const workspaceRoot = ensureWorkspaceDir();
98
+ const { repoPath } = cloneFeatureRepo(workspaceRoot, `release-sync-${productId}`, gh.owner, gh.repo, gh.token);
99
+ cwd = repoPath;
100
+ }
101
+ catch (err) {
102
+ logWarning(`Could not clone repo for snapshot detection: ${err instanceof Error ? err.message : String(err)}`);
103
+ }
104
+ if (cwd) {
105
+ try {
106
+ const { branch } = await getDefaultBranchHead(gh.owner, gh.repo, gh.token);
107
+ syncRepoToRef(cwd, { branch }, gh.token);
108
+ const detection = await detectSnapshotVersion({
109
+ cwd,
110
+ latestReleaseTag: latest.tag_name,
111
+ config: _config,
112
+ verbose,
113
+ });
114
+ if (detection.snapshot_tag &&
115
+ isPlausibleSnapshotTag(detection.snapshot_tag, latest.tag_name)) {
116
+ const snapshotRow = await ensureReleaseRow({
117
+ productId,
118
+ tag: detection.snapshot_tag,
119
+ previousTag: latest.tag_name,
120
+ previousPublishedAt: latest.published_at ?? null,
121
+ githubRelease: null,
122
+ }, verbose);
123
+ synced.push({
124
+ id: snapshotRow.release.id,
125
+ tag: snapshotRow.release.tag,
126
+ isSnapshot: true,
127
+ });
128
+ if (snapshotRow.created) {
129
+ logInfo(`Detected unreleased snapshot ${detection.snapshot_tag} (${detection.source ?? 'unknown source'})`);
130
+ }
131
+ }
132
+ else if (verbose) {
133
+ logInfo(`No snapshot version ahead of ${latest.tag_name}`);
134
+ }
135
+ }
136
+ catch (err) {
137
+ logWarning(`Snapshot detection skipped: ${err instanceof Error ? err.message : String(err)}`);
138
+ }
139
+ }
140
+ logSuccess(`Synced ${synced.length} release${synced.length === 1 ? '' : 's'}`);
141
+ return {
142
+ status: 'success',
143
+ productId,
144
+ summary: `Synced ${synced.length} release${synced.length === 1 ? '' : 's'} from GitHub`,
145
+ syncedReleases: synced,
146
+ };
147
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Snapshot detection: after the latest GitHub release already has a
3
+ * smoke-test plan, inspect the cloned repo for a yet-to-be-released
4
+ * "snapshot" version (next package.json version, an [Unreleased] entry
5
+ * in CHANGELOG, an unreleased git tag, etc.) so we can prepare the
6
+ * next smoke test before anyone cuts the tag on GitHub.
7
+ */
8
+ import { type EdsgerConfig } from '../../types/index.js';
9
+ export interface SnapshotDetection {
10
+ snapshot_tag: string | null;
11
+ source: string | null;
12
+ reasoning: string;
13
+ }
14
+ export declare function buildSnapshotDetectionPrompt(latestReleaseTag: string): string;
15
+ export declare function parseSnapshotDetection(raw: string): SnapshotDetection;
16
+ /**
17
+ * Very loose sanity check on a proposed snapshot tag. We reject tags
18
+ * that are obviously the same as the latest release or that contain
19
+ * characters that would break downstream git / GitHub API calls.
20
+ */
21
+ export declare function isPlausibleSnapshotTag(candidate: string, latestReleaseTag: string): boolean;
22
+ export declare function detectSnapshotVersion(options: {
23
+ cwd: string;
24
+ latestReleaseTag: string;
25
+ config: EdsgerConfig;
26
+ verbose?: boolean;
27
+ }): Promise<SnapshotDetection>;