pi-plus-sdk 0.2.46 → 0.2.48

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 CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  ### Added
6
6
 
7
+ - `createPlusAgentSessionRuntime()` now returns host-owned Bash execution alongside the upstream runtime: `runtime.executeBash(command, onChunk?, { id?, excludeFromContext?, operations? })` records the result in session context and `runtime.abortBash()` cancels in-flight commands. This is the stable embedding API for host-initiated commands such as a desktop composer's `!` runner; it bypasses the model tool-permission gate by design, so hosts remain responsible for user consent.
7
8
  - The diagram extension (`pi-plus-diagram`, shared core `packages/plus/src/extensions/diagram/`) joins `plusSdkExtensionFactories`: SDK sessions get the `draw_diagram` tool (structured JSON spec → layered layout → box-drawing ASCII in `details`, optional `file` write of a standalone HTML/SVG document), and the SDK surface re-exports the rendering pieces directly — `renderDiagramHtml(spec, options?)` for hosts that want self-contained HTML/SVG from a spec without a tool call, plus `layoutDiagram`, the `DiagramSpec`/`DiagramNode`/`DiagramEdge`/`DiagramShape`/`DiagramDetails` types, and `DiagramError`/`DIAGRAM_TOOL_NAME`.
8
9
 
9
10
  - `createPlusSdkExtensionFactories(agentDir?: string)` builds the hidden non-TUI pi-plus extension factories with the session's agent dir bound into the sub-agent-spawning extensions (`pi-plus-subagent`, `pi-plus-memory`); `plusSdkExtensionFactories` stays the env-fallback binding (`createPlusSdkExtensionFactories()`), so hosts importing the array directly keep the pipi-CLI behavior. Declared in `api.d.ts`.
package/README.md CHANGED
@@ -80,8 +80,9 @@ await session.prompt("Review this repository");
80
80
  `session.bindExtensions()` yourself. Pass `ui` dialog handlers to get working
81
81
  `ask_user` questions (bound with mode `"rpc"`, so the tool falls back to sequential
82
82
  select/input/confirm dialogs bridged to your UI); omit `ui` for a headless session.
83
- - `createPlusAgentSessionRuntime()` returns an `AgentSessionRuntime` instead of a
84
- single session: the same pi-plus layer and one-bind-per-session rules, plus the
83
+ - `createPlusAgentSessionRuntime()` returns a `PlusAgentSessionRuntime` (an
84
+ `AgentSessionRuntime` plus host-owned Bash execution) instead of a single
85
+ session: the same pi-plus layer and one-bind-per-session rules, plus the
85
86
  CLI's session-replacement machinery — `runtime.cd`-style switches
86
87
  (`switchSession`), `newSession`, and `fork` (with `{position: "at"}` for the CLI's
87
88
  in-place `/clone`). The pi-plus `/cd`/`/init` extensions and anything else needing
@@ -91,6 +92,7 @@ await session.prompt("Review this repository");
91
92
  the `onRebind` callback (it also fires for the initial bind) and never call
92
93
  `bindExtensions()` yourself. `runtime.dispose()` is async and emits
93
94
  `session_shutdown`.
95
+
94
96
  - `session.setAutoCompactionEnabled(bool)` writes the **global**
95
97
  `<agentDir>/settings.json` compaction flag (not a per-session setting), so a host
96
98
  toggle labeled per-session would surprise users — it also flips behavior for the
@@ -110,6 +112,24 @@ await session.prompt("Review this repository");
110
112
  `SettingsSelectorComponent` are upstream pi's versions, not the pipi-branded CLI
111
113
  wrappers.
112
114
 
115
+ ### Bash execution
116
+
117
+ Hosts can run shell commands outside an LLM turn through the runtime:
118
+
119
+ ```ts
120
+ const result = await runtime.executeBash("git status", (chunk) => {
121
+ process.stdout.write(chunk);
122
+ }, { id: "status-1" });
123
+
124
+ runtime.abortBash(); // cancels every command currently running on the session
125
+ ```
126
+
127
+ The result is recorded in the session context unless `excludeFromContext` is
128
+ set. This API is for host-initiated actions (for example, a user-entered `!`
129
+ command); it does not route through the model's tool-permission gate, so the
130
+ host must obtain any required user consent before calling it. `excludeTools:
131
+ ["bash"]` only controls the model-facing Bash tool during LLM turns.
132
+
113
133
  ## Building the artifact
114
134
 
115
135
  ```bash
package/api.d.ts CHANGED
@@ -39,6 +39,16 @@ import type {
39
39
  ToolCallEventResult,
40
40
  } from "@earendil-works/pi-coding-agent";
41
41
 
42
+ /** Options for running a Bash command through an embedding host. */
43
+ export type ExecuteBashOptions = NonNullable<Parameters<AgentSession["executeBash"]>[2]>;
44
+ /** Result of a Bash command run through an embedding host. */
45
+ export type ExecuteBashResult = Awaited<ReturnType<AgentSession["executeBash"]>>;
46
+ /** Runtime returned by `createPlusAgentSessionRuntime`, including host-owned Bash execution. */
47
+ export type PlusAgentSessionRuntime = AgentSessionRuntime & {
48
+ executeBash(command: string, onChunk?: (chunk: string) => void, options?: ExecuteBashOptions): Promise<ExecuteBashResult>;
49
+ abortBash(): void;
50
+ };
51
+
42
52
  // Value import for the SessionManager static shadow below (the augmented
43
53
  // instance side is reachable via interface merging; statics are not).
44
54
  import { SessionManager as UpstreamSessionManager } from "@earendil-works/pi-coding-agent";
@@ -621,7 +631,7 @@ export interface CreatePlusAgentSessionRuntimeOptions extends CreateAgentSession
621
631
  * bindExtensions themselves. */
622
632
  export declare function createPlusAgentSessionRuntime(
623
633
  options?: CreatePlusAgentSessionRuntimeOptions,
624
- ): Promise<AgentSessionRuntime>;
634
+ ): Promise<PlusAgentSessionRuntime>;
625
635
 
626
636
  /**
627
637
  * Profile management: the curated @earendil-works/pi-hub surface bundled into