pi-plus 0.1.15 → 0.1.16
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 +1 -0
- package/README.md +44 -2
- package/api.d.ts +44 -0
- package/api.js +2367 -0
- package/package.json +13 -3
- package/pipi.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
### Added
|
|
12
12
|
|
|
13
|
+
- The published `pi-plus` package gains a programmatic library entry alongside the `pipi` CLI: `import { createPlusAgentSession, createPlusUIContext, plusSdkExtensionFactories } from "pi-plus"` lets a host application (e.g. a desktop app) embed pi with the full pi-plus layer in-process — the compaction/context/reasoning overrides are baked into `api.js` by the same bundle-time redirect plugin as the CLI, and the seven non-TUI pi-plus extensions (subagent, tasks, memory, plan, ask-user, hooks, context-guard) are registered the same way the CLI wrapper registers them. `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.json now has an `exports` map (deep imports are 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 builds `api.js` as a second esbuild entry, roughly doubling the artifact size. 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.
|
|
13
14
|
- The tab-title spinner now also runs while context compaction is in progress (manual `/compact` when idle, or automatic/overflow compaction mid-run): `session_before_compact` marks compaction active and `session_compact`/`session_compact_failed` clear it, so a backgrounded tab shows at a glance that a long compaction is running. The spinner stops only when neither the agent run nor compaction is active, so mid-run compaction (which settles the run before retrying) no longer leaves the tab static.
|
|
14
15
|
- A `<tasks>` system-prompt section (registered by the `pi-plus-tasks` extension on every agent start) nudging the model to break non-trivial multi-step work into TaskCreate tasks and update statuses as it goes, and listing the session's current tasks (with status and blockers) when non-empty so resumed sessions can pick up where they left off.
|
|
15
16
|
- A `<subagents>` system-prompt section (registered by the `pi-plus-subagent` extension on every agent start) nudging the model to delegate self-contained work units via the `subagent` tool — including complete, self-contained prompts and concurrent calls in one turn — and listing the agent types available in this session (built-in `worker`/`explore` plus user- and project-defined agents) with their source, tools, and model.
|
package/README.md
CHANGED
|
@@ -88,14 +88,56 @@ npm publish --access public --ignore-scripts # in packages/plus/dist/npm
|
|
|
88
88
|
|
|
89
89
|
The bundle applies `loader/redirects.mjs` at bundle time (esbuild plugin) and keeps each
|
|
90
90
|
module a singleton by funneling every `packages/*/src/**` import with a compiled `dist/`
|
|
91
|
-
counterpart to that dist file. `--no-env` is preserved via a banner scrub
|
|
92
|
-
|
|
91
|
+
counterpart to that dist file. `--no-env` is preserved via a banner scrub (inert for
|
|
92
|
+
library imports: it only scrubs when `process.argv` contains a literal `--no-env`).
|
|
93
|
+
Provider credentials, config dir (`~/.pi`), and session layout are identical to
|
|
94
|
+
source-mode `pipi`.
|
|
95
|
+
|
|
96
|
+
### Programmatic API (library hosts)
|
|
97
|
+
|
|
98
|
+
The same package also exposes a programmatic entry for hosts that embed pi-plus
|
|
99
|
+
in-process (e.g. a desktop app) instead of running the `pipi` CLI:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { createPlusAgentSession } from "pi-plus";
|
|
103
|
+
|
|
104
|
+
const { session } = await createPlusAgentSession({
|
|
105
|
+
cwd: projectDir,
|
|
106
|
+
ui: {
|
|
107
|
+
select: async (title, options) => showPicker(title, options),
|
|
108
|
+
confirm: async (title, message) => showConfirm(title, message),
|
|
109
|
+
input: async (title, placeholder) => showInput(title, placeholder),
|
|
110
|
+
},
|
|
111
|
+
// Hosts without a pi CLI on PATH should exclude the subagent tool: it
|
|
112
|
+
// launches a pi subprocess and could otherwise relaunch the host app.
|
|
113
|
+
excludeTools: ["subagent"],
|
|
114
|
+
});
|
|
115
|
+
await session.prompt("Review this repository");
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- The full pi-plus layer is included: the compaction/context/reasoning overrides are
|
|
119
|
+
baked into `api.js` by the same bundle-time redirect plugin as the CLI, and the seven
|
|
120
|
+
non-TUI pi-plus extensions (subagent, tasks, memory, plan, ask-user, hooks,
|
|
121
|
+
context-guard) are registered exactly as the CLI wrapper registers them.
|
|
122
|
+
- `createPlusAgentSession()` extends the upstream `createAgentSession` (re-exported, with
|
|
123
|
+
the whole upstream SDK surface) with those extension factories, and always binds
|
|
124
|
+
extensions once — do not call `session.bindExtensions()` yourself. Pass `ui` dialog
|
|
125
|
+
handlers to get working `ask_user` questions (bound with mode `"rpc"`, so the tool
|
|
126
|
+
falls back to sequential select/input/confirm dialogs bridged to your UI); omit `ui`
|
|
127
|
+
for a headless session.
|
|
128
|
+
- The staged `package.json` has an `exports` map, so deep imports (e.g.
|
|
129
|
+
`pi-plus/pipi.js`) are no longer reachable; `api.d.ts` re-exports the
|
|
130
|
+
`@earendil-works/pi-coding-agent` types (exact-pinned dependency, type resolution
|
|
131
|
+
only — the runtime is self-contained). Building `api.js` as a second esbuild entry
|
|
132
|
+
roughly doubles the artifact size.
|
|
93
133
|
|
|
94
134
|
Known limitations of the compiled artifact:
|
|
95
135
|
|
|
96
136
|
- `pipi server` / `pipi client` experimental subcommands (`PI_EXPERIMENTAL=1`) spawn sibling JS
|
|
97
137
|
files that are not emitted next to the bundle; use source-mode `./pipi` for those.
|
|
98
138
|
- `docs/` and `examples/` are not shipped, so `/docs`-style paths into them are absent.
|
|
139
|
+
- Hub profile resolution (`pipi --as <name>`, `pipi profile …`) is CLI-launch logic and is
|
|
140
|
+
not part of the programmatic entry; SDK hosts pass `cwd`/`agentDir` explicitly.
|
|
99
141
|
|
|
100
142
|
## Tests
|
|
101
143
|
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type contract for the "pi-plus" npm package's programmatic entry
|
|
3
|
+
* (api.js). Hand-authored mirror of src/api.ts: the runtime is fully
|
|
4
|
+
* self-contained in api.js (built from this repo with the pi-plus override
|
|
5
|
+
* layer baked in), so this file only needs to re-export the upstream SDK
|
|
6
|
+
* types and declare the pi-plus additions. A vitest drift guard
|
|
7
|
+
* (test/api.test.ts) asserts every runtime export of src/api.ts appears here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export * from "@earendil-works/pi-coding-agent";
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
CreateAgentSessionOptions,
|
|
14
|
+
CreateAgentSessionResult,
|
|
15
|
+
ExtensionCommandContextActions,
|
|
16
|
+
ExtensionError,
|
|
17
|
+
ExtensionUIContext,
|
|
18
|
+
InlineExtension,
|
|
19
|
+
} from "@earendil-works/pi-coding-agent";
|
|
20
|
+
|
|
21
|
+
export declare const plusSdkExtensionFactories: InlineExtension[];
|
|
22
|
+
|
|
23
|
+
export interface PlusUIDialogHandlers {
|
|
24
|
+
select(title: string, options: string[]): Promise<string | undefined>;
|
|
25
|
+
confirm(title: string, message: string): Promise<boolean>;
|
|
26
|
+
input(title: string, placeholder?: string): Promise<string | undefined>;
|
|
27
|
+
editor?(title: string, prefill?: string): Promise<string | undefined>;
|
|
28
|
+
notify?(message: string, type?: "info" | "warning" | "error"): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare function createPlusUIContext(handlers: PlusUIDialogHandlers): ExtensionUIContext;
|
|
32
|
+
|
|
33
|
+
export interface CreatePlusAgentSessionOptions extends CreateAgentSessionOptions {
|
|
34
|
+
extensionFactories?: InlineExtension[];
|
|
35
|
+
ui?: PlusUIDialogHandlers;
|
|
36
|
+
commandContextActions?: ExtensionCommandContextActions;
|
|
37
|
+
abortHandler?: () => void;
|
|
38
|
+
shutdownHandler?: () => void;
|
|
39
|
+
onError?: (error: ExtensionError) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare function createPlusAgentSession(
|
|
43
|
+
options?: CreatePlusAgentSessionOptions,
|
|
44
|
+
): Promise<CreateAgentSessionResult>;
|