evolcore 0.0.41-test.1 → 0.0.41-test.2
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/CHANGELOG.md +49 -36
- package/dist/agents/baseagent.js +68 -6
- package/dist/agents/codex-runner.js +62 -43
- package/dist/aun/aid/agentmd.js +98 -11
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +26 -2
- package/dist/aun/aid/identity.js +91 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/managed-operation.js +1 -1
- package/dist/aun/aid/ownership-operation.js +23 -22
- package/dist/aun/menu/client.js +27 -0
- package/dist/aun/msg/p2p.js +3 -8
- package/dist/aun/service-proxy.js +17 -0
- package/dist/channels/aun.js +321 -34
- package/dist/cli/agent-command.js +5 -2
- package/dist/cli/agent-create.js +991 -233
- package/dist/cli/agent.js +49 -10
- package/dist/cli/aid-bind-command.js +48 -19
- package/dist/cli/aun-commands.js +44 -16
- package/dist/cli/daemon-commands.js +1 -0
- package/dist/cli/index.js +24 -1
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +13 -1
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/boot-log.js +3 -2
- package/dist/config/config-field-policy.js +12 -7
- package/dist/config/config-manager.js +138 -6
- package/dist/config/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +2 -1
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +8 -1
- package/dist/config/schema-migration.js +322 -8
- package/dist/config-store.js +10 -1
- package/dist/contracts/ecweb-service-protocol.js +2 -1
- package/dist/core/agent-application-service.js +60 -11
- package/dist/core/agent-create-status.js +203 -0
- package/dist/core/agent-creation-claim.js +177 -0
- package/dist/core/agent-ipc-registration.js +39 -18
- package/dist/core/agent-runtime.js +193 -23
- package/dist/core/auth/agent-delegation.js +4 -2
- package/dist/core/auth/auth-gateway.js +66 -1
- package/dist/core/auth/authorization-audit.js +41 -5
- package/dist/core/auth/delegation-authorization.js +2 -1
- package/dist/core/auth/operation-authorizer.js +28 -6
- package/dist/core/auth/operation-catalog.js +14 -1
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +257 -14
- package/dist/core/command/cli-intent-parser.js +6 -2
- package/dist/core/command/command-handler.js +64 -55
- package/dist/core/command/memory-slash.js +1 -1
- package/dist/core/command/menu-catalog.js +5 -0
- package/dist/core/command/menu-handler.js +64 -18
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/slash-handler.js +2 -1
- package/dist/core/daemon-control.js +18 -13
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +3 -1
- package/dist/core/evolagent.js +8 -6
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +34 -22
- package/dist/core/memory/consolidation-ops-records.js +95 -0
- package/dist/core/memory/consolidation-trigger.js +19 -2
- package/dist/core/memory/consolidation.js +19 -8
- package/dist/core/memory/memory-admin.js +1 -1
- package/dist/core/memory/relation-sweep.js +11 -6
- package/dist/core/message/aun-ipc-sender.js +73 -67
- package/dist/core/message/im-renderer.js +18 -0
- package/dist/core/message/message-bridge.js +35 -3
- package/dist/core/message/response-engine.js +32 -28
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/model/config-scope.js +5 -7
- package/dist/core/ownership/owner-resolver.js +755 -143
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +32 -4
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/tool-policy.js +7 -43
- package/dist/core/system-session/memory.js +37 -7
- package/dist/directory/owner-directory-cache.js +2 -2
- package/dist/ecweb/init-menu.js +32 -0
- package/dist/index.js +17 -5
- package/dist/ipc.js +85 -25
- package/dist/paths.js +3 -0
- package/dist/proxy/manager.js +6 -7
- package/dist/trigger/authorization.js +27 -17
- package/dist/trigger/feedback.js +2 -3
- package/dist/trigger/ipc-service.js +105 -78
- package/dist/trigger/local-files.js +2 -1
- package/dist/trigger/manager.js +5 -3
- package/dist/trigger/scheduler.js +88 -6
- package/dist/utils/atomic-write.js +28 -0
- package/dist/utils/error-utils.js +24 -0
- package/dist/utils/logger.js +68 -1
- package/dist/utils/welcome.js +1 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/aun/SDK.md +4 -1
- package/kits/docs/evolcore/INDEX.md +1 -0
- package/kits/docs/evolcore/agent.md +8 -1
- package/kits/docs/evolcore/aid.md +67 -17
- package/kits/docs/evolcore/config.md +11 -1
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- package/kits/schemas/_meta.json +2 -2
- package/kits/schemas/agent-config.schema.16.json +3 -3
- package/kits/schemas/relation-config.schema.11.json +17 -0
- package/kits/skills/.switches.json +8 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- package/kits/skills/ec-trigger/SKILL.md +5 -13
- package/kits/skills/thread-ops/SKILL.md +5 -0
- package/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +3 -3
- package/dist/core/memory/forget-log.js +0 -96
- package/dist/core/message/create-status.js +0 -96
|
@@ -10,6 +10,7 @@ import { checkDangerousCommand } from './tool-policy.js';
|
|
|
10
10
|
import { resolveProtectedCandidate } from './protected-paths.js';
|
|
11
11
|
import { auditPermissionDecision, auditPermissionLifecycle } from '../auth/authorization-audit.js';
|
|
12
12
|
import { ConfigTarget, onConfigWrite } from '../../config/config-manager.js';
|
|
13
|
+
import { permissionApprovalResult, permissionFailureResult } from './permission-result.js';
|
|
13
14
|
import { fileChangeApprovalScope, permissionApprovalScope, filesystemScopeContains, } from './filesystem-approval-scope.js';
|
|
14
15
|
export function parsePermissionApprovalDecision(value) {
|
|
15
16
|
if (value === 'approve_once')
|
|
@@ -27,23 +28,29 @@ export function parsePermissionApprovalDecision(value) {
|
|
|
27
28
|
}
|
|
28
29
|
return undefined;
|
|
29
30
|
}
|
|
30
|
-
export async function requestDangerousCommandPermission(
|
|
31
|
+
export async function requestDangerousCommandPermission(...args) {
|
|
32
|
+
const outcome = await requestDangerousCommandPermissionResult(...args);
|
|
33
|
+
return outcome.matched ? { matched: true, decision: outcome.result.decision } : outcome;
|
|
34
|
+
}
|
|
35
|
+
export async function requestDangerousCommandPermissionResult(gateway, sessionId, toolName, input, sendPrompt, context, grantScope = 'default', mode = 'request') {
|
|
31
36
|
const dangerCheck = checkDangerousCommand(toolName, input);
|
|
32
37
|
if (!dangerCheck.isDangerous) {
|
|
33
38
|
return { matched: false };
|
|
34
39
|
}
|
|
35
40
|
if (mode === 'bypass' && dangerCheck.approvalScope === 'request') {
|
|
36
|
-
return { matched: true,
|
|
41
|
+
return { matched: true, result: {
|
|
42
|
+
decision: 'allow', decisionSource: 'policy', requestId: `perm-policy-${randomUUID()}`,
|
|
43
|
+
reason: '当前权限模式允许执行此操作。',
|
|
44
|
+
} };
|
|
37
45
|
}
|
|
38
46
|
if (!gateway || !sendPrompt) {
|
|
47
|
+
const result = permissionFailureResult(`perm-infra-${randomUUID()}`, !gateway ? 'approval_gateway_unavailable' : 'approval_prompt_unavailable', {}, 'approval_channel_unavailable');
|
|
39
48
|
logger.warn(`[PermissionGateway] Dangerous operation denied because approval is unavailable: session=${sessionId} tool=${toolName}`);
|
|
40
49
|
auditPermissionDecision({
|
|
41
|
-
|
|
50
|
+
...result,
|
|
42
51
|
sessionId,
|
|
43
52
|
toolName,
|
|
44
|
-
|
|
45
|
-
policyCode: 'approval_channel_unavailable',
|
|
46
|
-
reason: 'dangerous operation approval channel is unavailable',
|
|
53
|
+
policyCode: result.policyCode,
|
|
47
54
|
permissionMode: context?.permissionMode,
|
|
48
55
|
agentAid: context?.selfAid,
|
|
49
56
|
agentName: context?.agentName,
|
|
@@ -51,10 +58,10 @@ export async function requestDangerousCommandPermission(gateway, sessionId, tool
|
|
|
51
58
|
taskId: context?.taskId,
|
|
52
59
|
summary: summarizeToolInputForAudit(toolName, input).slice(0, 512),
|
|
53
60
|
});
|
|
54
|
-
return { matched: true,
|
|
61
|
+
return { matched: true, result };
|
|
55
62
|
}
|
|
56
|
-
const
|
|
57
|
-
return { matched: true,
|
|
63
|
+
const result = await gateway.requestPermissionResult(sessionId, dangerCheck.cacheKey, input, sendPrompt, context, `⚠️ ${dangerCheck.command}`, dangerCheck.reason, grantScope, dangerCheck.kind === 'git-destructive' ? 'agent_manager' : undefined);
|
|
64
|
+
return { matched: true, result };
|
|
58
65
|
}
|
|
59
66
|
const SESSION_GRANT_TTL_MS = 30 * 60 * 1000;
|
|
60
67
|
const FILESYSTEM_GRANT_TTL_MS = 60 * 60 * 1000;
|
|
@@ -142,6 +149,7 @@ function permissionGrantMatch(toolName, input, options) {
|
|
|
142
149
|
}),
|
|
143
150
|
scope: 'file-change-paths',
|
|
144
151
|
filesystem,
|
|
152
|
+
workspacePath: options?.workspacePath ?? fileChangeCwd,
|
|
145
153
|
};
|
|
146
154
|
}
|
|
147
155
|
}
|
|
@@ -154,6 +162,7 @@ function permissionGrantMatch(toolName, input, options) {
|
|
|
154
162
|
inputFingerprint: permissionInputFingerprint(input),
|
|
155
163
|
scope: 'exact-operation',
|
|
156
164
|
filesystem,
|
|
165
|
+
workspacePath: options?.workspacePath ?? fileChangeCwd,
|
|
157
166
|
};
|
|
158
167
|
}
|
|
159
168
|
function permissionGrantContextKey(context, approverPolicy) {
|
|
@@ -213,6 +222,9 @@ function approvalButtons(match, route, context) {
|
|
|
213
222
|
}
|
|
214
223
|
buttons.push({ key: 'deny', label: '✗ 拒绝', style: 'danger' });
|
|
215
224
|
const detail = scope ? [
|
|
225
|
+
...(match.workspacePath ? [`当前工作区:${match.workspacePath}`] : []),
|
|
226
|
+
`目标文件:\n${scope.targets.map(target => target.path).join("\n")}`,
|
|
227
|
+
'默认仅允许本次请求中的明确目标;目录或跨请求授权必须单独选择。',
|
|
216
228
|
...(scope.directory ? [`目录授权范围(含子目录):${scope.directory}`] : []),
|
|
217
229
|
...(owner ? ['“所有普通目录 60 分钟”覆盖当前会话内所有非受保护目录。'] : []),
|
|
218
230
|
`临时文件权限:${scope.access === 'write' ? '读写' : '只读'};仅当前会话和权限上下文有效。`,
|
|
@@ -378,7 +390,7 @@ export function planApprovalRoute(challenge, context) {
|
|
|
378
390
|
return { kind: 'unavailable', reason: 'no_aun_owner_available' };
|
|
379
391
|
}
|
|
380
392
|
if (!routing?.ownerAdapter) {
|
|
381
|
-
return { kind: 'unavailable', reason: 'owner_approval_channel_unavailable' };
|
|
393
|
+
return { kind: 'unavailable', reason: 'owner_approval_channel_unavailable', approverOperatorId: approverId, approverPrincipalId: approverId };
|
|
382
394
|
}
|
|
383
395
|
return {
|
|
384
396
|
kind: 'handoff',
|
|
@@ -640,70 +652,17 @@ export class PermissionGateway {
|
|
|
640
652
|
this.syncManagementRevalidationTimer();
|
|
641
653
|
const sessionGrant = selectedDecision !== 'allow' && selectedDecision !== 'deny';
|
|
642
654
|
const approved = selectedDecision !== 'deny';
|
|
643
|
-
const
|
|
655
|
+
const result = permissionApprovalResult(requestId, approved ? 'allow' : 'deny', pending);
|
|
644
656
|
const decisionCausation = deriveCausation(pending.causation);
|
|
645
657
|
if (sessionGrant)
|
|
646
658
|
this.addTemporaryGrant(pending, selectedDecision, decisionCausation);
|
|
647
|
-
pending.resolve(
|
|
648
|
-
|
|
649
|
-
phase: 'response',
|
|
650
|
-
requestId,
|
|
651
|
-
sessionId,
|
|
652
|
-
toolName: pending.toolName,
|
|
653
|
-
decision: approved ? 'allow' : 'deny',
|
|
654
|
-
decisionSource: 'approval',
|
|
655
|
-
policyCode: approved ? undefined : 'user_approval_denied',
|
|
656
|
-
reason: approved ? 'owner approval accepted' : 'owner approval denied',
|
|
657
|
-
permissionMode: pending.permissionMode,
|
|
658
|
-
agentAid: pending.selfAid,
|
|
659
|
-
agentName: pending.agentName,
|
|
660
|
-
role: pending.role,
|
|
661
|
-
taskId: pending.taskId,
|
|
662
|
-
summary: pending.auditSummary,
|
|
663
|
-
response: action,
|
|
664
|
-
});
|
|
665
|
-
auditPermissionLifecycle({
|
|
666
|
-
phase: 'final',
|
|
667
|
-
requestId,
|
|
668
|
-
sessionId,
|
|
669
|
-
toolName: pending.toolName,
|
|
670
|
-
decision: approved ? 'allow' : 'deny',
|
|
671
|
-
decisionSource: 'approval',
|
|
672
|
-
policyCode: approved ? undefined : 'user_approval_denied',
|
|
673
|
-
reason: approved ? 'owner approval accepted' : 'owner approval denied',
|
|
674
|
-
permissionMode: pending.permissionMode,
|
|
675
|
-
agentAid: pending.selfAid,
|
|
676
|
-
agentName: pending.agentName,
|
|
677
|
-
role: pending.role,
|
|
678
|
-
taskId: pending.taskId,
|
|
679
|
-
summary: pending.auditSummary,
|
|
680
|
-
response: action,
|
|
681
|
-
});
|
|
682
|
-
void this.notifyPermissionState(pending, approved
|
|
683
|
-
? { state: 'approved', requestId, toolName: pending.toolName }
|
|
684
|
-
: {
|
|
685
|
-
state: 'failed',
|
|
686
|
-
requestId,
|
|
687
|
-
toolName: pending.toolName,
|
|
688
|
-
reason: 'denied',
|
|
689
|
-
message: 'owner 已拒绝授权,任务已停止。',
|
|
690
|
-
});
|
|
659
|
+
pending.resolve(result);
|
|
660
|
+
this.recordPermissionResult(sessionId, pending.toolName, result, pending, pending.auditSummary, action);
|
|
691
661
|
recordCausationSpan(decisionCausation, 'permission.decision', {
|
|
692
662
|
status: approved ? 'completed' : 'failed',
|
|
693
663
|
refs: { permissionRequestId: requestId, sessionId },
|
|
694
664
|
reason: approved ? undefined : 'denied',
|
|
695
665
|
});
|
|
696
|
-
this.eventBus?.publish({
|
|
697
|
-
type: 'permission:resolved',
|
|
698
|
-
sessionId,
|
|
699
|
-
requestId,
|
|
700
|
-
toolName: pending.toolName,
|
|
701
|
-
approved,
|
|
702
|
-
...(approved
|
|
703
|
-
? { decisionSource: 'approval' }
|
|
704
|
-
: { decisionSource: 'approval', policyCode: 'user_approval_denied' }),
|
|
705
|
-
causation: decisionCausation,
|
|
706
|
-
});
|
|
707
666
|
return true;
|
|
708
667
|
}
|
|
709
668
|
expireCrossSessionPermission(sessionId, requestId, reason, notifyState = true, cancelled = reason === 'cancelled') {
|
|
@@ -714,81 +673,15 @@ export class PermissionGateway {
|
|
|
714
673
|
pending.interactionRouter?.cancel(requestId, reason);
|
|
715
674
|
this.crossSessionPending.delete(requestId);
|
|
716
675
|
this.syncManagementRevalidationTimer();
|
|
717
|
-
pending
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
auditPermissionLifecycle({
|
|
721
|
-
phase: 'response',
|
|
722
|
-
requestId,
|
|
723
|
-
sessionId,
|
|
724
|
-
toolName: pending.toolName,
|
|
725
|
-
decision: 'deny',
|
|
726
|
-
decisionSource,
|
|
727
|
-
policyCode,
|
|
728
|
-
reason,
|
|
729
|
-
permissionMode: pending.permissionMode,
|
|
730
|
-
agentAid: pending.selfAid,
|
|
731
|
-
agentName: pending.agentName,
|
|
732
|
-
role: pending.role,
|
|
733
|
-
taskId: pending.taskId,
|
|
734
|
-
summary: pending.auditSummary,
|
|
735
|
-
response: reason,
|
|
736
|
-
});
|
|
737
|
-
auditPermissionDecision({
|
|
738
|
-
requestId,
|
|
739
|
-
sessionId,
|
|
740
|
-
toolName: pending.toolName,
|
|
741
|
-
decisionSource,
|
|
742
|
-
policyCode,
|
|
743
|
-
reason,
|
|
744
|
-
permissionMode: pending.permissionMode,
|
|
745
|
-
agentAid: pending.selfAid,
|
|
746
|
-
agentName: pending.agentName,
|
|
747
|
-
role: pending.role,
|
|
748
|
-
taskId: pending.taskId,
|
|
749
|
-
summary: pending.auditSummary,
|
|
750
|
-
});
|
|
751
|
-
if (notifyState) {
|
|
752
|
-
const failure = permissionFailure(reason);
|
|
753
|
-
void this.notifyPermissionState(pending, {
|
|
754
|
-
state: 'failed',
|
|
755
|
-
requestId,
|
|
756
|
-
toolName: pending.toolName,
|
|
757
|
-
reason,
|
|
758
|
-
message: failure,
|
|
759
|
-
});
|
|
760
|
-
}
|
|
676
|
+
const result = permissionFailureResult(requestId, reason, pending);
|
|
677
|
+
pending.resolve(result);
|
|
678
|
+
this.recordPermissionResult(sessionId, pending.toolName, result, pending, pending.auditSummary, reason, notifyState, cancelled);
|
|
761
679
|
const decisionCausation = deriveCausation(pending.causation);
|
|
762
680
|
recordCausationSpan(decisionCausation, 'permission.decision', {
|
|
763
681
|
status: 'failed',
|
|
764
682
|
refs: { permissionRequestId: requestId, sessionId },
|
|
765
683
|
reason,
|
|
766
684
|
});
|
|
767
|
-
if (cancelled) {
|
|
768
|
-
this.eventBus?.publish({
|
|
769
|
-
type: 'permission:cancelled',
|
|
770
|
-
sessionId,
|
|
771
|
-
requestId,
|
|
772
|
-
toolName: pending.toolName,
|
|
773
|
-
reason,
|
|
774
|
-
decisionSource: 'infrastructure',
|
|
775
|
-
policyCode: `approval_${reason}`,
|
|
776
|
-
causation: decisionCausation,
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
else {
|
|
780
|
-
this.eventBus?.publish({
|
|
781
|
-
type: 'permission:resolved',
|
|
782
|
-
sessionId,
|
|
783
|
-
requestId,
|
|
784
|
-
toolName: pending.toolName,
|
|
785
|
-
reason,
|
|
786
|
-
approved: false,
|
|
787
|
-
decisionSource: 'infrastructure',
|
|
788
|
-
policyCode: `approval_${reason}`,
|
|
789
|
-
causation: decisionCausation,
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
685
|
return true;
|
|
793
686
|
}
|
|
794
687
|
async requestCrossSessionPermission(sessionId, challenge, route, sendPrompt, context, grantScope, requestCausation, grantMatch) {
|
|
@@ -796,39 +689,13 @@ export class PermissionGateway {
|
|
|
796
689
|
const interactionRouter = context.interactionRouter;
|
|
797
690
|
const auditSummary = summarizeToolInputForAudit(challenge.toolName, challenge.toolInput).slice(0, 512);
|
|
798
691
|
if (!approval || !interactionRouter) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
toolName: challenge.toolName,
|
|
805
|
-
decision: 'deny',
|
|
806
|
-
decisionSource: 'infrastructure',
|
|
807
|
-
policyCode: 'approval_route_unavailable',
|
|
808
|
-
reason: 'owner approval routing context is unavailable',
|
|
809
|
-
permissionMode: context.permissionMode,
|
|
810
|
-
agentAid: context.selfAid,
|
|
811
|
-
agentName: context.agentName,
|
|
812
|
-
role: context.role,
|
|
813
|
-
taskId: context.taskId,
|
|
814
|
-
summary: auditSummary,
|
|
815
|
-
response: 'unavailable',
|
|
816
|
-
});
|
|
817
|
-
auditPermissionDecision({
|
|
818
|
-
requestId: challenge.id,
|
|
819
|
-
sessionId,
|
|
820
|
-
toolName: challenge.toolName,
|
|
821
|
-
decisionSource: 'infrastructure',
|
|
822
|
-
policyCode: 'approval_route_unavailable',
|
|
823
|
-
reason: 'owner approval routing context is unavailable',
|
|
824
|
-
permissionMode: context.permissionMode,
|
|
825
|
-
agentAid: context.selfAid,
|
|
826
|
-
agentName: context.agentName,
|
|
827
|
-
role: context.role,
|
|
828
|
-
taskId: context.taskId,
|
|
829
|
-
summary: structuredApprovalAuditSummary(challenge.toolInput),
|
|
692
|
+
const failure = !approval ? 'approval_routing_context_unavailable' : 'approval_router_unavailable';
|
|
693
|
+
const result = permissionFailureResult(challenge.id, failure, route, 'approval_route_unavailable');
|
|
694
|
+
this.recordPermissionResult(sessionId, challenge.toolName, result, context, auditSummary, failure);
|
|
695
|
+
await sendPrompt(`${result.reason}\nrequest_id=${challenge.id}`).catch(error => {
|
|
696
|
+
logger.warn(`[PermissionGateway] Failure notice delivery failed: request=${challenge.id} error=${String(error)}`);
|
|
830
697
|
});
|
|
831
|
-
return
|
|
698
|
+
return result;
|
|
832
699
|
}
|
|
833
700
|
const { id: requestId, toolName, toolInput, summary: displaySummary, reason } = challenge;
|
|
834
701
|
const ttlMs = approval.approvalTtlMs && approval.approvalTtlMs > 0
|
|
@@ -913,7 +780,7 @@ export class PermissionGateway {
|
|
|
913
780
|
approverOperatorId: route.approverOperatorId,
|
|
914
781
|
approverChannelKey: route.approverChannelKey,
|
|
915
782
|
approverPrincipalId: route.approverPrincipalId,
|
|
916
|
-
selfAid: approval.selfAid,
|
|
783
|
+
selfAid: context.selfAid ?? approval.selfAid,
|
|
917
784
|
agentName: context.agentName,
|
|
918
785
|
permissionMode: context.permissionMode,
|
|
919
786
|
role: context.role,
|
|
@@ -992,13 +859,13 @@ export class PermissionGateway {
|
|
|
992
859
|
sent = isInteractionSendAccepted(receipt);
|
|
993
860
|
}
|
|
994
861
|
catch (error) {
|
|
995
|
-
logger.warn(`[PermissionGateway] Owner approval delivery failed: session=${sessionId} tool=${toolName} error=${error instanceof Error ? error.message : String(error)}`);
|
|
862
|
+
logger.warn(`[PermissionGateway] Owner approval delivery failed: request=${requestId} session=${sessionId} tool=${toolName} error=${error instanceof Error ? error.message : String(error)}`);
|
|
996
863
|
}
|
|
997
864
|
if (this.crossSessionPending.get(requestId) !== crossPending) {
|
|
998
865
|
return decisionPromise;
|
|
999
866
|
}
|
|
1000
867
|
if (!sent) {
|
|
1001
|
-
this.expireCrossSessionPermission(sessionId, requestId, '
|
|
868
|
+
this.expireCrossSessionPermission(sessionId, requestId, 'delivery_failed');
|
|
1002
869
|
return decisionPromise;
|
|
1003
870
|
}
|
|
1004
871
|
void this.notifyPermissionState(this.crossSessionPending.get(requestId), {
|
|
@@ -1019,7 +886,35 @@ export class PermissionGateway {
|
|
|
1019
886
|
logger.warn(`[PermissionGateway] permission state delivery failed: request=${event.requestId} state=${event.state} error=${error instanceof Error ? error.message : String(error)}`);
|
|
1020
887
|
}
|
|
1021
888
|
}
|
|
1022
|
-
|
|
889
|
+
recordPermissionResult(sessionId, toolName, result, context, summary, response = result.decision, notifyState = true, cancelled = false) {
|
|
890
|
+
const audit = {
|
|
891
|
+
...result,
|
|
892
|
+
sessionId,
|
|
893
|
+
toolName,
|
|
894
|
+
agentAid: context?.selfAid,
|
|
895
|
+
agentName: context?.agentName,
|
|
896
|
+
permissionMode: context?.permissionMode,
|
|
897
|
+
role: context?.role,
|
|
898
|
+
taskId: context?.taskId,
|
|
899
|
+
summary,
|
|
900
|
+
response,
|
|
901
|
+
};
|
|
902
|
+
auditPermissionLifecycle({ ...audit, phase: 'response' });
|
|
903
|
+
auditPermissionLifecycle({ ...audit, phase: 'final' });
|
|
904
|
+
const event = { ...result, reason: response, message: result.reason, sessionId, toolName, causation: context?.causation };
|
|
905
|
+
this.eventBus?.publish(cancelled
|
|
906
|
+
? { ...event, type: 'permission:cancelled' }
|
|
907
|
+
: { ...event, type: 'permission:resolved', approved: result.decision !== 'deny' });
|
|
908
|
+
if (notifyState)
|
|
909
|
+
void this.notifyPermissionState(context, result.decision === 'deny'
|
|
910
|
+
? {
|
|
911
|
+
...result, state: 'failed', toolName,
|
|
912
|
+
reason: result.policyCode === 'user_approval_denied' ? 'denied' : response,
|
|
913
|
+
message: result.reason,
|
|
914
|
+
}
|
|
915
|
+
: { state: 'approved', requestId: result.requestId, toolName });
|
|
916
|
+
}
|
|
917
|
+
failPendingPermission(sessionId, requestId, reason, notifyState = true, cancelled = false) {
|
|
1023
918
|
const pending = this.pending.get(requestId);
|
|
1024
919
|
if (!pending || pending.sessionId !== sessionId)
|
|
1025
920
|
return false;
|
|
@@ -1027,68 +922,31 @@ export class PermissionGateway {
|
|
|
1027
922
|
pending.interactionRouter?.cancel(requestId, reason);
|
|
1028
923
|
this.pending.delete(requestId);
|
|
1029
924
|
this.syncManagementRevalidationTimer();
|
|
1030
|
-
pending
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
phase: 'response',
|
|
1034
|
-
requestId,
|
|
1035
|
-
sessionId,
|
|
1036
|
-
toolName: pending.toolName,
|
|
1037
|
-
decision: 'deny',
|
|
1038
|
-
decisionSource,
|
|
1039
|
-
policyCode: `approval_${reason}`,
|
|
1040
|
-
reason,
|
|
1041
|
-
permissionMode: pending.permissionMode,
|
|
1042
|
-
agentAid: pending.selfAid,
|
|
1043
|
-
agentName: pending.agentName,
|
|
1044
|
-
role: pending.role,
|
|
1045
|
-
taskId: pending.taskId,
|
|
1046
|
-
summary: pending.auditSummary,
|
|
1047
|
-
response: reason,
|
|
1048
|
-
});
|
|
1049
|
-
auditPermissionDecision({
|
|
1050
|
-
requestId,
|
|
1051
|
-
sessionId,
|
|
1052
|
-
toolName: pending.toolName,
|
|
1053
|
-
decisionSource,
|
|
1054
|
-
policyCode: `approval_${reason}`,
|
|
1055
|
-
reason,
|
|
1056
|
-
permissionMode: pending.permissionMode,
|
|
1057
|
-
agentAid: pending.selfAid,
|
|
1058
|
-
agentName: pending.agentName,
|
|
1059
|
-
role: pending.role,
|
|
1060
|
-
taskId: pending.taskId,
|
|
1061
|
-
summary: pending.auditSummary,
|
|
1062
|
-
});
|
|
925
|
+
const result = permissionFailureResult(requestId, reason, pending);
|
|
926
|
+
pending.resolve(result);
|
|
927
|
+
this.recordPermissionResult(sessionId, pending.toolName, result, pending, pending.auditSummary, reason, notifyState, cancelled);
|
|
1063
928
|
const decisionCausation = deriveCausation(pending.causation);
|
|
1064
929
|
recordCausationSpan(decisionCausation, 'permission.decision', {
|
|
1065
930
|
status: 'failed',
|
|
1066
931
|
refs: { permissionRequestId: requestId, sessionId },
|
|
1067
932
|
reason,
|
|
1068
933
|
});
|
|
1069
|
-
this.eventBus?.publish({
|
|
1070
|
-
type: 'permission:resolved',
|
|
1071
|
-
sessionId,
|
|
1072
|
-
requestId,
|
|
1073
|
-
toolName: pending.toolName,
|
|
1074
|
-
reason,
|
|
1075
|
-
approved: false,
|
|
1076
|
-
decisionSource,
|
|
1077
|
-
policyCode: `approval_${reason}`,
|
|
1078
|
-
causation: decisionCausation,
|
|
1079
|
-
});
|
|
1080
934
|
return true;
|
|
1081
935
|
}
|
|
1082
936
|
/**
|
|
1083
937
|
* 请求人工审批。返回三态决策。
|
|
1084
938
|
*/
|
|
1085
|
-
async requestPermission(
|
|
939
|
+
async requestPermission(...args) {
|
|
940
|
+
return (await this.requestPermissionResult(...args)).decision;
|
|
941
|
+
}
|
|
942
|
+
async requestPermissionResult(sessionId, toolName, toolInput, sendPrompt, context, summary, reason, grantScope = 'default', approverPolicy, matchOptions) {
|
|
943
|
+
const requestId = `perm-${randomUUID()}`;
|
|
1086
944
|
const effectiveApproverPolicy = approverPolicy
|
|
1087
945
|
?? context?.approvalRouting?.approverPolicy
|
|
1088
946
|
?? 'requester';
|
|
1089
947
|
const auditSummary = summarizeToolInputForAudit(toolName, toolInput).slice(0, 512);
|
|
1090
948
|
if (context?.approvalInteractionPolicy === 'deny') {
|
|
1091
|
-
const denialRequestId =
|
|
949
|
+
const denialRequestId = requestId;
|
|
1092
950
|
const anomaly = {
|
|
1093
951
|
code: 'runtime_permission_denied',
|
|
1094
952
|
severity: 'warning',
|
|
@@ -1112,38 +970,17 @@ export class PermissionGateway {
|
|
|
1112
970
|
logger.warn(`[PermissionGateway] Failed to record unattended denial: session=${sessionId} tool=${toolName} error=${error instanceof Error ? error.message : String(error)}`);
|
|
1113
971
|
}
|
|
1114
972
|
logger.info(`[PermissionGateway] Unattended runtime permission denied: session=${sessionId} tool=${toolName} policy=${effectiveApproverPolicy}`);
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
toolName,
|
|
1119
|
-
decisionSource: 'policy',
|
|
1120
|
-
policyCode: 'permission_mode_denied',
|
|
1121
|
-
reason: 'permission mode denied runtime approval',
|
|
1122
|
-
permissionMode: context.permissionMode,
|
|
1123
|
-
agentAid: context.selfAid,
|
|
1124
|
-
agentName: context.agentName,
|
|
1125
|
-
role: context.role,
|
|
1126
|
-
taskId: context.taskId,
|
|
1127
|
-
summary: auditSummary,
|
|
1128
|
-
});
|
|
1129
|
-
return 'deny';
|
|
973
|
+
const result = permissionFailureResult(requestId, 'permission_mode_denied', {}, 'permission_mode_denied');
|
|
974
|
+
this.recordPermissionResult(sessionId, toolName, result, context, auditSummary);
|
|
975
|
+
return result;
|
|
1130
976
|
}
|
|
1131
977
|
if (!context?.userId) {
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
decisionSource: 'infrastructure',
|
|
1137
|
-
policyCode: 'approval_identity_missing',
|
|
1138
|
-
reason: 'approval requester identity is unavailable',
|
|
1139
|
-
permissionMode: context?.permissionMode,
|
|
1140
|
-
agentAid: context?.selfAid,
|
|
1141
|
-
agentName: context?.agentName,
|
|
1142
|
-
role: context?.role,
|
|
1143
|
-
taskId: context?.taskId,
|
|
1144
|
-
summary: auditSummary,
|
|
978
|
+
const result = permissionFailureResult(requestId, 'approval_identity_missing', {}, 'approval_identity_missing');
|
|
979
|
+
this.recordPermissionResult(sessionId, toolName, result, context, auditSummary);
|
|
980
|
+
await sendPrompt(`${result.reason}\nrequest_id=${requestId}`).catch(error => {
|
|
981
|
+
logger.warn(`[PermissionGateway] Failure notice delivery failed: request=${requestId} error=${String(error)}`);
|
|
1145
982
|
});
|
|
1146
|
-
return
|
|
983
|
+
return result;
|
|
1147
984
|
}
|
|
1148
985
|
const grantMatch = permissionGrantMatch(toolName, toolInput, matchOptions);
|
|
1149
986
|
const grantContextKey = permissionGrantContextKey(context, effectiveApproverPolicy);
|
|
@@ -1157,9 +994,8 @@ export class PermissionGateway {
|
|
|
1157
994
|
refs: { taskId: context?.taskId, sessionId },
|
|
1158
995
|
reason: `temporary_grant:${temporaryGrant.target.kind}:expires=${temporaryGrant.expiresAt}`,
|
|
1159
996
|
});
|
|
1160
|
-
return 'allow';
|
|
997
|
+
return { decision: 'allow', decisionSource: 'approval', requestId, reason: '已使用仍然有效的临时授权。' };
|
|
1161
998
|
}
|
|
1162
|
-
const requestId = `perm-${randomUUID()}`;
|
|
1163
999
|
const displaySummary = summary || summarizeToolInput(toolName, toolInput);
|
|
1164
1000
|
const reasonLine = reason ? `\n原因:${reason}` : '';
|
|
1165
1001
|
const challenge = {
|
|
@@ -1196,61 +1032,23 @@ export class PermissionGateway {
|
|
|
1196
1032
|
const route = planApprovalRoute(challenge, context);
|
|
1197
1033
|
logger.info(`[PermissionGateway] approval_route request=${requestId} policy=${challenge.approverPolicy}`
|
|
1198
1034
|
+ ` route=${route.kind}`
|
|
1199
|
-
+ ` operator=${route.
|
|
1200
|
-
+ ` channel=${route.
|
|
1201
|
-
+ ` principal=${route.
|
|
1035
|
+
+ ` operator=${route.approverOperatorId ?? '<none>'}`
|
|
1036
|
+
+ ` channel=${route.approverChannelKey ?? '<none>'}`
|
|
1037
|
+
+ ` principal=${route.approverPrincipalId ?? '<unmapped>'}`
|
|
1202
1038
|
+ `${route.kind === 'unavailable' ? ` reason=${route.reason}` : ''}`);
|
|
1203
1039
|
if (route.kind === 'unavailable') {
|
|
1204
|
-
|
|
1040
|
+
const result = permissionFailureResult(requestId, route.reason, route, 'approval_route_unavailable');
|
|
1205
1041
|
const decisionCausation = deriveCausation(requestCausation);
|
|
1206
1042
|
recordCausationSpan(decisionCausation, 'permission.decision', {
|
|
1207
1043
|
status: 'failed',
|
|
1208
1044
|
refs: { permissionRequestId: requestId, sessionId },
|
|
1209
1045
|
reason: route.reason,
|
|
1210
1046
|
});
|
|
1211
|
-
this.
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
requestId,
|
|
1215
|
-
toolName,
|
|
1216
|
-
reason: route.reason,
|
|
1217
|
-
approved: false,
|
|
1218
|
-
decisionSource: 'infrastructure',
|
|
1219
|
-
policyCode: 'approval_route_unavailable',
|
|
1220
|
-
causation: decisionCausation,
|
|
1047
|
+
this.recordPermissionResult(sessionId, toolName, result, context, auditSummary, route.reason);
|
|
1048
|
+
await sendPrompt(`${result.reason}\nrequest_id=${requestId}`).catch(error => {
|
|
1049
|
+
logger.warn(`[PermissionGateway] Failure notice delivery failed: request=${requestId} error=${String(error)}`);
|
|
1221
1050
|
});
|
|
1222
|
-
|
|
1223
|
-
requestId,
|
|
1224
|
-
sessionId,
|
|
1225
|
-
toolName,
|
|
1226
|
-
decisionSource: 'infrastructure',
|
|
1227
|
-
policyCode: 'approval_route_unavailable',
|
|
1228
|
-
reason: route.reason,
|
|
1229
|
-
permissionMode: context.permissionMode,
|
|
1230
|
-
agentAid: context.selfAid,
|
|
1231
|
-
agentName: context.agentName,
|
|
1232
|
-
role: context.role,
|
|
1233
|
-
taskId: context.taskId,
|
|
1234
|
-
summary: summarizeToolInputForAudit(toolName, toolInput).slice(0, 512),
|
|
1235
|
-
});
|
|
1236
|
-
auditPermissionLifecycle({
|
|
1237
|
-
phase: 'response',
|
|
1238
|
-
requestId,
|
|
1239
|
-
sessionId,
|
|
1240
|
-
toolName,
|
|
1241
|
-
decision: 'deny',
|
|
1242
|
-
decisionSource: 'infrastructure',
|
|
1243
|
-
policyCode: 'approval_route_unavailable',
|
|
1244
|
-
reason: route.reason,
|
|
1245
|
-
permissionMode: context.permissionMode,
|
|
1246
|
-
agentAid: context.selfAid,
|
|
1247
|
-
agentName: context.agentName,
|
|
1248
|
-
role: context.role,
|
|
1249
|
-
taskId: context.taskId,
|
|
1250
|
-
summary: summarizeToolInputForAudit(toolName, toolInput).slice(0, 512),
|
|
1251
|
-
response: 'unavailable',
|
|
1252
|
-
});
|
|
1253
|
-
return 'deny';
|
|
1051
|
+
return result;
|
|
1254
1052
|
}
|
|
1255
1053
|
if (route.kind === 'handoff') {
|
|
1256
1054
|
return this.requestCrossSessionPermission(sessionId, challenge, route, sendPrompt, context, grantScope, requestCausation, grantMatch);
|
|
@@ -1295,7 +1093,7 @@ export class PermissionGateway {
|
|
|
1295
1093
|
approverOperatorId: route.approverOperatorId,
|
|
1296
1094
|
approverChannelKey: route.approverChannelKey,
|
|
1297
1095
|
approverPrincipalId: route.approverPrincipalId,
|
|
1298
|
-
selfAid: context?.approvalRouting?.selfAid,
|
|
1096
|
+
selfAid: context?.selfAid ?? context?.approvalRouting?.selfAid,
|
|
1299
1097
|
agentName: context?.agentName,
|
|
1300
1098
|
originPrincipalId: context?.approvalRouting?.originPrincipalId,
|
|
1301
1099
|
originAuthRevision: context?.approvalRouting?.originAuthRevision,
|
|
@@ -1383,10 +1181,14 @@ export class PermissionGateway {
|
|
|
1383
1181
|
await sendPrompt(renderActionAsText(interaction));
|
|
1384
1182
|
}
|
|
1385
1183
|
catch (error) {
|
|
1386
|
-
logger.warn(`[PermissionGateway] Approval delivery failed: session=${sessionId} tool=${toolName} error=${error instanceof Error ? error.message : String(error)}`);
|
|
1184
|
+
logger.warn(`[PermissionGateway] Approval delivery failed: request=${requestId} session=${sessionId} tool=${toolName} error=${error instanceof Error ? error.message : String(error)}`);
|
|
1387
1185
|
this.failPendingPermission(sessionId, requestId, 'delivery_failed');
|
|
1388
1186
|
}
|
|
1389
1187
|
}
|
|
1188
|
+
if (this.pending.get(requestId) === localPending)
|
|
1189
|
+
void this.notifyPermissionState(localPending, {
|
|
1190
|
+
state: 'waiting', requestId, toolName, expiresAt: interaction.expiresAt,
|
|
1191
|
+
});
|
|
1390
1192
|
return decisionPromise;
|
|
1391
1193
|
}
|
|
1392
1194
|
resolvePermission(sessionId, requestId, decision, operatorId, channelKey) {
|
|
@@ -1408,43 +1210,11 @@ export class PermissionGateway {
|
|
|
1408
1210
|
// through this gateway so the selected match scope and TTL are checked.
|
|
1409
1211
|
this.clearPendingResources(pending);
|
|
1410
1212
|
pending.interactionRouter?.cancel(requestId);
|
|
1411
|
-
|
|
1213
|
+
const result = permissionApprovalResult(requestId, normalizedDecision === 'deny' ? 'deny' : 'allow', pending);
|
|
1214
|
+
pending.resolve(result);
|
|
1412
1215
|
this.pending.delete(requestId);
|
|
1413
1216
|
this.syncManagementRevalidationTimer();
|
|
1414
|
-
|
|
1415
|
-
phase: 'response',
|
|
1416
|
-
requestId,
|
|
1417
|
-
sessionId,
|
|
1418
|
-
toolName: pending.toolName,
|
|
1419
|
-
decision: normalizedDecision === 'deny' ? 'deny' : 'allow',
|
|
1420
|
-
decisionSource: 'approval',
|
|
1421
|
-
policyCode: normalizedDecision === 'deny' ? 'user_approval_denied' : undefined,
|
|
1422
|
-
reason: normalizedDecision === 'deny' ? 'user approval denied' : 'user approval accepted',
|
|
1423
|
-
permissionMode: pending.permissionMode,
|
|
1424
|
-
agentAid: pending.selfAid,
|
|
1425
|
-
agentName: pending.agentName,
|
|
1426
|
-
role: pending.role,
|
|
1427
|
-
taskId: pending.taskId,
|
|
1428
|
-
summary: pending.auditSummary,
|
|
1429
|
-
response: normalizedDecision,
|
|
1430
|
-
});
|
|
1431
|
-
auditPermissionLifecycle({
|
|
1432
|
-
phase: 'final',
|
|
1433
|
-
requestId,
|
|
1434
|
-
sessionId,
|
|
1435
|
-
toolName: pending.toolName,
|
|
1436
|
-
decision: normalizedDecision === 'deny' ? 'deny' : 'allow',
|
|
1437
|
-
decisionSource: 'approval',
|
|
1438
|
-
policyCode: normalizedDecision === 'deny' ? 'user_approval_denied' : undefined,
|
|
1439
|
-
reason: normalizedDecision === 'deny' ? 'user approval denied' : 'user approval accepted',
|
|
1440
|
-
permissionMode: pending.permissionMode,
|
|
1441
|
-
agentAid: pending.selfAid,
|
|
1442
|
-
agentName: pending.agentName,
|
|
1443
|
-
role: pending.role,
|
|
1444
|
-
taskId: pending.taskId,
|
|
1445
|
-
summary: pending.auditSummary,
|
|
1446
|
-
response: normalizedDecision,
|
|
1447
|
-
});
|
|
1217
|
+
this.recordPermissionResult(sessionId, pending.toolName, result, pending, pending.auditSummary, normalizedDecision);
|
|
1448
1218
|
const decisionCausation = deriveCausation(pending.causation);
|
|
1449
1219
|
if (normalizedDecision !== 'allow' && normalizedDecision !== 'deny') {
|
|
1450
1220
|
this.addTemporaryGrant(pending, normalizedDecision, decisionCausation);
|
|
@@ -1454,9 +1224,6 @@ export class PermissionGateway {
|
|
|
1454
1224
|
refs: { permissionRequestId: requestId, sessionId },
|
|
1455
1225
|
reason: normalizedDecision,
|
|
1456
1226
|
});
|
|
1457
|
-
const decisionSource = 'approval';
|
|
1458
|
-
const policyCode = normalizedDecision === 'deny' ? 'user_approval_denied' : undefined;
|
|
1459
|
-
this.eventBus?.publish({ type: 'permission:resolved', sessionId, requestId, toolName: pending.toolName, approved: normalizedDecision !== 'deny', ...(policyCode ? { decisionSource, policyCode } : { decisionSource }), causation: decisionCausation });
|
|
1460
1227
|
return true;
|
|
1461
1228
|
}
|
|
1462
1229
|
/**
|
|
@@ -1511,57 +1278,7 @@ export class PermissionGateway {
|
|
|
1511
1278
|
cancelAll(sessionId, reason = 'cancelled', notifyState = true) {
|
|
1512
1279
|
for (const [requestId, pending] of this.pending.entries()) {
|
|
1513
1280
|
if (pending.sessionId === sessionId) {
|
|
1514
|
-
this.
|
|
1515
|
-
pending.interactionRouter?.cancel(requestId, reason);
|
|
1516
|
-
pending.resolve('deny');
|
|
1517
|
-
auditPermissionLifecycle({
|
|
1518
|
-
phase: 'response',
|
|
1519
|
-
requestId,
|
|
1520
|
-
sessionId,
|
|
1521
|
-
toolName: pending.toolName,
|
|
1522
|
-
decision: 'deny',
|
|
1523
|
-
decisionSource: 'infrastructure',
|
|
1524
|
-
policyCode: `approval_${reason}`,
|
|
1525
|
-
reason,
|
|
1526
|
-
permissionMode: pending.permissionMode,
|
|
1527
|
-
agentAid: pending.selfAid,
|
|
1528
|
-
agentName: pending.agentName,
|
|
1529
|
-
role: pending.role,
|
|
1530
|
-
taskId: pending.taskId,
|
|
1531
|
-
summary: pending.auditSummary,
|
|
1532
|
-
response: reason,
|
|
1533
|
-
});
|
|
1534
|
-
auditPermissionDecision({
|
|
1535
|
-
requestId,
|
|
1536
|
-
sessionId,
|
|
1537
|
-
toolName: pending.toolName,
|
|
1538
|
-
decisionSource: 'infrastructure',
|
|
1539
|
-
policyCode: `approval_${reason}`,
|
|
1540
|
-
reason,
|
|
1541
|
-
permissionMode: pending.permissionMode,
|
|
1542
|
-
agentAid: pending.selfAid,
|
|
1543
|
-
agentName: pending.agentName,
|
|
1544
|
-
role: pending.role,
|
|
1545
|
-
taskId: pending.taskId,
|
|
1546
|
-
summary: pending.auditSummary,
|
|
1547
|
-
});
|
|
1548
|
-
this.pending.delete(requestId);
|
|
1549
|
-
const decisionCausation = deriveCausation(pending.causation);
|
|
1550
|
-
recordCausationSpan(decisionCausation, 'permission.decision', {
|
|
1551
|
-
status: 'failed',
|
|
1552
|
-
refs: { permissionRequestId: requestId, sessionId },
|
|
1553
|
-
reason,
|
|
1554
|
-
});
|
|
1555
|
-
this.eventBus?.publish({
|
|
1556
|
-
type: 'permission:cancelled',
|
|
1557
|
-
sessionId,
|
|
1558
|
-
requestId,
|
|
1559
|
-
toolName: pending.toolName,
|
|
1560
|
-
reason,
|
|
1561
|
-
decisionSource: 'infrastructure',
|
|
1562
|
-
policyCode: `approval_${reason}`,
|
|
1563
|
-
causation: decisionCausation,
|
|
1564
|
-
});
|
|
1281
|
+
this.failPendingPermission(sessionId, requestId, reason, notifyState, true);
|
|
1565
1282
|
}
|
|
1566
1283
|
}
|
|
1567
1284
|
for (const requestId of [...this.crossSessionPending.keys()]) {
|
|
@@ -1571,22 +1288,12 @@ export class PermissionGateway {
|
|
|
1571
1288
|
}
|
|
1572
1289
|
async cancelAllPending(reason = 'daemon_restart') {
|
|
1573
1290
|
const crossSession = [...this.crossSessionPending.values()];
|
|
1574
|
-
for (const pending of crossSession)
|
|
1575
|
-
void this.notifyPermissionState(pending, {
|
|
1576
|
-
state: 'failed',
|
|
1577
|
-
requestId: pending.requestId,
|
|
1578
|
-
toolName: pending.toolName,
|
|
1579
|
-
reason,
|
|
1580
|
-
message: reason === 'daemon_restart'
|
|
1581
|
-
? 'daemon 已重启,审批任务已终止。'
|
|
1582
|
-
: '审批任务已终止。',
|
|
1583
|
-
});
|
|
1584
1291
|
const sessionIds = new Set([
|
|
1585
1292
|
...[...this.pending.values()].map(pending => pending.sessionId),
|
|
1586
1293
|
...crossSession.map(pending => pending.sessionId),
|
|
1587
1294
|
]);
|
|
1588
1295
|
for (const sessionId of sessionIds)
|
|
1589
|
-
this.cancelAll(sessionId, reason
|
|
1296
|
+
this.cancelAll(sessionId, reason);
|
|
1590
1297
|
}
|
|
1591
1298
|
/** 获取指定会话的所有 pending requestId */
|
|
1592
1299
|
getPendingRequests(sessionId) {
|
|
@@ -1604,10 +1311,3 @@ export class PermissionGateway {
|
|
|
1604
1311
|
return ids;
|
|
1605
1312
|
}
|
|
1606
1313
|
}
|
|
1607
|
-
function permissionFailure(reason) {
|
|
1608
|
-
if (reason === 'expired')
|
|
1609
|
-
return 'owner 审批超时,任务已停止。';
|
|
1610
|
-
if (reason === 'cancelled')
|
|
1611
|
-
return 'owner 审批已取消,任务已停止。';
|
|
1612
|
-
return '向 owner 发送授权申请失败,任务已停止。';
|
|
1613
|
-
}
|