@cydm/pie 2.7.19 → 2.8.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/README.md +6 -6
- package/dist/builtin/extensions/ask-user/README.md +117 -0
- package/dist/builtin/extensions/ask-user/index.js +3 -3
- package/dist/builtin/extensions/cron/index.js +166 -23
- package/dist/builtin/extensions/im-forward/README.md +297 -0
- package/dist/builtin/extensions/im-forward/index.js +319 -42
- package/dist/builtin/extensions/init/index.js +0 -6
- package/dist/builtin/extensions/mcp-adapter/README.md +27 -0
- package/dist/builtin/extensions/memory/index.js +323 -0
- package/dist/builtin/extensions/memory/package.json +18 -0
- package/dist/builtin/extensions/pie-ipc/README.md +21 -0
- package/dist/builtin/extensions/pie-ipc/index.js +16 -16
- package/dist/builtin/extensions/plan-mode/METHOD.md +70 -0
- package/dist/builtin/extensions/plan-mode/index.js +149 -82
- package/dist/builtin/extensions/subagent/README.md +315 -0
- package/dist/builtin/extensions/subagent/index.js +7 -5
- package/dist/builtin/extensions/todo/index.js +3 -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/chunks/chunk-5353DEEC.js +130 -0
- package/dist/chunks/{chunk-2H2DD22Z.js → chunk-HGC25NYB.js} +1 -1
- package/dist/chunks/{chunk-X7UO6BA6.js → chunk-JNOFHHLZ.js} +156 -65
- package/dist/chunks/{chunk-UDCGB3LZ.js → chunk-LJXHECZ7.js} +12183 -10951
- package/dist/chunks/{chunk-TGCI5M6R.js → chunk-NEES4EBX.js} +19 -141
- package/dist/chunks/{src-GX4UBAYF.js → src-5XOKRS6F.js} +2 -2
- package/dist/chunks/{test-stream-AKIZNFCM.js → test-stream-5SDHKKDB.js} +1 -1
- package/dist/cli.js +127 -96
- package/package.json +2 -2
|
@@ -1,14 +1,14 @@
|
|
|
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-LJXHECZ7.js";
|
|
10
|
+
import "../../../chunks/chunk-HGC25NYB.js";
|
|
11
|
+
import "../../../chunks/chunk-JNOFHHLZ.js";
|
|
12
12
|
import {
|
|
13
13
|
Type
|
|
14
14
|
} from "../../../chunks/chunk-XXGYUYXI.js";
|
|
@@ -27,11 +27,15 @@ var SCRATCH_NAME = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
|
|
27
27
|
var MAX_SCRATCH_CHARS = 64e3;
|
|
28
28
|
var MAX_PLAN_STEPS = 50;
|
|
29
29
|
var MAX_PLAN_ITEM_CHARS = 500;
|
|
30
|
+
var MAX_STEP_FILES = 40;
|
|
31
|
+
var NEW_FILE_MARKER = /\((?:new|新建)\)\s*$/i;
|
|
30
32
|
function toPlanTodoItems(state) {
|
|
31
33
|
return state.steps.map((step) => ({
|
|
32
34
|
step: step.id,
|
|
33
35
|
text: step.title,
|
|
34
36
|
detail: step.description || void 0,
|
|
37
|
+
verify: step.verify,
|
|
38
|
+
files: step.files,
|
|
35
39
|
completed: step.status === "completed"
|
|
36
40
|
}));
|
|
37
41
|
}
|
|
@@ -39,8 +43,7 @@ function planModeExtension(ctx) {
|
|
|
39
43
|
const capability = createPlanCapability();
|
|
40
44
|
let planModeEnabled = false;
|
|
41
45
|
let executingPlan = false;
|
|
42
|
-
let
|
|
43
|
-
let lastOfferedPlanKey = "";
|
|
46
|
+
let revisionPrefix = null;
|
|
44
47
|
function setExecutingPlan(value) {
|
|
45
48
|
executingPlan = value;
|
|
46
49
|
ctx.setSessionMetadata(EXECUTION_FLAG_KEY, value);
|
|
@@ -118,8 +121,13 @@ function planModeExtension(ctx) {
|
|
|
118
121
|
return next;
|
|
119
122
|
}
|
|
120
123
|
function formatPlanText(items) {
|
|
121
|
-
return items.map((item, index) =>
|
|
122
|
-
|
|
124
|
+
return items.map((item, index) => {
|
|
125
|
+
const lines = [`${index + 1}. ${item.text}`];
|
|
126
|
+
if (item.detail) lines.push(` ${item.detail}`);
|
|
127
|
+
if (item.verify) lines.push(` verify: ${item.verify}`);
|
|
128
|
+
if (item.files?.length) lines.push(` files: ${item.files.join(", ")}`);
|
|
129
|
+
return lines.join("\n");
|
|
130
|
+
}).join("\n");
|
|
123
131
|
}
|
|
124
132
|
async function planSelect(prompt, options, leftShortcut) {
|
|
125
133
|
const response = await ctx.interactions.request({
|
|
@@ -145,29 +153,60 @@ function planModeExtension(ctx) {
|
|
|
145
153
|
});
|
|
146
154
|
return response.type === "multiline_input" ? response.value : void 0;
|
|
147
155
|
}
|
|
148
|
-
function renderPlanMarkdown(goal, items) {
|
|
149
|
-
const
|
|
156
|
+
function renderPlanMarkdown(goal, items, warnings) {
|
|
157
|
+
const scopeUnion = /* @__PURE__ */ new Set();
|
|
158
|
+
for (const item of items) for (const file of item.files ?? []) scopeUnion.add(file.replace(NEW_FILE_MARKER, "").trim());
|
|
159
|
+
scopeUnion.delete("");
|
|
160
|
+
const heading = goal ? `## \u{1F4CB} ${goal}` : "## \u{1F4CB} Plan";
|
|
161
|
+
const summary = `**${items.length} steps** \xB7 ${scopeUnion.size > 0 ? `${scopeUnion.size} files in scope` : "scope: declared per step"}`;
|
|
150
162
|
const steps = items.map((item, index) => {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
const lines = [`**${index + 1}. ${item.text}**`];
|
|
164
|
+
if (item.detail) lines.push(` ${item.detail}`);
|
|
165
|
+
if (item.verify) lines.push(`- \u2705 verify: \`${item.verify}\``);
|
|
166
|
+
if (item.files?.length) lines.push(`- \u{1F4C1} \`${item.files.join("`, `")}\``);
|
|
167
|
+
return lines.join("\n");
|
|
168
|
+
}).join("\n\n");
|
|
169
|
+
const warningLines = warnings.length > 0 ? `
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
\u26A0\uFE0F **Scope check** (informational, submission proceeds):
|
|
174
|
+
${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
175
|
return `${heading}
|
|
156
176
|
|
|
157
|
-
${
|
|
177
|
+
${summary}
|
|
178
|
+
|
|
179
|
+
${steps}${warningLines}`;
|
|
180
|
+
}
|
|
181
|
+
async function pathExists(target) {
|
|
182
|
+
try {
|
|
183
|
+
await fs.stat(path.resolve(ctx.cwd, target));
|
|
184
|
+
return true;
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
158
188
|
}
|
|
159
189
|
function startPlanExecution(items) {
|
|
160
190
|
planModeEnabled = false;
|
|
161
191
|
ctx.setSessionMetadata(SESSION_METADATA_KEY, false);
|
|
162
192
|
ctx.setPlanMode(false);
|
|
163
|
-
|
|
164
|
-
|
|
193
|
+
const merged = revisionPrefix ? [...revisionPrefix, ...items.map((item, index) => ({ ...item, step: revisionPrefix.length + index + 1 }))] : items;
|
|
194
|
+
revisionPrefix = null;
|
|
195
|
+
setExecutingPlan(merged.length > 0);
|
|
196
|
+
writeExecutionState(createExecutionStateFromPlan(merged));
|
|
165
197
|
updateStatus();
|
|
166
|
-
|
|
198
|
+
const steps = merged.map((item, index) => {
|
|
199
|
+
const lines = [`${index + 1}. ${item.text}`];
|
|
200
|
+
if (item.detail) lines.push(` ${item.detail}`);
|
|
201
|
+
if (item.verify) lines.push(` verify: ${item.verify} \u2014 the step is only DONE when this holds; report [VERIFIED:n] next to [DONE:n]`);
|
|
202
|
+
if (item.files?.length) lines.push(` files: ${item.files.join(", ")}`);
|
|
203
|
+
return lines.join("\n");
|
|
204
|
+
}).join("\n");
|
|
205
|
+
return `Execute the approved plan (one step at a time, in order):
|
|
167
206
|
|
|
168
|
-
${
|
|
207
|
+
${steps}
|
|
169
208
|
|
|
170
|
-
|
|
209
|
+
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
210
|
}
|
|
172
211
|
function updateStatus() {
|
|
173
212
|
const state = readExecutionState();
|
|
@@ -175,7 +214,7 @@ Execute the steps in order, starting with step 1. After completing a step, inclu
|
|
|
175
214
|
const completed = state.steps.filter((step) => step.status === "completed").length;
|
|
176
215
|
ctx.ui.notify(`\u{1F4CB} Plan: ${completed}/${state.steps.length} completed`, "info");
|
|
177
216
|
} else if (planModeEnabled) {
|
|
178
|
-
ctx.ui.notify("\u23F8\uFE0F Plan mode
|
|
217
|
+
ctx.ui.notify("\u23F8\uFE0F Plan mode \u2014 discussing (no plan output until you ask for one)", "info");
|
|
179
218
|
}
|
|
180
219
|
}
|
|
181
220
|
function applyPlanModeState(enabled, forcePromptInjection = false) {
|
|
@@ -189,25 +228,26 @@ Execute the steps in order, starting with step 1. After completing a step, inclu
|
|
|
189
228
|
planModeEnabled = !planModeEnabled;
|
|
190
229
|
setExecutingPlan(false);
|
|
191
230
|
writeExecutionState(null);
|
|
231
|
+
revisionPrefix = null;
|
|
192
232
|
ctx.setSessionMetadata(SESSION_METADATA_KEY, planModeEnabled);
|
|
193
|
-
approvalOfferedThisTurn = false;
|
|
194
|
-
lastOfferedPlanKey = "";
|
|
195
233
|
applyPlanModeState(planModeEnabled, true);
|
|
196
234
|
ctx.ui.notify(
|
|
197
|
-
planModeEnabled ? `Plan mode enabled
|
|
235
|
+
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
236
|
);
|
|
199
237
|
updateStatus();
|
|
200
238
|
}
|
|
201
239
|
ctx.registerTool({
|
|
202
240
|
name: "plan_submit",
|
|
203
241
|
label: "plan_submit",
|
|
204
|
-
description:
|
|
242
|
+
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
243
|
parameters: Type.Object({
|
|
206
244
|
goal: Type.Optional(Type.String({ description: "One-line summary of what the plan accomplishes" })),
|
|
207
245
|
steps: Type.Array(
|
|
208
246
|
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 }))
|
|
247
|
+
title: Type.String({ description: "Short imperative step title (one MVP)", maxLength: MAX_PLAN_ITEM_CHARS }),
|
|
248
|
+
detail: Type.Optional(Type.String({ description: "Constraints, risks, or verification notes for this step", maxLength: 2e3 })),
|
|
249
|
+
verify: Type.Optional(Type.String({ description: "How to verify this step passed \u2014 ideally one command or test name", maxLength: 500 })),
|
|
250
|
+
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
251
|
}),
|
|
212
252
|
{ minItems: 1, maxItems: MAX_PLAN_STEPS }
|
|
213
253
|
)
|
|
@@ -216,31 +256,38 @@ Execute the steps in order, starting with step 1. After completing a step, inclu
|
|
|
216
256
|
async execute(args) {
|
|
217
257
|
const reply = (text, isError = false) => ({ content: [{ type: "text", text }], isError });
|
|
218
258
|
if (!planModeEnabled) {
|
|
219
|
-
return reply("plan_submit is only available in Plan mode.
|
|
259
|
+
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
260
|
}
|
|
221
261
|
const items = [];
|
|
222
262
|
for (const step of (args.steps ?? []).slice(0, MAX_PLAN_STEPS)) {
|
|
223
263
|
const title = String(step?.title ?? "").trim().slice(0, MAX_PLAN_ITEM_CHARS);
|
|
224
264
|
if (!title) continue;
|
|
225
265
|
const detail = typeof step?.detail === "string" && step.detail.trim() ? step.detail.trim().slice(0, 2e3) : void 0;
|
|
226
|
-
|
|
266
|
+
const verify = typeof step?.verify === "string" && step.verify.trim() ? step.verify.trim().slice(0, 500) : void 0;
|
|
267
|
+
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;
|
|
268
|
+
items.push({ step: items.length + 1, text: title, detail, verify, files: files?.length ? files : void 0, completed: false });
|
|
227
269
|
}
|
|
228
270
|
if (items.length === 0) {
|
|
229
271
|
return reply("plan_submit requires at least one step with a non-empty title.", true);
|
|
230
272
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const rendered = items.map((item) => `${item.step}. \u2610 ${item.text}${item.detail ? `
|
|
234
|
-
${item.detail}` : ""}`).join("\n");
|
|
273
|
+
const warnings = await checkPlanScopeAsync(items);
|
|
274
|
+
const goal = typeof args.goal === "string" && args.goal.trim() ? args.goal.trim() : void 0;
|
|
235
275
|
if (!ctx.interactions.isAvailable()) {
|
|
236
|
-
|
|
276
|
+
const rendered = items.map((item) => `${item.step}. ${item.text}${item.detail ? `
|
|
277
|
+
${item.detail}` : ""}${item.verify ? `
|
|
278
|
+
verify: ${item.verify}` : ""}${item.files?.length ? `
|
|
279
|
+
files: ${item.files.join(", ")}` : ""}`).join("\n");
|
|
280
|
+
const warningText = warnings.length > 0 ? `
|
|
237
281
|
|
|
238
|
-
|
|
282
|
+
Scope warnings:
|
|
283
|
+
${warnings.map((warning) => `- ${warning.path} ${warning.kind === "missing" ? "does not exist \u2014 typo, or understanding gap?" : "already exists but was declared new"}`).join("\n")}` : "";
|
|
284
|
+
return reply(`Plan submitted (${items.length} steps)${goal ? ` \u2014 ${goal}` : ""} in headless mode; interactive approval is unavailable, so nothing will be executed:
|
|
285
|
+
|
|
286
|
+
${rendered}${warningText}`);
|
|
239
287
|
}
|
|
240
|
-
|
|
241
|
-
planNotify(renderPlanMarkdown(goal, items));
|
|
288
|
+
planNotify(renderPlanMarkdown(goal, items, warnings), warnings.length > 0 ? "warning" : "info");
|
|
242
289
|
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?`, [
|
|
290
|
+
const choice = await planSelect(`\u{1F4CB} Plan (${items.length} steps)${warnings.length > 0 ? ` \u2014 ${warnings.length} scope warning(s)` : ""} \u2014 what next?`, [
|
|
244
291
|
"Execute the plan (track progress)",
|
|
245
292
|
...yoloOption,
|
|
246
293
|
"Stay in plan mode",
|
|
@@ -267,13 +314,74 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
267
314
|
return reply("The user chose to stay in Plan mode. Do not execute anything; wait for guidance or refine the plan when asked.");
|
|
268
315
|
}
|
|
269
316
|
});
|
|
317
|
+
async function checkPlanScopeAsync(items) {
|
|
318
|
+
const declaredNew = /* @__PURE__ */ new Set();
|
|
319
|
+
const normalized = items.map((item) => ({
|
|
320
|
+
...item,
|
|
321
|
+
files: (item.files ?? []).map((file) => {
|
|
322
|
+
const bare = file.replace(NEW_FILE_MARKER, "").trim();
|
|
323
|
+
if (bare && NEW_FILE_MARKER.test(file)) declaredNew.add(bare);
|
|
324
|
+
return bare;
|
|
325
|
+
}).filter(Boolean)
|
|
326
|
+
}));
|
|
327
|
+
if (normalized.every((item) => item.files.length === 0)) return [];
|
|
328
|
+
const existsCache = /* @__PURE__ */ new Map();
|
|
329
|
+
for (const target of new Set(normalized.flatMap((item) => item.files))) {
|
|
330
|
+
existsCache.set(target, await pathExists(target));
|
|
331
|
+
}
|
|
332
|
+
return checkPlanScope(
|
|
333
|
+
normalized,
|
|
334
|
+
(target) => existsCache.get(target) === true,
|
|
335
|
+
(_item, target) => declaredNew.has(target)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
270
338
|
ctx.registerCommand({
|
|
271
339
|
path: capability.commands?.[0]?.path ?? ["tools", "plan"],
|
|
272
|
-
description:
|
|
340
|
+
description: "Toggle plan mode (read-only exploration, discussion-first)",
|
|
273
341
|
handler: async () => {
|
|
274
342
|
togglePlanMode();
|
|
275
343
|
}
|
|
276
344
|
});
|
|
345
|
+
ctx.registerCommand({
|
|
346
|
+
path: ["tools", "plan", "submit"],
|
|
347
|
+
description: "Ask for the plan now (optional free-text context)",
|
|
348
|
+
handler: async (_commandCtx, args) => {
|
|
349
|
+
if (!planModeEnabled) {
|
|
350
|
+
ctx.ui.notify("Enter Plan mode first (/tools/plan), then ask for the plan again.", "info");
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const context = (args ?? "").trim();
|
|
354
|
+
return context ? `\u8F93\u51FA\u8BA1\u5212\u3002Additional context from the user: ${context}
|
|
355
|
+
|
|
356
|
+
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.";
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
ctx.registerCommand({
|
|
360
|
+
path: ["tools", "plan", "revise"],
|
|
361
|
+
description: "Revise the remaining plan (during or after execution)",
|
|
362
|
+
handler: async () => {
|
|
363
|
+
const state = readExecutionState();
|
|
364
|
+
if (state.steps.length === 0 && !revisionPrefix) {
|
|
365
|
+
ctx.ui.notify("No plan is executing. Enable Plan mode (/tools/plan), discuss, then ask for the plan (/tools/plan/submit).", "info");
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const completedItems = toPlanTodoItems(state).filter((item) => item.completed);
|
|
369
|
+
const remainingItems = toPlanTodoItems(state).filter((item) => !item.completed);
|
|
370
|
+
revisionPrefix = revisionPrefix ?? completedItems;
|
|
371
|
+
setExecutingPlan(false);
|
|
372
|
+
ctx.setSessionMetadata(SESSION_METADATA_KEY, true);
|
|
373
|
+
applyPlanModeState(true, true);
|
|
374
|
+
updateStatus();
|
|
375
|
+
const completedLines = revisionPrefix.length > 0 ? revisionPrefix.map((item) => `- \u2713 ${item.text}`).join("\n") : "- (none yet)";
|
|
376
|
+
return `Revise the remaining plan. Completed so far (do not redo these; they carry over into the revised ladder automatically):
|
|
377
|
+
${completedLines}
|
|
378
|
+
|
|
379
|
+
Remaining steps as previously approved:
|
|
380
|
+
${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)"}
|
|
381
|
+
|
|
382
|
+
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.`;
|
|
383
|
+
}
|
|
384
|
+
});
|
|
277
385
|
ctx.registerShortcut("ctrl+alt+p", {
|
|
278
386
|
description: "Toggle plan mode",
|
|
279
387
|
handler: async () => {
|
|
@@ -284,16 +392,12 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
284
392
|
const persisted = readPersistedPlanMode();
|
|
285
393
|
applyPlanModeState(persisted);
|
|
286
394
|
executingPlan = !persisted && readPersistedExecuting();
|
|
287
|
-
approvalOfferedThisTurn = false;
|
|
288
|
-
if (!persisted) lastOfferedPlanKey = "";
|
|
289
395
|
writeExecutionState(readExecutionState());
|
|
290
396
|
});
|
|
291
397
|
ctx.on("session:changed", async () => {
|
|
292
398
|
const enabled = readPersistedPlanMode();
|
|
293
399
|
applyPlanModeState(enabled, enabled);
|
|
294
400
|
executingPlan = !enabled && readPersistedExecuting();
|
|
295
|
-
approvalOfferedThisTurn = false;
|
|
296
|
-
lastOfferedPlanKey = "";
|
|
297
401
|
writeExecutionState(readExecutionState());
|
|
298
402
|
});
|
|
299
403
|
ctx.on("turn:end", async (event) => {
|
|
@@ -312,8 +416,7 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
312
416
|
const state = readExecutionState();
|
|
313
417
|
if (executingPlan && state.steps.length > 0) {
|
|
314
418
|
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");
|
|
419
|
+
const completedList = state.steps.map((step) => `${step.id}. \u2713 ${step.title}${step.verify ? ` \u2014 verified: ${step.verify}` : ""}`).join("\n");
|
|
317
420
|
ctx.ui.notify(`## \u2705 Plan complete
|
|
318
421
|
|
|
319
422
|
${completedList}`, "info", { markdown: true });
|
|
@@ -322,43 +425,7 @@ ${completedList}`, "info", { markdown: true });
|
|
|
322
425
|
}
|
|
323
426
|
return;
|
|
324
427
|
}
|
|
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
|
-
}
|
|
428
|
+
void event;
|
|
362
429
|
});
|
|
363
430
|
ctx.log("Plan mode extension loaded");
|
|
364
431
|
}
|