@a5c-ai/hooks-adapter-opencode 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 +36 -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 +24 -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 +17 -0
- package/dist/mappings.d.ts.map +1 -0
- package/dist/mappings.js +73 -0
- package/dist/mappings.js.map +1 -0
- package/dist/normalizer.d.ts +72 -0
- package/dist/normalizer.d.ts.map +1 -0
- package/dist/normalizer.js +162 -0
- package/dist/normalizer.js.map +1 -0
- package/dist/renderer.d.ts +48 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +88 -0
- package/dist/renderer.js.map +1 -0
- package/dist/session-resolver.d.ts +23 -0
- package/dist/session-resolver.d.ts.map +1 -0
- package/dist/session-resolver.js +89 -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-opencode
|
|
2
|
+
|
|
3
|
+
OpenCode harness adapter for hooks-adapter.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @a5c-ai/hooks-adapter-opencode @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
|
+
normalizeOpenCode,
|
|
20
|
+
} from "@a5c-ai/hooks-adapter-opencode";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The package exposes OpenCode-specific normalization, phase mappings, session utilities, 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,CAqBtF"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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 OpenCode 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.8.
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_ADAPTER_NAME = 'opencode';
|
|
14
|
+
function createAdapter(name = DEFAULT_ADAPTER_NAME) {
|
|
15
|
+
const target = (0, catalog_1.getPluginTargetDescriptor)(name);
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
family: target?.hooksMuxFamily ?? 'in-process',
|
|
19
|
+
sessionIdQuality: target?.sessionIdQuality ?? 'native',
|
|
20
|
+
supportsOrderedFanout: target?.supportsOrderedFanout ?? false,
|
|
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; no CLI shell-hook mode',
|
|
31
|
+
'Native env injection via shell.env hook',
|
|
32
|
+
'Session ID provided natively by the OpenCode runtime',
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";;AAaA,sCAqBC;AAjCD,mDAAkE;AAElE;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAExC,SAAgB,aAAa,CAAC,OAAe,oBAAoB;IAC/D,MAAM,MAAM,GAAG,IAAA,mCAAyB,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,KAAK;QAC7D,+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,8CAA8C;YAC9C,yCAAyC;YACzC,sDAAsD;SACvD;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createAdapter } from './adapter';
|
|
2
|
+
export { OPENCODE_PHASE_MAPPINGS, SHELL_ENV_NATIVE_HOOK, getOpenCodePhaseMapping, getSupportedPhases, } from './mappings';
|
|
3
|
+
export { createConfiguredEngine } from './integration';
|
|
4
|
+
export { normalizeOpenCode, parseEventData, buildExecutionContext, buildPayload, setAdapterName, } from './normalizer';
|
|
5
|
+
export { renderOpenCodeOutput } from './renderer';
|
|
6
|
+
export { resolveSessionId, deriveSessionId } from './session-resolver';
|
|
7
|
+
export type { OpenCodeEventBase, OpenCodeSessionCreatedPayload, OpenCodeToolExecuteBeforePayload, OpenCodeToolExecuteAfterPayload, OpenCodeShellEnvPayload, } from './normalizer';
|
|
8
|
+
export type { OpenCodeSessionCreatedOutput, OpenCodeToolExecuteBeforeOutput, OpenCodeToolExecuteAfterOutput, OpenCodeShellEnvOutput, } from './renderer';
|
|
9
|
+
//# 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,EACL,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGvE,YAAY,EACV,iBAAiB,EACjB,6BAA6B,EAC7B,gCAAgC,EAChC,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,4BAA4B,EAC5B,+BAA+B,EAC/B,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveSessionId = exports.resolveSessionId = exports.renderOpenCodeOutput = exports.setAdapterName = exports.buildPayload = exports.buildExecutionContext = exports.parseEventData = exports.normalizeOpenCode = exports.createConfiguredEngine = exports.getSupportedPhases = exports.getOpenCodePhaseMapping = exports.SHELL_ENV_NATIVE_HOOK = exports.OPENCODE_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, "OPENCODE_PHASE_MAPPINGS", { enumerable: true, get: function () { return mappings_1.OPENCODE_PHASE_MAPPINGS; } });
|
|
8
|
+
Object.defineProperty(exports, "SHELL_ENV_NATIVE_HOOK", { enumerable: true, get: function () { return mappings_1.SHELL_ENV_NATIVE_HOOK; } });
|
|
9
|
+
Object.defineProperty(exports, "getOpenCodePhaseMapping", { enumerable: true, get: function () { return mappings_1.getOpenCodePhaseMapping; } });
|
|
10
|
+
Object.defineProperty(exports, "getSupportedPhases", { enumerable: true, get: function () { return mappings_1.getSupportedPhases; } });
|
|
11
|
+
var integration_1 = require("./integration");
|
|
12
|
+
Object.defineProperty(exports, "createConfiguredEngine", { enumerable: true, get: function () { return integration_1.createConfiguredEngine; } });
|
|
13
|
+
var normalizer_1 = require("./normalizer");
|
|
14
|
+
Object.defineProperty(exports, "normalizeOpenCode", { enumerable: true, get: function () { return normalizer_1.normalizeOpenCode; } });
|
|
15
|
+
Object.defineProperty(exports, "parseEventData", { enumerable: true, get: function () { return normalizer_1.parseEventData; } });
|
|
16
|
+
Object.defineProperty(exports, "buildExecutionContext", { enumerable: true, get: function () { return normalizer_1.buildExecutionContext; } });
|
|
17
|
+
Object.defineProperty(exports, "buildPayload", { enumerable: true, get: function () { return normalizer_1.buildPayload; } });
|
|
18
|
+
Object.defineProperty(exports, "setAdapterName", { enumerable: true, get: function () { return normalizer_1.setAdapterName; } });
|
|
19
|
+
var renderer_1 = require("./renderer");
|
|
20
|
+
Object.defineProperty(exports, "renderOpenCodeOutput", { enumerable: true, get: function () { return renderer_1.renderOpenCodeOutput; } });
|
|
21
|
+
var session_resolver_1 = require("./session-resolver");
|
|
22
|
+
Object.defineProperty(exports, "resolveSessionId", { enumerable: true, get: function () { return session_resolver_1.resolveSessionId; } });
|
|
23
|
+
Object.defineProperty(exports, "deriveSessionId", { enumerable: true, get: function () { return session_resolver_1.deriveSessionId; } });
|
|
24
|
+
//# 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,uCAKoB;AAJlB,mHAAA,uBAAuB,OAAA;AACvB,iHAAA,qBAAqB,OAAA;AACrB,mHAAA,uBAAuB,OAAA;AACvB,8GAAA,kBAAkB,OAAA;AAEpB,6CAAuD;AAA9C,qHAAA,sBAAsB,OAAA;AAC/B,2CAMsB;AALpB,+GAAA,iBAAiB,OAAA;AACjB,4GAAA,cAAc,OAAA;AACd,mHAAA,qBAAqB,OAAA;AACrB,0GAAA,YAAY,OAAA;AACZ,4GAAA,cAAc,OAAA;AAEhB,uCAAkD;AAAzC,gHAAA,oBAAoB,OAAA;AAC7B,uDAAuE;AAA9D,oHAAA,gBAAgB,OAAA;AAAE,mHAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic engine integration for the OpenCode adapter.
|
|
3
|
+
*
|
|
4
|
+
* Creates a pre-configured HooksEngine wired to the OpenCode 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-opencode';
|
|
10
|
+
*
|
|
11
|
+
* const engine = createConfiguredEngine();
|
|
12
|
+
*
|
|
13
|
+
* engine.registerHandler({
|
|
14
|
+
* id: 'my-handler',
|
|
15
|
+
* pluginId: 'my-plugin',
|
|
16
|
+
* phase: 'tool.before',
|
|
17
|
+
* priority: 10,
|
|
18
|
+
* handler: async (event) => ({
|
|
19
|
+
* decision: 'allow',
|
|
20
|
+
* }),
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const result = await engine.processEvent({
|
|
24
|
+
* nativeEventName: 'tool.execute.before',
|
|
25
|
+
* payload: { toolName: 'Bash', command: 'ls' },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import { type HooksEngine } from '@a5c-ai/hooks-adapter-core';
|
|
30
|
+
/**
|
|
31
|
+
* Create a pre-configured hooks engine for the OpenCode 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 OpenCode adapter.
|
|
4
|
+
*
|
|
5
|
+
* Creates a pre-configured HooksEngine wired to the OpenCode 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-opencode';
|
|
11
|
+
*
|
|
12
|
+
* const engine = createConfiguredEngine();
|
|
13
|
+
*
|
|
14
|
+
* engine.registerHandler({
|
|
15
|
+
* id: 'my-handler',
|
|
16
|
+
* pluginId: 'my-plugin',
|
|
17
|
+
* phase: 'tool.before',
|
|
18
|
+
* priority: 10,
|
|
19
|
+
* handler: async (event) => ({
|
|
20
|
+
* decision: 'allow',
|
|
21
|
+
* }),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const result = await engine.processEvent({
|
|
25
|
+
* nativeEventName: 'tool.execute.before',
|
|
26
|
+
* payload: { toolName: 'Bash', command: 'ls' },
|
|
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 OpenCode 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.OPENCODE_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,17 @@
|
|
|
1
|
+
import type { PhaseMapping } from '@a5c-ai/hooks-adapter-core';
|
|
2
|
+
export declare const OPENCODE_PHASE_MAPPINGS: PhaseMapping[];
|
|
3
|
+
/**
|
|
4
|
+
* The shell.env event is a special env-injection hook, not a standard
|
|
5
|
+
* lifecycle phase. We track it separately so the normalizer can handle
|
|
6
|
+
* it without conflating it with session.start.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SHELL_ENV_NATIVE_HOOK = "shell.env";
|
|
9
|
+
/**
|
|
10
|
+
* Look up the phase mapping for a given OpenCode native event name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getOpenCodePhaseMapping(nativeEventName: string): PhaseMapping | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Get all canonical phases supported by the OpenCode adapter.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getSupportedPhases(): string[];
|
|
17
|
+
//# sourceMappingURL=mappings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappings.d.ts","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAsD/D,eAAO,MAAM,uBAAuB,EAAE,YAAY,EAAuB,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,cAAc,CAAC;AAEjD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,eAAe,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEzF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C"}
|
package/dist/mappings.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHELL_ENV_NATIVE_HOOK = exports.OPENCODE_PHASE_MAPPINGS = void 0;
|
|
4
|
+
exports.getOpenCodePhaseMapping = getOpenCodePhaseMapping;
|
|
5
|
+
exports.getSupportedPhases = getSupportedPhases;
|
|
6
|
+
const catalog_1 = require("@a5c-ai/atlas/catalog");
|
|
7
|
+
/**
|
|
8
|
+
* OpenCode 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.8.
|
|
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
|
+
/** Native hooks excluded from the standard phase mapping table. */
|
|
36
|
+
const EXCLUDED_NATIVE_HOOKS = new Set(['shell.env']);
|
|
37
|
+
function buildFromCatalog() {
|
|
38
|
+
const mappings = (0, catalog_1.listHookMappingsByAdapterFamily)('opencode');
|
|
39
|
+
if (mappings.length === 0) {
|
|
40
|
+
throw new Error('hooks-adapter adapter-opencode: catalog unavailable or returned no mappings for family "opencode"');
|
|
41
|
+
}
|
|
42
|
+
const phaseMappings = mappings
|
|
43
|
+
.map(hookMappingToPhaseMapping)
|
|
44
|
+
.filter((m) => m !== null)
|
|
45
|
+
.filter((m) => !EXCLUDED_NATIVE_HOOKS.has(m.nativeHook));
|
|
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.OPENCODE_PHASE_MAPPINGS = buildFromCatalog();
|
|
55
|
+
/**
|
|
56
|
+
* The shell.env event is a special env-injection hook, not a standard
|
|
57
|
+
* lifecycle phase. We track it separately so the normalizer can handle
|
|
58
|
+
* it without conflating it with session.start.
|
|
59
|
+
*/
|
|
60
|
+
exports.SHELL_ENV_NATIVE_HOOK = 'shell.env';
|
|
61
|
+
/**
|
|
62
|
+
* Look up the phase mapping for a given OpenCode native event name.
|
|
63
|
+
*/
|
|
64
|
+
function getOpenCodePhaseMapping(nativeEventName) {
|
|
65
|
+
return exports.OPENCODE_PHASE_MAPPINGS.find((m) => m.nativeHook === nativeEventName);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get all canonical phases supported by the OpenCode adapter.
|
|
69
|
+
*/
|
|
70
|
+
function getSupportedPhases() {
|
|
71
|
+
return [...new Set(exports.OPENCODE_PHASE_MAPPINGS.map((m) => m.canonicalPhase))];
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=mappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mappings.js","sourceRoot":"","sources":["../src/mappings.ts"],"names":[],"mappings":";;;AAkEA,0DAEC;AAKD,gDAEC;AA1ED,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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AC;AAEjD;;GAEG;AACH,SAAgB,uBAAuB,CAAC,eAAuB;IAC7D,OAAO,+BAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,eAAe,CAAC,CAAC;AAC/E,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB;IAChC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,+BAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { UnifiedHookEvent, UnifiedExecutionContext } from '@a5c-ai/hooks-adapter-core';
|
|
2
|
+
/** The default adapter name. */
|
|
3
|
+
export declare const ADAPTER_NAME = "opencode";
|
|
4
|
+
/** Override the adapter name used in normalized events. */
|
|
5
|
+
export declare function setAdapterName(name: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* OpenCode event payload shapes.
|
|
8
|
+
*
|
|
9
|
+
* OpenCode passes events programmatically as objects (in-process adapter).
|
|
10
|
+
*/
|
|
11
|
+
/** Common fields present across OpenCode hook events. */
|
|
12
|
+
export interface OpenCodeEventBase {
|
|
13
|
+
/** Session identifier provided by OpenCode runtime. */
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
/** Workspace or project directory. */
|
|
16
|
+
cwd?: string;
|
|
17
|
+
/** Model identifier. */
|
|
18
|
+
model?: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
/** session.created event payload. */
|
|
22
|
+
export interface OpenCodeSessionCreatedPayload extends OpenCodeEventBase {
|
|
23
|
+
/** Initial user prompt if available. */
|
|
24
|
+
prompt?: string;
|
|
25
|
+
}
|
|
26
|
+
/** tool.execute.before event payload. */
|
|
27
|
+
export interface OpenCodeToolExecuteBeforePayload extends OpenCodeEventBase {
|
|
28
|
+
/** Name of the tool being executed. */
|
|
29
|
+
toolName?: string;
|
|
30
|
+
/** Input arguments for the tool. */
|
|
31
|
+
toolInput?: unknown;
|
|
32
|
+
/** Tool call identifier. */
|
|
33
|
+
toolCallId?: string;
|
|
34
|
+
}
|
|
35
|
+
/** tool.execute.after event payload. */
|
|
36
|
+
export interface OpenCodeToolExecuteAfterPayload extends OpenCodeEventBase {
|
|
37
|
+
/** Name of the tool that was executed. */
|
|
38
|
+
toolName?: string;
|
|
39
|
+
/** Input arguments for the tool. */
|
|
40
|
+
toolInput?: unknown;
|
|
41
|
+
/** Tool execution result. */
|
|
42
|
+
toolResult?: unknown;
|
|
43
|
+
/** Tool call identifier. */
|
|
44
|
+
toolCallId?: string;
|
|
45
|
+
}
|
|
46
|
+
/** shell.env event payload -- used for runtime env injection. */
|
|
47
|
+
export interface OpenCodeShellEnvPayload extends OpenCodeEventBase {
|
|
48
|
+
/** Environment variables to inject into the runtime. */
|
|
49
|
+
env?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse raw event input (string or object) into a structured object.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseEventData(raw: unknown): Record<string, unknown>;
|
|
55
|
+
/**
|
|
56
|
+
* Build a UnifiedExecutionContext from an OpenCode event payload and environment.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildExecutionContext(eventData: Record<string, unknown>, nativeEventName: string, env: Record<string, string>): UnifiedExecutionContext;
|
|
59
|
+
/**
|
|
60
|
+
* Build the payload portion of the unified event from OpenCode event data.
|
|
61
|
+
* Extracts event-specific fields into the normalized payload.
|
|
62
|
+
*/
|
|
63
|
+
export declare function buildPayload(nativeEventName: string, eventData: Record<string, unknown>): Record<string, unknown>;
|
|
64
|
+
/**
|
|
65
|
+
* Normalize an OpenCode event into a UnifiedHookEvent.
|
|
66
|
+
*
|
|
67
|
+
* @param nativeEventName - The OpenCode event name (e.g. 'session.created', 'tool.execute.before').
|
|
68
|
+
* @param rawEvent - Raw event content (string or object).
|
|
69
|
+
* @param env - Environment variables at invocation time.
|
|
70
|
+
*/
|
|
71
|
+
export declare function normalizeOpenCode(nativeEventName: string, rawEvent: unknown, env?: Record<string, string>): UnifiedHookEvent;
|
|
72
|
+
//# 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,4BAA4B,CAAC;AAI5F,gCAAgC;AAChC,eAAO,MAAM,YAAY,aAAa,CAAC;AAKvC,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;;;GAIG;AAEH,yDAAyD;AACzD,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qCAAqC;AACrC,MAAM,WAAW,6BAA8B,SAAQ,iBAAiB;IACtE,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,yCAAyC;AACzC,MAAM,WAAW,gCAAiC,SAAQ,iBAAiB;IACzE,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wCAAwC;AACxC,MAAM,WAAW,+BAAgC,SAAQ,iBAAiB;IACxE,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,iEAAiE;AACjE,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBpE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,uBAAuB,CAgCzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoCzB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,OAAO,EACjB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,gBAAgB,CAqClB"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADAPTER_NAME = void 0;
|
|
4
|
+
exports.setAdapterName = setAdapterName;
|
|
5
|
+
exports.parseEventData = parseEventData;
|
|
6
|
+
exports.buildExecutionContext = buildExecutionContext;
|
|
7
|
+
exports.buildPayload = buildPayload;
|
|
8
|
+
exports.normalizeOpenCode = normalizeOpenCode;
|
|
9
|
+
const mappings_1 = require("./mappings");
|
|
10
|
+
const session_resolver_1 = require("./session-resolver");
|
|
11
|
+
/** The default adapter name. */
|
|
12
|
+
exports.ADAPTER_NAME = 'opencode';
|
|
13
|
+
/** Mutable adapter name, defaulting to the opencode adapter identity. */
|
|
14
|
+
let _adapterName = 'opencode';
|
|
15
|
+
/** Override the adapter name used in normalized events. */
|
|
16
|
+
function setAdapterName(name) {
|
|
17
|
+
_adapterName = name;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse raw event input (string or object) into a structured object.
|
|
21
|
+
*/
|
|
22
|
+
function parseEventData(raw) {
|
|
23
|
+
if (raw == null) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
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
|
+
return { raw: parsed };
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { raw };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (typeof raw === 'object' && !Array.isArray(raw)) {
|
|
39
|
+
return raw;
|
|
40
|
+
}
|
|
41
|
+
return { raw };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build a UnifiedExecutionContext from an OpenCode event payload and environment.
|
|
45
|
+
*/
|
|
46
|
+
function buildExecutionContext(eventData, nativeEventName, env) {
|
|
47
|
+
const persistedEnv = {};
|
|
48
|
+
const contextVars = {};
|
|
49
|
+
for (const [key, value] of Object.entries(env)) {
|
|
50
|
+
if (key.startsWith('HOOKS_PROXY_PERSIST_')) {
|
|
51
|
+
persistedEnv[key] = value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const sessionId = (0, session_resolver_1.resolveSessionId)(eventData, env);
|
|
55
|
+
return {
|
|
56
|
+
sessionId,
|
|
57
|
+
turnId: env['HOOKS_PROXY_TURN_ID'] ?? null,
|
|
58
|
+
conversationId: env['HOOKS_PROXY_CONVERSATION_ID'] ?? null,
|
|
59
|
+
adapter: _adapterName,
|
|
60
|
+
cwd: eventData['cwd'] ?? env['PWD'] ?? null,
|
|
61
|
+
worktree: env['HOOKS_PROXY_WORKTREE'] ?? null,
|
|
62
|
+
transcriptPath: null,
|
|
63
|
+
source: null,
|
|
64
|
+
model: eventData['model'] ?? env['HOOKS_PROXY_MODEL'] ?? null,
|
|
65
|
+
agentType: null,
|
|
66
|
+
permissionMode: null,
|
|
67
|
+
toolName: eventData['toolName'] ?? null,
|
|
68
|
+
toolCallId: eventData['toolCallId'] ?? null,
|
|
69
|
+
nativeEventName,
|
|
70
|
+
rawEventScope: null,
|
|
71
|
+
persistedEnv,
|
|
72
|
+
contextVars,
|
|
73
|
+
metadata: {},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build the payload portion of the unified event from OpenCode event data.
|
|
78
|
+
* Extracts event-specific fields into the normalized payload.
|
|
79
|
+
*/
|
|
80
|
+
function buildPayload(nativeEventName, eventData) {
|
|
81
|
+
const payload = {};
|
|
82
|
+
switch (nativeEventName) {
|
|
83
|
+
case 'session.created':
|
|
84
|
+
if (eventData['prompt'] != null)
|
|
85
|
+
payload.initialPrompt = eventData['prompt'];
|
|
86
|
+
break;
|
|
87
|
+
case 'tool.execute.before':
|
|
88
|
+
if (eventData['toolName'] != null)
|
|
89
|
+
payload.toolName = eventData['toolName'];
|
|
90
|
+
if (eventData['toolInput'] != null)
|
|
91
|
+
payload.toolInput = eventData['toolInput'];
|
|
92
|
+
if (eventData['toolCallId'] != null)
|
|
93
|
+
payload.toolCallId = eventData['toolCallId'];
|
|
94
|
+
break;
|
|
95
|
+
case 'tool.execute.after':
|
|
96
|
+
if (eventData['toolName'] != null)
|
|
97
|
+
payload.toolName = eventData['toolName'];
|
|
98
|
+
if (eventData['toolInput'] != null)
|
|
99
|
+
payload.toolInput = eventData['toolInput'];
|
|
100
|
+
if (eventData['toolResult'] != null)
|
|
101
|
+
payload.toolResponse = eventData['toolResult'];
|
|
102
|
+
if (eventData['toolCallId'] != null)
|
|
103
|
+
payload.toolCallId = eventData['toolCallId'];
|
|
104
|
+
break;
|
|
105
|
+
case mappings_1.SHELL_ENV_NATIVE_HOOK:
|
|
106
|
+
if (eventData['env'] != null)
|
|
107
|
+
payload.env = eventData['env'];
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
// Unknown event: pass through all non-common fields
|
|
111
|
+
for (const [key, value] of Object.entries(eventData)) {
|
|
112
|
+
if (!['sessionId', 'cwd', 'model'].includes(key)) {
|
|
113
|
+
payload[key] = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return payload;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Normalize an OpenCode event into a UnifiedHookEvent.
|
|
122
|
+
*
|
|
123
|
+
* @param nativeEventName - The OpenCode event name (e.g. 'session.created', 'tool.execute.before').
|
|
124
|
+
* @param rawEvent - Raw event content (string or object).
|
|
125
|
+
* @param env - Environment variables at invocation time.
|
|
126
|
+
*/
|
|
127
|
+
function normalizeOpenCode(nativeEventName, rawEvent, env = {}) {
|
|
128
|
+
const eventData = parseEventData(rawEvent);
|
|
129
|
+
const mapping = (0, mappings_1.getOpenCodePhaseMapping)(nativeEventName);
|
|
130
|
+
// shell.env is a special env-injection event; map to session.start (lossy)
|
|
131
|
+
const isShellEnv = nativeEventName === mappings_1.SHELL_ENV_NATIVE_HOOK;
|
|
132
|
+
const phase = isShellEnv ? 'session.start' : (mapping?.canonicalPhase ?? 'unknown');
|
|
133
|
+
const supportLevel = isShellEnv ? 'lossy' : (mapping?.supportLevel ?? 'unsupported');
|
|
134
|
+
const execution = buildExecutionContext(eventData, nativeEventName, env);
|
|
135
|
+
const payload = buildPayload(nativeEventName, eventData);
|
|
136
|
+
// Split env into input and persisted buckets
|
|
137
|
+
const inputEnv = {};
|
|
138
|
+
const persistedEnv = {};
|
|
139
|
+
for (const [key, value] of Object.entries(env)) {
|
|
140
|
+
if (key.startsWith('HOOKS_PROXY_PERSIST_')) {
|
|
141
|
+
persistedEnv[key] = value;
|
|
142
|
+
}
|
|
143
|
+
else if (key.startsWith('HOOKS_PROXY_')) {
|
|
144
|
+
inputEnv[key] = value;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
version: 'a5c.hooks.v1',
|
|
149
|
+
adapter: _adapterName,
|
|
150
|
+
phase,
|
|
151
|
+
rawEventName: nativeEventName,
|
|
152
|
+
supportLevel,
|
|
153
|
+
execution,
|
|
154
|
+
payload,
|
|
155
|
+
env: {
|
|
156
|
+
input: inputEnv,
|
|
157
|
+
persisted: persistedEnv,
|
|
158
|
+
},
|
|
159
|
+
raw: rawEvent,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.js","sourceRoot":"","sources":["../src/normalizer.ts"],"names":[],"mappings":";;;AAWA,wCAEC;AAwDD,wCAmBC;AAKD,sDAoCC;AAMD,oCAuCC;AASD,8CAyCC;AA/ND,yCAA4E;AAC5E,yDAAsD;AAEtD,gCAAgC;AACnB,QAAA,YAAY,GAAG,UAAU,CAAC;AAEvC,yEAAyE;AACzE,IAAI,YAAY,GAAW,UAAU,CAAC;AAEtC,2DAA2D;AAC3D,SAAgB,cAAc,CAAC,IAAY;IACzC,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAqDD;;GAEG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC/B,IAAI,OAAO,MAAM,KAAK,Q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OAAO,EAAE,YAAY,IAAI,aAAa,CAAC,CAAC;IAErF,MAAM,SAAS,GAAG,qBAAqB,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,YAAY,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;IAEzD,6CAA6C;IAC7C,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,YAAY,GAA2B,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,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,48 @@
|
|
|
1
|
+
import type { UnifiedHookResult } from '@a5c-ai/hooks-adapter-core';
|
|
2
|
+
/**
|
|
3
|
+
* OpenCode native hook output formats.
|
|
4
|
+
*
|
|
5
|
+
* OpenCode is an in-process adapter; results are returned programmatically
|
|
6
|
+
* rather than via stdout.
|
|
7
|
+
*/
|
|
8
|
+
/** session.created hook output. */
|
|
9
|
+
export interface OpenCodeSessionCreatedOutput {
|
|
10
|
+
/** Additional context to provide to the session. */
|
|
11
|
+
additionalContext?: string;
|
|
12
|
+
/** Environment variables to persist via shell.env. */
|
|
13
|
+
persistEnv?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/** tool.execute.before hook output: permission and mutation. */
|
|
16
|
+
export interface OpenCodeToolExecuteBeforeOutput {
|
|
17
|
+
/** Permission decision. */
|
|
18
|
+
decision?: 'allow' | 'deny';
|
|
19
|
+
/** Reason for the decision. */
|
|
20
|
+
reason?: string;
|
|
21
|
+
/** Mutated tool input (replaces original). */
|
|
22
|
+
toolInput?: unknown;
|
|
23
|
+
/** Additional context to inject. */
|
|
24
|
+
additionalContext?: string;
|
|
25
|
+
/** Environment variables to persist via shell.env. */
|
|
26
|
+
persistEnv?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
/** tool.execute.after hook output. */
|
|
29
|
+
export interface OpenCodeToolExecuteAfterOutput {
|
|
30
|
+
/** Additional context to inject. */
|
|
31
|
+
additionalContext?: string;
|
|
32
|
+
/** Environment variables to persist via shell.env. */
|
|
33
|
+
persistEnv?: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
/** shell.env hook output: env injection payload. */
|
|
36
|
+
export interface OpenCodeShellEnvOutput {
|
|
37
|
+
/** Environment variables to inject into the runtime. */
|
|
38
|
+
env?: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Render a UnifiedHookResult back to OpenCode's native output format.
|
|
42
|
+
*
|
|
43
|
+
* @param result - The unified hook result from handler execution.
|
|
44
|
+
* @param nativeEventName - The original OpenCode event name.
|
|
45
|
+
* @returns The native output object.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderOpenCodeOutput(result: UnifiedHookResult, nativeEventName: string): Record<string, unknown>;
|
|
48
|
+
//# 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,4BAA4B,CAAC;AAEpE;;;;;GAKG;AAEH,mCAAmC;AACnC,MAAM,WAAW,4BAA4B;IAC3C,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,gEAAgE;AAChE,MAAM,WAAW,+BAA+B;IAC9C,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,sCAAsC;AACtC,MAAM,WAAW,8BAA8B;IAC7C,oCAAoC;IACpC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,oDAAoD;AACpD,MAAM,WAAW,sBAAsB;IACrC,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,EACzB,eAAe,EAAE,MAAM,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderOpenCodeOutput = renderOpenCodeOutput;
|
|
4
|
+
/**
|
|
5
|
+
* Render a UnifiedHookResult back to OpenCode's native output format.
|
|
6
|
+
*
|
|
7
|
+
* @param result - The unified hook result from handler execution.
|
|
8
|
+
* @param nativeEventName - The original OpenCode event name.
|
|
9
|
+
* @returns The native output object.
|
|
10
|
+
*/
|
|
11
|
+
function renderOpenCodeOutput(result, nativeEventName) {
|
|
12
|
+
switch (nativeEventName) {
|
|
13
|
+
case 'session.created':
|
|
14
|
+
return renderSessionCreatedOutput(result);
|
|
15
|
+
case 'tool.execute.before':
|
|
16
|
+
return renderToolExecuteBeforeOutput(result);
|
|
17
|
+
case 'tool.execute.after':
|
|
18
|
+
return renderToolExecuteAfterOutput(result);
|
|
19
|
+
case 'shell.env':
|
|
20
|
+
return renderShellEnvOutput(result);
|
|
21
|
+
default:
|
|
22
|
+
return renderGenericOutput(result);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function renderSessionCreatedOutput(result) {
|
|
26
|
+
const output = {};
|
|
27
|
+
if (result.additionalContext != null) {
|
|
28
|
+
output.additionalContext = result.additionalContext;
|
|
29
|
+
}
|
|
30
|
+
if (result.persistEnv != null && Object.keys(result.persistEnv).length > 0) {
|
|
31
|
+
output.persistEnv = result.persistEnv;
|
|
32
|
+
}
|
|
33
|
+
return output;
|
|
34
|
+
}
|
|
35
|
+
function renderToolExecuteBeforeOutput(result) {
|
|
36
|
+
const output = {};
|
|
37
|
+
if (result.decision === 'allow') {
|
|
38
|
+
output.decision = 'allow';
|
|
39
|
+
}
|
|
40
|
+
else if (result.decision === 'deny') {
|
|
41
|
+
output.decision = 'deny';
|
|
42
|
+
}
|
|
43
|
+
// 'ask', 'continue', 'noop' produce no decision
|
|
44
|
+
if (result.reason != null) {
|
|
45
|
+
output.reason = result.reason;
|
|
46
|
+
}
|
|
47
|
+
// Tool input mutation
|
|
48
|
+
if (result.toolMutation?.value != null) {
|
|
49
|
+
output.toolInput = result.toolMutation.value;
|
|
50
|
+
}
|
|
51
|
+
if (result.additionalContext != null) {
|
|
52
|
+
output.additionalContext = result.additionalContext;
|
|
53
|
+
}
|
|
54
|
+
if (result.persistEnv != null && Object.keys(result.persistEnv).length > 0) {
|
|
55
|
+
output.persistEnv = result.persistEnv;
|
|
56
|
+
}
|
|
57
|
+
return output;
|
|
58
|
+
}
|
|
59
|
+
function renderToolExecuteAfterOutput(result) {
|
|
60
|
+
const output = {};
|
|
61
|
+
if (result.additionalContext != null) {
|
|
62
|
+
output.additionalContext = result.additionalContext;
|
|
63
|
+
}
|
|
64
|
+
if (result.persistEnv != null && Object.keys(result.persistEnv).length > 0) {
|
|
65
|
+
output.persistEnv = result.persistEnv;
|
|
66
|
+
}
|
|
67
|
+
return output;
|
|
68
|
+
}
|
|
69
|
+
function renderShellEnvOutput(result) {
|
|
70
|
+
const output = {};
|
|
71
|
+
// The shell.env hook's primary purpose is env injection.
|
|
72
|
+
// Map persistEnv to the native env field.
|
|
73
|
+
if (result.persistEnv != null && Object.keys(result.persistEnv).length > 0) {
|
|
74
|
+
output.env = result.persistEnv;
|
|
75
|
+
}
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
function renderGenericOutput(result) {
|
|
79
|
+
const output = {};
|
|
80
|
+
if (result.additionalContext != null) {
|
|
81
|
+
output.additionalContext = result.additionalContext;
|
|
82
|
+
}
|
|
83
|
+
if (result.persistEnv != null && Object.keys(result.persistEnv).length > 0) {
|
|
84
|
+
output.persistEnv = result.persistEnv;
|
|
85
|
+
}
|
|
86
|
+
return output;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":";;AAoDA,oDAgBC;AAvBD;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAClC,MAAyB,EACzB,eAAuB;IAEvB,QAAQ,eAAe,EAAE,CAAC;QACxB,KAAK,iBAAiB;YACpB,OAAO,0BAA0B,CAAC,MAAM,CAA4B,CAAC;QACvE,KAAK,qBAAqB;YACxB,OAAO,6BAA6B,CA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,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACtD,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3E,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a session ID for OpenCode.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode provides a native session ID in the event payload.
|
|
5
|
+
* Resolution priority:
|
|
6
|
+
*
|
|
7
|
+
* 1. Explicit env: AGENT_SESSION_ID or HOOKS_PROXY_SESSION_ID
|
|
8
|
+
* 2. Native session ID from the event payload (`sessionId`)
|
|
9
|
+
* 3. OpenCode-specific env: OPENCODE_SESSION_ID
|
|
10
|
+
* 4. Derived from workspace (cwd) + a date-bucket fallback
|
|
11
|
+
*
|
|
12
|
+
* Spec section 9.2 -- session ID quality: 'native'.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveSessionId(eventData: Record<string, unknown>, env: Record<string, string>): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Derive a deterministic session ID from the workspace directory.
|
|
17
|
+
*
|
|
18
|
+
* Uses a 15-minute time bucket so that events within the same working
|
|
19
|
+
* session are grouped together, while separate launches in different
|
|
20
|
+
* time windows get different IDs.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deriveSessionId(cwd: string): string;
|
|
23
|
+
//# 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;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,MAAM,GAAG,IAAI,CA0Bf;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMnD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveSessionId = resolveSessionId;
|
|
37
|
+
exports.deriveSessionId = deriveSessionId;
|
|
38
|
+
const crypto = __importStar(require("crypto"));
|
|
39
|
+
/**
|
|
40
|
+
* Resolve a session ID for OpenCode.
|
|
41
|
+
*
|
|
42
|
+
* OpenCode provides a native session ID in the event payload.
|
|
43
|
+
* Resolution priority:
|
|
44
|
+
*
|
|
45
|
+
* 1. Explicit env: AGENT_SESSION_ID or HOOKS_PROXY_SESSION_ID
|
|
46
|
+
* 2. Native session ID from the event payload (`sessionId`)
|
|
47
|
+
* 3. OpenCode-specific env: OPENCODE_SESSION_ID
|
|
48
|
+
* 4. Derived from workspace (cwd) + a date-bucket fallback
|
|
49
|
+
*
|
|
50
|
+
* Spec section 9.2 -- session ID quality: 'native'.
|
|
51
|
+
*/
|
|
52
|
+
function resolveSessionId(eventData, env) {
|
|
53
|
+
// 1. Explicit session ID from env (highest priority)
|
|
54
|
+
if (env['AGENT_SESSION_ID']) {
|
|
55
|
+
return env['AGENT_SESSION_ID'];
|
|
56
|
+
}
|
|
57
|
+
if (env['HOOKS_PROXY_SESSION_ID']) {
|
|
58
|
+
return env['HOOKS_PROXY_SESSION_ID'];
|
|
59
|
+
}
|
|
60
|
+
// 2. Native session ID from event payload
|
|
61
|
+
if (typeof eventData['sessionId'] === 'string' && eventData['sessionId']) {
|
|
62
|
+
return eventData['sessionId'];
|
|
63
|
+
}
|
|
64
|
+
// 3. OpenCode-specific env
|
|
65
|
+
if (env['OPENCODE_SESSION_ID']) {
|
|
66
|
+
return env['OPENCODE_SESSION_ID'];
|
|
67
|
+
}
|
|
68
|
+
// 4. Derive from workspace + date bucket
|
|
69
|
+
const cwd = eventData['cwd'] ?? env['PWD'] ?? null;
|
|
70
|
+
if (cwd != null) {
|
|
71
|
+
return deriveSessionId(cwd);
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Derive a deterministic session ID from the workspace directory.
|
|
77
|
+
*
|
|
78
|
+
* Uses a 15-minute time bucket so that events within the same working
|
|
79
|
+
* session are grouped together, while separate launches in different
|
|
80
|
+
* time windows get different IDs.
|
|
81
|
+
*/
|
|
82
|
+
function deriveSessionId(cwd) {
|
|
83
|
+
const bucketMs = 15 * 60 * 1000; // 15 minutes
|
|
84
|
+
const timeBucket = Math.floor(Date.now() / bucketMs);
|
|
85
|
+
const input = `opencode:${cwd}:${timeBucket}`;
|
|
86
|
+
const hash = crypto.createHash('sha256').update(input).digest('hex').slice(0, 16);
|
|
87
|
+
return `opencode-derived-${hash}`;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=session-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-resolver.js","sourceRoot":"","sources":["../src/session-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,4CA6BC;AASD,0CAMC;AA3DD,+CAAiC;AAEjC;;;;;;;;;;;;GAYG;AACH,SAAgB,gBAAgB,CAC9B,SAAkC,EAClC,GAA2B;IAE3B,qDAAqD;IACrD,IAAI,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACjC,CAAC;IACD,IAAI,GAAG,CAAC,wBAAwB,CAAC,EAAE,CAAC;QAClC,OAAO,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACvC,CAAC;IAED,0CAA0C;IAC1C,IAAI,OAAO,SAAS,CAAC,WAAW,CAAC,KAAK,QAAQ,IAAI,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;QACzE,OAAO,SAAS,CAAC,WAAW,CAAW,CAAC;IAC1C,CAAC;IAED,2BAA2B;IAC3B,IAAI,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACpC,CAAC;IAED,yCAAyC;IACzC,MAAM,GAAG,GAAI,SAAS,CAAC,KAAK,CAAwB,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAC3E,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,YAAY,GAAG,IAAI,UAAU,EAAE,CAAC;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClF,OAAO,oBAAoB,IAAI,EAAE,CAAC;AACpC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5c-ai/hooks-adapter-opencode",
|
|
3
|
+
"version": "5.1.1-staging.52898ebfc24f",
|
|
4
|
+
"description": "OpenCode 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-opencode"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/a5c-ai/babysitter/tree/main/packages/adapters/hooks/adapter-opencode#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
|
+
}
|