@testchimp/cli 0.1.41 → 0.1.42
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/chimphands/run.js +36 -17
- package/package.json +1 -1
package/dist/chimphands/run.js
CHANGED
|
@@ -45,6 +45,17 @@ function normalizeUserMessage(content) {
|
|
|
45
45
|
function sleep(ms) {
|
|
46
46
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
47
|
}
|
|
48
|
+
/** Protobuf JsonFormat uses camelCase; accept snake_case too for resilience. */
|
|
49
|
+
function bootStr(boot, snake, camel) {
|
|
50
|
+
const raw = boot;
|
|
51
|
+
const v = raw[snake] ?? raw[camel];
|
|
52
|
+
return typeof v === "string" ? v.trim() : "";
|
|
53
|
+
}
|
|
54
|
+
function bootNum(boot, snake, camel) {
|
|
55
|
+
const raw = boot;
|
|
56
|
+
const v = raw[snake] ?? raw[camel];
|
|
57
|
+
return typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
58
|
+
}
|
|
48
59
|
/** Agent/CLI hook: persist the conversation working branch (+ optional PR) for UI + later turns. */
|
|
49
60
|
export async function reportWorkingBranch(opts) {
|
|
50
61
|
const apiKey = requireApiKey();
|
|
@@ -147,8 +158,8 @@ class AgentEventPoster {
|
|
|
147
158
|
}
|
|
148
159
|
const TESTCHIMP_PROVIDER_ID = "testchimp";
|
|
149
160
|
function resolveOpencodeModelId(boot) {
|
|
150
|
-
const raw = (boot
|
|
151
|
-
const modelId = raw.includes("/") ? raw.split("/").pop() || "gpt-
|
|
161
|
+
const raw = bootStr(boot, "llm_model", "llmModel") || "gpt-5.6-luna";
|
|
162
|
+
const modelId = raw.includes("/") ? raw.split("/").pop() || "gpt-5.6-luna" : raw;
|
|
152
163
|
return modelId;
|
|
153
164
|
}
|
|
154
165
|
function resolveOpencodeModel(boot) {
|
|
@@ -271,19 +282,29 @@ function detectWorkingBranchFromToolOutput(output) {
|
|
|
271
282
|
};
|
|
272
283
|
}
|
|
273
284
|
function writeOpencodeConfig(backend, apiKey, boot) {
|
|
274
|
-
const llmBase = (boot
|
|
275
|
-
const llmKey = apiKey || boot
|
|
285
|
+
const llmBase = (bootStr(boot, "llm_base_url", "llmBaseUrl") || `${backend}/v1`).replace(/\/$/, "");
|
|
286
|
+
const llmKey = apiKey || bootStr(boot, "llm_api_key", "llmApiKey");
|
|
276
287
|
const modelId = resolveOpencodeModelId(boot);
|
|
277
288
|
const model = `${TESTCHIMP_PROVIDER_ID}/${modelId}`;
|
|
289
|
+
const sessionId = bootStr(boot, "session_id", "sessionId");
|
|
278
290
|
const mcpEnv = {
|
|
279
291
|
TESTCHIMP_API_KEY: apiKey,
|
|
280
292
|
TESTCHIMP_BACKEND_URL: backend,
|
|
281
293
|
TESTCHIMP_EXECUTION_SOURCE: "CLOUD_AGENT",
|
|
282
294
|
};
|
|
283
|
-
const serviceUserId = boot
|
|
295
|
+
const serviceUserId = bootStr(boot, "chimphands_service_account_user_id", "chimphandsServiceAccountUserId");
|
|
284
296
|
if (serviceUserId) {
|
|
285
297
|
mcpEnv.TESTCHIMP_USER_ID = serviceUserId;
|
|
286
298
|
}
|
|
299
|
+
const providerOptions = {
|
|
300
|
+
apiKey: llmKey,
|
|
301
|
+
baseURL: llmBase,
|
|
302
|
+
};
|
|
303
|
+
if (sessionId) {
|
|
304
|
+
providerOptions.headers = {
|
|
305
|
+
"X-TestChimp-ChimpHands-Session-Id": sessionId,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
287
308
|
writeFileSync("opencode.json", JSON.stringify({
|
|
288
309
|
$schema: "https://opencode.ai/config.json",
|
|
289
310
|
model,
|
|
@@ -293,10 +314,7 @@ function writeOpencodeConfig(backend, apiKey, boot) {
|
|
|
293
314
|
[TESTCHIMP_PROVIDER_ID]: {
|
|
294
315
|
npm: "@ai-sdk/openai-compatible",
|
|
295
316
|
name: "TestChimp",
|
|
296
|
-
options:
|
|
297
|
-
apiKey: llmKey,
|
|
298
|
-
baseURL: llmBase,
|
|
299
|
-
},
|
|
317
|
+
options: providerOptions,
|
|
300
318
|
models: {
|
|
301
319
|
[modelId]: {
|
|
302
320
|
name: modelId,
|
|
@@ -572,17 +590,17 @@ export async function runChimphands(opts) {
|
|
|
572
590
|
console.error(`ChimpHands link run failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
573
591
|
});
|
|
574
592
|
}
|
|
575
|
-
const userId = boot
|
|
593
|
+
const userId = bootStr(boot, "chimphands_service_account_user_id", "chimphandsServiceAccountUserId");
|
|
576
594
|
if (userId) {
|
|
577
595
|
process.env.TESTCHIMP_USER_ID = userId;
|
|
578
596
|
}
|
|
579
597
|
mkdirSync(".opencode", { recursive: true });
|
|
580
598
|
const opencodeModel = writeOpencodeConfig(backend, apiKey, boot);
|
|
581
599
|
console.error(`ChimpHands OpenCode model: ${opencodeModel}`);
|
|
582
|
-
let opencodeSessionId = boot
|
|
583
|
-
const conversationSummary = boot
|
|
584
|
-
let workingBranch = boot
|
|
585
|
-
let pullRequestUrl = boot
|
|
600
|
+
let opencodeSessionId = bootStr(boot, "opencode_session_id", "opencodeSessionId") || undefined;
|
|
601
|
+
const conversationSummary = bootStr(boot, "conversation_summary", "conversationSummary");
|
|
602
|
+
let workingBranch = bootStr(boot, "working_branch", "workingBranch") || undefined;
|
|
603
|
+
let pullRequestUrl = bootStr(boot, "pull_request_url", "pullRequestUrl") || undefined;
|
|
586
604
|
const noteWorkingBranch = (branch, prUrl) => {
|
|
587
605
|
const normalizedBranch = branch.trim();
|
|
588
606
|
if (!normalizedBranch)
|
|
@@ -599,7 +617,7 @@ export async function runChimphands(opts) {
|
|
|
599
617
|
poster.reportWorkingBranch(normalizedBranch, nextPr);
|
|
600
618
|
}
|
|
601
619
|
};
|
|
602
|
-
const idleMs = (
|
|
620
|
+
const idleMs = (bootNum(boot, "idle_timeout_seconds", "idleTimeoutSeconds") || 600) * 1000;
|
|
603
621
|
const queue = [];
|
|
604
622
|
const seenUserMessageIds = new Set();
|
|
605
623
|
let idle = false;
|
|
@@ -669,8 +687,9 @@ export async function runChimphands(opts) {
|
|
|
669
687
|
shouldRun: () => sessionActive,
|
|
670
688
|
});
|
|
671
689
|
poster.fireAndForget(ROLE_STATUS, "Agent ready", { status: STATUS_RUNNING });
|
|
672
|
-
let prompt = normalizeUserMessage(promptInput || boot
|
|
673
|
-
|
|
690
|
+
let prompt = normalizeUserMessage(promptInput || bootStr(boot, "initial_prompt", "initialPrompt"));
|
|
691
|
+
const pending = boot.pending_user_messages || boot.pendingUserMessages || [];
|
|
692
|
+
for (const m of pending) {
|
|
674
693
|
if (m?.content)
|
|
675
694
|
enqueueUserMessage({ content: m.content });
|
|
676
695
|
}
|
package/package.json
CHANGED