pi-plus-sdk 0.2.9 → 0.2.11
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/CHANGELOG.md +3 -2
- package/api.d.ts +104 -2
- package/api.js +34 -34
- package/github-copilot.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### Added
|
|
6
6
|
|
|
7
|
+
- The SDK entry now owns the session/host-facing surface that previously required direct upstream edits: `api.js` re-exports `getDefaultSessionDir` through the pi-plus session overlay and the `ConfiguredPackage`, `PackageUpdate`, and `DefaultResourceLoaderOptions` types via type-only imports from their source modules (the coding-agent barrel stays pristine), and `api.d.ts` declares the pi-plus runtime additions — `AgentSession.getSlashCommands()`, `SessionManager.deleteSession()`, `SessionManager.search()` (instance side via module augmentation, statics via a shadow class export) — plus inline mirrors of the four re-exported names. Embedding hosts keep the same runtime and typed surface as before the upstream edits were moved into the plus packages.
|
|
7
8
|
- The web search extension (`pi-plus-web-search`, shared core `packages/plus/src/extensions/web-search/`) joins `plusSdkExtensionFactories`: SDK sessions get the `WebSearch` (provider chain over `WEB_SEARCH_PROVIDER`/`*_API_KEY` env vars, keyless DuckDuckGo fallback last) and `WebFetch` (URL → text) tools, registered exactly as the CLI wrapper registers them.
|
|
8
9
|
- Session recap failures are re-exported from the SDK surface (`packages/plus/src/extensions/recap/events.ts`): `subscribeToRecapFailures(listener)` — fires with a `{ sessionId, reason: "timeout" | "error", message }` `RecapFailure` after every failed auto-title call (the one-off recap LLM call after the first prompt or a compaction hitting its 30s timeout, or a provider error), returning an unsubscribe function — plus the `RecapFailure`/`RecapFailureReason` types. A host (e.g. the pi-plus desktop) can show its own "session name not set" indicator or trigger a retry without polling. In-process only. Hosts that wire `PlusUIDialogHandlers.notify` via `createPlusUIContext` also receive the failure as a transcript warning through the notify bridge, since the TUI warning that replaced the old stderr dump routes through the same `ui.notify`.
|
|
9
10
|
- `/plan <prompt>` in the plan extension (shared core): any argument other than the `show` / `edit` subcommands turns plan mode on (when off) and forwards the text to the model as a user message (queued as steering while the agent is streaming).
|
|
@@ -15,10 +16,10 @@
|
|
|
15
16
|
|
|
16
17
|
- The task store API is re-exported from the SDK surface (`packages/plus/src/extensions/tasks/store.ts`): `TaskStore` (file-backed `TaskCreate`/`TaskUpdate`/`TaskList`/`TaskGet` storage under `<agentDir>/tasks/<sessionId>/`, now a per-process singleton per list id), `subscribeToTasks(listId, listener)` — fires immediately with the current list, then with the full post-mutation list after every task-tool change in this process, returning an unsubscribe function — plus the `Task`/`TaskStatus`/`TaskListListener` types. A host (e.g. the pi-plus desktop) can render a native task panel that stays in sync without polling the files. In-process only: writers in another process are not observed.
|
|
17
18
|
- Runtime settings layering for hub profiles applies to SDK hosts with no environment plumbing (shared `loader/redirects.mjs` entry for `coding-agent/src/core/settings-manager.ts`): whenever the agent dir passed to `SettingsManager.create` is a hub-materialized profile dir (a direct child of `~/.pi/pi-hub/profiles`, honoring `PI_HUB_PI_DIR`/`PI_HUB_DIR`; the pipi-set `PI_PLUS_BASE_AGENT_DIR` marker also still activates it), the global scope reads the base agent `settings.json` deep-merged under the profile `settings.json` with the profile winning, and writes route per top-level key — the profile-scoped `defaultProvider`/`defaultModel`/`defaultThinkingLevel` to the profile file, everything else to the agent file with any profile shadow cleared. Any other agent dir keeps `SettingsManager.create` behaving exactly as upstream.
|
|
18
|
-
- The pi-plus context settings are re-exported from the SDK surface (`packages/plus/src/context/threshold-setting.ts`): `readPlusSettings/writePlusSettings/getPlusSettingsPath` for the pi-plus settings store next to `settings.json`, plus the typed getters/setters and UI formatters behind the pipi `/settings` rows — `get/setAutoCompactThresholdPercent` (default 80%), `get/setContextFloorTokens` (default/built-in minimum 13000), and `get/setContextWindowCapTokens` (undefined = no cap). Embedding hosts get the same knobs the TUI edits, against the same file detection actually reads. `SessionManager.deleteSession` and `SessionManager.search` (
|
|
19
|
+
- The pi-plus context settings are re-exported from the SDK surface (`packages/plus/src/context/threshold-setting.ts`): `readPlusSettings/writePlusSettings/getPlusSettingsPath` for the pi-plus settings store next to `settings.json`, plus the typed getters/setters and UI formatters behind the pipi `/settings` rows — `get/setAutoCompactThresholdPercent` (default 80%), `get/setContextFloorTokens` (default/built-in minimum 13000), and `get/setContextWindowCapTokens` (undefined = no cap). Embedding hosts get the same knobs the TUI edits, against the same file detection actually reads. `SessionManager.deleteSession` and `SessionManager.search` (defined by the pi-plus session overlay, reachable through the SDK surface) cover transcript deletion and title/content search for history-management UIs.
|
|
19
20
|
- Initial **`pi-plus-sdk`** npm artifact (published from this package): the programmatic pi-plus entry, split out of the `pi-plus` package so library hosts embed pi in-process with zero CLI logic. `import { createPlusAgentSession, createPlusUIContext, plusSdkExtensionFactories } from "pi-plus-sdk"` gives a host application (e.g. a desktop app) the compaction/context/reasoning overrides (baked in at bundle time by the shared redirect plugin) plus the nine non-TUI pi-plus extensions (subagent, tasks, memory, plan, ask-user, hooks, context-guard, /cd, /init). `createPlusAgentSession()` composes the upstream `createAgentSession` with a `DefaultResourceLoader` carrying those factories, reloads it, and binds extensions once (emitting `session_start`); hosts pass dialog handlers via the `ui` option to get working `ask_user` questions (select/confirm/input bridged to native UI), or omit it for a headless session. The staged package has an `exports` map (deep imports closed off), ships a hand-authored `api.d.ts` re-exporting `@earendil-works/pi-coding-agent` types (added as an exact-pinned dependency for type resolution only; the runtime stays self-contained), and has no bin. Hosts without a pi CLI on PATH should pass `excludeTools: ["subagent"]`: the subagent tool launches a pi subprocess and could otherwise relaunch the host app itself.
|
|
20
21
|
- The `/init` extension (shared core, `packages/plus/src/extensions/init/`) is registered by `plusSdkExtensionFactories` too: the `/init` command creates or improves `AGENTS.md` at the cwd root — pi's default project instructions file, loaded automatically by upstream's context loader.
|
|
21
|
-
- `createPlusAgentSessionRuntime(options?)` — a runtime-backed sibling of `createPlusAgentSession` for embedding hosts that need the CLI's session-replacement machinery. It composes `createAgentSessionServices`/`createAgentSessionFromServices`/`createAgentSessionRuntime` (the same layering the CLI's main uses, trimmed to host concerns) with the pi-plus extension factories and binding rules: extensions are bound exactly once per session through the rebind hook (initial bind plus every `switchSession`/`fork`/`newSession` replacement, emitting one `session_start` each with the matching reason), and the default `commandContextActions` route `waitForIdle`/`newSession`/`fork`/`navigateTree`/`switchSession`/`reload` to the runtime + live session, which is what makes `/cd` (and `/clone`-style `runtime.fork(leafId, { position: "at" })`) work in-process. The live session is `runtime.session` — hosts read it after each replacement or subscribe in the new `onRebind` callback; the initial session defaults to `SessionManager.create(cwd, getDefaultSessionDir(cwd, agentDir))`, and `projectTrusted` (default true) plus `resourceLoaderOptions` passthroughs cover per-cwd settings and loader customization. The
|
|
22
|
+
- `createPlusAgentSessionRuntime(options?)` — a runtime-backed sibling of `createPlusAgentSession` for embedding hosts that need the CLI's session-replacement machinery. It composes `createAgentSessionServices`/`createAgentSessionFromServices`/`createAgentSessionRuntime` (the same layering the CLI's main uses, trimmed to host concerns) with the pi-plus extension factories and binding rules: extensions are bound exactly once per session through the rebind hook (initial bind plus every `switchSession`/`fork`/`newSession` replacement, emitting one `session_start` each with the matching reason), and the default `commandContextActions` route `waitForIdle`/`newSession`/`fork`/`navigateTree`/`switchSession`/`reload` to the runtime + live session, which is what makes `/cd` (and `/clone`-style `runtime.fork(leafId, { position: "at" })`) work in-process. The live session is `runtime.session` — hosts read it after each replacement or subscribe in the new `onRebind` callback; the initial session defaults to `SessionManager.create(cwd, getDefaultSessionDir(cwd, agentDir))`, and `projectTrusted` (default true) plus `resourceLoaderOptions` passthroughs cover per-cwd settings and loader customization. The SDK entry additionally re-exports `getDefaultSessionDir` (through the pi-plus session overlay, plus the `DefaultResourceLoaderOptions` type via a type-only deep import) to support this entry, keeping the coding-agent barrel pristine.
|
|
22
23
|
- `addProfileModel(name, model)` and `removeProfileModel(name, model)` join the curated profile surface (implemented in `@earendil-works/pi-hub`): append a model without selecting it (bounded by the same three-models-per-profile limit) and remove one with the `pipi` CLI delete semantics — the default promotes to the next remaining model, and removing the last clears `models`/`model` so the profile inherits. Both return a human-readable message for host UIs, completing the per-profile model editing that `setProfileDefaultModel` started.
|
|
23
24
|
- `setProfileDefaultModel(name, model)` joins the curated profile surface (implemented in `@earendil-works/pi-hub`): selects a profile's default model — the list position 1 that materialization writes as `settings.defaultModel` — moving an existing model or adding a new one (bounded by the same three-models-per-profile limit the `pipi` CLI enforces), and returns a human-readable message for host UIs. This is the library entry for the "select model" behavior that previously lived only in the CLI command layer.
|
|
24
25
|
- The SDK build redirects the upstream `main.ts` to a stub that throws — the CLI entry graph (startup UI, session picker, auth command, …) stays out of `api.js`, and calling `main()` is a clear error instead of silently running un-layered upstream pi. The re-exported `parseArgs`/`SettingsSelectorComponent` resolve to upstream pi (no pipi help text or CLI settings rows leak into the library surface).
|
package/api.d.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
export * from "@earendil-works/pi-coding-agent";
|
|
11
11
|
|
|
12
12
|
import type {
|
|
13
|
-
ConfiguredPackage,
|
|
14
13
|
ProgressCallback,
|
|
15
14
|
SettingsManager,
|
|
16
15
|
} from "@earendil-works/pi-coding-agent";
|
|
@@ -20,16 +19,27 @@ import type {
|
|
|
20
19
|
AgentSessionRuntime,
|
|
21
20
|
CreateAgentSessionOptions,
|
|
22
21
|
CreateAgentSessionResult,
|
|
23
|
-
|
|
22
|
+
EventBus,
|
|
24
23
|
ExtensionCommandContextActions,
|
|
25
24
|
ExtensionContext,
|
|
26
25
|
ExtensionError,
|
|
27
26
|
ExtensionUIContext,
|
|
28
27
|
InlineExtension,
|
|
28
|
+
LoadExtensionsResult,
|
|
29
|
+
PromptTemplate,
|
|
30
|
+
ResourceDiagnostic,
|
|
31
|
+
SessionInfo,
|
|
32
|
+
SlashCommandInfo,
|
|
33
|
+
Skill,
|
|
34
|
+
Theme,
|
|
29
35
|
ToolCallEvent,
|
|
30
36
|
ToolCallEventResult,
|
|
31
37
|
} from "@earendil-works/pi-coding-agent";
|
|
32
38
|
|
|
39
|
+
// Value import for the SessionManager static shadow below (the augmented
|
|
40
|
+
// instance side is reachable via interface merging; statics are not).
|
|
41
|
+
import { SessionManager as UpstreamSessionManager } from "@earendil-works/pi-coding-agent";
|
|
42
|
+
|
|
33
43
|
// pi-plus runtime addition: the SettingsManager wrapper patches a setter +
|
|
34
44
|
// raw getter pair onto the upstream class next to its existing read-side
|
|
35
45
|
// getExternalEditorCommand (see packages/plus/src/coding-agent/core/settings-manager.ts).
|
|
@@ -64,6 +74,98 @@ declare module "@earendil-works/pi-coding-agent" {
|
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
|
|
77
|
+
// pi-plus session surface: the SDK bundle redirects the upstream core modules
|
|
78
|
+
// onto the packages/plus overlays, so at runtime the embedded classes carry
|
|
79
|
+
// these pi-plus members. The published upstream package does not declare them
|
|
80
|
+
// (Override Policy: upstream stays pristine), so the contract adds them here:
|
|
81
|
+
// instance-side via interface merging, static-side via a shadowing class
|
|
82
|
+
// declaration (an explicit export shadows the star re-export above).
|
|
83
|
+
declare module "@earendil-works/pi-coding-agent" {
|
|
84
|
+
interface AgentSession {
|
|
85
|
+
/** Slash commands invokable through prompt(): extension commands, prompt
|
|
86
|
+
* templates, and `skill:<name>` entries — the TUI autocomplete set minus
|
|
87
|
+
* interactive-mode-only builtins (pi-plus overlay). */
|
|
88
|
+
getSlashCommands(): SlashCommandInfo[];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class SessionManager extends UpstreamSessionManager {
|
|
93
|
+
/** Delete a persisted session transcript file (.jsonl); returns whether the
|
|
94
|
+
* file was removed, throws for paths outside the session-file convention
|
|
95
|
+
* (pi-plus overlay). */
|
|
96
|
+
static deleteSession(filePath: string): boolean;
|
|
97
|
+
/** Case-insensitive substring search over session history: session name,
|
|
98
|
+
* first user message, or any user/assistant message text; SessionInfo
|
|
99
|
+
* entries ordered by last activity (pi-plus overlay). */
|
|
100
|
+
static search(
|
|
101
|
+
query: string,
|
|
102
|
+
sessionDir?: string,
|
|
103
|
+
onProgress?: (loaded: number, total: number, partialSessions?: readonly SessionInfo[]) => void,
|
|
104
|
+
signal?: AbortSignal,
|
|
105
|
+
): Promise<SessionInfo[]>;
|
|
106
|
+
}
|
|
107
|
+
export { SessionManager };
|
|
108
|
+
|
|
109
|
+
/** Session dir for a cwd under the agent dir's sessions tree (pi-plus SDK
|
|
110
|
+
* re-export; the upstream barrel does not export this). */
|
|
111
|
+
export declare function getDefaultSessionDir(cwd: string, agentDir?: string): string;
|
|
112
|
+
|
|
113
|
+
// Mirrors of upstream-internal types the pi-plus SDK surface exposes but the
|
|
114
|
+
// published upstream barrel does not re-export (kept pristine per the Override
|
|
115
|
+
// Policy). Shapes copied from packages/coding-agent/src/core.
|
|
116
|
+
export interface ConfiguredPackage {
|
|
117
|
+
source: string;
|
|
118
|
+
scope: "user" | "project";
|
|
119
|
+
filtered: boolean;
|
|
120
|
+
installedPath?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface PackageUpdate {
|
|
124
|
+
source: string;
|
|
125
|
+
displayName: string;
|
|
126
|
+
type: "npm" | "git";
|
|
127
|
+
scope: "user" | "project";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface DefaultResourceLoaderOptions {
|
|
131
|
+
cwd: string;
|
|
132
|
+
agentDir: string;
|
|
133
|
+
settingsManager?: SettingsManager;
|
|
134
|
+
eventBus?: EventBus;
|
|
135
|
+
additionalExtensionPaths?: string[];
|
|
136
|
+
additionalSkillPaths?: string[];
|
|
137
|
+
additionalPromptTemplatePaths?: string[];
|
|
138
|
+
additionalThemePaths?: string[];
|
|
139
|
+
extensionFactories?: InlineExtension[];
|
|
140
|
+
noExtensions?: boolean;
|
|
141
|
+
/** Built-in extensions not to load, by name (such as `mcp`), even when settings or `-e` enable them. */
|
|
142
|
+
disabledBuiltinExtensions?: string[];
|
|
143
|
+
noSkills?: boolean;
|
|
144
|
+
noPromptTemplates?: boolean;
|
|
145
|
+
noThemes?: boolean;
|
|
146
|
+
noContextFiles?: boolean;
|
|
147
|
+
systemPrompt?: string;
|
|
148
|
+
appendSystemPrompt?: string[];
|
|
149
|
+
extensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;
|
|
150
|
+
skillsOverride?: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {
|
|
151
|
+
skills: Skill[];
|
|
152
|
+
diagnostics: ResourceDiagnostic[];
|
|
153
|
+
};
|
|
154
|
+
promptsOverride?: (base: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] }) => {
|
|
155
|
+
prompts: PromptTemplate[];
|
|
156
|
+
diagnostics: ResourceDiagnostic[];
|
|
157
|
+
};
|
|
158
|
+
themesOverride?: (base: { themes: Theme[]; diagnostics: ResourceDiagnostic[] }) => {
|
|
159
|
+
themes: Theme[];
|
|
160
|
+
diagnostics: ResourceDiagnostic[];
|
|
161
|
+
};
|
|
162
|
+
agentsFilesOverride?: (base: { agentsFiles: Array<{ path: string; content: string }> }) => {
|
|
163
|
+
agentsFiles: Array<{ path: string; content: string }>;
|
|
164
|
+
};
|
|
165
|
+
systemPromptOverride?: (base: string | undefined) => string | undefined;
|
|
166
|
+
appendSystemPromptOverride?: (base: string[]) => string[];
|
|
167
|
+
}
|
|
168
|
+
|
|
67
169
|
/** Declare whether this process counts as a human-driven host. Process-global
|
|
68
170
|
* (pi-plus overlay) because session-replacing paths carry no per-call option. */
|
|
69
171
|
export declare function setDefaultSessionInteractive(interactive: boolean): void;
|