@a5c-ai/hooks-adapter-oh-my-pi 5.1.1-staging.52898ebfc24f
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 +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +38 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +48 -0
- package/dist/integration.js.map +1 -0
- package/dist/mappings.d.ts +11 -0
- package/dist/mappings.d.ts.map +1 -0
- package/dist/mappings.js +67 -0
- package/dist/mappings.js.map +1 -0
- package/dist/normalizer.d.ts +68 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +116 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/renderer.d.ts +21 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +106 -0
- package/dist/renderer.js.map +1 -0
- package/dist/session-resolver.d.ts +38 -0
- package/dist/session-resolver.d.ts.map +1 -0
- package/dist/session-resolver.js +58 -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-adapter-oh-my-pi
|
|
2
|
+
|
|
3
|
+
oh-my-pi harness adapter for hooks-adapter.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @a5c-ai/hooks-adapter-oh-my-pi @a5c-ai/hooks-adapter-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
|
+
createConfiguredEngine,
|
|
19
|
+
normalizeOhMyPiEvent,
|
|
20
|
+
} from "@a5c-ai/hooks-adapter-oh-my-pi";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The package exposes oh-my-pi-specific normalization, phase mappings, session helpers, and an in-process configured engine for hooks-adapter integrations.
|
|
24
|
+
|
|
25
|
+
See [`packages/adapters/hooks/README.md`](../README.md) for the workspace overview and `packages/adapters/hooks/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,4BAA4B,CAAC;AAatE,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 catalog_1 = require("@a5c-ai/atlas/catalog");
|
|
5
|
+
/**
|
|
6
|
+
* Creates the Oh-My-Pi adapter capability descriptor.
|
|
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.7.
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_ADAPTER_NAME = 'oh-my-pi';
|
|
14
|
+
function createAdapter(name = DEFAULT_ADAPTER_NAME) {
|
|
15
|
+
const target = (0, catalog_1.getPluginTargetDescriptor)(name === 'oh-my-pi' ? 'oh-my-pi' : name);
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
family: target?.hooksMuxFamily ?? 'in-process',
|
|
19
|
+
sessionIdQuality: target?.sessionIdQuality ?? 'native',
|
|
20
|
+
supportsOrderedFanout: target?.supportsOrderedFanout ?? true,
|
|
21
|
+
supportsNativeAdditionalContext: target?.supportsNativeAdditionalContext ?? true,
|
|
22
|
+
supportsBlock: target?.supportsBlock ?? false,
|
|
23
|
+
supportsAsk: target?.supportsAsk ?? false,
|
|
24
|
+
supportsToolInputMutation: target?.supportsToolInputMutation ?? false,
|
|
25
|
+
supportsToolResultMutation: target?.supportsToolResultMutation ?? false,
|
|
26
|
+
supportsPersistedEnv: target?.supportsPersistedEnv ?? true,
|
|
27
|
+
envPersistenceMode: target?.envPersistenceMode ?? 'runtime_hook',
|
|
28
|
+
toolInterceptionScope: target?.toolInterceptionScope ?? 'none',
|
|
29
|
+
notes: [
|
|
30
|
+
'library-only adapter, no CLI/shell-hook mode',
|
|
31
|
+
'supportsToolInputMutation is explicitly false — Pi supports it but Oh-My-Pi does not',
|
|
32
|
+
'session IDs are natively provided by the Pi runtime',
|
|
33
|
+
'chained context propagation with session-before short-circuit',
|
|
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,mDAAkE;AAElE;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAExC,SAAgB,aAAa,CAAC,OAAe,oBAAoB;IAC/D,MAAM,MAAM,GAAG,IAAA,mCAAyB,EAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClF,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,IAAI;QAChF,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,KAAK;QAC7C,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,IAAI;QAC1D,kBAAkB,EAAG,MAAM,EAAE,kBAAgE,IAAI,cAAc;QAC/G,qBAAqB,EAAG,MAAM,EAAE,qBAAsE,IAAI,MAAM;QAChH,KAAK,EAAE;YACL,8CAA8C;YAC9C,sFAAsF;YACtF,qDAAqD;YACrD,+DAA+D;SAChE;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createAdapter } from './adapter';
|
|
2
|
+
export { OH_MY_PI_PHASE_MAPPINGS, findMapping, getSupportedPhases } from './mappings';
|
|
3
|
+
export { createConfiguredEngine } from './integration';
|
|
4
|
+
export { normalizeOhMyPiEvent, parseEventContext, setAdapterName, ADAPTER_NAME, } from './normalizer';
|
|
5
|
+
export type { OhMyPiEventContext, OhMyPiSessionStartPayload, OhMyPiSessionEndPayload, OhMyPiPromptPayload, OhMyPiToolCallPayload, OhMyPiToolResultPayload, OhMyPiErrorPayload, } from './normalizer';
|
|
6
|
+
export { renderOhMyPiOutput, isFieldSupportedForEvent } from './renderer';
|
|
7
|
+
export { resolveSessionId, deriveSessionId, isValidSessionId } from './session-resolver';
|
|
8
|
+
export type { SessionResolutionResult } from './session-resolver';
|
|
9
|
+
//# 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,uBAAuB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAG1E,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzF,YAAY,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidSessionId = exports.deriveSessionId = exports.resolveSessionId = exports.isFieldSupportedForEvent = exports.renderOhMyPiOutput = exports.ADAPTER_NAME = exports.setAdapterName = exports.parseEventContext = exports.normalizeOhMyPiEvent = exports.createConfiguredEngine = exports.getSupportedPhases = exports.findMapping = exports.OH_MY_PI_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, "OH_MY_PI_PHASE_MAPPINGS", { enumerable: true, get: function () { return mappings_1.OH_MY_PI_PHASE_MAPPINGS; } });
|
|
10
|
+
Object.defineProperty(exports, "findMapping", { enumerable: true, get: function () { return mappings_1.findMapping; } });
|
|
11
|
+
Object.defineProperty(exports, "getSupportedPhases", { enumerable: true, get: function () { return mappings_1.getSupportedPhases; } });
|
|
12
|
+
// Programmatic integration
|
|
13
|
+
var integration_1 = require("./integration");
|
|
14
|
+
Object.defineProperty(exports, "createConfiguredEngine", { enumerable: true, get: function () { return integration_1.createConfiguredEngine; } });
|
|
15
|
+
// Normalizer
|
|
16
|
+
var normalizer_1 = require("./normalizer");
|
|
17
|
+
Object.defineProperty(exports, "normalizeOhMyPiEvent", { enumerable: true, get: function () { return normalizer_1.normalizeOhMyPiEvent; } });
|
|
18
|
+
Object.defineProperty(exports, "parseEventContext", { enumerable: true, get: function () { return normalizer_1.parseEventContext; } });
|
|
19
|
+
Object.defineProperty(exports, "setAdapterName", { enumerable: true, get: function () { return normalizer_1.setAdapterName; } });
|
|
20
|
+
Object.defineProperty(exports, "ADAPTER_NAME", { enumerable: true, get: function () { return normalizer_1.ADAPTER_NAME; } });
|
|
21
|
+
// Renderer
|
|
22
|
+
var renderer_1 = require("./renderer");
|
|
23
|
+
Object.defineProperty(exports, "renderOhMyPiOutput", { enumerable: true, get: function () { return renderer_1.renderOhMyPiOutput; } });
|
|
24
|
+
Object.defineProperty(exports, "isFieldSupportedForEvent", { enumerable: true, get: function () { return renderer_1.isFieldSupportedForEvent; } });
|
|
25
|
+
// Session resolver
|
|
26
|
+
var session_resolver_1 = require("./session-resolver");
|
|
27
|
+
Object.defineProperty(exports, "resolveSessionId", { enumerable: true, get: function () { return session_resolver_1.resolveSessionId; } });
|
|
28
|
+
Object.defineProperty(exports, "deriveSessionId", { enumerable: true, get: function () { return session_resolver_1.deriveSessionId; } });
|
|
29
|
+
Object.defineProperty(exports, "isValidSessionId", { enumerable: true, get: function () { return session_resolver_1.isValidSessionId; } });
|
|
30
|
+
//# 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,uCAAsF;AAA7E,mHAAA,uBAAuB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,8GAAA,kBAAkB,OAAA;AAEjE,2BAA2B;AAC3B,6CAAuD;AAA9C,qHAAA,sBAAsB,OAAA;AAE/B,aAAa;AACb,2CAKsB;AAJpB,kHAAA,oBAAoB,OAAA;AACpB,+GAAA,iBAAiB,OAAA;AACjB,4GAAA,cAAc,OAAA;AACd,0GAAA,YAAY,OAAA;AAYd,WAAW;AACX,uCAA0E;AAAjE,8GAAA,kBAAkB,OAAA;AAAE,oHAAA,wBAAwB,OAAA;AAErD,mBAAmB;AACnB,uDAAyF;AAAhF,oHAAA,gBAAgB,OAAA;AAAE,mHAAA,eAAe,OAAA;AAAE,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic engine integration for the Oh-My-Pi adapter.
|
|
3
|
+
*
|
|
4
|
+
* Creates a pre-configured HooksEngine wired to the Oh-My-Pi adapter's
|
|
5
|
+
* capabilities and phase mappings, ready for in-process hook execution.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createConfiguredEngine } from '@a5c-ai/hooks-adapter-oh-my-pi';
|
|
10
|
+
*
|
|
11
|
+
* const engine = createConfiguredEngine();
|
|
12
|
+
*
|
|
13
|
+
* engine.registerHandler({
|
|
14
|
+
* id: 'my-handler',
|
|
15
|
+
* pluginId: 'my-plugin',
|
|
16
|
+
* phase: 'session.start',
|
|
17
|
+
* priority: 10,
|
|
18
|
+
* handler: async (event) => ({
|
|
19
|
+
* persistEnv: { MY_PLUGIN_READY: '1' },
|
|
20
|
+
* }),
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const result = await engine.processEvent({
|
|
24
|
+
* nativeEventName: 'session_start',
|
|
25
|
+
* payload: { sessionId: 'abc', cwd: '/project' },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { type HooksEngine } from '@a5c-ai/hooks-adapter-core';
|
|
30
|
+
/**
|
|
31
|
+
* Create a pre-configured hooks engine for the Oh-My-Pi adapter.
|
|
32
|
+
* Ready to register handlers and process events.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createConfiguredEngine(options: {
|
|
35
|
+
sessionDir?: string;
|
|
36
|
+
adapterName: string;
|
|
37
|
+
}): HooksEngine;
|
|
38
|
+
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIjF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAQzG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Programmatic engine integration for the Oh-My-Pi adapter.
|
|
4
|
+
*
|
|
5
|
+
* Creates a pre-configured HooksEngine wired to the Oh-My-Pi adapter's
|
|
6
|
+
* capabilities and phase mappings, ready for in-process hook execution.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createConfiguredEngine } from '@a5c-ai/hooks-adapter-oh-my-pi';
|
|
11
|
+
*
|
|
12
|
+
* const engine = createConfiguredEngine();
|
|
13
|
+
*
|
|
14
|
+
* engine.registerHandler({
|
|
15
|
+
* id: 'my-handler',
|
|
16
|
+
* pluginId: 'my-plugin',
|
|
17
|
+
* phase: 'session.start',
|
|
18
|
+
* priority: 10,
|
|
19
|
+
* handler: async (event) => ({
|
|
20
|
+
* persistEnv: { MY_PLUGIN_READY: '1' },
|
|
21
|
+
* }),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const result = await engine.processEvent({
|
|
25
|
+
* nativeEventName: 'session_start',
|
|
26
|
+
* payload: { sessionId: 'abc', cwd: '/project' },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.createConfiguredEngine = createConfiguredEngine;
|
|
32
|
+
const hooks_adapter_core_1 = require("@a5c-ai/hooks-adapter-core");
|
|
33
|
+
const adapter_1 = require("./adapter");
|
|
34
|
+
const mappings_1 = require("./mappings");
|
|
35
|
+
/**
|
|
36
|
+
* Create a pre-configured hooks engine for the Oh-My-Pi adapter.
|
|
37
|
+
* Ready to register handlers and process events.
|
|
38
|
+
*/
|
|
39
|
+
function createConfiguredEngine(options) {
|
|
40
|
+
const name = options.adapterName;
|
|
41
|
+
return (0, hooks_adapter_core_1.createHooksEngine)({
|
|
42
|
+
adapter: name,
|
|
43
|
+
capabilities: (0, adapter_1.createAdapter)(name),
|
|
44
|
+
phaseMappings: mappings_1.OH_MY_PI_PHASE_MAPPINGS,
|
|
45
|
+
sessionDir: options?.sessionDir,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;AAUH,wDAQC;AAhBD,mEAAiF;AACjF,uCAA0C;AAC1C,yCAAqD;AAErD;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,OAAqD;IAC1F,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IACjC,OAAO,IAAA,sCAAiB,EAAC;QACvB,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAA,uBAAa,EAAC,IAAI,CAAC;QACjC,aAAa,EAAE,kCAAuB;QACtC,UAAU,EAAE,OAAO,EAAE,UAAU;KAChC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PhaseMapping } from '@a5c-ai/hooks-adapter-core';
|
|
2
|
+
export declare const OH_MY_PI_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
|
+
/**
|
|
8
|
+
* Get all canonical phases supported by the Oh-My-Pi adapter.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSupportedPhases(): string[];
|
|
11
|
+
//# 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,4BAA4B,CAAC;AAqD/D,eAAO,MAAM,uBAAuB,EAAE,YAAY,EAAuB,CAAC;AAE1E;;GAEG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE7E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C"}
|
package/dist/mappings.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OH_MY_PI_PHASE_MAPPINGS = void 0;
|
|
4
|
+
exports.findMapping = findMapping;
|
|
5
|
+
exports.getSupportedPhases = getSupportedPhases;
|
|
6
|
+
const catalog_1 = require("@a5c-ai/atlas/catalog");
|
|
7
|
+
/**
|
|
8
|
+
* Oh-My-Pi native event to canonical phase mapping table.
|
|
9
|
+
*
|
|
10
|
+
* Phase mappings are built from the Atlas graph HookMapping records
|
|
11
|
+
* via the agent-catalog. Falls back to hardcoded defaults if the
|
|
12
|
+
* catalog is unavailable.
|
|
13
|
+
*
|
|
14
|
+
* Spec section 17.7.
|
|
15
|
+
*/
|
|
16
|
+
const SUPPORT_LEVEL_MAP = {
|
|
17
|
+
supported: 'native',
|
|
18
|
+
native: 'native',
|
|
19
|
+
lossy: 'lossy',
|
|
20
|
+
emulated: 'emulated',
|
|
21
|
+
unsupported: 'unsupported',
|
|
22
|
+
};
|
|
23
|
+
function hookMappingToPhaseMapping(mapping) {
|
|
24
|
+
if (!mapping.canonicalPhase)
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
canonicalPhase: mapping.canonicalPhase,
|
|
28
|
+
nativeHook: mapping.nativeName,
|
|
29
|
+
supportLevel: SUPPORT_LEVEL_MAP[mapping.supportLevel] ?? 'native',
|
|
30
|
+
blockCapability: mapping.blockCapability ?? false,
|
|
31
|
+
mutationCapability: mapping.mutationCapability ?? false,
|
|
32
|
+
scope: (mapping.scope ?? 'session'),
|
|
33
|
+
notes: mapping.nativeName === 'tool_call'
|
|
34
|
+
? 'Mutation is NOT supported by Oh-My-Pi tool_call hooks.'
|
|
35
|
+
: undefined,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function buildFromCatalog() {
|
|
39
|
+
const mappings = (0, catalog_1.listHookMappingsByAdapterFamily)('oh-my-pi');
|
|
40
|
+
if (mappings.length === 0) {
|
|
41
|
+
throw new Error('hooks-adapter adapter-oh-my-pi: catalog unavailable or returned no mappings for family "oh-my-pi"');
|
|
42
|
+
}
|
|
43
|
+
const phaseMappings = mappings
|
|
44
|
+
.map(hookMappingToPhaseMapping)
|
|
45
|
+
.filter((m) => m !== null);
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
return phaseMappings.filter((m) => {
|
|
48
|
+
if (seen.has(m.nativeHook))
|
|
49
|
+
return false;
|
|
50
|
+
seen.add(m.nativeHook);
|
|
51
|
+
return true;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.OH_MY_PI_PHASE_MAPPINGS = buildFromCatalog();
|
|
55
|
+
/**
|
|
56
|
+
* Quick lookup from native event name to phase mapping.
|
|
57
|
+
*/
|
|
58
|
+
function findMapping(nativeEventName) {
|
|
59
|
+
return exports.OH_MY_PI_PHASE_MAPPINGS.find((m) => m.nativeHook === nativeEventName);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get all canonical phases supported by the Oh-My-Pi adapter.
|
|
63
|
+
*/
|
|
64
|
+
function getSupportedPhases() {
|
|
65
|
+
return exports.OH_MY_PI_PHASE_MAPPINGS.map((m) => m.canonicalPhase);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=mappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappings.js","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":";;;AA0DA,kCAEC;AAKD,gDAEC;AAlED,mDAAwE;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,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,QAAQ;QACjE,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,KAAK;QACjD,kBAAkB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;AAC9D,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type UnifiedHookEvent } from '@a5c-ai/hooks-adapter-core';
|
|
2
|
+
/** The default adapter identifier used in all normalized events. */
|
|
3
|
+
export declare const ADAPTER_NAME = "oh-my-pi";
|
|
4
|
+
/** Override the adapter name used in normalized events. */
|
|
5
|
+
export declare function setAdapterName(name: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Common fields that may be present on Oh-My-Pi extension event contexts.
|
|
8
|
+
* Oh-My-Pi events are delivered in-process as typed objects, not stdin.
|
|
9
|
+
*/
|
|
10
|
+
export interface OhMyPiEventContext {
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
workspace?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** session_start-specific fields. */
|
|
18
|
+
export interface OhMyPiSessionStartPayload extends OhMyPiEventContext {
|
|
19
|
+
source?: string;
|
|
20
|
+
}
|
|
21
|
+
/** session_end-specific fields. */
|
|
22
|
+
export interface OhMyPiSessionEndPayload extends OhMyPiEventContext {
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
25
|
+
/** prompt-specific fields. */
|
|
26
|
+
export interface OhMyPiPromptPayload extends OhMyPiEventContext {
|
|
27
|
+
text?: string;
|
|
28
|
+
}
|
|
29
|
+
/** tool_call-specific fields. */
|
|
30
|
+
export interface OhMyPiToolCallPayload extends OhMyPiEventContext {
|
|
31
|
+
tool_name?: string;
|
|
32
|
+
tool_call_id?: string;
|
|
33
|
+
tool_input?: unknown;
|
|
34
|
+
}
|
|
35
|
+
/** tool_result-specific fields. */
|
|
36
|
+
export interface OhMyPiToolResultPayload extends OhMyPiEventContext {
|
|
37
|
+
tool_name?: string;
|
|
38
|
+
tool_call_id?: string;
|
|
39
|
+
tool_input?: unknown;
|
|
40
|
+
tool_result?: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** error-specific fields. */
|
|
43
|
+
export interface OhMyPiErrorPayload extends OhMyPiEventContext {
|
|
44
|
+
error?: string;
|
|
45
|
+
code?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse raw event context into a typed object.
|
|
49
|
+
* Oh-My-Pi events are delivered in-process as objects, but we
|
|
50
|
+
* handle string/null/undefined gracefully for robustness.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseEventContext(raw: unknown): Record<string, unknown>;
|
|
53
|
+
/**
|
|
54
|
+
* Normalize a raw Oh-My-Pi extension event into a UnifiedHookEvent.
|
|
55
|
+
*
|
|
56
|
+
* Oh-My-Pi is a library-only adapter. Events arrive as in-process
|
|
57
|
+
* objects from the Pi extension API, not via stdin. The normalizer:
|
|
58
|
+
* - Parses event context gracefully
|
|
59
|
+
* - Enriches env from context fields
|
|
60
|
+
* - Extracts native session ID when available
|
|
61
|
+
* - Annotates events with mutability limitation metadata
|
|
62
|
+
*
|
|
63
|
+
* @param rawEventName - The native Oh-My-Pi event name (e.g. 'session_start', 'tool_call')
|
|
64
|
+
* @param eventContext - In-process event context object
|
|
65
|
+
* @param env - Environment variables at invocation time
|
|
66
|
+
*/
|
|
67
|
+
export declare function normalizeOhMyPiEvent(rawEventName: string, eventContext: unknown, env?: Record<string, string>): UnifiedHookEvent;
|
|
68
|
+
//# 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,4BAA4B,CAAC;AAG1G,oEAAoE;AACpE,eAAO,MAAM,YAAY,aAAa,CAAC;AAKvC,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,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yDlB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADAPTER_NAME = void 0;
|
|
4
|
+
exports.setAdapterName = setAdapterName;
|
|
5
|
+
exports.parseEventContext = parseEventContext;
|
|
6
|
+
exports.normalizeOhMyPiEvent = normalizeOhMyPiEvent;
|
|
7
|
+
const hooks_adapter_core_1 = require("@a5c-ai/hooks-adapter-core");
|
|
8
|
+
const mappings_1 = require("./mappings");
|
|
9
|
+
/** The default adapter identifier used in all normalized events. */
|
|
10
|
+
exports.ADAPTER_NAME = 'oh-my-pi';
|
|
11
|
+
/** Mutable adapter name, defaulting to the oh-my-pi adapter identity. */
|
|
12
|
+
let _adapterName = 'oh-my-pi';
|
|
13
|
+
/** Override the adapter name used in normalized events. */
|
|
14
|
+
function setAdapterName(name) {
|
|
15
|
+
_adapterName = name;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse raw event context into a typed object.
|
|
19
|
+
* Oh-My-Pi events are delivered in-process as objects, but we
|
|
20
|
+
* handle string/null/undefined gracefully for robustness.
|
|
21
|
+
*/
|
|
22
|
+
function parseEventContext(raw) {
|
|
23
|
+
if (raw == null)
|
|
24
|
+
return {};
|
|
25
|
+
if (typeof raw === 'string') {
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(raw);
|
|
28
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// fail open for robustness
|
|
34
|
+
}
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
if (typeof raw === 'object' && !Array.isArray(raw)) {
|
|
38
|
+
return raw;
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract tool metadata from a tool_call/tool_result event context.
|
|
44
|
+
*/
|
|
45
|
+
function extractToolFields(ctx) {
|
|
46
|
+
const fields = {};
|
|
47
|
+
if (typeof ctx['tool_name'] === 'string') {
|
|
48
|
+
fields['HOOKS_PROXY_TOOL_NAME'] = ctx['tool_name'];
|
|
49
|
+
}
|
|
50
|
+
if (typeof ctx['tool_call_id'] === 'string') {
|
|
51
|
+
fields['HOOKS_PROXY_TOOL_CALL_ID'] = ctx['tool_call_id'];
|
|
52
|
+
}
|
|
53
|
+
return fields;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Normalize a raw Oh-My-Pi extension event into a UnifiedHookEvent.
|
|
57
|
+
*
|
|
58
|
+
* Oh-My-Pi is a library-only adapter. Events arrive as in-process
|
|
59
|
+
* objects from the Pi extension API, not via stdin. The normalizer:
|
|
60
|
+
* - Parses event context gracefully
|
|
61
|
+
* - Enriches env from context fields
|
|
62
|
+
* - Extracts native session ID when available
|
|
63
|
+
* - Annotates events with mutability limitation metadata
|
|
64
|
+
*
|
|
65
|
+
* @param rawEventName - The native Oh-My-Pi event name (e.g. 'session_start', 'tool_call')
|
|
66
|
+
* @param eventContext - In-process event context object
|
|
67
|
+
* @param env - Environment variables at invocation time
|
|
68
|
+
*/
|
|
69
|
+
function normalizeOhMyPiEvent(rawEventName, eventContext, env = {}) {
|
|
70
|
+
const parsed = parseEventContext(eventContext);
|
|
71
|
+
// Enrich env with Oh-My-Pi-specific fields extracted from context
|
|
72
|
+
const enrichedEnv = { ...env };
|
|
73
|
+
// Oh-My-Pi provides native session IDs via the Pi runtime
|
|
74
|
+
if (typeof parsed['sessionId'] === 'string' && !enrichedEnv['HOOKS_PROXY_SESSION_ID']) {
|
|
75
|
+
enrichedEnv['HOOKS_PROXY_SESSION_ID'] = parsed['sessionId'];
|
|
76
|
+
}
|
|
77
|
+
if (typeof parsed['cwd'] === 'string' && !enrichedEnv['HOOKS_PROXY_CWD']) {
|
|
78
|
+
enrichedEnv['HOOKS_PROXY_CWD'] = parsed['cwd'];
|
|
79
|
+
}
|
|
80
|
+
if (typeof parsed['workspace'] === 'string' && !enrichedEnv['HOOKS_PROXY_WORKTREE']) {
|
|
81
|
+
enrichedEnv['HOOKS_PROXY_WORKTREE'] = parsed['workspace'];
|
|
82
|
+
}
|
|
83
|
+
if (typeof parsed['model'] === 'string' && !enrichedEnv['HOOKS_PROXY_MODEL']) {
|
|
84
|
+
enrichedEnv['HOOKS_PROXY_MODEL'] = parsed['model'];
|
|
85
|
+
}
|
|
86
|
+
if (typeof parsed['source'] === 'string' && !enrichedEnv['HOOKS_PROXY_SOURCE']) {
|
|
87
|
+
enrichedEnv['HOOKS_PROXY_SOURCE'] = parsed['source'];
|
|
88
|
+
}
|
|
89
|
+
// Tool-specific env enrichment
|
|
90
|
+
if (rawEventName === 'tool_call' || rawEventName === 'tool_result') {
|
|
91
|
+
const toolFields = extractToolFields(parsed);
|
|
92
|
+
for (const [k, v] of Object.entries(toolFields)) {
|
|
93
|
+
if (!enrichedEnv[k]) {
|
|
94
|
+
enrichedEnv[k] = v;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const options = {
|
|
99
|
+
adapter: _adapterName,
|
|
100
|
+
rawEventName,
|
|
101
|
+
stdinPayload: parsed,
|
|
102
|
+
env: enrichedEnv,
|
|
103
|
+
adapterMappings: mappings_1.OH_MY_PI_PHASE_MAPPINGS,
|
|
104
|
+
};
|
|
105
|
+
const event = (0, hooks_adapter_core_1.normalizeEvent)(options);
|
|
106
|
+
// Annotate with Oh-My-Pi-specific metadata
|
|
107
|
+
event.execution.metadata = {
|
|
108
|
+
...event.execution.metadata,
|
|
109
|
+
adapterFamily: 'in-process',
|
|
110
|
+
supportsToolInputMutation: false,
|
|
111
|
+
chainedContext: true,
|
|
112
|
+
sessionBeforeShortCircuit: true,
|
|
113
|
+
};
|
|
114
|
+
return event;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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C,WAAW,CAAC,oBAAoB,CAAC,EAAE,CAAC;QAC/E,WAAW,CAAC,oBAAoB,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,KAAK,WAAW,IAAI,YAAY,KAAK,aAAa,EAAE,CAAC;QACnE,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC7C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAChD,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAqB;QAChC,OAAO,EAAE,YAAY;QACrB,YAAY;QACZ,YAAY,EAAE,MAAM;QACpB,GAAG,EAAE,WAAW;QAChB,eAAe,EAAE,kCAAuB;KACzC,CAAC;IAEF,MAAM,KAAK,GAAG,IAAA,mCAAc,EAAC,OAAO,CAAC,CAAC;IAEtC,2CAA2C;IAC3C,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG;QACzB,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ;QAC3B,aAAa,EAAE,YAAY;QAC3B,yBAAyB,EAAE,KAAK;QAChC,cAAc,EAAE,IAAI;QACpB,yBAAyB,EAAE,IAAI;KAChC,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MergedExecutionResult } from '@a5c-ai/hooks-adapter-core';
|
|
2
|
+
/**
|
|
3
|
+
* Render a merged execution result into Oh-My-Pi native output.
|
|
4
|
+
*
|
|
5
|
+
* Only includes fields that are meaningful for the given native event
|
|
6
|
+
* type. Unsupported fields are silently dropped. Tool input mutation
|
|
7
|
+
* is never emitted (explicit Oh-My-Pi limitation).
|
|
8
|
+
*
|
|
9
|
+
* @param mergedResult - The merged result from multi-hook fan-out
|
|
10
|
+
* @param nativeEventName - The original Oh-My-Pi event name
|
|
11
|
+
* @returns Oh-My-Pi native output object, and list of dropped fields
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderOhMyPiOutput(mergedResult: MergedExecutionResult, nativeEventName: string): {
|
|
14
|
+
output: Record<string, unknown>;
|
|
15
|
+
droppedFields: string[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Check whether a given output field is supported for a native event.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isFieldSupportedForEvent(field: string, nativeEventName: string): boolean;
|
|
21
|
+
//# 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,4BAA4B,CAAC;AAsExE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,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,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderOhMyPiOutput = renderOhMyPiOutput;
|
|
4
|
+
exports.isFieldSupportedForEvent = isFieldSupportedForEvent;
|
|
5
|
+
/**
|
|
6
|
+
* Oh-My-Pi native output fields that are supported per event type.
|
|
7
|
+
*
|
|
8
|
+
* Oh-My-Pi is an in-process adapter. Output is returned directly
|
|
9
|
+
* to the Pi extension runtime, not written to stdout. Only emit
|
|
10
|
+
* fields that are meaningful for the Pi extension API to process.
|
|
11
|
+
*
|
|
12
|
+
* Spec section 17.7: Oh-My-Pi does not support tool input mutation,
|
|
13
|
+
* so toolMutation fields are never emitted.
|
|
14
|
+
*/
|
|
15
|
+
/** Output fields supported on session_start. */
|
|
16
|
+
const SESSION_START_FIELDS = new Set([
|
|
17
|
+
'reason',
|
|
18
|
+
'additionalContext',
|
|
19
|
+
]);
|
|
20
|
+
/** Output fields supported on session_end (observer-only). */
|
|
21
|
+
const SESSION_END_FIELDS = new Set([
|
|
22
|
+
'reason',
|
|
23
|
+
]);
|
|
24
|
+
/** Output fields supported on prompt. */
|
|
25
|
+
const PROMPT_FIELDS = new Set([
|
|
26
|
+
'reason',
|
|
27
|
+
'additionalContext',
|
|
28
|
+
]);
|
|
29
|
+
/** Output fields supported on tool_call (no mutation). */
|
|
30
|
+
const TOOL_CALL_FIELDS = new Set([
|
|
31
|
+
'reason',
|
|
32
|
+
]);
|
|
33
|
+
/** Output fields supported on tool_result. */
|
|
34
|
+
const TOOL_RESULT_FIELDS = new Set([
|
|
35
|
+
'reason',
|
|
36
|
+
]);
|
|
37
|
+
/** Output fields supported on error. */
|
|
38
|
+
const ERROR_FIELDS = new Set([
|
|
39
|
+
'reason',
|
|
40
|
+
]);
|
|
41
|
+
/** Output fields supported on context. */
|
|
42
|
+
const CONTEXT_FIELDS = new Set([
|
|
43
|
+
'reason',
|
|
44
|
+
'additionalContext',
|
|
45
|
+
]);
|
|
46
|
+
/** Output fields supported on before_provider_request. */
|
|
47
|
+
const BEFORE_PROVIDER_REQUEST_FIELDS = new Set([
|
|
48
|
+
'reason',
|
|
49
|
+
'additionalContext',
|
|
50
|
+
'systemMessage',
|
|
51
|
+
]);
|
|
52
|
+
/** Map native event names to their supported output field sets. */
|
|
53
|
+
const SUPPORTED_FIELDS_BY_EVENT = {
|
|
54
|
+
session_start: SESSION_START_FIELDS,
|
|
55
|
+
session_end: SESSION_END_FIELDS,
|
|
56
|
+
prompt: PROMPT_FIELDS,
|
|
57
|
+
tool_call: TOOL_CALL_FIELDS,
|
|
58
|
+
tool_result: TOOL_RESULT_FIELDS,
|
|
59
|
+
error: ERROR_FIELDS,
|
|
60
|
+
context: CONTEXT_FIELDS,
|
|
61
|
+
before_provider_request: BEFORE_PROVIDER_REQUEST_FIELDS,
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Render a merged execution result into Oh-My-Pi native output.
|
|
65
|
+
*
|
|
66
|
+
* Only includes fields that are meaningful for the given native event
|
|
67
|
+
* type. Unsupported fields are silently dropped. Tool input mutation
|
|
68
|
+
* is never emitted (explicit Oh-My-Pi limitation).
|
|
69
|
+
*
|
|
70
|
+
* @param mergedResult - The merged result from multi-hook fan-out
|
|
71
|
+
* @param nativeEventName - The original Oh-My-Pi event name
|
|
72
|
+
* @returns Oh-My-Pi native output object, and list of dropped fields
|
|
73
|
+
*/
|
|
74
|
+
function renderOhMyPiOutput(mergedResult, nativeEventName) {
|
|
75
|
+
const supportedFields = SUPPORTED_FIELDS_BY_EVENT[nativeEventName] ?? new Set();
|
|
76
|
+
const output = {};
|
|
77
|
+
const droppedFields = [];
|
|
78
|
+
// Candidate output fields from the merged result
|
|
79
|
+
const candidates = [
|
|
80
|
+
{ key: 'decision', value: mergedResult.decision, isEmpty: mergedResult.decision === 'noop' },
|
|
81
|
+
{ key: 'reason', value: mergedResult.reason, isEmpty: !mergedResult.reason },
|
|
82
|
+
{ key: 'additionalContext', value: mergedResult.additionalContext, isEmpty: !mergedResult.additionalContext },
|
|
83
|
+
{ key: 'systemMessage', value: mergedResult.systemMessage, isEmpty: !mergedResult.systemMessage },
|
|
84
|
+
{ key: 'continueSession', value: mergedResult.continueSession, isEmpty: mergedResult.continueSession === true },
|
|
85
|
+
{ key: 'stopReason', value: mergedResult.stopReason, isEmpty: !mergedResult.stopReason },
|
|
86
|
+
];
|
|
87
|
+
for (const candidate of candidates) {
|
|
88
|
+
if (candidate.isEmpty)
|
|
89
|
+
continue;
|
|
90
|
+
if (supportedFields.has(candidate.key)) {
|
|
91
|
+
output[candidate.key] = candidate.value;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
droppedFields.push(candidate.key);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { output, droppedFields };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check whether a given output field is supported for a native event.
|
|
101
|
+
*/
|
|
102
|
+
function isFieldSupportedForEvent(field, nativeEventName) {
|
|
103
|
+
const supported = SUPPORTED_FIELDS_BY_EVENT[nativeEventName];
|
|
104
|
+
return supported ? supported.has(field) : false;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;AAiFA,gDA6BC;AAKD,4DAGC;AApHD;;;;;;;;;GASG;AAEH,gDAAgD;AAChD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,QAAQ;IACR,mBAAmB;CACpB,CAAC,CAAC;AAEH,8DAA8D;AAC9D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,QAAQ;CACT,CAAC,CAAC;AAEH,yCAAyC;AACzC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,QAAQ;IACR,mBAAmB;CACpB,CAAC,CAAC;AAEH,0DAA0D;AAC1D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,QAAQ;CACT,CAAC,CAAC;AAEH,8CAA8C;AAC9C,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,QAAQ;CACT,CAAC,CAAC;AAEH,wCAAwC;AACxC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,QAAQ;CACT,CAAC,CAAC;AAEH,0CAA0C;AAC1C,MAAM,cAAc,GA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AE,KAAK,EAAE,YAAY,CAAC,eAAe,EAAE,OAAO,EAAE,YAAY,CAAC,eAAe,KAAK,IAAI,EAAE;QAC/G,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE;KACzF,CAAC;IAEF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,CAAC,OAAO;YAAE,SAAS;QAEhC,IAAI,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,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,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve session ID from Oh-My-Pi extension event context.
|
|
3
|
+
*
|
|
4
|
+
* Oh-My-Pi provides NATIVE session IDs via the Pi runtime, giving
|
|
5
|
+
* it 'native' sessionIdQuality in the capability model. When
|
|
6
|
+
* a native session ID is not available, derivation from workspace
|
|
7
|
+
* or cwd is used as a fallback.
|
|
8
|
+
*
|
|
9
|
+
* Resolution precedence (per spec 9.2):
|
|
10
|
+
* 1. Explicit AGENT_SESSION_ID env var
|
|
11
|
+
* 2. Native sessionId from event context (Pi runtime)
|
|
12
|
+
* 3. OMP_SESSION_ID env var (harness-specific)
|
|
13
|
+
* 4. Derived from workspace or cwd via stable hash
|
|
14
|
+
* 5. null (no session available)
|
|
15
|
+
*/
|
|
16
|
+
export interface SessionResolutionResult {
|
|
17
|
+
sessionId: string | null;
|
|
18
|
+
source: 'explicit_env' | 'native' | 'harness_env' | 'derived' | 'none';
|
|
19
|
+
/** Whether the ID was derived (hashed) rather than provided natively. */
|
|
20
|
+
isDerived: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the session ID for an Oh-My-Pi extension event.
|
|
24
|
+
*
|
|
25
|
+
* @param eventContext - Parsed event context object from the Pi extension API
|
|
26
|
+
* @param env - Environment variables at invocation time
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveSessionId(eventContext: Record<string, unknown>, env?: Record<string, string>): SessionResolutionResult;
|
|
29
|
+
/**
|
|
30
|
+
* Derive a stable session ID from a workspace or directory path.
|
|
31
|
+
* Uses a truncated SHA-256 hash prefixed with 'omp-' for identifiability.
|
|
32
|
+
*/
|
|
33
|
+
export declare function deriveSessionId(path: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Validate that a session ID looks reasonable.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isValidSessionId(sessionId: string): boolean;
|
|
38
|
+
//# 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":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,cAAc,GAAG,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,MAAM,CAAC;IACvE,yEAAyE;IACzE,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,uBAAuB,CAmCzB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSessionId = resolveSessionId;
|
|
4
|
+
exports.deriveSessionId = deriveSessionId;
|
|
5
|
+
exports.isValidSessionId = isValidSessionId;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the session ID for an Oh-My-Pi extension event.
|
|
9
|
+
*
|
|
10
|
+
* @param eventContext - Parsed event context object from the Pi extension API
|
|
11
|
+
* @param env - Environment variables at invocation time
|
|
12
|
+
*/
|
|
13
|
+
function resolveSessionId(eventContext, env = {}) {
|
|
14
|
+
// Priority 1: explicit env override
|
|
15
|
+
const explicit = env['AGENT_SESSION_ID'];
|
|
16
|
+
if (typeof explicit === 'string' && explicit.length > 0) {
|
|
17
|
+
return { sessionId: explicit, source: 'explicit_env', isDerived: false };
|
|
18
|
+
}
|
|
19
|
+
// Priority 2: native session ID from event context (Pi runtime)
|
|
20
|
+
const nativeSessionId = eventContext['sessionId'];
|
|
21
|
+
if (typeof nativeSessionId === 'string' && nativeSessionId.length > 0) {
|
|
22
|
+
return { sessionId: nativeSessionId, source: 'native', isDerived: false };
|
|
23
|
+
}
|
|
24
|
+
// Priority 3: harness-specific env var
|
|
25
|
+
const harnessEnv = env['OMP_SESSION_ID'];
|
|
26
|
+
if (typeof harnessEnv === 'string' && harnessEnv.length > 0) {
|
|
27
|
+
return { sessionId: harnessEnv, source: 'harness_env', isDerived: false };
|
|
28
|
+
}
|
|
29
|
+
// Priority 4: derive from workspace or cwd
|
|
30
|
+
const workspace = typeof eventContext['workspace'] === 'string'
|
|
31
|
+
? eventContext['workspace']
|
|
32
|
+
: undefined;
|
|
33
|
+
const cwd = typeof eventContext['cwd'] === 'string'
|
|
34
|
+
? eventContext['cwd']
|
|
35
|
+
: env['PWD'] ?? env['HOMEDRIVE'] ?? undefined;
|
|
36
|
+
const derivationSource = workspace ?? cwd;
|
|
37
|
+
if (derivationSource) {
|
|
38
|
+
const derived = deriveSessionId(derivationSource);
|
|
39
|
+
return { sessionId: derived, source: 'derived', isDerived: true };
|
|
40
|
+
}
|
|
41
|
+
// Priority 5: no session
|
|
42
|
+
return { sessionId: null, source: 'none', isDerived: false };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Derive a stable session ID from a workspace or directory path.
|
|
46
|
+
* Uses a truncated SHA-256 hash prefixed with 'omp-' for identifiability.
|
|
47
|
+
*/
|
|
48
|
+
function deriveSessionId(path) {
|
|
49
|
+
const hash = (0, crypto_1.createHash)('sha256').update(path).digest('hex').slice(0, 16);
|
|
50
|
+
return `omp-${hash}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validate that a session ID looks reasonable.
|
|
54
|
+
*/
|
|
55
|
+
function isValidSessionId(sessionId) {
|
|
56
|
+
return sessionId.length > 0 && sessionId.length <= 256;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=session-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-resolver.js","sourceRoot":"","sources":["../src/session-resolver.ts"],"names":[],"mappings":";;AA+BA,4CAsCC;AAMD,0CAGC;AAKD,4CAEC;AArFD,mCAAoC;AAyBpC;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,YAAqC,EACrC,MAA8B,EAAE;IAEhC,oCAAoC;IACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACzC,IAAI,OAAO,QAAQ,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AO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpE,CAAC;IAED,yBAAyB;IACzB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,IAAY;IAC1C,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1E,OAAO,OAAO,IAAI,EAAE,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAiB;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-adapter-oh-my-pi",
|
|
3
|
+
"version": "5.1.1-staging.52898ebfc24f",
|
|
4
|
+
"description": "oh-my-pi harness adapter for the hooks-adapter 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/adapters/hooks/adapter-oh-my-pi"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/a5c-ai/babysitter/tree/main/packages/adapters/hooks/adapter-oh-my-pi#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-adapter-core": "5.1.1-staging.52898ebfc24f"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"rimraf": "^6.0.0",
|
|
37
|
+
"typescript": "^5.7.0",
|
|
38
|
+
"vitest": "^4.1.8"
|
|
39
|
+
}
|
|
40
|
+
}
|