pi-sage 0.2.2 → 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.
@@ -1,6 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
- import { EOL } from "node:os";
3
- import { isAbsolute, resolve } from "node:path";
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: ["pipe", "pipe", "pipe"]
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/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sage",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Interactive-only advisory Sage extension for Pi",