ensemble-review 1.0.35 → 1.0.36

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 (129) hide show
  1. package/package.json +5 -2
  2. package/dist/ai/check-tool.js +0 -6
  3. package/dist/api/routes/auth.js +0 -194
  4. package/dist/api/routes/billing.js +0 -209
  5. package/dist/api/routes/claude-review.js +0 -522
  6. package/dist/api/routes/contact.js +0 -318
  7. package/dist/api/routes/feed.js +0 -21
  8. package/dist/api/routes/inbox.js +0 -45
  9. package/dist/api/routes/mentions.js +0 -22
  10. package/dist/api/routes/teams.js +0 -150
  11. package/dist/api/routes/webhooks.js +0 -181
  12. package/dist/coding/activity.js +0 -80
  13. package/dist/coding/agent.js +0 -147
  14. package/dist/coding/ai-fix/checks-preview.js +0 -58
  15. package/dist/coding/ai-fix/comment-seed.js +0 -519
  16. package/dist/coding/ai-fix/prompts.js +0 -283
  17. package/dist/coding/ai-resolve/prompt.js +0 -161
  18. package/dist/coding/ai-resolve/routes.js +0 -97
  19. package/dist/coding/ai-resolve/run.js +0 -343
  20. package/dist/coding/ai-resolve/schema.js +0 -26
  21. package/dist/coding/ai-resolve/validate.js +0 -136
  22. package/dist/coding/checks/deny-scan.js +0 -75
  23. package/dist/coding/checks/discover.js +0 -541
  24. package/dist/coding/checks/docker.js +0 -38
  25. package/dist/coding/checks/env.js +0 -88
  26. package/dist/coding/checks/hooks.js +0 -91
  27. package/dist/coding/checks/index.js +0 -8
  28. package/dist/coding/checks/local.js +0 -40
  29. package/dist/coding/checks/sandbox.js +0 -206
  30. package/dist/coding/checks/session.js +0 -518
  31. package/dist/coding/checks/spawn.js +0 -123
  32. package/dist/coding/checks/spec.js +0 -140
  33. package/dist/coding/checks/types.js +0 -6
  34. package/dist/coding/partial-spend.js +0 -19
  35. package/dist/coding/safe-path.js +0 -75
  36. package/dist/coding/story-build/build-prompts.js +0 -178
  37. package/dist/coding/story-build/build.js +0 -332
  38. package/dist/coding/story-build/checkouts.js +0 -66
  39. package/dist/coding/story-build/docs-runner.js +0 -178
  40. package/dist/coding/story-build/docs.js +0 -334
  41. package/dist/coding/story-build/manager.js +0 -999
  42. package/dist/coding/story-build/plan-agent.js +0 -190
  43. package/dist/coding/story-build/plan.js +0 -338
  44. package/dist/coding/story-build/prompts.js +0 -147
  45. package/dist/coding/story-build/routes-docs.js +0 -113
  46. package/dist/coding/story-build/routes.js +0 -295
  47. package/dist/coding/story-build/schema.js +0 -53
  48. package/dist/db/automation-output.js +0 -349
  49. package/dist/db/credits.js +0 -79
  50. package/dist/db/schema.js +0 -321
  51. package/dist/db/schema.pg.js +0 -2197
  52. package/dist/db/sprint-repo-suggest.js +0 -257
  53. package/dist/db/sprint-stories.js +0 -42
  54. package/dist/db/sprint-story.js +0 -505
  55. package/dist/db/sprint-ticket-repos.js +0 -195
  56. package/dist/db/story-selection.js +0 -270
  57. package/dist/db/team-comparison.js +0 -124
  58. package/dist/db/workspace-comparison.js +0 -98
  59. package/dist/feed/fyi-provider.js +0 -10
  60. package/dist/github/local-user.js +0 -92
  61. package/dist/github/repo-files.js +0 -26
  62. package/dist/ml/worker.js +0 -31
  63. package/dist/platform/advisor/discovery/tier2.js +0 -88
  64. package/dist/platform/advisor/discovery/tier3.js +0 -57
  65. package/dist/platform/advisor/emitters/adapter.js +0 -5
  66. package/dist/platform/advisor/emitters/coderabbit.js +0 -175
  67. package/dist/platform/advisor/emitters/copilot-prose.js +0 -118
  68. package/dist/platform/advisor/emitters/greptile.js +0 -176
  69. package/dist/platform/advisor/emitters/lint.js +0 -37
  70. package/dist/platform/advisor/emitters/manifest.js +0 -239
  71. package/dist/platform/advisor/emitters/prose.js +0 -183
  72. package/dist/platform/advisor/emitters/registry.js +0 -20
  73. package/dist/platform/advisor/emitters/yaml-doc.js +0 -95
  74. package/dist/platform/advisor/evidence.js +0 -79
  75. package/dist/platform/advisor/findings.js +0 -15
  76. package/dist/platform/advisor/intents.js +0 -269
  77. package/dist/platform/advisor/measure/effect.js +0 -18
  78. package/dist/platform/advisor/outputs/brief.js +0 -68
  79. package/dist/platform/advisor/outputs/config-pr.js +0 -156
  80. package/dist/platform/advisor/refine/diff-guard.js +0 -38
  81. package/dist/platform/advisor/refine/refine.js +0 -35
  82. package/dist/platform/advisor/retro-check.js +0 -98
  83. package/dist/platform/advisor/routes.js +0 -648
  84. package/dist/platform/advisor/store.js +0 -321
  85. package/dist/platform/advisor/taxonomy.js +0 -67
  86. package/dist/platform/annotations/prompts.js +0 -84
  87. package/dist/platform/annotations/routes.js +0 -86
  88. package/dist/platform/annotations/runner.js +0 -234
  89. package/dist/platform/annotations/targets.js +0 -203
  90. package/dist/platform/insights/grounded-figures.js +0 -162
  91. package/dist/platform/insights/period-questions.js +0 -235
  92. package/dist/platform/work-plan/hash.js +0 -99
  93. package/dist/platform/work-plan/prompt.js +0 -209
  94. package/dist/platform/work-plan/routes.js +0 -350
  95. package/dist/pro/bind.js +0 -309
  96. package/dist/pro/contract.js +0 -36
  97. package/dist/pro/event-hooks.js +0 -37
  98. package/dist/pro/migrate.js +0 -64
  99. package/dist/review/events.js +0 -24
  100. package/dist/review/local-settings.js +0 -78
  101. package/dist/review/memory/capture.js +0 -0
  102. package/dist/review/memory/retrieval.js +0 -272
  103. package/dist/review/memory/routes.js +0 -78
  104. package/dist/review/persist.js +0 -203
  105. package/dist/review/plugin-providers.js +0 -12
  106. package/dist/review/prompt.js +0 -264
  107. package/dist/review/review-manager.js +0 -259
  108. package/dist/review/routing.js +0 -164
  109. package/dist/review/sprint-assess/agent.js +0 -145
  110. package/dist/review/sprint-assess/manager.js +0 -382
  111. package/dist/review/sprint-assess/prompts.js +0 -99
  112. package/dist/review/sprint-assess/routes.js +0 -109
  113. package/dist/review/sprint-assess/schema.js +0 -70
  114. package/dist/review/sprint-assess/validate.js +0 -180
  115. package/dist/review/sprint-story/manager.js +0 -98
  116. package/dist/review/sprint-story/prompt.js +0 -45
  117. package/dist/review/sprint-story/validate.js +0 -127
  118. package/dist/review/story-docs/build-prompts.js +0 -153
  119. package/dist/review/story-docs/build-validate.js +0 -162
  120. package/dist/review/story-report/agent.js +0 -203
  121. package/dist/review/story-report/fingerprint.js +0 -45
  122. package/dist/review/story-report/manager.js +0 -287
  123. package/dist/review/story-report/routes.js +0 -154
  124. package/dist/review/story-report/story-detail.js +0 -148
  125. package/dist/review/story-report/validate.js +0 -105
  126. package/dist/review/ticket-review/sweep-waits.js +0 -20
  127. package/dist/review/write-deny.js +0 -170
  128. package/dist/shared/conflict-ai.js +0 -24
  129. package/dist/sync/benchmark-rollup.js +0 -50
@@ -1,181 +0,0 @@
1
- // GitHub App webhook receiver — real-time sync Phase 1 (see docs/REALTIME-SYNC.md).
2
- //
3
- // A GitHub App has ONE webhook URL that receives events for every installation, so this
4
- // single route serves every tenant. On a PR-affecting event it resolves which watched
5
- // repos the change touches and fires a debounced, targeted single-PR sync (Phase 0's
6
- // enqueuePrSync) — near-real-time freshness at ~1 GraphQL point per change, no window
7
- // re-walk. It is ADDITIVE: the periodic poll (SYNC.md) stays as the backstop for dropped
8
- // deliveries and for accounts signed in via the OAuth App (no App install → no webhooks).
9
- //
10
- // Structure mirrors the Stripe webhook (api/routes/billing.ts): authenticity is the
11
- // signature, not a session (so the route is exempted from the cloud auth gate); the raw
12
- // body is read via an ENCAPSULATED content-type parser so the rest of the API keeps
13
- // normal JSON parsing. Registered in both modes; inert until GITHUB_APP_WEBHOOK_SECRET is
14
- // set (replies 501 unconfigured).
15
- import { createHmac, timingSafeEqual } from 'node:crypto';
16
- import { and, eq } from 'drizzle-orm';
17
- import { config } from '../../config.js';
18
- import { db, schema } from '../../db/client.js';
19
- import { enqueuePrSync } from '../../sync/sync-one-pr.js';
20
- const { repos } = schema;
21
- /**
22
- * Verify a GitHub webhook signature (the `X-Hub-Signature-256` header) without a
23
- * dependency. Format: `sha256=<hex>`, where the hex is HMAC-SHA256(secret) over the raw
24
- * request bytes. Compared timing-safely. Pure so it's unit-testable without Fastify.
25
- */
26
- export function verifyGithubSignature(rawBody, header, secret) {
27
- const prefix = 'sha256=';
28
- if (!header.startsWith(prefix))
29
- return false;
30
- const provided = header.slice(prefix.length);
31
- const expected = createHmac('sha256', secret).update(rawBody).digest('hex');
32
- const providedBuf = Buffer.from(provided, 'utf-8');
33
- const expectedBuf = Buffer.from(expected, 'utf-8');
34
- return (providedBuf.length === expectedBuf.length &&
35
- timingSafeEqual(providedBuf, expectedBuf));
36
- }
37
- function asRecord(v) {
38
- return v !== null && typeof v === 'object' ? v : null;
39
- }
40
- // A positive integer `number` field off an object (a PR reference), else null.
41
- function prNumberOf(v) {
42
- const n = asRecord(v)?.['number'];
43
- return typeof n === 'number' && Number.isInteger(n) && n > 0 ? n : null;
44
- }
45
- /**
46
- * Map a GitHub webhook (event type + payload) to the repo + PR numbers it should refresh.
47
- * Pure — no DB, no Fastify — so the per-event extraction is unit-testable. Every handled
48
- * event carries `repository.owner.login` + `repository.name`; the PR number(s) live in a
49
- * per-event slot. Returns null when there's nothing to sync.
50
- */
51
- export function extractPrTargets(eventType, payload) {
52
- const p = asRecord(payload);
53
- if (!p)
54
- return null;
55
- const repo = asRecord(p['repository']);
56
- const owner = asRecord(repo?.['owner'])?.['login'];
57
- const name = repo?.['name'];
58
- if (typeof owner !== 'string' || typeof name !== 'string')
59
- return null;
60
- const numbers = new Set();
61
- const addNum = (v) => {
62
- const n = prNumberOf(v);
63
- if (n != null)
64
- numbers.add(n);
65
- };
66
- const addArray = (v) => {
67
- if (Array.isArray(v))
68
- for (const e of v)
69
- addNum(e);
70
- };
71
- switch (eventType) {
72
- // All the PR-scoped events carry the PR directly.
73
- case 'pull_request':
74
- case 'pull_request_review':
75
- case 'pull_request_review_comment':
76
- case 'pull_request_review_thread':
77
- addNum(p['pull_request']);
78
- break;
79
- // issue_comment also fires on plain issues; only PRs carry `issue.pull_request`.
80
- case 'issue_comment': {
81
- const issue = asRecord(p['issue']);
82
- if (issue && issue['pull_request'] != null)
83
- addNum(issue);
84
- break;
85
- }
86
- // CI events carry the associated PRs (same-repo only) — this is how a check
87
- // finishing (which never bumps a PR's updatedAt) drives a refresh.
88
- case 'check_run':
89
- addArray(asRecord(p['check_run'])?.['pull_requests']);
90
- break;
91
- case 'check_suite':
92
- addArray(asRecord(p['check_suite'])?.['pull_requests']);
93
- break;
94
- // ping / push / installation / anything else → no targeted PR (a push to a PR's head
95
- // arrives separately as pull_request `synchronize`, which the case above handles).
96
- default:
97
- return null;
98
- }
99
- if (numbers.size === 0)
100
- return null;
101
- return { owner, name, prNumbers: [...numbers] };
102
- }
103
- export async function webhookRoutes(app) {
104
- // A STABLE logger for the detached (debounced) syncs — the request-scoped req.log is
105
- // gone by the time enqueuePrSync's timer fires. Mirrors scheduler.ts's adapter.
106
- const log = {
107
- info: (m, ...a) => app.log.info(a.length ? { a } : {}, m),
108
- warn: (m, ...a) => app.log.warn(a.length ? { a } : {}, m),
109
- error: (m, ...a) => app.log.error(a.length ? { a } : {}, m),
110
- };
111
- // The signature signs the exact bytes, so this route needs the RAW body. Fastify's
112
- // content-type parsers are ENCAPSULATED, so registering the buffer parser in this
113
- // nested scope affects ONLY /api/webhooks/github — the rest of the API keeps normal
114
- // JSON parsing (proven by webhooks.test.ts's sibling-route case).
115
- await app.register(async (scope) => {
116
- scope.addContentTypeParser('application/json', { parseAs: 'buffer' }, (_req, body, done) => {
117
- done(null, body);
118
- });
119
- // GitHub posts unauthenticated (exempted from the auth gate); authenticity is the
120
- // signature. Never 500 on a data mismatch — GitHub retries non-2xx.
121
- scope.post('/api/webhooks/github', async (req, reply) => {
122
- if (!config.githubAppWebhookSecret) {
123
- return reply.code(501).send({ error: 'github webhooks not configured' });
124
- }
125
- const raw = req.body;
126
- if (!Buffer.isBuffer(raw)) {
127
- return reply.code(400).send({ error: 'expected a JSON body' });
128
- }
129
- const sig = req.headers['x-hub-signature-256'];
130
- if (typeof sig !== 'string' ||
131
- !verifyGithubSignature(raw, sig, config.githubAppWebhookSecret)) {
132
- return reply.code(401).send({ error: 'invalid signature' });
133
- }
134
- const eventType = req.headers['x-github-event'];
135
- if (typeof eventType !== 'string') {
136
- return reply.code(400).send({ error: 'missing X-GitHub-Event' });
137
- }
138
- // GitHub pings a newly-configured webhook once — ack it.
139
- if (eventType === 'ping')
140
- return { received: true, queued: 0 };
141
- let payload;
142
- try {
143
- payload = JSON.parse(raw.toString('utf-8'));
144
- }
145
- catch {
146
- return reply.code(400).send({ error: 'invalid JSON' });
147
- }
148
- const target = extractPrTargets(eventType, payload);
149
- if (!target)
150
- return { received: true, queued: 0 };
151
- // Route by (owner, name) across ALL accounts watching this repo. `repos` is keyed
152
- // (accountId, owner, name), so one webhook fans out to every tenant's copy — each
153
- // synced with ITS OWN token inside syncOnePr (isolation is structural). No
154
- // installation→account table is needed.
155
- const rows = await db
156
- .select({ id: repos.id })
157
- .from(repos)
158
- .where(and(eq(repos.owner, target.owner), eq(repos.name, target.name)))
159
- .execute();
160
- let queued = 0;
161
- for (const row of rows) {
162
- for (const prNumber of target.prNumbers) {
163
- // Debounced + coalesced + reservation-guarded: a burst for one PR collapses to
164
- // a single targeted sync (Phase 0). Fire-and-forget; syncOnePr swallows errors.
165
- enqueuePrSync(row.id, prNumber, log);
166
- queued += 1;
167
- }
168
- }
169
- if (queued > 0) {
170
- req.log.info({
171
- repo: `${target.owner}/${target.name}`,
172
- event: eventType,
173
- prs: target.prNumbers,
174
- watchers: rows.length,
175
- }, 'github webhook → queued targeted sync');
176
- }
177
- return { received: true, queued };
178
- });
179
- });
180
- }
181
- //# sourceMappingURL=webhooks.js.map
@@ -1,80 +0,0 @@
1
- // Live progress derivation for the coding agent — turns each assistant turn into a
2
- // few short, human-readable lines (tool labels + clipped text). Mirrors the private
3
- // helpers in review/agent.ts but understands the WRITE tools (Write/Edit/MultiEdit)
4
- // the fixer uses. Defensive throughout: the SDK content/tool-input shapes vary, so
5
- // every access is guarded and this never throws.
6
- const TEXT_SNIPPET_CAP = 120;
7
- const ARG_CAP = 80;
8
- export function describeAssistantBlocks(message) {
9
- const lines = [];
10
- const content = message?.message
11
- ?.content;
12
- if (!Array.isArray(content))
13
- return lines;
14
- for (const raw of content) {
15
- if (!raw || typeof raw !== 'object')
16
- continue;
17
- const block = raw;
18
- if (block.type === 'tool_use') {
19
- const name = typeof block.name === 'string' ? block.name : 'Tool';
20
- const input = block.input && typeof block.input === 'object'
21
- ? block.input
22
- : {};
23
- lines.push(labelToolUse(name, input));
24
- }
25
- else if (block.type === 'text' && typeof block.text === 'string') {
26
- const snippet = clip(block.text.replace(/\s+/g, ' ').trim(), TEXT_SNIPPET_CAP);
27
- if (snippet)
28
- lines.push(snippet);
29
- }
30
- }
31
- return lines;
32
- }
33
- function labelToolUse(name, input) {
34
- const str = (v) => typeof v === 'string' && v.trim().length > 0 ? v.trim() : null;
35
- switch (name) {
36
- case 'Read': {
37
- const p = str(input.file_path) ?? str(input.path);
38
- return p ? `Read ${p}` : 'Read …';
39
- }
40
- case 'Write': {
41
- const p = str(input.file_path) ?? str(input.path);
42
- return p ? `Write ${p}` : 'Write …';
43
- }
44
- case 'Edit':
45
- case 'MultiEdit': {
46
- const p = str(input.file_path) ?? str(input.path);
47
- return p ? `Edit ${p}` : 'Edit …';
48
- }
49
- case 'Glob': {
50
- const p = str(input.pattern);
51
- return p ? `Glob ${p}` : 'Glob …';
52
- }
53
- case 'Grep': {
54
- const p = str(input.pattern);
55
- return p ? `Grep "${clip(p, ARG_CAP)}"` : 'Grep …';
56
- }
57
- // Unreachable as things stand — the fixer does not allow Bash (coding/agent.ts denies it
58
- // outright), so no such block arrives and the panel simply shows fewer lines. Kept because
59
- // this function's contract is "label whatever the SDK hands me", and the default branch
60
- // below would render this one worse.
61
- case 'Bash': {
62
- const c = str(input.command);
63
- return c ? `Bash ${clip(c, ARG_CAP)}` : 'Bash …';
64
- }
65
- case 'mcp__fix__submit_fix':
66
- return 'Recording fix summary…';
67
- default: {
68
- for (const key of Object.keys(input)) {
69
- const v = str(input[key]);
70
- if (v)
71
- return `${name} ${clip(v, ARG_CAP)}`;
72
- }
73
- return `${name} …`;
74
- }
75
- }
76
- }
77
- function clip(s, max) {
78
- return s.length > max ? `${s.slice(0, max)}…` : s;
79
- }
80
- //# sourceMappingURL=activity.js.map
@@ -1,147 +0,0 @@
1
- import { claudeModelChoice, getActiveProvider, getProvider, } from '../ai/provider.js';
2
- import { applyClaudeReviewAuth } from '../review/auth.js';
3
- import { estimateCostUsd } from '../review/pricing.js';
4
- import { withPartialSpend } from './partial-spend.js';
5
- // THE HOST-SIDE AGENT RUN IN A WORKTREE, used ONLY by Resolve with Claude (coding/ai-resolve/run.ts,
6
- // read-only, its own `submit_resolution` tool and its own READ_TOOLS / DENIED_TOOLS lists). It has NO
7
- // SHELL: the caller's deny list carries Bash. AI Fix and Implement no longer run here — both are a
8
- // sandboxed workspace session (sandbox/session/; docs/SANDBOX.md), the ONE place an agent has a shell.
9
- const ACTIVITY_LOG_CAP = 25;
10
- function emptyUsage() {
11
- return {
12
- inputTokens: 0,
13
- outputTokens: 0,
14
- cacheReadTokens: 0,
15
- cacheCreationTokens: 0,
16
- };
17
- }
18
- /**
19
- * The agent run core: the provider OWNS the isolation config (`permissionMode:'bypassPermissions'`,
20
- * `settingSources:[]`, budget/turn caps, the caller's tool lists) and streams activity; this knows
21
- * nothing about worktree prep or git — the caller owns those.
22
- *
23
- * Auth: the credential ladder (applyClaudeReviewAuth), restored in `finally`. The env mutation only
24
- * bites with no ambient login (an API-key-only setup), where a concurrent run would set the identical
25
- * key; Resolve with Claude runs one at a time per PR.
26
- */
27
- export async function runAgentInWorktree(opts) {
28
- const model = opts.model;
29
- let liveUsage = emptyUsage();
30
- let outcome = null;
31
- const provider = opts.provider ? getProvider(opts.provider) : getActiveProvider();
32
- // CODEX (docs/CODEX-PLAN.md Phase 3): its tokens are never Claude-priced. On a ChatGPT sign-in a run
33
- // costs US$ 0 (the budget's share is token-weighted, ai/budget.ts), and the provider reports its
34
- // own US$ on the outcome — so nothing below estimates a Codex run with Claude's price table. It
35
- // records its own ledger row when given `usageRecord` (ai/providers/codex.ts), even for a run that
36
- // failed or was cancelled.
37
- const isCodex = provider.id === 'codex';
38
- const usageRecorded = isCodex && opts.usageRecord != null;
39
- const priceOf = (u) => (isCodex ? (outcome?.costUsd ?? 0) : estimateCostUsd(model, u));
40
- // The credential ladder (ai/credentials.ts): the Claude Code login, else ANTHROPIC_API_KEY. Restored
41
- // below. (Claude's only: a Codex run's environment is built by its provider from Limn's Codex home.)
42
- const restoreEnv = isCodex ? () => { } : applyClaudeReviewAuth(true);
43
- try {
44
- const activity = [];
45
- const pushActivity = (line) => {
46
- const trimmed = line.trim();
47
- if (!trimmed)
48
- return;
49
- activity.push(trimmed);
50
- if (activity.length > ACTIVITY_LOG_CAP)
51
- activity.shift();
52
- };
53
- // What the run has spent so far, from the streamed assistant turns. A cancelled or failed run
54
- // still bills: the caller records this.
55
- const spentSoFar = () => {
56
- // Codex emits its whole-run outcome before it throws: its tokens beat the live tally.
57
- const u = { ...(isCodex && outcome?.usage ? outcome.usage : liveUsage) };
58
- const has = u.inputTokens + u.outputTokens + u.cacheReadTokens > 0;
59
- return { usage: u, costUsd: has ? priceOf(u) : null, ...(usageRecorded ? { usageRecorded } : {}) };
60
- };
61
- try {
62
- // THROUGH THE PROVIDER (ai/provider.ts; Claude's is ai/providers/claude.ts). It OWNS the sandbox
63
- // config (`permissionMode:'bypassPermissions'`, `settingSources:[]`, the isolated MCP config) and
64
- // puts ⚠ THE PATH GUARD first on PreToolUse: file tools stay inside the worktree (cwd, no other
65
- // root). Under bypassPermissions nothing else confines an ABSOLUTE path. 'worktree' mode; the effort is
66
- // opts.effort or, when absent, `defaultRunEffort` for a worktree run.
67
- ({ outcome } = await provider.runAgent({
68
- kind: opts.kind,
69
- model: claudeModelChoice(model),
70
- effort: 'worktree',
71
- prompt: opts.prompt,
72
- ...(opts.systemPrompt ? { system: opts.systemPrompt } : {}),
73
- cwd: opts.worktreePath,
74
- roots: [],
75
- readOnlyRoots: opts.readOnlyRoots ?? [],
76
- writeRoots: opts.writes ? [opts.worktreePath] : [],
77
- tools: opts.tools,
78
- budget: { usd: opts.maxBudgetUsd, turns: opts.maxTurns },
79
- abortController: opts.abortController,
80
- claude: {
81
- allowedTools: opts.allowedTools,
82
- disallowedTools: opts.disallowedTools,
83
- ...(opts.effort ? { effort: opts.effort } : {}),
84
- },
85
- ...(opts.usageRecord ? { usageRecord: opts.usageRecord } : {}),
86
- ...(opts.codex || opts.effort ? { codex: { ...opts.codex, effort: opts.codex?.effort ?? opts.effort } } : {}),
87
- // The write-capable words for its steps.
88
- activity: 'fix',
89
- onProgress: (p) => {
90
- if (p.kind === 'step') {
91
- if (p.usage)
92
- liveUsage = p.usage;
93
- for (const line of p.lines)
94
- pushActivity(line);
95
- const live = liveUsage;
96
- opts.onActivity?.([...activity], {
97
- ...live,
98
- estCostUsd: priceOf(live),
99
- });
100
- }
101
- else if (p.kind === 'outcome') {
102
- outcome = p.outcome;
103
- }
104
- },
105
- }));
106
- }
107
- catch (err) {
108
- // A cancel may surface as a throw from the iterator: fall through to the aborted result.
109
- // Any other failure carries what was spent so far (`partialSpendOf`).
110
- if (!opts.abortController.signal.aborted)
111
- throw withPartialSpend(err, spentSoFar());
112
- }
113
- if (opts.abortController.signal.aborted) {
114
- const spent = spentSoFar();
115
- return {
116
- outcome,
117
- usage: spent.usage,
118
- costUsd: spent.costUsd,
119
- numTurns: null,
120
- aborted: true,
121
- provider: provider.id,
122
- usageRecorded,
123
- };
124
- }
125
- const usage = outcome?.usage ?? liveUsage;
126
- const hasUsage = usage.inputTokens + usage.outputTokens + usage.cacheReadTokens > 0;
127
- const costUsd = outcome?.costUsd ?? (hasUsage ? priceOf(usage) : null);
128
- return {
129
- outcome,
130
- usage: {
131
- inputTokens: usage.inputTokens,
132
- outputTokens: usage.outputTokens,
133
- cacheReadTokens: usage.cacheReadTokens,
134
- cacheCreationTokens: usage.cacheCreationTokens,
135
- },
136
- costUsd,
137
- numTurns: outcome?.numTurns ?? null,
138
- aborted: false,
139
- provider: provider.id,
140
- usageRecorded,
141
- };
142
- }
143
- finally {
144
- restoreEnv();
145
- }
146
- }
147
- //# sourceMappingURL=agent.js.map
@@ -1,58 +0,0 @@
1
- import { config } from '../../config.js';
2
- import { CHECK_MANIFEST_FILES, detectSandbox, discoverChecks } from '../checks/index.js';
3
- import { getFixPrContext } from './pr-context.js';
4
- const TTL_MS = 10 * 60_000;
5
- const cache = new Map();
6
- /** For tests. */
7
- export function clearChecksPreviewCache() {
8
- cache.clear();
9
- }
10
- /** The sentence the picker shows when tests cannot run on this machine, or null. */
11
- export function checksUnavailableNote(sandbox, allowUnsandboxed) {
12
- if (sandbox.kind !== 'none' || allowUnsandboxed)
13
- return null;
14
- return `Tests can’t run here: Limn runs them only inside a sandbox. ${sandbox.reason ?? ''}`.trim();
15
- }
16
- export async function loadChecksPreview(ctx, input) {
17
- const fetchFiles = ctx.github.fetchRepoFiles;
18
- if (!fetchFiles)
19
- return null;
20
- const pr = await getFixPrContext(ctx, input.accountId, input.prId);
21
- if (!pr)
22
- return null;
23
- // The synced head: the run itself re-reads the live head and discovers again on its own worktree,
24
- // so a stale list can only offer a name the run then skips — never run something undeclared.
25
- let ref = pr.headSha;
26
- if (!ref)
27
- ref = (await ctx.github.fetchPrHeadInfo(input.accountId, pr.owner, pr.name, pr.number)).headSha || null;
28
- if (!ref)
29
- return null;
30
- const key = `${input.accountId}:${pr.repoId}:${ref}`;
31
- const hit = cache.get(key);
32
- if (hit && Date.now() - hit.at < TTL_MS)
33
- return hit.value;
34
- const files = await fetchFiles(input.accountId, { owner: pr.owner, name: pr.name, ref, paths: CHECK_MANIFEST_FILES });
35
- const value = checksPreviewFromFiles(files);
36
- cache.set(key, { at: Date.now(), value });
37
- return value;
38
- }
39
- /** The picker's list from the manifest files at one commit (AI Fix's head, a story build's base). */
40
- export function checksPreviewFromFiles(files) {
41
- const plan = discoverChecks({ read: (p) => files[p] ?? null });
42
- const sandbox = detectSandbox();
43
- return {
44
- checks: plan.checks.map((c) => ({
45
- name: c.name,
46
- kind: c.kind,
47
- command: c.kind === 'hook' ? `git commit (${c.source})` : c.argv.join(' '),
48
- source: c.source,
49
- defaultOn: c.defaultOn,
50
- needsDocker: c.needsDocker,
51
- refused: c.refused,
52
- })),
53
- sandbox: sandbox.kind,
54
- unavailable: checksUnavailableNote(sandbox, config.checksAllowUnsandboxed),
55
- unsandboxed: sandbox.kind === 'none' && config.checksAllowUnsandboxed,
56
- };
57
- }
58
- //# sourceMappingURL=checks-preview.js.map