@opengoat/core 2026.2.20 → 2026.2.23
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/core/bootstrap/application/bootstrap.service.js +26 -7
- package/dist/core/bootstrap/application/bootstrap.service.js.map +1 -1
- package/dist/core/opengoat/application/opengoat.service.d.ts +16 -1
- package/dist/core/opengoat/application/opengoat.service.js +227 -47
- package/dist/core/opengoat/application/opengoat.service.js.map +1 -1
- package/dist/core/opengoat/index.d.ts +1 -1
- package/dist/core/skills/application/skill.service.d.ts +28 -2
- package/dist/core/skills/application/skill.service.js +433 -33
- package/dist/core/skills/application/skill.service.js.map +1 -1
- package/dist/core/skills/domain/skill.d.ts +19 -1
- package/dist/core/skills/domain/skill.js.map +1 -1
- package/dist/core/skills/index.d.ts +1 -1
- package/dist/core/skills/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_AGENT_ID } from "../../domain/agent-id.js";
|
|
1
|
+
import { DEFAULT_AGENT_ID, normalizeAgentId } from "../../domain/agent-id.js";
|
|
2
2
|
import { listOrganizationMarkdownTemplates, renderAgentsIndex, renderGlobalConfig, } from "../../templates/default-templates.js";
|
|
3
3
|
export class BootstrapService {
|
|
4
4
|
fileSystem;
|
|
@@ -26,7 +26,7 @@ export class BootstrapService {
|
|
|
26
26
|
await this.ensureDirectory(paths.runsDir, createdPaths, skippedPaths);
|
|
27
27
|
await this.ensureOrganizationMarkdownFiles(paths.organizationDir, createdPaths, skippedPaths);
|
|
28
28
|
const now = this.nowIso();
|
|
29
|
-
await this.ensureGlobalConfig(paths.globalConfigJsonPath, now, createdPaths, skippedPaths);
|
|
29
|
+
const defaultAgent = await this.ensureGlobalConfig(paths.globalConfigJsonPath, now, createdPaths, skippedPaths);
|
|
30
30
|
await this.ensureAgentsIndex(paths.agentsIndexJsonPath, now, createdPaths, skippedPaths);
|
|
31
31
|
const ceo = {
|
|
32
32
|
id: DEFAULT_AGENT_ID,
|
|
@@ -59,20 +59,38 @@ export class BootstrapService {
|
|
|
59
59
|
paths,
|
|
60
60
|
createdPaths,
|
|
61
61
|
skippedPaths,
|
|
62
|
-
defaultAgent
|
|
62
|
+
defaultAgent,
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
async ensureGlobalConfig(globalConfigJsonPath, now, createdPaths, skippedPaths) {
|
|
66
66
|
const exists = await this.fileSystem.exists(globalConfigJsonPath);
|
|
67
67
|
if (!exists) {
|
|
68
|
-
|
|
68
|
+
const created = renderGlobalConfig(now);
|
|
69
|
+
await this.fileSystem.writeFile(globalConfigJsonPath, `${JSON.stringify(created, null, 2)}\n`);
|
|
69
70
|
createdPaths.push(globalConfigJsonPath);
|
|
70
|
-
return;
|
|
71
|
+
return created.defaultAgent;
|
|
71
72
|
}
|
|
72
73
|
const current = await this.readJsonIfPresent(globalConfigJsonPath);
|
|
73
|
-
|
|
74
|
+
const normalizedDefaultAgent = normalizeAgentId(current?.defaultAgent ?? "");
|
|
75
|
+
if (current && normalizedDefaultAgent) {
|
|
76
|
+
if (current.schemaVersion === 1 &&
|
|
77
|
+
current.defaultAgent === normalizedDefaultAgent &&
|
|
78
|
+
typeof current.createdAt === "string" &&
|
|
79
|
+
current.createdAt.trim() &&
|
|
80
|
+
typeof current.updatedAt === "string" &&
|
|
81
|
+
current.updatedAt.trim()) {
|
|
82
|
+
skippedPaths.push(globalConfigJsonPath);
|
|
83
|
+
return normalizedDefaultAgent;
|
|
84
|
+
}
|
|
85
|
+
const repairedCurrent = {
|
|
86
|
+
schemaVersion: 1,
|
|
87
|
+
defaultAgent: normalizedDefaultAgent,
|
|
88
|
+
createdAt: current.createdAt ?? now,
|
|
89
|
+
updatedAt: now,
|
|
90
|
+
};
|
|
91
|
+
await this.fileSystem.writeFile(globalConfigJsonPath, `${JSON.stringify(repairedCurrent, null, 2)}\n`);
|
|
74
92
|
skippedPaths.push(globalConfigJsonPath);
|
|
75
|
-
return;
|
|
93
|
+
return repairedCurrent.defaultAgent;
|
|
76
94
|
}
|
|
77
95
|
const repaired = {
|
|
78
96
|
schemaVersion: 1,
|
|
@@ -82,6 +100,7 @@ export class BootstrapService {
|
|
|
82
100
|
};
|
|
83
101
|
await this.fileSystem.writeFile(globalConfigJsonPath, `${JSON.stringify(repaired, null, 2)}\n`);
|
|
84
102
|
skippedPaths.push(globalConfigJsonPath);
|
|
103
|
+
return repaired.defaultAgent;
|
|
85
104
|
}
|
|
86
105
|
async ensureAgentsIndex(agentsIndexJsonPath, now, createdPaths, skippedPaths) {
|
|
87
106
|
const exists = await this.fileSystem.exists(agentsIndexJsonPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.service.js","sourceRoot":"","sources":["../../../../src/core/bootstrap/application/bootstrap.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.service.js","sourceRoot":"","sources":["../../../../src/core/bootstrap/application/bootstrap.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAS9E,OAAO,EACL,iCAAiC,EACjC,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,sCAAsC,CAAC;AAU9C,MAAM,OAAO,gBAAgB;IACV,UAAU,CAAiB;IAC3B,QAAQ,CAAW;IACnB,aAAa,CAAwB;IACrC,YAAY,CAAe;IAC3B,MAAM,CAAe;IAEtC,YAAmB,IAA0B;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,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|
|
10
10
|
import type { AgentProviderBinding, OpenClawGatewayConfig, ProviderAuthOptions, ProviderExecutionResult, ProviderOnboardingSpec, ProviderRegistry, ProviderStoredConfig, ProviderSummary } from "../../providers/index.js";
|
|
11
11
|
import { type AgentLastAction, type SessionCompactionResult, type SessionHistoryResult, type SessionRemoveResult, type SessionRunInfo, type SessionSummary } from "../../sessions/index.js";
|
|
12
|
-
import { type InstallSkillRequest, type InstallSkillResult, type ResolvedSkill } from "../../skills/index.js";
|
|
12
|
+
import { type InstallSkillRequest, type InstallSkillResult, type RemoveSkillRequest, type RemoveSkillResult, type ResolvedSkill } from "../../skills/index.js";
|
|
13
13
|
import { type TaskDelegationStrategiesConfig } from "./opengoat.service.helpers.js";
|
|
14
14
|
interface OpenGoatServiceDeps {
|
|
15
15
|
fileSystem: FileSystemPort;
|
|
@@ -25,6 +25,11 @@ export interface RuntimeDefaultsSyncResult {
|
|
|
25
25
|
ceoSynced: boolean;
|
|
26
26
|
warnings: string[];
|
|
27
27
|
}
|
|
28
|
+
export interface DefaultAgentUpdateResult {
|
|
29
|
+
defaultAgent: string;
|
|
30
|
+
previousDefaultAgent: string;
|
|
31
|
+
configPath: string;
|
|
32
|
+
}
|
|
28
33
|
export interface TaskCronDispatchResult {
|
|
29
34
|
kind: "todo" | "doing" | "pending" | "blocked" | "inactive" | "topdown";
|
|
30
35
|
targetAgentId: string;
|
|
@@ -77,6 +82,10 @@ export declare class OpenGoatService {
|
|
|
77
82
|
initialize(options?: {
|
|
78
83
|
syncRuntimeDefaults?: boolean;
|
|
79
84
|
}): Promise<InitializationResult>;
|
|
85
|
+
getDefaultAgentId(options?: {
|
|
86
|
+
requireExisting?: boolean;
|
|
87
|
+
}): Promise<string>;
|
|
88
|
+
setDefaultAgent(rawAgentId: string): Promise<DefaultAgentUpdateResult>;
|
|
80
89
|
hardReset(): Promise<HardResetResult>;
|
|
81
90
|
syncRuntimeDefaults(): Promise<RuntimeDefaultsSyncResult>;
|
|
82
91
|
createAgent(rawName: string, options?: CreateAgentOptions): Promise<AgentCreationResult>;
|
|
@@ -139,6 +148,8 @@ export declare class OpenGoatService {
|
|
|
139
148
|
listSkills(agentId?: string): Promise<ResolvedSkill[]>;
|
|
140
149
|
listGlobalSkills(): Promise<ResolvedSkill[]>;
|
|
141
150
|
installSkill(request: InstallSkillRequest): Promise<InstallSkillResult>;
|
|
151
|
+
removeSkill(request: RemoveSkillRequest): Promise<RemoveSkillResult>;
|
|
152
|
+
private resolveAgentSkillInstallOptions;
|
|
142
153
|
runOpenClaw(args: string[], options?: {
|
|
143
154
|
cwd?: string;
|
|
144
155
|
env?: NodeJS.ProcessEnv;
|
|
@@ -164,6 +175,10 @@ export declare class OpenGoatService {
|
|
|
164
175
|
getPaths(): import("../../domain/opengoat-paths.js").OpenGoatPaths;
|
|
165
176
|
private dispatchAutomationMessage;
|
|
166
177
|
private resolveNowIso;
|
|
178
|
+
private resolveInputAgentId;
|
|
179
|
+
private resolveDefaultAgentId;
|
|
180
|
+
private readGlobalConfig;
|
|
181
|
+
private readJsonFileIfPresent;
|
|
167
182
|
private initializeRuntimeDefaults;
|
|
168
183
|
private resolveNowMs;
|
|
169
184
|
private syncOpenClawRoleSkills;
|
|
@@ -20,6 +20,7 @@ const OPENCLAW_OPENGOAT_PLUGIN_ID = "openclaw-plugin";
|
|
|
20
20
|
const OPENCLAW_OPENGOAT_PLUGIN_ROOT_ID = "opengoat-plugin";
|
|
21
21
|
const OPENCLAW_OPENGOAT_PLUGIN_LEGACY_PACK_ID = "openclaw-plugin-pack";
|
|
22
22
|
const OPENCLAW_OPENGOAT_PLUGIN_FALLBACK_ID = "workspace";
|
|
23
|
+
const OPENGOAT_DEFAULT_AGENT_ENV = "OPENGOAT_DEFAULT_AGENT";
|
|
23
24
|
const NOTIFICATION_SESSION_COMPACTION_COMMAND = [
|
|
24
25
|
"/compact",
|
|
25
26
|
"Keep only the last 3 notification exchanges plus active task ids, statuses, blockers, and explicit next actions.",
|
|
@@ -71,6 +72,7 @@ export class OpenGoatService {
|
|
|
71
72
|
this.skillService = new SkillService({
|
|
72
73
|
fileSystem: deps.fileSystem,
|
|
73
74
|
pathPort: deps.pathPort,
|
|
75
|
+
commandRunner: deps.commandRunner,
|
|
74
76
|
});
|
|
75
77
|
this.providerService = new ProviderService({
|
|
76
78
|
fileSystem: deps.fileSystem,
|
|
@@ -108,6 +110,39 @@ export class OpenGoatService {
|
|
|
108
110
|
syncRuntimeDefaults: options.syncRuntimeDefaults ?? true,
|
|
109
111
|
});
|
|
110
112
|
}
|
|
113
|
+
async getDefaultAgentId(options = {}) {
|
|
114
|
+
const paths = this.pathsProvider.getPaths();
|
|
115
|
+
return this.resolveDefaultAgentId(paths, {
|
|
116
|
+
requireExisting: options.requireExisting ?? true,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async setDefaultAgent(rawAgentId) {
|
|
120
|
+
const defaultAgent = normalizeAgentId(rawAgentId);
|
|
121
|
+
if (!defaultAgent) {
|
|
122
|
+
throw new Error("Agent id cannot be empty.");
|
|
123
|
+
}
|
|
124
|
+
const paths = this.pathsProvider.getPaths();
|
|
125
|
+
await this.bootstrapService.initialize();
|
|
126
|
+
const agents = await this.agentService.listAgents(paths);
|
|
127
|
+
if (!agents.some((agent) => agent.id === defaultAgent)) {
|
|
128
|
+
throw new Error(`Agent "${defaultAgent}" does not exist.`);
|
|
129
|
+
}
|
|
130
|
+
const now = this.resolveNowIso();
|
|
131
|
+
const currentConfig = await this.readGlobalConfig(paths);
|
|
132
|
+
const previousDefaultAgent = normalizeAgentId(currentConfig?.defaultAgent ?? "") || DEFAULT_AGENT_ID;
|
|
133
|
+
const nextConfig = {
|
|
134
|
+
schemaVersion: 1,
|
|
135
|
+
defaultAgent,
|
|
136
|
+
createdAt: currentConfig?.createdAt ?? now,
|
|
137
|
+
updatedAt: now,
|
|
138
|
+
};
|
|
139
|
+
await this.fileSystem.writeFile(paths.globalConfigJsonPath, `${JSON.stringify(nextConfig, null, 2)}\n`);
|
|
140
|
+
return {
|
|
141
|
+
defaultAgent,
|
|
142
|
+
previousDefaultAgent,
|
|
143
|
+
configPath: paths.globalConfigJsonPath,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
111
146
|
async hardReset() {
|
|
112
147
|
const paths = this.pathsProvider.getPaths();
|
|
113
148
|
const warnings = [];
|
|
@@ -277,14 +312,17 @@ export class OpenGoatService {
|
|
|
277
312
|
}
|
|
278
313
|
async createAgent(rawName, options = {}) {
|
|
279
314
|
const identity = this.agentService.normalizeAgentName(rawName);
|
|
280
|
-
const
|
|
315
|
+
const paths = this.pathsProvider.getPaths();
|
|
316
|
+
const defaultManagerAgentId = await this.resolveDefaultAgentId(paths, {
|
|
317
|
+
requireExisting: true,
|
|
318
|
+
});
|
|
319
|
+
const managerAgentId = resolveCreateAgentManagerId(identity.id, options.reportsTo, defaultManagerAgentId);
|
|
281
320
|
if (managerAgentId) {
|
|
282
321
|
await this.assertManagerSupportsReportees(managerAgentId);
|
|
283
322
|
}
|
|
284
|
-
const paths = this.pathsProvider.getPaths();
|
|
285
323
|
const created = await this.agentService.ensureAgent(paths, identity, {
|
|
286
324
|
type: options.type,
|
|
287
|
-
reportsTo: options.reportsTo,
|
|
325
|
+
reportsTo: options.reportsTo === undefined ? managerAgentId : options.reportsTo,
|
|
288
326
|
skills: options.skills,
|
|
289
327
|
role: options.role,
|
|
290
328
|
});
|
|
@@ -397,12 +435,15 @@ export class OpenGoatService {
|
|
|
397
435
|
};
|
|
398
436
|
}
|
|
399
437
|
async setAgentManager(rawAgentId, rawReportsTo) {
|
|
400
|
-
const
|
|
438
|
+
const paths = this.pathsProvider.getPaths();
|
|
439
|
+
const defaultManagerAgentId = await this.resolveDefaultAgentId(paths, {
|
|
440
|
+
requireExisting: true,
|
|
441
|
+
});
|
|
442
|
+
const managerAgentId = resolveCreateAgentManagerId(rawAgentId, rawReportsTo, defaultManagerAgentId);
|
|
401
443
|
if (managerAgentId) {
|
|
402
444
|
await this.assertManagerSupportsReportees(managerAgentId);
|
|
403
445
|
}
|
|
404
|
-
const
|
|
405
|
-
const updated = await this.agentService.setAgentManager(paths, rawAgentId, rawReportsTo);
|
|
446
|
+
const updated = await this.agentService.setAgentManager(paths, rawAgentId, managerAgentId);
|
|
406
447
|
await this.syncOpenClawRoleSkills(paths, updated.agentId);
|
|
407
448
|
if (updated.previousReportsTo) {
|
|
408
449
|
await this.syncOpenClawRoleSkills(paths, updated.previousReportsTo);
|
|
@@ -586,6 +627,9 @@ export class OpenGoatService {
|
|
|
586
627
|
}
|
|
587
628
|
async runTaskCronCycle(options = {}) {
|
|
588
629
|
const paths = this.pathsProvider.getPaths();
|
|
630
|
+
const defaultAgentId = await this.resolveDefaultAgentId(paths, {
|
|
631
|
+
requireExisting: true,
|
|
632
|
+
});
|
|
589
633
|
const ranAt = this.resolveNowIso();
|
|
590
634
|
const manifests = await this.agentManifestService.listManifests(paths);
|
|
591
635
|
const inProgressMinutes = resolveInProgressTimeoutMinutes(options.inProgressMinutes);
|
|
@@ -593,16 +637,16 @@ export class OpenGoatService {
|
|
|
593
637
|
const bottomUpStrategy = resolveBottomUpTaskDelegationStrategy(options);
|
|
594
638
|
const maxParallelFlows = resolveMaxParallelFlows(options.maxParallelFlows);
|
|
595
639
|
const inactiveCandidates = bottomUpStrategy.enabled
|
|
596
|
-
? await this.collectInactiveAgents(paths, manifests, bottomUpStrategy.inactiveMinutes, bottomUpStrategy.notificationTarget)
|
|
640
|
+
? await this.collectInactiveAgents(paths, manifests, bottomUpStrategy.inactiveMinutes, bottomUpStrategy.notificationTarget, defaultAgentId)
|
|
597
641
|
: [];
|
|
598
642
|
const tasks = await this.boardService.listTasks(paths, { limit: 10_000 });
|
|
599
643
|
const topDownDispatches = topDownStrategy.enabled
|
|
600
|
-
? await this.dispatchTopDownTaskDelegationAutomations(paths, tasks, manifests, topDownStrategy.openTasksThreshold, ranAt, maxParallelFlows)
|
|
644
|
+
? await this.dispatchTopDownTaskDelegationAutomations(paths, tasks, manifests, topDownStrategy.openTasksThreshold, ranAt, defaultAgentId, maxParallelFlows)
|
|
601
645
|
: [];
|
|
602
646
|
const pendingTaskIds = new Set(await this.boardService.listPendingTaskIdsOlderThan(paths, bottomUpStrategy.inactiveMinutes));
|
|
603
647
|
const doingTaskIds = new Set(await this.boardService.listDoingTaskIdsOlderThan(paths, inProgressMinutes));
|
|
604
|
-
const taskStatusDispatch = await this.dispatchTaskStatusAutomations(paths, tasks, manifests, doingTaskIds, pendingTaskIds, inProgressMinutes, bottomUpStrategy.inactiveMinutes, ranAt, maxParallelFlows);
|
|
605
|
-
const inactiveDispatches = await this.dispatchInactiveAgentAutomations(paths, inactiveCandidates, bottomUpStrategy.inactiveMinutes, ranAt, maxParallelFlows);
|
|
648
|
+
const taskStatusDispatch = await this.dispatchTaskStatusAutomations(paths, tasks, manifests, doingTaskIds, pendingTaskIds, inProgressMinutes, bottomUpStrategy.inactiveMinutes, ranAt, defaultAgentId, maxParallelFlows);
|
|
649
|
+
const inactiveDispatches = await this.dispatchInactiveAgentAutomations(paths, inactiveCandidates, bottomUpStrategy.inactiveMinutes, ranAt, defaultAgentId, maxParallelFlows);
|
|
606
650
|
const dispatches = [
|
|
607
651
|
...topDownDispatches,
|
|
608
652
|
...taskStatusDispatch.dispatches,
|
|
@@ -621,7 +665,7 @@ export class OpenGoatService {
|
|
|
621
665
|
dispatches,
|
|
622
666
|
};
|
|
623
667
|
}
|
|
624
|
-
async dispatchTopDownTaskDelegationAutomations(paths, tasks, manifests, openTasksThreshold, notificationTimestamp, maxParallelFlows = 1) {
|
|
668
|
+
async dispatchTopDownTaskDelegationAutomations(paths, tasks, manifests, openTasksThreshold, notificationTimestamp, defaultAgentId, maxParallelFlows = 1) {
|
|
625
669
|
const openTasks = tasks
|
|
626
670
|
.filter((task) => isTopDownOpenTaskStatus(task.status))
|
|
627
671
|
.sort((left, right) => {
|
|
@@ -642,8 +686,8 @@ export class OpenGoatService {
|
|
|
642
686
|
return [];
|
|
643
687
|
}
|
|
644
688
|
const managerAgents = manifests.filter((manifest) => manifest.metadata.type === "manager").length;
|
|
645
|
-
const ceoDirectReportees = manifests.filter((manifest) => normalizeAgentId(manifest.metadata.reportsTo ?? "") ===
|
|
646
|
-
const sessionRef = buildNotificationSessionRef(
|
|
689
|
+
const ceoDirectReportees = manifests.filter((manifest) => normalizeAgentId(manifest.metadata.reportsTo ?? "") === defaultAgentId).length;
|
|
690
|
+
const sessionRef = buildNotificationSessionRef(defaultAgentId);
|
|
647
691
|
const message = buildTopDownTaskDelegationMessage({
|
|
648
692
|
openTasksThreshold,
|
|
649
693
|
openTasksCount: openTasks.length,
|
|
@@ -660,7 +704,7 @@ export class OpenGoatService {
|
|
|
660
704
|
});
|
|
661
705
|
const requests = [
|
|
662
706
|
{
|
|
663
|
-
targetAgentId:
|
|
707
|
+
targetAgentId: defaultAgentId,
|
|
664
708
|
sessionRef,
|
|
665
709
|
message,
|
|
666
710
|
},
|
|
@@ -677,7 +721,7 @@ export class OpenGoatService {
|
|
|
677
721
|
};
|
|
678
722
|
});
|
|
679
723
|
}
|
|
680
|
-
async dispatchTaskStatusAutomations(paths, tasks, manifests, doingTaskIds, pendingTaskIds, doingMinutes, pendingMinutes, notificationTimestamp, maxParallelFlows) {
|
|
724
|
+
async dispatchTaskStatusAutomations(paths, tasks, manifests, doingTaskIds, pendingTaskIds, doingMinutes, pendingMinutes, notificationTimestamp, defaultAgentId, maxParallelFlows) {
|
|
681
725
|
const manifestsById = new Map(manifests.map((manifest) => [manifest.agentId, manifest]));
|
|
682
726
|
const requests = [];
|
|
683
727
|
let todoTasks = 0;
|
|
@@ -749,7 +793,7 @@ export class OpenGoatService {
|
|
|
749
793
|
blockedTasks += 1;
|
|
750
794
|
const assigneeManifest = manifestsById.get(task.assignedTo);
|
|
751
795
|
const managerAgentId = normalizeAgentId(assigneeManifest?.metadata.reportsTo ?? "") ||
|
|
752
|
-
|
|
796
|
+
defaultAgentId;
|
|
753
797
|
const sessionRef = buildNotificationSessionRef(managerAgentId);
|
|
754
798
|
const message = buildBlockedTaskMessage({
|
|
755
799
|
task,
|
|
@@ -764,7 +808,7 @@ export class OpenGoatService {
|
|
|
764
808
|
});
|
|
765
809
|
}
|
|
766
810
|
}
|
|
767
|
-
const dispatches = await runWithConcurrencyByKey(requests, maxParallelFlows, (request) => normalizeAgentId(request.targetAgentId) ||
|
|
811
|
+
const dispatches = await runWithConcurrencyByKey(requests, maxParallelFlows, (request) => normalizeAgentId(request.targetAgentId) || defaultAgentId, async (request) => {
|
|
768
812
|
const result = await this.dispatchAutomationMessage(paths, request.targetAgentId, request.sessionRef, request.message);
|
|
769
813
|
return {
|
|
770
814
|
kind: request.kind,
|
|
@@ -791,10 +835,10 @@ export class OpenGoatService {
|
|
|
791
835
|
blockedTasks,
|
|
792
836
|
};
|
|
793
837
|
}
|
|
794
|
-
async dispatchInactiveAgentAutomations(paths, inactiveCandidates, inactiveMinutes, notificationTimestamp, maxParallelFlows = 1) {
|
|
838
|
+
async dispatchInactiveAgentAutomations(paths, inactiveCandidates, inactiveMinutes, notificationTimestamp, defaultAgentId, maxParallelFlows = 1) {
|
|
795
839
|
const groupedCandidatesByManager = new Map();
|
|
796
840
|
for (const candidate of inactiveCandidates) {
|
|
797
|
-
const managerAgentId = normalizeAgentId(candidate.managerAgentId) ||
|
|
841
|
+
const managerAgentId = normalizeAgentId(candidate.managerAgentId) || defaultAgentId;
|
|
798
842
|
const bucket = groupedCandidatesByManager.get(managerAgentId) ?? [];
|
|
799
843
|
bucket.push(candidate);
|
|
800
844
|
groupedCandidatesByManager.set(managerAgentId, bucket);
|
|
@@ -830,9 +874,10 @@ export class OpenGoatService {
|
|
|
830
874
|
};
|
|
831
875
|
});
|
|
832
876
|
}
|
|
833
|
-
async listSkills(agentId
|
|
877
|
+
async listSkills(agentId) {
|
|
834
878
|
const paths = this.pathsProvider.getPaths();
|
|
835
|
-
|
|
879
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
880
|
+
return this.skillService.listSkills(paths, resolvedAgentId);
|
|
836
881
|
}
|
|
837
882
|
async listGlobalSkills() {
|
|
838
883
|
const paths = this.pathsProvider.getPaths();
|
|
@@ -840,11 +885,85 @@ export class OpenGoatService {
|
|
|
840
885
|
}
|
|
841
886
|
async installSkill(request) {
|
|
842
887
|
const paths = this.pathsProvider.getPaths();
|
|
843
|
-
const
|
|
844
|
-
if (
|
|
845
|
-
await this.
|
|
888
|
+
const scope = request.scope === "global" ? "global" : "agent";
|
|
889
|
+
if (scope === "agent") {
|
|
890
|
+
const normalizedAgentId = await this.resolveInputAgentId(paths, request.agentId);
|
|
891
|
+
const installOptions = await this.resolveAgentSkillInstallOptions(paths, normalizedAgentId);
|
|
892
|
+
const result = await this.skillService.installSkill(paths, {
|
|
893
|
+
...request,
|
|
894
|
+
scope: "agent",
|
|
895
|
+
agentId: normalizedAgentId,
|
|
896
|
+
}, installOptions);
|
|
897
|
+
await this.syncOpenClawRoleSkills(paths, normalizedAgentId);
|
|
898
|
+
return result;
|
|
899
|
+
}
|
|
900
|
+
const globalResult = await this.skillService.installSkill(paths, {
|
|
901
|
+
...request,
|
|
902
|
+
scope: "global",
|
|
903
|
+
});
|
|
904
|
+
if (!request.assignToAllAgents) {
|
|
905
|
+
return globalResult;
|
|
906
|
+
}
|
|
907
|
+
const agents = await this.agentService.listAgents(paths);
|
|
908
|
+
const assignedAgentIds = [];
|
|
909
|
+
const workspaceInstallPaths = [
|
|
910
|
+
...(globalResult.workspaceInstallPaths ?? []),
|
|
911
|
+
];
|
|
912
|
+
for (const agent of agents) {
|
|
913
|
+
const installOptions = await this.resolveAgentSkillInstallOptions(paths, agent.id);
|
|
914
|
+
const installedPaths = await this.skillService.assignInstalledSkillToAgent(paths, agent.id, globalResult.skillId, installOptions);
|
|
915
|
+
workspaceInstallPaths.push(...installedPaths);
|
|
916
|
+
assignedAgentIds.push(agent.id);
|
|
917
|
+
await this.syncOpenClawRoleSkills(paths, agent.id);
|
|
918
|
+
}
|
|
919
|
+
return {
|
|
920
|
+
...globalResult,
|
|
921
|
+
assignedAgentIds,
|
|
922
|
+
workspaceInstallPaths: [...new Set(workspaceInstallPaths)],
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
async removeSkill(request) {
|
|
926
|
+
const paths = this.pathsProvider.getPaths();
|
|
927
|
+
const scope = request.scope === "global" ? "global" : "agent";
|
|
928
|
+
if (scope === "agent") {
|
|
929
|
+
const normalizedAgentId = await this.resolveInputAgentId(paths, request.agentId);
|
|
930
|
+
const installOptions = await this.resolveAgentSkillInstallOptions(paths, normalizedAgentId);
|
|
931
|
+
const result = await this.skillService.removeSkill(paths, {
|
|
932
|
+
...request,
|
|
933
|
+
scope: "agent",
|
|
934
|
+
agentId: normalizedAgentId,
|
|
935
|
+
}, installOptions);
|
|
936
|
+
await this.syncOpenClawRoleSkills(paths, normalizedAgentId);
|
|
937
|
+
return result;
|
|
938
|
+
}
|
|
939
|
+
const globalResult = await this.skillService.removeSkill(paths, {
|
|
940
|
+
...request,
|
|
941
|
+
scope: "global",
|
|
942
|
+
});
|
|
943
|
+
const agents = await this.agentService.listAgents(paths);
|
|
944
|
+
const removedFromAgentIds = [];
|
|
945
|
+
const removedWorkspacePaths = [...globalResult.removedWorkspacePaths];
|
|
946
|
+
for (const agent of agents) {
|
|
947
|
+
const installOptions = await this.resolveAgentSkillInstallOptions(paths, agent.id);
|
|
948
|
+
const removed = await this.skillService.removeAssignedSkillFromAgent(paths, agent.id, globalResult.skillId, installOptions);
|
|
949
|
+
if (removed.removedFromConfig || removed.removedWorkspacePaths.length > 0) {
|
|
950
|
+
removedFromAgentIds.push(agent.id);
|
|
951
|
+
}
|
|
952
|
+
removedWorkspacePaths.push(...removed.removedWorkspacePaths);
|
|
953
|
+
await this.syncOpenClawRoleSkills(paths, agent.id);
|
|
846
954
|
}
|
|
847
|
-
return
|
|
955
|
+
return {
|
|
956
|
+
...globalResult,
|
|
957
|
+
removedFromAgentIds: [...new Set(removedFromAgentIds)],
|
|
958
|
+
removedWorkspacePaths: [...new Set(removedWorkspacePaths)],
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
async resolveAgentSkillInstallOptions(paths, agentId) {
|
|
962
|
+
const runtimeProfile = await this.providerService.getAgentRuntimeProfile(paths, agentId);
|
|
963
|
+
return {
|
|
964
|
+
workspaceDir: this.pathPort.join(paths.workspacesDir, runtimeProfile.agentId),
|
|
965
|
+
workspaceSkillDirectories: runtimeProfile.roleSkillDirectories,
|
|
966
|
+
};
|
|
848
967
|
}
|
|
849
968
|
async runOpenClaw(args, options = {}) {
|
|
850
969
|
if (!this.commandRunner) {
|
|
@@ -875,13 +994,15 @@ export class OpenGoatService {
|
|
|
875
994
|
throw error;
|
|
876
995
|
}
|
|
877
996
|
}
|
|
878
|
-
async listSessions(agentId
|
|
997
|
+
async listSessions(agentId, options = {}) {
|
|
879
998
|
const paths = this.pathsProvider.getPaths();
|
|
880
|
-
|
|
999
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1000
|
+
return this.sessionService.listSessions(paths, resolvedAgentId, options);
|
|
881
1001
|
}
|
|
882
|
-
async prepareSession(agentId
|
|
1002
|
+
async prepareSession(agentId, options = {}) {
|
|
883
1003
|
const paths = this.pathsProvider.getPaths();
|
|
884
|
-
const
|
|
1004
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1005
|
+
const prepared = await this.sessionService.prepareRunSession(paths, resolvedAgentId, {
|
|
885
1006
|
sessionRef: options.sessionRef,
|
|
886
1007
|
forceNew: options.forceNew,
|
|
887
1008
|
userMessage: "",
|
|
@@ -891,29 +1012,35 @@ export class OpenGoatService {
|
|
|
891
1012
|
}
|
|
892
1013
|
return prepared.info;
|
|
893
1014
|
}
|
|
894
|
-
async getAgentLastAction(agentId
|
|
1015
|
+
async getAgentLastAction(agentId) {
|
|
895
1016
|
const paths = this.pathsProvider.getPaths();
|
|
896
|
-
|
|
1017
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1018
|
+
return this.sessionService.getLastAgentAction(paths, resolvedAgentId);
|
|
897
1019
|
}
|
|
898
|
-
async getSessionHistory(agentId
|
|
1020
|
+
async getSessionHistory(agentId, options = {}) {
|
|
899
1021
|
const paths = this.pathsProvider.getPaths();
|
|
900
|
-
|
|
1022
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1023
|
+
return this.sessionService.getSessionHistory(paths, resolvedAgentId, options);
|
|
901
1024
|
}
|
|
902
|
-
async resetSession(agentId
|
|
1025
|
+
async resetSession(agentId, sessionRef) {
|
|
903
1026
|
const paths = this.pathsProvider.getPaths();
|
|
904
|
-
|
|
1027
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1028
|
+
return this.sessionService.resetSession(paths, resolvedAgentId, sessionRef);
|
|
905
1029
|
}
|
|
906
|
-
async compactSession(agentId
|
|
1030
|
+
async compactSession(agentId, sessionRef) {
|
|
907
1031
|
const paths = this.pathsProvider.getPaths();
|
|
908
|
-
|
|
1032
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1033
|
+
return this.sessionService.compactSession(paths, resolvedAgentId, sessionRef);
|
|
909
1034
|
}
|
|
910
|
-
async renameSession(agentId
|
|
1035
|
+
async renameSession(agentId, title = "", sessionRef) {
|
|
911
1036
|
const paths = this.pathsProvider.getPaths();
|
|
912
|
-
|
|
1037
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1038
|
+
return this.sessionService.renameSession(paths, resolvedAgentId, title, sessionRef);
|
|
913
1039
|
}
|
|
914
|
-
async removeSession(agentId
|
|
1040
|
+
async removeSession(agentId, sessionRef) {
|
|
915
1041
|
const paths = this.pathsProvider.getPaths();
|
|
916
|
-
|
|
1042
|
+
const resolvedAgentId = await this.resolveInputAgentId(paths, agentId);
|
|
1043
|
+
return this.sessionService.removeSession(paths, resolvedAgentId, sessionRef);
|
|
917
1044
|
}
|
|
918
1045
|
getHomeDir() {
|
|
919
1046
|
return this.pathsProvider.getPaths().homeDir;
|
|
@@ -972,6 +1099,53 @@ export class OpenGoatService {
|
|
|
972
1099
|
resolveNowIso() {
|
|
973
1100
|
return this.nowIso();
|
|
974
1101
|
}
|
|
1102
|
+
async resolveInputAgentId(paths, requestedAgentId) {
|
|
1103
|
+
const normalizedRequested = normalizeAgentId(requestedAgentId ?? "");
|
|
1104
|
+
if (normalizedRequested) {
|
|
1105
|
+
return normalizedRequested;
|
|
1106
|
+
}
|
|
1107
|
+
return this.resolveDefaultAgentId(paths, { requireExisting: true });
|
|
1108
|
+
}
|
|
1109
|
+
async resolveDefaultAgentId(paths, options) {
|
|
1110
|
+
const envDefaultAgent = normalizeAgentId(process.env[OPENGOAT_DEFAULT_AGENT_ENV] ?? "");
|
|
1111
|
+
const configDefaultAgent = normalizeAgentId((await this.readGlobalConfig(paths))?.defaultAgent ?? "");
|
|
1112
|
+
const candidates = dedupeStrings([
|
|
1113
|
+
envDefaultAgent,
|
|
1114
|
+
configDefaultAgent,
|
|
1115
|
+
DEFAULT_AGENT_ID,
|
|
1116
|
+
]);
|
|
1117
|
+
if (!options.requireExisting) {
|
|
1118
|
+
return candidates[0] ?? DEFAULT_AGENT_ID;
|
|
1119
|
+
}
|
|
1120
|
+
let knownAgentIds;
|
|
1121
|
+
try {
|
|
1122
|
+
knownAgentIds = new Set((await this.agentService.listAgents(paths)).map((agent) => agent.id));
|
|
1123
|
+
}
|
|
1124
|
+
catch {
|
|
1125
|
+
return candidates[0] ?? DEFAULT_AGENT_ID;
|
|
1126
|
+
}
|
|
1127
|
+
for (const candidate of candidates) {
|
|
1128
|
+
if (knownAgentIds.has(candidate)) {
|
|
1129
|
+
return candidate;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return DEFAULT_AGENT_ID;
|
|
1133
|
+
}
|
|
1134
|
+
async readGlobalConfig(paths) {
|
|
1135
|
+
return this.readJsonFileIfPresent(paths.globalConfigJsonPath);
|
|
1136
|
+
}
|
|
1137
|
+
async readJsonFileIfPresent(filePath) {
|
|
1138
|
+
if (!(await this.fileSystem.exists(filePath))) {
|
|
1139
|
+
return null;
|
|
1140
|
+
}
|
|
1141
|
+
try {
|
|
1142
|
+
const raw = await this.fileSystem.readFile(filePath);
|
|
1143
|
+
return JSON.parse(raw);
|
|
1144
|
+
}
|
|
1145
|
+
catch {
|
|
1146
|
+
return null;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
975
1149
|
async initializeRuntimeDefaults(options) {
|
|
976
1150
|
const initialization = await this.bootstrapService.initialize();
|
|
977
1151
|
if (options.syncRuntimeDefaults) {
|
|
@@ -982,7 +1156,13 @@ export class OpenGoatService {
|
|
|
982
1156
|
// Startup remains functional even if OpenClaw CLI/runtime is unavailable.
|
|
983
1157
|
}
|
|
984
1158
|
}
|
|
985
|
-
|
|
1159
|
+
const defaultAgent = await this.resolveDefaultAgentId(initialization.paths, {
|
|
1160
|
+
requireExisting: true,
|
|
1161
|
+
});
|
|
1162
|
+
return {
|
|
1163
|
+
...initialization,
|
|
1164
|
+
defaultAgent,
|
|
1165
|
+
};
|
|
986
1166
|
}
|
|
987
1167
|
resolveNowMs() {
|
|
988
1168
|
return Date.now();
|
|
@@ -1465,7 +1645,7 @@ export class OpenGoatService {
|
|
|
1465
1645
|
...process.env,
|
|
1466
1646
|
};
|
|
1467
1647
|
}
|
|
1468
|
-
async collectInactiveAgents(paths, manifests, inactiveMinutes, notificationTarget) {
|
|
1648
|
+
async collectInactiveAgents(paths, manifests, inactiveMinutes, notificationTarget, defaultAgentId) {
|
|
1469
1649
|
const nowMs = this.resolveNowMs();
|
|
1470
1650
|
const inactiveCutoffMs = nowMs - inactiveMinutes * 60_000;
|
|
1471
1651
|
const reporteeStats = buildReporteeStats(manifests);
|
|
@@ -1476,7 +1656,7 @@ export class OpenGoatService {
|
|
|
1476
1656
|
continue;
|
|
1477
1657
|
}
|
|
1478
1658
|
if (notificationTarget === "ceo-only" &&
|
|
1479
|
-
managerAgentId !==
|
|
1659
|
+
managerAgentId !== defaultAgentId) {
|
|
1480
1660
|
continue;
|
|
1481
1661
|
}
|
|
1482
1662
|
const lastAction = await this.sessionService.getLastAgentAction(paths, manifest.agentId);
|
|
@@ -1710,17 +1890,17 @@ function extractBalancedJsonCandidate(raw, startIndex) {
|
|
|
1710
1890
|
function dedupeNumbers(values) {
|
|
1711
1891
|
return [...new Set(values)];
|
|
1712
1892
|
}
|
|
1713
|
-
function resolveCreateAgentManagerId(agentId, reportsTo) {
|
|
1893
|
+
function resolveCreateAgentManagerId(agentId, reportsTo, defaultManagerAgentId) {
|
|
1714
1894
|
const normalizedAgentId = normalizeAgentId(agentId);
|
|
1715
1895
|
if (isDefaultAgentId(normalizedAgentId)) {
|
|
1716
1896
|
return null;
|
|
1717
1897
|
}
|
|
1718
1898
|
if (reportsTo === null || reportsTo === undefined) {
|
|
1719
|
-
return
|
|
1899
|
+
return defaultManagerAgentId;
|
|
1720
1900
|
}
|
|
1721
1901
|
const normalizedManagerId = normalizeAgentId(reportsTo);
|
|
1722
1902
|
if (!normalizedManagerId || normalizedManagerId === normalizedAgentId) {
|
|
1723
|
-
return
|
|
1903
|
+
return defaultManagerAgentId;
|
|
1724
1904
|
}
|
|
1725
1905
|
return normalizedManagerId;
|
|
1726
1906
|
}
|