@markus-global/cli 0.4.15 → 0.4.16
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/dist/commands/start.js +118 -34
- package/dist/commands/start.js.map +1 -1
- package/dist/markus.mjs +826 -734
- package/dist/web-ui/assets/{index-D_HpVTyL.js → index-CFSDM4KA.js} +12 -12
- package/dist/web-ui/index.html +1 -1
- package/package.json +1 -1
- package/templates/openclaw-markus-skill/AGENTS.md +6 -14
- package/templates/roles/SHARED.md +9 -18
- package/templates/roles/agent-father/ROLE.md +1 -1
- package/templates/roles/developer/HEARTBEAT.md +7 -0
- package/templates/roles/developer/POLICIES.md +4 -6
- package/templates/roles/developer/ROLE.md +2 -2
- package/templates/roles/openclaw-developer/openclaw.md +3 -5
- package/templates/roles/operations/HEARTBEAT.md +7 -0
- package/templates/roles/org-manager/HEARTBEAT.md +7 -0
- package/templates/roles/product-manager/HEARTBEAT.md +7 -0
- package/templates/roles/reviewer/HEARTBEAT.md +7 -0
- package/templates/roles/secretary/HEARTBEAT.md +12 -0
- package/templates/roles/team-factory/ROLE.md +2 -2
- package/templates/skills/agent-building/SKILL.md +1 -1
- package/templates/skills/self-evolution/SKILL.md +17 -2
- package/templates/teams/dev-squad/NORMS.md +2 -2
- package/templates/teams/engineering-pod/NORMS.md +2 -2
package/dist/markus.mjs
CHANGED
|
@@ -4085,17 +4085,103 @@ var init_version = __esm({
|
|
|
4085
4085
|
}
|
|
4086
4086
|
});
|
|
4087
4087
|
|
|
4088
|
+
// ../shared/dist/limits.js
|
|
4089
|
+
var TASK_GET_NOTES_DEFAULT, TASK_GET_DELIVERABLES_DEFAULT, PROMPT_TASK_NOTES_MAX, PROMPT_TASK_NOTE_CHARS, PROMPT_DEP_NOTES_MAX, PROMPT_DEP_NOTE_CHARS, PROMPT_DEP_DESC_CHARS, PROMPT_EXECUTION_ROUNDS_MAX, PROMPT_LOG_ENTRY_CHARS, PROMPT_RECENT_ERRORS_MAX, PROMPT_HUMAN_COMMENTS_MAX, REVIEWER_NOTES_MAX, SYSTEM_MY_TASKS_MAX, SYSTEM_TEAM_TASKS_MAX, SYSTEM_TASK_DESC_CHARS, PROMPT_PROJECT_DESC_CHARS, PROMPT_REQUIREMENT_DESC_CHARS, REVIEWER_FILE_LIST_MAX, DELIVERABLE_TITLE_CHARS, REVISION_REASON_CHARS, TASK_MAX_RETRIES, TASK_MAX_NO_SUBMIT_RETRIES, TASK_RETRY_DELAYS_MS, SYSTEM_SOPS_CHARS, SYSTEM_LONGTERM_MEMORY_CHARS, SYSTEM_LESSON_ENTRIES_MAX, SYSTEM_BEST_PRACTICE_ENTRIES_MAX, SYSTEM_DELIVERABLES_CHARS, SYSTEM_DAILY_LOG_CHARS, SYSTEM_DAILY_LOG_DAYS, SYSTEM_USER_PROFILE_CHARS, SYSTEM_CHAT_SESSIONS_MAX, HEARTBEAT_DAILY_LOG_CHARS, SYSTEM_PROJECT_DESC_CHARS, SYSTEM_DELIVERABLE_PREVIEW_CHARS, SYSTEM_MAILBOX_MERGED_CHARS, SYSTEM_MAILBOX_ITEM_PREVIEW_CHARS, TASK_LIST_PAGE_SIZE, TASK_LIST_PAGE_MAX;
|
|
4090
|
+
var init_limits = __esm({
|
|
4091
|
+
"../shared/dist/limits.js"() {
|
|
4092
|
+
"use strict";
|
|
4093
|
+
TASK_GET_NOTES_DEFAULT = 50;
|
|
4094
|
+
TASK_GET_DELIVERABLES_DEFAULT = 20;
|
|
4095
|
+
PROMPT_TASK_NOTES_MAX = 30;
|
|
4096
|
+
PROMPT_TASK_NOTE_CHARS = 1200;
|
|
4097
|
+
PROMPT_DEP_NOTES_MAX = 5;
|
|
4098
|
+
PROMPT_DEP_NOTE_CHARS = 500;
|
|
4099
|
+
PROMPT_DEP_DESC_CHARS = 300;
|
|
4100
|
+
PROMPT_EXECUTION_ROUNDS_MAX = 3;
|
|
4101
|
+
PROMPT_LOG_ENTRY_CHARS = 800;
|
|
4102
|
+
PROMPT_RECENT_ERRORS_MAX = 10;
|
|
4103
|
+
PROMPT_HUMAN_COMMENTS_MAX = 5;
|
|
4104
|
+
REVIEWER_NOTES_MAX = 5;
|
|
4105
|
+
SYSTEM_MY_TASKS_MAX = 15;
|
|
4106
|
+
SYSTEM_TEAM_TASKS_MAX = 10;
|
|
4107
|
+
SYSTEM_TASK_DESC_CHARS = 150;
|
|
4108
|
+
PROMPT_PROJECT_DESC_CHARS = 300;
|
|
4109
|
+
PROMPT_REQUIREMENT_DESC_CHARS = 500;
|
|
4110
|
+
REVIEWER_FILE_LIST_MAX = 10;
|
|
4111
|
+
DELIVERABLE_TITLE_CHARS = 200;
|
|
4112
|
+
REVISION_REASON_CHARS = 200;
|
|
4113
|
+
TASK_MAX_RETRIES = 3;
|
|
4114
|
+
TASK_MAX_NO_SUBMIT_RETRIES = 8;
|
|
4115
|
+
TASK_RETRY_DELAYS_MS = [1e4, 3e4, 6e4, 12e4, 3e5];
|
|
4116
|
+
SYSTEM_SOPS_CHARS = 3e3;
|
|
4117
|
+
SYSTEM_LONGTERM_MEMORY_CHARS = 5e3;
|
|
4118
|
+
SYSTEM_LESSON_ENTRIES_MAX = 10;
|
|
4119
|
+
SYSTEM_BEST_PRACTICE_ENTRIES_MAX = 10;
|
|
4120
|
+
SYSTEM_DELIVERABLES_CHARS = 3e3;
|
|
4121
|
+
SYSTEM_DAILY_LOG_CHARS = 1500;
|
|
4122
|
+
SYSTEM_DAILY_LOG_DAYS = 1;
|
|
4123
|
+
SYSTEM_USER_PROFILE_CHARS = 1500;
|
|
4124
|
+
SYSTEM_CHAT_SESSIONS_MAX = 5;
|
|
4125
|
+
HEARTBEAT_DAILY_LOG_CHARS = 3e3;
|
|
4126
|
+
SYSTEM_PROJECT_DESC_CHARS = 200;
|
|
4127
|
+
SYSTEM_DELIVERABLE_PREVIEW_CHARS = 200;
|
|
4128
|
+
SYSTEM_MAILBOX_MERGED_CHARS = 500;
|
|
4129
|
+
SYSTEM_MAILBOX_ITEM_PREVIEW_CHARS = 120;
|
|
4130
|
+
TASK_LIST_PAGE_SIZE = 20;
|
|
4131
|
+
TASK_LIST_PAGE_MAX = 100;
|
|
4132
|
+
}
|
|
4133
|
+
});
|
|
4134
|
+
|
|
4088
4135
|
// ../shared/dist/index.js
|
|
4089
4136
|
var dist_exports = {};
|
|
4090
4137
|
__export(dist_exports, {
|
|
4091
4138
|
APP_VERSION: () => APP_VERSION,
|
|
4139
|
+
DELIVERABLE_TITLE_CHARS: () => DELIVERABLE_TITLE_CHARS,
|
|
4140
|
+
HEARTBEAT_DAILY_LOG_CHARS: () => HEARTBEAT_DAILY_LOG_CHARS,
|
|
4092
4141
|
Logger: () => Logger,
|
|
4093
4142
|
MAILBOX_CATEGORIES: () => MAILBOX_CATEGORIES,
|
|
4094
4143
|
MAILBOX_TYPE_REGISTRY: () => MAILBOX_TYPE_REGISTRY,
|
|
4095
4144
|
MARKUS_MANIFEST_FILENAME: () => MARKUS_MANIFEST_FILENAME,
|
|
4096
4145
|
MailboxPriorityLevel: () => MailboxPriorityLevel,
|
|
4097
4146
|
PRIORITY_LABELS: () => PRIORITY_LABELS,
|
|
4147
|
+
PROMPT_DEP_DESC_CHARS: () => PROMPT_DEP_DESC_CHARS,
|
|
4148
|
+
PROMPT_DEP_NOTES_MAX: () => PROMPT_DEP_NOTES_MAX,
|
|
4149
|
+
PROMPT_DEP_NOTE_CHARS: () => PROMPT_DEP_NOTE_CHARS,
|
|
4150
|
+
PROMPT_EXECUTION_ROUNDS_MAX: () => PROMPT_EXECUTION_ROUNDS_MAX,
|
|
4151
|
+
PROMPT_HUMAN_COMMENTS_MAX: () => PROMPT_HUMAN_COMMENTS_MAX,
|
|
4152
|
+
PROMPT_LOG_ENTRY_CHARS: () => PROMPT_LOG_ENTRY_CHARS,
|
|
4153
|
+
PROMPT_PROJECT_DESC_CHARS: () => PROMPT_PROJECT_DESC_CHARS,
|
|
4154
|
+
PROMPT_RECENT_ERRORS_MAX: () => PROMPT_RECENT_ERRORS_MAX,
|
|
4155
|
+
PROMPT_REQUIREMENT_DESC_CHARS: () => PROMPT_REQUIREMENT_DESC_CHARS,
|
|
4156
|
+
PROMPT_TASK_NOTES_MAX: () => PROMPT_TASK_NOTES_MAX,
|
|
4157
|
+
PROMPT_TASK_NOTE_CHARS: () => PROMPT_TASK_NOTE_CHARS,
|
|
4098
4158
|
PROVIDERS: () => PROVIDERS,
|
|
4159
|
+
REVIEWER_FILE_LIST_MAX: () => REVIEWER_FILE_LIST_MAX,
|
|
4160
|
+
REVIEWER_NOTES_MAX: () => REVIEWER_NOTES_MAX,
|
|
4161
|
+
REVISION_REASON_CHARS: () => REVISION_REASON_CHARS,
|
|
4162
|
+
SYSTEM_BEST_PRACTICE_ENTRIES_MAX: () => SYSTEM_BEST_PRACTICE_ENTRIES_MAX,
|
|
4163
|
+
SYSTEM_CHAT_SESSIONS_MAX: () => SYSTEM_CHAT_SESSIONS_MAX,
|
|
4164
|
+
SYSTEM_DAILY_LOG_CHARS: () => SYSTEM_DAILY_LOG_CHARS,
|
|
4165
|
+
SYSTEM_DAILY_LOG_DAYS: () => SYSTEM_DAILY_LOG_DAYS,
|
|
4166
|
+
SYSTEM_DELIVERABLES_CHARS: () => SYSTEM_DELIVERABLES_CHARS,
|
|
4167
|
+
SYSTEM_DELIVERABLE_PREVIEW_CHARS: () => SYSTEM_DELIVERABLE_PREVIEW_CHARS,
|
|
4168
|
+
SYSTEM_LESSON_ENTRIES_MAX: () => SYSTEM_LESSON_ENTRIES_MAX,
|
|
4169
|
+
SYSTEM_LONGTERM_MEMORY_CHARS: () => SYSTEM_LONGTERM_MEMORY_CHARS,
|
|
4170
|
+
SYSTEM_MAILBOX_ITEM_PREVIEW_CHARS: () => SYSTEM_MAILBOX_ITEM_PREVIEW_CHARS,
|
|
4171
|
+
SYSTEM_MAILBOX_MERGED_CHARS: () => SYSTEM_MAILBOX_MERGED_CHARS,
|
|
4172
|
+
SYSTEM_MY_TASKS_MAX: () => SYSTEM_MY_TASKS_MAX,
|
|
4173
|
+
SYSTEM_PROJECT_DESC_CHARS: () => SYSTEM_PROJECT_DESC_CHARS,
|
|
4174
|
+
SYSTEM_SOPS_CHARS: () => SYSTEM_SOPS_CHARS,
|
|
4175
|
+
SYSTEM_TASK_DESC_CHARS: () => SYSTEM_TASK_DESC_CHARS,
|
|
4176
|
+
SYSTEM_TEAM_TASKS_MAX: () => SYSTEM_TEAM_TASKS_MAX,
|
|
4177
|
+
SYSTEM_USER_PROFILE_CHARS: () => SYSTEM_USER_PROFILE_CHARS,
|
|
4178
|
+
TASK_GET_DELIVERABLES_DEFAULT: () => TASK_GET_DELIVERABLES_DEFAULT,
|
|
4179
|
+
TASK_GET_NOTES_DEFAULT: () => TASK_GET_NOTES_DEFAULT,
|
|
4180
|
+
TASK_LIST_PAGE_MAX: () => TASK_LIST_PAGE_MAX,
|
|
4181
|
+
TASK_LIST_PAGE_SIZE: () => TASK_LIST_PAGE_SIZE,
|
|
4182
|
+
TASK_MAX_NO_SUBMIT_RETRIES: () => TASK_MAX_NO_SUBMIT_RETRIES,
|
|
4183
|
+
TASK_MAX_RETRIES: () => TASK_MAX_RETRIES,
|
|
4184
|
+
TASK_RETRY_DELAYS_MS: () => TASK_RETRY_DELAYS_MS,
|
|
4099
4185
|
TASK_TRANSITIONS: () => TASK_TRANSITIONS,
|
|
4100
4186
|
TERMINAL_STATUSES: () => TERMINAL_STATUSES,
|
|
4101
4187
|
USER_NOTIFICATION_TYPE_REGISTRY: () => USER_NOTIFICATION_TYPE_REGISTRY,
|
|
@@ -4141,6 +4227,7 @@ var init_dist = __esm({
|
|
|
4141
4227
|
init_text();
|
|
4142
4228
|
init_models();
|
|
4143
4229
|
init_version();
|
|
4230
|
+
init_limits();
|
|
4144
4231
|
}
|
|
4145
4232
|
});
|
|
4146
4233
|
|
|
@@ -4843,6 +4930,14 @@ ${content}
|
|
|
4843
4930
|
return "";
|
|
4844
4931
|
return readFileSync3(this.longTermFile, "utf-8");
|
|
4845
4932
|
}
|
|
4933
|
+
getLongTermSection(sectionName) {
|
|
4934
|
+
const content = this.getLongTermMemory();
|
|
4935
|
+
if (!content)
|
|
4936
|
+
return "";
|
|
4937
|
+
const escaped = sectionName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4938
|
+
const match = content.match(new RegExp(`## ${escaped}\\n([\\s\\S]*?)(?=\\n## |$)`));
|
|
4939
|
+
return match?.[1]?.trim() ?? "";
|
|
4940
|
+
}
|
|
4846
4941
|
// --- Context compaction (OpenClawd pattern) ---
|
|
4847
4942
|
compactSession(sessionId, keepLast = 20) {
|
|
4848
4943
|
const session = this.sessions.get(sessionId);
|
|
@@ -5238,6 +5333,9 @@ ${summaryParts.join("\n")}`;
|
|
|
5238
5333
|
getLongTermMemory() {
|
|
5239
5334
|
return this.baseStore.getLongTermMemory();
|
|
5240
5335
|
}
|
|
5336
|
+
getLongTermSection(sectionName) {
|
|
5337
|
+
return this.baseStore.getLongTermSection(sectionName);
|
|
5338
|
+
}
|
|
5241
5339
|
getRecentMessages(sessionId, limit) {
|
|
5242
5340
|
return this.baseStore.getRecentMessages(sessionId, limit);
|
|
5243
5341
|
}
|
|
@@ -6300,20 +6398,14 @@ var init_context_engine = __esm({
|
|
|
6300
6398
|
parts.push("\n## Current Project");
|
|
6301
6399
|
parts.push(`- Project: **${project.name}** (${project.status})`);
|
|
6302
6400
|
if (project.description)
|
|
6303
|
-
parts.push(`- ${project.description.slice(0,
|
|
6401
|
+
parts.push(`- ${project.description.slice(0, SYSTEM_PROJECT_DESC_CHARS)}`);
|
|
6304
6402
|
if (repositories?.length) {
|
|
6305
6403
|
for (const repo of repositories) {
|
|
6306
6404
|
parts.push(`- Repository: \`${repo.localPath}\` (${repo.role}, default branch: \`${repo.defaultBranch}\`)`);
|
|
6307
6405
|
}
|
|
6308
6406
|
}
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
parts.push(`- Base branch: \`${opts.taskBaseBranch ?? "main"}\``);
|
|
6312
|
-
parts.push("");
|
|
6313
|
-
parts.push("**Workspace isolation**: You are responsible for setting up your own isolated workspace before modifying code.");
|
|
6314
|
-
parts.push("Use `git worktree add` or `git checkout -b` via `shell_execute` to create an isolated working area on your task branch.");
|
|
6315
|
-
parts.push("Some git operations (switching to existing branches, pushing to protected branches, merge, rebase) require human approval \u2014 the system will pause and ask the reviewer. If denied, you will receive a reason; read it and adjust your approach.");
|
|
6316
|
-
}
|
|
6407
|
+
parts.push("");
|
|
6408
|
+
parts.push("Some git operations (switching to existing branches, pushing to protected branches, merge, rebase) require human approval \u2014 the system will pause and ask the reviewer. If denied, you will receive a reason; read it and adjust your approach.");
|
|
6317
6409
|
if (teamRole)
|
|
6318
6410
|
parts.push(`- Your role: ${teamRole}`);
|
|
6319
6411
|
if (governanceRules)
|
|
@@ -6351,7 +6443,7 @@ var init_context_engine = __esm({
|
|
|
6351
6443
|
const userProfile = readFileSync6(userMdPath, "utf-8").trim();
|
|
6352
6444
|
if (userProfile) {
|
|
6353
6445
|
parts.push("\n## About the Owner");
|
|
6354
|
-
parts.push(userProfile.slice(0,
|
|
6446
|
+
parts.push(userProfile.slice(0, SYSTEM_USER_PROFILE_CHARS));
|
|
6355
6447
|
parts.push("\n_This profile is maintained by the Secretary. If you notice new preferences or patterns from the owner, mention them to the Secretary via `agent_send_message`._");
|
|
6356
6448
|
}
|
|
6357
6449
|
}
|
|
@@ -6389,7 +6481,7 @@ var init_context_engine = __esm({
|
|
|
6389
6481
|
if (opts.projectDeliverables?.length) {
|
|
6390
6482
|
parts.push("\n## Project Deliverables (key entries)");
|
|
6391
6483
|
for (const k of opts.projectDeliverables) {
|
|
6392
|
-
parts.push(`- **[${k.category}]** ${k.title}: ${k.content.slice(0,
|
|
6484
|
+
parts.push(`- **[${k.category}]** ${k.title}: ${k.content.slice(0, SYSTEM_DELIVERABLE_PREVIEW_CHARS)}`);
|
|
6393
6485
|
}
|
|
6394
6486
|
}
|
|
6395
6487
|
if (opts.role.defaultPolicies.length > 0) {
|
|
@@ -6401,12 +6493,18 @@ var init_context_engine = __esm({
|
|
|
6401
6493
|
}
|
|
6402
6494
|
}
|
|
6403
6495
|
}
|
|
6496
|
+
const sops = opts.memory.getLongTermSection("sops");
|
|
6497
|
+
if (sops) {
|
|
6498
|
+
parts.push("\n## Your SOPs (Standard Operating Procedures)");
|
|
6499
|
+
parts.push("These are your proven, repeatable workflows. Follow them when the trigger matches.");
|
|
6500
|
+
parts.push(sops.slice(0, SYSTEM_SOPS_CHARS));
|
|
6501
|
+
}
|
|
6404
6502
|
const longTermMem = opts.memory.getLongTermMemory();
|
|
6405
6503
|
if (longTermMem) {
|
|
6406
6504
|
parts.push("\n## Long-term Knowledge");
|
|
6407
|
-
parts.push(longTermMem.slice(0,
|
|
6505
|
+
parts.push(longTermMem.slice(0, SYSTEM_LONGTERM_MEMORY_CHARS));
|
|
6408
6506
|
}
|
|
6409
|
-
const lessons = opts.memory.getEntriesByTag("lesson",
|
|
6507
|
+
const lessons = opts.memory.getEntriesByTag("lesson", SYSTEM_LESSON_ENTRIES_MAX);
|
|
6410
6508
|
if (lessons.length > 0) {
|
|
6411
6509
|
parts.push("\n## Lessons from Past Experience");
|
|
6412
6510
|
for (const lesson of lessons) {
|
|
@@ -6414,10 +6512,19 @@ var init_context_engine = __esm({
|
|
|
6414
6512
|
parts.push(`- [${ts}] ${lesson.content}`);
|
|
6415
6513
|
}
|
|
6416
6514
|
}
|
|
6515
|
+
const bestPractices = opts.memory.getEntriesByTag("best-practice", SYSTEM_BEST_PRACTICE_ENTRIES_MAX);
|
|
6516
|
+
if (bestPractices.length > 0) {
|
|
6517
|
+
parts.push("\n## Best Practices");
|
|
6518
|
+
parts.push("Proven approaches from your completed tasks. Apply when relevant.");
|
|
6519
|
+
for (const bp of bestPractices) {
|
|
6520
|
+
const ts = bp.timestamp ? new Date(bp.timestamp).toLocaleDateString() : "";
|
|
6521
|
+
parts.push(`- [${ts}] ${bp.content}`);
|
|
6522
|
+
}
|
|
6523
|
+
}
|
|
6417
6524
|
const isDream = opts.scenario === "memory_consolidation";
|
|
6418
6525
|
if (!isDream && (opts.deliverableContext || opts.knowledgeContext)) {
|
|
6419
6526
|
parts.push("\n## Shared Deliverables");
|
|
6420
|
-
parts.push((opts.deliverableContext ?? opts.knowledgeContext ?? "").slice(0,
|
|
6527
|
+
parts.push((opts.deliverableContext ?? opts.knowledgeContext ?? "").slice(0, SYSTEM_DELIVERABLES_CHARS));
|
|
6421
6528
|
}
|
|
6422
6529
|
if (!isDream) {
|
|
6423
6530
|
const relevantMemories = await this.retrieveRelevantMemories(opts.memory, opts.currentQuery, opts.agentId);
|
|
@@ -6430,10 +6537,10 @@ var init_context_engine = __esm({
|
|
|
6430
6537
|
}
|
|
6431
6538
|
}
|
|
6432
6539
|
if (!isDream) {
|
|
6433
|
-
const dailyLog = opts.memory.getRecentDailyLogs(
|
|
6540
|
+
const dailyLog = opts.memory.getRecentDailyLogs(SYSTEM_DAILY_LOG_DAYS);
|
|
6434
6541
|
if (dailyLog) {
|
|
6435
6542
|
parts.push("\n## Recent Activity Summary");
|
|
6436
|
-
parts.push(dailyLog.slice(0,
|
|
6543
|
+
parts.push(dailyLog.slice(0, SYSTEM_DAILY_LOG_CHARS));
|
|
6437
6544
|
}
|
|
6438
6545
|
}
|
|
6439
6546
|
if (!isDream) {
|
|
@@ -6444,8 +6551,8 @@ var init_context_engine = __esm({
|
|
|
6444
6551
|
const otherTasks = opts.assignedTasks.filter((t) => t.assignedAgentId !== opts.agentId);
|
|
6445
6552
|
const myActive = myTasks.filter((t) => !["completed", "cancelled", "failed"].includes(t.status)).sort(byPriority);
|
|
6446
6553
|
const myDone = myTasks.filter((t) => ["completed", "cancelled", "failed"].includes(t.status));
|
|
6447
|
-
const MY_TASK_LIMIT =
|
|
6448
|
-
const TEAM_TASK_LIMIT =
|
|
6554
|
+
const MY_TASK_LIMIT = SYSTEM_MY_TASKS_MAX;
|
|
6555
|
+
const TEAM_TASK_LIMIT = SYSTEM_TEAM_TASKS_MAX;
|
|
6449
6556
|
parts.push("\n## Task Board");
|
|
6450
6557
|
parts.push("### My Tasks (assigned to you):");
|
|
6451
6558
|
if (myActive.length > 0) {
|
|
@@ -6453,7 +6560,7 @@ var init_context_engine = __esm({
|
|
|
6453
6560
|
for (const t of shown) {
|
|
6454
6561
|
parts.push(`- [${t.status.toUpperCase()}] **${t.title}** (ID: \`${t.id}\`, priority: ${t.priority})`);
|
|
6455
6562
|
if (t.description)
|
|
6456
|
-
parts.push(` ${t.description.slice(0,
|
|
6563
|
+
parts.push(` ${t.description.slice(0, SYSTEM_TASK_DESC_CHARS)}`);
|
|
6457
6564
|
}
|
|
6458
6565
|
if (myActive.length > MY_TASK_LIMIT) {
|
|
6459
6566
|
parts.push(`_(${myActive.length - MY_TASK_LIMIT} more active tasks not shown \u2014 use \`task_list\` for full list)_`);
|
|
@@ -6537,7 +6644,7 @@ var init_context_engine = __esm({
|
|
|
6537
6644
|
}
|
|
6538
6645
|
if (!isDream && opts.chatSessions && opts.chatSessions.length > 0) {
|
|
6539
6646
|
const sessionLines = ["\n## Your Chat Sessions with the User"];
|
|
6540
|
-
for (const s of opts.chatSessions.slice(0,
|
|
6647
|
+
for (const s of opts.chatSessions.slice(0, SYSTEM_CHAT_SESSIONS_MAX)) {
|
|
6541
6648
|
const preview = s.lastMessagePreview ? `: "${s.lastMessagePreview}"` : "";
|
|
6542
6649
|
const title = s.title ? ` (${s.title})` : "";
|
|
6543
6650
|
sessionLines.push(`- Session ${s.id}${title} (last active: ${s.lastMessageAt})${preview}`);
|
|
@@ -6576,18 +6683,18 @@ Current date and time: ${localStr} (${tz}, UTC${sign}${absH}:${absM})`);
|
|
|
6576
6683
|
if (ctx.topQueued && ctx.topQueued.length > 0) {
|
|
6577
6684
|
lines.push("You MUST review all waiting items and prioritize user chat/comments above everything else:");
|
|
6578
6685
|
for (const q of ctx.topQueued) {
|
|
6579
|
-
lines.push(` - [${q.type}] p${q.priority}: ${q.summary.slice(0,
|
|
6686
|
+
lines.push(` - [${q.type}] p${q.priority}: ${q.summary.slice(0, SYSTEM_MAILBOX_ITEM_PREVIEW_CHARS)}`);
|
|
6580
6687
|
}
|
|
6581
6688
|
}
|
|
6582
6689
|
if (ctx.recentDecisions && ctx.recentDecisions.length > 0) {
|
|
6583
6690
|
lines.push("**Recent attention decisions**:");
|
|
6584
6691
|
for (const d of ctx.recentDecisions.slice(-5)) {
|
|
6585
|
-
lines.push(` - ${d.type}: ${d.reasoning.slice(0,
|
|
6692
|
+
lines.push(` - ${d.type}: ${d.reasoning.slice(0, SYSTEM_MAILBOX_ITEM_PREVIEW_CHARS)}`);
|
|
6586
6693
|
}
|
|
6587
6694
|
}
|
|
6588
6695
|
if (ctx.mergedContent) {
|
|
6589
6696
|
lines.push(`**Merged context** (absorbed into current work):
|
|
6590
|
-
${ctx.mergedContent.slice(0,
|
|
6697
|
+
${ctx.mergedContent.slice(0, SYSTEM_MAILBOX_MERGED_CHARS)}`);
|
|
6591
6698
|
}
|
|
6592
6699
|
return lines.join("\n");
|
|
6593
6700
|
}
|
|
@@ -6612,7 +6719,7 @@ ${ctx.mergedContent.slice(0, 500)}`);
|
|
|
6612
6719
|
lines.push("- If there is `\u26A0 USER FEEDBACK` above, READ IT FIRST and adjust your approach");
|
|
6613
6720
|
lines.push("- If there are dependency tasks, review ALL their deliverables before starting (`file_read` + `task_get`)");
|
|
6614
6721
|
lines.push("");
|
|
6615
|
-
lines.push("**Workspace setup**: Before modifying code,
|
|
6722
|
+
lines.push("**Workspace setup**: Before modifying project code, set up an isolated workspace (e.g., `git worktree add` into your workspace directory). Some git operations require human approval \u2014 if denied, read the reason and adjust.");
|
|
6616
6723
|
lines.push("");
|
|
6617
6724
|
lines.push("**Execution protocol** (follow the Task Workflow above):");
|
|
6618
6725
|
lines.push("1. **Decompose**: `subtask_create` to break the task into concrete, verifiable steps");
|
|
@@ -8228,29 +8335,12 @@ import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, mkdirSy
|
|
|
8228
8335
|
import { dirname as dirname3, resolve as resolve5 } from "node:path";
|
|
8229
8336
|
function resolveAndCheckAccess(rawPath, workspacePath, policy) {
|
|
8230
8337
|
const resolved = workspacePath ? resolve5(workspacePath, rawPath) : resolve5(rawPath);
|
|
8231
|
-
if (
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
return { resolved, access: "readwrite" };
|
|
8237
|
-
}
|
|
8238
|
-
if (policy.sharedWorkspace && resolved.startsWith(resolve5(policy.sharedWorkspace))) {
|
|
8239
|
-
return { resolved, access: "readwrite" };
|
|
8240
|
-
}
|
|
8241
|
-
if (policy.roleDir && resolved.startsWith(resolve5(policy.roleDir))) {
|
|
8242
|
-
return { resolved, access: "readwrite" };
|
|
8243
|
-
}
|
|
8244
|
-
if (policy.teamDataDir && resolved.startsWith(resolve5(policy.teamDataDir))) {
|
|
8245
|
-
return { resolved, access: "readwrite" };
|
|
8246
|
-
}
|
|
8247
|
-
if (policy.builderArtifactsDir && resolved.startsWith(resolve5(policy.builderArtifactsDir))) {
|
|
8248
|
-
return { resolved, access: "readwrite" };
|
|
8338
|
+
if (policy?.denyWritePaths) {
|
|
8339
|
+
for (const denied of policy.denyWritePaths) {
|
|
8340
|
+
if (resolved.startsWith(resolve5(denied))) {
|
|
8341
|
+
return { resolved, access: "denied" };
|
|
8342
|
+
}
|
|
8249
8343
|
}
|
|
8250
|
-
return { resolved, access: "readonly" };
|
|
8251
|
-
}
|
|
8252
|
-
if (workspacePath && !resolved.startsWith(resolve5(workspacePath))) {
|
|
8253
|
-
return { resolved, access: "readonly" };
|
|
8254
8344
|
}
|
|
8255
8345
|
return { resolved, access: "readwrite" };
|
|
8256
8346
|
}
|
|
@@ -8346,8 +8436,8 @@ function createFileWriteTool(security, workspacePath, policy) {
|
|
|
8346
8436
|
async execute(args) {
|
|
8347
8437
|
const rawPath = args["path"];
|
|
8348
8438
|
const { resolved: path, access } = resolveAndCheckAccess(rawPath, workspacePath, policy);
|
|
8349
|
-
if (access
|
|
8350
|
-
return JSON.stringify({ status: "denied", error: "Write
|
|
8439
|
+
if (access === "denied") {
|
|
8440
|
+
return JSON.stringify({ status: "denied", error: "Write denied: this path belongs to another agent's workspace. Create your own worktree or copy the files to your workspace." });
|
|
8351
8441
|
}
|
|
8352
8442
|
const content = args["content"];
|
|
8353
8443
|
const check2 = guard.validateFilePath(path);
|
|
@@ -8381,8 +8471,8 @@ function createFileEditTool(security, workspacePath, policy) {
|
|
|
8381
8471
|
async execute(args) {
|
|
8382
8472
|
const rawPath = args["path"];
|
|
8383
8473
|
const { resolved: path, access } = resolveAndCheckAccess(rawPath, workspacePath, policy);
|
|
8384
|
-
if (access
|
|
8385
|
-
return JSON.stringify({ status: "denied", error: "Edit
|
|
8474
|
+
if (access === "denied") {
|
|
8475
|
+
return JSON.stringify({ status: "denied", error: "Edit denied: this path belongs to another agent's workspace. Create your own worktree or copy the files to your workspace." });
|
|
8386
8476
|
}
|
|
8387
8477
|
const oldStr = args["old_string"];
|
|
8388
8478
|
const newStr = args["new_string"];
|
|
@@ -41278,8 +41368,8 @@ function createPatchTool(security, workspacePath, policy) {
|
|
|
41278
41368
|
const results = [];
|
|
41279
41369
|
for (const patch of patches) {
|
|
41280
41370
|
const { resolved: filePath, access } = resolveAndCheckAccess(patch.file, workspacePath, policy);
|
|
41281
|
-
if (access
|
|
41282
|
-
return JSON.stringify({ status: "denied", error: `Write
|
|
41371
|
+
if (access === "denied") {
|
|
41372
|
+
return JSON.stringify({ status: "denied", error: `Write denied: this path belongs to another agent's workspace. Cannot ${patch.action}: ${patch.file}` });
|
|
41283
41373
|
}
|
|
41284
41374
|
const check2 = guard.validateFilePath(filePath);
|
|
41285
41375
|
if (!check2.allowed) {
|
|
@@ -43747,12 +43837,6 @@ ${notification.stdoutTail}`);
|
|
|
43747
43837
|
this.stateManager.updateState({ status });
|
|
43748
43838
|
}
|
|
43749
43839
|
this.notifyStateChange();
|
|
43750
|
-
this.eventBus.emit("agent:status-changed", {
|
|
43751
|
-
agentId: this.id,
|
|
43752
|
-
oldStatus,
|
|
43753
|
-
newStatus: status,
|
|
43754
|
-
state: this.getState()
|
|
43755
|
-
});
|
|
43756
43840
|
}
|
|
43757
43841
|
async start(options) {
|
|
43758
43842
|
this.setStatus("idle");
|
|
@@ -43868,7 +43952,7 @@ ${notification.stdoutTail}`);
|
|
|
43868
43952
|
* so the attention controller triggers `executeTask()` instead of a
|
|
43869
43953
|
* lightweight notification.
|
|
43870
43954
|
*/
|
|
43871
|
-
sendTaskExecution(taskId2, taskDescription, onLog, cancelToken,
|
|
43955
|
+
sendTaskExecution(taskId2, taskDescription, onLog, cancelToken, taskProjectContext, executionRound) {
|
|
43872
43956
|
const payload = {
|
|
43873
43957
|
summary: `Task: ${taskDescription.slice(0, 80)}`,
|
|
43874
43958
|
content: taskDescription,
|
|
@@ -43877,7 +43961,7 @@ ${notification.stdoutTail}`);
|
|
|
43877
43961
|
triggerExecution: true,
|
|
43878
43962
|
onLog,
|
|
43879
43963
|
cancelToken,
|
|
43880
|
-
|
|
43964
|
+
taskProjectContext,
|
|
43881
43965
|
executionRound
|
|
43882
43966
|
}
|
|
43883
43967
|
};
|
|
@@ -43944,7 +44028,6 @@ ${notification.stdoutTail}`);
|
|
|
43944
44028
|
return this.processMailboxItemInternal(item);
|
|
43945
44029
|
},
|
|
43946
44030
|
onDecisionMade: (decision) => {
|
|
43947
|
-
this.eventBus.emit("agent:decision", { agentId: this.id, decision });
|
|
43948
44031
|
log16.debug("Attention decision", {
|
|
43949
44032
|
agentId: this.id,
|
|
43950
44033
|
type: decision.decisionType,
|
|
@@ -44027,7 +44110,7 @@ ${notification.stdoutTail}`);
|
|
|
44027
44110
|
const description = item.payload.content;
|
|
44028
44111
|
const onLog = extra.onLog ?? (() => {
|
|
44029
44112
|
});
|
|
44030
|
-
await this.executeTask(taskId2, description, onLog, extra.cancelToken, extra.
|
|
44113
|
+
await this.executeTask(taskId2, description, onLog, extra.cancelToken, extra.taskProjectContext, extra.executionRound);
|
|
44031
44114
|
resolveResponse("");
|
|
44032
44115
|
return;
|
|
44033
44116
|
}
|
|
@@ -44184,6 +44267,12 @@ ${notification.stdoutTail}`);
|
|
|
44184
44267
|
if (this.state.status === "offline")
|
|
44185
44268
|
return;
|
|
44186
44269
|
this.pauseReason = reason;
|
|
44270
|
+
this.heartbeat.stop();
|
|
44271
|
+
this.attentionController.stop();
|
|
44272
|
+
if (this.memoryConsolidationTimer) {
|
|
44273
|
+
clearInterval(this.memoryConsolidationTimer);
|
|
44274
|
+
this.memoryConsolidationTimer = void 0;
|
|
44275
|
+
}
|
|
44187
44276
|
this.setStatus("paused");
|
|
44188
44277
|
this.eventBus.emit("agent:paused", { agentId: this.id, reason });
|
|
44189
44278
|
log16.info(`Agent paused: ${this.config.name}`, { reason });
|
|
@@ -44192,6 +44281,13 @@ ${notification.stdoutTail}`);
|
|
|
44192
44281
|
if (this.state.status !== "paused")
|
|
44193
44282
|
return;
|
|
44194
44283
|
this.pauseReason = void 0;
|
|
44284
|
+
this.heartbeat.start();
|
|
44285
|
+
this.attentionController.start();
|
|
44286
|
+
if (!this.memoryConsolidationTimer) {
|
|
44287
|
+
this.memoryConsolidationTimer = setInterval(() => {
|
|
44288
|
+
this.consolidateMemory().catch((e) => log16.warn("Memory consolidation failed", { error: String(e) }));
|
|
44289
|
+
}, _Agent.MEMORY_CONSOLIDATION_INTERVAL_MS);
|
|
44290
|
+
}
|
|
44195
44291
|
this.setStatus(this.activeTasks.size > 0 ? "working" : "idle");
|
|
44196
44292
|
this.eventBus.emit("agent:resumed", { agentId: this.id });
|
|
44197
44293
|
log16.info(`Agent resumed: ${this.config.name}`);
|
|
@@ -44521,15 +44617,6 @@ ${conversationText}`
|
|
|
44521
44617
|
this.stateManager.updateTokensUsed(tokens);
|
|
44522
44618
|
}
|
|
44523
44619
|
this.notifyStateChange();
|
|
44524
|
-
const profile = this.config.profile;
|
|
44525
|
-
if (profile?.maxTokensPerDay !== void 0 && profile.maxTokensPerDay !== null && this.state.tokensUsedToday >= profile.maxTokensPerDay) {
|
|
44526
|
-
this.setStatus("paused");
|
|
44527
|
-
log16.warn("Agent paused: daily token budget exceeded", {
|
|
44528
|
-
agentId: this.id,
|
|
44529
|
-
tokensUsedToday: this.state.tokensUsedToday,
|
|
44530
|
-
maxTokensPerDay: profile.maxTokensPerDay
|
|
44531
|
-
});
|
|
44532
|
-
}
|
|
44533
44620
|
}
|
|
44534
44621
|
/**
|
|
44535
44622
|
* 获取令牌使用量
|
|
@@ -44548,19 +44635,13 @@ ${conversationText}`
|
|
|
44548
44635
|
}
|
|
44549
44636
|
/**
|
|
44550
44637
|
* Reset daily token counter (called at midnight by scheduler).
|
|
44551
|
-
* If agent was paused due to budget exceeded, resume to idle.
|
|
44552
44638
|
*/
|
|
44553
44639
|
resetDailyTokens() {
|
|
44554
|
-
const wasPausedByBudget = this.state.status === "paused" && this.config.profile?.maxTokensPerDay !== void 0 && this.config.profile.maxTokensPerDay !== null && this.state.tokensUsedToday >= this.config.profile.maxTokensPerDay;
|
|
44555
44640
|
this.state.tokensUsedToday = 0;
|
|
44556
44641
|
if (this.stateManager) {
|
|
44557
44642
|
this.stateManager.resetTokensUsed();
|
|
44558
44643
|
}
|
|
44559
44644
|
this.notifyStateChange();
|
|
44560
|
-
if (wasPausedByBudget) {
|
|
44561
|
-
this.setStatus("idle");
|
|
44562
|
-
log16.info("Agent resumed after daily token reset", { agentId: this.id });
|
|
44563
|
-
}
|
|
44564
44645
|
}
|
|
44565
44646
|
get maxToolIterations() {
|
|
44566
44647
|
return this._maxToolIterations;
|
|
@@ -45551,17 +45632,17 @@ ${chatYield.item.payload.content}`;
|
|
|
45551
45632
|
/**
|
|
45552
45633
|
* 执行任务(兼容旧版本)
|
|
45553
45634
|
*/
|
|
45554
|
-
async executeTask(taskId2, description, onLog, cancelToken,
|
|
45555
|
-
return this.executeTaskConcurrent(taskId2, description, onLog, cancelToken, void 0,
|
|
45635
|
+
async executeTask(taskId2, description, onLog, cancelToken, taskProjectContext, executionRound) {
|
|
45636
|
+
return this.executeTaskConcurrent(taskId2, description, onLog, cancelToken, void 0, taskProjectContext, executionRound);
|
|
45556
45637
|
}
|
|
45557
45638
|
/**
|
|
45558
45639
|
* 并发执行任务(使用TaskExecutor)
|
|
45559
45640
|
*/
|
|
45560
|
-
async executeTaskConcurrent(taskId2, description, onLog, cancelToken, priority = TaskPriority.MEDIUM,
|
|
45641
|
+
async executeTaskConcurrent(taskId2, description, onLog, cancelToken, priority = TaskPriority.MEDIUM, taskProjectContext, executionRound) {
|
|
45561
45642
|
if (!this.taskExecutor) {
|
|
45562
45643
|
throw new Error("Task executor not initialized");
|
|
45563
45644
|
}
|
|
45564
|
-
const result = await this.taskExecutor.executeTaskTask(taskId2, () => taskAsyncContext.run({ taskId: taskId2 }, () => this._executeTaskInternal(taskId2, description, onLog, cancelToken,
|
|
45645
|
+
const result = await this.taskExecutor.executeTaskTask(taskId2, () => taskAsyncContext.run({ taskId: taskId2 }, () => this._executeTaskInternal(taskId2, description, onLog, cancelToken, taskProjectContext, executionRound)), {
|
|
45565
45646
|
priority,
|
|
45566
45647
|
onProgress: (progress, currentStep) => {
|
|
45567
45648
|
onLog({
|
|
@@ -45580,7 +45661,7 @@ ${chatYield.item.payload.content}`;
|
|
|
45580
45661
|
/**
|
|
45581
45662
|
* 内部任务执行逻辑(原executeTask的核心逻辑)
|
|
45582
45663
|
*/
|
|
45583
|
-
async _executeTaskInternal(taskId2, description, onLog, cancelToken,
|
|
45664
|
+
async _executeTaskInternal(taskId2, description, onLog, cancelToken, taskProjectContext, executionRound) {
|
|
45584
45665
|
this.currentTaskId = taskId2;
|
|
45585
45666
|
if (this.config.profile?.maxConcurrentTasks !== void 0 && this.config.profile.maxConcurrentTasks !== null && this.activeTasks.size >= this.config.profile.maxConcurrentTasks) {
|
|
45586
45667
|
throw new Error(`Agent has reached maximum concurrent tasks (${this.config.profile.maxConcurrentTasks})`);
|
|
@@ -45610,35 +45691,11 @@ ${chatYield.item.payload.content}`;
|
|
|
45610
45691
|
alsStore.subagentProgress = subagentProgress;
|
|
45611
45692
|
}
|
|
45612
45693
|
emit("status", "started", { agentId: this.id, agentName: this.config.name });
|
|
45613
|
-
if (
|
|
45614
|
-
|
|
45615
|
-
primaryWorkspace: taskWorkspace.repoPath,
|
|
45616
|
-
sharedWorkspace: this.pathPolicy?.sharedWorkspace,
|
|
45617
|
-
readOnlyPaths: [
|
|
45618
|
-
...this.pathPolicy?.readOnlyPaths ?? [],
|
|
45619
|
-
...taskWorkspace.projectContext?.repositories?.filter((r) => r.localPath !== taskWorkspace.repoPath).map((r) => r.localPath) ?? []
|
|
45620
|
-
].filter(Boolean)
|
|
45621
|
-
};
|
|
45622
|
-
if (!taskPolicy.readOnlyPaths?.length)
|
|
45623
|
-
taskPolicy.readOnlyPaths = void 0;
|
|
45624
|
-
const taskTools = createBuiltinTools({
|
|
45625
|
-
agentId: this.id,
|
|
45626
|
-
workspacePath: taskWorkspace.repoPath,
|
|
45627
|
-
pathPolicy: taskPolicy,
|
|
45628
|
-
onCommandApproval: this.getCommandApprovalCallback()
|
|
45629
|
-
});
|
|
45630
|
-
const taskLocalTools = new Map(this.tools);
|
|
45631
|
-
for (const tool of taskTools) {
|
|
45632
|
-
taskLocalTools.set(tool.name, tool);
|
|
45633
|
-
}
|
|
45634
|
-
const ctx = taskAsyncContext.getStore();
|
|
45635
|
-
if (ctx) {
|
|
45636
|
-
ctx.tools = taskLocalTools;
|
|
45637
|
-
}
|
|
45638
|
-
log16.info("Tools rebound to project repo (task-local)", {
|
|
45694
|
+
if (taskProjectContext) {
|
|
45695
|
+
log16.info("Task execution with project context", {
|
|
45639
45696
|
taskId: taskId2,
|
|
45640
45697
|
agentId: this.id,
|
|
45641
|
-
|
|
45698
|
+
repos: taskProjectContext.repositories.map((r) => r.localPath)
|
|
45642
45699
|
});
|
|
45643
45700
|
}
|
|
45644
45701
|
const abortController = new AbortController();
|
|
@@ -45718,11 +45775,7 @@ ${chatYield.item.payload.content}`;
|
|
|
45718
45775
|
deliverableContext: this.getDeliverableContext(taskPrompt),
|
|
45719
45776
|
environment: this.environmentProfile,
|
|
45720
45777
|
scenario: "task_execution",
|
|
45721
|
-
...
|
|
45722
|
-
projectContext: taskWorkspace.projectContext,
|
|
45723
|
-
taskBranch: taskWorkspace.branch,
|
|
45724
|
-
taskBaseBranch: taskWorkspace.baseBranch
|
|
45725
|
-
} : {},
|
|
45778
|
+
...taskProjectContext ? { projectContext: taskProjectContext } : {},
|
|
45726
45779
|
agentWorkspace: this.pathPolicy ? {
|
|
45727
45780
|
primaryWorkspace: this.pathPolicy.primaryWorkspace,
|
|
45728
45781
|
sharedWorkspace: this.pathPolicy.sharedWorkspace,
|
|
@@ -46144,53 +46197,6 @@ ${yieldResult.item.payload.content}`
|
|
|
46144
46197
|
this.activatedExtraTools.add(name);
|
|
46145
46198
|
}
|
|
46146
46199
|
}
|
|
46147
|
-
/**
|
|
46148
|
-
* Dynamically add a read-only path to this agent's access policy and rebuild tools.
|
|
46149
|
-
* Used when assigning review tasks so the reviewer can read the worker's workspace.
|
|
46150
|
-
*/
|
|
46151
|
-
grantReadOnlyAccess(path) {
|
|
46152
|
-
if (!this.pathPolicy)
|
|
46153
|
-
return;
|
|
46154
|
-
const existing = this.pathPolicy.readOnlyPaths ?? [];
|
|
46155
|
-
if (existing.includes(path))
|
|
46156
|
-
return;
|
|
46157
|
-
this.pathPolicy = {
|
|
46158
|
-
...this.pathPolicy,
|
|
46159
|
-
readOnlyPaths: [...existing, path]
|
|
46160
|
-
};
|
|
46161
|
-
const updatedTools = createBuiltinTools({
|
|
46162
|
-
agentId: this.id,
|
|
46163
|
-
workspacePath: this.pathPolicy.primaryWorkspace,
|
|
46164
|
-
pathPolicy: this.pathPolicy,
|
|
46165
|
-
onCommandApproval: this.getCommandApprovalCallback()
|
|
46166
|
-
});
|
|
46167
|
-
for (const tool of updatedTools) {
|
|
46168
|
-
this.tools.set(tool.name, tool);
|
|
46169
|
-
}
|
|
46170
|
-
log16.info("Granted read-only access", { agentId: this.id, path });
|
|
46171
|
-
}
|
|
46172
|
-
/**
|
|
46173
|
-
* Remove a previously granted read-only path and rebuild tools.
|
|
46174
|
-
*/
|
|
46175
|
-
revokeReadOnlyAccess(path) {
|
|
46176
|
-
if (!this.pathPolicy?.readOnlyPaths)
|
|
46177
|
-
return;
|
|
46178
|
-
const filtered = this.pathPolicy.readOnlyPaths.filter((p) => p !== path);
|
|
46179
|
-
this.pathPolicy = {
|
|
46180
|
-
...this.pathPolicy,
|
|
46181
|
-
readOnlyPaths: filtered.length ? filtered : void 0
|
|
46182
|
-
};
|
|
46183
|
-
const updatedTools = createBuiltinTools({
|
|
46184
|
-
agentId: this.id,
|
|
46185
|
-
workspacePath: this.pathPolicy.primaryWorkspace,
|
|
46186
|
-
pathPolicy: this.pathPolicy,
|
|
46187
|
-
onCommandApproval: this.getCommandApprovalCallback()
|
|
46188
|
-
});
|
|
46189
|
-
for (const tool of updatedTools) {
|
|
46190
|
-
this.tools.set(tool.name, tool);
|
|
46191
|
-
}
|
|
46192
|
-
log16.info("Revoked read-only access", { agentId: this.id, path });
|
|
46193
|
-
}
|
|
46194
46200
|
getState() {
|
|
46195
46201
|
const state = { ...this.state };
|
|
46196
46202
|
if (state.status === "error" && !state.lastError) {
|
|
@@ -46667,7 +46673,7 @@ ${latest.content}
|
|
|
46667
46673
|
"",
|
|
46668
46674
|
todayLog ? `**Today's activity log (${todayDate})**:
|
|
46669
46675
|
\`\`\`
|
|
46670
|
-
${todayLog.slice(0,
|
|
46676
|
+
${todayLog.slice(0, HEARTBEAT_DAILY_LOG_CHARS)}
|
|
46671
46677
|
\`\`\`` : `**Today's activity log**: No activity recorded for ${todayDate}.`,
|
|
46672
46678
|
"",
|
|
46673
46679
|
"**Report format** \u2014 create a deliverable via `deliverable_create`:",
|
|
@@ -46687,15 +46693,34 @@ ${todayLog.slice(0, 3e3)}
|
|
|
46687
46693
|
].join("\n");
|
|
46688
46694
|
}
|
|
46689
46695
|
const selfEvolutionSection = [
|
|
46696
|
+
"",
|
|
46697
|
+
"## Completed Task Review & Best Practice Extraction",
|
|
46698
|
+
"Use `task_list` to find tasks recently completed (status `completed`) where you were the assignee.",
|
|
46699
|
+
"For each completed task since your last heartbeat:",
|
|
46700
|
+
"",
|
|
46701
|
+
"1. **What went well?** \u2014 Identify approaches, patterns, or techniques that led to a smooth completion.",
|
|
46702
|
+
" - First-pass approvals (no revision needed) are strong signals of good practice.",
|
|
46703
|
+
" - Efficient tool usage, clean code patterns, good decomposition strategies.",
|
|
46704
|
+
"2. **What could be improved?** \u2014 Note any friction, rework, or reviewer feedback that revealed a better way.",
|
|
46705
|
+
"3. **Is there a repeatable pattern?** \u2014 If you solved a class of problems (not just one instance), this is SOP material.",
|
|
46706
|
+
"",
|
|
46707
|
+
"If you identify a best practice worth preserving:",
|
|
46708
|
+
'- Save it via `memory_save` with `tags: ["lesson", "best-practice", ...]` and format:',
|
|
46709
|
+
" `[BEST-PRACTICE] <one-line summary>\\nContext: <when this applies>\\nApproach: <what to do>\\nWhy: <why this works>`",
|
|
46710
|
+
'- If it is a multi-step repeatable workflow, promote it to an SOP via `memory_update_longterm({ section: "sops", ... })`.',
|
|
46690
46711
|
"",
|
|
46691
46712
|
"## Self-Evolution Reflection",
|
|
46692
|
-
"
|
|
46693
|
-
"Follow your **self-evolution** skill instructions. Check each layer:",
|
|
46713
|
+
"After reviewing completed tasks, reflect on your overall growth. Follow your **self-evolution** skill instructions:",
|
|
46694
46714
|
"",
|
|
46695
46715
|
'1. **Lessons** \u2014 Did anything go wrong or get corrected? Save with `memory_save` using `tags: ["lesson", ...]` and the `[LESSON]` format.',
|
|
46696
46716
|
'2. **Tool preferences** \u2014 Did you discover a better tool or parameter for a task? Save with `tags: ["lesson", "tool-preference", ...]` and the `[TOOL-PREF]` format.',
|
|
46697
|
-
'3. **SOPs** \u2014
|
|
46698
|
-
|
|
46717
|
+
'3. **SOPs** \u2014 Consolidate best practices from completed tasks into SOPs. Update `memory_update_longterm({ section: "sops", ... })`.',
|
|
46718
|
+
' - Review existing SOPs first (`memory_search("sops")`) \u2014 update rather than duplicate.',
|
|
46719
|
+
" - Each SOP: trigger, steps, gotchas, last updated date.",
|
|
46720
|
+
"4. **Role evolution** \u2014 When you accumulate 3+ related best practices or lessons pointing to a fundamental behavioral improvement, update your ROLE.md:",
|
|
46721
|
+
" - Read current ROLE.md via `file_read`",
|
|
46722
|
+
" - Append the new guideline (do NOT rewrite the file)",
|
|
46723
|
+
' - Log the change via `memory_save` with `tags: ["lesson", "role-evolution"]`',
|
|
46699
46724
|
"",
|
|
46700
46725
|
"Quality bar: Only record insights that are **specific**, **actionable**, and **non-obvious**.",
|
|
46701
46726
|
"Skip if nothing meaningful happened since last heartbeat."
|
|
@@ -47960,7 +47985,13 @@ function createManagerTools(ctx) {
|
|
|
47960
47985
|
},
|
|
47961
47986
|
async execute(args) {
|
|
47962
47987
|
try {
|
|
47963
|
-
const
|
|
47988
|
+
const templateId = args["template_id"]?.trim();
|
|
47989
|
+
const name = args["name"]?.trim();
|
|
47990
|
+
if (!templateId)
|
|
47991
|
+
return JSON.stringify({ status: "error", error: "template_id is required" });
|
|
47992
|
+
if (!name)
|
|
47993
|
+
return JSON.stringify({ status: "error", error: "name is required \u2014 please provide a display name for the new agent" });
|
|
47994
|
+
const result = await ctx.hireFromTemplate(templateId, name, args["skills"]);
|
|
47964
47995
|
return JSON.stringify({
|
|
47965
47996
|
status: "success",
|
|
47966
47997
|
agent: result,
|
|
@@ -48014,7 +48045,13 @@ function createManagerTools(ctx) {
|
|
|
48014
48045
|
},
|
|
48015
48046
|
async execute(args) {
|
|
48016
48047
|
try {
|
|
48017
|
-
const
|
|
48048
|
+
const type = args["type"]?.trim();
|
|
48049
|
+
const name = args["name"]?.trim();
|
|
48050
|
+
if (!type || !["agent", "team", "skill"].includes(type))
|
|
48051
|
+
return JSON.stringify({ status: "error", error: "type is required and must be one of: agent, team, skill" });
|
|
48052
|
+
if (!name)
|
|
48053
|
+
return JSON.stringify({ status: "error", error: "name is required \u2014 provide the artifact name from builder_list" });
|
|
48054
|
+
const result = await ctx.installArtifact(type, name);
|
|
48018
48055
|
const isAgentOrTeam = result.type === "agent" || result.type === "team";
|
|
48019
48056
|
return JSON.stringify({
|
|
48020
48057
|
status: "success",
|
|
@@ -48084,7 +48121,10 @@ function createHubTools(ctx) {
|
|
|
48084
48121
|
},
|
|
48085
48122
|
async execute(args) {
|
|
48086
48123
|
try {
|
|
48087
|
-
const
|
|
48124
|
+
const itemId = args["item_id"]?.trim();
|
|
48125
|
+
if (!itemId)
|
|
48126
|
+
return JSON.stringify({ status: "error", error: "item_id is required \u2014 use hub_search to find available items first" });
|
|
48127
|
+
const result = await ctx.downloadAndInstall(itemId);
|
|
48088
48128
|
const isAgentOrTeam = result.type === "agent" || result.type === "team";
|
|
48089
48129
|
return JSON.stringify({
|
|
48090
48130
|
status: "success",
|
|
@@ -48815,14 +48855,14 @@ function createAgentTaskTools(ctx) {
|
|
|
48815
48855
|
const taskObj = task;
|
|
48816
48856
|
if (!full) {
|
|
48817
48857
|
const notes = taskObj["notes"];
|
|
48818
|
-
if (notes && notes.length >
|
|
48819
|
-
taskObj["notes"] = notes.slice(-
|
|
48820
|
-
taskObj["_notesTruncated"] = { total: notes.length, showing:
|
|
48858
|
+
if (notes && notes.length > TASK_GET_NOTES_DEFAULT) {
|
|
48859
|
+
taskObj["notes"] = notes.slice(-TASK_GET_NOTES_DEFAULT);
|
|
48860
|
+
taskObj["_notesTruncated"] = { total: notes.length, showing: TASK_GET_NOTES_DEFAULT, hint: "Use full=true to see all" };
|
|
48821
48861
|
}
|
|
48822
48862
|
const deliverables2 = taskObj["deliverables"];
|
|
48823
|
-
if (deliverables2 && deliverables2.length >
|
|
48824
|
-
taskObj["deliverables"] = deliverables2.slice(0,
|
|
48825
|
-
taskObj["_deliverablesTruncated"] = { total: deliverables2.length, showing:
|
|
48863
|
+
if (deliverables2 && deliverables2.length > TASK_GET_DELIVERABLES_DEFAULT) {
|
|
48864
|
+
taskObj["deliverables"] = deliverables2.slice(0, TASK_GET_DELIVERABLES_DEFAULT);
|
|
48865
|
+
taskObj["_deliverablesTruncated"] = { total: deliverables2.length, showing: TASK_GET_DELIVERABLES_DEFAULT, hint: "Use full=true to see all" };
|
|
48826
48866
|
}
|
|
48827
48867
|
}
|
|
48828
48868
|
return JSON.stringify({ status: "success", task: taskObj });
|
|
@@ -50898,10 +50938,19 @@ Priority: ${delegation.priority}`, envelope.from, { name: envelope.from, role: "
|
|
|
50898
50938
|
* and any project repos as read-only paths.
|
|
50899
50939
|
*/
|
|
50900
50940
|
static BUILDER_ROLES = /* @__PURE__ */ new Set(["agent-father", "team-factory", "skill-architect"]);
|
|
50901
|
-
buildPathPolicy(
|
|
50941
|
+
buildPathPolicy(agentId2, workspacePath, roleDir, teamDataDir, builderArtifactsDir) {
|
|
50942
|
+
const agentOwnDir = join11(this.dataDir, agentId2);
|
|
50943
|
+
const denyWritePaths = [];
|
|
50944
|
+
if (existsSync17(this.dataDir)) {
|
|
50945
|
+
for (const entry of readdirSync4(this.dataDir, { withFileTypes: true })) {
|
|
50946
|
+
if (entry.isDirectory() && entry.name !== agentId2) {
|
|
50947
|
+
denyWritePaths.push(join11(this.dataDir, entry.name));
|
|
50948
|
+
}
|
|
50949
|
+
}
|
|
50950
|
+
}
|
|
50902
50951
|
const policy = {
|
|
50903
50952
|
primaryWorkspace: workspacePath,
|
|
50904
|
-
|
|
50953
|
+
denyWritePaths: denyWritePaths.length ? denyWritePaths : void 0
|
|
50905
50954
|
};
|
|
50906
50955
|
if (this.sharedDataDir) {
|
|
50907
50956
|
policy.sharedWorkspace = this.sharedDataDir;
|
|
@@ -50918,6 +50967,8 @@ Priority: ${delegation.priority}`, envelope.from, { name: envelope.from, role: "
|
|
|
50918
50967
|
return policy;
|
|
50919
50968
|
}
|
|
50920
50969
|
async createAgent(request) {
|
|
50970
|
+
if (!request.name?.trim())
|
|
50971
|
+
throw new Error("Agent name is required");
|
|
50921
50972
|
const id = agentId();
|
|
50922
50973
|
const role = this.roleLoader.loadRole(request.roleName);
|
|
50923
50974
|
const agentDataDir = join11(this.dataDir, id);
|
|
@@ -50952,20 +51003,10 @@ Priority: ${delegation.priority}`, envelope.from, { name: envelope.from, role: "
|
|
|
50952
51003
|
mkdirSync11(workspacePath, { recursive: true });
|
|
50953
51004
|
const teamDataDir = request.teamId && request.agentRole === "manager" ? join11(homedir5(), ".markus", "teams", request.teamId) : void 0;
|
|
50954
51005
|
const builderArtifactsDir = join11(homedir5(), ".markus", "builder-artifacts");
|
|
50955
|
-
const pathPolicy = this.buildPathPolicy(
|
|
50956
|
-
const securityAllowlist = [workspacePath, agentRoleDir];
|
|
50957
|
-
if (pathPolicy.sharedWorkspace)
|
|
50958
|
-
securityAllowlist.push(pathPolicy.sharedWorkspace);
|
|
50959
|
-
if (pathPolicy.teamDataDir)
|
|
50960
|
-
securityAllowlist.push(pathPolicy.teamDataDir);
|
|
50961
|
-
if (pathPolicy.builderArtifactsDir)
|
|
50962
|
-
securityAllowlist.push(pathPolicy.builderArtifactsDir);
|
|
50963
|
-
if (pathPolicy.readOnlyPaths)
|
|
50964
|
-
securityAllowlist.push(...pathPolicy.readOnlyPaths);
|
|
51006
|
+
const pathPolicy = this.buildPathPolicy(id, workspacePath, agentRoleDir, teamDataDir, builderArtifactsDir);
|
|
50965
51007
|
const basePolicy = request.securityPolicy ?? this.globalSecurityPolicy;
|
|
50966
51008
|
const security = new SecurityGuard({
|
|
50967
|
-
...basePolicy
|
|
50968
|
-
pathAllowlist: [...basePolicy?.pathAllowlist ?? [], ...securityAllowlist]
|
|
51009
|
+
...basePolicy
|
|
50969
51010
|
});
|
|
50970
51011
|
const agentMeta = {
|
|
50971
51012
|
agentId: id,
|
|
@@ -51502,20 +51543,10 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
51502
51543
|
mkdirSync11(workspacePath, { recursive: true });
|
|
51503
51544
|
const teamDataDir = config.teamId && config.agentRole === "manager" ? join11(homedir5(), ".markus", "teams", config.teamId) : void 0;
|
|
51504
51545
|
const builderArtifactsDir = join11(homedir5(), ".markus", "builder-artifacts");
|
|
51505
|
-
const pathPolicy = this.buildPathPolicy(
|
|
51506
|
-
const securityAllowlist = [workspacePath, agentRoleDir];
|
|
51507
|
-
if (pathPolicy.sharedWorkspace)
|
|
51508
|
-
securityAllowlist.push(pathPolicy.sharedWorkspace);
|
|
51509
|
-
if (pathPolicy.teamDataDir)
|
|
51510
|
-
securityAllowlist.push(pathPolicy.teamDataDir);
|
|
51511
|
-
if (pathPolicy.builderArtifactsDir)
|
|
51512
|
-
securityAllowlist.push(pathPolicy.builderArtifactsDir);
|
|
51513
|
-
if (pathPolicy.readOnlyPaths)
|
|
51514
|
-
securityAllowlist.push(...pathPolicy.readOnlyPaths);
|
|
51546
|
+
const pathPolicy = this.buildPathPolicy(id, workspacePath, agentRoleDir, teamDataDir, builderArtifactsDir);
|
|
51515
51547
|
const basePolicy = this.globalSecurityPolicy;
|
|
51516
51548
|
const security = new SecurityGuard({
|
|
51517
|
-
...basePolicy
|
|
51518
|
-
pathAllowlist: [...basePolicy?.pathAllowlist ?? [], ...securityAllowlist]
|
|
51549
|
+
...basePolicy
|
|
51519
51550
|
});
|
|
51520
51551
|
const agentMeta = {
|
|
51521
51552
|
agentId: id,
|
|
@@ -52028,28 +52059,6 @@ Known issues: ${knownIssues}` : ""}`
|
|
|
52028
52059
|
hasAgent(agentId2) {
|
|
52029
52060
|
return this.agents.has(agentId2);
|
|
52030
52061
|
}
|
|
52031
|
-
/**
|
|
52032
|
-
* Grant a reviewer agent read-only access to a task's workspace.
|
|
52033
|
-
* Called when a task enters review and a reviewer is assigned.
|
|
52034
|
-
*/
|
|
52035
|
-
grantReviewAccess(reviewerAgentId, workspacePath) {
|
|
52036
|
-
if (!this.agents.has(reviewerAgentId))
|
|
52037
|
-
return;
|
|
52038
|
-
const reviewer = this.getAgent(reviewerAgentId);
|
|
52039
|
-
reviewer.grantReadOnlyAccess(workspacePath);
|
|
52040
|
-
log30.info("Granted reviewer access to task workspace", { reviewerAgentId, workspacePath });
|
|
52041
|
-
}
|
|
52042
|
-
/**
|
|
52043
|
-
* Revoke a reviewer agent's read-only access to a task's workspace.
|
|
52044
|
-
* Called when a review is complete or the reviewer changes.
|
|
52045
|
-
*/
|
|
52046
|
-
revokeReviewAccess(reviewerAgentId, workspacePath) {
|
|
52047
|
-
if (!this.agents.has(reviewerAgentId))
|
|
52048
|
-
return;
|
|
52049
|
-
const reviewer = this.getAgent(reviewerAgentId);
|
|
52050
|
-
reviewer.revokeReadOnlyAccess(workspacePath);
|
|
52051
|
-
log30.info("Revoked reviewer access to task workspace", { reviewerAgentId, workspacePath });
|
|
52052
|
-
}
|
|
52053
52062
|
setAuditCallback(cb) {
|
|
52054
52063
|
this.agentAuditCallback = cb;
|
|
52055
52064
|
for (const [id, agent] of this.agents) {
|
|
@@ -55580,19 +55589,6 @@ var init_review_service = __esm({
|
|
|
55580
55589
|
}
|
|
55581
55590
|
});
|
|
55582
55591
|
|
|
55583
|
-
// ../core/dist/workspace-manager.js
|
|
55584
|
-
import { exec as execCb2 } from "node:child_process";
|
|
55585
|
-
import { promisify as promisify3 } from "node:util";
|
|
55586
|
-
var execAsync2, log38;
|
|
55587
|
-
var init_workspace_manager = __esm({
|
|
55588
|
-
"../core/dist/workspace-manager.js"() {
|
|
55589
|
-
"use strict";
|
|
55590
|
-
init_dist();
|
|
55591
|
-
execAsync2 = promisify3(execCb2);
|
|
55592
|
-
log38 = createLogger("workspace-manager");
|
|
55593
|
-
}
|
|
55594
|
-
});
|
|
55595
|
-
|
|
55596
55592
|
// ../core/dist/tools/index.js
|
|
55597
55593
|
var init_tools = __esm({
|
|
55598
55594
|
"../core/dist/tools/index.js"() {
|
|
@@ -55619,22 +55615,22 @@ var init_tools = __esm({
|
|
|
55619
55615
|
});
|
|
55620
55616
|
|
|
55621
55617
|
// ../core/dist/tool-profiles.js
|
|
55622
|
-
var
|
|
55618
|
+
var log38;
|
|
55623
55619
|
var init_tool_profiles = __esm({
|
|
55624
55620
|
"../core/dist/tool-profiles.js"() {
|
|
55625
55621
|
"use strict";
|
|
55626
55622
|
init_dist();
|
|
55627
|
-
|
|
55623
|
+
log38 = createLogger("tool-profiles");
|
|
55628
55624
|
}
|
|
55629
55625
|
});
|
|
55630
55626
|
|
|
55631
55627
|
// ../core/dist/skills/registry.js
|
|
55632
|
-
var
|
|
55628
|
+
var log39, InMemorySkillRegistry;
|
|
55633
55629
|
var init_registry = __esm({
|
|
55634
55630
|
"../core/dist/skills/registry.js"() {
|
|
55635
55631
|
"use strict";
|
|
55636
55632
|
init_dist();
|
|
55637
|
-
|
|
55633
|
+
log39 = createLogger("skill-registry");
|
|
55638
55634
|
InMemorySkillRegistry = class _InMemorySkillRegistry {
|
|
55639
55635
|
skills = /* @__PURE__ */ new Map();
|
|
55640
55636
|
aliases = /* @__PURE__ */ new Map();
|
|
@@ -55644,18 +55640,18 @@ var init_registry = __esm({
|
|
|
55644
55640
|
register(skill) {
|
|
55645
55641
|
const name = skill.manifest.name;
|
|
55646
55642
|
if (this.skills.has(name)) {
|
|
55647
|
-
|
|
55643
|
+
log39.warn(`Skill ${name} already registered, overwriting`);
|
|
55648
55644
|
}
|
|
55649
55645
|
this.skills.set(name, skill);
|
|
55650
55646
|
this.aliases.set(_InMemorySkillRegistry.normalize(name), name);
|
|
55651
|
-
|
|
55647
|
+
log39.info(`Skill registered: ${name} v${skill.manifest.version}`, {
|
|
55652
55648
|
hasInstructions: !!skill.manifest.instructions
|
|
55653
55649
|
});
|
|
55654
55650
|
}
|
|
55655
55651
|
unregister(skillName) {
|
|
55656
55652
|
this.skills.delete(skillName);
|
|
55657
55653
|
this.aliases.delete(_InMemorySkillRegistry.normalize(skillName));
|
|
55658
|
-
|
|
55654
|
+
log39.info(`Skill unregistered: ${skillName}`);
|
|
55659
55655
|
}
|
|
55660
55656
|
get(skillName) {
|
|
55661
55657
|
return this.skills.get(skillName) ?? this.skills.get(this.aliases.get(_InMemorySkillRegistry.normalize(skillName)) ?? "");
|
|
@@ -55740,12 +55736,12 @@ function readSkillInstructions(skillDir) {
|
|
|
55740
55736
|
return void 0;
|
|
55741
55737
|
}
|
|
55742
55738
|
}
|
|
55743
|
-
var
|
|
55739
|
+
var log40;
|
|
55744
55740
|
var init_loader = __esm({
|
|
55745
55741
|
"../core/dist/skills/loader.js"() {
|
|
55746
55742
|
"use strict";
|
|
55747
55743
|
init_dist();
|
|
55748
|
-
|
|
55744
|
+
log40 = createLogger("skill-loader");
|
|
55749
55745
|
}
|
|
55750
55746
|
});
|
|
55751
55747
|
|
|
@@ -55830,7 +55826,7 @@ function discoverSkillsInDir(dir) {
|
|
|
55830
55826
|
results.push({ manifest, path: skillDir, source: dir });
|
|
55831
55827
|
}
|
|
55832
55828
|
} catch (err) {
|
|
55833
|
-
|
|
55829
|
+
log41.warn(`Invalid SKILL.md in ${skillDir}: ${err}`);
|
|
55834
55830
|
}
|
|
55835
55831
|
continue;
|
|
55836
55832
|
}
|
|
@@ -55846,14 +55842,14 @@ async function createDefaultSkillRegistry(options) {
|
|
|
55846
55842
|
const found = discoverSkillsInDir(dir);
|
|
55847
55843
|
for (const { manifest, path: skillPath } of found) {
|
|
55848
55844
|
if (registry.get(manifest.name)) {
|
|
55849
|
-
|
|
55845
|
+
log41.debug(`Skill ${manifest.name} already registered, skipping ${skillPath}`);
|
|
55850
55846
|
continue;
|
|
55851
55847
|
}
|
|
55852
55848
|
manifest.sourcePath = skillPath;
|
|
55853
55849
|
if (isBuiltin)
|
|
55854
55850
|
manifest.builtIn = true;
|
|
55855
55851
|
registry.register({ manifest });
|
|
55856
|
-
|
|
55852
|
+
log41.info(`Loaded skill: ${manifest.name} from ${skillPath}`, {
|
|
55857
55853
|
hasInstructions: !!manifest.instructions,
|
|
55858
55854
|
builtIn: isBuiltin
|
|
55859
55855
|
});
|
|
@@ -55861,7 +55857,7 @@ async function createDefaultSkillRegistry(options) {
|
|
|
55861
55857
|
}
|
|
55862
55858
|
return registry;
|
|
55863
55859
|
}
|
|
55864
|
-
var
|
|
55860
|
+
var log41, WELL_KNOWN_SKILL_DIRS;
|
|
55865
55861
|
var init_skills = __esm({
|
|
55866
55862
|
"../core/dist/skills/index.js"() {
|
|
55867
55863
|
"use strict";
|
|
@@ -55869,7 +55865,7 @@ var init_skills = __esm({
|
|
|
55869
55865
|
init_dist();
|
|
55870
55866
|
init_registry();
|
|
55871
55867
|
init_loader();
|
|
55872
|
-
|
|
55868
|
+
log41 = createLogger("skill-registry");
|
|
55873
55869
|
WELL_KNOWN_SKILL_DIRS = [
|
|
55874
55870
|
join15(homedir8(), ".markus", "skills"),
|
|
55875
55871
|
join15(homedir8(), ".claude", "skills"),
|
|
@@ -56087,12 +56083,12 @@ function createDefaultTemplateRegistry() {
|
|
|
56087
56083
|
}
|
|
56088
56084
|
return registry;
|
|
56089
56085
|
}
|
|
56090
|
-
var
|
|
56086
|
+
var log42, TemplateRegistry;
|
|
56091
56087
|
var init_registry2 = __esm({
|
|
56092
56088
|
"../core/dist/templates/registry.js"() {
|
|
56093
56089
|
"use strict";
|
|
56094
56090
|
init_dist();
|
|
56095
|
-
|
|
56091
|
+
log42 = createLogger("template-registry");
|
|
56096
56092
|
TemplateRegistry = class {
|
|
56097
56093
|
templates = /* @__PURE__ */ new Map();
|
|
56098
56094
|
persistence;
|
|
@@ -56115,16 +56111,16 @@ var init_registry2 = __esm({
|
|
|
56115
56111
|
loaded++;
|
|
56116
56112
|
}
|
|
56117
56113
|
}
|
|
56118
|
-
|
|
56114
|
+
log42.info(`Synced ${loaded} templates from database`, { total: this.templates.size });
|
|
56119
56115
|
return loaded;
|
|
56120
56116
|
} catch (err) {
|
|
56121
|
-
|
|
56117
|
+
log42.warn("Failed to sync templates from database", { error: String(err) });
|
|
56122
56118
|
return 0;
|
|
56123
56119
|
}
|
|
56124
56120
|
}
|
|
56125
56121
|
register(template) {
|
|
56126
56122
|
this.templates.set(template.id, template);
|
|
56127
|
-
|
|
56123
|
+
log42.info(`Template registered: ${template.name} (${template.id})`, {
|
|
56128
56124
|
source: template.source,
|
|
56129
56125
|
category: template.category
|
|
56130
56126
|
});
|
|
@@ -56186,12 +56182,12 @@ var init_templates = __esm({
|
|
|
56186
56182
|
});
|
|
56187
56183
|
|
|
56188
56184
|
// ../core/dist/workflow/engine.js
|
|
56189
|
-
var
|
|
56185
|
+
var log43, WorkflowEngine;
|
|
56190
56186
|
var init_engine = __esm({
|
|
56191
56187
|
"../core/dist/workflow/engine.js"() {
|
|
56192
56188
|
"use strict";
|
|
56193
56189
|
init_dist();
|
|
56194
|
-
|
|
56190
|
+
log43 = createLogger("workflow-engine");
|
|
56195
56191
|
WorkflowEngine = class {
|
|
56196
56192
|
executor;
|
|
56197
56193
|
executions = /* @__PURE__ */ new Map();
|
|
@@ -56212,7 +56208,7 @@ var init_engine = __esm({
|
|
|
56212
56208
|
try {
|
|
56213
56209
|
handler4(event);
|
|
56214
56210
|
} catch (err) {
|
|
56215
|
-
|
|
56211
|
+
log43.warn("Event handler error", { error: String(err) });
|
|
56216
56212
|
}
|
|
56217
56213
|
}
|
|
56218
56214
|
}
|
|
@@ -56307,7 +56303,7 @@ var init_engine = __esm({
|
|
|
56307
56303
|
};
|
|
56308
56304
|
this.executions.set(executionId, execution);
|
|
56309
56305
|
this.emit({ type: "workflow_started", executionId, timestamp: /* @__PURE__ */ new Date() });
|
|
56310
|
-
|
|
56306
|
+
log43.info("Workflow started", { executionId, workflowId: def.id, stepCount: def.steps.length });
|
|
56311
56307
|
try {
|
|
56312
56308
|
await this.executeGraph(def, execution);
|
|
56313
56309
|
if (execution.status === "cancelled")
|
|
@@ -56320,13 +56316,13 @@ var init_engine = __esm({
|
|
|
56320
56316
|
execution.status = "completed";
|
|
56321
56317
|
execution.completedAt = /* @__PURE__ */ new Date();
|
|
56322
56318
|
this.emit({ type: "workflow_completed", executionId, timestamp: /* @__PURE__ */ new Date(), data: execution.outputs });
|
|
56323
|
-
|
|
56319
|
+
log43.info("Workflow completed", { executionId, elapsed: Date.now() - execution.startedAt.getTime() });
|
|
56324
56320
|
} catch (err) {
|
|
56325
56321
|
execution.status = "failed";
|
|
56326
56322
|
execution.error = String(err);
|
|
56327
56323
|
execution.completedAt = /* @__PURE__ */ new Date();
|
|
56328
56324
|
this.emit({ type: "workflow_failed", executionId, timestamp: /* @__PURE__ */ new Date(), data: { error: String(err) } });
|
|
56329
|
-
|
|
56325
|
+
log43.error("Workflow failed", { executionId, error: String(err) });
|
|
56330
56326
|
}
|
|
56331
56327
|
return execution;
|
|
56332
56328
|
}
|
|
@@ -56366,7 +56362,7 @@ var init_engine = __esm({
|
|
|
56366
56362
|
const promises = readySteps.map((stepId) => {
|
|
56367
56363
|
const stepDef = stepDefs.get(stepId);
|
|
56368
56364
|
return this.executeStep(stepDef, execution).catch((err) => {
|
|
56369
|
-
|
|
56365
|
+
log43.error("Step execution error", { stepId, error: String(err) });
|
|
56370
56366
|
});
|
|
56371
56367
|
});
|
|
56372
56368
|
await Promise.all(promises);
|
|
@@ -56457,7 +56453,7 @@ var init_engine = __esm({
|
|
|
56457
56453
|
timestamp: /* @__PURE__ */ new Date(),
|
|
56458
56454
|
data: { attempt: stepExec.retryCount, maxRetries }
|
|
56459
56455
|
});
|
|
56460
|
-
|
|
56456
|
+
log43.warn("Step retrying", { stepId: stepDef.id, attempt: stepExec.retryCount });
|
|
56461
56457
|
} else {
|
|
56462
56458
|
stepExec.status = "failed";
|
|
56463
56459
|
stepExec.error = String(err);
|
|
@@ -56645,7 +56641,7 @@ var init_engine = __esm({
|
|
|
56645
56641
|
const fn = new Function("steps", "inputs", `return !!(${expr})`);
|
|
56646
56642
|
return fn(steps, execution.inputs);
|
|
56647
56643
|
} catch {
|
|
56648
|
-
|
|
56644
|
+
log43.warn("Expression evaluation failed", { expr });
|
|
56649
56645
|
return false;
|
|
56650
56646
|
}
|
|
56651
56647
|
}
|
|
@@ -56710,7 +56706,7 @@ function loadTeamTemplateFromDir(dirPath) {
|
|
|
56710
56706
|
norms: existsSync21(normsPath) ? readFileSync16(normsPath, "utf-8") : void 0
|
|
56711
56707
|
};
|
|
56712
56708
|
} catch (err) {
|
|
56713
|
-
|
|
56709
|
+
log44.warn(`Failed to load team template from ${dirPath}`, { error: String(err) });
|
|
56714
56710
|
return null;
|
|
56715
56711
|
}
|
|
56716
56712
|
}
|
|
@@ -56733,7 +56729,7 @@ function createDefaultTeamTemplates() {
|
|
|
56733
56729
|
templatesDir = resolve11(process.cwd(), "templates", "teams");
|
|
56734
56730
|
}
|
|
56735
56731
|
if (!existsSync21(templatesDir)) {
|
|
56736
|
-
|
|
56732
|
+
log44.warn(`Team templates directory not found: ${templatesDir}`);
|
|
56737
56733
|
return registry;
|
|
56738
56734
|
}
|
|
56739
56735
|
const entries2 = readdirSync7(templatesDir, { withFileTypes: true });
|
|
@@ -56745,20 +56741,20 @@ function createDefaultTeamTemplates() {
|
|
|
56745
56741
|
registry.register(tpl);
|
|
56746
56742
|
}
|
|
56747
56743
|
}
|
|
56748
|
-
|
|
56744
|
+
log44.info(`Loaded ${registry.list().length} team templates from ${templatesDir}`);
|
|
56749
56745
|
return registry;
|
|
56750
56746
|
}
|
|
56751
|
-
var
|
|
56747
|
+
var log44, TeamTemplateRegistry;
|
|
56752
56748
|
var init_team_template = __esm({
|
|
56753
56749
|
"../core/dist/workflow/team-template.js"() {
|
|
56754
56750
|
"use strict";
|
|
56755
56751
|
init_dist();
|
|
56756
|
-
|
|
56752
|
+
log44 = createLogger("team-template");
|
|
56757
56753
|
TeamTemplateRegistry = class {
|
|
56758
56754
|
templates = /* @__PURE__ */ new Map();
|
|
56759
56755
|
register(template) {
|
|
56760
56756
|
this.templates.set(template.id, template);
|
|
56761
|
-
|
|
56757
|
+
log44.info(`Team template registered: ${template.name}`, {
|
|
56762
56758
|
members: template.members.length
|
|
56763
56759
|
});
|
|
56764
56760
|
}
|
|
@@ -56797,13 +56793,13 @@ var init_types = __esm({
|
|
|
56797
56793
|
});
|
|
56798
56794
|
|
|
56799
56795
|
// ../core/dist/federation/federation-manager.js
|
|
56800
|
-
var
|
|
56796
|
+
var log45;
|
|
56801
56797
|
var init_federation_manager = __esm({
|
|
56802
56798
|
"../core/dist/federation/federation-manager.js"() {
|
|
56803
56799
|
"use strict";
|
|
56804
56800
|
init_dist();
|
|
56805
56801
|
init_types();
|
|
56806
|
-
|
|
56802
|
+
log45 = createLogger("federation");
|
|
56807
56803
|
}
|
|
56808
56804
|
});
|
|
56809
56805
|
|
|
@@ -56817,12 +56813,12 @@ var init_federation = __esm({
|
|
|
56817
56813
|
});
|
|
56818
56814
|
|
|
56819
56815
|
// ../core/dist/agent-snapshot.js
|
|
56820
|
-
var
|
|
56816
|
+
var log46;
|
|
56821
56817
|
var init_agent_snapshot = __esm({
|
|
56822
56818
|
"../core/dist/agent-snapshot.js"() {
|
|
56823
56819
|
"use strict";
|
|
56824
56820
|
init_dist();
|
|
56825
|
-
|
|
56821
|
+
log46 = createLogger("agent-snapshot");
|
|
56826
56822
|
}
|
|
56827
56823
|
});
|
|
56828
56824
|
|
|
@@ -56857,7 +56853,6 @@ var init_dist4 = __esm({
|
|
|
56857
56853
|
init_external_gateway();
|
|
56858
56854
|
init_gateway();
|
|
56859
56855
|
init_review_service();
|
|
56860
|
-
init_workspace_manager();
|
|
56861
56856
|
init_events();
|
|
56862
56857
|
init_mailbox2();
|
|
56863
56858
|
init_attention();
|
|
@@ -56879,13 +56874,13 @@ var init_dist4 = __esm({
|
|
|
56879
56874
|
import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync11, existsSync as existsSync22, rmSync as rmSync2 } from "node:fs";
|
|
56880
56875
|
import { join as join17 } from "node:path";
|
|
56881
56876
|
import { homedir as homedir9 } from "node:os";
|
|
56882
|
-
var
|
|
56877
|
+
var log47, OrganizationService;
|
|
56883
56878
|
var init_org_service = __esm({
|
|
56884
56879
|
"../org-manager/dist/org-service.js"() {
|
|
56885
56880
|
"use strict";
|
|
56886
56881
|
init_dist();
|
|
56887
56882
|
init_dist4();
|
|
56888
|
-
|
|
56883
|
+
log47 = createLogger("org-service");
|
|
56889
56884
|
OrganizationService = class _OrganizationService {
|
|
56890
56885
|
orgs = /* @__PURE__ */ new Map();
|
|
56891
56886
|
teams = /* @__PURE__ */ new Map();
|
|
@@ -56916,10 +56911,10 @@ var init_org_service = __esm({
|
|
|
56916
56911
|
this.refreshIdentityContextsForOrg(orgId2);
|
|
56917
56912
|
if (this.storage && opts?.email) {
|
|
56918
56913
|
this.storage.userRepo.upsert({ id: user.id, orgId: orgId2, name, email: opts.email, role }).catch((error) => {
|
|
56919
|
-
|
|
56914
|
+
log47.warn("Failed to persist user to DB", { error: String(error) });
|
|
56920
56915
|
});
|
|
56921
56916
|
}
|
|
56922
|
-
|
|
56917
|
+
log47.info(`Human user added: ${name} (${role})`, { orgId: orgId2, userId: user.id });
|
|
56923
56918
|
return user;
|
|
56924
56919
|
}
|
|
56925
56920
|
getHumanUser(userId) {
|
|
@@ -56935,10 +56930,10 @@ var init_org_service = __esm({
|
|
|
56935
56930
|
this.refreshIdentityContextsForOrg(user.orgId);
|
|
56936
56931
|
if (this.storage) {
|
|
56937
56932
|
this.storage.userRepo.delete(userId).catch((error) => {
|
|
56938
|
-
|
|
56933
|
+
log47.warn("Failed to delete user from DB", { error: String(error) });
|
|
56939
56934
|
});
|
|
56940
56935
|
}
|
|
56941
|
-
|
|
56936
|
+
log47.info(`Human user removed: ${user.name}`);
|
|
56942
56937
|
}
|
|
56943
56938
|
}
|
|
56944
56939
|
resolveHumanIdentity(senderId) {
|
|
@@ -56987,10 +56982,10 @@ var init_org_service = __esm({
|
|
|
56987
56982
|
try {
|
|
56988
56983
|
await this.storage.orgRepo.createOrg({ id, name, ownerId });
|
|
56989
56984
|
} catch (error) {
|
|
56990
|
-
|
|
56985
|
+
log47.warn("Failed to persist org to DB (may already exist)", { error: String(error) });
|
|
56991
56986
|
}
|
|
56992
56987
|
}
|
|
56993
|
-
|
|
56988
|
+
log47.info(`Organization created: ${name}`, { id: org.id });
|
|
56994
56989
|
return org;
|
|
56995
56990
|
}
|
|
56996
56991
|
getOrganization(id) {
|
|
@@ -57039,10 +57034,10 @@ var init_org_service = __esm({
|
|
|
57039
57034
|
try {
|
|
57040
57035
|
await this.storage.teamRepo.create({ id: team.id, orgId: orgId2, name, description });
|
|
57041
57036
|
} catch (error) {
|
|
57042
|
-
|
|
57037
|
+
log47.warn("Failed to persist team to DB", { error: String(error) });
|
|
57043
57038
|
}
|
|
57044
57039
|
}
|
|
57045
|
-
|
|
57040
|
+
log47.info(`Team created: ${name}`, { orgId: orgId2, teamId: team.id });
|
|
57046
57041
|
return team;
|
|
57047
57042
|
}
|
|
57048
57043
|
async updateTeam(teamId, data) {
|
|
@@ -57066,7 +57061,7 @@ var init_org_service = __esm({
|
|
|
57066
57061
|
managerType: "managerType" in data ? data.managerType ?? null : void 0
|
|
57067
57062
|
});
|
|
57068
57063
|
} catch (error) {
|
|
57069
|
-
|
|
57064
|
+
log47.warn("Failed to update team in DB", { error: String(error) });
|
|
57070
57065
|
}
|
|
57071
57066
|
}
|
|
57072
57067
|
return team;
|
|
@@ -57114,7 +57109,7 @@ var init_org_service = __esm({
|
|
|
57114
57109
|
try {
|
|
57115
57110
|
await this.storage.teamRepo.delete(teamId);
|
|
57116
57111
|
} catch (error) {
|
|
57117
|
-
|
|
57112
|
+
log47.error("Failed to delete team from DB", { teamId, error: String(error) });
|
|
57118
57113
|
}
|
|
57119
57114
|
}
|
|
57120
57115
|
this.teams.delete(teamId);
|
|
@@ -57123,13 +57118,13 @@ var init_org_service = __esm({
|
|
|
57123
57118
|
if (existsSync22(teamDir)) {
|
|
57124
57119
|
try {
|
|
57125
57120
|
rmSync2(teamDir, { recursive: true, force: true });
|
|
57126
|
-
|
|
57121
|
+
log47.info(`Team data directory purged: ${teamDir}`);
|
|
57127
57122
|
} catch (err) {
|
|
57128
|
-
|
|
57123
|
+
log47.warn("Failed to purge team data directory", { teamId, error: String(err) });
|
|
57129
57124
|
}
|
|
57130
57125
|
}
|
|
57131
57126
|
}
|
|
57132
|
-
|
|
57127
|
+
log47.info(`Team deleted: ${teamId}`, { deleteMembers, purgeFiles: !!opts?.purgeFiles });
|
|
57133
57128
|
}
|
|
57134
57129
|
addMemberToTeam(teamId, memberId, memberType) {
|
|
57135
57130
|
const team = this.teams.get(teamId);
|
|
@@ -57145,7 +57140,7 @@ var init_org_service = __esm({
|
|
|
57145
57140
|
}
|
|
57146
57141
|
if (this.storage) {
|
|
57147
57142
|
this.storage.agentRepo.updateTeamId(memberId, teamId).catch((error) => {
|
|
57148
|
-
|
|
57143
|
+
log47.warn("Failed to update agent teamId in DB", { error: String(error) });
|
|
57149
57144
|
});
|
|
57150
57145
|
}
|
|
57151
57146
|
} else {
|
|
@@ -57158,7 +57153,7 @@ var init_org_service = __esm({
|
|
|
57158
57153
|
user.teamId = teamId;
|
|
57159
57154
|
if (this.storage) {
|
|
57160
57155
|
this.storage.userRepo.updateTeamId(memberId, teamId).catch((error) => {
|
|
57161
|
-
|
|
57156
|
+
log47.warn("Failed to update user teamId in DB", { error: String(error) });
|
|
57162
57157
|
});
|
|
57163
57158
|
}
|
|
57164
57159
|
}
|
|
@@ -57183,7 +57178,7 @@ var init_org_service = __esm({
|
|
|
57183
57178
|
}
|
|
57184
57179
|
if (wasAgent && this.storage) {
|
|
57185
57180
|
this.storage.agentRepo.updateTeamId(memberId, null).catch((error) => {
|
|
57186
|
-
|
|
57181
|
+
log47.warn("Failed to clear agent teamId in DB", { error: String(error) });
|
|
57187
57182
|
});
|
|
57188
57183
|
}
|
|
57189
57184
|
const user = this.humans.get(memberId);
|
|
@@ -57191,7 +57186,7 @@ var init_org_service = __esm({
|
|
|
57191
57186
|
user.teamId = void 0;
|
|
57192
57187
|
if (this.storage) {
|
|
57193
57188
|
this.storage.userRepo.updateTeamId(memberId, null).catch((error) => {
|
|
57194
|
-
|
|
57189
|
+
log47.warn("Failed to clear user teamId in DB", { error: String(error) });
|
|
57195
57190
|
});
|
|
57196
57191
|
}
|
|
57197
57192
|
}
|
|
@@ -57368,7 +57363,7 @@ var init_org_service = __esm({
|
|
|
57368
57363
|
heartbeatIntervalMs: agent.config.heartbeatIntervalMs
|
|
57369
57364
|
});
|
|
57370
57365
|
} catch (error) {
|
|
57371
|
-
|
|
57366
|
+
log47.warn("Failed to persist agent to DB", { error: String(error) });
|
|
57372
57367
|
}
|
|
57373
57368
|
}
|
|
57374
57369
|
if (request.teamId) {
|
|
@@ -57380,19 +57375,19 @@ var init_org_service = __esm({
|
|
|
57380
57375
|
if (request.agentRole === "manager" && org) {
|
|
57381
57376
|
org.managerAgentId = agent.id;
|
|
57382
57377
|
if (this.storage?.orgRepo?.updateManagerAgentId) {
|
|
57383
|
-
this.storage.orgRepo.updateManagerAgentId(request.orgId, agent.id).catch((err) =>
|
|
57378
|
+
this.storage.orgRepo.updateManagerAgentId(request.orgId, agent.id).catch((err) => log47.warn("Failed to persist managerAgentId", { error: String(err) }));
|
|
57384
57379
|
}
|
|
57385
57380
|
}
|
|
57386
57381
|
this.refreshIdentityContextsForOrg(request.orgId);
|
|
57387
57382
|
try {
|
|
57388
57383
|
await this.agentManager.startAgent(agent.id);
|
|
57389
|
-
|
|
57384
|
+
log47.info(`Agent onboarded: ${request.name} (auto-started)`, {
|
|
57390
57385
|
orgId: request.orgId,
|
|
57391
57386
|
agentId: agent.id,
|
|
57392
57387
|
agentRole: request.agentRole ?? "worker"
|
|
57393
57388
|
});
|
|
57394
57389
|
} catch (error) {
|
|
57395
|
-
|
|
57390
|
+
log47.warn(`Agent created but auto-start failed: ${request.name}`, { error: String(error) });
|
|
57396
57391
|
}
|
|
57397
57392
|
return agent;
|
|
57398
57393
|
}
|
|
@@ -57419,7 +57414,7 @@ var init_org_service = __esm({
|
|
|
57419
57414
|
if (org.managerAgentId === agentId2) {
|
|
57420
57415
|
org.managerAgentId = void 0;
|
|
57421
57416
|
if (this.storage?.orgRepo?.updateManagerAgentId) {
|
|
57422
|
-
this.storage.orgRepo.updateManagerAgentId(org.id, null).catch((err) =>
|
|
57417
|
+
this.storage.orgRepo.updateManagerAgentId(org.id, null).catch((err) => log47.warn("Failed to clear managerAgentId", { error: String(err) }));
|
|
57423
57418
|
}
|
|
57424
57419
|
}
|
|
57425
57420
|
}
|
|
@@ -57427,7 +57422,7 @@ var init_org_service = __esm({
|
|
|
57427
57422
|
try {
|
|
57428
57423
|
await this.storage.agentRepo.delete(agentId2);
|
|
57429
57424
|
} catch (error) {
|
|
57430
|
-
|
|
57425
|
+
log47.error("Failed to remove agent from DB", { agentId: agentId2, error: String(error) });
|
|
57431
57426
|
}
|
|
57432
57427
|
}
|
|
57433
57428
|
for (const team of this.teams.values()) {
|
|
@@ -57436,7 +57431,7 @@ var init_org_service = __esm({
|
|
|
57436
57431
|
const orgIdToRefresh = agentInfo ? this.findAgentOrgId(agentId2) : void 0;
|
|
57437
57432
|
if (orgIdToRefresh)
|
|
57438
57433
|
this.refreshIdentityContextsForOrg(orgIdToRefresh);
|
|
57439
|
-
|
|
57434
|
+
log47.info(`Agent offboarded: ${agentId2}`);
|
|
57440
57435
|
}
|
|
57441
57436
|
/** Alias for fireAgent — offboard semantics */
|
|
57442
57437
|
async offboardAgent(agentId2) {
|
|
@@ -57485,7 +57480,7 @@ var init_org_service = __esm({
|
|
|
57485
57480
|
async loadFromDB(orgId2) {
|
|
57486
57481
|
if (!this.storage)
|
|
57487
57482
|
return;
|
|
57488
|
-
|
|
57483
|
+
log47.info("Loading data from DB...", { orgId: orgId2 });
|
|
57489
57484
|
try {
|
|
57490
57485
|
const orgRow = this.storage.orgRepo.findOrgById?.(orgId2);
|
|
57491
57486
|
if (orgRow) {
|
|
@@ -57495,7 +57490,7 @@ var init_org_service = __esm({
|
|
|
57495
57490
|
}
|
|
57496
57491
|
}
|
|
57497
57492
|
} catch (error) {
|
|
57498
|
-
|
|
57493
|
+
log47.warn("Failed to restore org fields from DB", { error: String(error) });
|
|
57499
57494
|
}
|
|
57500
57495
|
try {
|
|
57501
57496
|
const teamRows = await this.storage.teamRepo.findByOrgId(orgId2);
|
|
@@ -57514,9 +57509,9 @@ var init_org_service = __esm({
|
|
|
57514
57509
|
};
|
|
57515
57510
|
this.teams.set(team.id, team);
|
|
57516
57511
|
}
|
|
57517
|
-
|
|
57512
|
+
log47.info(`Restored ${teamRows.length} teams from DB`);
|
|
57518
57513
|
} catch (error) {
|
|
57519
|
-
|
|
57514
|
+
log47.warn("Failed to restore teams from DB", { error: String(error) });
|
|
57520
57515
|
}
|
|
57521
57516
|
this.pendingAgentStartIds = [];
|
|
57522
57517
|
try {
|
|
@@ -57534,15 +57529,15 @@ var init_org_service = __esm({
|
|
|
57534
57529
|
}
|
|
57535
57530
|
return true;
|
|
57536
57531
|
} catch (agentErr) {
|
|
57537
|
-
|
|
57532
|
+
log47.warn(`Failed to restore agent ${row.id}`, { error: String(agentErr) });
|
|
57538
57533
|
return false;
|
|
57539
57534
|
}
|
|
57540
57535
|
});
|
|
57541
57536
|
const results = await Promise.all(restorePromises);
|
|
57542
57537
|
const restoredCount = results.filter(Boolean).length;
|
|
57543
|
-
|
|
57538
|
+
log47.info(`Restored ${restoredCount} agents from DB`);
|
|
57544
57539
|
} catch (error) {
|
|
57545
|
-
|
|
57540
|
+
log47.warn("Failed to restore agents from DB", { error: String(error) });
|
|
57546
57541
|
}
|
|
57547
57542
|
try {
|
|
57548
57543
|
const userRows = await this.storage.userRepo.listByOrg(orgId2);
|
|
@@ -57583,12 +57578,12 @@ var init_org_service = __esm({
|
|
|
57583
57578
|
}
|
|
57584
57579
|
restoredCount++;
|
|
57585
57580
|
}
|
|
57586
|
-
|
|
57581
|
+
log47.info(`Restored ${restoredCount} users from DB`);
|
|
57587
57582
|
} catch (error) {
|
|
57588
|
-
|
|
57583
|
+
log47.warn("Failed to restore users from DB", { error: String(error) });
|
|
57589
57584
|
}
|
|
57590
57585
|
this.refreshIdentityContextsForOrg(orgId2);
|
|
57591
|
-
|
|
57586
|
+
log47.info("Data restored from DB successfully", { orgId: orgId2 });
|
|
57592
57587
|
}
|
|
57593
57588
|
/**
|
|
57594
57589
|
* Start all restored agents in the background with staggered delays.
|
|
@@ -57602,7 +57597,7 @@ var init_org_service = __esm({
|
|
|
57602
57597
|
return;
|
|
57603
57598
|
const STAGGER_MS = 1e3;
|
|
57604
57599
|
const DEFAULT_HEARTBEAT_INTERVAL_MS = 30 * 60 * 1e3;
|
|
57605
|
-
|
|
57600
|
+
log47.info(`Starting ${ids.length} restored agents in background (heartbeats will be staggered)...`);
|
|
57606
57601
|
const startAll = async () => {
|
|
57607
57602
|
let started = 0;
|
|
57608
57603
|
for (let i = 0; i < ids.length; i++) {
|
|
@@ -57615,13 +57610,13 @@ var init_org_service = __esm({
|
|
|
57615
57610
|
await new Promise((r) => setTimeout(r, STAGGER_MS));
|
|
57616
57611
|
}
|
|
57617
57612
|
} catch (err) {
|
|
57618
|
-
|
|
57613
|
+
log47.warn(`Failed to auto-start restored agent ${id}`, { error: String(err) });
|
|
57619
57614
|
}
|
|
57620
57615
|
}
|
|
57621
|
-
|
|
57616
|
+
log47.info(`Background agent startup complete: ${started}/${ids.length} agents started`);
|
|
57622
57617
|
};
|
|
57623
57618
|
startAll().catch((err) => {
|
|
57624
|
-
|
|
57619
|
+
log47.error("Background agent startup failed", { error: String(err) });
|
|
57625
57620
|
});
|
|
57626
57621
|
}
|
|
57627
57622
|
/**
|
|
@@ -57633,7 +57628,7 @@ var init_org_service = __esm({
|
|
|
57633
57628
|
const existing = this.listTeams(orgId2);
|
|
57634
57629
|
if (existing.length > 0)
|
|
57635
57630
|
return;
|
|
57636
|
-
|
|
57631
|
+
log47.info("Seeding default team for org", { orgId: orgId2 });
|
|
57637
57632
|
try {
|
|
57638
57633
|
const team = await this.createTeam(orgId2, "My Team", "Your primary team \u2014 you and your personal AI Secretary.");
|
|
57639
57634
|
const owner = this.humans.get(ownerUserId);
|
|
@@ -57652,12 +57647,12 @@ var init_org_service = __esm({
|
|
|
57652
57647
|
managerId: secretary.id,
|
|
57653
57648
|
managerType: "agent"
|
|
57654
57649
|
});
|
|
57655
|
-
|
|
57650
|
+
log47.info("Default team seeded", {
|
|
57656
57651
|
teamId: team.id,
|
|
57657
57652
|
secretaryId: secretary.id
|
|
57658
57653
|
});
|
|
57659
57654
|
} catch (error) {
|
|
57660
|
-
|
|
57655
|
+
log47.warn("Failed to seed default team", { error: String(error) });
|
|
57661
57656
|
}
|
|
57662
57657
|
}
|
|
57663
57658
|
static BUILDING_SKILLS = /* @__PURE__ */ new Set(["agent-building", "team-building", "skill-building"]);
|
|
@@ -57675,7 +57670,7 @@ var init_org_service = __esm({
|
|
|
57675
57670
|
continue;
|
|
57676
57671
|
agent.addDynamicContextProvider(() => this.buildBuilderDynamicContext(skillRegistry), "builder-context");
|
|
57677
57672
|
} catch {
|
|
57678
|
-
|
|
57673
|
+
log47.warn(`Could not register dynamic context for builder: ${info4.name}`);
|
|
57679
57674
|
}
|
|
57680
57675
|
}
|
|
57681
57676
|
}
|
|
@@ -57815,12 +57810,12 @@ function computeNextRunFromConfig(config) {
|
|
|
57815
57810
|
}
|
|
57816
57811
|
return void 0;
|
|
57817
57812
|
}
|
|
57818
|
-
var
|
|
57813
|
+
var log48, TaskService, INTERVAL_MULTIPLIERS;
|
|
57819
57814
|
var init_task_service = __esm({
|
|
57820
57815
|
"../org-manager/dist/task-service.js"() {
|
|
57821
57816
|
"use strict";
|
|
57822
57817
|
init_dist();
|
|
57823
|
-
|
|
57818
|
+
log48 = createLogger("task-service");
|
|
57824
57819
|
TaskService = class _TaskService {
|
|
57825
57820
|
tasks = /* @__PURE__ */ new Map();
|
|
57826
57821
|
agentManager;
|
|
@@ -58077,9 +58072,9 @@ var init_task_service = __esm({
|
|
|
58077
58072
|
this.timeoutCheckInterval = void 0;
|
|
58078
58073
|
}
|
|
58079
58074
|
}
|
|
58080
|
-
static MAX_TASK_RETRIES =
|
|
58081
|
-
static MAX_IN_PROGRESS_RETRIES =
|
|
58082
|
-
static RETRY_DELAYS_MS =
|
|
58075
|
+
static MAX_TASK_RETRIES = TASK_MAX_RETRIES;
|
|
58076
|
+
static MAX_IN_PROGRESS_RETRIES = TASK_MAX_NO_SUBMIT_RETRIES;
|
|
58077
|
+
static RETRY_DELAYS_MS = TASK_RETRY_DELAYS_MS;
|
|
58083
58078
|
static STATUS_ACTION_GUIDANCE = {
|
|
58084
58079
|
blocked: "Task is paused. Stop any active work on this task.",
|
|
58085
58080
|
cancelled: "Task cancelled. Stop any related work and clean up.",
|
|
@@ -58284,17 +58279,17 @@ var init_task_service = __esm({
|
|
|
58284
58279
|
lines.push("**CRITICAL: Pay close attention to human comments \u2014 they contain instructions, feedback, and accumulated knowledge.**");
|
|
58285
58280
|
lines.push("");
|
|
58286
58281
|
if (task?.notes?.length) {
|
|
58287
|
-
const recentNotes = task.notes.slice(-
|
|
58282
|
+
const recentNotes = task.notes.slice(-PROMPT_TASK_NOTES_MAX);
|
|
58288
58283
|
lines.push("### Task Notes (accumulated knowledge)");
|
|
58289
|
-
if (task.notes.length >
|
|
58290
|
-
lines.push(`_(showing most recent
|
|
58284
|
+
if (task.notes.length > PROMPT_TASK_NOTES_MAX) {
|
|
58285
|
+
lines.push(`_(showing most recent ${PROMPT_TASK_NOTES_MAX} of ${task.notes.length} notes)_`);
|
|
58291
58286
|
}
|
|
58292
58287
|
for (const note of recentNotes) {
|
|
58293
|
-
lines.push(`- ${note.slice(0,
|
|
58288
|
+
lines.push(`- ${note.slice(0, PROMPT_TASK_NOTE_CHARS)}`);
|
|
58294
58289
|
}
|
|
58295
58290
|
lines.push("");
|
|
58296
58291
|
}
|
|
58297
|
-
const MAX_ROUNDS_TO_SHOW =
|
|
58292
|
+
const MAX_ROUNDS_TO_SHOW = PROMPT_EXECUTION_ROUNDS_MAX;
|
|
58298
58293
|
const roundsSorted = [...seenRounds].sort((a, b) => a - b);
|
|
58299
58294
|
const roundsToShow = roundsSorted.length > MAX_ROUNDS_TO_SHOW ? roundsSorted.slice(-MAX_ROUNDS_TO_SHOW) : roundsSorted;
|
|
58300
58295
|
const showFromRound = roundsToShow.length > 0 ? roundsToShow[0] : 1;
|
|
@@ -58356,7 +58351,7 @@ var init_task_service = __esm({
|
|
|
58356
58351
|
continue;
|
|
58357
58352
|
}
|
|
58358
58353
|
if (entry.type === "text") {
|
|
58359
|
-
const text2 = entry.content.length >
|
|
58354
|
+
const text2 = entry.content.length > PROMPT_LOG_ENTRY_CHARS ? entry.content.slice(0, PROMPT_LOG_ENTRY_CHARS) + "\u2026" : entry.content;
|
|
58360
58355
|
lines.push(text2);
|
|
58361
58356
|
lines.push("");
|
|
58362
58357
|
} else if (entry.type === "tool_start") {
|
|
@@ -58389,7 +58384,7 @@ var init_task_service = __esm({
|
|
|
58389
58384
|
lines.push("");
|
|
58390
58385
|
}
|
|
58391
58386
|
}
|
|
58392
|
-
const recentErrors = collectedErrors.slice(-
|
|
58387
|
+
const recentErrors = collectedErrors.slice(-PROMPT_RECENT_ERRORS_MAX);
|
|
58393
58388
|
if (recentErrors.length > 0) {
|
|
58394
58389
|
const guidance = _TaskService.analyzeErrorPatterns(recentErrors);
|
|
58395
58390
|
if (guidance.length > 0) {
|
|
@@ -58420,7 +58415,7 @@ var init_task_service = __esm({
|
|
|
58420
58415
|
if (!this.agentManager)
|
|
58421
58416
|
throw new Error("AgentManager not set");
|
|
58422
58417
|
if (task.status !== "in_progress") {
|
|
58423
|
-
|
|
58418
|
+
log48.warn("runTask called but task not in in_progress state, skipping", {
|
|
58424
58419
|
taskId: taskId2,
|
|
58425
58420
|
currentStatus: task.status
|
|
58426
58421
|
});
|
|
@@ -58445,7 +58440,7 @@ var init_task_service = __esm({
|
|
|
58445
58440
|
}
|
|
58446
58441
|
prevContext = this.formatPreviousExecutionContext(prevLogs, prevComments, task);
|
|
58447
58442
|
} catch (err) {
|
|
58448
|
-
|
|
58443
|
+
log48.warn("Failed to load previous task logs for context", { taskId: taskId2, error: String(err) });
|
|
58449
58444
|
}
|
|
58450
58445
|
}
|
|
58451
58446
|
let dependencyContext = "";
|
|
@@ -58457,12 +58452,12 @@ var init_task_service = __esm({
|
|
|
58457
58452
|
continue;
|
|
58458
58453
|
const lines = [`### Dependency: ${depTask.title} (ID: ${depId}, status: ${depTask.status})`];
|
|
58459
58454
|
if (depTask.description) {
|
|
58460
|
-
lines.push(`**Description:** ${depTask.description.slice(0,
|
|
58455
|
+
lines.push(`**Description:** ${depTask.description.slice(0, PROMPT_DEP_DESC_CHARS)}`);
|
|
58461
58456
|
}
|
|
58462
58457
|
if (depTask.notes?.length) {
|
|
58463
58458
|
lines.push("**Notes (most recent first):**");
|
|
58464
|
-
for (const note of depTask.notes.slice(-
|
|
58465
|
-
lines.push(`- ${note.slice(0,
|
|
58459
|
+
for (const note of depTask.notes.slice(-PROMPT_DEP_NOTES_MAX).reverse()) {
|
|
58460
|
+
lines.push(`- ${note.slice(0, PROMPT_DEP_NOTE_CHARS)}`);
|
|
58466
58461
|
}
|
|
58467
58462
|
}
|
|
58468
58463
|
if (depTask.deliverables?.length) {
|
|
@@ -58499,12 +58494,12 @@ var init_task_service = __esm({
|
|
|
58499
58494
|
if (task.projectId && this.projectService) {
|
|
58500
58495
|
const project = this.projectService.getProject(task.projectId);
|
|
58501
58496
|
if (project) {
|
|
58502
|
-
goalLines.push(`**Project:** ${project.name} \u2014 ${project.description.slice(0,
|
|
58497
|
+
goalLines.push(`**Project:** ${project.name} \u2014 ${project.description.slice(0, PROMPT_PROJECT_DESC_CHARS)}`);
|
|
58503
58498
|
}
|
|
58504
58499
|
}
|
|
58505
58500
|
goalLines.push(`**Requirement:** ${req.title}`);
|
|
58506
58501
|
if (req.description) {
|
|
58507
|
-
goalLines.push(`**Requirement Description:** ${req.description.slice(0,
|
|
58502
|
+
goalLines.push(`**Requirement Description:** ${req.description.slice(0, PROMPT_REQUIREMENT_DESC_CHARS)}`);
|
|
58508
58503
|
}
|
|
58509
58504
|
goalLines.push("");
|
|
58510
58505
|
goalLines.push("Keep this goal context in mind. Your task should directly advance this requirement.");
|
|
@@ -58514,12 +58509,12 @@ var init_task_service = __esm({
|
|
|
58514
58509
|
}
|
|
58515
58510
|
let notesSection = "";
|
|
58516
58511
|
if (!prevContext && task.notes?.length) {
|
|
58517
|
-
const recentNotes = task.notes.slice(-
|
|
58512
|
+
const recentNotes = task.notes.slice(-PROMPT_TASK_NOTES_MAX);
|
|
58518
58513
|
const noteLines = ["## Task Notes"];
|
|
58519
|
-
if (task.notes.length >
|
|
58520
|
-
noteLines.push(`_(showing most recent
|
|
58514
|
+
if (task.notes.length > PROMPT_TASK_NOTES_MAX) {
|
|
58515
|
+
noteLines.push(`_(showing most recent ${PROMPT_TASK_NOTES_MAX} of ${task.notes.length} notes)_`);
|
|
58521
58516
|
}
|
|
58522
|
-
noteLines.push(...recentNotes.map((n) => `- ${n.slice(0,
|
|
58517
|
+
noteLines.push(...recentNotes.map((n) => `- ${n.slice(0, PROMPT_TASK_NOTE_CHARS)}`), "", "---", "");
|
|
58523
58518
|
notesSection = noteLines.join("\n");
|
|
58524
58519
|
}
|
|
58525
58520
|
let scheduleSection = "";
|
|
@@ -58579,28 +58574,23 @@ var init_task_service = __esm({
|
|
|
58579
58574
|
${task.description}` : `${scheduleSection}${notesSection}${goalContext}${dependencyContext}${subtaskSection}${task.title}
|
|
58580
58575
|
|
|
58581
58576
|
${task.description}`;
|
|
58582
|
-
let
|
|
58577
|
+
let taskProjectContext;
|
|
58583
58578
|
if (task.projectId) {
|
|
58584
58579
|
const project = this.projectService?.getProject(task.projectId);
|
|
58585
|
-
const
|
|
58586
|
-
if (
|
|
58587
|
-
|
|
58588
|
-
|
|
58589
|
-
|
|
58590
|
-
|
|
58591
|
-
|
|
58592
|
-
|
|
58593
|
-
|
|
58594
|
-
|
|
58595
|
-
|
|
58596
|
-
|
|
58597
|
-
|
|
58598
|
-
|
|
58599
|
-
localPath: r.localPath,
|
|
58600
|
-
defaultBranch: r.defaultBranch,
|
|
58601
|
-
role: r.role
|
|
58602
|
-
}))
|
|
58603
|
-
} : void 0
|
|
58580
|
+
const repos = project?.repositories?.filter((r) => r.localPath) ?? [];
|
|
58581
|
+
if (repos.length > 0 && project) {
|
|
58582
|
+
taskProjectContext = {
|
|
58583
|
+
project: {
|
|
58584
|
+
id: project.id,
|
|
58585
|
+
name: project.name,
|
|
58586
|
+
description: project.description,
|
|
58587
|
+
status: project.status
|
|
58588
|
+
},
|
|
58589
|
+
repositories: repos.map((r) => ({
|
|
58590
|
+
localPath: r.localPath,
|
|
58591
|
+
defaultBranch: r.defaultBranch,
|
|
58592
|
+
role: r.role
|
|
58593
|
+
}))
|
|
58604
58594
|
};
|
|
58605
58595
|
}
|
|
58606
58596
|
}
|
|
@@ -58631,7 +58621,7 @@ ${task.description}`;
|
|
|
58631
58621
|
subtasks: task.subtasks
|
|
58632
58622
|
});
|
|
58633
58623
|
} catch (err) {
|
|
58634
|
-
|
|
58624
|
+
log48.warn("Failed to ensure task exists in DB before execution", { taskId: taskId2, error: String(err) });
|
|
58635
58625
|
}
|
|
58636
58626
|
}
|
|
58637
58627
|
let seq = 0;
|
|
@@ -58654,7 +58644,7 @@ ${task.description}`;
|
|
|
58654
58644
|
const humanComments = prevComments.filter((c) => c.authorType === "human" || c.authorType === "owner");
|
|
58655
58645
|
if (humanComments.length > 0) {
|
|
58656
58646
|
const sessionId = `task_${taskId2}_r${executionRound}`;
|
|
58657
|
-
const recentFeedback = humanComments.slice(-
|
|
58647
|
+
const recentFeedback = humanComments.slice(-PROMPT_HUMAN_COMMENTS_MAX);
|
|
58658
58648
|
const feedbackLines = recentFeedback.map((c) => {
|
|
58659
58649
|
const ts = c.createdAt instanceof Date ? c.createdAt.toISOString().slice(0, 19).replace("T", " ") : String(c.createdAt);
|
|
58660
58650
|
return `**${c.authorName}** (${ts}):
|
|
@@ -58704,14 +58694,14 @@ ${c.content}`;
|
|
|
58704
58694
|
const row = await taskLogRepo.append(logEntry);
|
|
58705
58695
|
savedId = row.id;
|
|
58706
58696
|
} catch (err) {
|
|
58707
|
-
|
|
58697
|
+
log48.warn("Failed to persist task log", { taskId: taskId2, error: String(err) });
|
|
58708
58698
|
}
|
|
58709
58699
|
}
|
|
58710
58700
|
if (this.executionStreamRepo) {
|
|
58711
58701
|
try {
|
|
58712
58702
|
this.executionStreamRepo.append({ sourceType: "task", sourceId: taskId2, agentId: agentId2, seq: currentSeq, type: entry.type, content: entry.content, metadata: entry.metadata, executionRound });
|
|
58713
58703
|
} catch (err) {
|
|
58714
|
-
|
|
58704
|
+
log48.warn("Failed to persist execution stream log", { taskId: taskId2, error: String(err) });
|
|
58715
58705
|
}
|
|
58716
58706
|
}
|
|
58717
58707
|
ws?.broadcast({
|
|
@@ -58753,16 +58743,16 @@ ${c.content}`;
|
|
|
58753
58743
|
const nextAttempt = _retryAttempt + 1;
|
|
58754
58744
|
if (nextAttempt < _TaskService.MAX_IN_PROGRESS_RETRIES) {
|
|
58755
58745
|
const delayMs = _TaskService.RETRY_DELAYS_MS[Math.min(_retryAttempt, _TaskService.RETRY_DELAYS_MS.length - 1)] ?? 3e5;
|
|
58756
|
-
|
|
58746
|
+
log48.warn(`Task execution finished without task_submit_review \u2014 auto-retrying in ${delayMs / 1e3}s (attempt ${nextAttempt})`, { taskId: taskId2 });
|
|
58757
58747
|
this.addTaskNote(taskId2, `[System] Execution finished but agent did not call task_submit_review. Auto-retrying (attempt ${nextAttempt}).`, "system");
|
|
58758
58748
|
setTimeout(() => {
|
|
58759
58749
|
const current = this.tasks.get(taskId2);
|
|
58760
58750
|
if (!current || current.status !== "in_progress")
|
|
58761
58751
|
return;
|
|
58762
|
-
this.runTask(taskId2, nextAttempt).catch((e) =>
|
|
58752
|
+
this.runTask(taskId2, nextAttempt).catch((e) => log48.error("No-submit retry invocation failed", { taskId: taskId2, error: String(e) }));
|
|
58763
58753
|
}, delayMs);
|
|
58764
58754
|
} else {
|
|
58765
|
-
|
|
58755
|
+
log48.error(`Task execution finished without task_submit_review after ${nextAttempt} attempts \u2014 marking failed`, { taskId: taskId2 });
|
|
58766
58756
|
this.addTaskNote(taskId2, `[System] Execution finished without task_submit_review after ${nextAttempt} attempts. Task marked as failed.`, "system");
|
|
58767
58757
|
this.taskRetryErrors.delete(taskId2);
|
|
58768
58758
|
this.updateTaskStatus(taskId2, "failed");
|
|
@@ -58799,8 +58789,8 @@ ${c.content}`;
|
|
|
58799
58789
|
const activeToken = this.taskCancelTokens.get(taskId2);
|
|
58800
58790
|
if (activeToken && !activeToken.cancelled)
|
|
58801
58791
|
return;
|
|
58802
|
-
|
|
58803
|
-
this.runTask(taskId2).catch((err) =>
|
|
58792
|
+
log48.info("Re-queuing preempted task", { taskId: taskId2 });
|
|
58793
|
+
this.runTask(taskId2).catch((err) => log48.warn("Failed to re-queue preempted task", { taskId: taskId2, error: String(err) }));
|
|
58804
58794
|
});
|
|
58805
58795
|
}
|
|
58806
58796
|
} else if (entry.type === "error") {
|
|
@@ -58809,7 +58799,7 @@ ${c.content}`;
|
|
|
58809
58799
|
if (retryDecision.shouldRetry) {
|
|
58810
58800
|
const delayMs = _TaskService.RETRY_DELAYS_MS[Math.min(_retryAttempt, _TaskService.RETRY_DELAYS_MS.length - 1)] ?? 3e5;
|
|
58811
58801
|
const retryMsg = `Attempt ${nextAttempt} failed. Retrying in ${delayMs / 1e3}s\u2026 (${retryDecision.reason})`;
|
|
58812
|
-
|
|
58802
|
+
log48.warn(retryMsg, { taskId: taskId2, attempt: nextAttempt, error: entry.content });
|
|
58813
58803
|
const noticeSeq = seq++;
|
|
58814
58804
|
const noticeEntry = {
|
|
58815
58805
|
taskId: taskId2,
|
|
@@ -58843,11 +58833,11 @@ ${c.content}`;
|
|
|
58843
58833
|
const current = this.tasks.get(taskId2);
|
|
58844
58834
|
if (!current || current.status !== "in_progress")
|
|
58845
58835
|
return;
|
|
58846
|
-
this.runTask(taskId2, nextAttempt).catch((e) =>
|
|
58836
|
+
this.runTask(taskId2, nextAttempt).catch((e) => log48.error("Retry invocation failed", { taskId: taskId2, error: String(e) }));
|
|
58847
58837
|
}, delayMs);
|
|
58848
58838
|
} else if (!cancelToken.cancelled) {
|
|
58849
58839
|
const failMsg = `Task failed after ${nextAttempt} attempts: ${retryDecision.reason}`;
|
|
58850
|
-
|
|
58840
|
+
log48.error(failMsg, { taskId: taskId2 });
|
|
58851
58841
|
this.taskRetryErrors.delete(taskId2);
|
|
58852
58842
|
this.updateTaskStatus(taskId2, "failed");
|
|
58853
58843
|
}
|
|
@@ -58862,22 +58852,22 @@ ${c.content}`;
|
|
|
58862
58852
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
58863
58853
|
});
|
|
58864
58854
|
}
|
|
58865
|
-
}, cancelToken,
|
|
58866
|
-
|
|
58855
|
+
}, cancelToken, taskProjectContext, executionRound).catch((err) => {
|
|
58856
|
+
log48.error("Task execution promise rejected", { taskId: taskId2, error: String(err) });
|
|
58867
58857
|
if (!cancelToken.cancelled) {
|
|
58868
58858
|
const retryDecision = this.shouldRetryTask(taskId2, String(err), _retryAttempt, false);
|
|
58869
58859
|
if (retryDecision.shouldRetry) {
|
|
58870
58860
|
const delayMs = _TaskService.RETRY_DELAYS_MS[Math.min(_retryAttempt, _TaskService.RETRY_DELAYS_MS.length - 1)] ?? 3e5;
|
|
58871
58861
|
const nextAttempt = _retryAttempt + 1;
|
|
58872
|
-
|
|
58862
|
+
log48.warn(`Retrying task in ${delayMs / 1e3}s (attempt ${nextAttempt}, ${retryDecision.reason})`, { taskId: taskId2 });
|
|
58873
58863
|
setTimeout(() => {
|
|
58874
58864
|
const current = this.tasks.get(taskId2);
|
|
58875
58865
|
if (!current || current.status !== "in_progress")
|
|
58876
58866
|
return;
|
|
58877
|
-
this.runTask(taskId2, nextAttempt).catch((e) =>
|
|
58867
|
+
this.runTask(taskId2, nextAttempt).catch((e) => log48.error("Retry invocation failed", { taskId: taskId2, error: String(e) }));
|
|
58878
58868
|
}, delayMs);
|
|
58879
58869
|
} else {
|
|
58880
|
-
|
|
58870
|
+
log48.error(`Task failed permanently: ${retryDecision.reason}`, { taskId: taskId2 });
|
|
58881
58871
|
this.taskRetryErrors.delete(taskId2);
|
|
58882
58872
|
this.updateTaskStatus(taskId2, "failed");
|
|
58883
58873
|
}
|
|
@@ -58945,12 +58935,12 @@ ${c.content}`;
|
|
|
58945
58935
|
};
|
|
58946
58936
|
this.tasks.set(task.id, task);
|
|
58947
58937
|
if (needsMigration && this.taskRepo) {
|
|
58948
|
-
this.taskRepo.updateStatus(task.id, migrated).catch((err) =>
|
|
58938
|
+
this.taskRepo.updateStatus(task.id, migrated).catch((err) => log48.warn("Failed to persist migrated status", { taskId: task.id, from: row.status, to: migrated, error: String(err) }));
|
|
58949
58939
|
}
|
|
58950
58940
|
}
|
|
58951
|
-
|
|
58941
|
+
log48.info(`Loaded ${rows.length} tasks from DB for org ${orgId2}`);
|
|
58952
58942
|
} catch (err) {
|
|
58953
|
-
|
|
58943
|
+
log48.warn("Failed to load tasks from DB", { error: String(err) });
|
|
58954
58944
|
}
|
|
58955
58945
|
}
|
|
58956
58946
|
/**
|
|
@@ -58961,13 +58951,13 @@ ${c.content}`;
|
|
|
58961
58951
|
const inProgressTasks = [...this.tasks.values()].filter((t) => t.status === "in_progress");
|
|
58962
58952
|
if (inProgressTasks.length === 0)
|
|
58963
58953
|
return;
|
|
58964
|
-
|
|
58954
|
+
log48.info(`Resuming ${inProgressTasks.length} in_progress task(s) after restart`);
|
|
58965
58955
|
for (const task of inProgressTasks) {
|
|
58966
58956
|
try {
|
|
58967
58957
|
await this.runTask(task.id);
|
|
58968
|
-
|
|
58958
|
+
log48.info(`Resumed task execution after restart`, { taskId: task.id, title: task.title });
|
|
58969
58959
|
} catch (err) {
|
|
58970
|
-
|
|
58960
|
+
log48.warn(`Failed to resume task on startup`, {
|
|
58971
58961
|
taskId: task.id,
|
|
58972
58962
|
title: task.title,
|
|
58973
58963
|
error: String(err)
|
|
@@ -59052,7 +59042,7 @@ ${c.content}`;
|
|
|
59052
59042
|
dueAt: task.dueAt ? new Date(task.dueAt) : void 0,
|
|
59053
59043
|
taskType: task.taskType,
|
|
59054
59044
|
scheduleConfig: task.scheduleConfig
|
|
59055
|
-
}).catch((err) =>
|
|
59045
|
+
}).catch((err) => log48.warn("Failed to persist task to DB", { error: String(err) }));
|
|
59056
59046
|
}
|
|
59057
59047
|
if (task.requirementId && this.requirementService) {
|
|
59058
59048
|
this.requirementService.linkTask(task.requirementId, task.id);
|
|
@@ -59078,7 +59068,7 @@ ${c.content}`;
|
|
|
59078
59068
|
metadata: { taskId: task.id, agentId: task.assignedAgentId }
|
|
59079
59069
|
});
|
|
59080
59070
|
}
|
|
59081
|
-
|
|
59071
|
+
log48.info(`Task created: ${task.title}`, {
|
|
59082
59072
|
id: task.id,
|
|
59083
59073
|
status: task.status,
|
|
59084
59074
|
assignedTo: task.assignedAgentId,
|
|
@@ -59103,7 +59093,7 @@ ${c.content}`;
|
|
|
59103
59093
|
this.rejectTask(task.id);
|
|
59104
59094
|
}
|
|
59105
59095
|
}).catch((err) => {
|
|
59106
|
-
|
|
59096
|
+
log48.error("HITL approval flow error, auto-rejecting task", { taskId: task.id, error: String(err) });
|
|
59107
59097
|
const current = this.tasks.get(task.id);
|
|
59108
59098
|
if (current?.status === "pending") {
|
|
59109
59099
|
this.rejectTask(task.id);
|
|
@@ -59178,7 +59168,7 @@ ${c.content}`;
|
|
|
59178
59168
|
if (!result)
|
|
59179
59169
|
return this.tasks.get(id);
|
|
59180
59170
|
this.handleTransitionSideEffects(result.task, result.prevStatus, status, updatedBy, _skipAutoStart);
|
|
59181
|
-
|
|
59171
|
+
log48.info(`Task status updated: ${result.task.title}`, { id, status, prevStatus: result.prevStatus });
|
|
59182
59172
|
return result.task;
|
|
59183
59173
|
}
|
|
59184
59174
|
// ─── Phase 1: Pure validation + state mutation ───────────────────────────────
|
|
@@ -59193,7 +59183,7 @@ ${c.content}`;
|
|
|
59193
59183
|
if (prevStatus === status)
|
|
59194
59184
|
return null;
|
|
59195
59185
|
if (!isValidTaskTransition(prevStatus, status)) {
|
|
59196
|
-
|
|
59186
|
+
log48.warn("Rejected illegal task state transition", { taskId: id, from: prevStatus, to: status, updatedBy });
|
|
59197
59187
|
throw new Error(`Illegal task state transition: ${prevStatus} \u2192 ${status} (task "${task.title}", id: ${id})`);
|
|
59198
59188
|
}
|
|
59199
59189
|
if (!_internal && prevStatus === "pending" && status !== "pending") {
|
|
@@ -59234,7 +59224,7 @@ ${c.content}`;
|
|
|
59234
59224
|
if (token) {
|
|
59235
59225
|
token.cancelled = true;
|
|
59236
59226
|
this.taskCancelTokens.delete(taskId2);
|
|
59237
|
-
|
|
59227
|
+
log48.info(`Cancelled running execution for task ${taskId2} (status \u2192 ${to})`);
|
|
59238
59228
|
}
|
|
59239
59229
|
}
|
|
59240
59230
|
if (from === "review" && to !== "review") {
|
|
@@ -59244,7 +59234,7 @@ ${c.content}`;
|
|
|
59244
59234
|
// ─── Stage 2: DB persistence ─────────────────────────────────────────────────
|
|
59245
59235
|
persistStatusChange(id, status, updatedBy) {
|
|
59246
59236
|
if (this.taskRepo) {
|
|
59247
|
-
this.taskRepo.updateStatus(id, status, updatedBy).catch((err) =>
|
|
59237
|
+
this.taskRepo.updateStatus(id, status, updatedBy).catch((err) => log48.warn("Failed to persist task status to DB", { error: String(err) }));
|
|
59248
59238
|
}
|
|
59249
59239
|
}
|
|
59250
59240
|
// ─── Stage 3: Auto-start execution ───────────────────────────────────────────
|
|
@@ -59256,9 +59246,9 @@ ${c.content}`;
|
|
|
59256
59246
|
const activeToken = this.taskCancelTokens.get(task.id);
|
|
59257
59247
|
if (activeToken && !activeToken.cancelled)
|
|
59258
59248
|
return false;
|
|
59259
|
-
|
|
59249
|
+
log48.info("Auto-starting task execution", { taskId: task.id });
|
|
59260
59250
|
setImmediate(() => {
|
|
59261
|
-
this.runTask(task.id).catch((err) =>
|
|
59251
|
+
this.runTask(task.id).catch((err) => log48.warn("Auto-start runTask failed", { taskId: task.id, error: String(err) }));
|
|
59262
59252
|
});
|
|
59263
59253
|
return true;
|
|
59264
59254
|
}
|
|
@@ -59371,10 +59361,10 @@ Action: ${guidance}` : ""
|
|
|
59371
59361
|
task.assignedAgentId = agentId2;
|
|
59372
59362
|
task.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
59373
59363
|
if (this.taskRepo) {
|
|
59374
|
-
this.taskRepo.assign(id, agentId2).catch((err) =>
|
|
59364
|
+
this.taskRepo.assign(id, agentId2).catch((err) => log48.warn("Failed to persist task assignment to DB", { error: String(err) }));
|
|
59375
59365
|
}
|
|
59376
59366
|
this.ws?.broadcastTaskUpdate(id, task.status, { title: task.title, assignedAgentId: agentId2 });
|
|
59377
|
-
|
|
59367
|
+
log48.info(`Task assigned`, { taskId: id, agentId: agentId2 });
|
|
59378
59368
|
return task;
|
|
59379
59369
|
}
|
|
59380
59370
|
addTaskNote(id, note, author) {
|
|
@@ -59388,9 +59378,9 @@ Action: ${guidance}` : ""
|
|
|
59388
59378
|
task.notes.push(`[${formatLocalTimestamp(now2)}${authorTag}] ${note}`);
|
|
59389
59379
|
task.updatedAt = now2.toISOString();
|
|
59390
59380
|
if (this.taskRepo) {
|
|
59391
|
-
this.taskRepo.update(id, { notes: task.notes }).catch((err) =>
|
|
59381
|
+
this.taskRepo.update(id, { notes: task.notes }).catch((err) => log48.warn("Failed to persist task note to DB", { error: String(err) }));
|
|
59392
59382
|
}
|
|
59393
|
-
|
|
59383
|
+
log48.info(`Task note added`, { taskId: id, author, note: note.slice(0, 80) });
|
|
59394
59384
|
}
|
|
59395
59385
|
listTasks(filters2) {
|
|
59396
59386
|
let result = [...this.tasks.values()];
|
|
@@ -59463,7 +59453,7 @@ Action: ${guidance}` : ""
|
|
|
59463
59453
|
}
|
|
59464
59454
|
return sortOrder === "asc" ? cmp : -cmp;
|
|
59465
59455
|
});
|
|
59466
|
-
const pageSize = Math.min(Math.max(opts?.pageSize ?? 20, 1),
|
|
59456
|
+
const pageSize = Math.min(Math.max(opts?.pageSize ?? 20, 1), TASK_LIST_PAGE_MAX);
|
|
59467
59457
|
const totalPages = Math.max(Math.ceil(total / pageSize), 1);
|
|
59468
59458
|
const page = Math.min(Math.max(opts?.page ?? 1, 1), totalPages);
|
|
59469
59459
|
const start = (page - 1) * pageSize;
|
|
@@ -59593,7 +59583,7 @@ Action: ${guidance}` : ""
|
|
|
59593
59583
|
if (data.blockedBy !== void 0) {
|
|
59594
59584
|
task.blockedBy = data.blockedBy;
|
|
59595
59585
|
if (this.taskRepo && "updateBlockedBy" in this.taskRepo) {
|
|
59596
|
-
this.taskRepo.updateBlockedBy(id, data.blockedBy).catch((err) =>
|
|
59586
|
+
this.taskRepo.updateBlockedBy(id, data.blockedBy).catch((err) => log48.warn("Failed to persist blockedBy to DB", { error: String(err) }));
|
|
59597
59587
|
}
|
|
59598
59588
|
this.reevaluateBlockedStatus(task);
|
|
59599
59589
|
}
|
|
@@ -59604,7 +59594,7 @@ Action: ${guidance}` : ""
|
|
|
59604
59594
|
const { blockedBy: _bb, ...rest } = data;
|
|
59605
59595
|
const persistData = updatedBy ? { ...rest, updatedBy } : rest;
|
|
59606
59596
|
if (Object.keys(persistData).length > 0) {
|
|
59607
|
-
this.taskRepo.update(id, persistData).catch((err) =>
|
|
59597
|
+
this.taskRepo.update(id, persistData).catch((err) => log48.warn("Failed to persist task update to DB", { error: String(err) }));
|
|
59608
59598
|
}
|
|
59609
59599
|
}
|
|
59610
59600
|
this.ws?.broadcastTaskUpdate(id, task.status, { title: task.title });
|
|
@@ -59678,7 +59668,7 @@ Action: ${guidance}` : ""
|
|
|
59678
59668
|
}
|
|
59679
59669
|
persistSubtasks(task) {
|
|
59680
59670
|
if (this.taskRepo) {
|
|
59681
|
-
this.taskRepo.updateSubtasks?.(task.id, task.subtasks)?.catch?.((err) =>
|
|
59671
|
+
this.taskRepo.updateSubtasks?.(task.id, task.subtasks)?.catch?.((err) => log48.warn("Failed to persist subtasks to DB", { taskId: task.id, error: String(err) }));
|
|
59682
59672
|
}
|
|
59683
59673
|
}
|
|
59684
59674
|
/**
|
|
@@ -59692,7 +59682,7 @@ Action: ${guidance}` : ""
|
|
|
59692
59682
|
if (!task.blockedBy.includes(finishedTask.id))
|
|
59693
59683
|
continue;
|
|
59694
59684
|
if (this.areBlockersSatisfied(task)) {
|
|
59695
|
-
|
|
59685
|
+
log48.info(`Unblocking task ${task.id} (dependency ${finishedTask.id} resolved)`);
|
|
59696
59686
|
this.updateTaskStatus(task.id, "in_progress", void 0, true);
|
|
59697
59687
|
}
|
|
59698
59688
|
}
|
|
@@ -59706,10 +59696,10 @@ Action: ${guidance}` : ""
|
|
|
59706
59696
|
continue;
|
|
59707
59697
|
if (!task.blockedBy.includes(cancelledTask.id))
|
|
59708
59698
|
continue;
|
|
59709
|
-
|
|
59699
|
+
log48.info(`Cascade-cancelling task ${task.id} (dependency ${cancelledTask.id} was cancelled)`);
|
|
59710
59700
|
task.notes = [...task.notes ?? [], `Auto-cancelled: dependency "${cancelledTask.title}" (${cancelledTask.id}) was cancelled`];
|
|
59711
59701
|
if (this.taskRepo) {
|
|
59712
|
-
this.taskRepo.update(task.id, { notes: task.notes }).catch((err) =>
|
|
59702
|
+
this.taskRepo.update(task.id, { notes: task.notes }).catch((err) => log48.warn("Failed to persist cascade-cancel notes", { error: String(err) }));
|
|
59713
59703
|
}
|
|
59714
59704
|
this.updateTaskStatus(task.id, "cancelled", void 0, true);
|
|
59715
59705
|
this.cascadeCancelDependents(task);
|
|
@@ -59732,7 +59722,7 @@ Action: ${guidance}` : ""
|
|
|
59732
59722
|
continue;
|
|
59733
59723
|
const elapsed = now2 - new Date(task.startedAt).getTime();
|
|
59734
59724
|
if (elapsed > task.timeoutMs) {
|
|
59735
|
-
|
|
59725
|
+
log48.warn(`Task ${task.id} timed out after ${elapsed}ms (limit: ${task.timeoutMs}ms)`);
|
|
59736
59726
|
this.updateTaskStatus(task.id, "failed");
|
|
59737
59727
|
this.emitTaskEvent({
|
|
59738
59728
|
type: "timeout",
|
|
@@ -59753,10 +59743,10 @@ Action: ${guidance}` : ""
|
|
|
59753
59743
|
try {
|
|
59754
59744
|
const result = webhook(event);
|
|
59755
59745
|
if (result instanceof Promise) {
|
|
59756
|
-
result.catch((err) =>
|
|
59746
|
+
result.catch((err) => log48.warn("Task webhook error", { error: String(err) }));
|
|
59757
59747
|
}
|
|
59758
59748
|
} catch (err) {
|
|
59759
|
-
|
|
59749
|
+
log48.warn("Task webhook error (sync)", { error: String(err) });
|
|
59760
59750
|
}
|
|
59761
59751
|
}
|
|
59762
59752
|
}
|
|
@@ -59772,7 +59762,7 @@ Action: ${guidance}` : ""
|
|
|
59772
59762
|
};
|
|
59773
59763
|
setGovernancePolicy(policy) {
|
|
59774
59764
|
this.governancePolicy = policy;
|
|
59775
|
-
|
|
59765
|
+
log48.info("Governance policy updated", {
|
|
59776
59766
|
enabled: policy.enabled,
|
|
59777
59767
|
defaultTier: policy.defaultTier
|
|
59778
59768
|
});
|
|
@@ -59866,13 +59856,13 @@ Action: ${guidance}` : ""
|
|
|
59866
59856
|
// ReviewContext field
|
|
59867
59857
|
baseBranch
|
|
59868
59858
|
});
|
|
59869
|
-
|
|
59859
|
+
log48.info("Automated review completed for task submission", {
|
|
59870
59860
|
taskId: taskId2,
|
|
59871
59861
|
overallStatus: reviewReport.overallStatus,
|
|
59872
59862
|
summary: reviewReport.summary
|
|
59873
59863
|
});
|
|
59874
59864
|
} catch (err) {
|
|
59875
|
-
|
|
59865
|
+
log48.warn("Automated review failed, proceeding with submission", { taskId: taskId2, error: String(err) });
|
|
59876
59866
|
}
|
|
59877
59867
|
}
|
|
59878
59868
|
if (task.taskType === "scheduled" && task.deliverables?.length) {
|
|
@@ -59890,9 +59880,9 @@ Action: ${guidance}` : ""
|
|
|
59890
59880
|
task.reviewerAgentId = reviewerAgentId;
|
|
59891
59881
|
}
|
|
59892
59882
|
if (this.taskRepo) {
|
|
59893
|
-
this.taskRepo.updateDeliverables(task.id, task.deliverables).catch((err) =>
|
|
59883
|
+
this.taskRepo.updateDeliverables(task.id, task.deliverables).catch((err) => log48.warn("Failed to persist deliverables to DB", { taskId: task.id, error: String(err) }));
|
|
59894
59884
|
if (reviewerAgentId) {
|
|
59895
|
-
this.taskRepo.update(task.id, { reviewerAgentId }).catch((err) =>
|
|
59885
|
+
this.taskRepo.update(task.id, { reviewerAgentId }).catch((err) => log48.warn("Failed to persist reviewer change to DB", { taskId: task.id, error: String(err) }));
|
|
59896
59886
|
}
|
|
59897
59887
|
}
|
|
59898
59888
|
if (this.deliverableService && deliverables2.length > 0) {
|
|
@@ -59921,7 +59911,7 @@ Action: ${guidance}` : ""
|
|
|
59921
59911
|
}
|
|
59922
59912
|
this.deliverableService.create({
|
|
59923
59913
|
type: d.type === "directory" ? "directory" : "file",
|
|
59924
|
-
title: d.summary.slice(0,
|
|
59914
|
+
title: d.summary.slice(0, DELIVERABLE_TITLE_CHARS) || d.reference,
|
|
59925
59915
|
summary: d.summary,
|
|
59926
59916
|
reference,
|
|
59927
59917
|
taskId: task.id,
|
|
@@ -59932,7 +59922,7 @@ Action: ${guidance}` : ""
|
|
|
59932
59922
|
artifactData,
|
|
59933
59923
|
diffStats: d.diffStats,
|
|
59934
59924
|
testResults: d.testResults
|
|
59935
|
-
}).catch((err) =>
|
|
59925
|
+
}).catch((err) => log48.warn("Failed to create deliverable entity", { taskId: task.id, error: String(err) }));
|
|
59936
59926
|
}
|
|
59937
59927
|
}
|
|
59938
59928
|
if (this.sharedDataDir) {
|
|
@@ -59954,7 +59944,7 @@ Action: ${guidance}` : ""
|
|
|
59954
59944
|
metadata: { deliverableCount: deliverables2.length, reviewReportStatus: reviewReport?.overallStatus }
|
|
59955
59945
|
});
|
|
59956
59946
|
this.updateTaskStatus(task.id, "review");
|
|
59957
|
-
|
|
59947
|
+
log48.info(`Task submitted for review: ${task.title}`, { id: task.id });
|
|
59958
59948
|
return task;
|
|
59959
59949
|
}
|
|
59960
59950
|
/**
|
|
@@ -59962,15 +59952,15 @@ Action: ${guidance}` : ""
|
|
|
59962
59952
|
*/
|
|
59963
59953
|
notifyReviewer(task, reviewerAgentId) {
|
|
59964
59954
|
if (!this.agentManager || !this.agentManager.hasAgent(reviewerAgentId)) {
|
|
59965
|
-
|
|
59955
|
+
log48.warn("Reviewer agent not found, cannot notify", { taskId: task.id, reviewerAgentId });
|
|
59966
59956
|
return;
|
|
59967
59957
|
}
|
|
59968
59958
|
if (reviewerAgentId === task.assignedAgentId) {
|
|
59969
|
-
|
|
59959
|
+
log48.warn("Reviewer is the same as assignee, skipping notification", { taskId: task.id, reviewerAgentId });
|
|
59970
59960
|
return;
|
|
59971
59961
|
}
|
|
59972
59962
|
if (this.activeReviews.has(task.id)) {
|
|
59973
|
-
|
|
59963
|
+
log48.debug("Review notification already active for task, skipping duplicate", { taskId: task.id, reviewerAgentId });
|
|
59974
59964
|
return;
|
|
59975
59965
|
}
|
|
59976
59966
|
this.activeReviews.add(task.id);
|
|
@@ -59985,11 +59975,11 @@ Action: ${guidance}` : ""
|
|
|
59985
59975
|
if (files.length > 0) {
|
|
59986
59976
|
parts.push("");
|
|
59987
59977
|
parts.push("**Deliverables:**");
|
|
59988
|
-
for (const d of files.slice(0,
|
|
59978
|
+
for (const d of files.slice(0, REVIEWER_FILE_LIST_MAX)) {
|
|
59989
59979
|
parts.push(`- [${d.type}] ${d.reference}${d.summary ? ` \u2014 ${d.summary}` : ""}`);
|
|
59990
59980
|
}
|
|
59991
|
-
if (files.length >
|
|
59992
|
-
parts.push(` ... and ${files.length -
|
|
59981
|
+
if (files.length > REVIEWER_FILE_LIST_MAX)
|
|
59982
|
+
parts.push(` ... and ${files.length - REVIEWER_FILE_LIST_MAX} more`);
|
|
59993
59983
|
}
|
|
59994
59984
|
const branch = task.deliverables.find((d) => d.type === "branch");
|
|
59995
59985
|
if (branch) {
|
|
@@ -60010,7 +60000,7 @@ Action: ${guidance}` : ""
|
|
|
60010
60000
|
if (task.notes && task.notes.length > 0) {
|
|
60011
60001
|
parts.push("");
|
|
60012
60002
|
parts.push("**Recent Notes:**");
|
|
60013
|
-
for (const note of task.notes.slice(-
|
|
60003
|
+
for (const note of task.notes.slice(-REVIEWER_NOTES_MAX)) {
|
|
60014
60004
|
parts.push(`> ${note}`);
|
|
60015
60005
|
}
|
|
60016
60006
|
}
|
|
@@ -60039,12 +60029,12 @@ Action: ${guidance}` : ""
|
|
|
60039
60029
|
this.activeReviews.delete(task.id);
|
|
60040
60030
|
}).catch((err) => {
|
|
60041
60031
|
this.activeReviews.delete(task.id);
|
|
60042
|
-
|
|
60032
|
+
log48.warn("Failed to notify reviewer about review", { taskId: task.id, reviewerAgentId, error: String(err) });
|
|
60043
60033
|
});
|
|
60044
|
-
|
|
60034
|
+
log48.info("Notified reviewer about review", { taskId: task.id, reviewerAgentId });
|
|
60045
60035
|
} catch (err) {
|
|
60046
60036
|
this.activeReviews.delete(task.id);
|
|
60047
|
-
|
|
60037
|
+
log48.warn("Failed to notify reviewer about review", { taskId: task.id, reviewerAgentId, error: String(err) });
|
|
60048
60038
|
}
|
|
60049
60039
|
}
|
|
60050
60040
|
// Workspace path derivation removed — agents manage their own workspaces.
|
|
@@ -60108,7 +60098,7 @@ Action: ${guidance}` : ""
|
|
|
60108
60098
|
const destName = src.split("/").pop() ?? "deliverable";
|
|
60109
60099
|
cpSync(src, join18(taskSharedDir, destName), { recursive: true });
|
|
60110
60100
|
} catch (err) {
|
|
60111
|
-
|
|
60101
|
+
log48.warn("Failed to copy deliverable to shared space", { taskId: task.id, ref: d.reference, error: String(err) });
|
|
60112
60102
|
}
|
|
60113
60103
|
}
|
|
60114
60104
|
}
|
|
@@ -60117,7 +60107,7 @@ Action: ${guidance}` : ""
|
|
|
60117
60107
|
writeFileSync12(join18(taskSharedDir, `${safeName}.md`), d.summary);
|
|
60118
60108
|
}
|
|
60119
60109
|
}
|
|
60120
|
-
|
|
60110
|
+
log48.info("Deliverables published to shared workspace", { taskId: task.id, dir: taskSharedDir });
|
|
60121
60111
|
}
|
|
60122
60112
|
/**
|
|
60123
60113
|
* Managers can only review tasks from their own team members or tasks they created.
|
|
@@ -60174,7 +60164,7 @@ Action: ${guidance}` : ""
|
|
|
60174
60164
|
if (task.assignedAgentId && this.agentManager) {
|
|
60175
60165
|
this.triggerPostTaskReflection(task);
|
|
60176
60166
|
}
|
|
60177
|
-
|
|
60167
|
+
log48.info(`Task accepted and completed: ${task.title}`, { id: task.id });
|
|
60178
60168
|
return task;
|
|
60179
60169
|
}
|
|
60180
60170
|
reflectionCountByAgent = /* @__PURE__ */ new Map();
|
|
@@ -60195,7 +60185,7 @@ Action: ${guidance}` : ""
|
|
|
60195
60185
|
if (!agent)
|
|
60196
60186
|
return;
|
|
60197
60187
|
if (this.isReflectionRateLimited(task.assignedAgentId)) {
|
|
60198
|
-
|
|
60188
|
+
log48.debug("Skipping reflection \u2014 daily limit reached", { agentId: task.assignedAgentId });
|
|
60199
60189
|
return;
|
|
60200
60190
|
}
|
|
60201
60191
|
const hadRevisions = (task.executionRound ?? 1) > 1;
|
|
@@ -60229,7 +60219,7 @@ Action: ${guidance}` : ""
|
|
|
60229
60219
|
sessionId: `sys_${agent.id}_${Date.now()}`,
|
|
60230
60220
|
scenario: "heartbeat"
|
|
60231
60221
|
}).catch((err) => {
|
|
60232
|
-
|
|
60222
|
+
log48.warn("Post-task reflection failed", { taskId: task.id, error: String(err) });
|
|
60233
60223
|
});
|
|
60234
60224
|
}
|
|
60235
60225
|
async requestRevision(taskId2, reason, author) {
|
|
@@ -60248,8 +60238,8 @@ Action: ${guidance}` : ""
|
|
|
60248
60238
|
task.notes = task.notes ?? [];
|
|
60249
60239
|
task.notes.push(`[${formatLocalTimestamp(now2)} by ${by}] Revision requested (round ${task.executionRound}): ${reason}`);
|
|
60250
60240
|
if (this.taskRepo) {
|
|
60251
|
-
this.taskRepo.updateExecutionRound?.(task.id, task.executionRound)?.catch?.((err) =>
|
|
60252
|
-
this.taskRepo.update(task.id, { notes: task.notes }).catch((err) =>
|
|
60241
|
+
this.taskRepo.updateExecutionRound?.(task.id, task.executionRound)?.catch?.((err) => log48.warn("Failed to persist execution round", { taskId: task.id, error: String(err) }));
|
|
60242
|
+
this.taskRepo.update(task.id, { notes: task.notes }).catch((err) => log48.warn("Failed to persist revision notes", { error: String(err) }));
|
|
60253
60243
|
}
|
|
60254
60244
|
if (this.taskCommentRepo) {
|
|
60255
60245
|
try {
|
|
@@ -60263,7 +60253,7 @@ Action: ${guidance}` : ""
|
|
|
60263
60253
|
${reason}`
|
|
60264
60254
|
});
|
|
60265
60255
|
} catch (err) {
|
|
60266
|
-
|
|
60256
|
+
log48.warn("Failed to persist revision comment", { taskId: task.id, error: String(err) });
|
|
60267
60257
|
}
|
|
60268
60258
|
}
|
|
60269
60259
|
this.auditService?.record({
|
|
@@ -60271,14 +60261,14 @@ ${reason}`
|
|
|
60271
60261
|
agentId: task.assignedAgentId,
|
|
60272
60262
|
type: "task_review_revision_requested",
|
|
60273
60263
|
action: "request_revision",
|
|
60274
|
-
detail: `Revision requested for task "${task.title}" (round ${task.executionRound}): ${reason.slice(0,
|
|
60264
|
+
detail: `Revision requested for task "${task.title}" (round ${task.executionRound}): ${reason.slice(0, REVISION_REASON_CHARS)}`,
|
|
60275
60265
|
taskId: task.id,
|
|
60276
60266
|
projectId: task.projectId,
|
|
60277
60267
|
success: true,
|
|
60278
60268
|
metadata: { reason, executionRound: task.executionRound }
|
|
60279
60269
|
});
|
|
60280
60270
|
this.updateTaskStatus(task.id, "in_progress");
|
|
60281
|
-
|
|
60271
|
+
log48.info(`Revision requested, auto-restarting task: ${task.title}`, { id: task.id, reason, round: task.executionRound });
|
|
60282
60272
|
return task;
|
|
60283
60273
|
}
|
|
60284
60274
|
archiveTask(taskId2) {
|
|
@@ -60380,9 +60370,9 @@ ${reason}`
|
|
|
60380
60370
|
this.addTaskNote(dup.id, `Auto-cancelled: duplicate of task ${keeper.id} ("${keeper.title}")`, "System");
|
|
60381
60371
|
this.updateTaskStatus(dup.id, "cancelled");
|
|
60382
60372
|
cancelledIds.push(dup.id);
|
|
60383
|
-
|
|
60373
|
+
log48.info(`Auto-cancelled duplicate task`, { cancelledId: dup.id, keeperId: keeper.id });
|
|
60384
60374
|
} catch (err) {
|
|
60385
|
-
|
|
60375
|
+
log48.warn("Failed to cancel duplicate task", { taskId: dup.id, error: String(err) });
|
|
60386
60376
|
}
|
|
60387
60377
|
}
|
|
60388
60378
|
}
|
|
@@ -60485,13 +60475,13 @@ ${reason}`
|
|
|
60485
60475
|
task.notes = task.notes ?? [];
|
|
60486
60476
|
task.notes.push(`[${formatLocalTimestamp(/* @__PURE__ */ new Date())}] Fresh retry requested (round ${task.executionRound}) \u2014 starting without previous execution context`);
|
|
60487
60477
|
if (this.taskRepo) {
|
|
60488
|
-
this.taskRepo.clearForRerun?.(task.id, task.executionRound)?.catch?.((err) =>
|
|
60489
|
-
this.taskRepo.update(task.id, { notes: task.notes }).catch((err) =>
|
|
60478
|
+
this.taskRepo.clearForRerun?.(task.id, task.executionRound)?.catch?.((err) => log48.warn("Failed to persist fresh retry reset", { taskId: task.id, error: String(err) }));
|
|
60479
|
+
this.taskRepo.update(task.id, { notes: task.notes }).catch((err) => log48.warn("Failed to persist retry notes", { error: String(err) }));
|
|
60490
60480
|
}
|
|
60491
60481
|
this.updateTaskStatus(taskIdStr, "in_progress", void 0, true, true);
|
|
60492
60482
|
if (this.agentManager) {
|
|
60493
60483
|
setImmediate(() => {
|
|
60494
|
-
this.runTaskFresh(task.id).catch((err) =>
|
|
60484
|
+
this.runTaskFresh(task.id).catch((err) => log48.warn("Failed to start fresh retry", { taskId: task.id, error: String(err) }));
|
|
60495
60485
|
});
|
|
60496
60486
|
}
|
|
60497
60487
|
return task;
|
|
@@ -60509,7 +60499,7 @@ ${reason}`
|
|
|
60509
60499
|
if (!this.agentManager)
|
|
60510
60500
|
throw new Error("AgentManager not set");
|
|
60511
60501
|
if (task.status !== "in_progress") {
|
|
60512
|
-
|
|
60502
|
+
log48.warn("runTaskFresh called but task not in in_progress state, skipping", {
|
|
60513
60503
|
taskId: taskId2,
|
|
60514
60504
|
currentStatus: task.status
|
|
60515
60505
|
});
|
|
@@ -60528,11 +60518,11 @@ ${reason}`
|
|
|
60528
60518
|
continue;
|
|
60529
60519
|
const lines = [`### Dependency: ${depTask.title} (ID: ${depId}, status: ${depTask.status})`];
|
|
60530
60520
|
if (depTask.description)
|
|
60531
|
-
lines.push(`**Description:** ${depTask.description.slice(0,
|
|
60521
|
+
lines.push(`**Description:** ${depTask.description.slice(0, PROMPT_DEP_DESC_CHARS)}`);
|
|
60532
60522
|
if (depTask.notes?.length) {
|
|
60533
60523
|
lines.push("**Notes (most recent first):**");
|
|
60534
|
-
for (const note of depTask.notes.slice(-
|
|
60535
|
-
lines.push(`- ${note.slice(0,
|
|
60524
|
+
for (const note of depTask.notes.slice(-PROMPT_DEP_NOTES_MAX).reverse())
|
|
60525
|
+
lines.push(`- ${note.slice(0, PROMPT_DEP_NOTE_CHARS)}`);
|
|
60536
60526
|
}
|
|
60537
60527
|
if (depTask.deliverables?.length) {
|
|
60538
60528
|
lines.push("**Deliverables (review these for background context):**");
|
|
@@ -60562,12 +60552,12 @@ ${reason}`
|
|
|
60562
60552
|
if (task.projectId && this.projectService) {
|
|
60563
60553
|
const project = this.projectService.getProject(task.projectId);
|
|
60564
60554
|
if (project) {
|
|
60565
|
-
goalLines.push(`**Project:** ${project.name} \u2014 ${project.description.slice(0,
|
|
60555
|
+
goalLines.push(`**Project:** ${project.name} \u2014 ${project.description.slice(0, PROMPT_PROJECT_DESC_CHARS)}`);
|
|
60566
60556
|
}
|
|
60567
60557
|
}
|
|
60568
60558
|
goalLines.push(`**Requirement:** ${req.title}`);
|
|
60569
60559
|
if (req.description) {
|
|
60570
|
-
goalLines.push(`**Requirement Description:** ${req.description.slice(0,
|
|
60560
|
+
goalLines.push(`**Requirement Description:** ${req.description.slice(0, PROMPT_REQUIREMENT_DESC_CHARS)}`);
|
|
60571
60561
|
}
|
|
60572
60562
|
goalLines.push("");
|
|
60573
60563
|
goalLines.push("Keep this goal context in mind. Your task should directly advance this requirement.");
|
|
@@ -60577,9 +60567,9 @@ ${reason}`
|
|
|
60577
60567
|
}
|
|
60578
60568
|
let notesSection = "";
|
|
60579
60569
|
if (task.notes?.length) {
|
|
60580
|
-
const recentNotes = task.notes.slice(-
|
|
60570
|
+
const recentNotes = task.notes.slice(-PROMPT_TASK_NOTES_MAX);
|
|
60581
60571
|
const noteLines = ["## Task Notes"];
|
|
60582
|
-
noteLines.push(...recentNotes.map((n) => `- ${n.slice(0,
|
|
60572
|
+
noteLines.push(...recentNotes.map((n) => `- ${n.slice(0, PROMPT_TASK_NOTE_CHARS)}`), "", "---", "");
|
|
60583
60573
|
notesSection = noteLines.join("\n");
|
|
60584
60574
|
}
|
|
60585
60575
|
let subtaskSection = "";
|
|
@@ -60634,7 +60624,7 @@ ${task.description}`;
|
|
|
60634
60624
|
subtasks: task.subtasks
|
|
60635
60625
|
});
|
|
60636
60626
|
} catch (err) {
|
|
60637
|
-
|
|
60627
|
+
log48.warn("Failed to ensure task exists in DB before fresh retry", { taskId: taskId2, error: String(err) });
|
|
60638
60628
|
}
|
|
60639
60629
|
}
|
|
60640
60630
|
const taskLogRepo = this.taskLogRepo;
|
|
@@ -60670,14 +60660,14 @@ ${task.description}`;
|
|
|
60670
60660
|
const saved = await taskLogRepo.append({ taskId: taskId2, agentId: task.assignedAgentId, seq: currentSeq, type: entry.type, content: entry.content, metadata: entry.metadata, executionRound });
|
|
60671
60661
|
savedId = saved.id;
|
|
60672
60662
|
} catch (err) {
|
|
60673
|
-
|
|
60663
|
+
log48.warn("Failed to persist task log", { taskId: taskId2, error: String(err) });
|
|
60674
60664
|
}
|
|
60675
60665
|
}
|
|
60676
60666
|
if (this.executionStreamRepo) {
|
|
60677
60667
|
try {
|
|
60678
60668
|
this.executionStreamRepo.append({ sourceType: "task", sourceId: taskId2, agentId: task.assignedAgentId, seq: currentSeq, type: entry.type, content: entry.content, metadata: entry.metadata, executionRound });
|
|
60679
60669
|
} catch (err) {
|
|
60680
|
-
|
|
60670
|
+
log48.warn("Failed to persist execution stream log", { taskId: taskId2, error: String(err) });
|
|
60681
60671
|
}
|
|
60682
60672
|
}
|
|
60683
60673
|
if (ws) {
|
|
@@ -60689,13 +60679,13 @@ ${task.description}`;
|
|
|
60689
60679
|
const alreadyTerminal = currentTask && ["review", "completed", "failed", "cancelled", "archived"].includes(currentTask.status);
|
|
60690
60680
|
if (!alreadyTerminal && currentTask && currentTask.status === "in_progress") {
|
|
60691
60681
|
const delayMs = _TaskService.RETRY_DELAYS_MS[0] ?? 1e4;
|
|
60692
|
-
|
|
60682
|
+
log48.warn(`Fresh retry finished without task_submit_review \u2014 auto-retrying in ${delayMs / 1e3}s`, { taskId: taskId2 });
|
|
60693
60683
|
this.addTaskNote(taskId2, `[System] Fresh retry finished without task_submit_review. Auto-retrying.`, "system");
|
|
60694
60684
|
setTimeout(() => {
|
|
60695
60685
|
const current = this.tasks.get(taskId2);
|
|
60696
60686
|
if (!current || current.status !== "in_progress")
|
|
60697
60687
|
return;
|
|
60698
|
-
this.runTask(taskId2, 1).catch((e) =>
|
|
60688
|
+
this.runTask(taskId2, 1).catch((e) => log48.error("Fresh no-submit retry invocation failed", { taskId: taskId2, error: String(e) }));
|
|
60699
60689
|
}, delayMs);
|
|
60700
60690
|
}
|
|
60701
60691
|
} else if (entry.type === "status" && entry.content === "preempted") {
|
|
@@ -60708,8 +60698,8 @@ ${task.description}`;
|
|
|
60708
60698
|
const activeToken = this.taskCancelTokens.get(taskId2);
|
|
60709
60699
|
if (activeToken && !activeToken.cancelled)
|
|
60710
60700
|
return;
|
|
60711
|
-
|
|
60712
|
-
this.runTask(taskId2).catch((err) =>
|
|
60701
|
+
log48.info("Re-queuing preempted task (fresh)", { taskId: taskId2 });
|
|
60702
|
+
this.runTask(taskId2).catch((err) => log48.warn("Failed to re-queue preempted task", { taskId: taskId2, error: String(err) }));
|
|
60713
60703
|
});
|
|
60714
60704
|
} else if (entry.type === "error") {
|
|
60715
60705
|
const retryDecision = this.shouldRetryTask(taskId2, entry.content, 0, cancelToken.cancelled);
|
|
@@ -60719,7 +60709,7 @@ ${task.description}`;
|
|
|
60719
60709
|
}
|
|
60720
60710
|
}
|
|
60721
60711
|
}, cancelToken, void 0, executionRound).catch((err) => {
|
|
60722
|
-
|
|
60712
|
+
log48.error("Fresh retry execution rejected", { taskId: taskId2, error: String(err) });
|
|
60723
60713
|
if (!cancelToken.cancelled) {
|
|
60724
60714
|
this.taskRetryErrors.delete(taskId2);
|
|
60725
60715
|
this.updateTaskStatus(taskId2, "failed");
|
|
@@ -60759,9 +60749,9 @@ ${task.description}`;
|
|
|
60759
60749
|
"**IMPORTANT: Address this comment in your current work. It may contain new instructions, corrections, or feedback that you must follow.**"
|
|
60760
60750
|
].join("\n");
|
|
60761
60751
|
agent.injectUserMessage(sessionId, injectedMessage);
|
|
60762
|
-
|
|
60752
|
+
log48.info("Injected live comment into agent session", { taskId: taskId2, sessionId, authorName });
|
|
60763
60753
|
} catch (err) {
|
|
60764
|
-
|
|
60754
|
+
log48.warn("Failed to inject comment into agent session", { taskId: taskId2, error: String(err) });
|
|
60765
60755
|
}
|
|
60766
60756
|
}
|
|
60767
60757
|
/**
|
|
@@ -60772,14 +60762,14 @@ ${task.description}`;
|
|
|
60772
60762
|
*/
|
|
60773
60763
|
async handlePostTaskComment(taskId2, task, authorName, content) {
|
|
60774
60764
|
if (!task.assignedAgentId || !this.agentManager) {
|
|
60775
|
-
|
|
60765
|
+
log48.debug("Cannot handle post-task comment \u2014 no agent assigned or agent manager unavailable", { taskId: taskId2 });
|
|
60776
60766
|
return;
|
|
60777
60767
|
}
|
|
60778
60768
|
let agent;
|
|
60779
60769
|
try {
|
|
60780
60770
|
agent = this.agentManager.getAgent(task.assignedAgentId);
|
|
60781
60771
|
} catch {
|
|
60782
|
-
|
|
60772
|
+
log48.debug("Cannot handle post-task comment \u2014 agent not found", { taskId: taskId2, agentId: task.assignedAgentId });
|
|
60783
60773
|
return;
|
|
60784
60774
|
}
|
|
60785
60775
|
const agentId2 = task.assignedAgentId;
|
|
@@ -60805,7 +60795,7 @@ ${task.description}`;
|
|
|
60805
60795
|
"You have all your tools available \u2014 take action if appropriate.)"
|
|
60806
60796
|
].join("\n");
|
|
60807
60797
|
try {
|
|
60808
|
-
|
|
60798
|
+
log48.info("Triggering post-task agent reply", { taskId: taskId2, taskSessionId, agentId: agentId2, authorName });
|
|
60809
60799
|
const reply = await agent.sendSessionReply(taskSessionId, prompt, (entry) => {
|
|
60810
60800
|
if (!entry.persist) {
|
|
60811
60801
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -60816,7 +60806,7 @@ ${task.description}`;
|
|
|
60816
60806
|
const currentSeq = seq++;
|
|
60817
60807
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
60818
60808
|
let savedId;
|
|
60819
|
-
taskLogRepo?.append({ taskId: taskId2, agentId: agentId2, seq: currentSeq, type: entry.type, content: entry.content, metadata: entry.metadata, executionRound: round }).catch((err) =>
|
|
60809
|
+
taskLogRepo?.append({ taskId: taskId2, agentId: agentId2, seq: currentSeq, type: entry.type, content: entry.content, metadata: entry.metadata, executionRound: round }).catch((err) => log48.warn("Failed to persist post-task log", { taskId: taskId2, error: String(err) }));
|
|
60820
60810
|
if (this.executionStreamRepo) {
|
|
60821
60811
|
try {
|
|
60822
60812
|
this.executionStreamRepo.append({ sourceType: "task", sourceId: taskId2, agentId: agentId2, seq: currentSeq, type: entry.type, content: entry.content, metadata: entry.metadata, executionRound: round });
|
|
@@ -60828,7 +60818,7 @@ ${task.description}`;
|
|
|
60828
60818
|
});
|
|
60829
60819
|
const cleanReply = reply.trim();
|
|
60830
60820
|
if (!cleanReply) {
|
|
60831
|
-
|
|
60821
|
+
log48.warn("Agent returned empty reply for post-task comment", { taskId: taskId2 });
|
|
60832
60822
|
return;
|
|
60833
60823
|
}
|
|
60834
60824
|
if (this.taskCommentRepo) {
|
|
@@ -60857,9 +60847,9 @@ ${task.description}`;
|
|
|
60857
60847
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
60858
60848
|
});
|
|
60859
60849
|
}
|
|
60860
|
-
|
|
60850
|
+
log48.info("Post-task agent reply saved", { taskId: taskId2, replyLength: cleanReply.length });
|
|
60861
60851
|
} catch (err) {
|
|
60862
|
-
|
|
60852
|
+
log48.warn("Post-task comment reply failed", { taskId: taskId2, error: String(err) });
|
|
60863
60853
|
}
|
|
60864
60854
|
}
|
|
60865
60855
|
async resetTaskForRerun(taskIdStr) {
|
|
@@ -60871,10 +60861,10 @@ ${task.description}`;
|
|
|
60871
60861
|
task.startedAt = void 0;
|
|
60872
60862
|
task.completedAt = void 0;
|
|
60873
60863
|
if (this.taskRepo) {
|
|
60874
|
-
this.taskRepo.clearForRerun?.(task.id, task.executionRound)?.catch?.((err) =>
|
|
60864
|
+
this.taskRepo.clearForRerun?.(task.id, task.executionRound)?.catch?.((err) => log48.warn("Failed to persist rerun reset", { taskId: task.id, error: String(err) }));
|
|
60875
60865
|
}
|
|
60876
60866
|
this.updateTaskStatus(taskIdStr, "in_progress", void 0, true);
|
|
60877
|
-
|
|
60867
|
+
log48.info("Scheduled task reset for rerun", { taskId: task.id, title: task.title, round: task.executionRound });
|
|
60878
60868
|
}
|
|
60879
60869
|
};
|
|
60880
60870
|
INTERVAL_MULTIPLIERS = {
|
|
@@ -60892,12 +60882,12 @@ ${task.description}`;
|
|
|
60892
60882
|
import { join as join19 } from "node:path";
|
|
60893
60883
|
import { readdirSync as readdirSync8, readFileSync as readFileSync18, existsSync as existsSync24, writeFileSync as writeFileSync13, mkdirSync as mkdirSync16, copyFileSync as copyFileSync2, statSync as statSync4 } from "node:fs";
|
|
60894
60884
|
import { homedir as homedir11 } from "node:os";
|
|
60895
|
-
var
|
|
60885
|
+
var log49, FS_HELPER, BuilderService;
|
|
60896
60886
|
var init_builder_service = __esm({
|
|
60897
60887
|
"../org-manager/dist/builder-service.js"() {
|
|
60898
60888
|
"use strict";
|
|
60899
60889
|
init_dist();
|
|
60900
|
-
|
|
60890
|
+
log49 = createLogger("builder-service");
|
|
60901
60891
|
FS_HELPER = {
|
|
60902
60892
|
existsSync: existsSync24,
|
|
60903
60893
|
readFileSync: (p, _enc) => readFileSync18(p, "utf-8"),
|
|
@@ -61098,7 +61088,7 @@ var init_builder_service = __esm({
|
|
|
61098
61088
|
}
|
|
61099
61089
|
});
|
|
61100
61090
|
} catch (regErr) {
|
|
61101
|
-
|
|
61091
|
+
log49.warn("Failed to register skill into runtime registry", { error: String(regErr) });
|
|
61102
61092
|
}
|
|
61103
61093
|
}
|
|
61104
61094
|
return {
|
|
@@ -61112,12 +61102,12 @@ var init_builder_service = __esm({
|
|
|
61112
61102
|
|
|
61113
61103
|
// ../org-manager/dist/ws-server.js
|
|
61114
61104
|
import { WebSocketServer, WebSocket } from "ws";
|
|
61115
|
-
var
|
|
61105
|
+
var log50, WSBroadcaster;
|
|
61116
61106
|
var init_ws_server = __esm({
|
|
61117
61107
|
"../org-manager/dist/ws-server.js"() {
|
|
61118
61108
|
"use strict";
|
|
61119
61109
|
init_dist();
|
|
61120
|
-
|
|
61110
|
+
log50 = createLogger("ws-server");
|
|
61121
61111
|
WSBroadcaster = class {
|
|
61122
61112
|
wss;
|
|
61123
61113
|
clients = /* @__PURE__ */ new Set();
|
|
@@ -61125,13 +61115,13 @@ var init_ws_server = __esm({
|
|
|
61125
61115
|
this.wss = new WebSocketServer({ server, path: "/ws" });
|
|
61126
61116
|
this.wss.on("connection", (ws, _req) => {
|
|
61127
61117
|
this.clients.add(ws);
|
|
61128
|
-
|
|
61118
|
+
log50.info("WebSocket client connected", { clients: this.clients.size });
|
|
61129
61119
|
ws.on("close", () => {
|
|
61130
61120
|
this.clients.delete(ws);
|
|
61131
|
-
|
|
61121
|
+
log50.debug("WebSocket client disconnected", { clients: this.clients.size });
|
|
61132
61122
|
});
|
|
61133
61123
|
ws.on("error", (err) => {
|
|
61134
|
-
|
|
61124
|
+
log50.error("WebSocket client error", { error: String(err) });
|
|
61135
61125
|
this.clients.delete(ws);
|
|
61136
61126
|
});
|
|
61137
61127
|
ws.send(JSON.stringify({
|
|
@@ -61140,7 +61130,7 @@ var init_ws_server = __esm({
|
|
|
61140
61130
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
61141
61131
|
}));
|
|
61142
61132
|
});
|
|
61143
|
-
|
|
61133
|
+
log50.info("WebSocket server attached");
|
|
61144
61134
|
}
|
|
61145
61135
|
broadcast(event) {
|
|
61146
61136
|
const data = JSON.stringify(event);
|
|
@@ -61215,12 +61205,12 @@ var init_ws_server = __esm({
|
|
|
61215
61205
|
});
|
|
61216
61206
|
|
|
61217
61207
|
// ../org-manager/dist/sse-buffer.js
|
|
61218
|
-
var
|
|
61208
|
+
var log51, SSEBuffer;
|
|
61219
61209
|
var init_sse_buffer = __esm({
|
|
61220
61210
|
"../org-manager/dist/sse-buffer.js"() {
|
|
61221
61211
|
"use strict";
|
|
61222
61212
|
init_dist();
|
|
61223
|
-
|
|
61213
|
+
log51 = createLogger("sse-buffer");
|
|
61224
61214
|
SSEBuffer = class {
|
|
61225
61215
|
response;
|
|
61226
61216
|
buffer = [];
|
|
@@ -61266,7 +61256,7 @@ var init_sse_buffer = __esm({
|
|
|
61266
61256
|
this.close();
|
|
61267
61257
|
});
|
|
61268
61258
|
this.response.on("error", (err) => {
|
|
61269
|
-
|
|
61259
|
+
log51.error("SSE response error", { error: String(err) });
|
|
61270
61260
|
this.close();
|
|
61271
61261
|
});
|
|
61272
61262
|
}
|
|
@@ -61285,7 +61275,7 @@ var init_sse_buffer = __esm({
|
|
|
61285
61275
|
this.droppedAfterClose++;
|
|
61286
61276
|
if (!this.closedWarnLogged) {
|
|
61287
61277
|
this.closedWarnLogged = true;
|
|
61288
|
-
|
|
61278
|
+
log51.warn("SSE connection closed \u2014 further messages will be silently dropped");
|
|
61289
61279
|
}
|
|
61290
61280
|
return;
|
|
61291
61281
|
}
|
|
@@ -61314,7 +61304,7 @@ var init_sse_buffer = __esm({
|
|
|
61314
61304
|
this.stats.messagesSent++;
|
|
61315
61305
|
this.stats.bytesSent += Buffer.byteLength(eventStr, "utf8");
|
|
61316
61306
|
} catch (err) {
|
|
61317
|
-
|
|
61307
|
+
log51.error("Failed to send immediate SSE message", { error: String(err) });
|
|
61318
61308
|
this.stats.errors++;
|
|
61319
61309
|
}
|
|
61320
61310
|
}
|
|
@@ -61368,7 +61358,7 @@ var init_sse_buffer = __esm({
|
|
|
61368
61358
|
this.flushTimer = null;
|
|
61369
61359
|
}
|
|
61370
61360
|
} catch (err) {
|
|
61371
|
-
|
|
61361
|
+
log51.error("Failed to flush SSE buffer", { error: String(err) });
|
|
61372
61362
|
this.stats.errors++;
|
|
61373
61363
|
this.close();
|
|
61374
61364
|
}
|
|
@@ -61387,7 +61377,7 @@ var init_sse_buffer = __esm({
|
|
|
61387
61377
|
try {
|
|
61388
61378
|
this.sendImmediate({ type: "heartbeat", timestamp: Date.now() });
|
|
61389
61379
|
} catch (err) {
|
|
61390
|
-
|
|
61380
|
+
log51.warn("Heartbeat failed", { error: String(err) });
|
|
61391
61381
|
this.stopHeartbeat();
|
|
61392
61382
|
this.close();
|
|
61393
61383
|
}
|
|
@@ -61425,14 +61415,14 @@ var init_sse_buffer = __esm({
|
|
|
61425
61415
|
this.response.end();
|
|
61426
61416
|
}
|
|
61427
61417
|
} catch (err) {
|
|
61428
|
-
|
|
61418
|
+
log51.debug("Error closing SSE connection", { error: String(err) });
|
|
61429
61419
|
}
|
|
61430
61420
|
if (this.droppedAfterClose > 0) {
|
|
61431
|
-
|
|
61421
|
+
log51.warn("SSE connection closed after dropping messages", {
|
|
61432
61422
|
droppedAfterClose: this.droppedAfterClose
|
|
61433
61423
|
});
|
|
61434
61424
|
}
|
|
61435
|
-
|
|
61425
|
+
log51.debug("SSE connection closed", { stats: this.stats });
|
|
61436
61426
|
if (this.onCloseCallback) {
|
|
61437
61427
|
try {
|
|
61438
61428
|
this.onCloseCallback();
|
|
@@ -61457,13 +61447,13 @@ var init_sse_buffer = __esm({
|
|
|
61457
61447
|
});
|
|
61458
61448
|
|
|
61459
61449
|
// ../org-manager/dist/sse-handler.js
|
|
61460
|
-
var
|
|
61450
|
+
var log52, SSEHandler;
|
|
61461
61451
|
var init_sse_handler = __esm({
|
|
61462
61452
|
"../org-manager/dist/sse-handler.js"() {
|
|
61463
61453
|
"use strict";
|
|
61464
61454
|
init_dist();
|
|
61465
61455
|
init_sse_buffer();
|
|
61466
|
-
|
|
61456
|
+
log52 = createLogger("sse-handler");
|
|
61467
61457
|
SSEHandler = class {
|
|
61468
61458
|
options;
|
|
61469
61459
|
sseBuffer = null;
|
|
@@ -61498,7 +61488,7 @@ var init_sse_handler = __esm({
|
|
|
61498
61488
|
if (!this.isComplete) {
|
|
61499
61489
|
this.sseDisconnected = true;
|
|
61500
61490
|
this.cancelToken.cancelled = true;
|
|
61501
|
-
|
|
61491
|
+
log52.warn("SSE client disconnected \u2014 cancelling agent", {
|
|
61502
61492
|
agentId: this.options.agentId
|
|
61503
61493
|
});
|
|
61504
61494
|
if (this.options.wsBroadcaster?.broadcastAgentUpdate) {
|
|
@@ -61523,7 +61513,7 @@ var init_sse_handler = __esm({
|
|
|
61523
61513
|
persistReply = segText;
|
|
61524
61514
|
}
|
|
61525
61515
|
if (this.sseDisconnected) {
|
|
61526
|
-
|
|
61516
|
+
log52.info("Agent finished but SSE was disconnected \u2014 delivering reply via WebSocket fallback", {
|
|
61527
61517
|
agentId: this.options.agentId,
|
|
61528
61518
|
replyLength: persistReply.length
|
|
61529
61519
|
});
|
|
@@ -61554,7 +61544,7 @@ var init_sse_handler = __esm({
|
|
|
61554
61544
|
try {
|
|
61555
61545
|
await this.options.persistAssistantMessage(this.sessionId, this.options.agentId, persistReply, this.options.agent.getState().tokensUsedToday, Object.keys(msgMeta).length > 0 ? msgMeta : void 0);
|
|
61556
61546
|
} catch (e) {
|
|
61557
|
-
|
|
61547
|
+
log52.error("Failed to persist assistant message", { agentId: this.options.agentId, error: String(e) });
|
|
61558
61548
|
}
|
|
61559
61549
|
}
|
|
61560
61550
|
if (this.options.onComplete) {
|
|
@@ -61570,7 +61560,7 @@ var init_sse_handler = __esm({
|
|
|
61570
61560
|
}, 100);
|
|
61571
61561
|
}
|
|
61572
61562
|
} catch (error) {
|
|
61573
|
-
|
|
61563
|
+
log52.error("SSE handler error", {
|
|
61574
61564
|
agentId: this.options.agentId,
|
|
61575
61565
|
error: String(error)
|
|
61576
61566
|
});
|
|
@@ -61590,11 +61580,11 @@ var init_sse_handler = __esm({
|
|
|
61590
61580
|
try {
|
|
61591
61581
|
await this.options.persistAssistantMessage(this.sessionId, this.options.agentId, errReply, 0, errMeta);
|
|
61592
61582
|
} catch (e) {
|
|
61593
|
-
|
|
61583
|
+
log52.error("Failed to persist error message", { agentId: this.options.agentId, error: String(e) });
|
|
61594
61584
|
}
|
|
61595
61585
|
}
|
|
61596
61586
|
if (this.options.onError) {
|
|
61597
|
-
void this.options.onError(error, this.msgSegments).catch((e) =>
|
|
61587
|
+
void this.options.onError(error, this.msgSegments).catch((e) => log52.warn("onError callback failed", { error: String(e) }));
|
|
61598
61588
|
}
|
|
61599
61589
|
} finally {
|
|
61600
61590
|
this.isProcessing = false;
|
|
@@ -61621,7 +61611,7 @@ var init_sse_handler = __esm({
|
|
|
61621
61611
|
}
|
|
61622
61612
|
}
|
|
61623
61613
|
} catch (err) {
|
|
61624
|
-
|
|
61614
|
+
log52.warn("Failed to persist chat segments to execution stream", { messageId, error: String(err) });
|
|
61625
61615
|
}
|
|
61626
61616
|
}
|
|
61627
61617
|
/**
|
|
@@ -61725,7 +61715,7 @@ var init_sse_handler = __esm({
|
|
|
61725
61715
|
res.end();
|
|
61726
61716
|
}
|
|
61727
61717
|
} catch (e) {
|
|
61728
|
-
|
|
61718
|
+
log52.error("Error handling SSE error", { error: String(e) });
|
|
61729
61719
|
}
|
|
61730
61720
|
}
|
|
61731
61721
|
/**
|
|
@@ -61919,7 +61909,7 @@ async function installSkill(request, skillRegistry) {
|
|
|
61919
61909
|
installed = true;
|
|
61920
61910
|
installMethod = "clawhub-zip";
|
|
61921
61911
|
} catch {
|
|
61922
|
-
|
|
61912
|
+
log53.warn("unzip failed for skill", { skillName });
|
|
61923
61913
|
}
|
|
61924
61914
|
try {
|
|
61925
61915
|
execSync2(`rm -f "${tmpZip}"`);
|
|
@@ -61927,7 +61917,7 @@ async function installSkill(request, skillRegistry) {
|
|
|
61927
61917
|
}
|
|
61928
61918
|
}
|
|
61929
61919
|
} catch (err) {
|
|
61930
|
-
|
|
61920
|
+
log53.warn(`ClawHub download failed for ${slug}`, { error: String(err) });
|
|
61931
61921
|
}
|
|
61932
61922
|
}
|
|
61933
61923
|
if (!installed && source === "skillssh" && githubRepo) {
|
|
@@ -61943,7 +61933,7 @@ async function installSkill(request, skillRegistry) {
|
|
|
61943
61933
|
installMethod = "github-skillmd";
|
|
61944
61934
|
}
|
|
61945
61935
|
} catch (err) {
|
|
61946
|
-
|
|
61936
|
+
log53.warn(`GitHub SKILL.md download failed`, { error: String(err) });
|
|
61947
61937
|
}
|
|
61948
61938
|
if (!installed) {
|
|
61949
61939
|
try {
|
|
@@ -61975,7 +61965,7 @@ async function installSkill(request, skillRegistry) {
|
|
|
61975
61965
|
installed = true;
|
|
61976
61966
|
installMethod = "clawhub-zip-fallback";
|
|
61977
61967
|
} catch {
|
|
61978
|
-
|
|
61968
|
+
log53.warn("unzip failed (fallback)", { skillName });
|
|
61979
61969
|
}
|
|
61980
61970
|
try {
|
|
61981
61971
|
execSync2(`rm -f "${tmpZip}"`);
|
|
@@ -61983,7 +61973,7 @@ async function installSkill(request, skillRegistry) {
|
|
|
61983
61973
|
}
|
|
61984
61974
|
}
|
|
61985
61975
|
} catch {
|
|
61986
|
-
|
|
61976
|
+
log53.warn(`ClawHub fallback failed for ${trySlug}`);
|
|
61987
61977
|
}
|
|
61988
61978
|
}
|
|
61989
61979
|
if (!installed) {
|
|
@@ -62019,18 +62009,18 @@ async function installSkill(request, skillRegistry) {
|
|
|
62019
62009
|
skillRegistry.register({ manifest: discovered.manifest });
|
|
62020
62010
|
}
|
|
62021
62011
|
} catch (regErr) {
|
|
62022
|
-
|
|
62012
|
+
log53.warn("Failed to register installed skill into runtime registry", { error: String(regErr) });
|
|
62023
62013
|
}
|
|
62024
62014
|
}
|
|
62025
62015
|
return { installed: true, name: skillName, path: targetDir, method: installMethod };
|
|
62026
62016
|
}
|
|
62027
|
-
var
|
|
62017
|
+
var log53, cache, CACHE_TTL_MS, SKILLHUB_CACHE_TTL_MS;
|
|
62028
62018
|
var init_skill_service = __esm({
|
|
62029
62019
|
"../org-manager/dist/skill-service.js"() {
|
|
62030
62020
|
"use strict";
|
|
62031
62021
|
init_dist();
|
|
62032
62022
|
init_dist4();
|
|
62033
|
-
|
|
62023
|
+
log53 = createLogger("skill-service");
|
|
62034
62024
|
cache = /* @__PURE__ */ new Map();
|
|
62035
62025
|
CACHE_TTL_MS = 6e5;
|
|
62036
62026
|
SKILLHUB_CACHE_TTL_MS = 36e5;
|
|
@@ -62118,7 +62108,7 @@ function parseCookies(cookieHeader) {
|
|
|
62118
62108
|
}
|
|
62119
62109
|
return result;
|
|
62120
62110
|
}
|
|
62121
|
-
var
|
|
62111
|
+
var log54, PBKDF2_ITERATIONS, APIServer;
|
|
62122
62112
|
var init_api_server = __esm({
|
|
62123
62113
|
"../org-manager/dist/api-server.js"() {
|
|
62124
62114
|
"use strict";
|
|
@@ -62128,7 +62118,7 @@ var init_api_server = __esm({
|
|
|
62128
62118
|
init_ws_server();
|
|
62129
62119
|
init_sse_handler();
|
|
62130
62120
|
init_skill_service();
|
|
62131
|
-
|
|
62121
|
+
log54 = createLogger("api-server");
|
|
62132
62122
|
PBKDF2_ITERATIONS = 1e4;
|
|
62133
62123
|
APIServer = class {
|
|
62134
62124
|
orgService;
|
|
@@ -62477,7 +62467,7 @@ var init_api_server = __esm({
|
|
|
62477
62467
|
role: "owner",
|
|
62478
62468
|
passwordHash: hash
|
|
62479
62469
|
});
|
|
62480
|
-
|
|
62470
|
+
log54.info("Created default admin user (admin@markus.local)");
|
|
62481
62471
|
}
|
|
62482
62472
|
get jwtSecret() {
|
|
62483
62473
|
return process.env["JWT_SECRET"] ?? "markus-dev-secret-change-in-prod";
|
|
@@ -62522,7 +62512,7 @@ var init_api_server = __esm({
|
|
|
62522
62512
|
await this.storage.chatSessionRepo.appendMessage(session.id, agentId2, "assistant", reply, tokensUsed, metadata);
|
|
62523
62513
|
await this.storage.chatSessionRepo.updateLastMessage(session.id, title);
|
|
62524
62514
|
} catch (err) {
|
|
62525
|
-
|
|
62515
|
+
log54.warn("Failed to persist chat turn", { error: String(err) });
|
|
62526
62516
|
}
|
|
62527
62517
|
}
|
|
62528
62518
|
/**
|
|
@@ -62590,7 +62580,7 @@ var init_api_server = __esm({
|
|
|
62590
62580
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
62591
62581
|
});
|
|
62592
62582
|
} catch (err) {
|
|
62593
|
-
|
|
62583
|
+
log54.warn("Group chat agent reply failed", { agentId: agentId2, error: String(err) });
|
|
62594
62584
|
if (this.storage) {
|
|
62595
62585
|
try {
|
|
62596
62586
|
const errDetail = String(err).slice(0, 500);
|
|
@@ -62628,7 +62618,7 @@ var init_api_server = __esm({
|
|
|
62628
62618
|
await this.storage.chatSessionRepo.updateLastMessage(session.id, title);
|
|
62629
62619
|
return session.id;
|
|
62630
62620
|
} catch (err) {
|
|
62631
|
-
|
|
62621
|
+
log54.warn("Failed to persist user message", { error: String(err) });
|
|
62632
62622
|
return null;
|
|
62633
62623
|
}
|
|
62634
62624
|
}
|
|
@@ -62640,14 +62630,14 @@ var init_api_server = __esm({
|
|
|
62640
62630
|
await this.storage.chatSessionRepo.appendMessage(sessionId, agentId2, "assistant", reply, tokensUsed, metadata);
|
|
62641
62631
|
await this.storage.chatSessionRepo.updateLastMessage(sessionId);
|
|
62642
62632
|
} catch (err) {
|
|
62643
|
-
|
|
62633
|
+
log54.warn("Failed to persist assistant message", { error: String(err) });
|
|
62644
62634
|
}
|
|
62645
62635
|
}
|
|
62646
62636
|
start() {
|
|
62647
62637
|
this.server = createServer2((req, res) => this.handleRequest(req, res));
|
|
62648
62638
|
this.ws.attach(this.server);
|
|
62649
62639
|
this.server.listen(this.port, "0.0.0.0", () => {
|
|
62650
|
-
|
|
62640
|
+
log54.info(`API server listening on 0.0.0.0:${this.port} (HTTP + WebSocket)`);
|
|
62651
62641
|
});
|
|
62652
62642
|
}
|
|
62653
62643
|
stop() {
|
|
@@ -62668,7 +62658,7 @@ var init_api_server = __esm({
|
|
|
62668
62658
|
const url = new URL(req.url ?? "/", `http://localhost:${this.port}`);
|
|
62669
62659
|
const path = url.pathname;
|
|
62670
62660
|
this.route(req, res, path, url).catch((error) => {
|
|
62671
|
-
|
|
62661
|
+
log54.error("Request handler error", { error: String(error), path });
|
|
62672
62662
|
if (res.headersSent) {
|
|
62673
62663
|
try {
|
|
62674
62664
|
res.write(`data: ${JSON.stringify({ type: "error", message: String(error) })}
|
|
@@ -62928,7 +62918,7 @@ var init_api_server = __esm({
|
|
|
62928
62918
|
mentions: []
|
|
62929
62919
|
});
|
|
62930
62920
|
} catch (e) {
|
|
62931
|
-
|
|
62921
|
+
log54.warn("Failed to persist channel error message", { error: String(e) });
|
|
62932
62922
|
}
|
|
62933
62923
|
}
|
|
62934
62924
|
const statusCode = raw.includes("402") ? 402 : raw.includes("401") ? 401 : raw.includes("429") ? 429 : 502;
|
|
@@ -63070,7 +63060,7 @@ var init_api_server = __esm({
|
|
|
63070
63060
|
const histResult = await this.storage.chatSessionRepo.getMessages(sessionId, 200);
|
|
63071
63061
|
agent.restoreSessionFromHistory(sessionId, histResult.messages.map((m) => ({ role: m.role, content: m.content })));
|
|
63072
63062
|
} catch (err) {
|
|
63073
|
-
|
|
63063
|
+
log54.warn("Failed to restore session history, starting fresh", { sessionId, error: String(err) });
|
|
63074
63064
|
agent.startNewSession();
|
|
63075
63065
|
}
|
|
63076
63066
|
}
|
|
@@ -63776,6 +63766,15 @@ var init_api_server = __esm({
|
|
|
63776
63766
|
if (path.match(/^\/api\/tasks\/[^/]+\/run$/) && req.method === "POST") {
|
|
63777
63767
|
const taskId2 = path.split("/")[3];
|
|
63778
63768
|
try {
|
|
63769
|
+
const task = this.taskService.getTask(taskId2);
|
|
63770
|
+
if (!task) {
|
|
63771
|
+
this.json(res, 404, { error: "Task not found" });
|
|
63772
|
+
return;
|
|
63773
|
+
}
|
|
63774
|
+
if (task.status !== "in_progress") {
|
|
63775
|
+
this.json(res, 400, { error: `Cannot run task in ${task.status} status \u2014 must be in_progress` });
|
|
63776
|
+
return;
|
|
63777
|
+
}
|
|
63779
63778
|
await this.taskService.runTask(taskId2);
|
|
63780
63779
|
this.json(res, 202, { status: "running", taskId: taskId2 });
|
|
63781
63780
|
} catch (err) {
|
|
@@ -63966,7 +63965,16 @@ var init_api_server = __esm({
|
|
|
63966
63965
|
if (path.match(/^\/api\/tasks\/[^/]+\/resume$/) && req.method === "POST") {
|
|
63967
63966
|
const taskId2 = path.split("/")[3];
|
|
63968
63967
|
try {
|
|
63969
|
-
|
|
63968
|
+
const task = this.taskService.getTask(taskId2);
|
|
63969
|
+
if (!task) {
|
|
63970
|
+
this.json(res, 404, { error: "Task not found" });
|
|
63971
|
+
return;
|
|
63972
|
+
}
|
|
63973
|
+
if (task.status !== "blocked") {
|
|
63974
|
+
this.json(res, 400, { error: `Cannot resume task in ${task.status} status` });
|
|
63975
|
+
return;
|
|
63976
|
+
}
|
|
63977
|
+
this.taskService.updateTaskStatus(taskId2, "in_progress");
|
|
63970
63978
|
this.json(res, 202, { status: "running", taskId: taskId2 });
|
|
63971
63979
|
} catch (err) {
|
|
63972
63980
|
this.json(res, 400, { error: String(err) });
|
|
@@ -64189,7 +64197,7 @@ var init_api_server = __esm({
|
|
|
64189
64197
|
heartbeatIntervalMs: body["heartbeatIntervalMs"]
|
|
64190
64198
|
});
|
|
64191
64199
|
} catch (persistErr) {
|
|
64192
|
-
|
|
64200
|
+
log54.warn("Failed to persist agent config to DB", { agentId: agentId2, error: String(persistErr) });
|
|
64193
64201
|
}
|
|
64194
64202
|
}
|
|
64195
64203
|
this.json(res, 200, { ok: true, config: agent.config });
|
|
@@ -64418,7 +64426,7 @@ var init_api_server = __esm({
|
|
|
64418
64426
|
try {
|
|
64419
64427
|
await this.storage.agentRepo.updateConfig(agentId2, { skills: agent.config.skills });
|
|
64420
64428
|
} catch (e) {
|
|
64421
|
-
|
|
64429
|
+
log54.warn("Failed to persist skill assignment", { agentId: agentId2, error: String(e) });
|
|
64422
64430
|
}
|
|
64423
64431
|
}
|
|
64424
64432
|
this.json(res, 200, { ok: true, skills: agent.getActiveSkillNames() });
|
|
@@ -64439,7 +64447,7 @@ var init_api_server = __esm({
|
|
|
64439
64447
|
try {
|
|
64440
64448
|
await this.storage.agentRepo.updateConfig(agentId2, { skills: agent.config.skills });
|
|
64441
64449
|
} catch (e) {
|
|
64442
|
-
|
|
64450
|
+
log54.warn("Failed to persist skill removal", { agentId: agentId2, error: String(e) });
|
|
64443
64451
|
}
|
|
64444
64452
|
}
|
|
64445
64453
|
this.json(res, 200, { ok: true, skills: agent.getActiveSkillNames() });
|
|
@@ -65444,7 +65452,7 @@ var init_api_server = __esm({
|
|
|
65444
65452
|
try {
|
|
65445
65453
|
await this.storage.agentRepo.updateConfig(agentInfo.id, { skills: agent.config.skills });
|
|
65446
65454
|
} catch (e) {
|
|
65447
|
-
|
|
65455
|
+
log54.warn("Failed to persist skill removal from agent after uninstall", { agentId: agentInfo.id, error: String(e) });
|
|
65448
65456
|
}
|
|
65449
65457
|
}
|
|
65450
65458
|
}
|
|
@@ -65647,7 +65655,7 @@ var init_api_server = __esm({
|
|
|
65647
65655
|
artifactType: mode,
|
|
65648
65656
|
artifactData: artifact,
|
|
65649
65657
|
tags: ["builder", mode]
|
|
65650
|
-
}).catch((err) =>
|
|
65658
|
+
}).catch((err) => log54.warn("Failed to create deliverable for builder artifact", { error: String(err) }));
|
|
65651
65659
|
}
|
|
65652
65660
|
this.json(res, 201, { type: mode, name: manifest.name, path: artDir });
|
|
65653
65661
|
} catch (err) {
|
|
@@ -66049,7 +66057,7 @@ var init_api_server = __esm({
|
|
|
66049
66057
|
heartbeatIntervalMs: agent.config.heartbeatIntervalMs
|
|
66050
66058
|
});
|
|
66051
66059
|
} catch (persistErr) {
|
|
66052
|
-
|
|
66060
|
+
log54.warn("Failed to persist instantiated agent to DB", { error: String(persistErr) });
|
|
66053
66061
|
}
|
|
66054
66062
|
}
|
|
66055
66063
|
await agentManager.startAgent(agent.id);
|
|
@@ -66464,9 +66472,9 @@ var init_api_server = __esm({
|
|
|
66464
66472
|
} else if (existsSync26(tokenPath)) {
|
|
66465
66473
|
rmSync3(tokenPath);
|
|
66466
66474
|
}
|
|
66467
|
-
|
|
66475
|
+
log54.info(`Hub token ${token ? "saved to" : "cleared from"} ${tokenPath}`);
|
|
66468
66476
|
} catch (err) {
|
|
66469
|
-
|
|
66477
|
+
log54.error("Failed to write hub token file", { error: String(err) });
|
|
66470
66478
|
}
|
|
66471
66479
|
this.json(res, 200, { ok: true });
|
|
66472
66480
|
return;
|
|
@@ -66498,7 +66506,7 @@ var init_api_server = __esm({
|
|
|
66498
66506
|
try {
|
|
66499
66507
|
saveConfig({ llm: { defaultProvider } }, this.markusConfigPath);
|
|
66500
66508
|
} catch (e) {
|
|
66501
|
-
|
|
66509
|
+
log54.warn("Failed to persist defaultProvider to config file", { error: String(e) });
|
|
66502
66510
|
}
|
|
66503
66511
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66504
66512
|
} catch (err) {
|
|
@@ -66526,7 +66534,7 @@ var init_api_server = __esm({
|
|
|
66526
66534
|
try {
|
|
66527
66535
|
saveConfig({ agent: { maxToolIterations: am.maxToolIterations } }, this.markusConfigPath);
|
|
66528
66536
|
} catch (e) {
|
|
66529
|
-
|
|
66537
|
+
log54.warn("Failed to persist agent settings to config file", { error: String(e) });
|
|
66530
66538
|
}
|
|
66531
66539
|
for (const info4 of am.listAgents()) {
|
|
66532
66540
|
const agent = am.getAgent(info4.id);
|
|
@@ -66615,7 +66623,7 @@ var init_api_server = __esm({
|
|
|
66615
66623
|
};
|
|
66616
66624
|
saveConfig({ llm: { providers } }, this.markusConfigPath);
|
|
66617
66625
|
} catch (e) {
|
|
66618
|
-
|
|
66626
|
+
log54.warn("Failed to persist new provider", { error: String(e) });
|
|
66619
66627
|
}
|
|
66620
66628
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66621
66629
|
} catch (err) {
|
|
@@ -66677,7 +66685,7 @@ var init_api_server = __esm({
|
|
|
66677
66685
|
};
|
|
66678
66686
|
saveConfig({ llm: { providers } }, this.markusConfigPath);
|
|
66679
66687
|
} catch (e) {
|
|
66680
|
-
|
|
66688
|
+
log54.warn("Failed to persist provider update", { error: String(e) });
|
|
66681
66689
|
}
|
|
66682
66690
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66683
66691
|
} catch (err) {
|
|
@@ -66708,7 +66716,7 @@ var init_api_server = __esm({
|
|
|
66708
66716
|
}
|
|
66709
66717
|
saveConfig(configUpdates, this.markusConfigPath);
|
|
66710
66718
|
} catch (e) {
|
|
66711
|
-
|
|
66719
|
+
log54.warn("Failed to persist provider deletion", { error: String(e) });
|
|
66712
66720
|
}
|
|
66713
66721
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66714
66722
|
} catch (err) {
|
|
@@ -66751,7 +66759,7 @@ var init_api_server = __esm({
|
|
|
66751
66759
|
customModels[providerName] = [...existing.filter((m) => m.id !== id), modelDef];
|
|
66752
66760
|
saveConfig({ llm: { customModels } }, this.markusConfigPath);
|
|
66753
66761
|
} catch (e) {
|
|
66754
|
-
|
|
66762
|
+
log54.warn("Failed to persist custom model", { error: String(e) });
|
|
66755
66763
|
}
|
|
66756
66764
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66757
66765
|
} catch (err) {
|
|
@@ -66783,7 +66791,7 @@ var init_api_server = __esm({
|
|
|
66783
66791
|
}
|
|
66784
66792
|
saveConfig({ llm: { customModels } }, this.markusConfigPath);
|
|
66785
66793
|
} catch (e) {
|
|
66786
|
-
|
|
66794
|
+
log54.warn("Failed to persist custom model removal", { error: String(e) });
|
|
66787
66795
|
}
|
|
66788
66796
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66789
66797
|
} catch (err) {
|
|
@@ -66815,7 +66823,7 @@ var init_api_server = __esm({
|
|
|
66815
66823
|
providers[providerName] = { ...providers[providerName], model };
|
|
66816
66824
|
saveConfig({ llm: { providers } }, this.markusConfigPath);
|
|
66817
66825
|
} catch (e) {
|
|
66818
|
-
|
|
66826
|
+
log54.warn("Failed to persist provider model change", { error: String(e) });
|
|
66819
66827
|
}
|
|
66820
66828
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66821
66829
|
} catch (err) {
|
|
@@ -66851,7 +66859,7 @@ var init_api_server = __esm({
|
|
|
66851
66859
|
}
|
|
66852
66860
|
saveConfig({ llm: { providers } }, this.markusConfigPath);
|
|
66853
66861
|
} catch (e) {
|
|
66854
|
-
|
|
66862
|
+
log54.warn("Failed to persist provider enabled state", { error: String(e) });
|
|
66855
66863
|
}
|
|
66856
66864
|
this.json(res, 200, this.llmRouter.getEnhancedSettings());
|
|
66857
66865
|
} catch (err) {
|
|
@@ -66951,7 +66959,7 @@ var init_api_server = __esm({
|
|
|
66951
66959
|
baseUrl: cfg.baseUrl
|
|
66952
66960
|
});
|
|
66953
66961
|
} catch (e) {
|
|
66954
|
-
|
|
66962
|
+
log54.warn(`Failed to hot-register provider ${provName}`, { error: String(e) });
|
|
66955
66963
|
}
|
|
66956
66964
|
}
|
|
66957
66965
|
}
|
|
@@ -67010,18 +67018,18 @@ var init_api_server = __esm({
|
|
|
67010
67018
|
try {
|
|
67011
67019
|
const { authorizeUrl, promise } = await this.llmRouter.oauthManager.startLogin(provider);
|
|
67012
67020
|
promise.then((profile) => {
|
|
67013
|
-
|
|
67021
|
+
log54.info(`OAuth login completed for ${provider}`, { profileId: profile.id });
|
|
67014
67022
|
if (this.llmRouter && !this.llmRouter.getProvider(provider)) {
|
|
67015
67023
|
try {
|
|
67016
67024
|
this.llmRouter.registerOAuthProvider(provider, profile, {
|
|
67017
67025
|
model: provider === "openai-codex" ? "gpt-5.4" : void 0
|
|
67018
67026
|
});
|
|
67019
67027
|
} catch (err) {
|
|
67020
|
-
|
|
67028
|
+
log54.warn(`Failed to auto-register OAuth provider after login`, { error: String(err) });
|
|
67021
67029
|
}
|
|
67022
67030
|
}
|
|
67023
67031
|
}).catch((err) => {
|
|
67024
|
-
|
|
67032
|
+
log54.warn(`OAuth login failed for ${provider}`, { error: String(err) });
|
|
67025
67033
|
});
|
|
67026
67034
|
this.json(res, 200, { authorizeUrl, provider });
|
|
67027
67035
|
} catch (err) {
|
|
@@ -67607,7 +67615,7 @@ var init_api_server = __esm({
|
|
|
67607
67615
|
}
|
|
67608
67616
|
exec2(cmd, (err) => {
|
|
67609
67617
|
if (err) {
|
|
67610
|
-
|
|
67618
|
+
log54.warn("Failed to reveal file in system browser", { path: resolved, error: String(err) });
|
|
67611
67619
|
}
|
|
67612
67620
|
});
|
|
67613
67621
|
this.json(res, 200, { ok: true, path: resolved });
|
|
@@ -68048,12 +68056,17 @@ var init_api_server = __esm({
|
|
|
68048
68056
|
this.json(res, 400, { error: "Task is awaiting approval" });
|
|
68049
68057
|
return;
|
|
68050
68058
|
}
|
|
68059
|
+
if (["rejected", "archived"].includes(task.status)) {
|
|
68060
|
+
this.json(res, 400, { error: `Cannot run task in ${task.status} status` });
|
|
68061
|
+
return;
|
|
68062
|
+
}
|
|
68051
68063
|
await this.taskService.advanceScheduleConfig(taskId2);
|
|
68052
68064
|
const resettable = ["completed", "cancelled", "failed"];
|
|
68053
68065
|
if (resettable.includes(task.status)) {
|
|
68054
68066
|
await this.taskService.resetTaskForRerun(taskId2);
|
|
68067
|
+
} else {
|
|
68068
|
+
await this.taskService.runTask(taskId2);
|
|
68055
68069
|
}
|
|
68056
|
-
await this.taskService.runTask(taskId2);
|
|
68057
68070
|
this.json(res, 202, { status: "running", taskId: taskId2 });
|
|
68058
68071
|
} catch (err) {
|
|
68059
68072
|
this.json(res, 400, { error: String(err) });
|
|
@@ -68620,12 +68633,12 @@ var init_api_server = __esm({
|
|
|
68620
68633
|
function genId(prefix) {
|
|
68621
68634
|
return `${prefix}_${Date.now().toString(36)}_${(++idCounter).toString(36)}`;
|
|
68622
68635
|
}
|
|
68623
|
-
var
|
|
68636
|
+
var log55, idCounter, HITLService;
|
|
68624
68637
|
var init_hitl_service = __esm({
|
|
68625
68638
|
"../org-manager/dist/hitl-service.js"() {
|
|
68626
68639
|
"use strict";
|
|
68627
68640
|
init_dist();
|
|
68628
|
-
|
|
68641
|
+
log55 = createLogger("hitl");
|
|
68629
68642
|
idCounter = 0;
|
|
68630
68643
|
HITLService = class {
|
|
68631
68644
|
approvals = /* @__PURE__ */ new Map();
|
|
@@ -68668,7 +68681,7 @@ var init_hitl_service = __esm({
|
|
|
68668
68681
|
expiresAt: opts.expiresInMs ? new Date(Date.now() + opts.expiresInMs).toISOString() : void 0
|
|
68669
68682
|
};
|
|
68670
68683
|
this.approvals.set(id, approval);
|
|
68671
|
-
|
|
68684
|
+
log55.info(`Approval requested: ${id} by ${opts.agentName}`);
|
|
68672
68685
|
this.notify({
|
|
68673
68686
|
targetUserId: opts.targetUserId ?? "default",
|
|
68674
68687
|
type: "approval_request",
|
|
@@ -68704,7 +68717,7 @@ var init_hitl_service = __esm({
|
|
|
68704
68717
|
approval.respondedBy = respondedBy;
|
|
68705
68718
|
if (comment)
|
|
68706
68719
|
approval.responseComment = comment;
|
|
68707
|
-
|
|
68720
|
+
log55.info(`Approval ${id} ${approval.status} by ${respondedBy}`, comment ? { comment } : {});
|
|
68708
68721
|
if (this.notificationRepo) {
|
|
68709
68722
|
try {
|
|
68710
68723
|
const rows = this.notificationRepo.list(approval.agentId, { type: "approval_request", limit: 100 });
|
|
@@ -68745,7 +68758,7 @@ var init_hitl_service = __esm({
|
|
|
68745
68758
|
createdAt: now2
|
|
68746
68759
|
};
|
|
68747
68760
|
this.bounties.set(id, bounty);
|
|
68748
|
-
|
|
68761
|
+
log55.info(`Bounty posted: ${id} by ${opts.agentName}`);
|
|
68749
68762
|
this.notify({
|
|
68750
68763
|
targetUserId: "all",
|
|
68751
68764
|
type: "bounty_posted",
|
|
@@ -68761,7 +68774,7 @@ var init_hitl_service = __esm({
|
|
|
68761
68774
|
return void 0;
|
|
68762
68775
|
bounty.status = "claimed";
|
|
68763
68776
|
bounty.claimedBy = userId;
|
|
68764
|
-
|
|
68777
|
+
log55.info(`Bounty ${id} claimed by ${userId}`);
|
|
68765
68778
|
return bounty;
|
|
68766
68779
|
}
|
|
68767
68780
|
completeBounty(id, result) {
|
|
@@ -68771,7 +68784,7 @@ var init_hitl_service = __esm({
|
|
|
68771
68784
|
bounty.status = "completed";
|
|
68772
68785
|
bounty.completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
68773
68786
|
bounty.result = result;
|
|
68774
|
-
|
|
68787
|
+
log55.info(`Bounty ${id} completed`);
|
|
68775
68788
|
return bounty;
|
|
68776
68789
|
}
|
|
68777
68790
|
listBounties(status) {
|
|
@@ -68844,7 +68857,7 @@ var init_hitl_service = __esm({
|
|
|
68844
68857
|
createdAt: notification.createdAt
|
|
68845
68858
|
});
|
|
68846
68859
|
} catch (err) {
|
|
68847
|
-
|
|
68860
|
+
log55.warn("Failed to persist notification", { error: String(err) });
|
|
68848
68861
|
}
|
|
68849
68862
|
}
|
|
68850
68863
|
this.emit(notification);
|
|
@@ -68871,12 +68884,12 @@ var init_hitl_service = __esm({
|
|
|
68871
68884
|
|
|
68872
68885
|
// ../org-manager/dist/billing-service.js
|
|
68873
68886
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
68874
|
-
var
|
|
68887
|
+
var log56, DEFAULT_PLANS, keyCounter, BillingService;
|
|
68875
68888
|
var init_billing_service = __esm({
|
|
68876
68889
|
"../org-manager/dist/billing-service.js"() {
|
|
68877
68890
|
"use strict";
|
|
68878
68891
|
init_dist();
|
|
68879
|
-
|
|
68892
|
+
log56 = createLogger("billing");
|
|
68880
68893
|
DEFAULT_PLANS = {
|
|
68881
68894
|
free: {
|
|
68882
68895
|
maxAgents: -1,
|
|
@@ -68913,7 +68926,7 @@ var init_billing_service = __esm({
|
|
|
68913
68926
|
limits: { ...DEFAULT_PLANS[tier] }
|
|
68914
68927
|
};
|
|
68915
68928
|
this.orgPlans.set(orgId2, plan);
|
|
68916
|
-
|
|
68929
|
+
log56.info(`Plan set for org ${orgId2}: ${tier}`);
|
|
68917
68930
|
return plan;
|
|
68918
68931
|
}
|
|
68919
68932
|
getOrgPlan(orgId2) {
|
|
@@ -69018,7 +69031,7 @@ var init_billing_service = __esm({
|
|
|
69018
69031
|
};
|
|
69019
69032
|
this.apiKeys.set(id, apiKey);
|
|
69020
69033
|
this.apiKeysByKey.set(key2, apiKey);
|
|
69021
|
-
|
|
69034
|
+
log56.info(`API key created: ${id} for org ${orgId2}`);
|
|
69022
69035
|
return apiKey;
|
|
69023
69036
|
}
|
|
69024
69037
|
validateAPIKey(key2) {
|
|
@@ -69035,7 +69048,7 @@ var init_billing_service = __esm({
|
|
|
69035
69048
|
if (!apiKey)
|
|
69036
69049
|
return false;
|
|
69037
69050
|
apiKey.active = false;
|
|
69038
|
-
|
|
69051
|
+
log56.info(`API key revoked: ${id}`);
|
|
69039
69052
|
return true;
|
|
69040
69053
|
}
|
|
69041
69054
|
listAPIKeys(orgId2) {
|
|
@@ -69111,12 +69124,12 @@ var init_billing_service = __esm({
|
|
|
69111
69124
|
});
|
|
69112
69125
|
|
|
69113
69126
|
// ../org-manager/dist/audit-service.js
|
|
69114
|
-
var
|
|
69127
|
+
var log57, entryCounter, AuditService;
|
|
69115
69128
|
var init_audit_service = __esm({
|
|
69116
69129
|
"../org-manager/dist/audit-service.js"() {
|
|
69117
69130
|
"use strict";
|
|
69118
69131
|
init_dist();
|
|
69119
|
-
|
|
69132
|
+
log57 = createLogger("audit");
|
|
69120
69133
|
entryCounter = 0;
|
|
69121
69134
|
AuditService = class {
|
|
69122
69135
|
entries = [];
|
|
@@ -69124,7 +69137,7 @@ var init_audit_service = __esm({
|
|
|
69124
69137
|
db;
|
|
69125
69138
|
setRepository(db) {
|
|
69126
69139
|
this.db = db;
|
|
69127
|
-
|
|
69140
|
+
log57.info("Audit persistence enabled \u2014 events will be written to DB");
|
|
69128
69141
|
}
|
|
69129
69142
|
record(entry) {
|
|
69130
69143
|
const full = {
|
|
@@ -69150,7 +69163,7 @@ var init_audit_service = __esm({
|
|
|
69150
69163
|
durationMs: full.durationMs,
|
|
69151
69164
|
success: full.success,
|
|
69152
69165
|
createdAt: new Date(full.timestamp)
|
|
69153
|
-
}).catch((err) =>
|
|
69166
|
+
}).catch((err) => log57.warn("Failed to persist audit entry", { id: full.id, error: String(err) }));
|
|
69154
69167
|
}
|
|
69155
69168
|
return full;
|
|
69156
69169
|
}
|
|
@@ -69233,12 +69246,12 @@ var init_audit_service = __esm({
|
|
|
69233
69246
|
});
|
|
69234
69247
|
|
|
69235
69248
|
// ../org-manager/dist/project-service.js
|
|
69236
|
-
var
|
|
69249
|
+
var log58, ProjectService;
|
|
69237
69250
|
var init_project_service = __esm({
|
|
69238
69251
|
"../org-manager/dist/project-service.js"() {
|
|
69239
69252
|
"use strict";
|
|
69240
69253
|
init_dist();
|
|
69241
|
-
|
|
69254
|
+
log58 = createLogger("project-service");
|
|
69242
69255
|
ProjectService = class {
|
|
69243
69256
|
projects = /* @__PURE__ */ new Map();
|
|
69244
69257
|
projectRepo;
|
|
@@ -69267,9 +69280,9 @@ var init_project_service = __esm({
|
|
|
69267
69280
|
};
|
|
69268
69281
|
this.projects.set(project.id, project);
|
|
69269
69282
|
}
|
|
69270
|
-
|
|
69283
|
+
log58.info(`Loaded ${this.projects.size} projects from DB`);
|
|
69271
69284
|
} catch (err) {
|
|
69272
|
-
|
|
69285
|
+
log58.warn("Failed to load projects from DB", { error: String(err) });
|
|
69273
69286
|
}
|
|
69274
69287
|
}
|
|
69275
69288
|
}
|
|
@@ -69304,8 +69317,8 @@ var init_project_service = __esm({
|
|
|
69304
69317
|
archivePolicy: project.archivePolicy,
|
|
69305
69318
|
reportSchedule: project.reportSchedule,
|
|
69306
69319
|
onboardingConfig: project.onboardingConfig
|
|
69307
|
-
}).catch((err) =>
|
|
69308
|
-
|
|
69320
|
+
}).catch((err) => log58.warn("Failed to persist project", { error: String(err) }));
|
|
69321
|
+
log58.info("Project created", { id: project.id, name: project.name });
|
|
69309
69322
|
return project;
|
|
69310
69323
|
}
|
|
69311
69324
|
getProject(id) {
|
|
@@ -69320,14 +69333,14 @@ var init_project_service = __esm({
|
|
|
69320
69333
|
if (!project)
|
|
69321
69334
|
throw new Error(`Project not found: ${id}`);
|
|
69322
69335
|
Object.assign(project, updates, { updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
69323
|
-
this.projectRepo?.update(id, updates).catch((err) =>
|
|
69324
|
-
|
|
69336
|
+
this.projectRepo?.update(id, updates).catch((err) => log58.warn("Failed to persist project update", { error: String(err) }));
|
|
69337
|
+
log58.info("Project updated", { id });
|
|
69325
69338
|
return project;
|
|
69326
69339
|
}
|
|
69327
69340
|
deleteProject(id) {
|
|
69328
69341
|
this.projects.delete(id);
|
|
69329
|
-
this.projectRepo?.delete(id).catch((err) =>
|
|
69330
|
-
|
|
69342
|
+
this.projectRepo?.delete(id).catch((err) => log58.warn("Failed to delete project from DB", { error: String(err) }));
|
|
69343
|
+
log58.info("Project deleted", { id });
|
|
69331
69344
|
}
|
|
69332
69345
|
// ─── Agent Onboarding ──────────────────────────────────────────────────────
|
|
69333
69346
|
async onboardAgent(agentId2, projectId) {
|
|
@@ -69352,7 +69365,7 @@ var init_project_service = __esm({
|
|
|
69352
69365
|
parts.push(`- Max pending tasks per agent: ${project.governancePolicy.maxPendingTasksPerAgent}`);
|
|
69353
69366
|
}
|
|
69354
69367
|
const onboardingDoc = parts.join("\n");
|
|
69355
|
-
|
|
69368
|
+
log58.info("Agent onboarded to project", { agentId: agentId2, projectId });
|
|
69356
69369
|
return onboardingDoc;
|
|
69357
69370
|
}
|
|
69358
69371
|
};
|
|
@@ -69360,12 +69373,12 @@ var init_project_service = __esm({
|
|
|
69360
69373
|
});
|
|
69361
69374
|
|
|
69362
69375
|
// ../org-manager/dist/requirement-service.js
|
|
69363
|
-
var
|
|
69376
|
+
var log59, RequirementService;
|
|
69364
69377
|
var init_requirement_service = __esm({
|
|
69365
69378
|
"../org-manager/dist/requirement-service.js"() {
|
|
69366
69379
|
"use strict";
|
|
69367
69380
|
init_dist();
|
|
69368
|
-
|
|
69381
|
+
log59 = createLogger("requirement-service");
|
|
69369
69382
|
RequirementService = class _RequirementService {
|
|
69370
69383
|
requirements = /* @__PURE__ */ new Map();
|
|
69371
69384
|
requirementRepo;
|
|
@@ -69449,7 +69462,7 @@ var init_requirement_service = __esm({
|
|
|
69449
69462
|
approvedBy: req.approvedBy ?? void 0,
|
|
69450
69463
|
approvedAt: req.approvedAt ? new Date(req.approvedAt) : void 0,
|
|
69451
69464
|
tags: req.tags
|
|
69452
|
-
}).catch((e) =>
|
|
69465
|
+
}).catch((e) => log59.error("Failed to persist requirement", { id: req.id, error: String(e) }));
|
|
69453
69466
|
}
|
|
69454
69467
|
this.broadcast("requirement:created", req);
|
|
69455
69468
|
if (this.hitlService && req.source === "agent") {
|
|
@@ -69464,7 +69477,7 @@ var init_requirement_service = __esm({
|
|
|
69464
69477
|
metadata: { requirementId: req.id, createdBy: req.createdBy }
|
|
69465
69478
|
});
|
|
69466
69479
|
}
|
|
69467
|
-
|
|
69480
|
+
log59.info("Requirement created", {
|
|
69468
69481
|
id: req.id,
|
|
69469
69482
|
source: req.source,
|
|
69470
69483
|
status: req.status,
|
|
@@ -69500,10 +69513,10 @@ var init_requirement_service = __esm({
|
|
|
69500
69513
|
req.approvedAt = now2;
|
|
69501
69514
|
req.updatedAt = now2;
|
|
69502
69515
|
if (this.requirementRepo) {
|
|
69503
|
-
this.requirementRepo.approve(id, userId).catch((e) =>
|
|
69516
|
+
this.requirementRepo.approve(id, userId).catch((e) => log59.error("Failed to persist requirement approval", { id, error: String(e) }));
|
|
69504
69517
|
}
|
|
69505
69518
|
this.broadcast("requirement:approved", req);
|
|
69506
|
-
|
|
69519
|
+
log59.info("Requirement approved", { id, approvedBy: userId });
|
|
69507
69520
|
this.notifyCreatorOnDecision(req, "approved", userId);
|
|
69508
69521
|
return req;
|
|
69509
69522
|
}
|
|
@@ -69522,10 +69535,10 @@ var init_requirement_service = __esm({
|
|
|
69522
69535
|
req.rejectedReason = reason;
|
|
69523
69536
|
req.updatedAt = now2;
|
|
69524
69537
|
if (this.requirementRepo) {
|
|
69525
|
-
this.requirementRepo.reject(id, reason).catch((e) =>
|
|
69538
|
+
this.requirementRepo.reject(id, reason).catch((e) => log59.error("Failed to persist requirement rejection", { id, error: String(e) }));
|
|
69526
69539
|
}
|
|
69527
69540
|
this.broadcast("requirement:rejected", req);
|
|
69528
|
-
|
|
69541
|
+
log59.info("Requirement rejected", { id, reason });
|
|
69529
69542
|
this.notifyCreatorOnDecision(req, "rejected", userId, reason);
|
|
69530
69543
|
return req;
|
|
69531
69544
|
}
|
|
@@ -69555,14 +69568,14 @@ var init_requirement_service = __esm({
|
|
|
69555
69568
|
req.approvedAt = void 0;
|
|
69556
69569
|
req.updatedAt = now2;
|
|
69557
69570
|
if (this.requirementRepo) {
|
|
69558
|
-
const persistErr = (e) =>
|
|
69571
|
+
const persistErr = (e) => log59.error("Failed to persist requirement resubmission", { id, error: String(e) });
|
|
69559
69572
|
this.requirementRepo.updateStatus(id, "pending").catch(persistErr);
|
|
69560
69573
|
if (updates) {
|
|
69561
69574
|
this.requirementRepo.update(id, updates).catch(persistErr);
|
|
69562
69575
|
}
|
|
69563
69576
|
}
|
|
69564
69577
|
this.broadcast("requirement:resubmitted", req);
|
|
69565
|
-
|
|
69578
|
+
log59.info("Requirement resubmitted for review", { id, hasUpdates: !!updates });
|
|
69566
69579
|
return req;
|
|
69567
69580
|
}
|
|
69568
69581
|
/**
|
|
@@ -69593,7 +69606,7 @@ var init_requirement_service = __esm({
|
|
|
69593
69606
|
req.rejectedReason = void 0;
|
|
69594
69607
|
}
|
|
69595
69608
|
if (this.requirementRepo) {
|
|
69596
|
-
const persistErr = (e) =>
|
|
69609
|
+
const persistErr = (e) => log59.error("Failed to persist requirement status update", { id, error: String(e) });
|
|
69597
69610
|
if (newStatus === "in_progress" && oldStatus === "pending") {
|
|
69598
69611
|
this.requirementRepo.approve(id, req.approvedBy ?? "unknown").catch(persistErr);
|
|
69599
69612
|
} else if (newStatus === "rejected") {
|
|
@@ -69622,7 +69635,7 @@ var init_requirement_service = __esm({
|
|
|
69622
69635
|
}
|
|
69623
69636
|
}
|
|
69624
69637
|
this.broadcast("requirement:updated", req);
|
|
69625
|
-
|
|
69638
|
+
log59.info("Requirement status updated", { id, from: oldStatus, to: newStatus });
|
|
69626
69639
|
return req;
|
|
69627
69640
|
}
|
|
69628
69641
|
/**
|
|
@@ -69642,7 +69655,7 @@ var init_requirement_service = __esm({
|
|
|
69642
69655
|
req.tags = data.tags;
|
|
69643
69656
|
req.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
69644
69657
|
if (this.requirementRepo) {
|
|
69645
|
-
this.requirementRepo.update(id, data).catch((e) =>
|
|
69658
|
+
this.requirementRepo.update(id, data).catch((e) => log59.error("Failed to persist requirement update", { id, error: String(e) }));
|
|
69646
69659
|
}
|
|
69647
69660
|
this.broadcast("requirement:updated", req);
|
|
69648
69661
|
return req;
|
|
@@ -69686,10 +69699,10 @@ var init_requirement_service = __esm({
|
|
|
69686
69699
|
req.status = "completed";
|
|
69687
69700
|
req.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
69688
69701
|
if (this.requirementRepo) {
|
|
69689
|
-
this.requirementRepo.updateStatus(requirementId2, "completed").catch((e) =>
|
|
69702
|
+
this.requirementRepo.updateStatus(requirementId2, "completed").catch((e) => log59.error("Failed to persist requirement completion", { id: requirementId2, error: String(e) }));
|
|
69690
69703
|
}
|
|
69691
69704
|
this.broadcast("requirement:completed", req);
|
|
69692
|
-
|
|
69705
|
+
log59.info("Requirement completed", { id: requirementId2 });
|
|
69693
69706
|
return true;
|
|
69694
69707
|
}
|
|
69695
69708
|
return false;
|
|
@@ -69704,10 +69717,10 @@ var init_requirement_service = __esm({
|
|
|
69704
69717
|
req.status = "cancelled";
|
|
69705
69718
|
req.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
69706
69719
|
if (this.requirementRepo) {
|
|
69707
|
-
this.requirementRepo.updateStatus(id, "cancelled").catch((e) =>
|
|
69720
|
+
this.requirementRepo.updateStatus(id, "cancelled").catch((e) => log59.error("Failed to persist requirement cancellation", { id, error: String(e) }));
|
|
69708
69721
|
}
|
|
69709
69722
|
this.broadcast("requirement:cancelled", req);
|
|
69710
|
-
|
|
69723
|
+
log59.info("Requirement cancelled", { id });
|
|
69711
69724
|
return req;
|
|
69712
69725
|
}
|
|
69713
69726
|
getRequirement(id) {
|
|
@@ -69763,9 +69776,9 @@ var init_requirement_service = __esm({
|
|
|
69763
69776
|
};
|
|
69764
69777
|
this.requirements.set(req.id, req);
|
|
69765
69778
|
}
|
|
69766
|
-
|
|
69779
|
+
log59.info("Loaded requirements from storage", { orgId: orgId2, count: rows.length });
|
|
69767
69780
|
} catch (e) {
|
|
69768
|
-
|
|
69781
|
+
log59.error("Failed to load requirements from storage", { orgId: orgId2, error: String(e) });
|
|
69769
69782
|
}
|
|
69770
69783
|
}
|
|
69771
69784
|
/**
|
|
@@ -69787,13 +69800,13 @@ var init_requirement_service = __esm({
|
|
|
69787
69800
|
}
|
|
69788
69801
|
const linked = [...this.requirements.values()].filter((r) => r.taskIds.length > 0).length;
|
|
69789
69802
|
if (linked > 0) {
|
|
69790
|
-
|
|
69803
|
+
log59.info("Rebuilt requirement-task links", { linkedRequirements: linked });
|
|
69791
69804
|
}
|
|
69792
69805
|
}
|
|
69793
69806
|
deleteRequirement(id) {
|
|
69794
69807
|
this.requirements.delete(id);
|
|
69795
69808
|
if (this.requirementRepo) {
|
|
69796
|
-
this.requirementRepo.delete(id).catch((e) =>
|
|
69809
|
+
this.requirementRepo.delete(id).catch((e) => log59.error("Failed to delete requirement from storage", { id, error: String(e) }));
|
|
69797
69810
|
}
|
|
69798
69811
|
}
|
|
69799
69812
|
/**
|
|
@@ -69840,7 +69853,7 @@ var init_requirement_service = __esm({
|
|
|
69840
69853
|
}, {
|
|
69841
69854
|
metadata: { senderName: "System", senderRole: "manager" }
|
|
69842
69855
|
});
|
|
69843
|
-
|
|
69856
|
+
log59.info("Notified creator agent about requirement decision", {
|
|
69844
69857
|
requirementId: req.id,
|
|
69845
69858
|
creatorId,
|
|
69846
69859
|
decision
|
|
@@ -69874,12 +69887,12 @@ var init_requirement_service = __esm({
|
|
|
69874
69887
|
});
|
|
69875
69888
|
|
|
69876
69889
|
// ../org-manager/dist/knowledge-service.js
|
|
69877
|
-
var
|
|
69890
|
+
var log60, KnowledgeService;
|
|
69878
69891
|
var init_knowledge_service = __esm({
|
|
69879
69892
|
"../org-manager/dist/knowledge-service.js"() {
|
|
69880
69893
|
"use strict";
|
|
69881
69894
|
init_dist();
|
|
69882
|
-
|
|
69895
|
+
log60 = createLogger("knowledge-service");
|
|
69883
69896
|
KnowledgeService = class {
|
|
69884
69897
|
entries = /* @__PURE__ */ new Map();
|
|
69885
69898
|
fileStore;
|
|
@@ -69889,7 +69902,7 @@ var init_knowledge_service = __esm({
|
|
|
69889
69902
|
for (const entry of fileStore.loadAll()) {
|
|
69890
69903
|
this.entries.set(entry.id, entry);
|
|
69891
69904
|
}
|
|
69892
|
-
|
|
69905
|
+
log60.info("Knowledge loaded from file store", { count: this.entries.size });
|
|
69893
69906
|
}
|
|
69894
69907
|
}
|
|
69895
69908
|
/** Returns the absolute file path of a knowledge entry (for agent file_read). */
|
|
@@ -69934,7 +69947,7 @@ var init_knowledge_service = __esm({
|
|
|
69934
69947
|
}
|
|
69935
69948
|
}
|
|
69936
69949
|
this.persistScope(entry.scope, entry.scopeId);
|
|
69937
|
-
|
|
69950
|
+
log60.info("Knowledge contributed", {
|
|
69938
69951
|
id: entry.id,
|
|
69939
69952
|
scope: entry.scope,
|
|
69940
69953
|
category: entry.category,
|
|
@@ -70012,7 +70025,7 @@ var init_knowledge_service = __esm({
|
|
|
70012
70025
|
entry.status = "outdated";
|
|
70013
70026
|
entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
70014
70027
|
this.persistScope(entry.scope, entry.scopeId);
|
|
70015
|
-
|
|
70028
|
+
log60.info("Knowledge flagged as outdated", { id, reason });
|
|
70016
70029
|
}
|
|
70017
70030
|
flagDisputed(id, reason) {
|
|
70018
70031
|
const entry = this.entries.get(id);
|
|
@@ -70021,7 +70034,7 @@ var init_knowledge_service = __esm({
|
|
|
70021
70034
|
entry.status = "disputed";
|
|
70022
70035
|
entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
70023
70036
|
this.persistScope(entry.scope, entry.scopeId);
|
|
70024
|
-
|
|
70037
|
+
log60.info("Knowledge flagged as disputed", { id, reason });
|
|
70025
70038
|
}
|
|
70026
70039
|
verify(id, verifiedBy) {
|
|
70027
70040
|
const entry = this.entries.get(id);
|
|
@@ -70031,7 +70044,7 @@ var init_knowledge_service = __esm({
|
|
|
70031
70044
|
entry.verifiedBy = verifiedBy;
|
|
70032
70045
|
entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
70033
70046
|
this.persistScope(entry.scope, entry.scopeId);
|
|
70034
|
-
|
|
70047
|
+
log60.info("Knowledge verified", { id, verifiedBy });
|
|
70035
70048
|
}
|
|
70036
70049
|
// ─── Metrics ───────────────────────────────────────────────────────────────
|
|
70037
70050
|
getContributions(scopeId, periodStart, periodEnd) {
|
|
@@ -70064,12 +70077,12 @@ function readdirSafe(dir) {
|
|
|
70064
70077
|
return [];
|
|
70065
70078
|
}
|
|
70066
70079
|
}
|
|
70067
|
-
var
|
|
70080
|
+
var log61, FileKnowledgeStore;
|
|
70068
70081
|
var init_file_knowledge_store = __esm({
|
|
70069
70082
|
"../org-manager/dist/file-knowledge-store.js"() {
|
|
70070
70083
|
"use strict";
|
|
70071
70084
|
init_dist();
|
|
70072
|
-
|
|
70085
|
+
log61 = createLogger("file-knowledge-store");
|
|
70073
70086
|
FileKnowledgeStore = class {
|
|
70074
70087
|
baseDir;
|
|
70075
70088
|
constructor(baseDir) {
|
|
@@ -70100,11 +70113,11 @@ var init_file_knowledge_store = __esm({
|
|
|
70100
70113
|
const data = JSON.parse(readFileSync21(idxPath, "utf-8"));
|
|
70101
70114
|
entries2.push(...data);
|
|
70102
70115
|
} catch (err) {
|
|
70103
|
-
|
|
70116
|
+
log61.warn("Failed to load index", { path: idxPath, error: String(err) });
|
|
70104
70117
|
}
|
|
70105
70118
|
}
|
|
70106
70119
|
}
|
|
70107
|
-
|
|
70120
|
+
log61.info("Knowledge loaded from disk", { count: entries2.length });
|
|
70108
70121
|
return entries2;
|
|
70109
70122
|
}
|
|
70110
70123
|
// ─── Write ───────────────────────────────────────────────────────────────
|
|
@@ -70142,12 +70155,12 @@ var init_file_knowledge_store = __esm({
|
|
|
70142
70155
|
});
|
|
70143
70156
|
|
|
70144
70157
|
// ../org-manager/dist/deliverable-service.js
|
|
70145
|
-
var
|
|
70158
|
+
var log62, DeliverableService;
|
|
70146
70159
|
var init_deliverable_service = __esm({
|
|
70147
70160
|
"../org-manager/dist/deliverable-service.js"() {
|
|
70148
70161
|
"use strict";
|
|
70149
70162
|
init_dist();
|
|
70150
|
-
|
|
70163
|
+
log62 = createLogger("deliverable-service");
|
|
70151
70164
|
DeliverableService = class {
|
|
70152
70165
|
repo;
|
|
70153
70166
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -70165,7 +70178,7 @@ var init_deliverable_service = __esm({
|
|
|
70165
70178
|
for (const r of rows) {
|
|
70166
70179
|
this.cache.set(r.id, this.rowToDeliverable(r));
|
|
70167
70180
|
}
|
|
70168
|
-
|
|
70181
|
+
log62.info("Deliverables loaded", { count: this.cache.size });
|
|
70169
70182
|
}
|
|
70170
70183
|
async create(opts) {
|
|
70171
70184
|
const id = generateId("dlv");
|
|
@@ -70208,7 +70221,7 @@ var init_deliverable_service = __esm({
|
|
|
70208
70221
|
testResults: opts.testResults
|
|
70209
70222
|
});
|
|
70210
70223
|
this.cache.set(id, deliverable);
|
|
70211
|
-
|
|
70224
|
+
log62.info("Deliverable created", { id, type: opts.type, title: opts.title });
|
|
70212
70225
|
this.ws?.broadcastDeliverableUpdate(id, "created", {
|
|
70213
70226
|
type: opts.type,
|
|
70214
70227
|
title: opts.title,
|
|
@@ -70289,7 +70302,7 @@ var init_deliverable_service = __esm({
|
|
|
70289
70302
|
d.status = data.status;
|
|
70290
70303
|
d.updatedAt = now2;
|
|
70291
70304
|
await this.repo?.update(id, data);
|
|
70292
|
-
|
|
70305
|
+
log62.info("Deliverable updated", { id, fields: Object.keys(data) });
|
|
70293
70306
|
return d;
|
|
70294
70307
|
}
|
|
70295
70308
|
async flagOutdated(id) {
|
|
@@ -70299,7 +70312,7 @@ var init_deliverable_service = __esm({
|
|
|
70299
70312
|
d.status = "outdated";
|
|
70300
70313
|
d.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
70301
70314
|
await this.repo?.update(id, { status: "outdated" });
|
|
70302
|
-
|
|
70315
|
+
log62.info("Deliverable flagged outdated", { id });
|
|
70303
70316
|
}
|
|
70304
70317
|
async remove(id) {
|
|
70305
70318
|
await this.flagOutdated(id);
|
|
@@ -70339,7 +70352,7 @@ var init_deliverable_service = __esm({
|
|
|
70339
70352
|
}
|
|
70340
70353
|
}
|
|
70341
70354
|
if (branchCleaned > 0) {
|
|
70342
|
-
|
|
70355
|
+
log62.info("Cleaned up legacy branch-type deliverables", { count: branchCleaned });
|
|
70343
70356
|
}
|
|
70344
70357
|
const existingTaskIds = this.repo ? await this.repo.listTaskIdsWithDeliverables() : new Set([...this.cache.values()].map((d) => d.taskId).filter(Boolean));
|
|
70345
70358
|
let migrated = 0;
|
|
@@ -70366,12 +70379,12 @@ var init_deliverable_service = __esm({
|
|
|
70366
70379
|
});
|
|
70367
70380
|
migrated++;
|
|
70368
70381
|
} catch (err) {
|
|
70369
|
-
|
|
70382
|
+
log62.warn("Failed to migrate task deliverable", { taskId: task.id, ref: d.reference, error: String(err) });
|
|
70370
70383
|
}
|
|
70371
70384
|
}
|
|
70372
70385
|
}
|
|
70373
70386
|
if (migrated > 0) {
|
|
70374
|
-
|
|
70387
|
+
log62.info("Migrated task deliverables to unified table", { migrated });
|
|
70375
70388
|
}
|
|
70376
70389
|
return migrated;
|
|
70377
70390
|
}
|
|
@@ -70410,12 +70423,12 @@ var init_deliverable_service = __esm({
|
|
|
70410
70423
|
});
|
|
70411
70424
|
|
|
70412
70425
|
// ../org-manager/dist/report-service.js
|
|
70413
|
-
var
|
|
70426
|
+
var log63, ReportService;
|
|
70414
70427
|
var init_report_service = __esm({
|
|
70415
70428
|
"../org-manager/dist/report-service.js"() {
|
|
70416
70429
|
"use strict";
|
|
70417
70430
|
init_dist();
|
|
70418
|
-
|
|
70431
|
+
log63 = createLogger("report-service");
|
|
70419
70432
|
ReportService = class {
|
|
70420
70433
|
taskService;
|
|
70421
70434
|
billingService;
|
|
@@ -70468,7 +70481,7 @@ var init_report_service = __esm({
|
|
|
70468
70481
|
generatedBy: opts.generatedBy ?? "system"
|
|
70469
70482
|
};
|
|
70470
70483
|
this.reports.set(report.id, report);
|
|
70471
|
-
|
|
70484
|
+
log63.info("Report generated", { id: report.id, type: report.type, scope: report.scope });
|
|
70472
70485
|
return report;
|
|
70473
70486
|
}
|
|
70474
70487
|
getReport(id) {
|
|
@@ -70490,7 +70503,7 @@ var init_report_service = __esm({
|
|
|
70490
70503
|
if (!report?.upcomingPlan)
|
|
70491
70504
|
throw new Error("Report has no plan");
|
|
70492
70505
|
report.upcomingPlan.status = "pending";
|
|
70493
|
-
|
|
70506
|
+
log63.info("Plan submitted for approval", { reportId });
|
|
70494
70507
|
}
|
|
70495
70508
|
approvePlan(reportId, userId) {
|
|
70496
70509
|
const report = this.reports.get(reportId);
|
|
@@ -70517,7 +70530,7 @@ var init_report_service = __esm({
|
|
|
70517
70530
|
projectId: report.scope === "project" ? report.scopeId : void 0
|
|
70518
70531
|
});
|
|
70519
70532
|
}
|
|
70520
|
-
|
|
70533
|
+
log63.info("Plan approved \u2014 tasks created", {
|
|
70521
70534
|
reportId,
|
|
70522
70535
|
taskCount: report.upcomingPlan.plannedTasks.length
|
|
70523
70536
|
});
|
|
@@ -70529,7 +70542,7 @@ var init_report_service = __esm({
|
|
|
70529
70542
|
throw new Error("Report has no plan");
|
|
70530
70543
|
report.upcomingPlan.status = "rejected";
|
|
70531
70544
|
report.upcomingPlan.rejectionReason = reason;
|
|
70532
|
-
|
|
70545
|
+
log63.info("Plan rejected", { reportId, reason });
|
|
70533
70546
|
return report;
|
|
70534
70547
|
}
|
|
70535
70548
|
// ─── Feedback ──────────────────────────────────────────────────────────────
|
|
@@ -70581,7 +70594,7 @@ var init_report_service = __esm({
|
|
|
70581
70594
|
const existing = this.feedbackStore.get(opts.reportId) ?? [];
|
|
70582
70595
|
existing.push(feedback);
|
|
70583
70596
|
this.feedbackStore.set(opts.reportId, existing);
|
|
70584
|
-
|
|
70597
|
+
log63.info("Feedback added to report", {
|
|
70585
70598
|
reportId: opts.reportId,
|
|
70586
70599
|
type: opts.type,
|
|
70587
70600
|
disclosure: opts.disclosure.scope
|
|
@@ -70662,12 +70675,12 @@ var init_report_service = __esm({
|
|
|
70662
70675
|
});
|
|
70663
70676
|
|
|
70664
70677
|
// ../org-manager/dist/trust-service.js
|
|
70665
|
-
var
|
|
70678
|
+
var log64, TrustService;
|
|
70666
70679
|
var init_trust_service = __esm({
|
|
70667
70680
|
"../org-manager/dist/trust-service.js"() {
|
|
70668
70681
|
"use strict";
|
|
70669
70682
|
init_dist();
|
|
70670
|
-
|
|
70683
|
+
log64 = createLogger("trust-service");
|
|
70671
70684
|
TrustService = class {
|
|
70672
70685
|
trustLevels = /* @__PURE__ */ new Map();
|
|
70673
70686
|
getOrCreate(agentId2) {
|
|
@@ -70716,7 +70729,7 @@ var init_trust_service = __esm({
|
|
|
70716
70729
|
trust.level = this.scoreToLevel(trust.score, trust.totalDeliveries);
|
|
70717
70730
|
trust.lastEvaluatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
70718
70731
|
if (trust.level !== oldLevel) {
|
|
70719
|
-
|
|
70732
|
+
log64.info("Trust level changed", {
|
|
70720
70733
|
agentId: trust.agentId,
|
|
70721
70734
|
oldLevel,
|
|
70722
70735
|
newLevel: trust.level,
|
|
@@ -70761,22 +70774,22 @@ var init_trust_service = __esm({
|
|
|
70761
70774
|
});
|
|
70762
70775
|
|
|
70763
70776
|
// ../org-manager/dist/archive-service.js
|
|
70764
|
-
var
|
|
70777
|
+
var log65;
|
|
70765
70778
|
var init_archive_service = __esm({
|
|
70766
70779
|
"../org-manager/dist/archive-service.js"() {
|
|
70767
70780
|
"use strict";
|
|
70768
70781
|
init_dist();
|
|
70769
|
-
|
|
70782
|
+
log65 = createLogger("archive-service");
|
|
70770
70783
|
}
|
|
70771
70784
|
});
|
|
70772
70785
|
|
|
70773
70786
|
// ../org-manager/dist/stale-detector.js
|
|
70774
|
-
var
|
|
70787
|
+
var log66, DEFAULT_CONFIG4;
|
|
70775
70788
|
var init_stale_detector = __esm({
|
|
70776
70789
|
"../org-manager/dist/stale-detector.js"() {
|
|
70777
70790
|
"use strict";
|
|
70778
70791
|
init_dist();
|
|
70779
|
-
|
|
70792
|
+
log66 = createLogger("stale-detector");
|
|
70780
70793
|
DEFAULT_CONFIG4 = {
|
|
70781
70794
|
maxInProgressMs: 24 * 60 * 60 * 1e3,
|
|
70782
70795
|
maxReviewWaitMs: 12 * 60 * 60 * 1e3,
|
|
@@ -70787,12 +70800,12 @@ var init_stale_detector = __esm({
|
|
|
70787
70800
|
});
|
|
70788
70801
|
|
|
70789
70802
|
// ../org-manager/dist/scheduled-task-runner.js
|
|
70790
|
-
var
|
|
70803
|
+
var log67, ScheduledTaskRunner;
|
|
70791
70804
|
var init_scheduled_task_runner = __esm({
|
|
70792
70805
|
"../org-manager/dist/scheduled-task-runner.js"() {
|
|
70793
70806
|
"use strict";
|
|
70794
70807
|
init_dist();
|
|
70795
|
-
|
|
70808
|
+
log67 = createLogger("scheduled-task-runner");
|
|
70796
70809
|
ScheduledTaskRunner = class {
|
|
70797
70810
|
taskService;
|
|
70798
70811
|
pollIntervalMs;
|
|
@@ -70807,9 +70820,9 @@ var init_scheduled_task_runner = __esm({
|
|
|
70807
70820
|
return;
|
|
70808
70821
|
this.running = true;
|
|
70809
70822
|
this.timer = setInterval(() => {
|
|
70810
|
-
this.tick().catch((e) =>
|
|
70823
|
+
this.tick().catch((e) => log67.error("Scheduled task tick failed", { error: String(e) }));
|
|
70811
70824
|
}, this.pollIntervalMs);
|
|
70812
|
-
|
|
70825
|
+
log67.info("ScheduledTaskRunner started", { pollIntervalMs: this.pollIntervalMs });
|
|
70813
70826
|
}
|
|
70814
70827
|
stop() {
|
|
70815
70828
|
if (this.timer) {
|
|
@@ -70817,7 +70830,7 @@ var init_scheduled_task_runner = __esm({
|
|
|
70817
70830
|
this.timer = void 0;
|
|
70818
70831
|
}
|
|
70819
70832
|
this.running = false;
|
|
70820
|
-
|
|
70833
|
+
log67.info("ScheduledTaskRunner stopped");
|
|
70821
70834
|
}
|
|
70822
70835
|
isRunning() {
|
|
70823
70836
|
return this.running;
|
|
@@ -70844,27 +70857,27 @@ var init_scheduled_task_runner = __esm({
|
|
|
70844
70857
|
try {
|
|
70845
70858
|
await this.fireScheduledTask(task);
|
|
70846
70859
|
} catch (e) {
|
|
70847
|
-
|
|
70860
|
+
log67.error("Failed to fire scheduled task", { taskId: task.id, error: String(e) });
|
|
70848
70861
|
}
|
|
70849
70862
|
}
|
|
70850
70863
|
}
|
|
70851
70864
|
async fireScheduledTask(task) {
|
|
70852
|
-
|
|
70865
|
+
log67.info("Firing scheduled task", { taskId: task.id, title: task.title });
|
|
70853
70866
|
await this.taskService.advanceScheduleConfig(task.id);
|
|
70854
70867
|
const resettableStatuses = ["completed", "cancelled", "failed"];
|
|
70855
70868
|
if (resettableStatuses.includes(task.status)) {
|
|
70856
70869
|
await this.taskService.resetTaskForRerun(task.id);
|
|
70857
70870
|
} else if (!["in_progress", "review", "blocked", "pending"].includes(task.status)) {
|
|
70858
|
-
|
|
70871
|
+
log67.warn("Scheduled task has unexpected status, resetting for rerun", { taskId: task.id, status: task.status });
|
|
70859
70872
|
await this.taskService.resetTaskForRerun(task.id);
|
|
70860
70873
|
}
|
|
70861
70874
|
const current = this.taskService.getTask(task.id);
|
|
70862
70875
|
if (current && current.status === "in_progress") {
|
|
70863
70876
|
try {
|
|
70864
70877
|
await this.taskService.runTask(task.id);
|
|
70865
|
-
|
|
70878
|
+
log67.info("Scheduled task auto-started", { taskId: task.id });
|
|
70866
70879
|
} catch (err) {
|
|
70867
|
-
|
|
70880
|
+
log67.warn("Failed to auto-start scheduled task (agent may be busy)", { taskId: task.id, error: String(err) });
|
|
70868
70881
|
}
|
|
70869
70882
|
}
|
|
70870
70883
|
}
|
|
@@ -80620,7 +80633,7 @@ function openSqlite(dbPath) {
|
|
|
80620
80633
|
const cols = _db.prepare(`PRAGMA table_info(${m.table})`).all();
|
|
80621
80634
|
if (!cols.some((c) => c.name === m.column)) {
|
|
80622
80635
|
_db.exec(m.sql);
|
|
80623
|
-
|
|
80636
|
+
log68.info(`Migration: added column ${m.column} to ${m.table}`);
|
|
80624
80637
|
}
|
|
80625
80638
|
}
|
|
80626
80639
|
_db.exec("CREATE INDEX IF NOT EXISTS idx_agent_activities_mailbox ON agent_activities(mailbox_item_id)");
|
|
@@ -80634,10 +80647,10 @@ function openSqlite(dbPath) {
|
|
|
80634
80647
|
for (const m of statusMigrations) {
|
|
80635
80648
|
const result = _db.prepare(m.sql).run();
|
|
80636
80649
|
if (result.changes > 0) {
|
|
80637
|
-
|
|
80650
|
+
log68.info(`Status migration: ${m.desc} (${result.changes} rows)`);
|
|
80638
80651
|
}
|
|
80639
80652
|
}
|
|
80640
|
-
|
|
80653
|
+
log68.info("SQLite database opened", { path: dbPath });
|
|
80641
80654
|
return _db;
|
|
80642
80655
|
}
|
|
80643
80656
|
function closeSqlite() {
|
|
@@ -80657,7 +80670,7 @@ function migrateToExecutionStreamLogs(db) {
|
|
|
80657
80670
|
SELECT id, 'task', task_id, agent_id, seq, type, content, metadata, execution_round, created_at
|
|
80658
80671
|
FROM task_logs
|
|
80659
80672
|
`);
|
|
80660
|
-
|
|
80673
|
+
log68.info(`Migration: copied ${taskLogCount} task_logs to execution_stream_logs`);
|
|
80661
80674
|
}
|
|
80662
80675
|
const actLogCount = db.prepare("SELECT COUNT(*) as cnt FROM agent_activity_logs").get().cnt;
|
|
80663
80676
|
if (actLogCount > 0) {
|
|
@@ -80668,15 +80681,15 @@ function migrateToExecutionStreamLogs(db) {
|
|
|
80668
80681
|
seq, type, content, metadata, NULL, created_at
|
|
80669
80682
|
FROM agent_activity_logs
|
|
80670
80683
|
`);
|
|
80671
|
-
|
|
80684
|
+
log68.info(`Migration: copied ${actLogCount} agent_activity_logs to execution_stream_logs`);
|
|
80672
80685
|
}
|
|
80673
80686
|
}
|
|
80674
|
-
var
|
|
80687
|
+
var log68, SCHEMA_SQL, _db, SqliteOrgRepo, SqliteAgentRepo, SqliteTaskRepo, SqliteRequirementRepo, SqliteProjectRepo, SqliteTaskLogRepo, SqliteTaskCommentRepo, SqliteRequirementCommentRepo, SqliteMessageRepo, SqliteChatSessionRepo, SqliteChannelMessageRepo, SqliteUserRepo, SqliteTeamRepo, SqliteMarketplaceTemplateRepo, SqliteMarketplaceSkillRepo, SqliteMarketplaceRatingRepo, SqliteAgentKnowledgeRepo, SqliteExternalAgentRepo, SqliteDeliverableRepo, SqliteActivityRepo, SqliteExecutionStreamRepo, SqliteMailboxRepo, SqliteDecisionRepo, SqliteNotificationRepo;
|
|
80675
80688
|
var init_sqlite_storage = __esm({
|
|
80676
80689
|
"../storage/dist/sqlite-storage.js"() {
|
|
80677
80690
|
"use strict";
|
|
80678
80691
|
init_dist();
|
|
80679
|
-
|
|
80692
|
+
log68 = createLogger("sqlite-storage");
|
|
80680
80693
|
SCHEMA_SQL = `
|
|
80681
80694
|
CREATE TABLE IF NOT EXISTS organizations (
|
|
80682
80695
|
id TEXT PRIMARY KEY,
|
|
@@ -83113,21 +83126,21 @@ async function initSqliteStorage(url) {
|
|
|
83113
83126
|
decisionRepo: new storage.SqliteDecisionRepo(db),
|
|
83114
83127
|
notificationRepo: new storage.SqliteNotificationRepo(db)
|
|
83115
83128
|
};
|
|
83116
|
-
|
|
83129
|
+
log69.info("SQLite storage initialized", { path: dbPath });
|
|
83117
83130
|
return bridge;
|
|
83118
83131
|
} catch (error) {
|
|
83119
|
-
|
|
83132
|
+
log69.warn("Failed to initialize SQLite storage, falling back to memory-only mode", {
|
|
83120
83133
|
error: String(error)
|
|
83121
83134
|
});
|
|
83122
83135
|
return null;
|
|
83123
83136
|
}
|
|
83124
83137
|
}
|
|
83125
|
-
var
|
|
83138
|
+
var log69;
|
|
83126
83139
|
var init_storage_bridge = __esm({
|
|
83127
83140
|
"../org-manager/dist/storage-bridge.js"() {
|
|
83128
83141
|
"use strict";
|
|
83129
83142
|
init_dist();
|
|
83130
|
-
|
|
83143
|
+
log69 = createLogger("storage-bridge");
|
|
83131
83144
|
}
|
|
83132
83145
|
});
|
|
83133
83146
|
|
|
@@ -83159,12 +83172,12 @@ var init_dist6 = __esm({
|
|
|
83159
83172
|
});
|
|
83160
83173
|
|
|
83161
83174
|
// ../comms/dist/feishu/client.js
|
|
83162
|
-
var
|
|
83175
|
+
var log70, FeishuClient;
|
|
83163
83176
|
var init_client = __esm({
|
|
83164
83177
|
"../comms/dist/feishu/client.js"() {
|
|
83165
83178
|
"use strict";
|
|
83166
83179
|
init_dist();
|
|
83167
|
-
|
|
83180
|
+
log70 = createLogger("feishu-client");
|
|
83168
83181
|
FeishuClient = class {
|
|
83169
83182
|
appId;
|
|
83170
83183
|
appSecret;
|
|
@@ -83194,7 +83207,7 @@ var init_client = __esm({
|
|
|
83194
83207
|
}
|
|
83195
83208
|
this.tenantToken = data.tenant_access_token;
|
|
83196
83209
|
this.tokenExpiresAt = Date.now() + (data.expire - 300) * 1e3;
|
|
83197
|
-
|
|
83210
|
+
log70.info("Feishu tenant token refreshed");
|
|
83198
83211
|
return this.tenantToken;
|
|
83199
83212
|
}
|
|
83200
83213
|
async sendTextMessage(chatId, text2) {
|
|
@@ -83327,15 +83340,15 @@ var init_client = __esm({
|
|
|
83327
83340
|
// ../comms/dist/feishu/adapter.js
|
|
83328
83341
|
import { createServer as createServer3 } from "node:http";
|
|
83329
83342
|
import { createDecipheriv, scrypt } from "node:crypto";
|
|
83330
|
-
import { promisify as
|
|
83331
|
-
var
|
|
83343
|
+
import { promisify as promisify3 } from "node:util";
|
|
83344
|
+
var log71, scryptAsync, FeishuAdapter;
|
|
83332
83345
|
var init_adapter = __esm({
|
|
83333
83346
|
"../comms/dist/feishu/adapter.js"() {
|
|
83334
83347
|
"use strict";
|
|
83335
83348
|
init_dist();
|
|
83336
83349
|
init_client();
|
|
83337
|
-
|
|
83338
|
-
scryptAsync =
|
|
83350
|
+
log71 = createLogger("feishu-adapter");
|
|
83351
|
+
scryptAsync = promisify3(scrypt);
|
|
83339
83352
|
FeishuAdapter = class {
|
|
83340
83353
|
platform = "feishu";
|
|
83341
83354
|
client;
|
|
@@ -83355,10 +83368,10 @@ var init_adapter = __esm({
|
|
|
83355
83368
|
const port = this.config.webhookPort ?? 9e3;
|
|
83356
83369
|
this.server = createServer3((req, res) => this.handleWebhook(req, res));
|
|
83357
83370
|
this.server.listen(port, () => {
|
|
83358
|
-
|
|
83371
|
+
log71.info(`Feishu webhook server listening on port ${port}`);
|
|
83359
83372
|
});
|
|
83360
83373
|
this.connected = true;
|
|
83361
|
-
|
|
83374
|
+
log71.info("Feishu adapter connected");
|
|
83362
83375
|
}
|
|
83363
83376
|
async disconnect() {
|
|
83364
83377
|
if (this.server) {
|
|
@@ -83366,7 +83379,7 @@ var init_adapter = __esm({
|
|
|
83366
83379
|
this.server = void 0;
|
|
83367
83380
|
}
|
|
83368
83381
|
this.connected = false;
|
|
83369
|
-
|
|
83382
|
+
log71.info("Feishu adapter disconnected");
|
|
83370
83383
|
}
|
|
83371
83384
|
async sendMessage(channelId, content, options) {
|
|
83372
83385
|
if (!this.client)
|
|
@@ -83442,12 +83455,12 @@ var init_adapter = __esm({
|
|
|
83442
83455
|
res.end("ok");
|
|
83443
83456
|
if (event.header?.event_type === "im.message.receive_v1") {
|
|
83444
83457
|
this.processMessageEvent(event).catch((err) => {
|
|
83445
|
-
|
|
83458
|
+
log71.error("Failed to process Feishu message event", { error: err.message });
|
|
83446
83459
|
});
|
|
83447
83460
|
}
|
|
83448
83461
|
if (event["action"]) {
|
|
83449
83462
|
this.processCardAction(event).catch((err) => {
|
|
83450
|
-
|
|
83463
|
+
log71.error("Failed to process card action", { error: err.message });
|
|
83451
83464
|
});
|
|
83452
83465
|
}
|
|
83453
83466
|
};
|
|
@@ -83458,14 +83471,14 @@ var init_adapter = __esm({
|
|
|
83458
83471
|
const event = JSON.parse(decrypted);
|
|
83459
83472
|
processEvent(event);
|
|
83460
83473
|
} else if (raw.encrypt && !this.config?.encryptKey) {
|
|
83461
|
-
|
|
83474
|
+
log71.warn("Received encrypted Feishu payload but no encryptKey configured");
|
|
83462
83475
|
res.writeHead(200);
|
|
83463
83476
|
res.end("ok");
|
|
83464
83477
|
} else {
|
|
83465
83478
|
processEvent(raw);
|
|
83466
83479
|
}
|
|
83467
83480
|
} catch (err) {
|
|
83468
|
-
|
|
83481
|
+
log71.error("Failed to process Feishu webhook", { error: err instanceof Error ? err.message : String(err) });
|
|
83469
83482
|
res.writeHead(400);
|
|
83470
83483
|
res.end("bad request");
|
|
83471
83484
|
}
|
|
@@ -83510,7 +83523,7 @@ var init_adapter = __esm({
|
|
|
83510
83523
|
try {
|
|
83511
83524
|
await handler4(message);
|
|
83512
83525
|
} catch (error) {
|
|
83513
|
-
|
|
83526
|
+
log71.error("Message handler failed", { error });
|
|
83514
83527
|
}
|
|
83515
83528
|
}
|
|
83516
83529
|
}
|
|
@@ -83545,7 +83558,7 @@ var init_adapter = __esm({
|
|
|
83545
83558
|
try {
|
|
83546
83559
|
await handler4(message);
|
|
83547
83560
|
} catch (error) {
|
|
83548
|
-
|
|
83561
|
+
log71.error("Card action handler failed", { error });
|
|
83549
83562
|
}
|
|
83550
83563
|
}
|
|
83551
83564
|
}
|
|
@@ -83562,12 +83575,12 @@ var init_cards = __esm({
|
|
|
83562
83575
|
|
|
83563
83576
|
// ../comms/dist/webui/adapter.js
|
|
83564
83577
|
import { createServer as createServer4 } from "node:http";
|
|
83565
|
-
var
|
|
83578
|
+
var log72, WebUIAdapter;
|
|
83566
83579
|
var init_adapter2 = __esm({
|
|
83567
83580
|
"../comms/dist/webui/adapter.js"() {
|
|
83568
83581
|
"use strict";
|
|
83569
83582
|
init_dist();
|
|
83570
|
-
|
|
83583
|
+
log72 = createLogger("webui-adapter");
|
|
83571
83584
|
WebUIAdapter = class {
|
|
83572
83585
|
platform = "webui";
|
|
83573
83586
|
handlers = [];
|
|
@@ -83579,7 +83592,7 @@ var init_adapter2 = __esm({
|
|
|
83579
83592
|
this.port = config["port"] ?? 8058;
|
|
83580
83593
|
this.server = createServer4((req, res) => this.handleRequest(req, res));
|
|
83581
83594
|
this.server.listen(this.port, "0.0.0.0", () => {
|
|
83582
|
-
|
|
83595
|
+
log72.info(`WebUI comm server listening on 0.0.0.0:${this.port}`);
|
|
83583
83596
|
});
|
|
83584
83597
|
this.connected = true;
|
|
83585
83598
|
}
|
|
@@ -83652,7 +83665,7 @@ var init_adapter2 = __esm({
|
|
|
83652
83665
|
res.end(JSON.stringify({ received: true, messageId: message.id }));
|
|
83653
83666
|
for (const handler4 of this.handlers) {
|
|
83654
83667
|
handler4(message).catch((err) => {
|
|
83655
|
-
|
|
83668
|
+
log72.error("WebUI message handler failed", { error: String(err) });
|
|
83656
83669
|
});
|
|
83657
83670
|
}
|
|
83658
83671
|
} catch (error) {
|
|
@@ -83666,87 +83679,87 @@ var init_adapter2 = __esm({
|
|
|
83666
83679
|
});
|
|
83667
83680
|
|
|
83668
83681
|
// ../comms/dist/whatsapp/client.js
|
|
83669
|
-
var
|
|
83682
|
+
var log73;
|
|
83670
83683
|
var init_client2 = __esm({
|
|
83671
83684
|
"../comms/dist/whatsapp/client.js"() {
|
|
83672
83685
|
"use strict";
|
|
83673
83686
|
init_dist();
|
|
83674
|
-
|
|
83687
|
+
log73 = createLogger("whatsapp-client");
|
|
83675
83688
|
}
|
|
83676
83689
|
});
|
|
83677
83690
|
|
|
83678
83691
|
// ../comms/dist/whatsapp/adapter.js
|
|
83679
|
-
var
|
|
83692
|
+
var log74;
|
|
83680
83693
|
var init_adapter3 = __esm({
|
|
83681
83694
|
"../comms/dist/whatsapp/adapter.js"() {
|
|
83682
83695
|
"use strict";
|
|
83683
83696
|
init_dist();
|
|
83684
83697
|
init_client2();
|
|
83685
|
-
|
|
83698
|
+
log74 = createLogger("whatsapp-adapter");
|
|
83686
83699
|
}
|
|
83687
83700
|
});
|
|
83688
83701
|
|
|
83689
83702
|
// ../comms/dist/slack/client.js
|
|
83690
|
-
var
|
|
83703
|
+
var log75;
|
|
83691
83704
|
var init_client3 = __esm({
|
|
83692
83705
|
"../comms/dist/slack/client.js"() {
|
|
83693
83706
|
"use strict";
|
|
83694
83707
|
init_dist();
|
|
83695
|
-
|
|
83708
|
+
log75 = createLogger("slack-client");
|
|
83696
83709
|
}
|
|
83697
83710
|
});
|
|
83698
83711
|
|
|
83699
83712
|
// ../comms/dist/slack/adapter.js
|
|
83700
|
-
var
|
|
83713
|
+
var log76;
|
|
83701
83714
|
var init_adapter4 = __esm({
|
|
83702
83715
|
"../comms/dist/slack/adapter.js"() {
|
|
83703
83716
|
"use strict";
|
|
83704
83717
|
init_dist();
|
|
83705
83718
|
init_client3();
|
|
83706
|
-
|
|
83719
|
+
log76 = createLogger("slack-adapter");
|
|
83707
83720
|
}
|
|
83708
83721
|
});
|
|
83709
83722
|
|
|
83710
83723
|
// ../comms/dist/telegram/client.js
|
|
83711
|
-
var
|
|
83724
|
+
var log77;
|
|
83712
83725
|
var init_client4 = __esm({
|
|
83713
83726
|
"../comms/dist/telegram/client.js"() {
|
|
83714
83727
|
"use strict";
|
|
83715
83728
|
init_dist();
|
|
83716
|
-
|
|
83729
|
+
log77 = createLogger("telegram-client");
|
|
83717
83730
|
}
|
|
83718
83731
|
});
|
|
83719
83732
|
|
|
83720
83733
|
// ../comms/dist/telegram/adapter.js
|
|
83721
|
-
var
|
|
83734
|
+
var log78;
|
|
83722
83735
|
var init_adapter5 = __esm({
|
|
83723
83736
|
"../comms/dist/telegram/adapter.js"() {
|
|
83724
83737
|
"use strict";
|
|
83725
83738
|
init_dist();
|
|
83726
83739
|
init_client4();
|
|
83727
|
-
|
|
83740
|
+
log78 = createLogger("telegram-adapter");
|
|
83728
83741
|
}
|
|
83729
83742
|
});
|
|
83730
83743
|
|
|
83731
83744
|
// ../comms/dist/router.js
|
|
83732
|
-
var
|
|
83745
|
+
var log79, MessageRouter;
|
|
83733
83746
|
var init_router2 = __esm({
|
|
83734
83747
|
"../comms/dist/router.js"() {
|
|
83735
83748
|
"use strict";
|
|
83736
83749
|
init_dist();
|
|
83737
|
-
|
|
83750
|
+
log79 = createLogger("message-router");
|
|
83738
83751
|
MessageRouter = class {
|
|
83739
83752
|
adapters = /* @__PURE__ */ new Map();
|
|
83740
83753
|
agentChannelMap = /* @__PURE__ */ new Map();
|
|
83741
83754
|
agentHandler;
|
|
83742
83755
|
registerAdapter(adapter2) {
|
|
83743
83756
|
this.adapters.set(adapter2.platform, adapter2);
|
|
83744
|
-
|
|
83757
|
+
log79.info(`Registered comm adapter: ${adapter2.platform}`);
|
|
83745
83758
|
}
|
|
83746
83759
|
bindAgentToChannel(agentId2, platform3, channelId) {
|
|
83747
83760
|
const key2 = `${platform3}:${channelId}`;
|
|
83748
83761
|
this.agentChannelMap.set(key2, agentId2);
|
|
83749
|
-
|
|
83762
|
+
log79.info(`Bound agent ${agentId2} to ${key2}`);
|
|
83750
83763
|
}
|
|
83751
83764
|
setAgentHandler(handler4) {
|
|
83752
83765
|
this.agentHandler = handler4;
|
|
@@ -83755,7 +83768,7 @@ var init_router2 = __esm({
|
|
|
83755
83768
|
for (const config of configs) {
|
|
83756
83769
|
const adapter2 = this.adapters.get(config.platform);
|
|
83757
83770
|
if (!adapter2) {
|
|
83758
|
-
|
|
83771
|
+
log79.warn(`No adapter registered for platform: ${config.platform}`);
|
|
83759
83772
|
continue;
|
|
83760
83773
|
}
|
|
83761
83774
|
await adapter2.connect(config);
|
|
@@ -83774,7 +83787,7 @@ var init_router2 = __esm({
|
|
|
83774
83787
|
async sendToChannel(platform3, channelId, content) {
|
|
83775
83788
|
const adapter2 = this.adapters.get(platform3);
|
|
83776
83789
|
if (!adapter2 || !adapter2.isConnected()) {
|
|
83777
|
-
|
|
83790
|
+
log79.warn(`Adapter not available for platform: ${platform3}`);
|
|
83778
83791
|
return void 0;
|
|
83779
83792
|
}
|
|
83780
83793
|
return adapter2.sendMessage(channelId, content);
|
|
@@ -83786,7 +83799,7 @@ var init_router2 = __esm({
|
|
|
83786
83799
|
const key2 = `${message.platform}:${message.channelId}`;
|
|
83787
83800
|
const agentId2 = message.agentId || this.agentChannelMap.get(key2);
|
|
83788
83801
|
if (!agentId2) {
|
|
83789
|
-
|
|
83802
|
+
log79.debug("No agent bound to channel, skipping message", { key: key2 });
|
|
83790
83803
|
return;
|
|
83791
83804
|
}
|
|
83792
83805
|
message.agentId = agentId2;
|
|
@@ -83802,7 +83815,7 @@ var init_router2 = __esm({
|
|
|
83802
83815
|
}
|
|
83803
83816
|
}
|
|
83804
83817
|
} catch (error) {
|
|
83805
|
-
|
|
83818
|
+
log79.error("Agent handler failed", { agentId: agentId2, error: String(error) });
|
|
83806
83819
|
}
|
|
83807
83820
|
}
|
|
83808
83821
|
}
|
|
@@ -85045,7 +85058,7 @@ async function startServer(config, values) {
|
|
|
85045
85058
|
const webUiDir = resolveWebUiDir();
|
|
85046
85059
|
if (webUiDir) {
|
|
85047
85060
|
apiServer.setWebUiDir(webUiDir);
|
|
85048
|
-
|
|
85061
|
+
log80.info("Web UI static files enabled", { dir: webUiDir });
|
|
85049
85062
|
}
|
|
85050
85063
|
const firstOrgId = "default";
|
|
85051
85064
|
if (storage) {
|
|
@@ -85080,38 +85093,43 @@ async function startServer(config, values) {
|
|
|
85080
85093
|
});
|
|
85081
85094
|
if (storage?.chatSessionRepo) {
|
|
85082
85095
|
const ws = apiServer.getWSBroadcaster();
|
|
85083
|
-
|
|
85084
|
-
|
|
85085
|
-
|
|
85086
|
-
|
|
85087
|
-
|
|
85088
|
-
|
|
85089
|
-
|
|
85090
|
-
if (sessions2.length > 0) {
|
|
85091
|
-
sessionId = sessions2[0].id;
|
|
85096
|
+
const wireAgentChatIntegration = (agentId2) => {
|
|
85097
|
+
try {
|
|
85098
|
+
const agent = agentManager.getAgent(agentId2);
|
|
85099
|
+
agentManager.setUserMessageSender(agentId2, async (message, opts) => {
|
|
85100
|
+
let sessionId;
|
|
85101
|
+
if (opts?.sessionId) {
|
|
85102
|
+
sessionId = opts.sessionId;
|
|
85092
85103
|
} else {
|
|
85093
|
-
const
|
|
85094
|
-
|
|
85104
|
+
const sessions2 = await storage.chatSessionRepo.getSessionsByAgent(agentId2);
|
|
85105
|
+
if (sessions2.length > 0) {
|
|
85106
|
+
sessionId = sessions2[0].id;
|
|
85107
|
+
} else {
|
|
85108
|
+
const newSess = await storage.chatSessionRepo.createSession(agentId2);
|
|
85109
|
+
sessionId = newSess.id;
|
|
85110
|
+
}
|
|
85095
85111
|
}
|
|
85096
|
-
|
|
85097
|
-
|
|
85098
|
-
|
|
85099
|
-
|
|
85100
|
-
|
|
85101
|
-
|
|
85102
|
-
|
|
85103
|
-
|
|
85104
|
-
|
|
85105
|
-
|
|
85106
|
-
|
|
85107
|
-
|
|
85108
|
-
|
|
85109
|
-
|
|
85110
|
-
|
|
85111
|
-
|
|
85112
|
-
|
|
85113
|
-
|
|
85114
|
-
|
|
85112
|
+
const msg = await storage.chatSessionRepo.appendMessage(sessionId, agentId2, "assistant", message);
|
|
85113
|
+
ws.broadcastProactiveMessage(agentId2, agent.config.name, sessionId, msg.id, message);
|
|
85114
|
+
return { sessionId, messageId: msg.id };
|
|
85115
|
+
});
|
|
85116
|
+
agentManager.setChatSessionsFetcher(agentId2, async () => {
|
|
85117
|
+
const sessions2 = await storage.chatSessionRepo.getSessionsByAgent(agentId2);
|
|
85118
|
+
return sessions2.slice(0, 5).map((s) => ({
|
|
85119
|
+
id: s.id,
|
|
85120
|
+
title: s.title,
|
|
85121
|
+
lastMessageAt: s.lastMessageAt ?? s.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
85122
|
+
lastMessagePreview: s.lastMessagePreview
|
|
85123
|
+
}));
|
|
85124
|
+
});
|
|
85125
|
+
} catch {
|
|
85126
|
+
}
|
|
85127
|
+
};
|
|
85128
|
+
for (const info4 of agentManager.listAgents()) wireAgentChatIntegration(info4.id);
|
|
85129
|
+
agentManager.getEventBus().on("agent:created", (evt) => {
|
|
85130
|
+
const { agentId: agentId2 } = evt;
|
|
85131
|
+
wireAgentChatIntegration(agentId2);
|
|
85132
|
+
});
|
|
85115
85133
|
}
|
|
85116
85134
|
agentManager.setUserNotifier((opts) => {
|
|
85117
85135
|
hitlService.notify({
|
|
@@ -85129,7 +85147,7 @@ async function startServer(config, values) {
|
|
|
85129
85147
|
try {
|
|
85130
85148
|
await taskService.resumeInProgressTasks();
|
|
85131
85149
|
} catch (err) {
|
|
85132
|
-
|
|
85150
|
+
log80.warn("Failed to auto-resume in_progress tasks", { error: String(err) });
|
|
85133
85151
|
}
|
|
85134
85152
|
}, 3e3);
|
|
85135
85153
|
const gatewaySecret = config.security?.gatewaySecret ?? process.env["GATEWAY_SECRET"] ?? "markus-gateway-default-secret-change-me";
|
|
@@ -85167,7 +85185,7 @@ async function startServer(config, values) {
|
|
|
85167
85185
|
heartbeatIntervalMs: agent.config.heartbeatIntervalMs
|
|
85168
85186
|
});
|
|
85169
85187
|
} catch (err) {
|
|
85170
|
-
|
|
85188
|
+
log80.warn("Failed to persist gateway agent to DB (may already exist)", { error: String(err) });
|
|
85171
85189
|
}
|
|
85172
85190
|
}
|
|
85173
85191
|
return { id: agent.id };
|
|
@@ -85212,7 +85230,7 @@ async function startServer(config, values) {
|
|
|
85212
85230
|
}));
|
|
85213
85231
|
});
|
|
85214
85232
|
apiServer.setGateway(gateway, gatewaySecret);
|
|
85215
|
-
|
|
85233
|
+
log80.info("External Agent Gateway enabled", { secret: gatewaySecret === "markus-gateway-default-secret-change-me" ? "(default)" : "(custom)" });
|
|
85216
85234
|
apiServer.start();
|
|
85217
85235
|
taskService.setWSBroadcaster(apiServer.getWSBroadcaster());
|
|
85218
85236
|
requirementService.setWSBroadcaster(apiServer.getWSBroadcaster());
|
|
@@ -85220,7 +85238,7 @@ async function startServer(config, values) {
|
|
|
85220
85238
|
const scheduledTaskRunner = new ScheduledTaskRunner(taskService);
|
|
85221
85239
|
scheduledTaskRunner.start();
|
|
85222
85240
|
agentManager.setEscalationHandler((agentId2, reason) => {
|
|
85223
|
-
|
|
85241
|
+
log80.warn("Agent escalation", { agentId: agentId2, reason });
|
|
85224
85242
|
hitlService.notify({
|
|
85225
85243
|
targetUserId: "default",
|
|
85226
85244
|
type: "system",
|
|
@@ -85310,7 +85328,7 @@ async function startServer(config, values) {
|
|
|
85310
85328
|
state.status
|
|
85311
85329
|
);
|
|
85312
85330
|
} catch (err) {
|
|
85313
|
-
|
|
85331
|
+
log80.warn("Failed to persist agent state", { agentId: agentId2, error: String(err) });
|
|
85314
85332
|
}
|
|
85315
85333
|
apiServer.getWSBroadcaster().broadcastAgentUpdate(agentId2, state.status, {
|
|
85316
85334
|
lastError: state.lastError,
|
|
@@ -85335,7 +85353,7 @@ async function startServer(config, values) {
|
|
|
85335
85353
|
startedAt: activity.startedAt
|
|
85336
85354
|
});
|
|
85337
85355
|
} catch (err) {
|
|
85338
|
-
|
|
85356
|
+
log80.warn("Failed to persist activity start", { activityId: activity.id, error: String(err) });
|
|
85339
85357
|
}
|
|
85340
85358
|
},
|
|
85341
85359
|
onLog: (data) => {
|
|
@@ -85351,20 +85369,20 @@ async function startServer(config, values) {
|
|
|
85351
85369
|
metadata: data.metadata
|
|
85352
85370
|
});
|
|
85353
85371
|
} catch (err) {
|
|
85354
|
-
|
|
85372
|
+
log80.warn("Failed to persist execution stream activity log", { activityId: data.activityId, error: String(err) });
|
|
85355
85373
|
}
|
|
85356
85374
|
}
|
|
85357
85375
|
try {
|
|
85358
85376
|
actRepo.insertActivityLog(data);
|
|
85359
85377
|
} catch (err) {
|
|
85360
|
-
|
|
85378
|
+
log80.warn("Failed to persist activity log", { activityId: data.activityId, error: String(err) });
|
|
85361
85379
|
}
|
|
85362
85380
|
},
|
|
85363
85381
|
onEnd: (activityId, summary) => {
|
|
85364
85382
|
try {
|
|
85365
85383
|
actRepo.updateActivity(activityId, summary);
|
|
85366
85384
|
} catch (err) {
|
|
85367
|
-
|
|
85385
|
+
log80.warn("Failed to persist activity end", { activityId, error: String(err) });
|
|
85368
85386
|
}
|
|
85369
85387
|
}
|
|
85370
85388
|
});
|
|
@@ -85389,14 +85407,14 @@ async function startServer(config, values) {
|
|
|
85389
85407
|
queuedAt: item.queuedAt
|
|
85390
85408
|
});
|
|
85391
85409
|
} catch (e) {
|
|
85392
|
-
|
|
85410
|
+
log80.warn("Failed to persist mailbox item", { id: item.id, error: String(e) });
|
|
85393
85411
|
}
|
|
85394
85412
|
},
|
|
85395
85413
|
updateStatus: (itemId, status, extra) => {
|
|
85396
85414
|
try {
|
|
85397
85415
|
mbRepo.updateStatus(itemId, status, extra);
|
|
85398
85416
|
} catch (e) {
|
|
85399
|
-
|
|
85417
|
+
log80.warn("Failed to update mailbox status", { itemId, error: String(e) });
|
|
85400
85418
|
}
|
|
85401
85419
|
}
|
|
85402
85420
|
});
|
|
@@ -85414,7 +85432,7 @@ async function startServer(config, values) {
|
|
|
85414
85432
|
createdAt: decision.createdAt
|
|
85415
85433
|
});
|
|
85416
85434
|
} catch (e) {
|
|
85417
|
-
|
|
85435
|
+
log80.warn("Failed to persist decision", { id: decision.id, error: String(e) });
|
|
85418
85436
|
}
|
|
85419
85437
|
}
|
|
85420
85438
|
});
|
|
@@ -85422,11 +85440,38 @@ async function startServer(config, values) {
|
|
|
85422
85440
|
}
|
|
85423
85441
|
};
|
|
85424
85442
|
for (const a of agentManager.listAgents()) wireMailboxPersistence(a.id);
|
|
85425
|
-
agentManager.getEventBus().on("agent:
|
|
85443
|
+
agentManager.getEventBus().on("agent:created", (evt) => {
|
|
85426
85444
|
const { agentId: agentId2 } = evt;
|
|
85427
85445
|
wireMailboxPersistence(agentId2);
|
|
85428
85446
|
});
|
|
85429
85447
|
}
|
|
85448
|
+
if (storage?.agentRepo) {
|
|
85449
|
+
const agentRepo = storage.agentRepo;
|
|
85450
|
+
const existingIds = new Set(agentManager.listAgents().map((a) => a.id));
|
|
85451
|
+
agentManager.getEventBus().on("agent:created", (evt) => {
|
|
85452
|
+
const { agentId: agentId2 } = evt;
|
|
85453
|
+
if (existingIds.has(agentId2)) return;
|
|
85454
|
+
existingIds.add(agentId2);
|
|
85455
|
+
try {
|
|
85456
|
+
const agent = agentManager.getAgent(agentId2);
|
|
85457
|
+
agentRepo.create({
|
|
85458
|
+
id: agent.id,
|
|
85459
|
+
name: agent.config.name,
|
|
85460
|
+
orgId: agent.config.orgId ?? "default",
|
|
85461
|
+
teamId: agent.config.teamId,
|
|
85462
|
+
roleId: agent.config.roleId,
|
|
85463
|
+
roleName: agent.role.name,
|
|
85464
|
+
agentRole: agent.config.agentRole ?? "worker",
|
|
85465
|
+
skills: agent.config.skills,
|
|
85466
|
+
llmConfig: agent.config.llmConfig,
|
|
85467
|
+
heartbeatIntervalMs: agent.config.heartbeatIntervalMs
|
|
85468
|
+
}).catch((err) => {
|
|
85469
|
+
log80.warn("Failed to persist runtime-created agent to DB", { agentId: agentId2, error: String(err) });
|
|
85470
|
+
});
|
|
85471
|
+
} catch {
|
|
85472
|
+
}
|
|
85473
|
+
});
|
|
85474
|
+
}
|
|
85430
85475
|
agentManager.getEventBus().on("agent:activity_log", (event) => {
|
|
85431
85476
|
const ws = apiServer.getWSBroadcaster();
|
|
85432
85477
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -85460,12 +85505,59 @@ async function startServer(config, values) {
|
|
|
85460
85505
|
const ws = apiServer.getWSBroadcaster();
|
|
85461
85506
|
ws.broadcast({ type: "agent:focus", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85462
85507
|
});
|
|
85508
|
+
eventBus.on("agent:removed", (event) => {
|
|
85509
|
+
const { agentId: agentId2 } = event;
|
|
85510
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85511
|
+
ws.broadcastAgentUpdate(agentId2, "removed");
|
|
85512
|
+
});
|
|
85513
|
+
eventBus.on("agent:paused", (event) => {
|
|
85514
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85515
|
+
ws.broadcast({ type: "agent:paused", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85516
|
+
});
|
|
85517
|
+
eventBus.on("agent:resumed", (event) => {
|
|
85518
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85519
|
+
ws.broadcast({ type: "agent:resumed", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85520
|
+
});
|
|
85521
|
+
eventBus.on("agent:started", (event) => {
|
|
85522
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85523
|
+
ws.broadcast({ type: "agent:started", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85524
|
+
});
|
|
85525
|
+
eventBus.on("agent:stopped", (event) => {
|
|
85526
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85527
|
+
ws.broadcast({ type: "agent:stopped", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85528
|
+
});
|
|
85529
|
+
eventBus.on("task:completed", (event) => {
|
|
85530
|
+
const { taskId: taskId2, agentId: agentId2 } = event;
|
|
85531
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85532
|
+
ws.broadcastTaskUpdate(taskId2, "completed", { agentId: agentId2 });
|
|
85533
|
+
});
|
|
85534
|
+
eventBus.on("task:failed", (event) => {
|
|
85535
|
+
const { taskId: taskId2, agentId: agentId2, error } = event;
|
|
85536
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85537
|
+
ws.broadcastTaskUpdate(taskId2, "failed", { agentId: agentId2, error });
|
|
85538
|
+
});
|
|
85539
|
+
eventBus.on("system:pause-all", (event) => {
|
|
85540
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85541
|
+
ws.broadcast({ type: "system:pause-all", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85542
|
+
});
|
|
85543
|
+
eventBus.on("system:resume-all", (event) => {
|
|
85544
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85545
|
+
ws.broadcast({ type: "system:resume-all", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85546
|
+
});
|
|
85547
|
+
eventBus.on("system:emergency-stop", (event) => {
|
|
85548
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85549
|
+
ws.broadcast({ type: "system:emergency-stop", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85550
|
+
});
|
|
85551
|
+
eventBus.on("system:announcement", (event) => {
|
|
85552
|
+
const ws = apiServer.getWSBroadcaster();
|
|
85553
|
+
ws.broadcast({ type: "system:announcement", payload: event, timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
85554
|
+
});
|
|
85463
85555
|
const scheduleDailyReset = () => {
|
|
85464
85556
|
const now2 = /* @__PURE__ */ new Date();
|
|
85465
85557
|
const nextMidnight = new Date(now2.getFullYear(), now2.getMonth(), now2.getDate() + 1, 0, 0, 0, 0);
|
|
85466
85558
|
const msUntilMidnight = nextMidnight.getTime() - now2.getTime();
|
|
85467
85559
|
setTimeout(() => {
|
|
85468
|
-
|
|
85560
|
+
log80.info("Daily token reset triggered");
|
|
85469
85561
|
for (const agentInfo of agentManager.listAgents()) {
|
|
85470
85562
|
try {
|
|
85471
85563
|
const agent = agentManager.getAgent(agentInfo.id);
|
|
@@ -85475,7 +85567,7 @@ async function startServer(config, values) {
|
|
|
85475
85567
|
}
|
|
85476
85568
|
scheduleDailyReset();
|
|
85477
85569
|
}, msUntilMidnight);
|
|
85478
|
-
|
|
85570
|
+
log80.info(`Daily token reset scheduled in ${Math.round(msUntilMidnight / 6e4)} minutes`);
|
|
85479
85571
|
};
|
|
85480
85572
|
scheduleDailyReset();
|
|
85481
85573
|
const messageRouter = new MessageRouter();
|
|
@@ -85506,7 +85598,7 @@ async function startServer(config, values) {
|
|
|
85506
85598
|
durationMs: Date.now() - startTs,
|
|
85507
85599
|
success: false
|
|
85508
85600
|
});
|
|
85509
|
-
|
|
85601
|
+
log80.error("Agent message handler error", { error: String(error) });
|
|
85510
85602
|
return void 0;
|
|
85511
85603
|
}
|
|
85512
85604
|
});
|
|
@@ -85554,7 +85646,7 @@ async function startServer(config, values) {
|
|
|
85554
85646
|
await new Promise(() => {
|
|
85555
85647
|
});
|
|
85556
85648
|
}
|
|
85557
|
-
var
|
|
85649
|
+
var log80;
|
|
85558
85650
|
var init_start = __esm({
|
|
85559
85651
|
"src/commands/start.ts"() {
|
|
85560
85652
|
"use strict";
|
|
@@ -85566,7 +85658,7 @@ var init_start = __esm({
|
|
|
85566
85658
|
init_logger3();
|
|
85567
85659
|
init_browser();
|
|
85568
85660
|
init_startupProgress();
|
|
85569
|
-
|
|
85661
|
+
log80 = createLogger("cli");
|
|
85570
85662
|
}
|
|
85571
85663
|
});
|
|
85572
85664
|
|