Skip to content

feat: storagePath config for custom session-state storage location (#379) - #380

Merged
ranxianglei merged 4 commits into
masterfrom
2026-09-09_custom-storage-path
Sep 9, 2026
Merged

feat: storagePath config for custom session-state storage location (#379)#380
ranxianglei merged 4 commits into
masterfrom
2026-09-09_custom-storage-path

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Fixes #379 — 支持压缩内容自定义存储位置 (support custom storage location for compressed content).

Adds a new optional top-level config option storagePath that relocates where ACP persists per-session state files ({sessionId}.json). The location was previously hardcoded to $XDG_DATA_HOME/opencode/storage/plugin/acp.

Path semantics

Value Resolution
unset / empty default $XDG_DATA_HOME/opencode/storage/plugin/acp (unchanged)
/abs/path as-is
~ / ~/x expanded against the home directory
rel/path resolved against the project directory (opencode cwd)

The resolved directory is computed once per session in ensureSessionInitialized and carried on SessionState.storageDir — a transient field that is never written to the persisted JSON (covered by a dedicated test).

Migration policy

No auto-migration (by design — moving user data silently is worse than warning). If storagePath is set, no valid state is found there, but a state file exists at the default location, ACP logs a one-time WARN per session telling the user to move the file manually. Switching storagePath from one custom location to another is a documented follow-up.

Changes

  • lib/config.tsPluginConfig.storagePath?: string + mergeLayer merge (3-layer override works)
  • lib/config-validation.tsVALID_CONFIG_KEYS + string type check
  • dcp.schema.jsonstoragePath property (schema is additionalProperties: false)
  • lib/state/persistence.tsgetDefaultStorageDir() / resolveStorageDir() (exported); storageDir? threaded through path/save/load/stats helpers; saveSessionState reads sessionState.storageDir
  • lib/state/types.ts — transient SessionState.storageDir
  • lib/state/state.tscreateSessionState / resetSessionState / ensureSessionInitialized (resolve + migration WARN) / registry projectDir constructor arg
  • index.tsnew SessionStateRegistry(logger, ctx.directory)
  • tests/storage-path.test.ts — 19 new tests (1131 total, all passing)
  • CONFIGURATION.md / CONFIGURATION.zh-CN.md — parameter entry + recipe
  • devlog/2026-09-09_custom-storage-path/ — REQ / DESIGN / WORKLOG

Verification

  • npm run typecheck ✓, npm run build ✓, npm run test → 1131/1131 ✓
  • ./scripts/ci/check-pr.sh → all checks passed (version unchanged)
  • Regression detection verified via mutation testing (dropping the merge line / always-default resolution / ignoring storageDir in save-load each fail multiple new tests)
  • Dual-agent code review (2 independent agents): both APPROVE
  • Dual-agent test review (2 independent agents): round-1 findings addressed, round-2 APPROVE

Compatibility

  • No persisted-format change; no internal dcp naming change
  • Default location byte-for-byte unchanged when the option is unset
  • All API changes additive/optional

Follow-ups (tracked in devlog WORKLOG §7)

  • WARN when switching between two custom locations
  • Startup validation of storagePath (writability)
  • ACP_STORAGE_DIR env var override (deferred — config option is the supported path)

ework-agent added 4 commits September 9, 2026 19:47
)

Add top-level storagePath option to relocate the per-session state
directory. Absolute paths used as-is, ~/... expanded against home,
relative paths resolved against the project directory. Resolved once
per session (transient SessionState.storageDir, never persisted).
WARN instead of auto-migration when the custom location is empty but
the default location holds the session file. Default behavior
unchanged when unset.
…cwd-fallback, non-persistence)

- Add getConfig layering test (global + project override + unset)
- Add validateConfigTypes non-string rejection test
- Add custom-location resume happy path (no spurious WARN)
- Add process.cwd() fallback test (projectDir omitted)
- Assert transient storageDir never appears in persisted JSON
- Move default-loc regression cleanup into finally
- Remove dead ensureStorageDir helper (pre-existing, touched by PR)
…tate, WARN wording)

- Add SessionStateRegistry.getOrCreate projectDir wiring test (relative
  storagePath must resolve against the registry's projectDir, not cwd)
- Add resetSessionState clears transient storageDir test
- Cover storagePath: undefined in validateConfigTypes test
- WARN wording: 'no state' -> 'no valid state' (corrupt-file edge)
- Update devlog WORKLOG (19 tests, 1131 total, dual-agent review status,
  deferred follow-ups)
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

📦 Built Plugin Artifact

Branch: 2026-09-09_custom-storage-path (90c2a1e)

Option A — Install from npm PR tag (recommended)

opencode plugin opencode-acp@pr-380 --global

Each push to this PR publishes a new version under the pr-380 npm tag.

Option B — Install from GitHub

opencode plugin "github:ranxianglei/opencode-acp#2026-09-09_custom-storage-path" --global

Option C — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf opencode-acp-pr380.tgz
cp -r package/dist ~/.cache/opencode/packages/opencode-acp@latest/node_modules/opencode-acp/dist
  1. Restart opencode to pick up changes.

This comment is automatically updated on each push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

支持压缩内容自定义存储位置

1 participant