edsger 0.46.0 → 0.48.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 (121) hide show
  1. package/.claude/settings.local.json +3 -23
  2. package/dist/api/__tests__/app-store.test.d.ts +7 -0
  3. package/dist/api/__tests__/app-store.test.js +60 -0
  4. package/dist/api/__tests__/intelligence.test.d.ts +11 -0
  5. package/dist/api/__tests__/intelligence.test.js +315 -0
  6. package/dist/api/features/__tests__/feature-utils.test.d.ts +4 -0
  7. package/dist/api/features/__tests__/feature-utils.test.js +370 -0
  8. package/dist/api/features/__tests__/status-updater.test.d.ts +4 -0
  9. package/dist/api/features/__tests__/status-updater.test.js +88 -0
  10. package/dist/commands/build/__tests__/build.test.d.ts +5 -0
  11. package/dist/commands/build/__tests__/build.test.js +206 -0
  12. package/dist/commands/build/__tests__/detect-project.test.d.ts +6 -0
  13. package/dist/commands/build/__tests__/detect-project.test.js +160 -0
  14. package/dist/commands/build/__tests__/run-build.test.d.ts +6 -0
  15. package/dist/commands/build/__tests__/run-build.test.js +433 -0
  16. package/dist/commands/intelligence/__tests__/command.test.d.ts +4 -0
  17. package/dist/commands/intelligence/__tests__/command.test.js +48 -0
  18. package/dist/commands/run-sheet/index.js +6 -0
  19. package/dist/commands/workflow/core/__tests__/feature-filter.test.d.ts +5 -0
  20. package/dist/commands/workflow/core/__tests__/feature-filter.test.js +316 -0
  21. package/dist/commands/workflow/core/__tests__/pipeline-evaluator.test.d.ts +4 -0
  22. package/dist/commands/workflow/core/__tests__/pipeline-evaluator.test.js +397 -0
  23. package/dist/commands/workflow/core/__tests__/state-manager.test.d.ts +4 -0
  24. package/dist/commands/workflow/core/__tests__/state-manager.test.js +384 -0
  25. package/dist/config/__tests__/config.test.d.ts +4 -0
  26. package/dist/config/__tests__/config.test.js +286 -0
  27. package/dist/config/__tests__/feature-status.test.d.ts +4 -0
  28. package/dist/config/__tests__/feature-status.test.js +111 -0
  29. package/dist/errors/__tests__/index.test.d.ts +4 -0
  30. package/dist/errors/__tests__/index.test.js +349 -0
  31. package/dist/index.js +0 -0
  32. package/dist/phases/app-store-generation/__tests__/agent.test.d.ts +5 -0
  33. package/dist/phases/app-store-generation/__tests__/agent.test.js +142 -0
  34. package/dist/phases/app-store-generation/__tests__/context.test.d.ts +4 -0
  35. package/dist/phases/app-store-generation/__tests__/context.test.js +284 -0
  36. package/dist/phases/app-store-generation/__tests__/prompts.test.d.ts +4 -0
  37. package/dist/phases/app-store-generation/__tests__/prompts.test.js +122 -0
  38. package/dist/phases/app-store-generation/__tests__/screenshot-composer.test.d.ts +5 -0
  39. package/dist/phases/app-store-generation/__tests__/screenshot-composer.test.js +826 -0
  40. package/dist/phases/code-review/__tests__/diff-utils.test.d.ts +1 -0
  41. package/dist/phases/code-review/__tests__/diff-utils.test.js +101 -0
  42. package/dist/phases/intelligence-analysis/__tests__/context.test.d.ts +4 -0
  43. package/dist/phases/intelligence-analysis/__tests__/context.test.js +192 -0
  44. package/dist/phases/intelligence-analysis/__tests__/matching.test.d.ts +13 -0
  45. package/dist/phases/intelligence-analysis/__tests__/matching.test.js +154 -0
  46. package/dist/phases/intelligence-analysis/__tests__/orchestration.test.d.ts +5 -0
  47. package/dist/phases/intelligence-analysis/__tests__/orchestration.test.js +378 -0
  48. package/dist/phases/intelligence-analysis/__tests__/prompts.test.d.ts +4 -0
  49. package/dist/phases/intelligence-analysis/__tests__/prompts.test.js +33 -0
  50. package/dist/phases/pr-execution/__tests__/file-assigner.test.d.ts +1 -0
  51. package/dist/phases/pr-execution/__tests__/file-assigner.test.js +303 -0
  52. package/dist/phases/pr-resolve/__tests__/checklist-learner.test.d.ts +1 -0
  53. package/dist/phases/pr-resolve/__tests__/checklist-learner.test.js +157 -0
  54. package/dist/phases/pr-resolve/__tests__/prompts.test.d.ts +1 -0
  55. package/dist/phases/pr-resolve/__tests__/prompts.test.js +116 -0
  56. package/dist/phases/pr-resolve/__tests__/resolve-mapping.test.d.ts +1 -0
  57. package/dist/phases/pr-resolve/__tests__/resolve-mapping.test.js +138 -0
  58. package/dist/phases/pr-resolve/__tests__/types.test.d.ts +1 -0
  59. package/dist/phases/pr-resolve/__tests__/types.test.js +43 -0
  60. package/dist/phases/pr-resolve/__tests__/workspace.test.d.ts +1 -0
  61. package/dist/phases/pr-resolve/__tests__/workspace.test.js +111 -0
  62. package/dist/phases/pr-review/__tests__/prompts.test.d.ts +1 -0
  63. package/dist/phases/pr-review/__tests__/prompts.test.js +49 -0
  64. package/dist/phases/pr-review/__tests__/review-comments.test.d.ts +1 -0
  65. package/dist/phases/pr-review/__tests__/review-comments.test.js +110 -0
  66. package/dist/phases/pr-shared/__tests__/agent-utils.test.d.ts +1 -0
  67. package/dist/phases/pr-shared/__tests__/agent-utils.test.js +91 -0
  68. package/dist/phases/pr-shared/__tests__/context.test.d.ts +1 -0
  69. package/dist/phases/pr-shared/__tests__/context.test.js +94 -0
  70. package/dist/phases/pr-splitting/__tests__/import-dep-validator.test.d.ts +1 -0
  71. package/dist/phases/pr-splitting/__tests__/import-dep-validator.test.js +331 -0
  72. package/dist/phases/release-sync/github.d.ts +12 -0
  73. package/dist/phases/release-sync/github.js +39 -0
  74. package/dist/phases/release-sync/snapshot.js +0 -1
  75. package/dist/phases/run-sheet/index.d.ts +15 -0
  76. package/dist/phases/run-sheet/index.js +154 -22
  77. package/dist/phases/run-sheet/render.d.ts +23 -5
  78. package/dist/phases/run-sheet/render.js +193 -31
  79. package/dist/phases/smoke-test/__tests__/agent.test.d.ts +4 -0
  80. package/dist/phases/smoke-test/__tests__/agent.test.js +84 -0
  81. package/dist/phases/smoke-test/__tests__/github.test.d.ts +9 -0
  82. package/dist/phases/smoke-test/__tests__/github.test.js +120 -0
  83. package/dist/phases/smoke-test/__tests__/snapshot.test.d.ts +8 -0
  84. package/dist/phases/smoke-test/__tests__/snapshot.test.js +93 -0
  85. package/dist/phases/smoke-test/github.d.ts +54 -0
  86. package/dist/phases/smoke-test/github.js +101 -0
  87. package/dist/phases/smoke-test/snapshot.d.ts +27 -0
  88. package/dist/phases/smoke-test/snapshot.js +157 -0
  89. package/dist/services/coaching/__tests__/coaching-agent.test.d.ts +1 -0
  90. package/dist/services/coaching/__tests__/coaching-agent.test.js +74 -0
  91. package/dist/services/coaching/__tests__/coaching-loop.test.d.ts +1 -0
  92. package/dist/services/coaching/__tests__/coaching-loop.test.js +59 -0
  93. package/dist/services/coaching/__tests__/self-rating.test.d.ts +1 -0
  94. package/dist/services/coaching/__tests__/self-rating.test.js +188 -0
  95. package/dist/services/lifecycle-agent/__tests__/phase-criteria.test.d.ts +4 -0
  96. package/dist/services/lifecycle-agent/__tests__/phase-criteria.test.js +133 -0
  97. package/dist/services/lifecycle-agent/__tests__/transition-rules.test.d.ts +4 -0
  98. package/dist/services/lifecycle-agent/__tests__/transition-rules.test.js +336 -0
  99. package/dist/services/lifecycle-agent/index.d.ts +24 -0
  100. package/dist/services/lifecycle-agent/index.js +25 -0
  101. package/dist/services/lifecycle-agent/phase-criteria.d.ts +57 -0
  102. package/dist/services/lifecycle-agent/phase-criteria.js +335 -0
  103. package/dist/services/lifecycle-agent/transition-rules.d.ts +60 -0
  104. package/dist/services/lifecycle-agent/transition-rules.js +184 -0
  105. package/dist/services/lifecycle-agent/types.d.ts +190 -0
  106. package/dist/services/lifecycle-agent/types.js +12 -0
  107. package/dist/services/phase-hooks/__tests__/bindings-fetcher.test.d.ts +1 -0
  108. package/dist/services/phase-hooks/__tests__/bindings-fetcher.test.js +122 -0
  109. package/dist/services/phase-hooks/__tests__/hook-executor.test.d.ts +1 -0
  110. package/dist/services/phase-hooks/__tests__/hook-executor.test.js +321 -0
  111. package/dist/services/phase-hooks/__tests__/hook-runner.test.d.ts +1 -0
  112. package/dist/services/phase-hooks/__tests__/hook-runner.test.js +261 -0
  113. package/dist/services/phase-hooks/__tests__/plugin-loader.test.d.ts +1 -0
  114. package/dist/services/phase-hooks/__tests__/plugin-loader.test.js +158 -0
  115. package/dist/services/video/__tests__/video-pipeline.test.d.ts +6 -0
  116. package/dist/services/video/__tests__/video-pipeline.test.js +249 -0
  117. package/dist/workspace/__tests__/workspace-manager.test.d.ts +7 -0
  118. package/dist/workspace/__tests__/workspace-manager.test.js +52 -0
  119. package/dist/workspace/workspace-manager.js +17 -4
  120. package/package.json +1 -1
  121. package/.env.local +0 -12
@@ -0,0 +1,9 @@
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
+ export {};
@@ -0,0 +1,120 @@
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: { message: 'feat: add checkout flow\n\nmore body', author: null },
19
+ },
20
+ {
21
+ sha: '2222222bbbbbbbb',
22
+ commit: { message: 'fix: null deref', author: { name: 'Ada' } },
23
+ },
24
+ ],
25
+ files: [
26
+ {
27
+ filename: 'src/checkout.ts',
28
+ status: 'modified',
29
+ additions: 10,
30
+ deletions: 2,
31
+ changes: 12,
32
+ patch: '@@ -1 +1 @@\n-old\n+new',
33
+ },
34
+ {
35
+ filename: 'src/util.ts',
36
+ status: 'added',
37
+ additions: 5,
38
+ deletions: 0,
39
+ changes: 5,
40
+ },
41
+ ],
42
+ ...over,
43
+ };
44
+ }
45
+ void describe('summariseStats', () => {
46
+ void it('sums additions, deletions, and file count', () => {
47
+ const stats = summariseStats(makeCompare());
48
+ assert.deepStrictEqual(stats, {
49
+ files_changed: 2,
50
+ additions: 15,
51
+ deletions: 2,
52
+ total_commits: 2,
53
+ });
54
+ });
55
+ void it('handles an empty diff', () => {
56
+ const stats = summariseStats({
57
+ total_commits: 0,
58
+ commits: [],
59
+ files: [],
60
+ });
61
+ assert.deepStrictEqual(stats, {
62
+ files_changed: 0,
63
+ additions: 0,
64
+ deletions: 0,
65
+ total_commits: 0,
66
+ });
67
+ });
68
+ });
69
+ void describe('buildDiffDigest', () => {
70
+ void it('includes commit subjects, file list, and patches', () => {
71
+ const digest = buildDiffDigest(makeCompare());
72
+ assert.match(digest, /Total commits: 2/);
73
+ assert.match(digest, /1111111 feat: add checkout flow/);
74
+ assert.match(digest, /2222222 fix: null deref/);
75
+ assert.match(digest, /modified src\/checkout\.ts \(\+10\/-2\)/);
76
+ assert.match(digest, /added src\/util\.ts \(\+5\/-0\)/);
77
+ assert.match(digest, /--- src\/checkout\.ts ---/);
78
+ assert.match(digest, /\+new/);
79
+ });
80
+ void it('truncates only the subject line of multi-line commit messages', () => {
81
+ const digest = buildDiffDigest(makeCompare());
82
+ // "more body" from the first commit's message body must not leak in.
83
+ assert.ok(!digest.includes('more body'));
84
+ });
85
+ void it('caps the patch budget and appends a truncation marker', () => {
86
+ const huge = 'x'.repeat(200_000);
87
+ const compare = makeCompare({
88
+ files: [
89
+ {
90
+ filename: 'src/big.ts',
91
+ status: 'modified',
92
+ additions: 1,
93
+ deletions: 0,
94
+ changes: 1,
95
+ patch: huge,
96
+ },
97
+ ],
98
+ });
99
+ const digest = buildDiffDigest(compare);
100
+ assert.match(digest, /\[truncated\]/);
101
+ // Even with a 200k patch, digest stays bounded by the internal budget.
102
+ assert.ok(digest.length < 200_000);
103
+ });
104
+ void it('skips files without patches in the patches section', () => {
105
+ const compare = makeCompare({
106
+ files: [
107
+ {
108
+ filename: 'vendored.min.js',
109
+ status: 'added',
110
+ additions: 1,
111
+ deletions: 0,
112
+ changes: 1,
113
+ },
114
+ ],
115
+ });
116
+ const digest = buildDiffDigest(compare);
117
+ assert.ok(digest.includes('== Patches (truncated) =='));
118
+ assert.ok(!digest.includes('--- vendored.min.js ---'));
119
+ });
120
+ });
@@ -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,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>;
@@ -0,0 +1,157 @@
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 { query } from '@anthropic-ai/claude-agent-sdk';
9
+ import { DEFAULT_MODEL } from '../../constants.js';
10
+ import { logDebug, logInfo } from '../../utils/logger.js';
11
+ import { findBalancedJsonObject } from './agent.js';
12
+ export function buildSnapshotDetectionPrompt(latestReleaseTag) {
13
+ return `You are inspecting a code repository to decide whether an unreleased "snapshot" version is being prepared.
14
+
15
+ The most recent shipped release on GitHub is tagged: **${latestReleaseTag}**
16
+
17
+ Your job:
18
+
19
+ 1. Read the repository's primary version source. In priority order:
20
+ - package.json "version" field (JS/TS projects)
21
+ - Cargo.toml [package] version (Rust)
22
+ - pyproject.toml [project] / [tool.poetry] version (Python)
23
+ - pom.xml <version> (Java / Maven)
24
+ - VERSION file (plain text)
25
+ 2. Read CHANGELOG.md / HISTORY.md / RELEASES.md for an [Unreleased] or similarly labelled section.
26
+ 3. Run \`git tag --list\` and \`git tag --sort=-creatordate | head -5\` to look for tags newer than ${latestReleaseTag} that have not yet been cut as GitHub releases.
27
+
28
+ Then decide:
29
+ - If the primary version source is strictly greater than ${latestReleaseTag} (accounting for "v" prefixes and semver prerelease suffixes like \`-SNAPSHOT\`, \`-rc.1\`, \`-next.0\`), OR there is a newer unreleased git tag, report that string as \`snapshot_tag\`.
30
+ - Otherwise report \`snapshot_tag: null\`.
31
+ - Do NOT invent a version. Use the exact string from the source file. Preserve the repo's existing tag convention (e.g. if releases are \`v1.2.3\` but package.json says \`1.2.3\`, return \`v1.2.3\`).
32
+
33
+ Respond with ONLY a JSON object — no prose, no markdown fences:
34
+
35
+ {
36
+ "snapshot_tag": "v2.0.0" | null,
37
+ "source": "package.json" | "Cargo.toml" | "pyproject.toml" | "pom.xml" | "VERSION" | "CHANGELOG" | "git_tag" | null,
38
+ "reasoning": "<one sentence>"
39
+ }`;
40
+ }
41
+ export function parseSnapshotDetection(raw) {
42
+ let body = raw.trim();
43
+ const fence = body.match(/```(?:json)?\s*([\s\S]*?)```/);
44
+ if (fence) {
45
+ body = fence[1].trim();
46
+ }
47
+ let parsed;
48
+ try {
49
+ parsed = JSON.parse(body);
50
+ }
51
+ catch {
52
+ const object = findBalancedJsonObject(body);
53
+ if (!object) {
54
+ throw new Error('No JSON object found in snapshot-detection output');
55
+ }
56
+ parsed = JSON.parse(object);
57
+ }
58
+ if (typeof parsed !== 'object' || parsed === null) {
59
+ throw new Error('Snapshot detection returned non-object response');
60
+ }
61
+ const obj = parsed;
62
+ const rawTag = obj.snapshot_tag;
63
+ const snapshotTag = typeof rawTag === 'string' && rawTag.trim().length > 0
64
+ ? rawTag.trim()
65
+ : null;
66
+ const source = typeof obj.source === 'string' ? obj.source : null;
67
+ const reasoning = typeof obj.reasoning === 'string' ? obj.reasoning : '(no reasoning given)';
68
+ return { snapshot_tag: snapshotTag, source, reasoning };
69
+ }
70
+ /**
71
+ * Very loose sanity check on a proposed snapshot tag. We reject tags
72
+ * that are obviously the same as the latest release or that contain
73
+ * characters that would break downstream git / GitHub API calls.
74
+ */
75
+ export function isPlausibleSnapshotTag(candidate, latestReleaseTag) {
76
+ if (candidate === latestReleaseTag) {
77
+ return false;
78
+ }
79
+ if (candidate.length === 0 || candidate.length > 100) {
80
+ return false;
81
+ }
82
+ if (/\s/.test(candidate)) {
83
+ return false;
84
+ }
85
+ if (/^[-.]/.test(candidate) || candidate.includes('..') || candidate.includes('@{')) {
86
+ return false;
87
+ }
88
+ return /^[A-Za-z0-9._\-+/@]+$/.test(candidate);
89
+ }
90
+ function userMessage(content) {
91
+ return { type: 'user', message: { role: 'user', content } };
92
+ }
93
+ // eslint-disable-next-line @typescript-eslint/require-await -- async generator required by SDK interface
94
+ async function* makePrompt(text) {
95
+ yield userMessage(text);
96
+ }
97
+ // eslint-disable-next-line complexity -- agent loop with message-type handling
98
+ export async function detectSnapshotVersion(options) {
99
+ const { cwd, latestReleaseTag, config, verbose } = options;
100
+ if (verbose) {
101
+ logInfo(`Detecting snapshot version ahead of ${latestReleaseTag}...`);
102
+ }
103
+ let lastAssistant = '';
104
+ let detection = null;
105
+ for await (const message of query({
106
+ prompt: makePrompt(buildSnapshotDetectionPrompt(latestReleaseTag)),
107
+ options: {
108
+ systemPrompt: {
109
+ type: 'preset',
110
+ preset: 'claude_code',
111
+ },
112
+ model: config.model || DEFAULT_MODEL,
113
+ maxTurns: 10,
114
+ permissionMode: 'bypassPermissions',
115
+ cwd,
116
+ },
117
+ })) {
118
+ if (message.type === 'assistant' && message.message?.content) {
119
+ for (const content of message.message.content) {
120
+ if (content.type === 'text') {
121
+ lastAssistant += `${content.text}\n`;
122
+ logDebug(content.text, verbose);
123
+ }
124
+ }
125
+ }
126
+ if (message.type === 'result') {
127
+ const text = message.result || lastAssistant;
128
+ try {
129
+ detection = parseSnapshotDetection(text);
130
+ }
131
+ catch (err) {
132
+ if (verbose) {
133
+ logDebug(`Snapshot detection parse error: ${err instanceof Error ? err.message : String(err)}`, verbose);
134
+ }
135
+ }
136
+ }
137
+ }
138
+ if (!detection) {
139
+ return {
140
+ snapshot_tag: null,
141
+ source: null,
142
+ reasoning: 'Could not parse detection response',
143
+ };
144
+ }
145
+ // Validate the proposed tag before returning.
146
+ if (detection.snapshot_tag !== null &&
147
+ !isPlausibleSnapshotTag(detection.snapshot_tag, latestReleaseTag)) {
148
+ if (verbose) {
149
+ logInfo(`Rejecting implausible snapshot tag: ${JSON.stringify(detection.snapshot_tag)}`);
150
+ }
151
+ return {
152
+ ...detection,
153
+ snapshot_tag: null,
154
+ };
155
+ }
156
+ return detection;
157
+ }
@@ -0,0 +1,74 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { buildImprovementPrompt, } from '../coaching-agent.js';
4
+ void describe('buildImprovementPrompt', () => {
5
+ const decision = {
6
+ shouldContinue: true,
7
+ reasoning: 'Completeness is weak, needs more coverage',
8
+ focusAreas: ['completeness', 'accuracy'],
9
+ suggestions: [
10
+ 'Add error handling section',
11
+ 'Include database migration plan',
12
+ ],
13
+ };
14
+ const rating = {
15
+ score: 72,
16
+ summary: 'Decent but incomplete',
17
+ criteria_scores: {
18
+ completeness: { score: 60, reason: 'Missing sections' },
19
+ accuracy: { score: 75, reason: 'Minor issues' },
20
+ quality: { score: 82, reason: 'Good structure' },
21
+ },
22
+ strengths: ['Clean structure'],
23
+ weaknesses: ['Missing error handling', 'No migration plan'],
24
+ };
25
+ void it('includes current score and target', () => {
26
+ const prompt = buildImprovementPrompt(decision, rating);
27
+ assert.ok(prompt.includes('72/100'));
28
+ assert.ok(prompt.includes('100/100'));
29
+ });
30
+ void it('includes coaching reasoning', () => {
31
+ const prompt = buildImprovementPrompt(decision, rating);
32
+ assert.ok(prompt.includes('Completeness is weak, needs more coverage'));
33
+ });
34
+ void it('includes focus areas with scores', () => {
35
+ const prompt = buildImprovementPrompt(decision, rating);
36
+ assert.ok(prompt.includes('completeness'));
37
+ assert.ok(prompt.includes('60/100'));
38
+ assert.ok(prompt.includes('accuracy'));
39
+ assert.ok(prompt.includes('75/100'));
40
+ });
41
+ void it('includes specific suggestions', () => {
42
+ const prompt = buildImprovementPrompt(decision, rating);
43
+ assert.ok(prompt.includes('Add error handling section'));
44
+ assert.ok(prompt.includes('Include database migration plan'));
45
+ });
46
+ void it('includes weaknesses to address', () => {
47
+ const prompt = buildImprovementPrompt(decision, rating);
48
+ assert.ok(prompt.includes('Missing error handling'));
49
+ assert.ok(prompt.includes('No migration plan'));
50
+ });
51
+ void it('handles empty focus areas gracefully', () => {
52
+ const emptyDecision = {
53
+ shouldContinue: true,
54
+ reasoning: 'General improvement needed',
55
+ focusAreas: [],
56
+ suggestions: ['Improve overall'],
57
+ };
58
+ const prompt = buildImprovementPrompt(emptyDecision, rating);
59
+ assert.ok(prompt.includes('General improvement needed'));
60
+ assert.ok(prompt.includes('Improve overall'));
61
+ });
62
+ void it('handles focus areas not present in criteria_scores', () => {
63
+ const decisionWithUnknown = {
64
+ shouldContinue: true,
65
+ reasoning: 'test',
66
+ focusAreas: ['nonexistent_criterion'],
67
+ suggestions: ['test'],
68
+ };
69
+ const prompt = buildImprovementPrompt(decisionWithUnknown, rating);
70
+ // Should not crash, should show '?' for missing score
71
+ assert.ok(prompt.includes('nonexistent_criterion'));
72
+ assert.ok(prompt.includes('?/100'));
73
+ });
74
+ });