@a5c-ai/hooks-mux-adapter-pi 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 +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +39 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +49 -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 +64 -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 +150 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/renderer.d.ts +55 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +91 -0
- package/dist/renderer.js.map +1 -0
- package/dist/session-resolver.d.ts +26 -0
- package/dist/session-resolver.d.ts.map +1 -0
- package/dist/session-resolver.js +47 -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-pi
|
|
2
|
+
|
|
3
|
+
Pi harness adapter for hooks-mux.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @a5c-ai/hooks-mux-adapter-pi @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
|
+
createConfiguredEngine,
|
|
19
|
+
normalizePi,
|
|
20
|
+
} from "@a5c-ai/hooks-mux-adapter-pi";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The package exposes Pi-specific normalization, phase mappings, session helpers, rendering utilities, and an in-process configured engine for hooks-mux integrations.
|
|
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 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.6.
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_ADAPTER_NAME = 'pi';
|
|
14
|
+
function createAdapter(name = DEFAULT_ADAPTER_NAME) {
|
|
15
|
+
const target = (0, agent_catalog_1.getPluginTargetDescriptor)(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 ?? false,
|
|
22
|
+
supportsBlock: target?.supportsBlock ?? true,
|
|
23
|
+
supportsAsk: target?.supportsAsk ?? false,
|
|
24
|
+
supportsToolInputMutation: target?.supportsToolInputMutation ?? true,
|
|
25
|
+
supportsToolResultMutation: target?.supportsToolResultMutation ?? false,
|
|
26
|
+
supportsPersistedEnv: target?.supportsPersistedEnv ?? true,
|
|
27
|
+
envPersistenceMode: target?.envPersistenceMode ?? 'runtime_hook',
|
|
28
|
+
toolInterceptionScope: target?.toolInterceptionScope ?? 'all',
|
|
29
|
+
notes: [
|
|
30
|
+
'Library-only adapter — Pi hooks are in-process, not shell subprocesses',
|
|
31
|
+
'Tool input mutation is in-place; later handlers see earlier mutations',
|
|
32
|
+
'Session persistence via native extension-state; does not automatically enter model context',
|
|
33
|
+
'No stdin parsing required — input arrives as programmatic objects',
|
|
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,IAAI,CAAC;AAElC,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,IAAI;QACpE,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,KAAK;QAC/G,KAAK,EAAE;YACL,wEAAwE;YACxE,uEAAuE;YACvE,4FAA4F;YAC5F,mEAAmE;SACpE;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createAdapter } from './adapter';
|
|
2
|
+
export { PI_PHASE_MAPPINGS, getPiPhaseMapping, getSupportedPhases } from './mappings';
|
|
3
|
+
export { createConfiguredEngine } from './integration';
|
|
4
|
+
export { normalizePi, coerceInput, buildExecutionContext, buildPayload, setAdapterName } from './normalizer';
|
|
5
|
+
export type { PiEventBase, PiSessionStartPayload, PiToolCallPayload, PiContextPayload, PiBeforeProviderRequestPayload, } from './normalizer';
|
|
6
|
+
export { renderPiOutput, buildExtensionState } from './renderer';
|
|
7
|
+
export type { PiToolCallOutput, PiSessionStartOutput, PiContextOutput, PiBeforeProviderRequestOutput, PiGenericOutput, } from './renderer';
|
|
8
|
+
export { resolveSessionId } from './session-resolver';
|
|
9
|
+
export type { SessionResolutionResult } from './session-resolver';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,qBAAqB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7G,YAAY,EACV,WAAW,EACX,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,8BAA8B,GAC/B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,6BAA6B,EAC7B,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSessionId = exports.buildExtensionState = exports.renderPiOutput = exports.setAdapterName = exports.buildPayload = exports.buildExecutionContext = exports.coerceInput = exports.normalizePi = exports.createConfiguredEngine = exports.getSupportedPhases = exports.getPiPhaseMapping = exports.PI_PHASE_MAPPINGS = exports.createAdapter = void 0;
|
|
4
|
+
var adapter_1 = require("./adapter");
|
|
5
|
+
Object.defineProperty(exports, "createAdapter", { enumerable: true, get: function () { return adapter_1.createAdapter; } });
|
|
6
|
+
var mappings_1 = require("./mappings");
|
|
7
|
+
Object.defineProperty(exports, "PI_PHASE_MAPPINGS", { enumerable: true, get: function () { return mappings_1.PI_PHASE_MAPPINGS; } });
|
|
8
|
+
Object.defineProperty(exports, "getPiPhaseMapping", { enumerable: true, get: function () { return mappings_1.getPiPhaseMapping; } });
|
|
9
|
+
Object.defineProperty(exports, "getSupportedPhases", { enumerable: true, get: function () { return mappings_1.getSupportedPhases; } });
|
|
10
|
+
var integration_1 = require("./integration");
|
|
11
|
+
Object.defineProperty(exports, "createConfiguredEngine", { enumerable: true, get: function () { return integration_1.createConfiguredEngine; } });
|
|
12
|
+
var normalizer_1 = require("./normalizer");
|
|
13
|
+
Object.defineProperty(exports, "normalizePi", { enumerable: true, get: function () { return normalizer_1.normalizePi; } });
|
|
14
|
+
Object.defineProperty(exports, "coerceInput", { enumerable: true, get: function () { return normalizer_1.coerceInput; } });
|
|
15
|
+
Object.defineProperty(exports, "buildExecutionContext", { enumerable: true, get: function () { return normalizer_1.buildExecutionContext; } });
|
|
16
|
+
Object.defineProperty(exports, "buildPayload", { enumerable: true, get: function () { return normalizer_1.buildPayload; } });
|
|
17
|
+
Object.defineProperty(exports, "setAdapterName", { enumerable: true, get: function () { return normalizer_1.setAdapterName; } });
|
|
18
|
+
var renderer_1 = require("./renderer");
|
|
19
|
+
Object.defineProperty(exports, "renderPiOutput", { enumerable: true, get: function () { return renderer_1.renderPiOutput; } });
|
|
20
|
+
Object.defineProperty(exports, "buildExtensionState", { enumerable: true, get: function () { return renderer_1.buildExtensionState; } });
|
|
21
|
+
var session_resolver_1 = require("./session-resolver");
|
|
22
|
+
Object.defineProperty(exports, "resolveSessionId", { enumerable: true, get: function () { return session_resolver_1.resolveSessionId; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,uCAAsF;AAA7E,6GAAA,iBAAiB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,8GAAA,kBAAkB,OAAA;AACjE,6CAAuD;AAA9C,qHAAA,sBAAsB,OAAA;AAC/B,2CAA6G;AAApG,yGAAA,WAAW,OAAA;AAAE,yGAAA,WAAW,OAAA;AAAE,mHAAA,qBAAqB,OAAA;AAAE,0GAAA,YAAY,OAAA;AAAE,4GAAA,cAAc,OAAA;AAQtF,uCAAiE;AAAxD,0GAAA,cAAc,OAAA;AAAE,+GAAA,mBAAmB,OAAA;AAQ5C,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic engine integration for the Pi adapter.
|
|
3
|
+
*
|
|
4
|
+
* Creates a pre-configured HooksEngine wired to the 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-mux-adapter-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
|
+
* // When Pi fires a session_start event:
|
|
24
|
+
* const result = await engine.processEvent({
|
|
25
|
+
* nativeEventName: 'session_start',
|
|
26
|
+
* payload: { sessionId: 'abc', cwd: '/project' },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import { type HooksEngine } from '@a5c-ai/hooks-mux-core';
|
|
31
|
+
/**
|
|
32
|
+
* Create a pre-configured hooks engine for the Pi adapter.
|
|
33
|
+
* Ready to register handlers and process events.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createConfiguredEngine(options: {
|
|
36
|
+
sessionDir?: string;
|
|
37
|
+
adapterName: string;
|
|
38
|
+
}): HooksEngine;
|
|
39
|
+
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAI7E;;;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,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Programmatic engine integration for the Pi adapter.
|
|
4
|
+
*
|
|
5
|
+
* Creates a pre-configured HooksEngine wired to the 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-mux-adapter-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
|
+
* // When Pi fires a session_start event:
|
|
25
|
+
* const result = await engine.processEvent({
|
|
26
|
+
* nativeEventName: 'session_start',
|
|
27
|
+
* payload: { sessionId: 'abc', cwd: '/project' },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.createConfiguredEngine = createConfiguredEngine;
|
|
33
|
+
const hooks_mux_core_1 = require("@a5c-ai/hooks-mux-core");
|
|
34
|
+
const adapter_1 = require("./adapter");
|
|
35
|
+
const mappings_1 = require("./mappings");
|
|
36
|
+
/**
|
|
37
|
+
* Create a pre-configured hooks engine for the Pi adapter.
|
|
38
|
+
* Ready to register handlers and process events.
|
|
39
|
+
*/
|
|
40
|
+
function createConfiguredEngine(options) {
|
|
41
|
+
const name = options.adapterName;
|
|
42
|
+
return (0, hooks_mux_core_1.createHooksEngine)({
|
|
43
|
+
adapter: name,
|
|
44
|
+
capabilities: (0, adapter_1.createAdapter)(name),
|
|
45
|
+
phaseMappings: mappings_1.PI_PHASE_MAPPINGS,
|
|
46
|
+
sessionDir: options?.sessionDir,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;AAUH,wDAQC;AAhBD,2DAA6E;AAC7E,uCAA0C;AAC1C,yCAA+C;AAE/C;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,OAAqD;IAC1F,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IACjC,OAAO,IAAA,kCAAiB,EAAC;QACvB,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAA,uBAAa,EAAC,IAAI,CAAC;QACjC,aAAa,EAAE,4BAAiB;QAChC,UAAU,EAAE,OAAO,EAAE,UAAU;KAChC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PhaseMapping } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
export declare const PI_PHASE_MAPPINGS: PhaseMapping[];
|
|
3
|
+
/**
|
|
4
|
+
* Look up the phase mapping for a given Pi native event name.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getPiPhaseMapping(nativeEventName: string): PhaseMapping | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Get all canonical phases supported by the 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,wBAAwB,CAAC;AAkD3D,eAAO,MAAM,iBAAiB,EAAE,YAAY,EAAuB,CAAC;AAEpE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEnF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C"}
|
package/dist/mappings.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PI_PHASE_MAPPINGS = void 0;
|
|
4
|
+
exports.getPiPhaseMapping = getPiPhaseMapping;
|
|
5
|
+
exports.getSupportedPhases = getSupportedPhases;
|
|
6
|
+
const agent_catalog_1 = require("@a5c-ai/agent-catalog");
|
|
7
|
+
/**
|
|
8
|
+
* Pi native event name to canonical phase mappings.
|
|
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 8.2 / 17.6.
|
|
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
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function buildFromCatalog() {
|
|
36
|
+
const mappings = (0, agent_catalog_1.listHookMappingsByAdapterFamily)('pi');
|
|
37
|
+
if (mappings.length === 0) {
|
|
38
|
+
throw new Error('hooks-mux adapter-pi: catalog unavailable or returned no mappings for family "pi"');
|
|
39
|
+
}
|
|
40
|
+
const phaseMappings = mappings
|
|
41
|
+
.map(hookMappingToPhaseMapping)
|
|
42
|
+
.filter((m) => m !== null);
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
return phaseMappings.filter((m) => {
|
|
45
|
+
if (seen.has(m.nativeHook))
|
|
46
|
+
return false;
|
|
47
|
+
seen.add(m.nativeHook);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.PI_PHASE_MAPPINGS = buildFromCatalog();
|
|
52
|
+
/**
|
|
53
|
+
* Look up the phase mapping for a given Pi native event name.
|
|
54
|
+
*/
|
|
55
|
+
function getPiPhaseMapping(nativeEventName) {
|
|
56
|
+
return exports.PI_PHASE_MAPPINGS.find((m) => m.nativeHook === nativeEventName);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get all canonical phases supported by the Pi adapter.
|
|
60
|
+
*/
|
|
61
|
+
function getSupportedPhases() {
|
|
62
|
+
return exports.PI_PHASE_MAPPINGS.map((m) => m.canonicalPhase);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=mappings.js.map
|
|
@@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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,iBAAiB,GAAmB,gBAAgB,EAAE,CAAC;AAEpE;;GAEG;AACH,SAAgB,iBAAiB,CAAC,eAAuB;IACvD,OAAO,yBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,eAAe,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB;IAChC,OAAO,yBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { UnifiedHookEvent, UnifiedExecutionContext } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/** The default adapter name. */
|
|
3
|
+
export declare const ADAPTER_NAME = "pi";
|
|
4
|
+
/** Override the adapter name used in normalized events. */
|
|
5
|
+
export declare function setAdapterName(name: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Pi programmatic event payload shapes.
|
|
8
|
+
*
|
|
9
|
+
* Pi passes hook input as in-process objects (not stdin),
|
|
10
|
+
* so no stdin parsing is needed.
|
|
11
|
+
*/
|
|
12
|
+
/** Common fields present across Pi hook events. */
|
|
13
|
+
export interface PiEventBase {
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
cwd?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** session_start-specific fields. */
|
|
20
|
+
export interface PiSessionStartPayload extends PiEventBase {
|
|
21
|
+
/** Initial prompt or message that started the session. */
|
|
22
|
+
initialPrompt?: string;
|
|
23
|
+
}
|
|
24
|
+
/** tool_call-specific fields. */
|
|
25
|
+
export interface PiToolCallPayload extends PiEventBase {
|
|
26
|
+
toolName?: string;
|
|
27
|
+
toolCallId?: string;
|
|
28
|
+
/** Mutable tool input — later handlers see earlier mutations. */
|
|
29
|
+
toolInput?: unknown;
|
|
30
|
+
}
|
|
31
|
+
/** context-specific fields. */
|
|
32
|
+
export interface PiContextPayload extends PiEventBase {
|
|
33
|
+
/** Context content to inject into the turn. */
|
|
34
|
+
contextContent?: string;
|
|
35
|
+
}
|
|
36
|
+
/** before_provider_request-specific fields. */
|
|
37
|
+
export interface PiBeforeProviderRequestPayload extends PiEventBase {
|
|
38
|
+
/** The messages about to be sent to the provider. */
|
|
39
|
+
messages?: unknown[];
|
|
40
|
+
/** Provider configuration. */
|
|
41
|
+
providerConfig?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Coerce raw input to a record. Pi input is always programmatic objects,
|
|
45
|
+
* but we handle edge cases defensively.
|
|
46
|
+
*/
|
|
47
|
+
export declare function coerceInput(raw: unknown): Record<string, unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Build a UnifiedExecutionContext from a Pi event payload.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildExecutionContext(data: Record<string, unknown>, nativeEventName: string, extensionState?: Record<string, string>): UnifiedExecutionContext;
|
|
52
|
+
/**
|
|
53
|
+
* Build the payload portion of the unified event from Pi event data.
|
|
54
|
+
* Extracts event-specific fields into the normalized payload.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildPayload(nativeEventName: string, data: Record<string, unknown>): Record<string, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* Normalize a Pi hook invocation into a UnifiedHookEvent.
|
|
59
|
+
*
|
|
60
|
+
* Unlike shell-hook adapters, Pi events arrive as in-process objects.
|
|
61
|
+
* No stdin parsing is required.
|
|
62
|
+
*
|
|
63
|
+
* @param nativeEventName - The Pi event name (e.g. 'session_start', 'tool_call').
|
|
64
|
+
* @param rawInput - The programmatic event object from Pi.
|
|
65
|
+
* @param extensionState - Extension-state key-value pairs for session persistence.
|
|
66
|
+
*/
|
|
67
|
+
export declare function normalizePi(nativeEventName: string, rawInput: unknown, extensionState?: 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,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGxF,gCAAgC;AAChC,eAAO,MAAM,YAAY,OAAO,CAAC;AAKjC,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;;;;GAKG;AAEH,mDAAmD;AACnD,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qCAAqC;AACrC,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACxD,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,iCAAiC;AACjC,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,+BAA+B;AAC/B,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,+CAA+C;AAC/C,MAAM,WAAW,8BAA+B,SAAQ,WAAW;IACjE,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,8BAA8B;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQjE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,eAAe,EAAE,MAAM,EACvB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC1C,uBAAuB,CAmCzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,eAAe,EAAE,MAAM,EACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkCzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,OAAO,EACjB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC1C,gBAAgB,CAmClB"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADAPTER_NAME = void 0;
|
|
4
|
+
exports.setAdapterName = setAdapterName;
|
|
5
|
+
exports.coerceInput = coerceInput;
|
|
6
|
+
exports.buildExecutionContext = buildExecutionContext;
|
|
7
|
+
exports.buildPayload = buildPayload;
|
|
8
|
+
exports.normalizePi = normalizePi;
|
|
9
|
+
const mappings_1 = require("./mappings");
|
|
10
|
+
/** The default adapter name. */
|
|
11
|
+
exports.ADAPTER_NAME = 'pi';
|
|
12
|
+
/** Mutable adapter name, defaulting to the pi adapter identity. */
|
|
13
|
+
let _adapterName = 'pi';
|
|
14
|
+
/** Override the adapter name used in normalized events. */
|
|
15
|
+
function setAdapterName(name) {
|
|
16
|
+
_adapterName = name;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Coerce raw input to a record. Pi input is always programmatic objects,
|
|
20
|
+
* but we handle edge cases defensively.
|
|
21
|
+
*/
|
|
22
|
+
function coerceInput(raw) {
|
|
23
|
+
if (raw == null) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
if (typeof raw === 'object' && !Array.isArray(raw)) {
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
return { raw };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build a UnifiedExecutionContext from a Pi event payload.
|
|
33
|
+
*/
|
|
34
|
+
function buildExecutionContext(data, nativeEventName, extensionState = {}) {
|
|
35
|
+
const persistedEnv = {};
|
|
36
|
+
const contextVars = {};
|
|
37
|
+
// Collect persisted state from extension-state
|
|
38
|
+
for (const [key, value] of Object.entries(extensionState)) {
|
|
39
|
+
if (key.startsWith('HOOKS_PROXY_PERSIST_')) {
|
|
40
|
+
persistedEnv[key] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const sessionId = data.sessionId
|
|
44
|
+
?? extensionState['AGENT_SESSION_ID']
|
|
45
|
+
?? null;
|
|
46
|
+
return {
|
|
47
|
+
sessionId,
|
|
48
|
+
turnId: extensionState['HOOKS_PROXY_TURN_ID'] ?? null,
|
|
49
|
+
conversationId: extensionState['HOOKS_PROXY_CONVERSATION_ID'] ?? null,
|
|
50
|
+
adapter: _adapterName,
|
|
51
|
+
cwd: data.cwd ?? null,
|
|
52
|
+
worktree: extensionState['HOOKS_PROXY_WORKTREE'] ?? null,
|
|
53
|
+
transcriptPath: null,
|
|
54
|
+
source: null,
|
|
55
|
+
model: data.model ?? extensionState['HOOKS_PROXY_MODEL'] ?? null,
|
|
56
|
+
agentType: null,
|
|
57
|
+
permissionMode: null,
|
|
58
|
+
toolName: data.toolName ?? null,
|
|
59
|
+
toolCallId: data.toolCallId ?? null,
|
|
60
|
+
nativeEventName,
|
|
61
|
+
rawEventScope: null,
|
|
62
|
+
persistedEnv,
|
|
63
|
+
contextVars,
|
|
64
|
+
metadata: {},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build the payload portion of the unified event from Pi event data.
|
|
69
|
+
* Extracts event-specific fields into the normalized payload.
|
|
70
|
+
*/
|
|
71
|
+
function buildPayload(nativeEventName, data) {
|
|
72
|
+
const payload = {};
|
|
73
|
+
switch (nativeEventName) {
|
|
74
|
+
case 'session_start':
|
|
75
|
+
if (data.initialPrompt != null)
|
|
76
|
+
payload.initialPrompt = data.initialPrompt;
|
|
77
|
+
break;
|
|
78
|
+
case 'tool_call':
|
|
79
|
+
if (data.toolName != null)
|
|
80
|
+
payload.toolName = data.toolName;
|
|
81
|
+
if (data.toolCallId != null)
|
|
82
|
+
payload.toolCallId = data.toolCallId;
|
|
83
|
+
if (data.toolInput != null)
|
|
84
|
+
payload.toolInput = data.toolInput;
|
|
85
|
+
break;
|
|
86
|
+
case 'context':
|
|
87
|
+
if (data.contextContent != null)
|
|
88
|
+
payload.contextContent = data.contextContent;
|
|
89
|
+
break;
|
|
90
|
+
case 'before_provider_request':
|
|
91
|
+
if (data.messages != null)
|
|
92
|
+
payload.messages = data.messages;
|
|
93
|
+
if (data.providerConfig != null)
|
|
94
|
+
payload.providerConfig = data.providerConfig;
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
// Unknown event: pass through all non-common fields
|
|
98
|
+
for (const [key, value] of Object.entries(data)) {
|
|
99
|
+
if (!['sessionId', 'cwd', 'model'].includes(key)) {
|
|
100
|
+
payload[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return payload;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Normalize a Pi hook invocation into a UnifiedHookEvent.
|
|
109
|
+
*
|
|
110
|
+
* Unlike shell-hook adapters, Pi events arrive as in-process objects.
|
|
111
|
+
* No stdin parsing is required.
|
|
112
|
+
*
|
|
113
|
+
* @param nativeEventName - The Pi event name (e.g. 'session_start', 'tool_call').
|
|
114
|
+
* @param rawInput - The programmatic event object from Pi.
|
|
115
|
+
* @param extensionState - Extension-state key-value pairs for session persistence.
|
|
116
|
+
*/
|
|
117
|
+
function normalizePi(nativeEventName, rawInput, extensionState = {}) {
|
|
118
|
+
const data = coerceInput(rawInput);
|
|
119
|
+
const mapping = (0, mappings_1.getPiPhaseMapping)(nativeEventName);
|
|
120
|
+
const phase = mapping?.canonicalPhase ?? 'unknown';
|
|
121
|
+
const supportLevel = mapping?.supportLevel ?? 'unsupported';
|
|
122
|
+
const execution = buildExecutionContext(data, nativeEventName, extensionState);
|
|
123
|
+
const payload = buildPayload(nativeEventName, data);
|
|
124
|
+
// Split extension-state into input and persisted buckets
|
|
125
|
+
const inputEnv = {};
|
|
126
|
+
const persistedEnv = {};
|
|
127
|
+
for (const [key, value] of Object.entries(extensionState)) {
|
|
128
|
+
if (key.startsWith('HOOKS_PROXY_PERSIST_')) {
|
|
129
|
+
persistedEnv[key] = value;
|
|
130
|
+
}
|
|
131
|
+
else if (key.startsWith('HOOKS_PROXY_')) {
|
|
132
|
+
inputEnv[key] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
version: 'a5c.hooks.v1',
|
|
137
|
+
adapter: _adapterName,
|
|
138
|
+
phase,
|
|
139
|
+
rawEventName: nativeEventName,
|
|
140
|
+
supportLevel,
|
|
141
|
+
execution,
|
|
142
|
+
payload,
|
|
143
|
+
env: {
|
|
144
|
+
input: inputEnv,
|
|
145
|
+
persisted: persistedEnv,
|
|
146
|
+
},
|
|
147
|
+
raw: rawInput,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.js","sourceRoot":"","sources":["../src/normalizer.ts"],"names":[],"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AAc,CAAC,EAAE,CAAC;QAC1D,IAAI,GAAG,CAAC,UAAU,CAAC,sBAAsB,CAAC,EAAE,CAAC;YAC3C,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC5B,CAAC;aAAM,IAAI,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;YAC1C,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,YAAY;QACrB,KAAK;QACL,YAAY,EAAE,eAAe;QAC7B,YAAY;QACZ,SAAS;QACT,OAAO;QACP,GAAG,EAAE;YACH,KAAK,EAAE,QAAQ;YACf,SAAS,EAAE,YAAY;SACxB;QACD,GAAG,EAAE,QAAQ;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { UnifiedHookResult } from '@a5c-ai/hooks-mux-core';
|
|
2
|
+
/**
|
|
3
|
+
* Pi native hook output formats.
|
|
4
|
+
*
|
|
5
|
+
* Pi hooks communicate results as in-process return objects.
|
|
6
|
+
* The shape depends on the event type.
|
|
7
|
+
*/
|
|
8
|
+
/** tool_call hook output: permission decision and optional tool input mutation. */
|
|
9
|
+
export interface PiToolCallOutput {
|
|
10
|
+
decision?: 'allow' | 'deny';
|
|
11
|
+
reason?: string;
|
|
12
|
+
/** Mutated tool input — Pi supports in-place mutation. */
|
|
13
|
+
toolInput?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** session_start hook output. */
|
|
16
|
+
export interface PiSessionStartOutput {
|
|
17
|
+
/** Additional context to inject (not native — must be handled by the hook layer). */
|
|
18
|
+
additionalContext?: string;
|
|
19
|
+
/** State to persist via extension-state. */
|
|
20
|
+
persistState?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/** context hook output. */
|
|
23
|
+
export interface PiContextOutput {
|
|
24
|
+
/** Context content to inject into the model context. */
|
|
25
|
+
contextContent?: string;
|
|
26
|
+
}
|
|
27
|
+
/** before_provider_request hook output. */
|
|
28
|
+
export interface PiBeforeProviderRequestOutput {
|
|
29
|
+
/** Modified messages to send to the provider. */
|
|
30
|
+
messages?: unknown[];
|
|
31
|
+
}
|
|
32
|
+
/** Generic output shape for unrecognized events. */
|
|
33
|
+
export interface PiGenericOutput {
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Render a UnifiedHookResult back to Pi's native output format.
|
|
38
|
+
*
|
|
39
|
+
* @param result - The unified hook result from handler execution.
|
|
40
|
+
* @param nativeEventName - The original Pi event name.
|
|
41
|
+
* @returns The native output object to return to Pi.
|
|
42
|
+
*/
|
|
43
|
+
export declare function renderPiOutput(result: UnifiedHookResult, nativeEventName: string): Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Build extension-state entries for Pi session persistence.
|
|
46
|
+
*
|
|
47
|
+
* Pi uses its native extension-state mechanism for key-value persistence
|
|
48
|
+
* across hook invocations. Unlike Claude's env-file approach, this is
|
|
49
|
+
* an in-process API — no file I/O needed.
|
|
50
|
+
*
|
|
51
|
+
* @param persistEnv - Key-value pairs to persist.
|
|
52
|
+
* @returns Record of key-value pairs to store in extension-state.
|
|
53
|
+
*/
|
|
54
|
+
export declare function buildExtensionState(persistEnv: Record<string, string>): Record<string, string>;
|
|
55
|
+
//# 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,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;GAKG;AAEH,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,iCAAiC;AACjC,MAAM,WAAW,oBAAoB;IACnC,qFAAqF;IACrF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED,2BAA2B;AAC3B,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,2CAA2C;AAC3C,MAAM,WAAW,6BAA6B;IAC5C,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB;AAED,oDAAoD;AACpD,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,MAAM,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB;AAuED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE9F"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderPiOutput = renderPiOutput;
|
|
4
|
+
exports.buildExtensionState = buildExtensionState;
|
|
5
|
+
/**
|
|
6
|
+
* Render a UnifiedHookResult back to Pi's native output format.
|
|
7
|
+
*
|
|
8
|
+
* @param result - The unified hook result from handler execution.
|
|
9
|
+
* @param nativeEventName - The original Pi event name.
|
|
10
|
+
* @returns The native output object to return to Pi.
|
|
11
|
+
*/
|
|
12
|
+
function renderPiOutput(result, nativeEventName) {
|
|
13
|
+
switch (nativeEventName) {
|
|
14
|
+
case 'tool_call':
|
|
15
|
+
return renderToolCallOutput(result);
|
|
16
|
+
case 'session_start':
|
|
17
|
+
return renderSessionStartOutput(result);
|
|
18
|
+
case 'context':
|
|
19
|
+
return renderContextOutput(result);
|
|
20
|
+
case 'before_provider_request':
|
|
21
|
+
return renderBeforeProviderRequestOutput(result);
|
|
22
|
+
default:
|
|
23
|
+
return renderGenericOutput(result);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function renderToolCallOutput(result) {
|
|
27
|
+
const output = {};
|
|
28
|
+
// Map unified decision to Pi's permission decision
|
|
29
|
+
if (result.decision === 'allow') {
|
|
30
|
+
output['decision'] = 'allow';
|
|
31
|
+
}
|
|
32
|
+
else if (result.decision === 'deny') {
|
|
33
|
+
output['decision'] = 'deny';
|
|
34
|
+
}
|
|
35
|
+
// 'ask', 'continue', and 'noop' are not natively supported by Pi;
|
|
36
|
+
// 'ask' falls through to no decision (Pi defaults to allow)
|
|
37
|
+
if (result.reason != null) {
|
|
38
|
+
output['reason'] = result.reason;
|
|
39
|
+
}
|
|
40
|
+
// Tool input mutation: Pi supports in-place mutation via toolMutation
|
|
41
|
+
if (result.toolMutation != null) {
|
|
42
|
+
output['toolInput'] = result.toolMutation.value;
|
|
43
|
+
}
|
|
44
|
+
return output;
|
|
45
|
+
}
|
|
46
|
+
function renderSessionStartOutput(result) {
|
|
47
|
+
const output = {};
|
|
48
|
+
if (result.additionalContext != null) {
|
|
49
|
+
output['additionalContext'] = result.additionalContext;
|
|
50
|
+
}
|
|
51
|
+
// Collect env to persist via extension-state
|
|
52
|
+
if (result.persistEnv != null && Object.keys(result.persistEnv).length > 0) {
|
|
53
|
+
output['persistState'] = result.persistEnv;
|
|
54
|
+
}
|
|
55
|
+
return output;
|
|
56
|
+
}
|
|
57
|
+
function renderContextOutput(result) {
|
|
58
|
+
const output = {};
|
|
59
|
+
if (result.additionalContext != null) {
|
|
60
|
+
output['contextContent'] = result.additionalContext;
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
64
|
+
function renderBeforeProviderRequestOutput(result) {
|
|
65
|
+
const output = {};
|
|
66
|
+
if (result.systemMessage != null) {
|
|
67
|
+
output['systemMessage'] = result.systemMessage;
|
|
68
|
+
}
|
|
69
|
+
return output;
|
|
70
|
+
}
|
|
71
|
+
function renderGenericOutput(result) {
|
|
72
|
+
const output = {};
|
|
73
|
+
if (result.additionalContext != null) {
|
|
74
|
+
output['additionalContext'] = result.additionalContext;
|
|
75
|
+
}
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build extension-state entries for Pi session persistence.
|
|
80
|
+
*
|
|
81
|
+
* Pi uses its native extension-state mechanism for key-value persistence
|
|
82
|
+
* across hook invocations. Unlike Claude's env-file approach, this is
|
|
83
|
+
* an in-process API — no file I/O needed.
|
|
84
|
+
*
|
|
85
|
+
* @param persistEnv - Key-value pairs to persist.
|
|
86
|
+
* @returns Record of key-value pairs to store in extension-state.
|
|
87
|
+
*/
|
|
88
|
+
function buildExtensionState(persistEnv) {
|
|
89
|
+
return { ...persistEnv };
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;AAiDA,wCAgBC;AAiFD,kDAEC;AA1GD;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,MAAyB,EACzB,eAAuB;IAEvB,QAAQ,eAAe,EAAE,CAAC;QACxB,KAAK,WAAW;YACd,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtC,KAAK,eAAe;YAClB,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAC1C,KAAK,SAAS;YACZ,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACrC,KAAK,yBAAyB;YAC5B,OAAO,iCAAiC,CAAC,MAAM,CAAC,CAAC;QACnD;YACE,OAAO,mBAAmB,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E,CAAC;IAE3C,IAAI,MAAM,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACtD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iCAAiC,CAAC,MAAyB;IAClE,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,IAAI,MAAM,CAAC,aAAa,IAAI,IAAI,EAAE,CAAC;QACjC,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC;IACjD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAyB;IACpD,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,IAAI,MAAM,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACzD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,mBAAmB,CAAC,UAAkC;IACpE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session ID resolution for Pi.
|
|
3
|
+
*
|
|
4
|
+
* Pi provides a native session ID via its programmatic API,
|
|
5
|
+
* so the resolution quality is 'native'.
|
|
6
|
+
*
|
|
7
|
+
* Resolution precedence (spec section 9.2):
|
|
8
|
+
* 1. Explicit override (e.g. from caller)
|
|
9
|
+
* 2. Explicit env/extension-state AGENT_SESSION_ID
|
|
10
|
+
* 3. Native sessionId from Pi event payload
|
|
11
|
+
* 4. PI_SESSION_ID from extension-state
|
|
12
|
+
* 5. Fallback: null
|
|
13
|
+
*/
|
|
14
|
+
export interface SessionResolutionResult {
|
|
15
|
+
sessionId: string | null;
|
|
16
|
+
source: 'explicit_override' | 'explicit_env' | 'native' | 'harness_env' | 'none';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the session ID for a Pi hook invocation.
|
|
20
|
+
*
|
|
21
|
+
* @param data - Parsed event payload from Pi.
|
|
22
|
+
* @param extensionState - Extension-state key-value pairs.
|
|
23
|
+
* @param explicitSessionId - Explicit session ID override from caller, if any.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveSessionId(data: Record<string, unknown>, extensionState?: Record<string, string>, explicitSessionId?: string): SessionResolutionResult;
|
|
26
|
+
//# 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,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,mBAAmB,GAAG,cAAc,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,CAAC;CAClF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EAC3C,iBAAiB,CAAC,EAAE,MAAM,GACzB,uBAAuB,CA0BzB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Session ID resolution for Pi.
|
|
4
|
+
*
|
|
5
|
+
* Pi provides a native session ID via its programmatic API,
|
|
6
|
+
* so the resolution quality is 'native'.
|
|
7
|
+
*
|
|
8
|
+
* Resolution precedence (spec section 9.2):
|
|
9
|
+
* 1. Explicit override (e.g. from caller)
|
|
10
|
+
* 2. Explicit env/extension-state AGENT_SESSION_ID
|
|
11
|
+
* 3. Native sessionId from Pi event payload
|
|
12
|
+
* 4. PI_SESSION_ID from extension-state
|
|
13
|
+
* 5. Fallback: null
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.resolveSessionId = resolveSessionId;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the session ID for a Pi hook invocation.
|
|
19
|
+
*
|
|
20
|
+
* @param data - Parsed event payload from Pi.
|
|
21
|
+
* @param extensionState - Extension-state key-value pairs.
|
|
22
|
+
* @param explicitSessionId - Explicit session ID override from caller, if any.
|
|
23
|
+
*/
|
|
24
|
+
function resolveSessionId(data, extensionState = {}, explicitSessionId) {
|
|
25
|
+
// 1. Explicit override
|
|
26
|
+
if (explicitSessionId) {
|
|
27
|
+
return { sessionId: explicitSessionId, source: 'explicit_override' };
|
|
28
|
+
}
|
|
29
|
+
// 2. Explicit env
|
|
30
|
+
const envSessionId = extensionState['AGENT_SESSION_ID'];
|
|
31
|
+
if (envSessionId) {
|
|
32
|
+
return { sessionId: envSessionId, source: 'explicit_env' };
|
|
33
|
+
}
|
|
34
|
+
// 3. Native sessionId from Pi event
|
|
35
|
+
const nativeSessionId = data.sessionId;
|
|
36
|
+
if (typeof nativeSessionId === 'string' && nativeSessionId.length > 0) {
|
|
37
|
+
return { sessionId: nativeSessionId, source: 'native' };
|
|
38
|
+
}
|
|
39
|
+
// 4. PI_SESSION_ID from extension-state
|
|
40
|
+
const piSessionId = extensionState['PI_SESSION_ID'];
|
|
41
|
+
if (piSessionId) {
|
|
42
|
+
return { sessionId: piSessionId, source: 'harness_env' };
|
|
43
|
+
}
|
|
44
|
+
// 5. No session ID available
|
|
45
|
+
return { sessionId: null, source: 'none' };
|
|
46
|
+
}
|
|
47
|
+
//# 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;;AAcH,4CA8BC;AArCD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,IAA6B,EAC7B,iBAAyC,EAAE,EAC3C,iBAA0B;IAE1B,uBAAuB;IACvB,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IACvE,CAAC;IAED,kBAAkB;IAClB,MAAM,YAAY,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACxD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IAC7D,CAAC;IAED,oCAAoC;IACpC,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC;IACvC,IAAI,OAAO,eAAe,KAAK,QAAQ,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAC1D,CAAC;IAED,wCAAwC;IACxC,MAAM,WAAW,GAAG,cAAc,CAAC,eAAe,CAAC,CAAC;IACpD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAC3D,CAAC;IAED,6BAA6B;IAC7B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC7C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5c-ai/hooks-mux-adapter-pi",
|
|
3
|
+
"version": "5.0.1-staging.00fa5317c",
|
|
4
|
+
"description": "Pi 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-pi"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/a5c-ai/babysitter/tree/main/packages/hooks-mux/adapter-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-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
|
+
}
|