visionclaw 0.1.220-beta.2 → 0.1.220-beta.21
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 +2 -2
- package/dist/agent/activity-tracker.d.ts +8 -17
- package/dist/agent/activity-tracker.d.ts.map +1 -1
- package/dist/agent/activity-tracker.js +11 -25
- package/dist/agent/activity-tracker.js.map +1 -1
- package/dist/agent/command-handlers.js +1 -1
- package/dist/agent/command-handlers.js.map +1 -1
- package/dist/agent/context.d.ts +0 -22
- package/dist/agent/context.d.ts.map +1 -1
- package/dist/agent/context.js +0 -79
- package/dist/agent/context.js.map +1 -1
- package/dist/agent/engine-switch-handler.d.ts +2 -2
- package/dist/agent/engine-switch-handler.js +3 -3
- package/dist/agent/engine-switch-handler.js.map +1 -1
- package/dist/agent/engine-switch-target.d.ts.map +1 -1
- package/dist/agent/engine-switch-target.js +5 -1
- package/dist/agent/engine-switch-target.js.map +1 -1
- package/dist/agent/engine-switch.d.ts +4 -4
- package/dist/agent/engine-switch.d.ts.map +1 -1
- package/dist/agent/engine-switch.js +9 -3
- package/dist/agent/engine-switch.js.map +1 -1
- package/dist/agent/engines/claude/session.d.ts +2 -1
- package/dist/agent/engines/claude/session.d.ts.map +1 -1
- package/dist/agent/engines/claude/session.js +5 -4
- package/dist/agent/engines/claude/session.js.map +1 -1
- package/dist/agent/engines/pi/tools.d.ts.map +1 -1
- package/dist/agent/engines/pi/tools.js +3 -1
- package/dist/agent/engines/pi/tools.js.map +1 -1
- package/dist/agent/engines/pi-coding/mcp-config.d.ts +10 -1
- package/dist/agent/engines/pi-coding/mcp-config.d.ts.map +1 -1
- package/dist/agent/engines/pi-coding/mcp-config.js +4 -7
- package/dist/agent/engines/pi-coding/mcp-config.js.map +1 -1
- package/dist/agent/engines/pi-coding/session.d.ts +1 -1
- package/dist/agent/engines/pi-coding/session.d.ts.map +1 -1
- package/dist/agent/engines/pi-coding/session.js +17 -22
- package/dist/agent/engines/pi-coding/session.js.map +1 -1
- package/dist/agent/engines/session-types.d.ts +2 -0
- package/dist/agent/engines/session-types.d.ts.map +1 -1
- package/dist/agent/fast-response-eligibility.d.ts +2 -2
- package/dist/agent/fast-response-eligibility.d.ts.map +1 -1
- package/dist/agent/fast-response-eligibility.js +10 -2
- package/dist/agent/fast-response-eligibility.js.map +1 -1
- package/dist/agent/interrupt-handler.d.ts +2 -2
- package/dist/agent/interrupt-handler.js +4 -4
- package/dist/agent/interrupt-handler.js.map +1 -1
- package/dist/agent/llm-engine-capabilities.d.ts.map +1 -1
- package/dist/agent/llm-engine-capabilities.js +4 -1
- package/dist/agent/llm-engine-capabilities.js.map +1 -1
- package/dist/agent/loop.d.ts +0 -2
- package/dist/agent/loop.d.ts.map +1 -1
- package/dist/agent/loop.js +12 -4
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/model-provider.d.ts +1 -7
- package/dist/agent/model-provider.d.ts.map +1 -1
- package/dist/agent/model-provider.js +2 -10
- package/dist/agent/model-provider.js.map +1 -1
- package/dist/agent/owner-initiated-eligibility.d.ts +2 -0
- package/dist/agent/owner-initiated-eligibility.d.ts.map +1 -1
- package/dist/agent/owner-initiated-eligibility.js +5 -15
- package/dist/agent/owner-initiated-eligibility.js.map +1 -1
- package/dist/agent/reply-watchdog.d.ts +1 -1
- package/dist/agent/reply-watchdog.js +2 -2
- package/dist/agent/reply-watchdog.js.map +1 -1
- package/dist/agent/runtime-surface.d.ts +2 -0
- package/dist/agent/runtime-surface.d.ts.map +1 -1
- package/dist/agent/runtime-surface.js +12 -2
- package/dist/agent/runtime-surface.js.map +1 -1
- package/dist/agent/status.js +1 -1
- package/dist/agent/status.js.map +1 -1
- package/dist/agent/stream-handler.d.ts.map +1 -1
- package/dist/agent/stream-handler.js +48 -22
- package/dist/agent/stream-handler.js.map +1 -1
- package/dist/agent/system-prompt.d.ts.map +1 -1
- package/dist/agent/system-prompt.js +10 -4
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/agent/wake-cycle-runner.d.ts +1 -1
- package/dist/agent/wake-cycle-runner.d.ts.map +1 -1
- package/dist/agent/wake-cycle-runner.js +2 -3
- package/dist/agent/wake-cycle-runner.js.map +1 -1
- package/dist/builtin-skills/rethinka-fund/SKILL.md +287 -28
- package/dist/builtin-skills/rethinka-fund/core-contract.md +30 -14
- package/dist/channels/interface.d.ts +0 -34
- package/dist/channels/interface.d.ts.map +1 -1
- package/dist/channels/manager.d.ts.map +1 -1
- package/dist/channels/manager.js +4 -0
- package/dist/channels/manager.js.map +1 -1
- package/dist/channels/qq.js +1 -1
- package/dist/channels/qq.js.map +1 -1
- package/dist/channels/rethinka-fund.d.ts +16 -3
- package/dist/channels/rethinka-fund.d.ts.map +1 -1
- package/dist/channels/rethinka-fund.js +180 -16
- package/dist/channels/rethinka-fund.js.map +1 -1
- package/dist/channels/telegram.js +1 -1
- package/dist/channels/telegram.js.map +1 -1
- package/dist/channels/tui-commands.js +1 -1
- package/dist/channels/tui-commands.js.map +1 -1
- package/dist/config/types.d.ts +4 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/obs/mini-app/status.d.ts.map +1 -1
- package/dist/obs/mini-app/status.js +63 -0
- package/dist/obs/mini-app/status.js.map +1 -1
- package/dist/obs/mini-app/telegram-auth.d.ts +23 -0
- package/dist/obs/mini-app/telegram-auth.d.ts.map +1 -0
- package/dist/obs/mini-app/telegram-auth.js +55 -0
- package/dist/obs/mini-app/telegram-auth.js.map +1 -0
- package/dist/obs/rdp/linux-x11-backend.d.ts +9 -0
- package/dist/obs/rdp/linux-x11-backend.d.ts.map +1 -1
- package/dist/obs/rdp/linux-x11-backend.js +69 -33
- package/dist/obs/rdp/linux-x11-backend.js.map +1 -1
- package/dist/obs/server.d.ts.map +1 -1
- package/dist/obs/server.js +29 -0
- package/dist/obs/server.js.map +1 -1
- package/dist/reconfigure.d.ts.map +1 -1
- package/dist/reconfigure.js +7 -1
- package/dist/reconfigure.js.map +1 -1
- package/dist/rethinka-fund/hyperliquid-signing.d.ts +56 -0
- package/dist/rethinka-fund/hyperliquid-signing.d.ts.map +1 -0
- package/dist/rethinka-fund/hyperliquid-signing.js +159 -0
- package/dist/rethinka-fund/hyperliquid-signing.js.map +1 -0
- package/dist/rethinka-fund/hyperliquid-trading.d.ts +154 -0
- package/dist/rethinka-fund/hyperliquid-trading.d.ts.map +1 -0
- package/dist/rethinka-fund/hyperliquid-trading.js +673 -0
- package/dist/rethinka-fund/hyperliquid-trading.js.map +1 -0
- package/dist/rethinka-fund/ibkr-flex.d.ts +49 -0
- package/dist/rethinka-fund/ibkr-flex.d.ts.map +1 -0
- package/dist/rethinka-fund/ibkr-flex.js +182 -0
- package/dist/rethinka-fund/ibkr-flex.js.map +1 -0
- package/dist/rethinka-fund/ibkr-mcp.d.ts +119 -0
- package/dist/rethinka-fund/ibkr-mcp.d.ts.map +1 -0
- package/dist/rethinka-fund/ibkr-mcp.js +418 -0
- package/dist/rethinka-fund/ibkr-mcp.js.map +1 -0
- package/dist/rethinka-fund/ibkr-sync.d.ts +30 -17
- package/dist/rethinka-fund/ibkr-sync.d.ts.map +1 -1
- package/dist/rethinka-fund/ibkr-sync.js +66 -31
- package/dist/rethinka-fund/ibkr-sync.js.map +1 -1
- package/dist/rethinka-fund/ibkr-trading.d.ts +102 -0
- package/dist/rethinka-fund/ibkr-trading.d.ts.map +1 -0
- package/dist/rethinka-fund/ibkr-trading.js +594 -0
- package/dist/rethinka-fund/ibkr-trading.js.map +1 -0
- package/dist/rethinka-fund/order-refresh.d.ts +66 -0
- package/dist/rethinka-fund/order-refresh.d.ts.map +1 -0
- package/dist/rethinka-fund/order-refresh.js +195 -0
- package/dist/rethinka-fund/order-refresh.js.map +1 -0
- package/dist/rethinka-fund/polymarket-redeem.d.ts +82 -0
- package/dist/rethinka-fund/polymarket-redeem.d.ts.map +1 -0
- package/dist/rethinka-fund/polymarket-redeem.js +353 -0
- package/dist/rethinka-fund/polymarket-redeem.js.map +1 -0
- package/dist/rethinka-fund/polymarket-trading.d.ts +61 -30
- package/dist/rethinka-fund/polymarket-trading.d.ts.map +1 -1
- package/dist/rethinka-fund/polymarket-trading.js +183 -71
- package/dist/rethinka-fund/polymarket-trading.js.map +1 -1
- package/dist/rethinka-fund/trading-common.d.ts +157 -0
- package/dist/rethinka-fund/trading-common.d.ts.map +1 -0
- package/dist/rethinka-fund/trading-common.js +237 -0
- package/dist/rethinka-fund/trading-common.js.map +1 -0
- package/dist/rethinka-fund-credentials.d.ts +2 -0
- package/dist/rethinka-fund-credentials.d.ts.map +1 -1
- package/dist/rethinka-fund-credentials.js +2 -0
- package/dist/rethinka-fund-credentials.js.map +1 -1
- package/dist/sites/manager.d.ts +50 -0
- package/dist/sites/manager.d.ts.map +1 -0
- package/dist/sites/manager.js +353 -0
- package/dist/sites/manager.js.map +1 -0
- package/dist/sites/pm2-injected-env.d.ts +49 -0
- package/dist/sites/pm2-injected-env.d.ts.map +1 -0
- package/dist/sites/pm2-injected-env.js +160 -0
- package/dist/sites/pm2-injected-env.js.map +1 -0
- package/dist/sites/process.d.ts +20 -0
- package/dist/sites/process.d.ts.map +1 -0
- package/dist/sites/process.js +122 -0
- package/dist/sites/process.js.map +1 -0
- package/dist/sites/registry.d.ts +79 -0
- package/dist/sites/registry.d.ts.map +1 -0
- package/dist/sites/registry.js +147 -0
- package/dist/sites/registry.js.map +1 -0
- package/dist/threads/execution-snapshot.d.ts +1 -0
- package/dist/threads/execution-snapshot.d.ts.map +1 -1
- package/dist/threads/foreground-task.d.ts +16 -3
- package/dist/threads/foreground-task.d.ts.map +1 -1
- package/dist/threads/foreground-task.js +57 -7
- package/dist/threads/foreground-task.js.map +1 -1
- package/dist/threads/foreman-execution.d.ts +14 -2
- package/dist/threads/foreman-execution.d.ts.map +1 -1
- package/dist/threads/foreman-execution.js +15 -3
- package/dist/threads/foreman-execution.js.map +1 -1
- package/dist/threads/foreman-host.d.ts +1 -0
- package/dist/threads/foreman-host.d.ts.map +1 -1
- package/dist/threads/foreman-host.js +27 -5
- package/dist/threads/foreman-host.js.map +1 -1
- package/dist/threads/foreman-protocol.d.ts +1 -0
- package/dist/threads/foreman-protocol.d.ts.map +1 -1
- package/dist/threads/foreman-protocol.js +2 -2
- package/dist/threads/foreman-protocol.js.map +1 -1
- package/dist/threads/foreman-write-contract.d.ts +1 -1
- package/dist/threads/foreman-write-contract.d.ts.map +1 -1
- package/dist/threads/foreman-write-contract.js +1 -1
- package/dist/threads/foreman-write-contract.js.map +1 -1
- package/dist/threads/supervisor.d.ts +2 -1
- package/dist/threads/supervisor.d.ts.map +1 -1
- package/dist/threads/supervisor.js +4 -1
- package/dist/threads/supervisor.js.map +1 -1
- package/dist/threads/thread-meta.d.ts +1 -0
- package/dist/threads/thread-meta.d.ts.map +1 -1
- package/dist/tools/delegation.d.ts.map +1 -1
- package/dist/tools/delegation.js +4 -1
- package/dist/tools/delegation.js.map +1 -1
- package/dist/tools/email.d.ts +1 -1
- package/dist/tools/event-trigger.d.ts +2 -2
- package/dist/tools/finish.d.ts.map +1 -1
- package/dist/tools/finish.js +5 -1
- package/dist/tools/finish.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/rethinka-fund-trading.d.ts +137 -1
- package/dist/tools/rethinka-fund-trading.d.ts.map +1 -1
- package/dist/tools/rethinka-fund-trading.js +102 -5
- package/dist/tools/rethinka-fund-trading.js.map +1 -1
- package/dist/tools/sites.d.ts +24 -0
- package/dist/tools/sites.d.ts.map +1 -0
- package/dist/tools/sites.js +61 -0
- package/dist/tools/sites.js.map +1 -0
- package/dist/tui/index.js +1 -1
- package/dist-agent/bundle.cjs +2 -2
- package/dist-agent/image-resize-worker.js +1 -0
- package/dist-agent/image-resize-worker.mjs +375 -0
- package/dist-agent/mcp-script-worker.mjs +6 -2
- package/package.json +8 -8
- package/dist/agent/fast-responder.d.ts +0 -52
- package/dist/agent/fast-responder.d.ts.map +0 -1
- package/dist/agent/fast-responder.js +0 -213
- package/dist/agent/fast-responder.js.map +0 -1
- package/dist/rethinka-fund/ibkr-collect.d.ts +0 -70
- package/dist/rethinka-fund/ibkr-collect.d.ts.map +0 -1
- package/dist/rethinka-fund/ibkr-collect.js +0 -180
- package/dist/rethinka-fund/ibkr-collect.js.map +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import https from "node:https";
|
|
5
|
+
import net from "node:net";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { isAgentUnderPm2, isPm2InjectedEnvKey, isPm2ProcessMarker } from "./pm2-injected-env.js";
|
|
8
|
+
export const PROBE_TIMEOUT_MS = 5_000;
|
|
9
|
+
export const LOOPBACK_HOSTNAME = /^(localhost|127\.0\.0\.1|\[::1\])$/;
|
|
10
|
+
const MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
11
|
+
/**
|
|
12
|
+
* Names that carry the Agent's own credentials. A site is model-written code,
|
|
13
|
+
* so it gets the environment a user shell would have, not the Agent's secrets.
|
|
14
|
+
*/
|
|
15
|
+
// PAT only as a whole word, so PATH survives.
|
|
16
|
+
const CREDENTIAL_ENV = /(KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH|COOKIE|SESSION|DSN|WEBHOOK)|(^|_)PAT(_|$)/i;
|
|
17
|
+
const AGENT_ENV_PREFIXES = ["VISIONCLAW_", "ANTHROPIC_", "OPENAI_", "AWS_", "CLAUDE_", "LLM_", "PI_", "FUND_LEAGUE_"];
|
|
18
|
+
/** A URL with a password in it (postgres://user:pass@host, http://user:pass@proxy). */
|
|
19
|
+
const URL_WITH_PASSWORD = /^[a-z][a-z0-9+.-]*:\/\/[^/@\s]*:[^/@\s]*@/i;
|
|
20
|
+
export function siteEnvironment(source, siteId) {
|
|
21
|
+
const underPm2 = isAgentUnderPm2(source);
|
|
22
|
+
const rawName = source.name;
|
|
23
|
+
const appName = underPm2 && typeof rawName === "string" && rawName.length > 0
|
|
24
|
+
? rawName
|
|
25
|
+
: null;
|
|
26
|
+
const env = {};
|
|
27
|
+
for (const [name, value] of Object.entries(source)) {
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
continue;
|
|
30
|
+
if (CREDENTIAL_ENV.test(name) || name.startsWith("PM2_") || name === "NODE_APP_INSTANCE" || URL_WITH_PASSWORD.test(value))
|
|
31
|
+
continue;
|
|
32
|
+
// Under PM2, strip every key PM2 flattened from pm2_env (schema + internals
|
|
33
|
+
// + pm_*/axm_*), plus CLI markers and the `{appName: "{}"}` slot God adds.
|
|
34
|
+
// Only drop the app-name key when its value is exactly "{}" — a real PATH
|
|
35
|
+
// (or HOME) must survive if the Agent happens to be named PATH.
|
|
36
|
+
// Outside PM2, leave ordinary names like `name` alone.
|
|
37
|
+
if (underPm2) {
|
|
38
|
+
if (isPm2InjectedEnvKey(name) || isPm2ProcessMarker(name))
|
|
39
|
+
continue;
|
|
40
|
+
if (appName !== null && name === appName && value === "{}")
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (AGENT_ENV_PREFIXES.some((prefix) => name.toUpperCase().startsWith(prefix)))
|
|
44
|
+
continue;
|
|
45
|
+
env[name] = value;
|
|
46
|
+
}
|
|
47
|
+
env.VISIONCLAW_SITE_ID = siteId;
|
|
48
|
+
return env;
|
|
49
|
+
}
|
|
50
|
+
const UNREACHABLE_CODES = new Set(["ECONNREFUSED", "EADDRNOTAVAIL", "ENETUNREACH", "EHOSTUNREACH", "EAFNOSUPPORT", "EPROTONOSUPPORT"]);
|
|
51
|
+
function connectionFailure(error) {
|
|
52
|
+
if (error instanceof AggregateError && error.errors.length > 0) {
|
|
53
|
+
return error.errors.every((cause) => cause instanceof Error && connectionFailure(cause) === "unreachable")
|
|
54
|
+
? "unreachable" : "unknown";
|
|
55
|
+
}
|
|
56
|
+
return UNREACHABLE_CODES.has(error.code ?? "") ? "unreachable" : "unknown";
|
|
57
|
+
}
|
|
58
|
+
function connects(host, port) {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const socket = net.connect({ host, port });
|
|
61
|
+
const done = (result) => {
|
|
62
|
+
socket.destroy();
|
|
63
|
+
resolve(result);
|
|
64
|
+
};
|
|
65
|
+
socket.setTimeout(PROBE_TIMEOUT_MS, () => done("unknown"));
|
|
66
|
+
socket.once("connect", () => done("running"));
|
|
67
|
+
socket.once("error", (error) => done(connectionFailure(error)));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function probe(check) {
|
|
71
|
+
if ("port" in check) {
|
|
72
|
+
const results = await Promise.all([connects("127.0.0.1", check.port), connects("::1", check.port)]);
|
|
73
|
+
if (results.includes("running"))
|
|
74
|
+
return "running";
|
|
75
|
+
return results.includes("unknown") ? "unknown" : "unreachable";
|
|
76
|
+
}
|
|
77
|
+
// Inspect the first response only. A local redirect may point outside the machine.
|
|
78
|
+
const url = new URL(check.healthUrl);
|
|
79
|
+
const client = url.protocol === "https:" ? https : http;
|
|
80
|
+
return new Promise((resolve) => {
|
|
81
|
+
const req = client.get(url, {
|
|
82
|
+
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS), agent: false,
|
|
83
|
+
rejectUnauthorized: !LOOPBACK_HOSTNAME.test(url.hostname),
|
|
84
|
+
}, (res) => {
|
|
85
|
+
const code = res.statusCode ?? 0;
|
|
86
|
+
res.destroy();
|
|
87
|
+
resolve(code >= 200 && code < 400 ? "running" : "unreachable");
|
|
88
|
+
});
|
|
89
|
+
req.once("upgrade", (_res, socket) => {
|
|
90
|
+
socket.destroy();
|
|
91
|
+
resolve("unknown");
|
|
92
|
+
});
|
|
93
|
+
req.once("error", (error) => resolve(connectionFailure(error)));
|
|
94
|
+
req.once("close", () => resolve("unknown"));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const launch = async (site, logFile) => {
|
|
98
|
+
fs.mkdirSync(path.dirname(logFile), { recursive: true });
|
|
99
|
+
if (fs.existsSync(logFile) && fs.statSync(logFile).size > MAX_LOG_BYTES)
|
|
100
|
+
fs.truncateSync(logFile, 0);
|
|
101
|
+
const log = fs.openSync(logFile, "a");
|
|
102
|
+
try {
|
|
103
|
+
fs.writeSync(log, `\n--- ${new Date().toISOString()} starting site ${site.siteId} ---\n`);
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
const child = spawn("/bin/sh", ["-c", site.restartCommand], {
|
|
106
|
+
cwd: site.cwd,
|
|
107
|
+
detached: true,
|
|
108
|
+
stdio: ["ignore", log, log],
|
|
109
|
+
env: siteEnvironment(process.env, site.siteId),
|
|
110
|
+
});
|
|
111
|
+
child.once("error", reject);
|
|
112
|
+
child.once("spawn", () => { child.unref(); resolve(); });
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
fs.closeSync(log);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
export function createSiteHost() {
|
|
120
|
+
return { now: Date.now, probe, launch };
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/sites/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAWjG,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,oC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
8
|
+
port: z.ZodNumber;
|
|
9
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
10
|
+
healthUrl: z.ZodURL;
|
|
11
|
+
}, z.core.$strict>]>;
|
|
12
|
+
restartCommand: z.ZodNullable<z.ZodString>;
|
|
13
|
+
cwd: z.ZodNullable<z.ZodString>;
|
|
14
|
+
autoRestart: z.ZodBoolean;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const IDEMPOTENCY_GUIDANCE = "Automatic recovery can run the restart command again while the service is already running, so the command must be idempotent. If the user has not already confirmed this exact command and working directory, show them both and ask the user to explicitly confirm that repeating it there will succeed without starting a second instance. After the user confirms, submit or retry with restartCommandIdempotent: true. Examples include docker compose up -d, systemctl --user start <unit>, launchctl kickstart, and pm2 start <ecosystem> for an already-running app of the same name.";
|
|
17
|
+
export declare const MIGRATION_NOTICE = "Reconfirm that the restart command is idempotent before enabling auto-restart.";
|
|
18
|
+
export declare const SITE_ERRORS: {
|
|
19
|
+
readonly unreachable: "The local site check failed.";
|
|
20
|
+
readonly unknown: "The local site check was inconclusive.";
|
|
21
|
+
readonly timeout: "The site did not become reachable within the startup window.";
|
|
22
|
+
readonly launch: "The restart command could not be started.";
|
|
23
|
+
readonly paused: "Automatic restart paused after three unsuccessful attempts.";
|
|
24
|
+
};
|
|
25
|
+
export declare const SiteAgentSchema: z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
profile: z.ZodString;
|
|
28
|
+
conversationId: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type SiteAgent = z.infer<typeof SiteAgentSchema>;
|
|
31
|
+
declare const SiteRecordSchema: z.ZodObject<{
|
|
32
|
+
siteId: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
requestedBy: z.ZodString;
|
|
35
|
+
url: z.ZodURL;
|
|
36
|
+
check: z.ZodUnion<readonly [z.ZodObject<{
|
|
37
|
+
port: z.ZodNumber;
|
|
38
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
39
|
+
healthUrl: z.ZodURL;
|
|
40
|
+
}, z.core.$strict>]>;
|
|
41
|
+
autoRestart: z.ZodBoolean;
|
|
42
|
+
restartCommand: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
cwd: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
44
|
+
agent: z.ZodObject<{
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
profile: z.ZodString;
|
|
47
|
+
conversationId: z.ZodString;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
status: z.ZodEnum<{
|
|
50
|
+
unknown: "unknown";
|
|
51
|
+
running: "running";
|
|
52
|
+
unreachable: "unreachable";
|
|
53
|
+
deleted: "deleted";
|
|
54
|
+
starting: "starting";
|
|
55
|
+
}>;
|
|
56
|
+
lastCheckedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
57
|
+
lastError: z.ZodNullable<z.ZodEnum<{
|
|
58
|
+
"Reconfirm that the restart command is idempotent before enabling auto-restart.": "Reconfirm that the restart command is idempotent before enabling auto-restart.";
|
|
59
|
+
"The local site check failed.": "The local site check failed.";
|
|
60
|
+
"The local site check was inconclusive.": "The local site check was inconclusive.";
|
|
61
|
+
"The site did not become reachable within the startup window.": "The site did not become reachable within the startup window.";
|
|
62
|
+
"The restart command could not be started.": "The restart command could not be started.";
|
|
63
|
+
"Automatic restart paused after three unsuccessful attempts.": "Automatic restart paused after three unsuccessful attempts.";
|
|
64
|
+
}>>;
|
|
65
|
+
lastErrorDetail: z.ZodNullable<z.ZodString>;
|
|
66
|
+
recoveryAttempts: z.ZodNumber;
|
|
67
|
+
lastRecoveredAt: z.ZodDefault<z.ZodNullable<z.ZodISODateTime>>;
|
|
68
|
+
recoveryCount: z.ZodDefault<z.ZodNumber>;
|
|
69
|
+
recoveryPending: z.ZodDefault<z.ZodBoolean>;
|
|
70
|
+
nextAttemptAt: z.ZodNullable<z.ZodISODateTime>;
|
|
71
|
+
lastLaunchAt: z.ZodNullable<z.ZodISODateTime>;
|
|
72
|
+
deletedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
export type SiteRecord = z.infer<typeof SiteRecordSchema>;
|
|
75
|
+
export declare function writeRegistry(file: string, sites: Iterable<SiteRecord>): void;
|
|
76
|
+
export declare function readRegistryOnly(file: string): SiteRecord[];
|
|
77
|
+
export declare function readRegistry(file: string): SiteRecord[];
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/sites/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkBxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;iBASrB,CAAC;AAEH,eAAO,MAAM,oBAAoB,ikBAAikB,CAAC;AACnmB,eAAO,MAAM,gBAAgB,mFAAmF,CAAC;AACjH,eAAO,MAAM,WAAW;;;;;;CAMd,CAAC;AAEX,eAAO,MAAM,eAAe;;;;iBAAgE,CAAC;AAC7F,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAGxD,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkBlB,CAAC;AACL,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAwB1D,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,IAAI,CAE7E;AAyCD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAI3D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAqBvD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { logger } from "../logger.js";
|
|
5
|
+
import { writeJsonAtomically } from "../utils/atomic-json.js";
|
|
6
|
+
import { LOOPBACK_HOSTNAME } from "./process.js";
|
|
7
|
+
const port = z.number().int().min(1).max(65535);
|
|
8
|
+
const url = z.url({ protocol: /^https?$/, error: "Expected an http(s) URL" });
|
|
9
|
+
const healthUrl = z.url({
|
|
10
|
+
protocol: /^https?$/,
|
|
11
|
+
hostname: LOOPBACK_HOSTNAME,
|
|
12
|
+
error: "healthUrl must use HTTP(S) on 127.0.0.1, localhost or [::1]",
|
|
13
|
+
});
|
|
14
|
+
const check = z.union([z.strictObject({ port }), z.strictObject({ healthUrl })]);
|
|
15
|
+
const text = z.string().trim().min(1);
|
|
16
|
+
const command = text.max(2000);
|
|
17
|
+
const cwd = z.string().refine((value) => path.isAbsolute(value), "cwd must be an absolute path");
|
|
18
|
+
const timestamp = z.iso.datetime().nullable();
|
|
19
|
+
export const SiteFields = z.object({
|
|
20
|
+
siteId: z.string().regex(/^[a-z0-9][a-z0-9-]{0,62}$/, "Expected a lowercase slug of up to 63 characters"),
|
|
21
|
+
name: text.max(100),
|
|
22
|
+
requestedBy: text,
|
|
23
|
+
url,
|
|
24
|
+
check,
|
|
25
|
+
restartCommand: command.nullable(),
|
|
26
|
+
cwd: cwd.nullable(),
|
|
27
|
+
autoRestart: z.boolean(),
|
|
28
|
+
});
|
|
29
|
+
export const IDEMPOTENCY_GUIDANCE = "Automatic recovery can run the restart command again while the service is already running, so the command must be idempotent. If the user has not already confirmed this exact command and working directory, show them both and ask the user to explicitly confirm that repeating it there will succeed without starting a second instance. After the user confirms, submit or retry with restartCommandIdempotent: true. Examples include docker compose up -d, systemctl --user start <unit>, launchctl kickstart, and pm2 start <ecosystem> for an already-running app of the same name.";
|
|
30
|
+
export const MIGRATION_NOTICE = "Reconfirm that the restart command is idempotent before enabling auto-restart.";
|
|
31
|
+
export const SITE_ERRORS = {
|
|
32
|
+
unreachable: "The local site check failed.",
|
|
33
|
+
unknown: "The local site check was inconclusive.",
|
|
34
|
+
timeout: "The site did not become reachable within the startup window.",
|
|
35
|
+
launch: "The restart command could not be started.",
|
|
36
|
+
paused: "Automatic restart paused after three unsuccessful attempts.",
|
|
37
|
+
};
|
|
38
|
+
export const SiteAgentSchema = z.object({ name: text, profile: text, conversationId: text });
|
|
39
|
+
const knownError = z.enum([...Object.values(SITE_ERRORS), MIGRATION_NOTICE]);
|
|
40
|
+
const SiteRecordSchema = SiteFields.extend({
|
|
41
|
+
restartCommand: command.nullable().default(null),
|
|
42
|
+
cwd: cwd.nullable().default(null),
|
|
43
|
+
agent: SiteAgentSchema,
|
|
44
|
+
status: z.enum(["unknown", "running", "unreachable", "starting", "deleted"]),
|
|
45
|
+
lastCheckedAt: timestamp,
|
|
46
|
+
lastError: knownError.nullable(),
|
|
47
|
+
lastErrorDetail: z.string().nullable(),
|
|
48
|
+
recoveryAttempts: z.number().int().nonnegative(),
|
|
49
|
+
lastRecoveredAt: timestamp.default(null),
|
|
50
|
+
recoveryCount: z.number().int().nonnegative().default(0),
|
|
51
|
+
recoveryPending: z.boolean().default(false),
|
|
52
|
+
nextAttemptAt: timestamp,
|
|
53
|
+
lastLaunchAt: timestamp,
|
|
54
|
+
deletedAt: timestamp,
|
|
55
|
+
}).refine((site) => (site.restartCommand === null) === (site.cwd === null), "Provide restartCommand and cwd together")
|
|
56
|
+
.refine((site) => (site.status === "deleted") === (site.deletedAt !== null), {
|
|
57
|
+
path: ["deletedAt"], message: "Set deletedAt exactly when status is deleted",
|
|
58
|
+
});
|
|
59
|
+
const storedSite = z.preprocess((value) => {
|
|
60
|
+
if (value && typeof value === "object" && "lastError" in value
|
|
61
|
+
&& typeof value.lastError === "string" && !knownError.safeParse(value.lastError).success) {
|
|
62
|
+
return { ...value, lastError: null, lastErrorDetail: null };
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}, SiteRecordSchema);
|
|
66
|
+
const legacySite = z.object({
|
|
67
|
+
siteId: SiteFields.shape.siteId, name: SiteFields.shape.name, url,
|
|
68
|
+
localPort: port.optional(), port: port.optional(), startCommand: command, cwd,
|
|
69
|
+
status: z.enum(["unknown", "running", "unreachable", "starting", "stopped", "deleted"]),
|
|
70
|
+
lastCheckedAt: timestamp, deletedAt: timestamp,
|
|
71
|
+
}).transform((site) => ({
|
|
72
|
+
siteId: site.siteId, name: site.name, url: site.url, check: { port: site.localPort ?? site.port },
|
|
73
|
+
requestedBy: "未知", agent: { name: "未知", profile: "未知", conversationId: "未知" },
|
|
74
|
+
restartCommand: site.startCommand, cwd: site.cwd, autoRestart: false,
|
|
75
|
+
status: site.status === "stopped" || site.status === "starting" ? "unknown" : site.status,
|
|
76
|
+
lastCheckedAt: site.lastCheckedAt, lastError: MIGRATION_NOTICE, lastErrorDetail: null,
|
|
77
|
+
recoveryAttempts: 0, nextAttemptAt: null, lastLaunchAt: null, deletedAt: site.deletedAt,
|
|
78
|
+
})).pipe(SiteRecordSchema);
|
|
79
|
+
export function writeRegistry(file, sites) {
|
|
80
|
+
writeJsonAtomically(file, { version: 2, sites: z.array(SiteRecordSchema).parse([...sites]) });
|
|
81
|
+
}
|
|
82
|
+
const header = z.object({ version: z.union([z.literal(1), z.literal(2)]), sites: z.array(z.unknown()) });
|
|
83
|
+
function parseRegistryFile(file) {
|
|
84
|
+
let contents;
|
|
85
|
+
try {
|
|
86
|
+
contents = fs.readFileSync(file, "utf8");
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (error.code === "ENOENT")
|
|
90
|
+
return { version: 2, sites: [], rejected: [] };
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
let json;
|
|
94
|
+
try {
|
|
95
|
+
json = JSON.parse(contents);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const parsed = header.safeParse(json);
|
|
101
|
+
if (!parsed.success)
|
|
102
|
+
return null;
|
|
103
|
+
const { version } = parsed.data;
|
|
104
|
+
const schema = version === 1 ? legacySite : storedSite;
|
|
105
|
+
const sitesById = new Map();
|
|
106
|
+
const rejected = [];
|
|
107
|
+
for (const raw of parsed.data.sites) {
|
|
108
|
+
const record = schema.safeParse(raw);
|
|
109
|
+
if (!record.success || sitesById.has(record.data.siteId)) {
|
|
110
|
+
rejected.push(raw);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
sitesById.set(record.data.siteId, record.data);
|
|
114
|
+
}
|
|
115
|
+
return { version, sites: [...sitesById.values()], rejected };
|
|
116
|
+
}
|
|
117
|
+
export function readRegistryOnly(file) {
|
|
118
|
+
const data = parseRegistryFile(file);
|
|
119
|
+
if (!data)
|
|
120
|
+
throw new Error("Unreadable site registry");
|
|
121
|
+
return data.sites;
|
|
122
|
+
}
|
|
123
|
+
export function readRegistry(file) {
|
|
124
|
+
const data = parseRegistryFile(file);
|
|
125
|
+
if (!data) {
|
|
126
|
+
const aside = `${file}.corrupt-${Date.now()}`;
|
|
127
|
+
fs.renameSync(file, aside);
|
|
128
|
+
logger.warn(`[sites] Unreadable registry moved to ${aside}`);
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
if (data.rejected.length) {
|
|
132
|
+
const aside = `${file}.rejected-${Date.now()}.json`;
|
|
133
|
+
writeJsonAtomically(aside, data.rejected);
|
|
134
|
+
logger.warn(`[sites] Saved ${data.rejected.length} rejected site records to ${aside}`);
|
|
135
|
+
try {
|
|
136
|
+
writeRegistry(file, data.sites);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
logger.warn(`[sites] Could not write back valid site records to ${file}: ${String(error)}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (data.version === 1) {
|
|
143
|
+
writeRegistry(file, data.sites);
|
|
144
|
+
}
|
|
145
|
+
return data.sites;
|
|
146
|
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AO,IAAI,CAAC,KAAK,CAAC;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-snapshot.d.ts","sourceRoot":"","sources":["../../src/threads/execution-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,eAAO,MAAM,2BAA2B;;;;kBAO7B,CAAC;AAEZ,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,eAAO,MAAM,yBAAyB
|
|
1
|
+
{"version":3,"file":"execution-snapshot.d.ts","sourceRoot":"","sources":["../../src/threads/execution-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,eAAO,MAAM,2BAA2B;;;;kBAO7B,CAAC;AAEZ,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAiB3B,CAAC;AAEZ,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,qBAIpC,CAAC;AAEF,qFAAqF;AACrF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,iBAAiB,CAKtE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5D,OAAO,EAAE,UAAU,GAAG,IAAI,EAC1B,QAAQ,EAAE,MAAM,GACf,iBAAiB,CAAC,OAAO,CAAC,CAmB5B;AAED,eAAO,MAAM,sBAAsB,kCAAkC,CAAC;AAEtE,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,GAAG,uBAAuB,CAGjH;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAgB/F;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAkB/G"}
|
|
@@ -3,12 +3,12 @@ import type { TaskSettlement } from "./task-settlement.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* General's foreground work counter (#2805 stage 3, Foreman).
|
|
5
5
|
*
|
|
6
|
-
* While Foreman is on, one logical task
|
|
6
|
+
* While Foreman is on, one logical task starts with
|
|
7
7
|
* {@link FOREGROUND_TOOL_CALL_LIMIT} task tool calls in General's foreground.
|
|
8
8
|
* A fourth call is refused at the engine's tool entry, before it starts, so
|
|
9
9
|
* the threshold does not depend on the prompt: the model hands the remaining
|
|
10
10
|
* work to a background worker with `delegate_task`, which carries this count
|
|
11
|
-
* over.
|
|
11
|
+
* over. An external write restricted to General can receive one extension.
|
|
12
12
|
*
|
|
13
13
|
* Only tools a background worker can run count: files, shell, web reading,
|
|
14
14
|
* memory and subagents. Coordination (dispatch, task status, input, cancel,
|
|
@@ -21,12 +21,14 @@ import type { TaskSettlement } from "./task-settlement.js";
|
|
|
21
21
|
*
|
|
22
22
|
* The record is persisted in the thread directory, so a new message, a new
|
|
23
23
|
* model turn, a context refresh or a restart does not reset it. It is cleared
|
|
24
|
-
* when the task ends
|
|
24
|
+
* when the task ends, or when a user replies after an explicit wait for input.
|
|
25
25
|
* After a handoff the task belongs to the worker: further task calls are
|
|
26
26
|
* refused until the turn finishes, so General and the worker never both
|
|
27
27
|
* write for it.
|
|
28
28
|
*/
|
|
29
29
|
export declare const FOREGROUND_TOOL_CALL_LIMIT = 3;
|
|
30
|
+
/** One extension per foreground task, for a total of 10 counted calls. */
|
|
31
|
+
export declare const FOREGROUND_FINAL_WRITE_EXTRA_CALLS = 7;
|
|
30
32
|
export declare const FOREGROUND_TASK_FILE = "foreground-task.json";
|
|
31
33
|
declare const RecordSchema: z.ZodObject<{
|
|
32
34
|
taskId: z.ZodString;
|
|
@@ -34,6 +36,9 @@ declare const RecordSchema: z.ZodObject<{
|
|
|
34
36
|
startedAt: z.ZodString;
|
|
35
37
|
calls: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
36
38
|
handedOff: z.ZodDefault<z.ZodBoolean>;
|
|
39
|
+
refusedAtLimit: z.ZodDefault<z.ZodBoolean>;
|
|
40
|
+
awaitingUser: z.ZodDefault<z.ZodBoolean>;
|
|
41
|
+
extraCalls: z.ZodDefault<z.ZodNumber>;
|
|
37
42
|
accountedToolCalls: z.ZodDefault<z.ZodNumber>;
|
|
38
43
|
}, z.core.$strict>;
|
|
39
44
|
export type ForegroundTaskRecord = z.infer<typeof RecordSchema>;
|
|
@@ -65,6 +70,7 @@ export declare class ForegroundTaskTracker {
|
|
|
65
70
|
private handedOffIds;
|
|
66
71
|
/** Replies held back this wake as stale; the first one also told the model why. */
|
|
67
72
|
private heldStale;
|
|
73
|
+
private heldFinish;
|
|
68
74
|
private record;
|
|
69
75
|
private readonly filePath;
|
|
70
76
|
/**
|
|
@@ -76,6 +82,8 @@ export declare class ForegroundTaskTracker {
|
|
|
76
82
|
constructor(dir: string, now?: () => Date, isExempt?: () => boolean, settled?: (taskId: string) => TaskSettlement | undefined);
|
|
77
83
|
get current(): ForegroundTaskRecord | null;
|
|
78
84
|
get unassignedToolCalls(): number;
|
|
85
|
+
private get callLimit();
|
|
86
|
+
get remainingToolCalls(): number;
|
|
79
87
|
/**
|
|
80
88
|
* Admit one tool call at the engine's tool entry. Calls that are not
|
|
81
89
|
* foreground task work are always admitted and never counted. Task work is
|
|
@@ -84,6 +92,11 @@ export declare class ForegroundTaskTracker {
|
|
|
84
92
|
admit(toolName: string): ForegroundAdmission;
|
|
85
93
|
/** The current task, created when no task call has been made yet, for a handoff. */
|
|
86
94
|
taskForHandoff(): ForegroundTaskRecord;
|
|
95
|
+
finishGate(awaitingUser: boolean): string | null;
|
|
96
|
+
/** Bind the host's refusal to the task that requested it, even if the reply arrives late. */
|
|
97
|
+
grantFinalWrite(taskId?: string | undefined): boolean;
|
|
98
|
+
markAwaitingUser(): void;
|
|
99
|
+
noteUserMessage(): void;
|
|
87
100
|
/**
|
|
88
101
|
* The worker accepted the task: General must not keep writing for it.
|
|
89
102
|
* `acceptedTaskIds` are the ids the host admitted (a batch admits several),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreground-task.d.ts","sourceRoot":"","sources":["../../src/threads/foreground-task.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,0B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AO,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAmBvI,kCAAkC;IAClC,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED;;;;;OAKG;IACH,SAAS,IAAI,IAAI;IAOjB,sDAAsD;IACtD,KAAK,IAAI,IAAI;IAYb,OAAO,CAAC,MAAM;IAed,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,IAAI;CAGb;AAID,+EAA+E;AAC/E,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,GAAG,IAAI,CAExF;AAED,wBAAgB,wBAAwB,IAAI,qBAAqB,GAAG,IAAI,CAEvE"}
|
|
@@ -8,12 +8,12 @@ import { isConnectorToolName } from "../agent/connectors.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* General's foreground work counter (#2805 stage 3, Foreman).
|
|
10
10
|
*
|
|
11
|
-
* While Foreman is on, one logical task
|
|
11
|
+
* While Foreman is on, one logical task starts with
|
|
12
12
|
* {@link FOREGROUND_TOOL_CALL_LIMIT} task tool calls in General's foreground.
|
|
13
13
|
* A fourth call is refused at the engine's tool entry, before it starts, so
|
|
14
14
|
* the threshold does not depend on the prompt: the model hands the remaining
|
|
15
15
|
* work to a background worker with `delegate_task`, which carries this count
|
|
16
|
-
* over.
|
|
16
|
+
* over. An external write restricted to General can receive one extension.
|
|
17
17
|
*
|
|
18
18
|
* Only tools a background worker can run count: files, shell, web reading,
|
|
19
19
|
* memory and subagents. Coordination (dispatch, task status, input, cancel,
|
|
@@ -26,12 +26,14 @@ import { isConnectorToolName } from "../agent/connectors.js";
|
|
|
26
26
|
*
|
|
27
27
|
* The record is persisted in the thread directory, so a new message, a new
|
|
28
28
|
* model turn, a context refresh or a restart does not reset it. It is cleared
|
|
29
|
-
* when the task ends
|
|
29
|
+
* when the task ends, or when a user replies after an explicit wait for input.
|
|
30
30
|
* After a handoff the task belongs to the worker: further task calls are
|
|
31
31
|
* refused until the turn finishes, so General and the worker never both
|
|
32
32
|
* write for it.
|
|
33
33
|
*/
|
|
34
34
|
export const FOREGROUND_TOOL_CALL_LIMIT = 3;
|
|
35
|
+
/** One extension per foreground task, for a total of 10 counted calls. */
|
|
36
|
+
export const FOREGROUND_FINAL_WRITE_EXTRA_CALLS = 7;
|
|
35
37
|
export const FOREGROUND_TASK_FILE = "foreground-task.json";
|
|
36
38
|
/** Bare tool names (`mcp__visionclaw__memory` → `memory`) that count as foreground task work. */
|
|
37
39
|
const DELEGABLE_TOOLS = new Set([
|
|
@@ -56,6 +58,9 @@ const RecordSchema = z.object({
|
|
|
56
58
|
calls: z.array(z.string()).default([]),
|
|
57
59
|
/** Set once the task was handed to a background worker. */
|
|
58
60
|
handedOff: z.boolean().default(false),
|
|
61
|
+
refusedAtLimit: z.boolean().default(false),
|
|
62
|
+
awaitingUser: z.boolean().default(false),
|
|
63
|
+
extraCalls: z.number().int().nonnegative().default(0),
|
|
59
64
|
accountedToolCalls: z.number().int().nonnegative().default(0),
|
|
60
65
|
}).strict();
|
|
61
66
|
export function bareToolName(toolName) {
|
|
@@ -91,6 +96,7 @@ export class ForegroundTaskTracker {
|
|
|
91
96
|
handedOffIds = [];
|
|
92
97
|
/** Replies held back this wake as stale; the first one also told the model why. */
|
|
93
98
|
heldStale = null;
|
|
99
|
+
heldFinish = false;
|
|
94
100
|
record;
|
|
95
101
|
filePath;
|
|
96
102
|
/**
|
|
@@ -112,6 +118,12 @@ export class ForegroundTaskTracker {
|
|
|
112
118
|
get unassignedToolCalls() {
|
|
113
119
|
return this.record ? Math.max(0, this.record.toolCallsUsed - this.record.accountedToolCalls) : 0;
|
|
114
120
|
}
|
|
121
|
+
get callLimit() {
|
|
122
|
+
return FOREGROUND_TOOL_CALL_LIMIT + (this.record?.extraCalls ?? 0);
|
|
123
|
+
}
|
|
124
|
+
get remainingToolCalls() {
|
|
125
|
+
return Math.max(0, this.callLimit - (this.record?.toolCallsUsed ?? 0));
|
|
126
|
+
}
|
|
115
127
|
/**
|
|
116
128
|
* Admit one tool call at the engine's tool entry. Calls that are not
|
|
117
129
|
* foreground task work are always admitted and never counted. Task work is
|
|
@@ -130,15 +142,21 @@ export class ForegroundTaskTracker {
|
|
|
130
142
|
reason: "Heavy work from this turn has been delegated. You may delegate more independent Tasks, coordinate their work, or reply. Send changes to existing Tasks with background_task_input; do not duplicate their file/shell work here.",
|
|
131
143
|
};
|
|
132
144
|
}
|
|
133
|
-
if (record.toolCallsUsed >=
|
|
145
|
+
if (record.toolCallsUsed >= this.callLimit) {
|
|
146
|
+
if (!record.refusedAtLimit) {
|
|
147
|
+
record.refusedAtLimit = true;
|
|
148
|
+
this.save();
|
|
149
|
+
}
|
|
134
150
|
return {
|
|
135
151
|
allowed: false,
|
|
136
152
|
taskId: record.taskId,
|
|
137
153
|
toolCallsUsed: record.toolCallsUsed,
|
|
138
154
|
reason: [
|
|
139
|
-
`Foreground limit reached: this task already used ${record.toolCallsUsed} of ${
|
|
140
|
-
"
|
|
141
|
-
|
|
155
|
+
`Foreground limit reached: this task already used ${record.toolCallsUsed} of ${this.callLimit} task tool calls in the conversation.`,
|
|
156
|
+
"Answer if ready, or ask for any missing user input. Hand off remaining work with delegate_task, required_tools and external_write_mode=none. For an external write, delegate investigation and drafting with external_write_mode=prepare, then perform the separately authorized final write in a fresh turn when the result arrives.",
|
|
157
|
+
record.extraCalls === 0
|
|
158
|
+
? "If only the final write remains, declare it with delegate_task(external_write_mode=execute). The handoff will be refused and you can continue the authorized write here."
|
|
159
|
+
: "The final-write allowance is spent. If you cannot finish, use notify_user to explain what remains and what you need, then finish with awaiting_user=true.",
|
|
142
160
|
].join(" "),
|
|
143
161
|
};
|
|
144
162
|
}
|
|
@@ -153,6 +171,33 @@ export class ForegroundTaskTracker {
|
|
|
153
171
|
this.save();
|
|
154
172
|
return { ...record, calls: [...record.calls] };
|
|
155
173
|
}
|
|
174
|
+
finishGate(awaitingUser) {
|
|
175
|
+
if (!this.record?.refusedAtLimit || this.record.handedOff || this.handedOffIds.length > 0 ||
|
|
176
|
+
awaitingUser || this.record.awaitingUser || this.heldFinish || this.isExempt())
|
|
177
|
+
return null;
|
|
178
|
+
this.heldFinish = true;
|
|
179
|
+
return "Finish held once: this task hit the foreground limit with work left and nothing was handed off, so nothing continues after this turn. Choose one: (1) hand the remaining work off with delegate_task; (2) if you cannot go on, tell the user with notify_user exactly what is not done and what you need from them, then call finish with awaiting_user=true; (3) if the request is in fact fully answered, call finish again. Do not promise to continue in a later turn: no later turn is scheduled.";
|
|
180
|
+
}
|
|
181
|
+
/** Bind the host's refusal to the task that requested it, even if the reply arrives late. */
|
|
182
|
+
grantFinalWrite(taskId = this.record?.taskId) {
|
|
183
|
+
const record = this.record;
|
|
184
|
+
if (!record || record.taskId !== taskId || record.handedOff || record.extraCalls > 0)
|
|
185
|
+
return false;
|
|
186
|
+
record.extraCalls = FOREGROUND_FINAL_WRITE_EXTRA_CALLS;
|
|
187
|
+
record.refusedAtLimit = false;
|
|
188
|
+
this.save();
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
markAwaitingUser() {
|
|
192
|
+
if (this.record) {
|
|
193
|
+
this.record.awaitingUser = true;
|
|
194
|
+
this.save();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
noteUserMessage() {
|
|
198
|
+
if (this.record?.awaitingUser)
|
|
199
|
+
this.reset();
|
|
200
|
+
}
|
|
156
201
|
/**
|
|
157
202
|
* The worker accepted the task: General must not keep writing for it.
|
|
158
203
|
* `acceptedTaskIds` are the ids the host admitted (a batch admits several),
|
|
@@ -223,6 +268,7 @@ export class ForegroundTaskTracker {
|
|
|
223
268
|
* foreground keeps its count across wakes.
|
|
224
269
|
*/
|
|
225
270
|
beginWake() {
|
|
271
|
+
this.heldFinish = false;
|
|
226
272
|
this.handedOffIds = [];
|
|
227
273
|
this.heldStale = null;
|
|
228
274
|
if (this.record?.handedOff)
|
|
@@ -230,6 +276,7 @@ export class ForegroundTaskTracker {
|
|
|
230
276
|
}
|
|
231
277
|
/** The task ended: the next task starts from zero. */
|
|
232
278
|
reset() {
|
|
279
|
+
this.heldFinish = false;
|
|
233
280
|
this.record = null;
|
|
234
281
|
this.handedOffIds = [];
|
|
235
282
|
this.heldStale = null;
|
|
@@ -247,6 +294,9 @@ export class ForegroundTaskTracker {
|
|
|
247
294
|
startedAt: this.now().toISOString(),
|
|
248
295
|
calls: [],
|
|
249
296
|
handedOff: false,
|
|
297
|
+
refusedAtLimit: false,
|
|
298
|
+
awaitingUser: false,
|
|
299
|
+
extraCalls: 0,
|
|
250
300
|
accountedToolCalls: 0,
|
|
251
301
|
};
|
|
252
302
|
return this.record;
|