plugin-agent-orchestrator 1.2.0 → 1.2.1

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 (220) hide show
  1. package/LICENSE +201 -0
  2. package/dist/client/{117.2e4cb0477da3db1f.js → 117.6c69b6a87751dd18.js} +1 -1
  3. package/dist/client/{253.93deb9e0192e76a5.js → 253.52f62e1bc0e9520a.js} +1 -1
  4. package/dist/client/{404.498d2d9516dd1dce.js → 404.86593f98c9768ed5.js} +1 -1
  5. package/dist/client/{627.fdd60bcc0f3a9cf6.js → 453.fa2d169576262213.js} +1 -1
  6. package/dist/client/{53.774ff07505d521fa.js → 53.567db3ae078650c6.js} +1 -1
  7. package/dist/client/{619.e342b0fa467d39ca.js → 619.01713281e5e951d3.js} +1 -1
  8. package/dist/client/652.69da1598312b3a3f.js +10 -0
  9. package/dist/client/773.648965568ff476f9.js +10 -0
  10. package/dist/client/{981.e0546ffc34afedcd.js → 981.37e7aeecdb1ef6fa.js} +1 -1
  11. package/dist/client/{993.5d04b510835ab0d2.js → 993.ac89f3852990918d.js} +1 -1
  12. package/dist/client/index.js +1 -1
  13. package/dist/client-v2/{117.ccf43ae8631f7d74.js → 117.c982d79ff68738f5.js} +1 -1
  14. package/dist/client-v2/{214.cdf76752053a8990.js → 214.94c4257bf2838577.js} +1 -1
  15. package/dist/client-v2/{253.1198df22f5baf304.js → 253.8e19956d2a44dfb8.js} +1 -1
  16. package/dist/client-v2/{264.78887ff88f969467.js → 264.80e8e358c8c6c2e5.js} +1 -1
  17. package/dist/client-v2/{404.9ba964c28a151c81.js → 404.ab032b79c95dab6f.js} +1 -1
  18. package/dist/client-v2/{41.b28cf7a675a603d1.js → 41.cd5610fcf7446127.js} +1 -1
  19. package/dist/client-v2/{627.e16f4a0dd596c3e6.js → 453.42c6d70628d56cc2.js} +1 -1
  20. package/dist/client-v2/{53.282081f97e4308c6.js → 53.37c08089a648f89a.js} +1 -1
  21. package/dist/client-v2/{619.8c03913873785fb6.js → 619.6e9618550101e819.js} +1 -1
  22. package/dist/client-v2/652.eeba4e0c38367321.js +10 -0
  23. package/dist/client-v2/{70.9166ed70906d041f.js → 70.332698e53eb59677.js} +1 -1
  24. package/dist/client-v2/773.4de2ba5acb07318c.js +10 -0
  25. package/dist/client-v2/981.76060f466e6f7c11.js +10 -0
  26. package/dist/client-v2/{993.ca5b28f1e2b4c1ef.js → 993.f8cdb5172566ce75.js} +1 -1
  27. package/dist/client-v2/index.js +1 -1
  28. package/dist/externalVersion.js +4 -1
  29. package/dist/locale/en-US.json +80 -1
  30. package/dist/locale/vi-VN.json +5 -1
  31. package/dist/locale/zh-CN.json +80 -1
  32. package/dist/node_modules/acorn/LICENSE +21 -0
  33. package/dist/node_modules/acorn/bin/acorn +4 -0
  34. package/dist/node_modules/acorn/dist/acorn.d.mts +857 -0
  35. package/dist/node_modules/acorn/dist/acorn.d.ts +857 -0
  36. package/dist/node_modules/acorn/dist/acorn.js +1 -0
  37. package/dist/node_modules/acorn/dist/bin.js +90 -0
  38. package/dist/node_modules/acorn/package.json +1 -0
  39. package/dist/node_modules/acorn-walk/LICENSE +21 -0
  40. package/dist/node_modules/acorn-walk/dist/walk.d.mts +177 -0
  41. package/dist/node_modules/acorn-walk/dist/walk.d.ts +177 -0
  42. package/dist/node_modules/acorn-walk/dist/walk.js +1 -0
  43. package/dist/node_modules/acorn-walk/node_modules/.bin/acorn +15 -0
  44. package/dist/node_modules/acorn-walk/node_modules/.bin/acorn.cmd +7 -0
  45. package/dist/node_modules/acorn-walk/node_modules/acorn/bin/acorn +4 -0
  46. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.mts +866 -0
  47. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.ts +866 -0
  48. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.js +6174 -0
  49. package/dist/node_modules/acorn-walk/node_modules/acorn/dist/bin.js +90 -0
  50. package/dist/node_modules/acorn-walk/node_modules/acorn/package.json +50 -0
  51. package/dist/node_modules/acorn-walk/package.json +1 -0
  52. package/dist/node_modules/adm-zip/package.json +1 -1
  53. package/dist/node_modules/ajv/package.json +1 -1
  54. package/dist/node_modules/zod/package.json +1 -1
  55. package/dist/server/collections/agent-auto-approval-checkpoints.js +47 -0
  56. package/dist/server/collections/agent-execution-spans.js +3 -3
  57. package/dist/server/collections/agent-hierarchy-invocations.js +59 -0
  58. package/dist/server/collections/agent-routing-graph-locks.js +40 -0
  59. package/dist/server/collections/agent-session-auto-approvals.js +45 -0
  60. package/dist/server/collections/orchestrator-config.js +17 -0
  61. package/dist/server/migrations/20261119000000-widen-native-employee-identifiers.js +59 -0
  62. package/dist/server/plugin.js +55 -0
  63. package/dist/server/resources/agent-auto-approval.js +80 -0
  64. package/dist/server/resources/hierarchical-routing.js +60 -0
  65. package/dist/server/services/AutoApprovalCheckpoint.js +133 -0
  66. package/dist/server/services/CodeValidator.js +8 -4
  67. package/dist/server/services/GovernanceAdmission.js +60 -0
  68. package/dist/server/services/HarnessCompiler.js +3 -0
  69. package/dist/server/services/HarnessSchema.js +13 -1
  70. package/dist/server/services/HierarchicalAgentRuntime.js +925 -0
  71. package/dist/server/services/HierarchyEnrollmentGuard.js +216 -0
  72. package/dist/server/services/HierarchyInvocationJournal.js +157 -0
  73. package/dist/server/services/HierarchyRequestCancellation.js +150 -0
  74. package/dist/server/services/LoopRunRepository.js +1 -1
  75. package/dist/server/services/LoopRunStateMachine.js +2 -2
  76. package/dist/server/services/LoopWorkerService.js +7 -7
  77. package/dist/server/services/PluginAiRuntimeAdapter.js +107 -9
  78. package/dist/server/services/RoutingBindingRepository.js +156 -0
  79. package/dist/server/services/RoutingBindingValidation.js +161 -0
  80. package/dist/server/services/SandboxRunner.js +19 -0
  81. package/dist/server/services/SessionAutoApproval.js +173 -0
  82. package/dist/server/services/VerificationService.js +2 -2
  83. package/dist/server/skill-hub/plugin.js +17 -0
  84. package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +2 -2
  85. package/dist/server/skill-hub/services/registry-node-package.js +191 -0
  86. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +21 -6
  87. package/dist/server/tools/skill-execute.js +1 -0
  88. package/dist/server/utils/ensure-indexes.js +1 -0
  89. package/package.json +5 -2
  90. package/src/client/SkillPages.tsx +1 -8
  91. package/src/client/__tests__/embedded-settings.test.tsx +1 -8
  92. package/src/client/plugin.tsx +3 -8
  93. package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +21 -6
  94. package/src/client/skill-hub/tools/SkillHubCard.tsx +22 -16
  95. package/src/client/skill-hub/tools/__tests__/skill-hub-card.test.tsx +255 -0
  96. package/src/client/skill-hub/tools/registerSkillLoopCards.ts +12 -3
  97. package/src/client-v2/__tests__/embedded-settings.test.tsx +20 -11
  98. package/src/client-v2/__tests__/hierarchical-routing-settings.test.tsx +350 -0
  99. package/src/client-v2/auto-approval/AutoApprovalBridge.tsx +513 -0
  100. package/src/client-v2/auto-approval/AutoApprovalProvider.tsx +399 -0
  101. package/src/client-v2/auto-approval/__tests__/session-auto-approval.test.tsx +1676 -0
  102. package/src/client-v2/components/AgentBindingsTab.tsx +275 -3
  103. package/src/client-v2/components/AgentRunsTab.tsx +1 -8
  104. package/src/client-v2/components/EmployeeGovernanceTab.tsx +1 -8
  105. package/src/client-v2/components/HarnessProfilesTab.tsx +4 -8
  106. package/src/client-v2/components/HarnessSettingsForm.tsx +221 -0
  107. package/src/client-v2/components/UsageGovernanceTab.tsx +1 -8
  108. package/src/client-v2/pages/AgentBindingsPage.tsx +1 -8
  109. package/src/client-v2/pages/ApprovalsPage.tsx +1 -8
  110. package/src/client-v2/pages/EmployeeGovernancePage.tsx +1 -8
  111. package/src/client-v2/pages/ExecutionHistoryPage.tsx +1 -8
  112. package/src/client-v2/pages/HarnessProfilesPage.tsx +1 -8
  113. package/src/client-v2/pages/KnowledgeAccessPage.tsx +1 -8
  114. package/src/client-v2/pages/LoopSettingsPage.tsx +1 -8
  115. package/src/client-v2/pages/MemoryInspectorPage.tsx +1 -8
  116. package/src/client-v2/pages/RetrievalTracePage.tsx +1 -8
  117. package/src/client-v2/pages/RulesPage.tsx +1 -8
  118. package/src/client-v2/pages/SkillDefinitionsPage.tsx +1 -8
  119. package/src/client-v2/pages/SkillMetricsPage.tsx +1 -8
  120. package/src/client-v2/pages/TracingPage.tsx +1 -8
  121. package/src/client-v2/pages/UsageGovernancePage.tsx +1 -8
  122. package/src/client-v2/plugin.tsx +3 -8
  123. package/src/client-v2/skill-hub/tools/__tests__/interactions.test.ts +17 -1
  124. package/src/client-v2/skill-hub/tools/interactions.ts +12 -3
  125. package/src/locale/en-US.json +80 -1
  126. package/src/locale/vi-VN.json +5 -1
  127. package/src/locale/zh-CN.json +80 -1
  128. package/src/server/__tests__/agent-governance.integration.test.ts +1 -8
  129. package/src/server/__tests__/agent-monitor-acl.integration.test.ts +1 -8
  130. package/src/server/__tests__/agent-usage-report.integration.test.ts +1 -8
  131. package/src/server/__tests__/auto-approval-checkpoint.integration.test.ts +295 -0
  132. package/src/server/__tests__/harness-capabilities.test.ts +1 -8
  133. package/src/server/__tests__/harness-compiler.test.ts +64 -0
  134. package/src/server/__tests__/harness-tool-plan.test.ts +1 -8
  135. package/src/server/__tests__/hierarchical-routing.integration.test.ts +2318 -0
  136. package/src/server/__tests__/hierarchy-invocation-journal.integration.test.ts +119 -0
  137. package/src/server/__tests__/loop-approval-decision.test.ts +59 -12
  138. package/src/server/__tests__/loop-budget-service.test.ts +1 -8
  139. package/src/server/__tests__/loop-run-repository.test.ts +1 -8
  140. package/src/server/__tests__/loop-trigger-service.test.ts +1 -8
  141. package/src/server/__tests__/loop-worker-claim.test.ts +46 -9
  142. package/src/server/__tests__/loop-worker-execution.test.ts +1 -8
  143. package/src/server/__tests__/native-agent-monitor-sync.test.ts +1 -8
  144. package/src/server/__tests__/native-hierarchy-probe.integration.test.ts +527 -0
  145. package/src/server/__tests__/native-sub-agent-observer.test.ts +1 -8
  146. package/src/server/__tests__/native-usage-attribution.integration.test.ts +1 -8
  147. package/src/server/__tests__/plugin-ai-runtime-adapter.test.ts +403 -0
  148. package/src/server/__tests__/registry-node-package.test.ts +299 -0
  149. package/src/server/__tests__/routing-binding-graph.integration.test.ts +217 -0
  150. package/src/server/__tests__/routing-binding-validation.test.ts +256 -0
  151. package/src/server/__tests__/session-auto-approval.integration.test.ts +329 -0
  152. package/src/server/__tests__/skill-execute.test.ts +11 -0
  153. package/src/server/__tests__/skill-review-guard.test.ts +171 -0
  154. package/src/server/__tests__/token-tracker.test.ts +1 -8
  155. package/src/server/__tests__/tracing-retention-policy.test.ts +1 -8
  156. package/src/server/__tests__/usage-ledger.integration.test.ts +1 -8
  157. package/src/server/collections/agent-auto-approval-checkpoints.ts +18 -0
  158. package/src/server/collections/agent-execution-spans.ts +4 -11
  159. package/src/server/collections/agent-governance-audit-events.ts +1 -8
  160. package/src/server/collections/agent-governance-policies.ts +1 -8
  161. package/src/server/collections/agent-governance-policy-versions.ts +1 -8
  162. package/src/server/collections/agent-governance-prompt-bindings.ts +1 -8
  163. package/src/server/collections/agent-hierarchy-invocations.ts +30 -0
  164. package/src/server/collections/agent-loop-runs.ts +1 -8
  165. package/src/server/collections/agent-routing-graph-locks.ts +11 -0
  166. package/src/server/collections/agent-session-auto-approvals.ts +16 -0
  167. package/src/server/collections/orchestrator-config.ts +26 -0
  168. package/src/server/migrations/20261110000000-add-usage-pricing-snapshots.ts +1 -8
  169. package/src/server/migrations/20261110010000-add-usage-department-attribution.ts +1 -8
  170. package/src/server/migrations/20261119000000-widen-native-employee-identifiers.ts +37 -0
  171. package/src/server/plugin.ts +58 -8
  172. package/src/server/resources/agent-auto-approval.ts +51 -0
  173. package/src/server/resources/agent-governance.ts +1 -8
  174. package/src/server/resources/agent-harness-profile.ts +1 -8
  175. package/src/server/resources/agent-monitor.ts +1 -8
  176. package/src/server/resources/agent-usage.ts +1 -8
  177. package/src/server/resources/hierarchical-routing.ts +39 -0
  178. package/src/server/resources/native-monitor-format.ts +1 -8
  179. package/src/server/resources/tracing.ts +1 -8
  180. package/src/server/services/AgentGovernanceService.ts +1 -8
  181. package/src/server/services/AutoApprovalCheckpoint.ts +140 -0
  182. package/src/server/services/CodeValidator.ts +23 -4
  183. package/src/server/services/DepartmentAttribution.ts +1 -8
  184. package/src/server/services/ExecutionSpanService.ts +1 -8
  185. package/src/server/services/GovernanceAdmission.ts +83 -8
  186. package/src/server/services/HarnessCapabilities.ts +1 -8
  187. package/src/server/services/HarnessCompiler.ts +12 -0
  188. package/src/server/services/HarnessSchema.ts +30 -0
  189. package/src/server/services/HierarchicalAgentRuntime.ts +1052 -0
  190. package/src/server/services/HierarchyEnrollmentGuard.ts +211 -0
  191. package/src/server/services/HierarchyInvocationJournal.ts +172 -0
  192. package/src/server/services/HierarchyRequestCancellation.ts +132 -0
  193. package/src/server/services/LoopBudgetService.ts +1 -8
  194. package/src/server/services/LoopRunRepository.ts +2 -9
  195. package/src/server/services/LoopRunStateMachine.ts +3 -10
  196. package/src/server/services/LoopTriggerService.ts +1 -8
  197. package/src/server/services/LoopWorkerService.ts +8 -19
  198. package/src/server/services/ManagedPromptProtection.ts +1 -8
  199. package/src/server/services/NativeAgentMonitorSyncService.ts +1 -8
  200. package/src/server/services/NativeSubAgentObserver.ts +1 -8
  201. package/src/server/services/NativeUsageAttribution.ts +1 -8
  202. package/src/server/services/PluginAiRuntimeAdapter.ts +140 -9
  203. package/src/server/services/RoutingBindingRepository.ts +146 -0
  204. package/src/server/services/RoutingBindingValidation.ts +161 -0
  205. package/src/server/services/SandboxRunner.ts +35 -1
  206. package/src/server/services/SessionAutoApproval.ts +167 -0
  207. package/src/server/services/TokenTracker.ts +1 -8
  208. package/src/server/services/TracingRetentionPolicy.ts +1 -8
  209. package/src/server/services/VerificationService.ts +3 -10
  210. package/src/server/skill-hub/plugin.ts +40 -0
  211. package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +11 -1
  212. package/src/server/skill-hub/services/registry-node-package.ts +191 -0
  213. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +34 -5
  214. package/src/server/tools/skill-execute.ts +10 -0
  215. package/src/server/utils/ensure-indexes.ts +2 -8
  216. package/dist/client/418.6f01da17774a5a25.js +0 -10
  217. package/dist/client/652.477e21bfff67bc1c.js +0 -10
  218. package/dist/client-v2/418.55b6b28cda8bb5f3.js +0 -10
  219. package/dist/client-v2/652.1a48364774d5383a.js +0 -10
  220. package/dist/client-v2/981.a81521f0296c7db8.js +0 -10
@@ -0,0 +1,171 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { describe, expect, it, vi } from 'vitest';
11
+ import { createSkillExecuteTool } from '../tools/skill-execute';
12
+ import { SkillHubSubFeature } from '../skill-hub/plugin';
13
+
14
+ type Row = Record<string, unknown>;
15
+ type Runtime = { toolCallId: string; writer: ReturnType<typeof vi.fn> };
16
+
17
+ function skill(overrides: Row = {}) {
18
+ const values: Row = {
19
+ id: 1,
20
+ name: 'monthly-report',
21
+ toolName: 'skill_hub_monthly_report',
22
+ title: 'Monthly report',
23
+ description: 'Build a monthly report.',
24
+ language: 'python',
25
+ toolScope: 'CUSTOM',
26
+ autoCall: true,
27
+ interactionSchema: JSON.stringify({ type: 'confirm', prompt: 'Review the report.' }),
28
+ inputSchema: { type: 'object', properties: {} },
29
+ ...overrides,
30
+ };
31
+ return { get: (name: string) => values[name] };
32
+ }
33
+
34
+ function acceptedCall(overrides: Row = {}) {
35
+ return {
36
+ toolCallId: 'call-1',
37
+ toolName: 'skill_hub_monthly_report',
38
+ auto: false,
39
+ invokeStatus: 'pending',
40
+ userDecision: { type: 'approve' },
41
+ ...overrides,
42
+ };
43
+ }
44
+
45
+ function createFeature(options: { call?: Row | null } = {}) {
46
+ const targetSkill = skill();
47
+ const skillDefinitions = {
48
+ find: vi.fn(async () => [targetSkill]),
49
+ findOne: vi.fn(async () => targetSkill),
50
+ };
51
+ const skillLoopConfigs = {
52
+ find: vi.fn(async () => []),
53
+ findOne: vi.fn(async () => null),
54
+ };
55
+ const aiToolMessages = {
56
+ findOne: vi.fn(async (query: Row) => {
57
+ const filter = query.filter as Row;
58
+ const call = options.call;
59
+ if (!call || call.toolCallId !== filter.toolCallId || call.toolName !== filter.toolName) return null;
60
+ return call;
61
+ }),
62
+ };
63
+ const db = {
64
+ getRepository(name: string) {
65
+ if (name === 'skillDefinitions') return skillDefinitions;
66
+ if (name === 'skillLoopConfigs') return skillLoopConfigs;
67
+ if (name === 'aiToolMessages') return aiToolMessages;
68
+ throw new Error(`Unexpected repository ${name}`);
69
+ },
70
+ };
71
+ const toolsManager = {
72
+ registerTools: vi.fn(),
73
+ registerDynamicTools: vi.fn(),
74
+ };
75
+ const app = { aiManager: { toolsManager }, logger: { info: vi.fn(), warn: vi.fn() } };
76
+ const feature = new SkillHubSubFeature({ app, db, name: 'plugin-agent-orchestrator' });
77
+ const executeSkill = vi.spyOn(feature, 'executeSkill').mockResolvedValue({ status: 'succeeded', files: [] });
78
+ vi.spyOn(feature, 'getSkillDescriptionForAI').mockResolvedValue('Monthly report instructions.');
79
+ return { feature, app, toolsManager, skillDefinitions, skillLoopConfigs, aiToolMessages, executeSkill };
80
+ }
81
+
82
+ function runtime(toolCallId = 'call-1'): Runtime {
83
+ return { toolCallId, writer: vi.fn() };
84
+ }
85
+
86
+ async function dynamicTool(feature: SkillHubSubFeature, app: { aiManager: { toolsManager: Row } }) {
87
+ let registerDynamic: ((registration: { registerTools: (tools: unknown[]) => void }) => Promise<void>) | undefined;
88
+ const toolsManager = app.aiManager.toolsManager as {
89
+ registerTools: ReturnType<typeof vi.fn>;
90
+ registerDynamicTools: ReturnType<typeof vi.fn>;
91
+ };
92
+ toolsManager.registerDynamicTools.mockImplementation((callback) => {
93
+ registerDynamic = callback as typeof registerDynamic;
94
+ });
95
+ const methods = feature as unknown as { registerAITools(): void };
96
+ methods.registerAITools();
97
+ if (!registerDynamic) throw new Error('Dynamic skill tool registration did not run.');
98
+ const tools: unknown[] = [];
99
+ await registerDynamic({ registerTools: (registered) => tools.push(...registered) });
100
+ const tool = tools.find((entry) => {
101
+ const definition = (entry as { definition?: Row }).definition;
102
+ return definition?.name === 'skill_hub_monthly_report';
103
+ });
104
+ if (!tool) throw new Error('Monthly report dynamic tool was not registered.');
105
+ return tool as {
106
+ defaultPermission: string;
107
+ invoke(ctx: Row, args: Row, runtime?: Runtime): Promise<Row>;
108
+ };
109
+ }
110
+
111
+ describe('Skill Hub explicit review guard', () => {
112
+ it.each(['approve', 'edit'] as const)('allows a trusted native %s decision', async (decision) => {
113
+ const call = acceptedCall({ userDecision: { type: decision } });
114
+ const { feature, aiToolMessages } = createFeature({ call });
115
+
116
+ await expect(
117
+ feature.assertSkillReviewApproved(skill(), runtime(), 'skill_hub_monthly_report'),
118
+ ).resolves.toBeUndefined();
119
+ expect(aiToolMessages.findOne).toHaveBeenCalledWith({
120
+ filter: { toolCallId: 'call-1', toolName: 'skill_hub_monthly_report' },
121
+ });
122
+ });
123
+
124
+ it.each([
125
+ ['Auto call is still enabled', acceptedCall({ auto: true }), runtime()],
126
+ ['the call is not pending', acceptedCall({ invokeStatus: 'interrupted' }), runtime()],
127
+ ['no native decision is recorded', acceptedCall({ userDecision: null }), runtime()],
128
+ ['the native decision is reject', acceptedCall({ userDecision: { type: 'reject' } }), runtime()],
129
+ ['the stored tool name does not match', acceptedCall({ toolName: 'skill_hub_other' }), runtime()],
130
+ ['the tool-call identity does not match', acceptedCall(), runtime('other-call')],
131
+ ['there is no trusted runtime tool-call identity', acceptedCall(), undefined],
132
+ ])('fails closed when %s', async (_caseName, call, toolRuntime) => {
133
+ const { feature, executeSkill } = createFeature({ call });
134
+
135
+ await expect(feature.assertSkillReviewApproved(skill(), toolRuntime, 'skill_hub_monthly_report')).rejects.toThrow(
136
+ 'Human review is required',
137
+ );
138
+ expect(executeSkill).not.toHaveBeenCalled();
139
+ });
140
+
141
+ it('does not let the dynamic tool bypass review when Auto call is enabled', async () => {
142
+ const { feature, app, executeSkill } = createFeature({ call: acceptedCall({ auto: true }) });
143
+ const tool = await dynamicTool(feature, app);
144
+
145
+ expect(tool.defaultPermission).toBe('ASK');
146
+ await expect(tool.invoke({}, { input: {} }, runtime())).rejects.toThrow('Human review is required');
147
+ expect(executeSkill).not.toHaveBeenCalled();
148
+ });
149
+
150
+ it.each(['approve', 'edit'] as const)('runs a dynamic tool only after native %s review', async (decision) => {
151
+ const { feature, app, executeSkill } = createFeature({
152
+ call: acceptedCall({ userDecision: { type: decision } }),
153
+ });
154
+ const tool = await dynamicTool(feature, app);
155
+
156
+ const result = await tool.invoke({}, { input: {} }, runtime());
157
+
158
+ expect(result.status).toBe('success');
159
+ expect(executeSkill).toHaveBeenCalledOnce();
160
+ });
161
+
162
+ it('checks generic gateway execute actions before dispatching to the sandbox', async () => {
163
+ const { feature, executeSkill } = createFeature({ call: acceptedCall({ auto: true }) });
164
+ const tool = createSkillExecuteTool(feature);
165
+ const result = await tool.invoke({}, { action: 'execute', skillName: 'monthly-report', input: {} }, runtime());
166
+
167
+ expect(result.status).toBe('error');
168
+ expect(result.content).toContain('Human review is required');
169
+ expect(executeSkill).not.toHaveBeenCalled();
170
+ });
171
+ });
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
11
4
  import { TokenTracker, usageFromAIUsageEvent } from '../services/TokenTracker';
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { describe, expect, it } from 'vitest';
11
4
  import { getHarnessProfileRetentionDays } from '../services/TracingRetentionPolicy';
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { createMockServer, type MockServer } from '@nocobase/test';
11
4
  import { PluginAgentOrchestratorServer } from '../plugin';
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { defineCollection } from '@nocobase/database';
3
+
4
+ export default defineCollection({
5
+ name: 'agentAutoApprovalCheckpoints',
6
+ autoGenId: false,
7
+ title: 'Agent Auto Approval Checkpoints',
8
+ fields: [
9
+ { name: 'checkpointKey', type: 'string', length: 64, allowNull: false, primaryKey: true },
10
+ { name: 'ownerId', type: 'bigInt', allowNull: false },
11
+ { name: 'sessionId', type: 'string', length: 100, allowNull: false },
12
+ { name: 'messageId', type: 'string', length: 100, allowNull: false },
13
+ { name: 'interruptId', type: 'text', allowNull: false },
14
+ { name: 'status', type: 'string', length: 16, allowNull: false, defaultValue: 'pending' },
15
+ { name: 'createdAt', type: 'date' },
16
+ { name: 'updatedAt', type: 'date' },
17
+ ],
18
+ });
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -47,7 +40,7 @@ export default defineCollection({
47
40
  {
48
41
  name: 'role',
49
42
  type: 'string',
50
- length: 30,
43
+ length: 255,
51
44
  },
52
45
  {
53
46
  name: 'harnessProfileTag',
@@ -216,12 +209,12 @@ export default defineCollection({
216
209
  {
217
210
  name: 'leaderUsername',
218
211
  type: 'string',
219
- length: 100,
212
+ length: 255,
220
213
  },
221
214
  {
222
215
  name: 'employeeUsername',
223
216
  type: 'string',
224
- length: 100,
217
+ length: 255,
225
218
  comment: 'The AI Employee currently executing this span',
226
219
  },
227
220
  {
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { defineCollection } from '@nocobase/database';
3
+
4
+ export default defineCollection({
5
+ name: 'agentHierarchyInvocations',
6
+ title: 'Agent Hierarchy Invocations',
7
+ fields: [
8
+ { name: 'id', type: 'bigInt', autoIncrement: true, primaryKey: true },
9
+ { name: 'ownerId', type: 'bigInt', allowNull: false },
10
+ { name: 'rootSessionId', type: 'string', length: 100, allowNull: false },
11
+ { name: 'parentSessionId', type: 'string', length: 100, allowNull: false },
12
+ { name: 'parentEmployee', type: 'string', length: 200, allowNull: false },
13
+ { name: 'parentToolCallId', type: 'string', length: 200, allowNull: false },
14
+ { name: 'childSessionId', type: 'string', length: 100 },
15
+ { name: 'employeeUsername', type: 'string', length: 200, allowNull: false },
16
+ { name: 'role', type: 'string', length: 30, allowNull: false },
17
+ { name: 'questionHash', type: 'string', length: 64, allowNull: false },
18
+ { name: 'snapshot', type: 'json', allowNull: false },
19
+ { name: 'status', type: 'string', length: 30, allowNull: false, defaultValue: 'reserved' },
20
+ { name: 'claimToken', type: 'string', length: 100 },
21
+ { name: 'result', type: 'json' },
22
+ { name: 'createdAt', type: 'date' },
23
+ { name: 'updatedAt', type: 'date' },
24
+ ],
25
+ indexes: [
26
+ { unique: true, fields: ['parentSessionId', 'parentToolCallId'] },
27
+ { fields: ['rootSessionId', 'ownerId'] },
28
+ { fields: ['status', 'updatedAt'] },
29
+ ],
30
+ });
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { defineCollection } from '@nocobase/database';
3
+
4
+ export default defineCollection({
5
+ name: 'agentRoutingGraphLocks',
6
+ autoGenId: false,
7
+ fields: [
8
+ { name: 'key', type: 'string', length: 40, primaryKey: true, allowNull: false },
9
+ { name: 'marker', type: 'integer', allowNull: false, defaultValue: 0 },
10
+ ],
11
+ });
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { defineCollection } from '@nocobase/database';
3
+
4
+ export default defineCollection({
5
+ name: 'agentSessionAutoApprovals',
6
+ title: 'Agent Session Auto Approvals',
7
+ fields: [
8
+ { name: 'id', type: 'bigInt', autoIncrement: true, primaryKey: true },
9
+ { name: 'ownerId', type: 'bigInt', allowNull: false },
10
+ { name: 'sessionId', type: 'string', length: 100, allowNull: false },
11
+ { name: 'enabled', type: 'boolean', allowNull: false, defaultValue: false },
12
+ { name: 'createdAt', type: 'date' },
13
+ { name: 'updatedAt', type: 'date' },
14
+ ],
15
+ indexes: [{ unique: true, fields: ['ownerId', 'sessionId'] }],
16
+ });
@@ -1,7 +1,17 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  import { defineCollection } from '@nocobase/database';
2
11
 
3
12
  export default defineCollection({
4
13
  name: 'orchestratorConfig',
14
+ repository: 'RoutingBindingRepository',
5
15
  title: 'Orchestrator Config',
6
16
  fields: [
7
17
  {
@@ -77,6 +87,22 @@ export default defineCollection({
77
87
  type: 'string',
78
88
  comment: 'Optional overridden model for the sub-agent',
79
89
  },
90
+ {
91
+ name: 'routingEnabled',
92
+ type: 'boolean',
93
+ defaultValue: false,
94
+ comment: 'Enables this binding for the hierarchical routing tool.',
95
+ },
96
+ {
97
+ name: 'routingRole',
98
+ type: 'string',
99
+ comment: 'Role of the target employee in hierarchical routing: specialist or worker.',
100
+ },
101
+ {
102
+ name: 'routingPrompt',
103
+ type: 'text',
104
+ comment: 'Description of when the target employee should be selected.',
105
+ },
80
106
  ],
81
107
  indexes: [
82
108
  {
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { DataTypes } from '@nocobase/database';
11
4
  import type { Database } from '@nocobase/database';
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { DataTypes } from '@nocobase/database';
11
4
  import { Migration } from '@nocobase/server';
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ import { DataTypes } from '@nocobase/database';
4
+ import { Migration } from '@nocobase/server';
5
+
6
+ /**
7
+ * AI Employee usernames are stored in the native message role as well as the employee
8
+ * field. Preserve complete identifiers in native usage and execution projections.
9
+ */
10
+ export default class WidenNativeEmployeeIdentifiers extends Migration {
11
+ on = 'afterLoad';
12
+ appVersion = '<=2.x';
13
+
14
+ async up() {
15
+ const collection = this.db.getCollection('agentExecutionSpans');
16
+ if (!collection) return;
17
+ const queryInterface = this.db.sequelize.getQueryInterface();
18
+ const table = collection.getTableNameWithSchema();
19
+ const columns = await queryInterface.describeTable(table);
20
+ for (const attribute of ['role', 'employeeUsername', 'leaderUsername']) {
21
+ const field = collection.model.rawAttributes[attribute]?.field || attribute;
22
+ const column = columns[field];
23
+ if (!column) continue;
24
+ const match = /^(?:VARCHAR|CHARACTER VARYING|NVARCHAR)\s*\(\s*(\d+)\s*\)/i.exec(String(column.type));
25
+ if (!match || Number(match[1]) >= 255) continue;
26
+ await queryInterface.changeColumn(table, field, {
27
+ type: DataTypes.STRING(255),
28
+ allowNull: column.allowNull,
29
+ ...(column.defaultValue == null ? {} : { defaultValue: column.defaultValue }),
30
+ });
31
+ }
32
+ }
33
+
34
+ async down() {
35
+ // Preserve identifiers already stored at the larger native length.
36
+ }
37
+ }
@@ -1,11 +1,4 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { Plugin } from '@nocobase/server';
11
4
  import type { Context } from '@nocobase/actions';
@@ -21,6 +14,9 @@ import { registerAgentLoopEventsStreamResource } from './resources/agent-loop-ev
21
14
  import { registerAgentKnowledgeInsightsResource } from './resources/agent-knowledge-insights';
22
15
  import { registerAgentGovernanceResource } from './resources/agent-governance';
23
16
  import { registerAgentUsageResource } from './resources/agent-usage';
17
+ import { registerHierarchicalRoutingResource } from './resources/hierarchical-routing';
18
+ import { registerAgentAutoApprovalResource } from './resources/agent-auto-approval';
19
+ import { guardAutoApprovalDecision } from './services/SessionAutoApproval';
24
20
  import SkillHubSubFeature from './skill-hub/plugin';
25
21
  import { NativeSubAgentObserver } from './services/NativeSubAgentObserver';
26
22
  import { NativeAgentMonitorSyncService } from './services/NativeAgentMonitorSyncService';
@@ -42,6 +38,11 @@ import { resolveTracingRetentionDays } from './services/TracingRetentionPolicy';
42
38
  import { createGovernanceAdmission } from './services/GovernanceAdmission';
43
39
  import { installManagedPromptProtection, ManagedPromptError } from './services/ManagedPromptProtection';
44
40
  import { installNativeUsageAttribution } from './services/NativeUsageAttribution';
41
+ import { createHierarchicalAgentTools } from './services/HierarchicalAgentRuntime';
42
+ import { validateRoutingBindingAction } from './services/RoutingBindingValidation';
43
+ import { initializeRoutingGraphLock, RoutingBindingRepository } from './services/RoutingBindingRepository';
44
+ import { guardHierarchyEnrollment, guardManagedChildActions } from './services/HierarchyEnrollmentGuard';
45
+ import { HierarchyRequestCancellation } from './services/HierarchyRequestCancellation';
45
46
 
46
47
  function normalizeOptionalString(value: unknown) {
47
48
  return typeof value === 'string' ? value.trim() : '';
@@ -161,6 +162,7 @@ async function validateAgentMemoryContextValues(ctx: any) {
161
162
  }
162
163
 
163
164
  export class PluginAgentOrchestratorServer extends Plugin {
165
+ private readonly hierarchyCancellation = new HierarchyRequestCancellation(this);
164
166
  skillHub: SkillHubSubFeature;
165
167
  registrySkillSnapshotService: RegistrySkillSnapshotService;
166
168
  registrySkillInstallationService: RegistrySkillInstallationService;
@@ -196,6 +198,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
196
198
  }
197
199
 
198
200
  async beforeLoad() {
201
+ this.db.registerRepositories({ RoutingBindingRepository });
199
202
  // Import collection definitions
200
203
  this.db.import({ directory: path.resolve(__dirname, 'collections') });
201
204
 
@@ -218,6 +221,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
218
221
  'agentMonitor:*',
219
222
  'agentUsage:*',
220
223
  'agentGovernance:*',
224
+ 'agentHierarchy:*',
221
225
  'agentKnowledgeInsights:*',
222
226
  'agentMemoryContexts:*',
223
227
  'agentLoopRuns:*',
@@ -257,8 +261,25 @@ export class PluginAgentOrchestratorServer extends Plugin {
257
261
  this.app.acl.allow('agentLoopApprovals', ['list', 'get', 'decide'], 'loggedIn');
258
262
  this.app.acl.allow('agentLoopArtifactsView', ['list', 'get'], 'loggedIn');
259
263
  this.app.acl.allow('agentLoopEventsStream', ['stream'], 'loggedIn');
264
+ this.app.acl.allow('agentAutoApproval', ['get', 'set', 'eligible'], 'loggedIn');
260
265
 
261
266
  this.installGovernanceHooks();
267
+ this.app.resourceManager.use(
268
+ async (ctx, next) => {
269
+ if (
270
+ [
271
+ 'agentHierarchyInvocations',
272
+ 'agentSessionAutoApprovals',
273
+ 'agentAutoApprovalCheckpoints',
274
+ 'agentRoutingGraphLocks',
275
+ ].includes(ctx.action?.resourceName ?? '')
276
+ ) {
277
+ return ctx.throw(403, ctx.t('Hierarchy invocation records are not directly accessible.'));
278
+ }
279
+ return next();
280
+ },
281
+ { tag: 'orchestrator-hierarchy-record-protection', after: 'acl' },
282
+ );
262
283
  this.app.resourceManager.use(
263
284
  async (ctx, next) => {
264
285
  const { resourceName, actionName } = ctx.action || {};
@@ -290,6 +311,27 @@ export class PluginAgentOrchestratorServer extends Plugin {
290
311
  after: 'acl',
291
312
  });
292
313
 
314
+ this.app.resourceManager.use(async (ctx, next) => validateRoutingBindingAction(ctx as Context, next), {
315
+ tag: 'orchestrator-routing-binding-validation',
316
+ after: 'acl',
317
+ });
318
+ this.app.resourceManager.use(async (ctx, next) => guardHierarchyEnrollment(ctx as Context, next), {
319
+ tag: 'orchestrator-hierarchy-enrollment',
320
+ after: 'acl',
321
+ });
322
+ this.app.resourceManager.use(async (ctx, next) => guardManagedChildActions(ctx as Context, next), {
323
+ tag: 'orchestrator-hierarchy-child-protection',
324
+ after: 'orchestrator-hierarchy-enrollment',
325
+ });
326
+ this.app.resourceManager.use(async (ctx, next) => guardAutoApprovalDecision(ctx as Context, next), {
327
+ tag: 'orchestrator-auto-approval-decision',
328
+ after: 'orchestrator-hierarchy-child-protection',
329
+ });
330
+ this.app.resourceManager.use(async (ctx, next) => this.hierarchyCancellation.middleware(ctx as Context, next), {
331
+ tag: 'orchestrator-hierarchy-cancellation',
332
+ after: 'orchestrator-hierarchy-child-protection',
333
+ });
334
+
293
335
  // Data scoping for skillExecutions: a logged-in non-admin user may only
294
336
  // read their own executions. Rows hold inputArgs / stdout / output files,
295
337
  // so an unscoped list/get would leak one user's data to another. Admins
@@ -408,6 +450,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
408
450
  // drives work through the Loop Control Plane (trigger → durable run → worker → verifier).
409
451
  const toolsManager = getAIToolsManager(this.app);
410
452
  toolsManager.registerTools(createExternalRagSearchTool(this));
453
+ toolsManager.registerTools(createHierarchicalAgentTools(this));
411
454
 
412
455
  // --- Loop Control Plane runtime ---
413
456
  const patterns = new LoopPatternService(this.db, employeeHarnessResolver(this), async () =>
@@ -425,6 +468,8 @@ export class PluginAgentOrchestratorServer extends Plugin {
425
468
  registerAgentLoopEventsStreamResource(this);
426
469
  registerAgentHarnessProfileResource(this);
427
470
  registerAgentGovernanceResource(this);
471
+ registerHierarchicalRoutingResource(this);
472
+ registerAgentAutoApprovalResource(this);
428
473
  registerAgentUsageResource(this);
429
474
 
430
475
  // --- Native plugin-ai Monitor Resource ---
@@ -596,10 +641,12 @@ export class PluginAgentOrchestratorServer extends Plugin {
596
641
 
597
642
  async install() {
598
643
  await this.skillHub.install();
644
+ await initializeRoutingGraphLock(this.db);
599
645
  await ensureAgentOrchestratorIndexes(this.db);
600
646
  }
601
647
 
602
648
  async upgrade() {
649
+ await initializeRoutingGraphLock(this.db);
603
650
  await ensureAgentOrchestratorIndexes(this.db);
604
651
  }
605
652
 
@@ -610,6 +657,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
610
657
  }
611
658
  async afterDisable() {
612
659
  this.governanceEnabled = false;
660
+ this.hierarchyCancellation.abortAll();
613
661
  this.removeManagedPromptProtection?.();
614
662
  this.removeManagedPromptProtection = undefined;
615
663
  this.removeNativeUsageAttribution?.();
@@ -622,6 +670,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
622
670
 
623
671
  async beforeStop() {
624
672
  this.governanceEnabled = false;
673
+ this.hierarchyCancellation.abortAll();
625
674
  this.removeManagedPromptProtection?.();
626
675
  this.removeManagedPromptProtection = undefined;
627
676
  this.removeNativeUsageAttribution?.();
@@ -640,6 +689,7 @@ export class PluginAgentOrchestratorServer extends Plugin {
640
689
  }
641
690
 
642
691
  async handleSyncMessage(message: unknown) {
692
+ this.hierarchyCancellation.handleSyncMessage(message);
643
693
  await this.loopScheduler?.handleSyncMessage(message);
644
694
  await this.loopWorker?.handleSyncMessage(message);
645
695
  }