@a5c-ai/hooks-mux-adapter-codex 5.0.1-staging.00fa5317c
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/README.md +29 -0
- package/dist/adapter.d.ts +3 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +37 -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 +28 -0
- package/dist/index.js.map +1 -0
- package/dist/mappings.d.ts +7 -0
- package/dist/mappings.d.ts.map +1 -0
- package/dist/mappings.js +71 -0
- package/dist/mappings.js.map +1 -0
- package/dist/normalizer.d.ts +65 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +108 -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 +92 -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 +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @a5c-ai/hooks-mux-adapter-codex
|
|
2
|
+
|
|
3
|
+
Codex harness adapter for hooks-mux.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @a5c-ai/hooks-mux-adapter-codex @a5c-ai/hooks-mux-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package ships the built adapter runtime in `dist/` and this package README for npm publish-surface auditing.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
createAdapter,
|
|
18
|
+
normalizeCodexEvent,
|
|
19
|
+
renderCodexOutput,
|
|
20
|
+
} from "@a5c-ai/hooks-mux-adapter-codex";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The package exposes Codex-specific normalization, phase mappings, rendering helpers, and session-resolution utilities for the hooks-mux execution pipeline.
|
|
24
|
+
|
|
25
|
+
See [`packages/hooks-mux/README.md`](../README.md) for the workspace overview and `packages/hooks-mux/docs/adapter-integration-guide.md` for end-to-end integration guidance.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
MIT © a5c-ai
|
|
@@ -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;AAalE,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAA6B,GAAG,mBAAmB,CAsBtF"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdapter = createAdapter;
|
|
4
|
+
const agent_catalog_1 = require("@a5c-ai/agent-catalog");
|
|
5
|
+
/**
|
|
6
|
+
* Creates the Codex adapter with its capability metadata.
|
|
7
|
+
*
|
|
8
|
+
* Reads capability data from the Atlas graph via the agent-catalog.
|
|
9
|
+
* Falls back to hardcoded defaults if the catalog is unavailable.
|
|
10
|
+
*
|
|
11
|
+
* Spec section 17.2.
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_ADAPTER_NAME = 'codex';
|
|
14
|
+
function createAdapter(name = DEFAULT_ADAPTER_NAME) {
|
|
15
|
+
const target = (0, agent_catalog_1.getPluginTargetDescriptor)(name);
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
family: target?.hooksMuxFamily ?? 'shell-hook',
|
|
19
|
+
sessionIdQuality: target?.sessionIdQuality ?? 'native',
|
|
20
|
+
supportsOrderedFanout: target?.supportsOrderedFanout ?? true,
|
|
21
|
+
supportsNativeAdditionalContext: target?.supportsNativeAdditionalContext ?? false,
|
|
22
|
+
supportsBlock: target?.supportsBlock ?? true,
|
|
23
|
+
supportsAsk: target?.supportsAsk ?? false,
|
|
24
|
+
supportsToolInputMutation: target?.supportsToolInputMutation ?? false,
|
|
25
|
+
supportsToolResultMutation: target?.supportsToolResultMutation ?? false,
|
|
26
|
+
supportsPersistedEnv: target?.supportsPersistedEnv ?? false,
|
|
27
|
+
envPersistenceMode: target?.envPersistenceMode ?? 'wrapper_only',
|
|
28
|
+
toolInterceptionScope: target?.toolInterceptionScope ?? 'partial_shell_only',
|
|
29
|
+
notes: [
|
|
30
|
+
'experimental',
|
|
31
|
+
'tool interception is bash-only',
|
|
32
|
+
'multiple matching hooks can launch concurrently',
|
|
33
|
+
'many parsed output fields currently fail open',
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;AAaA,sCAsBC;AAlCD,yDAAkE;AAElE;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAErC,SAAgB,aAAa,CAAC,OAAe,oBAAoB;IAC/D,MAAM,MAAM,GAAG,IAAA,yCAAyB,EAAC,IAAI,CAAC,CAAC;IAC/C,OAAO;QACL,IAAI;QACJ,MAAM,EAAG,MAAM,EAAE,cAAgD,IAAI,YAAY;QACjF,gBAAgB,EAAG,MAAM,EAAE,gBAA4D,IAAI,QAAQ;QACnG,qBAAqB,EAAE,MAAM,EAAE,qBAAqB,IAAI,IAAI;QAC5D,+BAA+B,EAAE,MAAM,EAAE,+BAA+B,IAAI,KAAK;QACjF,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,IAAI;QAC5C,WAAW,EAAE,MAAM,EAAE,WAAW,IAAI,KAAK;QACzC,yBAAyB,EAAE,MAAM,EAAE,yBAAyB,IAAI,KAAK;QACrE,0BAA0B,EAAE,MAAM,EAAE,0BAA0B,IAAI,KAAK;QACvE,oBAAoB,EAAE,MAAM,EAAE,oBAAoB,IAAI,KAAK;QAC3D,kBAAkB,EAAG,MAAM,EAAE,kBAAgE,IAAI,cAAc;QAC/G,qBAAqB,EAAG,MAAM,EAAE,qBAAsE,IAAI,oBAAoB;QAC9H,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, normalizeCodexEvent as normalizeForInvoke, setAdapterName, parseStdin, extractSessionId, ADAPTER_NAME, } from './normalizer';
|
|
4
|
+
export type { CodexSessionStartPayload, CodexUserPromptPayload, CodexStopPayload, CodexToolPayload, } from './normalizer';
|
|
5
|
+
export { renderCodexOutput, renderCodexOutput as renderForInvoke, 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,mBAAmB,IAAI,kBAAkB,EACzC,cAAc,EACd,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,EACL,iBAAiB,EACjB,iBAAiB,IAAI,eAAe,EACpC,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidSessionId = exports.resolveSessionId = exports.isFieldSupportedForEvent = exports.renderForInvoke = exports.renderCodexOutput = exports.ADAPTER_NAME = exports.extractSessionId = exports.parseStdin = exports.setAdapterName = exports.normalizeForInvoke = 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, "normalizeForInvoke", { enumerable: true, get: function () { return normalizer_1.normalizeCodexEvent; } });
|
|
15
|
+
Object.defineProperty(exports, "setAdapterName", { enumerable: true, get: function () { return normalizer_1.setAdapterName; } });
|
|
16
|
+
Object.defineProperty(exports, "parseStdin", { enumerable: true, get: function () { return normalizer_1.parseStdin; } });
|
|
17
|
+
Object.defineProperty(exports, "extractSessionId", { enumerable: true, get: function () { return normalizer_1.extractSessionId; } });
|
|
18
|
+
Object.defineProperty(exports, "ADAPTER_NAME", { enumerable: true, get: function () { return normalizer_1.ADAPTER_NAME; } });
|
|
19
|
+
// Renderer
|
|
20
|
+
var renderer_1 = require("./renderer");
|
|
21
|
+
Object.defineProperty(exports, "renderCodexOutput", { enumerable: true, get: function () { return renderer_1.renderCodexOutput; } });
|
|
22
|
+
Object.defineProperty(exports, "renderForInvoke", { enumerable: true, get: function () { return renderer_1.renderCodexOutput; } });
|
|
23
|
+
Object.defineProperty(exports, "isFieldSupportedForEvent", { enumerable: true, get: function () { return renderer_1.isFieldSupportedForEvent; } });
|
|
24
|
+
// Session resolver
|
|
25
|
+
var session_resolver_1 = require("./session-resolver");
|
|
26
|
+
Object.defineProperty(exports, "resolveSessionId", { enumerable: true, get: function () { return session_resolver_1.resolveSessionId; } });
|
|
27
|
+
Object.defineProperty(exports, "isValidSessionId", { enumerable: true, get: function () { return session_resolver_1.isValidSessionId; } });
|
|
28
|
+
//# 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,2CAOsB;AANpB,iHAAA,mBAAmB,OAAA;AACnB,gHAAA,mBAAmB,OAAsB;AACzC,4GAAA,cAAc,OAAA;AACd,wGAAA,UAAU,OAAA;AACV,8GAAA,gBAAgB,OAAA;AAChB,0GAAA,YAAY,OAAA;AASd,WAAW;AACX,uCAIoB;AAHlB,6GAAA,iBAAiB,OAAA;AACjB,2GAAA,iBAAiB,OAAmB;AACpC,oHAAA,wBAAwB,OAAA;AAG1B,mBAAmB;AACnB,uDAAwE;AAA/D,oHAAA,gBAAgB,OAAA;AAAE,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PhaseMapping } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
export declare const CODEX_PHASE_MAPPINGS: PhaseMapping[];
|
|
3
|
+
/**
|
|
4
|
+
* Quick lookup from native event name to phase mapping.
|
|
5
|
+
*/
|
|
6
|
+
export declare function findMapping(nativeEventName: string): PhaseMapping | undefined;
|
|
7
|
+
//# 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;AAiE3D,eAAO,MAAM,oBAAoB,EAAE,YAAY,EAAuB,CAAC;AAEvE;;GAEG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE7E"}
|
package/dist/mappings.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CODEX_PHASE_MAPPINGS = void 0;
|
|
4
|
+
exports.findMapping = findMapping;
|
|
5
|
+
const agent_catalog_1 = require("@a5c-ai/agent-catalog");
|
|
6
|
+
/**
|
|
7
|
+
* Codex native event to canonical phase mapping table.
|
|
8
|
+
*
|
|
9
|
+
* Phase mappings are built from the Atlas graph HookMapping records
|
|
10
|
+
* via the agent-catalog. Falls back to hardcoded defaults if the
|
|
11
|
+
* catalog is unavailable.
|
|
12
|
+
*
|
|
13
|
+
* Spec section 17.2.
|
|
14
|
+
*/
|
|
15
|
+
const SUPPORT_LEVEL_MAP = {
|
|
16
|
+
supported: 'native',
|
|
17
|
+
native: 'native',
|
|
18
|
+
lossy: 'lossy',
|
|
19
|
+
emulated: 'emulated',
|
|
20
|
+
unsupported: 'unsupported',
|
|
21
|
+
};
|
|
22
|
+
const CODEX_COMPATIBILITY_MAPPINGS = [
|
|
23
|
+
{
|
|
24
|
+
canonicalPhase: 'tool.before',
|
|
25
|
+
nativeHook: 'PreToolUse',
|
|
26
|
+
supportLevel: 'lossy',
|
|
27
|
+
blockCapability: true,
|
|
28
|
+
mutationCapability: false,
|
|
29
|
+
scope: 'tool',
|
|
30
|
+
notes: 'Bash-only compatibility alias for legacy Codex hook payloads.',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
function hookMappingToPhaseMapping(mapping) {
|
|
34
|
+
if (!mapping.canonicalPhase)
|
|
35
|
+
return null;
|
|
36
|
+
return {
|
|
37
|
+
canonicalPhase: mapping.canonicalPhase,
|
|
38
|
+
nativeHook: mapping.nativeName,
|
|
39
|
+
supportLevel: SUPPORT_LEVEL_MAP[mapping.supportLevel] ?? (mapping.requiresRuntimeHooks ? 'native' : 'lossy'),
|
|
40
|
+
blockCapability: mapping.blockCapability ?? false,
|
|
41
|
+
mutationCapability: mapping.mutationCapability ?? false,
|
|
42
|
+
scope: (mapping.scope ?? 'session'),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function buildFromCatalog() {
|
|
46
|
+
const mappings = (0, agent_catalog_1.listHookMappingsByAdapterFamily)('codex');
|
|
47
|
+
if (mappings.length === 0) {
|
|
48
|
+
throw new Error('hooks-mux adapter-codex: catalog unavailable or returned no mappings for family "codex"');
|
|
49
|
+
}
|
|
50
|
+
const phaseMappings = [
|
|
51
|
+
...CODEX_COMPATIBILITY_MAPPINGS,
|
|
52
|
+
...mappings
|
|
53
|
+
.map(hookMappingToPhaseMapping)
|
|
54
|
+
.filter((m) => m !== null),
|
|
55
|
+
];
|
|
56
|
+
const seen = new Set();
|
|
57
|
+
return phaseMappings.filter((m) => {
|
|
58
|
+
if (seen.has(m.nativeHook))
|
|
59
|
+
return false;
|
|
60
|
+
seen.add(m.nativeHook);
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.CODEX_PHASE_MAPPINGS = buildFromCatalog();
|
|
65
|
+
/**
|
|
66
|
+
* Quick lookup from native event name to phase mapping.
|
|
67
|
+
*/
|
|
68
|
+
function findMapping(nativeEventName) {
|
|
69
|
+
return exports.CODEX_PHASE_MAPPINGS.find((m) => m.nativeHook === nativeEventName);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=mappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappings.js","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":";;;AAsEA,kCAEC;AAvED,yDAAwE;AAGxE;;;;;;;;GAQG;AAEH,MAAM,iBAAiB,GAAiD;IACtE,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;CAC3B,CAAC;AAEF,MAAM,4BAA4B,GAAmB;IACnD;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,+DAA+D;KACvE;CACF,CAAC;AAEF,SAAS,yBAAyB,CAAC,OAA8B;IAC/D,IAAI,CAAC,OAAO,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IACzC,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAgD;QACxE,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,YAAY,EAAE,iBAAiB,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QAC5G,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,KAAK;QACjD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,KAAK;QACvD,KAAK,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,SAAS,CAA0B;KAC7D,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB;IACvB,MAAM,QAAQ,GAAG,IAAA,+CAA+B,EAAC,OAAO,CAAC,CAAC;IAC1D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAC;IAC7G,CAAC;IACD,MAAM,aAAa,GAAG;QACpB,GAAG,4BAA4B;QAC/B,GAAG,QAAQ;aACR,GAAG,CAAC,yBAAyB,CAAC;aAC9B,MAAM,CAAC,CAAC,CAAC,EAAqB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;KAChD,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAChC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAEY,QAAA,oBAAoB,GAAmB,gBAAgB,EAAE,CAAC;AAEvE;;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,65 @@
|
|
|
1
|
+
import { type UnifiedHookEvent } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/** The default adapter identifier used in all normalized events. */
|
|
3
|
+
export declare const ADAPTER_NAME = "codex";
|
|
4
|
+
/** Override the adapter name used in normalized events. */
|
|
5
|
+
export declare function setAdapterName(name: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Shape of a Codex SessionStart stdin payload.
|
|
8
|
+
* Fields may be absent or null -- fail open per spec 17.2.
|
|
9
|
+
*/
|
|
10
|
+
export interface CodexSessionStartPayload {
|
|
11
|
+
session_id?: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
source?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Shape of a Codex UserPromptSubmit stdin payload.
|
|
19
|
+
*/
|
|
20
|
+
export interface CodexUserPromptPayload {
|
|
21
|
+
session_id?: string;
|
|
22
|
+
prompt?: string;
|
|
23
|
+
cwd?: string;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Shape of a Codex Stop stdin payload.
|
|
28
|
+
*/
|
|
29
|
+
export interface CodexStopPayload {
|
|
30
|
+
session_id?: string;
|
|
31
|
+
reason?: string;
|
|
32
|
+
stop_hook_active?: boolean;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Shape of a Codex PreToolUse / PostToolUse stdin payload.
|
|
37
|
+
*/
|
|
38
|
+
export interface CodexToolPayload {
|
|
39
|
+
session_id?: string;
|
|
40
|
+
tool_name?: string;
|
|
41
|
+
tool_call_id?: string;
|
|
42
|
+
tool_input?: unknown;
|
|
43
|
+
tool_output?: unknown;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse raw stdin input into a typed object.
|
|
48
|
+
* Codex hooks receive JSON on stdin. If parsing fails, return empty object
|
|
49
|
+
* (fail-open per spec 17.2).
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseStdin(raw: unknown): Record<string, unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Extract session_id from stdin payload.
|
|
54
|
+
* Codex provides a native session_id in most events.
|
|
55
|
+
*/
|
|
56
|
+
export declare function extractSessionId(payload: Record<string, unknown>): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Normalize a raw Codex hook invocation into a UnifiedHookEvent.
|
|
59
|
+
*
|
|
60
|
+
* @param rawEventName - The native Codex event name (e.g. 'SessionStart', 'Stop')
|
|
61
|
+
* @param stdinPayload - Raw stdin content (string or parsed object)
|
|
62
|
+
* @param env - Environment variables at invocation time
|
|
63
|
+
*/
|
|
64
|
+
export declare function normalizeCodexEvent(rawEventName: string, stdinPayload: unknown, env?: Record<string, string>): UnifiedHookEvent;
|
|
65
|
+
//# 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,oEAAoE;AACpE,eAAO,MAAM,YAAY,UAAU,CAAC;AAKpC,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBhE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAKhF;AAgBD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,OAAO,EACrB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,gBAAgB,CA0ClB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADAPTER_NAME = void 0;
|
|
4
|
+
exports.setAdapterName = setAdapterName;
|
|
5
|
+
exports.parseStdin = parseStdin;
|
|
6
|
+
exports.extractSessionId = extractSessionId;
|
|
7
|
+
exports.normalizeCodexEvent = normalizeCodexEvent;
|
|
8
|
+
const hooks_mux_core_1 = require("@a5c-ai/hooks-mux-core");
|
|
9
|
+
const mappings_1 = require("./mappings");
|
|
10
|
+
/** The default adapter identifier used in all normalized events. */
|
|
11
|
+
exports.ADAPTER_NAME = 'codex';
|
|
12
|
+
/** The mutable adapter name, defaulting to the Codex adapter identity. */
|
|
13
|
+
let _adapterName = exports.ADAPTER_NAME;
|
|
14
|
+
/** Override the adapter name used in normalized events. */
|
|
15
|
+
function setAdapterName(name) {
|
|
16
|
+
_adapterName = name;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse raw stdin input into a typed object.
|
|
20
|
+
* Codex hooks receive JSON on stdin. If parsing fails, return empty object
|
|
21
|
+
* (fail-open per spec 17.2).
|
|
22
|
+
*/
|
|
23
|
+
function parseStdin(raw) {
|
|
24
|
+
if (raw == null)
|
|
25
|
+
return {};
|
|
26
|
+
if (typeof raw === 'string') {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(raw);
|
|
29
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// fail open
|
|
35
|
+
}
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
if (typeof raw === 'object' && !Array.isArray(raw)) {
|
|
39
|
+
return raw;
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Extract session_id from stdin payload.
|
|
45
|
+
* Codex provides a native session_id in most events.
|
|
46
|
+
*/
|
|
47
|
+
function extractSessionId(payload) {
|
|
48
|
+
if (typeof payload['session_id'] === 'string' && payload['session_id'].length > 0) {
|
|
49
|
+
return payload['session_id'];
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extract tool metadata from a PreToolUse/PostToolUse payload.
|
|
55
|
+
*/
|
|
56
|
+
function extractToolFields(payload) {
|
|
57
|
+
const fields = {};
|
|
58
|
+
if (typeof payload['tool_name'] === 'string') {
|
|
59
|
+
fields['HOOKS_PROXY_TOOL_NAME'] = payload['tool_name'];
|
|
60
|
+
}
|
|
61
|
+
if (typeof payload['tool_call_id'] === 'string') {
|
|
62
|
+
fields['HOOKS_PROXY_TOOL_CALL_ID'] = payload['tool_call_id'];
|
|
63
|
+
}
|
|
64
|
+
return fields;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Normalize a raw Codex hook invocation into a UnifiedHookEvent.
|
|
68
|
+
*
|
|
69
|
+
* @param rawEventName - The native Codex event name (e.g. 'SessionStart', 'Stop')
|
|
70
|
+
* @param stdinPayload - Raw stdin content (string or parsed object)
|
|
71
|
+
* @param env - Environment variables at invocation time
|
|
72
|
+
*/
|
|
73
|
+
function normalizeCodexEvent(rawEventName, stdinPayload, env = {}) {
|
|
74
|
+
const parsed = parseStdin(stdinPayload);
|
|
75
|
+
// Enrich env with Codex-specific fields extracted from stdin
|
|
76
|
+
const enrichedEnv = { ...env };
|
|
77
|
+
const sessionId = extractSessionId(parsed);
|
|
78
|
+
if (sessionId && !enrichedEnv['HOOKS_PROXY_SESSION_ID']) {
|
|
79
|
+
enrichedEnv['HOOKS_PROXY_SESSION_ID'] = sessionId;
|
|
80
|
+
}
|
|
81
|
+
if (typeof parsed['cwd'] === 'string' && !enrichedEnv['HOOKS_PROXY_CWD']) {
|
|
82
|
+
enrichedEnv['HOOKS_PROXY_CWD'] = parsed['cwd'];
|
|
83
|
+
}
|
|
84
|
+
if (typeof parsed['model'] === 'string' && !enrichedEnv['HOOKS_PROXY_MODEL']) {
|
|
85
|
+
enrichedEnv['HOOKS_PROXY_MODEL'] = parsed['model'];
|
|
86
|
+
}
|
|
87
|
+
if (typeof parsed['source'] === 'string' && !enrichedEnv['HOOKS_PROXY_SOURCE']) {
|
|
88
|
+
enrichedEnv['HOOKS_PROXY_SOURCE'] = parsed['source'];
|
|
89
|
+
}
|
|
90
|
+
// Tool-specific env enrichment
|
|
91
|
+
if (rawEventName === 'PreToolUse' || rawEventName === 'PostToolUse') {
|
|
92
|
+
const toolFields = extractToolFields(parsed);
|
|
93
|
+
for (const [k, v] of Object.entries(toolFields)) {
|
|
94
|
+
if (!enrichedEnv[k]) {
|
|
95
|
+
enrichedEnv[k] = v;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const options = {
|
|
100
|
+
adapter: _adapterName,
|
|
101
|
+
rawEventName,
|
|
102
|
+
stdinPayload: parsed,
|
|
103
|
+
env: enrichedEnv,
|
|
104
|
+
adapterMappings: mappings_1.CODEX_PHASE_MAPPINGS,
|
|
105
|
+
};
|
|
106
|
+
return (0, hooks_mux_core_1.normalizeEvent)(options);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.js","sourceRoot":"","sources":["../src/normalizer.ts"],"names":[],"mappings":";;;AAUA,wCAEC;AAmDD,gCAiBC;AAMD,4CAKC;AAuBD,kDA8CC;AAhKD,2DAAsG;AACtG,yCAAkD;AAElD,oEAAoE;AACvD,QAAA,YAAY,GAAG,OAAO,CAAC;AAEpC,0EAA0E;AAC1E,IAAI,YAAY,GAAW,oBAAY,CAAC;AAExC,2DAA2D;AAC3D,SAAgB,cAAc,CAAC,IAAY;IACzC,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AA8CD;;;;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,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5E,OAAO,MAAiC,CAAC;YAC3C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAA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|
+
*
|
|
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;AAuDpE;;;;;;;;;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,92 @@
|
|
|
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
|
+
/** Output fields supported on SessionEnd (mostly ignored). */
|
|
38
|
+
const SESSION_END_FIELDS = new Set([
|
|
39
|
+
'reason',
|
|
40
|
+
]);
|
|
41
|
+
/** Map native event names to their supported output field sets. */
|
|
42
|
+
const SUPPORTED_FIELDS_BY_EVENT = {
|
|
43
|
+
SessionStart: SESSION_START_FIELDS,
|
|
44
|
+
SessionEnd: SESSION_END_FIELDS,
|
|
45
|
+
UserPromptSubmit: USER_PROMPT_SUBMIT_FIELDS,
|
|
46
|
+
Stop: STOP_FIELDS,
|
|
47
|
+
PreToolUse: TOOL_BEFORE_FIELDS,
|
|
48
|
+
PostToolUse: TOOL_AFTER_FIELDS,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Render a merged execution result into Codex-native output JSON.
|
|
52
|
+
*
|
|
53
|
+
* Only includes fields that are documented for the given native event type.
|
|
54
|
+
* Unsupported fields are silently dropped (fail-open behavior per spec).
|
|
55
|
+
*
|
|
56
|
+
* @param mergedResult - The merged result from multi-hook fan-out
|
|
57
|
+
* @param nativeEventName - The original Codex event name
|
|
58
|
+
* @returns Codex-native output object, and list of dropped fields
|
|
59
|
+
*/
|
|
60
|
+
function renderCodexOutput(mergedResult, nativeEventName) {
|
|
61
|
+
const supportedFields = SUPPORTED_FIELDS_BY_EVENT[nativeEventName] ?? new Set();
|
|
62
|
+
const output = {};
|
|
63
|
+
const droppedFields = [];
|
|
64
|
+
// Candidate output fields from the merged result
|
|
65
|
+
const candidates = [
|
|
66
|
+
{ key: 'decision', value: mergedResult.decision, isEmpty: mergedResult.decision === 'noop' },
|
|
67
|
+
{ key: 'reason', value: mergedResult.reason, isEmpty: !mergedResult.reason },
|
|
68
|
+
{ key: 'systemMessage', value: mergedResult.systemMessage, isEmpty: !mergedResult.systemMessage },
|
|
69
|
+
{ key: 'continueSession', value: mergedResult.continueSession, isEmpty: mergedResult.continueSession === true },
|
|
70
|
+
{ key: 'stopReason', value: mergedResult.stopReason, isEmpty: !mergedResult.stopReason },
|
|
71
|
+
{ key: 'suppressOutput', value: mergedResult.suppressOutput, isEmpty: !mergedResult.suppressOutput },
|
|
72
|
+
];
|
|
73
|
+
for (const candidate of candidates) {
|
|
74
|
+
if (candidate.isEmpty)
|
|
75
|
+
continue;
|
|
76
|
+
if (supportedFields.has(candidate.key)) {
|
|
77
|
+
output[candidate.key] = candidate.value;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
droppedFields.push(candidate.key);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { output, droppedFields };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check whether a given output field is supported for a native event.
|
|
87
|
+
*/
|
|
88
|
+
function isFieldSupportedForEvent(field, nativeEventName) {
|
|
89
|
+
const supported = SUPPORTED_FIELDS_BY_EVENT[nativeEventName];
|
|
90
|
+
return supported ? supported.has(field) : false;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;AAiEA,8CA6BC;AAKD,4DAGC;AApGD;;;;;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,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,QAAQ;CACT,CAAC,CAAC;AAEH,mEAAmE;AACnE,MAAM,yBAAyB,GAAgC;IAC7D,YAAY,EAAE,oBAAoB;IAClC,UAAU,EAAE,kBAAkB;IAC9B,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,IAA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AAE,aAAa,EAAE,CAAC;AACnC,CAAC;AAED;;GAEG;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,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5c-ai/hooks-mux-adapter-codex",
|
|
3
|
+
"version": "5.0.1-staging.00fa5317c",
|
|
4
|
+
"description": "Codex harness adapter for the hooks-mux system",
|
|
5
|
+
"license": "MIT",
|
|
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": "git+https://github.com/a5c-ai/babysitter.git",
|
|
15
|
+
"directory": "packages/hooks-mux/adapter-codex"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/a5c-ai/babysitter/tree/main/packages/hooks-mux/adapter-codex#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/a5c-ai/babysitter/issues"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"clean": "rimraf dist",
|
|
28
|
+
"lint": "eslint \"src/**/*.ts\" --max-warnings=0",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@a5c-ai/hooks-mux-core": "5.0.1-staging.00fa5317c"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.7.0",
|
|
37
|
+
"vitest": "^3.0.0",
|
|
38
|
+
"rimraf": "^6.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|