@bryti/agent 0.0.1 → 0.1.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/Dockerfile +27 -0
- package/README.md +77 -50
- package/config.example.yml +265 -0
- package/dist/active-hours.d.ts +23 -0
- package/dist/active-hours.d.ts.map +1 -0
- package/dist/active-hours.js +68 -0
- package/dist/active-hours.js.map +1 -0
- package/dist/agent.d.ts +84 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +383 -0
- package/dist/agent.js.map +1 -0
- package/dist/channels/markdown/ir.d.ts +79 -0
- package/dist/channels/markdown/ir.d.ts.map +1 -0
- package/dist/channels/markdown/ir.js +824 -0
- package/dist/channels/markdown/ir.js.map +1 -0
- package/dist/channels/markdown/render.d.ts +35 -0
- package/dist/channels/markdown/render.d.ts.map +1 -0
- package/dist/channels/markdown/render.js +178 -0
- package/dist/channels/markdown/render.js.map +1 -0
- package/dist/channels/telegram-network-errors.d.ts +27 -0
- package/dist/channels/telegram-network-errors.d.ts.map +1 -0
- package/dist/channels/telegram-network-errors.js +156 -0
- package/dist/channels/telegram-network-errors.js.map +1 -0
- package/dist/channels/telegram.d.ts +76 -0
- package/dist/channels/telegram.d.ts.map +1 -0
- package/dist/channels/telegram.js +814 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/types.d.ts +59 -0
- package/dist/channels/types.d.ts.map +1 -0
- package/dist/channels/types.js +9 -0
- package/dist/channels/types.js.map +1 -0
- package/dist/channels/whatsapp.d.ts +45 -0
- package/dist/channels/whatsapp.d.ts.map +1 -0
- package/dist/channels/whatsapp.js +310 -0
- package/dist/channels/whatsapp.js.map +1 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +635 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +35 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +113 -0
- package/dist/commands.js.map +1 -0
- package/dist/compaction/history.d.ts +17 -0
- package/dist/compaction/history.d.ts.map +1 -0
- package/dist/compaction/history.js +35 -0
- package/dist/compaction/history.js.map +1 -0
- package/dist/compaction/index.d.ts +3 -0
- package/dist/compaction/index.d.ts.map +1 -0
- package/dist/compaction/index.js +3 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/proactive.d.ts +25 -0
- package/dist/compaction/proactive.d.ts.map +1 -0
- package/dist/compaction/proactive.js +87 -0
- package/dist/compaction/proactive.js.map +1 -0
- package/dist/compaction/transcript-repair.d.ts +55 -0
- package/dist/compaction/transcript-repair.d.ts.map +1 -0
- package/dist/compaction/transcript-repair.js +215 -0
- package/dist/compaction/transcript-repair.js.map +1 -0
- package/dist/config.d.ts +128 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +317 -0
- package/dist/config.js.map +1 -0
- package/dist/crash-recovery.d.ts +23 -0
- package/dist/crash-recovery.d.ts.map +1 -0
- package/dist/crash-recovery.js +96 -0
- package/dist/crash-recovery.js.map +1 -0
- package/dist/defaults/extensions/EXTENSIONS.md +158 -0
- package/dist/defaults/extensions/documents-hedgedoc.ts +153 -0
- package/dist/history.d.ts +31 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +49 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +673 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +39 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +143 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory/conversation-search.d.ts +15 -0
- package/dist/memory/conversation-search.d.ts.map +1 -0
- package/dist/memory/conversation-search.js +60 -0
- package/dist/memory/conversation-search.js.map +1 -0
- package/dist/memory/core-memory.d.ts +28 -0
- package/dist/memory/core-memory.d.ts.map +1 -0
- package/dist/memory/core-memory.js +102 -0
- package/dist/memory/core-memory.js.map +1 -0
- package/dist/memory/embeddings.d.ts +44 -0
- package/dist/memory/embeddings.d.ts.map +1 -0
- package/dist/memory/embeddings.js +139 -0
- package/dist/memory/embeddings.js.map +1 -0
- package/dist/memory/search.d.ts +49 -0
- package/dist/memory/search.d.ts.map +1 -0
- package/dist/memory/search.js +97 -0
- package/dist/memory/search.js.map +1 -0
- package/dist/memory/store.d.ts +32 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +205 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/message-queue.d.ts +73 -0
- package/dist/message-queue.d.ts.map +1 -0
- package/dist/message-queue.js +188 -0
- package/dist/message-queue.js.map +1 -0
- package/dist/model-infra.d.ts +64 -0
- package/dist/model-infra.d.ts.map +1 -0
- package/dist/model-infra.js +202 -0
- package/dist/model-infra.js.map +1 -0
- package/dist/projection/format.d.ts +10 -0
- package/dist/projection/format.d.ts.map +1 -0
- package/dist/projection/format.js +30 -0
- package/dist/projection/format.js.map +1 -0
- package/dist/projection/index.d.ts +11 -0
- package/dist/projection/index.d.ts.map +1 -0
- package/dist/projection/index.js +9 -0
- package/dist/projection/index.js.map +1 -0
- package/dist/projection/reflection.d.ts +94 -0
- package/dist/projection/reflection.d.ts.map +1 -0
- package/dist/projection/reflection.js +334 -0
- package/dist/projection/reflection.js.map +1 -0
- package/dist/projection/store.d.ts +144 -0
- package/dist/projection/store.d.ts.map +1 -0
- package/dist/projection/store.js +519 -0
- package/dist/projection/store.js.map +1 -0
- package/dist/projection/tools.d.ts +11 -0
- package/dist/projection/tools.d.ts.map +1 -0
- package/dist/projection/tools.js +237 -0
- package/dist/projection/tools.js.map +1 -0
- package/dist/scheduler.d.ts +36 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +286 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/system-prompt.d.ts +41 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/system-prompt.js +162 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/time.d.ts +52 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +138 -0
- package/dist/time.js.map +1 -0
- package/dist/tools/archival-memory-tool.d.ts +8 -0
- package/dist/tools/archival-memory-tool.d.ts.map +1 -0
- package/dist/tools/archival-memory-tool.js +68 -0
- package/dist/tools/archival-memory-tool.js.map +1 -0
- package/dist/tools/conversation-search-tool.d.ts +6 -0
- package/dist/tools/conversation-search-tool.d.ts.map +1 -0
- package/dist/tools/conversation-search-tool.js +28 -0
- package/dist/tools/conversation-search-tool.js.map +1 -0
- package/dist/tools/core-memory-tool.d.ts +7 -0
- package/dist/tools/core-memory-tool.d.ts.map +1 -0
- package/dist/tools/core-memory-tool.js +59 -0
- package/dist/tools/core-memory-tool.js.map +1 -0
- package/dist/tools/fetch-url.d.ts +15 -0
- package/dist/tools/fetch-url.d.ts.map +1 -0
- package/dist/tools/fetch-url.js +76 -0
- package/dist/tools/fetch-url.js.map +1 -0
- package/dist/tools/files.d.ts +10 -0
- package/dist/tools/files.d.ts.map +1 -0
- package/dist/tools/files.js +127 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +118 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/result.d.ts +21 -0
- package/dist/tools/result.d.ts.map +1 -0
- package/dist/tools/result.js +36 -0
- package/dist/tools/result.js.map +1 -0
- package/dist/tools/skill-install.d.ts +17 -0
- package/dist/tools/skill-install.d.ts.map +1 -0
- package/dist/tools/skill-install.js +148 -0
- package/dist/tools/skill-install.js.map +1 -0
- package/dist/tools/web-search.d.ts +42 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +237 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/trust/guardrail.d.ts +60 -0
- package/dist/trust/guardrail.d.ts.map +1 -0
- package/dist/trust/guardrail.js +171 -0
- package/dist/trust/guardrail.js.map +1 -0
- package/dist/trust/index.d.ts +12 -0
- package/dist/trust/index.d.ts.map +1 -0
- package/dist/trust/index.js +12 -0
- package/dist/trust/index.js.map +1 -0
- package/dist/trust/store.d.ts +118 -0
- package/dist/trust/store.d.ts.map +1 -0
- package/dist/trust/store.js +209 -0
- package/dist/trust/store.js.map +1 -0
- package/dist/trust/wrapper.d.ts +36 -0
- package/dist/trust/wrapper.d.ts.map +1 -0
- package/dist/trust/wrapper.js +142 -0
- package/dist/trust/wrapper.js.map +1 -0
- package/dist/usage.d.ts +53 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +124 -0
- package/dist/usage.js.map +1 -0
- package/dist/util/math.d.ts +9 -0
- package/dist/util/math.d.ts.map +1 -0
- package/dist/util/math.js +22 -0
- package/dist/util/math.js.map +1 -0
- package/dist/util/ssrf.d.ts +21 -0
- package/dist/util/ssrf.d.ts.map +1 -0
- package/dist/util/ssrf.js +77 -0
- package/dist/util/ssrf.js.map +1 -0
- package/dist/workers/index.d.ts +8 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +7 -0
- package/dist/workers/index.js.map +1 -0
- package/dist/workers/registry.d.ts +53 -0
- package/dist/workers/registry.d.ts.map +1 -0
- package/dist/workers/registry.js +38 -0
- package/dist/workers/registry.js.map +1 -0
- package/dist/workers/scoped-tools.d.ts +21 -0
- package/dist/workers/scoped-tools.d.ts.map +1 -0
- package/dist/workers/scoped-tools.js +111 -0
- package/dist/workers/scoped-tools.js.map +1 -0
- package/dist/workers/spawn.d.ts +62 -0
- package/dist/workers/spawn.d.ts.map +1 -0
- package/dist/workers/spawn.js +314 -0
- package/dist/workers/spawn.js.map +1 -0
- package/dist/workers/tools.d.ts +26 -0
- package/dist/workers/tools.d.ts.map +1 -0
- package/dist/workers/tools.js +380 -0
- package/dist/workers/tools.js.map +1 -0
- package/docker-compose.yml +72 -0
- package/package.json +16 -1
- package/run.sh +27 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker session spawner and lifecycle management.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from tools.ts to reduce file size and separate concerns:
|
|
5
|
+
* - tools.ts handles the tool definitions (public API)
|
|
6
|
+
* - spawn.ts handles session creation and lifecycle
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { createAgentSession, DefaultResourceLoader, SessionManager, SettingsManager, } from "@mariozechner/pi-coding-agent";
|
|
11
|
+
import { embed } from "../memory/embeddings.js";
|
|
12
|
+
import { createBraveSearchTool, createWebSearchTool } from "../tools/web-search.js";
|
|
13
|
+
import { createFetchUrlTool } from "../tools/fetch-url.js";
|
|
14
|
+
import { createWorkerScopedTools } from "./scoped-tools.js";
|
|
15
|
+
import { createModelInfra, resolveModel } from "../model-infra.js";
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Constants
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Worker system prompt
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Build the system prompt for a worker session.
|
|
25
|
+
*
|
|
26
|
+
* The steering.md polling instruction embedded here (check every 3 tool calls)
|
|
27
|
+
* is the only communication channel from the main agent to a worker that is
|
|
28
|
+
* already running. worker_steer writes the file; the worker reads it on its
|
|
29
|
+
* own schedule. There is no push mechanism — the interval of 3 tool calls is
|
|
30
|
+
* a trade-off between responsiveness and unnecessary read_file overhead.
|
|
31
|
+
*/
|
|
32
|
+
function buildWorkerSystemPrompt(task, workerDir) {
|
|
33
|
+
return [
|
|
34
|
+
`You are a research worker. Your task is described below.`,
|
|
35
|
+
``,
|
|
36
|
+
`Write your findings to result.md in your working directory.`,
|
|
37
|
+
`Structure the output as markdown with clear sections.`,
|
|
38
|
+
`Be thorough but concise. Include sources where relevant.`,
|
|
39
|
+
``,
|
|
40
|
+
`Rules:`,
|
|
41
|
+
`- Your working directory is the root path you have access to.`,
|
|
42
|
+
`- Write your main output to result.md.`,
|
|
43
|
+
`- You may create additional files (notes.md, sources.md, etc.) as needed.`,
|
|
44
|
+
`- Do not ask for feedback or confirmation. Work autonomously.`,
|
|
45
|
+
`- When you are done, stop. Write your last thoughts to result.md and end.`,
|
|
46
|
+
``,
|
|
47
|
+
`## Steering`,
|
|
48
|
+
``,
|
|
49
|
+
`After every 3 tool calls, check for a file called steering.md using read_file.`,
|
|
50
|
+
`If the file exists, read it and immediately incorporate the guidance into your work.`,
|
|
51
|
+
`The steering note may narrow your focus, redirect your research, or add new requirements.`,
|
|
52
|
+
`Treat it as an authoritative update from the agent that dispatched you.`,
|
|
53
|
+
``,
|
|
54
|
+
`## Task`,
|
|
55
|
+
``,
|
|
56
|
+
task,
|
|
57
|
+
``,
|
|
58
|
+
`## Working directory`,
|
|
59
|
+
``,
|
|
60
|
+
workerDir,
|
|
61
|
+
].join("\n");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Write (or overwrite) the status.json file in the worker directory.
|
|
65
|
+
*
|
|
66
|
+
* This is the primary way the main agent reads worker status via worker_check.
|
|
67
|
+
* worker_check first consults the in-memory registry; if the worker is no
|
|
68
|
+
* longer there (e.g. after a restart or 24-hour cleanup) it falls back to
|
|
69
|
+
* reading this file from disk. Writing is best-effort: failures are swallowed
|
|
70
|
+
* so they never abort a completion or timeout handler.
|
|
71
|
+
*/
|
|
72
|
+
export function writeStatusFile(workerDir, data) {
|
|
73
|
+
try {
|
|
74
|
+
fs.writeFileSync(path.join(workerDir, "status.json"), JSON.stringify(data, null, 2), "utf-8");
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Best-effort — don't crash the completion handler
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// Types
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
const ALLOWED_TOOLS = ["web_search", "fetch_url"];
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Worker session spawner
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
export async function spawnWorkerSession(opts) {
|
|
88
|
+
const { config, workerId, workerDir, task, modelOverride, toolNames, memoryStore, registry, timeoutMs, onTrigger, } = opts;
|
|
89
|
+
const { authStorage, modelRegistry, agentDir } = createModelInfra(config);
|
|
90
|
+
const modelsDir = path.join(config.data_dir, ".models");
|
|
91
|
+
const resultPath = path.join(workerDir, "result.md");
|
|
92
|
+
// Resolve model. Workers default to the first fallback model (cheaper) rather
|
|
93
|
+
// than the primary model. The primary might be Opus/Sonnet via OAuth; we don't
|
|
94
|
+
// want workers burning those tokens on research tasks.
|
|
95
|
+
const workerDefault = config.tools.workers.model
|
|
96
|
+
?? config.agent.fallback_models?.[0]
|
|
97
|
+
?? config.agent.model;
|
|
98
|
+
const modelString = modelOverride ?? workerDefault;
|
|
99
|
+
const model = resolveModel(modelString, modelRegistry);
|
|
100
|
+
if (!model) {
|
|
101
|
+
throw new Error(`Worker model not found: ${modelString}`);
|
|
102
|
+
}
|
|
103
|
+
// ---- Tool selection -------------------------------------------------------
|
|
104
|
+
// Only the tools explicitly requested by the dispatcher are included. The
|
|
105
|
+
// scoped file tools (write_file, read_file) are always added regardless.
|
|
106
|
+
const workerTools = [];
|
|
107
|
+
if (toolNames.includes("web_search") && config.tools.web_search.enabled) {
|
|
108
|
+
const ws = config.tools.web_search;
|
|
109
|
+
if (ws.brave_api_key) {
|
|
110
|
+
workerTools.push(createBraveSearchTool(ws.brave_api_key));
|
|
111
|
+
}
|
|
112
|
+
else if (ws.searxng_url) {
|
|
113
|
+
workerTools.push(createWebSearchTool(ws.searxng_url));
|
|
114
|
+
}
|
|
115
|
+
// If neither is configured, web_search is silently omitted from worker tools.
|
|
116
|
+
}
|
|
117
|
+
if (toolNames.includes("fetch_url")) {
|
|
118
|
+
workerTools.push(createFetchUrlTool(config.tools.fetch_url.timeout_ms));
|
|
119
|
+
}
|
|
120
|
+
// Scoped file tools are always present — they are the worker's only way to
|
|
121
|
+
// persist findings. The worker cannot access files outside workerDir.
|
|
122
|
+
workerTools.push(...createWorkerScopedTools(workerDir));
|
|
123
|
+
// ---- Session creation -----------------------------------------------------
|
|
124
|
+
const systemPrompt = buildWorkerSystemPrompt(task, workerDir);
|
|
125
|
+
const loader = new DefaultResourceLoader({
|
|
126
|
+
cwd: config.data_dir,
|
|
127
|
+
agentDir,
|
|
128
|
+
settingsManager: SettingsManager.create(config.data_dir, agentDir),
|
|
129
|
+
systemPromptOverride: () => systemPrompt,
|
|
130
|
+
});
|
|
131
|
+
await loader.reload();
|
|
132
|
+
const settingsManager = SettingsManager.create(config.data_dir, agentDir);
|
|
133
|
+
// Spawn the session (no persistence — in-memory only)
|
|
134
|
+
const { session } = await createAgentSession({
|
|
135
|
+
cwd: workerDir,
|
|
136
|
+
agentDir,
|
|
137
|
+
authStorage,
|
|
138
|
+
modelRegistry,
|
|
139
|
+
model,
|
|
140
|
+
thinkingLevel: "off",
|
|
141
|
+
tools: [],
|
|
142
|
+
customTools: workerTools,
|
|
143
|
+
resourceLoader: loader,
|
|
144
|
+
sessionManager: SessionManager.inMemory(workerDir),
|
|
145
|
+
settingsManager,
|
|
146
|
+
});
|
|
147
|
+
// ---- Timeout setup --------------------------------------------------------
|
|
148
|
+
registry.update(workerId, {
|
|
149
|
+
abort: () => session.abort(),
|
|
150
|
+
});
|
|
151
|
+
// Set up timeout
|
|
152
|
+
const timeoutHandle = setTimeout(async () => {
|
|
153
|
+
console.log(`[worker] ${workerId} timed out after ${timeoutMs / 1000}s`);
|
|
154
|
+
registry.update(workerId, {
|
|
155
|
+
status: "timeout",
|
|
156
|
+
completedAt: new Date(),
|
|
157
|
+
error: `Timed out after ${timeoutMs / 1000}s`,
|
|
158
|
+
});
|
|
159
|
+
const entry = registry.get(workerId);
|
|
160
|
+
try {
|
|
161
|
+
await session.abort();
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Best-effort abort
|
|
165
|
+
}
|
|
166
|
+
session.dispose();
|
|
167
|
+
if (entry) {
|
|
168
|
+
writeStatusFile(workerDir, {
|
|
169
|
+
worker_id: workerId,
|
|
170
|
+
status: "timeout",
|
|
171
|
+
task,
|
|
172
|
+
started_at: entry.startedAt.toISOString(),
|
|
173
|
+
completed_at: new Date().toISOString(),
|
|
174
|
+
model: modelString,
|
|
175
|
+
error: `Timed out after ${timeoutMs / 1000}s`,
|
|
176
|
+
result_path: resultPath,
|
|
177
|
+
});
|
|
178
|
+
const factContent = `Worker ${workerId} failed: timed out after ${timeoutMs / 1000}s`;
|
|
179
|
+
try {
|
|
180
|
+
const embedding = await embed(factContent, modelsDir);
|
|
181
|
+
memoryStore.addFact(factContent, "worker", embedding);
|
|
182
|
+
console.log(`[worker] ${workerId} timeout fact archived`);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
console.error(`[worker] ${workerId} failed to archive timeout fact:`, err.message);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
scheduleCleanup(registry, workerId, workerDir);
|
|
189
|
+
}, timeoutMs);
|
|
190
|
+
// Store handle so we can cancel it if the worker finishes first
|
|
191
|
+
registry.update(workerId, { timeoutHandle });
|
|
192
|
+
// ---- Task execution and completion callback --------------------------------
|
|
193
|
+
// session.prompt() runs the worker to completion. Everything below the await
|
|
194
|
+
// is the completion callback — it runs once the model has stopped generating.
|
|
195
|
+
const taskPrompt = `Please complete the task described in the system prompt. ` +
|
|
196
|
+
`Write your findings to result.md when done.`;
|
|
197
|
+
try {
|
|
198
|
+
await session.prompt(taskPrompt);
|
|
199
|
+
// Check for model errors
|
|
200
|
+
const lastAssistant = session.messages
|
|
201
|
+
.filter((m) => m.role === "assistant")
|
|
202
|
+
.pop();
|
|
203
|
+
if (lastAssistant?.stopReason === "error") {
|
|
204
|
+
throw new Error(String(lastAssistant.errorMessage ?? "Model error"));
|
|
205
|
+
}
|
|
206
|
+
// Success path
|
|
207
|
+
clearTimeout(timeoutHandle);
|
|
208
|
+
registry.update(workerId, {
|
|
209
|
+
status: "complete",
|
|
210
|
+
completedAt: new Date(),
|
|
211
|
+
error: null,
|
|
212
|
+
timeoutHandle: null,
|
|
213
|
+
});
|
|
214
|
+
const entry = registry.get(workerId);
|
|
215
|
+
// Step 1: Write status.json so worker_check can read the result from disk
|
|
216
|
+
// even after the registry entry has been cleaned up.
|
|
217
|
+
writeStatusFile(workerDir, {
|
|
218
|
+
worker_id: workerId,
|
|
219
|
+
status: "complete",
|
|
220
|
+
task,
|
|
221
|
+
started_at: entry?.startedAt.toISOString() ?? new Date().toISOString(),
|
|
222
|
+
completed_at: new Date().toISOString(),
|
|
223
|
+
model: modelString,
|
|
224
|
+
error: null,
|
|
225
|
+
result_path: resultPath,
|
|
226
|
+
});
|
|
227
|
+
console.log(`[worker] ${workerId} complete`);
|
|
228
|
+
const factContent = `Worker ${workerId} complete, results at ${resultPath}`;
|
|
229
|
+
try {
|
|
230
|
+
// Step 2: Archive the completion fact. This is what the main agent's
|
|
231
|
+
// projection matched against trigger_on_fact (e.g. "worker w-xxx complete").
|
|
232
|
+
const embedding = await embed(factContent, modelsDir);
|
|
233
|
+
memoryStore.addFact(factContent, "worker", embedding);
|
|
234
|
+
console.log(`[worker] ${workerId} completion fact archived`);
|
|
235
|
+
// Step 3: Check the fact against active projections and invoke the
|
|
236
|
+
// onTrigger callback if any match. The callback injects a scheduler
|
|
237
|
+
// message immediately rather than waiting for the 5-minute cron tick,
|
|
238
|
+
// so the main agent wakes up as soon as the worker finishes.
|
|
239
|
+
if (onTrigger && opts.projectionStore) {
|
|
240
|
+
try {
|
|
241
|
+
const triggered = await opts.projectionStore.checkTriggers(factContent, (text) => embed(text, modelsDir));
|
|
242
|
+
if (triggered.length > 0) {
|
|
243
|
+
console.log(`[worker] ${workerId} triggered ${triggered.length} projection(s)`);
|
|
244
|
+
onTrigger(triggered);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (triggerErr) {
|
|
248
|
+
console.error(`[worker] ${workerId} trigger check failed:`, triggerErr.message);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
console.error(`[worker] ${workerId} failed to archive completion fact:`, err.message);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
const errMsg = error.message;
|
|
258
|
+
// Don't overwrite a terminal status set externally (timeout handler or
|
|
259
|
+
// worker_interrupt). Both set their own status before aborting the session,
|
|
260
|
+
// so the error thrown by abort() here would otherwise clobber it.
|
|
261
|
+
const currentEntry = registry.get(workerId);
|
|
262
|
+
if (currentEntry?.status === "timeout" || currentEntry?.status === "cancelled") {
|
|
263
|
+
session.dispose();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
clearTimeout(timeoutHandle);
|
|
267
|
+
registry.update(workerId, {
|
|
268
|
+
status: "failed",
|
|
269
|
+
completedAt: new Date(),
|
|
270
|
+
error: errMsg,
|
|
271
|
+
timeoutHandle: null,
|
|
272
|
+
});
|
|
273
|
+
const entry = registry.get(workerId);
|
|
274
|
+
writeStatusFile(workerDir, {
|
|
275
|
+
worker_id: workerId,
|
|
276
|
+
status: "failed",
|
|
277
|
+
task,
|
|
278
|
+
started_at: entry?.startedAt.toISOString() ?? new Date().toISOString(),
|
|
279
|
+
completed_at: new Date().toISOString(),
|
|
280
|
+
model: modelString,
|
|
281
|
+
error: errMsg,
|
|
282
|
+
result_path: resultPath,
|
|
283
|
+
});
|
|
284
|
+
console.error(`[worker] ${workerId} failed:`, errMsg);
|
|
285
|
+
const factContent = `Worker ${workerId} failed: ${errMsg}`;
|
|
286
|
+
try {
|
|
287
|
+
const embedding = await embed(factContent, modelsDir);
|
|
288
|
+
memoryStore.addFact(factContent, "worker", embedding);
|
|
289
|
+
console.log(`[worker] ${workerId} failure fact archived`);
|
|
290
|
+
}
|
|
291
|
+
catch (err2) {
|
|
292
|
+
console.error(`[worker] ${workerId} failed to archive failure fact:`, err2.message);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
session.dispose();
|
|
297
|
+
scheduleCleanup(registry, workerId, workerDir);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
// Cleanup
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
/**
|
|
304
|
+
* Remove the worker's registry entry after 24 hours. Result files stay on
|
|
305
|
+
* disk; only the in-memory tracking is cleared.
|
|
306
|
+
*/
|
|
307
|
+
export function scheduleCleanup(registry, workerId, _workerDir) {
|
|
308
|
+
// Keep the entry for 24 hours so worker_check still works.
|
|
309
|
+
setTimeout(() => {
|
|
310
|
+
registry.remove(workerId);
|
|
311
|
+
console.log(`[worker] ${workerId} removed from registry after 24h`);
|
|
312
|
+
}, 24 * 60 * 60 * 1000);
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,eAAe,GAChB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEnE,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AA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AAM,WAAW,GAAG,UAAU,QAAQ,YAAY,MAAM,EAAE,CAAC;QAC3D,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YACtD,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,YAAY,QAAQ,wBAAwB,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,IAAI,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,YAAY,QAAQ,kCAAkC,EAAG,IAAc,CAAC,OAAO,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAwB,EACxB,QAAgB,EAChB,UAAkB;IAElB,2DAA2D;IAC3D,UAAU,CAAC,GAAG,EAAE;QACd,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,YAAY,QAAQ,kCAAkC,CAAC,CAAC;IACtE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker tools: dispatch, check, interrupt, steer.
|
|
3
|
+
*
|
|
4
|
+
* Workers are background LLM sessions with a scoped tool set. They write
|
|
5
|
+
* results to a file and signal completion by archiving a fact, which triggers
|
|
6
|
+
* any matching projection in the main agent.
|
|
7
|
+
*
|
|
8
|
+
* Lifecycle:
|
|
9
|
+
* 1. dispatch: create worker dir, write task.md, spawn session
|
|
10
|
+
* 2. Worker runs autonomously (web search, fetch URL, write result.md)
|
|
11
|
+
* 3. On completion/failure/timeout: write status.json, archive a fact
|
|
12
|
+
* 4. check: query status; interrupt: cancel immediately; steer: redirect
|
|
13
|
+
*/
|
|
14
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
15
|
+
import type { Config } from "../config.js";
|
|
16
|
+
import type { MemoryStore } from "../memory/store.js";
|
|
17
|
+
import type { WorkerRegistry } from "./registry.js";
|
|
18
|
+
import type { ProjectionStore } from "../projection/store.js";
|
|
19
|
+
import { type WorkerTriggerCallback } from "./spawn.js";
|
|
20
|
+
export type { WorkerTriggerCallback } from "./spawn.js";
|
|
21
|
+
/**
|
|
22
|
+
* Create worker tools (dispatch, check, interrupt, steer).
|
|
23
|
+
* When isWorkerSession is true, dispatch rejects all calls (no nesting).
|
|
24
|
+
*/
|
|
25
|
+
export declare function createWorkerTools(config: Config, memoryStore: MemoryStore, registry: WorkerRegistry, isWorkerSession?: boolean, projectionStore?: ProjectionStore, onTrigger?: WorkerTriggerCallback): AgentTool<any>[];
|
|
26
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/workers/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAG9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AAYpB,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA8DxD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,cAAc,EACxB,eAAe,UAAQ,EACvB,eAAe,CAAC,EAAE,eAAe,EACjC,SAAS,CAAC,EAAE,qBAAqB,GAChC,SAAS,CAAC,GAAG,CAAC,EAAE,CAoWlB"}
|