pi-suite 0.3.8 → 0.4.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-suite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Custom modular Pi extension suite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
]
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@earendil-works/pi-ai": ">=1.
|
|
46
|
-
"@earendil-works/pi-coding-agent": ">=1.
|
|
47
|
-
"@earendil-works/pi-tui": ">=1.
|
|
45
|
+
"@earendil-works/pi-ai": ">=1.8.0",
|
|
46
|
+
"@earendil-works/pi-coding-agent": ">=1.8.0",
|
|
47
|
+
"@earendil-works/pi-tui": ">=1.8.0",
|
|
48
48
|
"typebox": "^1.3.27"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@earendil-works/pi-ai": "1.
|
|
52
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
53
|
-
"@earendil-works/pi-tui": "1.
|
|
51
|
+
"@earendil-works/pi-ai": "1.8.0",
|
|
52
|
+
"@earendil-works/pi-coding-agent": "1.8.0",
|
|
53
|
+
"@earendil-works/pi-tui": "1.8.0",
|
|
54
54
|
"@narumitw/pi-starship": "0.65.2",
|
|
55
55
|
"@types/node": "24.19.2",
|
|
56
56
|
"typebox": "1.3.27",
|
package/src/agents/runner.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Same-process SDK lifecycle adapted from @tintinweb/pi-subagents 0.23.0 src/agent-runner.ts (MIT).
|
|
2
|
+
import { dirname } from 'node:path';
|
|
2
3
|
import { createAgentSession, getAgentDir, SessionManager, type ExtensionFactory } from '@earendil-works/pi-coding-agent';
|
|
3
4
|
import type { AgentEventKind, Execution } from './types.ts';
|
|
4
5
|
import { AGENT_ENTRY, resultText } from './records.ts';
|
|
@@ -18,7 +19,8 @@ export async function executeAgent(run: Execution, factory: ExtensionFactory, ch
|
|
|
18
19
|
const modelRuntime = parentModelRuntime(parent.ctx);
|
|
19
20
|
const { settingsManager, loader, scope } = await childResources(run, factory);
|
|
20
21
|
if (run.controller.signal.aborted) return;
|
|
21
|
-
|
|
22
|
+
// Pi 1.8 defaults open() to the workspace's main session directory unless it is passed explicitly.
|
|
23
|
+
const manager = run.sessionManager ?? (record.sessionFile ? SessionManager.open(record.sessionFile, dirname(record.sessionFile))
|
|
22
24
|
: record.persisted ? createChildSession(record.cwd, parent.ctx.sessionManager.getSessionFile(),
|
|
23
25
|
run.type.sessionDir === undefined ? undefined : resourcePath(run.type.sessionDir, record.cwd)) : SessionManager.inMemory(record.cwd));
|
|
24
26
|
if (record.persisted && run.type.sessionDir !== undefined) {
|
|
@@ -6,7 +6,7 @@ import { promises as fs } from 'node:fs';
|
|
|
6
6
|
import type { FileHandle } from 'node:fs/promises';
|
|
7
7
|
import { resolve, dirname } from 'node:path';
|
|
8
8
|
import { performance } from 'node:perf_hooks';
|
|
9
|
-
import type
|
|
9
|
+
import { shellInvocation, type ResolvedShellConfig } from '../terminal/shell.ts';
|
|
10
10
|
import { trackIdentity, type Tracked } from './process.ts';
|
|
11
11
|
import type { ExitObservation } from '../types.ts';
|
|
12
12
|
|
|
@@ -37,9 +37,9 @@ export async function launchPipe(input: { command: string; cwd: string; shell: R
|
|
|
37
37
|
let stderr: FileHandle;
|
|
38
38
|
try { stderr = await openOutput(input.stderrPath); } catch (error) { await stdout.close().catch(() => {}); throw error; }
|
|
39
39
|
try {
|
|
40
|
-
const
|
|
41
|
-
const child = spawn(input.shell.shell,
|
|
42
|
-
cwd: input.cwd, env
|
|
40
|
+
const { args, env } = shellInvocation(input.shell, input.command);
|
|
41
|
+
const child = spawn(input.shell.shell, args, {
|
|
42
|
+
cwd: input.cwd, env, windowsHide: true, detached: process.platform !== 'win32',
|
|
43
43
|
stdio: ['pipe', stdout.fd, stderr.fd],
|
|
44
44
|
});
|
|
45
45
|
const exit = Promise.withResolvers<ExitObservation>();
|
|
@@ -62,7 +62,7 @@ export async function launchPipe(input: { command: string; cwd: string; shell: R
|
|
|
62
62
|
child.once('spawn', () => started.resolve());
|
|
63
63
|
child.stdin?.on('error', error => { inputError = String(error); });
|
|
64
64
|
// Legacy WSL bash reads its script from stdin; such shells cannot also receive job input.
|
|
65
|
-
if (
|
|
65
|
+
if (input.shell.commandTransport === 'stdin') child.stdin?.end(input.command);
|
|
66
66
|
await started.promise;
|
|
67
67
|
run.pid = child.pid!;
|
|
68
68
|
trackIdentity(run);
|
|
@@ -88,7 +88,7 @@ export function compileMonitor(input: MonitorInput, command: string | undefined,
|
|
|
88
88
|
throw new ToolError('INVALID_ARGS', strategy === 'file-watch' ? 'file-watch needs monitor.fileWatch and no command' : 'command is required');
|
|
89
89
|
}
|
|
90
90
|
// A stdin-transport shell (legacy WSL bash) cannot also pipe the candidate JSON to a detector.
|
|
91
|
-
if (input.detector && shell.commandTransport
|
|
91
|
+
if (input.detector && shell.commandTransport === 'stdin') throw new ToolError('INVALID_ARGS', 'monitor.detector cannot use a shell that reads commands from stdin (set shellPath to Git Bash on Windows)');
|
|
92
92
|
const ids = input.triggers.map(trigger => trigger.id);
|
|
93
93
|
if (new Set(ids).size !== ids.length) throw new ToolError('INVALID_ARGS', 'monitor trigger ids must be unique');
|
|
94
94
|
const pollMs = input.poll?.intervalMs ?? 5000;
|
|
@@ -8,7 +8,7 @@ import { StringDecoder } from 'node:string_decoder';
|
|
|
8
8
|
import { setImmediate as yieldToLoop } from 'node:timers/promises';
|
|
9
9
|
import { normalizeVisibleText } from '../terminal/visible-text.ts';
|
|
10
10
|
import { sanitizeText } from '../../runtime/text.ts';
|
|
11
|
-
import type
|
|
11
|
+
import { shellInvocation, type ResolvedShellConfig } from '../terminal/shell.ts';
|
|
12
12
|
import { POLL_BOUNDARY, type CompiledMonitor, type Strategy } from './compile.ts';
|
|
13
13
|
|
|
14
14
|
export type MonitorEvent = {
|
|
@@ -36,7 +36,8 @@ function summarizeDiff(previous: string, current: string): string {
|
|
|
36
36
|
|
|
37
37
|
async function runDetector(detector: NonNullable<CompiledMonitor['detector']>, candidate: Candidate, shell: ResolvedShellConfig, cwd: string): Promise<Partial<Candidate> & { emit: boolean }> {
|
|
38
38
|
const exited = Promise.withResolvers<number | null>();
|
|
39
|
-
const
|
|
39
|
+
const { args, env } = shellInvocation(shell, detector.command);
|
|
40
|
+
const child = spawn(shell.shell, args, { cwd, env, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true });
|
|
40
41
|
let stdout = '', stderr = '';
|
|
41
42
|
const timer = setTimeout(() => { child.kill(); exited.reject(new Error(`detector timed out after ${detector.timeoutMs}ms`)); }, detector.timeoutMs);
|
|
42
43
|
child.stdout.setEncoding('utf8').on('data', chunk => { stdout += chunk; });
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { TerminalScreen } from './screen.ts';
|
|
5
5
|
import type { TerminalSnapshot } from './snapshot.ts';
|
|
6
6
|
import { buildCursorPositionResponse, buildPrimaryDeviceAttributesResponse, splitAroundDeviceQueries, type DeviceQuery } from './protocol.ts';
|
|
7
|
-
import type
|
|
7
|
+
import { shellInvocation, type ResolvedShellConfig } from './shell.ts';
|
|
8
8
|
import { createPtyProcess, type PtyExitEvent, type PtyProcess } from '../backends/pty.ts';
|
|
9
9
|
|
|
10
10
|
type OutputBatch = { chunks: string[]; queryAfter?: DeviceQuery };
|
|
@@ -30,14 +30,14 @@ export class PtyTerminalSession extends TerminalScreen {
|
|
|
30
30
|
constructor(private options: PtySessionOptions, spawnPty = createPtyProcess) {
|
|
31
31
|
const { cols = 80, rows = 24, scrollback = 5000 } = options;
|
|
32
32
|
super(cols, rows, scrollback);
|
|
33
|
-
if (options.shellConfig.commandTransport
|
|
33
|
+
if (options.shellConfig.commandTransport === 'stdin') {
|
|
34
34
|
throw new Error(`PTY jobs cannot use "${options.shellConfig.shell}" because it reads commands from stdin; set shellPath to Git Bash in Pi settings.json`);
|
|
35
35
|
}
|
|
36
36
|
this.xterm.buffer.onBufferChange(buffer => { if (buffer.type === 'alternate') this.alternateScreen = true; });
|
|
37
|
+
const { args, env: shellEnv } = shellInvocation(options.shellConfig, options.command);
|
|
37
38
|
const env: Record<string, string> = {};
|
|
38
|
-
for (const [key, value] of Object.entries({ TERM: 'xterm-256color', ...
|
|
39
|
-
this.ptyProcess = spawnPty(options.shellConfig.shell,
|
|
40
|
-
{ name: 'xterm-256color', cols, rows, cwd: options.cwd, env });
|
|
39
|
+
for (const [key, value] of Object.entries({ TERM: 'xterm-256color', ...shellEnv })) if (value !== undefined) env[key] = value;
|
|
40
|
+
this.ptyProcess = spawnPty(options.shellConfig.shell, args, { name: 'xterm-256color', cols, rows, cwd: options.cwd, env });
|
|
41
41
|
this.ptyProcess.onData(data => {
|
|
42
42
|
if (this.disposed) return;
|
|
43
43
|
const { segments, trailingText } = splitAroundDeviceQueries(typeof data === 'string' ? data : data.toString('utf8'));
|
|
@@ -4,7 +4,17 @@ import { getAgentDir, getShellConfig, SettingsManager } from '@earendil-works/pi
|
|
|
4
4
|
export interface ResolvedShellConfig {
|
|
5
5
|
readonly shell: string;
|
|
6
6
|
readonly args: readonly string[];
|
|
7
|
-
readonly commandTransport: 'argv' | 'stdin';
|
|
7
|
+
readonly commandTransport: 'argv' | 'env' | 'stdin';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function shellInvocation(shell: ResolvedShellConfig, command: string) {
|
|
11
|
+
const args = [...shell.args];
|
|
12
|
+
const env = { ...process.env };
|
|
13
|
+
if (shell.commandTransport === 'argv') args.push(command);
|
|
14
|
+
// Pi 1.8's Git Bash runner reads this variable and unsets it before evaluating the command.
|
|
15
|
+
// Keep it local to this spawn; older Pi versions never select env transport.
|
|
16
|
+
if (shell.commandTransport === 'env') env.PI_BASH_COMMAND = command;
|
|
17
|
+
return { args, env };
|
|
8
18
|
}
|
|
9
19
|
|
|
10
20
|
/**
|