OpenCodeSharp.Acp 1.0.1

dotnet add package OpenCodeSharp.Acp --version 1.0.1
                    
NuGet\Install-Package OpenCodeSharp.Acp -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenCodeSharp.Acp" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenCodeSharp.Acp" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="OpenCodeSharp.Acp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenCodeSharp.Acp --version 1.0.1
                    
#r "nuget: OpenCodeSharp.Acp, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenCodeSharp.Acp@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenCodeSharp.Acp&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=OpenCodeSharp.Acp&version=1.0.1
                    
Install as a Cake Tool

OpenCodeSharp.Acp

Visual Studio 2022용 C# OpenCode ACP wrapper입니다.

이 버전은 외부 API를 단순하게 유지합니다. ACP의 raw JSON, kind, status 같은 세부 필드는 외부에 노출하지 않고, 애플리케이션에서 바로 사용하기 쉬운 lifecycle 이벤트와 텍스트 이벤트만 제공합니다.

요구사항

  • Visual Studio 2022
  • .NET 8 SDK
  • Windows x64
  • OpenCode CLI
  • opencode acp가 실행 가능한 환경

주요 이벤트

전체 작업

session.WorkingStarted += () => { };
session.WorkingCompleted += () => { };

Thinking

session.ThinkingStarted += () => { };
session.ThinkingTextReceived += text => Console.Write(text);
session.ThinkingCompleted += () => { };

agent_thought_chunk가 시작되면 ThinkingStarted가 한 번 호출되고, 연속되는 생각 텍스트는 ThinkingTextReceived로 전달됩니다. Tool 실행 또는 응답 출력으로 전환되면 ThinkingCompleted가 호출됩니다.

Response

session.ResponseStarted += () => { };
session.ResponseTextReceived += text => Console.Write(text);
session.ResponseCompleted += () => { };

agent_message_chunk가 시작되면 ResponseStarted가 한 번 호출됩니다. 사용자에게 보여줄 답변 텍스트만 ResponseTextReceived로 전달합니다. Tool/Thinking으로 전환되거나 Prompt가 끝나면 ResponseCompleted가 호출됩니다.

Tool

session.ToolStarted += toolName => Console.WriteLine(toolName);
session.ToolCompleted += toolName => Console.WriteLine(toolName);

예:

read
edit
bash
skill

내부적으로 toolCallId를 추적하지만 외부에는 Tool 이름만 전달합니다.

Skill

session.SkillStarted += skillName => Console.WriteLine(skillName);
session.SkillCompleted += skillName => Console.WriteLine(skillName);

OpenCode의 skill Tool이 실행될 때 rawInput.name에서 실제 Skill 이름을 찾아 전달합니다.

예:

initiate-msbuild
msbuild

OpenCode에서는 Skill이 native skill({ name: "..." }) Tool 호출로 로드되므로, Skill 호출 시 일반 Tool 이벤트의 skill과 Skill 전용 이벤트가 모두 발생할 수 있습니다.

Error

Library 또는 OpenCode ACP process의 stderr에서 발생한 오류/로그 텍스트를 받습니다.

client.ErrorReceived += text =>
{
    Console.Error.WriteLine(text);
};

JSON parsing 실패, ACP RPC error, transport 오류 등의 library 내부 오류도 이 이벤트로 전달됩니다. 예외가 필요한 경우 기존 Task 예외도 그대로 throw됩니다.

최소 사용 예

await using var client = new OpenCodeAcpClient(new OpenCodeAcpOptions
{
    ExecutablePath = "opencode",
    ProcessWorkingDirectory = projectDirectory,
    ForceUtf8OnWindows = true
});

client.ErrorReceived += text => Console.Error.WriteLine(text);

await client.StartAsync();
var session = await client.CreateSessionAsync(projectDirectory);

session.ThinkingStarted += () => Console.WriteLine("Thinking...");
session.ThinkingTextReceived += text => Console.Write(text);
session.ThinkingCompleted += () => Console.WriteLine();

session.ResponseStarted += () => Console.WriteLine("Response...");
session.ResponseTextReceived += text => Console.Write(text);
session.ResponseCompleted += () => Console.WriteLine();

session.ToolStarted += name => Console.WriteLine($"Tool: {name}");
session.SkillStarted += name => Console.WriteLine($"Skill: {name}");

await session.PromptAsync("프로젝트를 분석해줘.");

UTF-8 / BOM

ACP stdin/stdout/stderr는 UTF-8 no-BOM으로 처리합니다. Windows에서는 기본적으로 chcp 65001을 적용하고, ACP stdout을 오염시키지 않도록 CHCP 출력은 nul로 보냅니다.

수신 시에는 실제 U+FEFF BOM과  형태로 잘못 변환된 BOM도 방어적으로 제거합니다.

빌드

Visual Studio 2022에서 다음 솔루션을 엽니다.

OpenCodeSharp.Acp.sln

또는 CMD:

scripts\build_vs2022.cmd
Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 93 9/18/2026
1.0.0 87 9/18/2026