orquesta-agent 0.2.292 → 0.2.294
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/dist/deploy-key.d.ts +27 -0
- package/dist/deploy-key.d.ts.map +1 -0
- package/dist/deploy-key.js +96 -0
- package/dist/deploy-key.js.map +1 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +8 -0
- package/dist/executor.js.map +1 -1
- package/dist/git-app-auth.d.ts +36 -0
- package/dist/git-app-auth.d.ts.map +1 -0
- package/dist/git-app-auth.js +166 -0
- package/dist/git-app-auth.js.map +1 -0
- package/dist/index.js +83 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Refresh when fewer than this many ms of token life remain (and before each helper answer). */
|
|
2
|
+
export declare const TOKEN_REFRESH_MARGIN_MS: number;
|
|
3
|
+
/** `x-access-token` is GitHub's documented username for an installation token over HTTPS. */
|
|
4
|
+
export declare const GIT_APP_USERNAME = "x-access-token";
|
|
5
|
+
export interface GitAppPaths {
|
|
6
|
+
dir: string;
|
|
7
|
+
cache: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function gitAppPaths(home?: string): GitAppPaths;
|
|
10
|
+
/** The runner bootstrap asked for App mode (gitAuth.mode === 'github_app')? */
|
|
11
|
+
export declare function bootstrapWantsGithubApp(bootstrapFile?: string | undefined): boolean;
|
|
12
|
+
/** `https://github.com/o/r(.git)` (or an ssh form) → `https://github.com/o/r.git`; null for anything not on github.com. */
|
|
13
|
+
export declare function httpsUrlFor(repoUrl: string): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* A valid installation token, from cache if it still has >10 min of life, else freshly minted
|
|
16
|
+
* and cached. Env: ORQUESTA_API_URL + ORQUESTA_TOKEN (the agent's own token).
|
|
17
|
+
*/
|
|
18
|
+
export declare function getInstallationToken(opts?: {
|
|
19
|
+
apiUrl?: string;
|
|
20
|
+
orquestaToken?: string;
|
|
21
|
+
paths?: GitAppPaths;
|
|
22
|
+
now?: number;
|
|
23
|
+
}): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* The `git credential` protocol on stdin/stdout. Git calls `get` before a request and
|
|
26
|
+
* `store`/`erase` after; we only answer `get`, minting/reusing a token. Anything else is a no-op.
|
|
27
|
+
* Reads the key=value block from stdin, writes username/password to stdout.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runGitCredential(verb: string, stdin: string, out?: (s: string) => void): Promise<void>;
|
|
30
|
+
/** The `-c credential.helper=...` git runs: re-exec THIS binary as `git-credential`. */
|
|
31
|
+
export declare function credentialHelperArg(selfPath?: string): string;
|
|
32
|
+
/** Clone over HTTPS using the App credential helper, and pin the helper in the clone. */
|
|
33
|
+
export declare function cloneWithGithubApp(repoUrl: string, targetDir: string, timeoutMs: number, selfPath?: string): void;
|
|
34
|
+
/** Point an existing clone at HTTPS + our credential helper (agent restarted next to an old clone). */
|
|
35
|
+
export declare function pinGithubApp(repoDir: string, repoUrl: string, selfPath?: string): void;
|
|
36
|
+
//# sourceMappingURL=git-app-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-app-auth.d.ts","sourceRoot":"","sources":["../src/git-app-auth.ts"],"names":[],"mappings":"AA2BA,iGAAiG;AACjG,eAAO,MAAM,uBAAuB,QAAc,CAAA;AAClD,6FAA6F;AAC7F,eAAO,MAAM,gBAAgB,mBAAmB,CAAA;AAEhD,MAAM,WAAW,WAAW;IAAG,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAE3D,wBAAgB,WAAW,CAAC,IAAI,SAAe,GAAG,WAAW,CAG5D;AAID,+EAA+E;AAC/E,wBAAgB,uBAAuB,CAAC,aAAa,qBAAsC,GAAG,OAAO,CAMpG;AAED,2HAA2H;AAC3H,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG1D;AAqCD;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,GAAE;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;CACR,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBvB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAmC,GAAG,OAAO,CAAC,IAAI,CAAC,CAY1I;AAED,wFAAwF;AACxF,wBAAgB,mBAAmB,CAAC,QAAQ,SAAkB,GAAG,MAAM,CAKtE;AAWD,yFAAyF;AACzF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAOjH;AAED,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAStF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub App mode for the on-demand microVM runner (docs/runner-github-app-plan.md).
|
|
3
|
+
*
|
|
4
|
+
* The alternative to the SSH deploy key (deploy-key.ts): when the project has a
|
|
5
|
+
* verified GitHub App installation, the runner bootstrap carries
|
|
6
|
+
* `gitAuth: { mode: 'github_app' }` instead of a `deployKey` (lib/runner/agentcore.ts).
|
|
7
|
+
* The microVM then clones over HTTPS, authenticating with a SHORT-LIVED (≤1h)
|
|
8
|
+
* installation token scoped to this one repository.
|
|
9
|
+
*
|
|
10
|
+
* The token is NOT in the bootstrap: the agent mints it on demand from
|
|
11
|
+
* `POST /api/agent/runner-git-token` (authenticated with its own ORQUESTA_TOKEN),
|
|
12
|
+
* which the server only answers for the project's runner token. Git obtains it
|
|
13
|
+
* through a credential helper that re-execs this binary as `git-credential`, so
|
|
14
|
+
* the token never sits in the clone URL nor in `.git/config`.
|
|
15
|
+
*
|
|
16
|
+
* The token is cached at ~/.orquesta/git-app/token.json (0600 in a 0700 dir) and
|
|
17
|
+
* refreshed when under 10 minutes of life remain, so a long clone or a burst of
|
|
18
|
+
* pushes does not race its expiry.
|
|
19
|
+
*
|
|
20
|
+
* A failed clone is remembered via setRepoCloneFailure (deploy-key.ts), so every
|
|
21
|
+
* prompt fails with `REPO_CLONE_FAILED: …` instead of running on an empty dir.
|
|
22
|
+
*/
|
|
23
|
+
import { execFileSync } from 'child_process';
|
|
24
|
+
import * as fs from 'fs';
|
|
25
|
+
import * as os from 'os';
|
|
26
|
+
import * as path from 'path';
|
|
27
|
+
/** Refresh when fewer than this many ms of token life remain (and before each helper answer). */
|
|
28
|
+
export const TOKEN_REFRESH_MARGIN_MS = 10 * 60_000;
|
|
29
|
+
/** `x-access-token` is GitHub's documented username for an installation token over HTTPS. */
|
|
30
|
+
export const GIT_APP_USERNAME = 'x-access-token';
|
|
31
|
+
export function gitAppPaths(home = os.homedir()) {
|
|
32
|
+
const dir = process.env.ORQUESTA_GIT_APP_DIR || path.join(home, '.orquesta', 'git-app');
|
|
33
|
+
return { dir, cache: path.join(dir, 'token.json') };
|
|
34
|
+
}
|
|
35
|
+
/** The runner bootstrap asked for App mode (gitAuth.mode === 'github_app')? */
|
|
36
|
+
export function bootstrapWantsGithubApp(bootstrapFile = process.env.ORQUESTA_BOOTSTRAP_FILE) {
|
|
37
|
+
if (!bootstrapFile)
|
|
38
|
+
return false;
|
|
39
|
+
try {
|
|
40
|
+
const b = JSON.parse(fs.readFileSync(bootstrapFile, 'utf8'));
|
|
41
|
+
return b?.gitAuth?.mode === 'github_app';
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** `https://github.com/o/r(.git)` (or an ssh form) → `https://github.com/o/r.git`; null for anything not on github.com. */
|
|
48
|
+
export function httpsUrlFor(repoUrl) {
|
|
49
|
+
const m = repoUrl.trim().match(/^(?:https:\/\/(?:[^@/]+@)?github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([A-Za-z0-9._-]+)\/([A-Za-z0-9._-]+?)(?:\.git)?\/?$/);
|
|
50
|
+
return m ? `https://github.com/${m[1]}/${m[2]}.git` : null;
|
|
51
|
+
}
|
|
52
|
+
function readCache(paths) {
|
|
53
|
+
try {
|
|
54
|
+
const c = JSON.parse(fs.readFileSync(paths.cache, 'utf8'));
|
|
55
|
+
if (typeof c?.token === 'string' && typeof c?.expiresAt === 'string')
|
|
56
|
+
return c;
|
|
57
|
+
}
|
|
58
|
+
catch { /* no cache yet, or unreadable */ }
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function writeCache(paths, tok) {
|
|
62
|
+
fs.mkdirSync(paths.dir, { recursive: true, mode: 0o700 });
|
|
63
|
+
fs.chmodSync(paths.dir, 0o700);
|
|
64
|
+
fs.writeFileSync(paths.cache, JSON.stringify(tok), { mode: 0o600 });
|
|
65
|
+
fs.chmodSync(paths.cache, 0o600);
|
|
66
|
+
}
|
|
67
|
+
function fresh(tok, now) {
|
|
68
|
+
return !!tok && new Date(tok.expiresAt).getTime() - now > TOKEN_REFRESH_MARGIN_MS;
|
|
69
|
+
}
|
|
70
|
+
/** Ask the server to mint a 1h installation token for this project's repo. */
|
|
71
|
+
async function mintToken(apiUrl, orquestaToken) {
|
|
72
|
+
const res = await fetch(`${apiUrl.replace(/\/$/, '')}/api/agent/runner-git-token`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: { 'Content-Type': 'application/json' },
|
|
75
|
+
body: JSON.stringify({ token: orquestaToken }),
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok) {
|
|
78
|
+
// Keep only the HTTP status; never echo a response body that might carry something sensitive.
|
|
79
|
+
throw new Error(`runner-git-token HTTP ${res.status}`);
|
|
80
|
+
}
|
|
81
|
+
const j = await res.json();
|
|
82
|
+
if (typeof j.token !== 'string' || typeof j.expires_at !== 'string')
|
|
83
|
+
throw new Error('runner-git-token returned an incomplete token');
|
|
84
|
+
return { token: j.token, expiresAt: j.expires_at };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A valid installation token, from cache if it still has >10 min of life, else freshly minted
|
|
88
|
+
* and cached. Env: ORQUESTA_API_URL + ORQUESTA_TOKEN (the agent's own token).
|
|
89
|
+
*/
|
|
90
|
+
export async function getInstallationToken(opts = {}) {
|
|
91
|
+
const paths = opts.paths ?? gitAppPaths();
|
|
92
|
+
const now = opts.now ?? Date.now();
|
|
93
|
+
const cached = readCache(paths);
|
|
94
|
+
if (fresh(cached, now))
|
|
95
|
+
return cached.token;
|
|
96
|
+
const apiUrl = opts.apiUrl ?? process.env.ORQUESTA_API_URL ?? 'https://getorquesta.com';
|
|
97
|
+
const orquestaToken = opts.orquestaToken ?? process.env.ORQUESTA_TOKEN;
|
|
98
|
+
if (!orquestaToken) {
|
|
99
|
+
// Fall back to a still-usable cached token rather than failing a live clone.
|
|
100
|
+
if (cached && new Date(cached.expiresAt).getTime() > now)
|
|
101
|
+
return cached.token;
|
|
102
|
+
throw new Error('ORQUESTA_TOKEN is not set');
|
|
103
|
+
}
|
|
104
|
+
const tok = await mintToken(apiUrl, orquestaToken);
|
|
105
|
+
writeCache(paths, tok);
|
|
106
|
+
return tok.token;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The `git credential` protocol on stdin/stdout. Git calls `get` before a request and
|
|
110
|
+
* `store`/`erase` after; we only answer `get`, minting/reusing a token. Anything else is a no-op.
|
|
111
|
+
* Reads the key=value block from stdin, writes username/password to stdout.
|
|
112
|
+
*/
|
|
113
|
+
export async function runGitCredential(verb, stdin, out = s => process.stdout.write(s)) {
|
|
114
|
+
if (verb !== 'get')
|
|
115
|
+
return; // store/erase: nothing to persist here; the cache file is ours
|
|
116
|
+
const req = {};
|
|
117
|
+
for (const line of stdin.split('\n')) {
|
|
118
|
+
const i = line.indexOf('=');
|
|
119
|
+
if (i > 0)
|
|
120
|
+
req[line.slice(0, i)] = line.slice(i + 1);
|
|
121
|
+
}
|
|
122
|
+
// Only vouch for github.com over https; let git's default helper handle anything else.
|
|
123
|
+
if (req.protocol && req.protocol !== 'https')
|
|
124
|
+
return;
|
|
125
|
+
if (req.host && req.host !== 'github.com')
|
|
126
|
+
return;
|
|
127
|
+
const token = await getInstallationToken();
|
|
128
|
+
out(`username=${GIT_APP_USERNAME}\npassword=${token}\n`);
|
|
129
|
+
}
|
|
130
|
+
/** The `-c credential.helper=...` git runs: re-exec THIS binary as `git-credential`. */
|
|
131
|
+
export function credentialHelperArg(selfPath = process.argv[1]) {
|
|
132
|
+
// git runs the helper via `sh -c "<helper> <verb>"`; single-quote our path.
|
|
133
|
+
const node = process.execPath;
|
|
134
|
+
const q = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
135
|
+
return `credential.helper=!${q(node)} ${q(selfPath)} git-credential`;
|
|
136
|
+
}
|
|
137
|
+
function gitEnv() {
|
|
138
|
+
return { ...process.env, GIT_TERMINAL_PROMPT: '0' };
|
|
139
|
+
}
|
|
140
|
+
/** Common config: our credential helper, and no other helper chiming in first. */
|
|
141
|
+
function helperConfigArgs(selfPath) {
|
|
142
|
+
return ['-c', 'credential.helper=', '-c', credentialHelperArg(selfPath)];
|
|
143
|
+
}
|
|
144
|
+
/** Clone over HTTPS using the App credential helper, and pin the helper in the clone. */
|
|
145
|
+
export function cloneWithGithubApp(repoUrl, targetDir, timeoutMs, selfPath) {
|
|
146
|
+
const url = httpsUrlFor(repoUrl);
|
|
147
|
+
if (!url)
|
|
148
|
+
throw new Error(`not a github.com repository: ${repoUrl}`);
|
|
149
|
+
execFileSync('git', [...helperConfigArgs(selfPath), 'clone', url, targetDir], {
|
|
150
|
+
stdio: ['ignore', 'ignore', 'pipe'], timeout: timeoutMs, env: gitEnv(),
|
|
151
|
+
});
|
|
152
|
+
pinGithubApp(targetDir, repoUrl, selfPath);
|
|
153
|
+
}
|
|
154
|
+
/** Point an existing clone at HTTPS + our credential helper (agent restarted next to an old clone). */
|
|
155
|
+
export function pinGithubApp(repoDir, repoUrl, selfPath) {
|
|
156
|
+
const url = httpsUrlFor(repoUrl);
|
|
157
|
+
if (!url)
|
|
158
|
+
return;
|
|
159
|
+
execFileSync('git', ['remote', 'set-url', 'origin', url], { cwd: repoDir, stdio: 'ignore' });
|
|
160
|
+
// Scope the helper to github.com so it never answers for another host.
|
|
161
|
+
execFileSync('git', ['config', '--local', 'credential.https://github.com.helper', ''], { cwd: repoDir, stdio: 'ignore' });
|
|
162
|
+
const node = process.execPath;
|
|
163
|
+
const self = selfPath ?? process.argv[1];
|
|
164
|
+
execFileSync('git', ['config', '--local', '--add', 'credential.https://github.com.helper', `!'${node.replace(/'/g, `'\\''`)}' '${self.replace(/'/g, `'\\''`)}' git-credential`], { cwd: repoDir, stdio: 'ignore' });
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=git-app-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-app-auth.js","sourceRoot":"","sources":["../src/git-app-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,iGAAiG;AACjG,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,MAAM,CAAA;AAClD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAA;AAIhD,MAAM,UAAU,WAAW,CAAC,IAAI,GAAG,E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F,uEAAuE;IACvE,YAAY,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,sCAAsC,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;IACzH,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAA;IAC7B,MAAM,IAAI,GAAG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACxC,YAAY,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,sCAAsC,EAAE,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;AACrN,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,9 @@ import { startDaemon, isDaemonChild, acquireSingleInstanceLock } from './daemon.
|
|
|
35
35
|
import { getCliTokenHash } from './cli-config.js';
|
|
36
36
|
import { validateToken, markDisconnected, subscribeToChannel, setAgentToken, reportAgentError, reportAgentProblem, persistAgentSettings, startHeartbeat, stopHeartbeat, setOnTokenInvalidated, setPermissionModeUpdater, setCliPreferenceUpdater, setCliEndpointUpdater, setBrowserEnabledUpdater, setRemoteDesktopUpdater, setSandboxUpdater, setSandboxAccessUpdater, setCurrentProjectId, getCurrentProjectId, fetchCredentials, fetchSkills, syncSkillsToDirectory, uploadClaudeMd, setClaudeAuthChecker, setOrquestaCliChecker, setKimiCliChecker, setCursorCliChecker, setKiroCliChecker, setActiveCliResolver, setEffectiveConfigResolver, setAgentVersion, setAgentName, updatePromptStatus, setRunnerSnapshotHandler, setPreviewTunnelsHandler, reportPreviewTunnel, reportRunnerSnapshot, } from './supabase.js';
|
|
37
37
|
import { applyBootstrapFromEnv, createRunnerSnapshot } from './runner-snapshot.js';
|
|
38
|
+
import { prepareDeployKey, cloneWithDeployKey, pinDeployKey, sshUrlFor, setRepoCloneFailure } from './deploy-key.js';
|
|
39
|
+
import { bootstrapWantsGithubApp, cloneWithGithubApp, pinGithubApp, httpsUrlFor } from './git-app-auth.js';
|
|
40
|
+
import { redactSecrets } from './redact.js';
|
|
38
41
|
import { createSocketIOConnection, createExecutionChannel, setupSocketIOListeners, } from './socketio-transport.js';
|
|
39
42
|
import { execSync, spawn } from 'child_process';
|
|
40
43
|
import * as remoteDesktop from './remote-desktop.js';
|
|
@@ -534,6 +537,22 @@ async function connect(options) {
|
|
|
534
537
|
if (!credentials['BATUTA_API_KEY']) {
|
|
535
538
|
credentials['BATUTA_API_KEY'] = token;
|
|
536
539
|
}
|
|
540
|
+
// A runner bootstrap with a deploy key means the repo is reached over SSH, so
|
|
541
|
+
// the GitHub OAuth token is never put in the clone URL or the agent's env.
|
|
542
|
+
let deployKeySsh = null;
|
|
543
|
+
try {
|
|
544
|
+
deployKeySsh = prepareDeployKey();
|
|
545
|
+
}
|
|
546
|
+
catch (err) {
|
|
547
|
+
logger.warn(`Deploy key not installed: ${err instanceof Error ? err.message : String(err)}`);
|
|
548
|
+
}
|
|
549
|
+
if (deployKeySsh)
|
|
550
|
+
process.env.ORQUESTA_AGENT_NO_GITHUB_TOKEN = '1';
|
|
551
|
+
// GitHub App mode wins over the deploy key: the microVM clones over HTTPS with
|
|
552
|
+
// a short-lived token minted per boot (git-app-auth.ts), no key on disk.
|
|
553
|
+
const useGithubApp = !deployKeySsh && bootstrapWantsGithubApp();
|
|
554
|
+
if (useGithubApp)
|
|
555
|
+
process.env.ORQUESTA_AGENT_NO_GITHUB_TOKEN = '1';
|
|
537
556
|
setInjectedCredentials(credentials);
|
|
538
557
|
const credCount = Object.keys(credentials).length;
|
|
539
558
|
logger.stopSpinner(`Loaded ${credCount} credential${credCount !== 1 ? 's' : ''}`);
|
|
@@ -701,6 +720,22 @@ async function connect(options) {
|
|
|
701
720
|
// Use found directory or clone
|
|
702
721
|
if (foundProjectDir) {
|
|
703
722
|
workingDirectory = foundProjectDir;
|
|
723
|
+
if (deployKeySsh) {
|
|
724
|
+
try {
|
|
725
|
+
pinDeployKey(foundProjectDir, expectedRepoUrl, deployKeySsh);
|
|
726
|
+
}
|
|
727
|
+
catch (err) {
|
|
728
|
+
logger.warn(`Could not pin the deploy key: ${err instanceof Error ? err.message : String(err)}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
else if (useGithubApp && httpsUrlFor(expectedRepoUrl)) {
|
|
732
|
+
try {
|
|
733
|
+
pinGithubApp(foundProjectDir, expectedRepoUrl);
|
|
734
|
+
}
|
|
735
|
+
catch (err) {
|
|
736
|
+
logger.warn(`Could not pin the GitHub App credential helper: ${err instanceof Error ? err.message : String(err)}`);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
704
739
|
if (options.autoPull !== false) {
|
|
705
740
|
await gitPull(foundProjectDir);
|
|
706
741
|
}
|
|
@@ -716,8 +751,28 @@ async function connect(options) {
|
|
|
716
751
|
}
|
|
717
752
|
else {
|
|
718
753
|
logger.info(`Cloning repository to ./${repoName}`);
|
|
719
|
-
|
|
720
|
-
|
|
754
|
+
// A failed clone must fail every prompt (repoCloneFailure in the executor),
|
|
755
|
+
// not crash the agent nor run it on an empty directory.
|
|
756
|
+
try {
|
|
757
|
+
if (deployKeySsh && sshUrlFor(expectedRepoUrl)) {
|
|
758
|
+
cloneWithDeployKey(expectedRepoUrl, targetDir, deployKeySsh, 120_000);
|
|
759
|
+
}
|
|
760
|
+
else if (useGithubApp && httpsUrlFor(expectedRepoUrl)) {
|
|
761
|
+
cloneWithGithubApp(expectedRepoUrl, targetDir, 120_000);
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
await gitClone(expectedRepoUrl, targetDir, validation.githubToken);
|
|
765
|
+
}
|
|
766
|
+
setRepoCloneFailure(null);
|
|
767
|
+
workingDirectory = targetDir;
|
|
768
|
+
}
|
|
769
|
+
catch (err) {
|
|
770
|
+
const e = err;
|
|
771
|
+
const detail = (e.stderr ? String(e.stderr).trim() : '') || e.message || String(err);
|
|
772
|
+
const msg = redactSecrets(detail).split('\n').slice(-3).join(' ').slice(0, 500);
|
|
773
|
+
setRepoCloneFailure(msg);
|
|
774
|
+
logger.error(`Could not clone ${repoName}: ${msg}`);
|
|
775
|
+
}
|
|
721
776
|
}
|
|
722
777
|
}
|
|
723
778
|
}
|
|
@@ -2596,5 +2651,31 @@ serviceCmd
|
|
|
2596
2651
|
logger.error(`Failed to stop service: ${message}`);
|
|
2597
2652
|
}
|
|
2598
2653
|
});
|
|
2654
|
+
// git credential helper for GitHub App mode (git-app-auth.ts). git invokes
|
|
2655
|
+
// `orquesta-agent git-credential <get|store|erase>` with a key=value block on
|
|
2656
|
+
// stdin; we only answer `get`, printing a short-lived installation token. Kept
|
|
2657
|
+
// terminal-quiet: git parses our stdout, so nothing else may be written there.
|
|
2658
|
+
program
|
|
2659
|
+
.command('git-credential <verb>')
|
|
2660
|
+
.description('Internal: git credential helper for the microVM runner GitHub App')
|
|
2661
|
+
.action(async (verb) => {
|
|
2662
|
+
try {
|
|
2663
|
+
const { runGitCredential } = await import('./git-app-auth.js');
|
|
2664
|
+
const stdin = fs.existsSync('/dev/stdin') || !process.stdin.isTTY
|
|
2665
|
+
? await new Promise(resolve => {
|
|
2666
|
+
let data = '';
|
|
2667
|
+
process.stdin.setEncoding('utf8');
|
|
2668
|
+
process.stdin.on('data', c => { data += c; });
|
|
2669
|
+
process.stdin.on('end', () => resolve(data));
|
|
2670
|
+
process.stdin.on('error', () => resolve(data));
|
|
2671
|
+
})
|
|
2672
|
+
: '';
|
|
2673
|
+
await runGitCredential(verb, stdin);
|
|
2674
|
+
}
|
|
2675
|
+
catch {
|
|
2676
|
+
// A failed helper makes git fall back / fail the operation; stay silent on stdout.
|
|
2677
|
+
}
|
|
2678
|
+
process.exit(0);
|
|
2679
|
+
});
|
|
2599
2680
|
program.parse();
|
|
2600
2681
|
//# sourceMappingURL=index.js.map
|