pi-plus-sdk 0.1.5 → 0.1.6
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 +2 -1
- package/README.md +8 -4
- package/api.d.ts +35 -0
- package/api.js +20 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
### Added
|
|
6
6
|
|
|
7
|
-
- 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 — `defaultProvider`/`defaultModel` 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.
|
|
7
|
+
- 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.
|
|
8
8
|
- 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` (new in the re-exported upstream surface) cover transcript deletion and title/content search for history-management UIs.
|
|
9
9
|
- 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.
|
|
10
10
|
- 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.
|
|
@@ -12,3 +12,4 @@
|
|
|
12
12
|
- `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.
|
|
13
13
|
- `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.
|
|
14
14
|
- 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).
|
|
15
|
+
- The session recap extension (`pi-plus-session-recap`, shared core `packages/plus/src/extensions/recap/`) joins `plusSdkExtensionFactories`: after the first prompt is answered and after every compaction, a one-off LLM call distills a ≤8-word recap applied as the session name via `setSessionName`, so embedding hosts' session lists/titles read meaningfully without manual naming. Manual renames lock the session against further recaps; failures are logged and never surface.
|
package/README.md
CHANGED
|
@@ -25,9 +25,9 @@ await session.prompt("Review this repository");
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
- The full pi-plus layer is included: the compaction/context/reasoning overrides are
|
|
28
|
-
baked into `api.js` by the shared bundle-time redirect plugin, and the
|
|
28
|
+
baked into `api.js` by the shared bundle-time redirect plugin, and the ten
|
|
29
29
|
non-TUI pi-plus extensions (subagent, tasks, memory, plan, ask-user, hooks,
|
|
30
|
-
context-guard, `/cd`, `/init`) are registered exactly as the CLI wrapper registers them. No CLI
|
|
30
|
+
context-guard, recap, `/cd`, `/init`) are registered exactly as the CLI wrapper registers them. No CLI
|
|
31
31
|
logic ships in this artifact: no hub command dispatch (`pipi profile ...`), no
|
|
32
32
|
completion, no pipi help text, no banner/vim/tab-title/plain-tools.
|
|
33
33
|
- Profile management ships as a library: the curated `@earendil-works/pi-hub`
|
|
@@ -49,10 +49,14 @@ await session.prompt("Review this repository");
|
|
|
49
49
|
`SessionManager.deleteSession(path)` to remove a transcript.
|
|
50
50
|
- Provider login ships as a library (`src/auth.ts`): `loginProvider(providerId, { agentDir?, interaction?, signal?, method? })`
|
|
51
51
|
runs pi's model-runtime login flow (OAuth login page / API-key setup — the same
|
|
52
|
-
flow `pipi profile add <name> -p <provider>`
|
|
52
|
+
flow `pipi profile add <name> -p <provider>` and the `--sign-in` flag on
|
|
53
|
+
`pipi profile add`/`profile update` trigger) and persists the credential
|
|
53
54
|
to `<agentDir>/auth.json`; `createTerminalAuthInteraction()` provides the readline
|
|
54
55
|
terminal UI for CLI use, and hosts pass their own `AuthInteraction` to drive the
|
|
55
|
-
prompts from a custom UI.
|
|
56
|
+
prompts from a custom UI. To mirror the CLI's sign-in token overwrite, write the
|
|
57
|
+
returned credential's `key` into `Profile.token` via `updateProfile` (and clear
|
|
58
|
+
the field for OAuth logins, whose credential only lives in the profile's
|
|
59
|
+
`auth.json` — a stored token would overwrite it at the next launch). pi-plus disables the TUI `/login` (the `interactive-mode`
|
|
56
60
|
and `slash-commands` core redirects are baked in here too), so this is the login
|
|
57
61
|
entry for the whole product.
|
|
58
62
|
- `createPlusAgentSession()` extends the upstream `createAgentSession` (re-exported,
|
package/api.d.ts
CHANGED
|
@@ -16,13 +16,48 @@ import type {
|
|
|
16
16
|
CreateAgentSessionResult,
|
|
17
17
|
DefaultResourceLoaderOptions,
|
|
18
18
|
ExtensionCommandContextActions,
|
|
19
|
+
ExtensionContext,
|
|
19
20
|
ExtensionError,
|
|
20
21
|
ExtensionUIContext,
|
|
21
22
|
InlineExtension,
|
|
23
|
+
ToolCallEvent,
|
|
24
|
+
ToolCallEventResult,
|
|
22
25
|
} from "@earendil-works/pi-coding-agent";
|
|
23
26
|
|
|
24
27
|
export declare const plusSdkExtensionFactories: InlineExtension[];
|
|
25
28
|
|
|
29
|
+
// --- pi-plus-permissions (bypass | acceptEdits | plan tool-call gate) ------
|
|
30
|
+
|
|
31
|
+
export type PermissionMode = "bypass" | "acceptEdits" | "plan";
|
|
32
|
+
|
|
33
|
+
/** Canonical order; hosts cycle forward through this list on their shortcut. */
|
|
34
|
+
export declare const PERMISSION_MODES: PermissionMode[];
|
|
35
|
+
|
|
36
|
+
export declare const PERMISSION_MODE_LABELS: Record<PermissionMode, string>;
|
|
37
|
+
|
|
38
|
+
/** Mutable holder shared between the host and the extension. */
|
|
39
|
+
export interface PermissionModeState {
|
|
40
|
+
mode: PermissionMode;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PermissionsExtensionOptions {
|
|
44
|
+
/** Host-owned state; a fresh bypass-on holder is created when omitted. */
|
|
45
|
+
state?: PermissionModeState;
|
|
46
|
+
/** Called after every mode change, including host-side writes. */
|
|
47
|
+
onModeChange?: (mode: PermissionMode) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export declare function parsePermissionMode(arg: string): PermissionMode | undefined;
|
|
51
|
+
|
|
52
|
+
export declare function gatePermissionToolCall(
|
|
53
|
+
event: ToolCallEvent,
|
|
54
|
+
mode: PermissionMode,
|
|
55
|
+
ctx: ExtensionContext,
|
|
56
|
+
): Promise<ToolCallEventResult | undefined>;
|
|
57
|
+
|
|
58
|
+
/** Build the pi-plus-permissions inline extension for a host. */
|
|
59
|
+
export declare function createPermissionsExtension(options?: PermissionsExtensionOptions): InlineExtension;
|
|
60
|
+
|
|
26
61
|
export interface PlusUIDialogHandlers {
|
|
27
62
|
select(title: string, options: string[]): Promise<string | undefined>;
|
|
28
63
|
confirm(title: string, message: string): Promise<boolean>;
|