@pimote/sdk 0.15.5-rc.2 → 0.16.0-rc.1
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 +33 -61
- package/dist/folders/index.d.ts +1 -1
- package/dist/folders/types.d.ts +5 -28
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/pimote/index.d.ts +23 -0
- package/dist/pimote/index.js +1 -0
- package/dist/subagents/index.d.ts +3 -0
- package/dist/subagents/index.js +1 -0
- package/dist/subagents/provider.d.ts +27 -0
- package/dist/subagents/provider.js +123 -0
- package/dist/subagents/types.d.ts +322 -0
- package/dist/subagents/types.js +1 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @pimote/sdk
|
|
2
2
|
|
|
3
|
-
Pimote's extensibility SDK
|
|
3
|
+
Pimote's extensibility SDK provides APIs for [Pi](https://github.com/earendil-works/pi) session extensions and process-global Pimote extensions. These hosts have separate entry points:
|
|
4
4
|
|
|
5
|
-
- **`@pimote/sdk/panels`** — push structured card data to the
|
|
6
|
-
- **`@pimote/sdk/folders`** —
|
|
7
|
-
- **`@pimote/sdk/activity`** — answer
|
|
5
|
+
- **`@pimote/sdk/panels`** — push structured card data to the Pimote web client
|
|
6
|
+
- **`@pimote/sdk/folders`** — type-only folder discovery entries for Pimote extensions
|
|
7
|
+
- **`@pimote/sdk/activity`** — answer Pimote's idle-reap background-activity poll
|
|
8
|
+
- **`@pimote/sdk/pimote`** — define global `PimoteExtension` factories for sources and Settings files
|
|
8
9
|
|
|
9
|
-
The root `@pimote/sdk` import re-exports
|
|
10
|
+
The root `@pimote/sdk` import re-exports session-scoped modules and Pimote extension types.
|
|
10
11
|
|
|
11
12
|
## Install
|
|
12
13
|
|
|
@@ -112,57 +113,38 @@ Detection uses pi's EventBus for a synchronous in-process round-trip — pimote'
|
|
|
112
113
|
|
|
113
114
|
When pimote isn't present, the EventBus emit fires with no listener, `detect()` returns `null`, and there's zero overhead.
|
|
114
115
|
|
|
115
|
-
##
|
|
116
|
-
|
|
117
|
-
Type-only module for user-authored folder-source modules: pimote scans a folder-sources directory (default `~/.config/pimote/folder-sources`, configurable via `folderSourcesDir`), dynamic-imports every JS/TS module it finds, and collects each module's exported `sources` and `creators` arrays. Sources contribute repos and hub folders to pimote's folder layer; creators make new folders from user-supplied form params.
|
|
116
|
+
## Pimote extensions — `@pimote/sdk/pimote`
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
Pimote extensions are process-global modules. The host loads direct JavaScript/TypeScript modules and entry-bearing directories from `$XDG_CONFIG_HOME/pimote/extensions/`. User-scoped Pi packages can contribute entries through their `pimote.extensions` manifest field. Project packages and `pi.extensions` entries never load in this host. A module listed in both sections is an explicit dual-host module and runs twice with independent lifecycles.
|
|
120
119
|
|
|
121
120
|
```ts
|
|
122
|
-
|
|
123
|
-
import type { FolderSource, FolderCreator } from '@pimote/sdk/folders';
|
|
121
|
+
import type { PimoteExtension } from '@pimote/sdk/pimote';
|
|
124
122
|
|
|
125
|
-
|
|
126
|
-
{
|
|
123
|
+
const extension: PimoteExtension = (context) => {
|
|
124
|
+
context.folders.registerSource({
|
|
127
125
|
id: 'my-source',
|
|
128
126
|
async list() {
|
|
129
|
-
return [
|
|
130
|
-
{
|
|
131
|
-
kind: 'repo',
|
|
132
|
-
path: '/home/me/work/api',
|
|
133
|
-
name: 'api',
|
|
134
|
-
branch: 'main',
|
|
135
|
-
dirty: false,
|
|
136
|
-
ahead: 0,
|
|
137
|
-
behind: 0,
|
|
138
|
-
},
|
|
139
|
-
];
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
export const creators: FolderCreator[] = [
|
|
145
|
-
{
|
|
146
|
-
id: 'my-creator',
|
|
147
|
-
describe() {
|
|
148
|
-
return { label: 'New API folder', paramSchema: { name: 'string', tags: 'string[]' } };
|
|
149
|
-
},
|
|
150
|
-
async create(params) {
|
|
151
|
-
const path = `/home/me/work/${String(params.name)}`;
|
|
152
|
-
// ... scaffold the folder ...
|
|
153
|
-
return { path };
|
|
127
|
+
return [{ kind: 'repo', path: '/home/me/work/api', name: 'api', branch: 'main', dirty: false, ahead: 0, behind: 0 }];
|
|
154
128
|
},
|
|
155
|
-
}
|
|
156
|
-
|
|
129
|
+
});
|
|
130
|
+
context.settings.registerFile('./instructions.md');
|
|
131
|
+
context.on('shutdown', async () => {
|
|
132
|
+
// Release process-global resources here.
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export default extension;
|
|
157
137
|
```
|
|
158
138
|
|
|
159
|
-
|
|
139
|
+
`registerSource()` contributes folder discovery. `registerFile()` contributes a global Settings tab. Relative file paths resolve from the extension entry module, while absolute and leading-`~` paths remain explicit. Registrations become inert after shutdown or reload. The host replaces all extension registrations on `/reload`, awaits shutdown handlers, and reports isolated diagnostics while continuing valid modules. Shutdown handlers have no timeout, so an extension must let them settle. Folder creation remains a Pimote core capability, so the public SDK has no external creator registration seam.
|
|
140
|
+
|
|
141
|
+
## Folders — `@pimote/sdk/folders`
|
|
160
142
|
|
|
161
|
-
|
|
143
|
+
This type-only module defines the source discovery seam used by `PimoteExtensionContext.folders.registerSource()`. Sources contribute repos and hubs. Their optional `onFolderOpen(folderPath)` hook runs before an open and can provision a missing entry. Pimote materializes standard hubs and owns the dashboard and manager folder-creation flows.
|
|
162
144
|
|
|
163
|
-
### `
|
|
145
|
+
### `FolderSource`
|
|
164
146
|
|
|
165
|
-
|
|
147
|
+
`list()` returns current entries without mutation. The optional `onFolderOpen(folderPath)` hook is awaited before row, new-session, and manager opens. A thrown error aborts the open.
|
|
166
148
|
|
|
167
149
|
### Entry shapes
|
|
168
150
|
|
|
@@ -187,7 +169,7 @@ interface HubSourceEntry {
|
|
|
187
169
|
|
|
188
170
|
### `RepoInfo`
|
|
189
171
|
|
|
190
|
-
Repo facts
|
|
172
|
+
Repo facts: `path`, `name`, `branch` (`string | null`), `dirty`, `ahead`, `behind`, and optional `worktreePath`, `lastActivity` (epoch ms), `missing` (repo path no longer exists on disk), and `tags`. In a worktree hub row, `path` stays the canonical source path; `worktreePath` identifies the nested checkout whose Git status Pimote reports. It mirrors Pimote's wire `RepoInfo` type — same name, same fields — so extension authors can write `interface MyEntry extends RepoInfo` against the SDK alone.
|
|
191
173
|
|
|
192
174
|
## Activity — `@pimote/sdk/activity`
|
|
193
175
|
|
|
@@ -227,22 +209,12 @@ The pimote-side twin, used by the server's idle reaper. Performs the synchronous
|
|
|
227
209
|
|
|
228
210
|
### 0.15.0 (0.x breaking)
|
|
229
211
|
|
|
230
|
-
The
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
| `ProjectCreator` | `FolderCreator` |
|
|
237
|
-
| `ProjectCreatorDescriptor` | `FolderCreatorDescriptor` |
|
|
238
|
-
| `ProjectCreatorParamType` | `FolderCreatorParamType` |
|
|
239
|
-
| `MultiRepoSourceEntry` | `HubSourceEntry` |
|
|
240
|
-
| entry discriminator `kind: 'project'` | entry discriminator `kind: 'hub'` |
|
|
241
|
-
| `onProjectOpen(projectPath)` | `onFolderOpen(folderPath)` |
|
|
242
|
-
| config key `projectSourcesDir` | `folderSourcesDir` (legacy key still read as a deprecated fallback) |
|
|
243
|
-
| sources dir `~/.config/pimote/project-sources` | `~/.config/pimote/folder-sources` (legacy dir still loaded when the new one is absent) |
|
|
244
|
-
|
|
245
|
-
Every name in the left column is retired; each is listed here only so existing modules can be migrated. The wire command for the built-in creation flow is likewise renamed (`create_project` → `create_folder`).
|
|
212
|
+
The SDK now exposes two independent hosts:
|
|
213
|
+
|
|
214
|
+
- `@pimote/sdk/pimote` runs process-global Pimote extensions for folder sources and Settings files.
|
|
215
|
+
- `@pimote/sdk` and its `panels` and `activity` modules run inside Pi sessions through EventBus bridges.
|
|
216
|
+
|
|
217
|
+
Folder creation is a Pimote core operation. External creation registration was removed. Existing source modules must move their exported source arrays into a default `PimoteExtension` factory and call `context.folders.registerSource()`. Pi package manifests can list separate `pi.extensions` and `pimote.extensions` entries; Pimote loads only the latter from user scope.
|
|
246
218
|
|
|
247
219
|
## License
|
|
248
220
|
|
package/dist/folders/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { FolderSource,
|
|
1
|
+
export type { FolderSource, SourceEntry, RepoSourceEntry, HubSourceEntry, RepoInfo } from './types.js';
|
package/dist/folders/types.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export interface RepoInfo {
|
|
|
10
10
|
/** Commits ahead of upstream; 0 when unknown. */
|
|
11
11
|
ahead: number;
|
|
12
12
|
behind: number;
|
|
13
|
+
/** Present for worktree hub members: the nested checkout inside the hub
|
|
14
|
+
* whose git facts these are. The canonical `path` stays the source repo. */
|
|
15
|
+
worktreePath?: string;
|
|
13
16
|
/** Epoch ms of last session activity in this repo, when known. */
|
|
14
17
|
lastActivity?: number;
|
|
15
18
|
/** True when the repo path no longer exists on disk (deleted member, broken symlink). */
|
|
@@ -17,8 +20,6 @@ export interface RepoInfo {
|
|
|
17
20
|
/** Effective tags (user + source-contributed). Absent when untagged. */
|
|
18
21
|
tags?: string[];
|
|
19
22
|
}
|
|
20
|
-
/** Human-readable parameter type for a creator form field. */
|
|
21
|
-
export type FolderCreatorParamType = 'string' | 'string[]';
|
|
22
23
|
/** A repo entry contributed to the discovery index (feeds single-repo folders). */
|
|
23
24
|
export interface RepoSourceEntry extends RepoInfo {
|
|
24
25
|
kind: 'repo';
|
|
@@ -41,8 +42,8 @@ export type SourceEntry = RepoSourceEntry | HubSourceEntry;
|
|
|
41
42
|
/**
|
|
42
43
|
* Extensible discovery seam: a source contributes repos and hub
|
|
43
44
|
* folders to the folder layer. Built in: the filesystem walker over
|
|
44
|
-
* configured roots. User-authored sources are
|
|
45
|
-
*
|
|
45
|
+
* configured roots. User-authored sources are registered by the global
|
|
46
|
+
* Pimote extension host.
|
|
46
47
|
*/
|
|
47
48
|
export interface FolderSource {
|
|
48
49
|
readonly id: string;
|
|
@@ -57,27 +58,3 @@ export interface FolderSource {
|
|
|
57
58
|
*/
|
|
58
59
|
onFolderOpen?(folderPath: string): Promise<void>;
|
|
59
60
|
}
|
|
60
|
-
/** Human-readable description of a creator's form, for the creation UI. */
|
|
61
|
-
export interface FolderCreatorDescriptor {
|
|
62
|
-
label: string;
|
|
63
|
-
paramSchema: Record<string, FolderCreatorParamType>;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Extensible creation seam: a creator makes a new folder from
|
|
67
|
-
* user-supplied params. Built in: mkdir + git init. User-authored creators
|
|
68
|
-
* are dynamic-imported from the configured folder-sources directory.
|
|
69
|
-
*/
|
|
70
|
-
export interface FolderCreator {
|
|
71
|
-
readonly id: string;
|
|
72
|
-
/** Human-readable description for the creation UI. */
|
|
73
|
-
describe(): FolderCreatorDescriptor;
|
|
74
|
-
/**
|
|
75
|
-
* Make the folder and return its path. Pimote resolves the path to its
|
|
76
|
-
* canonical filesystem identity before seeding, broadcasting, or opening a
|
|
77
|
-
* session, so a creator can return the lexical path it used to reach the
|
|
78
|
-
* folder. The path must name the successfully created folder.
|
|
79
|
-
*/
|
|
80
|
-
create(params: Record<string, unknown>): Promise<{
|
|
81
|
-
path: string;
|
|
82
|
-
}>;
|
|
83
|
-
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A server-global Pimote extension.
|
|
3
|
+
*
|
|
4
|
+
* The host creates a fresh context for each runtime. Extensions must keep all
|
|
5
|
+
* registrations behind that context because the host invalidates it on reload.
|
|
6
|
+
*/
|
|
7
|
+
export type PimoteExtension = (context: PimoteExtensionContext) => void | Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Context exposed to server-global Pimote extensions.
|
|
10
|
+
*
|
|
11
|
+
* This is intentionally separate from pi's session-scoped ExtensionAPI. Pimote
|
|
12
|
+
* extensions contribute folder discovery and global settings files only.
|
|
13
|
+
*/
|
|
14
|
+
export interface PimoteExtensionContext {
|
|
15
|
+
readonly folders: {
|
|
16
|
+
registerSource(source: import('../folders/types.js').FolderSource): void;
|
|
17
|
+
};
|
|
18
|
+
readonly settings: {
|
|
19
|
+
registerFile(path: string): void;
|
|
20
|
+
};
|
|
21
|
+
on(event: 'shutdown', handler: () => void | Promise<void>): () => void;
|
|
22
|
+
}
|
|
23
|
+
export type PimoteShutdownHandler = () => void | Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { AgentPath, BorrowedAgentSession, BorrowedSessionManager, CommunicationData, CompletionData, DelegationData, FeedCursor, PiEventRef, ReplayResult, SubagentAwaitChildStatus, SubagentAwaitData, SubagentCapabilities, SubagentCompletionData, SubagentDelegationData, SubagentEvent, SubagentEventData, SubagentEventKind, SubagentLease, SubagentLeaseEvent, SubagentLifecycleData, SubagentMessageData, SubagentNode, SubagentNodeEventData, SubagentNodeSnapshot, SubagentNodeState, SubagentOperation, SubagentOwnerControlPort, SubagentProvider, SubagentProviderDiscovery, SubagentProviderRequest, SubagentProviderResponse, SubagentResurrectRequest, SubagentResurrectResult, SubagentSemanticFact, SubagentSnapshot, SubagentState, SubagentStopRequest, SubagentTeardownReason, SubagentTeardownResult, SubagentUsage, SubagentUsageSnapshot, SubagentRuntimeReplacedData, SubagentCostBreakdown, } from './types.js';
|
|
2
|
+
export { SUBAGENT_PROVIDER_REQUEST, SUBAGENT_PROVIDER_RESPONSE, discover, discoverProvider, register, registerProvider } from './provider.js';
|
|
3
|
+
export type { DiscoverProviderOptions } from './provider.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SUBAGENT_PROVIDER_REQUEST, SUBAGENT_PROVIDER_RESPONSE, discover, discoverProvider, register, registerProvider } from './provider.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { SubagentEventBusOwner, SubagentProvider, SubagentProviderDiscovery } from './types.js';
|
|
3
|
+
/** EventBus channel emitted by a Pimote host to discover a provider. */
|
|
4
|
+
export declare const SUBAGENT_PROVIDER_REQUEST: "pimote:subagents:request";
|
|
5
|
+
/** EventBus channel carrying the currently registered provider. */
|
|
6
|
+
export declare const SUBAGENT_PROVIDER_RESPONSE: "pimote:subagents:response";
|
|
7
|
+
export declare function registerProvider(owner: SubagentEventBusOwner | ExtensionAPI, provider: SubagentProvider): () => void;
|
|
8
|
+
export interface DiscoverProviderOptions {
|
|
9
|
+
/** Called whenever the provider first appears or is replaced. */
|
|
10
|
+
onProvider?: (provider: SubagentProvider) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Discover the provider on a session EventBus and keep listening for late
|
|
14
|
+
* registration or replacement.
|
|
15
|
+
*
|
|
16
|
+
* With a callback, the return value is an unsubscribe function. Without a
|
|
17
|
+
* callback, the return value is a discovery handle whose `provider` getter
|
|
18
|
+
* reflects the latest registration. In both forms discovery emits one request
|
|
19
|
+
* after installing its response listener, so a provider registered before or
|
|
20
|
+
* during the handshake cannot be missed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function discoverProvider(owner: SubagentEventBusOwner | ExtensionAPI, onProvider: (provider: SubagentProvider) => void): () => void;
|
|
23
|
+
export declare function discoverProvider(owner: SubagentEventBusOwner | ExtensionAPI, options?: DiscoverProviderOptions): SubagentProviderDiscovery;
|
|
24
|
+
/** Short alias for hosts that use the request/response verb. */
|
|
25
|
+
export declare const discover: typeof discoverProvider;
|
|
26
|
+
/** Short alias for extensions that use the registration verb. */
|
|
27
|
+
export declare const register: typeof registerProvider;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/** EventBus channel emitted by a Pimote host to discover a provider. */
|
|
2
|
+
export const SUBAGENT_PROVIDER_REQUEST = 'pimote:subagents:request';
|
|
3
|
+
/** EventBus channel carrying the currently registered provider. */
|
|
4
|
+
export const SUBAGENT_PROVIDER_RESPONSE = 'pimote:subagents:response';
|
|
5
|
+
/**
|
|
6
|
+
* Narrow an ExtensionAPI/EventBus-like value to its EventBus.
|
|
7
|
+
*
|
|
8
|
+
* The SDK keeps this adapter structural so extensions can use the same seam in
|
|
9
|
+
* tests without constructing a complete ExtensionAPI object.
|
|
10
|
+
*/
|
|
11
|
+
function eventBusOf(owner) {
|
|
12
|
+
if ('events' in owner)
|
|
13
|
+
return owner.events;
|
|
14
|
+
return owner;
|
|
15
|
+
}
|
|
16
|
+
function providerFrom(data) {
|
|
17
|
+
if (data && typeof data === 'object' && 'provider' in data) {
|
|
18
|
+
const provider = data.provider;
|
|
19
|
+
return provider && typeof provider === 'object' ? provider : undefined;
|
|
20
|
+
}
|
|
21
|
+
return data && typeof data === 'object' ? data : undefined;
|
|
22
|
+
}
|
|
23
|
+
function response(provider) {
|
|
24
|
+
return { provider };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One provider registration per session EventBus.
|
|
28
|
+
*
|
|
29
|
+
* Registration is a live responder rather than a one-shot value. A host can
|
|
30
|
+
* begin discovery before the extension binds, and a later registration or
|
|
31
|
+
* replacement is delivered immediately. Calling this again on the same bus
|
|
32
|
+
* deactivates the previous responder. The function never owns or disposes the
|
|
33
|
+
* provider; the owner controls its lifecycle.
|
|
34
|
+
*/
|
|
35
|
+
const registrations = new WeakMap();
|
|
36
|
+
export function registerProvider(owner, provider) {
|
|
37
|
+
const bus = eventBusOf(owner);
|
|
38
|
+
const key = bus;
|
|
39
|
+
const previous = registrations.get(key);
|
|
40
|
+
previous?.unsubscribeRequest();
|
|
41
|
+
if (previous)
|
|
42
|
+
previous.active = false;
|
|
43
|
+
const registration = {
|
|
44
|
+
active: true,
|
|
45
|
+
unsubscribeRequest: () => undefined,
|
|
46
|
+
};
|
|
47
|
+
registration.unsubscribeRequest = bus.on(SUBAGENT_PROVIDER_REQUEST, () => {
|
|
48
|
+
if (!registration.active)
|
|
49
|
+
return;
|
|
50
|
+
bus.emit(SUBAGENT_PROVIDER_RESPONSE, response(provider));
|
|
51
|
+
});
|
|
52
|
+
registrations.set(key, registration);
|
|
53
|
+
// Hosts that already started discovery receive a replacement without a
|
|
54
|
+
// second request. Hosts that have not started simply have this value ignored.
|
|
55
|
+
bus.emit(SUBAGENT_PROVIDER_RESPONSE, response(provider));
|
|
56
|
+
return () => {
|
|
57
|
+
if (!registration.active)
|
|
58
|
+
return;
|
|
59
|
+
registration.active = false;
|
|
60
|
+
registration.unsubscribeRequest();
|
|
61
|
+
if (registrations.get(key) === registration)
|
|
62
|
+
registrations.delete(key);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function discoverProvider(owner, callbackOrOptions) {
|
|
66
|
+
const bus = eventBusOf(owner);
|
|
67
|
+
let current;
|
|
68
|
+
let closed = false;
|
|
69
|
+
const listeners = new Set();
|
|
70
|
+
const callback = typeof callbackOrOptions === 'function' ? callbackOrOptions : callbackOrOptions?.onProvider;
|
|
71
|
+
if (callback)
|
|
72
|
+
listeners.add((provider) => {
|
|
73
|
+
if (provider)
|
|
74
|
+
callback(provider);
|
|
75
|
+
});
|
|
76
|
+
const publish = (provider) => {
|
|
77
|
+
if (closed || provider === current)
|
|
78
|
+
return;
|
|
79
|
+
current = provider;
|
|
80
|
+
for (const listener of [...listeners])
|
|
81
|
+
listener(provider);
|
|
82
|
+
};
|
|
83
|
+
const unsubscribeResponse = bus.on(SUBAGENT_PROVIDER_RESPONSE, (data) => publish(providerFrom(data)));
|
|
84
|
+
bus.emit(SUBAGENT_PROVIDER_REQUEST, {});
|
|
85
|
+
const close = () => {
|
|
86
|
+
if (closed)
|
|
87
|
+
return;
|
|
88
|
+
closed = true;
|
|
89
|
+
unsubscribeResponse();
|
|
90
|
+
listeners.clear();
|
|
91
|
+
};
|
|
92
|
+
if (callback)
|
|
93
|
+
return close;
|
|
94
|
+
return {
|
|
95
|
+
get provider() {
|
|
96
|
+
return current;
|
|
97
|
+
},
|
|
98
|
+
get current() {
|
|
99
|
+
return current;
|
|
100
|
+
},
|
|
101
|
+
subscribe(listener) {
|
|
102
|
+
if (closed)
|
|
103
|
+
return () => undefined;
|
|
104
|
+
listeners.add(listener);
|
|
105
|
+
if (current)
|
|
106
|
+
listener(current);
|
|
107
|
+
return () => listeners.delete(listener);
|
|
108
|
+
},
|
|
109
|
+
onProvider(listener) {
|
|
110
|
+
if (closed)
|
|
111
|
+
return () => undefined;
|
|
112
|
+
listeners.add(listener);
|
|
113
|
+
if (current)
|
|
114
|
+
listener(current);
|
|
115
|
+
return () => listeners.delete(listener);
|
|
116
|
+
},
|
|
117
|
+
close,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Short alias for hosts that use the request/response verb. */
|
|
121
|
+
export const discover = discoverProvider;
|
|
122
|
+
/** Short alias for extensions that use the registration verb. */
|
|
123
|
+
export const register = registerProvider;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import type { AgentSession, EventBus } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
/** Root-relative identity of a my-pi child runtime. */
|
|
3
|
+
export type AgentPath = readonly string[];
|
|
4
|
+
/** Provider-owned replay position. Pimote keeps this separate from parent cursors. */
|
|
5
|
+
export type FeedCursor = Readonly<{
|
|
6
|
+
epoch: string;
|
|
7
|
+
sequence: number;
|
|
8
|
+
}>;
|
|
9
|
+
/** Native Pi transcript/session provenance for one semantic event. */
|
|
10
|
+
export type PiEventRef = Readonly<{
|
|
11
|
+
sessionId: string;
|
|
12
|
+
entryId?: string;
|
|
13
|
+
toolCallId?: string;
|
|
14
|
+
kind: 'message' | 'tool_call' | 'custom_message' | 'lifecycle';
|
|
15
|
+
}>;
|
|
16
|
+
export type SubagentEventKind = 'node_added' | 'node_updated' | 'node_removed' | 'runtime_replaced' | 'delegation' | 'message_thread' | 'await_started' | 'child_settled' | 'await_interrupted' | 'await_released' | 'completion' | 'interrupt' | 'teardown' | 'resurrect';
|
|
17
|
+
export type SubagentDelegationData = Readonly<{
|
|
18
|
+
invocationId: string;
|
|
19
|
+
awaitsResult: boolean;
|
|
20
|
+
children: readonly Readonly<{
|
|
21
|
+
path: AgentPath;
|
|
22
|
+
task: string;
|
|
23
|
+
persona?: string;
|
|
24
|
+
}>[];
|
|
25
|
+
}>;
|
|
26
|
+
/** Alias used by the my-pi provider implementation. */
|
|
27
|
+
export type DelegationData = SubagentDelegationData;
|
|
28
|
+
export type SubagentCompletionData = Readonly<{
|
|
29
|
+
status: 'idle' | 'errored' | 'dead' | 'stopped';
|
|
30
|
+
output?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
usage?: SubagentUsage;
|
|
33
|
+
}> & (Readonly<{
|
|
34
|
+
delivery: 'awaited';
|
|
35
|
+
invocationId: string;
|
|
36
|
+
}> | Readonly<{
|
|
37
|
+
delivery: 'asynchronous';
|
|
38
|
+
invocationId?: string;
|
|
39
|
+
}>);
|
|
40
|
+
/** Alias used by the my-pi provider implementation. */
|
|
41
|
+
export type CompletionData = SubagentCompletionData;
|
|
42
|
+
export type SubagentMessageData = Readonly<{
|
|
43
|
+
from: AgentPath;
|
|
44
|
+
to: AgentPath;
|
|
45
|
+
text: string;
|
|
46
|
+
correlationId?: string;
|
|
47
|
+
responseExpected: boolean;
|
|
48
|
+
}> & (Readonly<{
|
|
49
|
+
phase: 'sent' | 'received' | 'response';
|
|
50
|
+
}> | Readonly<{
|
|
51
|
+
phase: 'failure';
|
|
52
|
+
error: string;
|
|
53
|
+
}>);
|
|
54
|
+
/** Alias used by the my-pi provider implementation. */
|
|
55
|
+
export type CommunicationData = SubagentMessageData;
|
|
56
|
+
/** One child state included in await progress and settlement facts. */
|
|
57
|
+
export type SubagentAwaitChildStatus = Readonly<{
|
|
58
|
+
path: AgentPath;
|
|
59
|
+
state: 'running' | 'waiting' | 'idle' | 'errored' | 'dead' | 'stopped';
|
|
60
|
+
output?: string;
|
|
61
|
+
error?: string;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
}>;
|
|
64
|
+
/** Await progress, interruption, and release details. */
|
|
65
|
+
export type SubagentAwaitData = Readonly<{
|
|
66
|
+
invocationId?: string;
|
|
67
|
+
requested?: readonly AgentPath[];
|
|
68
|
+
statuses?: readonly SubagentAwaitChildStatus[];
|
|
69
|
+
path?: AgentPath;
|
|
70
|
+
output?: string;
|
|
71
|
+
error?: string;
|
|
72
|
+
reason?: 'settled' | 'detach' | 'stop' | 'message';
|
|
73
|
+
message?: SubagentMessageData;
|
|
74
|
+
/** Provider implementations can carry additional typed await facts. */
|
|
75
|
+
readonly [key: string]: unknown;
|
|
76
|
+
}>;
|
|
77
|
+
/** Lifecycle operation details carried by interrupt, teardown, and resurrection facts. */
|
|
78
|
+
export type SubagentLifecycleData = Readonly<{
|
|
79
|
+
operation?: 'interrupt' | 'teardown' | 'resurrect';
|
|
80
|
+
outcome?: string;
|
|
81
|
+
path?: AgentPath;
|
|
82
|
+
output?: string;
|
|
83
|
+
error?: string;
|
|
84
|
+
sessionId?: string;
|
|
85
|
+
recovery?: Readonly<Record<string, unknown>>;
|
|
86
|
+
/** Provider implementations can carry operation-specific recovery data. */
|
|
87
|
+
readonly [key: string]: unknown;
|
|
88
|
+
}>;
|
|
89
|
+
/** A public node projection carried by topology events and snapshots. */
|
|
90
|
+
export type SubagentNodeSnapshot = Readonly<{
|
|
91
|
+
path: AgentPath;
|
|
92
|
+
/** Stable for runtime replacement. Changes when a path is removed or reused. */
|
|
93
|
+
incarnation: string;
|
|
94
|
+
sessionId: string;
|
|
95
|
+
task?: string;
|
|
96
|
+
persona?: string;
|
|
97
|
+
personaIcon?: string;
|
|
98
|
+
model?: string;
|
|
99
|
+
thinkingLevel?: string;
|
|
100
|
+
state: SubagentState;
|
|
101
|
+
activity?: string;
|
|
102
|
+
usage: SubagentUsage;
|
|
103
|
+
/** Context fill as an integer percentage from 0 through 100. */
|
|
104
|
+
contextFill?: number;
|
|
105
|
+
channels: readonly string[];
|
|
106
|
+
waitingFor: readonly AgentPath[];
|
|
107
|
+
pendingCorrelations: readonly string[];
|
|
108
|
+
hasSubgroup: boolean;
|
|
109
|
+
lastOutput?: string;
|
|
110
|
+
lastError?: string;
|
|
111
|
+
}>;
|
|
112
|
+
/** Compatibility alias for consumers that call hierarchy rows nodes. */
|
|
113
|
+
export type SubagentNode = SubagentNodeSnapshot;
|
|
114
|
+
export type SubagentUsageSnapshot = SubagentUsage;
|
|
115
|
+
/** Topology events accept the complete projection and old session-id facts. */
|
|
116
|
+
export type SubagentNodeEventData = SubagentNodeSnapshot | Readonly<{
|
|
117
|
+
sessionId: string;
|
|
118
|
+
}>;
|
|
119
|
+
export type SubagentRuntimeReplacedData = Readonly<{
|
|
120
|
+
oldSessionId: string;
|
|
121
|
+
newSessionId: string;
|
|
122
|
+
}>;
|
|
123
|
+
export type SubagentEventData = Readonly<{
|
|
124
|
+
kind: 'node_added' | 'node_updated';
|
|
125
|
+
data: SubagentNodeEventData;
|
|
126
|
+
}> | Readonly<{
|
|
127
|
+
kind: 'node_removed';
|
|
128
|
+
data: Readonly<{
|
|
129
|
+
node: SubagentNodeSnapshot;
|
|
130
|
+
reason: string;
|
|
131
|
+
}>;
|
|
132
|
+
}> | Readonly<{
|
|
133
|
+
kind: 'runtime_replaced';
|
|
134
|
+
data: SubagentRuntimeReplacedData;
|
|
135
|
+
}> | Readonly<{
|
|
136
|
+
kind: 'delegation';
|
|
137
|
+
data: SubagentDelegationData;
|
|
138
|
+
}> | Readonly<{
|
|
139
|
+
kind: 'message_thread';
|
|
140
|
+
data: SubagentMessageData;
|
|
141
|
+
}> | Readonly<{
|
|
142
|
+
kind: 'await_started' | 'child_settled' | 'await_interrupted' | 'await_released';
|
|
143
|
+
data: SubagentAwaitData;
|
|
144
|
+
}> | Readonly<{
|
|
145
|
+
kind: 'completion';
|
|
146
|
+
data: SubagentCompletionData;
|
|
147
|
+
}> | Readonly<{
|
|
148
|
+
kind: 'interrupt' | 'teardown' | 'resurrect';
|
|
149
|
+
data: SubagentLifecycleData;
|
|
150
|
+
}>;
|
|
151
|
+
/** A semantic overlay. Native Pi entries remain the transcript source. */
|
|
152
|
+
export type SubagentSemanticFact = Readonly<{
|
|
153
|
+
eventId: string;
|
|
154
|
+
path: AgentPath;
|
|
155
|
+
relatedPiEvents: readonly PiEventRef[];
|
|
156
|
+
}> & SubagentEventData;
|
|
157
|
+
/** A typed live feed event with its provider-owned replay cursor. */
|
|
158
|
+
export type SubagentEvent = SubagentSemanticFact & Readonly<{
|
|
159
|
+
cursor: FeedCursor;
|
|
160
|
+
}>;
|
|
161
|
+
export type SubagentState = 'running' | 'waiting' | 'idle' | 'errored' | 'dead';
|
|
162
|
+
export type SubagentNodeState = SubagentState;
|
|
163
|
+
export type SubagentCostBreakdown = Readonly<{
|
|
164
|
+
input: number;
|
|
165
|
+
output: number;
|
|
166
|
+
cacheRead: number;
|
|
167
|
+
cacheWrite: number;
|
|
168
|
+
}>;
|
|
169
|
+
/** Provider usage accumulated for one child runtime. */
|
|
170
|
+
export type SubagentUsage = Readonly<{
|
|
171
|
+
input: number;
|
|
172
|
+
output: number;
|
|
173
|
+
cacheRead: number;
|
|
174
|
+
cacheWrite: number;
|
|
175
|
+
cost: number;
|
|
176
|
+
costBreakdown?: SubagentCostBreakdown;
|
|
177
|
+
turns: number;
|
|
178
|
+
}>;
|
|
179
|
+
/** Snapshot boundary for the current provider epoch. */
|
|
180
|
+
export type SubagentSnapshot = Readonly<{
|
|
181
|
+
cursor: FeedCursor;
|
|
182
|
+
nodes: readonly SubagentNodeSnapshot[];
|
|
183
|
+
}>;
|
|
184
|
+
export type ReplayResult = Readonly<{
|
|
185
|
+
kind: 'events';
|
|
186
|
+
cursor: FeedCursor;
|
|
187
|
+
events: readonly SubagentEvent[];
|
|
188
|
+
}> | Readonly<{
|
|
189
|
+
kind: 'snapshot_required';
|
|
190
|
+
reason: 'epoch_changed' | 'history_unavailable';
|
|
191
|
+
}>;
|
|
192
|
+
export type SubagentTeardownReason = 'not_found' | 'already_removed' | 'removed';
|
|
193
|
+
export type SubagentTeardownResult = Readonly<{
|
|
194
|
+
path: AgentPath;
|
|
195
|
+
removed: boolean;
|
|
196
|
+
sessionId?: string;
|
|
197
|
+
incarnation?: string;
|
|
198
|
+
reason?: SubagentTeardownReason;
|
|
199
|
+
}>;
|
|
200
|
+
/** Guarded request to stop the child that owns one public path incarnation. */
|
|
201
|
+
export type SubagentStopRequest = Readonly<{
|
|
202
|
+
path: AgentPath;
|
|
203
|
+
incarnation: string;
|
|
204
|
+
/** The host rejects a request for a replacement runtime at this path. */
|
|
205
|
+
expectedSessionId: string;
|
|
206
|
+
}>;
|
|
207
|
+
/** Input to the normal my-pi resurrection path. */
|
|
208
|
+
export type SubagentResurrectRequest = Readonly<{
|
|
209
|
+
/** Saved child session id returned by teardown. */
|
|
210
|
+
sessionId: string;
|
|
211
|
+
/** Owning root-relative parent path. */
|
|
212
|
+
parentPath: AgentPath;
|
|
213
|
+
/** New local id under `parentPath`. */
|
|
214
|
+
localId: string;
|
|
215
|
+
task: string;
|
|
216
|
+
channels: readonly string[];
|
|
217
|
+
model?: string;
|
|
218
|
+
}>;
|
|
219
|
+
/** Result of a normal resurrection operation. */
|
|
220
|
+
export type SubagentResurrectResult = Readonly<{
|
|
221
|
+
path: AgentPath;
|
|
222
|
+
node?: SubagentNodeSnapshot;
|
|
223
|
+
sessionId?: string;
|
|
224
|
+
incarnation?: string;
|
|
225
|
+
}>;
|
|
226
|
+
/** Operations that preserve the identity of the borrowed child runtime. */
|
|
227
|
+
export type SubagentOperation = 'prompt' | 'steer' | 'follow_up' | 'stop' | 'bash' | 'abort_bash' | 'set_model' | 'cycle_model' | 'set_thinking_level' | 'cycle_thinking_level' | 'set_auto_compaction' | 'compact' | 'tree' | 'completion' | 'state' | 'meta';
|
|
228
|
+
/** Provider-owned child capabilities. It never exposes extension machinery. */
|
|
229
|
+
export interface SubagentCapabilities {
|
|
230
|
+
/** Explicitly admitted identity-preserving operations. */
|
|
231
|
+
readonly operations?: readonly SubagentOperation[];
|
|
232
|
+
/** Whether the child renderer can expose a view. */
|
|
233
|
+
readonly renderer?: Readonly<{
|
|
234
|
+
visible?: boolean;
|
|
235
|
+
[key: string]: unknown;
|
|
236
|
+
}>;
|
|
237
|
+
/** Child-local model resolution and settings. */
|
|
238
|
+
readonly resolveModel?: (provider: string, modelId: string) => Promise<unknown> | unknown;
|
|
239
|
+
readonly getSettings?: () => unknown;
|
|
240
|
+
/** Native bash admission and dispatch. */
|
|
241
|
+
readonly nativeBash?: Readonly<{
|
|
242
|
+
admitted?: boolean;
|
|
243
|
+
execute?: (...args: readonly unknown[]) => Promise<unknown> | unknown;
|
|
244
|
+
abort?: (...args: readonly unknown[]) => Promise<void> | void;
|
|
245
|
+
[key: string]: unknown;
|
|
246
|
+
}>;
|
|
247
|
+
readonly executeBash?: (...args: readonly unknown[]) => Promise<unknown> | unknown;
|
|
248
|
+
/** Filtered command and argument-completion descriptors. */
|
|
249
|
+
readonly getCommands?: (...args: readonly unknown[]) => Promise<unknown> | unknown;
|
|
250
|
+
readonly completeArgs?: (...args: readonly unknown[]) => Promise<unknown> | unknown;
|
|
251
|
+
readonly completeFileRefs?: (...args: readonly unknown[]) => Promise<unknown> | unknown;
|
|
252
|
+
readonly [key: string]: unknown;
|
|
253
|
+
}
|
|
254
|
+
/** Minimal session-manager projection exposed beside a borrowed native session. */
|
|
255
|
+
export type BorrowedSessionManager = Pick<AgentSession['sessionManager'], 'getEntries' | 'getBranch' | 'buildContextEntries' | 'getTree' | 'getLeafId' | 'getCwd' | 'getLabel' | 'appendLabelChange'>;
|
|
256
|
+
/**
|
|
257
|
+
* Structural projection of the native child runtime borrowed by a view.
|
|
258
|
+
*
|
|
259
|
+
* The projection intentionally omits dispose, runtime replacement, session creation,
|
|
260
|
+
* fork/switch/reload, extension binding, and unrestricted manager mutation.
|
|
261
|
+
*/
|
|
262
|
+
export type BorrowedAgentSession = Pick<AgentSession, 'sessionId' | 'sessionFile' | 'messages' | 'model' | 'thinkingLevel' | 'isStreaming' | 'isIdle' | 'isCompacting' | 'subscribe' | 'prompt' | 'steer' | 'followUp' | 'abort' | 'executeBash' | 'abortBash' | 'setModel' | 'cycleModel' | 'setThinkingLevel' | 'cycleThinkingLevel' | 'setAutoCompactionEnabled' | 'compact' | 'navigateTree' | 'getContextUsage' | 'getSessionStats'> & {
|
|
263
|
+
readonly sessionManager: BorrowedSessionManager;
|
|
264
|
+
/** Full-resync native state projection. */
|
|
265
|
+
readonly state: Pick<AgentSession['state'], 'streamingMessage' | 'pendingToolCalls' | 'errorMessage'>;
|
|
266
|
+
};
|
|
267
|
+
export type SubagentLeaseEvent = Readonly<{
|
|
268
|
+
kind: 'rebound';
|
|
269
|
+
session: BorrowedAgentSession;
|
|
270
|
+
capabilities?: SubagentCapabilities;
|
|
271
|
+
}> | Readonly<{
|
|
272
|
+
kind: 'closed';
|
|
273
|
+
reason: 'removed' | 'unavailable';
|
|
274
|
+
}>;
|
|
275
|
+
/** A borrowed child runtime. Release is idempotent and never disposes it. */
|
|
276
|
+
export interface SubagentLease {
|
|
277
|
+
readonly path: AgentPath;
|
|
278
|
+
/** Current native session; access throws after the lease closes or releases. */
|
|
279
|
+
readonly session: BorrowedAgentSession;
|
|
280
|
+
readonly capabilities: SubagentCapabilities;
|
|
281
|
+
subscribe(listener: (event: SubagentLeaseEvent) => void): () => void;
|
|
282
|
+
release(): Promise<void>;
|
|
283
|
+
}
|
|
284
|
+
/** Root-scoped lifecycle authority used by the provider. */
|
|
285
|
+
export interface SubagentOwnerControlPort {
|
|
286
|
+
teardown(path: AgentPath, incarnation: string): Promise<SubagentTeardownResult>;
|
|
287
|
+
stop(request: SubagentStopRequest): Promise<void>;
|
|
288
|
+
resurrect(request: SubagentResurrectRequest): Promise<SubagentResurrectResult>;
|
|
289
|
+
}
|
|
290
|
+
/** Per-session provider feed and borrowed-runtime contract. */
|
|
291
|
+
export interface SubagentProvider {
|
|
292
|
+
subscribe(listener: (event: SubagentEvent) => void): () => void;
|
|
293
|
+
snapshot(): SubagentSnapshot;
|
|
294
|
+
replay(after?: FeedCursor): ReplayResult;
|
|
295
|
+
acquire(path: AgentPath): Promise<SubagentLease>;
|
|
296
|
+
teardown(path: AgentPath, incarnation: string): Promise<SubagentTeardownResult>;
|
|
297
|
+
stop(request: SubagentStopRequest): Promise<void>;
|
|
298
|
+
resurrect(request: SubagentResurrectRequest): Promise<SubagentResurrectResult>;
|
|
299
|
+
}
|
|
300
|
+
/** EventBus request payload used by provider discovery. */
|
|
301
|
+
export type SubagentProviderRequest = Readonly<{
|
|
302
|
+
/** Reserved for future handshake versions. */
|
|
303
|
+
version?: number;
|
|
304
|
+
}>;
|
|
305
|
+
/** EventBus response payload used by provider registration and discovery. */
|
|
306
|
+
export type SubagentProviderResponse = Readonly<{
|
|
307
|
+
provider: SubagentProvider;
|
|
308
|
+
}>;
|
|
309
|
+
/** A live discovery handle that tracks late registration and replacement. */
|
|
310
|
+
export interface SubagentProviderDiscovery {
|
|
311
|
+
readonly provider: SubagentProvider | undefined;
|
|
312
|
+
/** Alias for callers that model discovery as a mutable current value. */
|
|
313
|
+
readonly current: SubagentProvider | undefined;
|
|
314
|
+
subscribe(listener: (provider: SubagentProvider | undefined) => void): () => void;
|
|
315
|
+
/** Alias for subscribe, useful at the host event boundary. */
|
|
316
|
+
onProvider(listener: (provider: SubagentProvider | undefined) => void): () => void;
|
|
317
|
+
close(): void;
|
|
318
|
+
}
|
|
319
|
+
/** Extract the EventBus from either ExtensionAPI or an EventBus itself. */
|
|
320
|
+
export type SubagentEventBusOwner = Pick<EventBus, 'on' | 'emit'> | {
|
|
321
|
+
readonly events: Pick<EventBus, 'on' | 'emit'>;
|
|
322
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pimote/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Pimote extensibility SDK: panel cards, background-activity reap guard, and folder discovery
|
|
3
|
+
"version": "0.16.0-rc.1",
|
|
4
|
+
"description": "Pimote extensibility SDK: panel cards, background-activity reap guard, Pimote extensions, and source-only folder discovery",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Antoine Lennartz <alennartz@gmail.com>",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
".": "./dist/index.js",
|
|
27
27
|
"./panels": "./dist/panels/index.js",
|
|
28
28
|
"./activity": "./dist/activity/index.js",
|
|
29
|
-
"./folders": "./dist/folders/index.js"
|
|
29
|
+
"./folders": "./dist/folders/index.js",
|
|
30
|
+
"./pimote": "./dist/pimote/index.js",
|
|
31
|
+
"./subagents": "./dist/subagents/index.js"
|
|
30
32
|
},
|
|
31
33
|
"types": "./dist/index.d.ts",
|
|
32
34
|
"files": [
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
}
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
54
|
+
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
53
55
|
"typescript": "^6.0.2",
|
|
54
56
|
"vitest": "^4.1.2"
|
|
55
57
|
}
|