@cydm/pie 2.8.0 → 3.0.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 +18 -0
- package/dist/builtin/extensions/ask-user/index.js +4 -3
- package/dist/builtin/extensions/changelog/index.js +2 -2
- package/dist/builtin/extensions/cron/index.js +430 -43
- package/dist/builtin/extensions/document-attachments/index.js +1 -1
- package/dist/builtin/extensions/herdr-agent-state/index.js +2 -2
- package/dist/builtin/extensions/im-forward/index.js +13 -2
- package/dist/builtin/extensions/memory/index.js +277 -83
- package/dist/builtin/extensions/memory/package.json +2 -1
- package/dist/builtin/extensions/plan-mode/index.js +4 -3
- package/dist/builtin/extensions/subagent/index.js +7 -6
- package/dist/builtin/extensions/todo/index.js +4 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +106 -2
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +1 -0
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{chunk-BNSAEVRT.js → chunk-WOGAQ4P5.js} +2 -2
- package/dist/builtin/skills/chrome-devtools-axi/{cli-AO2ZTPRM.js → cli-CHC7XYFU.js} +27 -3
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +8 -3
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-cli.js +1 -0
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +6 -1
- package/dist/builtin/skills/computer-use-axi/scripts/setup-helper.mjs +6 -2
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +130 -9
- package/dist/chunks/auth-storage-3EGM3VTK.js +13 -0
- package/dist/chunks/{chunk-JNOFHHLZ.js → chunk-3BC5KGDQ.js} +383 -185
- package/dist/chunks/chunk-3FRKOFSP.js +9667 -0
- package/dist/chunks/chunk-6DNYGVZP.js +278 -0
- package/dist/chunks/{chunk-LJXHECZ7.js → chunk-7FEPQHYX.js} +13867 -19759
- package/dist/chunks/{chunk-NEES4EBX.js → chunk-BUDXV3TR.js} +28 -18
- package/dist/chunks/{chunk-HGC25NYB.js → chunk-GH4VW2OT.js} +1 -1
- package/dist/chunks/{chunk-5353DEEC.js → chunk-ILUHTKF3.js} +20 -1
- package/dist/chunks/chunk-OEQYEYB3.js +299 -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-AE3OCAE6.js +431 -0
- package/dist/chunks/src-RVTDUSPJ.js +293 -0
- package/dist/chunks/{src-5XOKRS6F.js → src-YG5M2H44.js} +2 -2
- package/dist/chunks/{test-stream-5SDHKKDB.js → test-stream-JBWXKOQA.js} +1 -1
- package/dist/cli.js +1455 -2358
- package/package.json +4 -4
|
@@ -2,21 +2,23 @@ import { createRequire as __createRequire } from "node:module"; const require =
|
|
|
2
2
|
import {
|
|
3
3
|
getBuiltinDir,
|
|
4
4
|
getConfigDir
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ILUHTKF3.js";
|
|
6
6
|
import {
|
|
7
7
|
classifyShellCommand,
|
|
8
8
|
createSharedWebFetchTool,
|
|
9
9
|
createSharedWebResearchTool,
|
|
10
10
|
createSharedWebSearchTool,
|
|
11
11
|
defaultShellKindForPlatform,
|
|
12
|
-
interpretShellExit
|
|
12
|
+
interpretShellExit
|
|
13
|
+
} from "./chunk-7FEPQHYX.js";
|
|
14
|
+
import {
|
|
13
15
|
requestInteraction
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-3FRKOFSP.js";
|
|
15
17
|
import {
|
|
16
18
|
EMPTY_ASSISTANT_CONTENT_ERROR,
|
|
17
19
|
OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
|
|
18
20
|
getLogger
|
|
19
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-3BC5KGDQ.js";
|
|
20
22
|
import {
|
|
21
23
|
Type
|
|
22
24
|
} from "./chunk-XXGYUYXI.js";
|
|
@@ -587,8 +589,8 @@ function buildBashSchema(commandDescription) {
|
|
|
587
589
|
timeout: Type.Optional(
|
|
588
590
|
Type.Number({
|
|
589
591
|
exclusiveMinimum: 0,
|
|
590
|
-
maximum:
|
|
591
|
-
description: "Timeout in seconds. Default:
|
|
592
|
+
maximum: 2147483e3,
|
|
593
|
+
description: "Timeout in MILLISECONDS (not seconds). Default: 120000 (2 minutes). Examples: 30000 = 30s, 300000 = 5 minutes."
|
|
592
594
|
})
|
|
593
595
|
),
|
|
594
596
|
cwd: Type.Optional(Type.String({ description: "Working directory for the command" })),
|
|
@@ -601,18 +603,25 @@ function buildBashSchema(commandDescription) {
|
|
|
601
603
|
});
|
|
602
604
|
}
|
|
603
605
|
var DEFAULT_TIMEOUT_SECONDS = 120;
|
|
604
|
-
var
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
606
|
+
var TIMEOUT_MAX_MS = 2147483e3;
|
|
607
|
+
function resolveTimeoutPolicy(requestedTimeoutMs) {
|
|
608
|
+
if (requestedTimeoutMs === void 0) {
|
|
609
|
+
return { requestedSeconds: DEFAULT_TIMEOUT_SECONDS, effectiveSeconds: DEFAULT_TIMEOUT_SECONDS };
|
|
610
|
+
}
|
|
611
|
+
if (!Number.isFinite(requestedTimeoutMs) || requestedTimeoutMs <= 0) {
|
|
612
|
+
throw new Error("Invalid shell timeout: pass a positive number of milliseconds (e.g. 120000 for two minutes).");
|
|
610
613
|
}
|
|
614
|
+
if (requestedTimeoutMs > TIMEOUT_MAX_MS) {
|
|
615
|
+
throw new Error(`Shell timeout ${requestedTimeoutMs}ms exceeds the supported timer range (2147483000ms \u2248 24.8 days).`);
|
|
616
|
+
}
|
|
617
|
+
const seconds = requestedTimeoutMs / 1e3;
|
|
611
618
|
return {
|
|
612
|
-
requestedSeconds,
|
|
613
|
-
effectiveSeconds:
|
|
619
|
+
requestedSeconds: seconds,
|
|
620
|
+
effectiveSeconds: seconds
|
|
614
621
|
};
|
|
615
622
|
}
|
|
623
|
+
var OUTPUT_DRAIN_TIMEOUT_MS = 1e3;
|
|
624
|
+
var MAX_SHELL_EXIT_DRAIN_MS = 1e4;
|
|
616
625
|
function validateBashCommand(command) {
|
|
617
626
|
const value = typeof command === "string" ? command : "";
|
|
618
627
|
const trimmed = value.trim();
|
|
@@ -650,7 +659,7 @@ function buildBashDescription(contract) {
|
|
|
650
659
|
return [
|
|
651
660
|
"Execute a shell command in the current working directory.",
|
|
652
661
|
contract.dialectBlock,
|
|
653
|
-
`Returns stdout and stderr as a bounded head/tail preview of at most ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB. If truncated, the result includes a private full-output artifact path. Default timeout:
|
|
662
|
+
`Returns stdout and stderr as a bounded head/tail preview of at most ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB. If truncated, the result includes a private full-output artifact path. Default timeout: 120000ms (2 minutes). The timeout parameter is in milliseconds and is the budget: pass a larger value when a task legitimately needs it, and keep long waits focused rather than polling loops.`
|
|
654
663
|
].join(" ");
|
|
655
664
|
}
|
|
656
665
|
function buildSpawnCommand(shell, command) {
|
|
@@ -1039,7 +1048,7 @@ function createBashTool(defaultCwd, options) {
|
|
|
1039
1048
|
});
|
|
1040
1049
|
}
|
|
1041
1050
|
const timeoutPolicy = resolveTimeoutPolicy(timeout);
|
|
1042
|
-
const timeoutMs =
|
|
1051
|
+
const timeoutMs = timeout ?? DEFAULT_TIMEOUT_SECONDS * 1e3;
|
|
1043
1052
|
return new Promise((resolve2, reject) => {
|
|
1044
1053
|
if (signal?.aborted) {
|
|
1045
1054
|
reject(new Error("Operation aborted"));
|
|
@@ -1340,7 +1349,7 @@ ${commandNonzeroHint}`;
|
|
|
1340
1349
|
outputText += `
|
|
1341
1350
|
|
|
1342
1351
|
[Command timed out after ${timeoutPolicy.effectiveSeconds} seconds]`;
|
|
1343
|
-
outputText += "\n[Timeout hint: the command ran longer than its requested budget. Inspect partial results/logs, then either raise the timeout to what the task needs or split long waits into smaller focused steps. Avoid repeating identical long waits.]";
|
|
1352
|
+
outputText += "\n[Timeout hint: the command ran longer than its requested budget. Inspect partial results/logs, then either raise the timeout (milliseconds) to what the task needs or split long waits into smaller focused steps. Avoid repeating identical long waits.]";
|
|
1344
1353
|
}
|
|
1345
1354
|
if (stdioIncomplete && !timedOut) {
|
|
1346
1355
|
outputText += "\n\n[Output capture ended after the command exited because a descendant kept stdio open or the output artifact was still draining (bounded wait). Captured output may be incomplete.]";
|
|
@@ -1409,7 +1418,8 @@ function runAxi(args, options = {}) {
|
|
|
1409
1418
|
stdio: ["ignore", "pipe", "pipe"],
|
|
1410
1419
|
shell: false,
|
|
1411
1420
|
env: options.env,
|
|
1412
|
-
cwd: options.cwd
|
|
1421
|
+
cwd: options.cwd,
|
|
1422
|
+
windowsHide: true
|
|
1413
1423
|
});
|
|
1414
1424
|
let stdout = "";
|
|
1415
1425
|
let stderr = "";
|
|
@@ -41,14 +41,20 @@ function getPackageJsonPath() {
|
|
|
41
41
|
return join(getPackageDir(), "package.json");
|
|
42
42
|
}
|
|
43
43
|
var pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8"));
|
|
44
|
+
var APP_NAME = "pie";
|
|
44
45
|
var CONFIG_DIR_NAME = ".pie";
|
|
45
46
|
var VERSION = pkg.version;
|
|
46
47
|
var ENV_AGENT_DIR = "PIE_CODING_AGENT_DIR";
|
|
47
48
|
function getConfigDir() {
|
|
48
49
|
const envDir = process.env[ENV_AGENT_DIR];
|
|
49
|
-
if (envDir) {
|
|
50
|
+
if (envDir !== void 0 && envDir !== "") {
|
|
50
51
|
if (envDir === "~") return homedir();
|
|
51
52
|
if (envDir.startsWith("~/")) return homedir() + envDir.slice(1);
|
|
53
|
+
if (envDir === "undefined" || envDir === "null") {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`${ENV_AGENT_DIR} is set to the literal string "${envDir}"; unset it or point it at a real directory`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
52
58
|
return envDir;
|
|
53
59
|
}
|
|
54
60
|
return join(homedir(), CONFIG_DIR_NAME);
|
|
@@ -59,6 +65,9 @@ function getAgentDir() {
|
|
|
59
65
|
function getCustomThemesDir() {
|
|
60
66
|
return join(getConfigDir(), "themes");
|
|
61
67
|
}
|
|
68
|
+
function getKeybindingsPath() {
|
|
69
|
+
return join(getConfigDir(), "keybindings.json");
|
|
70
|
+
}
|
|
62
71
|
function getSettingsPath() {
|
|
63
72
|
return join(getConfigDir(), "settings.json");
|
|
64
73
|
}
|
|
@@ -74,6 +83,9 @@ function getLogsDir() {
|
|
|
74
83
|
function getRuntimeLogPath() {
|
|
75
84
|
return join(getLogsDir(), "pie-cli.log");
|
|
76
85
|
}
|
|
86
|
+
function getDebugLogPath() {
|
|
87
|
+
return getRuntimeLogPath();
|
|
88
|
+
}
|
|
77
89
|
function migrateConfigFromAgentDir() {
|
|
78
90
|
const oldAgentDir = join(homedir(), CONFIG_DIR_NAME, "agent");
|
|
79
91
|
const newConfigDir = getConfigDir();
|
|
@@ -114,17 +126,24 @@ function migrateConfigFromAgentDir() {
|
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
export {
|
|
129
|
+
isBunRuntime,
|
|
117
130
|
getPackageDir,
|
|
118
131
|
getThemesDir,
|
|
119
132
|
getBuiltinDir,
|
|
133
|
+
getPackageJsonPath,
|
|
134
|
+
APP_NAME,
|
|
135
|
+
CONFIG_DIR_NAME,
|
|
120
136
|
VERSION,
|
|
137
|
+
ENV_AGENT_DIR,
|
|
121
138
|
getConfigDir,
|
|
122
139
|
getAgentDir,
|
|
123
140
|
getCustomThemesDir,
|
|
141
|
+
getKeybindingsPath,
|
|
124
142
|
getSettingsPath,
|
|
125
143
|
getProjectSettingsPath,
|
|
126
144
|
getSessionsDir,
|
|
127
145
|
getLogsDir,
|
|
128
146
|
getRuntimeLogPath,
|
|
147
|
+
getDebugLogPath,
|
|
129
148
|
migrateConfigFromAgentDir
|
|
130
149
|
};
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/commands/memory-distill.ts
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
var require2 = createRequire(import.meta.url);
|
|
9
|
+
function distillWorkerLogPath(memoryRoot) {
|
|
10
|
+
return path.join(memoryRoot, "distill-worker.log");
|
|
11
|
+
}
|
|
12
|
+
function distillLockPath(memoryRoot) {
|
|
13
|
+
return path.join(memoryRoot, "distill.lock");
|
|
14
|
+
}
|
|
15
|
+
function readDistillWorkerLog(memoryRoot, limit = 20) {
|
|
16
|
+
try {
|
|
17
|
+
const raw = fs.readFileSync(distillWorkerLogPath(memoryRoot), "utf8");
|
|
18
|
+
const lines = raw.split("\n").filter((line) => line.trim().length > 0);
|
|
19
|
+
return lines.slice(-limit);
|
|
20
|
+
} catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function spawnDistillWorker(memoryRoot, date) {
|
|
25
|
+
return spawnDistillCli(memoryRoot, ["--date", date]);
|
|
26
|
+
}
|
|
27
|
+
function spawnDistillAutoWorker(memoryRoot) {
|
|
28
|
+
return spawnDistillCli(memoryRoot, ["--auto"]);
|
|
29
|
+
}
|
|
30
|
+
function spawnDistillCli(memoryRoot, modeArgs) {
|
|
31
|
+
const logPath = distillWorkerLogPath(memoryRoot);
|
|
32
|
+
const entry = process.argv[1] ? path.resolve(process.argv[1]) : null;
|
|
33
|
+
if (!entry) return false;
|
|
34
|
+
try {
|
|
35
|
+
fs.mkdirSync(memoryRoot, { recursive: true });
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const args = [entry, "memory", "distill", ...modeArgs, "--worker", "--memory-root", memoryRoot];
|
|
40
|
+
let out;
|
|
41
|
+
try {
|
|
42
|
+
out = fs.openSync(logPath, "a");
|
|
43
|
+
const child = spawn(process.execPath, args, {
|
|
44
|
+
detached: true,
|
|
45
|
+
windowsHide: true,
|
|
46
|
+
stdio: ["ignore", out, out],
|
|
47
|
+
env: { ...process.env, PIE_MEMORY_WORKER: "1" }
|
|
48
|
+
});
|
|
49
|
+
child.on("error", (error) => {
|
|
50
|
+
try {
|
|
51
|
+
fs.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] spawn failed: ${String(error)}
|
|
52
|
+
`);
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
child.unref();
|
|
57
|
+
try {
|
|
58
|
+
fs.appendFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] spawned worker (${modeArgs.join(" ")}) (pid ${child.pid})
|
|
59
|
+
`);
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
} finally {
|
|
66
|
+
if (out !== void 0) {
|
|
67
|
+
try {
|
|
68
|
+
fs.closeSync(out);
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var advisoryLockBackend = /* @__PURE__ */ (() => {
|
|
75
|
+
let impl;
|
|
76
|
+
return () => {
|
|
77
|
+
if (impl) return impl;
|
|
78
|
+
const koffi = require2("koffi");
|
|
79
|
+
const { createMemoryLockBackend } = require2("@pie/shared-headless-capabilities");
|
|
80
|
+
impl = createMemoryLockBackend(koffi);
|
|
81
|
+
return impl;
|
|
82
|
+
};
|
|
83
|
+
})();
|
|
84
|
+
function acquireAdvisoryLock(lockPath) {
|
|
85
|
+
const backend = advisoryLockBackend();
|
|
86
|
+
fs.mkdirSync(path.dirname(lockPath), { recursive: true });
|
|
87
|
+
let handle;
|
|
88
|
+
try {
|
|
89
|
+
handle = backend.open(lockPath);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const result = backend.lock(handle);
|
|
95
|
+
if (result !== "acquired") {
|
|
96
|
+
backend.unlock(handle);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
backend.unlock(handle);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
let released = false;
|
|
104
|
+
return {
|
|
105
|
+
release() {
|
|
106
|
+
if (released) return;
|
|
107
|
+
released = true;
|
|
108
|
+
backend.unlock(handle);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function acquireDistillLock(memoryRoot) {
|
|
113
|
+
const lock = acquireAdvisoryLock(distillLockPath(memoryRoot));
|
|
114
|
+
return lock ? () => lock.release() : null;
|
|
115
|
+
}
|
|
116
|
+
async function withModelTimeout(promise, timeoutMs, label) {
|
|
117
|
+
let timer;
|
|
118
|
+
try {
|
|
119
|
+
return await new Promise((resolve2, reject) => {
|
|
120
|
+
timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
121
|
+
Promise.resolve(promise).then(
|
|
122
|
+
(value) => {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
resolve2(value);
|
|
125
|
+
},
|
|
126
|
+
(error) => {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
reject(error);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
} finally {
|
|
133
|
+
if (timer !== void 0) {
|
|
134
|
+
const t = timer;
|
|
135
|
+
queueMicrotask(() => clearTimeout(t));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function normalizeCwdPath(value) {
|
|
140
|
+
if (value.length > 1 && value.endsWith(path.sep)) return value.slice(0, -1);
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
function pathContains(parent, child) {
|
|
144
|
+
if (parent === child) return true;
|
|
145
|
+
const parentWithSep = parent.endsWith(path.sep) ? parent : parent + path.sep;
|
|
146
|
+
return child.startsWith(parentWithSep);
|
|
147
|
+
}
|
|
148
|
+
async function readExcludeCwds() {
|
|
149
|
+
try {
|
|
150
|
+
const { getSettingsPath } = await import("./config-74AUVDLT.js");
|
|
151
|
+
const raw = JSON.parse(fs.readFileSync(getSettingsPath(), "utf8"));
|
|
152
|
+
const list = raw?.extensions?.memory?.excludeCwds;
|
|
153
|
+
if (!Array.isArray(list)) return [];
|
|
154
|
+
return list.filter((entry) => typeof entry === "string" && path.isAbsolute(entry)).map(normalizeCwdPath);
|
|
155
|
+
} catch {
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function runDistillWorkerMain(memoryRoot, date, noExit = false) {
|
|
160
|
+
const log = (message) => {
|
|
161
|
+
try {
|
|
162
|
+
fs.appendFileSync(distillWorkerLogPath(memoryRoot), `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
163
|
+
`);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const release = acquireDistillLock(memoryRoot);
|
|
168
|
+
if (!release) {
|
|
169
|
+
return { ok: false, error: "another distillation worker holds the lock", busy: true };
|
|
170
|
+
}
|
|
171
|
+
let result;
|
|
172
|
+
let ledger;
|
|
173
|
+
try {
|
|
174
|
+
const { ModelRegistry } = await import("./model-registry-LI5THXV4.js");
|
|
175
|
+
const { AuthStorage } = await import("./auth-storage-3EGM3VTK.js");
|
|
176
|
+
const { getSessionsDir } = await import("./config-74AUVDLT.js");
|
|
177
|
+
const { FileSessionStore } = await import("./src-RVTDUSPJ.js");
|
|
178
|
+
const { MemoryStore, runDistillation } = await import("./src-AE3OCAE6.js");
|
|
179
|
+
const store = new MemoryStore(memoryRoot);
|
|
180
|
+
ledger = store;
|
|
181
|
+
const registry = new ModelRegistry(AuthStorage.create());
|
|
182
|
+
const excludeCwds = await readExcludeCwds();
|
|
183
|
+
const cwdFilter = excludeCwds.length > 0 ? (cwd) => {
|
|
184
|
+
if (!cwd) return true;
|
|
185
|
+
const normalized = normalizeCwdPath(cwd);
|
|
186
|
+
return !excludeCwds.some((excluded) => pathContains(excluded, normalized));
|
|
187
|
+
} : void 0;
|
|
188
|
+
const modelCall = (modelClass) => async (prompt, options) => {
|
|
189
|
+
const resolved = registry.resolveModelClass(modelClass);
|
|
190
|
+
if (!resolved.model || !resolved.apiKey) {
|
|
191
|
+
throw new Error(`no complete model/key pair for class ${modelClass}${resolved.fallbackReason ? `: ${resolved.fallbackReason}` : ""}`);
|
|
192
|
+
}
|
|
193
|
+
const { completeSimple } = await import("./src-66XSMIAM.js");
|
|
194
|
+
const message = await withModelTimeout(
|
|
195
|
+
completeSimple(
|
|
196
|
+
resolved.model,
|
|
197
|
+
{
|
|
198
|
+
systemPrompt: options?.system ?? "You are a precise extraction engine.",
|
|
199
|
+
messages: [{ role: "user", content: [{ type: "text", text: prompt }], timestamp: Date.now() }]
|
|
200
|
+
},
|
|
201
|
+
{ apiKey: resolved.apiKey, maxTokens: Math.min(resolved.model.maxTokens ?? 4096, 4096) }
|
|
202
|
+
),
|
|
203
|
+
12e4,
|
|
204
|
+
`memory ${modelClass} model call`
|
|
205
|
+
);
|
|
206
|
+
if (message.stopReason && message.stopReason !== "stop") {
|
|
207
|
+
throw new Error(`memory model call ended with stopReason=${message.stopReason}`);
|
|
208
|
+
}
|
|
209
|
+
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
|
|
210
|
+
};
|
|
211
|
+
const distilled = await runDistillation(
|
|
212
|
+
{
|
|
213
|
+
sessionStore: new FileSessionStore(getSessionsDir()),
|
|
214
|
+
memoryStore: store,
|
|
215
|
+
lightCall: modelCall("light"),
|
|
216
|
+
balancedCall: modelCall("balanced"),
|
|
217
|
+
callTimeoutMs: 12e4,
|
|
218
|
+
cwdFilter,
|
|
219
|
+
log
|
|
220
|
+
},
|
|
221
|
+
date
|
|
222
|
+
);
|
|
223
|
+
log(`done ${date}: status=${distilled.status} sessions=${distilled.sessions} ops=${distilled.patchOps}${distilled.error ? ` error=${distilled.error}` : ""}`);
|
|
224
|
+
if (distilled.status === "failed") {
|
|
225
|
+
ledger?.recordFailure(date, distilled.error ?? "unknown failure");
|
|
226
|
+
} else {
|
|
227
|
+
ledger?.clearFailures(date);
|
|
228
|
+
}
|
|
229
|
+
result = { ok: distilled.status === "applied" || distilled.status === "skipped-ran" || distilled.status === "skipped-empty", status: distilled.status, error: distilled.error };
|
|
230
|
+
} catch (error) {
|
|
231
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
232
|
+
log(`failed ${date}: ${message}`);
|
|
233
|
+
try {
|
|
234
|
+
ledger?.recordFailure(date, message);
|
|
235
|
+
} catch {
|
|
236
|
+
}
|
|
237
|
+
result = { ok: false, error: message };
|
|
238
|
+
} finally {
|
|
239
|
+
release();
|
|
240
|
+
}
|
|
241
|
+
if (!noExit) {
|
|
242
|
+
const exitCode = result.ok ? 0 : 1;
|
|
243
|
+
setTimeout(() => process.exit(exitCode), 50).unref?.();
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
async function runDistillAuto(memoryRoot, days = 7) {
|
|
248
|
+
const log = (message) => {
|
|
249
|
+
try {
|
|
250
|
+
fs.appendFileSync(distillWorkerLogPath(memoryRoot), `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
251
|
+
`);
|
|
252
|
+
} catch {
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const { MemoryStore, todayKey } = await import("./src-AE3OCAE6.js");
|
|
256
|
+
const store = new MemoryStore(memoryRoot);
|
|
257
|
+
const today = todayKey(Date.now());
|
|
258
|
+
const dates = [];
|
|
259
|
+
for (let offset = days; offset >= 1; offset -= 1) {
|
|
260
|
+
const probe = /* @__PURE__ */ new Date();
|
|
261
|
+
probe.setDate(probe.getDate() - offset);
|
|
262
|
+
const date = todayKey(probe.getTime());
|
|
263
|
+
if (date === today) continue;
|
|
264
|
+
if (!store.hasRun(date)) dates.push(date);
|
|
265
|
+
}
|
|
266
|
+
if (dates.length === 0) {
|
|
267
|
+
log("auto: no missing checkpoints in the window");
|
|
268
|
+
return { ok: true, lines: ["memory --auto: no missing checkpoints in the last " + days + " days."] };
|
|
269
|
+
}
|
|
270
|
+
log(`auto: ${dates.length} missing date(s): ${dates.join(", ")}`);
|
|
271
|
+
const lines = [];
|
|
272
|
+
let ok = true;
|
|
273
|
+
let deferred = false;
|
|
274
|
+
for (const date of dates) {
|
|
275
|
+
const result = await runDistillWorkerMain(memoryRoot, date, true);
|
|
276
|
+
if (!result.ok && result.busy) {
|
|
277
|
+
lines.push(`${date}: busy \u2014 another distillation worker is running; next schedule retries`);
|
|
278
|
+
deferred = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
lines.push(`${date}: ${result.status ?? "failed"}${result.error ? ` \u2014 ${result.error}` : ""}`);
|
|
282
|
+
if (!result.ok) {
|
|
283
|
+
ok = false;
|
|
284
|
+
lines.push(`stopping: journal order requires oldest-first; fix and re-run --auto for ${dates.slice(dates.indexOf(date) + 1).join(", ") || "the remaining dates"}`);
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
setTimeout(() => process.exit(ok || deferred ? 0 : 1), 50).unref?.();
|
|
289
|
+
return { ok: ok || deferred, lines };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export {
|
|
293
|
+
distillWorkerLogPath,
|
|
294
|
+
readDistillWorkerLog,
|
|
295
|
+
spawnDistillWorker,
|
|
296
|
+
spawnDistillAutoWorker,
|
|
297
|
+
runDistillWorkerMain,
|
|
298
|
+
runDistillAuto
|
|
299
|
+
};
|