pi-sage 0.2.1 → 0.2.3
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/.pi/extensions/sage/runner.ts +23 -11
- package/README.md +11 -2
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { EOL, tmpdir } from "node:os";
|
|
4
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
4
5
|
import { isPathAllowed, resolveToolPolicy, validateBashCommandForProfile } from "./tool-policy.js";
|
|
5
6
|
import type { ToolPolicySettings } from "./settings.js";
|
|
6
7
|
import type {
|
|
@@ -76,8 +77,11 @@ export async function runSageSingleShot(input: SageRunnerInput): Promise<SageRun
|
|
|
76
77
|
const startedAt = Date.now();
|
|
77
78
|
|
|
78
79
|
const invocation = resolvePiInvocation();
|
|
79
|
-
const args = [...invocation.prefixArgs, ...buildPiArgs(input.model, input.reasoningLevel, policy.cliTools)];
|
|
80
80
|
const prompt = buildSagePrompt(input);
|
|
81
|
+
const promptDir = await mkdtemp(join(tmpdir(), "pi-sage-"));
|
|
82
|
+
const promptPath = join(promptDir, "prompt.txt");
|
|
83
|
+
await writeFile(promptPath, prompt, "utf8");
|
|
84
|
+
const args = [...invocation.prefixArgs, ...buildPiArgs(input.model, input.reasoningLevel, policy.cliTools), `@${promptPath}`];
|
|
81
85
|
|
|
82
86
|
const child = spawn(invocation.command, args, {
|
|
83
87
|
cwd: input.cwd,
|
|
@@ -86,9 +90,16 @@ export async function runSageSingleShot(input: SageRunnerInput): Promise<SageRun
|
|
|
86
90
|
PI_SAGE_SUBAGENT: "1"
|
|
87
91
|
},
|
|
88
92
|
shell: invocation.shell,
|
|
89
|
-
stdio: ["
|
|
93
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
90
94
|
});
|
|
91
95
|
|
|
96
|
+
const cleanupPromptFile = (): void => {
|
|
97
|
+
void rm(promptDir, { recursive: true, force: true });
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
child.once("close", cleanupPromptFile);
|
|
101
|
+
child.once("error", cleanupPromptFile);
|
|
102
|
+
|
|
92
103
|
let stdoutBuffer = "";
|
|
93
104
|
let stderrBuffer = "";
|
|
94
105
|
let assistantText = "";
|
|
@@ -112,12 +123,6 @@ export async function runSageSingleShot(input: SageRunnerInput): Promise<SageRun
|
|
|
112
123
|
child.stdout.setEncoding("utf8");
|
|
113
124
|
child.stderr.setEncoding("utf8");
|
|
114
125
|
|
|
115
|
-
if (child.stdin) {
|
|
116
|
-
child.stdin.setDefaultEncoding("utf8");
|
|
117
|
-
child.stdin.write(prompt);
|
|
118
|
-
child.stdin.end();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
126
|
child.stdout.on("data", (chunk: string) => {
|
|
122
127
|
stdoutBuffer += chunk;
|
|
123
128
|
const lines = stdoutBuffer.split(/\r?\n/);
|
|
@@ -257,8 +262,12 @@ export async function runSageSingleShot(input: SageRunnerInput): Promise<SageRun
|
|
|
257
262
|
throw new Error(`Sage subprocess failed (code ${String(exit.code)}): ${stderrBuffer.trim() || "no stderr"}`);
|
|
258
263
|
}
|
|
259
264
|
|
|
265
|
+
if (assistantText.trim().length === 0) {
|
|
266
|
+
throw new Error(`Sage subprocess returned no assistant text (code ${String(exit.code)}): ${stderrBuffer.trim() || "no stderr"}`);
|
|
267
|
+
}
|
|
268
|
+
|
|
260
269
|
return {
|
|
261
|
-
text: assistantText
|
|
270
|
+
text: assistantText,
|
|
262
271
|
latencyMs,
|
|
263
272
|
stopReason,
|
|
264
273
|
usage,
|
|
@@ -311,6 +320,9 @@ function buildPiArgs(model: string, reasoningLevel: ReasoningLevel, cliTools: st
|
|
|
311
320
|
"-p",
|
|
312
321
|
"--no-session",
|
|
313
322
|
"--no-extensions",
|
|
323
|
+
"--no-skills",
|
|
324
|
+
"--no-prompt-templates",
|
|
325
|
+
"--no-themes",
|
|
314
326
|
"--model",
|
|
315
327
|
model,
|
|
316
328
|
"--thinking",
|
package/README.md
CHANGED
|
@@ -17,13 +17,13 @@ Interactive-only advisory Sage extension for Pi.
|
|
|
17
17
|
### Global install (all projects)
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
pi install pi-sage
|
|
20
|
+
pi install npm:pi-sage
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
### Project-local install (current project only)
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
pi install -l pi-sage
|
|
26
|
+
pi install -l npm:pi-sage
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Then in Pi run:
|
|
@@ -91,3 +91,12 @@ Project settings always override global settings for that project.
|
|
|
91
91
|
|
|
92
92
|
Package name `sage` is already taken on npm.
|
|
93
93
|
`pi-sage` is currently available and is the intended publish name.
|
|
94
|
+
|
|
95
|
+
## Install troubleshooting
|
|
96
|
+
|
|
97
|
+
If `pi install pi-sage` fails with a local-path error (for example `Path does not exist: .../pi-sage`), your Pi version is interpreting bare names as local paths.
|
|
98
|
+
Use the explicit npm source form instead:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pi install npm:pi-sage
|
|
102
|
+
```
|