evolcore 0.0.43-test.5 → 0.0.43-test.7
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 +95 -0
- package/bin/ecmsg.js +281 -81
- package/dist/agents/baseagent-availability.js +20 -5
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +36 -3
- package/dist/agents/codex-runner.js +75 -8
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/msg/p2p.js +6 -1
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +306 -30
- package/dist/cli/agent-create.js +18 -8
- package/dist/cli/aun-commands.js +9 -1
- package/dist/cli/daemon-commands.js +34 -65
- package/dist/cli/daemon-lifecycle-client.js +61 -0
- package/dist/cli/ecmsg-gateway.js +38 -3
- package/dist/cli/events-command.js +73 -0
- package/dist/cli/index.js +31 -14
- package/dist/cli/init.js +75 -0
- package/dist/cli/invoke-command.js +182 -0
- package/dist/cli/managed-command-guard.js +6 -1
- package/dist/cli/provider-command.js +1 -1
- package/dist/cli/restart-monitor.js +67 -50
- package/dist/cli/services-command.js +111 -0
- package/dist/cli/task-context.js +38 -1
- package/dist/cli/team-workspace-command.js +134 -0
- package/dist/cli/thread-command.js +6 -2
- package/dist/cli/watch-logs.js +6 -4
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/boot-log.js +6 -4
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +1 -8
- package/dist/config/invoke-ipc-service.js +118 -0
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/provider-identity-migration.js +92 -17
- package/dist/config/provider-local-sync.js +2 -0
- package/dist/config/providers-config.js +13 -0
- package/dist/config/providers-management.js +100 -10
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +86 -88
- package/dist/config/snapshot.js +70 -41
- package/dist/config-store.js +2 -1
- package/dist/core/agent-reload-coordinator.js +6 -4
- package/dist/core/agent-runtime.js +146 -15
- package/dist/core/auth/delegation-authorization.js +66 -0
- package/dist/core/auth/operation-catalog.js +20 -0
- package/dist/core/baseagent-loader.js +75 -42
- package/dist/core/channel-loader.js +45 -13
- package/dist/core/channel-runtime.js +116 -45
- package/dist/core/command/agent-control.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/chatmode-config.js +2 -36
- package/dist/core/command/command-handler.js +58 -16
- package/dist/core/command/data-root-resolver.js +32 -23
- package/dist/core/command/eventcenter-menu.js +338 -0
- package/dist/core/command/menu-catalog.js +8 -0
- package/dist/core/command/menu-handler.js +206 -87
- package/dist/core/command/menu-protocol.js +142 -22
- package/dist/core/command/menu-query-batch.js +194 -0
- package/dist/core/command/role-menu.js +27 -15
- package/dist/core/command/slash-gate.js +1 -1
- package/dist/core/command/slash-handler.js +34 -42
- package/dist/core/command/team-workspace-bootstrap.js +350 -0
- package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
- package/dist/core/command/team-workspace-initializer.js +2 -0
- package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
- package/dist/core/command/team-workspace-job-store.js +88 -0
- package/dist/core/command/team-workspace-management-service.js +2 -0
- package/dist/core/command/team-workspace-management-store.js +96 -0
- package/dist/core/command/team-workspace-management.js +265 -0
- package/dist/core/command/team-workspace-members-menu.js +88 -0
- package/dist/core/command/team-workspace-store.js +612 -0
- package/dist/core/command/team-workspace-team.js +193 -0
- package/dist/core/daemon-control.js +45 -15
- package/dist/core/daemon-lifecycle.js +478 -75
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +130 -42
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +4 -4
- package/dist/core/invoke/executors/index.js +13 -0
- package/dist/core/invoke/executors/media.js +283 -0
- package/dist/core/invoke/executors/text.js +198 -0
- package/dist/core/invoke/invoke-service.js +157 -0
- package/dist/core/invoke/style-router.js +48 -0
- package/dist/core/invoke/types.js +19 -0
- package/dist/core/ipc-registration.js +51 -11
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/memory/consolidation.js +7 -5
- package/dist/core/message/aun-ipc-sender.js +149 -19
- package/dist/core/message/im-renderer.js +28 -84
- package/dist/core/message/message-bridge.js +57 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/message-utils.js +10 -2
- package/dist/core/message/peer-mode.js +7 -34
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +163 -52
- package/dist/core/message/send-options.js +7 -4
- package/dist/core/message/send-routing.js +55 -7
- package/dist/core/ownership/owner-resolver.js +8 -0
- package/dist/core/permission/ec-command-parser.js +14 -3
- package/dist/core/permission/protected-paths.js +12 -2
- package/dist/core/permission/shell-environment.js +9 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-file-health.js +243 -0
- package/dist/core/session/session-fs-store.js +163 -3
- package/dist/core/session/session-idle-monitor.js +9 -1
- package/dist/core/session/session-manager.js +36 -2
- package/dist/core/task/task-recovery-service.js +13 -2
- package/dist/core/thread/command-parser.js +9 -2
- package/dist/core/thread/thread-operation.js +21 -2
- package/dist/core/thread/thread-route.js +13 -2
- package/dist/directory/owner-directory-admission.js +42 -30
- package/dist/directory/owner-directory-cache.js +143 -126
- package/dist/directory/owner-directory-query-operation.js +9 -8
- package/dist/eck/kit-renderer.js +7 -5
- package/dist/ecweb/basic-settings-service.js +1 -1
- package/dist/ecweb/message-context-service.js +0 -4
- package/dist/ecweb/runtime/lifecycle.js +14 -8
- package/dist/ecweb/runtime/supervisor.js +62 -30
- package/dist/event-center/admission-materializer.js +114 -0
- package/dist/event-center/bus-gate.js +136 -0
- package/dist/event-center/bus-host.js +290 -0
- package/dist/event-center/bus-resolver.js +120 -0
- package/dist/event-center/center-config.js +100 -0
- package/dist/event-center/client-factory.js +50 -0
- package/dist/event-center/daemon.js +45 -0
- package/dist/event-center/directory-source.js +53 -0
- package/dist/event-center/dispatcher.js +157 -0
- package/dist/event-center/event-log.js +110 -0
- package/dist/event-center/index-generator.js +63 -0
- package/dist/event-center/ipc-operation.js +308 -0
- package/dist/event-center/ledger.js +52 -0
- package/dist/event-center/pack-loader.js +202 -0
- package/dist/event-center/pack-manager.js +85 -0
- package/dist/event-center/registry.js +238 -0
- package/dist/event-center/runtime.js +641 -0
- package/dist/event-center/script-runner.js +356 -0
- package/dist/event-center/types.js +35 -0
- package/dist/event-center/validation.js +413 -0
- package/dist/index.js +751 -268
- package/dist/ipc.js +66 -12
- package/dist/paths.js +20 -0
- package/dist/product.js +14 -0
- package/dist/proxy/manager.js +43 -18
- package/dist/proxy/service-supervisor.js +78 -35
- package/dist/response-system/engines/v1/index.js +0 -1
- package/dist/response-system/modes/single-session/index.js +1 -1
- package/dist/services/dispatcher.js +100 -0
- package/dist/services/idempotency.js +90 -0
- package/dist/services/identity.js +52 -0
- package/dist/services/index-generator.js +70 -0
- package/dist/services/index.js +449 -0
- package/dist/services/ipc-operation.js +458 -0
- package/dist/services/ledger.js +52 -0
- package/dist/services/message-log.js +112 -0
- package/dist/services/pack-manager.js +204 -0
- package/dist/services/reply.js +55 -0
- package/dist/services/router.js +95 -0
- package/dist/services/script-runner.js +422 -0
- package/dist/services/service-payload.js +70 -0
- package/dist/services/types.js +18 -0
- package/dist/services/validation.js +297 -0
- package/dist/trigger/application-service.js +21 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +1 -1
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/ipc-service.js +3 -1
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +78 -5
- package/dist/trigger/script-sandbox.js +118 -22
- package/dist/utils/cross-platform.js +175 -13
- package/dist/utils/evolcore-version.js +69 -27
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/instance-registry.js +19 -13
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +109 -10
- package/dist/utils/startup-trace.js +222 -44
- package/dist/utils/windows-shell-trust.js +80 -6
- package/kits/docs/INDEX.md +2 -2
- package/kits/docs/aun/ABILITY_CALLING.md +10 -17
- package/kits/docs/context-assembly.md +1 -1
- package/kits/docs/evolcore/INDEX.md +5 -2
- package/kits/docs/evolcore/ability.md +4 -0
- package/kits/docs/evolcore/aid.md +1 -1
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/event-center.md +207 -0
- package/kits/docs/evolcore/file-navigation.md +10 -264
- package/kits/docs/evolcore/fs.md +3 -2
- package/kits/docs/evolcore/group.md +2 -2
- package/kits/docs/evolcore/memory-architecture.md +2 -0
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +21 -0
- package/kits/docs/evolcore/msg.md +27 -8
- package/kits/docs/evolcore/provider.md +23 -3
- package/kits/docs/evolcore/response.md +5 -5
- package/kits/docs/evolcore/services.md +277 -0
- package/kits/docs/evolcore/task.md +2 -0
- package/kits/docs/evolcore/team-workspace.md +41 -0
- package/kits/eck_manifest.json +45 -7
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/02-navigation.md +10 -1
- package/kits/rules/06-channel.md +5 -6
- package/kits/schemas/_meta.json +17 -6
- package/kits/schemas/agent-config.schema.19.json +5 -7
- package/kits/schemas/agent-config.schema.20.json +936 -0
- package/kits/schemas/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/relation-config.schema.12.json +2 -3
- package/kits/schemas/role-config.schema.2.json +4 -4
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/.switches.json +1 -5
- package/kits/skills/ability/SKILL.md +56 -0
- package/kits/skills/ability/references/calling.md +56 -0
- package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
- package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
- package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
- package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
- package/kits/skills/ec-agent-create/SKILL.md +0 -1
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +34 -5
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +6 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
- package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
- package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +3 -3
- package/kits/templates/system-fragments/commands.md +9 -7
- package/kits/templates/system-fragments/reply.md +2 -6
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +11 -9
- package/package.json +5 -6
- package/dist/cli/pa-workspace-command.js +0 -225
- package/dist/core/command/pa-workspace-store.js +0 -468
- package/dist/core/relation/pa-team.js +0 -132
- package/kits/docs/evolcore/pa-workspace.md +0 -51
- package/kits/skills/aid-ability/SKILL.md +0 -244
- package/kits/skills/ec-ability/SKILL.md +0 -67
- package/kits/skills/ec-ability/references/workflows.md +0 -15
|
@@ -5,12 +5,14 @@ import { assertTriggerLocalFileAuthority, daemonPrivilegedTriggerReason, isTrigg
|
|
|
5
5
|
import { decodeTriggerScriptFile } from './local-files.js';
|
|
6
6
|
import { applyTriggerPatch } from './patch.js';
|
|
7
7
|
import { definitionRevision, normalizeTriggerDefinition, splitScriptCommand } from './validation.js';
|
|
8
|
-
export function createTriggerBaseagentResolver({ daemonTriggerOwnerAid, getAgentName, getDaemonAgentName, agentMap, }) {
|
|
8
|
+
export function createTriggerBaseagentResolver({ daemonTriggerOwnerAid, getAgentName, getDaemonAgentName, agentMap, getConfiguredBaseagents, }) {
|
|
9
9
|
return agentAid => {
|
|
10
10
|
const ownerName = getAgentName(agentAid)
|
|
11
11
|
?? (agentAid === daemonTriggerOwnerAid ? getDaemonAgentName() : undefined);
|
|
12
12
|
if (!ownerName)
|
|
13
13
|
return [];
|
|
14
|
+
if (getConfiguredBaseagents)
|
|
15
|
+
return getConfiguredBaseagents(ownerName);
|
|
14
16
|
const prefix = `${ownerName}::`;
|
|
15
17
|
return [...agentMap.keys()]
|
|
16
18
|
.filter(key => key.startsWith(prefix))
|
package/dist/trigger/manager.js
CHANGED
|
@@ -15,9 +15,7 @@ export class TriggerDefinitionManager {
|
|
|
15
15
|
fs.mkdirSync(this.rootDir, { recursive: true });
|
|
16
16
|
assertRealDirectory(this.rootDir, 'Trigger root');
|
|
17
17
|
this.history = new TriggerHistoryStore(rootDir, agentAid);
|
|
18
|
-
|
|
19
|
-
this.history.ensureDefinitionSnapshot(definition);
|
|
20
|
-
}
|
|
18
|
+
this.history.ensureDefinitionSnapshots(this.list({ all: true }));
|
|
21
19
|
}
|
|
22
20
|
list(opts = {}) {
|
|
23
21
|
const definitions = [];
|
|
@@ -33,12 +33,14 @@ export class TriggerRuntimeScheduler {
|
|
|
33
33
|
eventBus;
|
|
34
34
|
targetSessionLocks;
|
|
35
35
|
timers = new Map();
|
|
36
|
+
authorizationRetries = new Map();
|
|
36
37
|
running = new Map();
|
|
37
38
|
runStartLocks = new Map();
|
|
38
39
|
recoveredOneShotIds = new Set();
|
|
39
40
|
eventSource;
|
|
40
41
|
initialized = false;
|
|
41
42
|
stopping = false;
|
|
43
|
+
lifecycleGeneration = 0;
|
|
42
44
|
constructor(manager, state, audit, scriptExecutor, feedback, daemonChannel, runtime, eventBus, targetSessionLocks = new TargetSessionLockRegistry()) {
|
|
43
45
|
this.manager = manager;
|
|
44
46
|
this.state = state;
|
|
@@ -56,10 +58,19 @@ export class TriggerRuntimeScheduler {
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
async init() {
|
|
59
|
-
|
|
61
|
+
const stopped = this.stop();
|
|
62
|
+
const generation = this.lifecycleGeneration;
|
|
63
|
+
await stopped;
|
|
64
|
+
if (generation !== this.lifecycleGeneration)
|
|
65
|
+
return;
|
|
60
66
|
this.stopping = false;
|
|
61
67
|
this.recoveredOneShotIds.clear();
|
|
68
|
+
await this.audit.initializeHistory?.();
|
|
69
|
+
if (this.stopping || generation !== this.lifecycleGeneration)
|
|
70
|
+
return;
|
|
62
71
|
await this.recoverOpenRuns();
|
|
72
|
+
if (this.stopping || generation !== this.lifecycleGeneration)
|
|
73
|
+
return;
|
|
63
74
|
for (const definition of this.manager.list()) {
|
|
64
75
|
if (this.recoveredOneShotIds.has(definition.id))
|
|
65
76
|
continue;
|
|
@@ -70,7 +81,9 @@ export class TriggerRuntimeScheduler {
|
|
|
70
81
|
logger.info(`[Trigger] scheduler initialized for ${this.manager.agentAid}`);
|
|
71
82
|
}
|
|
72
83
|
async stop() {
|
|
84
|
+
this.lifecycleGeneration++;
|
|
73
85
|
this.stopping = true;
|
|
86
|
+
this.clearAuthorizationRetries();
|
|
74
87
|
for (const timer of this.timers.values())
|
|
75
88
|
clearTimeout(timer);
|
|
76
89
|
this.timers.clear();
|
|
@@ -93,7 +106,9 @@ export class TriggerRuntimeScheduler {
|
|
|
93
106
|
* Explicit scheduler replacement/unload must continue to use stop().
|
|
94
107
|
*/
|
|
95
108
|
async suspendForDaemonExit() {
|
|
109
|
+
this.lifecycleGeneration++;
|
|
96
110
|
this.stopping = true;
|
|
111
|
+
this.clearAuthorizationRetries();
|
|
97
112
|
for (const timer of this.timers.values())
|
|
98
113
|
clearTimeout(timer);
|
|
99
114
|
this.timers.clear();
|
|
@@ -431,7 +446,8 @@ export class TriggerRuntimeScheduler {
|
|
|
431
446
|
return;
|
|
432
447
|
}
|
|
433
448
|
const result = await runPromise;
|
|
434
|
-
if (result.
|
|
449
|
+
if (result.reason === 'authorization_unavailable'
|
|
450
|
+
|| (result.status === 'running' && result.reason === 'daemon_restart_resume_pending'))
|
|
435
451
|
return;
|
|
436
452
|
const fresh = this.manager.get(triggerId);
|
|
437
453
|
if (fresh?.enabled && definitionRevision(fresh) === firedRevision) {
|
|
@@ -471,6 +487,24 @@ export class TriggerRuntimeScheduler {
|
|
|
471
487
|
return { ok: false, runId, triggerId: definition.id, status: 'failed', reason: 'invalid_execution_configuration', audit, error: message };
|
|
472
488
|
}
|
|
473
489
|
const executionAuthorization = await this.runtime.authorizeExecution?.(definition);
|
|
490
|
+
if (executionAuthorization?.retryable && !executionAuthorization.allowed) {
|
|
491
|
+
if (!payload.dryRun)
|
|
492
|
+
this.deferAuthorization(definition, definition.id, async (current) => {
|
|
493
|
+
const result = await this.startRun(current, payload);
|
|
494
|
+
if (payload.scheduledAt !== undefined && this.isOneShot(current.source) && result.reason !== 'authorization_unavailable'
|
|
495
|
+
&& result.reason !== 'stopped' && this.manager.get(current.id)?.enabled
|
|
496
|
+
&& definitionRevision(this.manager.get(current.id)) === definitionRevision(current)) {
|
|
497
|
+
this.setEnabled(current.id, false);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return { ok: false, runId, triggerId: definition.id, status: 'skipped', reason: 'authorization_unavailable' };
|
|
501
|
+
}
|
|
502
|
+
if (!payload.dryRun) {
|
|
503
|
+
const pending = this.authorizationRetries.get(definition.id);
|
|
504
|
+
if (pending)
|
|
505
|
+
clearTimeout(pending);
|
|
506
|
+
this.authorizationRetries.delete(definition.id);
|
|
507
|
+
}
|
|
474
508
|
if (executionAuthorization && !executionAuthorization.allowed) {
|
|
475
509
|
const reason = executionAuthorization.reason || 'execution_authorization_denied';
|
|
476
510
|
const failureNotice = payload.dryRun
|
|
@@ -843,9 +877,17 @@ export class TriggerRuntimeScheduler {
|
|
|
843
877
|
}
|
|
844
878
|
async runRecordedExecutionAttempt(definition, runId, firedAt, sourcePayload, signal, dryRun, causation, attempt, previousAttempt) {
|
|
845
879
|
const attemptId = `${runId}:attempt:${attempt}`;
|
|
846
|
-
|
|
880
|
+
let executionAuthorization = await this.runtime.authorizeExecution?.(definition);
|
|
881
|
+
while (executionAuthorization?.retryable && !executionAuthorization.allowed && !dryRun) {
|
|
882
|
+
if (!await sleep(5_000, signal))
|
|
883
|
+
throw new Error('Trigger authorization wait cancelled');
|
|
884
|
+
executionAuthorization = await this.runtime.authorizeExecution?.(definition);
|
|
885
|
+
}
|
|
886
|
+
if (signal.aborted)
|
|
887
|
+
throw new Error('Trigger execution cancelled');
|
|
847
888
|
if (executionAuthorization && !executionAuthorization.allowed) {
|
|
848
|
-
const
|
|
889
|
+
const reason = executionAuthorization.retryable ? 'authorization_unavailable' : 'authorization_denied';
|
|
890
|
+
const reply = errorReply(runId, 0, reason, executionAuthorization.reason || 'Trigger execution authorization denied');
|
|
849
891
|
const execution = {
|
|
850
892
|
script: null,
|
|
851
893
|
processing: { mode: definition.execution.type },
|
|
@@ -859,7 +901,7 @@ export class TriggerRuntimeScheduler {
|
|
|
859
901
|
});
|
|
860
902
|
this.state.completeExecutionAttempt?.(definition.id, runId, attemptId, {
|
|
861
903
|
status: 'failed',
|
|
862
|
-
error: { code:
|
|
904
|
+
error: { code: reason, message: reply.error?.text || 'Trigger execution authorization denied' },
|
|
863
905
|
});
|
|
864
906
|
}
|
|
865
907
|
return execution;
|
|
@@ -1161,10 +1203,41 @@ export class TriggerRuntimeScheduler {
|
|
|
1161
1203
|
}
|
|
1162
1204
|
}
|
|
1163
1205
|
}
|
|
1206
|
+
clearAuthorizationRetries() {
|
|
1207
|
+
for (const timer of this.authorizationRetries.values())
|
|
1208
|
+
clearTimeout(timer);
|
|
1209
|
+
this.authorizationRetries.clear();
|
|
1210
|
+
}
|
|
1211
|
+
deferAuthorization(definition, key, retry) {
|
|
1212
|
+
if (this.stopping || this.authorizationRetries.has(key))
|
|
1213
|
+
return;
|
|
1214
|
+
const revision = definitionRevision(definition);
|
|
1215
|
+
logger.info(`[Trigger] waiting for authorization evidence: trigger=${definition.id}`);
|
|
1216
|
+
const timer = setTimeout(() => {
|
|
1217
|
+
this.authorizationRetries.delete(key);
|
|
1218
|
+
const current = this.manager.get(definition.id);
|
|
1219
|
+
if (this.stopping || !current?.enabled || definitionRevision(current) !== revision)
|
|
1220
|
+
return;
|
|
1221
|
+
void retry(current).catch(error => logger.warn(`[Trigger] deferred authorization failed: ${definition.id}: ${error}`));
|
|
1222
|
+
}, 5_000);
|
|
1223
|
+
timer.unref?.();
|
|
1224
|
+
this.authorizationRetries.set(key, timer);
|
|
1225
|
+
}
|
|
1164
1226
|
async reclaimOpenRun(definition, run) {
|
|
1165
1227
|
if (!definition.enabled || !this.isResumableCheckpoint(definition, run))
|
|
1166
1228
|
return false;
|
|
1167
1229
|
const executionAuthorization = await this.runtime.authorizeExecution?.(definition);
|
|
1230
|
+
if (executionAuthorization?.retryable && !executionAuthorization.allowed) {
|
|
1231
|
+
this.deferAuthorization(definition, run.runId, async (current) => {
|
|
1232
|
+
if (!this.state.list(current.id).some(active => active.runId === run.runId))
|
|
1233
|
+
return;
|
|
1234
|
+
if (!await this.reclaimOpenRun(current, run))
|
|
1235
|
+
await this.closeOpenRunAfterRestart(current, run);
|
|
1236
|
+
});
|
|
1237
|
+
if (this.isOneShot(definition.source))
|
|
1238
|
+
this.recoveredOneShotIds.add(definition.id);
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1168
1241
|
if (executionAuthorization && !executionAuthorization.allowed) {
|
|
1169
1242
|
const reason = executionAuthorization.reason || 'Trigger execution authorization denied';
|
|
1170
1243
|
const notice = await this.disableAndNotifyAuthorizationDenied(definition, run.runId, run.source?.firedAt ?? Date.now(), reason, createRootCausation());
|
|
@@ -24,14 +24,47 @@ const SCRIPT_ENVIRONMENT_EXCLUDES = [
|
|
|
24
24
|
'GOOGLE_API_KEY',
|
|
25
25
|
'ECAGENT_API_KEY',
|
|
26
26
|
];
|
|
27
|
+
/**
|
|
28
|
+
* 构造 Trigger / 事件 / 服务脚本的启动配置。
|
|
29
|
+
*
|
|
30
|
+
* ## 三条执行路径(只此三条,其余组合一律 fail-closed)
|
|
31
|
+
*
|
|
32
|
+
* | 路径 | 判据 | 沙箱 | 平台 | 说明 |
|
|
33
|
+
* | --- | --- | --- | --- | --- |
|
|
34
|
+
* | daemon | `authorization.scope === 'daemon'` | **无** | 全平台 | 直接 spawn,继承 `process.env`(不清洗密钥) |
|
|
35
|
+
* | 无沙箱 | `permissionMode === 'fullaccess'`,或 `bypass` + `role === 'owner'` | **无** | 全平台 | 由 `:66` 与 `resolvePhaseOneExecutionSandbox` 判定;本函数在 fullaccess 时直接抛错要求走 daemon scope |
|
|
36
|
+
* | scoped | 其余非 fullaccess 模式 | **有** | Linux / Windows | macOS 不支持,见 `:70` |
|
|
37
|
+
*
|
|
38
|
+
* ## scoped 路径的沙箱后端(当前实现)
|
|
39
|
+
*
|
|
40
|
+
* - **Linux**:系统 `bubblewrap`(`--ro-bind / /` + `--tmpfs` 遮蔽 L/H-class 路径)。
|
|
41
|
+
* 不依赖 Codex。系统包缺失时报 `bubblewrap is required for scoped Trigger script isolation`。
|
|
42
|
+
* - **Windows**:**借用 `@openai/codex` 的 Windows 沙箱**(`codex.exe sandbox`
|
|
43
|
+
* 子命令 + `codex-windows-sandbox-setup.exe` 施加的 NTFS ACL)。
|
|
44
|
+
* Codex 在这里只当「沙箱宿主」用,与 baseagent 是 claude 还是 codex **无关**,
|
|
45
|
+
* 也不碰模型/认证/会话。这是已知的硬依赖:`package.json` 并未声明它,
|
|
46
|
+
* 需要用户在机器上全局安装。
|
|
47
|
+
* - **macOS**:**不支持**(`:70`)。没有可用后端,scoped 脚本一律拒跑。
|
|
48
|
+
*
|
|
49
|
+
* 三者的失败语义一致:要么跑在有隔离的沙箱里,要么拒跑(`SCRIPT_SANDBOX_UNAVAILABLE` /
|
|
50
|
+
* 退出码 126),不存在「静默降级成无沙箱」。
|
|
51
|
+
*
|
|
52
|
+
* ## 临时绕过(沙箱不可用时)
|
|
53
|
+
*
|
|
54
|
+
* 若机器上装不了 bubblewrap / codex,或 macOS 需要临时跑通,只能显式选择
|
|
55
|
+
* **daemon scope** 或 **fullaccess / bypass+owner**——两者都**没有沙箱**。
|
|
56
|
+
* 这是有意的:绕过必须显式,不能让调用方吞掉错误后自己 spawn。
|
|
57
|
+
* 走 daemon scope 时调用方必须向用户明示「本次执行没有沙箱」。
|
|
58
|
+
*/
|
|
27
59
|
export function buildTriggerScriptLaunch(input) {
|
|
28
60
|
const authorization = input.executionAuthorization;
|
|
29
61
|
if (!authorization?.allowed || !authorization.scope)
|
|
30
62
|
throw new Error('Trigger execution authorization is missing');
|
|
31
63
|
const runtime = resolveRuntime(input.trigger.execution.script?.runtime || '');
|
|
32
64
|
if (authorization.scope === 'daemon') {
|
|
65
|
+
// daemon scope:无沙箱,全平台可用。注意 env 是原样继承,KEY/TOKEN 不清洗。
|
|
33
66
|
const launch = buildCliLaunchCommand(runtime, [input.scriptPath, ...input.scriptArgs]);
|
|
34
|
-
return { ...launch, cwd: input.projectPath, env: process.env };
|
|
67
|
+
return { ...launch, cwd: input.projectPath, env: process.env, sandboxAbsent: 'daemon-scope' };
|
|
35
68
|
}
|
|
36
69
|
if (!authorization.permissionMode || authorization.permissionMode === 'fullaccess') {
|
|
37
70
|
throw new Error('scoped Trigger execution requires an effective non-fullaccess permission mode');
|
|
@@ -39,10 +72,15 @@ export function buildTriggerScriptLaunch(input) {
|
|
|
39
72
|
const sandboxDecision = resolvePhaseOneExecutionSandbox(authorization.permissionMode, authorization.role);
|
|
40
73
|
const readonly = sandboxDecision.permissionMode === 'readonly';
|
|
41
74
|
if (process.platform !== 'linux' && process.platform !== 'win32') {
|
|
42
|
-
throw new Error(
|
|
75
|
+
throw new Error(`scoped Trigger script isolation is unavailable on platform "${process.platform}" `
|
|
76
|
+
+ '(supported: linux via bubblewrap, win32 via the Codex Windows sandbox). '
|
|
77
|
+
+ 'On macOS there is no backend yet: either run this work on Linux/Windows, '
|
|
78
|
+
+ 'or execute the script through daemon scope / fullaccess and tell the user that no sandbox is applied.');
|
|
43
79
|
}
|
|
44
80
|
if (process.platform === 'win32' && path.extname(runtime).toLowerCase() !== '.exe') {
|
|
45
|
-
throw new Error(
|
|
81
|
+
throw new Error(`scoped Windows Trigger scripts require a native executable runtime (got "${runtime}"). `
|
|
82
|
+
+ 'Use runtime "node" (resolves to node.exe) or another .exe; '
|
|
83
|
+
+ '.mjs/.js script files are fine — only the runtime must be a native executable.');
|
|
46
84
|
}
|
|
47
85
|
const projectPath = resolveRealDirectory(input.projectPath, 'Trigger project path');
|
|
48
86
|
const triggerDir = resolveRealDirectory(input.triggerDir, 'Trigger directory');
|
|
@@ -70,7 +108,10 @@ export function buildTriggerScriptLaunch(input) {
|
|
|
70
108
|
}
|
|
71
109
|
const bubblewrap = process.platform === 'linux' ? resolveBubblewrapPath() : undefined;
|
|
72
110
|
if (process.platform === 'linux' && !bubblewrap) {
|
|
73
|
-
throw new Error('bubblewrap is required for scoped Trigger script isolation'
|
|
111
|
+
throw new Error('bubblewrap is required for scoped Trigger script isolation. '
|
|
112
|
+
+ 'Install it via your package manager (Debian/Ubuntu: `apt install bubblewrap`; '
|
|
113
|
+
+ 'Fedora: `dnf install bubblewrap`; Arch: `pacman -S bubblewrap`), '
|
|
114
|
+
+ 'or execute the script through daemon scope / fullaccess and tell the user that no sandbox is applied.');
|
|
74
115
|
}
|
|
75
116
|
const runtimeRoot = ensureSessionRuntimeDir(`trigger:${input.trigger.agentAid}:${input.trigger.id}`);
|
|
76
117
|
if (!runtimeRoot)
|
|
@@ -195,20 +236,50 @@ function resolveRuntime(value) {
|
|
|
195
236
|
throw new Error(`script runtime is unavailable: ${runtime}`);
|
|
196
237
|
return fs.realpathSync.native(executable);
|
|
197
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* 解析 Windows scoped 沙箱宿主。
|
|
241
|
+
*
|
|
242
|
+
* **这里就是「EvolCore 依赖 Codex」的全部来源。** Codex 只作为 Windows 沙箱的
|
|
243
|
+
* 执行宿主(`codex.exe sandbox` + `codex-windows-sandbox-setup.exe` 施加的 ACL),
|
|
244
|
+
* 与 baseagent 无关,也不涉及模型调用。替代方案(landstrip / srt)尚未接入。
|
|
245
|
+
*
|
|
246
|
+
* 失败分三类,各自的修复动作不同,报错里会明确区分:
|
|
247
|
+
* 1. 没装 Codex → 全局安装
|
|
248
|
+
* 2. 装了但缺平台包 → 重装(npm 的 optional 依赖常因超时被静默丢弃)
|
|
249
|
+
* 3. 装了但沙箱未 provisioning → 在宿主终端跑一次 elevated setup
|
|
250
|
+
*
|
|
251
|
+
* 三类都失败时,唯一出路是改用 daemon scope / fullaccess(无沙箱)。
|
|
252
|
+
*/
|
|
198
253
|
function resolveWindowsBackend() {
|
|
254
|
+
const noSandboxHint = 'Alternatively, execute the script through daemon scope or fullaccess '
|
|
255
|
+
+ '(no sandbox is applied) and tell the user explicitly.';
|
|
199
256
|
const codexPath = resolveCodexCliPath();
|
|
200
|
-
if (!codexPath)
|
|
201
|
-
throw new Error('Codex CLI is required for scoped Windows Trigger script isolation'
|
|
257
|
+
if (!codexPath) {
|
|
258
|
+
throw new Error('Codex CLI is required for scoped Windows Trigger script isolation, but `codex` was not found on PATH. '
|
|
259
|
+
+ 'EvolCore only uses it as the Windows sandbox host — install it with `npm install -g @openai/codex`, '
|
|
260
|
+
+ 'then re-run. ' + noSandboxHint);
|
|
261
|
+
}
|
|
202
262
|
let command = codexPath;
|
|
203
263
|
if (path.extname(command).toLowerCase() !== '.exe') {
|
|
204
264
|
const packageFile = path.join(path.dirname(codexPath), 'node_modules', '@openai', 'codex', 'package.json');
|
|
205
265
|
const platformName = `@openai/codex-win32-${process.arch}`;
|
|
206
|
-
|
|
266
|
+
let platformFile;
|
|
267
|
+
try {
|
|
268
|
+
platformFile = createRequire(packageFile).resolve(`${platformName}/package.json`);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
throw new Error(`Codex is installed but its Windows native package "${platformName}" is missing `
|
|
272
|
+
+ `(${error?.message || String(error)}). npm silently drops optional packages on download timeout; `
|
|
273
|
+
+ 'reinstall Codex with a longer timeout, e.g. `npm install -g @openai/codex --fetch-timeout=600000`. '
|
|
274
|
+
+ noSandboxHint, { cause: error });
|
|
275
|
+
}
|
|
207
276
|
const target = process.arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc';
|
|
208
277
|
command = path.join(path.dirname(platformFile), 'vendor', target, 'bin', 'codex.exe');
|
|
209
278
|
}
|
|
210
|
-
if (!fs.statSync(command).isFile())
|
|
211
|
-
throw new Error(
|
|
279
|
+
if (!fs.statSync(command).isFile()) {
|
|
280
|
+
throw new Error(`Codex is installed but the native sandbox executable is missing at "${command}". `
|
|
281
|
+
+ 'Reinstall Codex (`npm install -g @openai/codex`). ' + noSandboxHint);
|
|
282
|
+
}
|
|
212
283
|
const home = resolveRealDirectory(process.env.CODEX_HOME || path.join(os.homedir(), '.codex'), 'Codex control home');
|
|
213
284
|
let marker;
|
|
214
285
|
try {
|
|
@@ -227,7 +298,14 @@ function resolveWindowsBackend() {
|
|
|
227
298
|
|| users.online?.username !== 'CodexSandboxOnline' || typeof users.online?.password !== 'string' || !users.online.password
|
|
228
299
|
|| !fs.existsSync(path.join(home, '.sandbox-bin'))
|
|
229
300
|
|| !fs.readdirSync(path.join(home, '.sandbox-bin')).some(name => /^codex-command-runner-.+\.exe$/.test(name))) {
|
|
230
|
-
throw new Error('Windows restricted-read sandbox
|
|
301
|
+
throw new Error(`Codex's Windows restricted-read sandbox is not provisioned in "${home}" `
|
|
302
|
+
+ `(expected setup_marker version ${WINDOWS_SANDBOX_SETUP_VERSION}, sandbox users `
|
|
303
|
+
+ 'CodexSandboxOffline/Online, and a codex-command-runner-*.exe in .sandbox-bin). '
|
|
304
|
+
+ 'Automatic elevation is disabled by design — run the elevated setup once in a host terminal: '
|
|
305
|
+
+ 'Codex Desktop → Windows Sandbox settings → setup/repair (elevated, accept one UAC prompt). '
|
|
306
|
+
+ 'Then verify with `codex doctor --json` (backend=elevated, provisioning=complete) and '
|
|
307
|
+
+ '`codex sandbox -- cmd /c whoami` (should show CodexSandboxOffline/Online, not your desktop user). '
|
|
308
|
+
+ 'Troubleshooting: kits/docs/evolcore/codex-windows-sandbox.md. ' + noSandboxHint);
|
|
231
309
|
}
|
|
232
310
|
return { command: fs.realpathSync.native(command), home };
|
|
233
311
|
}
|
|
@@ -340,6 +418,20 @@ function getScriptEnvironmentExcludes() {
|
|
|
340
418
|
function filesystemEntry(value, access) {
|
|
341
419
|
return { path: { type: 'path', path: path.resolve(value) }, access };
|
|
342
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* 证明 Windows 沙箱的文件策略确实被执行。
|
|
423
|
+
*
|
|
424
|
+
* 这里验证的是「**显式 deny 生效**」,不是「默认拒绝读」——Codex 的 Windows
|
|
425
|
+
* 沙箱与 Linux 的 `--ro-bind / /` 同为「默认放行 + 显式 deny」语义:策略里
|
|
426
|
+
* `{ kind: 'root' }` 给 read,其余 deny 条目在其上做减法。因此拿一个不在
|
|
427
|
+
* deny 列表里的路径去期望 EACCES 永远不成立,只会把每次脚本执行都判成失败。
|
|
428
|
+
*
|
|
429
|
+
* 三步:
|
|
430
|
+
* 1. 读 canary 且策略里显式给 `read` → 必须成功(证明「能读」,策略未被整体拒绝)
|
|
431
|
+
* 2. 同一个 canary 在策略里显式给 `deny` → 必须 EACCES/EPERM
|
|
432
|
+
* (证明 deny 真的被沙箱执行;这一步失败说明沙箱没起效,必须拒跑)
|
|
433
|
+
* 3. 在 workDir 写文件 → 必须成功(证明 scoped 路径没有把整个文件系统锁死)
|
|
434
|
+
*/
|
|
343
435
|
async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir, signal) {
|
|
344
436
|
signal?.throwIfAborted();
|
|
345
437
|
const canary = path.join(runDir, 'read-isolation-canary');
|
|
@@ -350,26 +442,30 @@ async function verifyWindowsReadIsolation(launch, sandboxArgs, runDir, workDir,
|
|
|
350
442
|
'if (fs.readFileSync(process.argv[1], "utf8") !== "evolcore-read-isolation-canary") process.exit(91);',
|
|
351
443
|
'process.stdout.write("evolcore-trigger-sandbox-ready");',
|
|
352
444
|
].join('\n');
|
|
353
|
-
|
|
445
|
+
// 策略里显式 deny 的同一个文件必须读不到;能读到就说明沙箱没执行策略。
|
|
446
|
+
const denyProbe = [
|
|
354
447
|
'const fs = require("node:fs");',
|
|
355
448
|
'let denied = false;',
|
|
356
449
|
'try { fs.readFileSync(process.argv[1]); } catch (error) {',
|
|
357
|
-
'if (error.code === "EACCES" || error.code === "EPERM") denied = true; else throw error;',
|
|
450
|
+
'if (error.code === "EACCES" || error.code === "EPERM" || error.code === "ENOENT") denied = true; else throw error;',
|
|
358
451
|
'}',
|
|
359
|
-
'if (!denied) { process.stderr.write("
|
|
452
|
+
'if (!denied) { process.stderr.write("deny enforcement is not applied: denied path was readable"); process.exit(90); }',
|
|
360
453
|
'fs.writeFileSync(process.argv[2], "allowed");',
|
|
361
454
|
'process.stdout.write("evolcore-trigger-sandbox-ready");',
|
|
362
455
|
].join('\n');
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
const stateIndex =
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (
|
|
456
|
+
const withExtraEntry = (extra) => {
|
|
457
|
+
const args = [...sandboxArgs];
|
|
458
|
+
const stateIndex = args.indexOf('--sandbox-state-json') + 1;
|
|
459
|
+
const state = JSON.parse(args[stateIndex]);
|
|
460
|
+
state.permissionProfile.file_system.entries.push(extra);
|
|
461
|
+
args[stateIndex] = JSON.stringify(state);
|
|
462
|
+
if (args[stateIndex].length > 20_000)
|
|
370
463
|
throw new Error('filesystem probe policy exceeds the command-line budget');
|
|
371
|
-
|
|
372
|
-
|
|
464
|
+
return args;
|
|
465
|
+
};
|
|
466
|
+
try {
|
|
467
|
+
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'read')), readProbe, [canary], signal);
|
|
468
|
+
await runWindowsIsolationProbe(launch, withExtraEntry(filesystemEntry(canary, 'deny')), denyProbe, [canary, writableProbe], signal);
|
|
373
469
|
}
|
|
374
470
|
catch (error) {
|
|
375
471
|
throw new Error(`Windows sandbox cannot prove scoped read isolation; Trigger script execution is refused: ${error?.message || String(error)}`, { cause: error });
|