evolcore 0.0.41-test.0 → 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 +62 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +88 -49
- package/dist/agents/claude-runner.js +177 -92
- package/dist/agents/codex-runner.js +146 -71
- package/dist/agents/ecagent-runner.js +1 -1
- package/dist/agents/gemini-runner.js +1 -1
- 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/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -21
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/menu/client.js +27 -0
- package/dist/aun/msg/managed-operation.js +68 -7
- package/dist/aun/msg/p2p.js +8 -8
- package/dist/aun/service-proxy.js +53 -12
- package/dist/channels/aun.js +633 -32
- package/dist/channels/daemon.js +15 -1
- 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 +48 -36
- package/dist/cli/daemon-commands.js +679 -697
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +72 -5
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +17 -1
- package/dist/cli/model.js +40 -40
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/role.js +85 -0
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/access-policy.js +7 -2
- package/dist/config/boot-log.js +39 -1
- package/dist/config/config-field-policy.js +17 -39
- package/dist/config/config-manager.js +183 -44
- package/dist/config/config-operation-service.js +5 -19
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +88 -594
- package/dist/config/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +15 -12
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +11 -1
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +1000 -25
- package/dist/config-store.js +89 -4
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +4 -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 +194 -24
- package/dist/core/auth/agent-delegation.js +6 -3
- package/dist/core/auth/auth-gateway.js +67 -2
- package/dist/core/auth/authorization-audit.js +58 -11
- package/dist/core/auth/delegation-authorization.js +5 -2
- package/dist/core/auth/operation-authorizer.js +43 -6
- package/dist/core/auth/operation-catalog.js +45 -7
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +260 -21
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +8 -3
- package/dist/core/command/command-handler.js +112 -154
- package/dist/core/command/connect-menu.js +11 -3
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +10 -6
- package/dist/core/command/menu-handler.js +106 -73
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/role-menu.js +147 -30
- package/dist/core/command/slash-handler.js +125 -255
- package/dist/core/daemon-control.js +26 -27
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +7 -5
- package/dist/core/evolagent.js +10 -8
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +40 -24
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +96 -1
- package/dist/core/memory/consolidation-trigger.js +208 -191
- package/dist/core/memory/consolidation.js +333 -35
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +55 -45
- package/dist/core/message/aun-ipc-sender.js +81 -69
- package/dist/core/message/im-renderer.js +25 -4
- package/dist/core/message/message-admission.js +89 -4
- package/dist/core/message/message-bridge.js +66 -21
- package/dist/core/message/response-engine.js +108 -35
- package/dist/core/model/catalog-service.js +5 -3
- package/dist/core/model/config-scope.js +29 -71
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +30 -41
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +772 -158
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +62 -6
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +21 -46
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +1 -1
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +20 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +43 -8
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/init-menu.js +32 -0
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +93 -19
- package/dist/ipc.js +247 -29
- package/dist/paths.js +7 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +484 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- 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/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +26 -2
- package/dist/utils/logger.js +92 -6
- package/dist/utils/package-version-info.js +4 -2
- 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/channels/aun.md +9 -0
- 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 +28 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/fs.md +11 -0
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +4 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +4 -7
- package/kits/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +8 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +277 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/skills/thread-ops/SKILL.md +5 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/memory.md +4 -4
- package/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +7 -3
- package/dist/core/message/create-status.js +0 -96
|
@@ -212,7 +212,13 @@ export function isTriggerOperator(definition, actorConversationPeerId) {
|
|
|
212
212
|
return triggerOperatorPeerIds(definition).includes(actorConversationPeerId);
|
|
213
213
|
}
|
|
214
214
|
export async function authorizeTriggerExecution(definition, dependencies) {
|
|
215
|
-
|
|
215
|
+
if (definition.labels?.kind === 'cross-thread-review'
|
|
216
|
+
&& definition.labels.originAuthorization !== 'creator-session-v1') {
|
|
217
|
+
return { allowed: false, reason: 'legacy cross-thread review creator is unverified; recreate the Trigger from its source conversation' };
|
|
218
|
+
}
|
|
219
|
+
await refreshOwnershipForAuthorization(definition.agentAid, {
|
|
220
|
+
allowTransient: true, includeDaemon: definition.execution.permissionMode === 'fullaccess',
|
|
221
|
+
});
|
|
216
222
|
if (definition.execution.permissionMode === 'fullaccess') {
|
|
217
223
|
if (!definition.authorizedBy) {
|
|
218
224
|
return { allowed: false, reason: 'fullaccess Trigger approval provenance is missing' };
|
|
@@ -378,30 +384,34 @@ export async function authenticatedTriggerActor(dependencies, agentAid, actorSes
|
|
|
378
384
|
: dependencies.agentDelegationRegistry.validate.bind(dependencies.agentDelegationRegistry))(typeof delegationToken === 'string' ? delegationToken : undefined, actorSessionId, typeof delegationCommandHash === 'string' ? delegationCommandHash : undefined);
|
|
379
385
|
if (!validation.ok)
|
|
380
386
|
throw new Error(validation.reason);
|
|
381
|
-
|
|
382
|
-
|
|
387
|
+
return authenticatedTriggerActorFromGrant(dependencies, agentAid, validation.grant);
|
|
388
|
+
}
|
|
389
|
+
/** Internal continuation of an already authenticated operation; never accept a grant from IPC input. */
|
|
390
|
+
export async function authenticatedTriggerActorFromGrant(dependencies, agentAid, grant) {
|
|
391
|
+
const actorSession = await dependencies.sessionManager.getSessionById(grant.sessionId);
|
|
392
|
+
const actorOrigin = actorSession ? originFromActorSession(actorSession, grant.actorId, grant.channel, grant.chatType) : undefined;
|
|
383
393
|
if (!actorSession || !actorOrigin?.peerId)
|
|
384
394
|
throw new Error('trigger actor session has no authenticated peer');
|
|
385
|
-
if (
|
|
395
|
+
if (grant.actorId !== actorOrigin.peerId) {
|
|
386
396
|
throw new Error('trigger delegation actor does not match session peer');
|
|
387
397
|
}
|
|
388
398
|
const actorChatType = triggerOriginChatType(actorOrigin);
|
|
389
|
-
await refreshOwnershipForAuthorization(agentAid, { allowTransient: true });
|
|
399
|
+
await refreshOwnershipForAuthorization(agentAid, { allowTransient: true, includeDaemon: true });
|
|
390
400
|
const actorConversationId = actorChatType === 'group' ? actorOrigin.channelId : actorOrigin.peerId;
|
|
391
401
|
const roleDetail = resolvePeerRoleDetail({
|
|
392
402
|
selfAid: agentAid,
|
|
393
|
-
channelKey:
|
|
394
|
-
channelType:
|
|
403
|
+
channelKey: grant.channel,
|
|
404
|
+
channelType: grant.channelType,
|
|
395
405
|
chatType: actorChatType,
|
|
396
|
-
actorId:
|
|
406
|
+
actorId: grant.actorId,
|
|
397
407
|
conversationId: actorConversationId,
|
|
398
408
|
});
|
|
399
409
|
const currentRole = roleDetail.effectiveRole;
|
|
400
410
|
const subject = buildAuthSubject({
|
|
401
411
|
selfAid: agentAid,
|
|
402
|
-
actorId:
|
|
403
|
-
channel:
|
|
404
|
-
channelType:
|
|
412
|
+
actorId: grant.actorId,
|
|
413
|
+
channel: grant.channel,
|
|
414
|
+
channelType: grant.channelType,
|
|
405
415
|
channelId: actorOrigin.channelId,
|
|
406
416
|
chatType: actorChatType,
|
|
407
417
|
conversationId: actorConversationId,
|
|
@@ -409,9 +419,9 @@ export async function authenticatedTriggerActor(dependencies, agentAid, actorSes
|
|
|
409
419
|
identity: roleToSessionIdentity(currentRole),
|
|
410
420
|
processOwners: dependencies.getDaemonOwners(),
|
|
411
421
|
fromControlChannel: false,
|
|
412
|
-
...trustedExecutionIdentityInput(
|
|
422
|
+
...trustedExecutionIdentityInput(grant),
|
|
413
423
|
});
|
|
414
|
-
if (
|
|
424
|
+
if (grant.selfAid !== agentAid && subject.dataScope !== 'daemon') {
|
|
415
425
|
throw new Error('cross-agent Trigger operations require DaemonOwner');
|
|
416
426
|
}
|
|
417
427
|
if (subject.dataScope !== 'daemon' && !checkRoleAccess(currentRole, agentAid)) {
|
|
@@ -420,11 +430,11 @@ export async function authenticatedTriggerActor(dependencies, agentAid, actorSes
|
|
|
420
430
|
const permissionDecision = subject.processRole === 'fullaccess-run'
|
|
421
431
|
? { effectiveValue: 'fullaccess' }
|
|
422
432
|
: subject.dataScope === 'daemon'
|
|
423
|
-
? { effectiveValue:
|
|
433
|
+
? { effectiveValue: grant.permissionMode ?? subject.permissionMode ?? 'bypass' }
|
|
424
434
|
: constrainRuntimePermissionMode({
|
|
425
435
|
selfAid: agentAid,
|
|
426
436
|
role: currentRole,
|
|
427
|
-
requestedValue:
|
|
437
|
+
requestedValue: grant.permissionMode ?? subject.permissionMode,
|
|
428
438
|
});
|
|
429
439
|
if (subject.processRole === 'fullaccess-run'
|
|
430
440
|
&& (!subject.authorizedBy || !dependencies.getDaemonOwners().includes(subject.authorizedBy))) {
|
|
@@ -436,11 +446,11 @@ export async function authenticatedTriggerActor(dependencies, agentAid, actorSes
|
|
|
436
446
|
daemonOwner: subject.isDaemonOwner,
|
|
437
447
|
daemonPrivileged: subject.isDaemonOwner || subject.dataScope === 'daemon',
|
|
438
448
|
fullAccess: subject.processRole === 'fullaccess-run',
|
|
439
|
-
selfAid:
|
|
449
|
+
selfAid: grant.selfAid,
|
|
440
450
|
control: false,
|
|
441
451
|
role: currentRole || 'none',
|
|
442
452
|
subject,
|
|
443
453
|
permissionMode: permissionDecision.effectiveValue,
|
|
444
|
-
sessionRuntimeDir:
|
|
454
|
+
sessionRuntimeDir: grant.sessionRuntimeDir,
|
|
445
455
|
};
|
|
446
456
|
}
|
package/dist/trigger/feedback.js
CHANGED
|
@@ -16,7 +16,7 @@ export class TriggerFeedbackDispatcher {
|
|
|
16
16
|
}
|
|
17
17
|
async dispatch(input) {
|
|
18
18
|
const feedback = this.auditFeedback(input.trigger, input.branch);
|
|
19
|
-
const renderedText = this.renderFeedbackText(input);
|
|
19
|
+
const renderedText = input.textOverride ?? this.renderFeedbackText(input);
|
|
20
20
|
feedback.renderedTextHash = sha256(renderedText);
|
|
21
21
|
feedback.renderedTextPreview = previewText(renderedText);
|
|
22
22
|
if (input.trigger.feedback.strategy === 'silent' || !renderedText.trim()) {
|
|
@@ -291,8 +291,7 @@ export class TriggerFeedbackDispatcher {
|
|
|
291
291
|
noopSentinel: input.trigger.execution.noopSentinel,
|
|
292
292
|
authorizedBy: input.trigger.authorizedBy,
|
|
293
293
|
labels: input.trigger.labels,
|
|
294
|
-
//
|
|
295
|
-
// 而不是 originPeerId(来源话题的对端)。
|
|
294
|
+
// 标记通知类型;执行身份始终取已验证的 origin,而非目标会话角色。
|
|
296
295
|
...(input.trigger.labels?.kind === 'cross-thread-review'
|
|
297
296
|
? { reviewKind: 'cross-thread-review' }
|
|
298
297
|
: {}),
|
|
@@ -47,6 +47,107 @@ export function materializeTriggerCreateBaseagent(input, agentAid, dependencies)
|
|
|
47
47
|
}
|
|
48
48
|
return { ...input, execution: { ...execution, baseagent } };
|
|
49
49
|
}
|
|
50
|
+
export async function authorizeTriggerActorOperation(agentAid, operation, actor, triggerId) {
|
|
51
|
+
if (actor.permissionMode === 'readonly' && !actor.fullAccess
|
|
52
|
+
&& !['trigger.list', 'trigger.show', 'trigger.history', 'trigger.eventCatalog'].includes(operation)) {
|
|
53
|
+
throw new Error('readonly tasks cannot modify or run Triggers');
|
|
54
|
+
}
|
|
55
|
+
const isCrossAgent = !actor.control && actor.selfAid !== agentAid;
|
|
56
|
+
if (!isCrossAgentTriggerOperationAllowed({
|
|
57
|
+
control: actor.control,
|
|
58
|
+
daemonOwner: actor.daemonOwner || actor.fullAccess,
|
|
59
|
+
taskAgentAid: actor.selfAid,
|
|
60
|
+
targetAgentAid: agentAid,
|
|
61
|
+
targetManagement: actor.management,
|
|
62
|
+
operation,
|
|
63
|
+
})) {
|
|
64
|
+
if (isCrossAgent)
|
|
65
|
+
throw new Error('cross-agent Trigger operations require DaemonOwner');
|
|
66
|
+
throw new Error('trigger agent does not match authenticated task agent');
|
|
67
|
+
}
|
|
68
|
+
const operationDecision = await authorizeFreshOperation({
|
|
69
|
+
source: actor.control ? 'control' : 'agent-tool',
|
|
70
|
+
subject: actor.subject,
|
|
71
|
+
intent: {
|
|
72
|
+
operation,
|
|
73
|
+
scope: 'relation',
|
|
74
|
+
source: actor.control ? 'control' : 'agent-tool',
|
|
75
|
+
args: {
|
|
76
|
+
self: agentAid,
|
|
77
|
+
taskAgentAid: actor.selfAid,
|
|
78
|
+
targetAgentAid: agentAid,
|
|
79
|
+
peer: actor.origin.peerId,
|
|
80
|
+
peerKey: actor.subject.peerKey,
|
|
81
|
+
...(triggerId ? { triggerId } : {}),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
if (!operationDecision.allow)
|
|
86
|
+
throw new Error(operationDecision.reason);
|
|
87
|
+
actor.daemonOwner = actor.subject.isDaemonOwner;
|
|
88
|
+
actor.daemonPrivileged = actor.control || actor.daemonOwner || actor.fullAccess;
|
|
89
|
+
actor.role = actor.subject.role;
|
|
90
|
+
actor.management = ['owner', 'admin'].includes(actor.role) || actor.daemonPrivileged;
|
|
91
|
+
return actor;
|
|
92
|
+
}
|
|
93
|
+
function rejectUnapprovedFullAccessConfiguration(definition, actor) {
|
|
94
|
+
const approvalSource = actor.control ? 'daemon-service' : 'agent-delegation';
|
|
95
|
+
if (definition.execution.permissionMode === 'fullaccess'
|
|
96
|
+
&& !actor.fullAccess
|
|
97
|
+
&& !canApprovePersistentFullAccessTrigger({
|
|
98
|
+
daemonOwner: actor.daemonOwner,
|
|
99
|
+
source: approvalSource,
|
|
100
|
+
})) {
|
|
101
|
+
throw new Error('persistent fullaccess Trigger requires an explicit user or management-channel action');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function withFullAccessConfigurationProvenance(definition, actor) {
|
|
105
|
+
if (definition.execution.permissionMode !== 'fullaccess') {
|
|
106
|
+
const { authorizedBy: _authorizedBy, ...deescalated } = definition;
|
|
107
|
+
return deescalated;
|
|
108
|
+
}
|
|
109
|
+
const authorizedBy = actor.fullAccess
|
|
110
|
+
? actor.subject.authorizedBy
|
|
111
|
+
: actor.subject.principalId ?? actor.origin.peerId;
|
|
112
|
+
if (!authorizedBy)
|
|
113
|
+
throw new Error('fullaccess Trigger approval provenance is unavailable');
|
|
114
|
+
return { ...definition, authorizedBy };
|
|
115
|
+
}
|
|
116
|
+
export function prepareTriggerCreateDefinition(rawDefinition, agentAid, actor, dependencies) {
|
|
117
|
+
const operatorPeers = triggerOperatorPeerIds({
|
|
118
|
+
origin: actor.origin,
|
|
119
|
+
feedback: rawDefinition.feedback,
|
|
120
|
+
operatorPeers: undefined,
|
|
121
|
+
});
|
|
122
|
+
const materialized = materializeTriggerCreateBaseagent({ ...rawDefinition, origin: actor.origin, operatorPeers }, agentAid, dependencies);
|
|
123
|
+
let definition = normalizeTriggerDefinition(materialized);
|
|
124
|
+
if (definition.labels?.kind === 'cross-thread-review') {
|
|
125
|
+
definition.labels = { ...definition.labels, originAuthorization: 'creator-session-v1' };
|
|
126
|
+
}
|
|
127
|
+
rejectUnapprovedFullAccessConfiguration(definition, actor);
|
|
128
|
+
definition = withFullAccessConfigurationProvenance(definition, actor);
|
|
129
|
+
dependencies.validateTriggerDefinitionForActor(definition, actor);
|
|
130
|
+
if (definition.agentAid !== agentAid)
|
|
131
|
+
throw new Error('trigger agent does not match authenticated task agent');
|
|
132
|
+
dependencies.validateTriggerFeedbackChannels(definition);
|
|
133
|
+
return definition;
|
|
134
|
+
}
|
|
135
|
+
export async function createManagedCrossThreadReviewTrigger(input, dependencies) {
|
|
136
|
+
if (!dependencies.hasAgent(input.agentAid) && input.agentAid !== dependencies.daemonTriggerOwnerAid) {
|
|
137
|
+
throw new Error(`agent not found: ${input.agentAid}`);
|
|
138
|
+
}
|
|
139
|
+
const actor = await dependencies.authenticateDelegatedActor(input.agentAid, input.grant);
|
|
140
|
+
await authorizeTriggerActorOperation(input.agentAid, 'trigger.create', actor);
|
|
141
|
+
const definition = prepareTriggerCreateDefinition(input.definition, input.agentAid, actor, dependencies);
|
|
142
|
+
const executionAuthorization = await dependencies.authorizeExecution(definition);
|
|
143
|
+
if (!executionAuthorization.allowed) {
|
|
144
|
+
throw new Error(executionAuthorization.reason || 'Trigger execution authorization denied');
|
|
145
|
+
}
|
|
146
|
+
const trigger = dependencies.getScheduler(input.agentAid)?.create(definition, [], { enable: true });
|
|
147
|
+
if (!trigger)
|
|
148
|
+
throw new Error(`trigger scheduler not found for agent: ${input.agentAid}`);
|
|
149
|
+
return trigger;
|
|
150
|
+
}
|
|
50
151
|
export function createTriggerIpcExecutor(dependencies) {
|
|
51
152
|
return async (cmd) => {
|
|
52
153
|
let approvedActor;
|
|
@@ -79,29 +180,6 @@ export function createTriggerIpcExecutor(dependencies) {
|
|
|
79
180
|
reason,
|
|
80
181
|
});
|
|
81
182
|
};
|
|
82
|
-
const rejectUnapprovedFullAccessConfiguration = (definition, actor) => {
|
|
83
|
-
const approvalSource = actor.control ? 'daemon-service' : 'agent-delegation';
|
|
84
|
-
if (definition.execution.permissionMode === 'fullaccess'
|
|
85
|
-
&& !actor.fullAccess
|
|
86
|
-
&& !canApprovePersistentFullAccessTrigger({
|
|
87
|
-
daemonOwner: actor.daemonOwner,
|
|
88
|
-
source: approvalSource,
|
|
89
|
-
})) {
|
|
90
|
-
throw new Error('persistent fullaccess Trigger requires an explicit user or management-channel action');
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const withFullAccessConfigurationProvenance = (definition, actor) => {
|
|
94
|
-
if (definition.execution.permissionMode !== 'fullaccess') {
|
|
95
|
-
const { authorizedBy: _authorizedBy, ...deescalated } = definition;
|
|
96
|
-
return deescalated;
|
|
97
|
-
}
|
|
98
|
-
const authorizedBy = actor.fullAccess
|
|
99
|
-
? actor.subject.authorizedBy
|
|
100
|
-
: actor.subject.principalId ?? actor.origin.peerId;
|
|
101
|
-
if (!authorizedBy)
|
|
102
|
-
throw new Error('fullaccess Trigger approval provenance is unavailable');
|
|
103
|
-
return { ...definition, authorizedBy };
|
|
104
|
-
};
|
|
105
183
|
const authorizeTrigger = async (agentAid, operation, triggerId, contextOnly = false) => {
|
|
106
184
|
if (approvedActor && (agentAid !== approvedAgentAid || operation !== approvedOperation)) {
|
|
107
185
|
throw new Error('Trigger operation does not match its approved argv');
|
|
@@ -164,46 +242,7 @@ export function createTriggerIpcExecutor(dependencies) {
|
|
|
164
242
|
}
|
|
165
243
|
}
|
|
166
244
|
const actor = approvedActor ?? await dependencies.authenticateActor(agentAid, cmd.actorSessionId, cmd.delegationToken, cmd.delegationCommandHash, cmd.controlToken, contextOnly);
|
|
167
|
-
|
|
168
|
-
&& !['trigger.list', 'trigger.show', 'trigger.history', 'trigger.eventCatalog'].includes(operation)) {
|
|
169
|
-
throw new Error('readonly tasks cannot modify or run Triggers');
|
|
170
|
-
}
|
|
171
|
-
const isCrossAgent = !actor.control && actor.selfAid !== agentAid;
|
|
172
|
-
if (!isCrossAgentTriggerOperationAllowed({
|
|
173
|
-
control: actor.control,
|
|
174
|
-
daemonOwner: actor.daemonOwner || actor.fullAccess,
|
|
175
|
-
taskAgentAid: actor.selfAid,
|
|
176
|
-
targetAgentAid: agentAid,
|
|
177
|
-
targetManagement: actor.management,
|
|
178
|
-
operation,
|
|
179
|
-
})) {
|
|
180
|
-
if (isCrossAgent)
|
|
181
|
-
throw new Error('cross-agent Trigger operations require DaemonOwner');
|
|
182
|
-
throw new Error('trigger agent does not match authenticated task agent');
|
|
183
|
-
}
|
|
184
|
-
const operationDecision = await authorizeFreshOperation({
|
|
185
|
-
source: actor.control ? 'control' : 'agent-tool',
|
|
186
|
-
subject: actor.subject,
|
|
187
|
-
intent: {
|
|
188
|
-
operation,
|
|
189
|
-
scope: 'relation',
|
|
190
|
-
source: actor.control ? 'control' : 'agent-tool',
|
|
191
|
-
args: {
|
|
192
|
-
self: agentAid,
|
|
193
|
-
taskAgentAid: actor.selfAid,
|
|
194
|
-
targetAgentAid: agentAid,
|
|
195
|
-
peer: actor.origin.peerId,
|
|
196
|
-
peerKey: actor.subject.peerKey,
|
|
197
|
-
...(triggerId ? { triggerId } : {}),
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
if (!operationDecision.allow)
|
|
202
|
-
throw new Error(operationDecision.reason);
|
|
203
|
-
actor.daemonOwner = actor.subject.isDaemonOwner;
|
|
204
|
-
actor.daemonPrivileged = actor.control || actor.daemonOwner || actor.fullAccess;
|
|
205
|
-
actor.role = actor.subject.role;
|
|
206
|
-
actor.management = ['owner', 'admin'].includes(actor.role) || actor.daemonPrivileged;
|
|
245
|
+
await authorizeTriggerActorOperation(agentAid, operation, actor, triggerId);
|
|
207
246
|
if (!triggerId)
|
|
208
247
|
return actor;
|
|
209
248
|
const definition = schedulerFor(agentAid).list({ all: true }).find(trigger => trigger.id === triggerId);
|
|
@@ -244,9 +283,10 @@ export function createTriggerIpcExecutor(dependencies) {
|
|
|
244
283
|
.some(flag => value === flag || value.startsWith(`${flag}=`)));
|
|
245
284
|
if (usesFiles)
|
|
246
285
|
assertTriggerLocalFileAuthority(approvedActor);
|
|
247
|
-
const fileScope =
|
|
286
|
+
const fileScope = {
|
|
248
287
|
selfAid: approvedAgentAid, projectPath: session.projectPath,
|
|
249
288
|
sessionRuntimeDir: approvedActor.sessionRuntimeDir, cwd: session.projectPath,
|
|
289
|
+
...(approvedActor.fullAccess ? { allowProtectedPaths: true } : {}),
|
|
250
290
|
};
|
|
251
291
|
if (command.type === 'trigger.create') {
|
|
252
292
|
const parsed = await buildTriggerCreateRequest(args, fileScope, approvedAgentAid);
|
|
@@ -327,21 +367,8 @@ export function createTriggerIpcExecutor(dependencies) {
|
|
|
327
367
|
}
|
|
328
368
|
const agentAid = requireAgent(rawDefinition.agentAid);
|
|
329
369
|
const actor = await authorizeTrigger(agentAid, 'trigger.create');
|
|
330
|
-
|
|
331
|
-
// feedback 目标(C)因此也拿得到 cancel/update/show 权限,与 thread-ops
|
|
332
|
-
// 技能"在目标话题里结束复查"的流程一致。
|
|
333
|
-
const operatorPeers = triggerOperatorPeerIds({
|
|
334
|
-
origin: actor.origin,
|
|
335
|
-
feedback: rawDefinition.feedback,
|
|
336
|
-
operatorPeers: undefined,
|
|
337
|
-
});
|
|
338
|
-
const materialized = materializeTriggerCreateBaseagent({ ...rawDefinition, origin: actor.origin, operatorPeers }, agentAid, dependencies);
|
|
339
|
-
let definition = normalizeTriggerDefinition(materialized);
|
|
340
|
-
rejectUnapprovedFullAccessConfiguration(definition, actor);
|
|
341
|
-
definition = withFullAccessConfigurationProvenance(definition, actor);
|
|
342
|
-
dependencies.validateTriggerDefinitionForActor(definition, actor);
|
|
370
|
+
const definition = prepareTriggerCreateDefinition(rawDefinition, agentAid, actor, dependencies);
|
|
343
371
|
requireAgent(definition.agentAid);
|
|
344
|
-
dependencies.validateTriggerFeedbackChannels(definition);
|
|
345
372
|
const trigger = schedulerFor(definition.agentAid).create(definition, cmd.files ?? [], { enable: cmd.enable });
|
|
346
373
|
if (trigger.execution.permissionMode === 'fullaccess') {
|
|
347
374
|
auditFullAccessTriggerConfiguration('fullaccess.trigger.configured', trigger, actor, 'fullaccess Trigger created through IPC');
|
|
@@ -60,7 +60,8 @@ export function resolveManagedLocalPath(input, scope, kind) {
|
|
|
60
60
|
const root = resolveRoot();
|
|
61
61
|
const lexicalClass = classifyProtectedPath(lexical, { root, selfAid: scope.selfAid });
|
|
62
62
|
const resolvedClass = classifyProtectedPath(resolved, { root, selfAid: scope.selfAid });
|
|
63
|
-
if (
|
|
63
|
+
if (!scope.allowProtectedPaths
|
|
64
|
+
&& (isProtectedManagedInputClass(lexicalClass) || isProtectedManagedInputClass(resolvedClass))) {
|
|
64
65
|
throw new Error(messages.protectedPath);
|
|
65
66
|
}
|
|
66
67
|
return resolved;
|
package/dist/trigger/manager.js
CHANGED
|
@@ -48,7 +48,9 @@ export class TriggerDefinitionManager {
|
|
|
48
48
|
if (migrations.length > 0) {
|
|
49
49
|
definition.updatedAt = Date.now();
|
|
50
50
|
this.writeDefinition(definition);
|
|
51
|
-
|
|
51
|
+
for (const reason of migrations) {
|
|
52
|
+
this.history.recordDefinition('trigger.updated', definition, { reason });
|
|
53
|
+
}
|
|
52
54
|
}
|
|
53
55
|
return definition;
|
|
54
56
|
}
|
|
@@ -116,14 +118,14 @@ export class TriggerDefinitionManager {
|
|
|
116
118
|
});
|
|
117
119
|
return updated;
|
|
118
120
|
}
|
|
119
|
-
setEnabled(triggerId, enabled) {
|
|
121
|
+
setEnabled(triggerId, enabled, reason) {
|
|
120
122
|
const definition = this.require(triggerId);
|
|
121
123
|
if (enabled)
|
|
122
124
|
assertExplicitAunDeliveryRoutes(definition);
|
|
123
125
|
definition.enabled = enabled;
|
|
124
126
|
definition.updatedAt = Date.now();
|
|
125
127
|
this.writeDefinition(definition);
|
|
126
|
-
this.history.recordDefinition(enabled ? 'trigger.enabled' : 'trigger.disabled', definition);
|
|
128
|
+
this.history.recordDefinition(enabled ? 'trigger.enabled' : 'trigger.disabled', definition, { reason });
|
|
127
129
|
return definition;
|
|
128
130
|
}
|
|
129
131
|
cancel(triggerId) {
|
|
@@ -264,8 +264,8 @@ export class TriggerRuntimeScheduler {
|
|
|
264
264
|
this.publishTriggerDefinitionEvent('trigger:updated', definition);
|
|
265
265
|
return definition;
|
|
266
266
|
}
|
|
267
|
-
setEnabled(triggerId, enabled) {
|
|
268
|
-
const definition = this.manager.setEnabled(triggerId, enabled);
|
|
267
|
+
setEnabled(triggerId, enabled, reason) {
|
|
268
|
+
const definition = this.manager.setEnabled(triggerId, enabled, reason);
|
|
269
269
|
this.clearTimer(triggerId);
|
|
270
270
|
this.unregisterEvent(triggerId);
|
|
271
271
|
this.state.clearSchedule(triggerId);
|
|
@@ -448,6 +448,9 @@ export class TriggerRuntimeScheduler {
|
|
|
448
448
|
const executionAuthorization = await this.runtime.authorizeExecution?.(definition);
|
|
449
449
|
if (executionAuthorization && !executionAuthorization.allowed) {
|
|
450
450
|
const reason = executionAuthorization.reason || 'execution_authorization_denied';
|
|
451
|
+
const failureNotice = payload.dryRun
|
|
452
|
+
? undefined
|
|
453
|
+
: await this.disableAndNotifyAuthorizationDenied(definition, runId, firedAt, reason, payload.causation ?? createRootCausation());
|
|
451
454
|
const audit = this.buildAudit({
|
|
452
455
|
definition,
|
|
453
456
|
runId,
|
|
@@ -457,8 +460,8 @@ export class TriggerRuntimeScheduler {
|
|
|
457
460
|
source,
|
|
458
461
|
script: null,
|
|
459
462
|
reply: null,
|
|
460
|
-
feedback: null,
|
|
461
|
-
effects: [],
|
|
463
|
+
feedback: failureNotice?.feedback ?? null,
|
|
464
|
+
effects: failureNotice?.effects ?? [],
|
|
462
465
|
error: { code: 'authorization_denied', message: reason },
|
|
463
466
|
causation: payload.causation,
|
|
464
467
|
});
|
|
@@ -564,6 +567,32 @@ export class TriggerRuntimeScheduler {
|
|
|
564
567
|
if (runningRuntime)
|
|
565
568
|
runningRuntime.anomalies = anomalies;
|
|
566
569
|
}), controller.signal, RUN_ABORT_SETTLE_GRACE_MS, 'execution');
|
|
570
|
+
if (!payload.dryRun && execution.reply?.error?.reason === 'authorization_denied') {
|
|
571
|
+
const reason = execution.reply.error.text || 'Trigger execution authorization denied';
|
|
572
|
+
const failureNotice = await this.disableAndNotifyAuthorizationDenied(definition, runId, firedAt, reason, causation);
|
|
573
|
+
const audit = this.buildAudit({
|
|
574
|
+
definition,
|
|
575
|
+
runId,
|
|
576
|
+
startedAt,
|
|
577
|
+
status: 'failed',
|
|
578
|
+
reason: 'authorization_denied',
|
|
579
|
+
source,
|
|
580
|
+
processing: execution.processing,
|
|
581
|
+
script: execution.script,
|
|
582
|
+
reply: execution.reply,
|
|
583
|
+
feedback: failureNotice?.feedback ?? null,
|
|
584
|
+
effects: failureNotice?.effects ?? [],
|
|
585
|
+
error: { code: 'authorization_denied', message: reason },
|
|
586
|
+
causation,
|
|
587
|
+
});
|
|
588
|
+
this.audit.write(audit);
|
|
589
|
+
this.publishTriggerRunOutcome(definition, audit);
|
|
590
|
+
this.finishRun(definition.id, runId);
|
|
591
|
+
recordCausationSpan(causation, 'trigger.run', {
|
|
592
|
+
status: 'failed', refs: { triggerId: definition.id, runId }, reason: 'authorization_denied',
|
|
593
|
+
});
|
|
594
|
+
return { ok: false, runId, triggerId: definition.id, status: 'failed', reason: 'authorization_denied', audit, error: reason };
|
|
595
|
+
}
|
|
567
596
|
script = execution.script;
|
|
568
597
|
processing = execution.processing;
|
|
569
598
|
reply = execution.reply ?? null;
|
|
@@ -730,6 +759,33 @@ export class TriggerRuntimeScheduler {
|
|
|
730
759
|
settleCompletion?.({ anomalies: executionAnomalies, ...(incomplete ? { incomplete } : {}) });
|
|
731
760
|
}
|
|
732
761
|
}
|
|
762
|
+
async disableAndNotifyAuthorizationDenied(definition, runId, firedAt, reason, causation) {
|
|
763
|
+
const current = this.manager.get(definition.id);
|
|
764
|
+
if (!current?.enabled || definitionRevision(current) !== definitionRevision(definition))
|
|
765
|
+
return undefined;
|
|
766
|
+
this.setEnabled(definition.id, false, `authorization_denied: ${reason}`);
|
|
767
|
+
// Legacy reviews stored the recipient as origin; do not notify that peer as the creator.
|
|
768
|
+
if (definition.labels?.kind === 'cross-thread-review'
|
|
769
|
+
&& definition.labels.originAuthorization !== 'creator-session-v1')
|
|
770
|
+
return undefined;
|
|
771
|
+
try {
|
|
772
|
+
return await this.feedback.dispatch({
|
|
773
|
+
trigger: {
|
|
774
|
+
...definition,
|
|
775
|
+
feedback: { strategy: 'origin' },
|
|
776
|
+
},
|
|
777
|
+
runId,
|
|
778
|
+
firedAt,
|
|
779
|
+
reply: errorReply(runId, 0, 'authorization_denied', reason),
|
|
780
|
+
textOverride: `Trigger ${definition.name}(${definition.id})已因授权失败而停用:${reason}`,
|
|
781
|
+
causation,
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
catch (error) {
|
|
785
|
+
logger.warn(`[Trigger] authorization denial notification failed: trigger=${definition.id} error=${error instanceof Error ? error.message : String(error)}`);
|
|
786
|
+
return undefined;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
733
789
|
async runExecution(definition, runId, firedAt, sourcePayload, signal, dryRun, causation, onAnomalies) {
|
|
734
790
|
const maxAttempts = !dryRun && definition.execution.onError === 'retry'
|
|
735
791
|
? definition.reliability.retry.maxAttempts
|
|
@@ -1084,8 +1140,26 @@ export class TriggerRuntimeScheduler {
|
|
|
1084
1140
|
if (!definition.enabled || !this.isResumableCheckpoint(definition, run))
|
|
1085
1141
|
return false;
|
|
1086
1142
|
const executionAuthorization = await this.runtime.authorizeExecution?.(definition);
|
|
1087
|
-
if (executionAuthorization && !executionAuthorization.allowed)
|
|
1088
|
-
|
|
1143
|
+
if (executionAuthorization && !executionAuthorization.allowed) {
|
|
1144
|
+
const reason = executionAuthorization.reason || 'Trigger execution authorization denied';
|
|
1145
|
+
const notice = await this.disableAndNotifyAuthorizationDenied(definition, run.runId, run.source?.firedAt ?? Date.now(), reason, createRootCausation());
|
|
1146
|
+
const audit = this.buildAudit({
|
|
1147
|
+
definition,
|
|
1148
|
+
runId: run.runId,
|
|
1149
|
+
startedAt: run.startedAt,
|
|
1150
|
+
status: 'failed',
|
|
1151
|
+
reason: 'authorization_denied',
|
|
1152
|
+
source: run.source,
|
|
1153
|
+
script: null,
|
|
1154
|
+
feedback: notice?.feedback ?? null,
|
|
1155
|
+
effects: notice?.effects ?? [],
|
|
1156
|
+
error: { code: 'authorization_denied', message: reason },
|
|
1157
|
+
});
|
|
1158
|
+
this.audit.write(audit);
|
|
1159
|
+
this.publishTriggerRunOutcome(definition, audit);
|
|
1160
|
+
this.state.remove(definition.id, run.runId);
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1089
1163
|
const session = await this.daemonChannel.getResumableConversationSession(run.executionSessionId);
|
|
1090
1164
|
if (!session) {
|
|
1091
1165
|
logger.warn(`[Trigger] resumable session unavailable: trigger=${definition.id} run=${run.runId} session=${run.executionSessionId}`);
|
|
@@ -1177,6 +1251,14 @@ export class TriggerRuntimeScheduler {
|
|
|
1177
1251
|
renderedTextPreview: previewText(originalPrompt),
|
|
1178
1252
|
};
|
|
1179
1253
|
const execution = await awaitWithAbortSettleGrace(this.runRecoveredExecution(definition, runtime, session), controller.signal, RUN_ABORT_SETTLE_GRACE_MS, 'execution');
|
|
1254
|
+
if (!controller.signal.aborted && execution.reply?.error?.reason === 'authorization_denied') {
|
|
1255
|
+
const reason = execution.reply.error.text || 'Trigger execution authorization denied';
|
|
1256
|
+
const notice = await this.disableAndNotifyAuthorizationDenied(definition, runId, source.firedAt, reason, causation);
|
|
1257
|
+
execution.feedbackResult = {
|
|
1258
|
+
status: 'failed', reason: 'authorization_denied', feedback: notice?.feedback ?? { strategy: 'origin' },
|
|
1259
|
+
effects: notice?.effects ?? [], error: { code: 'authorization_denied', message: reason },
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1180
1262
|
reply = execution.reply ?? null;
|
|
1181
1263
|
anomalies = execution.anomalies ?? [];
|
|
1182
1264
|
runtime.anomalies = anomalies;
|
|
@@ -276,3 +276,31 @@ export async function atomicReplaceJson(file, value) {
|
|
|
276
276
|
fs.rmSync(temporary, { force: true });
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
+
const retryableCodes = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
280
|
+
const delays = [10, 25, 50, 100];
|
|
281
|
+
const pause = new Int32Array(new SharedArrayBuffer(4));
|
|
282
|
+
/** Retry brief file-handle contention without opening or deleting the live file. */
|
|
283
|
+
export function atomicReplaceFile(source, destination) {
|
|
284
|
+
let lastError;
|
|
285
|
+
for (let attempt = 0;; attempt += 1) {
|
|
286
|
+
try {
|
|
287
|
+
fs.renameSync(source, destination);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
lastError = error;
|
|
292
|
+
const code = error.code;
|
|
293
|
+
if (!retryableCodes.has(code ?? '') || attempt >= delays.length)
|
|
294
|
+
break;
|
|
295
|
+
Atomics.wait(pause, 0, 0, delays[attempt]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const code = lastError?.code;
|
|
299
|
+
if (process.platform === 'win32' && code === 'EPERM') {
|
|
300
|
+
// Some Windows file projections deny renaming an open JSON target. Keep
|
|
301
|
+
// its inode and use atomicWrite's hot-backup/stable-write fallback instead.
|
|
302
|
+
atomicWrite(destination, fs.readFileSync(source, 'utf8'));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
throw lastError;
|
|
306
|
+
}
|
|
@@ -723,6 +723,20 @@ export function killProcess(pid, force = false) {
|
|
|
723
723
|
return !isProcessRunning(pid);
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
|
+
/** Terminate a detached process group where supported, falling back to one PID. */
|
|
727
|
+
export function killProcessTree(pid, force = false) {
|
|
728
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
729
|
+
return false;
|
|
730
|
+
if (isWindows)
|
|
731
|
+
return killProcess(pid, force);
|
|
732
|
+
try {
|
|
733
|
+
process.kill(-pid, force ? 'SIGKILL' : 'SIGTERM');
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
return killProcess(pid, force);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
726
740
|
/** Wait until a process has really disappeared from the host process table. */
|
|
727
741
|
export async function waitForProcessExit(pid, timeoutMs = 10_000, intervalMs = 250) {
|
|
728
742
|
const deadline = Date.now() + timeoutMs;
|