1ccacad63281094de8a3372d5a507d38f9969e5c
6
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
a982f34130 |
plugins: async gateway hooks get the request's kind, subagent or not (ahwulv on X, #4655)
GatewayContext had no subagent marker, so OpenViking could not skip memory recall for Claude Code's subagents. It now carries kind: "subagent" when the client says so on that request, "" otherwise (main conversation, or a client that doesn't say). hookKind (internal/gateway/middleware.go) reuses the gateway's own readings: Claude Code's x-claude-code-agent-id (subOf), and Codex's x-openai-subagent collab_spawn (callKind + usage.PurposeOf, so a Codex review or compaction is not a subagent). Headers from #4655's real Claude Code 2.1.312 capture. It is read per request, so onRequest and that request's onResponse see the same value and the main turn after a subagent in the same session is "". Never guessed from the prompt or Agent tool history. Documented in docs/subsystems/gateway-request-hooks.md. Before/after: a hook's ctx had no kind; ctx.kind is now "subagent" for such requests (the OV plugin already reads ctx.kind === "subagent"). Run: TestHookKindFromClientHeaders (claude subagent, claude main in the same session, codex collab_spawn, codex review, none) and TestAsyncGatewayHookKindReachesPlugin (real gateway + Bun: main, subagent, main again; onRequest and onResponse) on mote at the commit before the final rebase and on a WSL box; with Kind dropped from the context the e2e test goes red (saw "" want "subagent"). go vet darwin green. Not tried: the real OpenViking plugin; Claude Code itself against this build; linux/windows vet was still queued on mote when this was pushed. |
||
|
|
86825005e2 |
plugin: a gateway hook given more than 10s gets up to 30s (#5890)
gatewayTimeoutMs was capped at 10000 and the Go side cut every hook RPC at 11s, so a recall hook (Nowledge Mem) asking for 15s was cut at 1s (any value over 10000 fell back to the default) and could never finish. - host.js: gatewayTimeoutMs takes integers 100-30000; a value outside is clamped to the nearer bound, a non-integer gets the 1000 default. gatewayBudget() is the old chain budget (sum, clamped 2-10s) or the longest hook's own timeout, whichever is larger. With no hook over 10s nothing changes. - gateway.go mirrors both (gatewayTimeout, gatewayBudget, cached with the HasGateway scan). GatewayBegin's request RPC, Finish's completion RPC and GatewaySignIn now wait the budget plus 1s, never less than the old 11s; host startup and the lock wait stay bounded at 11s. Caller cancellation still reaches the hook at once, a failing hook still rolls back, and the request-state limits are unchanged. - Docs: gateway-request-hooks subsystem page, plugins docs (en, zh, ja). site/public/llms-full.txt regenerated with `node llms-full.mjs`; it was already stale on origin/main (OpenCode 2 keys, billion-context tab, data-folder move, vendor presets, group rule), so those docs pages' text lands in it too. Run on mote at this tree (base 03a800ac6; origin/main has one newer commit touching none of these files): - gofmt -l internal/plugin internal/gateway: clean - go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: rc 0 - go test -tags nogui -count=1 -timeout 45m ./internal/plugin/... ./internal/gateway/...: ok plugin 161.6s, ok gateway 897.0s - site: node --test worker.test.mjs: 38 pass (llms-full red before the regeneration) New tests (internal/plugin/gateway_budget_test.go): a 12s onRequest and onResponse with gatewayTimeoutMs 15000 both land (24.2s); the default and 10000 are still cut with outcome "timeout"; two 8000ms hooks still share 10s; 130000 is clamped, not dropped; cancelling a 15000ms hook's request stops its fetch at once (0.07s); the Go mirror matches host.js. Broken by hand, each red: - A host.js as on main: SlowRecall red at 1.10s, Clamps red - B Go RPC kept at 11s: SlowRecall red at 11.04s, Mirror red - C chain capped at 10s: SlowRecall red at 10.13s - D default per-hook 30000: DefaultStillCuts/default red - E caller signal off the begin chain: LongBudgetCallerCancellation red - F chain budget 30s for every config: ChainStillTenSeconds red Not tried: a real Nowledge Mem server; the full ./... suite; GUI tests (no GUI change); a Windows or Linux runtime run (vet only). Reported-by: aboat0625-cpu |
||
|
|
ab3710de3a |
hooks: onSignIn tells a request hook of an account to sign in again
shannnnnks on X: with several Codex accounts behind the gateway, one is
now and then signed out, and they want the notify plugin to push it.
The magpie that serves the gateway now looks every 2 minutes (first
after 1) at the same sign-in states the desktop alert reads
(provider.WatchSignIns' checkSignIns, so every provider: Claude, Copilot
and plugin accounts that lapsed, and built-ins whose mark says the
sign-in expired or must be done again, Codex's revoked and refused
refreshes among them; accounts in use only). Each account to sign in
again, and each Claude sign-in ending within days, goes to every hooks
file that exports onSignIn, once until the account works again, kept in
signin-hooks.json beside the desktop alert's own file. The event is
{provider, providerName, account, state: "signed-out"|"ending", endsAt?}:
the account is its display label; no token and no vendor reason text.
It is fire-and-forget in the Bun host (gatewayRequest operation
"signIn"), each hook under its own timeout, one that throws doesn't stop
the next. With no hooks file nothing is looked at or marked. A hooks
file may now export onSignIn alone, without onRequest.
Docs: gateway-request-hooks.md (Sign-in notification),
providers-accounts.md, site plugins.html en/zh/ja.
Run on mote at d939dd699 (on origin/main 835439ebf; then rebased on
|
||
|
|
387e8572a8 |
plugins: the sharing key magpie made itself reaches a hook as origin magpie-key, any other gateway key stays gateway-key
A gateway hook's ctx.origin was "gateway-key" both for the sharing key
magpie makes and writes into this computer's own agents (a WSL distro
under NAT, MAGPIE_ADDR beyond loopback) and for a named key the owner
made for a friend. A plugin couldn't tell them apart: plugins PR #526
(nowledge-mem)'s "Agents using a Magpie key" switch would have put the
owner's memories into a friend's requests.
Now access.Authenticate marks the default sharing key (Identity.Default:
the key marked lan, the one LANKeyID names, or an older magpie's
settings-only key, as access.Default tells it), and gatewayOrigin
returns "magpie-key" for it. Every other key, on loopback too, stays
"gateway-key": one the owner made, a value a user brought, or a
sk-magpie- key that didn't authenticate. magpie has no "this named key
is mine" mark, so none of those is treated as the owner's.
Why a new value and not a new field: every consumer in
magpie-community/plugins (agent-office's track.mjs, powercontext, and
#526) compares origin to "local" only, and treats anything else, an
unknown value included, as not local. None compares to "gateway-key" in
code. So "magpie-key" lands in their not-local branch, where the
sharing key already was: no plugin gains or loses a request it serves.
host.js passes the context through untouched. A plugin that wants the
owner's agents checks one value.
docs/subsystems/gateway-request-hooks.md says what each value is. Not
changed: the plugins repo has no type or doc for origin; #526's own
README and switch are its author's to scope (asked on the PR).
Tests:
- TestAuthenticateTellsTheDefaultKey (access): the ConfigureLAN key, a
key named by LANKeyID only, and the legacy settings key read Default;
a made key and a user-brought value don't.
- TestAsyncGatewayOrigin (gateway, real Bun host): the sharing key from
10.0.0.1 and from loopback reaches onRequest and onResponse as
magpie-key; a friend's own-value key as gateway-key.
Run (on mote, at this tree):
- go test -timeout 45m ./...: 80 packages ok (access, gateway 760s,
plugin among them); internal/gui red only in its real-window AppKit
tests (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt,
TestMainWindowCorners and 7 more, each killed at its deadline). Three
of them run at a fresh origin/main
|
||
|
|
f2aa7fe346 |
plugin: HasGateway looks at the plugins once a second, not on every request (#3725)
Every agent request asks plugin.HasGateway (gatewayHooks, and GatewayBegin again when on). It read plugins.json through lastgood and steady, cloned the list, and stat'ed and read every enabled plugin's package.json. With 12 plugins installed and none with hooks: Windows (Ryzen AI MAX+ 395, Defender on): 457µs, 51KB, 360 allocs macOS (M4 Pro): 251-286µs, 36KB, 260 allocs per call. It now keeps its answer for a second, keyed on plugins.json's path and filememo.Gen, as middleware.current does: magpie's own writes (plugin add/remove/on/off all go through save, which calls filememo.Forget) are seen at once, another program's within a second. Now 0.5µs/640B on Windows and 0.3-0.85µs/208B on macOS. Run at |
||
|
|
9b04c4e20f |
plugin: async gateway request hooks, run in Bun before routing and after the reply (#2118)
A package's magpie.hooks entry (or a *.hooks.{js,mjs,ts,mts} file) exports
`async onRequest(body, ctx)` and an optional `onResponse(reply, ctx)`. They
run in the Bun plugin host, so a hook can await I/O, for example a context
service like PowerContext, which the sync moejs middleware can't. The
gateway still makes one model request per client request. A hook adds
context to the body; it doesn't register tools or run a loop, so magpie
doesn't become an agent runtime.
Ported from Tsukikage7/magpie#1. Changes from the fork:
- The entry name is magpie.hooks / *.hooks.*. The fork's magpie.gateway /
*.gateway.mjs is already the middleware's alias, so a hook importing
node:fs was also loaded as moejs middleware and failed there.
TestGatewayHookNamesApartFromMiddleware fails if the two sets overlap.
- onRequest is rolled back, and counts as failed with no onResponse, when
it throws, times out, returns non-JSON, or changes tools, tool_choice,
function_call, functions, toolConfig, model or stream.
- onResponse gets the client-facing reply, merged through the gateway's own
stream decoder, collector and renderer (no second merger).
- Codex's native passthrough (/backend-api/codex) runs the hooks too,
without the sync middleware.
- The run ends with the request handler, not the client connection. Codex
hangs up on response.completed, and the reply it got is still captured
as a success. TestGatewayHookSeesReplyAfterClientHangsUp is red on the
old `r.Context().Err()` check and green with -count=3.
- ctx.origin is host-derived (local / gateway-key / remote). Headers, keys
and peer addresses never reach the hook.
- Plugins page: a hook package shows a "Request hook" chip, a diagnostics
line (outcome code, calls, avg ms, bytes, failures; no content), and
Options. Strings are in en, zh, zh-TW, ja and de.
Docs: docs/subsystems/gateway-request-hooks.md (new), provider-plugins.md,
gateway-middleware.md, and site docs plugins.html in en, zh and ja.
Real use, sandbox HOME on 127.0.0.1:3486 with the owner's real Codex Pro
sign-in. The probe hook adds a codename note and logs both callbacks:
- /v1/responses, /v1/messages, Gemini generateContent: stream and
non-stream. onRequest's note reached the model (the answer had the
codename), and onResponse got success=true and the whole reply.
- /v1/chat/completions: with the probe also changing `model`, the change
was rolled back (the reply came from the asked model) and no onResponse
ran. Without that change, earlier: stream and non-stream success.
- The real Codex CLI 0.162.1 `codex exec` through openai_base_url ->
/backend-api/codex: the hook saw origin=local, agent=codex and the
query; the answer had the codename; onResponse success=true (before the
hang-up fix it never ran: the context was already cancelled).
- `magpie plugin list` shows only "async gateway hook onRequest" for the
hook package, no failed middleware.
Tests (base origin/main
|