@cleocode/adapters 2026.4.31 → 2026.4.36
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/dist/index.js +641 -5
- package/dist/index.js.map +4 -4
- package/dist/providers/claude-code/adapter.js +184 -0
- package/dist/providers/claude-code/adapter.js.map +1 -0
- package/dist/providers/claude-code/context-monitor.js +159 -0
- package/dist/providers/claude-code/context-monitor.js.map +1 -0
- package/dist/providers/claude-code/hooks.js +286 -0
- package/dist/providers/claude-code/hooks.js.map +1 -0
- package/dist/providers/claude-code/index.js +41 -0
- package/dist/providers/claude-code/index.js.map +1 -0
- package/dist/providers/claude-code/install.js +199 -0
- package/dist/providers/claude-code/install.js.map +1 -0
- package/dist/providers/claude-code/paths.js +41 -0
- package/dist/providers/claude-code/paths.js.map +1 -0
- package/dist/providers/claude-code/spawn.js +171 -0
- package/dist/providers/claude-code/spawn.js.map +1 -0
- package/dist/providers/claude-code/statusline.js +130 -0
- package/dist/providers/claude-code/statusline.js.map +1 -0
- package/dist/providers/claude-code/task-sync.js +119 -0
- package/dist/providers/claude-code/task-sync.js.map +1 -0
- package/dist/providers/claude-code/transport.js +29 -0
- package/dist/providers/claude-code/transport.js.map +1 -0
- package/dist/providers/codex/adapter.js +146 -0
- package/dist/providers/codex/adapter.js.map +1 -0
- package/dist/providers/codex/hooks.js +113 -0
- package/dist/providers/codex/hooks.js.map +1 -0
- package/dist/providers/codex/index.js +39 -0
- package/dist/providers/codex/index.js.map +1 -0
- package/dist/providers/codex/install.js +124 -0
- package/dist/providers/codex/install.js.map +1 -0
- package/dist/providers/cursor/adapter.js +151 -0
- package/dist/providers/cursor/adapter.js.map +1 -0
- package/dist/providers/cursor/hooks.js +208 -0
- package/dist/providers/cursor/hooks.js.map +1 -0
- package/dist/providers/cursor/index.js +36 -0
- package/dist/providers/cursor/index.js.map +1 -0
- package/dist/providers/cursor/install.js +180 -0
- package/dist/providers/cursor/install.js.map +1 -0
- package/dist/providers/cursor/spawn.js +59 -0
- package/dist/providers/cursor/spawn.js.map +1 -0
- package/dist/providers/gemini-cli/adapter.js +158 -0
- package/dist/providers/gemini-cli/adapter.js.map +1 -0
- package/dist/providers/gemini-cli/hooks.js +128 -0
- package/dist/providers/gemini-cli/hooks.js.map +1 -0
- package/dist/providers/gemini-cli/index.js +39 -0
- package/dist/providers/gemini-cli/index.js.map +1 -0
- package/dist/providers/gemini-cli/install.js +124 -0
- package/dist/providers/gemini-cli/install.js.map +1 -0
- package/dist/providers/kimi/adapter.js +145 -0
- package/dist/providers/kimi/adapter.js.map +1 -0
- package/dist/providers/kimi/hooks.js +79 -0
- package/dist/providers/kimi/hooks.js.map +1 -0
- package/dist/providers/kimi/index.js +39 -0
- package/dist/providers/kimi/index.js.map +1 -0
- package/dist/providers/kimi/install.js +124 -0
- package/dist/providers/kimi/install.js.map +1 -0
- package/dist/providers/opencode/adapter.js +166 -0
- package/dist/providers/opencode/adapter.js.map +1 -0
- package/dist/providers/opencode/hooks.js +206 -0
- package/dist/providers/opencode/hooks.js.map +1 -0
- package/dist/providers/opencode/index.js +37 -0
- package/dist/providers/opencode/index.js.map +1 -0
- package/dist/providers/opencode/install.js +115 -0
- package/dist/providers/opencode/install.js.map +1 -0
- package/dist/providers/opencode/spawn.js +241 -0
- package/dist/providers/opencode/spawn.js.map +1 -0
- package/dist/providers/pi/adapter.d.ts +102 -0
- package/dist/providers/pi/adapter.d.ts.map +1 -0
- package/dist/providers/pi/adapter.js +220 -0
- package/dist/providers/pi/adapter.js.map +1 -0
- package/dist/providers/pi/hooks.d.ts +149 -0
- package/dist/providers/pi/hooks.d.ts.map +1 -0
- package/dist/providers/pi/hooks.js +223 -0
- package/dist/providers/pi/hooks.js.map +1 -0
- package/dist/providers/pi/index.d.ts +36 -0
- package/dist/providers/pi/index.d.ts.map +1 -0
- package/dist/providers/pi/index.js +38 -0
- package/dist/providers/pi/index.js.map +1 -0
- package/dist/providers/pi/install.d.ts +68 -0
- package/dist/providers/pi/install.d.ts.map +1 -0
- package/dist/providers/pi/install.js +175 -0
- package/dist/providers/pi/install.js.map +1 -0
- package/dist/providers/pi/spawn.d.ts +68 -0
- package/dist/providers/pi/spawn.d.ts.map +1 -0
- package/dist/providers/pi/spawn.js +187 -0
- package/dist/providers/pi/spawn.js.map +1 -0
- package/dist/providers/shared/transcript-reader.js +124 -0
- package/dist/providers/shared/transcript-reader.js.map +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +92 -0
- package/dist/registry.js.map +1 -0
- package/package.json +3 -3
- package/src/providers/pi/adapter.ts +240 -0
- package/src/providers/pi/hooks.ts +232 -0
- package/src/providers/pi/index.ts +41 -0
- package/src/providers/pi/install.ts +189 -0
- package/src/providers/pi/manifest.json +40 -0
- package/src/providers/pi/spawn.ts +207 -0
- package/src/registry.ts +6 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Adapter
|
|
3
|
+
*
|
|
4
|
+
* Main CLEOProviderAdapter implementation for the Pi coding agent
|
|
5
|
+
* (https://github.com/badlogic/pi-mono). Pi is CAAMP's first-class primary
|
|
6
|
+
* harness and owns skills, instructions, extensions, and subagent spawning
|
|
7
|
+
* through native filesystem conventions.
|
|
8
|
+
*
|
|
9
|
+
* Pi supports 11 of 16 CAAMP canonical events through its TypeScript extension
|
|
10
|
+
* system (session_start, session_shutdown, input, turn_end, tool_call,
|
|
11
|
+
* tool_result, before_agent_start, agent_end, before_provider_request, context).
|
|
12
|
+
*
|
|
13
|
+
* Detection: PI_CLI_PATH env var, PI_CODING_AGENT_DIR env var, PI_HOME env var,
|
|
14
|
+
* or presence of ~/.pi/agent/ directory.
|
|
15
|
+
*
|
|
16
|
+
* @task T553
|
|
17
|
+
*/
|
|
18
|
+
import { exec } from 'node:child_process';
|
|
19
|
+
import { existsSync } from 'node:fs';
|
|
20
|
+
import { homedir } from 'node:os';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import { promisify } from 'node:util';
|
|
23
|
+
import { PiHookProvider } from './hooks.js';
|
|
24
|
+
import { PiInstallProvider } from './install.js';
|
|
25
|
+
import { PiSpawnProvider } from './spawn.js';
|
|
26
|
+
const execAsync = promisify(exec);
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the Pi global state root directory.
|
|
29
|
+
*
|
|
30
|
+
* Honours `PI_CODING_AGENT_DIR` env var when set (with `~` expansion),
|
|
31
|
+
* then `PI_HOME`, then falls back to `~/.pi/agent`.
|
|
32
|
+
*/
|
|
33
|
+
function getPiAgentDir() {
|
|
34
|
+
const env = process.env['PI_CODING_AGENT_DIR'];
|
|
35
|
+
if (env !== undefined && env.length > 0) {
|
|
36
|
+
if (env === '~')
|
|
37
|
+
return homedir();
|
|
38
|
+
if (env.startsWith('~/'))
|
|
39
|
+
return join(homedir(), env.slice(2));
|
|
40
|
+
return env;
|
|
41
|
+
}
|
|
42
|
+
const piHome = process.env['PI_HOME'];
|
|
43
|
+
if (piHome !== undefined && piHome.length > 0) {
|
|
44
|
+
return join(piHome, 'agent');
|
|
45
|
+
}
|
|
46
|
+
return join(homedir(), '.pi', 'agent');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* CLEO provider adapter for Pi coding agent.
|
|
50
|
+
*
|
|
51
|
+
* Bridges CLEO's adapter system with Pi's native capabilities:
|
|
52
|
+
* - Hooks: Maps Pi events (session_start, tool_call, etc.) to CAAMP events
|
|
53
|
+
* - Spawn: Launches subagent processes via the `pi` CLI
|
|
54
|
+
* - Install: Manages AGENTS.md instruction files and global Pi state root
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* Pi is CAAMP's first-class primary harness (ADR-035). It supports 11 of 16
|
|
58
|
+
* canonical hook events through its TypeScript extension system. Extensions
|
|
59
|
+
* live at `~/.pi/agent/extensions/` (global) or `<projectDir>/.pi/extensions/`
|
|
60
|
+
* (project scope).
|
|
61
|
+
*
|
|
62
|
+
* The session_shutdown event handler in `cleo-cant-bridge.ts` clears module
|
|
63
|
+
* cache. The adapter's hook mapping ensures that Pi's session lifecycle events
|
|
64
|
+
* are visible in the CAAMP event stream for downstream listeners (e.g. memory
|
|
65
|
+
* refresh triggers, backup triggers).
|
|
66
|
+
*
|
|
67
|
+
* Detection hierarchy (first match wins):
|
|
68
|
+
* 1. `PI_CLI_PATH` env var set
|
|
69
|
+
* 2. `PI_CODING_AGENT_DIR` env var set
|
|
70
|
+
* 3. `PI_HOME` env var set
|
|
71
|
+
* 4. `~/.pi/agent/` directory exists
|
|
72
|
+
* 5. `pi` CLI available in PATH
|
|
73
|
+
*/
|
|
74
|
+
export class PiAdapter {
|
|
75
|
+
/** Unique provider identifier. */
|
|
76
|
+
id = 'pi';
|
|
77
|
+
/** Human-readable provider name. */
|
|
78
|
+
name = 'Pi';
|
|
79
|
+
/** Adapter version string. */
|
|
80
|
+
version = '1.0.0';
|
|
81
|
+
/** Declared capabilities for this provider. */
|
|
82
|
+
capabilities = {
|
|
83
|
+
supportsHooks: true,
|
|
84
|
+
// 11/16 canonical events — derived from piEventCatalog in CAAMP hook-mappings.json.
|
|
85
|
+
// ResponseComplete, PostToolUseFailure, PermissionRequest, PostModel, PostCompact,
|
|
86
|
+
// and ConfigChange are not supported by Pi's extension system.
|
|
87
|
+
supportedHookEvents: [
|
|
88
|
+
'SessionStart',
|
|
89
|
+
'SessionEnd',
|
|
90
|
+
'PromptSubmit',
|
|
91
|
+
'Notification',
|
|
92
|
+
'PreToolUse',
|
|
93
|
+
'PostToolUse',
|
|
94
|
+
'SubagentStart',
|
|
95
|
+
'SubagentStop',
|
|
96
|
+
'PreModel',
|
|
97
|
+
'PreCompact',
|
|
98
|
+
],
|
|
99
|
+
supportsSpawn: true,
|
|
100
|
+
supportsInstall: true,
|
|
101
|
+
supportsInstructionFiles: true,
|
|
102
|
+
instructionFilePattern: 'AGENTS.md',
|
|
103
|
+
supportsContextMonitor: false,
|
|
104
|
+
supportsStatusline: false,
|
|
105
|
+
supportsProviderPaths: true,
|
|
106
|
+
supportsTransport: false,
|
|
107
|
+
supportsTaskSync: false,
|
|
108
|
+
};
|
|
109
|
+
/** Hook provider for CAAMP event mapping and registration. */
|
|
110
|
+
hooks;
|
|
111
|
+
/** Spawn provider for launching subagent processes via `pi` CLI. */
|
|
112
|
+
spawn;
|
|
113
|
+
/** Install provider for managing AGENTS.md instruction files. */
|
|
114
|
+
install;
|
|
115
|
+
/** Project directory this adapter was initialized with, or null. */
|
|
116
|
+
projectDir = null;
|
|
117
|
+
/** Whether {@link initialize} has been called. */
|
|
118
|
+
initialized = false;
|
|
119
|
+
constructor() {
|
|
120
|
+
this.hooks = new PiHookProvider();
|
|
121
|
+
this.spawn = new PiSpawnProvider();
|
|
122
|
+
this.install = new PiInstallProvider();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Initialize the adapter for a given project directory.
|
|
126
|
+
*
|
|
127
|
+
* Validates the environment by checking for the Pi CLI and Pi state root.
|
|
128
|
+
*
|
|
129
|
+
* @param projectDir - Root directory of the project
|
|
130
|
+
*/
|
|
131
|
+
async initialize(projectDir) {
|
|
132
|
+
this.projectDir = projectDir;
|
|
133
|
+
this.initialized = true;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Dispose the adapter and clean up resources.
|
|
137
|
+
*
|
|
138
|
+
* Unregisters hooks and releases any tracked state.
|
|
139
|
+
*/
|
|
140
|
+
async dispose() {
|
|
141
|
+
if (this.hooks.isRegistered()) {
|
|
142
|
+
await this.hooks.unregisterNativeHooks();
|
|
143
|
+
}
|
|
144
|
+
this.initialized = false;
|
|
145
|
+
this.projectDir = null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Run a health check to verify Pi is accessible.
|
|
149
|
+
*
|
|
150
|
+
* Checks:
|
|
151
|
+
* 1. Adapter has been initialized
|
|
152
|
+
* 2. Pi CLI is available (via PI_CLI_PATH or `which pi`)
|
|
153
|
+
* 3. Pi global state root (~/.pi/agent/ or PI_CODING_AGENT_DIR) exists
|
|
154
|
+
*
|
|
155
|
+
* @returns Health status with details about each check
|
|
156
|
+
*/
|
|
157
|
+
async healthCheck() {
|
|
158
|
+
const details = {};
|
|
159
|
+
if (!this.initialized) {
|
|
160
|
+
return {
|
|
161
|
+
healthy: false,
|
|
162
|
+
provider: this.id,
|
|
163
|
+
details: { error: 'Adapter not initialized' },
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// Check Pi CLI availability
|
|
167
|
+
let cliAvailable = false;
|
|
168
|
+
const cliPath = process.env['PI_CLI_PATH'] ?? 'pi';
|
|
169
|
+
try {
|
|
170
|
+
if (cliPath !== 'pi') {
|
|
171
|
+
const { stdout } = await execAsync(`test -x "${cliPath}" && echo ok`);
|
|
172
|
+
cliAvailable = stdout.trim() === 'ok';
|
|
173
|
+
details.cliPath = cliPath;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const { stdout } = await execAsync('which pi');
|
|
177
|
+
cliAvailable = stdout.trim().length > 0;
|
|
178
|
+
details.cliPath = stdout.trim();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
details.cliAvailable = false;
|
|
183
|
+
}
|
|
184
|
+
// Check for Pi global state root
|
|
185
|
+
const agentDir = getPiAgentDir();
|
|
186
|
+
const agentDirExists = existsSync(agentDir);
|
|
187
|
+
details.agentDirExists = agentDirExists;
|
|
188
|
+
details.agentDir = agentDir;
|
|
189
|
+
// Check for project-level .pi/ directory
|
|
190
|
+
if (this.projectDir) {
|
|
191
|
+
const projectPiDir = join(this.projectDir, '.pi');
|
|
192
|
+
details.projectPiDirExists = existsSync(projectPiDir);
|
|
193
|
+
}
|
|
194
|
+
// Check detection env vars
|
|
195
|
+
details.piCodingAgentDirSet = process.env['PI_CODING_AGENT_DIR'] !== undefined;
|
|
196
|
+
details.piHomeSet = process.env['PI_HOME'] !== undefined;
|
|
197
|
+
details.piCliPathSet = process.env['PI_CLI_PATH'] !== undefined;
|
|
198
|
+
// Healthy if either CLI is available or global state root exists
|
|
199
|
+
const healthy = cliAvailable || agentDirExists;
|
|
200
|
+
details.cliAvailable = cliAvailable;
|
|
201
|
+
return {
|
|
202
|
+
healthy,
|
|
203
|
+
provider: this.id,
|
|
204
|
+
details,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check whether the adapter has been initialized.
|
|
209
|
+
*/
|
|
210
|
+
isInitialized() {
|
|
211
|
+
return this.initialized;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get the project directory this adapter was initialized with.
|
|
215
|
+
*/
|
|
216
|
+
getProjectDir() {
|
|
217
|
+
return this.projectDir;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/providers/pi/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAMtC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC;;;;;GAKG;AACH,SAAS,aAAa;IACpB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC/C,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,GAAG,C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QAEhE,iEAAiE;QACjE,MAAM,OAAO,GAAG,YAAY,IAAI,cAAc,CAAC;QAC/C,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;QAEpC,OAAO;YACL,OAAO;YACP,QAAQ,EAAE,IAAI,CAAC,EAAE;YACjB,OAAO;SACR,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Hook Provider
|
|
3
|
+
*
|
|
4
|
+
* Maps Pi coding agent native event names to CAAMP canonical hook events.
|
|
5
|
+
* Pi supports 11 of 16 canonical events through its extension/event system.
|
|
6
|
+
*
|
|
7
|
+
* Event translation uses CAAMP normalizer APIs:
|
|
8
|
+
* - `toCanonical(nativeName, 'pi')` for runtime event name resolution
|
|
9
|
+
* - `getSupportedEvents('pi')` to enumerate supported canonical events
|
|
10
|
+
* - `getProviderHookProfile('pi')` for the full provider profile
|
|
11
|
+
*
|
|
12
|
+
* A static map derived from CAAMP hook-mappings.json piEventCatalog is
|
|
13
|
+
* maintained as a fallback for environments where CAAMP's runtime
|
|
14
|
+
* resolution is unavailable.
|
|
15
|
+
*
|
|
16
|
+
* Mappings (11/16 supported):
|
|
17
|
+
* session_start → SessionStart
|
|
18
|
+
* session_shutdown → SessionEnd
|
|
19
|
+
* input → PromptSubmit
|
|
20
|
+
* turn_end → Notification (assistant turn complete)
|
|
21
|
+
* tool_call → PreToolUse
|
|
22
|
+
* tool_result → PostToolUse
|
|
23
|
+
* before_agent_start → SubagentStart
|
|
24
|
+
* agent_end → SubagentStop
|
|
25
|
+
* before_provider_request → PreModel
|
|
26
|
+
* context → PreCompact (context assembly = pre-compaction proxy)
|
|
27
|
+
*
|
|
28
|
+
* Unsupported (5/16):
|
|
29
|
+
* ResponseComplete, PostToolUseFailure, PermissionRequest,
|
|
30
|
+
* PostModel, PostCompact, ConfigChange
|
|
31
|
+
*
|
|
32
|
+
* @task T553
|
|
33
|
+
*/
|
|
34
|
+
import type { AdapterHookProvider } from '@cleocode/contracts';
|
|
35
|
+
/**
|
|
36
|
+
* Hook provider for Pi coding agent.
|
|
37
|
+
*
|
|
38
|
+
* Pi registers hooks via its TypeScript extension system. Extensions are
|
|
39
|
+
* loaded from `~/.pi/agent/extensions/*.ts` (global) or
|
|
40
|
+
* `<projectDir>/.pi/extensions/*.ts` (project scope).
|
|
41
|
+
*
|
|
42
|
+
* Event mapping is based on the `piEventCatalog` block in CAAMP
|
|
43
|
+
* hook-mappings.json. Async accessors (`getSupportedCanonicalEvents`,
|
|
44
|
+
* `getProviderProfile`) call CAAMP directly when available.
|
|
45
|
+
*
|
|
46
|
+
* Since hooks are registered through the extension system (managed by the
|
|
47
|
+
* install provider), `registerNativeHooks` and `unregisterNativeHooks`
|
|
48
|
+
* track registration state without performing filesystem operations.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Pi is CAAMP's first-class primary harness (ADR-035). Its native events
|
|
52
|
+
* use snake_case (e.g. `session_start`, `tool_call`) unlike the PascalCase
|
|
53
|
+
* CAAMP canonical names. The static event map covers all 11 supported events.
|
|
54
|
+
* Async CAAMP accessors fall back to the static map when CAAMP is unavailable.
|
|
55
|
+
*
|
|
56
|
+
* Pi does NOT support ResponseComplete, PostToolUseFailure, PermissionRequest,
|
|
57
|
+
* PostModel, PostCompact, or ConfigChange canonical events.
|
|
58
|
+
*
|
|
59
|
+
* All hook dispatch is best-effort — hooks MUST never block or crash Pi.
|
|
60
|
+
*
|
|
61
|
+
* @task T553
|
|
62
|
+
*/
|
|
63
|
+
export declare class PiHookProvider implements AdapterHookProvider {
|
|
64
|
+
/** Whether hooks have been registered for the current session. */
|
|
65
|
+
private registered;
|
|
66
|
+
/**
|
|
67
|
+
* Map a Pi native event name to a CAAMP canonical hook event name.
|
|
68
|
+
*
|
|
69
|
+
* Looks up the native event name in the map derived from the
|
|
70
|
+
* `piEventCatalog` block in CAAMP hook-mappings.json.
|
|
71
|
+
* Returns null for unrecognised or unsupported events.
|
|
72
|
+
*
|
|
73
|
+
* @param providerEvent - Pi native event (e.g. "session_start", "tool_call")
|
|
74
|
+
* @returns CAAMP canonical event name, or null if unmapped
|
|
75
|
+
* @task T553
|
|
76
|
+
*/
|
|
77
|
+
mapProviderEvent(providerEvent: string): string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Register native hooks for a project.
|
|
80
|
+
*
|
|
81
|
+
* For Pi, hooks are registered via the extension system, managed by
|
|
82
|
+
* the install provider. This method marks hooks as registered without
|
|
83
|
+
* performing filesystem operations.
|
|
84
|
+
*
|
|
85
|
+
* Iterating supported events is handled at install time using
|
|
86
|
+
* `getSupportedCanonicalEvents()` to enumerate all 11 supported hooks.
|
|
87
|
+
*
|
|
88
|
+
* @param _projectDir - Project directory (unused; Pi uses extension system)
|
|
89
|
+
* @task T553
|
|
90
|
+
*/
|
|
91
|
+
registerNativeHooks(_projectDir: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Unregister native hooks.
|
|
94
|
+
*
|
|
95
|
+
* For Pi, this is a no-op since hooks are managed through the extension
|
|
96
|
+
* system. Unregistration happens via the install provider's uninstall method.
|
|
97
|
+
*
|
|
98
|
+
* @task T553
|
|
99
|
+
*/
|
|
100
|
+
unregisterNativeHooks(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Check whether hooks have been registered via `registerNativeHooks`.
|
|
103
|
+
*/
|
|
104
|
+
isRegistered(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Get the native→canonical event mapping for introspection and debugging.
|
|
107
|
+
*
|
|
108
|
+
* Returns the map derived from the `piEventCatalog` block in CAAMP
|
|
109
|
+
* hook-mappings.json. Use `getSupportedCanonicalEvents()` to enumerate
|
|
110
|
+
* canonical names via live CAAMP APIs.
|
|
111
|
+
*
|
|
112
|
+
* @returns Immutable record of native event name → canonical event name
|
|
113
|
+
*/
|
|
114
|
+
getEventMap(): Readonly<Record<string, string>>;
|
|
115
|
+
/**
|
|
116
|
+
* Enumerate supported canonical events via CAAMP's `getSupportedEvents()`.
|
|
117
|
+
*
|
|
118
|
+
* Calls `getSupportedEvents('pi')` from the CAAMP normalizer to get the
|
|
119
|
+
* authoritative list. Pi supports 11 of 16 canonical events. Falls back
|
|
120
|
+
* to the unique values of the static event map when CAAMP is unavailable.
|
|
121
|
+
*
|
|
122
|
+
* @returns Array of CAAMP canonical event names supported by Pi
|
|
123
|
+
* @task T553
|
|
124
|
+
*/
|
|
125
|
+
getSupportedCanonicalEvents(): Promise<string[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve the full provider hook profile from CAAMP.
|
|
128
|
+
*
|
|
129
|
+
* Calls `getProviderHookProfile('pi')` from the CAAMP normalizer to get
|
|
130
|
+
* the complete profile including hook system type, config path, handler
|
|
131
|
+
* types, and all event mappings. Returns null when CAAMP is unavailable.
|
|
132
|
+
*
|
|
133
|
+
* @returns Provider hook profile or null if CAAMP is unavailable
|
|
134
|
+
* @task T553
|
|
135
|
+
*/
|
|
136
|
+
getProviderProfile(): Promise<unknown | null>;
|
|
137
|
+
/**
|
|
138
|
+
* Translate a CAAMP canonical event to its Pi native name via CAAMP.
|
|
139
|
+
*
|
|
140
|
+
* Calls `toNative(canonical, 'pi')` from the CAAMP normalizer.
|
|
141
|
+
* Returns null for unsupported events or when CAAMP is unavailable.
|
|
142
|
+
*
|
|
143
|
+
* @param canonical - CAAMP canonical event name (e.g. "PreToolUse")
|
|
144
|
+
* @returns Pi native event name or null
|
|
145
|
+
* @task T553
|
|
146
|
+
*/
|
|
147
|
+
toNativeEvent(canonical: string): Promise<string | null>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/providers/pi/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AA2C/D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,cAAe,YAAW,mBAAmB;IACxD,kEAAkE;IAClE,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAItD;;;;;;;;;;;;OAYG;IACG,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7D;;;;;;;OAOG;IACG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;;;;;;;OAQG;IACH,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAI/C;;;;;;;;;OASG;IACG,2BAA2B,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAStD;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IASnD;;;;;;;;;OASG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAU/D"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Hook Provider
|
|
3
|
+
*
|
|
4
|
+
* Maps Pi coding agent native event names to CAAMP canonical hook events.
|
|
5
|
+
* Pi supports 11 of 16 canonical events through its extension/event system.
|
|
6
|
+
*
|
|
7
|
+
* Event translation uses CAAMP normalizer APIs:
|
|
8
|
+
* - `toCanonical(nativeName, 'pi')` for runtime event name resolution
|
|
9
|
+
* - `getSupportedEvents('pi')` to enumerate supported canonical events
|
|
10
|
+
* - `getProviderHookProfile('pi')` for the full provider profile
|
|
11
|
+
*
|
|
12
|
+
* A static map derived from CAAMP hook-mappings.json piEventCatalog is
|
|
13
|
+
* maintained as a fallback for environments where CAAMP's runtime
|
|
14
|
+
* resolution is unavailable.
|
|
15
|
+
*
|
|
16
|
+
* Mappings (11/16 supported):
|
|
17
|
+
* session_start → SessionStart
|
|
18
|
+
* session_shutdown → SessionEnd
|
|
19
|
+
* input → PromptSubmit
|
|
20
|
+
* turn_end → Notification (assistant turn complete)
|
|
21
|
+
* tool_call → PreToolUse
|
|
22
|
+
* tool_result → PostToolUse
|
|
23
|
+
* before_agent_start → SubagentStart
|
|
24
|
+
* agent_end → SubagentStop
|
|
25
|
+
* before_provider_request → PreModel
|
|
26
|
+
* context → PreCompact (context assembly = pre-compaction proxy)
|
|
27
|
+
*
|
|
28
|
+
* Unsupported (5/16):
|
|
29
|
+
* ResponseComplete, PostToolUseFailure, PermissionRequest,
|
|
30
|
+
* PostModel, PostCompact, ConfigChange
|
|
31
|
+
*
|
|
32
|
+
* @task T553
|
|
33
|
+
*/
|
|
34
|
+
/** CAAMP provider identifier for Pi. */
|
|
35
|
+
const PROVIDER_ID = 'pi';
|
|
36
|
+
/**
|
|
37
|
+
* Fallback map from Pi native event names to CAAMP canonical names.
|
|
38
|
+
*
|
|
39
|
+
* Derived from the `piEventCatalog` block in CAAMP hook-mappings.json.
|
|
40
|
+
* Covers all 11 supported events. ResponseComplete, PostToolUseFailure,
|
|
41
|
+
* PermissionRequest, PostModel, PostCompact, and ConfigChange are not
|
|
42
|
+
* supported by Pi and are absent from this map.
|
|
43
|
+
*
|
|
44
|
+
* Used as fallback when CAAMP runtime is unavailable, and as the
|
|
45
|
+
* synchronous implementation of `mapProviderEvent()`.
|
|
46
|
+
*/
|
|
47
|
+
const PI_EVENT_MAP = {
|
|
48
|
+
// piEventCatalog: session_start → SessionStart
|
|
49
|
+
session_start: 'SessionStart',
|
|
50
|
+
// piEventCatalog: session_shutdown → SessionEnd
|
|
51
|
+
session_shutdown: 'SessionEnd',
|
|
52
|
+
// piEventCatalog: input → PromptSubmit
|
|
53
|
+
input: 'PromptSubmit',
|
|
54
|
+
// piEventCatalog: turn_end → Notification (assistant turn complete)
|
|
55
|
+
turn_end: 'Notification',
|
|
56
|
+
// piEventCatalog: tool_call → PreToolUse
|
|
57
|
+
tool_call: 'PreToolUse',
|
|
58
|
+
// piEventCatalog: tool_execution_start → PreToolUse (duplicate path)
|
|
59
|
+
tool_execution_start: 'PreToolUse',
|
|
60
|
+
// piEventCatalog: tool_result → PostToolUse
|
|
61
|
+
tool_result: 'PostToolUse',
|
|
62
|
+
// piEventCatalog: tool_execution_end → PostToolUse (duplicate path)
|
|
63
|
+
tool_execution_end: 'PostToolUse',
|
|
64
|
+
// piEventCatalog: before_agent_start → SubagentStart
|
|
65
|
+
before_agent_start: 'SubagentStart',
|
|
66
|
+
// piEventCatalog: agent_end → SubagentStop
|
|
67
|
+
agent_end: 'SubagentStop',
|
|
68
|
+
// piEventCatalog: before_provider_request → PreModel
|
|
69
|
+
before_provider_request: 'PreModel',
|
|
70
|
+
// piEventCatalog: context → PreCompact (context assembly is the pre-compaction proxy for Pi)
|
|
71
|
+
context: 'PreCompact',
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Hook provider for Pi coding agent.
|
|
75
|
+
*
|
|
76
|
+
* Pi registers hooks via its TypeScript extension system. Extensions are
|
|
77
|
+
* loaded from `~/.pi/agent/extensions/*.ts` (global) or
|
|
78
|
+
* `<projectDir>/.pi/extensions/*.ts` (project scope).
|
|
79
|
+
*
|
|
80
|
+
* Event mapping is based on the `piEventCatalog` block in CAAMP
|
|
81
|
+
* hook-mappings.json. Async accessors (`getSupportedCanonicalEvents`,
|
|
82
|
+
* `getProviderProfile`) call CAAMP directly when available.
|
|
83
|
+
*
|
|
84
|
+
* Since hooks are registered through the extension system (managed by the
|
|
85
|
+
* install provider), `registerNativeHooks` and `unregisterNativeHooks`
|
|
86
|
+
* track registration state without performing filesystem operations.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Pi is CAAMP's first-class primary harness (ADR-035). Its native events
|
|
90
|
+
* use snake_case (e.g. `session_start`, `tool_call`) unlike the PascalCase
|
|
91
|
+
* CAAMP canonical names. The static event map covers all 11 supported events.
|
|
92
|
+
* Async CAAMP accessors fall back to the static map when CAAMP is unavailable.
|
|
93
|
+
*
|
|
94
|
+
* Pi does NOT support ResponseComplete, PostToolUseFailure, PermissionRequest,
|
|
95
|
+
* PostModel, PostCompact, or ConfigChange canonical events.
|
|
96
|
+
*
|
|
97
|
+
* All hook dispatch is best-effort — hooks MUST never block or crash Pi.
|
|
98
|
+
*
|
|
99
|
+
* @task T553
|
|
100
|
+
*/
|
|
101
|
+
export class PiHookProvider {
|
|
102
|
+
/** Whether hooks have been registered for the current session. */
|
|
103
|
+
registered = false;
|
|
104
|
+
/**
|
|
105
|
+
* Map a Pi native event name to a CAAMP canonical hook event name.
|
|
106
|
+
*
|
|
107
|
+
* Looks up the native event name in the map derived from the
|
|
108
|
+
* `piEventCatalog` block in CAAMP hook-mappings.json.
|
|
109
|
+
* Returns null for unrecognised or unsupported events.
|
|
110
|
+
*
|
|
111
|
+
* @param providerEvent - Pi native event (e.g. "session_start", "tool_call")
|
|
112
|
+
* @returns CAAMP canonical event name, or null if unmapped
|
|
113
|
+
* @task T553
|
|
114
|
+
*/
|
|
115
|
+
mapProviderEvent(providerEvent) {
|
|
116
|
+
return PI_EVENT_MAP[providerEvent] ?? null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Register native hooks for a project.
|
|
120
|
+
*
|
|
121
|
+
* For Pi, hooks are registered via the extension system, managed by
|
|
122
|
+
* the install provider. This method marks hooks as registered without
|
|
123
|
+
* performing filesystem operations.
|
|
124
|
+
*
|
|
125
|
+
* Iterating supported events is handled at install time using
|
|
126
|
+
* `getSupportedCanonicalEvents()` to enumerate all 11 supported hooks.
|
|
127
|
+
*
|
|
128
|
+
* @param _projectDir - Project directory (unused; Pi uses extension system)
|
|
129
|
+
* @task T553
|
|
130
|
+
*/
|
|
131
|
+
async registerNativeHooks(_projectDir) {
|
|
132
|
+
this.registered = true;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Unregister native hooks.
|
|
136
|
+
*
|
|
137
|
+
* For Pi, this is a no-op since hooks are managed through the extension
|
|
138
|
+
* system. Unregistration happens via the install provider's uninstall method.
|
|
139
|
+
*
|
|
140
|
+
* @task T553
|
|
141
|
+
*/
|
|
142
|
+
async unregisterNativeHooks() {
|
|
143
|
+
this.registered = false;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Check whether hooks have been registered via `registerNativeHooks`.
|
|
147
|
+
*/
|
|
148
|
+
isRegistered() {
|
|
149
|
+
return this.registered;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the native→canonical event mapping for introspection and debugging.
|
|
153
|
+
*
|
|
154
|
+
* Returns the map derived from the `piEventCatalog` block in CAAMP
|
|
155
|
+
* hook-mappings.json. Use `getSupportedCanonicalEvents()` to enumerate
|
|
156
|
+
* canonical names via live CAAMP APIs.
|
|
157
|
+
*
|
|
158
|
+
* @returns Immutable record of native event name → canonical event name
|
|
159
|
+
*/
|
|
160
|
+
getEventMap() {
|
|
161
|
+
return { ...PI_EVENT_MAP };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Enumerate supported canonical events via CAAMP's `getSupportedEvents()`.
|
|
165
|
+
*
|
|
166
|
+
* Calls `getSupportedEvents('pi')` from the CAAMP normalizer to get the
|
|
167
|
+
* authoritative list. Pi supports 11 of 16 canonical events. Falls back
|
|
168
|
+
* to the unique values of the static event map when CAAMP is unavailable.
|
|
169
|
+
*
|
|
170
|
+
* @returns Array of CAAMP canonical event names supported by Pi
|
|
171
|
+
* @task T553
|
|
172
|
+
*/
|
|
173
|
+
async getSupportedCanonicalEvents() {
|
|
174
|
+
try {
|
|
175
|
+
const { getSupportedEvents } = await import('@cleocode/caamp');
|
|
176
|
+
return getSupportedEvents(PROVIDER_ID);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return [...new Set(Object.values(PI_EVENT_MAP))];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Retrieve the full provider hook profile from CAAMP.
|
|
184
|
+
*
|
|
185
|
+
* Calls `getProviderHookProfile('pi')` from the CAAMP normalizer to get
|
|
186
|
+
* the complete profile including hook system type, config path, handler
|
|
187
|
+
* types, and all event mappings. Returns null when CAAMP is unavailable.
|
|
188
|
+
*
|
|
189
|
+
* @returns Provider hook profile or null if CAAMP is unavailable
|
|
190
|
+
* @task T553
|
|
191
|
+
*/
|
|
192
|
+
async getProviderProfile() {
|
|
193
|
+
try {
|
|
194
|
+
const { getProviderHookProfile } = await import('@cleocode/caamp');
|
|
195
|
+
return getProviderHookProfile(PROVIDER_ID) ?? null;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Translate a CAAMP canonical event to its Pi native name via CAAMP.
|
|
203
|
+
*
|
|
204
|
+
* Calls `toNative(canonical, 'pi')` from the CAAMP normalizer.
|
|
205
|
+
* Returns null for unsupported events or when CAAMP is unavailable.
|
|
206
|
+
*
|
|
207
|
+
* @param canonical - CAAMP canonical event name (e.g. "PreToolUse")
|
|
208
|
+
* @returns Pi native event name or null
|
|
209
|
+
* @task T553
|
|
210
|
+
*/
|
|
211
|
+
async toNativeEvent(canonical) {
|
|
212
|
+
try {
|
|
213
|
+
const { toNative } = await import('@cleocode/caamp');
|
|
214
|
+
return toNative(canonical, PROVIDER_ID);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// Invert the static map as fallback — return the first match
|
|
218
|
+
const entry = Object.entries(PI_EVENT_MAP).find(([, v]) => v === canonical);
|
|
219
|
+
return entry?.[0] ?? null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/providers/pi/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAIH,wCAAwC;AACxC,MAAM,WAAW,GAAG,IAAa,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,YAAY,GAA2B;IAC3C,+CAA+C;IAC/C,aAAa,EAAE,cAAc;IAC7B,gDAAgD;IAChD,gBAAgB,EAAE,YAAY;IAC9B,uCAAuC;IACvC,KAAK,EAAE,cAAc;IACrB,oEAAoE;IACpE,QAAQ,EAAE,cAAc;IACxB,yCAAyC;IACzC,SAAS,EAAE,YAAY;IACvB,qEAAqE;IACrE,oBAAoB,EAAE,YAAY;IAClC,4CAA4C;IAC5C,WAAW,EAAE,aAAa;IAC1B,oEAAoE;IACpE,kBAAkB,EAAE,aAAa;IACjC,qDAAqD;IACrD,kBAAkB,EAAE,eAAe;IACnC,2CAA2C;IAC3C,SAAS,EAAE,cAAc;IACzB,qDAAqD;IACrD,uBAAuB,EAAE,UAAU;IACnC,6FAA6F;IAC7F,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,cAAc;IACzB,kEAAkE;IAC1D,UAAU,GAAG,KAAK,CAAC;IAE3B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,aAAqB;QACpC,OAAO,YAAY,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,mBAAmB,CAAC,WAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,qBAAqB;QACzB,IAAI,CAAC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,CAAC,CAAC,IAAI,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* CLEO provider adapter for Pi coding agent (https://github.com/badlogic/pi-mono).
|
|
5
|
+
* Pi is CAAMP's first-class primary harness with 11/16 canonical hook events.
|
|
6
|
+
* Default export is the adapter class for dynamic loading by AdapterManager.
|
|
7
|
+
*
|
|
8
|
+
* @task T553
|
|
9
|
+
*/
|
|
10
|
+
import { PiAdapter } from './adapter.js';
|
|
11
|
+
export { PiAdapter } from './adapter.js';
|
|
12
|
+
export { PiHookProvider } from './hooks.js';
|
|
13
|
+
export { PiInstallProvider } from './install.js';
|
|
14
|
+
export { PiSpawnProvider } from './spawn.js';
|
|
15
|
+
export default PiAdapter;
|
|
16
|
+
/**
|
|
17
|
+
* Factory function for creating Pi adapter instances.
|
|
18
|
+
* Used by AdapterManager's dynamic import fallback.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This is the primary entry point for dynamic adapter loading.
|
|
22
|
+
* AdapterManager calls this function when it resolves the pi provider
|
|
23
|
+
* via its import-based discovery mechanism.
|
|
24
|
+
*
|
|
25
|
+
* @returns A new {@link PiAdapter} instance ready for initialization
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { createAdapter } from '@cleocode/adapters/providers/pi';
|
|
30
|
+
*
|
|
31
|
+
* const adapter = createAdapter();
|
|
32
|
+
* await adapter.initialize('/path/to/project');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function createAdapter(): PiAdapter;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/pi/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAe,SAAS,CAAC;AAEzB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,IAAI,SAAS,CAEzC"}
|