@growthagent/ci 0.3.0 → 0.4.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/dist/cli.js +33 -25
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
5
|
-
import { cpSync, existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
-
import
|
|
5
|
+
import { cpSync, existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6
|
+
import path5 from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
9
|
// ../github/src/app.ts
|
|
@@ -235,6 +235,28 @@ function validatePatch(patch, limits = DEFAULT_PATCH_LIMITS) {
|
|
|
235
235
|
return { ok: true, report: { files, bytes, addedLines } };
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
// src/provider-config.ts
|
|
239
|
+
import { mkdtempSync as mkdtempSync2, writeFileSync } from "node:fs";
|
|
240
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
241
|
+
import path4 from "node:path";
|
|
242
|
+
var RUN_TOKEN_ENV = "GX_RUN_TOKEN";
|
|
243
|
+
function writeGoogleProviderConfig(model) {
|
|
244
|
+
const gateway = (process.env.GX_GATEWAY_URL ?? "").replace(/\/$/, "");
|
|
245
|
+
const dir = mkdtempSync2(path4.join(tmpdir3(), "growth-agent-pi-"));
|
|
246
|
+
const config = {
|
|
247
|
+
providers: {
|
|
248
|
+
"growthagent-google": {
|
|
249
|
+
baseUrl: `${gateway}/v1beta`,
|
|
250
|
+
api: "google-generative-ai",
|
|
251
|
+
apiKey: `$${RUN_TOKEN_ENV}`,
|
|
252
|
+
models: [{ id: model, name: model, input: ["text"], contextWindow: 1e6 }]
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
writeFileSync(path4.join(dir, "models.json"), JSON.stringify(config, null, 2));
|
|
257
|
+
return dir;
|
|
258
|
+
}
|
|
259
|
+
|
|
238
260
|
// src/trust.ts
|
|
239
261
|
var TRUSTED_APP_LOGIN = "growth-agent[bot]";
|
|
240
262
|
function authorIsTrusted(issue, extraLogins = []) {
|
|
@@ -340,11 +362,11 @@ function buildPrompt(fields, briefing) {
|
|
|
340
362
|
}
|
|
341
363
|
|
|
342
364
|
// src/cli.ts
|
|
343
|
-
var HERE =
|
|
365
|
+
var HERE = path5.dirname(fileURLToPath(import.meta.url));
|
|
344
366
|
var PATCH_FILE = "growth-agent.patch";
|
|
345
367
|
function assetsDir() {
|
|
346
|
-
const packaged =
|
|
347
|
-
return existsSync2(packaged) ? packaged :
|
|
368
|
+
const packaged = path5.join(HERE, "assets", "skills");
|
|
369
|
+
return existsSync2(packaged) ? packaged : path5.join(HERE, "..", "assets", "skills");
|
|
348
370
|
}
|
|
349
371
|
function sh(cmd, args, opts = {}) {
|
|
350
372
|
const r = spawnSync(cmd, args, { encoding: "utf8", stdio: ["inherit", "pipe", "inherit"] });
|
|
@@ -452,20 +474,6 @@ async function openSession() {
|
|
|
452
474
|
};
|
|
453
475
|
}
|
|
454
476
|
}
|
|
455
|
-
function writeGoogleProviderConfig(piDir, model, runToken) {
|
|
456
|
-
const gateway = (process.env.GX_GATEWAY_URL ?? "").replace(/\/$/, "");
|
|
457
|
-
const config = {
|
|
458
|
-
providers: {
|
|
459
|
-
"growthagent-google": {
|
|
460
|
-
baseUrl: `${gateway}/v1beta`,
|
|
461
|
-
api: "google-generative-ai",
|
|
462
|
-
apiKey: runToken,
|
|
463
|
-
models: [{ id: model, name: model, input: ["text"], contextWindow: 1e6 }]
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
writeFileSync(path4.join(piDir, "..", "models.json"), JSON.stringify(config, null, 2));
|
|
468
|
-
}
|
|
469
477
|
async function implement() {
|
|
470
478
|
const issue = readIssue();
|
|
471
479
|
const refusal = refuseUntrustedAuthor(issue);
|
|
@@ -485,7 +493,7 @@ async function implement() {
|
|
|
485
493
|
console.log(
|
|
486
494
|
meta.kind === "instrumentation" ? `\u25B8 instrumentation request #${issue.number}` : `\u25B8 change request #${issue.number} \u2014 flag ${meta.flagKey} on ${meta.surface}`
|
|
487
495
|
);
|
|
488
|
-
const skillsDir =
|
|
496
|
+
const skillsDir = path5.resolve(process.cwd(), ".pi", "skills");
|
|
489
497
|
mkdirSync(skillsDir, { recursive: true });
|
|
490
498
|
cpSync(assetsDir(), skillsDir, { recursive: true });
|
|
491
499
|
const prompt = buildPrompt(meta, extractBriefing(issue.body));
|
|
@@ -497,9 +505,7 @@ async function implement() {
|
|
|
497
505
|
return 1;
|
|
498
506
|
}
|
|
499
507
|
const piProvider = provider === "google" ? "growthagent-google" : provider;
|
|
500
|
-
|
|
501
|
-
writeGoogleProviderConfig(skillsDir, model, session.token);
|
|
502
|
-
}
|
|
508
|
+
const piConfigDir = provider === "google" ? writeGoogleProviderConfig(model) : null;
|
|
503
509
|
console.log(`\u25B8 running pi (${piProvider}/${model})`);
|
|
504
510
|
let piStatus;
|
|
505
511
|
try {
|
|
@@ -517,7 +523,9 @@ async function implement() {
|
|
|
517
523
|
// environment, whatever else it might read there. Nor may a raw
|
|
518
524
|
// provider key: everything is spent through the run token.
|
|
519
525
|
GROWTH_AGENT_TOKEN: "",
|
|
520
|
-
GEMINI_API_KEY: ""
|
|
526
|
+
GEMINI_API_KEY: "",
|
|
527
|
+
// Only set for the Google path; pi keeps its own default otherwise.
|
|
528
|
+
...piConfigDir ? { PI_CODING_AGENT_DIR: piConfigDir, [RUN_TOKEN_ENV]: session.token } : {}
|
|
521
529
|
}
|
|
522
530
|
}
|
|
523
531
|
);
|
|
@@ -537,7 +545,7 @@ async function implement() {
|
|
|
537
545
|
console.error("pi made no changes \u2014 nothing to open a PR for");
|
|
538
546
|
return 2;
|
|
539
547
|
}
|
|
540
|
-
|
|
548
|
+
writeFileSync2(PATCH_FILE, patch + "\n", "utf8");
|
|
541
549
|
const verdict = validatePatch(patch);
|
|
542
550
|
if (!verdict.ok) {
|
|
543
551
|
console.error(`The produced patch was refused: ${verdict.reason}`);
|