@dyyz1993/pi-coding-agent 0.70.6 → 0.74.5
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 +266 -80
- package/README.md +48 -20
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +4 -2
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts +13 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +32 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/cli/args.d.ts +2 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +34 -22
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +2 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -4
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +16 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +238 -66
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +10 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +14 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +2 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +37 -26
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1068 -1116
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +9 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +20 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +9 -6
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +0 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +1 -1
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/template.css +53 -4
- package/dist/core/export-html/template.js +84 -20
- package/dist/core/export-html/tool-renderer.d.ts +0 -6
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +15 -2
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +0 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +49 -137
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +24 -20
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +128 -253
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +88 -60
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +10 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/file-store/file-snapshot-manager.d.ts +95 -0
- package/dist/core/file-store/file-snapshot-manager.d.ts.map +1 -0
- package/dist/core/file-store/file-snapshot-manager.js +508 -0
- package/dist/core/file-store/file-snapshot-manager.js.map +1 -0
- package/dist/core/file-store/index.d.ts +5 -0
- package/dist/core/file-store/index.d.ts.map +1 -0
- package/dist/core/file-store/index.js +3 -0
- package/dist/core/file-store/index.js.map +1 -0
- package/dist/core/messages.d.ts +10 -2
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +23 -6
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts +19 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +97 -16
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +24 -15
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/package-manager.d.ts +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +61 -35
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +32 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +9 -21
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +9 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +39 -18
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +27 -17
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +133 -47
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +22 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +54 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -8
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -3
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/bash.d.ts +0 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +155 -110
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +3 -2
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +4 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +50 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +178 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +70 -13
- package/dist/core/tools/read.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -39
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +3 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +3 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +1 -4
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +14 -56
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +19 -4
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -6
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +93 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +3 -7
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +5 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +53 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +20 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +423 -186
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/print-mode.d.ts +3 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +62 -19
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +80 -60
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +108 -93
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +106 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +115 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +238 -12
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/child-process.d.ts +1 -0
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +8 -0
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -2
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +84 -45
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/paths.d.ts +9 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +31 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +5 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/structured-output.d.ts +10 -0
- package/dist/utils/structured-output.d.ts.map +1 -0
- package/dist/utils/structured-output.js +57 -0
- package/dist/utils/structured-output.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +6 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +77 -0
- package/dist/utils/version-check.js.map +1 -0
- package/docs/compaction.md +14 -14
- package/docs/custom-provider.md +40 -31
- package/docs/development.md +1 -1
- package/docs/docs.json +148 -0
- package/docs/extensions.md +116 -56
- package/docs/index.md +70 -0
- package/docs/json.md +4 -4
- package/docs/models.md +150 -3
- package/docs/packages.md +10 -5
- package/docs/providers.md +62 -17
- package/docs/quickstart.md +142 -0
- package/docs/rollback-architecture.md +693 -0
- package/docs/rollback-test-cases.md +412 -0
- package/docs/rpc.md +1 -1
- package/docs/sdk.md +26 -26
- package/docs/{session.md → session-format.md} +6 -6
- package/docs/sessions.md +137 -0
- package/docs/settings.md +52 -9
- package/docs/termux.md +1 -1
- package/docs/themes.md +2 -2
- package/docs/tui.md +20 -20
- package/docs/usage.md +277 -0
- package/examples/extensions/README.md +2 -4
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/commands.ts +2 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/git-checkpoint.ts +1 -1
- package/examples/extensions/handoff.ts +49 -11
- package/examples/extensions/plan-mode/index.ts +1 -1
- package/examples/extensions/sandbox/package-lock.json +5 -5
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/agents.ts +126 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/README.md +2 -2
- package/package.json +7 -16
- package/docs/tree.md +0 -233
- package/examples/extensions/antigravity-image-gen.ts +0 -418
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent discovery and configuration
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { getAgentDir, parseFrontmatter } from "@dyyz1993/pi-coding-agent";
|
|
8
|
+
|
|
9
|
+
export type AgentScope = "user" | "project" | "both";
|
|
10
|
+
|
|
11
|
+
export interface AgentConfig {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
tools?: string[];
|
|
15
|
+
model?: string;
|
|
16
|
+
systemPrompt: string;
|
|
17
|
+
source: "user" | "project";
|
|
18
|
+
filePath: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AgentDiscoveryResult {
|
|
22
|
+
agents: AgentConfig[];
|
|
23
|
+
projectAgentsDir: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function loadAgentsFromDir(dir: string, source: "user" | "project"): AgentConfig[] {
|
|
27
|
+
const agents: AgentConfig[] = [];
|
|
28
|
+
|
|
29
|
+
if (!fs.existsSync(dir)) {
|
|
30
|
+
return agents;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let entries: fs.Dirent[];
|
|
34
|
+
try {
|
|
35
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
36
|
+
} catch {
|
|
37
|
+
return agents;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
if (!entry.name.endsWith(".md")) continue;
|
|
42
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) continue;
|
|
43
|
+
|
|
44
|
+
const filePath = path.join(dir, entry.name);
|
|
45
|
+
let content: string;
|
|
46
|
+
try {
|
|
47
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
48
|
+
} catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { frontmatter, body } = parseFrontmatter<Record<string, string>>(content);
|
|
53
|
+
|
|
54
|
+
if (!frontmatter.name || !frontmatter.description) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const tools = frontmatter.tools
|
|
59
|
+
?.split(",")
|
|
60
|
+
.map((t: string) => t.trim())
|
|
61
|
+
.filter(Boolean);
|
|
62
|
+
|
|
63
|
+
agents.push({
|
|
64
|
+
name: frontmatter.name,
|
|
65
|
+
description: frontmatter.description,
|
|
66
|
+
tools: tools && tools.length > 0 ? tools : undefined,
|
|
67
|
+
model: frontmatter.model,
|
|
68
|
+
systemPrompt: body,
|
|
69
|
+
source,
|
|
70
|
+
filePath,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return agents;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isDirectory(p: string): boolean {
|
|
78
|
+
try {
|
|
79
|
+
return fs.statSync(p).isDirectory();
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function findNearestProjectAgentsDir(cwd: string): string | null {
|
|
86
|
+
let currentDir = cwd;
|
|
87
|
+
while (true) {
|
|
88
|
+
const candidate = path.join(currentDir, ".pi", "agents");
|
|
89
|
+
if (isDirectory(candidate)) return candidate;
|
|
90
|
+
|
|
91
|
+
const parentDir = path.dirname(currentDir);
|
|
92
|
+
if (parentDir === currentDir) return null;
|
|
93
|
+
currentDir = parentDir;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryResult {
|
|
98
|
+
const userDir = path.join(getAgentDir(), "agents");
|
|
99
|
+
const projectAgentsDir = findNearestProjectAgentsDir(cwd);
|
|
100
|
+
|
|
101
|
+
const userAgents = scope === "project" ? [] : loadAgentsFromDir(userDir, "user");
|
|
102
|
+
const projectAgents = scope === "user" || !projectAgentsDir ? [] : loadAgentsFromDir(projectAgentsDir, "project");
|
|
103
|
+
|
|
104
|
+
const agentMap = new Map<string, AgentConfig>();
|
|
105
|
+
|
|
106
|
+
if (scope === "both") {
|
|
107
|
+
for (const agent of userAgents) agentMap.set(agent.name, agent);
|
|
108
|
+
for (const agent of projectAgents) agentMap.set(agent.name, agent);
|
|
109
|
+
} else if (scope === "user") {
|
|
110
|
+
for (const agent of userAgents) agentMap.set(agent.name, agent);
|
|
111
|
+
} else {
|
|
112
|
+
for (const agent of projectAgents) agentMap.set(agent.name, agent);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { agents: Array.from(agentMap.values()), projectAgentsDir };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function formatAgentList(agents: AgentConfig[], maxItems: number): { text: string; remaining: number } {
|
|
119
|
+
if (agents.length === 0) return { text: "none", remaining: 0 };
|
|
120
|
+
const listed = agents.slice(0, maxItems);
|
|
121
|
+
const remaining = agents.length - listed.length;
|
|
122
|
+
return {
|
|
123
|
+
text: listed.map((a) => `${a.name} (${a.source}): ${a.description}`).join("; "),
|
|
124
|
+
remaining,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-with-deps",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.74.5",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
package/examples/sdk/README.md
CHANGED
|
@@ -32,7 +32,7 @@ npx tsx examples/sdk/01-minimal.ts
|
|
|
32
32
|
## Quick Reference
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
|
-
import { getModel } from "@
|
|
35
|
+
import { getModel } from "@dyyz1993/pi-ai";
|
|
36
36
|
import {
|
|
37
37
|
AuthStorage,
|
|
38
38
|
createAgentSession,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
codingTools,
|
|
44
44
|
readOnlyTools,
|
|
45
45
|
readTool, bashTool, editTool, writeTool,
|
|
46
|
-
} from "@
|
|
46
|
+
} from "@dyyz1993/pi-coding-agent";
|
|
47
47
|
|
|
48
48
|
// Auth and models setup
|
|
49
49
|
const authStorage = AuthStorage.create();
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyyz1993/pi-coding-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.5",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
7
|
-
"name": "pi",
|
|
8
7
|
"configDir": ".pi"
|
|
9
8
|
},
|
|
10
9
|
"bin": {
|
|
@@ -36,15 +35,12 @@
|
|
|
36
35
|
"copy-assets": "shx mkdir -p dist/modes/interactive/theme && shx cp src/modes/interactive/theme/*.json dist/modes/interactive/theme/ && shx mkdir -p dist/modes/interactive/assets && shx cp src/modes/interactive/assets/*.png dist/modes/interactive/assets/ && shx mkdir -p dist/core/export-html/vendor && shx cp src/core/export-html/template.html src/core/export-html/template.css src/core/export-html/template.js dist/core/export-html/ && shx cp src/core/export-html/vendor/*.js dist/core/export-html/vendor/",
|
|
37
36
|
"copy-binary-assets": "shx cp package.json dist/ && shx cp README.md dist/ && shx cp CHANGELOG.md dist/ && shx mkdir -p dist/theme && shx cp src/modes/interactive/theme/*.json dist/theme/ && shx mkdir -p dist/assets && shx cp src/modes/interactive/assets/*.png dist/assets/ && shx mkdir -p dist/export-html/vendor && shx cp src/core/export-html/template.html dist/export-html/ && shx cp src/core/export-html/vendor/*.js dist/export-html/vendor/ && shx cp -r docs dist/ && shx cp -r examples dist/ && shx cp ../../node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm dist/",
|
|
38
37
|
"test": "vitest --run",
|
|
39
|
-
"lint:extensions": "eslint extensions/",
|
|
40
|
-
"check:extensions": "tsgo -p tsconfig.extensions.json --noEmit",
|
|
41
38
|
"prepublishOnly": "npm run clean && npm run build"
|
|
42
39
|
},
|
|
43
40
|
"dependencies": {
|
|
44
|
-
"@dyyz1993/pi-agent-core": "^0.
|
|
45
|
-
"@dyyz1993/pi-ai": "^0.
|
|
46
|
-
"@dyyz1993/pi-tui": "^0.
|
|
47
|
-
"@mariozechner/jiti": "^2.6.2",
|
|
41
|
+
"@dyyz1993/pi-agent-core": "^0.74.5",
|
|
42
|
+
"@dyyz1993/pi-ai": "^0.74.5",
|
|
43
|
+
"@dyyz1993/pi-tui": "^0.74.5",
|
|
48
44
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
49
45
|
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
50
46
|
"chalk": "^5.5.0",
|
|
@@ -55,13 +51,14 @@
|
|
|
55
51
|
"glob": "^13.0.1",
|
|
56
52
|
"hosted-git-info": "^9.0.2",
|
|
57
53
|
"ignore": "^7.0.5",
|
|
54
|
+
"jiti": "^2.7.0",
|
|
58
55
|
"marked": "^15.0.12",
|
|
59
56
|
"minimatch": "^10.2.3",
|
|
60
57
|
"proper-lockfile": "^4.1.2",
|
|
61
58
|
"strip-ansi": "^7.1.0",
|
|
62
59
|
"typebox": "^1.1.24",
|
|
63
60
|
"undici": "^7.19.1",
|
|
64
|
-
"uuid": "^
|
|
61
|
+
"uuid": "^14.0.0",
|
|
65
62
|
"yaml": "^2.8.2"
|
|
66
63
|
},
|
|
67
64
|
"overrides": {
|
|
@@ -71,19 +68,16 @@
|
|
|
71
68
|
}
|
|
72
69
|
},
|
|
73
70
|
"optionalDependencies": {
|
|
74
|
-
"@mariozechner/clipboard": "^0.3.
|
|
71
|
+
"@mariozechner/clipboard": "^0.3.5"
|
|
75
72
|
},
|
|
76
73
|
"devDependencies": {
|
|
77
|
-
"@eslint/js": "^10.0.1",
|
|
78
74
|
"@types/diff": "^7.0.2",
|
|
79
75
|
"@types/hosted-git-info": "^3.0.5",
|
|
80
76
|
"@types/ms": "^2.1.0",
|
|
81
77
|
"@types/node": "^24.3.0",
|
|
82
78
|
"@types/proper-lockfile": "^4.1.4",
|
|
83
|
-
"eslint": "^10.3.0",
|
|
84
79
|
"shx": "^0.4.0",
|
|
85
80
|
"typescript": "^5.7.3",
|
|
86
|
-
"typescript-eslint": "^8.59.1",
|
|
87
81
|
"vitest": "^3.2.4"
|
|
88
82
|
},
|
|
89
83
|
"keywords": [
|
|
@@ -96,9 +90,6 @@
|
|
|
96
90
|
],
|
|
97
91
|
"author": "Mario Zechner",
|
|
98
92
|
"license": "MIT",
|
|
99
|
-
"publishConfig": {
|
|
100
|
-
"access": "public"
|
|
101
|
-
},
|
|
102
93
|
"repository": {
|
|
103
94
|
"type": "git",
|
|
104
95
|
"url": "git+https://github.com/dyyz1993/pi-mono.git",
|
package/docs/tree.md
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
# Session Tree Navigation
|
|
2
|
-
|
|
3
|
-
The `/tree` command provides tree-based navigation of the session history.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Sessions are stored as trees where each entry has an `id` and `parentId`. The "leaf" pointer tracks the current position. `/tree` lets you navigate to any point and optionally summarize the branch you're leaving.
|
|
8
|
-
|
|
9
|
-
### Comparison with `/fork`
|
|
10
|
-
|
|
11
|
-
| Feature | `/fork` | `/tree` |
|
|
12
|
-
|---------|---------|---------|
|
|
13
|
-
| View | Flat list of user messages | Full tree structure |
|
|
14
|
-
| Action | Extracts path to **new session file** | Changes leaf in **same session** |
|
|
15
|
-
| Summary | Never | Optional (user prompted) |
|
|
16
|
-
| Events | `session_before_fork` / `session_start` (`reason: "fork"`) | `session_before_tree` / `session_tree` |
|
|
17
|
-
|
|
18
|
-
Use `/clone` when you want a new session file containing the full current active branch without rewinding to an earlier user message.
|
|
19
|
-
|
|
20
|
-
## Tree UI
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
├─ user: "Hello, can you help..."
|
|
24
|
-
│ └─ assistant: "Of course! I can..."
|
|
25
|
-
│ ├─ user: "Let's try approach A..."
|
|
26
|
-
│ │ └─ assistant: "For approach A..."
|
|
27
|
-
│ │ └─ [compaction: 12k tokens]
|
|
28
|
-
│ │ └─ user: "That worked..." ← active
|
|
29
|
-
│ └─ user: "Actually, approach B..."
|
|
30
|
-
│ └─ assistant: "For approach B..."
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Controls
|
|
34
|
-
|
|
35
|
-
| Key | Action |
|
|
36
|
-
|-----|--------|
|
|
37
|
-
| ↑/↓ | Navigate (depth-first order) |
|
|
38
|
-
| ←/→ | Page up/down |
|
|
39
|
-
| Ctrl+←/Ctrl+→ or Alt+←/Alt+→ | Fold/unfold and jump between branch segments |
|
|
40
|
-
| Shift+L | Set or clear a label on the selected node |
|
|
41
|
-
| Shift+T | Toggle label timestamps |
|
|
42
|
-
| Enter | Select node |
|
|
43
|
-
| Escape/Ctrl+C | Cancel |
|
|
44
|
-
| Ctrl+U | Toggle: user messages only |
|
|
45
|
-
| Ctrl+O | Toggle: show all (including custom/label entries) |
|
|
46
|
-
|
|
47
|
-
`Ctrl+←` or `Alt+←` folds the current node if it is foldable. Foldable nodes are roots and branch segment starts that have visible children. If the current node is not foldable, or is already folded, the selection jumps up to the previous visible branch segment start.
|
|
48
|
-
|
|
49
|
-
`Ctrl+→` or `Alt+→` unfolds the current node if it is folded. Otherwise, the selection jumps down to the next visible branch segment start, or to the branch end when there is no further branch point.
|
|
50
|
-
|
|
51
|
-
### Display
|
|
52
|
-
|
|
53
|
-
- Height: half terminal height
|
|
54
|
-
- Current leaf marked with `← active`
|
|
55
|
-
- Labels shown inline: `[label-name]`
|
|
56
|
-
- `Shift+T` shows the latest label-change timestamp next to labeled nodes
|
|
57
|
-
- Foldable branch starts show `⊟` in the connector. Folded branches show `⊞`
|
|
58
|
-
- Active path marker `•` appears after the fold indicator when applicable
|
|
59
|
-
- Search and filter changes reset all folds
|
|
60
|
-
- Default filter hides `label` and `custom` entries (shown in Ctrl+O mode)
|
|
61
|
-
- At each branch point, the active subtree is shown first; other sibling branches are sorted by timestamp (oldest first)
|
|
62
|
-
|
|
63
|
-
## Selection Behavior
|
|
64
|
-
|
|
65
|
-
### User Message or Custom Message
|
|
66
|
-
1. Leaf set to **parent** of selected node (or `null` if root)
|
|
67
|
-
2. Message text placed in **editor** for re-submission
|
|
68
|
-
3. User edits and submits, creating a new branch
|
|
69
|
-
|
|
70
|
-
### Non-User Message (assistant, compaction, etc.)
|
|
71
|
-
1. Leaf set to **selected node**
|
|
72
|
-
2. Editor stays empty
|
|
73
|
-
3. User continues from that point
|
|
74
|
-
|
|
75
|
-
### Selecting Root User Message
|
|
76
|
-
If user selects the very first message (has no parent):
|
|
77
|
-
1. Leaf reset to `null` (empty conversation)
|
|
78
|
-
2. Message text placed in editor
|
|
79
|
-
3. User effectively restarts from scratch
|
|
80
|
-
|
|
81
|
-
## Branch Summarization
|
|
82
|
-
|
|
83
|
-
When switching branches, user is presented with three options:
|
|
84
|
-
|
|
85
|
-
1. **No summary** - Switch immediately without summarizing
|
|
86
|
-
2. **Summarize** - Generate a summary using the default prompt
|
|
87
|
-
3. **Summarize with custom prompt** - Opens an editor to enter additional focus instructions that are appended to the default summarization prompt
|
|
88
|
-
|
|
89
|
-
### What Gets Summarized
|
|
90
|
-
|
|
91
|
-
Path from old leaf back to common ancestor with target:
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
A → B → C → D → E → F ← old leaf
|
|
95
|
-
↘ G → H ← target
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Abandoned path: D → E → F (summarized)
|
|
99
|
-
|
|
100
|
-
Summarization stops at:
|
|
101
|
-
1. Common ancestor (always)
|
|
102
|
-
2. Compaction node (if encountered first)
|
|
103
|
-
|
|
104
|
-
### Summary Storage
|
|
105
|
-
|
|
106
|
-
Stored as `BranchSummaryEntry`:
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
interface BranchSummaryEntry {
|
|
110
|
-
type: "branch_summary";
|
|
111
|
-
id: string;
|
|
112
|
-
parentId: string; // New leaf position
|
|
113
|
-
timestamp: string;
|
|
114
|
-
fromId: string; // Old leaf we abandoned
|
|
115
|
-
summary: string; // LLM-generated summary
|
|
116
|
-
details?: unknown; // Optional hook data
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## Implementation
|
|
121
|
-
|
|
122
|
-
### AgentSession.navigateTree()
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
async navigateTree(
|
|
126
|
-
targetId: string,
|
|
127
|
-
options?: {
|
|
128
|
-
summarize?: boolean;
|
|
129
|
-
customInstructions?: string;
|
|
130
|
-
replaceInstructions?: boolean;
|
|
131
|
-
label?: string;
|
|
132
|
-
}
|
|
133
|
-
): Promise<{ editorText?: string; cancelled: boolean }>
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Options:
|
|
137
|
-
- `summarize`: Whether to generate a summary of the abandoned branch
|
|
138
|
-
- `customInstructions`: Custom instructions for the summarizer
|
|
139
|
-
- `replaceInstructions`: If true, `customInstructions` replaces the default prompt instead of being appended
|
|
140
|
-
- `label`: Label to attach to the branch summary entry (or target entry if not summarizing)
|
|
141
|
-
|
|
142
|
-
Flow:
|
|
143
|
-
1. Validate target, check no-op (target === current leaf)
|
|
144
|
-
2. Find common ancestor between old leaf and target
|
|
145
|
-
3. Collect entries to summarize (if requested)
|
|
146
|
-
4. Fire `session_before_tree` event (hook can cancel or provide summary)
|
|
147
|
-
5. Run default summarizer if needed
|
|
148
|
-
6. Switch leaf via `branch()` or `branchWithSummary()`
|
|
149
|
-
7. Update agent: `agent.state.messages = sessionManager.buildSessionContext().messages`
|
|
150
|
-
8. Fire `session_tree` event
|
|
151
|
-
9. Notify custom tools via session event
|
|
152
|
-
10. Return result with `editorText` if user message was selected
|
|
153
|
-
|
|
154
|
-
### SessionManager
|
|
155
|
-
|
|
156
|
-
- `getLeafUuid(): string | null` - Current leaf (null if empty)
|
|
157
|
-
- `resetLeaf(): void` - Set leaf to null (for root user message navigation)
|
|
158
|
-
- `getTree(): SessionTreeNode[]` - Full tree with children sorted by timestamp
|
|
159
|
-
- `branch(id)` - Change leaf pointer
|
|
160
|
-
- `branchWithSummary(id, summary)` - Change leaf and create summary entry
|
|
161
|
-
|
|
162
|
-
### InteractiveMode
|
|
163
|
-
|
|
164
|
-
`/tree` command shows `TreeSelectorComponent`, then:
|
|
165
|
-
1. Prompt for summarization
|
|
166
|
-
2. Call `session.navigateTree()`
|
|
167
|
-
3. Clear and re-render chat
|
|
168
|
-
4. Set editor text if applicable
|
|
169
|
-
|
|
170
|
-
## Hook Events
|
|
171
|
-
|
|
172
|
-
### `session_before_tree`
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
interface TreePreparation {
|
|
176
|
-
targetId: string;
|
|
177
|
-
oldLeafId: string | null;
|
|
178
|
-
commonAncestorId: string | null;
|
|
179
|
-
entriesToSummarize: SessionEntry[];
|
|
180
|
-
userWantsSummary: boolean;
|
|
181
|
-
customInstructions?: string;
|
|
182
|
-
replaceInstructions?: boolean;
|
|
183
|
-
label?: string;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
interface SessionBeforeTreeEvent {
|
|
187
|
-
type: "session_before_tree";
|
|
188
|
-
preparation: TreePreparation;
|
|
189
|
-
signal: AbortSignal;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
interface SessionBeforeTreeResult {
|
|
193
|
-
cancel?: boolean;
|
|
194
|
-
summary?: { summary: string; details?: unknown };
|
|
195
|
-
customInstructions?: string; // Override custom instructions
|
|
196
|
-
replaceInstructions?: boolean; // Override replace mode
|
|
197
|
-
label?: string; // Override label
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
Extensions can override `customInstructions`, `replaceInstructions`, and `label` by returning them from the `session_before_tree` handler.
|
|
202
|
-
|
|
203
|
-
### `session_tree`
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
interface SessionTreeEvent {
|
|
207
|
-
type: "session_tree";
|
|
208
|
-
newLeafId: string | null;
|
|
209
|
-
oldLeafId: string | null;
|
|
210
|
-
summaryEntry?: BranchSummaryEntry;
|
|
211
|
-
fromHook?: boolean;
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Example: Custom Summarizer
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
export default function(pi: HookAPI) {
|
|
219
|
-
pi.on("session_before_tree", async (event, ctx) => {
|
|
220
|
-
if (!event.preparation.userWantsSummary) return;
|
|
221
|
-
if (event.preparation.entriesToSummarize.length === 0) return;
|
|
222
|
-
|
|
223
|
-
const summary = await myCustomSummarizer(event.preparation.entriesToSummarize);
|
|
224
|
-
return { summary: { summary, details: { custom: true } } };
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
## Error Handling
|
|
230
|
-
|
|
231
|
-
- Summarization failure: cancels navigation, shows error
|
|
232
|
-
- User abort (Escape): cancels navigation
|
|
233
|
-
- Hook returns `cancel: true`: cancels navigation silently
|