@cydm/pie 2.7.20 → 2.8.1
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 +18 -0
- package/dist/builtin/extensions/ask-user/README.md +117 -0
- package/dist/builtin/extensions/ask-user/index.js +4 -3
- package/dist/builtin/extensions/cron/index.js +299 -39
- package/dist/builtin/extensions/im-forward/README.md +297 -0
- package/dist/builtin/extensions/im-forward/index.js +315 -27
- package/dist/builtin/extensions/mcp-adapter/README.md +27 -0
- package/dist/builtin/extensions/memory/index.js +515 -0
- package/dist/builtin/extensions/memory/package.json +19 -0
- package/dist/builtin/extensions/pie-ipc/README.md +21 -0
- package/dist/builtin/extensions/plan-mode/METHOD.md +70 -0
- package/dist/builtin/extensions/plan-mode/index.js +150 -82
- package/dist/builtin/extensions/subagent/README.md +315 -0
- package/dist/builtin/extensions/subagent/index.js +8 -5
- package/dist/builtin/extensions/todo/index.js +4 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{chunk-U75F4DPF.js → chunk-BNSAEVRT.js} +201 -77
- package/dist/builtin/skills/chrome-devtools-axi/{cli-4ITIR57L.js → cli-AO2ZTPRM.js} +57 -202
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +6 -1
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +6 -1
- package/dist/chunks/auth-storage-3EGM3VTK.js +13 -0
- package/dist/chunks/{chunk-X7UO6BA6.js → chunk-3BC5KGDQ.js} +451 -162
- package/dist/chunks/chunk-3NHP7HK5.js +298 -0
- package/dist/chunks/chunk-6DNYGVZP.js +278 -0
- package/dist/chunks/{chunk-TGCI5M6R.js → chunk-GDIYSMTS.js} +22 -142
- package/dist/chunks/{chunk-2H2DD22Z.js → chunk-GH4VW2OT.js} +1 -1
- package/dist/chunks/chunk-ILUHTKF3.js +149 -0
- package/dist/chunks/{chunk-UDCGB3LZ.js → chunk-PK72LVWQ.js} +11841 -16501
- package/dist/chunks/chunk-RSL7E4R7.js +9634 -0
- package/dist/chunks/chunk-YRR6C43W.js +1740 -0
- package/dist/chunks/config-74AUVDLT.js +46 -0
- package/dist/chunks/model-registry-LI5THXV4.js +17 -0
- package/dist/chunks/src-66XSMIAM.js +134 -0
- package/dist/chunks/src-BPSQMSSC.js +431 -0
- package/dist/chunks/src-OPPYTPWG.js +285 -0
- package/dist/chunks/{src-GX4UBAYF.js → src-YG5M2H44.js} +2 -2
- package/dist/chunks/{test-stream-AKIZNFCM.js → test-stream-JBWXKOQA.js} +1 -1
- package/dist/cli.js +986 -2292
- package/package.json +3 -3
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
buildExecutionReminder,
|
|
4
|
+
checkPlanScope,
|
|
4
5
|
createExecutionStateFromPlan,
|
|
5
6
|
createPlanCapability,
|
|
6
|
-
extractPlanTodoItems,
|
|
7
7
|
markCompletedPlanSteps,
|
|
8
8
|
restoreExecutionState
|
|
9
|
-
} from "../../../chunks/chunk-
|
|
10
|
-
import "../../../chunks/chunk-
|
|
11
|
-
import "../../../chunks/chunk-
|
|
9
|
+
} from "../../../chunks/chunk-PK72LVWQ.js";
|
|
10
|
+
import "../../../chunks/chunk-RSL7E4R7.js";
|
|
11
|
+
import "../../../chunks/chunk-GH4VW2OT.js";
|
|
12
|
+
import "../../../chunks/chunk-3BC5KGDQ.js";
|
|
12
13
|
import {
|
|
13
14
|
Type
|
|
14
15
|
} from "../../../chunks/chunk-XXGYUYXI.js";
|
|
@@ -27,11 +28,15 @@ var SCRATCH_NAME = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
|
|
27
28
|
var MAX_SCRATCH_CHARS = 64e3;
|
|
28
29
|
var MAX_PLAN_STEPS = 50;
|
|
29
30
|
var MAX_PLAN_ITEM_CHARS = 500;
|
|
31
|
+
var MAX_STEP_FILES = 40;
|
|
32
|
+
var NEW_FILE_MARKER = /\((?:new|新建)\)\s*$/i;
|
|
30
33
|
function toPlanTodoItems(state) {
|
|
31
34
|
return state.steps.map((step) => ({
|
|
32
35
|
step: step.id,
|
|
33
36
|
text: step.title,
|
|
34
37
|
detail: step.description || void 0,
|
|
38
|
+
verify: step.verify,
|
|
39
|
+
files: step.files,
|
|
35
40
|
completed: step.status === "completed"
|
|
36
41
|
}));
|
|
37
42
|
}
|
|
@@ -39,8 +44,7 @@ function planModeExtension(ctx) {
|
|
|
39
44
|
const capability = createPlanCapability();
|
|
40
45
|
let planModeEnabled = false;
|
|
41
46
|
let executingPlan = false;
|
|
42
|
-
let
|
|
43
|
-
let lastOfferedPlanKey = "";
|
|
47
|
+
let revisionPrefix = null;
|
|
44
48
|
function setExecutingPlan(value) {
|
|
45
49
|
executingPlan = value;
|
|
46
50
|
ctx.setSessionMetadata(EXECUTION_FLAG_KEY, value);
|
|
@@ -118,8 +122,13 @@ function planModeExtension(ctx) {
|
|
|
118
122
|
return next;
|
|
119
123
|
}
|
|
120
124
|
function formatPlanText(items) {
|
|
121
|
-
return items.map((item, index) =>
|
|
122
|
-
|
|
125
|
+
return items.map((item, index) => {
|
|
126
|
+
const lines = [`${index + 1}. ${item.text}`];
|
|
127
|
+
if (item.detail) lines.push(` ${item.detail}`);
|
|
128
|
+
if (item.verify) lines.push(` verify: ${item.verify}`);
|
|
129
|
+
if (item.files?.length) lines.push(` files: ${item.files.join(", ")}`);
|
|
130
|
+
return lines.join("\n");
|
|
131
|
+
}).join("\n");
|
|
123
132
|
}
|
|
124
133
|
async function planSelect(prompt, options, leftShortcut) {
|
|
125
134
|
const response = await ctx.interactions.request({
|
|
@@ -145,29 +154,60 @@ function planModeExtension(ctx) {
|
|
|
145
154
|
});
|
|
146
155
|
return response.type === "multiline_input" ? response.value : void 0;
|
|
147
156
|
}
|
|
148
|
-
function renderPlanMarkdown(goal, items) {
|
|
149
|
-
const
|
|
157
|
+
function renderPlanMarkdown(goal, items, warnings) {
|
|
158
|
+
const scopeUnion = /* @__PURE__ */ new Set();
|
|
159
|
+
for (const item of items) for (const file of item.files ?? []) scopeUnion.add(file.replace(NEW_FILE_MARKER, "").trim());
|
|
160
|
+
scopeUnion.delete("");
|
|
161
|
+
const heading = goal ? `## \u{1F4CB} ${goal}` : "## \u{1F4CB} Plan";
|
|
162
|
+
const summary = `**${items.length} steps** \xB7 ${scopeUnion.size > 0 ? `${scopeUnion.size} files in scope` : "scope: declared per step"}`;
|
|
150
163
|
const steps = items.map((item, index) => {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
const lines = [`**${index + 1}. ${item.text}**`];
|
|
165
|
+
if (item.detail) lines.push(` ${item.detail}`);
|
|
166
|
+
if (item.verify) lines.push(`- \u2705 verify: \`${item.verify}\``);
|
|
167
|
+
if (item.files?.length) lines.push(`- \u{1F4C1} \`${item.files.join("`, `")}\``);
|
|
168
|
+
return lines.join("\n");
|
|
169
|
+
}).join("\n\n");
|
|
170
|
+
const warningLines = warnings.length > 0 ? `
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
\u26A0\uFE0F **Scope check** (informational, submission proceeds):
|
|
175
|
+
${warnings.map((warning) => `- \`${warning.path}\` ${warning.kind === "missing" ? "does not exist \u2014 typo, or understanding gap?" : "already exists but was declared new"}`).join("\n")}` : "";
|
|
155
176
|
return `${heading}
|
|
156
177
|
|
|
157
|
-
${
|
|
178
|
+
${summary}
|
|
179
|
+
|
|
180
|
+
${steps}${warningLines}`;
|
|
181
|
+
}
|
|
182
|
+
async function pathExists(target) {
|
|
183
|
+
try {
|
|
184
|
+
await fs.stat(path.resolve(ctx.cwd, target));
|
|
185
|
+
return true;
|
|
186
|
+
} catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
158
189
|
}
|
|
159
190
|
function startPlanExecution(items) {
|
|
160
191
|
planModeEnabled = false;
|
|
161
192
|
ctx.setSessionMetadata(SESSION_METADATA_KEY, false);
|
|
162
193
|
ctx.setPlanMode(false);
|
|
163
|
-
|
|
164
|
-
|
|
194
|
+
const merged = revisionPrefix ? [...revisionPrefix, ...items.map((item, index) => ({ ...item, step: revisionPrefix.length + index + 1 }))] : items;
|
|
195
|
+
revisionPrefix = null;
|
|
196
|
+
setExecutingPlan(merged.length > 0);
|
|
197
|
+
writeExecutionState(createExecutionStateFromPlan(merged));
|
|
165
198
|
updateStatus();
|
|
166
|
-
|
|
199
|
+
const steps = merged.map((item, index) => {
|
|
200
|
+
const lines = [`${index + 1}. ${item.text}`];
|
|
201
|
+
if (item.detail) lines.push(` ${item.detail}`);
|
|
202
|
+
if (item.verify) lines.push(` verify: ${item.verify} \u2014 the step is only DONE when this holds; report [VERIFIED:n] next to [DONE:n]`);
|
|
203
|
+
if (item.files?.length) lines.push(` files: ${item.files.join(", ")}`);
|
|
204
|
+
return lines.join("\n");
|
|
205
|
+
}).join("\n");
|
|
206
|
+
return `Execute the approved plan (one step at a time, in order):
|
|
167
207
|
|
|
168
|
-
${
|
|
208
|
+
${steps}
|
|
169
209
|
|
|
170
|
-
|
|
210
|
+
Rules: execute one step, verify it (run its verify criterion when practical), then mark progress with [DONE:n]${merged.some((item) => item.verify) ? " plus [VERIFIED:n] for steps with a verify criterion" : ""}. A step whose verify criterion fails is NOT done \u2014 stop, report the failure, and wait for Retry / Revise / Abort. Do not skip steps.`;
|
|
171
211
|
}
|
|
172
212
|
function updateStatus() {
|
|
173
213
|
const state = readExecutionState();
|
|
@@ -175,7 +215,7 @@ Execute the steps in order, starting with step 1. After completing a step, inclu
|
|
|
175
215
|
const completed = state.steps.filter((step) => step.status === "completed").length;
|
|
176
216
|
ctx.ui.notify(`\u{1F4CB} Plan: ${completed}/${state.steps.length} completed`, "info");
|
|
177
217
|
} else if (planModeEnabled) {
|
|
178
|
-
ctx.ui.notify("\u23F8\uFE0F Plan mode
|
|
218
|
+
ctx.ui.notify("\u23F8\uFE0F Plan mode \u2014 discussing (no plan output until you ask for one)", "info");
|
|
179
219
|
}
|
|
180
220
|
}
|
|
181
221
|
function applyPlanModeState(enabled, forcePromptInjection = false) {
|
|
@@ -189,25 +229,26 @@ Execute the steps in order, starting with step 1. After completing a step, inclu
|
|
|
189
229
|
planModeEnabled = !planModeEnabled;
|
|
190
230
|
setExecutingPlan(false);
|
|
191
231
|
writeExecutionState(null);
|
|
232
|
+
revisionPrefix = null;
|
|
192
233
|
ctx.setSessionMetadata(SESSION_METADATA_KEY, planModeEnabled);
|
|
193
|
-
approvalOfferedThisTurn = false;
|
|
194
|
-
lastOfferedPlanKey = "";
|
|
195
234
|
applyPlanModeState(planModeEnabled, true);
|
|
196
235
|
ctx.ui.notify(
|
|
197
|
-
planModeEnabled ? `Plan mode enabled
|
|
236
|
+
planModeEnabled ? `Plan mode enabled \u2014 discussion first (grilling); say "\u8F93\u51FA\u8BA1\u5212"/"give me the plan" or /tools/plan/submit when you want the plan itself.` : "Plan mode disabled. Full access restored."
|
|
198
237
|
);
|
|
199
238
|
updateStatus();
|
|
200
239
|
}
|
|
201
240
|
ctx.registerTool({
|
|
202
241
|
name: "plan_submit",
|
|
203
242
|
label: "plan_submit",
|
|
204
|
-
description:
|
|
243
|
+
description: 'Submit the finished plan for user approval. DISCUSSION-FIRST: in Plan mode the default is grilling discussion (rounds of numbered questions with recommended answers), NOT plan output. Call plan_submit only after the user explicitly asks for the plan ("\u8F93\u51FA\u8BA1\u5212", "give me the plan", "/tools/plan/submit"). Steps are MVPs: each independently verifiable with a verify criterion and an explicit file scope.',
|
|
205
244
|
parameters: Type.Object({
|
|
206
245
|
goal: Type.Optional(Type.String({ description: "One-line summary of what the plan accomplishes" })),
|
|
207
246
|
steps: Type.Array(
|
|
208
247
|
Type.Object({
|
|
209
|
-
title: Type.String({ description: "Short imperative step title", maxLength: MAX_PLAN_ITEM_CHARS }),
|
|
210
|
-
detail: Type.Optional(Type.String({ description: "Constraints, risks, or verification notes for this step", maxLength: 2e3 }))
|
|
248
|
+
title: Type.String({ description: "Short imperative step title (one MVP)", maxLength: MAX_PLAN_ITEM_CHARS }),
|
|
249
|
+
detail: Type.Optional(Type.String({ description: "Constraints, risks, or verification notes for this step", maxLength: 2e3 })),
|
|
250
|
+
verify: Type.Optional(Type.String({ description: "How to verify this step passed \u2014 ideally one command or test name", maxLength: 500 })),
|
|
251
|
+
files: Type.Optional(Type.Array(Type.String({ maxLength: 500 }), { maxItems: MAX_STEP_FILES, description: 'Paths this step intends to touch; append "(new)" to a path that will be created' }))
|
|
211
252
|
}),
|
|
212
253
|
{ minItems: 1, maxItems: MAX_PLAN_STEPS }
|
|
213
254
|
)
|
|
@@ -216,31 +257,38 @@ Execute the steps in order, starting with step 1. After completing a step, inclu
|
|
|
216
257
|
async execute(args) {
|
|
217
258
|
const reply = (text, isError = false) => ({ content: [{ type: "text", text }], isError });
|
|
218
259
|
if (!planModeEnabled) {
|
|
219
|
-
return reply("plan_submit is only available in Plan mode.
|
|
260
|
+
return reply("plan_submit is only available in Plan mode. If a plan is executing and you want to change it, use /tools/plan/revise; otherwise enter Plan mode with /tools/plan first, or present the plan as text if you are not planning.", true);
|
|
220
261
|
}
|
|
221
262
|
const items = [];
|
|
222
263
|
for (const step of (args.steps ?? []).slice(0, MAX_PLAN_STEPS)) {
|
|
223
264
|
const title = String(step?.title ?? "").trim().slice(0, MAX_PLAN_ITEM_CHARS);
|
|
224
265
|
if (!title) continue;
|
|
225
266
|
const detail = typeof step?.detail === "string" && step.detail.trim() ? step.detail.trim().slice(0, 2e3) : void 0;
|
|
226
|
-
|
|
267
|
+
const verify = typeof step?.verify === "string" && step.verify.trim() ? step.verify.trim().slice(0, 500) : void 0;
|
|
268
|
+
const files = Array.isArray(step?.files) ? step.files.map((file) => String(file ?? "").trim().slice(0, 500)).filter(Boolean).slice(0, MAX_STEP_FILES) : void 0;
|
|
269
|
+
items.push({ step: items.length + 1, text: title, detail, verify, files: files?.length ? files : void 0, completed: false });
|
|
227
270
|
}
|
|
228
271
|
if (items.length === 0) {
|
|
229
272
|
return reply("plan_submit requires at least one step with a non-empty title.", true);
|
|
230
273
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const rendered = items.map((item) => `${item.step}. \u2610 ${item.text}${item.detail ? `
|
|
234
|
-
${item.detail}` : ""}`).join("\n");
|
|
274
|
+
const warnings = await checkPlanScopeAsync(items);
|
|
275
|
+
const goal = typeof args.goal === "string" && args.goal.trim() ? args.goal.trim() : void 0;
|
|
235
276
|
if (!ctx.interactions.isAvailable()) {
|
|
236
|
-
|
|
277
|
+
const rendered = items.map((item) => `${item.step}. ${item.text}${item.detail ? `
|
|
278
|
+
${item.detail}` : ""}${item.verify ? `
|
|
279
|
+
verify: ${item.verify}` : ""}${item.files?.length ? `
|
|
280
|
+
files: ${item.files.join(", ")}` : ""}`).join("\n");
|
|
281
|
+
const warningText = warnings.length > 0 ? `
|
|
237
282
|
|
|
238
|
-
|
|
283
|
+
Scope warnings:
|
|
284
|
+
${warnings.map((warning) => `- ${warning.path} ${warning.kind === "missing" ? "does not exist \u2014 typo, or understanding gap?" : "already exists but was declared new"}`).join("\n")}` : "";
|
|
285
|
+
return reply(`Plan submitted (${items.length} steps)${goal ? ` \u2014 ${goal}` : ""} in headless mode; interactive approval is unavailable, so nothing will be executed:
|
|
286
|
+
|
|
287
|
+
${rendered}${warningText}`);
|
|
239
288
|
}
|
|
240
|
-
|
|
241
|
-
planNotify(renderPlanMarkdown(goal, items));
|
|
289
|
+
planNotify(renderPlanMarkdown(goal, items, warnings), warnings.length > 0 ? "warning" : "info");
|
|
242
290
|
const yoloOption = typeof ctx.setYoloMode === "function" && !ctx.yoloMode ? ["Execute in YOLO mode (auto-approve everything)"] : [];
|
|
243
|
-
const choice = await planSelect(`\u{1F4CB} Plan (${items.length} steps) \u2014 what next?`, [
|
|
291
|
+
const choice = await planSelect(`\u{1F4CB} Plan (${items.length} steps)${warnings.length > 0 ? ` \u2014 ${warnings.length} scope warning(s)` : ""} \u2014 what next?`, [
|
|
244
292
|
"Execute the plan (track progress)",
|
|
245
293
|
...yoloOption,
|
|
246
294
|
"Stay in plan mode",
|
|
@@ -267,13 +315,74 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
267
315
|
return reply("The user chose to stay in Plan mode. Do not execute anything; wait for guidance or refine the plan when asked.");
|
|
268
316
|
}
|
|
269
317
|
});
|
|
318
|
+
async function checkPlanScopeAsync(items) {
|
|
319
|
+
const declaredNew = /* @__PURE__ */ new Set();
|
|
320
|
+
const normalized = items.map((item) => ({
|
|
321
|
+
...item,
|
|
322
|
+
files: (item.files ?? []).map((file) => {
|
|
323
|
+
const bare = file.replace(NEW_FILE_MARKER, "").trim();
|
|
324
|
+
if (bare && NEW_FILE_MARKER.test(file)) declaredNew.add(bare);
|
|
325
|
+
return bare;
|
|
326
|
+
}).filter(Boolean)
|
|
327
|
+
}));
|
|
328
|
+
if (normalized.every((item) => item.files.length === 0)) return [];
|
|
329
|
+
const existsCache = /* @__PURE__ */ new Map();
|
|
330
|
+
for (const target of new Set(normalized.flatMap((item) => item.files))) {
|
|
331
|
+
existsCache.set(target, await pathExists(target));
|
|
332
|
+
}
|
|
333
|
+
return checkPlanScope(
|
|
334
|
+
normalized,
|
|
335
|
+
(target) => existsCache.get(target) === true,
|
|
336
|
+
(_item, target) => declaredNew.has(target)
|
|
337
|
+
);
|
|
338
|
+
}
|
|
270
339
|
ctx.registerCommand({
|
|
271
340
|
path: capability.commands?.[0]?.path ?? ["tools", "plan"],
|
|
272
|
-
description:
|
|
341
|
+
description: "Toggle plan mode (read-only exploration, discussion-first)",
|
|
273
342
|
handler: async () => {
|
|
274
343
|
togglePlanMode();
|
|
275
344
|
}
|
|
276
345
|
});
|
|
346
|
+
ctx.registerCommand({
|
|
347
|
+
path: ["tools", "plan", "submit"],
|
|
348
|
+
description: "Ask for the plan now (optional free-text context)",
|
|
349
|
+
handler: async (_commandCtx, args) => {
|
|
350
|
+
if (!planModeEnabled) {
|
|
351
|
+
ctx.ui.notify("Enter Plan mode first (/tools/plan), then ask for the plan again.", "info");
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const context = (args ?? "").trim();
|
|
355
|
+
return context ? `\u8F93\u51FA\u8BA1\u5212\u3002Additional context from the user: ${context}
|
|
356
|
+
|
|
357
|
+
Produce the MVP-ladder plan now (each step: title, optional detail, verify criterion, file scope) and call plan_submit with it.` : "\u8F93\u51FA\u8BA1\u5212\u3002Produce the MVP-ladder plan now (each step: title, optional detail, verify criterion, file scope) and call plan_submit with it.";
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
ctx.registerCommand({
|
|
361
|
+
path: ["tools", "plan", "revise"],
|
|
362
|
+
description: "Revise the remaining plan (during or after execution)",
|
|
363
|
+
handler: async () => {
|
|
364
|
+
const state = readExecutionState();
|
|
365
|
+
if (state.steps.length === 0 && !revisionPrefix) {
|
|
366
|
+
ctx.ui.notify("No plan is executing. Enable Plan mode (/tools/plan), discuss, then ask for the plan (/tools/plan/submit).", "info");
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const completedItems = toPlanTodoItems(state).filter((item) => item.completed);
|
|
370
|
+
const remainingItems = toPlanTodoItems(state).filter((item) => !item.completed);
|
|
371
|
+
revisionPrefix = revisionPrefix ?? completedItems;
|
|
372
|
+
setExecutingPlan(false);
|
|
373
|
+
ctx.setSessionMetadata(SESSION_METADATA_KEY, true);
|
|
374
|
+
applyPlanModeState(true, true);
|
|
375
|
+
updateStatus();
|
|
376
|
+
const completedLines = revisionPrefix.length > 0 ? revisionPrefix.map((item) => `- \u2713 ${item.text}`).join("\n") : "- (none yet)";
|
|
377
|
+
return `Revise the remaining plan. Completed so far (do not redo these; they carry over into the revised ladder automatically):
|
|
378
|
+
${completedLines}
|
|
379
|
+
|
|
380
|
+
Remaining steps as previously approved:
|
|
381
|
+
${remainingItems.map((item) => `- ${item.text}${item.detail ? ` \u2014 ${item.detail}` : ""}${item.verify ? ` (verify: ${item.verify})` : ""}${item.files?.length ? ` [files: ${item.files.join(", ")}]` : ""}`).join("\n") || "- (none)"}
|
|
382
|
+
|
|
383
|
+
Discuss the revision with the user (read-only; Plan mode is back on). When the user asks for the revised plan (e.g. \u8F93\u51FA\u8BA1\u5212 / /tools/plan/submit), call plan_submit with the REVISED REMAINING steps only.`;
|
|
384
|
+
}
|
|
385
|
+
});
|
|
277
386
|
ctx.registerShortcut("ctrl+alt+p", {
|
|
278
387
|
description: "Toggle plan mode",
|
|
279
388
|
handler: async () => {
|
|
@@ -284,16 +393,12 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
284
393
|
const persisted = readPersistedPlanMode();
|
|
285
394
|
applyPlanModeState(persisted);
|
|
286
395
|
executingPlan = !persisted && readPersistedExecuting();
|
|
287
|
-
approvalOfferedThisTurn = false;
|
|
288
|
-
if (!persisted) lastOfferedPlanKey = "";
|
|
289
396
|
writeExecutionState(readExecutionState());
|
|
290
397
|
});
|
|
291
398
|
ctx.on("session:changed", async () => {
|
|
292
399
|
const enabled = readPersistedPlanMode();
|
|
293
400
|
applyPlanModeState(enabled, enabled);
|
|
294
401
|
executingPlan = !enabled && readPersistedExecuting();
|
|
295
|
-
approvalOfferedThisTurn = false;
|
|
296
|
-
lastOfferedPlanKey = "";
|
|
297
402
|
writeExecutionState(readExecutionState());
|
|
298
403
|
});
|
|
299
404
|
ctx.on("turn:end", async (event) => {
|
|
@@ -312,8 +417,7 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
312
417
|
const state = readExecutionState();
|
|
313
418
|
if (executingPlan && state.steps.length > 0) {
|
|
314
419
|
if (state.steps.every((step) => step.status === "completed")) {
|
|
315
|
-
const completedList = state.steps.map((step) => `${step.id}. \u2713 ${step.title}${step.
|
|
316
|
-
- \u21B3 ${step.description}` : ""}`).join("\n");
|
|
420
|
+
const completedList = state.steps.map((step) => `${step.id}. \u2713 ${step.title}${step.verify ? ` \u2014 verified: ${step.verify}` : ""}`).join("\n");
|
|
317
421
|
ctx.ui.notify(`## \u2705 Plan complete
|
|
318
422
|
|
|
319
423
|
${completedList}`, "info", { markdown: true });
|
|
@@ -322,43 +426,7 @@ ${completedList}`, "info", { markdown: true });
|
|
|
322
426
|
}
|
|
323
427
|
return;
|
|
324
428
|
}
|
|
325
|
-
|
|
326
|
-
if (!ctx.interactions.isAvailable()) return;
|
|
327
|
-
if (approvalOfferedThisTurn) return;
|
|
328
|
-
const messages = event.messages || [];
|
|
329
|
-
const lastAssistant = [...messages].reverse().find(
|
|
330
|
-
(message) => message.role === "assistant" && Array.isArray(message.content)
|
|
331
|
-
);
|
|
332
|
-
if (!lastAssistant) return;
|
|
333
|
-
const content = lastAssistant.content;
|
|
334
|
-
if (!Array.isArray(content)) return;
|
|
335
|
-
const text = content.filter((item) => item.type === "text").map((item) => item.text).join("\n");
|
|
336
|
-
const extracted = extractPlanTodoItems(text);
|
|
337
|
-
if (extracted.length === 0) return;
|
|
338
|
-
const planKey = JSON.stringify(extracted);
|
|
339
|
-
if (planKey === lastOfferedPlanKey) return;
|
|
340
|
-
lastOfferedPlanKey = planKey;
|
|
341
|
-
approvalOfferedThisTurn = true;
|
|
342
|
-
const todoListText = extracted.map((item, index) => `${index + 1}. \u2610 ${item.text}${item.detail ? `
|
|
343
|
-
- \u21B3 ${item.detail}` : ""}`).join("\n");
|
|
344
|
-
planNotify(`## \u{1F4CB} Plan \u2014 ${extracted.length} steps
|
|
345
|
-
|
|
346
|
-
${todoListText}`);
|
|
347
|
-
const choice = await planSelect(`\u{1F4CB} Plan (${extracted.length} steps) \u2014 what next?`, [
|
|
348
|
-
"Execute the plan (track progress)",
|
|
349
|
-
"Stay in plan mode",
|
|
350
|
-
"Refine the plan"
|
|
351
|
-
]);
|
|
352
|
-
if (choice?.startsWith("Execute")) {
|
|
353
|
-
ctx.sendUserMessage(startPlanExecution(extracted));
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
if (choice === "Refine the plan") {
|
|
357
|
-
const refinement = await planRefine(extracted);
|
|
358
|
-
if (refinement?.trim()) {
|
|
359
|
-
ctx.sendUserMessage(refinement.trim());
|
|
360
|
-
}
|
|
361
|
-
}
|
|
429
|
+
void event;
|
|
362
430
|
});
|
|
363
431
|
ctx.log("Plan mode extension loaded");
|
|
364
432
|
}
|