powercontext 0.2.0: PowerContext recall and opt-in capture as a gateway hook (#117)
PowerContext as a gateway hook package (@magpie-community/gateway-powercontext 0.2.0): recall from a user-deployed PowerContext service before a request, and opt-in capture of completed conversations, with a connection page that uses only the options/theme bridge. By @Tsukikage7. Reviewed at c61036e9 (author) plus bff430f9 (maintainer merge of main: README, registry.json and scripts/check.mjs conflicts, both sides kept; check.mjs takes main's identical hooks skip). All four points of the 10-25 review are fixed: the timing tests give the healthy side 1000 ms and move the backoff with a stubbed Date.now(); the empty page panels are gone; Scope ID is optional on the page as in the hook; both READMEs describe the npm install and the registry lists it. Run on mote (macOS, Bun 1.4.2, temp HOME) at bff430f9: - bun scripts/check.mjs: exit 0. Full bun test: 3423 pass, 8 skip, 0 fail. - packages/powercontext: 107 pass, 5 runs in a row, then 8 runs in parallel, 0 fail each. - Broken by hand: putting the Scope-required check back in page/settings.js turns the optional-Scope page test red; making the recall backoff expire at once (powercontext.hooks.mjs:336) turns 4 tests red (hung scope/prepare/body and connection-failure backoff). - Earlier round (10-25): the real package in magpie's Bun host behind the gateway handler, against fake PowerContext and upstream. Not tried: the page in a browser at this head (the author reports 40 Chromium/WebKit cases), a real PowerContext server.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
[OpenCode](https://opencode.ai) provider plugins for coding-plan
|
||||
subscriptions, and [gateway middleware](#gateway-middleware),
|
||||
[routing strategies](#routing-strategies), [tools for every
|
||||
[gateway hooks](#gateway-hooks), [routing strategies](#routing-strategies), [tools for every
|
||||
agent](#tools-for-every-agent), [pages](#pages) and [agents](#agents) for
|
||||
magpie, maintained by the community. To make one, see
|
||||
[Write your own](#write-your-own). Each package signs in to one
|
||||
@@ -115,6 +115,7 @@ These add a page to magpie's window, in the app and in `magpie web`, under Plugi
|
||||
| Package | Page | Reads |
|
||||
|---|---|---|
|
||||
| [usage](packages/usage) | Usage glance: calls, errors, tokens and cost for today, 7 or 30 days, and the models behind them | `usage:summary` |
|
||||
| [powercontext](packages/powercontext) | Connection settings for an independently deployed PowerContext service | None |
|
||||
| [agent-office](packages/agent-office) | What are my agents doing: live sessions as workers in a voxel office (3D/2D) or a list, with status, current step and resume commands | no `magpie.read`; its host part reads the local session files of Claude Code, Codex, dsh, Gemini CLI, Qwen Code, Pi, omp, Qoder, WorkBuddy and CodeBuddy, including prompts, replies and tool commands (`text:false` keeps statuses and tool names only) |
|
||||
| [chat](packages/chat) | Chat with magpie's models, your MCP servers, instructions and skills, by Magic_zero ([Magiczerowxy](https://github.com/Magiczerowxy)). Has a host part: a local service the page goes to | none (its service calls magpie's gateway) |
|
||||
|
||||
@@ -129,6 +130,41 @@ A page package is a folder under `packages/<name>/` with:
|
||||
- a test that the page's scripts read only what `permissions` declares and reach no network, and of what it draws from a read.
|
||||
- optionally a host part: `main` with the OpenCode v1 form `export default {id, server}`, where `server(input, options)` starts a service on 127.0.0.1 that the page navigates its frame to. Such a service guards every route with a token only its own page gets, and checks `Host` ([chat](packages/chat) is the example).
|
||||
|
||||
## Gateway hooks
|
||||
|
||||
Like middleware, these run on the requests agents send, but in magpie's Bun host rather than on moejs, so one can wait on a service, keep state and import Node's built-ins. They require Magpie 0.1.1273 or newer and declare `magpie.hooks`.
|
||||
|
||||
| Package | What it does |
|
||||
|---|---|
|
||||
| [powercontext](packages/powercontext) | [PowerContext](https://github.com/oceanbase/powercontext) recall and opt-in completed-conversation capture; no client MCP or skill required |
|
||||
|
||||
Use the same plugin management commands as middleware:
|
||||
|
||||
```sh
|
||||
magpie plugin add @magpie-community/gateway-powercontext
|
||||
```
|
||||
|
||||
Installed plugins use **Plugins › Installed › Options** and the normal on/off
|
||||
switch. Deploy PowerContext yourself using its
|
||||
[official installation walkthrough](https://powercontext.oceanbase.io/en/docs/get-started/quickstart/),
|
||||
then configure the Server URL and service key in the plugin's connection page
|
||||
or Options. The Scope ID is optional: without one, the service resolves the
|
||||
session/workspace binding or its default Scope. Use Magpie **0.1.1531 or newer**
|
||||
for page saves to reach hooks on the next request; earlier hook-capable versions
|
||||
need a Magpie restart after saving page options.
|
||||
No Server URL is assumed and capture defaults to off;
|
||||
remote/shared-key recall and capture each need a separate opt-in. The package calls an existing
|
||||
Server; it does not provision services or manage processes. See the
|
||||
[plugin README](packages/powercontext).
|
||||
The asynchronous hook API shipped in Magpie 0.1.1273; see the
|
||||
[released host contract](https://github.com/yetone/magpie/blob/v0.1.1273/docs/subsystems/gateway-request-hooks.md).
|
||||
|
||||
A gateway hook package is a folder under `packages/<name>/` with:
|
||||
|
||||
- **`package.json`**: name `@magpie-community/gateway-<name>`, `"magpie": {"hooks": "./<name>.hooks.mjs", "options": {…}}`, no `main`.
|
||||
- **`<name>.hooks.mjs`**: exports async `onRequest(body, ctx)` to add context. Optional `onResponse(reply, ctx)` observes a completed reply through a bounded, best-effort notification. The hooks share request-local `ctx.state`. Client tool declarations and execution loops remain client-owned.
|
||||
- tests that call the hooks the way the gateway does, with any service they talk to faked.
|
||||
|
||||
## Agents
|
||||
|
||||
These add an agent magpie has no setup of its own for. Once added, the agent is
|
||||
|
||||
Reference in New Issue
Block a user