@cydm/pie 1.0.4 → 1.0.6

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.
@@ -1,10 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
2
+ import {
3
+ __require
4
+ } from "../../../chunks/chunk-TG2EQLX2.js";
8
5
 
9
6
  // builtin/extensions/changelog/index.ts
10
7
  function getRecentCommits(cwd, count = 10) {
@@ -47,7 +44,6 @@ async function readChangelog(cwd) {
47
44
  }
48
45
  function changelogExtension(ctx) {
49
46
  ctx.log("Changelog extension loaded");
50
- ctx.ui.notify("\u{1F4DD} Changelog extension loaded", "info");
51
47
  ctx.registerCommand({
52
48
  path: ["tools", "changelog"],
53
49
  description: "Smart changelog management with gap detection",
@@ -193,7 +189,6 @@ ${changelog ? "\n```\n" + changelog.slice(0, 2e3) + "\n...\n```" : "(\u6587\u4EF
193
189
  }
194
190
  });
195
191
  ctx.log("Changelog extension ready");
196
- ctx.ui.notify(" Changelog extension loaded", "info");
197
192
  }
198
193
  export {
199
194
  changelogExtension as default
@@ -1,9 +1,9 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import "../../../chunks/chunk-TG2EQLX2.js";
2
3
 
3
4
  // builtin/extensions/deploy/index.ts
4
5
  function deployExtension(ctx) {
5
6
  ctx.log("Deploy extension loaded");
6
- ctx.ui.notify("\u{1F680} Deploy extension loaded", "info");
7
7
  ctx.log("Deploy extension ready");
8
8
  }
9
9
  export {
@@ -1,4 +1,5 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import "../../../chunks/chunk-TG2EQLX2.js";
2
3
 
3
4
  // builtin/extensions/document-attachments/index.ts
4
5
  import * as fs from "node:fs";
@@ -1,9 +1,9 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import "../../../chunks/chunk-TG2EQLX2.js";
2
3
 
3
4
  // builtin/extensions/files/index.ts
4
5
  function filesExtension(ctx) {
5
6
  ctx.log("Files extension loaded");
6
- ctx.ui.notify("\u{1F4C1} Files extension loaded", "info");
7
7
  }
8
8
  export {
9
9
  filesExtension as default
@@ -1,4 +1,5 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import "../../../chunks/chunk-TG2EQLX2.js";
2
3
 
3
4
  // builtin/extensions/init/index.ts
4
5
  async function loadExistingKnowledge(cwd) {
@@ -100,14 +101,11 @@ async function initExtension(ctx) {
100
101
  if (cachedKnowledge) {
101
102
  const firstLine = cachedKnowledge.split("\n")[0] || "";
102
103
  const projectName = firstLine.replace(/^#\s*/, "").trim() || "\u9879\u76EE";
103
- ctx.ui.notify(`\u{1F4DA} \u5DF2\u52A0\u8F7D ${projectName} \u77E5\u8BC6\u6587\u6863`, "info");
104
104
  ctx.log(`Pre-loaded agents.md (${cachedKnowledge.length} chars)`);
105
105
  } else {
106
- ctx.ui.notify("\u{1F4DA} Init extension loaded (no existing knowledge)", "info");
107
106
  ctx.log("No existing agents.md found");
108
107
  }
109
108
  } catch (err) {
110
- ctx.ui.notify("\u{1F4DA} Init extension loaded", "info");
111
109
  ctx.log(`Failed to pre-load agents.md: ${err}`);
112
110
  }
113
111
  ctx.registerCommand({
@@ -1,4 +1,5 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import "../../../chunks/chunk-TG2EQLX2.js";
2
3
 
3
4
  // builtin/extensions/kimi-attachments/index.ts
4
5
  function isKimiProvider(provider) {
@@ -1,95 +1,26 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ PLAN_MODE_TOOL_NAMES,
4
+ createPlanCapability,
5
+ extractPlanTodoItems,
6
+ isPlanModeSafeCommand,
7
+ markCompletedPlanSteps
8
+ } from "../../../chunks/chunk-TBJ25UWB.js";
9
+ import "../../../chunks/chunk-MWFBYJOI.js";
10
+ import "../../../chunks/chunk-RID3574D.js";
11
+ import "../../../chunks/chunk-TG2EQLX2.js";
2
12
 
3
13
  // builtin/extensions/plan-mode/index.ts
4
- function extractTodoItems(text) {
5
- const items = [];
6
- const planMatch = text.match(/Plan:\s*\n?([\s\S]*?)(?=\n\n|\n[A-Z]|$)/i);
7
- if (!planMatch) return items;
8
- const planSection = planMatch[1];
9
- const lines = planSection.split("\n");
10
- for (const line of lines) {
11
- const trimmed = line.trim();
12
- const match = trimmed.match(/^(?:\d+[.):\s]+|[\-*]\s+)(.+)$/);
13
- if (match) {
14
- items.push({
15
- step: items.length + 1,
16
- text: match[1].trim(),
17
- completed: false
18
- });
19
- }
20
- }
21
- return items;
22
- }
23
- function isSafeCommand(command) {
24
- const trimmed = command.trim();
25
- const safePrefixes = [
26
- "cat ",
27
- "ls ",
28
- "find ",
29
- "grep ",
30
- "head ",
31
- "tail ",
32
- "echo ",
33
- "pwd",
34
- "cd ",
35
- "which ",
36
- "git status",
37
- "git log",
38
- "git diff",
39
- "git show",
40
- "git branch -a",
41
- "git remote -v",
42
- "git config --list",
43
- "npm list",
44
- "npm view"
45
- ];
46
- const dangerousPatterns = [
47
- /\brm\s+-[rf]*/i,
48
- />[\s]*\/dev\//,
49
- /\|.*\brm\b/,
50
- /git\s+push/i,
51
- /git\s+reset/i,
52
- /git\s+checkout\s+-/,
53
- /git\s+revert/i,
54
- /npm\s+publish/i,
55
- /npm\s+uninstall/i,
56
- /npm\s+rm/i
57
- ];
58
- for (const pattern of dangerousPatterns) {
59
- if (pattern.test(trimmed)) {
60
- return false;
61
- }
62
- }
63
- for (const prefix of safePrefixes) {
64
- if (trimmed.startsWith(prefix)) {
65
- return true;
66
- }
67
- }
68
- if (/^[a-z]+$/.test(trimmed)) {
69
- return ["pwd", "ls", "clear", "whoami"].includes(trimmed);
70
- }
71
- return false;
72
- }
73
- function markCompletedSteps(text, todoItems2) {
74
- let markedCount = 0;
75
- const doneMatches = text.matchAll(/\[DONE:\s*(\d+)\]/gi);
76
- for (const match of doneMatches) {
77
- const stepNum = parseInt(match[1], 10);
78
- const item = todoItems2.find((t) => t.step === stepNum);
79
- if (item && !item.completed) {
80
- item.completed = true;
81
- markedCount++;
82
- }
83
- }
84
- return markedCount;
85
- }
86
- var PLAN_MODE_TOOLS = ["read", "bash", "grep", "find", "ls", "questionnaire"];
87
- var NORMAL_MODE_TOOLS = ["read", "bash", "edit", "write", "grep", "find", "ls", "questionnaire"];
14
+ var SESSION_METADATA_KEY = "planModeEnabled";
88
15
  var planModeEnabled = false;
89
16
  var executionMode = false;
90
17
  var todoItems = [];
91
18
  function planModeExtension(ctx) {
92
19
  ctx.log("Plan mode extension loaded");
20
+ const capability = createPlanCapability();
21
+ function readPersistedPlanMode() {
22
+ return ctx.getSessionMetadata()?.[SESSION_METADATA_KEY] === true;
23
+ }
93
24
  function updateStatus() {
94
25
  if (executionMode && todoItems.length > 0) {
95
26
  const completed = todoItems.filter((t) => t.completed).length;
@@ -98,23 +29,44 @@ function planModeExtension(ctx) {
98
29
  ctx.ui.notify("\u23F8\uFE0F Plan mode active (read-only)", "info");
99
30
  }
100
31
  }
32
+ function getNormalModeTools() {
33
+ const allToolNames = ctx.getAllTools?.()?.map((tool) => tool?.name).filter((name) => typeof name === "string" && name.length > 0);
34
+ if (allToolNames && allToolNames.length > 0) {
35
+ return allToolNames;
36
+ }
37
+ return ["read", "bash", "edit", "write", "grep", "find", "ls", "ask_user_multi", "manage_todo_list"];
38
+ }
101
39
  function togglePlanMode() {
102
40
  planModeEnabled = !planModeEnabled;
103
41
  executionMode = false;
104
42
  todoItems = [];
43
+ ctx.setSessionMetadata(SESSION_METADATA_KEY, planModeEnabled);
105
44
  ctx.setPlanMode(planModeEnabled);
106
45
  if (planModeEnabled) {
107
- ctx.setActiveTools(PLAN_MODE_TOOLS);
108
- ctx.ui.notify(`Plan mode enabled. Available tools: ${PLAN_MODE_TOOLS.join(", ")}`);
46
+ ctx.setActiveTools([...PLAN_MODE_TOOL_NAMES]);
47
+ ctx.ui.notify(`Plan mode enabled. Available tools: ${PLAN_MODE_TOOL_NAMES.join(", ")}`);
109
48
  } else {
110
- ctx.setActiveTools(NORMAL_MODE_TOOLS);
49
+ ctx.setActiveTools(getNormalModeTools());
111
50
  ctx.ui.notify("Plan mode disabled. Full access restored.");
112
51
  }
113
52
  updateStatus();
114
53
  }
54
+ function applyPlanModeState(enabled, options = {}) {
55
+ planModeEnabled = enabled;
56
+ executionMode = false;
57
+ todoItems = [];
58
+ ctx.setPlanMode(enabled, { forcePromptInjection: options.forcePromptInjection });
59
+ ctx.setActiveTools(enabled ? [...PLAN_MODE_TOOL_NAMES] : getNormalModeTools());
60
+ if (options.notify) {
61
+ ctx.ui.notify(
62
+ enabled ? `Plan mode enabled. Available tools: ${PLAN_MODE_TOOL_NAMES.join(", ")}` : "Plan mode disabled. Full access restored."
63
+ );
64
+ }
65
+ updateStatus();
66
+ }
115
67
  ctx.registerCommand({
116
- path: ["tools", "plan"],
117
- description: "Toggle plan mode (read-only exploration)",
68
+ path: capability.commands?.[0]?.path ?? ["tools", "plan"],
69
+ description: capability.commands?.[0]?.description ?? "Toggle plan mode (read-only exploration)",
118
70
  handler: async (_ctx) => {
119
71
  togglePlanMode();
120
72
  }
@@ -128,7 +80,7 @@ function planModeExtension(ctx) {
128
80
  ctx.on("tool:call", async (event) => {
129
81
  if (!planModeEnabled || event.toolName !== "bash") return;
130
82
  const command = event.args?.command;
131
- if (command && !isSafeCommand(command)) {
83
+ if (command && !isPlanModeSafeCommand(command)) {
132
84
  ctx.ui.notify(
133
85
  `Plan mode: Command blocked (not allowlisted). Use /plan to disable plan mode first.
134
86
  Command: ${command}`,
@@ -138,16 +90,24 @@ Command: ${command}`,
138
90
  }
139
91
  });
140
92
  ctx.on("agent:start", async () => {
93
+ const persisted = readPersistedPlanMode();
94
+ if (persisted !== planModeEnabled) {
95
+ applyPlanModeState(persisted);
96
+ }
141
97
  if (planModeEnabled) {
142
98
  ctx.log("[plan-mode] Injecting plan mode context");
143
99
  }
144
100
  });
101
+ ctx.on("session:changed", async () => {
102
+ const enabled = readPersistedPlanMode();
103
+ applyPlanModeState(enabled, { forcePromptInjection: enabled });
104
+ });
145
105
  ctx.on("turn:end", async (event) => {
146
106
  if (!executionMode || todoItems.length === 0) return;
147
107
  const message = event.message;
148
108
  if (message?.role === "assistant" && Array.isArray(message.content)) {
149
109
  const text = message.content.filter((c) => c.type === "text").map((c) => c.text).join("\n");
150
- if (markCompletedSteps(text, todoItems) > 0) {
110
+ if (markCompletedPlanSteps(text, todoItems) > 0) {
151
111
  updateStatus();
152
112
  }
153
113
  }
@@ -161,7 +121,7 @@ Command: ${command}`,
161
121
  ${completedList}`, "info");
162
122
  executionMode = false;
163
123
  todoItems = [];
164
- ctx.setActiveTools(NORMAL_MODE_TOOLS);
124
+ ctx.setActiveTools(getNormalModeTools());
165
125
  }
166
126
  return;
167
127
  }
@@ -172,7 +132,7 @@ ${completedList}`, "info");
172
132
  );
173
133
  if (lastAssistant) {
174
134
  const text = lastAssistant.content.filter((c) => c.type === "text").map((c) => c.text).join("\n");
175
- const extracted = extractTodoItems(text);
135
+ const extracted = extractPlanTodoItems(text);
176
136
  if (extracted.length > 0) {
177
137
  todoItems = extracted;
178
138
  }
@@ -189,8 +149,9 @@ ${todoListText}`, "info");
189
149
  if (choice?.startsWith("Execute")) {
190
150
  planModeEnabled = false;
191
151
  executionMode = todoItems.length > 0;
152
+ ctx.setSessionMetadata(SESSION_METADATA_KEY, false);
192
153
  ctx.setPlanMode(false);
193
- ctx.setActiveTools(NORMAL_MODE_TOOLS);
154
+ ctx.setActiveTools(getNormalModeTools());
194
155
  updateStatus();
195
156
  const execMessage = todoItems.length > 0 ? `Execute the plan. Start with: ${todoItems[0].text}. Mark completed steps with [DONE:n] in your response.` : "Execute the plan you just created.";
196
157
  ctx.sendUserMessage(execMessage);
@@ -202,7 +163,6 @@ ${todoListText}`, "info");
202
163
  }
203
164
  }
204
165
  });
205
- ctx.ui.notify("\u23F8\uFE0F Plan mode extension loaded", "info");
206
166
  }
207
167
  export {
208
168
  planModeExtension as default