Compare commits

..
Author SHA1 Message Date
mesalogo efd304fa1d feat: support native subagents and long-running prompts
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
GoodBuddy Agent Release / Authorize Agent release (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux arm64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux x64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Sign cumulative Agent catalog (push) Canceled after 0s
GoodBuddy Agent Release / Publish Agent to GitHub and OSS (push) Canceled after 0s
OpenCode Task calls now appear as first-class subagents in local and managed SSH conversations, with stable status, persistence, terminal handling, and true event ordering instead of duplicate generic tool entries.

GoodBuddy no longer applies a fixed outer wall-clock total to OpenCode, Continue, DeepSeek Harness, or managed SSH Prompts. Runtime-owned limits, user cancellation, bounded control operations, output limits, and released Agent protocol compatibility remain intact. Desktop and Agent release metadata are synchronized at 0.11.13 with approved bilingual notes.

Release note: OpenCode 原生 Task 现在以独立子 Agent 展示;长任务不再被 GoodBuddy 固定总时限中止,并修复 OpenCode 启动识别、可配置 HTTP 服务地址与发布说明读取问题。
2026-08-30 17:18:33 +08:00
mesalogo 7c6f15d3c0 fix: allow HTTP for configurable service endpoints
DeepSeek Harness and Weixin binding configuration rejected non-loopback HTTP endpoints even when users explicitly selected those internal services. Configurable endpoints now accept valid HTTP and HTTPS URLs without host-location restrictions, while retaining the required protocol and API-key checks.

Release note: 模型连接、DeepSeek Harness 与微信绑定现在可直接使用局域网或公网 HTTP/HTTPS 服务地址,不再强制公网 HTTPS 或本机回环地址。
2026-08-30 16:49:47 +08:00
mesalogo 6dc219f3a3 fix: detect OpenCode readiness by health
GoodBuddy previously treated one exact OpenCode stdout line as the startup signal, so harmless log formatting differences could report a timeout even when the server was already listening. It now polls the authenticated health endpoint on the loopback port that GoodBuddy selected, with bounded attempts and the original ten-second startup limit.

Release note: 修复 OpenCode 已启动但因监听日志格式未被识别而误报超时的问题;启动检测现在直接使用本机健康接口。
2026-08-30 15:30:43 +08:00
mesalogo acc5a8e2d8 fix: allow slower OpenCode server startup
The bundled OpenCode server could be reported unavailable when slower Linux ARM systems needed more than ten seconds to initialize. GoodBuddy now allows thirty seconds for startup before terminating the server and reports the updated timeout.

Release note: 修复部分 Linux ARM 设备上 OpenCode 冷启动较慢时被误报为启动超时的问题。
2026-08-30 14:42:18 +08:00
mesalogo 9f0f231e3b chore: prepare GoodBuddy 0.11.12 release
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
GoodBuddy Agent Release / Authorize Agent release (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux arm64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux x64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Sign cumulative Agent catalog (push) Canceled after 0s
GoodBuddy Agent Release / Publish Agent to GitHub and OSS (push) Canceled after 0s
2026-08-30 11:08:55 +08:00
mesalogo 967796539f fix: recover remote conversations after uncertain prompts
An interrupted managed SSH prompt could leave its ACP binding as the permanent owner of the conversation, so every later user message failed with the same uncertain-recovery error. A later explicit prompt now retires that binding and starts a fresh ACP session without replaying the uncertain operation.

Ask-mode Runtime startup also waited on the wrong bubblewrap executable identity. The Agent now supervises the bounded transition to the signed Runtime or model-bridge executable, and the Agent version advances to 0.11.10.

Release note: 修复远程 ACP 请求中断后同一会话无法继续输入,以及 Ask 模式可能在模型调用前启动失败的问题。
2026-08-30 11:02:20 +08:00
mesalogo 8e08ab0bac feat: show Magic Notes update times
The Magic Notes list previously showed only each title, content preview, and
entry count, making similarly named or recently changed notes harder to scan.
Each note now shows its localized update time beside the entry count, with a
semantic timestamp and bounded single-line layout for the narrow list pane.

Release note: 魔法笔记左侧列表现在显示每篇笔记的本地化更新时间,便于快速找到最近修改的内容。
2026-08-30 10:09:39 +08:00
mesalogo edba31e873 chore: prepare GoodBuddy 0.11.11 release
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Bump the desktop package metadata to 0.11.11 and package the approved Simplified Chinese and English release notes for complete remote conversation saves and discoverable Magic Notes list shortcuts.

Release note: GoodBuddy 0.11.11 修复远程项目长工具结果的会话持久化,并补充魔法笔记列表快捷输入提示。
2026-08-30 09:33:58 +08:00
mesalogo 0804f5ccd2 fix: preserve complete remote tool details
Managed SSH Runtime events could complete successfully and then fail local conversation persistence when tool details exceeded a second, smaller renderer-to-Main schema limit. Conversation persistence now stores the complete tool details already accepted from the Runtime, so long remote results no longer leave the final assistant message stuck in a streaming state.

Release note: 修复远程项目工具结果较长时会话持久化失败的问题;Runtime 已返回的工具详情现在会完整保存到本地会话。
2026-08-30 09:29:28 +08:00
mesalogo 29639ff516 fix: surface Magic Notes list shortcuts
Magic Notes already accepted Quill's native bullet, numbered, and checklist
autofill, but the editor did not make those shortcuts discoverable or protect
them with behavior coverage. The composer now explains the supported markers
in both languages, and tests verify they continue producing Delta list formats.

Release note: 魔法笔记编辑区现在提示项目符号、编号和待办清单快捷输入;输入标记后按空格即可创建对应列表。
2026-08-30 09:20:27 +08:00
mesalogo 22c80b2d94 fix: align Linux Agent verifier regression
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
The Linux source validator still expected the full verifier's old payload mode
message after entrypoint metadata checks moved ahead of the payload loop. The
test now asserts the actual bounded entrypoint error returned by the optimized
verifier.

The unpublished desktop 0.11.9 notes move to 0.11.10. The Agent lock remains
on the successfully published Agent 0.11.9, and the recovery release still has
no LoongArch preview.

Release note: GoodBuddy 0.11.10 延续已批准的 Host 更新修复;未发布的桌面 0.11.9 由新版本替代。
2026-08-29 23:01:46 +08:00
mesalogo 85e14ca626 fix: make Host updates simple and fast
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
GoodBuddy Agent Release / Authorize Agent release (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux arm64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Build Linux x64 compound package (push) Canceled after 0s
GoodBuddy Agent Release / Sign cumulative Agent catalog (push) Canceled after 0s
GoodBuddy Agent Release / Publish Agent to GitHub and OSS (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
Host repair could fail while adopting the published OpenCode Runtime, then
repeat package and payload verification and carry durable metadata snapshots
for recovery. Host preparation now verifies each acquired compound archive
once, adopts signed Agent and Runtime metadata without rereading payload trees,
and retries failed work by cleaning staging and preparing fresh.

The desktop and Agent versions are advanced to 0.11.9 with the approved
bilingual release notes. Remote Projects remain a disabled-by-default technical
preview, Agent packages remain separate Linux x64/arm64 releases, and this
release has no LoongArch preview.

Release note: 修复 Host 更新采用失败,移除重复远端包体校验,并将中断恢复简化为清理暂存后重新准备。
2026-08-29 22:31:39 +08:00
93 changed files with 4361 additions and 2695 deletions
+113 -292
View File
@@ -4,26 +4,60 @@
These instructions apply to the entire repository.
GoodBuddy is a secure, cross-platform Electron desktop assistant. It uses
Electron, React, TypeScript, Vite, Vitest, and SQLite. User-facing copy is
primarily Simplified Chinese.
GoodBuddy is a cross-platform Electron desktop assistant for internal
organizational networks. It uses Electron, React, TypeScript, Vite, Vitest, and
SQLite. User-facing copy is primarily Simplified Chinese.
## Product Priorities
GoodBuddy is primarily an internal-network product. Unless the user states
otherwise, assume a trusted organizational environment, not a hostile public,
multi-tenant, or zero-trust deployment.
Use this order when requirements or implementation choices compete:
1. Working product functionality.
2. Performance and responsiveness.
1. Complete, working product functionality.
2. Measured performance and responsiveness.
3. Clear, low-friction user experience.
4. Simple, conventional, maintainable implementation.
5. Security controls proportional to a concrete, realistic risk.
5. Security controls only for a concrete risk in the actual deployment model.
Follow KISS and YAGNI. Do not add trust tiers, consent ceremonies, durable
state machines, protocol phases, cryptographic identities, quotas, recovery
machinery, or compatibility layers unless they are needed for an actual user
workflow or a demonstrated failure mode. Prefer the normal platform mechanism
and the smallest design that works. Test Hosts are test environments; do not
turn their workflows into production compliance exercises.
Functionality and performance are the primary acceptance criteria. Do not
disable, delay, restrict, or complicate a working product path for speculative
security hardening. Preserve the existing Electron, credential, user-data, and
release-signing boundaries, but do not expand them without a concrete current
risk or an explicit user requirement.
## Design Simplicity
Follow KISS and YAGNI. Use the smallest conventional design that completes the
real user workflow.
- A demonstrated failure authorizes only the smallest proportional fix, not a
general recovery, compatibility, or security framework.
- Prefer deleting bounded staging and retrying, idempotent operations, and
reconciliation from one authoritative source of truth. Do not persist copies
of state that can be derived or safely retried.
- Do not add durable snapshots, journals, versioned internal receipts, rollback
engines, compatibility readers, multi-phase state machines, protocol phases,
cryptographic identities, trust tiers, consent ceremonies, or quotas when
cleanup, retry, or reconciliation is safe.
- Before introducing any of that machinery, stop before coding. Explain the
reproducible current failure, why the simple alternative is insufficient,
and obtain the user's explicit approval for the added complexity. A reviewer
suggestion, test-only scenario, hypothetical crash, or possible future need
is not sufficient evidence.
- Performance outranks simplicity only for a measured bottleneck. Security
complexity requires a concrete threat at an actual trust boundary.
- Ignore hypothetical threats that require a hostile public network,
untrusted tenants, or zero-trust deployment unless that environment is an
explicit product requirement. Do not turn such findings into implementation
work.
- A complete workflow means the normal production path plus demonstrated
failure cases. It does not require exhaustive recovery from every
hypothetical interruption point.
- Test Hosts are test environments. Do not turn their workflows into production
compliance exercises.
When the user asks to implement a feature, deliver the complete usable user
workflow unless the user explicitly requests a prototype, scaffold, staged
@@ -48,7 +82,8 @@ work as the implemented feature.
- `build`: packaging scripts and icons.
- `out` and `dist`: generated output. Change source files instead.
Keep Electron security boundaries intact:
Keep these existing Electron security boundaries intact. They do not authorize
additional hardening beyond the actual internal-network threat model:
- Preserve context isolation and sandboxing.
- Never enable renderer Node integration.
@@ -77,7 +112,11 @@ Keep Electron security boundaries intact:
## Data and Compatibility
- Preserve existing user data and migrations.
- Preserve released user-owned data, migrations required by released data, and
supported external contracts.
- Compatibility does not apply to unshipped, branch-local, or safely disposable
internal operation records. Replace or discard those records instead of
adding migrations, legacy readers, versioned receipts, or recovery machinery.
- Do not weaken SQLite transaction, lifecycle, deduplication, or cleanup logic.
- Treat user workspaces and untracked files as user-owned.
- Keep Windows, macOS, Linux x64, and Linux arm64 behavior in mind.
@@ -88,6 +127,10 @@ Keep Electron security boundaries intact:
- Follow surrounding TypeScript and React patterns.
- Reuse installed libraries and shared contracts before adding dependencies.
- Keep changes focused. Do not add unrelated refactors or documentation.
- Reviewer findings do not expand task scope. Implement a finding only when it
identifies a reachable current failure, a released compatibility contract,
or reproducible user-visible harm. Record speculative concerns without
building machinery around them.
- Validate the real end-to-end path, not only schemas, mocks, injected test
doubles, or isolated infrastructure. A feature is not complete until its
normal UI action reaches the production implementation and produces the
@@ -180,287 +223,28 @@ mode.
Release note: 修复左上角项目设置与消息通道项目设置不一致的问题;现在从任一入口修改后,另一处会同步显示相同配置。
```
## Release Packaging
## Releases
- Unless the user explicitly requests a local Windows package, never run local
Windows packaging or launch probes as part of release preparation. In
particular, do not run `npm run portable`, Windows
`npm run release:package`, direct `electron-builder` packaging, or launch a
locally packaged Windows app before publishing a release. Source validation
and the native GitHub Actions jobs are the release authorities.
- After a release is published, confirm only that the expected Windows assets
exist in the public release metadata. Do not locally rebuild or launch the
Windows package, download or hash published installers, attach browser
automation to a packaged app, or perform exhaustive per-asset network probes
unless the user explicitly asks for that additional validation.
- `.github/workflows/packages.yml` is the canonical cross-platform packaging
workflow. It validates and builds `out` once, then packages on six native
runners: Windows, macOS, and Linux, each for x64 and arm64.
- The experimental Linux LoongArch (`loong64`) preview is built separately
through `build/loongarch-cross` by following
`docs/development/loongarch-preview-build.md`. It is not part of
`.github/workflows/packages.yml`, the six-runner GitHub Actions matrix,
standard release manifests, GitHub Release asset expectations, or the
production update index. Do not add it to those paths unless the user
explicitly requests a future production-support migration.
- Run the unified packager with
`npm run release:package -- --platform <platform> --arch <arch>`. It only
packages for the native host and writes to
`dist/release/<platform>-<arch>`.
- Default deliverables are NSIS and portable ZIP for Windows, DMG and ZIP for
macOS, and AppImage, DEB, and RPM for Linux. Every target includes
`release-manifest.json` with SHA-256 hashes.
- `build/build-release.cjs` verifies the unpacked application, `app.asar`,
bundled Continue and OpenCode runtimes, executable architecture, and package
signatures before atomically replacing a release directory.
- All desktop build paths, including local `portable`, package the Agent and
remote Runtime version locks plus the public signing-key registry without
embedding installable Linux Agent or remote Runtime payloads. Managed SSH is
optional: users explicitly download a compatible compound `.gbagent` package
from Settings or import one offline before GoodBuddy can install or update a
Host.
- Each independently published Linux x64 or arm64 `.gbagent` contains the
Agent daemon, pinned Node, and the desktop-maintained compatible OpenCode
Runtime. Build both architectures on native GitHub Actions runners from one
immutable `agent-v<agentVersion>` tag.
- Keep the GoodBuddy Agent source, shared protocol/contracts, runtime lock,
bundle tooling, and tests in this repository so a desktop commit identifies
the exact Agent source it expects. Do not create a separate Agent repository
or long-lived Agent release branch unless the Agent becomes an independently
released product serving multiple clients.
- `.github/workflows/agents.yml` is the branch and pull-request build
verification workflow for GoodBuddy Agent. It must build Linux x64 and
arm64 on native runners from the checked-out commit, acquire the locked
official Node archive and locked OpenCode npm archive, verify every locked
digest, use only an ephemeral in-memory test signing identity, and verify the
resulting compound package and deterministic archive. It must not read
production signing secrets, publish installable release artifacts, or modify
the checked-in public key registry.
- `.github/workflows/agent-release.yml` is the only production compound Agent
publication path. It requires an annotated immutable Agent tag, the protected
`agent-signing` Environment, native x64/arm64 builds, one production
GoodBuddy signing identity for every layer of the compound package and
catalog, a non-Latest GitHub Agent Release, and synchronized immutable
Beijing OSS objects plus the final signed latest-catalog pointer.
- `.github/workflows/packages.yml` and `release:package` build only desktop
products. Missing Agent packages, remote Runtime inputs, or GoodBuddy signing
credentials must never block an ordinary desktop package or release.
- Keep electron-builder invocations on `--publish never`. Main-branch builds
run validation and build the production bundle without running the native
package matrix. Manual builds upload 30-day GitHub Actions artifacts.
Version-tag builds verify and aggregate packages before publishing GitHub
Release assets. The macOS jobs sign, notarize, and verify packages when all
five Apple credentials are configured. With no Apple credentials they must
use the explicit `--unsigned` path, warn that Gatekeeper may block the
packages, and still complete; a partial credential set must fail rather than
silently downgrade.
- Keep `ELECTRON_CACHE` and `ELECTRON_BUILDER_CACHE` under
`${{ runner.temp }}` in step-level workflow contexts. A cache beneath the
repository inherits the root `"type": "module"` and breaks electron-builder's
CommonJS macOS icon tool.
- Tag builds must use `v${package.version}`. The workflow also supports manual
dispatch and main-branch changes to release tooling.
Detailed release operations are governed by
[`docs/development/release-runbook.md`](./docs/development/release-runbook.md).
Read that runbook only when preparing, publishing, recovering, or verifying a
desktop or GoodBuddy Agent release. It is an operator and CI procedure, not an
authorization to add product persistence or recovery machinery.
### Agent Release Process
Repository-wide release invariants:
- Agent releases use annotated `agent-v${agent-runtime-lock.agentVersion}` tags
and are separate from desktop `v${package.version}` releases. Confirm the
exact Agent release commit and tag with the user before creating or pushing
either.
- The tagged commit must be reachable from protected `main`. The two native
jobs build the compound x64/arm64 packages from the same source and locks;
the catalog job rejects missing architectures, changed bytes for an existing
version/architecture identity, invalid prior signatures, and incompatible
matrix metadata.
- Agent GitHub Releases are ordinary non-draft, non-prerelease releases but
must use `--latest=false`; they must never replace the desktop release marked
Latest. Publish immutable packages and the versioned catalog to
`agent-releases/v<agentVersion>/` in Beijing OSS, publish the GitHub Agent
Release, then atomically update the single `agent-releases/latest.json`
pointer to that version's immutable catalog and signature.
- Do not report an Agent release complete until both public package
architectures match the signed catalog by size and SHA-256, the GitHub and
OSS catalog bytes/signatures are identical, the application can read the
selected source, and GitHub's repository Latest tag remains the desktop tag.
### Tagged Release Process
Every version-tag release must follow this sequence. A branch-only push does
not require release notes.
1. Confirm that the user wants a release tag and identify the exact release
commit and the new `package.json` version. Separately ask whether this
release should also receive an experimental LoongArch preview build; never
infer that choice from an earlier release.
2. Find the latest stable version tag reachable before the release commit and
inspect the complete commit and file diff from that tag to the release
commit. For the first tagged release, inspect the relevant repository
history instead.
3. Draft concise, user-facing release notes in both Simplified Chinese and
English based only on verified changes in that range. Use the titles
`GoodBuddy <version> 更新内容` and
`What's New in GoodBuddy <version>`, with corresponding `功能更新` /
`Features` and `问题修复` / `Bug Fixes` sections when applicable. The two
language versions must describe the same changes. Do not expose
internal-only details, credentials, private content, or unverified claims.
4. Show the exact bilingual release-note draft to the user and wait for
explicit approval. If the release commit or either language version changes
after approval, inspect the updated tag range and request approval again.
5. Write the approved notes to the single entry for the release version in
`resources/release-notes.json`. A failed unpublished candidate whose content
is carried forward must not retain a duplicate packaged entry.
6. Verify that `package.json`, the root `package-lock.json` version, and
`package-lock.json.packages[""].version` all equal the release version. Run
`npm run release:notes:verify`, the required source validators, the
production build, and any native candidate launch probe available on the
current host. The six native CI jobs remain the cross-platform authority.
If the user requested a LoongArch preview in step 1, build it separately
from this exact candidate by following the LoongArch build document, record
its size and SHA-256, and keep it outside the standard GitHub/OSS release
asset set unless the user separately authorizes publishing it.
7. Fetch both remotes immediately before tagging. Inspect any remote branch
movement instead of overwriting or silently merging it. Confirm the working
tree is clean, the candidate tag is unused locally and remotely, and the
exact approved commit has not changed.
8. Only after all previous steps pass, create an annotated
`v${package.version}` tag at the exact approved commit. Push `main` to
`origin` and `github`, verify both branch SHAs, then push the tag to both
remotes and verify each peeled tag SHA (`refs/tags/<tag>^{}`) equals the
release commit.
9. Keep both approved language versions as the single source for the GitHub
Release body and the packaged first-open release-notes modal. The modal
displays the release notes matching the current interface language and
contains no button linking to a full release page.
10. Observe the tag workflow through publication and complete the public
verification checklist below. A successful push is not a completed
release.
### OSS Publication Contract
The tagged release job publishes through the GitHub Environment selected by
`.github/workflows/packages.yml` (`aliyun-oss-release`) and reads the following
effective GitHub Actions variables. Before a release or same-tag rerun can
publish, verify that repository-, organization-, or environment-level
resolution exposes:
- `ALIYUN_OSS_BUCKET=goodbuddy`
- `ALIYUN_OSS_ENDPOINT=https://oss-cn-beijing.aliyuncs.com`
- a non-empty `ALIYUN_OIDC_PROVIDER_ARN` matching
`acs:ram::*:oidc-provider/*`
- a non-empty `ALIYUN_ROLE_ARN` matching `acs:ram::*:role/*`
For environment-scoped values, use the exact Environment name from the
workflow; do not assume a similarly named UI environment such as `Production`
contains the active variables.
The Bucket and Endpoint are a deployment contract, not interchangeable
examples. They must stay aligned with the trusted URL checks in
`src/main/version-checker.ts`, `sites/app.js`, website validation, and related
tests. A host, Bucket, Region, or CDN migration must update and validate every
surface together before a new release.
- Use GitHub OIDC and the RAM Role to obtain short-lived STS credentials.
Never add long-lived AccessKeys to repository or environment secrets.
- Keep `ossutil` pinned. Its V4 signing requires the Region; derive it from the
canonical Endpoint, verify that the production value resolves to
`cn-beijing`, and pass `--region` to every `ossutil cp`, including the final
`latest.json` update.
- Grant the RAM Role only the actions and prefixes required by the workflow.
It must be able to write immutable version objects and the final latest
pointer without granting unrelated administration privileges.
- Upload release assets and `site-release.json` under the immutable
`releases/<tag>/` prefix first. Verify all 14 installer URLs publicly before
creating or publishing the GitHub Release. Update
`releases/latest.json` only after the GitHub Release is public and all prior
checks succeeded.
- The expected GitHub Release contains 22 assets: 14 installers (two formats
for each Windows/macOS target and three formats for each Linux target), six
renamed target manifests, one aggregate `release-manifest.json`, and one `SHA256SUMS`.
`site-release.json` is an OSS publication artifact, not a GitHub Release
asset.
### Failed Tag Recovery
Classify a failed tag by the external side effects that completed before
choosing a recovery:
- If no source or release metadata must change, correct only the external
configuration and use **Re-run failed jobs** for the same immutable tag. Do
not change, move, delete, or recreate the tag.
- If immutable OSS objects were partially uploaded but their source bytes are
unchanged, a same-tag rerun may idempotently re-upload or verify them. Never
point `latest.json` at a partially verified prefix.
- If the GitHub Release is already public but the final latest-pointer step
failed, it is a published version. Keep its packaged notes and rerun the
failed release job for the same tag; do not classify it as an unpublished
candidate.
- If code or release metadata must change, keep the failed tag immutable,
increment the patch version, obtain approval for the revised exact release
commit and notes, and create a new tag. Do not reuse the failed version.
When recovering from a version tag whose workflow never published a public
GitHub Release:
- If a code or metadata change requires a higher version and a new tag, carry
the failed candidate's approved user-facing notes forward into the recovery
version, then remove the superseded failed version's entry from
`resources/release-notes.json`.
- The packaged first-open modal must show that carried-forward content only
once under the recovery version. Never retain both the failed version and
its cumulative recovery copy, because users upgrading across them would see
duplicate content.
- Never remove the packaged history for a version that successfully published
a GitHub Release. Verify the failed release state before treating an entry as
superseded.
### Post-Publication Verification
Do not report a release complete until all of the following are verified:
1. The tag workflow and all six native package jobs succeeded. Verify the
recorded macOS signing mode: signed builds must pass `codesign`, `spctl`,
and `stapler`; unsigned builds must record the Gatekeeper caveat in the
Actions log and job summary. In the final release job, explicitly verify
the OSS configuration, OIDC authentication, release-index generation,
immutable upload, public asset check, GitHub Release publication, and
latest-pointer steps.
2. The public GitHub Release is non-draft, non-prerelease, marked Latest, and
uses the expected tag and title. Its body must exactly match the Markdown
generated from the approved packaged bilingual notes.
3. The GitHub asset set has exactly the expected 22 names and every asset is
uploaded. Compare installer sizes and SHA-256 digests with the aggregate
manifest and `SHA256SUMS`.
4. The Beijing `releases/latest.json` returns HTTP 200, has the expected stable
version, exact six targets and 14 installer entries, the trusted Beijing
URLs, and the GitHub fallback URL. It must match the immutable
`releases/<tag>/site-release.json`.
5. All 14 public installer URLs accept `HEAD` without redirects and report the
declared size. For small JSON/checksum metadata, prefer a `GET` byte and
digest comparison; OSS may gzip JSON responses and omit an uncompressed
`Content-Length` on `HEAD`.
6. The live website successfully fetches the index and produces the 14 correct
platform/architecture/format links. Exercise the application's actual
mirror checker against the public index for all six targets.
7. Both remote `main` refs and both peeled tag refs still equal the approved
release commit, and the local working tree is clean.
Never create or push a release tag, and never push a previously created
release tag, before the release-note draft has received explicit approval.
- Before a push that updates the `github` remote, ask whether the user wants a
release tag unless they already specified that choice. A branch-only push
does not require a version bump or tag. When the user requests a release,
verify that `package.json` and `package-lock.json` contain the same release
version, create `v${package.version}` at the exact commit being pushed, and
push that tag so the native package matrix and GitHub Release run.
- Never move or reuse an existing release tag. If `v${package.version}` already
exists locally or on a remote at another commit, increment the package
version and create a new matching tag before the release push.
- Verified release baseline on 2026-08-18: commit
`60119a4317118fa3f077db0382664f15266a6682`, annotated tag `v0.10.4`, and
GitHub Actions run `32038633609` attempt 2 succeeded through all six native
packages, GitHub Release publication, Beijing OSS publication, and the final
`latest.json` switch.
- Never create or push a release tag before the user approves the exact release
commit and bilingual release notes.
- Never move, delete, recreate, or reuse a release tag.
- Keep desktop and Agent release paths, tags, artifacts, and Latest status
separate.
- Native GitHub Actions jobs are the cross-platform packaging authority. Never
run local Windows packaging or packaged-app probes unless the user explicitly
requests them.
- LoongArch is a separate experimental preview. Build or publish it only when
the user explicitly requests it for that release.
- Never commit or publish credentials. Production publication uses the existing
protected environments and short-lived credentials described in the runbook.
## Validation
@@ -481,10 +265,47 @@ possible, and report the exact call count. This standing authorization does
not cover bulk, high-cost, destructive, publishing, messaging, purchasing, or
other consequential external actions.
### GoodBuddy Agent development validation
Every source change that can alter the deployed GoodBuddy Agent or the
desktop-to-Agent production path must be validated on the shared Linux x64 test
Host while the change is being developed. This includes Agent daemon and
protocol changes, packaging and installation, attach/update behavior, Runtime
launch and process ownership, workspaces, model bridges, and lifecycle or
recovery behavior. Unit tests, mocks, fixtures, CI, and waiting for release
validation are not substitutes for this development-time check.
- Reach the shared Host at `192.168.0.23` on the LAN when available, otherwise
use `10.7.0.23` over VPN. These are two routes to the same physical machine,
not two independent test targets or architecture results.
- Exercise the current source or package under development, not only the
previously published Agent. Run the affected production path as soon as it is
runnable and repeat the relevant scenario after the final change.
- Select the real-Host scenario from the changed surface: attach/bootstrap or
update for installation changes; Ask/Execute and a bounded real model request
for Runtime or model-bridge changes; and the applicable disconnect, restart,
cancellation, or reconnection sequence for lifecycle and recovery changes.
- Use the existing pinned Host identity and GoodBuddy credential storage. Never
add credentials to source, documentation, commands, logs, or test output, and
never hard-code these test addresses into product behavior or defaults.
- Keep all artifacts in GoodBuddy-owned test directories. Before stopping or
changing a remote process, verify that it belongs to the test run; never
modify unrelated Host files or processes.
- If neither route is reachable, report the real-Host validation as blocked and
do not present the Agent work as complete or defer its first real validation
to release time.
The detailed scenario rules are documented in
[`docs/architecture/remote-host-and-goodbuddy-agent-design.md`](./docs/architecture/remote-host-and-goodbuddy-agent-design.md).
Before committing or pushing, inspect `git status`, `git diff`, and
`git diff --cached`. Do not commit secrets, local databases, logs, generated
credentials, or private user artifacts.
Before a push that updates the `github` remote, ask whether the user wants a
release tag unless they already specified that choice. A branch-only push does
not require a version bump or tag.
This repository has two synchronized remotes, `origin` and `github`. Unless the
user explicitly names a remote, every requested push must update the current
branch on both remotes. When the user requests a release tag, push the new tag
+8 -9
View File
@@ -172,13 +172,12 @@ JSON。签名目录、包描述符、manifest、签名和 payload 的原始字
两种 acquisition 都把同一签名 compound `.gbagent` 交付到固定 operation staging,随后
共用 control-plane `prepare → commit → Agent activate/health → Runtime activate →
finalize → cleanup`。commit 终态持久化,通道丢失时只用 `commit-status` 读取恢复而不
重新下载或准备包;若终态文件不完整,`commit-status` 会从已认证准备状态幂等完成剩余
rename/metadata 发布。prepare 完成后、commit 前快照 Agent/Runtime 五个 metadata 文件;任一 adoption 失败恢复
原字节或原缺失状态,已发布 side-by-side payload 不成为 current,确认 adoption 后显式
cleanup。Host 在 prepare 解包时完成一次完整 payload 校验;commit 只复核签名 metadata
finalize → cleanup`。Main 只持久化清理 operation staging 所需的 operation ID,不保存
Agent/Runtime metadata 副本。操作中断或 adoption 失败后,下一次更新尽力清理旧暂存并
重新 prepare,不恢复或续写旧操作。确认 adoption 后显式 cleanup。Host 在 prepare
解包时完成一次完整 payload 校验;commit 只复核签名 metadata
并原子发布,Agent/Runtime 注册后的 health、capabilities 和 prompt 启动不再遍历或哈希
完整 payload。cleanup 失败保留为维护重试,不回滚已健康环境。
完整 payload。cleanup 失败不回滚已健康环境,也不阻塞下一次 fresh prepare。
进入“主机与远程执行”设置页只读取本地 Host 列表,不逐台连接。用户点击某台 Host 的
“刷新版本”后才执行远端版本和直连准备能力探测。项目切换只更新本地选择,不建立 SSH
@@ -220,9 +219,9 @@ Agent、固定 Node 和当前桌面源码维护并适配的签名 OpenCode Runti
独立的用户版本流。远程直连所需的有界 one-shot installer 由桌面控制面打包并通过固定
SSH prepare channel 发送,不是 `.gbagent` 的必需条目。Host 按签名目录校验完整归档
大小和 SHA-256 后,包内固定 Node 解码并运行 installer。两种 acquisition 都在固定
operation staging 中执行同一 prepare/commit;commit 终态持久化,`commit-status`
可读取终态或从已认证准备状态幂等完成中断的发布。Agent/Runtime adoption 使用 commit 前五个 metadata 文件的原字节
或原缺失状态回滚,已发布 side-by-side payload 不会因此成为 current。生产构建命令为:
operation staging 中执行同一 prepare/commit;本地 pending record 只保存清理暂存所需的
operation ID。失败或中断后的下一次更新尽力清理旧暂存并重新 prepare,不保存或恢复
Agent/Runtime metadata 副本。生产构建命令为:
```bash
node build/agent-package.cjs build \
+2 -2
View File
@@ -23,8 +23,8 @@
- [x] **直连模型 Runtime**:支持问答、知识总结、受控工具执行和图像生成。
- [x] **OpenCode 与 Continue**:使用隔离子进程、环境变量白名单、统一配置、取消、总执行时限、有界流式输出和活动记录;共享进程回收逻辑保留 Windows 完整进程树终止,并对采用独立进程组的 POSIX 子进程执行组回收。交互提问只由前台对话回答,定时任务、远程通道和委派等后台执行遇到提问时会立即失败并提示改为前台运行,避免无限等待。
- [x] **托管 SSH OpenCode 闭环(技术预览)**:该能力由“设置 > 平台功能”中的独立“远程项目(技术预览)”页签控制并默认关闭;关闭时不影响任何本地项目、普通桌面功能或桌面发布。启用后可管理固定 Host Key 的 SSH Host、浏览有界远端目录并创建 Ask/Execute 项目;Ask 在 Runtime 边界通过 bubblewrap 保持 Workspace 只读,Execute 使用所选 SSH 账号的完整权限。Main 通过签名 Agent、私有 Unix socket、ACP v3、持久恢复 cursor 和 Main-only 模型桥维持长任务、重连与会话恢复,模型凭据不进入远端。远端组件不嵌入桌面包,项目切换只更新本地选择且不会连接或下载;设置页只读取小型签名目录并按 Linux x64/arm64 显示本地版本、在线最新兼容版本和“有更新/已是最新”,用户点击后才下载签名 `.gbagent`,也可导入/导出离线包。每个复合包包含 Agent、固定 Node 与由桌面源码统一维护适配的 OpenCode Runtime;在线来源跟随“关于与更新”的 GitHub/北京 OSS 选择,签名累计目录绑定最低桌面版本、Agent 协议、架构、大小、SHA-256 和固定 URL。公钥 registry 接受等价 JSON 空白和换行,但仍严格校验 schema、Ed25519 key、环境与撤销;目录、包、manifest、payload 签名和流式 SHA-256 不变。缺少某架构包只使该架构托管 SSH 不可用。项目只保存 Host、远端路径、Runtime 选择和模式;首次实际使用 Workspace/Runtime 时读取 Host current identity,同一进程内其他项目复用已确认 identity 和 Agent 连接。托管 SSH 会话只显示支持的 OpenCode 选择。同一 Host 可并行运行多个项目和对话;活动请求沿精确 resume/replay 恢复,controller 换代遗留的空闲 binding 只在 takeover 已证明且没有活动请求时换新 channel epoch 并恢复原 ACP session。Windows 到 Linux x64 的安装、provider-free 模型桥、断线重放、Session 续接和零残留清理已完成真实 Host 验证;签名 Agent 0.11.2-e2e.12 与 OpenCode Runtime 1.18.9 已完成一次只提交一遍、只调用一个 Ask 原生 read、无标题轮次且精确返回证据内容的有界真实模型验收,当前源码 lock 已更新为 Agent 0.11.8。
- [x] **SSH Host 手动环境准备源码链路**:Host Key、认证和系统探针成功后先保存 Host,并只读探测共享 Agent/Runtime;保存 Host、打开项目都不自动安装。Host 卡片只有一个按版本事实显示“安装远程环境”“更新远程环境”或“重新安装”的主按钮,次级 SegmentedControl 选择默认且不持久化的“自动”、Host 下载或 GoodBuddy 传输;“版本匹配”badge 不等同环境健康。自动模式只在 operation/prepare 前探测并择一,显式选择保持有效,任何 prepare、commit 或 adoption 失败都不跨 acquisition 自动 fallback。两种方式把同一签名 compound `.gbagent` 交付到固定 staging 后,共用 control-plane prepare、持久化 commit、Agent activate/health、Runtime activate、finalize 与显式 cleanup。GoodBuddy 路径可在同一次操作下载并验证缺失候选、缓存并取得 lease,再有界流式 SFTP 上传一个归档和其中已验证的 bootstrap Node,不把约 294 MiB 整包读入 Main `Buffer`;Host 在解包时完成一次完整 payload 校验。通道丢失时 `commit-status` 读取终态或从已认证准备状态幂等完成中断发布;组件 adoption 失败恢复 Agent/Runtime 五个 metadata 文件的原字节或原缺失状态,已健康环境的 cleanup 失败不触发回滚。已有项目在实际使用 Workspace/Runtime 时按需解析 Host current identity 并执行固定 `attach-or-bootstrap`,注册后的 health、capabilities 和 prompt 启动不扫描完整 payload。详见 [设计说明](./docs/architecture/remote-host-environment-provisioning-design.md)。
- [x] **托管 SSH OpenCode 闭环(技术预览)**:该能力由“设置 > 平台功能”中的独立“远程项目(技术预览)”页签控制并默认关闭;关闭时不影响任何本地项目、普通桌面功能或桌面发布。启用后可管理固定 Host Key 的 SSH Host、浏览有界远端目录并创建 Ask/Execute 项目;Ask 在 Runtime 边界通过 bubblewrap 保持 Workspace 只读,Execute 使用所选 SSH 账号的完整权限。Main 通过签名 Agent、私有 Unix socket、ACP v3、持久恢复 cursor 和 Main-only 模型桥维持长任务、重连与会话恢复,模型凭据不进入远端。远端组件不嵌入桌面包,项目切换只更新本地选择且不会连接或下载;设置页只读取小型签名目录并按 Linux x64/arm64 显示本地版本、在线最新兼容版本和“有更新/已是最新”,用户点击后才下载签名 `.gbagent`,也可导入/导出离线包。每个复合包包含 Agent、固定 Node 与由桌面源码统一维护适配的 OpenCode Runtime;在线来源跟随“关于与更新”的 GitHub/北京 OSS 选择,签名累计目录绑定最低桌面版本、Agent 协议、架构、大小、SHA-256 和固定 URL。公钥 registry 接受等价 JSON 空白和换行,但仍严格校验 schema、Ed25519 key、环境与撤销;目录、包、manifest、payload 签名和流式 SHA-256 不变。缺少某架构包只使该架构托管 SSH 不可用。项目只保存 Host、远端路径、Runtime 选择和模式;首次实际使用 Workspace/Runtime 时读取 Host current identity,同一进程内其他项目复用已确认 identity 和 Agent 连接。托管 SSH 会话只显示支持的 OpenCode 选择。同一 Host 可并行运行多个项目和对话;活动请求沿精确 resume/replay 恢复,controller 换代遗留的空闲 binding 只在 takeover 已证明且没有活动请求时换新 channel epoch 并恢复原 ACP session。Windows 到 Linux x64 的安装、provider-free 模型桥、断线重放、Session 续接和零残留清理已完成真实 Host 验证;签名 Agent 0.11.2-e2e.12 与 OpenCode Runtime 1.18.9 已完成一次只提交一遍、只调用一个 Ask 原生 read、无标题轮次且精确返回证据内容的有界真实模型验收,当前源码 lock 已更新为 Agent 0.11.9。
- [x] **SSH Host 手动环境准备源码链路**:Host Key、认证和系统探针成功后先保存 Host,并只读探测共享 Agent/Runtime;保存 Host、打开项目都不自动安装。Host 卡片只有一个按版本事实显示“安装远程环境”“更新远程环境”或“重新安装”的主按钮,次级 SegmentedControl 选择默认且不持久化的“自动”、Host 下载或 GoodBuddy 传输;“版本匹配”badge 不等同环境健康。自动模式只在 operation/prepare 前探测并择一,显式选择保持有效,任何 prepare、commit 或 adoption 失败都不跨 acquisition 自动 fallback。两种方式把同一签名 compound `.gbagent` 交付到固定 staging 后,共用 control-plane prepare、commit、Agent activate/health、Runtime activate、finalize 与显式 cleanup。GoodBuddy 路径可在同一次操作下载并验证缺失候选、缓存并取得 lease,再有界流式 SFTP 上传一个归档和其中已验证的 bootstrap Node,不把约 294 MiB 整包读入 Main `Buffer`;Host 在解包时完成一次完整 payload 校验。未完成操作只记录暂存 cleanup 所需的 operation ID;下次更新尽力清理旧暂存后重新 prepare,不保存远端 metadata 副本,也不让 cleanup 失败阻塞新更新或回滚健康环境。已有项目在实际使用 Workspace/Runtime 时按需解析 Host current identity 并执行固定 `attach-or-bootstrap`,注册后的 health、capabilities 和 prompt 启动不扫描完整 payload。详见 [设计说明](./docs/architecture/remote-host-environment-provisioning-design.md)。
- [ ] **SSH Host 环境准备真实 Host 验收**:源码已可使用当前 format v1 包;仍需完成 GitHub、北京镜像、Linux x64/arm64、取消和离线 GoodBuddy 传输的真实 Host 验收。当前状态不表示已发布或已完成真实 Host 测试。
- [x] **DeepSeek Harness(预览)**:使用 GoodBuddy 固定 Host 和 OpenAI 兼容模型连接;Ask 只允许调用 Host 中真实注册的 `read`、`skill` 以及 Main 管理的 Web Search/Fetch 代理,拒绝插件同名冒充,Execute 放行全部已启用内置及插件工具,并以当前用户权限运行。图像输入跟随所选模型连接的能力声明,文本模型在 Host 或模型调用前拒绝图片,图片模型通过有界内联内容和临时 Attachment Store 接收 JPEG/PNG。
- [x] **DSH npm 插件市场**:市场默认关闭,由用户显式开启后搜索公共 npm 的 `dsh-plugin` 包,使用捆绑 npm 执行精确版本安装和普通 lifecycle scripts,并支持启停、JSON 配置、移除、失败启动自动停用和离线管理已安装插件;关闭市场只隐藏目录与管理界面,不改变已有插件的启停状态,第三方代码不受 Ask 初始化隔离。
+3
View File
@@ -553,6 +553,7 @@ GoodBuddy 是可调整窗口大小的桌面应用。响应式设计优先保证
- OpenCode、Continue 和 DeepSeek Harness 后续的 Task 级委派与取消、后台执行进度/结果、Workflow/Hook 运行、长任务暂停/恢复/终止及原生会话监督统一进入应用级助手工作栏固定的“Runtime”栏目,不加入 Composer。栏目入口始终存在;只选择 Conversation 或 Task,并按 Task 聚合执行状态,不显示 Job/Run 树或独立操作菜单。内部可选区域按用户所选目标和 Runtime 的真实能力显示,不为未支持能力渲染空卡片或成排禁用按钮。切换跟随目标时必须清理上一归属的监督状态,固定目标则保持不变。
- 设置中心只管理持久 Runtime 配置、默认值和能力清单;右侧 Runtime 栏目管理用户当前跟随或固定目标的生命周期。两处不得复制同一实时操作,栏目中的高风险操作仍须就地确认并保留取消、权限、用量和活动审计。
- Runtime Prompt 快捷操作只把模板填入输入草稿,用户可以继续编辑;OpenCode Command 由 Runtime 原生 API 执行,输入框只承载可选参数,不以普通斜杠文本冒充执行。
- OpenCode 原生 Task 调用在本地项目和托管 SSH 项目中统一解析为子 Agent 状态卡,不显示为普通工具卡。状态卡持续显示 Agent 类型、任务说明、运行状态、完成输出或失败原因;身份徽标、Agent 名称和状态位于首层,任务说明作为主信息,Runtime 来源作为次级元数据,输出与错误在同一卡片内按需展开。父 Agent 的推理不冒充子 Agent 过程,必须与状态卡保持明确间距。状态不能只靠颜色表达。推理、子 Agent、工具和正文统一按事件首次出现顺序进入消息块;增量更新只更新原位置,Task 临时工具块重分类后必须原位替换,不能把子 Agent 卡统一提升到消息顶部。同一调用的增量事件按稳定调用 ID 更新,不能因 ACP 首帧尚无参数而永久保留重复工具卡或活动记录。一次请求内已观察到的子 Agent 均保留在消息与活动记录中;父请求取消、失败或意外中断时仍处于活动状态的卡片必须结算为对应终态,父请求成功结束但子 Agent 未报告终态时必须显示为失败而不是推断为完成。
- Agent 回复进行中锁定模型、专家角色、工作模式和 Runtime 定制选择器,并关闭已打开的上下文菜单;回复结束或停止后再恢复选择,避免界面状态与本次运行实际使用的上下文不一致。
- Agent 回复进行中不能禁用普通消息发送。新消息与到期 Scheduled Task 共用 Conversation 级待发送队列。队列位于 Composer 容器之外、与输入框等宽并保持独立间距;有待发送项时直接显示无标题栏的极简列表,空队列不保留占位。每项固定为一行,按进入顺序显示轻量来源图标和截断摘要;普通消息使用消息图标,Scheduled Task 统一使用淡出时钟图标。
- 待发送项默认在当前回复结束后顺序执行。每项提供明确的“立即中断并插入”(空闲时为“立即运行”)和删除操作;前者先取消当前 Conversation 的活动执行,再将所选项提升为下一项,不允许同一 Conversation 并发写入时间线。
@@ -625,6 +626,8 @@ GoodBuddy 是可调整窗口大小的桌面应用。响应式设计优先保证
- “笔记 / 待办”属于同一工作台内的同级内容面板,使用 `PageTabs` 的 `segmented` 视觉变体,与模型设置的分段控件保持同一外观。
- 页签切换保留 `tablist`、`tab` 和 `tabpanel` 语义;待办状态仍使用独立的 `SegmentedControl`,不得与内容页签合并。
- 笔记编辑器保留 Quill 原生列表快捷输入:输入 `-`、`*`、`1.`、`[ ]` 或 `[x]` 后按空格,分别转换为项目符号、编号或待办清单。快捷输入只生成现有 Delta 富文本,不引入 Markdown 源码模式、第二套持久化格式或第三方 Markdown 插件;编辑区附近持续提供简短提示。
- 左侧笔记列表依次显示标题、最多两行内容预览,以及同一行的记录数和本地化更新时间。记录数靠左、更新时间靠右,窄宽度下均保持单行省略,不挤压标题或扩大列表栏。
- 左侧“魔法笔记”入口可显示未完成待办数量。数量为 0 时隐藏徽标,超过 99 时显示 `99+`,可访问名称仍说明精确数量;勾选、取消勾选以及 Agent / MCP 对笔记清单的写入都必须刷新数量。
- 未完成待办徽标的高度不得超过主导航图标;数量从 0 变为可见或再次隐藏时,主导航项行高和相邻菜单位置必须保持不变。
- 在待办面板勾选或取消勾选后,当前缓存中的源笔记正文必须立即同步对应清单状态,不得依赖离开工作区后重新加载。
+1 -1
View File
@@ -1,6 +1,6 @@
{
"formatVersion": 1,
"agentVersion": "0.11.8",
"agentVersion": "0.11.13",
"protocol": {
"major": 2,
"minor": 0
@@ -163,7 +163,7 @@ Electron utilityProcess
├─ 本地 Shell / Filesystem Provider
├─ 最小工具集与 Main 代理 MCP
└─ Main 明确启用的第三方 Cordis 插件
│ HTTPS
│ HTTP/HTTPS
▼
用户选择的 OpenAI 兼容模型连接
```
@@ -325,12 +325,13 @@ GoodBuddy conversationId -> Harness sessionId + process generation
- 历史以明确的“不可信会话数据”结构传入,不能拼接成系统指令。
- 用户分配的 Skill 只通过 Main 校验的包路径进入 Host,并在 Agent scope 注册;不得把 Skill 内容伪装成用户 Prompt。
### 9.3 取消与超时
### 9.3 取消与有界控制操作
- 用户取消时立即发送 `session/cancel`。
- 取消等待有界,超时后关闭连接并终止整个 Harness 进程。
- 初始化、握手、Session 创建、Prompt、权限回传和关闭分别使用独立超时。
- Prompt 超时与用户取消使用不同错误类型,不能被宽泛 catch 抹平。
- 初始化、握手、请求准备、权限回传和关闭分别使用独立控制超时。
- 生产 Prompt 不设置固定墙钟总时限,由 Harness 自身协议终态或用户取消结束。测试可以
显式注入短 Prompt 时限验证取消传播,超时错误与用户取消仍不能被宽泛 catch 抹平。
- 取消后仍可接收并丢弃该请求的最终协议结算帧,但不得写入下一请求。
### 9.4 释放与退出
@@ -426,8 +427,7 @@ DeepSeek Harness 首版只使用符合下列边界的 GoodBuddy 模型连接:
- 协议必须是 `openai-chat-completions`。
- 认证必须是 API Key。
- 公网服务地址必须使用 HTTPS;`localhost`、`127.0.0.1` 和 `::1` 回环地址可以使用 HTTP。
- 服务地址可以使用自定义主机、端口和部署路径,但不得包含用户名、密码、查询参数或片段。
- 服务地址支持 HTTP 和 HTTPS,不根据主机位置、端口、凭据、查询参数或片段增加额外限制。
- 模型名称不限制为 DeepSeek 品牌,由所选 OpenAI 兼容服务决定。
- 模型名称和服务地址由 Main 传入受控 Host。
- 图片能力只读取所选 GoodBuddy 模型连接的 `supportsImageInput`;Main、Utility 启动配置、ACP 能力和 Pi-AI 模型输入模态必须使用同一个布尔值。
@@ -469,7 +469,7 @@ DeepSeek Harness 首版只使用符合下列边界的 GoodBuddy 模型连接:
| stderr 累计 | 64 KiB |
| Host 启动 | 10 秒基础预算 + 每插件 5 秒激活与最多 1 秒失败清理,插件序列最多 91 秒;Main 另预留 2 秒持久化失败状态 |
| ACP 初始化与内部握手 | 每阶段 10 秒 |
| 单次 Prompt | 10 分钟 |
| 单次 Prompt | 无固定墙钟总时限,由 Harness 终态或用户取消结束 |
| 有序关闭宽限期 | 2 秒 |
超过限制时应取消当前请求。协议帧、队列或 stderr 持续异常时,应终止 Runtime 进程,避免继续信任已失控的通道。
@@ -2,7 +2,7 @@
## 状态
本文记录截至 2026-08-29 的当前代码实现,不定义额外的信任框架。“新增 Host 只探测、Host 卡片手动准备
本文记录截至 2026-08-30 的当前代码实现,不定义额外的信任框架。“新增 Host 只探测、Host 卡片手动准备
Agent/Runtime、Host 直接从 GitHub/北京镜像下载、项目始终使用 Host current 环境”已经完成源码接线,
详细事务与验收边界见
[SSH Host 远程环境准备与直连下载设计](./remote-host-environment-provisioning-design.md);
@@ -13,8 +13,9 @@ Windows 到 Linux x64 的既有安装、
Main-only 模型桥、断线恢复、输出重放、同一 OpenCode Session 续接与终态清理已经在真实
Host 上完成 provider-free 验证。上一轮 Linux x64 验收使用 Agent `0.11.2-e2e.12` 与
OpenCode Runtime `1.18.9` 完成了一次有界真实模型工具调用;加入每 helper 随机 loopback
路径 capability 后,Agent `0.11.7` 已通过独立 workflow 发布 Linux x64/arm64 复合包和
签名累计目录;当前源码准备 `0.11.8`,修复 Host 更新并消除重复 payload 验证。失败的
路径 capability 后,Agent `0.11.10` 已通过独立 workflow 发布 Linux x64/arm64 复合包和
签名累计目录;当前桌面源码准备 `0.11.13`,显示本地与远端 OpenCode 原生 Task,并取消
GoodBuddy 对生产 Prompt 的固定墙钟总时限。失败的
`agent-v0.11.3` 保持不可变且未发布。
## 产品语义
@@ -108,16 +109,16 @@ Detached GoodBuddy Agent
bootstrap Node;约 294 MiB 完整包不会一次读入 Main `Buffer`,Host 仍再次校验完整包。
- 两种 acquisition 交付到固定 operation staging 后,完全共用 control-plane
`prepare → commit → Agent activate/health → Runtime activate → finalize → cleanup`。
commit 终态持久化;通道丢失时 `commit-status` 读取终态,或从已认证准备状态幂等完成
中断的目录/metadata 发布,不重新下载或准备包。prepare
完成后、commit 前快照 Agent/Runtime 五个 metadata 文件,任一组件 adoption 失败都恢复其原字节或原缺失
状态;已经发布的 side-by-side payload 可以保留但不能成为 current。确认 adoption 后
才显式 cleanup;cleanup 失败只保留维护重试,不回滚健康环境。Host 在 prepare 解包时
Main 只保存清理 operation staging 所需的 operation ID。中断或 adoption 失败后,下次
更新尽力清理旧暂存并重新 prepare,不保存或恢复 Agent/Runtime metadata 副本。确认
adoption 后才显式 cleanup;cleanup 失败不回滚健康环境,也不阻塞下一次 fresh prepare。
Host 在 prepare 解包时
完成一次完整 payload 校验,commit 和后续注册检查不再遍历包体。首次 bootstrap 不依赖
既有 Agent daemon,也不要求 format v1 归档携带 `agent/lib/package-installer.cjs`。
- 即使版本号均为当前版本,Host 卡片仍提供同版本“重新安装”,用于修复 registry、签名
或安装 identity 异常。GoodBuddy-owned 同 digest 目录损坏时先隔离后替换,并在发布或
激活失败时恢复;不要求删除 Host、凭据或引用项目。
原子 commit 失败时恢复;commit 成功后的激活失败保留新发布内容,下次点击重新安装时
清理旧暂存并重新 prepare/adopt。不要求删除 Host、凭据或引用项目。
- Host 卡片的“版本匹配”badge 只表达版本事实,不代表 Agent 正在运行或环境健康。重新安装
失败时明确显示本次操作未完成,并以随后重新检查的版本卡片表达当前事实;提交结果
不确定时不声称旧版本未被替换。
@@ -193,7 +194,13 @@ Execute 不经过 Ask 的 bubblewrap profile:
- 继承 SSH 账号的正常环境、文件系统、进程和网络能力;
- 不进行 T2/T3、confinement attestation、approval bridge 或逐工具批准。
两种模式都保留请求 deadline、输入/输出字节上限、取消和进程组清理。
两种模式都保留输入/输出字节上限、用户取消和进程组清理。生产 Prompt 不设置固定墙钟
总时限;只要 Runtime 尚未按自身协议结束,Main 和 Agent 就允许其持续运行。启动、握手、
单个控制 RPC、重连尝试和关闭清理仍使用独立的有界超时,测试可以显式注入短 Prompt
时限验证取消升级,但该覆盖值不是生产默认。无界 Prompt 继续复用已发布的必填
`deadlineAt` 字段,以 year-9999 哨兵表达;Main 与 Agent 必须同时理解该哨兵,Agent
`0.11.10` 及更早版本仍会按其 manifest 上限夹紧,因此桌面启用这一语义前必须配套更新
到 Agent `0.11.13` 或更高版本。
## ACP 与断线
@@ -207,12 +214,21 @@ Execute 不经过 Ask 的 bubblewrap profile:
调度、跨 channel 超车、批发送或第二套拥塞控制。
- Agent 在把 Main 输入交给 Runtime 前、以及把 Runtime 输出交给 Main 前,先把 ACP frame 写入本机 journal。ACK 只推进 cursor 并裁剪已确认 frame,不表示 channel 已终止。
- Main 持久化 binding identity 和单调 cursor;保留中的 connection lease 即使处于 offline/reconnecting,也可以先把新 cursor 落盘。重连提交不能覆盖 resume 过程中并发落盘的更新。
- Runtime 事件先经过单事件、单请求输出和每次 Prompt 最多 100 个不同工具调用的边界;
通过边界后,Renderer 和 Main 将已接受的工具详情保存到本地 SQLite,不再额外缩短其
输入、输出、错误或摘要。
- OpenCode 原生 Task 工具按 `subagent_type`、`description`、`prompt` 和稳定 tool call ID
解析为子 Agent 事件。本地 OpenCode SDK 与远端 ACP 增量工具事件复用同一转换;ACP
首帧缺少参数时可以先显示普通工具活动,后续参数确认其为 Task 后必须替换为子 Agent
状态卡,并持久化任务说明、终态与输出。
- 同一 detached Agent 存活时,短暂 SSH 断线依次执行 `controller/resume`、`runtime/resumeAcpChannel` 和 `runtime/replayAcpChannel`,从 Main 已确认的 cursor 后只重放 Agent 到 Main 的已记录输出。重复 frame 会被确认但不会再次交给上层。若上一代连接只留下没有活动请求的 detached binding,完成精确 controller takeover 后会先有界停止并核对遗留 Runtime process,再用新 channel epoch 重新打开同一 binding 并恢复已有 ACP session;其他 controller、未证明 takeover 或仍有活动请求的 binding 仍被拒绝。
- Main 到 Runtime 的 ACP 输入、模型请求、工具请求和 blob 不自动重放。
- 无法确认外部 Provider 是否已处理的模型调用保持结果未知,避免重复计费或重复副作用。
- 只有远端返回 identity 匹配且 `closed: true` 时,Main 才删除持久化 binding;传输失败或未确认 close 会保留 recovery identity。
- 终态 close 由 Agent 在一个事务中为两个方向记录 sequence high-water tombstone,删除剩余 frame 和 active channel,并归零对应 journal quota。tombstone 用于拒绝迟到的旧 epoch frame,因此当前不会按时间自动裁剪。
- 断线不主动终止正在运行的 Runtime。用户取消、deadline、显式关闭或 Agent shutdown 才触发停止。
- 断线不主动终止正在运行的 Runtime。用户取消、显式关闭、输出边界或 Agent shutdown
才触发停止;连接恢复只受当前用户取消信号和单次重连控制超时约束,不把 Prompt 已运行
时长当作停止条件。
- Agent 失联期间继续把 Runtime 输出写入本机 journal;重新连接只校验 controller
identity、恢复 binding,并从 Main 最后确认的 cursor 后同步缺失数据。已接受的
指令和结果不确定的 Provider 请求都不自动重放。
@@ -223,8 +239,8 @@ Execute 不经过 Ask 的 bubblewrap profile:
- 远端 OpenCode 通过 GoodBuddy Agent helper 和每次 Prompt 的私有 Unix socket 使用模型桥。
- Main 校验固定模型 profile、协议、请求路径和有界传输格式,并记录 Provider
返回的实际 usage;不限制 Prompt 内的模型调用轮数、工具调用次数、累计 Token
或单次模型输出 Token。取消、Runtime deadline、请求/响应字节上限和结果不确定时
禁止自动重放仍然保留。
或单次模型输出 Token。取消、请求/响应字节上限和结果不确定时禁止自动重放仍然保留;
模型桥不会为整个 Runtime Prompt 另设墙钟总时限。
- helper 可以接收同一 Prompt 内并发到达的模型桥请求;它在单一稳定模型桥上按到达
顺序等待并交付,不返回本地 `bridge-busy`,每个响应只有在 HTTP 完整 flush 后才
发送 delivery ACK。
@@ -241,12 +257,55 @@ Execute 不经过 Ask 的 bubblewrap profile:
不修改既有 React state 对象。这样开发环境 StrictMode 重复调用 state updater 时,
block metadata 与 canonical 消息正文保持一致。
## Agent 开发期间的真实 Host 验证
任何会改变已部署 GoodBuddy Agent 或桌面到 Agent 生产链路的源码改动,都必须在开发期间
使用共享 Linux x64 真实测试 Host 验证。适用范围包括 Agent daemon、Agent protocol
及共享 contract、Agent 组包与安装、attach/update、Runtime 启动与进程归属、Workspace、
model bridge,以及生命周期和恢复逻辑。单元测试、mock、fixture、CI 或正式发布前回归
都不能替代这一步;不得等到准备发布时才首次运行受影响的真实链路。
测试 Host 有两个网络入口:
- `192.168.0.23`:局域网入口,在本地网络可达时优先使用;
- `10.7.0.23`:VPN 入口,局域网入口不可达时使用。
两者指向同一台物理 Host,只代表两条访问路由,不能计为两个独立 Host、两种架构或两份
覆盖结果。测试只使用已固定的 Host identity 和 GoodBuddy 已有凭据存储;地址不得写入
产品行为或默认配置,用户名、密码、私钥等凭据不得写入源码、文档、命令、日志或测试输出。
开发时应在改动链路达到可运行状态后尽早执行真实 Host 验证,并在最终相关改动后重复受
影响的场景。必须使用当前源码构建或当前候选包,不能只验证 Host 上已经发布的旧 Agent。
按改动范围至少选择以下场景:
1. Agent 组包、安装或升级:验证当前候选的 attach-or-bootstrap、安装/更新、版本切换及
随后的连接。
2. Runtime profile、进程启动/归属或 Ask/Execute 边界:通过桌面生产入口启动真实 Runtime,
验证受影响模式;Ask 权限改动必须验证只读边界,Execute 权限改动必须验证所需写入、
进程和网络能力。
3. Agent protocol、RPC、stream、model bridge 或模型消息链路:执行最小有界真实模型调用,
禁用非必要工具和附件,并记录实际调用次数;大消息或工具链路改动还应覆盖对应的真实
payload/工具场景。
4. 会话、owner、取消、超时、断线或恢复逻辑:执行与改动直接相关的中断、取消、Agent/
Runtime 重启、SSH 断开或重连序列,并确认不会错误重放结果未知的操作。
5. Workspace 或 Host 文件路径:只在 GoodBuddy 专用测试目录操作,验证真实路径和权限,
不得读取、覆盖或删除无关 Host 文件。
停止或修改远端进程前必须先核对其启动身份、PID/进程组和 GoodBuddy 归属。若两个入口均
不可达,应立即把真实 Host 验证报告为开发阻塞,保持该验证未完成,不能把 Agent 改动表述
为已完成,也不能把首次真实验证推迟到发布阶段。
## 已完成的 E2E 验收记录
- 2026-08 的本地 fixture 完整验证 Linux x64 Agent `0.11.2-e2e.12`、Node `24.19.0`
和 Agent protocol `2.0`;当时没有 arm64 fixture,因此该记录不能作为当前独立发布
的双架构验收。Agent `0.11.7` 后续已由原生 workflow 发布并公开验证双架构工件;
当前源码 lock 是修复候选 `0.11.8`。
的双架构验收。Agent `0.11.10` 后续已由原生 workflow 发布并公开验证双架构工件;
当前源码 lock 固定为候选 `0.11.13`。
- 2026-08-30 在共享 Linux x64 Host 的隔离测试 HOME 中验证当前 `0.11.13` 源码候选:
签名 Runtime 清单的测试墙钟上限为 1 秒,模型桥首轮故意延迟 2.515 秒后 Prompt 仍在
5.770 秒正常完成;随后 OpenCode 原生 Task 依次产生 `running`、`completed` 子 Agent
事件并完成父请求。测试结束后隔离 Agent、Runtime、socket 和 Workspace 已全部清理,
Host current Agent 仍为 `0.11.10`。
- 正常 Host 更新路径把 Linux x64 Host 的 Agent 更新为 `0.11.2-e2e.12`,并确认
OpenCode Runtime 已安装版本与所需版本均为 `1.18.9`。
- 一条新的 Ask 用户操作只提交一次。OpenCode 先在 build 模型轮次请求一个原生
@@ -283,7 +342,12 @@ Workspace、Runtime 和 Saving 进度仅用于新建或显式保存项目;进
产生冲突的项目创建和设置入口。远端 RPC 拒绝只向
Renderer 暴露固定方法名、数字 RPC code 和有界 service code,不转发 Host 私有错误详情。
`runtime/preparePrompt` 在远端明确拒绝且尚未接受 Prompt 时会关闭对应 Main binding,
不会把确定性失败错误保留为 `outcome-unknown`。
不会把确定性失败错误保留为 `outcome-unknown`。未确认终态的 Prompt 仍不会自动重放;
用户之后显式发送的新 Prompt 会关闭旧的非就绪 Main binding,并以新的 ACP session
继续当前 Conversation,避免一次恢复不确定永久阻塞后续输入。
Ask 模式的 Linux Runtime 进程由 `bwrap` 启动后 `exec` 到已签名 Runtime 或 Agent
model bridge helper;监督器只接受同一 PID/进程组从固定 `bwrap` 路径到预期最终可执行文件
的有界转换,再登记为运行中进程。
不持久化 T2/T3、consent、approval bridge、confinement 或组件验证结果。数据库 schema
v31 保留项目及关联用户数据,但重建执行空间表为 `project_id/kind/root_path/ssh_host_id`
@@ -313,7 +377,10 @@ v31 保留项目及关联用户数据,但重建执行空间表为 `project_id/
信任条件。上传到 Host 前重新序列化为确定性 LF JSON。签名目录、描述符、manifest 和
payload 仍按原始签名字节及 SHA-256 验证。
## 发布前验证
## 发布前完整回归(不能替代开发验证)
以下清单只用于复核开发期间已经在真实 Host 上通过的链路,不得作为 Agent 改动的首次
真实 Host 验证:
1. `npm test`
2. `npm run typecheck`
@@ -152,19 +152,13 @@ daemon 参与。两种 acquisition 的差别只在于如何把同一个签名 co
`prepare` channel 发送有界 one-shot installer 与结构化输入。
2. Host 在解包写入准备目录的同一遍处理中校验归档大小、SHA-256、外层及内层签名、
平台、架构、协议和每个 payload digest;不再先完整扫描 payload、再重复解包和哈希。
3. `prepare` 完成后、`commit` 前按原字节记录 Agent 与 Runtime 的五个
current/registry metadata 文件,
同时记录原本缺失的状态。
4. `commit` 只复核有界的签名 manifest、准备回执和入口 metadata,再以目录 rename 发布
3. `commit` 只复核有界的签名 manifest、准备回执和入口 metadata,再以目录 rename 发布
已准备内容及包内认证的公钥 registry/Runtime lock;不会重读归档或遍历 payload。
终态先持久化到 operation staging;控制通道丢失时,同一 operation 的
`commit-status` 读取终态,或从已认证准备状态幂等完成中断的 rename/metadata 发布。
5. commit 后在同一条已固定身份的 SSH lease 上执行 Agent bootstrap/readiness 和 Runtime
4. commit 后在同一条已固定身份的 SSH lease 上执行 Agent bootstrap/readiness 和 Runtime
activate。新 Agent 最多完整验证一次,新 Runtime 最多完整验证一次;注册成功后的
health、capabilities 和 prompt 启动只读取 registry、签名 manifest 与入口 metadata。
adoption 失败时停止候选,并把五个 metadata 文件恢复为原字节或原缺失状态。
6. Main 确认 adoption 后显式执行 cleanup。cleanup 失败只保留待重试的有界 operation,
不回滚已经健康的 Agent/Runtime。
5. Main 确认 adoption 后显式执行 cleanup。cleanup 失败不回滚已经健康的 Agent/Runtime,
也不阻塞下一次更新。
这不是两个并行安装管理器,也不存在把 Agent 与 Runtime payload 逐文件走 SFTP 安装的
第二条路径。两种 acquisition 共享相同的 prepare、commit、adoption、finalize 与 cleanup。
@@ -194,8 +188,8 @@ Host 下载返回明确失败;本次操作不自动切换 acquisition,用户
Runtime。
- 每次显式安装或重装都从本次已经校验并解包的准备目录原子替换对应 Agent 与 Runtime
digest 目录,不为节省本机磁盘写入而重新遍历旧目录,也不使用跨安装硬链接。
- 操作响应丢失后的同 operation 重试只检查签名 manifest、registry identity 和三份小型
trust metadata,不重新读取归档或 payload;正常 cleanup 随后删除准备目录。
- 操作中断后不续写旧 operation。下一次更新尽力清理其 staging,并从签名候选重新
prepare;正常 cleanup 随后删除本次准备目录。
只有真实包体和发布频率证明网络成本仍不可接受时,才另行设计 Agent、Node 和 Runtime
独立签名组件目录;本功能不提前引入第二套发布协议。
@@ -220,14 +214,11 @@ Host 下载返回明确失败;本次操作不自动切换 acquisition,用户
同一 Host identity 同时只允许一个由用户启动、Main-owned 的准备操作。重复观察者加入
已有操作,不启动第二次发布;窗口关闭、显式取消、Host identity 改变或 Main 退出时执行
有界取消。Main 在 commit 前为该 Host 持久化一个不含凭据的 pending operation 记录,
其中包含五份有界 metadata 的原字节/原缺失快照;
commit 指令开始后若 SSH 通道、输出或终态丢失,当前操作保留该记录和远端 staging。
下一次重试或应用重启后的首次操作先对同一 Host identity 执行 `commit-status` 并
恢复 adoption;恢复中的 Agent/Runtime adoption 失败仍使用该持久化快照回滚。它不会
重新下载或准备包,也不开始第二条 acquisition。环境健康后再重试
cleanup,确认清理后删除 pending 记录。
取消在最终原子切换完成后不再伪装成回滚成功。
有界取消。Main 只为该 Host 持久化一个不含凭据的 version-1 pending operation ID,用于
下一次操作开始时尽力清理旧 staging。无论旧 cleanup 成功、目标已变化还是旧记录损坏,
都删除这条可丢弃记录并开始 fresh prepare;不保存远端 metadata 副本,不续写旧 commit,
也不跨重启恢复 adoption。当前操作中可确定的失败会立即尽力 cleanup。环境已健康后的
cleanup 失败不回滚环境,也不阻塞下一次更新。
## 项目创建与切换
@@ -277,8 +268,9 @@ cleanup,确认清理后删除 pending 记录。
这些路径不会取得安装包、发布组件或通过 SFTP 扫描 payload。
- Host 卡片即使显示相同版本也保留显式重装操作,用于修复 registry、签名或 payload
identity 异常;若同一 digest 的 GoodBuddy-owned 目录校验失败,重装会先隔离旧目录,
完整发布并验证新目录,失败时恢复旧目录。重装不要求删除 Host、凭据或项目,也不会处理
所有者异常、符号链接或非 GoodBuddy 管理路径。
并在原子 commit 失败时恢复旧目录。commit 成功后的 adoption 失败保留新发布内容,
下次重装清理旧暂存并重新 prepare/adopt。重装不要求删除 Host、凭据或项目,也不会
处理所有者异常、符号链接或非 GoodBuddy 管理路径。
- 由桌面控制面打包有界 one-shot installer,并通过固定短命令 `exec sh -s` 和 stdin
发送脚本及结构化输入,避免 SSH command 长度限制;既有 package format v1 归档内固定
Node 负责解码和运行它。
@@ -296,9 +288,8 @@ cleanup,确认清理后删除 pending 记录。
- 如果 Host 未就绪或版本不兼容,项目仍可在本地选择,但实际远程操作失败;不再走旧的
隐式安装。
- 已下载或导入的本地 `.gbagent` 保持可用,不能因加入远程直连而迁移或删除。
- `0.11.7` 遗留的 version-1 pending operation 没有持久化 metadata 快照,也没有新格式的
已解包准备状态;`0.11.8` 只清理其暂存并重新执行一次认证 prepare,不尝试用新 installer
续写旧 commit。
- pending operation 保持 version 1,只记录 Host、目标 identity 与 operation ID,用于
尽力清理旧 staging;它不是远端环境状态或恢复日志。
- 远程直连继续使用现有 package format version 1,不要求归档携带 installer,也不要求
目录声明额外的 bootstrap 能力元数据。
@@ -330,7 +321,6 @@ cleanup,确认清理后删除 pending 记录。
仍待完成。
12. Host 不可达或远端目录不存在时,用户仍可从项目浮动管理入口删除本地项目;删除 Host
会列出并本地清理全部关联项目,但不会连接 Host 或删除任何远端目录和内容。
13. commit 终态可在通道丢失后用 `commit-status` 读取,或从已认证准备状态幂等完成;
Agent 或 Runtime
adoption 失败恢复五个 metadata 文件的原字节/原缺失状态;已健康环境的 cleanup
失败保留为维护重试,不触发环境回滚。
13. 中断或 adoption 失败后的下一次更新只尽力清理旧 staging,然后 fresh prepare;
pending record 不包含远端 metadata 副本。已健康环境的 cleanup 失败不触发回滚,
也不阻塞下一次更新。
+292
View File
@@ -0,0 +1,292 @@
# GoodBuddy Release Runbook
Read this runbook only when preparing, publishing, recovering, or verifying a
desktop or GoodBuddy Agent release.
This is an operator and CI procedure. It does not authorize adding application
persistence, snapshots, journals, rollback engines, recovery protocols, or
compatibility layers to automate release operations. Determine release recovery
from the authoritative GitHub, OSS, workflow, and Git state, then use the
smallest existing idempotent rerun or a new immutable version as specified
below.
## Release Packaging
- Unless the user explicitly requests a local Windows package, never run local
Windows packaging or launch probes as part of release preparation. In
particular, do not run `npm run portable`, Windows
`npm run release:package`, direct `electron-builder` packaging, or launch a
locally packaged Windows app before publishing a release. Source validation
and the native GitHub Actions jobs are the release authorities.
- After a release is published, confirm only that the expected Windows assets
exist in the public release metadata. Do not locally rebuild or launch the
Windows package, download or hash published installers, attach browser
automation to a packaged app, or perform exhaustive per-asset network probes
unless the user explicitly asks for that additional validation.
- `.github/workflows/packages.yml` is the canonical cross-platform packaging
workflow. It validates and builds `out` once, then packages on six native
runners: Windows, macOS, and Linux, each for x64 and arm64.
- The experimental Linux LoongArch (`loong64`) preview is built separately
through `build/loongarch-cross` by following
`docs/development/loongarch-preview-build.md`. It is not part of
`.github/workflows/packages.yml`, the six-runner GitHub Actions matrix,
standard release manifests, GitHub Release asset expectations, or the
production update index. Do not add it to those paths unless the user
explicitly requests a future production-support migration.
- Run the unified packager with
`npm run release:package -- --platform <platform> --arch <arch>`. It only
packages for the native host and writes to
`dist/release/<platform>-<arch>`.
- Default deliverables are NSIS and portable ZIP for Windows, DMG and ZIP for
macOS, and AppImage, DEB, and RPM for Linux. Every target includes
`release-manifest.json` with SHA-256 hashes.
- `build/build-release.cjs` verifies the unpacked application, `app.asar`,
bundled Continue and OpenCode runtimes, executable architecture, and package
signatures before atomically replacing a release directory.
- All desktop build paths, including local `portable`, package the Agent and
remote Runtime version locks plus the public signing-key registry without
embedding installable Linux Agent or remote Runtime payloads. Managed SSH is
optional: users explicitly download a compatible compound `.gbagent` package
from Settings or import one offline before GoodBuddy can install or update a
Host.
- Each independently published Linux x64 or arm64 `.gbagent` contains the
Agent daemon, pinned Node, and the desktop-maintained compatible OpenCode
Runtime. Build both architectures on native GitHub Actions runners from one
immutable `agent-v<agentVersion>` tag.
- Keep the GoodBuddy Agent source, shared protocol/contracts, runtime lock,
bundle tooling, and tests in this repository so a desktop commit identifies
the exact Agent source it expects. Do not create a separate Agent repository
or long-lived Agent release branch unless the Agent becomes an independently
released product serving multiple clients.
- `.github/workflows/agents.yml` is the branch and pull-request build
verification workflow for GoodBuddy Agent. It must build Linux x64 and
arm64 on native runners from the checked-out commit, acquire the locked
official Node archive and locked OpenCode npm archive, verify every locked
digest, use only an ephemeral in-memory test signing identity, and verify the
resulting compound package and deterministic archive. It must not read
production signing secrets, publish installable release artifacts, or modify
the checked-in public key registry.
- `.github/workflows/agent-release.yml` is the only production compound Agent
publication path. It requires an annotated immutable Agent tag, the protected
`agent-signing` Environment, native x64/arm64 builds, one production
GoodBuddy signing identity for every layer of the compound package and
catalog, a non-Latest GitHub Agent Release, and synchronized immutable
Beijing OSS objects plus the final signed latest-catalog pointer.
- `.github/workflows/packages.yml` and `release:package` build only desktop
products. Missing Agent packages, remote Runtime inputs, or GoodBuddy signing
credentials must never block an ordinary desktop package or release.
- Keep electron-builder invocations on `--publish never`. Main-branch builds
run validation and build the production bundle without running the native
package matrix. Manual builds upload 30-day GitHub Actions artifacts.
Version-tag builds verify and aggregate packages before publishing GitHub
Release assets. The macOS jobs sign, notarize, and verify packages when all
five Apple credentials are configured. With no Apple credentials they must
use the explicit `--unsigned` path, warn that Gatekeeper may block the
packages, and still complete; a partial credential set must fail rather than
silently downgrade.
- Keep `ELECTRON_CACHE` and `ELECTRON_BUILDER_CACHE` under
`${{ runner.temp }}` in step-level workflow contexts. A cache beneath the
repository inherits the root `"type": "module"` and breaks electron-builder's
CommonJS macOS icon tool.
- Tag builds must use `v${package.version}`. The workflow also supports manual
dispatch and main-branch changes to release tooling.
### Agent Release Process
- Agent releases use annotated `agent-v${agent-runtime-lock.agentVersion}` tags
and are separate from desktop `v${package.version}` releases. Confirm the
exact Agent release commit and tag with the user before creating or pushing
either.
- The tagged commit must be reachable from protected `main`. The two native
jobs build the compound x64/arm64 packages from the same source and locks;
the catalog job rejects missing architectures, changed bytes for an existing
version/architecture identity, invalid prior signatures, and incompatible
matrix metadata.
- Agent GitHub Releases are ordinary non-draft, non-prerelease releases but
must use `--latest=false`; they must never replace the desktop release marked
Latest. Publish immutable packages and the versioned catalog to
`agent-releases/v<agentVersion>/` in Beijing OSS, publish the GitHub Agent
Release, then atomically update the single `agent-releases/latest.json`
pointer to that version's immutable catalog and signature.
- Do not report an Agent release complete until both public package
architectures match the signed catalog by size and SHA-256, the GitHub and
OSS catalog bytes/signatures are identical, the application can read the
selected source, and GitHub's repository Latest tag remains the desktop tag.
### Tagged Release Process
Every version-tag release must follow this sequence. A branch-only push does
not require release notes.
1. Confirm that the user wants a release tag and identify the exact release
commit and the new `package.json` version. Separately ask whether this
release should also receive an experimental LoongArch preview build; never
infer that choice from an earlier release.
2. Find the latest stable version tag reachable before the release commit and
inspect the complete commit and file diff from that tag to the release
commit. For the first tagged release, inspect the relevant repository
history instead.
3. Draft concise, user-facing release notes in both Simplified Chinese and
English based only on verified changes in that range. Use the titles
`GoodBuddy <version> 更新内容` and
`What's New in GoodBuddy <version>`, with corresponding `功能更新` /
`Features` and `问题修复` / `Bug Fixes` sections when applicable. The two
language versions must describe the same changes. Do not expose
internal-only details, credentials, private content, or unverified claims.
4. Show the exact bilingual release-note draft to the user and wait for
explicit approval. If the release commit or either language version changes
after approval, inspect the updated tag range and request approval again.
5. Write the approved notes to the single entry for the release version in
`resources/release-notes.json`. A failed unpublished candidate whose content
is carried forward must not retain a duplicate packaged entry.
6. Verify that `package.json`, the root `package-lock.json` version, and
`package-lock.json.packages[""].version` all equal the release version. Run
`npm run release:notes:verify`, the required source validators, the
production build. The six native CI jobs remain the cross-platform
authority; do not add local packaging or packaged-app launch probes unless
the user explicitly requests them.
If the user requested a LoongArch preview in step 1, build it separately
from this exact candidate by following the LoongArch build document, record
its size and SHA-256, and keep it outside the standard GitHub/OSS release
asset set unless the user separately authorizes publishing it.
7. Fetch both remotes immediately before tagging. Inspect any remote branch
movement instead of overwriting or silently merging it. Confirm the working
tree is clean, the candidate tag is unused locally and remotely, and the
exact approved commit has not changed.
8. Only after all previous steps pass, create an annotated
`v${package.version}` tag at the exact approved commit. Push `main` to
`origin` and `github`, verify both branch SHAs, then push the tag to both
remotes and verify each peeled tag SHA (`refs/tags/<tag>^{}`) equals the
release commit.
9. Keep both approved language versions as the single source for the GitHub
Release body and the packaged first-open release-notes modal. The modal
displays the release notes matching the current interface language and
contains no button linking to a full release page.
10. Observe the tag workflow through publication and complete the public
verification checklist below. A successful push is not a completed
release.
### OSS Publication Contract
The tagged release job publishes through the GitHub Environment selected by
`.github/workflows/packages.yml` (`aliyun-oss-release`) and reads the following
effective GitHub Actions variables. Before a release or same-tag rerun can
publish, verify that repository-, organization-, or environment-level
resolution exposes:
- `ALIYUN_OSS_BUCKET=goodbuddy`
- `ALIYUN_OSS_ENDPOINT=https://oss-cn-beijing.aliyuncs.com`
- a non-empty `ALIYUN_OIDC_PROVIDER_ARN` matching
`acs:ram::*:oidc-provider/*`
- a non-empty `ALIYUN_ROLE_ARN` matching `acs:ram::*:role/*`
For environment-scoped values, use the exact Environment name from the
workflow; do not assume a similarly named UI environment such as `Production`
contains the active variables.
The Bucket and Endpoint are a deployment contract, not interchangeable
examples. They must stay aligned with the trusted URL checks in
`src/main/version-checker.ts`, `sites/app.js`, website validation, and related
tests. A host, Bucket, Region, or CDN migration must update and validate every
surface together before a new release.
- Use GitHub OIDC and the RAM Role to obtain short-lived STS credentials.
Never add long-lived AccessKeys to repository or environment secrets.
- Keep `ossutil` pinned. Its V4 signing requires the Region; derive it from the
canonical Endpoint, verify that the production value resolves to
`cn-beijing`, and pass `--region` to every `ossutil cp`, including the final
`latest.json` update.
- Grant the RAM Role only the actions and prefixes required by the workflow.
It must be able to write immutable version objects and the final latest
pointer without granting unrelated administration privileges.
- Upload release assets and `site-release.json` under the immutable
`releases/<tag>/` prefix first. Verify all 14 installer URLs publicly before
creating or publishing the GitHub Release. Update
`releases/latest.json` only after the GitHub Release is public and all prior
checks succeeded.
- The expected GitHub Release contains 22 assets: 14 installers (two formats
for each Windows/macOS target and three formats for each Linux target), six
renamed target manifests, one aggregate `release-manifest.json`, and one `SHA256SUMS`.
`site-release.json` is an OSS publication artifact, not a GitHub Release
asset.
### Failed Tag Recovery
Classify a failed tag by the external side effects that completed before
choosing a recovery:
- If no source or release metadata must change, correct only the external
configuration and use **Re-run failed jobs** for the same immutable tag. Do
not change, move, delete, or recreate the tag.
- If immutable OSS objects were partially uploaded but their source bytes are
unchanged, a same-tag rerun may idempotently re-upload or verify them. Never
point `latest.json` at a partially verified prefix.
- If the GitHub Release is already public but the final latest-pointer step
failed, it is a published version. Keep its packaged notes and rerun the
failed release job for the same tag; do not classify it as an unpublished
candidate.
- If code or release metadata must change, keep the failed tag immutable,
increment the patch version, obtain approval for the revised exact release
commit and notes, and create a new tag. Do not reuse the failed version.
When recovering from a version tag whose workflow never published a public
GitHub Release:
- If a code or metadata change requires a higher version and a new tag, carry
the failed candidate's approved user-facing notes forward into the recovery
version, then remove the superseded failed version's entry from
`resources/release-notes.json`.
- The packaged first-open modal must show that carried-forward content only
once under the recovery version. Never retain both the failed version and
its cumulative recovery copy, because users upgrading across them would see
duplicate content.
- Never remove the packaged history for a version that successfully published
a GitHub Release. Verify the failed release state before treating an entry as
superseded.
### Post-Publication Verification
Do not report a release complete until all of the following are verified:
1. The tag workflow and all six native package jobs succeeded. Verify the
recorded macOS signing mode: signed builds must pass `codesign`, `spctl`,
and `stapler`; unsigned builds must record the Gatekeeper caveat in the
Actions log and job summary. In the final release job, explicitly verify
the OSS configuration, OIDC authentication, release-index generation,
immutable upload, public asset check, GitHub Release publication, and
latest-pointer steps.
2. The public GitHub Release is non-draft, non-prerelease, marked Latest, and
uses the expected tag and title. Its body must exactly match the Markdown
generated from the approved packaged bilingual notes.
3. GitHub release metadata contains exactly the expected 22 uploaded asset
names, including the expected Windows x64 and arm64 assets. Do not download,
hash, launch, or send individual network probes to published installers
unless the user explicitly requests that additional validation.
4. The Beijing `releases/latest.json` returns HTTP 200, has the expected stable
version, exact six targets and 14 installer entries, the trusted Beijing
URLs, and the GitHub fallback URL. It must match the immutable
`releases/<tag>/site-release.json`. Fetching and comparing these small JSON
metadata files is sufficient; rely on the successful publication job for
its per-asset public checks.
5. The live website successfully fetches the index and produces the 14 correct
platform/architecture/format links from that metadata.
6. Both remote `main` refs and both peeled tag refs still equal the approved
release commit, and the local working tree is clean.
Never create or push a release tag, and never push a previously created
release tag, before the release-note draft has received explicit approval.
- Before a push that updates the `github` remote, ask whether the user wants a
release tag unless they already specified that choice. A branch-only push
does not require a version bump or tag. When the user requests a release,
verify that `package.json` and `package-lock.json` contain the same release
version, create `v${package.version}` at the exact commit being pushed, and
push that tag so the native package matrix and GitHub Release run.
- Never move or reuse an existing release tag. If `v${package.version}` already
exists locally or on a remote at another commit, increment the package
version and create a new matching tag before the release push.
- Verified release baseline on 2026-08-18: commit
`60119a4317118fa3f077db0382664f15266a6682`, annotated tag `v0.10.4`, and
GitHub Actions run `32038633609` attempt 2 succeeded through all six native
packages, GitHub Release publication, Beijing OSS publication, and the final
`latest.json` switch.
@@ -589,12 +589,11 @@ attach 并读取 current registry,不存在项目中的旧 Host revision 或
- Agent 与 Runtime 各自维护版本,签名摘要标识精确工件。Host 在解包到准备目录的同一遍
处理中完成完整 payload 校验,commit 只复核签名 metadata 并原子替换 side-by-side
目录,不重新读取归档、扫描旧目录或使用跨安装硬链接。
- commit 终态持久化;控制通道丢失时,`commit-status` 读取终态,或从已认证准备状态
幂等完成中断的目录/metadata 发布,不重新下载或准备包。prepare 完成后、commit 前快照
Agent/Runtime 五个 metadata 文件;任一组件 adoption 失败恢复原字节或原缺失状态,
已发布 payload 不得成为 current。新 Agent/Runtime 各自最多完整验证一次;注册后的
- Main 只保存清理 operation staging 所需的 operation ID。控制通道中断或 adoption 失败
后,下次更新尽力清理旧暂存并重新 prepare,不保存或恢复 Agent/Runtime metadata 副本。
新 Agent/Runtime 各自最多完整验证一次;注册后的
health、capabilities 和 prompt 启动只检查 registry、签名 manifest 与入口 metadata。
确认 adoption 后显式 cleanup,cleanup 失败不回滚健康环境。
确认 adoption 后显式 cleanup,cleanup 失败不回滚健康环境,也不阻塞下一次 fresh prepare。
- 握手报告 installation、Daemon boot identity、协议、系统、架构、用户监督器和能力。
- 在远程执行路径规范化、Git、文件、PTY、进程组和 Runtime 管理。
- 持久化有界 Agent 到 Main 输出;SSH 断开后 Agent 继续运行,同一 Agent 重连时只恢复
@@ -807,8 +806,9 @@ Electron、ChildProcess、PTY、SSH Client、Socket 或文件句柄。
- 通用 Artifact Event。
- HTML 工作区和成果的静态即时预览。
- Runtime Inspector Snapshot 与事件。
- OpenCode 会话、子会话、Todo、工具、用量和取消。
- 直连模型及现有 GoodBuddy Subagent 的统一展示。
- OpenCode 会话、子会话、Todo、工具、用量和取消;本地与托管 SSH 的原生 Task 调用在
Conversation 中统一显示为可追踪的 Subagent 状态,而不是普通工具参数卡。
- 直连模型、OpenCode 原生 Subagent 及现有 GoodBuddy Subagent 的统一展示。
### 阶段 2:监督、终端与受管进程
+1 -1
View File
@@ -266,7 +266,7 @@ GoodBuddy 应能够:
1. 所有新 IPC 继续执行 Zod 校验和可信主窗口校验。
2. 项目根目录、成果路径和上下文路径必须 canonicalize 并验证目录包含关系。
3. Child Runtime 环境变量改用最小 allowlist,避免继承无关密钥。
4. 远程委派仅允许 HTTPS,开发环境只放行 loopback。
4. 远程委派支持用户配置的 HTTP 和 HTTPS 地址,不按主机位置增加额外限制。
5. 语音、窗口捕获和浏览器上下文分别授权。
6. 自动化不得绕过工具审批和项目权限。
7. 记忆必须保留来源和作用域。
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "goodbuddy",
"version": "0.11.8",
"version": "0.11.13",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "goodbuddy",
"version": "0.11.8",
"version": "0.11.13",
"license": "0BSD",
"dependencies": {
"@agentclientprotocol/sdk": "0.25.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "goodbuddy",
"version": "0.11.8",
"version": "0.11.13",
"private": true,
"description": "Secure desktop AI workspace with controlled Agent Runtimes",
"desktopName": "GoodBuddy",
+108 -12
View File
@@ -2,35 +2,131 @@
"formatVersion": 1,
"releases": [
{
"version": "0.11.8",
"releasedAt": "2026-08-29",
"version": "0.11.13",
"releasedAt": "2026-08-30",
"notes": {
"zh-CN": {
"highlights": [
"GoodBuddy 0.11.8 修复正式环境中的 Host 更新失败,并显著缩短 Agent 与 OpenCode Runtime 的安装、恢复和日常启动校验。"
"GoodBuddy 0.11.13 将本地与托管 SSH 项目中的 OpenCode 原生 Task 显示为独立子 Agent,并移除 GoodBuddy 固定的 Prompt 总时限,让 Runtime 决定长任务生命周期。"
],
"features": [
"**OpenCode 原生子 Agent。** OpenCode Task 调用现在以独立子 Agent 卡片显示,持续呈现任务、运行状态、输出和错误,不再同时重复为普通工具。"
],
"features": [],
"fixes": [
"**Host 更新恢复可用。** 修复已发布 OpenCode Runtime 在采用阶段被桌面内置锁重复校验而失败的问题。Host 现在信任签名复合包中的版本锁和身份,并在同一条固定 SSH 连接上完成 Agent 启动、健康检查与 Runtime 激活。",
"**不再重复扫描远端包体。** Host 在解包时完成完整 SHA-256 与签名校验;commit 只检查签名元数据。Main 不再通过 SFTP 逐文件读取 Agent/Runtime,后续健康检查、能力发现和每次提问只使用已登记 identity、manifest 与入口元数据。仍保留 SHA-256,提速来自消除重复读取。",
"**中断与清理更可靠。** 中断的 commit 可从已认证准备状态继续,待恢复操作会保留五份元数据快照并在采用失败时回滚。环境已健康后,暂存清理失败只留待重试,不再错误回滚;安装错误会显示具体的有界原因。"
"**长任务不再被固定时限中止。** 移除本地 OpenCode、Continue、DeepSeek Harness 和托管 SSH Prompt 的 2/10 分钟外层总时限。任务可持续数小时或更久,直到正常完成或用户取消;Runtime 自身超时仍然生效。",
"**OpenCode 启动更可靠。** 改用本机健康接口检测启动完成,不再依赖固定日志格式,并为较慢设备保留更充足的冷启动时间,减少已启动却误报超时。",
"**HTTP 服务地址配置更灵活。** 模型连接、DeepSeek Harness 与微信绑定可使用用户明确配置的合法 HTTP 或 HTTPS 地址,包括局域网与公网服务;仍保留协议和 API Key 校验。"
],
"notices": [
"**技术预览与版本要求。** 远程项目仍默认关闭且为技术预览。Host 需要安装单独发布的 Agent `0.11.8`,提供 Linux x64 和 arm64;桌面包不内置 Agent 或远程 Runtime,本次不构建 LoongArch 预览。"
"用户仍可随时停止任务;启动、控制请求、断线恢复、取消收敛、清理和输出大小仍有独立边界。",
"托管 SSH Host 需要单独发布的 Agent `0.11.13`。提供 Linux x64 和 arm64;桌面包不内置 Agent 或远程 Runtime。"
]
},
"en-US": {
"highlights": [
"GoodBuddy 0.11.8 fixes Host updates in production and substantially reduces Agent and OpenCode Runtime verification during installation, recovery, and normal startup."
"GoodBuddy 0.11.13 presents native OpenCode Tasks as dedicated subagents in local and managed SSH projects, and removes GoodBuddy's fixed Prompt deadline so the Runtime owns long-task lifetime."
],
"features": [
"**Native OpenCode subagents.** OpenCode Task calls now appear as dedicated subagent cards with the task, running state, output, and errors, without a duplicate generic-tool entry."
],
"fixes": [
"**Long tasks are no longer stopped by a fixed limit.** Removed the outer 2/10-minute total deadline from local OpenCode, Continue, DeepSeek Harness, and managed SSH Prompts. Tasks can run for hours or longer until completion or user cancellation; Runtime-owned timeouts still apply.",
"**More reliable OpenCode startup.** GoodBuddy now detects readiness through the local health endpoint instead of a fixed log format and allows more cold-start time on slower devices, avoiding false startup timeouts.",
"**More flexible HTTP service endpoints.** Model connections, DeepSeek Harness, and Weixin binding can use explicitly configured valid HTTP or HTTPS endpoints, including LAN and public services, while retaining protocol and API-key validation."
],
"notices": [
"Users can still stop tasks at any time. Startup, control requests, reconnection recovery, cancellation settlement, cleanup, and output sizes retain independent bounds.",
"Managed SSH Hosts require the separately published Agent `0.11.13`. Linux x64 and arm64 are provided; desktop packages do not embed the Agent or Remote Runtime."
]
}
}
},
{
"version": "0.11.12",
"releasedAt": "2026-08-30",
"notes": {
"zh-CN": {
"highlights": [],
"features": [
"**魔法笔记更新时间。** 魔法笔记列表现在显示每篇笔记的最后更新时间,便于快速判断最近修改过的内容。"
],
"fixes": [
"**远程会话中断后可以继续输入。** 修复托管 SSH 请求结果不确定后,同一会话的每条后续输入都会重复显示“恢复状态不确定”的问题。未确认的旧请求仍不会自动重放;用户再次明确发送时,GoodBuddy 会建立新的 ACP session 并继续当前会话。",
"**Ask 模式远程 Runtime 可以稳定启动。** 修复 Linux Host 上 `bwrap` 启动身份检查存在竞态,导致 Ask 模式可能在模型调用前被拒绝的问题。Agent 现在会验证从固定沙箱启动器到预期签名可执行文件的受限转换。"
],
"notices": [
"**远程项目技术预览与 Agent 要求。** 远程项目仍默认关闭且为技术预览。Host 需要更新到单独发布的 Agent `0.11.10` 才能获得 Ask 模式启动修复;提供 Linux x64 和 arm64,桌面包不内置 Agent 或远程 Runtime。本次不构建 LoongArch 预览。"
]
},
"en-US": {
"highlights": [],
"features": [
"**Magic Notes update times.** The Magic Notes list now shows when each note was last updated, making recently edited content easier to identify."
],
"fixes": [
"**Remote conversations continue after interruptions.** Fixed every later message in a managed SSH conversation repeatedly failing with an uncertain-recovery error after a prompt outcome could not be confirmed. The uncertain prompt is still never replayed automatically; when the user explicitly sends again, GoodBuddy starts a new ACP session and continues the current conversation.",
"**Reliable Ask-mode Remote Runtime startup.** Fixed a race in Linux Host `bwrap` launch identity verification that could reject Ask-mode requests before the model was called. The Agent now verifies the bounded transition from the fixed sandbox launcher to the expected signed executable."
],
"notices": [
"**Remote Projects technical preview and Agent requirement.** Remote Projects remain disabled by default and in technical preview. Hosts must update to the separately published Agent `0.11.10` to receive the Ask-mode startup fix. Linux x64 and arm64 are provided; desktop packages do not embed the Agent or Remote Runtime. This release does not include a LoongArch preview."
]
}
}
},
{
"version": "0.11.11",
"releasedAt": "2026-08-30",
"notes": {
"zh-CN": {
"highlights": [],
"features": [],
"fixes": [
"**远程会话完整保存。** 修复托管 SSH 远程项目的工具结果较长时,会话持久化失败并可能让已完成回复仍显示为生成中的问题。Runtime 已返回的工具输入、输出、错误和摘要现在会完整保存到本地会话,不再受额外的会话字段长度限制。",
"**魔法笔记列表快捷输入更易发现。** 编辑区现在提示输入 `-`、`1.`、`[ ]` 或 `[x]` 后按空格即可创建项目符号、编号或待办清单,并增加行为覆盖以防快捷输入回退。"
],
"notices": []
},
"en-US": {
"highlights": [],
"features": [],
"fixes": [
"**Complete remote conversation saves.** Fixed conversation persistence failing for managed SSH Remote Projects when tool results were long, which could leave a completed reply displayed as still generating. Tool input, output, errors, and summaries already returned by the Runtime are now saved completely without additional conversation-field length limits.",
"**Discoverable Magic Notes list shortcuts.** The editor now explains that typing `-`, `1.`, `[ ]`, or `[x]` followed by Space creates a bullet, numbered, or checklist item, with behavior coverage to prevent regressions."
],
"notices": []
}
}
},
{
"version": "0.11.10",
"releasedAt": "2026-08-29",
"notes": {
"zh-CN": {
"highlights": [
"GoodBuddy 0.11.10 修复正式环境中的 Host 更新失败,并显著缩短 Agent 与 OpenCode Runtime 的安装、恢复和日常启动校验。"
],
"features": [],
"fixes": [
"**Host 更新恢复可用。** 修复已发布 OpenCode Runtime 在采用阶段被桌面内置锁重复校验而失败的问题。Host 现在使用签名复合包中的版本锁和身份,并在同一条固定 SSH 连接上完成 Agent 启动、健康检查与 Runtime 激活。",
"**不再重复扫描远端包体。** 每种获取路径只对复合包执行一次完整 SHA-256;Host installer 在解包时验证全部签名与 payload digest,commit 只检查签名元数据。Main 不再通过 SFTP 逐文件读取 Agent/Runtime,后续健康检查、能力发现和每次提问只使用已登记 identity、manifest 与入口元数据。仍保留 SHA-256,提速来自消除重复读取。",
"**失败后直接重试。** 未完成操作只保留一个小型 staging 清理记录;下次更新先尽力清理旧暂存,再重新 prepare,不保存或回滚 Agent/Runtime 元数据副本。已健康环境不会因暂存清理失败而回滚,安装错误仍会显示具体的有界原因。"
],
"notices": [
"**技术预览与版本要求。** 远程项目仍默认关闭且为技术预览。Host 需要安装单独发布的 Agent `0.11.9`,提供 Linux x64 和 arm64;桌面包不内置 Agent 或远程 Runtime,本次不构建 LoongArch 预览。"
]
},
"en-US": {
"highlights": [
"GoodBuddy 0.11.10 fixes Host updates in production and substantially reduces Agent and OpenCode Runtime verification during installation, recovery, and normal startup."
],
"features": [],
"fixes": [
"**Host updates work again.** Fixed published OpenCode Runtime adoption failing because it was redundantly checked against the desktop-bundled lock. The Host now uses the signed compound package's lock and identity, then starts and health-checks the Agent and activates Runtime on one pinned SSH connection.",
"**No repeated remote payload scans.** The Host completes full SHA-256 and signature verification while extracting, and commit checks only signed metadata. Main no longer reads Agent or Runtime file trees over SFTP. Later health, capability, and prompt paths use registered identities, manifests, and entrypoint metadata. SHA-256 remains; the speedup comes from eliminating rereads.",
"**Reliable interruption and cleanup recovery.** Interrupted commits resume from authenticated prepared state. Pending recovery keeps snapshots of all five metadata files and restores them if adoption fails. Once the environment is healthy, staging cleanup failures are retried instead of rolling it back, and bounded installer errors retain their concrete cause."
"**No repeated remote payload scans.** Each acquisition path performs one full SHA-256 pass over the compound package. The Host installer verifies every signature and payload digest while extracting, and commit checks only signed metadata. Main no longer reads Agent or Runtime file trees over SFTP. Later health, capability, and prompt paths use registered identities, manifests, and entrypoint metadata. SHA-256 remains; the speedup comes from eliminating rereads.",
"**Simple retry after failures.** An unfinished operation keeps only a small staging-cleanup receipt. The next update makes one best-effort cleanup attempt and performs a fresh prepare without saving or restoring copies of Agent or Runtime metadata. A healthy environment is not rolled back for staging cleanup failures, and bounded installer errors retain their concrete cause."
],
"notices": [
"**Technical preview and version requirement.** Remote Projects remain disabled by default and in technical preview. Hosts require the separately published Agent `0.11.8` for Linux x64 or arm64. Desktop packages do not embed the Agent or remote Runtime, and this release does not build a LoongArch preview."
"**Technical preview and version requirement.** Remote Projects remain disabled by default and in technical preview. Hosts require the separately published Agent `0.11.9` for Linux x64 or arm64. Desktop packages do not embed the Agent or remote Runtime, and this release does not build a LoongArch preview."
]
}
}
+13 -8
View File
@@ -31,7 +31,7 @@ import {
loadRegisteredAgentBundle,
readManagedAgentReleaseKeyRegistry,
RegisteredAgentBundleError,
verifyInstalledAgentBundle,
verifyPublishedAgentBundle,
type VerifiedInstalledAgentBundle
} from './installed-bundle-verifier'
import { InstallationRegistry } from './installation-registry'
@@ -41,7 +41,7 @@ import {
import {
loadRegisteredRuntimeBundle,
readRemoteRuntimeLock,
verifyRuntimeBundle,
verifyPublishedRuntimeBundle,
type VerifiedRuntimeBundle
} from './runtime-bundle-verifier'
import { createProductionRuntimeProtocol } from './runtime-composition'
@@ -91,7 +91,7 @@ export type AgentCliDependencies = {
runtimeReleaseKeyRegistry?: AgentReleaseKeyRegistry
runtimeLock?: RemoteRuntimeLock
runtimeRegistry?: RuntimeBundleRegistry
verifyRuntime?: typeof verifyRuntimeBundle
verifyRuntime?: typeof verifyPublishedRuntimeBundle
runtimeVerificationEnvironment?: 'production' | 'test'
currentArchitecture?: () => AgentArchitecture
runModelBridgeHelper?: typeof runOpenCodeModelBridgeHelper
@@ -299,7 +299,7 @@ async function runRuntime(
const verified =
registered === undefined || forceVerification
? await (
dependencies.verifyRuntime ?? verifyRuntimeBundle
dependencies.verifyRuntime ?? verifyPublishedRuntimeBundle
)(paths.bundleDirectory, verificationOptions)
: await loadRegisteredRuntimeBundle(
registered.bundleDirectory,
@@ -524,10 +524,11 @@ async function runLifecycle(
paths,
dependencies
)
const alreadyCurrent =
const currentInstallationMatches =
registry.snapshot().current?.installationId ===
installationId
if (!alreadyCurrent) {
const alreadyCurrent = registry.isCurrent(verified)
if (!alreadyCurrent && !currentInstallationMatches) {
registry.stageCandidate(verified)
}
prepareManagedSocketDirectory(paths)
@@ -539,7 +540,11 @@ async function runLifecycle(
verified
).bootstrap()
if (!alreadyCurrent) {
registry.promoteCandidate(installationId)
if (currentInstallationMatches) {
registry.refreshCurrent(verified)
} else {
registry.promoteCandidate(installationId)
}
}
io.output.write(`${JSON.stringify(status)}\n`)
break
@@ -757,7 +762,7 @@ async function verifyManagedInstallation(
storagePath: resolve(agentRoot, 'registry.json')
})
const verified = await (
dependencies.verifyInstallation ?? verifyInstalledAgentBundle
dependencies.verifyInstallation ?? verifyPublishedAgentBundle
)(dirname(paths.executablePath), {
installationId,
architecture,
@@ -5,6 +5,9 @@ import { join } from 'node:path'
import { PassThrough } from 'node:stream'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { RemoteRuntimeBundleManifest } from '../shared/remote-runtime-launch-contracts'
import {
UNBOUNDED_REMOTE_PROMPT_DEADLINE
} from '../shared/remote-agent-contracts'
import {
launchDirectLinuxStdioProcessOwner,
reconcileOrphanedDirectLinuxStdioProcesses,
@@ -119,6 +122,47 @@ describe('direct Linux stdio Runtime ownership', () => {
registry.close()
})
it('waits for bubblewrap to exec the supervised bridge helper', async () => {
const registry = createRegistry()
const child = fakeChild()
const bwrapIdentity = identity()
const helperIdentity = {
...bwrapIdentity,
executablePath: '/agent/node'
}
const spawn: DirectLinuxStdioSpawn = () => {
queueMicrotask(() => child.emit('spawn'))
return child
}
const readProcessIdentity = vi
.fn()
.mockResolvedValueOnce(bwrapIdentity)
.mockResolvedValue(helperIdentity)
const owner = await launchDirectLinuxStdioProcessOwner({
manifest: manifest(),
profile: {
...profile(),
processExecutable: '/agent/node'
},
identity: { launchId: 'launch-1', processId: 'process-1' },
installationId: 'installation-1',
registry,
deadlineAt: '2030-01-01T00:00:00.000Z',
maximumInputBytes: 1024,
platform: 'linux',
spawn,
randomOwnerToken: () => 'a'.repeat(32),
readProcessIdentity
})
expect(readProcessIdentity).toHaveBeenCalledTimes(2)
expect(owner.processIdentity).toEqual(helperIdentity)
child.exitCode = 0
child.emit('close', 0, null)
registry.close()
})
it('rejects PID reuse before sending any signal', async () => {
const registry = createRegistry()
const child = fakeChild()
@@ -208,6 +252,48 @@ describe('direct Linux stdio Runtime ownership', () => {
registry.close()
})
it('does not stop an active prompt at the unbounded Runtime deadline', async () => {
vi.useFakeTimers()
try {
const registry = createRegistry()
const child = fakeChild()
const launched = identity()
const sendSignal = vi.fn<typeof process.kill>(() => true)
const owner = await launchDirectLinuxStdioProcessOwner({
manifest: manifest(),
profile: profile(),
identity: { launchId: 'launch-long', processId: 'process-long' },
installationId: 'installation-1',
registry,
deadlineAt: UNBOUNDED_REMOTE_PROMPT_DEADLINE,
maximumInputBytes: 1024,
platform: 'linux',
spawn: () => {
queueMicrotask(() => child.emit('spawn'))
return child
},
randomOwnerToken: () => 'a'.repeat(32),
readProcessIdentity: async () => launched,
listPidNamespaceMembers: async () => [],
sendSignal
})
await vi.advanceTimersByTimeAsync(25 * 60 * 60_000)
expect(sendSignal).not.toHaveBeenCalled()
expect(await owner.reconcile()).toMatchObject({
state: 'running',
processTree: 'running'
})
await owner.stop({
reason: 'user-cancelled',
deadlineAt: new Date(Date.now() + 10_000).toISOString()
})
registry.close()
} finally {
vi.useRealTimers()
}
})
it('startup reconciles only owners from the current installation', async () => {
const registry = createRegistry()
const reservation = {
@@ -8,6 +8,9 @@ import {
sha256DigestSchema
} from '../shared/agent-protocol/contracts'
import { canonicalJson } from '../shared/agent-protocol/canonical'
import {
UNBOUNDED_REMOTE_PROMPT_DEADLINE
} from '../shared/remote-agent-contracts'
import {
remoteRuntimeBundleManifestSchema,
type RemoteRuntimeBundleManifest
@@ -31,6 +34,7 @@ const DEFAULT_MAXIMUM_STDIN_WRITE_BYTES = 1024 * 1024
const DEFAULT_MAXIMUM_OUTPUT_QUEUE_CHUNKS = 128
const DEFAULT_MAXIMUM_LISTENERS = 8
const DEFAULT_STOP_TIMEOUT_MS = 10_000
const DEFAULT_LAUNCH_IDENTITY_TIMEOUT_MS = 5_000
const TERM_GRACE_MS = 2_000
const POLL_INTERVAL_MS = 25
const OWNER_TOKEN_ENVIRONMENT_NAME = 'GOODBUDDY_RUNTIME_OWNER_TOKEN'
@@ -510,6 +514,10 @@ export class DirectLinuxStdioProcessOwner {
}
#scheduleDeadline(deadlineAt: string): void {
if (deadlineAt === UNBOUNDED_REMOTE_PROMPT_DEADLINE) {
this.#clearDeadline()
return
}
const remaining = remainingMilliseconds(deadlineAt, this.#now())
this.#clearDeadline()
const generation = this.#promptGeneration
@@ -550,7 +558,10 @@ export async function launchDirectLinuxStdioProcessOwner(
now(),
limits.maximumPromptRuntimeMilliseconds
)
const timeoutMs = remainingMilliseconds(effectiveDeadlineAt, now())
const timeoutMs =
effectiveDeadlineAt === UNBOUNDED_REMOTE_PROMPT_DEADLINE
? DEFAULT_LAUNCH_IDENTITY_TIMEOUT_MS
: remainingMilliseconds(effectiveDeadlineAt, now())
const baseProfile = resolveProfile(options, manifest)
const ownerToken = (options.randomOwnerToken ?? (() => randomBytes(16).toString('hex')))()
if (!/^[a-f0-9]{32}$/u.test(ownerToken)) {
@@ -603,8 +614,18 @@ export async function launchDirectLinuxStdioProcessOwner(
await waitForSpawn(child, options.signal, timeoutMs)
if (child.pid === undefined) throw new Error('Runtime spawn did not return a PID')
const readIdentity = options.readProcessIdentity ?? readLinuxRuntimeProcessIdentity
const processIdentity = await readIdentity(child.pid)
assertLaunchedIdentity(processIdentity, profile)
const processIdentity = await waitForLaunchedIdentity({
child,
pid: child.pid,
profile,
readIdentity,
signal: options.signal,
deadline: Math.min(
Date.parse(effectiveDeadlineAt),
now() + DEFAULT_LAUNCH_IDENTITY_TIMEOUT_MS
),
now
})
const supervisorIdentityDigest = supervisorDigest({
installationId,
ownerId,
@@ -871,15 +892,72 @@ function validateProfile(profile: OpenCodeLaunchProfile): OpenCodeLaunchProfile
}
}
function assertLaunchedIdentity(
identity: LinuxRuntimeProcessIdentity,
async function waitForLaunchedIdentity(input: {
child: DirectLinuxStdioChild
pid: number
profile: OpenCodeLaunchProfile
): void {
if (
identity.executablePath !== profile.processExecutable ||
identity.processGroupId !== identity.pid
) {
throw identityError('Spawned Runtime does not match the launch identity')
readIdentity: typeof readLinuxRuntimeProcessIdentity
signal?: AbortSignal
deadline: number
now: () => number
}): Promise<LinuxRuntimeProcessIdentity> {
for (;;) {
input.signal?.throwIfAborted()
if (
input.child.exitCode !== null ||
input.child.signalCode !== null
) {
throw new DirectLinuxStdioProcessOwnerError(
'Runtime process exited during launch',
'process'
)
}
let identity: LinuxRuntimeProcessIdentity
try {
identity = await input.readIdentity(input.pid)
} catch (error) {
if (!isMissingProcess(error)) {
throw error
}
if (input.now() >= input.deadline) {
throw new DirectLinuxStdioProcessOwnerError(
'Runtime launch identity was not observed',
'process'
)
}
await delay(
Math.min(
POLL_INTERVAL_MS,
Math.max(1, input.deadline - input.now())
)
)
continue
}
if (identity.processGroupId !== identity.pid) {
throw identityError(
'Spawned Runtime does not match the launch identity'
)
}
if (identity.executablePath === input.profile.processExecutable) {
return identity
}
if (identity.executablePath !== input.profile.executable) {
throw identityError(
'Spawned Runtime does not match the launch identity'
)
}
if (input.now() >= input.deadline) {
throw new DirectLinuxStdioProcessOwnerError(
'Runtime launch did not reach its supervised executable',
'process'
)
}
await delay(
Math.min(
POLL_INTERVAL_MS,
Math.max(1, input.deadline - input.now())
)
)
}
}
@@ -1029,6 +1107,9 @@ function boundedPromptDeadline(
now: number,
maximumRuntimeMilliseconds: number
): string {
if (requestedDeadlineAt === UNBOUNDED_REMOTE_PROMPT_DEADLINE) {
return requestedDeadlineAt
}
const requested = Date.parse(requestedDeadlineAt)
if (!Number.isFinite(requested) || requested <= now) {
throw new DirectLinuxStdioProcessOwnerError(
@@ -76,6 +76,33 @@ describe('Agent installation registry', () => {
).toThrow('authorized registry role')
})
it('replaces same-installation legacy metadata after verification', () => {
const root = privateTemporaryDirectory()
const storagePath = resolve(root, 'registry.json')
writeFileSync(
storagePath,
`${JSON.stringify({
formatVersion: 1,
current: {
installationId: 'install-a',
agentVersion: '0.11.1',
manifestSha256: 'a'.repeat(64),
arch: 'x64'
}
}, null, 2)}\n`,
{ mode: 0o600 }
)
const registry = new InstallationRegistry({ storagePath })
const current = verified('install-a', '0.11.1', 'a')
expect(registry.isCurrent(current)).toBe(false)
registry.refreshCurrent(current)
expect(registry.snapshot().current).toMatchObject({
installationId: 'install-a',
protocol: { major: 1, minor: 0 }
})
})
it('replaces a stale candidate with the requested signed identity', () => {
const { registry } = createRegistry()
registry.stageCandidate(verified('install-a', '0.11.0', 'a'))
+30 -1
View File
@@ -40,6 +40,14 @@ export class InstallationRegistry {
return structuredClone(this.#state)
}
isCurrent(verified: VerifiedInstalledAgentBundle): boolean {
const current = this.#state.current
return (
current !== undefined &&
entryEquals(current, entryFromVerified(verified))
)
}
stageCandidate(
verified: VerifiedInstalledAgentBundle
): InstallationRegistryEntry {
@@ -100,6 +108,25 @@ export class InstallationRegistry {
return this.snapshot()
}
refreshCurrent(
verified: VerifiedInstalledAgentBundle
): InstallationRegistryState {
const entry = entryFromVerified(verified)
if (
this.#state.current?.installationId !==
entry.installationId
) {
throw new Error(
'Verified Agent installation is not the current identity'
)
}
this.#commit({
formatVersion: 1,
current: entry
})
return this.snapshot()
}
assertVerifiedRole(
verified: VerifiedInstalledAgentBundle,
roles: readonly ('current' | 'candidate')[]
@@ -234,7 +261,9 @@ function entryEquals(
left.installationId === right.installationId &&
left.agentVersion === right.agentVersion &&
left.manifestSha256 === right.manifestSha256 &&
left.arch === right.arch
left.arch === right.arch &&
JSON.stringify(left.protocol) ===
JSON.stringify(right.protocol)
)
}
@@ -24,6 +24,7 @@ import {
canonicalInstalledAgentManifestBytes,
installedAgentManifestSignaturePayload,
loadRegisteredAgentBundle,
verifyPublishedAgentBundle,
verifyInstalledAgentBundle
} from './installed-bundle-verifier'
@@ -88,7 +89,7 @@ describe('installed Agent bundle verifier', () => {
'tampered'
)
await expect(verifyBundle()).rejects.toThrow(
/size mismatch|hash mismatch/u
/entrypoint metadata changed|size mismatch|hash mismatch/u
)
resetInstallation()
@@ -112,7 +113,9 @@ describe('installed Agent bundle verifier', () => {
if (process.platform !== 'win32') {
writeBundle()
chmodSync(join(installationDirectory, 'goodbuddy-agent'), 0o777)
await expect(verifyBundle()).rejects.toThrow('mode mismatch')
await expect(verifyBundle()).rejects.toThrow(
'entrypoint metadata changed'
)
resetInstallation()
}
@@ -134,6 +137,26 @@ describe('installed Agent bundle verifier', () => {
})
it('adopts signed published metadata without rehashing unrelated payload', async () => {
writeBundle()
writeFileSync(
join(installationDirectory, 'licenses', 'GoodBuddy-0BSD.txt'),
'changed after extraction'
)
await expect(verifyPublishedBundle()).resolves.toMatchObject({
installationId: 'install-10',
manifest: { agentVersion: '0.11.0' }
})
writeFileSync(
join(installationDirectory, 'lib', 'agent.cjs'),
'changed entrypoint'
)
await expect(verifyPublishedBundle()).rejects.toThrow(
'entrypoint metadata changed'
)
})
it('loads Host-managed registry evidence without repeating signature or payload verification', async () => {
writeBundle()
const manifestBytes = readFileSync(
@@ -269,6 +292,16 @@ function verifyBundle() {
})
}
function verifyPublishedBundle() {
return verifyPublishedAgentBundle(installationDirectory, {
installationId: 'install-10',
architecture: 'x64',
releaseKeyRegistry,
verificationEnvironment: 'test',
enforceFilesystemMode: process.platform !== 'win32'
})
}
function elf(architecture: 'x64' | 'arm64'): Buffer {
const header = Buffer.alloc(64)
header.set([0x7f, 0x45, 0x4c, 0x46])
+101 -69
View File
@@ -110,6 +110,66 @@ export async function readManagedAgentReleaseKeyRegistry(
export async function verifyInstalledAgentBundle(
installationDirectoryInput: string,
options: VerifyInstalledAgentBundleOptions
): Promise<VerifiedInstalledAgentBundle> {
const verified = await verifyPublishedAgentBundle(
installationDirectoryInput,
options
)
const {
installationDirectory,
manifest
} = verified
const declaredPaths = new Set(
manifest.files.map((file) => file.path)
)
for (const file of manifest.files) {
const filePath = join(
installationDirectory,
...file.path.split('/')
)
const stat = await lstat(filePath)
assertOwnedRegularFile(stat, file.path, options.uid)
if (stat.size !== file.size) {
throw new Error(`Agent payload size mismatch: ${file.path}`)
}
if ((await sha256File(filePath)) !== file.sha256) {
throw new Error(`Agent payload hash mismatch: ${file.path}`)
}
if (
shouldEnforceMode(options) &&
modeString(stat.mode) !== file.mode
) {
throw new Error(`Agent payload mode mismatch: ${file.path}`)
}
}
const actualPaths = new Set(
await listInstallationFiles(installationDirectory, options)
)
const expectedPaths = new Set([
...declaredPaths,
MANIFEST_FILE_NAME,
SIGNATURE_FILE_NAME
])
if (
actualPaths.size !== expectedPaths.size ||
[...actualPaths].some((path) => !expectedPaths.has(path))
) {
throw new Error(
'Agent installation contains undeclared or missing files'
)
}
return verified
}
/**
* Authenticates a package-installer-published Agent from signed metadata and
* bounded entrypoint metadata. The installer already hashed every payload
* file while extracting it.
*/
export async function verifyPublishedAgentBundle(
installationDirectoryInput: string,
options: VerifyInstalledAgentBundleOptions
): Promise<VerifiedInstalledAgentBundle> {
const installationId = validateInstallationId(options.installationId)
const installationDirectory = resolve(installationDirectoryInput)
@@ -162,47 +222,11 @@ export async function verifyInstalledAgentBundle(
)
}
const declaredPaths = new Set(
manifest.files.map((file) => file.path)
const executablePath = await assertAgentEntrypoints(
installationDirectory,
manifest,
options
)
for (const file of manifest.files) {
const filePath = join(
installationDirectory,
...file.path.split('/')
)
const stat = await lstat(filePath)
assertOwnedRegularFile(stat, file.path, options.uid)
if (stat.size !== file.size) {
throw new Error(`Agent payload size mismatch: ${file.path}`)
}
if ((await sha256File(filePath)) !== file.sha256) {
throw new Error(`Agent payload hash mismatch: ${file.path}`)
}
if (
shouldEnforceMode(options) &&
modeString(stat.mode) !== file.mode
) {
throw new Error(`Agent payload mode mismatch: ${file.path}`)
}
}
const actualPaths = new Set(
await listInstallationFiles(installationDirectory, options)
)
const expectedPaths = new Set([
...declaredPaths,
MANIFEST_FILE_NAME,
SIGNATURE_FILE_NAME
])
if (
actualPaths.size !== expectedPaths.size ||
[...actualPaths].some((path) => !expectedPaths.has(path))
) {
throw new Error(
'Agent installation contains undeclared or missing files'
)
}
await assertElfArchitecture(
join(installationDirectory, manifest.entrypoint.runtimePath),
manifest.arch,
@@ -212,10 +236,7 @@ export async function verifyInstalledAgentBundle(
return {
installationId,
installationDirectory,
executablePath: join(
installationDirectory,
manifest.entrypoint.path
),
executablePath,
manifest,
manifestSha256,
binaryDigest: `sha256:${manifestSha256}`
@@ -326,19 +347,9 @@ async function loadRegisteredAgentBundleUnchecked(
)
}
const executablePath = join(
const executablePath = await assertAgentEntrypoints(
installationDirectory,
manifest.entrypoint.path
)
await assertRegisteredEntrypoint(executablePath, '0755', options)
await assertRegisteredEntrypoint(
join(installationDirectory, manifest.entrypoint.runtimePath),
'0755',
options
)
await assertRegisteredEntrypoint(
join(installationDirectory, manifest.entrypoint.scriptPath),
'0644',
manifest,
options
)
return {
@@ -500,24 +511,45 @@ function importPublicKey(key: AgentReleaseKey) {
return publicKey
}
async function assertRegisteredEntrypoint(
filePath: string,
expectedMode: string,
async function assertAgentEntrypoints(
installationDirectory: string,
manifest: AgentBundleManifest,
options: Pick<
LoadRegisteredAgentBundleOptions,
VerifyInstalledAgentBundleOptions,
'uid' | 'filesystemPlatform' | 'enforceFilesystemMode'
>
): Promise<void> {
const stat = await lstat(filePath)
assertOwnedRegularFile(stat, filePath, options.uid)
if (
shouldEnforceMode(options) &&
modeString(stat.mode) !== expectedMode
) {
throw new Error(
`Agent payload mode mismatch: ${basename(filePath)}`
): Promise<string> {
for (const path of [
manifest.entrypoint.path,
manifest.entrypoint.runtimePath,
manifest.entrypoint.scriptPath
]) {
const record = manifest.files.find((file) => file.path === path)
if (record === undefined) {
throw new Error(`Agent entrypoint is not declared: ${path}`)
}
const filePath = join(
installationDirectory,
...path.split('/')
)
const stat = await lstat(filePath)
assertOwnedRegularFile(stat, filePath, options.uid)
if (
stat.size !== record.size ||
(
shouldEnforceMode(options) &&
modeString(stat.mode) !== record.mode
)
) {
throw new Error(
`Agent entrypoint metadata changed: ${basename(filePath)}`
)
}
}
return join(
installationDirectory,
manifest.entrypoint.path
)
}
async function readMetadataFile(
@@ -241,6 +241,9 @@ describe('OpenCode bubblewrap launch profile', () => {
'--opencode-entrypoint',
resolve(fixture.bundleDirectory, 'bin', 'opencode')
])
expect(profile.processExecutable).toBe(
resolve(agentInstallationDirectory, 'node')
)
expect(profile.args.join('\0')).not.toMatch(
/api[-_]?key|authorization|bearer|(?:^|\0)--token(?:\0|$)/iu
)
+1 -1
View File
@@ -266,7 +266,7 @@ export function createOpenCodeLaunchProfile(input: {
return {
executable: OPENCODE_BWRAP_EXECUTABLE,
processExecutable: OPENCODE_BWRAP_EXECUTABLE,
processExecutable: runtimeCommand.executable,
args,
cwd: scratchDirectory,
env: {
+24 -1
View File
@@ -1,7 +1,8 @@
import { describe, expect, it, vi } from 'vitest'
import {
type AcpJournalCursor,
type RemotePromptOperationPreparation
type RemotePromptOperationPreparation,
UNBOUNDED_REMOTE_PROMPT_DEADLINE
} from '../shared/remote-agent-contracts'
import type { RemoteRuntimeBundleManifest } from '../shared/remote-runtime-launch-contracts'
import type { ControllerLease } from './controller-registry'
@@ -813,6 +814,28 @@ describe('RuntimeAcpBackend', () => {
).rejects.toMatchObject({ code: 'deadline' })
})
it('keeps an unbounded Runtime prompt alive without a wall-clock timer', async () => {
vi.useFakeTimers()
try {
const fixture = harness()
await open(fixture)
await invoke(
fixture,
'runtime/preparePrompt',
fixture.preparation({
deadlineAt: UNBOUNDED_REMOTE_PROMPT_DEADLINE
})
)
await vi.advanceTimersByTimeAsync(30 * 24 * 60 * 60_000)
expect(fixture.process.stops).toEqual([])
await fixture.process.emit('stdout', 'still-running')
expect(fixture.outputFrames).toEqual(['still-running'])
} finally {
vi.useRealTimers()
}
})
it('stops the process when its output quota is exceeded', async () => {
const fixture = harness({ maximumOutputBytes: 3 })
await open(fixture)
+5
View File
@@ -25,6 +25,7 @@ import {
acpJournalCursorSchema,
remotePromptOperationAcceptanceSchema,
remotePromptOperationPreparationSchema,
UNBOUNDED_REMOTE_PROMPT_DEADLINE,
type AcpJournalCursor,
type RemotePromptOperationAcceptance,
type RemotePromptOperationPreparation
@@ -1676,6 +1677,10 @@ export class RuntimeAcpBackend {
#scheduleDeadline(binding: BindingState, deadlineAt: string): void {
if (binding.deadlineTimer !== undefined) {
clearTimeout(binding.deadlineTimer)
binding.deadlineTimer = undefined
}
if (deadlineAt === UNBOUNDED_REMOTE_PROMPT_DEADLINE) {
return
}
const delay = Math.max(
1,
+4 -15
View File
@@ -283,8 +283,8 @@ async function loadVerifiedRuntimeCapabilities(
entry.runtimeId,
entry.bundleDigest
)
const verified = options.loadRegistered === undefined
? await loadRegisteredRuntimeBundle(
await (options.loadRegistered === undefined
? loadRegisteredRuntimeBundle(
bundleDirectory,
{
registered: entry,
@@ -315,21 +315,10 @@ async function loadVerifiedRuntimeCapabilities(
: { uid: options.uid })
}
)
: await options.loadRegistered(
: options.loadRegistered(
entry,
bundleDirectory
)
if (
verified.manifest.runtimeVersion !== entry.runtimeVersion ||
verified.manifestDigest !== entry.manifestDigest ||
verified.manifest.bundleDigest !== entry.bundleDigest ||
verified.manifest.acpCapabilitiesDigest !==
entry.acpCapabilitiesDigest
) {
throw new Error(
'Runtime bundle no longer matches its registry identity'
)
}
))
capabilities.push({
runtimeId: entry.runtimeId,
version: entry.runtimeVersion,
@@ -8,7 +8,10 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import {
type RemoteRuntimeBundleManifest
} from '../shared/remote-runtime-launch-contracts'
import { verifyRuntimeBundle } from './runtime-bundle-verifier'
import {
verifyPublishedRuntimeBundle,
verifyRuntimeBundle
} from './runtime-bundle-verifier'
import {
RuntimeBundleRegistry,
createVerifiedRuntimeCapabilitySource
@@ -216,6 +219,45 @@ describe('Remote Runtime bundle verifier', () => {
expect.any(Error)
)
})
it('adopts signed published metadata without rehashing unrelated payload', async () => {
const fixture = await createBundle()
const options = {
architecture: 'x64' as const,
releaseKeyRegistry: fixture.registry,
runtimeLock: lock,
verificationEnvironment: 'test' as const,
filesystemPlatform: 'win32' as const
}
writeFileSync(
join(fixture.bundleDirectory, 'licenses', 'opencode.txt'),
'changed after extraction'
)
await expect(
verifyPublishedRuntimeBundle(
fixture.bundleDirectory,
options
)
).resolves.toMatchObject({
manifest: { runtimeVersion: '1.18.9' }
})
writeFileSync(
join(fixture.bundleDirectory, 'bin', 'opencode'),
Buffer.concat([
readFileSync(
join(fixture.bundleDirectory, 'bin', 'opencode')
),
Buffer.from('changed')
])
)
await expect(
verifyPublishedRuntimeBundle(
fixture.bundleDirectory,
options
)
).rejects.toThrow('entrypoint metadata changed')
})
})
async function createBundle(
@@ -3,6 +3,7 @@ export {
loadRegisteredRuntimeBundle,
readRemoteRuntimeLock,
runtimeManifestSignaturePayload,
verifyPublishedRuntimeBundle,
verifyRuntimeBundle,
verifyRuntimeManifestSignature
} from '../shared/node/runtime-bundle-verifier'
+1 -11
View File
@@ -240,20 +240,10 @@ export async function createProductionRuntimeProtocol(
options.architecture
),
loadRegisteredRuntimeBundle: async (resolved) => {
const verified = await loadRegistered(
return await loadRegistered(
resolved.entry,
resolved.bundleDirectory
)
if (
verified.manifestDigest !== resolved.entry.manifestDigest ||
verified.manifest.bundleDigest !==
resolved.entry.bundleDigest
) {
throw new Error(
'Runtime bundle no longer matches its registered identity'
)
}
return verified
},
resolveWorkspace: async (preparation, context) =>
resolveCurrentWorkspace(
+260 -22
View File
@@ -259,10 +259,9 @@ function runtime(
assertHostCurrent: () => {},
cancellationGraceMs,
operationTimeoutMs: overrides.operationTimeoutMs ?? 100,
promptTimeoutMs:
overrides.promptTimeoutMs ??
overrides.operationTimeoutMs ??
100,
...(overrides.promptTimeoutMs === undefined
? {}
: { promptTimeoutMs: overrides.promptTimeoutMs }),
usage: {
runtime: 'opencode',
provider: 'test',
@@ -287,10 +286,9 @@ function factoryRuntime(
assertHostCurrent: () => {},
cancellationGraceMs: 5,
operationTimeoutMs: overrides.operationTimeoutMs ?? 100,
promptTimeoutMs:
overrides.promptTimeoutMs ??
overrides.operationTimeoutMs ??
100,
...(overrides.promptTimeoutMs === undefined
? {}
: { promptTimeoutMs: overrides.promptTimeoutMs }),
usage: {
runtime: 'opencode',
provider: 'test',
@@ -599,7 +597,7 @@ describe('AcpRemoteRuntime', () => {
})
it.each(['prompt-running', 'outcome-unknown'] as const)(
'does not replace a %s binding after identity changes',
'retires a %s binding before starting an explicit later prompt',
async (state) => {
const store = new MemoryRuntimeSessionBindingStore()
const active = {
@@ -625,7 +623,13 @@ describe('AcpRemoteRuntime', () => {
lastMainAckSequence: '0'
}
await store.put(active)
const factory = vi.fn(async () => fakeServer().channel)
const replacement = fakeServer()
const factory = vi.fn(
async (bindingId: string) => {
expect(bindingId).not.toBe(active.bindingId)
return replacement.channel
}
)
const instance = factoryRuntime(factory, store, {
identity: {
...identity,
@@ -633,22 +637,28 @@ describe('AcpRemoteRuntime', () => {
}
})
await expect(
collect(
instance.run(
{ ...request, requestId: 'prompt-2' },
new AbortController().signal
)
await collect(
instance.run(
{ ...request, requestId: 'prompt-2' },
new AbortController().signal
)
).rejects.toThrow('不会自动重放')
)
expect(factory).not.toHaveBeenCalled()
expect(factory).toHaveBeenCalledOnce()
expect(factory).not.toHaveBeenCalledWith(active.bindingId)
await expect(
store.getById(active.bindingId)
).resolves.toMatchObject({
bindingId: active.bindingId,
state: 'closed',
activePromptOperationId: undefined
})
await expect(
store.getByConversation(request.conversationId)
).resolves.toMatchObject({
bindingId: active.bindingId,
state: 'outcome-unknown',
activePromptOperationId: request.requestId
bindingId: factory.mock.calls[0]![0],
state: 'ready',
activePromptOperationId: undefined
})
await instance.dispose()
}
@@ -1246,6 +1256,233 @@ describe('AcpRemoteRuntime', () => {
])
})
it('merges incremental OpenCode Task input into native subagent events', async () => {
const client: { value?: AgentSideConnection } = {}
const server = fakeServer({
prompt: async ({ sessionId }) => {
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call',
toolCallId: 'task-1',
title: 'Review application architecture',
kind: 'other',
status: 'in_progress',
rawInput: {}
}
})
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call_update',
toolCallId: 'task-1',
status: 'in_progress',
rawInput: {
subagent_type: 'explorer',
description: 'Review application architecture',
prompt: 'Inspect the complete source tree.'
}
}
})
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call_update',
toolCallId: 'task-1',
status: 'in_progress',
rawInput: {
subagent_type: 'explorer',
description: 'Review application architecture',
prompt: 'Inspect the complete source tree.'
}
}
})
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call_update',
toolCallId: 'task-1',
status: 'completed',
rawOutput: 'Architecture review complete.'
}
})
return { stopReason: 'end_turn' }
}
})
client.value = server.client
const events = await collect(
runtime(server).run(
request,
new AbortController().signal,
async () => 'once'
)
)
expect(events.map((event) => event.type)).toEqual([
'status',
'tool',
'subagent',
'subagent',
'done'
])
expect(events[2]).toMatchObject({
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'task-1',
state: 'running'
})
expect(events[3]).toMatchObject({
state: 'completed',
output: 'Architecture review complete.'
})
})
it('bounds native subagent output per event and per request', async () => {
const client: { value?: AgentSideConnection } = {}
const server = fakeServer({
prompt: async ({ sessionId }) => {
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call',
toolCallId: 'task-bounded',
title: 'Bounded task',
kind: 'other',
status: 'completed',
rawInput: {
subagent_type: 'explorer',
prompt: 'Inspect the complete source tree.'
},
rawOutput: 'x'.repeat(100)
}
})
return { stopReason: 'end_turn' }
}
})
client.value = server.client
const events = await collect(
runtime(server, undefined, 5, {
maxEventCharacters: 10,
maxRequestOutputBytes: 1_000
}).run(
request,
new AbortController().signal,
async () => 'once'
)
)
expect(
events.find((event) => event.type === 'subagent')
).toMatchObject({
state: 'completed',
output: 'xxxxx…'
})
const overBudgetServer = fakeServer({
prompt: async ({ sessionId }) => {
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call',
toolCallId: 'task-over-budget',
title: 'Over-budget task',
kind: 'other',
status: 'completed',
rawInput: {
subagent_type: 'explorer',
prompt: 'Inspect the complete source tree.'
},
rawOutput: 'x'.repeat(100)
}
})
return { stopReason: 'end_turn' }
}
})
client.value = overBudgetServer.client
await expect(
collect(
runtime(overBudgetServer, undefined, 5, {
maxEventCharacters: 1_000,
maxRequestOutputBytes: 80
}).run(
{
...request,
requestId: 'b5b07fa5-f722-4bbc-ad19-33a6435817f1'
},
new AbortController().signal,
async () => 'once'
)
)
).rejects.toThrow('远端 Runtime 请求输出超过安全上限')
})
it('rejects more than 100 distinct remote tool calls', async () => {
const client: { value?: AgentSideConnection } = {}
const server = fakeServer({
prompt: async ({ sessionId }) => {
for (let index = 0; index <= 100; index += 1) {
await client.value!.sessionUpdate({
sessionId,
update: {
sessionUpdate: 'tool_call',
toolCallId: `call-${index}`,
title: 'tool',
status: 'in_progress'
}
})
}
return { stopReason: 'end_turn' }
}
})
client.value = server.client
await expect(
collect(
runtime(server).run(
request,
new AbortController().signal,
async () => 'once'
)
)
).rejects.toThrow(
'远端 Runtime 单次运行的工具调用超过 100 个'
)
})
it('does not impose a default wall-clock deadline on remote prompts', async () => {
vi.useFakeTimers()
try {
let release!: () => void
const gate = new Promise<void>((resolve) => {
release = resolve
})
const server = fakeServer({
prompt: async () => {
await gate
return { stopReason: 'end_turn' }
}
})
const running = collect(
runtime(server).run(
request,
new AbortController().signal,
async () => 'once'
)
)
await vi.waitFor(() => expect(server.prepare).toHaveBeenCalledOnce())
await vi.advanceTimersByTimeAsync(25 * 60 * 60_000)
expect(server.escalate).not.toHaveBeenCalled()
release()
await expect(running).resolves.toEqual([
expect.objectContaining({ type: 'status' }),
expect.objectContaining({ type: 'done' })
])
} finally {
vi.useRealTimers()
}
})
it('routes Execute permission through the authorizer and denies mutating Ask permission', async () => {
const client: { value?: AgentSideConnection } = {}
const outcomes: string[] = []
@@ -1715,7 +1952,8 @@ describe('AcpRemoteRuntime', () => {
})
})
const instance = runtime(server, store, 5, {
operationTimeoutMs: 20
operationTimeoutMs: 20,
promptTimeoutMs: 20
})
await expect(
+164 -32
View File
@@ -15,11 +15,15 @@ import {
import type {
AgentRuntimeStatus
} from '../../shared/contracts'
import {
maximumConversationToolActivities
} from '../../shared/assistant-contracts'
import {
assertRemotePromptAcceptanceMatchesPreparation,
remotePromptOperationAcceptanceSchema,
remotePromptOperationPreparationSchema,
runtimeSessionBindingSchema,
UNBOUNDED_REMOTE_PROMPT_DEADLINE,
type RemotePromptOperationAcceptance,
type RemotePromptOperationPreparation,
type RuntimeSessionBinding
@@ -48,6 +52,10 @@ import {
type RemoteRuntimeChannel
} from './remote-runtime-channel'
import type { RuntimeSessionBindingStore } from './runtime-session-binding-store'
import {
parseOpenCodeSubagentInput,
toOpenCodeSubagentEvent
} from './opencode-subagent'
type BindingIdentity = Pick<
RuntimeSessionBinding,
@@ -98,6 +106,7 @@ export type AcpRemoteRuntimeOptions = {
maxRequestOutputBytes?: number
cancellationGraceMs?: number
operationTimeoutMs?: number
/** Optional test/operator override. Production prompts are Runtime-controlled. */
promptTimeoutMs?: number
maxPendingUpdates?: number
maxPendingUpdateBytes?: number
@@ -120,6 +129,16 @@ type ActivePrompt = {
pendingUpdateBytes: number
inboundPaused: boolean
outputCharacters: number
toolCalls: Map<
string,
{
title?: string
kind?: string
status?: 'pending' | 'in_progress' | 'completed' | 'failed'
rawInput?: unknown
rawOutput?: unknown
}
>
open: boolean
completed: boolean
interruption?: Error
@@ -162,7 +181,6 @@ type ChannelContext = {
const DEFAULT_MAX_EVENT_CHARACTERS = 100_000
const DEFAULT_MAX_REQUEST_OUTPUT_BYTES = 1_000_000
const DEFAULT_OPERATION_TIMEOUT_MS = 30_000
const DEFAULT_PROMPT_TIMEOUT_MS = 120_000
const DEFAULT_CANCELLATION_GRACE_MS = 1_500
const DEFAULT_MAX_PENDING_UPDATES = 1_000
const DEFAULT_MAX_PENDING_UPDATE_BYTES = 4 * 1024 * 1024
@@ -188,6 +206,42 @@ function safeStringify(value: unknown, maximum: number): string | undefined {
}
}
function boundedRetainedValue(
value: unknown,
maximum: number
): unknown {
if (value === undefined) {
return undefined
}
if (typeof value === 'string') {
return value.length > maximum
? `${value.slice(0, maximum)}…`
: value
}
try {
const serialized = JSON.stringify(value)
if (serialized === undefined) {
return undefined
}
if (serialized.length > maximum) {
return `${serialized.slice(0, maximum)}…`
}
return JSON.parse(serialized) as unknown
} catch {
return undefined
}
}
function boundedRetainedToolInput(
value: unknown,
maximum: number
): unknown {
return (
parseOpenCodeSubagentInput(value) ??
boundedRetainedValue(value, maximum)
)
}
class RemoteOperationTimeoutError extends Error {
constructor(readonly operation: string) {
super(`远端 Runtime ${operation}超时`)
@@ -459,9 +513,8 @@ export class AcpRemoteRuntime implements AgentRuntime {
DEFAULT_OPERATION_TIMEOUT_MS
}
private get promptTimeoutMs(): number {
return this.options.promptTimeoutMs ??
DEFAULT_PROMPT_TIMEOUT_MS
private get promptTimeoutMs(): number | undefined {
return this.options.promptTimeoutMs
}
private async awaitOperation<T>(
@@ -833,7 +886,7 @@ export class AcpRemoteRuntime implements AgentRuntime {
return interrupted
}
private async persistRejectedPrompt(
private async persistClosedBinding(
binding: RuntimeSessionBinding
): Promise<RuntimeSessionBinding> {
const closed = runtimeSessionBindingSchema.parse({
@@ -982,9 +1035,10 @@ export class AcpRemoteRuntime implements AgentRuntime {
modelBridge?: RemoteModelBridgeSession
): RemotePromptOperationPreparation {
const workMode = request.workMode === 'execute' ? 'execute' : 'ask'
const deadlineAt = new Date(
Date.now() + this.promptTimeoutMs
).toISOString()
const deadlineAt =
this.promptTimeoutMs === undefined
? UNBOUNDED_REMOTE_PROMPT_DEADLINE
: new Date(Date.now() + this.promptTimeoutMs).toISOString()
const budget = {
// The Agent applies this to the complete ACP stdin stream, not only
// user content. The signed Runtime manifest supplies the effective
@@ -1198,24 +1252,19 @@ export class AcpRemoteRuntime implements AgentRuntime {
request: AgentExecutionRequest,
signal: AbortSignal
): Promise<SessionRecord> {
const old = await this.awaitLocalOperation(
let binding = await this.awaitLocalOperation(
'读取会话绑定',
this.options.bindingStore.getByConversation(conversationId),
signal
)
if (
old &&
old.state !== 'closed' &&
old.state !== 'ready'
binding &&
binding.state !== 'closed' &&
binding.state !== 'ready'
) {
await this.persistInterrupted(old)
throw new Error(
old.state === 'prompt-running'
? '远端 ACP 会话存在未确认的活动请求,结果未知且不会自动重放'
: '远端 ACP 会话恢复状态不确定,已中断且不会自动重放'
)
await this.persistClosedBinding(binding)
binding = undefined
}
let binding = old
let bindingId = binding?.bindingId ?? randomUUID()
if (
binding?.state === 'ready' &&
@@ -1437,7 +1486,7 @@ export class AcpRemoteRuntime implements AgentRuntime {
error,
'runtime/preparePrompt'
)
? this.persistRejectedPrompt(binding)
? this.persistClosedBinding(binding)
: this.persistInterrupted(binding)
await persist.catch(() => undefined)
}
@@ -1483,7 +1532,7 @@ export class AcpRemoteRuntime implements AgentRuntime {
error,
'runtime/preparePrompt'
)
? this.persistRejectedPrompt(current.binding)
? this.persistClosedBinding(current.binding)
: this.persistInterrupted(current.binding)
current.binding = await persist.catch(() => current.binding)
this.sessions.delete(conversationId)
@@ -1776,6 +1825,21 @@ export class AcpRemoteRuntime implements AgentRuntime {
(event.input?.length ?? 0) +
(event.output?.length ?? 0) +
(event.error?.length ?? 0)
} else if (event.type === 'subagent') {
const fieldMaximum = Math.max(1, Math.floor(maximum / 2))
const bounded = (value: string | undefined): string | undefined =>
value && value.length > fieldMaximum
? `${value.slice(0, fieldMaximum)}…`
: value
event = {
...event,
output: bounded(event.output),
error: bounded(event.error)
}
characters =
(event.reason?.length ?? 0) +
(event.output?.length ?? 0) +
(event.error?.length ?? 0)
} else if (event.type === 'status') {
if (event.message.length > maximum) {
event = {
@@ -1819,22 +1883,87 @@ export class AcpRemoteRuntime implements AgentRuntime {
update.sessionUpdate === 'tool_call' ||
update.sessionUpdate === 'tool_call_update'
) {
const callId = update.toolCallId.slice(0, 256)
const previous = prompt.toolCalls.get(callId)
if (
!previous &&
prompt.toolCalls.size >=
maximumConversationToolActivities
) {
throw new Error(
'远端 Runtime 单次运行的工具调用超过 100 个'
)
}
const retainedMaximum =
this.options.maxEventCharacters ??
DEFAULT_MAX_EVENT_CHARACTERS
const toolCall = {
title:
update.title === null
? undefined
: update.title?.slice(0, 200) ?? previous?.title,
kind:
update.kind === null
? undefined
: update.kind?.slice(0, 200) ?? previous?.kind,
status:
update.status === null
? undefined
: update.status ?? previous?.status,
rawInput:
update.rawInput === undefined
? previous?.rawInput
: boundedRetainedToolInput(
update.rawInput,
retainedMaximum
),
rawOutput:
update.rawOutput === undefined
? previous?.rawOutput
: boundedRetainedValue(
update.rawOutput,
retainedMaximum
)
}
if (previous && isDeepStrictEqual(previous, toolCall)) {
return undefined
}
prompt.toolCalls.set(callId, toolCall)
const name = (
update.title ??
update.kind ??
toolCall.title ??
toolCall.kind ??
'远端 Runtime 工具'
).slice(0, 200)
const input = safeStringify(update.rawInput, 100_000)
const output = safeStringify(update.rawOutput, 100_000)
const subagent =
this.options.runtimeId === 'opencode'
? toOpenCodeSubagentEvent({
requestId: prompt.requestId,
callId,
state: toolCall.status ?? 'pending',
input: toolCall.rawInput,
output: toolCall.rawOutput
})
: undefined
if (subagent) {
return subagent
}
const input = safeStringify(
toolCall.rawInput,
retainedMaximum
)
const output = safeStringify(
toolCall.rawOutput,
retainedMaximum
)
return {
requestId: prompt.requestId,
type: 'tool',
callId: update.toolCallId.slice(0, 256),
callId,
name,
state:
update.status === 'in_progress'
toolCall.status === 'in_progress'
? 'running'
: update.status ?? 'pending',
: toolCall.status ?? 'pending',
summary: `远端 Runtime 工具:${name}`,
...(input ? { input } : {}),
...(output ? { output } : {})
@@ -1930,6 +2059,7 @@ export class AcpRemoteRuntime implements AgentRuntime {
pendingUpdateBytes: 0,
inboundPaused: false,
outputCharacters: 0,
toolCalls: new Map(),
open: true,
completed: false,
context
@@ -1998,10 +2128,12 @@ export class AcpRemoteRuntime implements AgentRuntime {
prompt.wake?.()
prompt.wake = undefined
})
promptTimeout = setTimeout(
() => interrupt(new RemoteOperationTimeoutError('执行请求')),
this.promptTimeoutMs
)
if (this.promptTimeoutMs !== undefined) {
promptTimeout = setTimeout(
() => interrupt(new RemoteOperationTimeoutError('执行请求')),
this.promptTimeoutMs
)
}
yield {
requestId: request.requestId,
type: 'status',
+93 -3
View File
@@ -357,6 +357,9 @@ describe('ContinueHostAdapter', () => {
})
it('launches the prepared host through the injected launcher', async () => {
let now = Date.now()
const nowSpy = vi.spyOn(Date, 'now').mockImplementation(() => now)
environmentRestorations.push(() => nowSpy.mockRestore())
const distribution = await createDistribution()
const skillDirectory = join(
distribution.cacheRoot,
@@ -445,11 +448,14 @@ describe('ContinueHostAdapter', () => {
const url = String(input)
if (url.endsWith('/state')) {
stateRequests += 1
if (stateRequests === 2) {
now += 25 * 60 * 60_000
}
return new Response(
JSON.stringify({
session: {
history:
stateRequests === 1
stateRequests <= 2
? []
: [
{
@@ -460,7 +466,7 @@ describe('ContinueHostAdapter', () => {
}
],
usage:
stateRequests === 1
stateRequests <= 2
? {
promptTokens: 20,
completionTokens: 10,
@@ -478,7 +484,7 @@ describe('ContinueHostAdapter', () => {
}
}
},
isProcessing: false,
isProcessing: stateRequests === 2,
messageQueueLength: 0,
pendingPermission: null
})
@@ -605,6 +611,90 @@ describe('ContinueHostAdapter', () => {
expect(existsSync(generatedConfigPath)).toBe(false)
})
it('bounds each host control request without bounding the full run', async () => {
const distribution = await createDistribution()
let killed = false
const launchHost: ContinueHostLauncher = () => ({
exitCode: null,
get killed() {
return killed
},
stderr: null,
once: () => undefined,
kill: () => {
killed = true
return true
}
})
vi.stubGlobal(
'fetch',
vi.fn(
async (
input: string | URL | Request,
init?: RequestInit
): Promise<Response> => {
if (String(input).endsWith('/state')) {
return Response.json({
session: { history: [] },
isProcessing: false,
messageQueueLength: 0,
pendingPermission: null
})
}
if (String(input).endsWith('/message')) {
return await new Promise<Response>((_resolve, reject) => {
const rejectOnAbort = (): void =>
reject(init?.signal?.reason)
init?.signal?.addEventListener(
'abort',
rejectOnAbort,
{ once: true }
)
if (init?.signal?.aborted) {
rejectOnAbort()
}
})
}
return Response.json({})
}
)
)
const adapter = new ContinueHostAdapter(
{
binaryPath: distribution.entryPath,
configPath: '',
workspace: process.cwd(),
cacheRoot: distribution.cacheRoot,
trustedBundleHashes: [distribution.sourceHash],
launchHost,
modelProfile: {
id: '00000000-0000-4000-8000-000000000012',
name: '独立模型',
baseUrl: 'https://model.example',
modelName: 'private-model',
protocol: 'anthropic-messages',
authentication: 'api-key',
apiKey: 'private-key'
}
},
{
controlRequestTimeoutMs: 5,
terminateProcessTree: vi.fn(async (child) => {
child.kill()
})
}
)
await expect(
adapter.run(
'hello',
new AbortController().signal,
async () => 'deny'
)
).rejects.toThrow('Continue 宿主请求超时(/message)')
expect(killed).toBe(true)
})
it('injects scoped knowledge into a temporary copy of a JSONC config', async () => {
const distribution = await createDistribution()
const configPath = join(
+38 -30
View File
@@ -26,6 +26,9 @@ import type {
RuntimeNativeSnapshot,
RuntimeSettings
} from '../../shared/contracts'
import {
maximumConversationToolActivities
} from '../../shared/assistant-contracts'
import {
continueConfigurationPresetSchema,
runtimeNativeInventoryLimits,
@@ -66,8 +69,8 @@ const maximumConfiguredRules = runtimeNativeInventoryLimits.rules
const maximumConfiguredPrompts = runtimeNativeInventoryLimits.prompts
const maximumStreamEvents = 5_000
const maximumStreamEventBytes = 2 * 1024 * 1024
const maximumToolCalls = 100
const maximumExecutionMilliseconds = 10 * 60_000
const maximumToolCalls = maximumConversationToolActivities
const defaultControlRequestTimeoutMs = 30_000
const knowledgeMcpName = 'goodbuddy-knowledge'
const customMcpName = 'goodbuddy-custom-mcp'
export const continueConfigurationRequiredMessage =
@@ -246,6 +249,7 @@ export type ContinueHostAdapterDependencies = {
maximumStreamEvents: number
maximumStreamEventBytes: number
maximumToolCalls: number
controlRequestTimeoutMs: number
}
export type ContinueHostRunOptions = {
@@ -830,6 +834,7 @@ export class ContinueHostAdapter {
maximumStreamEvents,
maximumStreamEventBytes,
maximumToolCalls,
controlRequestTimeoutMs: defaultControlRequestTimeoutMs,
...dependencies
}
}
@@ -1140,16 +1145,32 @@ export class ContinueHostAdapter {
path: string,
init: RequestInit = {}
): Promise<unknown> {
const response = await fetch(`${origin}${path}`, {
...init,
headers: {
authorization: `Bearer ${token}`,
'content-type': 'application/json',
...init.headers
},
redirect: 'error',
signal: init.signal
})
const timeoutSignal = AbortSignal.timeout(
Math.max(1, this.dependencies.controlRequestTimeoutMs)
)
const requestSignal = init.signal
? AbortSignal.any([init.signal, timeoutSignal])
: timeoutSignal
let response: Response
try {
response = await fetch(`${origin}${path}`, {
...init,
headers: {
authorization: `Bearer ${token}`,
'content-type': 'application/json',
...init.headers
},
redirect: 'error',
signal: requestSignal
})
} catch (error) {
if (timeoutSignal.aborted && !init.signal?.aborted) {
throw new Error(`Continue 宿主请求超时(${path})`, {
cause: error
})
}
throw error
}
const body = await readBoundedResponseText(response, {
maxBytes: maximumStateBytes,
tooLargeMessage: 'Continue 宿主响应超过安全大小限制'
@@ -1559,7 +1580,6 @@ export class ContinueHostAdapter {
let streamEventCount = 0
let streamEventBytes = 0
const observedToolCallIds = new Set<string>()
let executionTimeoutSignal: AbortSignal | undefined
try {
const initialState = await this.waitForStartup(
child,
@@ -1569,13 +1589,7 @@ export class ContinueHostAdapter {
signal
)
const startIndex = initialState.session.history.length
executionTimeoutSignal = AbortSignal.timeout(
maximumExecutionMilliseconds
)
const executionSignal = AbortSignal.any([
signal,
executionTimeoutSignal
])
const executionSignal = signal
const message =
runOptions.images && runOptions.images.length > 0
? [
@@ -1598,9 +1612,8 @@ export class ContinueHostAdapter {
signal: executionSignal
})
const expiresAt = Date.now() + maximumExecutionMilliseconds
const handledPermissionIds = new Set<string>()
while (Date.now() < expiresAt) {
while (true) {
executionSignal.throwIfAborted()
if (childFailure) {
throw childFailure
@@ -1817,20 +1830,15 @@ export class ContinueHostAdapter {
}
await delay(150, executionSignal)
}
throw new Error('Continue 宿主执行超时')
} catch (error) {
if (error instanceof ContinueHostRunError) {
throw error
}
const normalizedError =
executionTimeoutSignal?.aborted && !signal.aborted
? new Error('Continue 宿主执行超时', { cause: error })
: error
throw new ContinueHostRunError(
normalizedError instanceof Error
? normalizedError.message
error instanceof Error
? error.message
: 'Continue 宿主执行失败',
{ cause: normalizedError, tools: observedTools }
{ cause: error, tools: observedTools }
)
} finally {
signal.removeEventListener('abort', abort)
+1 -1
View File
@@ -100,7 +100,7 @@ describe('createAgentRuntime model compatibility', () => {
{ deepseekHarnessLauncher: vi.fn() }
)
).toThrow(
'DeepSeek Harness 需要使用 API Key 的安全 OpenAI 兼容 Chat Completions 模型连接'
'DeepSeek Harness 需要使用 API Key 的 OpenAI 兼容 Chat Completions 模型连接'
)
})
+1 -1
View File
@@ -190,7 +190,7 @@ export function createAgentRuntime(
const profile = settings?.deepseekHarnessModelProfile
if (!profile || !isDeepSeekHarnessModelProfile(profile)) {
throw new Error(
'DeepSeek Harness 需要使用 API Key 的安全 OpenAI 兼容 Chat Completions 模型连接'
'DeepSeek Harness 需要使用 API Key 的 OpenAI 兼容 Chat Completions 模型连接'
)
}
if (!profile.apiKey) {
@@ -44,6 +44,7 @@ function setup(
nativeTools?: Array<Record<string, unknown>>
toolsSupported?: boolean
promptTimeoutMs?: number
useProductionPromptTimeout?: boolean
maxEventCharacters?: number
maxRequestOutputCharacters?: number
supportsImageInput?: boolean
@@ -51,6 +52,7 @@ function setup(
initializationTimeoutMs?: number
useDefaultInitializationTimeout?: boolean
launchDelayMs?: number
prepare?: () => Promise<Record<string, unknown>>
extensionPackages?: Array<{
id: string
entrypoint: string
@@ -170,7 +172,7 @@ function setup(
}
}
if (method === 'goodbuddy/session/prepare') {
return { prepared: true }
return options.prepare?.() ?? { prepared: true }
}
if (method === 'goodbuddy/session/release') {
return { released: true }
@@ -253,7 +255,9 @@ function setup(
initializationTimeoutMs:
options.initializationTimeoutMs ?? 100
}),
promptTimeoutMs: options.promptTimeoutMs ?? 100,
...(options.useProductionPromptTimeout
? {}
: { promptTimeoutMs: options.promptTimeoutMs ?? 100 }),
shutdownTimeoutMs: 10,
maxStderrBytes: 16,
maxEventCharacters: options.maxEventCharacters,
@@ -1347,6 +1351,62 @@ describe('DeepSeekHarnessRuntime', () => {
await harness.runtime.dispose()
})
it('does not submit a prompt after cancellation during preparation', async () => {
const prepare = deferred<Record<string, unknown>>()
const harness = setup({ prepare: () => prepare.promise })
const controller = new AbortController()
const running = collect(
harness.runtime.run(
request('cancel-during-prepare'),
controller.signal
)
)
await vi.waitFor(() =>
expect(
harness.requests.some(
({ method }) => method === 'goodbuddy/session/prepare'
)
).toBe(true)
)
controller.abort(new Error('cancelled during preparation'))
prepare.resolve({ prepared: true })
await expect(running).rejects.toThrow(
'cancelled during preparation'
)
expect(harness.agent.prompt).not.toHaveBeenCalled()
expect(harness.notifications).toContainEqual({
method: 'session/cancel',
params: { sessionId: 'session-1' }
})
await harness.runtime.dispose()
})
it('bounds cancellation when the harness prompt never settles', async () => {
const harness = setup({ useProductionPromptTimeout: true })
const controller = new AbortController()
const running = collect(
harness.runtime.run(
request('uncooperative-cancel'),
controller.signal
)
)
await vi.waitFor(() =>
expect(harness.promptGates).toHaveLength(1)
)
controller.abort(new Error('cancelled by user'))
await expect(running).rejects.toThrow('cancelled by user')
expect(harness.notifications).toContainEqual({
method: 'session/cancel',
params: { sessionId: 'session-1' }
})
expect(harness.child.terminate).toHaveBeenCalled()
await harness.runtime.dispose()
})
it('fails on bounded stderr overflow without exposing stderr text', async () => {
const harness = setup()
const running = collect(
@@ -1420,4 +1480,32 @@ describe('DeepSeekHarnessRuntime', () => {
})
await expect(harness.runtime.dispose()).resolves.toBeUndefined()
})
it('does not impose a default wall-clock deadline on prompts', async () => {
vi.useFakeTimers()
try {
const harness = setup({ useProductionPromptTimeout: true })
const running = collect(
harness.runtime.run(
request('long-running'),
new AbortController().signal
)
)
await vi.waitFor(() =>
expect(harness.promptGates).toHaveLength(1)
)
await vi.advanceTimersByTimeAsync(25 * 60 * 60_000)
expect(harness.notifications).not.toContainEqual({
method: 'session/cancel',
params: { sessionId: 'session-1' }
})
harness.promptGates[0]!.resolve({ stopReason: 'end_turn' })
await expect(running).resolves.toEqual([
expect.objectContaining({ type: 'status' }),
expect.objectContaining({ type: 'done' })
])
} finally {
vi.useRealTimers()
}
})
})
+70 -41
View File
@@ -38,7 +38,6 @@ import { deepSeekHarnessStartupBudget } from './deepseek-harness-control-protoco
const ACP_PACKAGE_NAME = '@agentclientprotocol/sdk'
const DEFAULT_INITIALIZATION_TIMEOUT_MS = 10_000
const DEFAULT_PROMPT_TIMEOUT_MS = 10 * 60_000
const DEFAULT_SHUTDOWN_TIMEOUT_MS = 2_000
const DEFAULT_MAX_STDERR_BYTES = 64 * 1024
const DEFAULT_MAX_EVENT_CHARACTERS = 64 * 1024
@@ -486,8 +485,8 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
)
}
private get promptTimeoutMs(): number {
return this.options.promptTimeoutMs ?? DEFAULT_PROMPT_TIMEOUT_MS
private get promptTimeoutMs(): number | undefined {
return this.options.promptTimeoutMs
}
private get shutdownTimeoutMs(): number {
@@ -1435,6 +1434,8 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
} else {
toolNames.delete(callId)
}
const input = safeStringify(update.rawInput)
const output = safeStringify(update.rawOutput)
return {
requestId,
type: 'tool',
@@ -1442,12 +1443,8 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
name,
state,
summary: `DeepSeek Harness 工具:${name}`,
...(safeStringify(update.rawInput)
? { input: safeStringify(update.rawInput) }
: {}),
...(safeStringify(update.rawOutput)
? { output: safeStringify(update.rawOutput) }
: {})
...(input ? { input } : {}),
...(output ? { output } : {})
}
}
return undefined
@@ -1505,8 +1502,10 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
| { stopReason?: string }
| undefined
let promptError: unknown
const promptController = new AbortController()
const cancel = (): void => {
run!.closed = true
run!.wake?.()
run!.wake = undefined
void state!.agent
.cancel({
sessionId: sessionId!
@@ -1514,33 +1513,47 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
.catch(() => undefined)
}
signal.addEventListener('abort', cancel, { once: true })
await withTimeout(
state.agent.extMethod(GOODBUDDY_PREPARE, {
sessionId,
requestId: request.requestId,
mode:
request.workMode === 'execute' ? 'execute' : 'ask'
}),
this.initializationTimeoutMs,
'请求准备'
)
const prompt = withTimeout(
state.agent.prompt({
sessionId,
prompt: [
{
type: 'text',
text: flattenPrompt(request)
},
...(request.images ?? []).map((image) => ({
type: 'image' as const,
data: image.data,
mimeType: image.mediaType
}))
]
}),
this.promptTimeoutMs,
'请求'
if (signal.aborted) {
cancel()
}
try {
await withTimeout(
state.agent.extMethod(GOODBUDDY_PREPARE, {
sessionId,
requestId: request.requestId,
mode:
request.workMode === 'execute' ? 'execute' : 'ask'
}),
this.initializationTimeoutMs,
'请求准备'
)
signal.throwIfAborted()
} catch (error) {
signal.removeEventListener('abort', cancel)
throw error
}
const promptOperation = state.agent.prompt({
sessionId,
prompt: [
{
type: 'text',
text: flattenPrompt(request)
},
...(request.images ?? []).map((image) => ({
type: 'image' as const,
data: image.data,
mimeType: image.mediaType
}))
]
})
const prompt = (
this.promptTimeoutMs === undefined
? promptOperation
: withTimeout(
promptOperation,
this.promptTimeoutMs,
'请求'
)
)
.then((value) => {
response = value
@@ -1555,9 +1568,15 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
})
try {
while (!completed || run.updates.length > 0) {
signal.throwIfAborted()
if (this.fatalError) {
throw this.fatalError
}
if (run.closed && !completed) {
throw new Error(
'DeepSeek Harness 请求在完成前已关闭'
)
}
if (run.updates.length === 0) {
await this.waitForUpdate(run)
continue
@@ -1588,11 +1607,21 @@ export class DeepSeekHarnessRuntime implements AgentRuntime {
sessionId
}
} finally {
promptController.abort(
new Error('DeepSeek Harness 流式消费已结束')
)
if (!completed) {
cancel()
}
signal.removeEventListener('abort', cancel)
await prompt
if (completed) {
await prompt
} else {
await withTimeout(
prompt,
this.shutdownTimeoutMs,
'取消请求'
).catch(async () => {
await this.terminate(state!.child)
})
}
}
} finally {
signal.removeEventListener('abort', abortTools)
@@ -50,7 +50,7 @@ async function fixture() {
launchOptions: {
cwd: workspace,
signal: new AbortController().signal,
baseUrl: 'https://gateway.example/openai/v1',
baseUrl: 'http://gateway.example/openai/v1?api-version=1',
model: 'qwen-plus',
supportsImageInput: false,
credentialRefs: [DEEPSEEK_HARNESS_CREDENTIAL_REF],
@@ -102,7 +102,7 @@ describe('DeepSeek Harness utility launcher', () => {
expect(utility.messages[0]).toMatchObject({
type: 'start',
config: {
baseUrl: 'https://gateway.example/openai/v1',
baseUrl: 'http://gateway.example/openai/v1?api-version=1',
model: 'qwen-plus',
supportsImageInput: false,
credentialRefs: [DEEPSEEK_HARNESS_CREDENTIAL_REF]
@@ -235,10 +235,9 @@ describe('DeepSeek Harness utility launcher', () => {
})
it.each([
'http://gateway.example/v1',
'https://user:secret@gateway.example/v1',
'https://gateway.example/v1?api-version=2025-01-01'
])('rejects unsafe endpoint %s before forking', async (baseUrl) => {
'file:///private/config',
'ftp://gateway.example/v1'
])('rejects unsupported endpoint %s before forking', async (baseUrl) => {
const { dshHome, hostPath, launchOptions } = await fixture()
const fork = vi.fn()
const launcher = createDeepSeekHarnessUtilityLauncher({
@@ -250,7 +249,7 @@ describe('DeepSeek Harness utility launcher', () => {
await expect(
launcher({ ...launchOptions, baseUrl })
).rejects.toThrow('HTTPS')
).rejects.toThrow('HTTP 或 HTTPS')
expect(fork).not.toHaveBeenCalled()
})
})
@@ -149,7 +149,7 @@ export function createDeepSeekHarnessUtilityLauncher(
}
if (!isDeepSeekHarnessCompatibleBaseUrl(options.baseUrl)) {
throw new Error(
'DeepSeek Harness 模型地址必须使用 HTTPS 或本机回环 HTTP,且不得包含凭据、查询参数或片段'
'DeepSeek Harness 模型地址必须使用 HTTP 或 HTTPS'
)
}
if (
+307 -114
View File
@@ -58,10 +58,6 @@ function fakeClient() {
} as unknown as ReturnType<typeof createOpencodeClient>
}
function stdoutOf(child: SpawnedProcess): PassThrough {
return child.stdout as PassThrough
}
function stderrOf(child: SpawnedProcess): PassThrough {
return child.stderr as PassThrough
}
@@ -91,6 +87,7 @@ function dependencies(
spawnMock: ReturnType<typeof vi.fn>
detectBinary: ReturnType<typeof vi.fn>
createClient: ReturnType<typeof vi.fn>
checkServerHealth: ReturnType<typeof vi.fn>
} {
const spawnMock = vi.fn(() => child)
const detectBinary = vi.fn().mockResolvedValue({
@@ -98,18 +95,21 @@ function dependencies(
detail: 'OpenCode CLI 已就绪'
})
const createClient = vi.fn(() => fakeClient())
const checkServerHealth = vi.fn().mockResolvedValue(true)
return {
deps: {
spawn: spawnMock as unknown as typeof spawn,
detectBinary,
createClient: createClient as unknown as typeof createOpencodeClient,
checkServerHealth,
platform: 'linux',
startupTimeoutMs: 100,
...overrides
},
spawnMock,
detectBinary,
createClient
createClient,
checkServerHealth
}
}
@@ -257,19 +257,16 @@ function embeddedRuntime(
client: ReturnType<typeof createOpencodeClient>,
overrides: Partial<
ConstructorParameters<typeof OpenCodeRuntime>[0]
> = {}
> = {},
dependencyOverrides: Partial<OpenCodeRuntimeDependencies> = {}
): OpenCodeRuntime {
const child = fakeChild()
const { deps } = dependencies(child, {
...dependencyOverrides,
createClient: vi.fn(
() => client
) as unknown as typeof createOpencodeClient
})
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:4010\n'
)
}, 0)
return new OpenCodeRuntime(options(overrides), deps)
}
@@ -301,6 +298,7 @@ describe('OpenCodeRuntime embedded launcher', () => {
detail: 'OpenCode CLI 已就绪'
})
const createClient = vi.fn(() => fakeClient())
const checkServerHealth = vi.fn().mockResolvedValue(true)
const spawnMock = vi.fn((command: string) => {
if (command === 'taskkill.exe') {
queueMicrotask(() => {
@@ -308,11 +306,6 @@ describe('OpenCodeRuntime embedded launcher', () => {
})
return killerChild
}
setTimeout(() => {
stdoutOf(serverChild).write(
'opencode server listening securely on http://127.0.0.1:43210\n'
)
}, 0)
return serverChild
})
const configPath = './private/opencode.json'
@@ -325,6 +318,7 @@ describe('OpenCodeRuntime embedded launcher', () => {
spawn: spawnMock as unknown as typeof spawn,
detectBinary,
createClient: createClient as unknown as typeof createOpencodeClient,
checkServerHealth,
platform: 'win32'
}
)
@@ -357,6 +351,14 @@ describe('OpenCodeRuntime embedded launcher', () => {
})
})
)
const firstSpawn = spawnMock.mock.calls[0] as unknown as
| [string, string[]]
| undefined
const serverPort = firstSpawn?.[1]
?.find((argument) => argument.startsWith('--port='))
?.slice('--port='.length)
expect(serverPort).toMatch(/^\d+$/u)
const serverUrl = `http://127.0.0.1:${serverPort}`
const clientOptions = (
createClient.mock.calls as unknown as Array<
[
@@ -375,12 +377,17 @@ describe('OpenCodeRuntime embedded launcher', () => {
}
| undefined
expect(clientOptions).toMatchObject({
baseUrl: 'http://127.0.0.1:43210',
baseUrl: serverUrl,
directory: process.cwd(),
headers: {
Authorization: expect.stringMatching(/^Basic /u)
}
})
expect(checkServerHealth).toHaveBeenCalledWith(
serverUrl,
clientOptions?.headers?.Authorization,
expect.any(AbortSignal)
)
const spawnOptions = (
spawnMock.mock.calls as unknown as Array<
[string, string[], { env?: NodeJS.ProcessEnv }]
@@ -445,11 +452,6 @@ describe('OpenCodeRuntime embedded launcher', () => {
)
const child = fakeChild()
const { deps, spawnMock } = dependencies(child)
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:3012\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({
skillPackages: [
@@ -523,11 +525,6 @@ describe('OpenCodeRuntime embedded launcher', () => {
it('injects an independent model profile without persisting its key', async () => {
const child = fakeChild()
const { deps, spawnMock } = dependencies(child)
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:3011\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({
modelProfile: {
@@ -601,11 +598,6 @@ describe('OpenCodeRuntime embedded launcher', () => {
])
)
Object.assign(process.env, inheritedCredentials)
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:3013\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({
modelProfile: {
@@ -730,7 +722,8 @@ describe('OpenCodeRuntime embedded launcher', () => {
authentication: 'api-key',
apiKey: 'local-probe-key'
}
})
}),
{ startupTimeoutMs: 20_000 }
)
const controller = new AbortController()
const timeout = setTimeout(
@@ -808,11 +801,6 @@ describe('OpenCodeRuntime embedded launcher', () => {
}) => {
const child = fakeChild()
const { deps, spawnMock } = dependencies(child)
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:3012\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({
modelProfile: {
@@ -899,11 +887,6 @@ describe('OpenCodeRuntime embedded launcher', () => {
process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
'https://telemetry.invalid'
try {
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:3010\n'
)
}, 0)
const runtime = new OpenCodeRuntime(options(), deps)
await expect(runtime.getStatus()).resolves.toMatchObject({
available: true
@@ -960,36 +943,39 @@ describe('OpenCodeRuntime embedded launcher', () => {
}
})
it.each([
'https://127.0.0.1:4321',
'http://0.0.0.0:4321',
'http://example.com:4321',
'http://127.0.0.1',
'http://127.0.0.1:4321/admin'
])('rejects an unsafe listening URL: %s', async (url) => {
it('polls the known loopback URL without waiting for stdout', async () => {
const child = fakeChild()
const { deps, createClient } = dependencies(child, {
spawn: vi.fn(() => {
queueMicrotask(() => {
stdoutOf(child).write(`opencode server listening on ${url}\n`)
closeChild(child, 7)
})
return child
}) as unknown as typeof spawn
const { deps, checkServerHealth, createClient } = dependencies(child, {
startupTimeoutMs: 1_000
})
checkServerHealth
.mockResolvedValueOnce(false)
.mockResolvedValueOnce(true)
const runtime = new OpenCodeRuntime(options(), deps)
await expect(runtime.getStatus()).resolves.toMatchObject({
available: false,
detail: 'OpenCode Server 启动前退出(code 7)'
available: true
})
expect(checkServerHealth).toHaveBeenCalledTimes(2)
const [url, authorization, signal] =
checkServerHealth.mock.calls[0] ?? []
expect(url).toMatch(/^http:\/\/127\.0\.0\.1:\d+$/)
expect(authorization).toMatch(/^Basic /)
expect(signal).toBeInstanceOf(AbortSignal)
expect(createClient).toHaveBeenCalledWith({
baseUrl: url,
directory: process.cwd(),
headers: { Authorization: authorization }
})
expect(createClient).not.toHaveBeenCalled()
})
it('times out, terminates the process tree, and does not expose stderr', async () => {
const child = fakeChild()
const secret = 'private-config-token'
const { deps } = dependencies(child, { startupTimeoutMs: 5 })
const { deps } = dependencies(child, {
startupTimeoutMs: 5,
checkServerHealth: vi.fn().mockResolvedValue(false)
})
stderrOf(child).write(secret)
const runtime = new OpenCodeRuntime(options(), deps)
@@ -1038,7 +1024,9 @@ describe('OpenCodeRuntime embedded launcher', () => {
it('terminates startup when the request is aborted', async () => {
const child = fakeChild()
const { deps, spawnMock } = dependencies(child)
const { deps, spawnMock } = dependencies(child, {
checkServerHealth: vi.fn().mockResolvedValue(false)
})
const runtime = new OpenCodeRuntime(options(), deps)
const controller = new AbortController()
const stream = runtime.run(
@@ -1058,6 +1046,25 @@ describe('OpenCodeRuntime embedded launcher', () => {
expect(child.kill).toHaveBeenCalledWith('SIGTERM')
})
it('bounds session setup without imposing a full-run deadline', async () => {
const harness = runClient([])
;(
harness.session.create as unknown as ReturnType<typeof vi.fn>
).mockImplementation(
() => new Promise(() => undefined)
)
const runtime = embeddedRuntime(
harness.client,
{},
{ controlRequestTimeoutMs: 5 }
)
await expect(collectRun(runtime)).rejects.toThrow(
'OpenCode 创建会话超时'
)
await runtime.dispose()
})
it('keeps external baseUrl mode free of binary detection and spawning', async () => {
const child = fakeChild()
const { deps, spawnMock, detectBinary, createClient } = dependencies(child)
@@ -1521,11 +1528,14 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
? questionEvent.value.questionId
: ''
await runtime.respondToQuestion(questionId, [['先写测试']])
expect(setup.questionReply).toHaveBeenCalledWith({
requestID: 'question-1',
directory: process.cwd(),
answers: [['先写测试']]
})
expect(setup.questionReply).toHaveBeenCalledWith(
{
requestID: 'question-1',
directory: process.cwd(),
answers: [['先写测试']]
},
{ signal: expect.any(AbortSignal) }
)
await expect(stream.next()).resolves.toMatchObject({
value: { type: 'done' }
})
@@ -1614,20 +1624,212 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
runtime.respondToQuestion(secondId, [['second answer']])
])
expect(setup.questionReply).toHaveBeenCalledTimes(2)
expect(setup.questionReply).toHaveBeenNthCalledWith(1, {
requestID: 'shared-question',
directory: process.cwd(),
answers: [['first answer']]
})
expect(setup.questionReply).toHaveBeenNthCalledWith(2, {
requestID: 'shared-question',
directory: process.cwd(),
answers: [['second answer']]
})
expect(setup.questionReply).toHaveBeenNthCalledWith(
1,
{
requestID: 'shared-question',
directory: process.cwd(),
answers: [['first answer']]
},
{ signal: expect.any(AbortSignal) }
)
expect(setup.questionReply).toHaveBeenNthCalledWith(
2,
{
requestID: 'shared-question',
directory: process.cwd(),
answers: [['second answer']]
},
{ signal: expect.any(AbortSignal) }
)
await Promise.all([first.next(), second.next()])
await runtime.dispose()
})
it('emits native Task calls as subagents instead of generic tools', async () => {
const taskInput = {
subagent_type: 'explorer',
description: 'Review application architecture',
prompt: 'Inspect the complete source tree.'
}
const setup = runClient([
{
id: 'task-running',
type: 'message.part.updated',
properties: {
sessionID: 'session-1',
part: {
id: 'part-task-1',
callID: 'call-task-1',
type: 'tool',
tool: 'task',
state: {
status: 'running',
input: taskInput,
time: { start: 1 }
}
}
}
},
{
id: 'task-completed',
type: 'message.part.updated',
properties: {
sessionID: 'session-1',
part: {
id: 'part-task-1',
callID: 'call-task-1',
type: 'tool',
tool: 'task',
state: {
status: 'completed',
input: taskInput,
output: 'Architecture review complete.',
title: 'Review application architecture',
metadata: {},
time: { start: 1, end: 2 }
}
}
}
},
{
id: 'idle',
type: 'session.idle',
properties: { sessionID: 'session-1' }
}
])
const runtime = embeddedRuntime(setup.client)
const events = await collectRun(runtime)
const subagents = events.filter(
(event) => event.type === 'subagent'
)
expect(subagents).toHaveLength(2)
expect(subagents[0]).toMatchObject({
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'running',
reason: 'Review application architecture'
})
expect(subagents[1]).toMatchObject({
childTaskId:
subagents[0]?.type === 'subagent'
? subagents[0].childTaskId
: undefined,
state: 'completed',
output: 'Architecture review complete.'
})
expect(events.some((event) => event.type === 'tool')).toBe(false)
await runtime.dispose()
})
it('keeps non-Task tools with Task-shaped input as generic tools', async () => {
const setup = runClient([
{
id: 'custom-tool-completed',
type: 'message.part.updated',
properties: {
sessionID: 'session-1',
part: {
id: 'part-custom-1',
callID: 'call-custom-1',
type: 'tool',
tool: 'custom_delegate',
state: {
status: 'completed',
input: {
subagent_type: 'explorer',
prompt: 'Inspect the complete source tree.'
},
output: 'Custom tool result.',
title: 'Custom delegate',
metadata: {},
time: { start: 1, end: 2 }
}
}
}
},
{
id: 'idle',
type: 'session.idle',
properties: { sessionID: 'session-1' }
}
])
const runtime = embeddedRuntime(setup.client)
const events = await collectRun(runtime)
expect(events).toContainEqual(
expect.objectContaining({
type: 'tool',
callId: 'call-custom-1',
name: 'custom_delegate',
state: 'completed'
})
)
expect(events.some((event) => event.type === 'subagent')).toBe(false)
await runtime.dispose()
})
it('does not impose a default wall-clock deadline on OpenCode runs', async () => {
vi.useFakeTimers()
try {
let release!: () => void
const gate = new Promise<void>((resolve) => {
release = resolve
})
const setup = runClient([])
;(
setup.event.subscribe as unknown as ReturnType<typeof vi.fn>
).mockResolvedValue({
stream: (async function* () {
await gate
yield {
id: 'idle',
type: 'session.idle',
properties: { sessionID: 'session-1' }
}
})()
})
const runtime = new OpenCodeRuntime(
options({
baseUrl: 'http://127.0.0.1:4096',
embedded: false
}),
dependencies(fakeChild(), {
createClient: vi.fn(
() => setup.client
) as unknown as typeof createOpencodeClient
}).deps
)
const stream = runtime.run(
{
requestId: '3f496642-f47d-4e0a-8944-a32c77b0d6ef',
conversationId: 'conversation-1',
prompt: 'work for more than a day',
workMode: 'execute'
},
new AbortController().signal
)
await expect(stream.next()).resolves.toMatchObject({
value: { type: 'status' }
})
const pending = stream.next()
await vi.advanceTimersByTimeAsync(25 * 60 * 60_000)
expect(setup.session.abort).not.toHaveBeenCalled()
release()
await expect(pending).resolves.toMatchObject({
value: { type: 'done' }
})
await runtime.dispose()
} finally {
vi.useRealTimers()
}
})
it('aborts an OpenCode run at its total execution deadline', async () => {
const setup = runClient([])
;(
@@ -1705,11 +1907,6 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
executionTimeoutMs: 20
}).deps
)
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:4010\n'
)
}, 0)
const stream = runtime.run(
{
requestId: '3f496642-f47d-4e0a-8944-a32c77b0d6ef',
@@ -1886,11 +2083,6 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
() => setup.client
) as unknown as typeof createOpencodeClient
})
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:4010\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({ knowledgeGateway: gateway }),
deps
@@ -1987,11 +2179,6 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
() => setup.client
) as unknown as typeof createOpencodeClient
})
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:4010\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({
knowledgeGateway: {
@@ -2090,11 +2277,6 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
() => setup.client
) as unknown as typeof createOpencodeClient
})
setTimeout(() => {
stdoutOf(child).write(
'opencode server listening on http://127.0.0.1:4010\n'
)
}, 0)
const runtime = new OpenCodeRuntime(
options({
knowledgeGateway: {
@@ -2340,11 +2522,14 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
{ signal: expect.any(AbortSignal) }
)
expect(permissionReply).toHaveBeenCalledOnce()
expect(permissionReply).toHaveBeenCalledWith({
requestID: 'permission-1',
directory: process.cwd(),
reply: 'once'
})
expect(permissionReply).toHaveBeenCalledWith(
{
requestID: 'permission-1',
directory: process.cwd(),
reply: 'once'
},
{ signal: expect.any(AbortSignal) }
)
expect(events).toContainEqual(
expect.objectContaining({
type: 'reasoning',
@@ -2436,14 +2621,16 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
requestID: 'permission-1',
directory: process.cwd(),
reply: 'once'
}
},
{ signal: expect.any(AbortSignal) }
],
[
{
requestID: 'permission-2',
directory: process.cwd(),
reply: 'once'
}
},
{ signal: expect.any(AbortSignal) }
]
])
await runtime.dispose()
@@ -2609,10 +2796,13 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
await collectRun(runtime)
await runtime.releaseConversation('conversation-1')
expect(session.delete).toHaveBeenCalledWith({
sessionID: 'session-1',
directory: process.cwd()
})
expect(session.delete).toHaveBeenCalledWith(
{
sessionID: 'session-1',
directory: process.cwd()
},
{ signal: expect.any(AbortSignal) }
)
await runtime.dispose()
})
@@ -2632,11 +2822,14 @@ describe('OpenCodeRuntime embedded permission mediation', () => {
await collectRun(runtime, 'execute')
expect(permissionReply).toHaveBeenCalledOnce()
expect(permissionReply).toHaveBeenCalledWith({
requestID: 'permission-1',
directory: process.cwd(),
reply: 'reject'
})
expect(permissionReply).toHaveBeenCalledWith(
{
requestID: 'permission-1',
directory: process.cwd(),
reply: 'reject'
},
{ signal: expect.any(AbortSignal) }
)
await runtime.dispose()
})
File diff suppressed because it is too large Load Diff
+57
View File
@@ -0,0 +1,57 @@
import { describe, expect, it } from 'vitest'
import { toOpenCodeSubagentEvent } from './opencode-subagent'
const requestId = '3f496642-f47d-4e0a-8944-a32c77b0d6ef'
describe('OpenCode native subagent events', () => {
it('maps Task tool updates to stable bounded subagent identities', () => {
const running = toOpenCodeSubagentEvent({
requestId,
callId: 'call-task-1',
state: 'running',
input: {
subagent_type: 'explorer',
description: 'Review application architecture',
prompt: 'Inspect the complete source tree.'
}
})
const completed = toOpenCodeSubagentEvent({
requestId,
callId: 'call-task-1',
state: 'completed',
input: {
subagent_type: 'explorer',
description: 'Review application architecture',
prompt: 'Inspect the complete source tree.'
},
output: 'Architecture review complete.'
})
expect(running).toMatchObject({
type: 'subagent',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'running',
reason: 'Review application architecture'
})
expect(completed).toMatchObject({
childTaskId: running?.childTaskId,
expertId: running?.expertId,
state: 'completed',
output: 'Architecture review complete.'
})
})
it('does not classify unrelated tools as subagents', () => {
expect(
toOpenCodeSubagentEvent({
requestId,
callId: 'call-read-1',
state: 'completed',
input: { filePath: 'README.md' },
output: 'contents'
})
).toBeUndefined()
})
})
+140
View File
@@ -0,0 +1,140 @@
import { createHash } from 'node:crypto'
import type { SubagentEvent } from '../../shared/contracts'
import { boundedToolDetail } from './approval-summary'
type OpenCodeSubagentState =
| 'pending'
| 'running'
| 'in_progress'
| 'completed'
| 'failed'
| 'error'
export type OpenCodeSubagentToolUpdate = {
requestId: string
callId: string
state: OpenCodeSubagentState
input: unknown
output?: unknown
error?: unknown
}
export type OpenCodeSubagentInput = {
subagent_type: string
prompt: string
description?: string
command?: string
}
function isRecord(value: unknown): value is Record<string, unknown> {
return (
typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
)
}
function boundedText(
value: unknown,
maximum: number
): string | undefined {
if (typeof value !== 'string') {
return undefined
}
const normalized = value.trim()
return normalized ? normalized.slice(0, maximum) : undefined
}
function boundedDetail(
value: unknown,
maximum: number
): string | undefined {
if (typeof value === 'string') {
return boundedText(value, maximum)
}
if (value === undefined || value === null) {
return undefined
}
return boundedToolDetail(value, maximum)
}
function deterministicUuid(value: string): string {
const bytes = createHash('sha256').update(value).digest().subarray(0, 16)
bytes[6] = (bytes[6]! & 0x0f) | 0x50
bytes[8] = (bytes[8]! & 0x3f) | 0x80
const hex = bytes.toString('hex')
return [
hex.slice(0, 8),
hex.slice(8, 12),
hex.slice(12, 16),
hex.slice(16, 20),
hex.slice(20)
].join('-')
}
export function parseOpenCodeSubagentInput(
value: unknown
): OpenCodeSubagentInput | undefined {
if (!isRecord(value)) {
return undefined
}
const subagentType = boundedText(value.subagent_type, 80)
const prompt = boundedText(value.prompt, 20_000)
if (!subagentType || !prompt) {
return undefined
}
const description = boundedText(value.description, 240)
const command = boundedText(value.command, 240)
return {
subagent_type: subagentType,
prompt,
...(description ? { description } : {}),
...(command ? { command } : {})
}
}
export function toOpenCodeSubagentEvent(
update: OpenCodeSubagentToolUpdate
): SubagentEvent | undefined {
const input = parseOpenCodeSubagentInput(update.input)
if (!input) {
return undefined
}
const expertName = input.subagent_type
const description =
input.description ?? input.command
const state =
update.state === 'pending'
? 'queued'
: update.state === 'running' ||
update.state === 'in_progress'
? 'running'
: update.state === 'completed'
? 'completed'
: 'failed'
const failed = state === 'failed'
const output = failed
? undefined
: boundedDetail(update.output, 16_000)
const error = failed
? boundedDetail(update.error ?? update.output, 1_000)
: undefined
return {
requestId: update.requestId,
type: 'subagent',
childTaskId: deterministicUuid(
`opencode-subagent-call\0${update.requestId}\0${update.callId}`
),
expertId: deterministicUuid(
`opencode-subagent-type\0${expertName}`
),
expertName,
routingMode: 'native',
runtimeCallId: update.callId.slice(0, 256),
state,
...(description ? { reason: description } : {}),
...(output ? { output } : {}),
...(error ? { error } : {})
}
}
+1 -1
View File
@@ -139,7 +139,7 @@ export function applyRuntimeSelection(
!isDeepSeekHarnessModelProfile(selectedProfile)
) {
throw new Error(
'DeepSeek Harness 仅支持使用 API Key 的安全 OpenAI 兼容 Chat Completions 连接'
'DeepSeek Harness 仅支持使用 API Key 的 OpenAI 兼容 Chat Completions 连接'
)
}
return {
+96 -1
View File
@@ -3299,6 +3299,29 @@ describe('AssistantDatabase', () => {
createdAt: 1_775_000_000_001,
state: 'complete' as const,
status: '已完成',
tools: [
{
callId: 'remote-tool-call',
name: '远程工具',
state: 'completed' as const,
summary: '完整远程工具结果',
output: '远程输出'.repeat(10_000)
}
],
subagents: [
{
childTaskId:
'00000000-0000-4000-8000-000000000513',
expertId:
'00000000-0000-4000-8000-000000000514',
expertName: 'explorer',
routingMode: 'native' as const,
runtimeCallId: 'call-task-1',
state: 'completed' as const,
reason: 'Review application architecture',
output: 'Architecture review complete.'
}
],
contextCompressions: [
{
state: 'completed' as const,
@@ -3350,6 +3373,29 @@ describe('AssistantDatabase', () => {
content: '生成完成',
state: 'complete',
status: '已完成',
tools: [
{
callId: 'remote-tool-call',
name: '远程工具',
state: 'completed',
summary: '完整远程工具结果',
output: '远程输出'.repeat(10_000)
}
],
subagents: [
{
childTaskId:
'00000000-0000-4000-8000-000000000513',
expertId:
'00000000-0000-4000-8000-000000000514',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'completed',
reason: 'Review application architecture',
output: 'Architecture review complete.'
}
],
contextCompressions: [
{
state: 'completed',
@@ -4260,7 +4306,7 @@ describe('AssistantDatabase', () => {
database.close()
})
it('durably interrupts active tool metadata during startup recovery', async () => {
it('durably interrupts active tool and subagent metadata during startup recovery', async () => {
const directory = await mkdtemp(
join(tmpdir(), 'goodbuddy-conversation-recovery-')
)
@@ -4271,6 +4317,8 @@ describe('AssistantDatabase', () => {
const messageId = '00000000-0000-4000-8000-000000000218'
const cancelledMessageId =
'00000000-0000-4000-8000-000000000219'
const subagentMessageId =
'00000000-0000-4000-8000-000000000220'
const initial = new AssistantDatabase(databasePath)
initial.initialize('C:\\Workspace')
initial.replaceConversations([
@@ -4324,6 +4372,38 @@ describe('AssistantDatabase', () => {
error: 'runtime parser detail'
}
]
},
{
id: subagentMessageId,
role: 'assistant',
content: '父请求已完成',
createdAt: 1_775_000_003_000,
state: 'complete',
status: '已完成',
subagents: [
{
childTaskId:
'00000000-0000-4000-8000-000000000221',
expertId:
'00000000-0000-4000-8000-000000000222',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'task-1',
state: 'running',
reason: '检查项目'
},
{
childTaskId:
'00000000-0000-4000-8000-000000000223',
expertId:
'00000000-0000-4000-8000-000000000224',
expertName: 'worker',
routingMode: 'native',
runtimeCallId: 'task-2',
state: 'completed',
output: '已完成'
}
]
}
]
}
@@ -4352,6 +4432,21 @@ describe('AssistantDatabase', () => {
expect.objectContaining({ name: 'failed-tool', state: 'failed' })
]
})
expect(recovered.listConversations()[0]?.messages[2]).toMatchObject({
id: subagentMessageId,
state: 'complete',
status: '已完成',
subagents: [
expect.objectContaining({
runtimeCallId: 'task-1',
state: 'cancelled'
}),
expect.objectContaining({
runtimeCallId: 'task-2',
state: 'completed'
})
]
})
expect(recovered.listConversations()[0]?.messages[1]).toMatchObject({
id: cancelledMessageId,
state: 'error',
+29 -3
View File
@@ -215,6 +215,7 @@ type MessageMetadata = {
contextCompression?: ConversationSnapshot['messages'][number]['contextCompression']
contextCompressions?: ConversationSnapshot['messages'][number]['contextCompressions']
tools?: ConversationSnapshot['messages'][number]['tools']
subagents?: ConversationSnapshot['messages'][number]['subagents']
sources?: string[]
sourceReferences?: ConversationSnapshot['messages'][number]['sourceReferences']
knowledgeRetrieval?: ConversationSnapshot['messages'][number]['knowledgeRetrieval']
@@ -903,6 +904,16 @@ function interruptActiveTools(
)
}
function interruptActiveSubagents(
subagents: MessageMetadata['subagents']
): MessageMetadata['subagents'] {
return subagents?.map((subagent) =>
subagent.state === 'queued' || subagent.state === 'running'
? { ...subagent, state: 'cancelled' as const }
: subagent
)
}
function interruptActiveToolBlocks(
blocks: MessageMetadata['blocks']
): MessageMetadata['blocks'] {
@@ -1017,6 +1028,9 @@ function toConversationSnapshot(
tools: interrupted
? interruptActiveTools(metadata.tools)
: metadata.tools,
subagents: interrupted
? interruptActiveSubagents(metadata.subagents)
: metadata.subagents,
sources: metadata.sources,
sourceReferences: metadata.sourceReferences,
knowledgeRetrieval: metadata.knowledgeRetrieval,
@@ -1040,6 +1054,7 @@ function serializeConversationMessageMetadata(
contextCompression: message.contextCompression,
contextCompressions: message.contextCompressions,
tools: message.tools,
subagents: message.subagents,
sources: message.sources,
sourceReferences: message.sourceReferences,
knowledgeRetrieval: message.knowledgeRetrieval,
@@ -1417,7 +1432,7 @@ export class AssistantDatabase {
const metadata = JSON.parse(
message.metadata_json
) as MessageMetadata
const hasActiveTool = Boolean(
const hasActiveActivity = Boolean(
metadata.tools?.some(
(tool) =>
tool.state === 'pending' || tool.state === 'running'
@@ -1427,9 +1442,17 @@ export class AssistantDatabase {
block.type === 'tool' &&
(block.tool.state === 'pending' ||
block.tool.state === 'running')
) ||
metadata.subagents?.some(
(subagent) =>
subagent.state === 'queued' ||
subagent.state === 'running'
)
)
if (message.state !== 'streaming' && !hasActiveTool) {
if (
message.state !== 'streaming' &&
!hasActiveActivity
) {
continue
}
updateMessage.run(
@@ -1441,7 +1464,10 @@ export class AssistantDatabase {
? interruptedMessageStatus
: metadata.status,
tools: interruptActiveTools(metadata.tools),
blocks: interruptActiveToolBlocks(metadata.blocks)
blocks: interruptActiveToolBlocks(metadata.blocks),
subagents: interruptActiveSubagents(
metadata.subagents
)
}),
message.id
)
@@ -231,7 +231,7 @@ describe('ChannelSettingsStore', () => {
const bound = await store.saveWeixinBinding({
accountId: 'account-123456',
userId: 'user-654321',
baseUrl: 'https://ilinkai.weixin.qq.com',
baseUrl: 'http://ilinkai.weixin.qq.com',
token: 'weixin-private-token'
})
expect(bound.weixin).toMatchObject({
+7 -3
View File
@@ -300,9 +300,13 @@ const weixinBindingSchema = z
.string()
.url()
.max(2_048)
.refine((value) => new URL(value).protocol === 'https:', {
message: '微信服务地址必须使用 HTTPS'
}),
.refine(
(value) =>
['http:', 'https:'].includes(new URL(value).protocol),
{
message: '微信服务地址必须使用 HTTP 或 HTTPS'
}
),
token: z
.string()
.trim()
+1 -1
View File
@@ -39,7 +39,7 @@ describe('controlled DeepSeek Harness host', () => {
dshHome: 'C:\\controlled-dsh-home',
skillPackages: []
})
).rejects.toThrow('secure OpenAI-compatible')
).rejects.toThrow('HTTP or HTTPS OpenAI-compatible')
})
it('suppresses console payloads instead of contaminating stdout', () => {
+1 -1
View File
@@ -93,7 +93,7 @@ function validateHostConfig(
!isDeepSeekHarnessCompatibleBaseUrl(config.baseUrl)
) {
throw new Error(
'Controlled Harness requires a secure OpenAI-compatible Chat Completions endpoint'
'Controlled Harness requires an HTTP or HTTPS OpenAI-compatible Chat Completions endpoint'
)
}
if (!config.credentialRefs.length) {
+66 -1
View File
@@ -3917,7 +3917,16 @@ describe('registerIpcHandlers local conversation persistence', () => {
role: 'assistant' as const,
content: '增量内容',
createdAt: 1,
state: 'streaming' as const
state: 'streaming' as const,
tools: [
{
callId: 'remote-tool-call',
name: '远程工具',
state: 'completed' as const,
summary: '完整远程工具结果',
output: '远程输出'.repeat(10_000)
}
]
}
]
}
@@ -6697,6 +6706,62 @@ describe('registerIpcHandlers agent terminal state', () => {
await harness.dispose()
})
it('does not fail a completed native subagent for its provisional Task tool', async () => {
const runtime = {
capability: 'chat',
requiresToolApproval: false,
supportsToolExecution: true,
getStatus: vi.fn(),
dispose: vi.fn(),
async *run(request: { requestId: string }) {
yield {
requestId: request.requestId,
type: 'tool',
callId: 'call-task-1',
name: 'task',
state: 'running',
summary: 'OpenCode 工具:task'
}
yield {
requestId: request.requestId,
type: 'subagent',
childTaskId: '00000000-0000-4000-8000-000000000601',
expertId: '00000000-0000-4000-8000-000000000701',
expertName: 'explore',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'completed',
output: 'Desktop files inspected.'
}
yield { requestId: request.requestId, type: 'done' }
}
}
const harness = createHarness(runtime)
const requestId = '3f496642-f47d-4e0a-8944-a32c77b0d6ef'
harness.handler?.(trustedEvent(harness.webContents), {
requestId,
conversationId: 'conversation-1',
prompt: 'inspect the desktop',
workMode: 'execute'
})
await vi.waitFor(() =>
expect(harness.assistantDatabase.updateTaskStatus).toHaveBeenCalledWith(
requestId,
'completed'
)
)
expect(
harness.assistantDatabase.updateTaskStatus
).not.toHaveBeenCalledWith(
requestId,
'failed',
expect.any(String)
)
await harness.dispose()
})
it.each(['opencode', 'continue'] as const)(
'preserves read-only Ask mode at the %s Runtime boundary',
async (runtimeId) => {
+7
View File
@@ -3488,6 +3488,13 @@ export function registerIpcHandlers(
if (publicEvent.type === 'tool') {
toolStates.set(publicEvent.callId, publicEvent)
}
if (
publicEvent.type === 'subagent' &&
publicEvent.routingMode === 'native' &&
publicEvent.runtimeCallId
) {
toolStates.delete(publicEvent.runtimeCallId)
}
if (publicEvent.type === 'question') {
pendingAgentQuestions.set(publicEvent.questionId, {
requestId: request.requestId,
+10
View File
@@ -88,6 +88,16 @@ describe('ReleaseNotesService', () => {
})
})
it('does not present older notes as a missing current release', async () => {
const { service, settingsStore } = await createService('0.8.19')
await settingsStore.setLastSeenReleaseNotesVersion('0.8.11')
await expect(service.getPending()).resolves.toEqual({
currentVersion: '0.8.19',
releases: []
})
})
it('persists acknowledgement and does not show the release again', async () => {
const { service, settingsStore } = await createService('0.8.18')
+6
View File
@@ -57,6 +57,12 @@ export class ReleaseNotesService {
async getPending(): Promise<ReleaseNotesSnapshot> {
const releases = await this.loadReleases()
const currentVersion = this.dependencies.currentVersion
if (!releases.some((release) => release.version === currentVersion)) {
return {
currentVersion,
releases: []
}
}
const lastSeenVersion =
await this.dependencies.settingsStore.getLastSeenReleaseNotesVersion()
const pending = releases.filter((release) => {
+7
View File
@@ -11,8 +11,15 @@ describe('packaged release notes', () => {
'utf8'
)
) as unknown
const packageSource = JSON.parse(
await readFile(join(process.cwd(), 'package.json'), 'utf8')
) as { version?: unknown }
const parsed = releaseNotesFileSchema.parse(source)
expect(typeof packageSource.version).toBe('string')
expect(parsed.releases).toContainEqual(
expect.objectContaining({ version: packageSource.version })
)
expect(parsed.releases).toContainEqual(
expect.objectContaining({ version: '0.8.19' })
)
@@ -25,7 +25,6 @@ import { HostActivationCoordinator } from './host-activation-coordinator'
import { isMissingPathError } from './path-errors'
import { remoteHostTargetIdentityKey } from './remote-host-target-identity'
const PRIVATE_FILE_MODE = 0o600
const MAXIMUM_METADATA_BYTES = 1024 * 1024
const AGENT_REGISTRY_PATH = '.goodbuddy/agent/registry.json'
const MAXIMUM_DIAGNOSTIC_CHARACTERS = 800
@@ -192,19 +191,6 @@ export class AgentInstallationManager {
},
signal
)
const metadata = await sftp.lstat(
AGENT_REGISTRY_PATH,
signal
)
if (
metadata.type !== 'file' ||
metadata.uid !== probe.uid ||
metadata.mode !== PRIVATE_FILE_MODE
) {
throw new Error(
'Installed Agent registry metadata is invalid'
)
}
const registry = parseInstallationRegistryState(
parseJsonBytes(
await sftp.readFile(AGENT_REGISTRY_PATH, signal),
@@ -142,6 +142,8 @@ type InstallerOptions = {
operationRoot: string
archive: string
expectedSha256: string
/** The acquisition path verified the archive before installer execution. */
archiveSha256Verified?: boolean
homeDirectory?: string
emit?: (event: PackageInstallerEvent) => void
}
@@ -1361,6 +1363,7 @@ function sameSnapshot(
function verifyArchive(
archivePath: string,
expectedSha256: string,
archiveSha256Verified: boolean,
emit: (phase: string) => void
): VerifiedPackage {
const handle = openSync(
@@ -1376,11 +1379,14 @@ function verifyArchive(
) {
throw new Error('Agent package archive is not a bounded regular file')
}
emit('hashing-archive')
const archiveSha256 = hashArchive(handle, snapshot.size)
if (archiveSha256 !== expectedSha256) {
throw new Error('Agent package archive SHA-256 does not match the authenticated catalog')
if (!archiveSha256Verified) {
emit('hashing-archive')
const archiveSha256 = hashArchive(handle, snapshot.size)
if (archiveSha256 !== expectedSha256) {
throw new Error('Agent package archive SHA-256 does not match the authenticated catalog')
}
}
const archiveSha256 = expectedSha256
emit('verifying-zip')
const entries = parseZip(handle, snapshot.size)
const descriptorBytes = readEntry(handle, entries, PACKAGE_DESCRIPTOR)
@@ -1637,28 +1643,7 @@ function persistPreparedState(
if (bytes.length > MAXIMUM_METADATA_BYTES) {
throw new Error('Prepared package state exceeds its limit')
}
const handle = openSync(
temporary,
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL,
0o600
)
try {
let offset = 0
while (offset < bytes.length) {
offset += writeFileChunk(handle, bytes, offset)
}
fsyncSync(handle)
} finally {
closeSync(handle)
}
try {
chmodSync(temporary, 0o600)
renameSync(temporary, destination)
} finally {
if (existsSync(temporary)) {
unlinkSync(temporary)
}
}
writeBufferAtomically(destination, temporary, bytes)
}
function writePreparedFile(
@@ -1677,6 +1662,15 @@ function writePreparedFile(
directory,
`.${name}-${process.pid}-${Date.now().toString(36)}.tmp`
)
writeBufferAtomically(destination, temporary, bytes)
}
function writeBufferAtomically(
destination: string,
temporary: string,
bytes: Buffer,
replaceExistingOnWindows = false
): void {
const handle = openSync(
temporary,
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL,
@@ -1693,6 +1687,13 @@ function writePreparedFile(
}
try {
chmodSync(temporary, 0o600)
if (
replaceExistingOnWindows &&
process.platform === 'win32' &&
existsSync(destination)
) {
unlinkSync(destination)
}
renameSync(temporary, destination)
} finally {
if (existsSync(temporary)) {
@@ -1808,6 +1809,7 @@ export function preparePackage(options: InstallerOptions): PackageInstallerResul
const verified = verifyArchive(
inputs.archive,
inputs.expectedSha256,
options.archiveSha256Verified === true,
progress
)
try {
@@ -1940,31 +1942,12 @@ function writePrivateFileAtomic(
dirname(destination),
`.${basename(destination)}-${process.pid}-${Date.now().toString(36)}.tmp`
)
const handle = openSync(
writeBufferAtomically(
destination,
temporary,
constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL,
0o600
contents,
true
)
try {
let offset = 0
while (offset < contents.length) {
offset += writeFileChunk(handle, contents, offset)
}
fsyncSync(handle)
} finally {
closeSync(handle)
}
try {
chmodSync(temporary, 0o600)
if (process.platform === 'win32' && existsSync(destination)) {
unlinkSync(destination)
}
renameSync(temporary, destination)
} finally {
if (existsSync(temporary)) {
unlinkSync(temporary)
}
}
}
function restoreLocalMetadata(
@@ -2571,14 +2554,18 @@ function parseCli(argv: readonly string[]): {
const command = argv[0]
if (command !== 'prepare' && command !== 'commit') {
throw new Error(
'Usage: remote-package-installer.mjs <prepare|commit> --operation-root <absolute-path> --archive <absolute-path> --expected-sha256 <hex>'
'Usage: remote-package-installer.mjs <prepare|commit> --operation-root <absolute-path> --archive <absolute-path> --expected-sha256 <hex> [--archive-sha256-verified true]'
)
}
const values: Record<string, string> = {}
const allowed = new Set([
const required = [
'--operation-root',
'--archive',
'--expected-sha256'
] as const
const allowed = new Set([
...required,
'--archive-sha256-verified'
])
for (let index = 1; index < argv.length; index += 2) {
const flag = argv[index]
@@ -2594,17 +2581,25 @@ function parseCli(argv: readonly string[]): {
}
values[flag] = value
}
for (const flag of allowed) {
for (const flag of required) {
if (values[flag] === undefined) {
throw new Error(`Missing required package installer argument: ${flag}`)
}
}
if (
values['--archive-sha256-verified'] !== undefined &&
values['--archive-sha256-verified'] !== 'true'
) {
throw new Error('Invalid package installer argument')
}
return {
command,
options: {
operationRoot: values['--operation-root']!,
archive: values['--archive']!,
expectedSha256: values['--expected-sha256']!
expectedSha256: values['--expected-sha256']!,
archiveSha256Verified:
values['--archive-sha256-verified'] === 'true'
}
}
}
@@ -22,7 +22,8 @@ import { AgentFrameError } from '../../shared/agent-protocol/frame'
import {
assertRemotePromptAcceptanceMatchesPreparation,
remotePromptOperationAcceptanceSchema,
remotePromptOperationPreparationSchema
remotePromptOperationPreparationSchema,
UNBOUNDED_REMOTE_PROMPT_DEADLINE
} from '../../shared/remote-agent-contracts'
import {
modelBridgePolicySchema
@@ -66,6 +67,9 @@ const RUNTIME_MODEL_BRIDGE_CAPABILITY = 'runtime/model-bridge'
const RUNTIME_MODEL_BRIDGE_CAPABILITY_VERSION = 1
const DEFAULT_CONTROL_TIMEOUT_MS = 15_000
const DEFAULT_MAXIMUM_PENDING_CONTROL_REQUESTS = 32
const UNBOUNDED_REMOTE_PROMPT_DEADLINE_MS = Date.parse(
UNBOUNDED_REMOTE_PROMPT_DEADLINE
)
const MAXIMUM_PENDING_OUTPUT_WRITES = 256
const MAXIMUM_OUTPUT_WRITE_BYTES =
AGENT_PROTOCOL_LIMITS.maximumBufferedProtocolBytes
@@ -1038,11 +1042,16 @@ export class ProtocolRemoteRuntimeChannel
].some(
(bridge) => bridge.providerDeliveryMayBeUncertain
)
const recoveryDeadlineExpired =
this.#recoveryDeadlineAt !== undefined &&
this.#recoveryDeadlineAt !==
UNBOUNDED_REMOTE_PROMPT_DEADLINE_MS &&
Date.now() >= this.#recoveryDeadlineAt
if (
this.#recoveryDeadlineAt === undefined ||
this.#recoverySignal === undefined ||
this.#recoverySignal.aborted ||
Date.now() >= this.#recoveryDeadlineAt ||
recoveryDeadlineExpired ||
this.#activeBinarySends > 0 ||
this.#pendingControlRequests > 0 ||
providerDeliveryMayBeUncertain ||
@@ -1090,11 +1099,13 @@ export class ProtocolRemoteRuntimeChannel
await this.#flushRecoveryPersistence()
const deadlineAt = this.#recoveryDeadlineAt!
const callerSignal = this.#recoverySignal!
const remaining = deadlineAt - Date.now()
if (remaining <= 0) {
if (
deadlineAt !== UNBOUNDED_REMOTE_PROMPT_DEADLINE_MS &&
Date.now() >= deadlineAt
) {
throw new ProtocolRemoteRuntimeChannelError(
'Remote Runtime recovery deadline expired',
'aborted'
'transport'
)
}
const recoveryController = new AbortController()
@@ -1108,6 +1119,13 @@ export class ProtocolRemoteRuntimeChannel
)
}
callerSignal.addEventListener('abort', abort, { once: true })
const recoveryTimeoutMs =
deadlineAt === UNBOUNDED_REMOTE_PROMPT_DEADLINE_MS
? this.#state.controlTimeoutMs
: Math.min(
this.#state.controlTimeoutMs,
Math.max(0, deadlineAt - Date.now())
)
const timeout = setTimeout(() => {
recoveryController.abort(
new DOMException(
@@ -1115,7 +1133,7 @@ export class ProtocolRemoteRuntimeChannel
'TimeoutError'
)
)
}, remaining)
}, recoveryTimeoutMs)
try {
await this.#state.connection.reconnect!(
recoveryController.signal
@@ -1151,10 +1169,7 @@ export class ProtocolRemoteRuntimeChannel
channelId: this.#state.openResult.channelId,
channelEpoch: this.#state.openResult.channelEpoch
},
Math.min(
this.#state.controlTimeoutMs,
Math.max(1, deadlineAt - Date.now())
),
this.#state.controlTimeoutMs,
recoveryController.signal
),
'Remote Runtime resume response is invalid'
@@ -1205,10 +1220,7 @@ export class ProtocolRemoteRuntimeChannel
acknowledgedSequence:
resume.cursors.lastMainAckSequence
},
Math.min(
this.#state.controlTimeoutMs,
Math.max(1, deadlineAt - Date.now())
),
this.#state.controlTimeoutMs,
recoveryController.signal
),
'Remote Runtime replay response is invalid'
@@ -1,207 +0,0 @@
import { describe, expect, it, vi } from 'vitest'
import type {
SftpEntryMetadata,
StagedSftp
} from '../ssh/bounded-sftp'
import {
REMOTE_ENVIRONMENT_METADATA_PATHS,
restoreRemoteEnvironmentMetadata,
snapshotRemoteEnvironmentMetadata,
type RemoteEnvironmentMetadataSnapshot
} from './remote-environment-metadata'
const UID = 1000
function missingPath(): Error & { code: string } {
return Object.assign(new Error('missing'), { code: 'ENOENT' })
}
function fileMetadata(
contents: Buffer,
overrides: Partial<SftpEntryMetadata> = {}
): SftpEntryMetadata {
return {
type: 'file',
size: contents.byteLength,
mode: 0o600,
uid: UID,
gid: UID,
atime: 0,
mtime: 0,
...overrides
}
}
function createSftp(
initial: ReadonlyMap<string, Buffer>,
metadataOverrides: ReadonlyMap<string, Partial<SftpEntryMetadata>> =
new Map()
) {
const files = new Map(
[...initial].map(([path, contents]) => [path, Buffer.from(contents)])
)
const temporary = new Map<string, Buffer>()
const sftp: StagedSftp = {
stagingDirectory: '/home/goodbuddy',
mkdir: vi.fn(),
uploadFile: vi.fn(),
writeFile: vi.fn(async (path, contents) => {
temporary.set(path, Buffer.from(contents))
}),
readFile: vi.fn(async (path) => {
const contents = files.get(path) ?? temporary.get(path)
if (!contents) throw missingPath()
return Buffer.from(contents)
}),
lstat: vi.fn(async (path) => {
const contents = files.get(path) ?? temporary.get(path)
if (!contents) throw missingPath()
return fileMetadata(
contents,
metadataOverrides.get(path)
)
}),
stat: vi.fn(),
chmod: vi.fn(),
setExecutable: vi.fn(),
rename: vi.fn(),
replaceFile: vi.fn(async (source, destination) => {
const contents = temporary.get(source)
if (!contents) throw missingPath()
files.set(destination, Buffer.from(contents))
temporary.delete(source)
}),
unlink: vi.fn(async (path) => {
if (!files.delete(path) && !temporary.delete(path)) {
throw missingPath()
}
}),
rmdir: vi.fn(),
close: vi.fn()
}
return { sftp, files, temporary }
}
describe('remote environment metadata', () => {
it('snapshots original bytes and restores them exactly', async () => {
const originals = new Map(
REMOTE_ENVIRONMENT_METADATA_PATHS.map((path, index) => [
path,
Buffer.from([0, index, 255, 10])
])
)
const value = createSftp(originals)
const snapshots = await snapshotRemoteEnvironmentMetadata(
value.sftp,
UID,
new AbortController().signal
)
for (const path of REMOTE_ENVIRONMENT_METADATA_PATHS) {
value.files.set(path, Buffer.from('changed'))
}
await restoreRemoteEnvironmentMetadata(value.sftp, snapshots)
expect(
REMOTE_ENVIRONMENT_METADATA_PATHS.map((path) =>
value.files.get(path)
)
).toEqual(
REMOTE_ENVIRONMENT_METADATA_PATHS.map((path) =>
originals.get(path)
)
)
expect(value.sftp.chmod).toHaveBeenCalledTimes(5)
expect(value.sftp.replaceFile).toHaveBeenCalledTimes(5)
})
it('records missing metadata and removes files created after the snapshot', async () => {
const value = createSftp(new Map())
const snapshots = await snapshotRemoteEnvironmentMetadata(
value.sftp,
UID,
new AbortController().signal
)
for (const path of REMOTE_ENVIRONMENT_METADATA_PATHS) {
value.files.set(path, Buffer.from('new'))
}
await restoreRemoteEnvironmentMetadata(value.sftp, snapshots)
expect(value.files.size).toBe(0)
expect(value.sftp.unlink).toHaveBeenCalledTimes(5)
})
it('distinguishes an empty original file from a missing file', async () => {
const path = REMOTE_ENVIRONMENT_METADATA_PATHS[0]
const value = createSftp(
new Map([[path, Buffer.alloc(0)]])
)
const snapshots = await snapshotRemoteEnvironmentMetadata(
value.sftp,
UID,
new AbortController().signal
)
value.files.set(path, Buffer.from('changed'))
await restoreRemoteEnvironmentMetadata(value.sftp, snapshots)
expect(value.files.get(path)).toEqual(Buffer.alloc(0))
})
it.each([
['permissions', { mode: 0o644 }],
['owner', { uid: UID + 1 }],
['symbolic link', { type: 'symbolic-link' as const }]
])('rejects metadata with invalid %s', async (_label, override) => {
const path = REMOTE_ENVIRONMENT_METADATA_PATHS[0]
const contents = Buffer.from('metadata')
const value = createSftp(
new Map([[path, contents]]),
new Map([[path, override]])
)
await expect(snapshotRemoteEnvironmentMetadata(
value.sftp,
UID,
new AbortController().signal
)).rejects.toThrow('类型、所有者或权限无效')
expect(value.sftp.readFile).not.toHaveBeenCalled()
})
it('continues restoring remaining files and aggregates every error', async () => {
const first = REMOTE_ENVIRONMENT_METADATA_PATHS[0]
const second = REMOTE_ENVIRONMENT_METADATA_PATHS[1]
const third = REMOTE_ENVIRONMENT_METADATA_PATHS[2]
const value = createSftp(new Map([
[first, Buffer.from('changed-1')],
[second, Buffer.from('changed-2')],
[third, Buffer.from('created')]
]))
const firstError = new Error('first replace failed')
const secondError = new Error('second replace failed')
vi.mocked(value.sftp.replaceFile).mockImplementation(
async (_source, destination) => {
throw destination === first ? firstError : secondError
}
)
const snapshots: readonly RemoteEnvironmentMetadataSnapshot[] = [
{ path: first, contents: Buffer.from('original-1'), uid: UID },
{ path: second, contents: Buffer.from('original-2'), uid: UID },
{ path: third, uid: UID }
]
const caught = await restoreRemoteEnvironmentMetadata(
value.sftp,
snapshots
).catch((error: unknown) => error)
expect(caught).toBeInstanceOf(AggregateError)
expect((caught as AggregateError).errors).toEqual([
firstError,
secondError
])
expect(value.sftp.replaceFile).toHaveBeenCalledTimes(2)
expect(value.files.has(third)).toBe(false)
})
})
@@ -1,142 +0,0 @@
import { randomUUID } from 'node:crypto'
import type { StagedSftp } from '../ssh/bounded-sftp'
import { isMissingPathError } from './path-errors'
const PRIVATE_FILE_MODE = 0o600
export const REMOTE_ENVIRONMENT_METADATA_PATHS = [
'.goodbuddy/agent/release-keys.json',
'.goodbuddy/agent/registry.json',
'.goodbuddy/runtimes/release-keys.json',
'.goodbuddy/runtimes/remote-runtime-lock.json',
'.goodbuddy/runtimes/registry.json'
] as const
export type RemoteEnvironmentMetadataSnapshot = {
path: (typeof REMOTE_ENVIRONMENT_METADATA_PATHS)[number]
contents?: Buffer
uid: number
}
export async function snapshotRemoteEnvironmentMetadata(
sftp: StagedSftp,
uid: number,
signal: AbortSignal
): Promise<readonly RemoteEnvironmentMetadataSnapshot[]> {
const snapshots: RemoteEnvironmentMetadataSnapshot[] = []
for (const path of REMOTE_ENVIRONMENT_METADATA_PATHS) {
signal.throwIfAborted()
const metadata = await metadataIfPresent(sftp, path, signal)
if (!metadata) {
snapshots.push({ path, uid })
continue
}
assertPrivateFile(metadata, path, uid)
snapshots.push({
path,
contents: await sftp.readFile(path, signal),
uid
})
}
return snapshots
}
export async function restoreRemoteEnvironmentMetadata(
sftp: StagedSftp,
snapshots: readonly RemoteEnvironmentMetadataSnapshot[]
): Promise<void> {
const errors: unknown[] = []
for (const snapshot of snapshots) {
try {
await restoreRemoteEnvironmentMetadataFile(sftp, snapshot)
} catch (error) {
errors.push(error)
}
}
if (errors.length > 0) {
throw new AggregateError(
errors,
'远程运行环境元数据回滚不完整'
)
}
}
async function restoreRemoteEnvironmentMetadataFile(
sftp: StagedSftp,
snapshot: RemoteEnvironmentMetadataSnapshot
): Promise<void> {
const existing = await metadataIfPresent(sftp, snapshot.path)
if (snapshot.contents === undefined) {
if (existing) {
assertPrivateFile(existing, snapshot.path, snapshot.uid)
await sftp.unlink(snapshot.path)
}
return
}
if (existing) {
assertPrivateFile(existing, snapshot.path, snapshot.uid)
if (
existing.size === snapshot.contents.byteLength &&
(await sftp.readFile(snapshot.path)).equals(snapshot.contents)
) {
return
}
}
const temporary =
`.goodbuddy/.environment-metadata-rollback-${randomUUID()}.tmp`
try {
await sftp.writeFile(temporary, snapshot.contents)
await sftp.chmod(temporary, PRIVATE_FILE_MODE)
await sftp.replaceFile(temporary, snapshot.path)
const restored = await sftp.lstat(snapshot.path)
assertPrivateFile(restored, snapshot.path, snapshot.uid)
if (
restored.size !== snapshot.contents.byteLength ||
!(await sftp.readFile(snapshot.path)).equals(snapshot.contents)
) {
throw new Error(
`远程运行环境元数据 ${snapshot.path} 回滚校验失败`
)
}
} catch (error) {
await sftp.unlink(temporary).catch((cleanupError: unknown) => {
if (!isMissingPathError(cleanupError)) {
throw cleanupError
}
})
throw error
}
}
async function metadataIfPresent(
sftp: StagedSftp,
path: string,
signal?: AbortSignal
) {
try {
return await sftp.lstat(path, signal)
} catch (error) {
if (isMissingPathError(error)) {
return undefined
}
throw error
}
}
function assertPrivateFile(
metadata: Awaited<ReturnType<StagedSftp['lstat']>>,
path: string,
uid: number
): void {
if (
metadata.type !== 'file' ||
metadata.uid !== uid ||
metadata.mode !== PRIVATE_FILE_MODE
) {
throw new Error(
`远程运行环境元数据 ${path} 的类型、所有者或权限无效`
)
}
}
@@ -12,10 +12,7 @@ const operation: PendingRemoteEnvironmentOperation = {
version: 1,
hostId: 'host-1',
targetIdentity: 'a'.repeat(64),
operationId: '00000000-0000-4000-8000-000000000777',
size: 123,
sha256: 'b'.repeat(64),
urls: []
operationId: '00000000-0000-4000-8000-000000000777'
}
afterEach(async () => {
@@ -42,39 +39,6 @@ describe('RemoteEnvironmentOperationStore', () => {
await expect(store.load(operation.hostId)).resolves.toBeUndefined()
})
it('persists bounded metadata snapshots for post-commit recovery', async () => {
const root = await mkdtemp(
join(tmpdir(), 'goodbuddy-environment-operation-')
)
temporaryDirectories.push(root)
const store = new RemoteEnvironmentOperationStore(root)
const recovered: PendingRemoteEnvironmentOperation = {
...operation,
version: 2,
metadataSnapshots: [
'.goodbuddy/agent/release-keys.json',
'.goodbuddy/agent/registry.json',
'.goodbuddy/runtimes/release-keys.json',
'.goodbuddy/runtimes/remote-runtime-lock.json',
'.goodbuddy/runtimes/registry.json'
].map((path, index) => ({
path: path as never,
uid: 1000,
...(index === 1
? {}
: {
contentsBase64:
Buffer.from(`metadata-${index}`).toString('base64')
})
}))
}
await store.save(recovered)
await expect(store.load(operation.hostId)).resolves.toEqual(
recovered
)
})
it('rejects a mismatched or oversized recovery record', async () => {
const root = await mkdtemp(
join(tmpdir(), 'goodbuddy-environment-operation-')
@@ -91,7 +55,7 @@ describe('RemoteEnvironmentOperationStore', () => {
const [record] = await readdir(files)
await writeFile(
join(files, record!),
Buffer.alloc(8 * 1024 * 1024 + 1)
Buffer.alloc(4 * 1024 + 1)
)
await expect(store.load(operation.hostId)).rejects.toThrow(
@@ -6,42 +6,18 @@ import {
writeJsonFileAtomically
} from '../settings-file-utils'
const MAXIMUM_RECORD_BYTES = 8 * 1024 * 1024
const MAXIMUM_RECORD_BYTES = 4 * 1024
const OPERATION_ID_PATTERN =
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u
const SHA256_PATTERN = /^[a-f0-9]{64}$/u
type PendingRemoteEnvironmentOperationBase = {
export type PendingRemoteEnvironmentOperation = {
version: 1
hostId: string
targetIdentity: string
operationId: string
size: number
sha256: string
urls: readonly string[]
}
export type PersistedRemoteEnvironmentMetadataSnapshot = {
path:
| '.goodbuddy/agent/release-keys.json'
| '.goodbuddy/agent/registry.json'
| '.goodbuddy/runtimes/release-keys.json'
| '.goodbuddy/runtimes/remote-runtime-lock.json'
| '.goodbuddy/runtimes/registry.json'
contentsBase64?: string
uid: number
}
export type PendingRemoteEnvironmentOperation =
PendingRemoteEnvironmentOperationBase &
(
| { version: 1 }
| {
version: 2
metadataSnapshots:
readonly PersistedRemoteEnvironmentMetadataSnapshot[]
}
)
export class RemoteEnvironmentOperationStore {
readonly #directory: string
@@ -116,27 +92,12 @@ function parsePendingOperation(
throw new Error('远程环境恢复记录无效')
}
const record = value as Record<string, unknown>
const version = record.version
const expectedKeys = version === 2
? [
'hostId',
'metadataSnapshots',
'operationId',
'sha256',
'size',
'targetIdentity',
'urls',
'version'
]
: [
'hostId',
'operationId',
'sha256',
'size',
'targetIdentity',
'urls',
'version'
]
const expectedKeys = [
'hostId',
'operationId',
'targetIdentity',
'version'
]
if (
Object.keys(value).sort().join('\0') !==
expectedKeys.sort().join('\0')
@@ -144,128 +105,19 @@ function parsePendingOperation(
throw new Error('远程环境恢复记录无效')
}
if (
(version !== 1 && version !== 2) ||
record.version !== 1 ||
record.hostId !== expectedHostId ||
typeof record.targetIdentity !== 'string' ||
!SHA256_PATTERN.test(record.targetIdentity) ||
typeof record.operationId !== 'string' ||
!OPERATION_ID_PATTERN.test(record.operationId) ||
!Number.isSafeInteger(record.size) ||
Number(record.size) <= 0 ||
typeof record.sha256 !== 'string' ||
!SHA256_PATTERN.test(record.sha256) ||
!Array.isArray(record.urls) ||
record.urls.length > 4 ||
record.urls.some(
(url) =>
typeof url !== 'string' ||
Buffer.byteLength(url, 'utf8') > 4_096
)
!OPERATION_ID_PATTERN.test(record.operationId)
) {
throw new Error('远程环境恢复记录无效')
}
const base: PendingRemoteEnvironmentOperationBase = {
hostId: expectedHostId,
targetIdentity: record.targetIdentity,
operationId: record.operationId,
size: Number(record.size),
sha256: record.sha256,
urls: [...record.urls] as string[]
}
if (version === 1) {
return { version: 1, ...base }
}
return {
version: 2,
...base,
metadataSnapshots: parseMetadataSnapshots(
record.metadataSnapshots
)
version: 1,
hostId: expectedHostId,
targetIdentity: record.targetIdentity,
operationId: record.operationId
}
}
const metadataPaths =
new Set<PersistedRemoteEnvironmentMetadataSnapshot['path']>([
'.goodbuddy/agent/release-keys.json',
'.goodbuddy/agent/registry.json',
'.goodbuddy/runtimes/release-keys.json',
'.goodbuddy/runtimes/remote-runtime-lock.json',
'.goodbuddy/runtimes/registry.json'
])
function parseMetadataSnapshots(
value: unknown
): readonly PersistedRemoteEnvironmentMetadataSnapshot[] {
if (!Array.isArray(value) || value.length !== metadataPaths.size) {
throw new Error('远程环境恢复记录无效')
}
const paths = new Set<string>()
let totalBytes = 0
const snapshots = value.map((item) => {
if (
typeof item !== 'object' ||
item === null ||
!(
Object.keys(item).sort().join('\0') ===
['path', 'uid'].sort().join('\0') ||
Object.keys(item).sort().join('\0') ===
['contentsBase64', 'path', 'uid'].sort().join('\0')
)
) {
throw new Error('远程环境恢复记录无效')
}
const snapshot = item as Record<string, unknown>
if (
typeof snapshot.path !== 'string' ||
!metadataPaths.has(
snapshot.path as PersistedRemoteEnvironmentMetadataSnapshot['path']
) ||
paths.has(snapshot.path) ||
!Number.isSafeInteger(snapshot.uid) ||
Number(snapshot.uid) < 0
) {
throw new Error('远程环境恢复记录无效')
}
paths.add(snapshot.path)
if (snapshot.contentsBase64 === undefined) {
return {
path:
snapshot.path as PersistedRemoteEnvironmentMetadataSnapshot['path'],
uid: Number(snapshot.uid)
}
}
if (
typeof snapshot.contentsBase64 !== 'string' ||
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u
.test(snapshot.contentsBase64)
) {
throw new Error('远程环境恢复记录无效')
}
const contents = Buffer.from(
snapshot.contentsBase64,
'base64'
)
if (
contents.toString('base64') !==
snapshot.contentsBase64 ||
contents.byteLength > 1024 * 1024
) {
throw new Error('远程环境恢复记录无效')
}
totalBytes += contents.byteLength
return {
path:
snapshot.path as PersistedRemoteEnvironmentMetadataSnapshot['path'],
contentsBase64: snapshot.contentsBase64,
uid: Number(snapshot.uid)
}
})
if (
paths.size !== metadataPaths.size ||
[...metadataPaths].some((path) => !paths.has(path)) ||
totalBytes > 5 * 1024 * 1024
) {
throw new Error('远程环境恢复记录无效')
}
return snapshots
}
@@ -4,12 +4,10 @@ import {
SshRemotePackageCommitIndeterminateError,
type SshRemotePackageIdentity
} from '../ssh/ssh-remote-package-bootstrap'
import type { StagedSftp } from '../ssh/bounded-sftp'
import type {
AgentPackageArchiveLease,
VerifiedRemoteAgentInstallCandidate
} from './agent-package-manager'
import { REMOTE_ENVIRONMENT_METADATA_PATHS } from './remote-environment-metadata'
import type {
PendingRemoteEnvironmentOperation
} from './remote-environment-operation-store'
@@ -100,72 +98,13 @@ type FixtureOptions = {
prepare?: ReturnType<typeof vi.fn>
prepareUploaded?: ReturnType<typeof vi.fn>
commit?: ReturnType<typeof vi.fn>
commitStatus?: ReturnType<typeof vi.fn>
cleanup?: ReturnType<typeof vi.fn>
uploadFile?: ReturnType<typeof vi.fn>
activateAgent?: ReturnType<typeof vi.fn>
activateRuntime?: ReturnType<typeof vi.fn>
metadataFiles?: Map<string, Buffer>
metadataReplaceFailure?: Error
pendingOperation?: PendingRemoteEnvironmentOperation
}
function missingPath(): Error & { code: string } {
return Object.assign(new Error('missing'), { code: 'ENOENT' })
}
function metadataSftp(
files: Map<string, Buffer>,
calls: string[],
replaceFailure?: Error
): StagedSftp {
const temporary = new Map<string, Buffer>()
return {
stagingDirectory: '/home/goodbuddy',
mkdir: vi.fn(),
uploadFile: vi.fn(),
writeFile: vi.fn(async (path: string, contents: Buffer) => {
temporary.set(path, Buffer.from(contents))
}),
readFile: vi.fn(async (path: string) => {
const contents = files.get(path) ?? temporary.get(path)
if (!contents) throw missingPath()
return Buffer.from(contents)
}),
lstat: vi.fn(async (path: string) => {
const contents = files.get(path) ?? temporary.get(path)
if (!contents) throw missingPath()
return {
type: 'file' as const,
size: contents.byteLength,
mode: 0o600,
uid: 1000,
gid: 1000,
atime: 0,
mtime: 0
}
}),
stat: vi.fn(),
chmod: vi.fn(),
setExecutable: vi.fn(),
rename: vi.fn(),
replaceFile: vi.fn(async (source: string, destination: string) => {
if (replaceFailure) throw replaceFailure
const contents = temporary.get(source)
if (!contents) throw missingPath()
files.set(destination, contents)
temporary.delete(source)
}),
unlink: vi.fn(async (path: string) => {
if (!files.delete(path) && !temporary.delete(path)) {
throw missingPath()
}
}),
rmdir: vi.fn(),
close: vi.fn(() => calls.push('close-metadata'))
}
}
function fixture(options: FixtureOptions = {}) {
const calls: string[] = []
const targets = options.targets ?? [target()]
@@ -182,12 +121,6 @@ function fixture(options: FixtureOptions = {}) {
hostKeyGeneration: targets[0]!.hostKeyGeneration,
authenticationIdentity: '3'.repeat(64)
}
const metadataFiles = options.metadataFiles ?? new Map<string, Buffer>()
const metadata = metadataSftp(
metadataFiles,
calls,
options.metadataReplaceFailure
)
const uploadFile = options.uploadFile ?? vi.fn(async (
path: string
) => {
@@ -202,14 +135,6 @@ function fixture(options: FixtureOptions = {}) {
close: vi.fn(() => calls.push('close-upload'))
}
const regularRelease = vi.fn(() => calls.push('release-probe'))
const stopCandidate = vi.fn(async (
_installationId?: string,
_action?: string
) => {
void _installationId
void _action
calls.push('stop-candidate')
})
const activateAgent = options.activateAgent ?? vi.fn(async () => {
calls.push('agent')
return { exitCode: 0, stdout: '{}', stderr: '' }
@@ -233,27 +158,17 @@ function fixture(options: FixtureOptions = {}) {
procfs: 'ready'
}
}),
openStagedSftp: vi.fn(async (root: string) => {
if (root.includes('install-operations')) {
calls.push('open-upload')
return uploadSftp
}
calls.push('open-metadata')
return metadata
openStagedSftp: vi.fn(async () => {
calls.push('open-upload')
return uploadSftp
}),
runAgentLifecycleAction: vi.fn(async (
installationId: string,
action: string
) => {
if (action === 'stop') {
await stopCandidate(installationId, action)
return { exitCode: 0, stdout: '{}', stderr: '' }
}
return (activateAgent as (
) => (activateAgent as (
installationId: string,
action: string
) => Promise<unknown>)(installationId, action)
}),
) => Promise<unknown>)(installationId, action)),
runAgentRuntimeAction: vi.fn(async (
installationId: string,
action: unknown
@@ -302,13 +217,6 @@ function fixture(options: FixtureOptions = {}) {
calls.push('cleanup')
return { cleaned: true, operationId }
})
const commitStatus = options.commitStatus ?? vi.fn(async (
input: { operationId: string }
) => ({
committed: true,
operationId: input.operationId,
identity
}))
const bootstrapRelease = vi.fn(() => calls.push('release-bootstrap'))
const probe = vi.fn(async () => {
calls.push('method-probe')
@@ -337,7 +245,6 @@ function fixture(options: FixtureOptions = {}) {
prepare,
prepareUploaded,
commit,
commitStatus,
cleanup,
release: bootstrapRelease
}
@@ -402,8 +309,6 @@ function fixture(options: FixtureOptions = {}) {
resolver,
regularLease,
bootstrapLease,
metadata,
metadataFiles,
uploadFile,
probe,
createUploadStaging,
@@ -417,8 +322,6 @@ function fixture(options: FixtureOptions = {}) {
archiveRelease,
regularRelease,
bootstrapRelease,
stopCandidate,
commitStatus,
operationStore
}
}
@@ -445,15 +348,12 @@ describe('RemoteEnvironmentPreparer', () => {
'acquire-bootstrap',
'save-operation',
'prepare',
'open-metadata',
'save-operation',
'resolve',
'commit',
'agent',
'runtime',
'cleanup',
'remove-operation',
'close-metadata',
'release-bootstrap',
'release-probe'
])
@@ -483,7 +383,7 @@ describe('RemoteEnvironmentPreparer', () => {
remoteCandidate.operationId,
{ signal: controller.signal }
)
expect(value.operationStore.save).toHaveBeenCalledTimes(2)
expect(value.operationStore.save).toHaveBeenCalledOnce()
expect(value.operationStore.remove).toHaveBeenCalledOnce()
expect(progress.some((event) =>
event.method === 'remote-download' &&
@@ -532,7 +432,6 @@ describe('RemoteEnvironmentPreparer', () => {
)).resolves.toBeUndefined()
expect(value.activateAgent).toHaveBeenCalledOnce()
expect(value.activateRuntime).toHaveBeenCalledOnce()
expect(value.stopCandidate).not.toHaveBeenCalled()
expect(value.operationStore.remove).not.toHaveBeenCalled()
})
@@ -725,13 +624,13 @@ describe('RemoteEnvironmentPreparer', () => {
new AbortController().signal
)).rejects.toBeInstanceOf(SshRemotePackageCommitIndeterminateError)
expect(value.cleanup).not.toHaveBeenCalled()
expect(value.operationStore.save).toHaveBeenCalledTimes(2)
expect(value.operationStore.save).toHaveBeenCalledOnce()
expect(value.operationStore.remove).not.toHaveBeenCalled()
expect(value.activateAgent).not.toHaveBeenCalled()
expect(value.activateRuntime).not.toHaveBeenCalled()
})
it('rolls metadata back when cancellation arrives with a successful commit result', async () => {
it('cleans staging when cancellation arrives with a successful commit result', async () => {
const controller = new AbortController()
const cancellation =
new DOMException('cancelled after commit', 'AbortError')
@@ -752,7 +651,6 @@ describe('RemoteEnvironmentPreparer', () => {
undefined,
controller.signal
)).rejects.toBe(cancellation)
expect(value.stopCandidate).toHaveBeenCalledOnce()
expect(value.cleanup).toHaveBeenCalledOnce()
expect(value.operationStore.remove).toHaveBeenCalledOnce()
expect(value.activateAgent).not.toHaveBeenCalled()
@@ -778,61 +676,7 @@ describe('RemoteEnvironmentPreparer', () => {
expect(value.operationStore.remove).not.toHaveBeenCalled()
})
it('resumes adoption for a committed operation instead of reinstalling it', async () => {
const pendingOperationId =
'00000000-0000-4000-8000-000000000777'
const originalTarget = target()
const renamedTarget = target({
host: {
...originalTarget.host,
name: 'Renamed builder'
},
hostRevision: 99
})
const value = fixture({
targets: [renamedTarget],
pendingOperation: {
version: 2,
hostId: HOST_ID,
targetIdentity:
remoteHostRecoveryIdentityKey(originalTarget),
operationId: pendingOperationId,
size: candidate.size,
sha256: candidate.sha256,
urls: candidate.urls,
metadataSnapshots:
REMOTE_ENVIRONMENT_METADATA_PATHS.map(
(path) => ({
path,
uid: 1000
})
)
}
})
await value.preparer.prepare(
HOST_ID,
'remote-download',
undefined,
new AbortController().signal
)
expect(value.commitStatus).toHaveBeenCalledWith(
expect.objectContaining({
operationId: pendingOperationId
}),
expect.any(Object)
)
expect(value.cleanup.mock.calls[0]?.[0]).toBe(
pendingOperationId
)
expect(value.activateAgent).toHaveBeenCalledOnce()
expect(value.activateRuntime).toHaveBeenCalledOnce()
expect(value.prepare).not.toHaveBeenCalled()
expect(value.operationStore.remove).toHaveBeenCalledOnce()
})
it('cleans a legacy pending operation and starts a fresh authenticated prepare', async () => {
it('cleans pending staging and starts a fresh authenticated prepare', async () => {
const originalTarget = target()
const pendingOperationId =
'00000000-0000-4000-8000-000000000780'
@@ -843,10 +687,7 @@ describe('RemoteEnvironmentPreparer', () => {
hostId: HOST_ID,
targetIdentity:
remoteHostRecoveryIdentityKey(originalTarget),
operationId: pendingOperationId,
size: candidate.size,
sha256: candidate.sha256,
urls: candidate.urls
operationId: pendingOperationId
}
})
@@ -857,7 +698,6 @@ describe('RemoteEnvironmentPreparer', () => {
new AbortController().signal
)
expect(value.commitStatus).not.toHaveBeenCalled()
expect(value.cleanup.mock.calls[0]?.[0]).toBe(
pendingOperationId
)
@@ -865,104 +705,30 @@ describe('RemoteEnvironmentPreparer', () => {
expect(value.operationStore.remove).toHaveBeenCalledTimes(2)
})
it('restores the durable snapshot when resumed commit does not complete', async () => {
it('does not block a fresh prepare when stale staging cleanup fails', async () => {
const originalTarget = target()
const originals = new Map<string, Buffer>(
REMOTE_ENVIRONMENT_METADATA_PATHS.map(
(path, index) => [
path,
Buffer.from(`before-commit-${index}`)
]
)
)
const files = new Map<string, Buffer>(
REMOTE_ENVIRONMENT_METADATA_PATHS.map(
(path) => [path, Buffer.from('partial-commit')]
)
)
let cleanupCalls = 0
const value = fixture({
targets: [originalTarget],
metadataFiles: files,
pendingOperation: {
version: 2,
version: 1,
hostId: HOST_ID,
targetIdentity:
remoteHostRecoveryIdentityKey(originalTarget),
operationId:
'00000000-0000-4000-8000-000000000781',
size: candidate.size,
sha256: candidate.sha256,
urls: candidate.urls,
metadataSnapshots: [...originals].map(
([path, contents]) => ({
path: path as never,
uid: 1000,
contentsBase64: contents.toString('base64')
})
)
'00000000-0000-4000-8000-000000000779'
},
commitStatus: vi.fn(async () => ({
committed: false,
reason: 'installer-failed'
}))
})
await value.preparer.prepare(
HOST_ID,
'remote-download',
undefined,
new AbortController().signal
)
expect([...files]).toEqual([...originals])
expect(value.prepare).toHaveBeenCalledOnce()
})
it('restores persisted pre-commit metadata when resumed Runtime adoption fails', async () => {
const originalTarget = target()
const originals = new Map<string, Buffer>(
REMOTE_ENVIRONMENT_METADATA_PATHS.map(
(path, index) => [
path,
Buffer.from(`original-${index}`)
]
)
)
const files = new Map<string, Buffer>(
REMOTE_ENVIRONMENT_METADATA_PATHS.map(
(path) => [path, Buffer.from('published')]
)
)
const runtimeFailure = new Error('runtime recovery failed')
const value = fixture({
targets: [originalTarget],
metadataFiles: files,
pendingOperation: {
version: 2,
hostId: HOST_ID,
targetIdentity:
remoteHostRecoveryIdentityKey(originalTarget),
operationId:
'00000000-0000-4000-8000-000000000779',
size: candidate.size,
sha256: candidate.sha256,
urls: candidate.urls,
metadataSnapshots: [...originals].map(
([path, contents]) => ({
path: path as never,
uid: 1000,
contentsBase64: contents.toString('base64')
})
)
},
activateAgent: vi.fn(async () => {
for (const path of REMOTE_ENVIRONMENT_METADATA_PATHS) {
files.set(path, Buffer.from('adopting'))
}
return { exitCode: 0, stdout: '{}', stderr: '' }
}),
activateRuntime: vi.fn(async () => {
throw runtimeFailure
cleanup: vi.fn(async (operationId: string) => {
cleanupCalls += 1
return cleanupCalls === 1
? {
cleaned: false as const,
reason: 'cleanup-failed' as const
}
: {
cleaned: true as const,
operationId
}
})
})
@@ -971,14 +737,14 @@ describe('RemoteEnvironmentPreparer', () => {
'remote-download',
undefined,
new AbortController().signal
)).rejects.toThrow('runtime recovery failed')
expect([...files]).toEqual([...originals])
expect(value.stopCandidate).toHaveBeenCalledOnce()
expect(value.cleanup).not.toHaveBeenCalled()
expect(value.operationStore.remove).not.toHaveBeenCalled()
)).resolves.toBeUndefined()
expect(value.prepare).toHaveBeenCalledOnce()
expect(value.cleanup).toHaveBeenCalledTimes(2)
expect(value.operationStore.remove).toHaveBeenCalledTimes(2)
})
it('retains pending recovery evidence when the real SSH target changes', async () => {
it('drops stale cleanup state when the SSH target changed and starts fresh', async () => {
const originalTarget = target()
const changedTarget = target({
host: {
@@ -986,6 +752,8 @@ describe('RemoteEnvironmentPreparer', () => {
hostname: 'different.example'
}
})
const pendingOperationId =
'00000000-0000-4000-8000-000000000778'
const value = fixture({
targets: [changedTarget],
pendingOperation: {
@@ -993,45 +761,27 @@ describe('RemoteEnvironmentPreparer', () => {
hostId: HOST_ID,
targetIdentity:
remoteHostRecoveryIdentityKey(originalTarget),
operationId:
'00000000-0000-4000-8000-000000000778',
size: candidate.size,
sha256: candidate.sha256,
urls: candidate.urls
operationId: pendingOperationId
}
})
await expect(value.preparer.prepare(
await value.preparer.prepare(
HOST_ID,
'remote-download',
undefined,
new AbortController().signal
)).rejects.toBeInstanceOf(
SshRemotePackageCommitIndeterminateError
)
expect(value.commitStatus).not.toHaveBeenCalled()
expect(value.operationStore.remove).not.toHaveBeenCalled()
expect(value.prepare).toHaveBeenCalledOnce()
expect(value.cleanup.mock.calls.some(
(call) => call[0] === pendingOperationId
)).toBe(false)
expect(value.operationStore.remove).toHaveBeenCalledTimes(2)
})
it('stops the committed Agent and restores all five metadata files when Runtime adoption fails', async () => {
const originals = new Map<string, Buffer>()
for (const [index, path] of REMOTE_ENVIRONMENT_METADATA_PATHS.entries()) {
if (index !== 2) originals.set(path, Buffer.from(`original-${index}`))
}
const files = new Map(
[...originals].map(([path, contents]) => [path, Buffer.from(contents)])
)
const runtimeFailure = new Error('runtime health failed')
it('cleans staging and leaves a fresh retry after Runtime adoption fails', async () => {
const runtimeFailure = new Error('runtime failed')
const value = fixture({
metadataFiles: files,
activateAgent: vi.fn(async () => {
value.calls.push('agent')
value.metadataFiles.clear()
for (const path of REMOTE_ENVIRONMENT_METADATA_PATHS) {
value.metadataFiles.set(path, Buffer.from('new'))
}
return { exitCode: 0, stdout: '{}', stderr: '' }
}),
activateRuntime: vi.fn(async () => {
throw runtimeFailure
})
@@ -1043,42 +793,7 @@ describe('RemoteEnvironmentPreparer', () => {
undefined,
new AbortController().signal
)).rejects.toBe(runtimeFailure)
expect(value.stopCandidate).toHaveBeenCalledWith(
identity.agent.installationId,
'stop'
)
expect([...value.metadataFiles]).toEqual([...originals])
expect(value.cleanup).toHaveBeenCalledOnce()
})
it('throws AggregateError when adoption and metadata rollback both fail', async () => {
const path = REMOTE_ENVIRONMENT_METADATA_PATHS[0]
const files = new Map([[path, Buffer.from('original')]])
const runtimeFailure = new Error('runtime failed')
const rollbackFailure = new Error('replace failed')
const value = fixture({
metadataFiles: files,
metadataReplaceFailure: rollbackFailure,
activateAgent: vi.fn(async () => {
files.set(path, Buffer.from('changed'))
return { exitCode: 0, stdout: '{}', stderr: '' }
}),
activateRuntime: vi.fn(async () => {
throw runtimeFailure
})
})
const caught = await value.preparer.prepare(
HOST_ID,
'remote-download',
undefined,
new AbortController().signal
).catch((error: unknown) => error)
expect(caught).toBeInstanceOf(AggregateError)
expect((caught as AggregateError).errors[0]).toBe(runtimeFailure)
expect((caught as AggregateError).errors[1]).toBeInstanceOf(
AggregateError
)
expect(value.stopCandidate).toHaveBeenCalledOnce()
expect(value.operationStore.remove).toHaveBeenCalledOnce()
})
})
@@ -5,7 +5,6 @@ import type {
RemoteEnvironmentPreparationMethod,
RemoteEnvironmentUpdateProgress
} from '../../shared/ssh-host-contracts'
import type { StagedSftp } from '../ssh/bounded-sftp'
import { verifyAgentInstallationId } from '../ssh/ssh-agent-command'
import type {
AgentDiagnosticResult,
@@ -33,13 +32,8 @@ import type {
AgentPackageManager,
VerifiedRemoteAgentInstallCandidate
} from './agent-package-manager'
import {
restoreRemoteEnvironmentMetadata,
snapshotRemoteEnvironmentMetadata,
type RemoteEnvironmentMetadataSnapshot
} from './remote-environment-metadata'
import type {
PersistedRemoteEnvironmentMetadataSnapshot,
PendingRemoteEnvironmentOperation,
RemoteEnvironmentOperationStore
} from './remote-environment-operation-store'
import type {
@@ -52,7 +46,6 @@ import {
import { boundedDiagnostic } from './bounded-diagnostic'
const MAXIMUM_PACKAGE_BYTES = 512 * 1024 * 1024
const MAXIMUM_METADATA_BYTES = 1024 * 1024
const MAXIMUM_DIAGNOSTIC_CHARACTERS = 800
function assertAgentCommandSucceeded(
@@ -95,7 +88,7 @@ export type RemoteEnvironmentPreparerOptions = {
/**
* Prepares one signed compound environment. The selected method controls only
* how the archive reaches the Host; both paths share prepare, commit,
* activation, rollback, health checks, and cleanup.
* activation, health checks, and cleanup.
*/
export class RemoteEnvironmentPreparer implements Preparer {
readonly #resolver: AgentInstallationTargetResolver
@@ -134,29 +127,21 @@ export class RemoteEnvironmentPreparer implements Preparer {
const target = await this.#resolver.resolve(hostId)
signal.throwIfAborted()
assertValidSshConnectionTarget(hostId, target)
const recovered = await this.#reconcilePendingOperation(
await this.#cleanupPendingOperation(
hostId,
target,
emit,
signal
)
if (recovered) {
return
}
let probeLease: SshConnectionLease | undefined
let bootstrapLease:
| SshRemotePackageBootstrapLease
| undefined
let archiveLease: AgentPackageArchiveLease | undefined
let metadataSftp: StagedSftp | undefined
let metadataSnapshots:
| readonly RemoteEnvironmentMetadataSnapshot[]
| undefined
let operationId: string | undefined
let operationCleaned = false
let pendingOperationSaved = false
let committedIdentity: SshRemotePackageIdentity | undefined
try {
probeLease = await this.#sshPool.acquire(target, signal)
assertLeaseMatchesTarget(probeLease, target)
@@ -256,16 +241,13 @@ export class RemoteEnvironmentPreparer implements Preparer {
}
emit(method, 'probing')
// Persist recovery identity before either preparation path may create
// remote staging. A Main crash must never leave an untracked operation.
// Keep only the operation ID needed to clean stale staging before the
// next fresh attempt. No remote environment state is copied locally.
await this.#operationStore.save({
version: 1,
hostId,
targetIdentity: remoteHostRecoveryIdentityKey(target),
operationId,
size: remoteCandidate.size,
sha256: remoteCandidate.sha256,
urls: [...remoteCandidate.urls]
operationId
})
pendingOperationSaved = true
@@ -289,35 +271,6 @@ export class RemoteEnvironmentPreparer implements Preparer {
assertPrepared(prepared, operationId)
assertPackageIdentity(prepared.identity, candidate)
// Snapshot the complete environment before commit so an Agent success
// followed by a Runtime failure cannot expose a partially adopted pair.
metadataSftp = await probeLease.openStagedSftp(
probe.canonicalHomeDirectory,
{
maximumFileBytes: MAXIMUM_METADATA_BYTES,
maximumTotalBytes: MAXIMUM_METADATA_BYTES * 24,
maximumOperations: 128
},
signal
)
metadataSnapshots =
await snapshotRemoteEnvironmentMetadata(
metadataSftp,
probe.uid,
signal
)
await this.#operationStore.save({
version: 2,
hostId,
targetIdentity: remoteHostRecoveryIdentityKey(target),
operationId,
size: remoteCandidate.size,
sha256: remoteCandidate.sha256,
urls: [...remoteCandidate.urls],
metadataSnapshots:
persistMetadataSnapshots(metadataSnapshots)
})
// Keep the full target re-resolution immediately adjacent to commit.
await assertTargetCurrent(this.#resolver, target, signal)
assertLeaseMatchesTarget(bootstrapLease, target)
@@ -355,7 +308,6 @@ export class RemoteEnvironmentPreparer implements Preparer {
throw new Error('远端安装提交身份与准备身份不匹配')
}
assertPackageIdentity(committed.identity, candidate)
committedIdentity = committed.identity
signal.throwIfAborted()
await this.#adoptCommittedEnvironment(
@@ -372,7 +324,10 @@ export class RemoteEnvironmentPreparer implements Preparer {
operationId,
{ signal }
)
if (cleanup.cleaned) {
if (
cleanup.cleaned ||
cleanup.reason === 'operation-unavailable'
) {
operationCleaned = true
try {
await this.#operationStore.remove(hostId)
@@ -381,29 +336,10 @@ export class RemoteEnvironmentPreparer implements Preparer {
}
}
} catch {
// The environment is already healthy. Leave the bounded
// operation for a later maintenance retry.
// The environment is already healthy. The next update will retry
// cleanup before starting a fresh operation.
}
} catch (error) {
let rollbackError: unknown
if (
committedIdentity &&
metadataSftp &&
metadataSnapshots
) {
await stopCandidateBestEffort(
probeLease,
committedIdentity.agent.installationId
)
try {
await restoreRemoteEnvironmentMetadata(
metadataSftp,
metadataSnapshots
)
} catch (reason) {
rollbackError = reason
}
}
if (
operationId &&
bootstrapLease &&
@@ -415,19 +351,11 @@ export class RemoteEnvironmentPreparer implements Preparer {
operationId
)
if (operationCleaned && pendingOperationSaved) {
await this.#operationStore.remove(hostId)
await this.#operationStore.remove(hostId).catch(() => undefined)
}
}
if (rollbackError) {
throw new AggregateError(
[error, rollbackError],
'远程运行环境准备失败,且原有环境元数据未能完整恢复',
{ cause: error }
)
}
throw error
} finally {
metadataSftp?.close()
archiveLease?.release()
bootstrapLease?.release()
probeLease?.release()
@@ -595,7 +523,7 @@ export class RemoteEnvironmentPreparer implements Preparer {
)
}
async #reconcilePendingOperation(
async #cleanupPendingOperation(
hostId: string,
target: SshConnectionTarget,
emit: (
@@ -603,207 +531,46 @@ export class RemoteEnvironmentPreparer implements Preparer {
phase: RemoteEnvironmentUpdateProgress['phase']
) => void,
signal: AbortSignal
): Promise<boolean> {
const pending = await this.#operationStore.load(hostId)
): Promise<void> {
let pending: PendingRemoteEnvironmentOperation | undefined
try {
pending = await this.#operationStore.load(hostId)
} catch {
await this.#operationStore.remove(hostId)
return
}
if (!pending) {
return false
return
}
if (
pending.targetIdentity !==
remoteHostRecoveryIdentityKey(target)
) {
throw new SshRemotePackageCommitIndeterminateError(
'SSH Host 连接目标已变化,无法确认上一次远程环境提交;请恢复原 Host 连接后重试,或删除此 Host 以明确放弃恢复'
)
await this.#operationStore.remove(hostId)
return
}
emit('auto', 'applying')
const candidate: SshRemotePackageCandidate = {
operationId: pending.operationId,
size: pending.size,
sha256: pending.sha256,
urls: pending.urls
}
const bootstrapLease =
await this.#sshPool.acquireRemotePackageBootstrap(
target,
signal
)
let commandLease: SshConnectionLease | undefined
let recoveryMetadataSftp: StagedSftp | undefined
).catch(() => undefined)
try {
if (!bootstrapLease) {
return
}
assertLeaseMatchesTarget(bootstrapLease, target)
if (pending.version === 1) {
const cleanup = await bootstrapLease.cleanup(
pending.operationId,
{ signal }
)
if (
!cleanup.cleaned &&
cleanup.reason !== 'operation-unavailable'
) {
throw new Error(
`旧版远程环境暂存清理失败:${cleanup.reason}`
)
}
await this.#operationStore.remove(hostId)
return false
}
const status = await bootstrapLease.commitStatus(
candidate,
{ signal }
)
if (
!status.committed &&
status.reason === 'operation-unavailable'
) {
await this.#operationStore.remove(hostId)
return false
}
if (
!status.committed &&
status.reason === 'installer-rollback-incomplete'
) {
throw new SshRemotePackageCommitIndeterminateError(
'上一次远程环境发布失败且回滚结果不完整,请检查 Host 状态'
)
}
commandLease = await this.#sshPool.acquire(
target,
signal
)
assertLeaseMatchesTarget(commandLease, target)
const probe =
await commandLease.runAgentBootstrapProbe(signal)
if (!probe.ready) {
throw new Error(
`远端系统不能恢复 GoodBuddy 环境:${probe.reason}`
)
}
recoveryMetadataSftp =
await commandLease.openStagedSftp(
probe.canonicalHomeDirectory,
{
maximumFileBytes: MAXIMUM_METADATA_BYTES,
maximumTotalBytes:
MAXIMUM_METADATA_BYTES * 24,
maximumOperations: 128
},
signal
)
const recoverySnapshots =
restorePersistedMetadataSnapshots(
pending.metadataSnapshots,
probe.uid
)
if (status.committed) {
try {
await this.#adoptCommittedEnvironment(
commandLease,
status.identity,
'auto',
emit,
signal
)
} catch (error) {
await stopCandidateBestEffort(
commandLease,
status.identity.agent.installationId
)
try {
await restoreRemoteEnvironmentMetadata(
recoveryMetadataSftp,
recoverySnapshots
)
} catch (rollbackError) {
throw new AggregateError(
[error, rollbackError],
'上一次远程环境恢复失败,且原有环境元数据未能完整恢复',
{ cause: rollbackError }
)
}
throw error
}
} else {
await restoreRemoteEnvironmentMetadata(
recoveryMetadataSftp,
recoverySnapshots
)
}
const cleanup = await bootstrapLease.cleanup(
await bootstrapLease.cleanup(
pending.operationId,
{ signal }
)
if (
cleanup.cleaned ||
cleanup.reason === 'operation-unavailable'
) {
await this.#operationStore.remove(hostId)
} else if (!status.committed) {
throw new Error(
`上一次未提交的远程环境暂存清理失败:${cleanup.reason}`
)
}
return status.committed
} catch (error) {
if (
error instanceof
SshRemotePackageCommitIndeterminateError
) {
throw error
}
const detail = error instanceof Error
? error.message
: String(error)
throw new SshRemotePackageCommitIndeterminateError(
`上一次远程环境恢复失败:${detail}`
)
).catch(() => undefined)
} finally {
recoveryMetadataSftp?.close()
commandLease?.release()
bootstrapLease.release()
bootstrapLease?.release()
await this.#operationStore.remove(hostId)
}
}
}
function persistMetadataSnapshots(
snapshots: readonly RemoteEnvironmentMetadataSnapshot[]
): readonly PersistedRemoteEnvironmentMetadataSnapshot[] {
return snapshots.map((snapshot) => ({
path: snapshot.path,
uid: snapshot.uid,
...(snapshot.contents === undefined
? {}
: {
contentsBase64:
snapshot.contents.toString('base64')
})
}))
}
function restorePersistedMetadataSnapshots(
snapshots:
readonly PersistedRemoteEnvironmentMetadataSnapshot[],
uid: number
): readonly RemoteEnvironmentMetadataSnapshot[] {
if (snapshots.some((snapshot) => snapshot.uid !== uid)) {
throw new Error(
'远程环境恢复元数据与当前 SSH 用户不匹配'
)
}
return snapshots.map((snapshot) => ({
path: snapshot.path,
uid: snapshot.uid,
...(snapshot.contentsBase64 === undefined
? {}
: {
contents: Buffer.from(
snapshot.contentsBase64,
'base64'
)
})
}))
}
async function resolvePreparationMethod(
requested: RemoteEnvironmentPreparationMethod,
lease: SshRemotePackageBootstrapLease,
@@ -854,23 +621,6 @@ async function cleanupBestEffort(
}
}
async function stopCandidateBestEffort(
lease: SshConnectionLease | undefined,
installationId: string
): Promise<void> {
if (!lease?.isUsable()) {
return
}
try {
await lease.runAgentLifecycleAction(
verifyAgentInstallationId(installationId),
'stop'
)
} catch {
// Metadata rollback remains the authoritative recovery action.
}
}
async function assertTargetCurrent(
resolver: AgentInstallationTargetResolver,
expected: SshConnectionTarget,
@@ -1,12 +1,7 @@
import {
readFileSync,
readdirSync
} from 'node:fs'
import {
join,
resolve
} from 'node:path'
import { describe, expect, it, vi } from 'vitest'
import type {
RemoteRuntimeBundleManifest
} from '../../shared/remote-runtime-launch-contracts'
import type {
SshConnectionPoolTarget
} from '../ssh/ssh-connection-pool'
@@ -17,24 +12,62 @@ import {
const HOST_ID = 'host-1'
const AGENT_ID = `agent-${'a'.repeat(64)}` as never
const runtimeRoot = resolve(
'.remote-runtime-resources',
'linux-x64',
'opencode'
)
const digestDirectory = readdirSync(runtimeRoot)[0]!
const manifest = JSON.parse(
readFileSync(
join(runtimeRoot, digestDirectory, 'manifest.json'),
'utf8'
)
) as {
runtimeId: string
runtimeVersion: string
architecture: 'x64'
bundleDigest: string
adapterDigest: string
acpCapabilitiesDigest: string
const digestDirectory = 'a'.repeat(64)
const manifest: RemoteRuntimeBundleManifest = {
formatVersion: 2,
product: 'GoodBuddy',
runtimeId: 'opencode',
runtimeVersion: '1.18.9',
provider: 'opencode',
platform: 'linux',
architecture: 'x64',
signingKeyId: 'runtime-test',
bundleDigest: `sha256:${digestDirectory}`,
adapterDigest: `sha256:${'b'.repeat(64)}`,
sourcePackage: {
name: 'opencode-linux-x64-baseline',
integrity:
'sha512-x4KiJk9EF7ktM18Ru5Jue4kTntxMvlhWb7tHniQGGRvY2KeoK1iIkyAFd7ri5H/fSkM22hNv/Gg1Jk6/h9IlxQ=='
},
entrypoint: {
identity: 'opencode-acp',
path: 'bin/opencode',
sha256: 'c'.repeat(64),
argvPrefix: ['acp']
},
files: [
{
path: 'bin/opencode',
size: 100,
sha256: 'c'.repeat(64),
mode: '0755'
},
{
path: 'licenses/opencode.txt',
size: 10,
sha256: 'd'.repeat(64),
mode: '0644'
}
],
licenses: [
{
package: 'opencode',
version: '1.18.9',
spdx: 'MIT',
path: 'licenses/opencode.txt'
}
],
allowedEnvironmentNames: ['HOME', 'LANG'],
protocol: {
major: 2,
minor: 0
},
acpCapabilitiesDigest: `sha256:${'e'.repeat(64)}`,
limits: {
maximumPromptRuntimeMilliseconds: 60_000,
maximumPromptInputBytes: 4096,
maximumPromptOutputBytes: 1024
}
}
const entry = {
runtimeId: manifest.runtimeId,
@@ -19,7 +19,6 @@ import { isMissingPathError } from './path-errors'
import { remoteHostTargetIdentityKey } from './remote-host-target-identity'
const MAXIMUM_METADATA_BYTES = 1024 * 1024
const PRIVATE_FILE_MODE = 0o600
const RUNTIME_REGISTRY_PATH =
'.goodbuddy/runtimes/registry.json'
const OPENCODE_ROOT = '.goodbuddy/runtimes/opencode'
@@ -212,12 +211,6 @@ export class RemoteRuntimeInstallationManager {
},
signal
)
await assertPrivateMetadata(
sftp,
RUNTIME_REGISTRY_PATH,
probe.uid,
signal
)
const registry = parseRuntimeRegistryState(
parseJsonBytes(
await sftp.readFile(
@@ -246,12 +239,6 @@ export class RemoteRuntimeInstallationManager {
`${OPENCODE_ROOT}/${digestDirectoryName(
current.bundleDigest
)}/manifest.json`
await assertPublicMetadata(
sftp,
manifestPath,
probe.uid,
signal
)
const manifest =
remoteRuntimeBundleManifestSchema.parse(
parseJsonBytes(
@@ -319,44 +306,6 @@ export class RemoteRuntimeInstallationManager {
}
async function assertPrivateMetadata(
sftp: StagedSftp,
path: string,
uid: number,
signal: AbortSignal
): Promise<void> {
const metadata = await sftp.lstat(path, signal)
if (
metadata.type !== 'file' ||
metadata.uid !== uid ||
metadata.mode !== PRIVATE_FILE_MODE ||
metadata.size > MAXIMUM_METADATA_BYTES
) {
throw new Error(
`Remote Runtime metadata is invalid: ${path}`
)
}
}
async function assertPublicMetadata(
sftp: StagedSftp,
path: string,
uid: number,
signal: AbortSignal
): Promise<void> {
const metadata = await sftp.lstat(path, signal)
if (
metadata.type !== 'file' ||
metadata.uid !== uid ||
metadata.mode !== 0o644 ||
metadata.size > MAXIMUM_METADATA_BYTES
) {
throw new Error(
`Remote Runtime manifest metadata is invalid: ${path}`
)
}
}
function digestDirectoryName(bundleDigest: string): string {
if (!/^sha256:[a-f0-9]{64}$/u.test(bundleDigest)) {
throw new Error('Runtime bundle digest is invalid')
+4 -21
View File
@@ -458,7 +458,7 @@ describe('RuntimeSettingsStore', () => {
const { store } = await createStore({
GOODBUDDY_MODEL_API_KEY: apiKey,
GOODBUDDY_MODEL_BASE_URL:
'https://gateway.example/openai/v1',
'http://gateway.example/openai/v1?api-version=1',
GOODBUDDY_MODEL_NAME: 'qwen-plus'
})
@@ -467,7 +467,7 @@ describe('RuntimeSettingsStore', () => {
deepseekHarnessModelProfile: {
id: 'goodbuddy-platform-harness',
name: '管理员预置模型',
baseUrl: 'https://gateway.example/openai/v1',
baseUrl: 'http://gateway.example/openai/v1?api-version=1',
modelName: 'qwen-plus',
protocol: 'openai-chat-completions',
authentication: 'api-key',
@@ -486,28 +486,11 @@ describe('RuntimeSettingsStore', () => {
it.each([
[
'an insecure public endpoint',
{
GOODBUDDY_MODEL_API_KEY: 'platform-key',
GOODBUDDY_MODEL_BASE_URL: 'http://gateway.example/v1',
GOODBUDDY_MODEL_NAME: 'qwen-plus'
}
],
[
'an endpoint with embedded credentials',
'an unsupported endpoint protocol',
{
GOODBUDDY_MODEL_API_KEY: 'platform-key',
GOODBUDDY_MODEL_BASE_URL:
'https://user:secret@gateway.example/v1',
GOODBUDDY_MODEL_NAME: 'qwen-plus'
}
],
[
'an endpoint with a query string',
{
GOODBUDDY_MODEL_API_KEY: 'platform-key',
GOODBUDDY_MODEL_BASE_URL:
'https://gateway.example/v1?api-version=1',
'ftp://gateway.example/v1',
GOODBUDDY_MODEL_NAME: 'qwen-plus'
}
],
+1 -1
View File
@@ -2290,7 +2290,7 @@ export class RuntimeSettingsStore {
}
if (!isDeepSeekHarnessModelProfile(profile)) {
throw new Error(
'DeepSeek Harness 仅支持使用 API Key 的安全 OpenAI 兼容 Chat Completions 连接'
'DeepSeek Harness 仅支持使用 API Key 的 OpenAI 兼容 Chat Completions 连接'
)
}
}
+69 -11
View File
@@ -67,7 +67,6 @@ function createConnection(identity: SshPoolConnectionIdentity) {
prepareRemotePackageBootstrap: vi.fn(),
prepareUploadedRemotePackageBootstrap: vi.fn(),
commitRemotePackageBootstrap: vi.fn(),
getRemotePackageBootstrapCommitStatus: vi.fn(),
cleanupRemotePackageBootstrap: vi.fn(),
runAgentLifecycleAction: vi.fn(),
runAgentRuntimeAction: vi.fn(),
@@ -270,10 +269,6 @@ describe("SSH connection pool", () => {
unavailable: false,
reason: "size-mismatch",
});
connection.getRemotePackageBootstrapCommitStatus.mockResolvedValue({
committed: false,
reason: "operation-unavailable",
});
const pool = new SshConnectionPool(async () => connection);
const lease = await pool.acquireRemotePackageBootstrap(createTarget());
const candidate = {
@@ -305,12 +300,6 @@ describe("SSH connection pool", () => {
expect(
connection.prepareUploadedRemotePackageBootstrap,
).toHaveBeenCalledWith(candidate, undefined);
await expect(lease.commitStatus(candidate)).resolves.toMatchObject({
reason: "operation-unavailable",
});
expect(
connection.getRemotePackageBootstrapCommitStatus,
).toHaveBeenCalledWith(candidate, undefined);
expect(lease).not.toHaveProperty("exec");
expect(lease).not.toHaveProperty("sftp");
lease.release();
@@ -699,6 +688,10 @@ describe("authenticated ssh2 connection", () => {
{ createClient: () => client as never },
);
await expect(connection.runAgentBootstrapProbe()).resolves.toMatchObject({
ready: true,
architecture: "arm64",
});
await expect(connection.runAgentBootstrapProbe()).resolves.toMatchObject({
ready: true,
architecture: "arm64",
@@ -713,6 +706,71 @@ describe("authenticated ssh2 connection", () => {
},
expect.any(Function),
);
expect(client.exec).toHaveBeenCalledOnce();
client.emit("close");
await expect(connection.runAgentBootstrapProbe()).rejects.toThrow(
"SSH 连接已关闭",
);
});
it("caches an incompatible bootstrap result on the connection", async () => {
const channel = Object.assign(new EventEmitter(), {
stderr: new EventEmitter(),
destroy: vi.fn(),
});
const output = [
"GOODBUDDY_AGENT_BOOTSTRAP_PROBE_V1",
"home=/home/builder",
"uid=1001",
"os=Linux",
"arch=riscv64",
"shell=/bin/bash",
"procfs=ready",
"",
].join("\n");
const client = Object.assign(new EventEmitter(), {
connect: vi.fn(function connect(this: EventEmitter) {
this.emit("ready");
}),
end: vi.fn(),
destroy: vi.fn(),
exec: vi.fn(
(
_command: string,
_options: unknown,
callback: (error: Error | undefined, stream: typeof channel) => void,
) => {
callback(undefined, channel);
setTimeout(() => {
channel.emit("data", output);
channel.emit("close", 0);
}, 0);
},
),
sftp: vi.fn(),
});
const target = createTarget();
const connection = await Ssh2AuthenticatedConnection.connect(
target,
{
hostId: target.host.id,
hostRevision: target.hostRevision,
hostKeyGeneration: target.hostKeyGeneration,
authenticationIdentity: "a".repeat(64),
},
new AbortController().signal,
{ createClient: () => client as never },
);
await expect(connection.runAgentBootstrapProbe()).resolves.toEqual({
ready: false,
reason: "unsupported-architecture",
});
await expect(connection.runAgentBootstrapProbe()).resolves.toEqual({
ready: false,
reason: "unsupported-architecture",
});
expect(client.exec).toHaveBeenCalledOnce();
});
it("cancels a running bootstrap probe and destroys its channel", async () => {
+11 -26
View File
@@ -99,10 +99,6 @@ export interface AuthenticatedSshConnection {
candidate: SshRemotePackageCandidate,
options?: SshRemotePackageBootstrapOptions,
): Promise<SshRemotePackageBootstrapCommitResult>;
getRemotePackageBootstrapCommitStatus(
candidate: SshRemotePackageCandidate,
options?: SshRemotePackageBootstrapOptions,
): Promise<SshRemotePackageBootstrapCommitResult>;
cleanupRemotePackageBootstrap(
operationId: string,
options?: Pick<SshRemotePackageBootstrapOptions, "signal">,
@@ -134,7 +130,6 @@ export interface SshConnectionLease extends Omit<
| "dispose"
| "createRemotePackageUploadStaging"
| "prepareUploadedRemotePackageBootstrap"
| "getRemotePackageBootstrapCommitStatus"
> {
release(): void;
}
@@ -150,7 +145,6 @@ type InternalSshConnectionLease = SshConnectionLease &
AuthenticatedSshConnection,
| "createRemotePackageUploadStaging"
| "prepareUploadedRemotePackageBootstrap"
| "getRemotePackageBootstrapCommitStatus"
>;
type ClientLike = Pick<
@@ -290,6 +284,7 @@ function waitForSharedConnection(
export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
private usable = true;
private disposed = false;
private agentBootstrapProbe: AgentBootstrapProbeResult | undefined;
private constructor(
readonly identity: SshPoolConnectionIdentity,
@@ -298,6 +293,7 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
) {
const disconnected = (): void => {
this.usable = false;
this.agentBootstrapProbe = undefined;
};
this.client.on("close", disconnected);
this.client.on("end", disconnected);
@@ -423,6 +419,11 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
async runAgentBootstrapProbe(
signal?: AbortSignal,
): Promise<AgentBootstrapProbeResult> {
this.assertUsable();
signal?.throwIfAborted();
if (this.agentBootstrapProbe !== undefined) {
return this.agentBootstrapProbe;
}
const result = await this.runBoundedCommand(
AGENT_BOOTSTRAP_PROBE_COMMAND,
signal,
@@ -430,7 +431,9 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
if (result.exitCode !== 0 || result.stderr.length !== 0) {
throw new Error("Agent 启动探针执行失败");
}
return parseAgentBootstrapProbeOutput(result.stdout);
const probe = parseAgentBootstrapProbeOutput(result.stdout);
this.agentBootstrapProbe = probe;
return probe;
}
probeRemotePackageBootstrap(
@@ -471,13 +474,6 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
return this.remotePackageBootstrap().commit(candidate, options);
}
getRemotePackageBootstrapCommitStatus(
candidate: SshRemotePackageCandidate,
options?: SshRemotePackageBootstrapOptions,
): Promise<SshRemotePackageBootstrapCommitResult> {
return this.remotePackageBootstrap().commitStatus(candidate, options);
}
cleanupRemotePackageBootstrap(
operationId: string,
options?: Pick<SshRemotePackageBootstrapOptions, "signal">,
@@ -587,6 +583,7 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
}
this.disposed = true;
this.usable = false;
this.agentBootstrapProbe = undefined;
this.client.end();
this.client.destroy();
}
@@ -878,11 +875,6 @@ export class SshConnectionPool {
),
commit: (candidate, options) =>
lease.commitRemotePackageBootstrap(candidate, options),
commitStatus: (candidate, options) =>
bootstrapConnection.getRemotePackageBootstrapCommitStatus(
candidate,
options,
),
cleanup: (operationId, options) =>
lease.cleanupRemotePackageBootstrap(operationId, options),
release: () => lease.release(),
@@ -955,13 +947,6 @@ export class SshConnectionPool {
assertActive();
return connection.commitRemotePackageBootstrap(candidate, options);
},
getRemotePackageBootstrapCommitStatus: (candidate, options) => {
assertActive();
return connection.getRemotePackageBootstrapCommitStatus(
candidate,
options,
);
},
cleanupRemotePackageBootstrap: (operationId, options) => {
assertActive();
return connection.cleanupRemotePackageBootstrap(operationId, options);
@@ -230,7 +230,6 @@ describe("fixed SSH remote package bootstrap", () => {
await executor.prepare(candidate);
await executor.prepareUploaded(candidate);
await executor.commit(candidate);
await executor.commitStatus(candidate);
await executor.cleanup(operationId);
const fields = requests.map((request) => request.split("\n"));
@@ -246,7 +245,7 @@ describe("fixed SSH remote package bootstrap", () => {
controlPlaneInstallerSha256,
controlPlaneInstaller.toString("base64"),
]);
for (const index of [4, 5, 6]) {
for (const index of [4, 5]) {
expect(fields[index]?.slice(5, 8)).toEqual(["0", "0".repeat(64), ""]);
}
expect(requests.map((request) => request.split("\n")[1])).toEqual([
@@ -255,7 +254,6 @@ describe("fixed SSH remote package bootstrap", () => {
"prepare",
"prepare-uploaded",
"commit",
"commit-status",
"cleanup",
]);
expect(fields[3]?.slice(8)).toEqual(["0", ""]);
@@ -501,6 +499,12 @@ describe("fixed SSH remote package bootstrap", () => {
expect(uploadedBlock).toContain('[ ! -x "$bootstrap/agent/node" ]');
expect(uploadedBlock).toContain("run_prepare");
expect(uploadedBlock).not.toMatch(/\b(?:curl|sha256sum|unzip)\b/u);
expect(SSH_REMOTE_PACKAGE_BOOTSTRAP_SCRIPT).toContain(
'--archive-sha256-verified true',
);
expect(SSH_REMOTE_PACKAGE_BOOTSTRAP_SCRIPT).toContain(
'actual_sha256=$(sha256sum "$archive"',
);
});
it("rejects empty installer terminal files for prepare and status", () => {
+1 -7
View File
@@ -233,10 +233,6 @@ export interface SshRemotePackageBootstrapExecutor {
candidate: SshRemotePackageCandidate,
options?: SshRemotePackageBootstrapOptions,
): Promise<SshRemotePackageBootstrapCommitResult>;
commitStatus(
candidate: SshRemotePackageCandidate,
options?: SshRemotePackageBootstrapOptions,
): Promise<SshRemotePackageBootstrapCommitResult>;
cleanup(
operationId: string,
options?: Pick<SshRemotePackageBootstrapOptions, "signal">,
@@ -572,6 +568,7 @@ run_prepare() {
"$bootstrap/agent/node" "$bootstrap/package-installer.mjs" \
prepare --operation-root "$operation_root" --archive "$archive" \
--expected-sha256 "$expected_sha256" \
--archive-sha256-verified true \
>"$installer_output" 2>/dev/null || true
installer_output_size=$(wc -c < "$installer_output" 2>/dev/null) ||
stop failed installer-failed
@@ -1611,9 +1608,6 @@ export function createSshRemotePackageBootstrapExecutor(
}
throw new Error("Agent 远程安装提交返回了无效结果");
},
commitStatus(candidate, options = {}) {
return readCommitStatus(candidate, options);
},
async cleanup(operationId, options = {}) {
const verifiedOperationId = validateOperationId(operationId);
const result = await runBootstrapCommand(
+162 -6
View File
@@ -8515,7 +8515,7 @@ describe('App', () => {
)
})
it('shows bounded Subagent states and records child expert activity', async () => {
it('shows Subagent states and records child expert activity', async () => {
render(<App />)
fireEvent.change(await screen.findByLabelText('向 GoodBuddy 提问'), {
target: { value: '分析复杂问题' }
@@ -8568,19 +8568,26 @@ describe('App', () => {
}
})
const statusRegion = await screen.findByLabelText('子专家状态')
const statusRegion = await screen.findByLabelText('子代理状态')
expect(within(statusRegion).getByText('研究专家')).toBeInTheDocument()
expect(within(statusRegion).getByText('等待中')).toBeInTheDocument()
expect(within(statusRegion).getByText('代码专家')).toBeInTheDocument()
expect(within(statusRegion).getByText('进行中')).toBeInTheDocument()
expect(within(statusRegion).getByText('安全专家')).toBeInTheDocument()
expect(within(statusRegion).getByText('失败')).toBeInTheDocument()
const subagentCards = within(statusRegion).getAllByRole('group')
fireEvent.click(
within(subagentCards[2]!).getByText('安全专家', {
selector: 'strong'
})
)
fireEvent(subagentCards[2]!, new Event('toggle'))
expect(
within(statusRegion).getByText('无法读取必要上下文')
).toBeInTheDocument()
expect(
within(statusRegion).queryByText('第四位专家')
).not.toBeInTheDocument()
within(statusRegion).getByText('第四位专家')
).toBeInTheDocument()
act(() => {
agentListener?.({
@@ -8599,9 +8606,20 @@ describe('App', () => {
output: '代码专家的部分结论'
})
})
expect(within(statusRegion).getByText('已完成')).toBeInTheDocument()
expect(within(statusRegion).getAllByText('已完成')).toHaveLength(2)
expect(within(statusRegion).getByText('已取消')).toBeInTheDocument()
expect(within(statusRegion).getByText('父任务已停止')).toBeInTheDocument()
for (const [index, expertName] of [
'研究专家',
'代码专家'
].entries()) {
fireEvent.click(
within(subagentCards[index]!).getByText(expertName, {
selector: 'strong'
})
)
fireEvent(subagentCards[index]!, new Event('toggle'))
}
expect(
within(statusRegion).getByText('研究专家的独立结论')
).toBeInTheDocument()
@@ -8627,7 +8645,7 @@ describe('App', () => {
fireEvent.click(screen.getByText('运行记录'))
expect(await screen.findAllByText('子专家')).toHaveLength(4)
expect(screen.getAllByText(/智能路由/u).length).toBeGreaterThan(0)
expect(screen.getAllByText(/手动指定/u).length).toBeGreaterThan(0)
expect(screen.getAllByText(/指定专家/u).length).toBeGreaterThan(0)
expect(
screen.getByText(/研究专家的独立结论/u)
).toBeInTheDocument()
@@ -8636,6 +8654,144 @@ describe('App', () => {
).toBeInTheDocument()
})
it('replaces an incremental OpenCode Task tool with a native subagent card', async () => {
render(<App />)
fireEvent.change(await screen.findByLabelText('向 GoodBuddy 提问'), {
target: { value: '检查架构' }
})
fireEvent.click(screen.getByLabelText('发送'))
await waitFor(() => expect(run).toHaveBeenCalledOnce())
const request = run.mock.calls[0]?.[0]
if (!request) {
throw new Error('Missing request')
}
act(() => {
agentListener?.({
requestId: request.requestId,
type: 'tool',
callId: 'call-task-1',
name: 'Review application architecture',
state: 'running',
summary: '远端 Runtime 工具:Review application architecture'
})
agentListener?.({
requestId: request.requestId,
type: 'reasoning',
delta: '等待子代理结果'
})
})
expect(await screen.findByText('等待子代理结果')).toBeInTheDocument()
act(() => {
agentListener?.({
requestId: request.requestId,
type: 'subagent',
childTaskId: '00000000-0000-4000-8000-000000000611',
expertId: '00000000-0000-4000-8000-000000000711',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'running',
reason: 'Review application architecture'
})
agentListener?.({
requestId: request.requestId,
type: 'text',
delta: '父 Agent 最终回复'
})
})
const region = await screen.findByLabelText('子代理状态')
expect(within(region).getByText('explorer')).toBeInTheDocument()
expect(within(region).getByText('OpenCode 原生'))
.toBeInTheDocument()
expect(
screen.queryByRole('region', {
name: '工具执行,共 1 项'
})
).not.toBeInTheDocument()
const assistantArticle = screen
.getByText('父 Agent 最终回复')
.closest('article')
const orderedBlocks = [
...assistantArticle!.querySelectorAll('.message-blocks > *')
].map((element) => element.textContent)
expect(orderedBlocks).toEqual([
expect.stringContaining('Review application architecture'),
expect.stringContaining('等待子代理结果'),
expect.stringContaining('父 Agent 最终回复')
])
fireEvent.click(screen.getByText('运行记录'))
expect(await screen.findAllByText('子专家')).toHaveLength(1)
expect(
screen.queryByText(
'远端 Runtime 工具:Review application architecture'
)
).not.toBeInTheDocument()
})
it('fails an unterminated subagent when the parent reports done', async () => {
render(<App />)
fireEvent.change(await screen.findByLabelText('向 GoodBuddy 提问'), {
target: { value: '检查未完成子任务' }
})
fireEvent.click(screen.getByLabelText('发送'))
await waitFor(() => expect(run).toHaveBeenCalledOnce())
const request = run.mock.calls[0]?.[0]
if (!request) {
throw new Error('Missing request')
}
act(() => {
agentListener?.({
requestId: request.requestId,
type: 'subagent',
childTaskId: '00000000-0000-4000-8000-000000000612',
expertId: '00000000-0000-4000-8000-000000000712',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-2',
state: 'running',
reason: '检查未完成路径'
})
agentListener?.({
requestId: request.requestId,
type: 'done'
})
})
const region = await screen.findByLabelText('子代理状态')
expect(within(region).getByText('失败')).toBeInTheDocument()
const subagentCard = within(region).getByRole('group')
fireEvent.click(
within(subagentCard).getByText('explorer', {
selector: 'strong'
})
)
fireEvent(subagentCard, new Event('toggle'))
expect(
within(region).getByText(
'父请求已结束,但子 Agent 未报告完成状态。'
)
).toBeInTheDocument()
await waitFor(() => {
const persistedMessages = vi
.mocked(api.conversations.saveLocal)
.mock.calls.flatMap(([batch]) =>
batch.flatMap((conversation) => conversation.messages)
)
expect(
persistedMessages.some(
(message) =>
message.subagents?.[0]?.state === 'failed' &&
message.subagents[0].error ===
'父请求已结束,但子 Agent 未报告完成状态。'
)
).toBe(true)
})
})
it('offers once, session, permanent, and deny for a tool call', async () => {
render(<App />)
+161 -26
View File
@@ -128,6 +128,7 @@ import {
conversationMessageBlocksSchema,
conversationSubagentActivitySchema,
interactiveWorkModes,
maximumConversationSubagentActivities,
normalizeInteractiveWorkMode,
projectChannelLabels
} from '../../shared/assistant-contracts'
@@ -619,9 +620,57 @@ function upsertMessageToolBlock(
]
}
function upsertMessageSubagentBlock(
blocks: ConversationMessageBlock[] | undefined,
childTaskId: string,
runtimeCallId?: string
): ConversationMessageBlock[] | undefined {
if (!blocks) {
return blocks
}
if (
blocks.some(
(block) =>
block.type === 'subagent' &&
block.childTaskId === childTaskId
)
) {
return blocks
}
const provisionalIndex = runtimeCallId
? blocks.findIndex(
(block) =>
block.type === 'tool' &&
block.tool.callId === runtimeCallId
)
: -1
if (provisionalIndex >= 0) {
return blocks.map((block, index) =>
index === provisionalIndex
? {
id: block.id,
type: 'subagent' as const,
childTaskId
}
: block
)
}
if (blocks.length >= maxMessageBlocks) {
return blocks
}
return [
...blocks,
{
id: crypto.randomUUID(),
type: 'subagent',
childTaskId
}
]
}
function terminalizeMessageToolBlocks(
blocks: ConversationMessageBlock[] | undefined,
state: 'failed' | 'cancelled'
state: 'failed' | 'cancelled' | 'interrupted'
): ConversationMessageBlock[] | undefined {
return blocks?.map((block) =>
block.type === 'tool' &&
@@ -1212,7 +1261,8 @@ function isConversation(value: unknown): value is Conversation {
))) &&
(entry.subagents === undefined ||
(Array.isArray(entry.subagents) &&
entry.subagents.length <= 3 &&
entry.subagents.length <=
maximumConversationSubagentActivities &&
entry.subagents.every(
(subagent) =>
conversationSubagentActivitySchema.safeParse(subagent)
@@ -4183,7 +4233,10 @@ function App(): React.JSX.Element {
conversationId: run.conversationId,
parentTaskId: event.requestId,
expertId: event.expertId,
routingMode: event.routingMode,
routingMode:
event.routingMode === 'native'
? undefined
: event.routingMode,
title: event.expertName,
instructions:
event.reason ??
@@ -4205,8 +4258,23 @@ function App(): React.JSX.Element {
? current.map((task) =>
task.id === event.childTaskId ? childTask : task
)
: [...current, childTask].slice(0, 100)
: [...current, childTask].slice(
0,
maximumConversationSubagentActivities
)
})
if (event.runtimeCallId) {
setActivityRecords((current) =>
current.filter(
(record) =>
!(
record.requestId === event.requestId &&
record.kind === 'tool' &&
record.callId === event.runtimeCallId
)
)
)
}
recordActivity({
conversationId: run.conversationId,
requestId: event.requestId,
@@ -4216,7 +4284,9 @@ function App(): React.JSX.Element {
detail: [
event.routingMode === 'smart'
? tRef.current('chat.subagents.smart')
: tRef.current('chat.subagents.manual'),
: event.routingMode === 'native'
? tRef.current('chat.subagents.native')
: tRef.current('chat.subagents.manual'),
event.reason,
event.error
]
@@ -4239,6 +4309,7 @@ function App(): React.JSX.Element {
expertId: event.expertId,
expertName: event.expertName,
routingMode: event.routingMode,
runtimeCallId: event.runtimeCallId,
state: event.state,
reason: event.reason,
output: event.output,
@@ -4246,10 +4317,27 @@ function App(): React.JSX.Element {
}
if (index >= 0) {
subagents[index] = subagent
} else if (subagents.length < 3) {
} else if (
subagents.length <
maximumConversationSubagentActivities
) {
subagents.push(subagent)
}
return { ...message, subagents }
const runtimeCallId = event.runtimeCallId
return {
...message,
subagents,
tools: runtimeCallId
? message.tools?.filter(
(tool) => tool.callId !== runtimeCallId
)
: message.tools,
blocks: upsertMessageSubagentBlock(
message.blocks,
event.childTaskId,
runtimeCallId
)
}
})
} else if (event.type === 'approval') {
recordActivity({
@@ -4342,6 +4430,12 @@ function App(): React.JSX.Element {
? 'cancelled'
: 'failed'
: 'completed'
const incompleteSubagentError = tRef.current(
'chat.subagents.incomplete'
)
const incompleteActivityDetail = tRef.current(
'chat.status.activityIncomplete'
)
updateRequestActivity(
event.requestId,
terminalStatus,
@@ -4349,25 +4443,27 @@ function App(): React.JSX.Element {
? event.message
: tRef.current('chat.status.taskCompleted')
)
if (event.type === 'error') {
setActivityRecords((current) =>
current.map((record) =>
record.requestId === event.requestId &&
record.kind !== 'request' &&
(record.status === 'pending' ||
record.status === 'running')
? {
...record,
status: terminalStatus,
detail: `${record.detail}\n${event.message}`.slice(
0,
4_000
)
}
: record
)
setActivityRecords((current) =>
current.map((record) =>
record.requestId === event.requestId &&
record.kind !== 'request' &&
(record.status === 'pending' ||
record.status === 'running')
? {
...record,
status:
event.type === 'done'
? 'interrupted'
: terminalStatus,
detail: `${record.detail}\n${
event.type === 'done'
? incompleteActivityDetail
: event.message
}`.slice(0, 4_000)
}
: record
)
}
)
recordActivity({
conversationId: run.conversationId,
requestId: event.requestId,
@@ -4382,6 +4478,25 @@ function App(): React.JSX.Element {
: tRef.current('chat.status.runtimeCompleted'),
status: terminalStatus
})
setAssistantTasks((current) =>
current.map((task) =>
task.parentTaskId === event.requestId &&
(task.status === 'queued' || task.status === 'running')
? {
...task,
status:
event.type === 'done'
? 'failed'
: terminalStatus,
completedAt: new Date().toISOString(),
error:
event.type === 'error'
? event.message
: incompleteSubagentError
}
: task
)
)
updateMessage(run.conversationId, run.messageId, (message) => {
const representedToolError =
event.type === 'error' &&
@@ -4394,7 +4509,7 @@ function App(): React.JSX.Element {
? event.status === 'cancelled'
? ('cancelled' as const)
: ('failed' as const)
: undefined
: ('interrupted' as const)
const fallbackError =
event.type === 'error' &&
!representedToolError &&
@@ -4436,6 +4551,26 @@ function App(): React.JSX.Element {
: tool
)
: message.tools,
subagents: message.subagents?.map((subagent) =>
subagent.state === 'queued' ||
subagent.state === 'running'
? {
...subagent,
state:
event.type === 'error'
? event.status === 'cancelled'
? ('cancelled' as const)
: ('failed' as const)
: ('failed' as const),
...(event.type === 'error' &&
event.status !== 'cancelled'
? { error: event.message.slice(0, 1_000) }
: event.type === 'done'
? { error: incompleteSubagentError }
: {})
}
: subagent
),
blocks: toolTerminalState
? terminalizeMessageToolBlocks(
appendMessageContentBlock(
+88 -4
View File
@@ -246,26 +246,110 @@ describe('ChatTimeline', () => {
/>
)
const region = screen.getByLabelText('子专家状态')
const region = screen.getByLabelText('子代理状态')
const summary = screen.getByText('综合结果').parentElement
const messageBody = region.parentElement
expect(summary?.parentElement).toBe(messageBody)
expect(
Array.from(messageBody?.children ?? []).indexOf(region)
).toBeLessThan(
).toBeGreaterThan(
Array.from(messageBody?.children ?? []).indexOf(summary!)
)
const cards = within(region).getAllByRole('group')
expect(cards).toHaveLength(3)
const experts = ['研究专家', '代码专家', '安全专家']
for (const [index, output] of [
'研究专家的独立结论',
'代码专家的独立结论',
'安全专家的独立结论'
].entries()) {
expect(within(cards[index]!).getByText(output)).toBeInTheDocument()
expect(
within(cards[index]!).queryByText(output)
).not.toBeInTheDocument()
expect(cards[index]).not.toHaveAttribute('open')
fireEvent.click(within(cards[index]!).getByText(/专家$/u))
fireEvent.click(
within(cards[index]!).getByText(experts[index]!, {
selector: 'strong'
})
)
fireEvent(cards[index]!, new Event('toggle'))
expect(cards[index]).toHaveAttribute('open')
expect(within(cards[index]!).getByText(output)).toBeInTheDocument()
}
})
it('labels native OpenCode subagents and shows their task description', () => {
const messages: Message[] = [
{
id: 'assistant-message',
role: 'assistant',
content: '',
createdAt: 1_775_000_000_000,
state: 'streaming',
blocks: [
{
id: '00000000-0000-4000-8000-000000000121',
type: 'reasoning',
content: '先分析桌面目录'
},
{
id: '00000000-0000-4000-8000-000000000122',
type: 'subagent',
childTaskId:
'00000000-0000-4000-8000-000000000111'
},
{
id: '00000000-0000-4000-8000-000000000123',
type: 'text',
content: '父 Agent 最终回复'
}
],
subagents: [
{
childTaskId: '00000000-0000-4000-8000-000000000111',
expertId: '00000000-0000-4000-8000-000000000211',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'running',
reason: 'Review application architecture'
}
]
}
]
render(
<ChatTimeline
artifactById={new Map()}
conversationId="conversation-1"
hiddenMessageCount={0}
isUnusedConversation={false}
locale="zh-CN"
messageStartIndex={0}
messages={messages}
{...callbacks}
retryContent=""
totalMessageCount={messages.length}
/>
)
expect(screen.getByText('子代理')).toBeInTheDocument()
expect(screen.getByText('OpenCode 原生')).toBeInTheDocument()
expect(screen.getByText('任务')).toBeInTheDocument()
expect(screen.getByText('进行中')).toBeInTheDocument()
expect(
screen.getByText('Review application architecture')
).toBeInTheDocument()
const assistantArticle = screen
.getByText('父 Agent 最终回复')
.closest('article')
const orderedBlocks = [
...assistantArticle!.querySelectorAll('.message-blocks > *')
].map((element) => element.textContent)
expect(orderedBlocks).toEqual([
expect.stringContaining('先分析桌面目录'),
expect.stringContaining('Review application architecture'),
expect.stringContaining('父 Agent 最终回复')
])
})
})
+142 -43
View File
@@ -1,14 +1,19 @@
import {
Bot,
CheckCircle2,
ChevronRight,
Clock3,
Download,
FileText,
Library,
ClockFading,
LoaderCircle,
ShieldCheck,
TerminalSquare,
UserRound
UserRound,
XCircle
} from 'lucide-react'
import { memo, useEffect, useRef } from 'react'
import { memo, useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import type {
ApprovalDecision,
@@ -78,19 +83,40 @@ export type ImageViewerItem = {
type MessageBlockRenderItem =
| {
kind: 'block'
block: Exclude<ConversationMessageBlock, { type: 'tool' }>
block: Extract<
ConversationMessageBlock,
{ type: 'text' | 'reasoning' }
>
}
| {
kind: 'tools'
id: string
tools: ToolActivity[]
}
| {
kind: 'subagents'
id: string
childTaskIds: string[]
}
function groupMessageBlocks(
blocks: ConversationMessageBlock[]
): MessageBlockRenderItem[] {
const items: MessageBlockRenderItem[] = []
for (const block of blocks) {
if (block.type === 'subagent') {
const previous = items.at(-1)
if (previous?.kind === 'subagents') {
previous.childTaskIds.push(block.childTaskId)
} else {
items.push({
kind: 'subagents',
id: block.id,
childTaskIds: [block.childTaskId]
})
}
continue
}
if (block.type !== 'tool') {
items.push({ kind: 'block', block })
continue
@@ -219,6 +245,90 @@ function ToolExecutionList({
)
}
const SubagentStatusCard = memo(function SubagentStatusCard({
subagent
}: {
subagent: SubagentActivity
}): React.JSX.Element {
const { t } = useTranslation('app')
const [expanded, setExpanded] = useState(false)
const StateIcon =
subagent.state === 'completed'
? CheckCircle2
: subagent.state === 'running'
? LoaderCircle
: subagent.state === 'queued'
? Clock3
: XCircle
const source =
subagent.routingMode === 'smart'
? t('chat.subagents.smart')
: subagent.routingMode === 'native'
? t('chat.subagents.native')
: t('chat.subagents.manual')
return (
<details
className={`subagent-status-card subagent-status-card--${subagent.state}`}
onToggle={(event) => setExpanded(event.currentTarget.open)}
>
<summary>
<span className="subagent-status-card__identity">
<span className="subagent-status-card__heading">
<span className="subagent-status-card__badge">
<Bot aria-hidden="true" size={13} />
{t('chat.subagents.badge')}
</span>
<strong>{subagent.expertName}</strong>
</span>
{subagent.reason && (
<span className="subagent-status-card__task">
<small>{t('chat.subagents.task')}</small>
<span>{subagent.reason}</span>
</span>
)}
<small className="subagent-status-card__source">
{source}
</small>
</span>
<span
className={`subagent-status-card__status subagent-status-card__status--${subagent.state}`}
>
<StateIcon aria-hidden="true" size={14} />
{t(`chat.subagents.states.${subagent.state}`)}
</span>
<ChevronRight
aria-hidden="true"
className="subagent-status-card__chevron"
size={15}
/>
</summary>
{expanded && (
<div className="subagent-status-card__details">
{subagent.output ? (
<section>
<strong>{t('chat.subagents.output')}</strong>
<div className="markdown-content">
<MarkdownRenderer>{subagent.output}</MarkdownRenderer>
</div>
</section>
) : (
<p>{t('chat.subagents.noOutput')}</p>
)}
{subagent.error &&
(subagent.state === 'failed' ||
subagent.state === 'cancelled') && (
<section className="subagent-status-card__error">
<strong>{t('chat.subagents.error')}</strong>
<p>{subagent.error}</p>
</section>
)}
</div>
)}
</details>
)
})
function SubagentStatusList({
subagents
}: {
@@ -231,44 +341,11 @@ function SubagentStatusList({
aria-label={t('chat.subagents.region')}
className="subagent-status-list"
>
{subagents.slice(0, 3).map((subagent) => (
<details
className={`subagent-status-card subagent-status-card--${subagent.state}`}
{subagents.map((subagent) => (
<SubagentStatusCard
key={subagent.childTaskId}
>
<summary>
<Bot aria-hidden="true" size={15} />
<span className="subagent-status-card__identity">
<strong>{subagent.expertName}</strong>
<small>
{subagent.routingMode === 'smart'
? t('chat.subagents.smart')
: t('chat.subagents.manual')}
</small>
</span>
<span>{t(`chat.subagents.states.${subagent.state}`)}</span>
</summary>
<div className="subagent-status-card__details">
{subagent.output ? (
<section>
<strong>{t('chat.subagents.output')}</strong>
<div className="markdown-content">
<MarkdownRenderer>{subagent.output}</MarkdownRenderer>
</div>
</section>
) : (
<p>{t('chat.subagents.noOutput')}</p>
)}
{(subagent.error || subagent.reason) &&
(subagent.state === 'failed' ||
subagent.state === 'cancelled') && (
<section className="subagent-status-card__error">
<strong>{t('chat.subagents.error')}</strong>
<p>{subagent.error ?? subagent.reason}</p>
</section>
)}
</div>
</details>
subagent={subagent}
/>
))}
</section>
)
@@ -327,6 +404,20 @@ function ChatMessageRowView({
const compressionMarkers =
message.contextCompressions ??
(message.contextCompression ? [message.contextCompression] : [])
const subagentsById = new Map(
(message.subagents ?? []).map((subagent) => [
subagent.childTaskId,
subagent
])
)
const orderedSubagentIds = new Set(
message.blocks
?.filter((block) => block.type === 'subagent')
.map((block) => block.childTaskId)
)
const unorderedSubagents = message.subagents?.filter(
(subagent) => !orderedSubagentIds.has(subagent.childTaskId)
)
const compressionLabel = (
compression: ConversationContextCompressionMarker
): string =>
@@ -468,14 +559,19 @@ function ChatMessageRowView({
})}
</div>
)}
{message.subagents && message.subagents.length > 0 && (
<SubagentStatusList subagents={message.subagents} />
)}
{message.blocks && message.blocks.length > 0 ? (
<div className="message-blocks">
{groupMessageBlocks(message.blocks).map((item) =>
item.kind === 'tools' ? (
<ToolExecutionList key={item.id} tools={item.tools} />
) : item.kind === 'subagents' ? (
<SubagentStatusList
key={item.id}
subagents={item.childTaskIds.flatMap((childTaskId) => {
const subagent = subagentsById.get(childTaskId)
return subagent ? [subagent] : []
})}
/>
) : item.block.type === 'reasoning' ? (
<MessageReasoning
content={item.block.content}
@@ -510,6 +606,9 @@ function ChatMessageRowView({
)}
</>
)}
{unorderedSubagents && unorderedSubagents.length > 0 && (
<SubagentStatusList subagents={unorderedSubagents} />
)}
{message.artifactIds?.map((artifactId) => {
const candidate = artifactById.get(artifactId)
const artifact =
+41
View File
@@ -3,6 +3,7 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import Quill from 'quill'
import { describe, expect, it, vi } from 'vitest'
import type { MagicNoteRichContent } from '../../shared/magic-notes-contracts'
import { MagicNoteEditor } from './MagicNoteEditor'
@@ -45,6 +46,46 @@ describe('MagicNoteEditor', () => {
).toBeInTheDocument()
})
it.each([
['-', 'bullet'],
['*', 'bullet'],
['1.', 'ordered'],
['[ ]', 'unchecked'],
['[x]', 'checked']
])(
'keeps the native Quill %s list shortcut enabled',
async (marker, expectedList) => {
const onChange = vi.fn<(content: MagicNoteRichContent) => void>()
const { container } = render(
<MagicNoteEditor
ariaLabel="笔记正文"
onChange={onChange}
onError={vi.fn()}
/>
)
const editor = container.querySelector<HTMLElement>('.ql-editor')
const quillContainer = container.querySelector<HTMLElement>(
'.magic-note-editor__content'
)
expect(editor).not.toBeNull()
expect(quillContainer).not.toBeNull()
const quill = Quill.find(quillContainer!) as Quill
quill.setText(marker, 'user')
quill.setSelection(marker.length, 0, 'silent')
fireEvent.keyDown(editor!, { key: ' ' })
await waitFor(() => {
const content = onChange.mock.calls.at(-1)?.[0]
expect(
content?.ops.some(
(operation) => operation.attributes?.list === expectedList
)
).toBe(true)
})
}
)
it('intercepts a pasted image before Quill and inserts it once', async () => {
const onChange = vi.fn<(content: MagicNoteRichContent) => void>()
const { container } = render(
@@ -399,6 +399,11 @@ describe('MagicNotesWorkspace', () => {
expect(
screen.getByRole('button', { name: /发布笔记/ })
).toHaveAttribute('aria-pressed', 'true')
const updatedTime = screen
.getByRole('button', { name: /发布笔记/ })
.querySelector('time')
expect(updatedTime).toHaveAttribute('datetime', detail.updatedAt)
expect(updatedTime).toHaveTextContent('更新于')
fireEvent.click(screen.getByRole('tab', { name: '待办' }))
expect(screen.getByText('准备演示')).toBeInTheDocument()
const selectedTodoButton = screen
+15 -6
View File
@@ -1657,12 +1657,21 @@ export function MagicNotesWorkspace({
{note.preview || t('notes.noPreview')}
</span>
<span className="magic-note-list-item__meta">
{t(
note.entryCount === 1
? 'notes.entryCountOne'
: 'notes.entryCountOther',
{ count: note.entryCount }
)}
<span>
{t(
note.entryCount === 1
? 'notes.entryCountOne'
: 'notes.entryCountOther',
{ count: note.entryCount }
)}
</span>
<time dateTime={note.updatedAt}>
{t('notes.updatedAt', {
date: dateFormatter.format(
new Date(note.updatedAt)
)
})}
</time>
</span>
</button>
))
+11 -4
View File
@@ -322,6 +322,8 @@ export const app = {
taskCompleted: 'Task completed',
taskFailed: 'Task failed',
runtimeCompleted: 'Agent Runtime completed its response',
activityIncomplete:
'The parent request ended before this activity reported completion',
answerSubmitted: 'Answer submitted; OpenCode is continuing',
questionSkipped: 'Question skipped'
},
@@ -345,12 +347,17 @@ export const app = {
},
subagents: {
region: 'Subagent status',
smart: 'Smart routing',
manual: 'Selected manually',
badge: 'Subagent',
smart: 'GoodBuddy smart routing',
manual: 'GoodBuddy selected expert',
native: 'Native OpenCode',
fallbackTask: '{{name}} subagent task',
output: 'Expert output',
task: 'Task',
output: 'Subagent output',
error: 'Execution details',
noOutput: 'This expert has no output to display yet.',
noOutput: 'This subagent has no output to display yet.',
incomplete:
'The parent request ended before the subagent reported completion.',
states: {
queued: 'Queued',
running: 'Running',
@@ -82,13 +82,15 @@ export const magicNotes = {
noPreview: 'No entries yet',
entryCountOne: '{{count}} entry',
entryCountOther: '{{count}} entries',
updatedAt: 'Updated {{date}}',
emptySelectionTitle: 'No note selected',
emptySelectionDescription:
'Select a note on the left, or create a note to start writing.',
newEntryLabel: 'New entry content',
composerImmediateHint: 'AI comments after you stop typing for 5 seconds',
composerImmediateHint:
'Type -, 1., [ ], or [x] then Space to start a list; AI comments after 5 seconds of inactivity',
composerRichTextHint:
'Supports rich text and pasting or dropping local images, videos, and attachments',
'Type -, 1., [ ], or [x] then Space to start a list; you can also paste or drop local files',
emptyEntries: 'No entries yet. Write the first entry above.',
editEntryLabel: 'Edit entry content',
entryAt: '{{date}} entry'
@@ -742,7 +742,7 @@ export const settings = {
incompatibleImageProtocol:
'Incompatible (image generation protocol is unsupported)',
incompatibleHarnessProtocol:
'Incompatible (requires Chat Completions, an API key, and a secure endpoint)',
'Incompatible (requires Chat Completions, an API key, and an HTTP/HTTPS endpoint)',
secureStorageWarning:
'Secure system key storage is unavailable. Use an environment variable to avoid storing an API Key in plaintext.'
},
+10 -5
View File
@@ -308,6 +308,7 @@ export const app = {
taskCompleted: '任务执行完成',
taskFailed: '任务执行失败',
runtimeCompleted: 'Agent Runtime 已完成响应',
activityIncomplete: '父请求已结束,但该活动未报告完成状态',
answerSubmitted: '回答已提交,OpenCode 正在继续执行',
questionSkipped: '已跳过问题'
},
@@ -330,13 +331,17 @@ export const app = {
}
},
subagents: {
region: '子专家状态',
smart: '智能路由',
manual: '手动指定',
region: '子代理状态',
badge: '子代理',
smart: 'GoodBuddy 智能路由',
manual: 'GoodBuddy 指定专家',
native: 'OpenCode 原生',
fallbackTask: '{{name}} 子专家任务',
output: '专家输出',
task: '任务',
output: '子代理输出',
error: '执行说明',
noOutput: '该专家暂时没有可显示的输出。',
noOutput: '子代理暂时没有可显示的输出。',
incomplete: '父请求已结束,但子 Agent 未报告完成状态。',
states: {
queued: '等待中',
running: '进行中',
@@ -77,11 +77,14 @@ export const magicNotes = {
noPreview: '还没有记录',
entryCountOne: '{{count}} 条记录',
entryCountOther: '{{count}} 条记录',
updatedAt: '更新于 {{date}}',
emptySelectionTitle: '还没有选择笔记',
emptySelectionDescription: '从左侧选择笔记,或新建一篇笔记开始记录。',
newEntryLabel: '新记录内容',
composerImmediateHint: '停止输入 5 秒后自动评论',
composerRichTextHint: '支持富文本,可粘贴或拖入本地图片、视频和附件',
composerImmediateHint:
'输入 -、1.、[ ] 或 [x] 后按空格可创建列表;停止输入 5 秒后自动评论',
composerRichTextHint:
'输入 -、1.、[ ] 或 [x] 后按空格可创建列表;也可粘贴或拖入本地文件',
emptyEntries: '还没有记录,在上方写下第一条内容。',
editEntryLabel: '编辑记录内容',
entryAt: '{{date}} 的记录'
@@ -681,7 +681,7 @@ export const settings = {
incompatible: '不兼容',
incompatibleImageProtocol: '不兼容(不支持图像生成协议)',
incompatibleHarnessProtocol:
'不兼容(需 Chat Completions、API Key 和安全地址)',
'不兼容(需 Chat Completions、API Key 和 HTTP/HTTPS 地址)',
secureStorageWarning:
'当前系统密钥服务不可用。为了避免明文落盘,请使用环境变量提供 API Key。'
},
+130 -15
View File
@@ -1609,8 +1609,24 @@
}
.magic-note-list-item__meta {
display: flex;
min-width: 0;
align-items: center;
justify-content: space-between;
color: var(--text-muted);
font-size: var(--font-caption);
gap: var(--space-2);
}
.magic-note-list-item__meta > :where(span, time) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.magic-note-list-item__meta time {
flex-shrink: 1;
text-align: right;
}
.magic-notes-stream-pane {
@@ -4891,7 +4907,8 @@ button > svg {
}
.message-blocks .message-reasoning,
.message-blocks .tool-execution-list {
.message-blocks .tool-execution-list,
.message-blocks .subagent-status-list {
margin: 0;
}
@@ -5243,25 +5260,25 @@ button > svg {
.subagent-status-list {
display: grid;
margin-top: var(--space-2);
margin: var(--space-2) 0 var(--space-4);
gap: var(--space-2);
}
.subagent-status-card {
border: 1px solid var(--border-default);
border-radius: var(--radius-control);
background: var(--surface-subtle);
border-radius: var(--radius-card);
background: var(--surface-raised);
color: var(--text-secondary);
overflow: hidden;
}
.subagent-status-card > summary {
display: grid;
align-items: center;
padding: var(--space-2) var(--space-3);
align-items: start;
padding: var(--space-3) var(--space-4);
cursor: pointer;
gap: var(--space-2);
grid-template-columns: auto minmax(0, 1fr) auto;
gap: var(--space-3);
grid-template-columns: minmax(0, 1fr) auto auto;
list-style: none;
}
@@ -5278,38 +5295,130 @@ button > svg {
outline-offset: -2px;
}
.subagent-status-card--queued {
box-shadow: inset 3px 0 0 var(--warning);
}
.subagent-status-card--running {
border-color: var(--accent-selected);
box-shadow: inset 3px 0 0 var(--accent);
}
.subagent-status-card--completed {
box-shadow: inset 3px 0 0 var(--success);
}
.subagent-status-card--failed,
.subagent-status-card--cancelled {
border-color: var(--danger-border);
background: var(--danger-subtle);
box-shadow: inset 3px 0 0 var(--danger);
}
.subagent-status-card__identity {
display: grid;
min-width: 0;
gap: var(--space-2);
}
.subagent-status-card__heading {
display: flex;
min-width: 0;
align-items: center;
flex-wrap: wrap;
gap: var(--space-2);
}
.subagent-status-card__badge {
display: inline-flex;
min-height: 22px;
padding: 2px var(--space-2);
align-items: center;
border: 1px solid var(--accent-selected);
border-radius: var(--radius-control);
background: var(--accent-subtle);
color: var(--accent);
font-size: var(--font-caption);
font-weight: 700;
gap: var(--space-1);
}
.subagent-status-card summary strong,
.subagent-status-card summary > span:last-child {
.subagent-status-card__heading > strong {
color: var(--text-primary);
font-size: var(--font-body);
font-size: var(--font-section-title);
overflow-wrap: anywhere;
}
.subagent-status-card summary small {
.subagent-status-card__task {
display: grid;
min-width: 0;
gap: var(--space-1);
}
.subagent-status-card__task > small,
.subagent-status-card__source {
color: var(--text-muted);
font-size: var(--font-caption);
}
.subagent-status-card__task > span {
color: var(--text-primary);
font-size: var(--font-body);
line-height: 1.5;
overflow-wrap: anywhere;
}
.subagent-status-card__status {
display: inline-flex;
min-height: 24px;
padding: 2px var(--space-2);
align-items: center;
border-radius: var(--radius-control);
font-size: var(--font-caption);
font-weight: 700;
gap: var(--space-1);
white-space: nowrap;
}
.subagent-status-card__status--queued {
background: var(--warning-subtle);
color: var(--warning);
}
.subagent-status-card__status--running {
background: var(--accent-subtle);
color: var(--accent);
}
.subagent-status-card__status--completed {
background: var(--success-subtle);
color: var(--success);
}
.subagent-status-card__status--failed,
.subagent-status-card__status--cancelled {
background: var(--danger-subtle);
color: var(--danger);
}
.subagent-status-card__status--running > svg {
animation: subagent-status-spin 900ms linear infinite;
}
.subagent-status-card__chevron {
margin-top: var(--space-1);
color: var(--text-muted);
transition: transform var(--motion-fast) ease-out;
}
.subagent-status-card[open] .subagent-status-card__chevron {
transform: rotate(90deg);
}
.subagent-status-card__details {
display: grid;
padding: var(--space-3);
padding: var(--space-3) var(--space-4) var(--space-4);
border-top: 1px solid var(--border-subtle);
background: var(--surface-raised);
background: var(--surface-subtle);
gap: var(--space-3);
}
@@ -5333,6 +5442,12 @@ button > svg {
color: var(--danger);
}
@keyframes subagent-status-spin {
to {
transform: rotate(360deg);
}
}
.approval-card {
display: grid;
align-items: center;
+85
View File
@@ -6,6 +6,7 @@ import {
conversationBranchInputSchema,
conversationSnapshotSchema,
isUntouchedBuiltInDefaultProject,
localConversationSaveBatchSchema,
persistedProjectExecutionSpaceSchema,
projectCreateSchema,
projectExecutionSpaceSchema,
@@ -203,3 +204,87 @@ describe('conversation branch contracts', () => {
).toBe(true)
})
})
describe('conversation persistence contracts', () => {
it('preserves complete tool details without persistence length limits', () => {
const input = 'input'.repeat(10_000)
const output = 'output'.repeat(20_000)
const error = 'error'.repeat(10_000)
const batch = [
{
header: {
id: '00000000-0000-4000-8000-000000000301',
title: '远程工具会话',
updatedAt: 1
},
messages: [
{
id: '00000000-0000-4000-8000-000000000302',
role: 'assistant',
content: '',
createdAt: 1,
state: 'complete',
tools: [
{
callId: 'remote-tool-call',
name: '远程工具',
state: 'completed',
summary: '完整远程工具结果',
input,
output,
error
}
]
}
]
}
]
expect(localConversationSaveBatchSchema.parse(batch)).toEqual(batch)
})
it('accepts persisted native OpenCode subagent activity', () => {
const batch = [
{
header: {
id: '00000000-0000-4000-8000-000000000311',
title: 'OpenCode 子 Agent',
updatedAt: 1
},
messages: [
{
id: '00000000-0000-4000-8000-000000000312',
role: 'assistant',
content: '',
createdAt: 1,
state: 'complete',
blocks: [
{
id: '00000000-0000-4000-8000-000000000315',
type: 'subagent',
childTaskId:
'00000000-0000-4000-8000-000000000313'
}
],
subagents: [
{
childTaskId:
'00000000-0000-4000-8000-000000000313',
expertId:
'00000000-0000-4000-8000-000000000314',
expertName: 'explorer',
routingMode: 'native',
runtimeCallId: 'call-task-1',
state: 'completed',
reason: 'Review application architecture',
output: 'Architecture review complete.'
}
]
}
]
}
]
expect(localConversationSaveBatchSchema.parse(batch)).toEqual(batch)
})
})
+23 -9
View File
@@ -133,8 +133,8 @@ export type ConversationQueueItem = z.infer<
export const conversationToolActivitySchema = z
.object({
callId: z.string().max(256).optional(),
name: z.string().max(200),
callId: z.string().optional(),
name: z.string(),
state: z.enum([
'pending',
'running',
@@ -144,10 +144,10 @@ export const conversationToolActivitySchema = z
'cancelled',
'interrupted'
]),
summary: z.string().max(2_000),
input: z.string().max(4_000).optional(),
output: z.string().max(16_000).optional(),
error: z.string().max(2_000).optional()
summary: z.string(),
input: z.string().optional(),
output: z.string().optional(),
error: z.string().optional()
})
.strict()
@@ -172,6 +172,13 @@ export const conversationMessageBlockSchema = z.discriminatedUnion('type', [
type: z.literal('tool'),
tool: conversationToolActivitySchema
})
.strict(),
z
.object({
id: assistantIdSchema,
type: z.literal('subagent'),
childTaskId: assistantIdSchema
})
.strict()
])
@@ -186,12 +193,16 @@ export type ConversationMessageBlock = z.infer<
typeof conversationMessageBlockSchema
>
export const maximumConversationToolActivities = 100
export const maximumConversationSubagentActivities = 100
export const conversationSubagentActivitySchema = z
.object({
childTaskId: assistantIdSchema,
expertId: assistantIdSchema,
expertName: z.string().trim().min(1).max(80),
routingMode: z.enum(['manual', 'smart']),
routingMode: z.enum(['manual', 'smart', 'native']),
runtimeCallId: z.string().trim().min(1).max(256).optional(),
state: z.enum([
'queued',
'running',
@@ -240,10 +251,13 @@ export const conversationMessageSchema = z
.array(conversationContextCompressionMarkerSchema)
.max(2)
.optional(),
tools: z.array(conversationToolActivitySchema).max(100).optional(),
tools: z
.array(conversationToolActivitySchema)
.max(maximumConversationToolActivities)
.optional(),
subagents: z
.array(conversationSubagentActivitySchema)
.max(3)
.max(maximumConversationSubagentActivities)
.optional(),
sources: z.array(z.string().max(8_192)).max(100).optional(),
sourceReferences: z
+6 -18
View File
@@ -21,6 +21,7 @@ import {
conversationAttachmentSchema,
conversationHistoryMessageSchema,
conversationContextCompressionStateSchema,
conversationSubagentActivitySchema,
legacyWorkModeSchema,
maximumConversationHistoryCharacters,
maximumConversationHistoryMessages,
@@ -830,7 +831,7 @@ export const runtimeSettingsInputSchema = z
code: 'custom',
path: ['deepseekHarnessModelSource'],
message:
'DeepSeek Harness 仅支持使用 API Key 的安全 OpenAI 兼容 Chat Completions 连接'
'DeepSeek Harness 仅支持使用 API Key 的 OpenAI 兼容 Chat Completions 连接'
})
}
const compressionSource = settings.contextCompression?.modelSource
@@ -1171,24 +1172,11 @@ export const approvalDecisionSchema = z.enum([
export type ApprovalDecision = z.infer<typeof approvalDecisionSchema>
export const subagentEventSchema = z
.object({
export const subagentEventSchema =
conversationSubagentActivitySchema
.extend({
requestId: z.string().uuid(),
type: z.literal('subagent'),
childTaskId: z.string().uuid(),
expertId: z.string().uuid(),
expertName: z.string().trim().min(1).max(80),
routingMode: z.enum(['manual', 'smart']),
state: z.enum([
'queued',
'running',
'completed',
'failed',
'cancelled'
]),
reason: z.string().trim().min(1).max(240).optional(),
output: z.string().optional(),
error: z.string().trim().min(1).max(1_000).optional()
type: z.literal('subagent')
})
.strict()
@@ -9,9 +9,14 @@ describe('DeepSeek Harness model compatibility', () => {
'https://api.deepseek.com',
'https://gateway.example/openai/v1',
'https://gateway.example:8443/v1',
'http://gateway.example/v1',
'http://192.168.1.50:11434/v1',
'http://127.0.0.1:11434/v1',
'http://localhost:1234/v1',
'http://[::1]:8080/v1'
'http://[::1]:8080/v1',
'https://gateway.example/v1?api-version=2025-01-01',
'https://gateway.example/v1#chat',
'http://user:password@gateway.example/v1'
])('accepts OpenAI-compatible base URL %s', (baseUrl) => {
expect(isDeepSeekHarnessCompatibleBaseUrl(baseUrl)).toBe(true)
expect(
@@ -24,12 +29,10 @@ describe('DeepSeek Harness model compatibility', () => {
})
it.each([
'http://gateway.example/v1',
'file:///private/config',
'https://user:secret@gateway.example/v1',
'https://gateway.example/v1?api-version=2025-01-01',
'https://gateway.example/v1#chat'
])('rejects unsafe or unsupported base URL %s', (baseUrl) => {
'ftp://gateway.example/v1',
'not-a-url'
])('rejects unsupported base URL %s', (baseUrl) => {
expect(isDeepSeekHarnessCompatibleBaseUrl(baseUrl)).toBe(false)
})
+2 -23
View File
@@ -4,35 +4,14 @@ type DeepSeekHarnessModelProfile = {
authentication: string
}
function isLoopbackHostname(hostname: string): boolean {
const normalized = hostname
.toLowerCase()
.replace(/^\[|\]$/gu, '')
return (
normalized === 'localhost' ||
normalized === '127.0.0.1' ||
normalized === '::1'
)
}
export function isDeepSeekHarnessCompatibleBaseUrl(
value: string
): boolean {
try {
const url = new URL(value)
if (
!url.hostname ||
url.username ||
url.password ||
url.search ||
url.hash
) {
return false
}
return (
url.protocol === 'https:' ||
(url.protocol === 'http:' &&
isLoopbackHostname(url.hostname))
Boolean(url.hostname) &&
(url.protocol === 'http:' || url.protocol === 'https:')
)
} catch {
return false
+94 -133
View File
@@ -26,7 +26,7 @@ import {
type AgentReleaseKeyRegistry
} from '../agent-installation-contracts'
import {
assertDetachedRemoteRuntimeBundleDigest,
digestRemoteRuntimeBundleIdentity,
digestRemoteRuntimeBundleManifest,
remoteRuntimeBundleManifestSchema,
remoteRuntimeLockSchema,
@@ -75,6 +75,68 @@ export type LoadRegisteredRuntimeBundleOptions =
export async function verifyRuntimeBundle(
bundleDirectoryInput: string,
options: VerifyRuntimeBundleOptions
): Promise<VerifiedRuntimeBundle> {
const verified = await verifyPublishedRuntimeBundle(
bundleDirectoryInput,
options
)
const { bundleDirectory, manifest } = verified
const inventory = await inventoryBundleFiles(
bundleDirectory,
options.uid
)
const declaredPaths = new Set(
manifest.files.map((file) => file.path)
)
for (const file of manifest.files) {
const filePath = join(
bundleDirectory,
...file.path.split('/')
)
const stat = inventory.get(file.path)
if (stat === undefined) {
throw new Error(`Runtime payload is missing: ${file.path}`)
}
if (stat.size !== file.size) {
throw new Error(`Runtime payload size mismatch: ${file.path}`)
}
if ((await sha256File(filePath)) !== file.sha256) {
throw new Error(`Runtime payload hash mismatch: ${file.path}`)
}
if (
shouldEnforceMode(options) &&
modeString(stat.mode) !== file.mode
) {
throw new Error(`Runtime payload mode mismatch: ${file.path}`)
}
}
const actualPaths = new Set(inventory.keys())
const expectedPaths = new Set([
...declaredPaths,
MANIFEST_FILE_NAME,
SIGNATURE_FILE_NAME
])
if (
actualPaths.size !== expectedPaths.size ||
[...actualPaths].some((path) => !expectedPaths.has(path))
) {
throw new Error(
'Runtime bundle contains undeclared or missing files'
)
}
return verified
}
/**
* Authenticates a package-installer-published Runtime from signed metadata and
* bounded entrypoint metadata. The installer already hashed every payload
* file while extracting it.
*/
export async function verifyPublishedRuntimeBundle(
bundleDirectoryInput: string,
options: VerifyRuntimeBundleOptions
): Promise<VerifiedRuntimeBundle> {
const bundleDirectory = assertAbsoluteManagedPath(
resolve(bundleDirectoryInput)
@@ -125,55 +187,35 @@ export async function verifyRuntimeBundle(
)
}
const inventory = await inventoryBundleFiles(
bundleDirectory,
options.uid
const executableRecord = manifest.files.find(
(file) => file.path === manifest.entrypoint.path
)
const declaredPaths = new Set(
manifest.files.map((file) => file.path)
)
for (const file of manifest.files) {
const filePath = join(
bundleDirectory,
...file.path.split('/')
)
const stat = inventory.get(file.path)
if (stat === undefined) {
throw new Error(`Runtime payload is missing: ${file.path}`)
}
if (stat.size !== file.size) {
throw new Error(`Runtime payload size mismatch: ${file.path}`)
}
if ((await sha256File(filePath)) !== file.sha256) {
throw new Error(`Runtime payload hash mismatch: ${file.path}`)
}
if (
shouldEnforceMode(options) &&
modeString(stat.mode) !== file.mode
) {
throw new Error(`Runtime payload mode mismatch: ${file.path}`)
}
}
const actualPaths = new Set(inventory.keys())
const expectedPaths = new Set([
...declaredPaths,
MANIFEST_FILE_NAME,
SIGNATURE_FILE_NAME
])
if (
actualPaths.size !== expectedPaths.size ||
[...actualPaths].some((path) => !expectedPaths.has(path))
) {
if (executableRecord === undefined) {
throw new Error(
'Runtime bundle contains undeclared or missing files'
'Published Runtime entrypoint is not declared'
)
}
const executablePath = join(
bundleDirectory,
...manifest.entrypoint.path.split('/')
)
const executableStat = await lstat(executablePath)
assertOwnedRegularFile(
executableStat,
'Runtime executable',
options.uid
)
if (
executableStat.size !== executableRecord.size ||
(
shouldEnforceMode(options) &&
modeString(executableStat.mode) !== executableRecord.mode
)
) {
throw new Error(
'Published Runtime entrypoint metadata changed'
)
}
await assertElfArchitecture(
executablePath,
options.architecture,
@@ -197,57 +239,14 @@ export async function loadRegisteredRuntimeBundle(
bundleDirectoryInput: string,
options: LoadRegisteredRuntimeBundleOptions
): Promise<VerifiedRuntimeBundle> {
const bundleDirectory = assertAbsoluteManagedPath(
resolve(bundleDirectoryInput)
)
const registered = runtimeRegistryEntrySchema.parse(
options.registered
)
const rootStat = await lstat(bundleDirectory)
assertOwnedDirectory(
rootStat,
'Runtime bundle directory',
options.uid
)
if (
shouldEnforceMode(options) &&
modeString(rootStat.mode) !== '0700'
) {
throw new Error(
'Runtime bundle directory permissions must be 0700'
)
}
if (
basename(bundleDirectory) !==
registered.bundleDigest.slice('sha256:'.length)
) {
throw new Error(
'Registered Runtime digest does not match its managed directory'
)
}
const manifestBytes = await readMetadataFile(
join(bundleDirectory, MANIFEST_FILE_NAME),
'Runtime manifest',
const verified = await verifyPublishedRuntimeBundle(
bundleDirectoryInput,
options
)
const signatureBytes = await readSignature(
join(bundleDirectory, SIGNATURE_FILE_NAME),
options
)
const manifest = await verifyRuntimeManifestSignature(
manifestBytes,
signatureBytes,
options.releaseKeyRegistry,
options.verificationEnvironment ?? 'production'
)
assertRuntimeManifestMatchesLock(
manifest,
remoteRuntimeLockSchema.parse(options.runtimeLock),
options.architecture
)
const manifestDigest =
await digestRemoteRuntimeBundleManifest(manifest)
const { manifest, manifestDigest } = verified
if (
manifest.runtimeId !== registered.runtimeId ||
manifest.runtimeVersion !== registered.runtimeVersion ||
@@ -266,41 +265,7 @@ export async function loadRegisteredRuntimeBundle(
)
}
const executableRecord = manifest.files.find(
(file) => file.path === manifest.entrypoint.path
)
if (executableRecord === undefined) {
throw new Error(
'Registered Runtime entrypoint is not declared'
)
}
const executablePath = join(
bundleDirectory,
...manifest.entrypoint.path.split('/')
)
const executableStat = await lstat(executablePath)
assertOwnedRegularFile(
executableStat,
'Runtime executable',
options.uid
)
if (
executableStat.size !== executableRecord.size ||
(
shouldEnforceMode(options) &&
modeString(executableStat.mode) !== executableRecord.mode
)
) {
throw new Error(
'Registered Runtime entrypoint metadata changed'
)
}
return {
bundleDirectory,
executablePath,
manifest,
manifestDigest
}
return verified
}
export function canonicalRuntimeManifestBytes(
@@ -362,16 +327,12 @@ export async function verifyRuntimeManifestSignature(
) {
throw new Error('Runtime manifest signature verification failed')
}
await assertDetachedRemoteRuntimeBundleDigest({
manifest,
detachedSignature: {
manifestDigest:
await digestRemoteRuntimeBundleManifest(manifest),
algorithm: 'ed25519',
keyId: manifest.signingKeyId,
signatureBase64: signatureBytes.toString('base64')
}
})
if (
await digestRemoteRuntimeBundleIdentity(manifest) !==
manifest.bundleDigest
) {
throw new Error('Runtime bundle identity digest does not match')
}
return manifest
}
+3
View File
@@ -15,6 +15,9 @@ import {
modelBridgePolicySchema
} from './model-bridge-contracts'
export const UNBOUNDED_REMOTE_PROMPT_DEADLINE =
'9999-12-31T23:59:59.999Z'
export const runtimeSessionBindingStateSchema = z.enum([
'opening',
'ready',