mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 08:00:59 +00:00
Add ./hooks subpath export for cleaner imports
This commit is contained in:
parent
7c553acd1e
commit
1abc635044
4 changed files with 18 additions and 11 deletions
|
|
@ -480,7 +480,7 @@ Hooks are TypeScript modules that extend pi's behavior by subscribing to lifecyc
|
||||||
**Quick example** (permission gate):
|
**Quick example** (permission gate):
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
pi.on("tool_call", async (event, ctx) => {
|
pi.on("tool_call", async (event, ctx) => {
|
||||||
|
|
@ -499,7 +499,7 @@ Use `pi.send(text, attachments?)` to inject messages into the session. If the ag
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
pi.on("session_start", async () => {
|
pi.on("session_start", async () => {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ You can also add explicit hook paths in `~/.pi/agent/settings.json`:
|
||||||
A hook is a TypeScript file that exports a default function. The function receives a `HookAPI` object used to subscribe to events.
|
A hook is a TypeScript file that exports a default function. The function receives a `HookAPI` object used to subscribe to events.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
pi.on("session_start", async (event, ctx) => {
|
pi.on("session_start", async (event, ctx) => {
|
||||||
|
|
@ -298,7 +298,7 @@ If the agent is currently streaming, the message is queued. Otherwise, a new age
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
pi.on("session_start", async (event, ctx) => {
|
pi.on("session_start", async (event, ctx) => {
|
||||||
|
|
@ -328,7 +328,7 @@ To trigger: `echo "Run the tests" > /tmp/agent-trigger.txt`
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import * as http from "node:http";
|
import * as http from "node:http";
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
pi.on("session_start", async (event, ctx) => {
|
pi.on("session_start", async (event, ctx) => {
|
||||||
|
|
@ -358,7 +358,7 @@ To trigger: `curl -X POST http://localhost:3333 -d "CI build failed"`
|
||||||
### Shitty Permission Gate
|
### Shitty Permission Gate
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
const dangerousPatterns = [
|
const dangerousPatterns = [
|
||||||
|
|
@ -394,7 +394,7 @@ export default function (pi: HookAPI) {
|
||||||
Stash code state at each turn so `/branch` can restore it.
|
Stash code state at each turn so `/branch` can restore it.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
const checkpoints = new Map<number, string>();
|
const checkpoints = new Map<number, string>();
|
||||||
|
|
@ -434,7 +434,7 @@ export default function (pi: HookAPI) {
|
||||||
### Block Writes to Certain Paths
|
### Block Writes to Certain Paths
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import type { HookAPI } from "@mariozechner/pi-coding-agent";
|
import type { HookAPI } from "@mariozechner/pi-coding-agent/hooks";
|
||||||
|
|
||||||
export default function (pi: HookAPI) {
|
export default function (pi: HookAPI) {
|
||||||
const protectedPaths = [".env", ".git/", "node_modules/"];
|
const protectedPaths = [".env", ".git/", "node_modules/"];
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,16 @@
|
||||||
},
|
},
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"import": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"./hooks": {
|
||||||
|
"types": "./dist/core/hooks/index.d.ts",
|
||||||
|
"import": "./dist/core/hooks/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"docs",
|
"docs",
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
{
|
{
|
||||||
"name": "pi-mono",
|
"name": "pi-mono",
|
||||||
"path": "."
|
"path": "."
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "../../.pi/hooks"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {}
|
"settings": {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue