plugin-agent-orchestrator 1.1.2 → 1.1.4

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.
Files changed (173) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/client-v2/214.b063f33ba044a808.js +10 -0
  3. package/dist/client-v2/253.59577b40d9875be0.js +10 -0
  4. package/dist/client-v2/264.7ed8bee71fa5935c.js +10 -0
  5. package/dist/client-v2/{41.ba6e080cc0488143.js → 41.3deb9e57a0f64fc4.js} +1 -1
  6. package/dist/client-v2/418.58fa350f5496efd3.js +10 -0
  7. package/dist/client-v2/{53.7c29c28043e9112d.js → 53.9a10455323390f14.js} +1 -1
  8. package/dist/client-v2/619.0a2144aaffefe018.js +10 -0
  9. package/dist/client-v2/{70.bda9518881c05360.js → 70.ffff2997c10fd4b0.js} +1 -1
  10. package/dist/client-v2/{794.9bbb8d3a61b2bdf2.js → 794.a67a2614405ba627.js} +1 -1
  11. package/dist/client-v2/925.e5925bf21ed68e7a.js +10 -0
  12. package/dist/client-v2/{993.82778b6fd6db3cb1.js → 993.b0688fdc5ccb000a.js} +1 -1
  13. package/dist/client-v2/index.js +1 -1
  14. package/dist/externalVersion.js +8 -6
  15. package/dist/locale/en-US.json +48 -28
  16. package/dist/locale/vi-VN.json +48 -28
  17. package/dist/locale/zh-CN.json +48 -28
  18. package/dist/server/collections/agent-execution-spans.js +47 -0
  19. package/dist/server/collections/agent-harness-profile-versions.js +56 -0
  20. package/dist/server/collections/agent-harness-profiles.js +12 -0
  21. package/dist/server/collections/agent-loop-action-approvals.js +68 -0
  22. package/dist/server/collections/agent-loop-artifacts.js +55 -0
  23. package/dist/server/collections/agent-loop-circuit-states.js +53 -0
  24. package/dist/server/collections/agent-loop-control-settings.js +51 -0
  25. package/dist/server/collections/agent-loop-events.js +27 -0
  26. package/dist/server/collections/agent-loop-path-locks.js +57 -0
  27. package/dist/server/collections/agent-loop-patterns.js +72 -0
  28. package/dist/server/collections/agent-loop-runs.js +163 -2
  29. package/dist/server/collections/agent-loop-steps.js +69 -0
  30. package/dist/server/collections/agent-loop-usage-buckets.js +52 -0
  31. package/dist/server/collections/agent-loop-worktrees.js +55 -0
  32. package/dist/server/migrations/{20260427000000-change-packages-to-text.js → 20260427000002-change-packages-to-text.js} +2 -0
  33. package/dist/server/migrations/20260429000000-add-llm-fields.js +3 -2
  34. package/dist/server/migrations/{20260429000000-fix-inputargs-json-to-text.js → 20260429000001-fix-inputargs-json-to-text.js} +14 -6
  35. package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +2 -1
  36. package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +2 -1
  37. package/dist/server/migrations/20260803010000-backfill-loop-control-plane-data.js +262 -0
  38. package/dist/server/plugin.js +52 -150
  39. package/dist/server/resources/agent-loop-approval.js +83 -0
  40. package/dist/server/resources/agent-loop-artifact.js +86 -0
  41. package/dist/server/resources/agent-loop-events-stream.js +130 -0
  42. package/dist/server/resources/agent-loop.js +181 -139
  43. package/dist/server/resources/resource-helpers.js +63 -0
  44. package/dist/server/resources/tracing.js +121 -107
  45. package/dist/server/services/DurableCircuitBreakerService.js +229 -0
  46. package/dist/server/services/HarnessCompiler.js +142 -0
  47. package/dist/server/services/HarnessProfileService.js +168 -0
  48. package/dist/server/services/HarnessSchema.js +167 -0
  49. package/dist/server/services/LoopBudgetService.js +269 -0
  50. package/dist/server/services/LoopControlService.js +139 -0
  51. package/dist/server/services/LoopPatternSchema.js +180 -0
  52. package/dist/server/services/LoopPatternService.js +132 -0
  53. package/dist/server/services/LoopRunRepository.js +205 -0
  54. package/dist/server/services/LoopRunStateMachine.js +389 -0
  55. package/dist/server/services/LoopSchedulerService.js +193 -0
  56. package/dist/server/services/LoopTriggerService.js +128 -0
  57. package/dist/server/services/LoopWorkerService.js +461 -0
  58. package/dist/server/services/PathLockService.js +288 -0
  59. package/dist/server/services/PluginAiRuntimeAdapter.js +215 -0
  60. package/dist/server/services/VerificationSchema.js +59 -0
  61. package/dist/server/services/VerificationService.js +169 -0
  62. package/dist/server/skill-hub/actions/git-import.js +13 -7
  63. package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +1 -5
  64. package/dist/server/utils/ensure-indexes.js +111 -0
  65. package/dist/server/utils/loop-pattern-context.js +56 -0
  66. package/package.json +2 -2
  67. package/src/client/OrchestratorSettings.tsx +44 -0
  68. package/src/client-v2/components/AgentRunsTab.tsx +576 -494
  69. package/src/client-v2/components/HarnessProfilesTab.tsx +13 -8
  70. package/src/client-v2/components/MemoryInspectorTab.tsx +19 -3
  71. package/src/client-v2/components/TracingTab.tsx +515 -432
  72. package/src/client-v2/hooks/useApiRequest.ts +141 -121
  73. package/src/client-v2/skill-hub/components/SkillMetrics.tsx +8 -6
  74. package/src/locale/en-US.json +52 -28
  75. package/src/locale/vi-VN.json +52 -28
  76. package/src/locale/zh-CN.json +52 -28
  77. package/src/server/__tests__/circuit-breaker.test.ts +225 -146
  78. package/src/server/__tests__/harness-compiler.test.ts +131 -0
  79. package/src/server/__tests__/harness-profile-service.test.ts +116 -0
  80. package/src/server/__tests__/harness-tool-plan.test.ts +148 -0
  81. package/src/server/__tests__/loop-budget-service.test.ts +255 -0
  82. package/src/server/__tests__/loop-control-plane-backfill.test.ts +266 -0
  83. package/src/server/__tests__/loop-pattern-schema.test.ts +56 -0
  84. package/src/server/__tests__/loop-pattern-service.test.ts +148 -0
  85. package/src/server/__tests__/loop-run-state-machine.test.ts +90 -0
  86. package/src/server/__tests__/loop-worker-claim.test.ts +341 -0
  87. package/src/server/__tests__/loop-worker-execution.test.ts +236 -0
  88. package/src/server/__tests__/path-lock-service.test.ts +254 -0
  89. package/src/server/__tests__/smoke.test.ts +62 -21
  90. package/src/server/collections/agent-execution-spans.ts +47 -0
  91. package/src/server/collections/agent-harness-profile-versions.ts +26 -0
  92. package/src/server/collections/agent-harness-profiles.ts +12 -0
  93. package/src/server/collections/agent-loop-action-approvals.ts +38 -0
  94. package/src/server/collections/agent-loop-artifacts.ts +25 -0
  95. package/src/server/collections/agent-loop-circuit-states.ts +23 -0
  96. package/src/server/collections/agent-loop-control-settings.ts +21 -0
  97. package/src/server/collections/agent-loop-events.ts +27 -0
  98. package/src/server/collections/agent-loop-path-locks.ts +27 -0
  99. package/src/server/collections/agent-loop-patterns.ts +42 -0
  100. package/src/server/collections/agent-loop-runs.ts +163 -2
  101. package/src/server/collections/agent-loop-steps.ts +69 -0
  102. package/src/server/collections/agent-loop-usage-buckets.ts +22 -0
  103. package/src/server/collections/agent-loop-worktrees.ts +25 -0
  104. package/src/server/migrations/{20260427000000-change-packages-to-text.ts → 20260427000002-change-packages-to-text.ts} +3 -0
  105. package/src/server/migrations/20260429000000-add-llm-fields.ts +3 -2
  106. package/src/server/migrations/{20260429000000-fix-inputargs-json-to-text.ts → 20260429000001-fix-inputargs-json-to-text.ts} +13 -6
  107. package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +2 -1
  108. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +2 -1
  109. package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -0
  110. package/src/server/plugin.ts +53 -167
  111. package/src/server/resources/agent-loop-approval.ts +52 -0
  112. package/src/server/resources/agent-loop-artifact.ts +56 -0
  113. package/src/server/resources/agent-loop-events-stream.ts +105 -0
  114. package/src/server/resources/agent-loop.ts +202 -143
  115. package/src/server/resources/agent-monitor.ts +482 -482
  116. package/src/server/resources/resource-helpers.ts +33 -0
  117. package/src/server/resources/tracing.ts +145 -137
  118. package/src/server/services/DurableCircuitBreakerService.ts +239 -0
  119. package/src/server/services/HarnessCompiler.ts +133 -0
  120. package/src/server/services/HarnessProfileService.ts +157 -0
  121. package/src/server/services/HarnessSchema.ts +163 -0
  122. package/src/server/services/LoopBudgetService.ts +275 -0
  123. package/src/server/services/LoopControlService.ts +124 -0
  124. package/src/server/services/LoopPatternSchema.ts +167 -0
  125. package/src/server/services/LoopPatternService.ts +143 -0
  126. package/src/server/services/LoopRunRepository.ts +237 -0
  127. package/src/server/services/LoopRunStateMachine.ts +432 -0
  128. package/src/server/services/LoopSchedulerService.ts +199 -0
  129. package/src/server/services/LoopTriggerService.ts +115 -0
  130. package/src/server/services/LoopWorkerService.ts +522 -0
  131. package/src/server/services/PathLockService.ts +321 -0
  132. package/src/server/services/PluginAiRuntimeAdapter.ts +315 -0
  133. package/src/server/services/VerificationSchema.ts +31 -0
  134. package/src/server/services/VerificationService.ts +185 -0
  135. package/src/server/skill-hub/actions/__tests__/git-import.test.ts +62 -0
  136. package/src/server/skill-hub/actions/git-import.ts +9 -3
  137. package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +1 -5
  138. package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +1 -3
  139. package/src/server/utils/ensure-indexes.ts +96 -0
  140. package/src/server/utils/logging.ts +0 -1
  141. package/src/server/utils/loop-pattern-context.ts +20 -0
  142. package/dist/client-v2/214.79650a549273f163.js +0 -10
  143. package/dist/client-v2/253.9f0537713cee9e6c.js +0 -10
  144. package/dist/client-v2/264.718a107e43fc163c.js +0 -10
  145. package/dist/client-v2/418.ce8f5b2b8a229d1d.js +0 -10
  146. package/dist/client-v2/619.bd3c5698b40705c3.js +0 -10
  147. package/dist/client-v2/925.f5370de8f6632d65.js +0 -10
  148. package/dist/server/services/AgentHarness.js +0 -81
  149. package/dist/server/services/AgentLoopController.js +0 -1023
  150. package/dist/server/services/AgentLoopRepository.js +0 -192
  151. package/dist/server/services/AgentLoopService.js +0 -142
  152. package/dist/server/services/AgentPlanValidator.js +0 -99
  153. package/dist/server/services/AgentPlannerService.js +0 -99
  154. package/dist/server/services/CircuitBreaker.js +0 -125
  155. package/dist/server/services/ContextAggregator.js +0 -201
  156. package/dist/server/services/PlanningPromptService.js +0 -95
  157. package/dist/server/tools/agent-loop.js +0 -373
  158. package/dist/server/tools/orchestrator-plan.js +0 -254
  159. package/src/server/__tests__/agent-loop-controller.test.ts +0 -375
  160. package/src/server/__tests__/context-aggregator.test.ts +0 -222
  161. package/src/server/__tests__/parallel-execution.test.ts +0 -318
  162. package/src/server/__tests__/planning-prompt-service.test.ts +0 -23
  163. package/src/server/services/AgentHarness.ts +0 -67
  164. package/src/server/services/AgentLoopController.ts +0 -1263
  165. package/src/server/services/AgentLoopRepository.ts +0 -178
  166. package/src/server/services/AgentLoopService.ts +0 -177
  167. package/src/server/services/AgentPlanValidator.ts +0 -73
  168. package/src/server/services/AgentPlannerService.ts +0 -80
  169. package/src/server/services/CircuitBreaker.ts +0 -126
  170. package/src/server/services/ContextAggregator.ts +0 -239
  171. package/src/server/services/PlanningPromptService.ts +0 -72
  172. package/src/server/tools/agent-loop.ts +0 -360
  173. package/src/server/tools/orchestrator-plan.ts +0 -255
@@ -1,178 +0,0 @@
1
- import { toPlain, trimText } from '../utils/ctx-utils';
2
- import { getRunEventBus } from './RunEventBus';
3
-
4
- export class AgentLoopRepository {
5
- constructor(private readonly plugin: any) {}
6
-
7
- get db() {
8
- return this.plugin.db;
9
- }
10
-
11
- async getRun(runId: string | number) {
12
- const run = await this.db.getRepository('agentLoopRuns').findOne({
13
- filter: { id: runId },
14
- });
15
- return run ? toPlain(run) : null;
16
- }
17
-
18
- async requireRun(runId: string | number) {
19
- const run = await this.getRun(runId);
20
- if (!run) {
21
- throw new Error(`Agent loop run "${runId}" was not found.`);
22
- }
23
- return run;
24
- }
25
-
26
- async createRun(values: any) {
27
- const run = await this.db.getRepository('agentLoopRuns').create({
28
- values,
29
- });
30
- return toPlain(run);
31
- }
32
-
33
- async updateRun(runId: string | number, values: any) {
34
- await this.db.getRepository('agentLoopRuns').update({
35
- filterByTk: runId,
36
- values,
37
- });
38
- }
39
-
40
- async getStep(stepId: string | number) {
41
- const step = await this.db.getRepository('agentLoopSteps').findOne({
42
- filter: { id: stepId },
43
- });
44
- return step ? toPlain(step) : null;
45
- }
46
-
47
- async requireStep(stepId: string | number) {
48
- const step = await this.getStep(stepId);
49
- if (!step) {
50
- throw new Error(`Agent loop step "${stepId}" was not found.`);
51
- }
52
- return step;
53
- }
54
-
55
- async createStep(values: any) {
56
- const step = await this.db.getRepository('agentLoopSteps').create({
57
- values,
58
- });
59
- return toPlain(step);
60
- }
61
-
62
- async updateStep(stepId: string | number, values: any) {
63
- await this.db.getRepository('agentLoopSteps').update({
64
- filterByTk: stepId,
65
- values,
66
- });
67
- }
68
-
69
- async getSteps(runId: string | number) {
70
- const steps = await this.db.getRepository('agentLoopSteps').find({
71
- filter: { runId },
72
- sort: ['index', 'createdAt'],
73
- pageSize: 1000,
74
- });
75
- return steps.map(toPlain);
76
- }
77
-
78
- async createEvent(values: any) {
79
- const record = await this.db.getRepository('agentLoopEvents').create({
80
- values: {
81
- ...values,
82
- content: trimText(values.content || '', 10000),
83
- payload: values.payload || {},
84
- createdAt: new Date(),
85
- },
86
- });
87
- const event = toPlain(record);
88
- // Push event to SSE subscribers
89
- getRunEventBus().emit(values.runId, event);
90
- return event;
91
- }
92
-
93
- async getEvents(runId: string | number) {
94
- const events = await this.db.getRepository('agentLoopEvents').find({
95
- filter: { runId },
96
- sort: ['createdAt'],
97
- pageSize: 500,
98
- });
99
- return events.map(toPlain);
100
- }
101
-
102
- async getLinkedSpans(runId: string | number, rootRunId?: string) {
103
- const repo = this.db.getRepository('agentExecutionSpans');
104
- if (!repo) return [];
105
- const filters = [];
106
- if (rootRunId) filters.push({ rootRunId });
107
- filters.push({ 'metadata.agentLoopRunId': String(runId) });
108
- try {
109
- const rows = await repo.find({
110
- filter: { $or: filters },
111
- sort: ['createdAt'],
112
- pageSize: 1000,
113
- });
114
- return rows.map(toPlain);
115
- } catch {
116
- if (!rootRunId) return [];
117
- const rows = await repo.find({
118
- filter: { rootRunId },
119
- sort: ['createdAt'],
120
- pageSize: 1000,
121
- });
122
- return rows.map(toPlain);
123
- }
124
- }
125
-
126
- async getLinkedSkillExecutions(runId: string | number, steps: any[]) {
127
- const ids = Array.from(
128
- new Set(
129
- steps
130
- .map((step) => step.skillExecutionId)
131
- .filter(Boolean)
132
- .map(String),
133
- ),
134
- );
135
- const repo = this.db.getRepository('skillExecutions');
136
- if (!repo) return [];
137
- const filters: any[] = [{ agentLoopRunId: String(runId) }];
138
- if (ids.length) {
139
- filters.push({ id: { $in: ids } });
140
- }
141
- const rows = await repo.find({
142
- filter: { $or: filters },
143
- sort: ['createdAt'],
144
- pageSize: 1000,
145
- });
146
- return rows.map(toPlain);
147
- }
148
-
149
- async lockRun(runId: string | number, lockName: string, durationMs: number): Promise<boolean> {
150
- const repo = this.db.getRepository('agentLoopRuns');
151
- if (!repo) return false;
152
- const now = new Date();
153
- const Op = repo.model.sequelize.Sequelize.Op;
154
-
155
- const result = await repo.model.update(
156
- {
157
- lockedBy: lockName,
158
- lockedUntil: new Date(now.getTime() + durationMs),
159
- },
160
- {
161
- where: {
162
- id: runId,
163
- [Op.or]: [{ lockedBy: null }, { lockedUntil: { [Op.lt]: now.toISOString() } }, { lockedBy: lockName }],
164
- },
165
- },
166
- );
167
-
168
- const affectedCount = Array.isArray(result) ? result[0] : Number(result || 0);
169
- return affectedCount > 0;
170
- }
171
-
172
- async unlockRun(runId: string | number) {
173
- await this.updateRun(runId, {
174
- lockedBy: null,
175
- lockedUntil: null,
176
- });
177
- }
178
- }
@@ -1,177 +0,0 @@
1
- import { AgentRegistryService } from './AgentRegistryService';
2
- import { AgentPlannerService } from './AgentPlannerService';
3
- import { AgentPlanValidator } from './AgentPlanValidator';
4
- import { AgentLoopRepository } from './AgentLoopRepository';
5
- import { AgentHarness } from './AgentHarness';
6
- import { AgentLoopController } from './AgentLoopController';
7
- import { TokenTracker } from './TokenTracker';
8
-
9
- export type AgentLoopRunStatus =
10
- | 'planning'
11
- | 'waiting_plan_approval'
12
- | 'approved'
13
- | 'running'
14
- | 'waiting_user'
15
- | 'needs_replan'
16
- | 'succeeded'
17
- | 'failed'
18
- | 'rejected'
19
- | 'canceled';
20
- export type AgentLoopStepStatus = 'pending' | 'running' | 'waiting_user' | 'succeeded' | 'failed' | 'skipped';
21
- export type AgentLoopStepType = 'reasoning' | 'skill' | 'tool' | 'sub_agent' | 'verification';
22
- export type AgentLoopStepDependencyPolicy = 'require_success' | 'allow_skipped';
23
-
24
- export type AgentLoopPolicy = {
25
- maxIterations: number;
26
- maxStepAttempts: number;
27
- allowReplan: boolean;
28
- requireVerification: boolean;
29
- stopOnApprovalRequired: boolean;
30
- maxContextTokens?: number;
31
- contextSummaryStrategy?: 'last_n' | 'all';
32
- includeToolResults?: boolean;
33
- includeStepOutputs?: boolean;
34
- maxConcurrency?: number;
35
- };
36
-
37
- export type AgentLoopPlanStepInput = {
38
- id?: string;
39
- key?: string;
40
- planKey?: string;
41
- parentStepId?: string | number;
42
- title?: string;
43
- description?: string;
44
- type?: AgentLoopStepType;
45
- target?: string;
46
- input?: any;
47
- dependsOn?: string[];
48
- dependencyPolicy?: AgentLoopStepDependencyPolicy;
49
- maxAttempts?: number;
50
- metadata?: any;
51
- };
52
-
53
- export class AgentLoopService {
54
- public readonly registryService: AgentRegistryService;
55
- public readonly plannerService: AgentPlannerService;
56
- public readonly validator: AgentPlanValidator;
57
- public readonly repository: AgentLoopRepository;
58
- public readonly harness: AgentHarness;
59
- public readonly controller: AgentLoopController;
60
-
61
- constructor(private readonly plugin: any) {
62
- this.registryService = new AgentRegistryService(plugin);
63
- this.plannerService = new AgentPlannerService();
64
- this.validator = new AgentPlanValidator();
65
- this.repository = new AgentLoopRepository(plugin);
66
- const tokenTracker = new TokenTracker(plugin);
67
- this.harness = new AgentHarness(plugin, this.registryService, tokenTracker);
68
- this.controller = new AgentLoopController(
69
- this.registryService,
70
- this.plannerService,
71
- this.validator,
72
- this.repository,
73
- this.harness,
74
- tokenTracker,
75
- );
76
- }
77
-
78
- get db() {
79
- return this.plugin.db;
80
- }
81
-
82
- get app() {
83
- return this.plugin.app;
84
- }
85
-
86
- async createRun(options: any) {
87
- return this.controller.createRun(options);
88
- }
89
-
90
- async planGoal(options: any) {
91
- return this.controller.planGoal(options);
92
- }
93
-
94
- async revisePlanGoal(runId: any, plan: any, options: any = {}) {
95
- return this.controller.revisePlanGoal(runId, plan, options);
96
- }
97
-
98
- async approvePlan(runId: any, options: any = {}) {
99
- return this.controller.approvePlan(runId, options);
100
- }
101
-
102
- async approvePlanAndExecute(runId: any, options: any = {}) {
103
- return this.controller.approvePlanAndExecute(runId, options);
104
- }
105
-
106
- async rejectPlan(runId: any, options: any = {}) {
107
- return this.controller.rejectPlan(runId, options);
108
- }
109
-
110
- async requestPlanChanges(runId: any, options: any = {}) {
111
- return this.controller.requestPlanChanges(runId, options);
112
- }
113
-
114
- async replacePlan(runId: any, plan: any, options: any = {}) {
115
- return this.controller.replacePlan(runId, plan, options);
116
- }
117
-
118
- async replan(runId: any, plan: any, options: any = {}) {
119
- return this.controller.replan(runId, plan, options);
120
- }
121
-
122
- async startStep(stepId: any, options: any = {}) {
123
- return this.controller.startStep(stepId, options);
124
- }
125
-
126
- async completeStep(stepId: any, output: any, options: any = {}) {
127
- return this.controller.completeStep(stepId, output, options);
128
- }
129
-
130
- async failStep(stepId: any, error: any, options: any = {}) {
131
- return this.controller.failStep(stepId, error, options);
132
- }
133
-
134
- async skipStep(stepId: any, reason: any = 'Skipped', options: any = {}) {
135
- return this.controller.skipStep(stepId, reason, options);
136
- }
137
-
138
- async requestApproval(stepId: any, approval: any, options: any = {}) {
139
- return this.controller.requestApproval(stepId, approval, options);
140
- }
141
-
142
- async resumeRun(runId: any, options: any) {
143
- return this.controller.resumeRun(runId, options);
144
- }
145
-
146
- async retryStep(stepId: any, options: any = {}) {
147
- return this.controller.retryStep(stepId, options);
148
- }
149
-
150
- async stepFeedback(stepId: any, feedback: any, options: any = {}) {
151
- return this.controller.stepFeedback(stepId, feedback, options);
152
- }
153
-
154
- async finishRun(runId: any, finalAnswer: any, options: any = {}) {
155
- return this.controller.finishRun(runId, finalAnswer, options);
156
- }
157
-
158
- async cancelRun(runId: any, options: any = {}) {
159
- return this.controller.cancelRun(runId, options);
160
- }
161
-
162
- async executeApprovedPlan(runId: any, options: any = {}) {
163
- return this.controller.executeApprovedPlan(runId, options);
164
- }
165
-
166
- async getRunSnapshot(runId: any) {
167
- return this.controller.getRunSnapshot(runId);
168
- }
169
-
170
- async getRunDetail(runId: any) {
171
- return this.controller.getRunDetail(runId);
172
- }
173
-
174
- async createEvent(values: any) {
175
- return this.repository.createEvent(values);
176
- }
177
- }
@@ -1,73 +0,0 @@
1
- import { AgentLoopPlanStepInput } from './AgentLoopService';
2
-
3
- function normalizeStepType(value: any) {
4
- return ['reasoning', 'skill', 'tool', 'sub_agent', 'verification'].includes(value) ? value : 'tool';
5
- }
6
-
7
- function normalizePlanKey(step: any, index: number) {
8
- return String(step.planKey || step.key || step.id || `step_${index + 1}`);
9
- }
10
-
11
- function asArray(value: any): any[] {
12
- return Array.isArray(value) ? value : [];
13
- }
14
-
15
- const ORCHESTRATOR_CONTROLLER_MAX_STEPS = 100;
16
-
17
- export class AgentPlanValidator {
18
- validate(plan: AgentLoopPlanStepInput[]) {
19
- if (!Array.isArray(plan) || plan.length === 0) {
20
- throw new Error('Plan must include at least one step.');
21
- }
22
- if (plan.length > ORCHESTRATOR_CONTROLLER_MAX_STEPS) {
23
- throw new Error(`Plan cannot exceed ${ORCHESTRATOR_CONTROLLER_MAX_STEPS} steps.`);
24
- }
25
-
26
- const keys = new Set<string>();
27
- const graph = new Map<string, string[]>();
28
- for (let i = 0; i < plan.length; i++) {
29
- const key = normalizePlanKey(plan[i], i).trim();
30
- if (!key) {
31
- throw new Error(`Plan step ${i + 1} has an empty planKey.`);
32
- }
33
- if (keys.has(key)) {
34
- throw new Error(`Duplicate planKey "${key}" in plan.`);
35
- }
36
- const type = normalizeStepType(plan[i].type);
37
- if (['tool', 'skill', 'sub_agent'].includes(type) && !plan[i].target) {
38
- throw new Error(`Step "${key}" of type "${type}" must include a target.`);
39
- }
40
- keys.add(key);
41
- graph.set(key, asArray(plan[i].dependsOn).map(String));
42
- }
43
-
44
- for (const [key, dependencies] of graph.entries()) {
45
- for (const dependency of dependencies) {
46
- if (!keys.has(dependency)) {
47
- throw new Error(`Step "${key}" depends on unknown step "${dependency}".`);
48
- }
49
- if (dependency === key) {
50
- throw new Error(`Step "${key}" cannot depend on itself.`);
51
- }
52
- }
53
- }
54
-
55
- const visiting = new Set<string>();
56
- const visited = new Set<string>();
57
- const visit = (key: string) => {
58
- if (visited.has(key)) return;
59
- if (visiting.has(key)) {
60
- throw new Error(`Plan has a dependency cycle at "${key}".`);
61
- }
62
- visiting.add(key);
63
- for (const dependency of graph.get(key) || []) {
64
- visit(dependency);
65
- }
66
- visiting.delete(key);
67
- visited.add(key);
68
- };
69
- for (const key of graph.keys()) {
70
- visit(key);
71
- }
72
- }
73
- }
@@ -1,80 +0,0 @@
1
- import { AgentLoopPlanStepInput } from './AgentLoopService';
2
-
3
- import { normalizeStepType, normalizePlanKey, asArray, asObject } from '../utils/ctx-utils';
4
-
5
- /**
6
- * Deterministic, template-based plan builder. This service does NOT call an LLM:
7
- * it either passes through a caller-provided plan or emits a fixed
8
- * prepare → (delegate|execute) → verify skeleton.
9
- *
10
- * The run's `plannerModel` field is metadata only (records which model an
11
- * upstream caller used to author a provided plan); it does not drive any
12
- * generation here. If LLM-authored planning is added later, it belongs in a
13
- * separate path — keep this builder deterministic so it stays test-stable.
14
- */
15
- export class AgentPlannerService {
16
- buildPlan(
17
- goal: string,
18
- plan: AgentLoopPlanStepInput[] | undefined,
19
- options: { targetAgent?: string; harnessTag?: string; metadata?: any },
20
- ): AgentLoopPlanStepInput[] {
21
- if (Array.isArray(plan) && plan.length > 0) {
22
- return plan.map((step, index) => ({
23
- ...step,
24
- planKey: normalizePlanKey(step, index),
25
- type: normalizeStepType(step.type),
26
- dependsOn: asArray(step.dependsOn).map(String),
27
- metadata: {
28
- ...asObject(step.metadata),
29
- harnessTag: options.harnessTag || options.metadata?.harnessTag || 'default',
30
- },
31
- }));
32
- }
33
-
34
- const harnessTag = options.harnessTag || options.metadata?.harnessTag || 'default';
35
- const steps: AgentLoopPlanStepInput[] = [
36
- {
37
- planKey: 'prepare_context',
38
- title: 'Prepare execution context',
39
- description: 'Review the user goal, available context, and constraints before execution.',
40
- type: 'reasoning',
41
- input: { goal },
42
- metadata: { harnessTag },
43
- },
44
- ];
45
-
46
- if (options.targetAgent) {
47
- steps.push({
48
- planKey: 'delegate_execution',
49
- title: `Delegate execution to ${options.targetAgent}`,
50
- description: goal,
51
- type: 'sub_agent',
52
- target: options.targetAgent,
53
- input: { goal },
54
- dependsOn: ['prepare_context'],
55
- metadata: { harnessTag },
56
- });
57
- } else {
58
- steps.push({
59
- planKey: 'execute_goal',
60
- title: 'Execute approved goal',
61
- description: 'Execute the user goal in the leader harness using the available approved tools.',
62
- type: 'reasoning',
63
- input: { goal },
64
- dependsOn: ['prepare_context'],
65
- metadata: { harnessTag, controllerOnly: true },
66
- });
67
- }
68
-
69
- steps.push({
70
- planKey: 'verify_result',
71
- title: 'Verify result',
72
- description: 'Check that the completed work matches the approved goal and report evidence.',
73
- type: 'verification',
74
- input: { goal },
75
- dependsOn: [steps[steps.length - 1].planKey || 'execute_goal'],
76
- metadata: { harnessTag },
77
- });
78
- return steps;
79
- }
80
- }
@@ -1,126 +0,0 @@
1
- export interface CircuitState {
2
- failures: number;
3
- lastFailureTime: number;
4
- state: 'closed' | 'open' | 'half-open';
5
- }
6
-
7
- /**
8
- * CircuitBreakerRegistry — prevents cascading failures by tracking per-key
9
- * failure rates and temporarily stopping calls when thresholds are exceeded.
10
- *
11
- * State machine: closed → open (after threshold failures) → half-open (after recoveryTimeout)
12
- * half-open: allows 1 probe request; success → closed, failure → open.
13
- */
14
- export class CircuitBreakerRegistry {
15
- private readonly circuits = new Map<string, CircuitState>();
16
-
17
- readonly threshold: number;
18
- readonly recoveryTimeout: number;
19
- readonly halfOpenMaxRequests: number;
20
- private readonly appLog: any;
21
-
22
- constructor(options?: { threshold?: number; recoveryTimeout?: number; halfOpenMaxRequests?: number; appLog?: any }) {
23
- this.threshold = options?.threshold ?? 3;
24
- this.recoveryTimeout = options?.recoveryTimeout ?? 30000;
25
- this.halfOpenMaxRequests = options?.halfOpenMaxRequests ?? 1;
26
- this.appLog = options?.appLog;
27
- }
28
-
29
- private getOrCreate(key: string): CircuitState {
30
- let state = this.circuits.get(key);
31
- if (!state) {
32
- state = { failures: 0, lastFailureTime: 0, state: 'closed' };
33
- this.circuits.set(key, state);
34
- }
35
- return state;
36
- }
37
-
38
- recordSuccess(key: string): void {
39
- const state = this.getOrCreate(key);
40
- if (state.state === 'half-open') {
41
- state.state = 'closed';
42
- state.failures = 0;
43
- this.appLog?.debug?.(`[CircuitBreaker] "${key}" recovered → closed`);
44
- } else if (state.state === 'closed' && state.failures > 0) {
45
- // Decrement failure count on success (graceful recovery)
46
- state.failures = Math.max(0, state.failures - 1);
47
- }
48
- }
49
-
50
- recordFailure(key: string): void {
51
- const state = this.getOrCreate(key);
52
- state.failures += 1;
53
- state.lastFailureTime = Date.now();
54
-
55
- if (state.state === 'half-open') {
56
- state.state = 'open';
57
- this.appLog?.warn?.(`[CircuitBreaker] "${key}" half-open probe failed → open`);
58
- } else if (state.state === 'closed' && state.failures >= this.threshold) {
59
- state.state = 'open';
60
- this.appLog?.warn?.(`[CircuitBreaker] "${key}" opened after ${state.failures} failures`);
61
- }
62
- }
63
-
64
- isAllowed(key: string): boolean {
65
- const state = this.getOrCreate(key);
66
-
67
- if (state.state === 'closed') return true;
68
-
69
- if (state.state === 'open') {
70
- const elapsed = Date.now() - state.lastFailureTime;
71
- if (elapsed >= this.recoveryTimeout) {
72
- state.state = 'half-open';
73
- this.appLog?.debug?.(`[CircuitBreaker] "${key}" open timeout elapsed → half-open`);
74
- return true;
75
- }
76
- return false;
77
- }
78
-
79
- // half-open: allow limited probe requests
80
- return this.halfOpenMaxRequests > 0;
81
- }
82
-
83
- getState(key: string): CircuitState | null {
84
- return this.circuits.get(key) ?? null;
85
- }
86
-
87
- /** Reset a circuit back to closed state. */
88
- reset(key: string): void {
89
- const state = this.circuits.get(key);
90
- if (state) {
91
- state.state = 'closed';
92
- state.failures = 0;
93
- state.lastFailureTime = 0;
94
- }
95
- }
96
-
97
- /** Get all circuit state keys (for monitoring/diagnostics). */
98
- getKeys(): string[] {
99
- return Array.from(this.circuits.keys());
100
- }
101
- }
102
-
103
- /**
104
- * Build the circuit key for a sub-agent. Keying by `${leader}::${target}` keeps
105
- * one leader's failures from opening the circuit for the same sub-agent under a
106
- * different leader — their delegations are independent code paths. Falls back to
107
- * the bare target when no leader is known.
108
- */
109
- export function subAgentCircuitKey(leaderUsername: string | undefined, target: string): string {
110
- return leaderUsername ? `${leaderUsername}::${target}` : target;
111
- }
112
-
113
- // Singleton shared across the plugin
114
- let globalInstance: CircuitBreakerRegistry | null = null;
115
-
116
- export function getCircuitBreaker(options?: {
117
- threshold?: number;
118
- recoveryTimeout?: number;
119
- halfOpenMaxRequests?: number;
120
- appLog?: any;
121
- }): CircuitBreakerRegistry {
122
- if (!globalInstance) {
123
- globalInstance = new CircuitBreakerRegistry(options);
124
- }
125
- return globalInstance;
126
- }