@cursor/july 0.1.68 → 0.1.74
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/AGENTS.md +17 -13
- package/README.md +23 -11
- package/dist/bin/agent-serve.js +10 -7
- package/dist/channels/github/api.d.ts +2 -0
- package/dist/channels/github/api.d.ts.map +1 -1
- package/dist/channels/github/api.js +2 -1
- package/dist/channels/github/binding.d.ts +7 -0
- package/dist/channels/github/binding.d.ts.map +1 -1
- package/dist/channels/github/binding.js +4 -0
- package/dist/channels/github/checks.d.ts +99 -0
- package/dist/channels/github/checks.d.ts.map +1 -0
- package/dist/channels/github/checks.js +108 -0
- package/dist/channels/github/cursor-account.d.ts +4 -4
- package/dist/channels/github/cursor-account.d.ts.map +1 -1
- package/dist/channels/github/cursor-account.js +7 -5
- package/dist/channels/github/index.d.ts +1 -0
- package/dist/channels/github/index.d.ts.map +1 -1
- package/dist/channels/github/index.js +1 -0
- package/dist/channels/github/types.d.ts +8 -0
- package/dist/channels/github/types.d.ts.map +1 -1
- package/dist/channels/slack/manifest.d.ts +2 -2
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +13 -11
- package/dist/channels/slack/types.d.ts +2 -2
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/connections.d.ts +17 -5
- package/dist/connections.d.ts.map +1 -1
- package/dist/connections.js +17 -5
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +3 -3
- package/dist/docs/assets/{app.C5XUTCw9.js → app.BETd-WqU.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DM5INS71.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.CGDTAYHY.js → VPLocalSearchBox.wEaGEmV9.js} +1 -1
- package/dist/docs/assets/chunks/{theme.lPixh250.js → theme.DNDicFOP.js} +2 -2
- package/dist/docs/assets/{concepts.md.CqOsxbMU.js → concepts.md.BXAm6G-C.js} +1 -1
- package/dist/docs/assets/{guides_mcp-oauth.md.C7G7IykG.js → guides_mcp-oauth.md.CzEB6RaG.js} +1 -1
- package/dist/docs/assets/{reference_agent-config.md.DHkkvcEZ.js → reference_agent-config.md.BZnEKfEc.js} +3 -4
- package/dist/docs/assets/{reference_agent-config.md.DHkkvcEZ.lean.js → reference_agent-config.md.BZnEKfEc.lean.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.Cl14Jfo3.js → reference_cli.md.TAaYU8br.js} +3 -3
- package/dist/docs/assets/{reference_cli.md.Cl14Jfo3.lean.js → reference_cli.md.TAaYU8br.lean.js} +1 -1
- package/dist/docs/assets/{reference_connections.md.Bwswbm6H.js → reference_connections.md.Cu3N-S3Q.js} +18 -11
- package/dist/docs/assets/{reference_connections.md.Bwswbm6H.lean.js → reference_connections.md.Cu3N-S3Q.lean.js} +1 -1
- package/dist/docs/assets/{reference_sessions.md.DBVFi2Sx.js → reference_sessions.md.B0DdlM-K.js} +1 -1
- package/dist/docs/assets/{reference_tools.md.Wmvb7Lob.js → reference_tools.md.DTg_kEsx.js} +1 -1
- package/dist/docs/assets/scaffolding-agents.md.CiGsJ1aw.js +1 -0
- package/dist/docs/assets/{scaffolding-agents.md.CrWSA0Ko.lean.js → scaffolding-agents.md.CiGsJ1aw.lean.js} +1 -1
- package/dist/docs/assets/troubleshooting.md.DQ-hYuZT.js +1 -0
- package/dist/docs/building-with-agents.html +3 -3
- package/dist/docs/concepts.html +5 -5
- package/dist/docs/deployment.html +3 -3
- package/dist/docs/evals.html +3 -3
- package/dist/docs/example-agents/approval-buddy.html +3 -3
- package/dist/docs/example-agents/benny.html +3 -3
- package/dist/docs/example-agents/bugbot.html +3 -3
- package/dist/docs/example-agents/codebase-wiki.html +3 -3
- package/dist/docs/example-agents/codeowners-review.html +3 -3
- package/dist/docs/example-agents/concierge.html +3 -3
- package/dist/docs/example-agents/fsd.html +3 -3
- package/dist/docs/example-agents/index.html +3 -3
- package/dist/docs/example-agents/knowledge-base.html +3 -3
- package/dist/docs/example-agents/oncall.html +3 -3
- package/dist/docs/example-agents/security-reviewer.html +3 -3
- package/dist/docs/example-agents/slack-agent.html +3 -3
- package/dist/docs/example-agents/weather-agent.html +3 -3
- package/dist/docs/guides/agent-to-agent.html +3 -3
- package/dist/docs/guides/cloud-runtime.html +3 -3
- package/dist/docs/guides/convert-automation.html +3 -3
- package/dist/docs/guides/github.html +3 -3
- package/dist/docs/guides/human-in-the-loop.html +3 -3
- package/dist/docs/guides/mcp-oauth.html +5 -5
- package/dist/docs/guides/opentelemetry.html +3 -3
- package/dist/docs/guides/slack.html +3 -3
- package/dist/docs/guides/webhooks.html +3 -3
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +3 -3
- package/dist/docs/index.html +3 -3
- package/dist/docs/quickstart.html +3 -3
- package/dist/docs/reference/agent-config.html +5 -6
- package/dist/docs/reference/artifacts.html +3 -3
- package/dist/docs/reference/channels.html +3 -3
- package/dist/docs/reference/cli.html +6 -6
- package/dist/docs/reference/connections.html +20 -13
- package/dist/docs/reference/hooks.html +3 -3
- package/dist/docs/reference/http-api.html +3 -3
- package/dist/docs/reference/instructions.html +3 -3
- package/dist/docs/reference/playground.html +3 -3
- package/dist/docs/reference/project-layout.html +3 -3
- package/dist/docs/reference/prompt.html +3 -3
- package/dist/docs/reference/schedules.html +3 -3
- package/dist/docs/reference/sessions.html +5 -5
- package/dist/docs/reference/skills.html +3 -3
- package/dist/docs/reference/subagents.html +3 -3
- package/dist/docs/reference/tools.html +5 -5
- package/dist/docs/scaffolding-agents.html +5 -5
- package/dist/docs/storage.html +3 -3
- package/dist/docs/templates/agentic-owners.html +3 -3
- package/dist/docs/templates/demo.html +3 -3
- package/dist/docs/templates/pr-autofixer.html +3 -3
- package/dist/docs/templates/security-reviewer.html +3 -3
- package/dist/docs/templates/triage.html +3 -3
- package/dist/docs/troubleshooting.html +5 -5
- package/dist/internal/advertise-tools.d.ts +11 -6
- package/dist/internal/advertise-tools.d.ts.map +1 -1
- package/dist/internal/advertise-tools.js +63 -30
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +2 -4
- package/dist/internal/cli-skills.d.ts +4 -2
- package/dist/internal/cli-skills.d.ts.map +1 -1
- package/dist/internal/cli-skills.js +8 -3
- package/dist/internal/convert-automation/convert-workflow.d.ts.map +1 -1
- package/dist/internal/convert-automation/convert-workflow.js +2 -10
- package/dist/internal/cursor/account-mcp.d.ts +29 -3
- package/dist/internal/cursor/account-mcp.d.ts.map +1 -1
- package/dist/internal/cursor/account-mcp.js +147 -67
- package/dist/internal/cursor/backend-client.d.ts +11 -6
- package/dist/internal/cursor/backend-client.d.ts.map +1 -1
- package/dist/internal/cursor/backend-client.js +32 -10
- package/dist/internal/cursor-account-mcp-auth.d.ts +11 -0
- package/dist/internal/cursor-account-mcp-auth.d.ts.map +1 -1
- package/dist/internal/cursor-account-mcp-auth.js +69 -0
- package/dist/internal/deploy-client.d.ts +0 -7
- package/dist/internal/deploy-client.d.ts.map +1 -1
- package/dist/internal/deploy-client.js +2 -4
- package/dist/internal/deploy-manifest.d.ts +15 -24
- package/dist/internal/deploy-manifest.d.ts.map +1 -1
- package/dist/internal/deploy-manifest.js +38 -27
- package/dist/internal/deployment-scm-event-stream.d.ts +4 -1
- package/dist/internal/deployment-scm-event-stream.d.ts.map +1 -1
- package/dist/internal/deployment-scm-event-stream.js +15 -1
- package/dist/internal/discovery.d.ts.map +1 -1
- package/dist/internal/discovery.js +42 -10
- package/dist/internal/init-project.d.ts.map +1 -1
- package/dist/internal/init-project.js +7 -106
- package/dist/internal/init-scaffold.d.ts +8 -0
- package/dist/internal/init-scaffold.d.ts.map +1 -0
- package/dist/internal/init-scaffold.js +168 -0
- package/dist/internal/inline-stdio-mcp.d.ts +2 -0
- package/dist/internal/inline-stdio-mcp.d.ts.map +1 -1
- package/dist/internal/inline-stdio-mcp.js +10 -8
- package/dist/internal/install-cursor-skills.d.ts +71 -16
- package/dist/internal/install-cursor-skills.d.ts.map +1 -1
- package/dist/internal/install-cursor-skills.js +160 -48
- package/dist/internal/json-schema.d.ts +7 -0
- package/dist/internal/json-schema.d.ts.map +1 -1
- package/dist/internal/json-schema.js +18 -3
- package/dist/internal/mcp-endpoint.js +7 -7
- package/dist/internal/mcp-host.js +4 -2
- package/dist/internal/mcp-oauth.d.ts +22 -0
- package/dist/internal/mcp-oauth.d.ts.map +1 -1
- package/dist/internal/mcp-oauth.js +40 -1
- package/dist/internal/package-inline-stdio.d.ts.map +1 -1
- package/dist/internal/package-inline-stdio.js +5 -5
- package/dist/internal/review-comments.d.ts +97 -0
- package/dist/internal/review-comments.d.ts.map +1 -1
- package/dist/internal/review-comments.js +151 -0
- package/dist/internal/sanitize-mcp-tool-name.d.ts +20 -0
- package/dist/internal/sanitize-mcp-tool-name.d.ts.map +1 -0
- package/dist/internal/sanitize-mcp-tool-name.js +30 -0
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +6 -2
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +4 -6
- package/dist/internal/shallow-clone.d.ts +94 -39
- package/dist/internal/shallow-clone.d.ts.map +1 -1
- package/dist/internal/shallow-clone.js +188 -68
- package/dist/internal/terminal-style.d.ts +18 -0
- package/dist/internal/terminal-style.d.ts.map +1 -1
- package/dist/internal/terminal-style.js +46 -1
- package/dist/internal/workspace.d.ts +2 -0
- package/dist/internal/workspace.d.ts.map +1 -1
- package/dist/internal/workspace.js +5 -0
- package/dist/playground/assets/index-D_8I9TM0.js +85 -0
- package/dist/playground/assets/index-M3nSMc6_.css +1 -0
- package/dist/playground/index.html +2 -2
- package/dist/tools.d.ts +7 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/types.d.ts +28 -3
- package/dist/types.d.ts.map +1 -1
- package/docs/concepts.md +4 -4
- package/docs/guides/mcp-oauth.md +3 -1
- package/docs/reference/agent-config.md +11 -12
- package/docs/reference/cli.md +16 -8
- package/docs/reference/connections.md +44 -26
- package/docs/reference/sessions.md +2 -2
- package/docs/reference/tools.md +1 -1
- package/docs/scaffolding-agents.md +14 -6
- package/docs/troubleshooting.md +3 -2
- package/package.json +6 -1
- package/scripts/install-cursor-skills.mjs +36 -0
- package/skills/ab/SKILL.md +1 -1
- package/skills/create-agent/SKILL.md +13 -10
- package/skills/debug/SKILL.md +3 -2
- package/skills/evals/SKILL.md +1 -1
- package/skills/framework-map/SKILL.md +7 -7
- package/skills/github/SKILL.md +1 -1
- package/skills/hillclimb/SKILL.md +1 -1
- package/skills/mcp-auth/SKILL.md +9 -7
- package/skills/otel/SKILL.md +1 -1
- package/skills/setup-slack/SKILL.md +1 -1
- package/src/bin/agent-serve.ts +10 -7
- package/src/channels/github/api.ts +6 -1
- package/src/channels/github/binding.ts +21 -0
- package/src/channels/github/checks.ts +179 -0
- package/src/channels/github/cursor-account.ts +9 -6
- package/src/channels/github/index.ts +1 -0
- package/src/channels/github/types.ts +8 -0
- package/src/channels/slack/manifest.ts +8 -10
- package/src/channels/slack/types.ts +2 -2
- package/src/connections.ts +17 -5
- package/src/internal/advertise-tools.ts +72 -23
- package/src/internal/cli-deploy.ts +4 -15
- package/src/internal/cli-skills.ts +10 -2
- package/src/internal/convert-automation/convert-workflow.ts +2 -11
- package/src/internal/cursor/account-mcp.ts +208 -73
- package/src/internal/cursor/backend-client.ts +45 -11
- package/src/internal/cursor-account-mcp-auth.ts +83 -0
- package/src/internal/deploy-client.ts +0 -10
- package/src/internal/deploy-manifest.ts +33 -39
- package/src/internal/deployment-scm-event-stream.ts +17 -1
- package/src/internal/discovery.ts +47 -3
- package/src/internal/init-project.ts +7 -133
- package/src/internal/init-scaffold.ts +176 -0
- package/src/internal/inline-stdio-mcp.ts +13 -0
- package/src/internal/install-cursor-skills.ts +204 -49
- package/src/internal/json-schema.ts +24 -3
- package/src/internal/mcp-endpoint.ts +6 -0
- package/src/internal/mcp-host.ts +4 -0
- package/src/internal/mcp-oauth.ts +55 -1
- package/src/internal/package-inline-stdio.ts +5 -1
- package/src/internal/review-comments.ts +245 -0
- package/src/internal/sanitize-mcp-tool-name.ts +33 -0
- package/src/internal/sdk-runner.ts +6 -3
- package/src/internal/session-engine.ts +7 -0
- package/src/internal/shallow-clone.ts +293 -105
- package/src/internal/terminal-style.ts +67 -1
- package/src/internal/workspace.ts +6 -0
- package/src/tools.ts +7 -0
- package/src/types.ts +32 -4
- package/templates/agentic-owners/agent/agent.ts +3 -0
- package/templates/demo/agent/agent.ts +3 -0
- package/templates/security-reviewer/agent/agent.ts +3 -0
- package/templates/triage/agent/agent.ts +3 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.DvUR3lv9.js +0 -1
- package/dist/docs/assets/scaffolding-agents.md.CrWSA0Ko.js +0 -1
- package/dist/docs/assets/troubleshooting.md.CuVztCKs.js +0 -1
- package/dist/playground/assets/index-CoL7xCJl.css +0 -1
- package/dist/playground/assets/index-yxs1heea.js +0 -85
- /package/dist/docs/assets/{concepts.md.CqOsxbMU.lean.js → concepts.md.BXAm6G-C.lean.js} +0 -0
- /package/dist/docs/assets/{guides_mcp-oauth.md.C7G7IykG.lean.js → guides_mcp-oauth.md.CzEB6RaG.lean.js} +0 -0
- /package/dist/docs/assets/{reference_sessions.md.DBVFi2Sx.lean.js → reference_sessions.md.B0DdlM-K.lean.js} +0 -0
- /package/dist/docs/assets/{reference_tools.md.Wmvb7Lob.lean.js → reference_tools.md.DTg_kEsx.lean.js} +0 -0
- /package/dist/docs/assets/{troubleshooting.md.CuVztCKs.lean.js → troubleshooting.md.DQ-hYuZT.lean.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shallow
|
|
2
|
+
* Shallow SCM PR checkout for SDK agents that review a PR's code.
|
|
3
3
|
*
|
|
4
4
|
* Mirrors Bugbot's `shallow_fetch` prefetch strategy
|
|
5
5
|
* (`backend/crates/napi_bugbot/src/temp_clone.rs`): instead of cloning the
|
|
@@ -10,11 +10,19 @@
|
|
|
10
10
|
* clone because its tools stream objects on demand; SDK agents read a real
|
|
11
11
|
* working tree, so we materialize the head checkout instead.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* SCM support follows Bugbot's provider seam (`IGitProvider.getCloneTarget`
|
|
14
|
+
* / the Rust `clone_url` dispatch): everything provider-specific — remote
|
|
15
|
+
* URL shape, git credential username convention, PR head ref layout — lives
|
|
16
|
+
* in one {@link ScmCloneTarget} produced by {@link resolveScmCloneTarget}.
|
|
17
|
+
* Supporting another SCM (GitLab, Bitbucket, …) means adding a resolver
|
|
18
|
+
* case and a default credential source; the fetch/verify/checkout machinery
|
|
19
|
+
* is provider-agnostic.
|
|
20
|
+
*
|
|
21
|
+
* Auth also mirrors Bugbot (`IGitProvider.getAccessToken` → token handed
|
|
22
|
+
* straight to git): the clone takes one explicit repo-scoped bearer token.
|
|
23
|
+
* For GitHub the default source is the serve host's Cursor-account lease —
|
|
24
|
+
* the same backend `GithubAccessService` mint Bugbot uses — which
|
|
25
|
+
* `CursorGithubCredentialProvider` installs as `GH_TOKEN` for child
|
|
18
26
|
* processes. Where Bugbot embeds the token in the clone URL, this module
|
|
19
27
|
* serves it through an inline credential helper that reads a child-process
|
|
20
28
|
* env var, so the token never lands in argv or in `.git/config` inside a
|
|
@@ -24,34 +32,90 @@
|
|
|
24
32
|
* the security reviewer's `prepare_review` stage). Consumed via relative
|
|
25
33
|
* source imports, following `tenant-mcp/run-mcp-registry.ts`.
|
|
26
34
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
/** SCMs with shallow-clone support. */
|
|
36
|
+
export type ScmProvider = "github";
|
|
37
|
+
/**
|
|
38
|
+
* Everything git needs to clone one SCM's PR head. Provider-specific
|
|
39
|
+
* conventions live here and nowhere else.
|
|
40
|
+
*/
|
|
41
|
+
export type ScmCloneTarget = {
|
|
42
|
+
provider: ScmProvider;
|
|
43
|
+
/** `owner/name` — used for logs and error messages. */
|
|
44
|
+
repo: string;
|
|
45
|
+
prNumber: number;
|
|
46
|
+
/** HTTPS remote to fetch from. */
|
|
47
|
+
remoteUrl: string;
|
|
48
|
+
/** Username paired with the bearer token for git-over-HTTPS basic auth. */
|
|
49
|
+
credentialUsername: string;
|
|
50
|
+
/**
|
|
51
|
+
* Server-advertised PR head ref (e.g. GitHub `refs/pull/<n>/head`,
|
|
52
|
+
* GitLab `refs/merge-requests/<n>/head`) — the fallback when the pinned
|
|
53
|
+
* SHA cannot be fetched directly.
|
|
54
|
+
*/
|
|
55
|
+
prHeadRef: string;
|
|
35
56
|
};
|
|
36
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Resolve a PR URL to its clone target, or `undefined` when the SCM has no
|
|
59
|
+
* shallow-clone support (callers then review on their fallback checkout —
|
|
60
|
+
* e.g. Origin PRs, where the host checkout already is the reviewed repo).
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveScmCloneTarget(prUrl: string): ScmCloneTarget | undefined;
|
|
63
|
+
/** Repo-scoped bearer for git-over-HTTPS. */
|
|
37
64
|
export type ShallowCloneAuth = {
|
|
38
65
|
token: string;
|
|
39
66
|
};
|
|
40
67
|
/**
|
|
41
|
-
* Default clone credential: the serve host's Cursor-account
|
|
68
|
+
* Default GitHub clone credential: the serve host's Cursor-account lease.
|
|
42
69
|
* `CursorGithubCredentialProvider` mints it repo-scoped from the backend and
|
|
43
70
|
* keeps `GH_TOKEN` refreshed for child processes; `GITHUB_TOKEN` covers
|
|
44
71
|
* local/CI runs that export the conventional variable instead.
|
|
45
72
|
*/
|
|
46
73
|
export declare function serveHostGithubAuth(env?: NodeJS.ProcessEnv): ShallowCloneAuth | undefined;
|
|
74
|
+
export type CommitRangeDiff = {
|
|
75
|
+
status: "ok";
|
|
76
|
+
diff: string;
|
|
77
|
+
} | {
|
|
78
|
+
status: "unavailable";
|
|
79
|
+
reason: string;
|
|
80
|
+
};
|
|
47
81
|
/**
|
|
48
|
-
*
|
|
82
|
+
* Diff two commits inside an existing shallow PR checkout, fetching either
|
|
83
|
+
* end on demand when the shallow history does not already contain it.
|
|
84
|
+
*
|
|
85
|
+
* Lives here because it needs the same authenticated git the clone uses —
|
|
86
|
+
* a `--depth=1` checkout usually lacks the older commit, so reading a range
|
|
87
|
+
* means another credentialed fetch. Never throws: every failure becomes an
|
|
88
|
+
* `unavailable` reason the caller can act on or surface.
|
|
89
|
+
*/
|
|
90
|
+
export declare function tryDiffCommitRange(args: {
|
|
91
|
+
/** Existing checkout to run git in (see {@link createShallowPrCheckout}). */
|
|
92
|
+
checkoutDir: string;
|
|
93
|
+
/** The checkout's clone target; supplies the remote's ref + auth conventions. */
|
|
94
|
+
target: ScmCloneTarget;
|
|
95
|
+
from: string;
|
|
96
|
+
to: string;
|
|
97
|
+
/** Restrict the diff to one path when set. */
|
|
98
|
+
file?: string | undefined;
|
|
99
|
+
/** Fetch credential; defaults to the target provider's credential source. */
|
|
100
|
+
auth?: ShallowCloneAuth | undefined;
|
|
101
|
+
}): Promise<CommitRangeDiff>;
|
|
102
|
+
export type ShallowPrCheckout = {
|
|
103
|
+
/** Directory containing the PR head working tree (detached at headSha). */
|
|
104
|
+
checkoutDir: string;
|
|
105
|
+
headSha: string;
|
|
106
|
+
/** True when the merge-base commit was also fetched (enables local diffs). */
|
|
107
|
+
baseFetched: boolean;
|
|
108
|
+
/** How the head commit was obtained. */
|
|
109
|
+
headSource: "sha_fetch" | "pr_ref_fetch";
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Create a fresh shallow checkout of a PR head at `checkoutDir`.
|
|
49
113
|
*
|
|
50
114
|
* Fetch order (both single depth-1 round-trips):
|
|
51
115
|
* 1. Fetch `headSha` (and `baseSha` when known) directly — GitHub advertises
|
|
52
116
|
* `allow-reachable-sha1-in-want`, and this pins the exact reviewed commit
|
|
53
117
|
* the way Bugbot's `shallow_fetch` does.
|
|
54
|
-
* 2. Fall back to
|
|
118
|
+
* 2. Fall back to the target's PR head ref, verifying it still resolves to
|
|
55
119
|
* `headSha` so the working tree cannot silently drift from the pinned
|
|
56
120
|
* patch in the review bundle.
|
|
57
121
|
*
|
|
@@ -59,35 +123,26 @@ export declare function serveHostGithubAuth(env?: NodeJS.ProcessEnv): ShallowClo
|
|
|
59
123
|
* patch text in their prompt); a missing head checkout throws.
|
|
60
124
|
*/
|
|
61
125
|
export declare function createShallowPrCheckout(args: {
|
|
62
|
-
|
|
63
|
-
repo: string;
|
|
64
|
-
prNumber?: number | undefined;
|
|
126
|
+
target: ScmCloneTarget;
|
|
65
127
|
headSha: string;
|
|
66
128
|
/** Merge-base SHA; fetched too so `git diff baseSha headSha` works locally. */
|
|
67
129
|
baseSha?: string | undefined;
|
|
68
130
|
checkoutDir: string;
|
|
69
|
-
/** Clone credential; required for
|
|
131
|
+
/** Clone credential; required for HTTPS remotes, unused for file fixtures. */
|
|
70
132
|
auth?: ShallowCloneAuth | undefined;
|
|
71
|
-
/** Test seam: clone from this URL instead of `https://github.com/<repo>.git`. */
|
|
72
|
-
remoteUrl?: string | undefined;
|
|
73
133
|
}): Promise<ShallowPrCheckout>;
|
|
74
|
-
/** True for `https://github.com/<owner>/<repo>/pull/<n>` URLs. */
|
|
75
|
-
export declare function isGithubPrUrl(prUrl: string): boolean;
|
|
76
134
|
export type TryShallowPrCheckoutOptions = {
|
|
77
|
-
/** PR URL;
|
|
135
|
+
/** PR URL; resolved to a clone target (unsupported SCMs skip). */
|
|
78
136
|
prUrl: string;
|
|
79
|
-
/** `owner/name`. */
|
|
80
|
-
repo: string;
|
|
81
|
-
prNumber?: number | undefined;
|
|
82
137
|
/** Pinned head SHA; skipped (undefined result) when unknown. */
|
|
83
138
|
headSha?: string | undefined;
|
|
84
139
|
/** Merge-base SHA; fetched too so `git diff baseSha headSha` works locally. */
|
|
85
140
|
baseSha?: string | undefined;
|
|
86
141
|
checkoutDir: string;
|
|
87
|
-
/** Clone credential; defaults to
|
|
142
|
+
/** Clone credential; defaults to the target provider's credential source. */
|
|
88
143
|
auth?: ShallowCloneAuth | undefined;
|
|
89
|
-
/** Test seam: clone
|
|
90
|
-
|
|
144
|
+
/** Test seam: clone this target instead of resolving `prUrl`. */
|
|
145
|
+
target?: ScmCloneTarget | undefined;
|
|
91
146
|
};
|
|
92
147
|
export type TryShallowPrCheckoutResult = {
|
|
93
148
|
/** Set when the shallow checkout succeeded. */
|
|
@@ -104,12 +159,12 @@ export type TryShallowPrCheckoutResult = {
|
|
|
104
159
|
* reviewed repo instead of the host's own checkout.
|
|
105
160
|
*
|
|
106
161
|
* Returns no checkout — leaving the caller on its fallback working
|
|
107
|
-
* directory — when the PR
|
|
108
|
-
* checkout is the reviewed repo), when no head SHA is
|
|
109
|
-
* credential is available, or when the clone fails;
|
|
110
|
-
* which. Failures are logged, never thrown: agents
|
|
111
|
-
* patch in their prompts, so a missing checkout
|
|
112
|
-
* than the run.
|
|
162
|
+
* directory — when the PR's SCM has no clone support (e.g. Origin PRs,
|
|
163
|
+
* where the host checkout is the reviewed repo), when no head SHA is
|
|
164
|
+
* pinned, when no clone credential is available, or when the clone fails;
|
|
165
|
+
* `fallbackReason` says which. Failures are logged, never thrown: agents
|
|
166
|
+
* still have the pinned patch in their prompts, so a missing checkout
|
|
167
|
+
* degrades quality rather than the run.
|
|
113
168
|
*/
|
|
114
169
|
export declare function tryCreateShallowPrCheckout(options: TryShallowPrCheckoutOptions): Promise<TryShallowPrCheckoutResult>;
|
|
115
170
|
//# sourceMappingURL=shallow-clone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shallow-clone.d.ts","sourceRoot":"","sources":["../../src/internal/shallow-clone.ts"],"names":[],"mappings":"AAMA
|
|
1
|
+
{"version":3,"file":"shallow-clone.d.ts","sourceRoot":"","sources":["../../src/internal/shallow-clone.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;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+12,38 @@ import { mkdirSync, rmSync } from "node:fs";
|
|
|
12
12
|
import { promisify } from "node:util";
|
|
13
13
|
const execFileAsync = promisify(execFile);
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Resolve a PR URL to its clone target, or `undefined` when the SCM has no
|
|
16
|
+
* shallow-clone support (callers then review on their fallback checkout —
|
|
17
|
+
* e.g. Origin PRs, where the host checkout already is the reviewed repo).
|
|
18
|
+
*/
|
|
19
|
+
export function resolveScmCloneTarget(prUrl) {
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(prUrl);
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
28
|
+
if (url.hostname === "github.com" &&
|
|
29
|
+
parts.length >= 4 &&
|
|
30
|
+
parts[2] === "pull" &&
|
|
31
|
+
Number.isInteger(Number(parts[3]))) {
|
|
32
|
+
const repo = `${parts[0]}/${parts[1]}`;
|
|
33
|
+
const prNumber = Number(parts[3]);
|
|
34
|
+
return {
|
|
35
|
+
provider: "github",
|
|
36
|
+
repo,
|
|
37
|
+
prNumber,
|
|
38
|
+
remoteUrl: `https://github.com/${repo}.git`,
|
|
39
|
+
credentialUsername: "x-access-token",
|
|
40
|
+
prHeadRef: `refs/pull/${prNumber}/head`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Default GitHub clone credential: the serve host's Cursor-account lease.
|
|
16
47
|
* `CursorGithubCredentialProvider` mints it repo-scoped from the backend and
|
|
17
48
|
* keeps `GH_TOKEN` refreshed for child processes; `GITHUB_TOKEN` covers
|
|
18
49
|
* local/CI runs that export the conventional variable instead.
|
|
@@ -22,6 +53,107 @@ export function serveHostGithubAuth(env = process.env) {
|
|
|
22
53
|
const token = ((_b = (_a = env.GH_TOKEN) !== null && _a !== void 0 ? _a : env.GITHUB_TOKEN) !== null && _b !== void 0 ? _b : "").trim();
|
|
23
54
|
return token === "" ? undefined : { token };
|
|
24
55
|
}
|
|
56
|
+
/** Pair the provider's git-over-HTTPS username with the bearer token. */
|
|
57
|
+
function cloneCredential(target, auth) {
|
|
58
|
+
return auth === undefined
|
|
59
|
+
? undefined
|
|
60
|
+
: { username: target.credentialUsername, token: auth.token };
|
|
61
|
+
}
|
|
62
|
+
/** Default clone credential source per provider. */
|
|
63
|
+
function defaultCloneAuth(target) {
|
|
64
|
+
switch (target.provider) {
|
|
65
|
+
case "github":
|
|
66
|
+
return serveHostGithubAuth();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Cap on diff text handed to a model; beyond this it is truncated. */
|
|
70
|
+
const DIFF_MAX_CHARS = 80000;
|
|
71
|
+
/**
|
|
72
|
+
* Diff two commits inside an existing shallow PR checkout, fetching either
|
|
73
|
+
* end on demand when the shallow history does not already contain it.
|
|
74
|
+
*
|
|
75
|
+
* Lives here because it needs the same authenticated git the clone uses —
|
|
76
|
+
* a `--depth=1` checkout usually lacks the older commit, so reading a range
|
|
77
|
+
* means another credentialed fetch. Never throws: every failure becomes an
|
|
78
|
+
* `unavailable` reason the caller can act on or surface.
|
|
79
|
+
*/
|
|
80
|
+
export function tryDiffCommitRange(args) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
var _a;
|
|
83
|
+
if (!isFullCommitSha(args.from) || !isFullCommitSha(args.to)) {
|
|
84
|
+
return {
|
|
85
|
+
status: "unavailable",
|
|
86
|
+
reason: "Could not compute a reliable diff because a commit SHA was not a full 40-character SHA.",
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const credential = cloneCredential(args.target, (_a = args.auth) !== null && _a !== void 0 ? _a : defaultCloneAuth(args.target));
|
|
90
|
+
for (const sha of [args.from, args.to]) {
|
|
91
|
+
if (!(yield ensureCommitFetched(args.checkoutDir, sha, args.target, credential))) {
|
|
92
|
+
return {
|
|
93
|
+
status: "unavailable",
|
|
94
|
+
reason: "Could not compute a reliable diff because a commit was unavailable in the checkout.",
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const diff = yield git(args.checkoutDir, [
|
|
100
|
+
"diff",
|
|
101
|
+
"--no-ext-diff",
|
|
102
|
+
"--unified=80",
|
|
103
|
+
`${args.from}..${args.to}`,
|
|
104
|
+
...(args.file === undefined ? [] : ["--", args.file]),
|
|
105
|
+
]);
|
|
106
|
+
return {
|
|
107
|
+
status: "ok",
|
|
108
|
+
diff: diff.length <= DIFF_MAX_CHARS
|
|
109
|
+
? diff
|
|
110
|
+
: `${diff.slice(0, DIFF_MAX_CHARS)}\n\n[diff truncated at ${DIFF_MAX_CHARS} characters]`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (_b) {
|
|
114
|
+
return {
|
|
115
|
+
status: "unavailable",
|
|
116
|
+
reason: "Could not compute a reliable diff because git diff failed.",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function isFullCommitSha(value) {
|
|
122
|
+
return /^[0-9a-f]{40}$/i.test(value);
|
|
123
|
+
}
|
|
124
|
+
/** Present already, or fetchable by SHA, or reachable from the PR head ref. */
|
|
125
|
+
function ensureCommitFetched(checkoutDir, sha, target, credential) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
if ((yield revParse(checkoutDir, sha)) !== undefined) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
const attempts = [
|
|
131
|
+
[...FETCH_ARGS, sha],
|
|
132
|
+
// Deeper history on the PR head ref: the older end of an inter-run range
|
|
133
|
+
// is usually an ancestor of the tip rather than the tip itself.
|
|
134
|
+
[
|
|
135
|
+
"fetch",
|
|
136
|
+
"--depth=200",
|
|
137
|
+
"--no-tags",
|
|
138
|
+
"--quiet",
|
|
139
|
+
"origin",
|
|
140
|
+
target.prHeadRef,
|
|
141
|
+
],
|
|
142
|
+
];
|
|
143
|
+
for (const attempt of attempts) {
|
|
144
|
+
try {
|
|
145
|
+
yield git(checkoutDir, attempt, credential);
|
|
146
|
+
if ((yield revParse(checkoutDir, sha)) !== undefined) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (_a) {
|
|
151
|
+
// Try the next strategy; the caller fails closed if none work.
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
25
157
|
function logShallowClone(message, fields = {}) {
|
|
26
158
|
const suffix = Object.entries(fields)
|
|
27
159
|
.filter(([, value]) => value !== undefined)
|
|
@@ -55,12 +187,12 @@ function gitError(args, error) {
|
|
|
55
187
|
return new Error(`git ${args.join(" ")} failed — ${detail}`);
|
|
56
188
|
}
|
|
57
189
|
/**
|
|
58
|
-
* The one credential helper git may use: serve the caller-provided
|
|
59
|
-
* from the child process env at request time. The shell reads
|
|
60
|
-
*
|
|
190
|
+
* The one credential helper git may use: serve the caller-provided
|
|
191
|
+
* credential from the child process env at request time. The shell reads
|
|
192
|
+
* the values when git asks, keeping the token out of argv.
|
|
61
193
|
*/
|
|
62
|
-
const
|
|
63
|
-
function git(cwd, args,
|
|
194
|
+
const CREDENTIAL_HELPER = '!f() { test "$1" = get && printf "username=$SHALLOW_CLONE_GIT_USERNAME\\npassword=$SHALLOW_CLONE_GIT_TOKEN\\n"; }; f';
|
|
195
|
+
function git(cwd, args, credential) {
|
|
64
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
197
|
// Async on purpose: fetches/checkouts of large repos take minutes, and the
|
|
66
198
|
// serve host runs the clone in-process. A synchronous git call blocks the
|
|
@@ -68,9 +200,9 @@ function git(cwd, args, auth) {
|
|
|
68
200
|
// long enough for the platform's probe budget to replace the engine.
|
|
69
201
|
try {
|
|
70
202
|
const { stdout } = yield execFileAsync("git", [
|
|
71
|
-
...(
|
|
203
|
+
...(credential === undefined
|
|
72
204
|
? []
|
|
73
|
-
: ["-c", `credential.helper=${
|
|
205
|
+
: ["-c", `credential.helper=${CREDENTIAL_HELPER}`]),
|
|
74
206
|
...args,
|
|
75
207
|
], {
|
|
76
208
|
cwd,
|
|
@@ -82,9 +214,12 @@ function git(cwd, args, auth) {
|
|
|
82
214
|
// .com/.insteadOf` entries scoped to a *different* repo, as cloud
|
|
83
215
|
// VMs bake in) cannot hijack auth away from the explicit token,
|
|
84
216
|
// and no ambient credential helpers run against PR-author input.
|
|
85
|
-
GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_SYSTEM: "/dev/null", GIT_TERMINAL_PROMPT: "0" }), (
|
|
217
|
+
GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_SYSTEM: "/dev/null", GIT_TERMINAL_PROMPT: "0" }), (credential === undefined
|
|
86
218
|
? {}
|
|
87
|
-
: {
|
|
219
|
+
: {
|
|
220
|
+
SHALLOW_CLONE_GIT_USERNAME: credential.username,
|
|
221
|
+
SHALLOW_CLONE_GIT_TOKEN: credential.token,
|
|
222
|
+
})),
|
|
88
223
|
});
|
|
89
224
|
return stdout;
|
|
90
225
|
}
|
|
@@ -105,14 +240,16 @@ function revParse(cwd, rev) {
|
|
|
105
240
|
});
|
|
106
241
|
}
|
|
107
242
|
const FETCH_ARGS = ["fetch", "--depth=1", "--no-tags", "--quiet", "origin"];
|
|
243
|
+
/** Local tracking ref the PR head ref is fetched into. */
|
|
244
|
+
const LOCAL_PR_HEAD_REF = "refs/remotes/origin/shallow-clone-pr-head";
|
|
108
245
|
/**
|
|
109
|
-
* Create a fresh shallow checkout of a
|
|
246
|
+
* Create a fresh shallow checkout of a PR head at `checkoutDir`.
|
|
110
247
|
*
|
|
111
248
|
* Fetch order (both single depth-1 round-trips):
|
|
112
249
|
* 1. Fetch `headSha` (and `baseSha` when known) directly — GitHub advertises
|
|
113
250
|
* `allow-reachable-sha1-in-want`, and this pins the exact reviewed commit
|
|
114
251
|
* the way Bugbot's `shallow_fetch` does.
|
|
115
|
-
* 2. Fall back to
|
|
252
|
+
* 2. Fall back to the target's PR head ref, verifying it still resolves to
|
|
116
253
|
* `headSha` so the working tree cannot silently drift from the pinned
|
|
117
254
|
* patch in the review bundle.
|
|
118
255
|
*
|
|
@@ -121,23 +258,19 @@ const FETCH_ARGS = ["fetch", "--depth=1", "--no-tags", "--quiet", "origin"];
|
|
|
121
258
|
*/
|
|
122
259
|
export function createShallowPrCheckout(args) {
|
|
123
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
|
|
125
|
-
const { repo, prNumber
|
|
261
|
+
const { target, headSha, baseSha, checkoutDir, auth } = args;
|
|
262
|
+
const { repo, prNumber } = target;
|
|
263
|
+
const credential = cloneCredential(target, auth);
|
|
126
264
|
const startedAt = Date.now();
|
|
127
265
|
logShallowClone("cloning PR head", { repo, prNumber, headSha, baseSha });
|
|
128
266
|
rmSync(checkoutDir, { recursive: true, force: true });
|
|
129
267
|
mkdirSync(checkoutDir, { recursive: true });
|
|
130
268
|
yield git(checkoutDir, ["init", "--quiet"]);
|
|
131
|
-
yield git(checkoutDir, [
|
|
132
|
-
"remote",
|
|
133
|
-
"add",
|
|
134
|
-
"origin",
|
|
135
|
-
(_a = args.remoteUrl) !== null && _a !== void 0 ? _a : `https://github.com/${repo}.git`,
|
|
136
|
-
]);
|
|
269
|
+
yield git(checkoutDir, ["remote", "add", "origin", target.remoteUrl]);
|
|
137
270
|
const shaFetch = () => __awaiter(this, void 0, void 0, function* () {
|
|
138
271
|
const extraBase = baseSha === undefined || baseSha === headSha ? [] : [baseSha];
|
|
139
272
|
try {
|
|
140
|
-
yield git(checkoutDir, [...FETCH_ARGS, headSha, ...extraBase],
|
|
273
|
+
yield git(checkoutDir, [...FETCH_ARGS, headSha, ...extraBase], credential);
|
|
141
274
|
}
|
|
142
275
|
catch (error) {
|
|
143
276
|
if (extraBase.length === 0) {
|
|
@@ -151,29 +284,24 @@ export function createShallowPrCheckout(args) {
|
|
|
151
284
|
baseSha,
|
|
152
285
|
error: errorSummary(error),
|
|
153
286
|
});
|
|
154
|
-
yield git(checkoutDir, [...FETCH_ARGS, headSha],
|
|
287
|
+
yield git(checkoutDir, [...FETCH_ARGS, headSha], credential);
|
|
155
288
|
}
|
|
156
289
|
});
|
|
157
290
|
let headSource;
|
|
158
|
-
let shaFetchError;
|
|
159
291
|
try {
|
|
160
292
|
yield shaFetch();
|
|
161
293
|
headSource = "sha_fetch";
|
|
162
294
|
}
|
|
163
295
|
catch (error) {
|
|
164
|
-
shaFetchError = errorSummary(error);
|
|
165
|
-
if (prNumber === undefined) {
|
|
166
|
-
throw new Error(`Shallow SHA fetch failed for ${repo}@${headSha} and no PR number is available for a ref fallback: ${shaFetchError}`);
|
|
167
|
-
}
|
|
296
|
+
const shaFetchError = errorSummary(error);
|
|
168
297
|
logShallowClone("sha fetch failed; falling back to PR head ref", {
|
|
169
298
|
repo,
|
|
170
299
|
prNumber,
|
|
171
300
|
headSha,
|
|
172
301
|
error: shaFetchError,
|
|
173
302
|
});
|
|
174
|
-
|
|
175
|
-
yield
|
|
176
|
-
const fetchedSha = yield revParse(checkoutDir, `refs/remotes/origin/pr/${prNumber}/head`);
|
|
303
|
+
yield git(checkoutDir, [...FETCH_ARGS, `+${target.prHeadRef}:${LOCAL_PR_HEAD_REF}`], credential);
|
|
304
|
+
const fetchedSha = yield revParse(checkoutDir, LOCAL_PR_HEAD_REF);
|
|
177
305
|
if (fetchedSha !== headSha) {
|
|
178
306
|
throw new Error(`Shallow PR ref fetch for ${repo}#${prNumber} resolved to ${fetchedSha !== null && fetchedSha !== void 0 ? fetchedSha : "nothing"}, expected pinned head ${headSha} (sha fetch error: ${shaFetchError})`);
|
|
179
307
|
}
|
|
@@ -194,7 +322,7 @@ export function createShallowPrCheckout(args) {
|
|
|
194
322
|
// Best-effort: local diffs are nice-to-have, the pinned patch in the
|
|
195
323
|
// prompt is the authoritative delta either way.
|
|
196
324
|
try {
|
|
197
|
-
yield git(checkoutDir, [...FETCH_ARGS, baseSha],
|
|
325
|
+
yield git(checkoutDir, [...FETCH_ARGS, baseSha], credential);
|
|
198
326
|
baseFetched = (yield revParse(checkoutDir, baseSha)) !== undefined;
|
|
199
327
|
}
|
|
200
328
|
catch (error) {
|
|
@@ -218,71 +346,63 @@ export function createShallowPrCheckout(args) {
|
|
|
218
346
|
return { checkoutDir, headSha, baseFetched, headSource };
|
|
219
347
|
});
|
|
220
348
|
}
|
|
221
|
-
/** True for `https://github.com/<owner>/<repo>/pull/<n>` URLs. */
|
|
222
|
-
export function isGithubPrUrl(prUrl) {
|
|
223
|
-
try {
|
|
224
|
-
const url = new URL(prUrl);
|
|
225
|
-
const parts = url.pathname.split("/").filter(Boolean);
|
|
226
|
-
return (url.hostname === "github.com" &&
|
|
227
|
-
parts.length >= 4 &&
|
|
228
|
-
parts[2] === "pull" &&
|
|
229
|
-
Number.isInteger(Number(parts[3])));
|
|
230
|
-
}
|
|
231
|
-
catch (_a) {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
349
|
/**
|
|
236
350
|
* Best-effort shallow PR checkout for hosts whose SDK agents should read the
|
|
237
351
|
* reviewed repo instead of the host's own checkout.
|
|
238
352
|
*
|
|
239
353
|
* Returns no checkout — leaving the caller on its fallback working
|
|
240
|
-
* directory — when the PR
|
|
241
|
-
* checkout is the reviewed repo), when no head SHA is
|
|
242
|
-
* credential is available, or when the clone fails;
|
|
243
|
-
* which. Failures are logged, never thrown: agents
|
|
244
|
-
* patch in their prompts, so a missing checkout
|
|
245
|
-
* than the run.
|
|
354
|
+
* directory — when the PR's SCM has no clone support (e.g. Origin PRs,
|
|
355
|
+
* where the host checkout is the reviewed repo), when no head SHA is
|
|
356
|
+
* pinned, when no clone credential is available, or when the clone fails;
|
|
357
|
+
* `fallbackReason` says which. Failures are logged, never thrown: agents
|
|
358
|
+
* still have the pinned patch in their prompts, so a missing checkout
|
|
359
|
+
* degrades quality rather than the run.
|
|
246
360
|
*/
|
|
247
361
|
export function tryCreateShallowPrCheckout(options) {
|
|
248
362
|
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
var _a;
|
|
250
|
-
const { prUrl,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
363
|
+
var _a, _b;
|
|
364
|
+
const { prUrl, headSha, baseSha, checkoutDir } = options;
|
|
365
|
+
const target = (_a = options.target) !== null && _a !== void 0 ? _a : resolveScmCloneTarget(prUrl);
|
|
366
|
+
if (target === undefined) {
|
|
367
|
+
logShallowClone("skipped: unsupported SCM for shallow clone", { prUrl });
|
|
368
|
+
return { fallbackReason: "skipped: unsupported SCM for shallow clone" };
|
|
254
369
|
}
|
|
255
370
|
if (headSha === undefined) {
|
|
256
|
-
logShallowClone("skipped: no pinned head SHA", {
|
|
371
|
+
logShallowClone("skipped: no pinned head SHA", {
|
|
372
|
+
repo: target.repo,
|
|
373
|
+
prUrl,
|
|
374
|
+
});
|
|
257
375
|
return { fallbackReason: "skipped: no pinned head SHA" };
|
|
258
376
|
}
|
|
259
|
-
const auth = (
|
|
260
|
-
if (
|
|
261
|
-
// Fail fast instead of letting an unauthenticated fetch 404/hang:
|
|
262
|
-
//
|
|
263
|
-
logShallowClone("skipped: no
|
|
377
|
+
const auth = (_b = options.auth) !== null && _b !== void 0 ? _b : defaultCloneAuth(target);
|
|
378
|
+
if (auth === undefined && target.remoteUrl.startsWith("https://")) {
|
|
379
|
+
// Fail fast instead of letting an unauthenticated fetch 404/hang: HTTPS
|
|
380
|
+
// clones need the provider's credential (or an explicit token).
|
|
381
|
+
logShallowClone("skipped: no clone credential", {
|
|
382
|
+
repo: target.repo,
|
|
383
|
+
provider: target.provider,
|
|
384
|
+
prUrl,
|
|
385
|
+
});
|
|
264
386
|
return {
|
|
265
|
-
fallbackReason:
|
|
387
|
+
fallbackReason: `skipped: no ${target.provider} clone credential (serve host token lease not installed)`,
|
|
266
388
|
};
|
|
267
389
|
}
|
|
268
390
|
try {
|
|
269
391
|
return {
|
|
270
392
|
checkout: yield createShallowPrCheckout({
|
|
271
|
-
|
|
272
|
-
prNumber,
|
|
393
|
+
target,
|
|
273
394
|
headSha,
|
|
274
395
|
baseSha,
|
|
275
396
|
checkoutDir,
|
|
276
397
|
auth,
|
|
277
|
-
remoteUrl,
|
|
278
398
|
}),
|
|
279
399
|
};
|
|
280
400
|
}
|
|
281
401
|
catch (error) {
|
|
282
402
|
const reason = errorSummary(error);
|
|
283
403
|
logShallowClone("failed; caller falls back to host checkout", {
|
|
284
|
-
repo,
|
|
285
|
-
prNumber,
|
|
404
|
+
repo: target.repo,
|
|
405
|
+
prNumber: target.prNumber,
|
|
286
406
|
headSha,
|
|
287
407
|
error: reason,
|
|
288
408
|
});
|
|
@@ -17,6 +17,24 @@ export declare function makePalette(enabled: boolean): TerminalPalette;
|
|
|
17
17
|
export declare function stdoutPalette(): TerminalPalette;
|
|
18
18
|
/** Palette for human-facing stderr (login progress, warnings). */
|
|
19
19
|
export declare function stderrPalette(): TerminalPalette;
|
|
20
|
+
/** Visible column count, ignoring CSI color/style and OSC 8 hyperlinks. */
|
|
21
|
+
export declare function visibleWidth(text: string): number;
|
|
22
|
+
/** True when `text` already carries CSI styling or OSC 8 (do not wrap again). */
|
|
23
|
+
export declare function hasAnsiStyling(text: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Clickable terminal hyperlink (OSC 8). The URI is the click target; `label`
|
|
26
|
+
* is what the user sees. `visibleWidth` ignores the OSC wrapper.
|
|
27
|
+
*/
|
|
28
|
+
export declare function terminalHyperlink(url: string, label: string, enabled?: boolean): string;
|
|
29
|
+
/**
|
|
30
|
+
* Unicode box around `lines`. `color` wraps the whole box (borders + body)
|
|
31
|
+
* so a warning panel can be yellow without per-line prefixes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatTerminalBox(lines: readonly string[], options?: {
|
|
34
|
+
color?: (s: string) => string;
|
|
35
|
+
minWidth?: number;
|
|
36
|
+
padding?: number;
|
|
37
|
+
}): string;
|
|
20
38
|
/** Wipe the terminal before a `dev` Enter-to-restart cycle. */
|
|
21
39
|
export declare function clearTerminal(stream?: NodeJS.WriteStream): void;
|
|
22
40
|
//# sourceMappingURL=terminal-style.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-style.d.ts","sourceRoot":"","sources":["../../src/internal/terminal-style.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5B,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7B,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/B;
|
|
1
|
+
{"version":3,"file":"terminal-style.d.ts","sourceRoot":"","sources":["../../src/internal/terminal-style.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5B,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7B,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM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