@mclawnet/codex-adapter 0.1.0

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.
@@ -0,0 +1,52 @@
1
+ import type { PermissionDecision, PermissionRequest } from "@mclawnet/backend-types";
2
+ /**
3
+ * Three coexisting decision-wire families codex app-server speaks:
4
+ * - "legacy" → ReviewDecision (approved/approved_for_session/denied/abort)
5
+ * - "v2" → CommandExecutionApprovalDecision / FileChangeApprovalDecision
6
+ * (accept/acceptForSession/decline/cancel)
7
+ * - "mcp" → McpServerElicitationAction
8
+ * ({ action: "accept" | "decline" | "cancel" })
9
+ *
10
+ * `parseApprovalRequest` returns the family so `respondToPermission` can pick
11
+ * the right wire without re-deriving it from a brittle method-name prefix.
12
+ */
13
+ export type ApprovalWireFamily = "legacy" | "v2" | "mcp";
14
+ export type ReviewDecisionWire = "approved" | "approved_for_session" | "denied" | "abort";
15
+ export declare function decisionToWire(d: PermissionDecision["decision"]): ReviewDecisionWire;
16
+ /**
17
+ * v2 CommandExecutionApprovalDecision / FileChangeApprovalDecision wire enum.
18
+ * Used by codex app-server >= 0.134 for `item/.../requestApproval` flows.
19
+ */
20
+ export type V2DecisionWire = "accept" | "acceptForSession" | "decline" | "cancel";
21
+ export declare function decisionToV2Wire(d: PermissionDecision["decision"]): V2DecisionWire;
22
+ /**
23
+ * MCP elicitation action enum (RMCP CreateElicitationResult). Note: "session"
24
+ * scope isn't part of the MCP spec — `allow_session` degrades to "accept".
25
+ */
26
+ export type McpElicitationAction = "accept" | "decline" | "cancel";
27
+ export declare function decisionToMcpAction(d: PermissionDecision["decision"]): McpElicitationAction;
28
+ /** @deprecated kept only for back-compat with M3.S5 test seam; prefer the
29
+ * wire family returned by `parseApprovalRequest`. */
30
+ export declare function isV2ApprovalMethod(method: string): boolean;
31
+ /**
32
+ * Build the wire-shaped reply body for a given decision + family.
33
+ * - legacy → `{ decision: "approved" | ... }`
34
+ * - v2 → `{ decision: "accept" | ... }`
35
+ * - mcp → `{ action: "accept" | ... }`
36
+ */
37
+ export declare function buildApprovalReply(family: ApprovalWireFamily, decision: PermissionDecision["decision"]): Record<string, string>;
38
+ export interface ParsedApprovalRequest {
39
+ req: PermissionRequest;
40
+ wireFamily: ApprovalWireFamily;
41
+ }
42
+ /**
43
+ * Map a codex JSON-RPC approval request to our backend-neutral
44
+ * PermissionRequest. Covers both legacy (`execCommandApproval`,
45
+ * `applyPatchApproval`) and v2 (`item/commandExecution/requestApproval`,
46
+ * `item/fileChange/requestApproval`) shapes, plus MCP elicitation.
47
+ *
48
+ * Returns null when the method is not a recognized approval channel — the
49
+ * adapter forwards such frames as raw output instead.
50
+ */
51
+ export declare function parseApprovalRequest(method: string, params: unknown): ParsedApprovalRequest | null;
52
+ //# sourceMappingURL=permission-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-mapper.d.ts","sourceRoot":"","sources":["../src/permission-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAErF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC;AAEzD,MAAM,MAAM,kBAAkB,GAC1B,UAAU,GACV,sBAAsB,GACtB,QAAQ,GACR,OAAO,CAAC;AAEZ,wBAAgB,cAAc,CAAC,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,GAAG,kBAAkB,CAepF;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,kBAAkB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAElF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,GAAG,cAAc,CAelF;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,GAAG,oBAAoB,CAc3F;AAED;qDACqD;AACrD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,GACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,iBAAiB,CAAC;IACvB,UAAU,EAAE,kBAAkB,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GACd,qBAAqB,GAAG,IAAI,CA+D9B"}
@@ -0,0 +1,146 @@
1
+ export function decisionToWire(d) {
2
+ switch (d) {
3
+ case "allow":
4
+ return "approved";
5
+ case "allow_session":
6
+ return "approved_for_session";
7
+ case "deny":
8
+ return "denied";
9
+ case "abort":
10
+ return "abort";
11
+ default: {
12
+ const _exhaustive = d;
13
+ return _exhaustive;
14
+ }
15
+ }
16
+ }
17
+ export function decisionToV2Wire(d) {
18
+ switch (d) {
19
+ case "allow":
20
+ return "accept";
21
+ case "allow_session":
22
+ return "acceptForSession";
23
+ case "deny":
24
+ return "decline";
25
+ case "abort":
26
+ return "cancel";
27
+ default: {
28
+ const _exhaustive = d;
29
+ return _exhaustive;
30
+ }
31
+ }
32
+ }
33
+ export function decisionToMcpAction(d) {
34
+ switch (d) {
35
+ case "allow":
36
+ case "allow_session":
37
+ return "accept";
38
+ case "deny":
39
+ return "decline";
40
+ case "abort":
41
+ return "cancel";
42
+ default: {
43
+ const _exhaustive = d;
44
+ return _exhaustive;
45
+ }
46
+ }
47
+ }
48
+ /** @deprecated kept only for back-compat with M3.S5 test seam; prefer the
49
+ * wire family returned by `parseApprovalRequest`. */
50
+ export function isV2ApprovalMethod(method) {
51
+ return method.startsWith("item/");
52
+ }
53
+ /**
54
+ * Build the wire-shaped reply body for a given decision + family.
55
+ * - legacy → `{ decision: "approved" | ... }`
56
+ * - v2 → `{ decision: "accept" | ... }`
57
+ * - mcp → `{ action: "accept" | ... }`
58
+ */
59
+ export function buildApprovalReply(family, decision) {
60
+ switch (family) {
61
+ case "legacy":
62
+ return { decision: decisionToWire(decision) };
63
+ case "v2":
64
+ return { decision: decisionToV2Wire(decision) };
65
+ case "mcp":
66
+ return { action: decisionToMcpAction(decision) };
67
+ default: {
68
+ const _exhaustive = family;
69
+ return _exhaustive;
70
+ }
71
+ }
72
+ }
73
+ /**
74
+ * Map a codex JSON-RPC approval request to our backend-neutral
75
+ * PermissionRequest. Covers both legacy (`execCommandApproval`,
76
+ * `applyPatchApproval`) and v2 (`item/commandExecution/requestApproval`,
77
+ * `item/fileChange/requestApproval`) shapes, plus MCP elicitation.
78
+ *
79
+ * Returns null when the method is not a recognized approval channel — the
80
+ * adapter forwards such frames as raw output instead.
81
+ */
82
+ export function parseApprovalRequest(method, params) {
83
+ const p = (params ?? {});
84
+ const callId = p.callId ?? p.itemId;
85
+ if (!callId)
86
+ return null;
87
+ const reason = p.reason;
88
+ const cwd = p.cwd;
89
+ if (method === "execCommandApproval") {
90
+ return {
91
+ req: {
92
+ callId,
93
+ toolName: "shell",
94
+ input: { command: p.command, cwd },
95
+ meta: { backend: "codex", reason, cwd },
96
+ },
97
+ wireFamily: "legacy",
98
+ };
99
+ }
100
+ if (method === "item/commandExecution/requestApproval") {
101
+ return {
102
+ req: {
103
+ callId,
104
+ toolName: "shell",
105
+ input: { command: p.command, cwd },
106
+ meta: { backend: "codex", reason, cwd },
107
+ },
108
+ wireFamily: "v2",
109
+ };
110
+ }
111
+ if (method === "applyPatchApproval") {
112
+ return {
113
+ req: {
114
+ callId,
115
+ toolName: "apply_patch",
116
+ input: { fileChanges: p.fileChanges },
117
+ meta: { backend: "codex", reason, cwd },
118
+ },
119
+ wireFamily: "legacy",
120
+ };
121
+ }
122
+ if (method === "item/fileChange/requestApproval") {
123
+ return {
124
+ req: {
125
+ callId,
126
+ toolName: "apply_patch",
127
+ input: { fileChanges: p.fileChanges },
128
+ meta: { backend: "codex", reason, cwd },
129
+ },
130
+ wireFamily: "v2",
131
+ };
132
+ }
133
+ if (method === "mcpServer/elicitation/request") {
134
+ return {
135
+ req: {
136
+ callId,
137
+ toolName: p.serverName ?? "mcp",
138
+ input: { message: p.message, meta: p._meta },
139
+ meta: { backend: "codex", reason },
140
+ },
141
+ wireFamily: "mcp",
142
+ };
143
+ }
144
+ return null;
145
+ }
146
+ //# sourceMappingURL=permission-mapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-mapper.js","sourceRoot":"","sources":["../src/permission-mapper.ts"],"names":[],"mappings":"AAqBA,MAAM,UAAU,cAAc,CAAC,CAAiC;IAC9D,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,OAAO;YACV,OAAO,UAAU,CAAC;QACpB,KAAK,eAAe;YAClB,OAAO,sBAAsB,CAAC;QAChC,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,WAAW,GAAU,CAAC,CAAC;YAC7B,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,gBAAgB,CAAC,CAAiC;IAChE,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC;QAClB,KAAK,eAAe;YAClB,OAAO,kBAAkB,CAAC;QAC5B,KAAK,MAAM;YACT,OAAO,SAAS,CAAC;QACnB,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC;QAClB,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,WAAW,GAAU,CAAC,CAAC;YAC7B,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC;AAQD,MAA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U,EAAE,IAAI;SACjB,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,+BAA+B,EAAE,CAAC;QAC/C,OAAO;YACL,GAAG,EAAE;gBACH,MAAM;gBACN,QAAQ,EAAG,CAAC,CAAC,UAAiC,IAAI,KAAK;gBACvD,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE;gBAC5C,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE;aACnC;YACD,UAAU,EAAE,KAAK;SAClB,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@mclawnet/codex-adapter",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ }
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "dependencies": {
18
+ "@mclawnet/backend-types": "0.1.0",
19
+ "@mclawnet/shared": "0.1.9",
20
+ "@mclawnet/logger": "0.1.7"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^22",
24
+ "typescript": "^5.8.3",
25
+ "vitest": "^4.0.18"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "clean": "rm -rf dist",
30
+ "test": "vitest run"
31
+ }
32
+ }