@a5c-ai/hooks-mux-adapter-codex 5.0.1-staging.37ca18bd
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/dist/adapter.d.ts +12 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +35 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/mappings.d.ts +17 -0
- package/dist/mappings.d.ts.map +1 -0
- package/dist/mappings.js +78 -0
- package/dist/mappings.js.map +1 -0
- package/dist/normalizer.d.ts +63 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +101 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/renderer.d.ts +20 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +87 -0
- package/dist/renderer.js.map +1 -0
- package/dist/session-resolver.d.ts +27 -0
- package/dist/session-resolver.d.ts.map +1 -0
- package/dist/session-resolver.js +51 -0
- package/dist/session-resolver.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AdapterCapabilities } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the Codex adapter with its capability metadata.
|
|
4
|
+
*
|
|
5
|
+
* Codex CLI is a shell-hook adapter with experimental status.
|
|
6
|
+
* Tool interception is partial (Bash-only), and env propagation
|
|
7
|
+
* is wrapper-based only -- there is no native env file mechanism.
|
|
8
|
+
*
|
|
9
|
+
* Spec section 17.2.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAdapter(): AdapterCapabilities;
|
|
12
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,mBAAmB,CAqBnD"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdapter = createAdapter;
|
|
4
|
+
/**
|
|
5
|
+
* Creates the Codex adapter with its capability metadata.
|
|
6
|
+
*
|
|
7
|
+
* Codex CLI is a shell-hook adapter with experimental status.
|
|
8
|
+
* Tool interception is partial (Bash-only), and env propagation
|
|
9
|
+
* is wrapper-based only -- there is no native env file mechanism.
|
|
10
|
+
*
|
|
11
|
+
* Spec section 17.2.
|
|
12
|
+
*/
|
|
13
|
+
function createAdapter() {
|
|
14
|
+
return {
|
|
15
|
+
name: 'codex',
|
|
16
|
+
family: 'shell-hook',
|
|
17
|
+
sessionIdQuality: 'native',
|
|
18
|
+
supportsOrderedFanout: true,
|
|
19
|
+
supportsNativeAdditionalContext: false,
|
|
20
|
+
supportsBlock: true,
|
|
21
|
+
supportsAsk: false,
|
|
22
|
+
supportsToolInputMutation: false,
|
|
23
|
+
supportsToolResultMutation: false,
|
|
24
|
+
supportsPersistedEnv: false,
|
|
25
|
+
envPersistenceMode: 'wrapper_only',
|
|
26
|
+
toolInterceptionScope: 'partial_shell_only',
|
|
27
|
+
notes: [
|
|
28
|
+
'experimental',
|
|
29
|
+
'tool interception is bash-only',
|
|
30
|
+
'multiple matching hooks can launch concurrently',
|
|
31
|
+
'many parsed output fields currently fail open',
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;AAWA,sCAqBC;AA9BD;;;;;;;;GAQG;AACH,SAAgB,aAAa;IAC3B,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,YAAY;QACpB,gBAAgB,EAAE,QAAQ;QAC1B,qBAAqB,EAAE,IAAI;QAC3B,+BAA+B,EAAE,KAAK;QACtC,aAAa,EAAE,IAAI;QACnB,WAAW,EAAE,KAAK;QAClB,yBAAyB,EAAE,KAAK;QAChC,0BAA0B,EAAE,KAAK;QACjC,oBAAoB,EAAE,KAAK;QAC3B,kBAAkB,EAAE,cAAc;QAClC,qBAAqB,EAAE,oBAAoB;QAC3C,KAAK,EAAE;YACL,cAAc;YACd,gCAAgC;YAChC,iDAAiD;YACjD,+CAA+C;SAChD;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createAdapter } from './adapter';
|
|
2
|
+
export { CODEX_PHASE_MAPPINGS, findMapping } from './mappings';
|
|
3
|
+
export { normalizeCodexEvent, parseStdin, extractSessionId, ADAPTER_NAME, } from './normalizer';
|
|
4
|
+
export type { CodexSessionStartPayload, CodexUserPromptPayload, CodexStopPayload, CodexToolPayload, } from './normalizer';
|
|
5
|
+
export { renderCodexOutput, isFieldSupportedForEvent } from './renderer';
|
|
6
|
+
export { resolveSessionId, isValidSessionId } from './session-resolver';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG/D,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAGzE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidSessionId = exports.resolveSessionId = exports.isFieldSupportedForEvent = exports.renderCodexOutput = exports.ADAPTER_NAME = exports.extractSessionId = exports.parseStdin = exports.normalizeCodexEvent = exports.findMapping = exports.CODEX_PHASE_MAPPINGS = exports.createAdapter = void 0;
|
|
4
|
+
// Adapter capabilities
|
|
5
|
+
var adapter_1 = require("./adapter");
|
|
6
|
+
Object.defineProperty(exports, "createAdapter", { enumerable: true, get: function () { return adapter_1.createAdapter; } });
|
|
7
|
+
// Phase mappings
|
|
8
|
+
var mappings_1 = require("./mappings");
|
|
9
|
+
Object.defineProperty(exports, "CODEX_PHASE_MAPPINGS", { enumerable: true, get: function () { return mappings_1.CODEX_PHASE_MAPPINGS; } });
|
|
10
|
+
Object.defineProperty(exports, "findMapping", { enumerable: true, get: function () { return mappings_1.findMapping; } });
|
|
11
|
+
// Normalizer
|
|
12
|
+
var normalizer_1 = require("./normalizer");
|
|
13
|
+
Object.defineProperty(exports, "normalizeCodexEvent", { enumerable: true, get: function () { return normalizer_1.normalizeCodexEvent; } });
|
|
14
|
+
Object.defineProperty(exports, "parseStdin", { enumerable: true, get: function () { return normalizer_1.parseStdin; } });
|
|
15
|
+
Object.defineProperty(exports, "extractSessionId", { enumerable: true, get: function () { return normalizer_1.extractSessionId; } });
|
|
16
|
+
Object.defineProperty(exports, "ADAPTER_NAME", { enumerable: true, get: function () { return normalizer_1.ADAPTER_NAME; } });
|
|
17
|
+
// Renderer
|
|
18
|
+
var renderer_1 = require("./renderer");
|
|
19
|
+
Object.defineProperty(exports, "renderCodexOutput", { enumerable: true, get: function () { return renderer_1.renderCodexOutput; } });
|
|
20
|
+
Object.defineProperty(exports, "isFieldSupportedForEvent", { enumerable: true, get: function () { return renderer_1.isFieldSupportedForEvent; } });
|
|
21
|
+
// Session resolver
|
|
22
|
+
var session_resolver_1 = require("./session-resolver");
|
|
23
|
+
Object.defineProperty(exports, "resolveSessionId", { enumerable: true, get: function () { return session_resolver_1.resolveSessionId; } });
|
|
24
|
+
Object.defineProperty(exports, "isValidSessionId", { enumerable: true, get: function () { return session_resolver_1.isValidSessionId; } });
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AAEtB,iBAAiB;AACjB,uCAA+D;AAAtD,gHAAA,oBAAoB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAE1C,aAAa;AACb,2CAKsB;AAJpB,iHAAA,mBAAmB,OAAA;AACnB,wGAAA,UAAU,OAAA;AACV,8GAAA,gBAAgB,OAAA;AAChB,0GAAA,YAAY,OAAA;AASd,WAAW;AACX,uCAAyE;AAAhE,6GAAA,iBAAiB,OAAA;AAAE,oHAAA,wBAAwB,OAAA;AAEpD,mBAAmB;AACnB,uDAAwE;AAA/D,oHAAA,gBAAgB,OAAA;AAAE,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PhaseMapping } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/**
|
|
3
|
+
* Codex native event to canonical phase mapping table.
|
|
4
|
+
*
|
|
5
|
+
* Codex CLI hooks use a similar event naming scheme to Claude Code,
|
|
6
|
+
* but with an experimental/limited surface. Tool-level hooks only
|
|
7
|
+
* cover Bash execution and are incomplete (spec section 17.2).
|
|
8
|
+
*
|
|
9
|
+
* Events documented in Codex hooks.json: SessionStart, UserPromptSubmit,
|
|
10
|
+
* Stop, PreToolUse, PostToolUse (Bash commands only).
|
|
11
|
+
*/
|
|
12
|
+
export declare const CODEX_PHASE_MAPPINGS: PhaseMapping[];
|
|
13
|
+
/**
|
|
14
|
+
* Quick lookup from native event name to phase mapping.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findMapping(nativeEventName: string): PhaseMapping | undefined;
|
|
17
|
+
//# sourceMappingURL=mappings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappings.d.ts","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,YAAY,EA0D9C,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE7E"}
|
package/dist/mappings.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CODEX_PHASE_MAPPINGS = void 0;
|
|
4
|
+
exports.findMapping = findMapping;
|
|
5
|
+
/**
|
|
6
|
+
* Codex native event to canonical phase mapping table.
|
|
7
|
+
*
|
|
8
|
+
* Codex CLI hooks use a similar event naming scheme to Claude Code,
|
|
9
|
+
* but with an experimental/limited surface. Tool-level hooks only
|
|
10
|
+
* cover Bash execution and are incomplete (spec section 17.2).
|
|
11
|
+
*
|
|
12
|
+
* Events documented in Codex hooks.json: SessionStart, UserPromptSubmit,
|
|
13
|
+
* Stop, PreToolUse, PostToolUse (Bash commands only).
|
|
14
|
+
*/
|
|
15
|
+
exports.CODEX_PHASE_MAPPINGS = [
|
|
16
|
+
// --- Session lifecycle ---
|
|
17
|
+
{
|
|
18
|
+
canonicalPhase: 'session.start',
|
|
19
|
+
nativeHook: 'SessionStart',
|
|
20
|
+
supportLevel: 'native',
|
|
21
|
+
blockCapability: false,
|
|
22
|
+
mutationCapability: false,
|
|
23
|
+
scope: 'session',
|
|
24
|
+
notes: 'Bootstrap event; output is largely ignored by Codex runtime',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
canonicalPhase: 'session.end',
|
|
28
|
+
nativeHook: 'SessionEnd',
|
|
29
|
+
supportLevel: 'lossy',
|
|
30
|
+
blockCapability: false,
|
|
31
|
+
mutationCapability: false,
|
|
32
|
+
scope: 'session',
|
|
33
|
+
notes: 'Codex may not reliably fire SessionEnd in all exit paths',
|
|
34
|
+
},
|
|
35
|
+
// --- Turn lifecycle ---
|
|
36
|
+
{
|
|
37
|
+
canonicalPhase: 'turn.user_prompt_submitted',
|
|
38
|
+
nativeHook: 'UserPromptSubmit',
|
|
39
|
+
supportLevel: 'native',
|
|
40
|
+
blockCapability: true,
|
|
41
|
+
mutationCapability: false,
|
|
42
|
+
scope: 'turn',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
canonicalPhase: 'turn.stop',
|
|
46
|
+
nativeHook: 'Stop',
|
|
47
|
+
supportLevel: 'native',
|
|
48
|
+
blockCapability: true,
|
|
49
|
+
mutationCapability: false,
|
|
50
|
+
scope: 'turn',
|
|
51
|
+
},
|
|
52
|
+
// --- Tool lifecycle (Bash-only, incomplete) ---
|
|
53
|
+
{
|
|
54
|
+
canonicalPhase: 'tool.before',
|
|
55
|
+
nativeHook: 'PreToolUse',
|
|
56
|
+
supportLevel: 'lossy',
|
|
57
|
+
blockCapability: true,
|
|
58
|
+
mutationCapability: false,
|
|
59
|
+
scope: 'tool',
|
|
60
|
+
notes: 'Bash-only; non-Bash tool calls are not intercepted',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
canonicalPhase: 'tool.after',
|
|
64
|
+
nativeHook: 'PostToolUse',
|
|
65
|
+
supportLevel: 'lossy',
|
|
66
|
+
blockCapability: false,
|
|
67
|
+
mutationCapability: false,
|
|
68
|
+
scope: 'tool',
|
|
69
|
+
notes: 'Bash-only; non-Bash tool calls are not intercepted',
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
/**
|
|
73
|
+
* Quick lookup from native event name to phase mapping.
|
|
74
|
+
*/
|
|
75
|
+
function findMapping(nativeEventName) {
|
|
76
|
+
return exports.CODEX_PHASE_MAPPINGS.find((m) => m.nativeHook === nativeEventName);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=mappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappings.js","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":";;;AA2EA,kCAEC;AA3ED;;;;;;;;;GASG;AACU,QAAA,oBAAoB,GAAmB;IAClD,4BAA4B;IAC5B;QACE,cAAc,EAAE,eAAe;QAC/B,UAAU,EAAE,cAAc;QAC1B,YAAY,EAAE,QAAQ;QACtB,eAAe,EAAE,KAAK;QACtB,kBAAkB,EAAE,KAAK;QACzB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,6DAA6D;KACrE;IACD;QACE,cAAc,EAAE,aAAa;QAC7B,UAAU,EAAE,YAAY;QACxB,YAAY,EAAE,OAAO;QACrB,eAAe,EAAE,KAAK;QACtB,kBAAkB,EAAE,KAAK;QACzB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,0DAA0D;KAClE;IAED,yBAAyB;IACzB;QACE,cAAc,EAAE,4BAA4B;QAC5C,UAAU,EAAE,kBAAkB;QAC9B,YAAY,EAAE,QAAQ;QACtB,eAAe,EAAE,IAAI;QACrB,kBAAkB,EAAE,KAAK;QACzB,KAAK,EAAE,MAAM;KACd;IACD;QACE,cAAc,EAAE,WAAW;QAC3B,UAAU,EAAE,MAAM;QAClB,YAAY,EAAE,QAAQ;QACtB,eAAe,EAAE,IAAI;QACrB,kBAAkB,EAAE,KAAK;QACzB,KAAK,EAAE,MAAM;KACd;IAED,iDAAiD;IACjD;QACE,cAAc,EAAE,aAAa;QAC7B,UAAU,EAAE,YAAY;QACxB,YAAY,EAAE,OAAO;QACrB,eAAe,EAAE,IAAI;QACrB,kBAAkB,EAAE,KAAK;QACzB,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,oDAAoD;KAC5D;IACD;QACE,cAAc,EAAE,YAAY;QAC5B,UAAU,EAAE,aAAa;QACzB,YAAY,EAAE,OAAO;QACrB,eAAe,EAAE,KAAK;QACtB,kBAAkB,EAAE,KAAK;QACzB,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,oDAAoD;KAC5D;CACF,CAAC;AAEF;;GAEG;AACH,SAAgB,WAAW,CAAC,eAAuB;IACjD,OAAO,4BAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,eAAe,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type UnifiedHookEvent } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/** The adapter identifier used in all normalized events. */
|
|
3
|
+
export declare const ADAPTER_NAME = "codex";
|
|
4
|
+
/**
|
|
5
|
+
* Shape of a Codex SessionStart stdin payload.
|
|
6
|
+
* Fields may be absent or null -- fail open per spec 17.2.
|
|
7
|
+
*/
|
|
8
|
+
export interface CodexSessionStartPayload {
|
|
9
|
+
session_id?: string;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
source?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Shape of a Codex UserPromptSubmit stdin payload.
|
|
17
|
+
*/
|
|
18
|
+
export interface CodexUserPromptPayload {
|
|
19
|
+
session_id?: string;
|
|
20
|
+
prompt?: string;
|
|
21
|
+
cwd?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shape of a Codex Stop stdin payload.
|
|
26
|
+
*/
|
|
27
|
+
export interface CodexStopPayload {
|
|
28
|
+
session_id?: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
stop_hook_active?: boolean;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Shape of a Codex PreToolUse / PostToolUse stdin payload.
|
|
35
|
+
*/
|
|
36
|
+
export interface CodexToolPayload {
|
|
37
|
+
session_id?: string;
|
|
38
|
+
tool_name?: string;
|
|
39
|
+
tool_call_id?: string;
|
|
40
|
+
tool_input?: unknown;
|
|
41
|
+
tool_output?: unknown;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse raw stdin input into a typed object.
|
|
46
|
+
* Codex hooks receive JSON on stdin. If parsing fails, return empty object
|
|
47
|
+
* (fail-open per spec 17.2).
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseStdin(raw: unknown): Record<string, unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* Extract session_id from stdin payload.
|
|
52
|
+
* Codex provides a native session_id in most events.
|
|
53
|
+
*/
|
|
54
|
+
export declare function extractSessionId(payload: Record<string, unknown>): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Normalize a raw Codex hook invocation into a UnifiedHookEvent.
|
|
57
|
+
*
|
|
58
|
+
* @param rawEventName - The native Codex event name (e.g. 'SessionStart', 'Stop')
|
|
59
|
+
* @param stdinPayload - Raw stdin content (string or parsed object)
|
|
60
|
+
* @param env - Environment variables at invocation time
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeCodexEvent(rawEventName: string, stdinPayload: unknown, env?: Record<string, string>): UnifiedHookEvent;
|
|
63
|
+
//# sourceMappingURL=normalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../src/normalizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,gBAAgB,EAAyB,MAAM,wBAAwB,CAAC;AAGtG,4DAA4D;AAC5D,eAAO,MAAM,YAAY,UAAU,CAAC;AAEpC;;;G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GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,gBAAgB,CA0ClB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADAPTER_NAME = void 0;
|
|
4
|
+
exports.parseStdin = parseStdin;
|
|
5
|
+
exports.extractSessionId = extractSessionId;
|
|
6
|
+
exports.normalizeCodexEvent = normalizeCodexEvent;
|
|
7
|
+
const hooks_mux_core_1 = require("@a5c-ai/hooks-mux-core");
|
|
8
|
+
const mappings_1 = require("./mappings");
|
|
9
|
+
/** The adapter identifier used in all normalized events. */
|
|
10
|
+
exports.ADAPTER_NAME = 'codex';
|
|
11
|
+
/**
|
|
12
|
+
* Parse raw stdin input into a typed object.
|
|
13
|
+
* Codex hooks receive JSON on stdin. If parsing fails, return empty object
|
|
14
|
+
* (fail-open per spec 17.2).
|
|
15
|
+
*/
|
|
16
|
+
function parseStdin(raw) {
|
|
17
|
+
if (raw == null)
|
|
18
|
+
return {};
|
|
19
|
+
if (typeof raw === 'string') {
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(raw);
|
|
22
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// fail open
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
if (typeof raw === 'object' && !Array.isArray(raw)) {
|
|
32
|
+
return raw;
|
|
33
|
+
}
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extract session_id from stdin payload.
|
|
38
|
+
* Codex provides a native session_id in most events.
|
|
39
|
+
*/
|
|
40
|
+
function extractSessionId(payload) {
|
|
41
|
+
if (typeof payload['session_id'] === 'string' && payload['session_id'].length > 0) {
|
|
42
|
+
return payload['session_id'];
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extract tool metadata from a PreToolUse/PostToolUse payload.
|
|
48
|
+
*/
|
|
49
|
+
function extractToolFields(payload) {
|
|
50
|
+
const fields = {};
|
|
51
|
+
if (typeof payload['tool_name'] === 'string') {
|
|
52
|
+
fields['HOOKS_PROXY_TOOL_NAME'] = payload['tool_name'];
|
|
53
|
+
}
|
|
54
|
+
if (typeof payload['tool_call_id'] === 'string') {
|
|
55
|
+
fields['HOOKS_PROXY_TOOL_CALL_ID'] = payload['tool_call_id'];
|
|
56
|
+
}
|
|
57
|
+
return fields;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Normalize a raw Codex hook invocation into a UnifiedHookEvent.
|
|
61
|
+
*
|
|
62
|
+
* @param rawEventName - The native Codex event name (e.g. 'SessionStart', 'Stop')
|
|
63
|
+
* @param stdinPayload - Raw stdin content (string or parsed object)
|
|
64
|
+
* @param env - Environment variables at invocation time
|
|
65
|
+
*/
|
|
66
|
+
function normalizeCodexEvent(rawEventName, stdinPayload, env = {}) {
|
|
67
|
+
const parsed = parseStdin(stdinPayload);
|
|
68
|
+
// Enrich env with Codex-specific fields extracted from stdin
|
|
69
|
+
const enrichedEnv = { ...env };
|
|
70
|
+
const sessionId = extractSessionId(parsed);
|
|
71
|
+
if (sessionId && !enrichedEnv['HOOKS_PROXY_SESSION_ID']) {
|
|
72
|
+
enrichedEnv['HOOKS_PROXY_SESSION_ID'] = sessionId;
|
|
73
|
+
}
|
|
74
|
+
if (typeof parsed['cwd'] === 'string' && !enrichedEnv['HOOKS_PROXY_CWD']) {
|
|
75
|
+
enrichedEnv['HOOKS_PROXY_CWD'] = parsed['cwd'];
|
|
76
|
+
}
|
|
77
|
+
if (typeof parsed['model'] === 'string' && !enrichedEnv['HOOKS_PROXY_MODEL']) {
|
|
78
|
+
enrichedEnv['HOOKS_PROXY_MODEL'] = parsed['model'];
|
|
79
|
+
}
|
|
80
|
+
if (typeof parsed['source'] === 'string' && !enrichedEnv['HOOKS_PROXY_SOURCE']) {
|
|
81
|
+
enrichedEnv['HOOKS_PROXY_SOURCE'] = parsed['source'];
|
|
82
|
+
}
|
|
83
|
+
// Tool-specific env enrichment
|
|
84
|
+
if (rawEventName === 'PreToolUse' || rawEventName === 'PostToolUse') {
|
|
85
|
+
const toolFields = extractToolFields(parsed);
|
|
86
|
+
for (const [k, v] of Object.entries(toolFields)) {
|
|
87
|
+
if (!enrichedEnv[k]) {
|
|
88
|
+
enrichedEnv[k] = v;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const options = {
|
|
93
|
+
adapter: exports.ADAPTER_NAME,
|
|
94
|
+
rawEventName,
|
|
95
|
+
stdinPayload: parsed,
|
|
96
|
+
env: enrichedEnv,
|
|
97
|
+
adapterMappings: mappings_1.CODEX_PHASE_MAPPINGS,
|
|
98
|
+
};
|
|
99
|
+
return (0, hooks_mux_core_1.normalizeEvent)(options);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.js","sourceRoot":"","sources":["../src/normalizer.ts"],"names":[],"mappings":";;;AAuDA,gCAiBC;AAMD,4CAKC;AAuBD,kDA8CC;AAxJD,2DAAsG;AACtG,yCAAkD;AAElD,4DAA4D;AAC/C,QAAA,YAAY,GAAG,OAAO,CAAC;AA8CpC;;;;GAIG;AACH,SAAgB,UAAU,CAAC,GAAY;IACrC,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,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BAAoB;KACtC,CAAC;IAEF,OAAO,IAAA,+BAAc,EAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MergedExecutionResult } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/**
|
|
3
|
+
* Render a merged execution result into Codex-native output JSON.
|
|
4
|
+
*
|
|
5
|
+
* Only includes fields that are documented for the given native event type.
|
|
6
|
+
* Unsupported fields are silently dropped (fail-open behavior per spec).
|
|
7
|
+
*
|
|
8
|
+
* @param mergedResult - The merged result from multi-hook fan-out
|
|
9
|
+
* @param nativeEventName - The original Codex event name
|
|
10
|
+
* @returns Codex-native output object, and list of dropped fields
|
|
11
|
+
*/
|
|
12
|
+
export declare function renderCodexOutput(mergedResult: MergedExecutionResult, nativeEventName: string): {
|
|
13
|
+
output: Record<string, unknown>;
|
|
14
|
+
droppedFields: string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Check whether a given output field is supported for a native event.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isFieldSupportedForEvent(field: string, nativeEventName: string): boolean;
|
|
20
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAiDpE;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,qBAAqB,EACnC,eAAe,EAAE,MAAM,GACtB;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,aAAa,EAAE,MAAM,EAAE,CAAA;CAAE,CA0B9D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAGxF"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderCodexOutput = renderCodexOutput;
|
|
4
|
+
exports.isFieldSupportedForEvent = isFieldSupportedForEvent;
|
|
5
|
+
/**
|
|
6
|
+
* Codex native output fields that are documented/supported per event type.
|
|
7
|
+
*
|
|
8
|
+
* Codex output semantics are limited -- many fields fail open
|
|
9
|
+
* (spec section 17.2). Only emit fields that are documented.
|
|
10
|
+
*/
|
|
11
|
+
/** Output fields supported on UserPromptSubmit. */
|
|
12
|
+
const USER_PROMPT_SUBMIT_FIELDS = new Set([
|
|
13
|
+
'decision',
|
|
14
|
+
'reason',
|
|
15
|
+
'systemMessage',
|
|
16
|
+
]);
|
|
17
|
+
/** Output fields supported on Stop. */
|
|
18
|
+
const STOP_FIELDS = new Set([
|
|
19
|
+
'continueSession',
|
|
20
|
+
'stopReason',
|
|
21
|
+
'reason',
|
|
22
|
+
]);
|
|
23
|
+
/** Output fields supported on PreToolUse. */
|
|
24
|
+
const TOOL_BEFORE_FIELDS = new Set([
|
|
25
|
+
'decision',
|
|
26
|
+
'reason',
|
|
27
|
+
]);
|
|
28
|
+
/** Output fields supported on PostToolUse. */
|
|
29
|
+
const TOOL_AFTER_FIELDS = new Set([
|
|
30
|
+
'suppressOutput',
|
|
31
|
+
'reason',
|
|
32
|
+
]);
|
|
33
|
+
/** Output fields supported on SessionStart (mostly ignored). */
|
|
34
|
+
const SESSION_START_FIELDS = new Set([
|
|
35
|
+
'reason',
|
|
36
|
+
]);
|
|
37
|
+
/** Map native event names to their supported output field sets. */
|
|
38
|
+
const SUPPORTED_FIELDS_BY_EVENT = {
|
|
39
|
+
SessionStart: SESSION_START_FIELDS,
|
|
40
|
+
UserPromptSubmit: USER_PROMPT_SUBMIT_FIELDS,
|
|
41
|
+
Stop: STOP_FIELDS,
|
|
42
|
+
PreToolUse: TOOL_BEFORE_FIELDS,
|
|
43
|
+
PostToolUse: TOOL_AFTER_FIELDS,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Render a merged execution result into Codex-native output JSON.
|
|
47
|
+
*
|
|
48
|
+
* Only includes fields that are documented for the given native event type.
|
|
49
|
+
* Unsupported fields are silently dropped (fail-open behavior per spec).
|
|
50
|
+
*
|
|
51
|
+
* @param mergedResult - The merged result from multi-hook fan-out
|
|
52
|
+
* @param nativeEventName - The original Codex event name
|
|
53
|
+
* @returns Codex-native output object, and list of dropped fields
|
|
54
|
+
*/
|
|
55
|
+
function renderCodexOutput(mergedResult, nativeEventName) {
|
|
56
|
+
const supportedFields = SUPPORTED_FIELDS_BY_EVENT[nativeEventName] ?? new Set();
|
|
57
|
+
const output = {};
|
|
58
|
+
const droppedFields = [];
|
|
59
|
+
// Candidate output fields from the merged result
|
|
60
|
+
const candidates = [
|
|
61
|
+
{ key: 'decision', value: mergedResult.decision, isEmpty: mergedResult.decision === 'noop' },
|
|
62
|
+
{ key: 'reason', value: mergedResult.reason, isEmpty: !mergedResult.reason },
|
|
63
|
+
{ key: 'systemMessage', value: mergedResult.systemMessage, isEmpty: !mergedResult.systemMessage },
|
|
64
|
+
{ key: 'continueSession', value: mergedResult.continueSession, isEmpty: mergedResult.continueSession === true },
|
|
65
|
+
{ key: 'stopReason', value: mergedResult.stopReason, isEmpty: !mergedResult.stopReason },
|
|
66
|
+
{ key: 'suppressOutput', value: mergedResult.suppressOutput, isEmpty: !mergedResult.suppressOutput },
|
|
67
|
+
];
|
|
68
|
+
for (const candidate of candidates) {
|
|
69
|
+
if (candidate.isEmpty)
|
|
70
|
+
continue;
|
|
71
|
+
if (supportedFields.has(candidate.key)) {
|
|
72
|
+
output[candidate.key] = candidate.value;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
droppedFields.push(candidate.key);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { output, droppedFields };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check whether a given output field is supported for a native event.
|
|
82
|
+
*/
|
|
83
|
+
function isFieldSupportedForEvent(field, nativeEventName) {
|
|
84
|
+
const supported = SUPPORTED_FIELDS_BY_EVENT[nativeEventName];
|
|
85
|
+
return supported ? supported.has(field) : false;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;AA2DA,8CA6BC;AAKD,4DAGC;AA9FD;;;;;GAKG;AAEH,mDAAmD;AACnD,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;IACxC,UAAU;IACV,QAAQ;IACR,eAAe;CAChB,CAAC,CAAC;AAEH,uCAAuC;AACvC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,iBAAiB;IACjB,YAAY;IACZ,QAAQ;CACT,CAAC,CAAC;AAEH,6CAA6C;AAC7C,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,UAAU;IACV,QAAQ;CACT,CAAC,CAAC;AAEH,8CAA8C;AAC9C,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,gBAAgB;IAChB,QAAQ;CACT,CAAC,CAAC;AAEH,gEAAgE;AAChE,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,QAAQ;CACT,CAAC,CAAC;AAEH,mEAAmE;AACnE,MAAM,yBAAyB,GAAgC;IAC7D,YAAY,EAAE,oBAAoB;IAClC,gBAAgB,EAAE,yBAAyB;IAC3C,IAAI,EAAE,WAAW;IACjB,UAAU,EAAE,kBAAkB;IAC9B,WAAW,EAAE,iBAAiB;CAC/B,CAAC;AAEF;;;;;;;;;GASG;AACH,SAAgB,iBAAiB,CAC/B,YAAmC,EACnC,eAAuB;IAEvB,MAAM,eAAe,GAAG,yBAAyB,CAAC,eAAe,CAAC,IAAI,IAAI,GAAG,EAAU,CAAC;IACxF,MAAM,MAAM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EG;AACH,SAAgB,wBAAwB,CAAC,KAAa,EAAE,eAAuB;IAC7E,MAAM,SAAS,GAAG,yBAAyB,CAAC,eAAe,CAAC,CAAC;IAC7D,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve session ID from Codex hook invocation context.
|
|
3
|
+
*
|
|
4
|
+
* Codex provides a native session_id in stdin payloads, giving it
|
|
5
|
+
* 'native' sessionIdQuality in the capability model.
|
|
6
|
+
*
|
|
7
|
+
* Resolution precedence (per spec 9.2):
|
|
8
|
+
* 1. Explicit --session-id CLI flag (handled upstream)
|
|
9
|
+
* 2. Explicit AGENT_SESSION_ID env var
|
|
10
|
+
* 3. Native session_id from stdin payload
|
|
11
|
+
* 4. CODEX_THREAD_ID env var (Codex-specific)
|
|
12
|
+
* 5. null (no session; caller decides fallback)
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Extract session ID from Codex stdin payload and environment.
|
|
16
|
+
*
|
|
17
|
+
* @param stdinPayload - Parsed stdin JSON from Codex hook
|
|
18
|
+
* @param env - Environment variables at invocation time
|
|
19
|
+
* @returns Resolved session ID or null
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveSessionId(stdinPayload: Record<string, unknown>, env?: Record<string, string>): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Validate that a session ID looks reasonable.
|
|
24
|
+
* Codex session IDs are typically UUIDs or similar opaque strings.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isValidSessionId(sessionId: string): boolean;
|
|
27
|
+
//# sourceMappingURL=session-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-resolver.d.ts","sourceRoot":"","sources":["../src/session-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,MAAM,GAAG,IAAI,CAoBf;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAG3D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve session ID from Codex hook invocation context.
|
|
4
|
+
*
|
|
5
|
+
* Codex provides a native session_id in stdin payloads, giving it
|
|
6
|
+
* 'native' sessionIdQuality in the capability model.
|
|
7
|
+
*
|
|
8
|
+
* Resolution precedence (per spec 9.2):
|
|
9
|
+
* 1. Explicit --session-id CLI flag (handled upstream)
|
|
10
|
+
* 2. Explicit AGENT_SESSION_ID env var
|
|
11
|
+
* 3. Native session_id from stdin payload
|
|
12
|
+
* 4. CODEX_THREAD_ID env var (Codex-specific)
|
|
13
|
+
* 5. null (no session; caller decides fallback)
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.resolveSessionId = resolveSessionId;
|
|
17
|
+
exports.isValidSessionId = isValidSessionId;
|
|
18
|
+
/**
|
|
19
|
+
* Extract session ID from Codex stdin payload and environment.
|
|
20
|
+
*
|
|
21
|
+
* @param stdinPayload - Parsed stdin JSON from Codex hook
|
|
22
|
+
* @param env - Environment variables at invocation time
|
|
23
|
+
* @returns Resolved session ID or null
|
|
24
|
+
*/
|
|
25
|
+
function resolveSessionId(stdinPayload, env = {}) {
|
|
26
|
+
// Priority 1: explicit env override
|
|
27
|
+
const explicit = env['AGENT_SESSION_ID'];
|
|
28
|
+
if (typeof explicit === 'string' && explicit.length > 0) {
|
|
29
|
+
return explicit;
|
|
30
|
+
}
|
|
31
|
+
// Priority 2: native session_id from stdin payload
|
|
32
|
+
const native = stdinPayload['session_id'];
|
|
33
|
+
if (typeof native === 'string' && native.length > 0) {
|
|
34
|
+
return native;
|
|
35
|
+
}
|
|
36
|
+
// Priority 3: Codex-specific env var
|
|
37
|
+
const codexThreadId = env['CODEX_THREAD_ID'];
|
|
38
|
+
if (typeof codexThreadId === 'string' && codexThreadId.length > 0) {
|
|
39
|
+
return codexThreadId;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validate that a session ID looks reasonable.
|
|
45
|
+
* Codex session IDs are typically UUIDs or similar opaque strings.
|
|
46
|
+
*/
|
|
47
|
+
function isValidSessionId(sessionId) {
|
|
48
|
+
// Accept non-empty strings of reasonable length
|
|
49
|
+
return sessionId.length > 0 && sessionId.length <= 256;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=session-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-resolver.js","sourceRoot":"","sources":["../src/session-resolver.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AASH,4CAuBC;AAMD,4CAGC;AAvCD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,YAAqC,EACrC,MAA8B,EAAE;IAEhC,oCAAoC;IACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACzC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,mDAAmD;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC1C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,qCAAqC;IACrC,MAAM,aAAa,GAAG,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC7C,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClE,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,SAAiB;IAChD,gDAAgD;IAChD,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC;AACzD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5c-ai/hooks-mux-adapter-codex",
|
|
3
|
+
"version": "5.0.1-staging.37ca18bd",
|
|
4
|
+
"description": "Codex harness adapter for the hooks-mux system",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/a5c-ai/babysitter.git",
|
|
15
|
+
"directory": "packages/hooks-mux/adapter-codex"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"lint": "eslint \"src/**/*.ts\" --max-warnings=0",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@a5c-ai/hooks-mux-core": "5.0.1-staging.37ca18bd"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.7.0",
|
|
32
|
+
"vitest": "^3.0.0",
|
|
33
|
+
"rimraf": "^6.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|