@igorjpimenta/winch-opencode 0.0.0-stage → 2026.11.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hooks.js ADDED
@@ -0,0 +1,22 @@
1
+ import { stampWinchIdentity } from "./identity.js";
2
+
3
+ // The agent is not on the tool call, only the session: remember it from the
4
+ // chat events that carry both, then stamp the pair on every winch call.
5
+ export function createWinchHooks() {
6
+ const agents = new Map();
7
+
8
+ return {
9
+ "chat.message": async (input) => {
10
+ if (input?.sessionID && input?.agent) agents.set(input.sessionID, input.agent);
11
+ },
12
+ "chat.params": async (input) => {
13
+ if (input?.sessionID && input?.agent) agents.set(input.sessionID, input.agent);
14
+ },
15
+ "tool.execute.before": async (input, output) => {
16
+ // Unconditional: when the agent is unknown the slot is blanked, so a
17
+ // model-supplied pair can never ride through as identity. Blank means
18
+ // unstamped, and the server refuses that rather than trusting it.
19
+ stampWinchIdentity(input, output, { agent: agents.get(input?.sessionID) ?? process.env.WINCH_AGENT ?? null });
20
+ },
21
+ };
22
+ }
package/identity.js ADDED
@@ -0,0 +1,30 @@
1
+ // identity.js — opencode can mutate tool args but not request _meta, so the
2
+ // winch server accepts a whole agent+session pair as winch_agent/winch_session
3
+ // args (src/identity.js, args channel). The hook overwrites them
4
+ // unconditionally: a model-supplied pair must never survive.
5
+
6
+ export function isWinchTool(name) {
7
+ return typeof name === "string" && name.includes("winch");
8
+ }
9
+
10
+ export function stampWinchIdentity(input, output, { agent = null } = {}) {
11
+ if (!isWinchTool(input?.tool)) return false;
12
+ output.args = output.args ?? {};
13
+ // Overwrite, never merge: an unknown agent blanks the slot (unstamped),
14
+ // which the server refuses — that is the fail-closed side of the rule that
15
+ // model-supplied identity never survives.
16
+ output.args.winch_agent = agent ?? "";
17
+ output.args.winch_session = input?.sessionID ?? "";
18
+ return true;
19
+ }
20
+
21
+ // V2: the tool hook hands one mutable event instead of (input, output). Same
22
+ // rule — the pair is stamped unconditionally.
23
+ export function stampWinchEvent(event, agent) {
24
+ if (!isWinchTool(event?.tool)) return false;
25
+ const input = event.input && typeof event.input === "object" ? event.input : {};
26
+ event.input = input;
27
+ input.winch_agent = agent ?? "";
28
+ input.winch_session = event.sessionID ?? "";
29
+ return true;
30
+ }
package/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import { createWinchHooks } from "./hooks.js";
2
+ import { stampWinchEvent } from "./identity.js";
3
+
4
+ // One package, two hosts: V1 calls server() and gets the object hooks; V2
5
+ // reads id/setup() and gets the domain hooks. The implementations stay
6
+ // separate — V1 mutates (input, output), V2 mutates one event — but both
7
+ // stamp the same unconditional identity pair.
8
+ export default {
9
+ id: "winch-opencode",
10
+ async setup(ctx) {
11
+ // SessionContext (the "context" hook event) carries both sessionID and
12
+ // the session's agent; session.get() in this beta returns a projection
13
+ // without agent, so the request hook is the reliable source.
14
+ const agents = new Map();
15
+ await ctx.session.hook("context", (event) => {
16
+ if (event?.sessionID && event.agent) agents.set(event.sessionID, event.agent);
17
+ });
18
+ await ctx.tool.hook("execute.before", (event) => {
19
+ const agent = agents.get(event.sessionID) ?? process.env.WINCH_AGENT ?? null;
20
+ // Unconditional: unknown agent blanks the slot, the server refuses
21
+ // rather than trusting whatever the model wrote there.
22
+ stampWinchEvent(event, agent);
23
+ });
24
+ },
25
+ async server() {
26
+ return createWinchHooks();
27
+ },
28
+ };
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@igorjpimenta/winch-opencode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2026.11.03-beta.1",
4
+ "description": "OpenCode companion for winch: stamps agent and session identity on winch tool calls (V1 hooks + V2 setup). No SDK dependency \u2014 a plain id/setup/server export.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/igorjpimenta/winch.git",
10
+ "directory": "plugins/opencode/winch"
11
+ },
12
+ "publishConfig": {
13
+ "registry": "https://registry.npmjs.org",
14
+ "access": "public"
15
+ },
16
+ "exports": {
17
+ ".": "./index.js"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "hooks.js",
22
+ "identity.js"
23
+ ],
24
+ "main": "index.js"
25
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.