@buddysh/buddy 0.11.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.
- package/CHANGELOG.md +1633 -0
- package/LICENSE.md +21 -0
- package/README.md +1087 -0
- package/bin/cli.ts +3401 -0
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +188 -0
- package/dist/chunk-0j7z87kh.js +3 -0
- package/dist/chunk-0r8zt3d7.js +2 -0
- package/dist/chunk-16yqbccr.js +3 -0
- package/dist/chunk-1a53wj0h.js +1 -0
- package/dist/chunk-1c1gznm9.js +3 -0
- package/dist/chunk-1h3ey7k5.js +3 -0
- package/dist/chunk-1stt2whn.js +62 -0
- package/dist/chunk-1wjnd24b.js +24 -0
- package/dist/chunk-1xe07hzm.js +2 -0
- package/dist/chunk-2bp7tqca.js +2 -0
- package/dist/chunk-2dbkpfy9.js +2 -0
- package/dist/chunk-3q6czqs4.js +6 -0
- package/dist/chunk-3zdcekfj.js +5 -0
- package/dist/chunk-49ey79p0.js +5 -0
- package/dist/chunk-4c9m61yd.js +5 -0
- package/dist/chunk-4efbxdjr.js +4 -0
- package/dist/chunk-4f7panqj.js +21 -0
- package/dist/chunk-4hd3rre0.js +2 -0
- package/dist/chunk-4xsq18p3.js +9 -0
- package/dist/chunk-52x8mvh4.js +15 -0
- package/dist/chunk-54sc18p8.js +2 -0
- package/dist/chunk-56q4pwb5.js +3 -0
- package/dist/chunk-5c3qf34r.js +2 -0
- package/dist/chunk-5k40mwd4.js +4 -0
- package/dist/chunk-5kt03hx5.js +2 -0
- package/dist/chunk-63ept76v.js +2 -0
- package/dist/chunk-65b3vq52.js +2 -0
- package/dist/chunk-6d9hmjt8.js +3 -0
- package/dist/chunk-6g1y9yqh.js +3 -0
- package/dist/chunk-6k653r8w.js +2 -0
- package/dist/chunk-6md7qf2g.js +4 -0
- package/dist/chunk-6patq6bw.js +2 -0
- package/dist/chunk-6sgh49z1.js +2 -0
- package/dist/chunk-74pxb991.js +7 -0
- package/dist/chunk-7mgec8kb.js +7 -0
- package/dist/chunk-7tfrww3v.js +2 -0
- package/dist/chunk-7xk28xrv.js +2 -0
- package/dist/chunk-82dv4p13.js +2 -0
- package/dist/chunk-8661pvb8.js +3 -0
- package/dist/chunk-887s0w81.js +2 -0
- package/dist/chunk-8rc6042h.js +4 -0
- package/dist/chunk-9750tenz.js +3 -0
- package/dist/chunk-978wtejw.js +44 -0
- package/dist/chunk-9eqpaxfz.js +2 -0
- package/dist/chunk-9h04nskh.js +8 -0
- package/dist/chunk-9p1xkmjy.js +2 -0
- package/dist/chunk-agdesgzv.js +2 -0
- package/dist/chunk-akffynkc.js +3 -0
- package/dist/chunk-ar01x04a.js +2 -0
- package/dist/chunk-ay43f085.js +2 -0
- package/dist/chunk-bk9bqd5j.js +2 -0
- package/dist/chunk-bm8d40j0.js +69 -0
- package/dist/chunk-bxfc4g2x.js +73 -0
- package/dist/chunk-c3fczawt.js +2 -0
- package/dist/chunk-c9r9nd4t.js +1 -0
- package/dist/chunk-ctsz0ynx.js +3 -0
- package/dist/chunk-czremqk7.js +2 -0
- package/dist/chunk-da3wbh04.js +2 -0
- package/dist/chunk-dat582cg.js +2 -0
- package/dist/chunk-dfesffnr.js +3 -0
- package/dist/chunk-djntbp7a.js +105 -0
- package/dist/chunk-eagjp0dh.js +3 -0
- package/dist/chunk-eht72nnj.js +2 -0
- package/dist/chunk-f4nv5x3z.js +2 -0
- package/dist/chunk-fdfk918n.js +2 -0
- package/dist/chunk-fdj0tewy.js +20 -0
- package/dist/chunk-fm8ckj9b.js +2 -0
- package/dist/chunk-fqj7e6xa.js +2 -0
- package/dist/chunk-frm8zz31.js +2 -0
- package/dist/chunk-fvpr07dn.js +16 -0
- package/dist/chunk-g0nv8psv.js +2 -0
- package/dist/chunk-g0w8n555.js +19 -0
- package/dist/chunk-gkmvxjbe.js +2 -0
- package/dist/chunk-gngwjf70.js +7 -0
- package/dist/chunk-h7hs95wn.js +5 -0
- package/dist/chunk-hfvezfxh.js +3 -0
- package/dist/chunk-hw70wbzg.js +3 -0
- package/dist/chunk-j8asz4hb.js +15 -0
- package/dist/chunk-k62w2v03.js +2 -0
- package/dist/chunk-mcrfxphm.js +5 -0
- package/dist/chunk-mh3x7j6h.js +2 -0
- package/dist/chunk-naq32yx3.js +86 -0
- package/dist/chunk-nsmcjkas.js +2 -0
- package/dist/chunk-p1xm1jvz.js +2 -0
- package/dist/chunk-p3wsm8kz.js +2 -0
- package/dist/chunk-p4zwy518.js +4 -0
- package/dist/chunk-p7zgy37f.js +2 -0
- package/dist/chunk-ph1b3vbp.js +315 -0
- package/dist/chunk-pkjm2r0a.js +2 -0
- package/dist/chunk-pkkwb0n0.js +4 -0
- package/dist/chunk-pnpx1kqn.js +6 -0
- package/dist/chunk-q9n79dd3.js +3 -0
- package/dist/chunk-qpz9k66h.js +2 -0
- package/dist/chunk-qvn1rtgp.js +2 -0
- package/dist/chunk-qyf90zz3.js +2 -0
- package/dist/chunk-r06ce5g6.js +2 -0
- package/dist/chunk-r2sbprdb.js +49 -0
- package/dist/chunk-r3zyw8x0.js +3 -0
- package/dist/chunk-rb1fh9vd.js +1 -0
- package/dist/chunk-rqdep14r.js +2 -0
- package/dist/chunk-s1km8cyq.js +2 -0
- package/dist/chunk-s4ms8zag.js +2 -0
- package/dist/chunk-sp818c27.js +9 -0
- package/dist/chunk-tb5y0350.js +3 -0
- package/dist/chunk-thaxgm5p.js +2 -0
- package/dist/chunk-tn8prpny.js +503 -0
- package/dist/chunk-ts35hc5t.js +3 -0
- package/dist/chunk-tzs22es2.js +3 -0
- package/dist/chunk-vagxqhef.js +13 -0
- package/dist/chunk-vh504tcv.js +6 -0
- package/dist/chunk-vkctfqpm.js +3 -0
- package/dist/chunk-vyapg8ca.js +186 -0
- package/dist/chunk-wdwvt7gb.js +43 -0
- package/dist/chunk-wtjhehz9.js +4 -0
- package/dist/chunk-x0ya2r4r.js +3 -0
- package/dist/chunk-x3kragh9.js +12 -0
- package/dist/chunk-x9ctz1qc.js +1 -0
- package/dist/chunk-xakpdqaq.js +3 -0
- package/dist/chunk-xqx460y2.js +3 -0
- package/dist/chunk-xvptf9jy.js +3 -0
- package/dist/chunk-yk23nc4t.js +2 -0
- package/dist/chunk-yncea6ty.js +2 -0
- package/dist/chunk-yq0gxtzv.js +2 -0
- package/dist/chunk-yqhs08ky.js +2 -0
- package/dist/chunk-zb62jhwm.js +31 -0
- package/dist/chunk-zs3jaj0g.js +1023 -0
- package/dist/chunk-zve5d96e.js +2 -0
- package/dist/src/agent/index.d.ts +44 -0
- package/dist/src/agent/modes.d.ts +33 -0
- package/dist/src/agent/runner.d.ts +44 -0
- package/dist/src/agent/stacked.d.ts +83 -0
- package/dist/src/agent/tasks.d.ts +41 -0
- package/dist/src/agent/toolbelt.d.ts +19 -0
- package/dist/src/agent/tools/fs.d.ts +26 -0
- package/dist/src/agent/tools/shell.d.ts +32 -0
- package/dist/src/agent/types.d.ts +56 -0
- package/dist/src/ai/aliases.d.ts +62 -0
- package/dist/src/ai/client.d.ts +42 -0
- package/dist/src/ai/index.d.ts +35 -0
- package/dist/src/ai/learnings.d.ts +78 -0
- package/dist/src/ai/providers/anthropic.d.ts +12 -0
- package/dist/src/ai/providers/google.d.ts +12 -0
- package/dist/src/ai/providers/openai.d.ts +15 -0
- package/dist/src/ai/redact.d.ts +30 -0
- package/dist/src/ai/types.d.ts +75 -0
- package/dist/src/analysis/analyzers/actionlint.d.ts +11 -0
- package/dist/src/analysis/analyzers/external.d.ts +57 -0
- package/dist/src/analysis/analyzers/github-actions.d.ts +9 -0
- package/dist/src/analysis/analyzers/hadolint.d.ts +9 -0
- package/dist/src/analysis/analyzers/linter.d.ts +53 -0
- package/dist/src/analysis/analyzers/markdownlint.d.ts +11 -0
- package/dist/src/analysis/analyzers/secrets.d.ts +23 -0
- package/dist/src/analysis/analyzers/shellcheck.d.ts +8 -0
- package/dist/src/analysis/analyzers/syntax.d.ts +13 -0
- package/dist/src/analysis/engine.d.ts +38 -0
- package/dist/src/analysis/index.d.ts +13 -0
- package/dist/src/analysis/types.d.ts +14 -0
- package/dist/src/buddy.d.ts +17 -0
- package/dist/src/ci/classify.d.ts +49 -0
- package/dist/src/ci/fix.d.ts +42 -0
- package/dist/src/ci/index.d.ts +8 -0
- package/dist/src/commands/dispatcher.d.ts +49 -0
- package/dist/src/commands/handlers.d.ts +23 -0
- package/dist/src/commands/index.d.ts +22 -0
- package/dist/src/commands/parser.d.ts +71 -0
- package/dist/src/config-validation.d.ts +38 -0
- package/dist/src/config.d.ts +22 -0
- package/dist/src/dashboard/dashboard-generator.d.ts +10 -0
- package/dist/src/doctor.d.ts +44 -0
- package/dist/src/ecosystems/go.d.ts +10 -0
- package/dist/src/ecosystems/index.d.ts +60 -0
- package/dist/src/ecosystems/pep440.d.ts +57 -0
- package/dist/src/ecosystems/python.d.ts +12 -0
- package/dist/src/ecosystems/ruby.d.ts +9 -0
- package/dist/src/ecosystems/rust.d.ts +8 -0
- package/dist/src/ecosystems/scan.d.ts +49 -0
- package/dist/src/ecosystems/shared.d.ts +45 -0
- package/dist/src/ecosystems/types.d.ts +58 -0
- package/dist/src/events/bus.d.ts +41 -0
- package/dist/src/events/index.d.ts +11 -0
- package/dist/src/events/sinks.d.ts +33 -0
- package/dist/src/gates/ai-checks.d.ts +77 -0
- package/dist/src/gates/checks.d.ts +84 -0
- package/dist/src/gates/index.d.ts +17 -0
- package/dist/src/gates/post-merge.d.ts +56 -0
- package/dist/src/git/bitbucket-provider.d.ts +50 -0
- package/dist/src/git/github-provider.d.ts +50 -0
- package/dist/src/git/gitlab-provider.d.ts +51 -0
- package/dist/src/git/provider.d.ts +210 -0
- package/dist/src/headless/run.d.ts +78 -0
- package/dist/src/index.d.ts +243 -0
- package/dist/src/index.js +2 -0
- package/dist/src/issues/enrichment.d.ts +76 -0
- package/dist/src/issues/index.d.ts +16 -0
- package/dist/src/issues/quick-links.d.ts +55 -0
- package/dist/src/pr/auto-merge.d.ts +75 -0
- package/dist/src/pr/pr-generator.d.ts +9 -0
- package/dist/src/pr/pr-manifest.d.ts +82 -0
- package/dist/src/pr/templates.d.ts +44 -0
- package/dist/src/registry/docker-tags.d.ts +56 -0
- package/dist/src/registry/eol.d.ts +87 -0
- package/dist/src/registry/oci-client.d.ts +98 -0
- package/dist/src/registry/registry-client.d.ts +39 -0
- package/dist/src/reports/history.d.ts +51 -0
- package/dist/src/reports/index.d.ts +23 -0
- package/dist/src/reports/metrics.d.ts +89 -0
- package/dist/src/reports/render.d.ts +33 -0
- package/dist/src/review/diff.d.ts +50 -0
- package/dist/src/review/engine.d.ts +49 -0
- package/dist/src/review/findings.d.ts +102 -0
- package/dist/src/review/guidelines.d.ts +46 -0
- package/dist/src/review/index.d.ts +48 -0
- package/dist/src/review/local.d.ts +81 -0
- package/dist/src/review/marker.d.ts +34 -0
- package/dist/src/review/poster.d.ts +39 -0
- package/dist/src/review/run.d.ts +24 -0
- package/dist/src/rules/engine.d.ts +108 -0
- package/dist/src/rules/index.d.ts +9 -0
- package/dist/src/rules/renovate.d.ts +25 -0
- package/dist/src/rules/schedule.d.ts +44 -0
- package/dist/src/scanner/catalog-scan.d.ts +39 -0
- package/dist/src/scanner/package-json-extras.d.ts +101 -0
- package/dist/src/scanner/package-scanner.d.ts +17 -0
- package/dist/src/scanner/resolution-drift.d.ts +81 -0
- package/dist/src/scanner/workspace-catalog.d.ts +53 -0
- package/dist/src/scheduler/scheduler.d.ts +27 -0
- package/dist/src/security/engine.d.ts +12 -0
- package/dist/src/security/loader.d.ts +7 -0
- package/dist/src/security/parser.d.ts +15 -0
- package/dist/src/security/rules/bash-injection.d.ts +18 -0
- package/dist/src/security/rules/dangerous-pull-request-target.d.ts +18 -0
- package/dist/src/security/rules/excessive-permissions.d.ts +14 -0
- package/dist/src/security/rules/index.d.ts +16 -0
- package/dist/src/security/rules/missing-timeout.d.ts +9 -0
- package/dist/src/security/rules/self-hosted-exposure.d.ts +13 -0
- package/dist/src/security/rules/unpinned-action.d.ts +10 -0
- package/dist/src/security/rules/walk.d.ts +13 -0
- package/dist/src/security/types.d.ts +64 -0
- package/dist/src/services/deprecated-dependencies-checker.d.ts +16 -0
- package/dist/src/services/release-notes-fetcher.d.ts +70 -0
- package/dist/src/services/security-advisories.d.ts +59 -0
- package/dist/src/setup.d.ts +162 -0
- package/dist/src/setup.js +2 -0
- package/dist/src/templates/github-actions.d.ts +31 -0
- package/dist/src/templates/gitlab-ci.d.ts +46 -0
- package/dist/src/types.d.ts +449 -0
- package/dist/src/upgrades/index.d.ts +18 -0
- package/dist/src/upgrades/migrate.d.ts +45 -0
- package/dist/src/upgrades/plan.d.ts +112 -0
- package/dist/src/upgrades/report.d.ts +22 -0
- package/dist/src/upgrades/span.d.ts +47 -0
- package/dist/src/upgrades/usage.d.ts +30 -0
- package/dist/src/upgrades/wire.d.ts +61 -0
- package/dist/src/utils/concurrency.d.ts +50 -0
- package/dist/src/utils/dependency-file-parser.d.ts +17 -0
- package/dist/src/utils/dockerfile-parser.d.ts +69 -0
- package/dist/src/utils/endpoints.d.ts +58 -0
- package/dist/src/utils/errors.d.ts +35 -0
- package/dist/src/utils/file-changes.d.ts +14 -0
- package/dist/src/utils/github-actions-parser.d.ts +21 -0
- package/dist/src/utils/globs.d.ts +22 -0
- package/dist/src/utils/helpers.d.ts +73 -0
- package/dist/src/utils/http.d.ts +81 -0
- package/dist/src/utils/lock-file.d.ts +28 -0
- package/dist/src/utils/logger.d.ts +45 -0
- package/dist/src/utils/package-paths.d.ts +6 -0
- package/dist/src/utils/pantry-parser.d.ts +30 -0
- package/dist/src/utils/repository.d.ts +41 -0
- package/dist/src/utils/security-format.d.ts +18 -0
- package/dist/src/utils/zig-parser.d.ts +18 -0
- package/dist/src/version/version-resolver.d.ts +9 -0
- package/package.json +115 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type { FinishingTouch, TouchOutput } from './tasks';
|
|
2
|
+
export type { AgentRunOptions } from './runner';
|
|
3
|
+
export type {
|
|
4
|
+
AgentContext,
|
|
5
|
+
AgentMode,
|
|
6
|
+
AgentRunResult,
|
|
7
|
+
AgentTool,
|
|
8
|
+
AgentToolOutput,
|
|
9
|
+
ToolTier,
|
|
10
|
+
TranscriptEntry,
|
|
11
|
+
} from './types';
|
|
12
|
+
export type { DeliveryMode, StackedOptions, StackedResult, Verification } from './stacked';
|
|
13
|
+
export {
|
|
14
|
+
AGENT_MODES,
|
|
15
|
+
fixCiMode,
|
|
16
|
+
getAgentMode,
|
|
17
|
+
implementMode,
|
|
18
|
+
planMode,
|
|
19
|
+
restrictedMode,
|
|
20
|
+
reviewMode,
|
|
21
|
+
} from './modes';
|
|
22
|
+
export { runAgent, wrapUntrusted } from './runner';
|
|
23
|
+
export {
|
|
24
|
+
autofixTouch,
|
|
25
|
+
docstringsTouch,
|
|
26
|
+
FINISHING_TOUCHES,
|
|
27
|
+
getFinishingTouch,
|
|
28
|
+
parseTouchSelections,
|
|
29
|
+
planTouch,
|
|
30
|
+
renderTouchOffer,
|
|
31
|
+
simplifyTouch,
|
|
32
|
+
unitTestsTouch,
|
|
33
|
+
} from './tasks';
|
|
34
|
+
export { BUILTIN_TOOLS, Toolbelt } from './toolbelt';
|
|
35
|
+
export { fsTools, listDirTool, readFileTool, resolveWorkspacePath, writeFileTool } from './tools/fs';
|
|
36
|
+
export { buildShellEnv, SHELL_ENV_ALLOWLIST, shellTool } from './tools/shell';
|
|
37
|
+
export { ToolPermissionError } from './types';
|
|
38
|
+
export {
|
|
39
|
+
detectChangedFiles,
|
|
40
|
+
runStackedTouch,
|
|
41
|
+
stackedBranchName,
|
|
42
|
+
TEST_COMMANDS,
|
|
43
|
+
verifyChanges,
|
|
44
|
+
} from './stacked';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentMode } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Look up a mode by name.
|
|
4
|
+
*
|
|
5
|
+
* @param name - Mode name
|
|
6
|
+
* @throws {Error} When the mode is unknown, rather than silently falling back
|
|
7
|
+
* to a more permissive one
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAgentMode(name: string): AgentMode;
|
|
10
|
+
/**
|
|
11
|
+
* Read-only review: can look at the repository and comment, nothing else.
|
|
12
|
+
*
|
|
13
|
+
* The tier list is the security boundary — a review-mode run is never offered
|
|
14
|
+
* a write, shell, or git tool, so no prompt in a PR body can talk it into
|
|
15
|
+
* modifying the repository.
|
|
16
|
+
*/
|
|
17
|
+
export declare const reviewMode: AgentMode;
|
|
18
|
+
/** Implementation work: may edit files, run commands, and commit to a branch. */
|
|
19
|
+
export declare const implementMode: AgentMode;
|
|
20
|
+
/** Diagnosing and repairing a failing CI run. */
|
|
21
|
+
export declare const fixCiMode: AgentMode;
|
|
22
|
+
/** Research and planning, with no ability to change anything. */
|
|
23
|
+
export declare const planMode: AgentMode;
|
|
24
|
+
/**
|
|
25
|
+
* The tier every non-collaborator gets.
|
|
26
|
+
*
|
|
27
|
+
* Public repositories accept input from anyone, so a run triggered by someone
|
|
28
|
+
* without write access is capped at reading — the same reasoning as
|
|
29
|
+
* review-mode's tier list, applied to the actor rather than the task.
|
|
30
|
+
*/
|
|
31
|
+
export declare const restrictedMode: AgentMode;
|
|
32
|
+
/** Every built-in mode, by name. */
|
|
33
|
+
export declare const AGENT_MODES: Record<string, AgentMode>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AgentContext, AgentMode, AgentRunResult, AgentTool } from './types';
|
|
2
|
+
import type { AiClient } from '../ai/types';
|
|
3
|
+
import type { Logger } from '../utils/logger';
|
|
4
|
+
/**
|
|
5
|
+
* Wrap third-party text so the model reads it as data.
|
|
6
|
+
*
|
|
7
|
+
* Untrusted content never reaches the system prompt or the task; it arrives
|
|
8
|
+
* only as tool output, inside this marker. That is the structural half of the
|
|
9
|
+
* prompt-injection defence — the mode playbook states the rule, and this
|
|
10
|
+
* ensures the model can always tell which half of its context a third party
|
|
11
|
+
* wrote.
|
|
12
|
+
*
|
|
13
|
+
* @param content - Text controlled by someone other than the repository owner
|
|
14
|
+
*/
|
|
15
|
+
export declare function wrapUntrusted(content: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Run an agent task to completion.
|
|
18
|
+
*
|
|
19
|
+
* The loop is bounded three ways — tool calls, wall clock, and the AI client's
|
|
20
|
+
* own token budget — because an agent that cannot finish should stop and say
|
|
21
|
+
* so rather than run until something else kills it.
|
|
22
|
+
*
|
|
23
|
+
* @param ai - Configured AI client
|
|
24
|
+
* @param options - Mode, task and run context
|
|
25
|
+
* @returns The final output, the reason the run ended, and a redacted transcript
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const result = await runAgent(ai, {
|
|
29
|
+
* mode: getAgentMode('review'),
|
|
30
|
+
* task: 'Review the diff on this branch.',
|
|
31
|
+
* context: { workspace: process.cwd(), baseBranch: 'main' },
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function runAgent(ai: AiClient, options: AgentRunOptions): Promise<AgentRunResult>;
|
|
36
|
+
/** Options for a single agent run. */
|
|
37
|
+
export declare interface AgentRunOptions {
|
|
38
|
+
mode: AgentMode
|
|
39
|
+
task: string
|
|
40
|
+
context: Omit<AgentContext, 'log'>
|
|
41
|
+
tools?: AgentTool[]
|
|
42
|
+
timeoutMs?: number
|
|
43
|
+
logger?: Logger
|
|
44
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { AiClient } from '../ai/types';
|
|
2
|
+
import type { FinishingTouch } from './tasks';
|
|
3
|
+
import type { GitProvider } from '../git/provider';
|
|
4
|
+
import type { Logger } from '../utils/logger';
|
|
5
|
+
import type { PullRequest } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Run the repository's tests.
|
|
8
|
+
*
|
|
9
|
+
* Reports `ran: false` rather than `passed: false` when there is no test
|
|
10
|
+
* script: a repository without tests has not failed verification, it has
|
|
11
|
+
* declined it, and treating the two the same would downgrade every finishing
|
|
12
|
+
* touch in every untested repository.
|
|
13
|
+
*
|
|
14
|
+
* @param dir - Repository root
|
|
15
|
+
* @param command - Explicit command, else the first that applies
|
|
16
|
+
* @returns Whether tests ran and whether they passed
|
|
17
|
+
*/
|
|
18
|
+
export declare function verifyChanges(dir: string, command?: string[]): Promise<Verification>;
|
|
19
|
+
/** Branch name for a touch stacked on a pull request. */
|
|
20
|
+
export declare function stackedBranchName(pullRequest: PullRequest, touch: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Run a finishing touch and deliver it as a stacked pull request.
|
|
23
|
+
*
|
|
24
|
+
* The delivery is what makes this safe. Buddy never commits to the
|
|
25
|
+
* contributor's branch — it opens a pull request *targeting* that branch, so
|
|
26
|
+
* the contributor reviews and merges it themselves. Writing directly would
|
|
27
|
+
* mean agent-authored commits appearing under someone else's name on a branch
|
|
28
|
+
* they are responsible for, which is not a trade worth making for convenience.
|
|
29
|
+
*
|
|
30
|
+
* When verification fails, the change is not published as a branch at all: it
|
|
31
|
+
* comes back as committable suggestions on the original pull request, clearly
|
|
32
|
+
* marked as unverified. A stacked PR that does not build is worse than a
|
|
33
|
+
* comment, because it looks finished.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Provider, pull request, touch and clients
|
|
36
|
+
* @returns How it was delivered and what to say back
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const result = await runStackedTouch({ provider, pullRequest, touch, ai, workspace })
|
|
40
|
+
* await provider.createComment(pullRequest.number, result.comment)
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function runStackedTouch(options: StackedOptions): Promise<StackedResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Files the working tree has modified, according to git.
|
|
46
|
+
*
|
|
47
|
+
* Deletions are excluded: a stacked pull request that removes a contributor's
|
|
48
|
+
* file is a much larger claim than one that edits it, and a finishing touch
|
|
49
|
+
* has no business making it.
|
|
50
|
+
*
|
|
51
|
+
* @param workspace - Repository directory
|
|
52
|
+
* @returns Repository-relative paths
|
|
53
|
+
*/
|
|
54
|
+
export declare function detectChangedFiles(workspace: string): Promise<string[]>;
|
|
55
|
+
/** Commands that run a repository's tests, in preference order. */
|
|
56
|
+
export declare const TEST_COMMANDS: string[][];
|
|
57
|
+
/** What running a finishing touch produced. */
|
|
58
|
+
export declare interface StackedResult {
|
|
59
|
+
mode: DeliveryMode
|
|
60
|
+
pullRequest?: PullRequest
|
|
61
|
+
changedFiles: string[]
|
|
62
|
+
verified: boolean
|
|
63
|
+
comment: string
|
|
64
|
+
}
|
|
65
|
+
/** What verifying a change found. */
|
|
66
|
+
export declare interface Verification {
|
|
67
|
+
ran: boolean
|
|
68
|
+
passed: boolean
|
|
69
|
+
output: string
|
|
70
|
+
}
|
|
71
|
+
/** Inputs to a stacked finishing touch. */
|
|
72
|
+
export declare interface StackedOptions {
|
|
73
|
+
provider: GitProvider
|
|
74
|
+
pullRequest: PullRequest
|
|
75
|
+
touch: FinishingTouch
|
|
76
|
+
ai: AiClient
|
|
77
|
+
workspace: string
|
|
78
|
+
testCommand?: string[]
|
|
79
|
+
files?: string[]
|
|
80
|
+
logger?: Logger
|
|
81
|
+
}
|
|
82
|
+
/** How a finishing touch was delivered. */
|
|
83
|
+
export type DeliveryMode = 'stacked-pr' | 'suggestions' | 'none';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AgentMode } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Look up a finishing touch by name.
|
|
4
|
+
*
|
|
5
|
+
* @param name - Touch name
|
|
6
|
+
* @throws {Error} When the name is unknown, rather than silently doing nothing
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFinishingTouch(name: string): FinishingTouch;
|
|
9
|
+
/**
|
|
10
|
+
* Render the offer of available touches as checkbox markers.
|
|
11
|
+
*
|
|
12
|
+
* Uses the same marker-and-checkbox mechanism as the dashboard, so ticking one
|
|
13
|
+
* is handled by machinery that already exists.
|
|
14
|
+
*
|
|
15
|
+
* @param names - Touches to offer
|
|
16
|
+
*/
|
|
17
|
+
export declare function renderTouchOffer(names?: string[]): string;
|
|
18
|
+
/** Parse which touches a maintainer ticked. */
|
|
19
|
+
export declare function parseTouchSelections(body: string | null | undefined): string[];
|
|
20
|
+
/** Generate missing documentation comments for changed public APIs. */
|
|
21
|
+
export declare const docstringsTouch: FinishingTouch;
|
|
22
|
+
/** Generate tests for changed behaviour, verified by running them. */
|
|
23
|
+
export declare const unitTestsTouch: FinishingTouch;
|
|
24
|
+
/** Apply the mechanical fixes a review already identified. */
|
|
25
|
+
export declare const autofixTouch: FinishingTouch;
|
|
26
|
+
/** Simplify changed code without altering behaviour. */
|
|
27
|
+
export declare const simplifyTouch: FinishingTouch;
|
|
28
|
+
/** Produce an implementation plan without changing anything. */
|
|
29
|
+
export declare const planTouch: FinishingTouch;
|
|
30
|
+
/** Every built-in finishing touch, by name. */
|
|
31
|
+
export declare const FINISHING_TOUCHES: Record<string, FinishingTouch>;
|
|
32
|
+
/** A named, repeatable agent task. */
|
|
33
|
+
export declare interface FinishingTouch {
|
|
34
|
+
name: string
|
|
35
|
+
description: string
|
|
36
|
+
mode: AgentMode
|
|
37
|
+
defaultOutput: TouchOutput
|
|
38
|
+
buildTask: (context: { summary?: string, files?: string[] }) => string
|
|
39
|
+
}
|
|
40
|
+
/** Where a finishing touch puts its result. */
|
|
41
|
+
export type TouchOutput = 'commit' | 'stacked-pr' | 'suggestion';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentContext, AgentMode, AgentTool, AgentToolOutput } from './types';
|
|
2
|
+
import type { AiTool } from '../ai/types';
|
|
3
|
+
/** Every tool the runtime knows about, before any mode filtering. */
|
|
4
|
+
export declare const BUILTIN_TOOLS: AgentTool[];
|
|
5
|
+
/**
|
|
6
|
+
* A mode's usable tools, and the means to run one.
|
|
7
|
+
*
|
|
8
|
+
* Filtering happens once, at construction: a tool outside the mode's tiers is
|
|
9
|
+
* never converted into a model-visible definition, so the model cannot request
|
|
10
|
+
* what it was never told exists. `invoke` re-checks anyway, because a caller
|
|
11
|
+
* assembling a belt by hand should not be able to bypass the boundary.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Toolbelt {
|
|
14
|
+
constructor(mode: AgentMode, tools?: AgentTool[]);
|
|
15
|
+
definitions(): AiTool[];
|
|
16
|
+
names(): string[];
|
|
17
|
+
has(name: string): boolean;
|
|
18
|
+
invoke(name: string, input: Record<string, unknown>, context: AgentContext): Promise<AgentToolOutput>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AgentContext, AgentTool } from '../types';
|
|
2
|
+
/** Re-exported so callers can guard paths without importing the tool module. */
|
|
3
|
+
export type { AgentContext };
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a model-supplied path against the workspace, refusing escapes.
|
|
6
|
+
*
|
|
7
|
+
* The path comes from the model, which means in the worst case it comes from
|
|
8
|
+
* whoever wrote the PR body the model is reading. Traversal is rejected twice
|
|
9
|
+
* — once on the repository-relative form, once on the resolved absolute path —
|
|
10
|
+
* because a symlink inside the workspace can satisfy the first check and still
|
|
11
|
+
* land outside it.
|
|
12
|
+
*
|
|
13
|
+
* @param path - Model-supplied path
|
|
14
|
+
* @param workspace - Directory the agent may operate within
|
|
15
|
+
* @returns The absolute path
|
|
16
|
+
* @throws {Error} When the path escapes the workspace
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveWorkspacePath(path: string, workspace: string): string;
|
|
19
|
+
/** Read a file from the workspace. */
|
|
20
|
+
export declare const readFileTool: AgentTool;
|
|
21
|
+
/** Write a file into the workspace. */
|
|
22
|
+
export declare const writeFileTool: AgentTool;
|
|
23
|
+
/** List a directory in the workspace. */
|
|
24
|
+
export declare const listDirTool: AgentTool;
|
|
25
|
+
/** Every filesystem tool, for registration. */
|
|
26
|
+
export declare const fsTools: AgentTool[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AgentTool } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Build the environment a sandboxed command runs with.
|
|
4
|
+
*
|
|
5
|
+
* @param base - Environment to filter, defaulting to the current process
|
|
6
|
+
* @param extraAllowed - Additional variable names the caller opted in to
|
|
7
|
+
* @returns Only the allowed, non-secret variables
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* buildShellEnv({ PATH: '/usr/bin', GITHUB_TOKEN: 'ghp_x' })
|
|
11
|
+
* // => { PATH: '/usr/bin' }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildShellEnv(base?: Record<string, string | undefined>, extraAllowed?: string[]): Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Environment variables the sandboxed shell may see.
|
|
17
|
+
*
|
|
18
|
+
* An allowlist rather than a blocklist: a new secret-bearing variable added to
|
|
19
|
+
* CI tomorrow is invisible to the agent by default, whereas a blocklist would
|
|
20
|
+
* leak it until someone remembered to add a rule. Nothing here carries
|
|
21
|
+
* credentials — these are the variables a build genuinely needs to run.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SHELL_ENV_ALLOWLIST: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Run a shell command inside the workspace with a stripped environment.
|
|
26
|
+
*
|
|
27
|
+
* The command itself is model-supplied and is not parsed or allowlisted — the
|
|
28
|
+
* containment boundary is the environment, the working directory, and the
|
|
29
|
+
* timeout, not the command text. Only modes that grant the `shell` tier get
|
|
30
|
+
* this tool at all.
|
|
31
|
+
*/
|
|
32
|
+
export declare const shellTool: AgentTool;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AiTool } from '../ai/types';
|
|
2
|
+
/** A tool the agent runtime can execute on the model's behalf. */
|
|
3
|
+
export declare interface AgentTool extends AiTool {
|
|
4
|
+
tier: ToolTier
|
|
5
|
+
run: (input: Record<string, unknown>, context: AgentContext) => Promise<AgentToolOutput>
|
|
6
|
+
}
|
|
7
|
+
/** The result of running a tool. */
|
|
8
|
+
export declare interface AgentToolOutput {
|
|
9
|
+
content: string
|
|
10
|
+
untrusted?: boolean
|
|
11
|
+
isError?: boolean
|
|
12
|
+
}
|
|
13
|
+
/** Everything a tool needs to do its work. */
|
|
14
|
+
export declare interface AgentContext {
|
|
15
|
+
workspace: string
|
|
16
|
+
baseBranch: string
|
|
17
|
+
branch?: string
|
|
18
|
+
repository?: { owner: string, name: string }
|
|
19
|
+
log: (message: string) => void
|
|
20
|
+
}
|
|
21
|
+
/** A named playbook plus the capabilities it may use. */
|
|
22
|
+
export declare interface AgentMode {
|
|
23
|
+
name: string
|
|
24
|
+
playbook: string
|
|
25
|
+
tiers: ToolTier[]
|
|
26
|
+
maxToolCalls: number
|
|
27
|
+
}
|
|
28
|
+
/** One step in a run, recorded for observability. */
|
|
29
|
+
export declare interface TranscriptEntry {
|
|
30
|
+
type: 'model' | 'tool' | 'error' | 'note'
|
|
31
|
+
at: number
|
|
32
|
+
name?: string
|
|
33
|
+
detail: string
|
|
34
|
+
outputTokens?: number
|
|
35
|
+
}
|
|
36
|
+
/** What a completed run produced. */
|
|
37
|
+
export declare interface AgentRunResult {
|
|
38
|
+
output: string
|
|
39
|
+
stopReason: 'completed' | 'max_tool_calls' | 'timeout' | 'budget' | 'error'
|
|
40
|
+
transcript: TranscriptEntry[]
|
|
41
|
+
outputTokens: number
|
|
42
|
+
toolCalls: number
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a tool is allowed to touch.
|
|
46
|
+
*
|
|
47
|
+
* Tiers are cumulative in capability but not in trust: a mode is granted a set
|
|
48
|
+
* of tiers, and a tool outside those tiers is never offered to the model at
|
|
49
|
+
* all rather than being offered and refused. A capability the model cannot see
|
|
50
|
+
* is one it cannot be talked into using.
|
|
51
|
+
*/
|
|
52
|
+
export type ToolTier = 'read' | 'comment' | 'write' | 'shell' | 'git';
|
|
53
|
+
/** Raised when a tool is invoked outside its mode's permitted tiers. */
|
|
54
|
+
export declare class ToolPermissionError extends Error {
|
|
55
|
+
constructor(toolName: string, tier: ToolTier, mode: string);
|
|
56
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AiProviderName } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve an alias to a concrete model ID.
|
|
4
|
+
*
|
|
5
|
+
* Unknown values pass through unchanged — they are assumed to be concrete IDs,
|
|
6
|
+
* so a newly released model works without waiting for the table to catch up.
|
|
7
|
+
*
|
|
8
|
+
* @param model - Alias or concrete model ID
|
|
9
|
+
* @returns The concrete model ID
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* resolveModelAlias('opus') // => 'claude-opus-5'
|
|
13
|
+
* resolveModelAlias('claude-haiku-4-5') // => 'claude-haiku-4-5'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveModelAlias(model: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Short names that resolve to concrete Anthropic model IDs.
|
|
19
|
+
*
|
|
20
|
+
* Only Anthropic aliases ship built in, because only those can be kept
|
|
21
|
+
* accurate here: resolving `gpt` or `gemini` to a specific ID would mean
|
|
22
|
+
* guessing at another vendor's catalogue and silently sending requests to a
|
|
23
|
+
* model the user did not choose. Other providers take an explicit model ID.
|
|
24
|
+
* @defaultValue
|
|
25
|
+
* ```ts
|
|
26
|
+
* {
|
|
27
|
+
* 'claude': 'claude-opus-5',
|
|
28
|
+
* 'claude-opus': 'claude-opus-5',
|
|
29
|
+
* 'opus': 'claude-opus-5',
|
|
30
|
+
* 'claude-sonnet': 'claude-sonnet-5',
|
|
31
|
+
* 'sonnet': 'claude-sonnet-5',
|
|
32
|
+
* 'claude-haiku': 'claude-haiku-4-5',
|
|
33
|
+
* 'haiku': 'claude-haiku-4-5',
|
|
34
|
+
* 'claude-fable': 'claude-fable-5',
|
|
35
|
+
* 'fable': 'claude-fable-5'
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const MODEL_ALIASES: Record<string, string>;
|
|
40
|
+
/** Model used when a provider is selected without naming one. */
|
|
41
|
+
export declare const PROVIDER_DEFAULT_MODEL: Partial<Record<AiProviderName, string>>;
|
|
42
|
+
/**
|
|
43
|
+
* Environment variable holding each provider's API key.
|
|
44
|
+
* @defaultValue
|
|
45
|
+
* ```ts
|
|
46
|
+
* {
|
|
47
|
+
* 'anthropic': ['ANTHROPIC_API_KEY'],
|
|
48
|
+
* 'openai': ['OPENAI_API_KEY'],
|
|
49
|
+
* 'google': ['GOOGLE_API_KEY', 'GEMINI_API_KEY'],
|
|
50
|
+
* 'openrouter': ['OPENROUTER_API_KEY'],
|
|
51
|
+
* 'openai-compatible': ['OPENAI_COMPATIBLE_API_KEY', 'OPENAI_API_KEY']
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const PROVIDER_KEY_ENV: Record<AiProviderName, string[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Order providers are auto-selected in when the config names none.
|
|
58
|
+
*
|
|
59
|
+
* Anthropic first because its models are the ones this codebase's prompts and
|
|
60
|
+
* alias table are written against.
|
|
61
|
+
*/
|
|
62
|
+
export declare const PROVIDER_PRIORITY: AiProviderName[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AiClient, AiProviderName } from './types';
|
|
2
|
+
import type { BuddyConfig } from '../types';
|
|
3
|
+
import type { Logger } from '../utils/logger';
|
|
4
|
+
/**
|
|
5
|
+
* Work out which provider and model to use, and find its key.
|
|
6
|
+
*
|
|
7
|
+
* Resolution order is explicit config, then the first provider in priority
|
|
8
|
+
* order with a key present. Returning `null` rather than throwing is
|
|
9
|
+
* deliberate: no key configured is the normal state for a dependency bot, and
|
|
10
|
+
* every AI feature is expected to degrade to a no-op rather than fail the run.
|
|
11
|
+
*
|
|
12
|
+
* @param config - Full buddy configuration
|
|
13
|
+
* @param env - Environment to read keys from (defaults to `process.env`)
|
|
14
|
+
* @returns The resolution, or `null` when no provider is usable
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveAiProvider(config: BuddyConfig, env?: Record<string, string | undefined>): AiResolution | null;
|
|
17
|
+
/**
|
|
18
|
+
* Build an AI client from configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param config - Full buddy configuration
|
|
21
|
+
* @param logger - Logger for diagnostics; defaults to the process-wide logger
|
|
22
|
+
* @returns A client, or `null` when no provider is configured — callers must
|
|
23
|
+
* treat `null` as "AI features are off" rather than as an error
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const ai = createAiClient(config)
|
|
27
|
+
* if (!ai) {
|
|
28
|
+
* logger.info('AI disabled (no API key)')
|
|
29
|
+
* return
|
|
30
|
+
* }
|
|
31
|
+
* const response = await ai.complete({ messages: [{ role: 'user', content: 'hi' }] })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function createAiClient(config: BuddyConfig, logger?: Logger): AiClient | null;
|
|
35
|
+
/** What provider, model and credentials a run resolved to. */
|
|
36
|
+
export declare interface AiResolution {
|
|
37
|
+
provider: AiProviderName
|
|
38
|
+
model: string
|
|
39
|
+
apiKey: string
|
|
40
|
+
baseUrl?: string
|
|
41
|
+
apiKeyEnv?: string
|
|
42
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type { Learning } from './learnings';
|
|
2
|
+
export type { AiResolution } from './client';
|
|
3
|
+
export type {
|
|
4
|
+
AiClient,
|
|
5
|
+
AiCompletionRequest,
|
|
6
|
+
AiEffort,
|
|
7
|
+
AiMessage,
|
|
8
|
+
AiProvider,
|
|
9
|
+
AiProviderName,
|
|
10
|
+
AiResponse,
|
|
11
|
+
AiTool,
|
|
12
|
+
AiToolCall,
|
|
13
|
+
AiUsage,
|
|
14
|
+
} from './types';
|
|
15
|
+
export { MODEL_ALIASES, PROVIDER_KEY_ENV, PROVIDER_PRIORITY, resolveModelAlias } from './aliases';
|
|
16
|
+
export { createAiClient, resolveAiProvider } from './client';
|
|
17
|
+
export {
|
|
18
|
+
addLearning,
|
|
19
|
+
createLearning,
|
|
20
|
+
DEFAULT_LEARNINGS_FILE,
|
|
21
|
+
DEFAULT_PROMPT_LIMIT,
|
|
22
|
+
loadLearnings,
|
|
23
|
+
parseLearnings,
|
|
24
|
+
renderLearnings,
|
|
25
|
+
selectLearnings,
|
|
26
|
+
serializeLearnings,
|
|
27
|
+
} from './learnings';
|
|
28
|
+
export { createAnthropicProvider } from './providers/anthropic';
|
|
29
|
+
export { createGoogleProvider } from './providers/google';
|
|
30
|
+
export { createOpenAiProvider } from './providers/openai';
|
|
31
|
+
export { redact, redactDeep, redactError, REDACTED } from './redact';
|
|
32
|
+
export {
|
|
33
|
+
AiBudgetExceededError,
|
|
34
|
+
AiProviderError,
|
|
35
|
+
} from './types';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Logger } from '../utils/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a learnings file.
|
|
4
|
+
*
|
|
5
|
+
* JSONL rather than JSON so appending a learning is a one-line diff a
|
|
6
|
+
* maintainer can review, and one corrupt line loses one learning instead of
|
|
7
|
+
* the whole file.
|
|
8
|
+
*
|
|
9
|
+
* @param content - File contents
|
|
10
|
+
* @returns Every readable learning; unreadable lines are skipped
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseLearnings(content: string | null | undefined): Learning[];
|
|
13
|
+
/** Render learnings back to JSONL. */
|
|
14
|
+
export declare function serializeLearnings(learnings: Learning[]): string;
|
|
15
|
+
/**
|
|
16
|
+
* Build a learning from free text.
|
|
17
|
+
*
|
|
18
|
+
* @param text - The fact to record
|
|
19
|
+
* @param options - Scope, category and provenance
|
|
20
|
+
*/
|
|
21
|
+
export declare function createLearning(text: string, options?: { paths?: string[], kind?: string, source?: Learning['source'] }): Learning;
|
|
22
|
+
/**
|
|
23
|
+
* Add a learning, replacing any that says the same thing.
|
|
24
|
+
*
|
|
25
|
+
* Deduplicating on text means a maintainer repeating themselves updates the
|
|
26
|
+
* existing note rather than growing the file with near-copies that each cost
|
|
27
|
+
* prompt budget.
|
|
28
|
+
*
|
|
29
|
+
* @param existing - Current learnings
|
|
30
|
+
* @param learning - Learning to add
|
|
31
|
+
*/
|
|
32
|
+
export declare function addLearning(existing: Learning[], learning: Learning): Learning[];
|
|
33
|
+
/**
|
|
34
|
+
* Pick the learnings worth sending for a given set of files.
|
|
35
|
+
*
|
|
36
|
+
* Path-scoped learnings that match rank above unscoped ones, and newer above
|
|
37
|
+
* older, because a note written about the files under review is more likely to
|
|
38
|
+
* matter than a general one written a year ago.
|
|
39
|
+
*
|
|
40
|
+
* @param learnings - Every recorded learning
|
|
41
|
+
* @param files - Files under review; empty selects only unscoped learnings
|
|
42
|
+
* @param limit - Maximum to return
|
|
43
|
+
* @returns The selected learnings, most relevant first
|
|
44
|
+
*/
|
|
45
|
+
export declare function selectLearnings(learnings: Learning[], files: string[], limit?: number): Learning[];
|
|
46
|
+
/**
|
|
47
|
+
* Render learnings as prompt text.
|
|
48
|
+
*
|
|
49
|
+
* @param learnings - Learnings to include
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderLearnings(learnings: Learning[]): string;
|
|
52
|
+
/**
|
|
53
|
+
* Load learnings from a repository ref.
|
|
54
|
+
*
|
|
55
|
+
* **Always read at the base ref.** Learnings are injected into prompts as
|
|
56
|
+
* trusted context, so reading them from a pull request's own branch would let
|
|
57
|
+
* a contributor add "approve everything" to the file their PR is reviewed
|
|
58
|
+
* under — the same rule that governs guideline files.
|
|
59
|
+
*
|
|
60
|
+
* @param read - Reader that fetches a path at a given ref
|
|
61
|
+
* @param baseRef - Branch or SHA to read from, never the PR head
|
|
62
|
+
* @param file - Path to the learnings file
|
|
63
|
+
* @param logger - Logger for diagnostics
|
|
64
|
+
*/
|
|
65
|
+
export declare function loadLearnings(read: (path: string, ref: string) => Promise<string | null>, baseRef: string, file?: string, logger?: Logger): Promise<Learning[]>;
|
|
66
|
+
/** Where learnings live by default, relative to the repository root. */
|
|
67
|
+
export declare const DEFAULT_LEARNINGS_FILE: '.buddy/learnings.jsonl';
|
|
68
|
+
/** How many learnings are injected into a prompt before ranking cuts off. */
|
|
69
|
+
export declare const DEFAULT_PROMPT_LIMIT: 20;
|
|
70
|
+
/** A durable fact recorded for future runs. */
|
|
71
|
+
export declare interface Learning {
|
|
72
|
+
id: string
|
|
73
|
+
text: string
|
|
74
|
+
paths?: string[]
|
|
75
|
+
kind?: string
|
|
76
|
+
source?: { pr?: number, issue?: number, comment?: number }
|
|
77
|
+
createdAt: string
|
|
78
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AiProvider } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic provider, backed by the official SDK.
|
|
4
|
+
*
|
|
5
|
+
* The SDK is used rather than raw fetch because it tracks the API's evolving
|
|
6
|
+
* request surface — thinking configuration, effort, structured outputs and
|
|
7
|
+
* error typing all changed shape across recent model generations.
|
|
8
|
+
*
|
|
9
|
+
* @param options - API key and optional gateway base URL
|
|
10
|
+
* @returns A provider ready to complete requests
|
|
11
|
+
*/
|
|
12
|
+
export declare function createAnthropicProvider(options: { apiKey: string, baseUrl?: string }): AiProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AiProvider } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Google Gemini provider.
|
|
4
|
+
*
|
|
5
|
+
* Gemini's wire format differs enough from the OpenAI shape — `contents` with
|
|
6
|
+
* `parts` rather than `messages`, `model` role rather than `assistant`, tools
|
|
7
|
+
* nested under `functionDeclarations` — that it gets its own mapping rather
|
|
8
|
+
* than a compatibility shim.
|
|
9
|
+
*
|
|
10
|
+
* @param options - API key and optional base URL
|
|
11
|
+
*/
|
|
12
|
+
export declare function createGoogleProvider(options: { apiKey: string, baseUrl?: string }): AiProvider;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AiProvider, AiProviderName } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Provider for any OpenAI-compatible chat-completions endpoint.
|
|
4
|
+
*
|
|
5
|
+
* One implementation serves OpenAI, OpenRouter and self-hosted gateways
|
|
6
|
+
* because they share a wire format — which is also why this provider takes a
|
|
7
|
+
* base URL rather than hard-coding a host.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Provider identity, credentials and endpoint
|
|
10
|
+
*/
|
|
11
|
+
export declare function createOpenAiProvider(options: {
|
|
12
|
+
apiKey: string
|
|
13
|
+
baseUrl?: string
|
|
14
|
+
provider?: AiProviderName
|
|
15
|
+
}): AiProvider;
|