@aoshizuku/pi-bettertui 0.1.1 → 0.1.2
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/README.md +327 -327
- package/package.json +1 -1
- package/src/format.ts +165 -165
- package/src/gutter.ts +236 -236
- package/src/index.ts +660 -660
- package/src/segment.ts +311 -311
- package/src/shell-description.ts +75 -75
- package/src/thinking.ts +524 -524
- package/src/timeline.ts +881 -881
- package/src/tool-lines.ts +173 -173
- package/src/tool-row.ts +387 -387
- package/src/tool-summary.ts +237 -237
- package/src/types.ts +13 -13
package/src/shell-description.ts
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createBashToolDefinition,
|
|
3
|
-
createPowerShellToolDefinition,
|
|
4
|
-
type ExtensionAPI,
|
|
5
|
-
SettingsManager,
|
|
6
|
-
type ToolDefinition,
|
|
7
|
-
} from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { type TSchema, Type } from "typebox";
|
|
9
|
-
|
|
10
|
-
type Settings = ReturnType<ExtensionAPI["getSettings"]>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Pi's shell tools only take `command`, so the transcript can show nothing but
|
|
14
|
-
* the raw command. These overrides add an optional `description` the model
|
|
15
|
-
* fills in, and delegate execution to Pi's own implementation unchanged.
|
|
16
|
-
*/
|
|
17
|
-
export const SHELL_DESCRIPTION_HINT =
|
|
18
|
-
"Short description of what this command does (5-10 words), shown to the user in place of the command. Write it in the user's language; keep commands, paths, and identifiers verbatim.";
|
|
19
|
-
|
|
20
|
-
export type ShellToolName = "bash" | "powershell";
|
|
21
|
-
|
|
22
|
-
export const SHELL_TOOL_NAMES: readonly ShellToolName[] = ["bash", "powershell"];
|
|
23
|
-
|
|
24
|
-
// The override changes the parameter schema of a built-in definition.
|
|
25
|
-
type AnyToolDefinition = ToolDefinition<any, any, any>;
|
|
26
|
-
|
|
27
|
-
/** Insert an optional `description` right after `command`, keeping every other parameter as is. */
|
|
28
|
-
export function withDescriptionParameter(parameters: TSchema): TSchema {
|
|
29
|
-
const source = parameters as { properties?: Record<string, TSchema>; additionalProperties?: unknown };
|
|
30
|
-
const description = Type.Optional(Type.String({ description: SHELL_DESCRIPTION_HINT }));
|
|
31
|
-
const properties: Record<string, TSchema> = {};
|
|
32
|
-
for (const [key, value] of Object.entries(source.properties ?? {})) {
|
|
33
|
-
if (key === "description") continue;
|
|
34
|
-
properties[key] = value;
|
|
35
|
-
if (key === "command") properties.description = description;
|
|
36
|
-
}
|
|
37
|
-
properties.description ??= description;
|
|
38
|
-
const options = typeof source.additionalProperties === "boolean"
|
|
39
|
-
? { additionalProperties: source.additionalProperties }
|
|
40
|
-
: {};
|
|
41
|
-
return Type.Object(properties, options);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function nativeDefinition(name: ShellToolName, cwd: string, settings?: SettingsManager): AnyToolDefinition {
|
|
45
|
-
if (name === "powershell") return createPowerShellToolDefinition(cwd) as AnyToolDefinition;
|
|
46
|
-
// Same options Pi passes when it builds its own bash tool.
|
|
47
|
-
const options = settings
|
|
48
|
-
? { commandPrefix: settings.getShellCommandPrefix(), shellPath: settings.getShellPath() }
|
|
49
|
-
: undefined;
|
|
50
|
-
return createBashToolDefinition(cwd, options) as AnyToolDefinition;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function shellSettings(getSettings: () => Settings): SettingsManager | undefined {
|
|
54
|
-
try {
|
|
55
|
-
return SettingsManager.inMemory(getSettings());
|
|
56
|
-
} catch {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function createDescribedShellTool(name: ShellToolName, getSettings: () => Settings): AnyToolDefinition {
|
|
62
|
-
const template = nativeDefinition(name, process.cwd());
|
|
63
|
-
return {
|
|
64
|
-
...template,
|
|
65
|
-
parameters: withDescriptionParameter(template.parameters),
|
|
66
|
-
// Registration would activate the tool; leave activation to Pi's built-in rules
|
|
67
|
-
// (bash on by default, powershell only when the user enables it).
|
|
68
|
-
defaultActive: false,
|
|
69
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
70
|
-
const { description: _description, ...rest } = (params ?? {}) as Record<string, unknown>;
|
|
71
|
-
const native = nativeDefinition(name, ctx?.cwd || process.cwd(), shellSettings(getSettings));
|
|
72
|
-
return native.execute(toolCallId, rest, signal, onUpdate, ctx);
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createBashToolDefinition,
|
|
3
|
+
createPowerShellToolDefinition,
|
|
4
|
+
type ExtensionAPI,
|
|
5
|
+
SettingsManager,
|
|
6
|
+
type ToolDefinition,
|
|
7
|
+
} from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import { type TSchema, Type } from "typebox";
|
|
9
|
+
|
|
10
|
+
type Settings = ReturnType<ExtensionAPI["getSettings"]>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pi's shell tools only take `command`, so the transcript can show nothing but
|
|
14
|
+
* the raw command. These overrides add an optional `description` the model
|
|
15
|
+
* fills in, and delegate execution to Pi's own implementation unchanged.
|
|
16
|
+
*/
|
|
17
|
+
export const SHELL_DESCRIPTION_HINT =
|
|
18
|
+
"Short description of what this command does (5-10 words), shown to the user in place of the command. Write it in the user's language; keep commands, paths, and identifiers verbatim.";
|
|
19
|
+
|
|
20
|
+
export type ShellToolName = "bash" | "powershell";
|
|
21
|
+
|
|
22
|
+
export const SHELL_TOOL_NAMES: readonly ShellToolName[] = ["bash", "powershell"];
|
|
23
|
+
|
|
24
|
+
// The override changes the parameter schema of a built-in definition.
|
|
25
|
+
type AnyToolDefinition = ToolDefinition<any, any, any>;
|
|
26
|
+
|
|
27
|
+
/** Insert an optional `description` right after `command`, keeping every other parameter as is. */
|
|
28
|
+
export function withDescriptionParameter(parameters: TSchema): TSchema {
|
|
29
|
+
const source = parameters as { properties?: Record<string, TSchema>; additionalProperties?: unknown };
|
|
30
|
+
const description = Type.Optional(Type.String({ description: SHELL_DESCRIPTION_HINT }));
|
|
31
|
+
const properties: Record<string, TSchema> = {};
|
|
32
|
+
for (const [key, value] of Object.entries(source.properties ?? {})) {
|
|
33
|
+
if (key === "description") continue;
|
|
34
|
+
properties[key] = value;
|
|
35
|
+
if (key === "command") properties.description = description;
|
|
36
|
+
}
|
|
37
|
+
properties.description ??= description;
|
|
38
|
+
const options = typeof source.additionalProperties === "boolean"
|
|
39
|
+
? { additionalProperties: source.additionalProperties }
|
|
40
|
+
: {};
|
|
41
|
+
return Type.Object(properties, options);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function nativeDefinition(name: ShellToolName, cwd: string, settings?: SettingsManager): AnyToolDefinition {
|
|
45
|
+
if (name === "powershell") return createPowerShellToolDefinition(cwd) as AnyToolDefinition;
|
|
46
|
+
// Same options Pi passes when it builds its own bash tool.
|
|
47
|
+
const options = settings
|
|
48
|
+
? { commandPrefix: settings.getShellCommandPrefix(), shellPath: settings.getShellPath() }
|
|
49
|
+
: undefined;
|
|
50
|
+
return createBashToolDefinition(cwd, options) as AnyToolDefinition;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function shellSettings(getSettings: () => Settings): SettingsManager | undefined {
|
|
54
|
+
try {
|
|
55
|
+
return SettingsManager.inMemory(getSettings());
|
|
56
|
+
} catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createDescribedShellTool(name: ShellToolName, getSettings: () => Settings): AnyToolDefinition {
|
|
62
|
+
const template = nativeDefinition(name, process.cwd());
|
|
63
|
+
return {
|
|
64
|
+
...template,
|
|
65
|
+
parameters: withDescriptionParameter(template.parameters),
|
|
66
|
+
// Registration would activate the tool; leave activation to Pi's built-in rules
|
|
67
|
+
// (bash on by default, powershell only when the user enables it).
|
|
68
|
+
defaultActive: false,
|
|
69
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
70
|
+
const { description: _description, ...rest } = (params ?? {}) as Record<string, unknown>;
|
|
71
|
+
const native = nativeDefinition(name, ctx?.cwd || process.cwd(), shellSettings(getSettings));
|
|
72
|
+
return native.execute(toolCallId, rest, signal, onUpdate, ctx);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|