@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.
@@ -0,0 +1,43 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+
38
+ export {
39
+ __require,
40
+ __commonJS,
41
+ __export,
42
+ __toESM
43
+ };
@@ -0,0 +1,322 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+
3
+ // src/debug/file-logger.ts
4
+ import * as fs from "fs";
5
+ import * as path from "path";
6
+ var FileLogger = class {
7
+ config = {
8
+ enabled: false,
9
+ filePath: this.getDefaultLogPath(),
10
+ maxBufferSize: 1e3
11
+ };
12
+ currentSessionId = null;
13
+ /**
14
+ * Get default log path - next to sessions directory for consistency
15
+ * ~/.pie/debug.log (Linux/macOS) or %USERPROFILE%\.pie\debug.log (Windows)
16
+ */
17
+ getDefaultLogPath() {
18
+ const homeDir = process.env.HOME || process.env.USERPROFILE || ".";
19
+ return path.join(homeDir, ".pie", "debug.log");
20
+ }
21
+ /**
22
+ * Get log path for a specific session
23
+ * ~/.pie/sessions/{sessionId}.log
24
+ */
25
+ getSessionLogPath(sessionId) {
26
+ const homeDir = process.env.HOME || process.env.USERPROFILE || ".";
27
+ return path.join(homeDir, ".pie", "sessions", `${sessionId}.log`);
28
+ }
29
+ buffer = [];
30
+ // Ring buffer for tail command
31
+ bufferIndex = 0;
32
+ totalLines = 0;
33
+ /**
34
+ * Check if logging is enabled
35
+ */
36
+ isEnabled() {
37
+ return this.config.enabled;
38
+ }
39
+ /**
40
+ * Get current configuration
41
+ */
42
+ getConfig() {
43
+ return { ...this.config };
44
+ }
45
+ /**
46
+ * Enable file logging
47
+ */
48
+ enable(filePath) {
49
+ this.config.enabled = true;
50
+ _LOG_ENABLED = true;
51
+ if (filePath) {
52
+ this.config.filePath = filePath;
53
+ }
54
+ const dir = path.dirname(this.config.filePath);
55
+ if (!fs.existsSync(dir)) {
56
+ fs.mkdirSync(dir, { recursive: true });
57
+ }
58
+ this.log("file-logger", `File logging enabled: ${this.config.filePath}`);
59
+ }
60
+ /**
61
+ * Disable file logging
62
+ */
63
+ disable() {
64
+ this.log("file-logger", "File logging disabled");
65
+ this.config.enabled = false;
66
+ _LOG_ENABLED = false;
67
+ this.currentSessionId = null;
68
+ }
69
+ /**
70
+ * Set session ID and update log path accordingly
71
+ * Log file will be: ~/.pie/sessions/{sessionId}.log
72
+ */
73
+ setSessionId(sessionId) {
74
+ const wasEnabled = this.config.enabled;
75
+ if (wasEnabled && this.currentSessionId && this.currentSessionId !== sessionId) {
76
+ this.log("file-logger", `Switching log from session ${this.currentSessionId} to ${sessionId}`);
77
+ this.config.enabled = false;
78
+ }
79
+ this.currentSessionId = sessionId;
80
+ if (sessionId) {
81
+ this.config.filePath = this.getSessionLogPath(sessionId);
82
+ if (wasEnabled) {
83
+ this.config.enabled = true;
84
+ const dir = path.dirname(this.config.filePath);
85
+ if (!fs.existsSync(dir)) {
86
+ fs.mkdirSync(dir, { recursive: true });
87
+ }
88
+ this.log("file-logger", `File logging enabled for session ${sessionId}: ${this.config.filePath}`);
89
+ }
90
+ } else {
91
+ this.config.filePath = this.getDefaultLogPath();
92
+ }
93
+ }
94
+ /**
95
+ * Get current session ID
96
+ */
97
+ getSessionId() {
98
+ return this.currentSessionId;
99
+ }
100
+ /**
101
+ * Clear log file and buffer
102
+ */
103
+ clear() {
104
+ this.buffer = [];
105
+ this.bufferIndex = 0;
106
+ this.totalLines = 0;
107
+ if (fs.existsSync(this.config.filePath)) {
108
+ fs.writeFileSync(this.config.filePath, "");
109
+ }
110
+ }
111
+ /**
112
+ * Set module filter (undefined = all modules)
113
+ */
114
+ setModules(modules) {
115
+ this.config.modules = modules;
116
+ }
117
+ /**
118
+ * Main log method
119
+ */
120
+ log(module, message, data) {
121
+ if (!this.config.enabled) return;
122
+ if (this.config.modules && !this.config.modules.includes(module)) {
123
+ return;
124
+ }
125
+ const entry = this.formatEntry(module, message, data);
126
+ try {
127
+ fs.appendFileSync(this.config.filePath, entry + "\n");
128
+ } catch (err) {
129
+ return;
130
+ }
131
+ this.buffer[this.bufferIndex] = entry;
132
+ this.bufferIndex = (this.bufferIndex + 1) % this.config.maxBufferSize;
133
+ this.totalLines++;
134
+ }
135
+ /**
136
+ * Get recent log entries (for tail command)
137
+ */
138
+ tail(count = 20) {
139
+ const result = [];
140
+ const size = Math.min(count, this.buffer.length);
141
+ for (let i = 0; i < size; i++) {
142
+ const idx = (this.bufferIndex - size + i + this.config.maxBufferSize) % this.config.maxBufferSize;
143
+ if (this.buffer[idx]) {
144
+ result.push(this.buffer[idx]);
145
+ }
146
+ }
147
+ return result;
148
+ }
149
+ /**
150
+ * Get log file stats
151
+ */
152
+ getStats() {
153
+ let size = 0;
154
+ if (fs.existsSync(this.config.filePath)) {
155
+ const stats = fs.statSync(this.config.filePath);
156
+ size = stats.size;
157
+ }
158
+ return {
159
+ path: this.config.filePath,
160
+ size,
161
+ lines: this.totalLines,
162
+ enabled: this.config.enabled
163
+ };
164
+ }
165
+ /**
166
+ * Read last N lines from file (fallback when buffer is not enough)
167
+ */
168
+ readLastLines(count) {
169
+ if (!fs.existsSync(this.config.filePath)) {
170
+ return [];
171
+ }
172
+ try {
173
+ const content = fs.readFileSync(this.config.filePath, "utf-8");
174
+ const lines = content.split("\n").filter(Boolean);
175
+ return lines.slice(-count);
176
+ } catch {
177
+ return [];
178
+ }
179
+ }
180
+ formatEntry(module, message, data) {
181
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
182
+ let entry = `[${timestamp}] [${module}] ${message}`;
183
+ if (data !== void 0) {
184
+ try {
185
+ entry += ` ${JSON.stringify(data)}`;
186
+ } catch {
187
+ entry += ` [Object]`;
188
+ }
189
+ }
190
+ return entry;
191
+ }
192
+ };
193
+ var fileLogger = new FileLogger();
194
+ var _LOG_ENABLED = false;
195
+ function isLogEnabled() {
196
+ return _LOG_ENABLED;
197
+ }
198
+ function debugLog(module, message, data) {
199
+ if (!_LOG_ENABLED) return;
200
+ fileLogger.log(module, message, data);
201
+ }
202
+ function withErrorLog(fn, context) {
203
+ if (!_LOG_ENABLED) return fn;
204
+ return ((...args) => {
205
+ try {
206
+ const result = fn(...args);
207
+ if (result && typeof result.then === "function" && typeof result.catch === "function") {
208
+ return result.catch((err) => {
209
+ if (_LOG_ENABLED) {
210
+ fileLogger.log("ERROR", `${context} FAILED`, {
211
+ error: err instanceof Error ? err.message : String(err),
212
+ stack: err instanceof Error ? err.stack : void 0
213
+ });
214
+ }
215
+ throw err;
216
+ });
217
+ }
218
+ return result;
219
+ } catch (err) {
220
+ if (_LOG_ENABLED) {
221
+ fileLogger.log("ERROR", `${context} FAILED`, {
222
+ error: err instanceof Error ? err.message : String(err),
223
+ stack: err instanceof Error ? err.stack : void 0
224
+ });
225
+ }
226
+ throw err;
227
+ }
228
+ });
229
+ }
230
+ function setupGlobalErrorHandlers(fallbackWriter) {
231
+ process.on("uncaughtException", (err) => {
232
+ const entry = `[${(/* @__PURE__ */ new Date()).toISOString()}] [ERROR] UNCAUGHT EXCEPTION ${JSON.stringify({
233
+ name: err.name,
234
+ message: err.message,
235
+ type: "uncaughtException"
236
+ })}
237
+ `;
238
+ try {
239
+ const logPath = fileLogger.getConfig().filePath;
240
+ const dir = path.dirname(logPath);
241
+ if (!fs.existsSync(dir)) {
242
+ fs.mkdirSync(dir, { recursive: true });
243
+ }
244
+ fs.appendFileSync(logPath, entry);
245
+ } catch {
246
+ console.error("UNCAUGHT EXCEPTION:", err);
247
+ }
248
+ try {
249
+ fallbackWriter?.("Uncaught Exception", err);
250
+ } catch {
251
+ }
252
+ setTimeout(() => process.exit(1), 100);
253
+ });
254
+ process.on("unhandledRejection", (reason, _promise) => {
255
+ try {
256
+ fallbackWriter?.("Unhandled Rejection", reason instanceof Error ? reason : new Error(String(reason)));
257
+ } catch {
258
+ }
259
+ if (_LOG_ENABLED) {
260
+ fileLogger.log("ERROR", "UNHANDLED REJECTION", {
261
+ reason: reason instanceof Error ? { name: reason.name, message: reason.message, stack: reason.stack } : String(reason),
262
+ type: "unhandledRejection"
263
+ });
264
+ }
265
+ });
266
+ process.on("warning", (warning) => {
267
+ if (_LOG_ENABLED) {
268
+ fileLogger.log("WARN", "NODE WARNING", {
269
+ name: warning.name,
270
+ message: warning.message,
271
+ stack: warning.stack,
272
+ type: "warning"
273
+ });
274
+ }
275
+ });
276
+ }
277
+ var _earlyLogs = [];
278
+ var _earlyLogEnabled = false;
279
+ function debugLogLazy(module, message, data) {
280
+ if (_LOG_ENABLED) {
281
+ fileLogger.log(module, message, data);
282
+ return;
283
+ }
284
+ if (_earlyLogEnabled) {
285
+ _earlyLogs.push({ module, message, data });
286
+ if (_earlyLogs.length > 100) {
287
+ _earlyLogs.shift();
288
+ }
289
+ }
290
+ }
291
+ function enableEarlyLogBuffer() {
292
+ _earlyLogEnabled = true;
293
+ if (process.env.PIE_DEBUG) {
294
+ fileLogger.enable();
295
+ }
296
+ }
297
+ function flushEarlyLogs() {
298
+ if (_earlyLogs.length === 0) return;
299
+ if (!_LOG_ENABLED) {
300
+ if (process.env.PIE_DEBUG) {
301
+ fileLogger.enable();
302
+ } else {
303
+ _earlyLogs = [];
304
+ return;
305
+ }
306
+ }
307
+ for (const log of _earlyLogs) {
308
+ fileLogger.log(log.module, log.message, log.data);
309
+ }
310
+ _earlyLogs = [];
311
+ }
312
+
313
+ export {
314
+ fileLogger,
315
+ isLogEnabled,
316
+ debugLog,
317
+ withErrorLog,
318
+ setupGlobalErrorHandlers,
319
+ debugLogLazy,
320
+ enableEarlyLogBuffer,
321
+ flushEarlyLogs
322
+ };
@@ -0,0 +1,22 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ debugLog,
4
+ debugLogLazy,
5
+ enableEarlyLogBuffer,
6
+ fileLogger,
7
+ flushEarlyLogs,
8
+ isLogEnabled,
9
+ setupGlobalErrorHandlers,
10
+ withErrorLog
11
+ } from "./chunk-XZXLO7YB.js";
12
+ import "./chunk-TG2EQLX2.js";
13
+ export {
14
+ debugLog,
15
+ debugLogLazy,
16
+ enableEarlyLogBuffer,
17
+ fileLogger,
18
+ flushEarlyLogs,
19
+ isLogEnabled,
20
+ setupGlobalErrorHandlers,
21
+ withErrorLog
22
+ };
@@ -0,0 +1,13 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ Agent,
4
+ agentLoop,
5
+ agentLoopContinue
6
+ } from "./chunk-MWFBYJOI.js";
7
+ import "./chunk-RID3574D.js";
8
+ import "./chunk-TG2EQLX2.js";
9
+ export {
10
+ Agent,
11
+ agentLoop,
12
+ agentLoopContinue
13
+ };
@@ -0,0 +1,132 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ AskUserMultiParamsSchema,
4
+ AskUserParamsSchema,
5
+ DEFAULT_MAX_BYTES,
6
+ DEFAULT_MAX_LINES,
7
+ GREP_MAX_LINE_LENGTH,
8
+ ManageTodoListParamsSchema,
9
+ PLAN_MODE_TOOL_NAMES,
10
+ ReadSkillParamsSchema,
11
+ TodoItemSchema,
12
+ buildPathResolutionDescription,
13
+ buildRootParameterSchema,
14
+ buildTodoSuccessMessage,
15
+ cloneTodos,
16
+ collectLastAssistantText,
17
+ collectSharedCapabilityPromptAdditions,
18
+ createAskUserCapability,
19
+ createEditTool,
20
+ createFileSystemTools,
21
+ createFindTool,
22
+ createGrepTool,
23
+ createLsTool,
24
+ createManageTodoCapability,
25
+ createPlanCapability,
26
+ createReadOnlyTools,
27
+ createReadSkillCapability,
28
+ createReadTool,
29
+ createSharedFileSystemTools,
30
+ createSharedReadOnlyTools,
31
+ createSubagentCapability,
32
+ createTodoStore,
33
+ createWriteTool,
34
+ defineSharedCapability,
35
+ detectLineEnding,
36
+ executeManageTodoList,
37
+ extractDoneSteps,
38
+ extractPlanTodoItems,
39
+ formatSize,
40
+ formatSkillsForPrompt,
41
+ fuzzyFindText,
42
+ generateDiffString,
43
+ getAvailableRoots,
44
+ getDefaultRootName,
45
+ getSharedCapabilityPromptAdditionsForToolNames,
46
+ getTodoStats,
47
+ getTodoValidation,
48
+ isPlanModeSafeCommand,
49
+ markCompletedPlanSteps,
50
+ normalizeForFuzzyMatch,
51
+ normalizeStatus,
52
+ normalizeToLF,
53
+ normalizeTodos,
54
+ resolveInSandbox,
55
+ resolveReadPath,
56
+ resolveToCwd,
57
+ restoreLineEndings,
58
+ restoreTodoState,
59
+ restoreTodosFromMessages,
60
+ stripBom,
61
+ truncateHead,
62
+ truncateLine,
63
+ truncateTail,
64
+ validateTodos
65
+ } from "./chunk-TBJ25UWB.js";
66
+ import "./chunk-MWFBYJOI.js";
67
+ import "./chunk-RID3574D.js";
68
+ import "./chunk-TG2EQLX2.js";
69
+ export {
70
+ AskUserMultiParamsSchema,
71
+ AskUserParamsSchema,
72
+ DEFAULT_MAX_BYTES,
73
+ DEFAULT_MAX_LINES,
74
+ GREP_MAX_LINE_LENGTH,
75
+ ManageTodoListParamsSchema,
76
+ PLAN_MODE_TOOL_NAMES,
77
+ ReadSkillParamsSchema,
78
+ TodoItemSchema,
79
+ buildPathResolutionDescription,
80
+ buildRootParameterSchema,
81
+ buildTodoSuccessMessage,
82
+ cloneTodos,
83
+ collectLastAssistantText,
84
+ collectSharedCapabilityPromptAdditions,
85
+ createAskUserCapability,
86
+ createEditTool,
87
+ createFileSystemTools,
88
+ createFindTool,
89
+ createGrepTool,
90
+ createLsTool,
91
+ createManageTodoCapability,
92
+ createPlanCapability,
93
+ createReadOnlyTools,
94
+ createReadSkillCapability,
95
+ createReadTool,
96
+ createSharedFileSystemTools,
97
+ createSharedReadOnlyTools,
98
+ createSubagentCapability,
99
+ createTodoStore,
100
+ createWriteTool,
101
+ defineSharedCapability,
102
+ detectLineEnding,
103
+ executeManageTodoList,
104
+ extractDoneSteps,
105
+ extractPlanTodoItems,
106
+ formatSize,
107
+ formatSkillsForPrompt,
108
+ fuzzyFindText,
109
+ generateDiffString,
110
+ getAvailableRoots,
111
+ getDefaultRootName,
112
+ getSharedCapabilityPromptAdditionsForToolNames,
113
+ getTodoStats,
114
+ getTodoValidation,
115
+ isPlanModeSafeCommand,
116
+ markCompletedPlanSteps,
117
+ normalizeForFuzzyMatch,
118
+ normalizeStatus,
119
+ normalizeToLF,
120
+ normalizeTodos,
121
+ resolveInSandbox,
122
+ resolveReadPath,
123
+ resolveToCwd,
124
+ restoreLineEndings,
125
+ restoreTodoState,
126
+ restoreTodosFromMessages,
127
+ stripBom,
128
+ truncateHead,
129
+ truncateLine,
130
+ truncateTail,
131
+ validateTodos
132
+ };