@fungi.computer/graft

中文文档
0.2.25发布于 2026/11/15MITTypeScriptES Module近 30 天下载 6581

ACP v1 projection for an authorized Shiitake Session

原始使用文档
文档目录8 节
  1. Install or set up
  2. Quick start
  3. Core concepts
  4. API reference
  5. Examples
  6. Limits and errors
  7. Contribute and license
  8. Editor capabilities

Graft (@fungi.computer/graft)

This package presents an authorized Shiitake Session through the stable Agent Client Protocol (ACP) v1. Editor and host integrations use it to create, load, prompt, and observe Sessions while the host remains responsible for authorization.

Just want Fungi in Zed or another ACP editor? Run fungi acp — see Use Fungi in your editor. Graft is for people embedding ACP in their own host.

Install or set up

npm install @fungi.computer/graft

Strict TypeScript consumers also install @modelcontextprotocol/[email protected]: the transitive Google GenAI declarations reference this optional peer.

Quick start

Just want Fungi in Zed or another ACP editor? Run fungi acp — see Use Fungi in your editor. Graft is for people embedding ACP in their own host.

This self-contained example initializes an ACP connection without granting access to any Session. Replace the refusing directory with your host's authorized Session directory before accepting create or load requests.

import * as acp from "@agentclientprotocol/sdk";
import { createHttpStream } from "@agentclientprotocol/sdk/experimental/http-client";
import {
  agentAcpMethods,
  type AuthorizedShiitakeSessionDirectory,
} from "@fungi.computer/graft";
import { createShiitakeAcpServer } from "@fungi.computer/graft/server";

const directory: AuthorizedShiitakeSessionDirectory = {
  create() {
    return Promise.reject(new Error("Session access is not granted"));
  },
  load() {
    return Promise.reject(new Error("Session access is not granted"));
  },
};
const server = createShiitakeAcpServer(directory);
const stream = createHttpStream("https://agent.test/acp", {
  fetch: (input, init) => server.handleRequest(new Request(input, init)),
});
try {
  await acp
    .client({ name: "graft-example" })
    .connectWith(stream, async (ctx) => {
      const initialized = await ctx.request(agentAcpMethods.initialize, {
        protocolVersion: acp.PROTOCOL_VERSION,
      });
      console.log(initialized.protocolVersion);
    });
} finally {
  await stream.writable.close();
  await server.close();
}

The fetch adapter calls the server in-process; it makes no network request and needs no model or credentials. The packed runtime proof in test/stranger/runtime.mjs exercises this flow on Node. test/index.test.ts additionally proves Session creation, prompting and cleanup through the maintained ACP client.

Core concepts

  • The directory owns access. Its create and load methods return a Session binding only after the host authorizes it. It can validate the working directory, additional directories, and MCP servers before opening the Session.
  • Shiitake owns Session state. The ACP adapter projects messages, tool calls, progress, cancellation, and terminal results. It does not own the transcript or delete the durable Session.
  • An ACP connection owns its lease. Closing a Session or connection releases its host-provided client lease and observation. An active prompt is cancelled and allowed to settle for up to five seconds by default when its Session closes.
  • The server is an adapter. createShiitakeAcpServer exposes the same agent through the maintained Streamable HTTP transport; it does not supply authorization by itself.

API reference

The package exports createShiitakeAcpAgent, the authorization and adapter types, and agentAcpMethods from src/index.ts. The HTTP server is exported separately from src/server.ts. The host-owned directory adapter lives in src/session-directory.ts. The generated API reference is included in the tarball.

Examples

  • test/index.test.ts proves create/load/prompt behavior, streamed message projection, cancellation and cleanup through the maintained ACP client.
  • The private Local stdio host currently rejects ACP additionalDirectories and mcpServers; other hosts may support them when their authorization boundary permits them.

Limits and errors

The adapter supports text and image prompts, embedded text or image resources, and text or image tool results. Audio and other binary resources are refused. A host decides which directories, MCP servers, and Sessions the connection may use. ACP create requests do not provide their own stable retry identity, so the directory generates a request identity for Shiitake. Callers must close the ACP connection so watches and authorization leases are released; closing the lease does not delete the Session.

Contribute and license

Run pnpm --filter @fungi.computer/graft test for the ACP protocol and lifecycle tests, and pnpm --filter @fungi.computer/graft build to compile the package. To qualify the packed tarballs as a stranger would install them:

pnpm install --frozen-lockfile
pnpm turbo:run run build [email protected]/graft
pnpm --filter @fungi.computer/graft run pack
pnpm --filter @fungi.computer/graft run stranger

The stranger proof packs the dependency closure and installs it in a fresh consumer with library checking enabled. The package uses the MIT license in LICENSE.

Editor capabilities

The adapter uses ACP SDK 1.7 and stable protocol v1. Initialization returns the supported protocol version even when an editor offers another version; the editor decides whether it can continue. Session listing is advertised only when the authorized host directory supplies it. Local lists saved project Sessions.

A host may supply a terminal login method. It is advertised only when the editor supports terminal authentication; the editor runs the login command in a separate interactive process. Hosted directories do not acquire Local credentials.

Text resources retain their URI and contents in prompt context. Resource links retain their name and URI for the Agent's authorized tools to resolve. Images, including embedded image resources, enter Shiitake's bounded prompt admission and persist as Pi image content. History replays images through ACP. Audio and other binary resources return invalid_params; they are not silently discarded.

Protocol references: initialization and content.

版本与发布记录

@fungi.computer/graft 共发布 35 个版本,首次发布于 2026/10/17;过去 12 个月发布了 35 个版本。

版本发布日期距今
0.2.25latest2026/11/15今天
0.2.242026/11/15今天
0.2.232026/11/141 天前
0.2.222026/11/141 天前
0.2.212026/11/141 天前
0.2.202026/11/141 天前

关于 @fungi.computer/graft 的常见问题

@fungi.computer/graft 是什么?

ACP v1 projection for an authorized Shiitake Session

如何安装 @fungi.computer/graft?

在项目目录运行 npm install @fungi.computer/graft,或使用 pnpm add / yarn add / bun add。

@fungi.computer/graft 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fungi.computer/graft 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fungi.computer/graft 可以商用吗?

@fungi.computer/graft 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fungi.computer/graft 的下载量有多少?

根据 npm 官方下载统计,@fungi.computer/graft 在 2026/10/16 – 2026/11/14 这 30 天内被下载 6,581 次,日均约 219 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fungi.computer/graft 还在维护吗?

最新版本 0.2.25 发布于 2026/11/15(今天);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2026/10/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。