@ia-ccun/code-agent-cli 0.0.52 → 0.0.53-beta.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/bin/cli.js +97 -69
- package/config/agent/bin/README.md +102 -0
- package/config/agent/extensions/aicode-advisor.ts +197 -61
- package/config/agent/extensions/aicode-banner.ts +101 -0
- package/config/agent/extensions/aicode-btw.ts +677 -183
- package/config/agent/extensions/aicode-cd.ts +1017 -0
- package/config/agent/extensions/aicode-grillMe.ts +198 -0
- package/config/agent/extensions/aicode-pets.ts +351 -0
- package/config/agent/extensions/aicode-plan.ts +2 -0
- package/config/agent/extensions/aicode-safety-guard.ts +555 -0
- package/config/agent/extensions/aicode-tips.ts +69 -30
- package/config/agent/extensions/aicode-todo-progress.ts +547 -0
- package/config/agent/extensions/context-monitor.ts +30 -15
- package/config/agent/extensions/context.ts +132 -60
- package/config/agent/extensions/custom-footer.ts +0 -5
- package/config/agent/extensions/custom.ts +119 -109
- package/config/agent/extensions/error-monitor.ts +38 -51
- package/config/agent/extensions/goal.ts +8 -6
- package/config/agent/extensions/msg-debug.ts +103 -112
- package/config/agent/extensions/ponytail.ts +441 -0
- package/config/agent/extensions/review.ts +365 -164
- package/config/agent/extensions/tps.ts +87 -0
- package/config/agent/extensions/working-msg.ts +164 -51
- package/config/agent/help.md +0 -7
- package/config/agent/models.json +7 -7
- package/config/agent/settings.json +2 -1
- package/config/agent/skills/chroma/LICENSE +21 -0
- package/config/agent/skills/chroma/chroma-local/SKILL.md +165 -0
- package/config/agent/skills/chroma/chroma-local/cli.md +48 -0
- package/config/agent/skills/chroma/chroma-local/data-model.md +103 -0
- package/config/agent/skills/chroma/chroma-local/error-handling/python.md +166 -0
- package/config/agent/skills/chroma/chroma-local/error-handling/typescript.md +231 -0
- package/config/agent/skills/chroma/chroma-local/local-chroma/python.md +95 -0
- package/config/agent/skills/chroma/chroma-local/local-chroma/typescript.md +101 -0
- package/config/agent/skills/chroma/chroma-local/metadata/python.md +154 -0
- package/config/agent/skills/chroma/chroma-local/metadata/typescript.md +153 -0
- package/config/agent/skills/chroma/chroma-local/querying/python.md +147 -0
- package/config/agent/skills/chroma/chroma-local/querying/typescript.md +157 -0
- package/config/agent/skills/chroma/chroma-local/regex/python.md +69 -0
- package/config/agent/skills/chroma/chroma-local/regex/typescript.md +71 -0
- package/config/agent/skills/chroma/chroma-local/understanding-a-codebase.md +80 -0
- package/config/agent/skills/chroma/chroma-local/updating-deleting/python.md +159 -0
- package/config/agent/skills/chroma/chroma-local/updating-deleting/typescript.md +228 -0
- package/config/agent/skills/milvus-skill/LICENSE +202 -0
- package/config/agent/skills/milvus-skill/README.md +37 -0
- package/config/agent/skills/milvus-skill/SKILL.md +259 -0
- package/config/agent/skills/milvus-skill/references/collection.md +86 -0
- package/config/agent/skills/milvus-skill/references/database.md +24 -0
- package/config/agent/skills/milvus-skill/references/index.md +69 -0
- package/config/agent/skills/milvus-skill/references/partition.md +29 -0
- package/config/agent/skills/milvus-skill/references/patterns.md +150 -0
- package/config/agent/skills/milvus-skill/references/user-role.md +90 -0
- package/config/agent/skills/milvus-skill/references/vector.md +247 -0
- package/config/agent/skills/ponytail/SKILL.md +100 -0
- package/config/agent/skills/ponytail-audit/SKILL.md +40 -0
- package/config/agent/skills/ponytail-debt/SKILL.md +44 -0
- package/config/agent/skills/ponytail-help/SKILL.md +68 -0
- package/config/agent/skills/ponytail-review/SKILL.md +56 -0
- package/config/agent/skills/zread/README.md +115 -0
- package/config/agent/skills/zread/SKILL.md +103 -0
- package/config/agent/skills/zread/references/stdio-protocol.md +312 -0
- package/dist/banner.d.ts.map +1 -1
- package/dist/banner.js +8 -1
- package/dist/banner.js.map +1 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +9 -2
- package/dist/config-loader.js.map +1 -1
- package/package.json +7 -7
- package/scripts/postinstall.js +58 -1
- package/scripts/regression/README.md +224 -0
- package/scripts/regression/cases/01-version-and-deps.sh +94 -0
- package/scripts/regression/cases/02-extension-loading.sh +130 -0
- package/scripts/regression/cases/03-rpc-protocol.sh +259 -0
- package/scripts/regression/cases/04-prompt-stream.sh +130 -0
- package/scripts/regression/cases/05-slash-commands-and-skills.sh +119 -0
- package/scripts/regression/cases/06-tool-execution.sh +115 -0
- package/scripts/regression/cases/07-pi-new-features.sh +141 -0
- package/scripts/regression/lib/common.sh +287 -0
- package/scripts/regression/results/.last_pid +1 -0
- package/scripts/regression/results/.last_workdir +1 -0
- package/scripts/regression/results/02-extension-loading.log +18 -0
- package/scripts/regression/results/03-prompt-stream.log +16 -0
- package/scripts/regression/results/03-rpc-protocol.log +27 -0
- package/scripts/regression/results/04-slash-commands-and-skills.log +11 -0
- package/scripts/regression/results/05-tool-execution.log +8 -0
- package/scripts/regression/results/06-pi-new-features.log +29 -0
- package/scripts/regression/run-all.sh +187 -0
- package/config/agent/dangerous-patterns.json +0 -106
- package/config/agent/extensions/bash-check.ts +0 -227
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
readFileSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
} from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import * as os from "node:os";
|
|
9
|
+
|
|
10
|
+
// ============== 配置解析 ==============
|
|
11
|
+
|
|
12
|
+
const STATUS_KEY = "ponytail-mode";
|
|
13
|
+
const CUSTOM_TYPE = "ponytail-mode";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_MODE = "full";
|
|
16
|
+
const VALID_MODES = ["off", "lite", "full", "ultra", "review"] as const;
|
|
17
|
+
const RUNTIME_MODES = ["off", "lite", "full", "ultra"] as const;
|
|
18
|
+
|
|
19
|
+
type ValidMode = (typeof VALID_MODES)[number];
|
|
20
|
+
type RuntimeMode = (typeof RUNTIME_MODES)[number];
|
|
21
|
+
type Mode = RuntimeMode | "review";
|
|
22
|
+
|
|
23
|
+
function normalizeMode(mode: unknown): RuntimeMode | null {
|
|
24
|
+
if (typeof mode !== "string") return null;
|
|
25
|
+
const normalized = mode.trim().toLowerCase() as RuntimeMode;
|
|
26
|
+
return (RUNTIME_MODES as readonly string[]).includes(normalized) ? normalized : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeConfigMode(mode: unknown): ValidMode | null {
|
|
30
|
+
if (typeof mode !== "string") return null;
|
|
31
|
+
const normalized = mode.trim().toLowerCase() as ValidMode;
|
|
32
|
+
return (VALID_MODES as readonly string[]).includes(normalized) ? normalized : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizePersistedMode(mode: unknown): Mode | null {
|
|
36
|
+
return normalizeMode(mode) || normalizeConfigMode(mode);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getConfigDir(): string {
|
|
40
|
+
if (process.env.XDG_CONFIG_HOME) {
|
|
41
|
+
return path.join(process.env.XDG_CONFIG_HOME, "ponytail");
|
|
42
|
+
}
|
|
43
|
+
if (process.platform === "win32") {
|
|
44
|
+
return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "ponytail");
|
|
45
|
+
}
|
|
46
|
+
return path.join(os.homedir(), ".config", "ponytail");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getConfigPath(): string {
|
|
50
|
+
return path.join(getConfigDir(), "config.json");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getDefaultMode(): ValidMode {
|
|
54
|
+
const envMode = process.env.PONYTAIL_DEFAULT_MODE;
|
|
55
|
+
if (envMode && (VALID_MODES as readonly string[]).includes(envMode.toLowerCase())) {
|
|
56
|
+
return envMode.toLowerCase() as ValidMode;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const configPath = getConfigPath();
|
|
61
|
+
const config = JSON.parse(readFileSync(configPath, "utf8")) as { defaultMode?: string };
|
|
62
|
+
if (config.defaultMode && (VALID_MODES as readonly string[]).includes(config.defaultMode.toLowerCase())) {
|
|
63
|
+
return config.defaultMode.toLowerCase() as ValidMode;
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
// Config file doesn't exist or is invalid — fall through
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return DEFAULT_MODE;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function writeDefaultMode(mode: unknown): ValidMode | null {
|
|
73
|
+
const normalized = normalizeConfigMode(mode);
|
|
74
|
+
if (!normalized) return null;
|
|
75
|
+
|
|
76
|
+
const configPath = getConfigPath();
|
|
77
|
+
mkdirSync(path.dirname(configPath), { recursive: true });
|
|
78
|
+
writeFileSync(configPath, JSON.stringify({ defaultMode: normalized }, null, 2), "utf8");
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ============== 指令构建 ==============
|
|
83
|
+
|
|
84
|
+
const INDEPENDENT_MODES = new Set<Mode>(["review"]);
|
|
85
|
+
|
|
86
|
+
const FALLBACK_INSTRUCTIONS: Record<RuntimeMode, string> = {
|
|
87
|
+
off: "",
|
|
88
|
+
lite: `PONYTAIL MODE ACTIVE — level: lite
|
|
89
|
+
|
|
90
|
+
You are a lazy senior developer. Lazy means efficient, not careless. The best code is the code never written.
|
|
91
|
+
|
|
92
|
+
## Rules (lite)
|
|
93
|
+
|
|
94
|
+
- Check if the standard library or built-in features can solve this before reaching for external packages
|
|
95
|
+
- Avoid unnecessary abstractions — prefer straightforward code for simple problems
|
|
96
|
+
- Keep functions focused and short when possible, but don't over-simplify complex logic
|
|
97
|
+
- Use existing project patterns and conventions; don't introduce new ones without need
|
|
98
|
+
- Write the minimum code that works correctly — no extra features, no premature optimization
|
|
99
|
+
|
|
100
|
+
## Output
|
|
101
|
+
|
|
102
|
+
Code first. Briefly note any skipped optimizations or abstractions.
|
|
103
|
+
If the explanation is longer than the code, delete the explanation.
|
|
104
|
+
|
|
105
|
+
## When NOT to be lazy
|
|
106
|
+
|
|
107
|
+
Never simplify away: input validation at trust boundaries, error handling that prevents data loss, security measures, accessibility basics, anything the user explicitly asked to keep.`,
|
|
108
|
+
|
|
109
|
+
full: `PONYTAIL MODE ACTIVE — level: full
|
|
110
|
+
|
|
111
|
+
You are a lazy senior developer. Lazy means efficient, not careless. The best code is the code never written.
|
|
112
|
+
|
|
113
|
+
## Persistence
|
|
114
|
+
|
|
115
|
+
ACTIVE EVERY RESPONSE. No drift back to over-building. Still active if unsure. Off only: "stop ponytail" / "normal mode".
|
|
116
|
+
|
|
117
|
+
Current level: **full**. Switch: \`/ponytail lite|full|ultra\`.
|
|
118
|
+
|
|
119
|
+
## The ladder
|
|
120
|
+
|
|
121
|
+
Before any code, stop at the first rung that holds:
|
|
122
|
+
1. Does this need to be built at all? (YAGNI)
|
|
123
|
+
2. Does the standard library do this? Use it.
|
|
124
|
+
3. Does a native platform feature cover it? Use it.
|
|
125
|
+
4. Does an already-installed dependency solve it? Use it.
|
|
126
|
+
5. Can this be one line? Make it one line.
|
|
127
|
+
6. Only then: write the minimum code that works.
|
|
128
|
+
|
|
129
|
+
## Rules
|
|
130
|
+
|
|
131
|
+
No abstractions that were not requested. No avoidable dependencies. No boilerplate nobody asked for. Deletion over addition. Boring over clever. Fewest files possible. Ship the lazy version and question the complex request in the same response — never stall. Between two same-size stdlib options, pick the one correct on edge cases. Mark intentional simplifications with a \`ponytail:\` comment — a shortcut with a known ceiling names the ceiling and the upgrade path in the comment.
|
|
132
|
+
|
|
133
|
+
## Output
|
|
134
|
+
|
|
135
|
+
Code first. Then at most three short lines: what was skipped, when to add it. If the explanation is longer than the code, delete the explanation. Explanation the user explicitly asked for is not debt, give it in full.
|
|
136
|
+
|
|
137
|
+
## When NOT to be lazy
|
|
138
|
+
|
|
139
|
+
Never simplify away: input validation at trust boundaries, error handling that prevents data loss, security measures, accessibility basics, the calibration real hardware needs (the platform is never the spec ideal), anything the user explicitly asked to keep. Lazy code without its check is unfinished: non-trivial logic leaves ONE runnable check behind (assert-based demo/self-check or one small test file; no frameworks). Trivial one-liners need no test.
|
|
140
|
+
|
|
141
|
+
## Boundaries
|
|
142
|
+
|
|
143
|
+
Ponytail governs what you build, not how you talk. "stop ponytail" or "normal mode": revert. Level persists until changed or session end.`,
|
|
144
|
+
|
|
145
|
+
ultra: `PONYTAIL MODE ACTIVE — level: ultra
|
|
146
|
+
|
|
147
|
+
You are a lazy senior developer. Lazy means efficient, not careless. The best code is the code never written.
|
|
148
|
+
|
|
149
|
+
## Persistence
|
|
150
|
+
|
|
151
|
+
ACTIVE EVERY RESPONSE. No drift back to over-building. Still active if unsure. Off only: "stop ponytail" / "normal mode".
|
|
152
|
+
|
|
153
|
+
Current level: **ultra**. Switch: \`/ponytail lite|full|ultra\`.
|
|
154
|
+
|
|
155
|
+
## The ladder
|
|
156
|
+
|
|
157
|
+
Before any code, stop at the first rung that holds:
|
|
158
|
+
1. Does this need to be built at all? (YAGNI) — if the answer is no, say so and stop.
|
|
159
|
+
2. Does the standard library do this? Use it.
|
|
160
|
+
3. Does a native platform feature cover it? Use it.
|
|
161
|
+
4. Does an already-installed dependency solve it? Use it.
|
|
162
|
+
5. Can this be one line? Make it one line.
|
|
163
|
+
6. Only then: write the minimum code that works.
|
|
164
|
+
|
|
165
|
+
## Rules (ultra)
|
|
166
|
+
|
|
167
|
+
- No new files unless absolutely necessary
|
|
168
|
+
- No new dependencies, period — use what's already installed or stdlib
|
|
169
|
+
- No abstractions, no interfaces, no config objects, no factories
|
|
170
|
+
- Modify existing code in place; don't create new modules
|
|
171
|
+
- If the user asks for something complex, build the simplest version that satisfies the core need and note what's deferred
|
|
172
|
+
- "ponytail:" comment for every deliberate simplification, naming the trade-off
|
|
173
|
+
|
|
174
|
+
## Output
|
|
175
|
+
|
|
176
|
+
Code first. Then ONE line max: what was skipped and why. If the explanation is longer than the code, delete the explanation. Explanation the user explicitly asked for is not debt, give it in full.
|
|
177
|
+
|
|
178
|
+
## When NOT to be lazy
|
|
179
|
+
|
|
180
|
+
Never simplify away: input validation at trust boundaries, error handling that prevents data loss, security measures, accessibility basics, the calibration real hardware needs (the platform is never the spec ideal), anything the user explicitly asked to keep. Non-trivial logic leaves ONE runnable check behind. Trivial one-liners need no test.
|
|
181
|
+
|
|
182
|
+
## Boundaries
|
|
183
|
+
|
|
184
|
+
Ponytail governs what you build, not how you talk. "stop ponytail" or "normal mode": revert. Level persists until changed or session end.`,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
function getPonytailInstructions(mode: Mode): string {
|
|
188
|
+
if (INDEPENDENT_MODES.has(mode)) {
|
|
189
|
+
return `PONYTAIL MODE ACTIVE — level: ${mode}. Behavior defined by /ponytail-${mode} skill.`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const effectiveMode = normalizeMode(mode) || DEFAULT_MODE;
|
|
193
|
+
|
|
194
|
+
if (effectiveMode === "off") return "";
|
|
195
|
+
|
|
196
|
+
// Try to load from skills directory first
|
|
197
|
+
const skillPath = path.join(
|
|
198
|
+
process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".pi", "agent"),
|
|
199
|
+
"skills",
|
|
200
|
+
"ponytail",
|
|
201
|
+
"SKILL.md",
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
const body = readFileSync(skillPath, "utf8");
|
|
206
|
+
return filterSkillBodyForMode(body, effectiveMode);
|
|
207
|
+
} catch {
|
|
208
|
+
// Fall back to embedded instructions
|
|
209
|
+
const fallback = FALLBACK_INSTRUCTIONS[effectiveMode as RuntimeMode];
|
|
210
|
+
if (fallback) {
|
|
211
|
+
return fallback;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return FALLBACK_INSTRUCTIONS.full;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function filterSkillBodyForMode(body: string, mode: RuntimeMode): string {
|
|
219
|
+
const withoutFrontmatter = String(body || "").replace(/^---[\s\S]*?---\s*/, "");
|
|
220
|
+
|
|
221
|
+
return withoutFrontmatter
|
|
222
|
+
.split(/\r?\n/)
|
|
223
|
+
.filter((line) => {
|
|
224
|
+
const tableLabel = line.match(/^\|\s*\*\*(.+?)\*\*\s*\|/);
|
|
225
|
+
if (tableLabel) {
|
|
226
|
+
const labelMode = normalizeMode(tableLabel[1].trim());
|
|
227
|
+
if (labelMode) return labelMode === mode;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const exampleLabel = line.match(/^-\s*([^:]+):\s*/);
|
|
231
|
+
if (exampleLabel) {
|
|
232
|
+
const labelMode = normalizeMode(exampleLabel[1].trim());
|
|
233
|
+
if (labelMode) return labelMode === mode;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return true;
|
|
237
|
+
})
|
|
238
|
+
.join("\n");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ============== 命令解析 ==============
|
|
242
|
+
|
|
243
|
+
interface SetModeCommand {
|
|
244
|
+
type: "set-mode";
|
|
245
|
+
mode: Mode;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
interface StatusCommand {
|
|
249
|
+
type: "status";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface SetDefaultCommand {
|
|
253
|
+
type: "set-default";
|
|
254
|
+
mode: ValidMode;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
interface InvalidCommand {
|
|
258
|
+
type: "invalid";
|
|
259
|
+
reason: string;
|
|
260
|
+
mode?: string;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
type ParsedCommand = SetModeCommand | StatusCommand | SetDefaultCommand | InvalidCommand;
|
|
264
|
+
|
|
265
|
+
function parsePonytailCommand(text: string, defaultMode: ValidMode = DEFAULT_MODE): ParsedCommand {
|
|
266
|
+
const fallback = normalizePersistedMode(defaultMode) || DEFAULT_MODE;
|
|
267
|
+
const normalizedText = String(text || "").trim().toLowerCase();
|
|
268
|
+
|
|
269
|
+
if (!normalizedText) {
|
|
270
|
+
return { type: "set-mode", mode: fallback === "off" ? "full" : fallback };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const [primary, secondary] = normalizedText.split(/\s+/);
|
|
274
|
+
|
|
275
|
+
if (primary === "status") return { type: "status" };
|
|
276
|
+
|
|
277
|
+
if (primary === "default") {
|
|
278
|
+
const mode = normalizeConfigMode(secondary);
|
|
279
|
+
return mode ? { type: "set-default", mode } : { type: "invalid", reason: "invalid-default-mode" };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const mode = normalizeMode(primary);
|
|
283
|
+
return mode ? { type: "set-mode", mode } : { type: "invalid", reason: "invalid-mode", mode: primary };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ============== Session 模式恢复 ==============
|
|
287
|
+
|
|
288
|
+
function resolveSessionMode(
|
|
289
|
+
entries: unknown[] | undefined,
|
|
290
|
+
fallbackMode: ValidMode = DEFAULT_MODE,
|
|
291
|
+
): Mode {
|
|
292
|
+
const fallback = normalizePersistedMode(fallbackMode) || DEFAULT_MODE;
|
|
293
|
+
if (!Array.isArray(entries)) return fallback;
|
|
294
|
+
|
|
295
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
296
|
+
const entry = entries[i] as Record<string, unknown> | undefined;
|
|
297
|
+
if (entry?.type !== "custom" || entry?.customType !== CUSTOM_TYPE) continue;
|
|
298
|
+
|
|
299
|
+
const data = entry.data as Record<string, unknown> | undefined;
|
|
300
|
+
const mode = normalizePersistedMode(data?.mode);
|
|
301
|
+
if (mode) return mode;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return fallback;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// ============== 扩展主函数 ==============
|
|
308
|
+
|
|
309
|
+
export default function ponytailExtension(pi: ExtensionAPI) {
|
|
310
|
+
let currentMode: Mode = DEFAULT_MODE;
|
|
311
|
+
let configuredDefaultMode: ValidMode = getDefaultMode();
|
|
312
|
+
|
|
313
|
+
const setMode = (mode: string, ctx?: ExtensionContext): void => {
|
|
314
|
+
const normalized = normalizePersistedMode(mode);
|
|
315
|
+
if (!normalized) return;
|
|
316
|
+
|
|
317
|
+
currentMode = normalized;
|
|
318
|
+
pi.appendEntry(CUSTOM_TYPE, { mode: normalized });
|
|
319
|
+
|
|
320
|
+
if (ctx?.ui) {
|
|
321
|
+
ctx.ui.notify(`Ponytail mode set to ${normalized}.`, "info");
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const sendAlias = (skillName: string, _args: string, ctx?: ExtensionContext): void => {
|
|
326
|
+
if (ctx?.isIdle?.() === false) {
|
|
327
|
+
pi.sendUserMessage(skillName, { deliverAs: "followUp" });
|
|
328
|
+
if (ctx?.ui) {
|
|
329
|
+
ctx.ui.notify(`${skillName} queued as follow-up.`, "info");
|
|
330
|
+
}
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
pi.sendUserMessage(skillName);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const updateStatus = (ctx: ExtensionContext): void => {
|
|
337
|
+
if (!ctx.hasUI) return;
|
|
338
|
+
|
|
339
|
+
if (currentMode === "off") {
|
|
340
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
ctx.ui.setStatus(
|
|
345
|
+
STATUS_KEY,
|
|
346
|
+
ctx.ui.theme.fg("accent", `🎀 ${currentMode.toUpperCase()}`),
|
|
347
|
+
);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// 注册 /ponytail 命令
|
|
351
|
+
pi.registerCommand("ponytail", {
|
|
352
|
+
description: "Set or report Ponytail mode. Usage: /ponytail [lite|full|ultra|off|status|default <mode>]",
|
|
353
|
+
handler: async (args, ctx) => {
|
|
354
|
+
const parsed = parsePonytailCommand(args, configuredDefaultMode);
|
|
355
|
+
|
|
356
|
+
if (parsed.type === "status") {
|
|
357
|
+
ctx.ui.notify(
|
|
358
|
+
`Ponytail: current ${currentMode} • default ${configuredDefaultMode}`,
|
|
359
|
+
"info",
|
|
360
|
+
);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (parsed.type === "set-default") {
|
|
365
|
+
const written = writeDefaultMode(parsed.mode);
|
|
366
|
+
if (written) {
|
|
367
|
+
configuredDefaultMode = getDefaultMode();
|
|
368
|
+
const message =
|
|
369
|
+
configuredDefaultMode === written
|
|
370
|
+
? `Default Ponytail mode set to ${written}.`
|
|
371
|
+
: `Saved default ${written}, but env override keeps default at ${configuredDefaultMode}.`;
|
|
372
|
+
ctx.ui.notify(message, "info");
|
|
373
|
+
}
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (parsed.type === "set-mode") {
|
|
378
|
+
setMode(parsed.mode, ctx);
|
|
379
|
+
updateStatus(ctx);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
ctx.ui.notify("Unknown or unsupported /ponytail mode.", "warning");
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// 注册 skill 别名命令
|
|
388
|
+
pi.registerCommand("ponytail-review", {
|
|
389
|
+
description: "Run /skill:ponytail-review",
|
|
390
|
+
handler: async (_args, ctx) => sendAlias("/skill:ponytail-review", "", ctx),
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
pi.registerCommand("ponytail-audit", {
|
|
394
|
+
description: "Run /skill:ponytail-audit",
|
|
395
|
+
handler: async (_args, ctx) => sendAlias("/skill:ponytail-audit", "", ctx),
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
pi.registerCommand("ponytail-debt", {
|
|
399
|
+
description: "Run /skill:ponytail-debt",
|
|
400
|
+
handler: async (_args, ctx) => sendAlias("/skill:ponytail-debt", "", ctx),
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
pi.registerCommand("ponytail-help", {
|
|
404
|
+
description: "Run /skill:ponytail-help",
|
|
405
|
+
handler: async (_args, ctx) => sendAlias("/skill:ponytail-help", "", ctx),
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// 监听用户输入,检测关闭指令
|
|
409
|
+
pi.on("input", async (event) => {
|
|
410
|
+
if (event?.source === "extension") return;
|
|
411
|
+
|
|
412
|
+
const text = String(event?.text || "");
|
|
413
|
+
if (currentMode !== "off" && /\b(stop ponytail|normal mode)\b/i.test(text)) {
|
|
414
|
+
setMode("off");
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// Session 启动时恢复模式
|
|
419
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
420
|
+
const entries =
|
|
421
|
+
ctx?.sessionManager?.getBranch?.() || ctx?.sessionManager?.getEntries?.() || [];
|
|
422
|
+
configuredDefaultMode = getDefaultMode();
|
|
423
|
+
currentMode = resolveSessionMode(entries, configuredDefaultMode);
|
|
424
|
+
updateStatus(ctx);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// Agent 启动前注入指令
|
|
428
|
+
pi.on("before_agent_start", async (event) => {
|
|
429
|
+
if (!currentMode || currentMode === "off") return;
|
|
430
|
+
const instructions = getPonytailInstructions(currentMode);
|
|
431
|
+
if (!instructions) return;
|
|
432
|
+
return { systemPrompt: `${event.systemPrompt}\n\n${instructions}` };
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Session 关闭时清理状态
|
|
436
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
437
|
+
if (ctx.hasUI) {
|
|
438
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|