Add Hermes and Pi agent provider support #2748
Closedjoeynyc(GitHub profile, opens in a new tab)wants to merge 23 commits into
main fromrefs/pull/2748/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/provider/Layers/PiProvider.ts line 40Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +20,21 @@20+import { createModelCapabilities } from "@t3tools/shared/model";21+22+import {23+ buildServerProvider,24+ collectStreamAsString,25+ isCommandMissingCause,26+ providerModelsFromSettings,27+ type CommandResult,28+ type ServerProviderDraft,29+} from "../providerSnapshot.ts";30+import {31+ enrichProviderSnapshotWithVersionAdvisory,32+ type ProviderMaintenanceCapabilities,33+} from "../providerMaintenance.ts";34+35+const PROVIDER = ProviderDriverKind.make("pi");36+const PI_PRESENTATION = {37+ displayName: "Pi",38+ badgeLabel: "Early Access",39+ showInteractionModeToggle: true,40+} as const;@@ -0,0 +236,21 @@236+ });237+238+ const generated = yield* runPiJson({239+ operation: "generateThreadTitle",240+ cwd: input.cwd,241+ prompt,242+ outputSchemaJson: outputSchema,243+ });244+245+ return {246+ title: sanitizeThreadTitle(generated.title),247+ } satisfies ThreadTitleGenerationResult;248+ });249+250+ return {251+ generateCommitMessage,252+ generatePrContent,253+ generateBranchName,254+ generateThreadTitle,255+ } satisfies TextGenerationShape;256+});
- @@ -0,0 +51,21 @@51+ } catch {52+ // Deleted source files still need a restart.53+ }54+55+ return sourceExtensions.has(extname(changedPath));56+}57+58+function scheduleRestart() {59+ clearTimeout(restartTimer);60+ restartTimer = setTimeout(() => {61+ restartTimer = undefined;62+ console.log("Restarting server...");63+64+ const previous = child;65+ previous.once("exit", () => {66+ if (!stopping) {67+ start();68+ }69+ });70+ previous.kill("SIGTERM");71+ }, 100);apps/server/src/provider/acp/PiAcpSupport.ts lines 65 to 91Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +38,21 @@38+ return next.join(PATH_DELIMITER);39+}40+41+function buildPiAcpEnvironment(42+ piSettings: PiAcpRuntimePiSettings | null | undefined,43+ environment?: NodeJS.ProcessEnv,44+): NodeJS.ProcessEnv | undefined {45+ if (!piSettings?.piBinaryPath && !piSettings?.binaryPath && !environment) {46+ return undefined;47+ }48+49+ const env = { ...environment };50+ if (piSettings?.piBinaryPath) {51+ env.PI_ACP_PI_COMMAND = piSettings.piBinaryPath;52+ }53+ env.PATH = prependUniquePathEntries(env.PATH, [54+ dirnameForExecutablePath(piSettings?.binaryPath),55+ dirnameForExecutablePath(piSettings?.piBinaryPath),56+ ]);57+ return env;58+}apps/server/src/provider/Layers/PiProvider.ts line 179OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +159,21 @@159+ .join(" ");160+}161+162+function modelFromPiDefault(defaultModel: string | null): ServerProviderModel {163+ const slug = defaultModel?.trim();164+ if (!slug) return PI_FALLBACK_MODEL;165+ return {166+ slug,167+ name: formatPiModelName(slug),168+ isCustom: false,169+ capabilities: EMPTY_CAPABILITIES,170+ };171+}172+173+function readPiConfigModelDefaults(174+ environment: NodeJS.ProcessEnv,175+): Effect.Effect<PiConfigModelDefaults, never, FileSystem.FileSystem | Path.Path> {176+ return Effect.gen(function* () {177+ const fs = yield* FileSystem.FileSystem;178+ const path = yield* Path.Path;179+ const home = environment.PI_CODING_AGENT_DIR?.trim()apps/server/src/provider/Layers/HermesProvider.ts lines 79 to 79OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +59,21 @@59+}60+61+function stripQuotes(value: string): string {62+ const trimmed = value.trim();63+ if (64+ (trimmed.startsWith('"') && trimmed.endsWith('"')) ||65+ (trimmed.startsWith("'") && trimmed.endsWith("'"))66+ ) {67+ return trimmed.slice(1, -1).trim();68+ }69+ return trimmed;70+}71+72+export function parseHermesConfigModelDefaults(raw: string): HermesConfigModelDefaults {73+ const lines = raw.replace(/\r\n?/g, "\n").split("\n");74+ let inModelBlock = false;75+ let modelIndent = 0;76+ let sawModelBlock = false;77+78+ for (const line of lines) {79+ const withoutComment = line.replace(/\s+#.*$/, "");
- apps/server/src/provider/acp/PiAcpSupport.ts lines 32 to 45Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +21,21 @@21+ return ";";22+ }23+ return PATH_DELIMITER;24+}25+26+function pathKeyForEnvironment(environment?: NodeJS.ProcessEnv): "PATH" | "Path" | "path" {27+ if (environment && "Path" in environment) return "Path";28+ if (environment && "path" in environment) return "path";29+ return "PATH";30+}31+32+function dirnameForExecutablePath(value: string | undefined): string | null {33+ if (!value) {34+ return null;35+ }36+ const normalized = value.replaceAll("\\", "/");37+ if (!normalized.startsWith("/") && !WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalized)) {38+ return null;39+ }40+ const separatorIndex = normalized.lastIndexOf("/");41+ return separatorIndex > 0 ? value.slice(0, separatorIndex) : "/";
- @@ -0,0 +816,21 @@816+817+ const streamEvents = Stream.fromPubSub(runtimeEventPubSub);818+819+ return {820+ provider: PROVIDER,821+ capabilities: { sessionModelSwitch: "in-session" },822+ startSession,823+ sendTurn,824+ interruptTurn,825+ readThread,826+ rollbackThread,827+ respondToRequest,828+ respondToUserInput,829+ stopSession,830+ listSessions,831+ hasSession,832+ stopAll,833+ streamEvents,834+ } satisfies PiAdapterShape;835+ });836+}
- @@ -0,0 +78,21 @@78+ Effect.gen(function* () {79+ const outputRef = yield* Ref.make("");80+ const runtime = yield* makePiAcpRuntime({81+ piSettings,82+ environment,83+ childProcessSpawner: commandSpawner,84+ cwd,85+ clientInfo: { name: "t3-code-git-text", version: "0.0.0" },86+ });87+88+ yield* runtime.handleSessionUpdate((notification) => {89+ const update = notification.update;90+ if (update.sessionUpdate !== "agent_message_chunk") {91+ return Effect.void;92+ }93+ const content = update.content;94+ if (content.type !== "text") {95+ return Effect.void;96+ }97+ return Ref.update(outputRef, (current) => current + content.text);98+ });@@ -0,0 +22,21 @@22+ });23+24+ child.on("exit", (code, signal) => {25+ if (stopping || restartTimer) {26+ return;27+ }28+ if (signal) {29+ process.kill(process.pid, signal);30+ return;31+ }32+ process.exit(code ?? 0);33+ });34+}35+36+async function shouldRestart(filename) {37+ if (!filename || typeof filename !== "string") {38+ return false;39+ }40+41+ const changedPath = resolve(srcDir, filename);42+ if (!changedPath.startsWith(`${srcDir}/`)) {
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
6c659f03-31a7-496e-a345-04b1e94b499dYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share