evolcore 0.0.41-test.1 → 0.0.41
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
package/dist/ipc.js
CHANGED
|
@@ -6,7 +6,7 @@ import crypto from 'crypto';
|
|
|
6
6
|
import os from 'os';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
|
-
import { logger } from './utils/logger.js';
|
|
9
|
+
import { logger, logOwnershipEvent } from './utils/logger.js';
|
|
10
10
|
import { withMenuProcessingTime, logMenuRequestCompleted, logMenuRequestReceived } from './core/command/menu-protocol.js';
|
|
11
11
|
import { fileCache } from './core/daemon-file-cache.js';
|
|
12
12
|
import { DAEMON_RUNTIME_EPOCH_ENV } from './cli/task-context.js';
|
|
@@ -16,13 +16,13 @@ import { getPackageRoot, getWindowsInstanceSocketPathCandidates, normalizeIpcEnd
|
|
|
16
16
|
import { getProcessStartTime, isSameOrOlderProcess } from './utils/process-introspect.js';
|
|
17
17
|
import { classifyProcessTree, ProcessTreeSampler, readProcessMetrics } from './utils/process-tree-stats.js';
|
|
18
18
|
import { readSystemMemoryUsage } from './utils/system-memory.js';
|
|
19
|
-
import { hashCurrentDelegatedCommand, hashDelegatedCommandArgv, parseDelegatedExecutionSpec, readDelegatedExecutionSpec } from './core/auth/agent-delegation.js';
|
|
19
|
+
import { AGENT_DELEGATION_TOKEN_ENV, CODEX_SESSION_TOKEN_ENV, hashCurrentDelegatedCommand, hashDelegatedCommandArgv, parseDelegatedExecutionSpec, readDelegatedExecutionSpec } from './core/auth/agent-delegation.js';
|
|
20
20
|
import { resolveSkillRefreshArgv } from './core/skill/command-parser.js';
|
|
21
21
|
import { normalizeAunMentionEntries } from './aun/msg/mention-schema.js';
|
|
22
22
|
import { remoteAccessService } from './core/auth/remote-access-store.js';
|
|
23
23
|
import { setModelCatalogDaemonOwner } from './core/model/model-catalog.js';
|
|
24
24
|
import { RUNTIME_ENVIRONMENT_NAMES, setRuntimeEnvironmentOverride } from './config/runtime-env.js';
|
|
25
|
-
import { MAIN_CLI_BIN } from './product.js';
|
|
25
|
+
import { MAIN_CLI_BIN, SESSION_ID_ENV } from './product.js';
|
|
26
26
|
import { ownerResolver } from './core/ownership/owner-resolver.js';
|
|
27
27
|
import { parseOwnershipCommand, executeOwnershipCommand, ownershipFailure } from './aun/aid/ownership-operation.js';
|
|
28
28
|
import { ECWEB_SERVICE_PROTOCOL, validateEcwebClientProtocolRequirements, } from './contracts/ecweb-service-protocol.js';
|
|
@@ -73,6 +73,8 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
73
73
|
'evolagent.resync',
|
|
74
74
|
'menu.exec',
|
|
75
75
|
'ecweb.providers',
|
|
76
|
+
'provider.op',
|
|
77
|
+
'ecweb.init',
|
|
76
78
|
'ecweb.basic-settings',
|
|
77
79
|
'ecweb.message.context',
|
|
78
80
|
'ecweb.session.runner-tasks',
|
|
@@ -102,7 +104,7 @@ function ipcLogToken(value, fallback = 'unknown') {
|
|
|
102
104
|
const token = String(value ?? '').replace(/[^A-Za-z0-9_.:-]/g, '_').slice(0, 128);
|
|
103
105
|
return token || fallback;
|
|
104
106
|
}
|
|
105
|
-
function nextIpcQueryId(cmd) {
|
|
107
|
+
function nextIpcQueryId(cmd, runtimeEpoch) {
|
|
106
108
|
const payload = cmd.payload;
|
|
107
109
|
const nestedId = payload && typeof payload === 'object' && !Array.isArray(payload)
|
|
108
110
|
? payload.requestId ?? payload.id
|
|
@@ -111,7 +113,9 @@ function nextIpcQueryId(cmd) {
|
|
|
111
113
|
if (typeof supplied === 'string' || typeof supplied === 'number')
|
|
112
114
|
return ipcLogToken(supplied, 'unknown');
|
|
113
115
|
ipcQuerySequence = (ipcQuerySequence + 1) % Number.MAX_SAFE_INTEGER;
|
|
114
|
-
|
|
116
|
+
// Scope fallback counters with the existing daemon epoch across restarts.
|
|
117
|
+
const scope = runtimeEpoch ? `${ipcLogToken(runtimeEpoch)}-` : '';
|
|
118
|
+
return `ipc-${scope}${ipcQuerySequence}`;
|
|
115
119
|
}
|
|
116
120
|
function requiresLocalControlToken(cmd) {
|
|
117
121
|
// Managed calls use task delegation. Standalone queries must not gain
|
|
@@ -123,8 +127,9 @@ function requiresLocalControlToken(cmd) {
|
|
|
123
127
|
return true;
|
|
124
128
|
if (type === 'debug-issue-token')
|
|
125
129
|
return true;
|
|
130
|
+
// Ownership has an explicit, non-fallback authentication contract below.
|
|
126
131
|
if (type === 'aid.ownership')
|
|
127
|
-
return
|
|
132
|
+
return false;
|
|
128
133
|
if (type === 'skill.refresh' || type === 'thread.op')
|
|
129
134
|
return !sessionId || !delegated;
|
|
130
135
|
return ['evolagent.bootstrapComplete', 'diag', 'handoff-status', 'handoff-list', 'handoff-trace', 'task.resume'].includes(type)
|
|
@@ -991,12 +996,20 @@ export class IpcServer {
|
|
|
991
996
|
}
|
|
992
997
|
}
|
|
993
998
|
async handleCommand(cmd, requestSignal, receivedAtMono = performance.now()) {
|
|
994
|
-
|
|
999
|
+
const requestId = nextIpcQueryId(cmd, this.daemonRuntimeEpoch);
|
|
1000
|
+
const result = await withDelegationDiagnosticContext({
|
|
995
1001
|
sessionId: typeof cmd.sessionId === 'string' ? cmd.sessionId : undefined,
|
|
996
|
-
requestId
|
|
1002
|
+
requestId,
|
|
997
1003
|
correlationId: typeof cmd.correlationId === 'string' ? ipcLogToken(cmd.correlationId) : undefined,
|
|
998
1004
|
operation: ipcLogToken(cmd.type),
|
|
999
|
-
}, () => this.dispatchCommand(cmd, requestSignal, receivedAtMono));
|
|
1005
|
+
}, () => this.dispatchCommand(cmd, requestSignal, receivedAtMono, requestId));
|
|
1006
|
+
if (cmd.type === 'aid.ownership' && result && typeof result === 'object'
|
|
1007
|
+
&& result.ok === false) {
|
|
1008
|
+
logOwnershipEvent('operation.failed', {
|
|
1009
|
+
errorCode: result.code,
|
|
1010
|
+
}, true);
|
|
1011
|
+
}
|
|
1012
|
+
return result;
|
|
1000
1013
|
}
|
|
1001
1014
|
diagnosticRejection(cause, cmd) {
|
|
1002
1015
|
const failure = this.delegationFailureRecorder?.(cause, typeof (cmd.sessionId ?? cmd.originSessionId ?? cmd.actorSessionId) === 'string'
|
|
@@ -1011,7 +1024,11 @@ export class IpcServer {
|
|
|
1011
1024
|
...(failure?.diagnosticEventId ? { diagnosticEventId: failure.diagnosticEventId } : {}),
|
|
1012
1025
|
};
|
|
1013
1026
|
}
|
|
1014
|
-
async dispatchCommand(cmd, requestSignal, receivedAtMono = performance.now()) {
|
|
1027
|
+
async dispatchCommand(cmd, requestSignal, receivedAtMono = performance.now(), requestId) {
|
|
1028
|
+
if (cmd.type === 'provider.op' && (cmd.sessionId !== undefined || cmd.actorSessionId !== undefined
|
|
1029
|
+
|| cmd.delegationToken !== undefined)) {
|
|
1030
|
+
return { ok: false, code: 'FORBIDDEN', error: 'Provider management requires host process control, not Agent task delegation' };
|
|
1031
|
+
}
|
|
1015
1032
|
if (requiresLocalControlToken(cmd) && !this.hasValidControlToken(cmd.controlToken)) {
|
|
1016
1033
|
return { ok: false, code: 'INVALID_CONTROL_TOKEN', error: 'valid local control token is required' };
|
|
1017
1034
|
}
|
|
@@ -1034,8 +1051,8 @@ export class IpcServer {
|
|
|
1034
1051
|
if (cmd.executionSpec !== undefined && !executionSpec) {
|
|
1035
1052
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Invalid delegated execution spec' };
|
|
1036
1053
|
}
|
|
1037
|
-
// 与客户端同一基准:有 spec
|
|
1038
|
-
// argv
|
|
1054
|
+
// 与客户端同一基准:有 spec 时绑定 preflight 批准并实际 spawn 的执行规格;
|
|
1055
|
+
// 否则绑定原始命令 argv。收发方等执行参数由 daemon 在授权后另行补全。
|
|
1039
1056
|
const expectedArgv = executionSpec
|
|
1040
1057
|
? [...executionSpec.argv]
|
|
1041
1058
|
: [
|
|
@@ -1125,10 +1142,18 @@ export class IpcServer {
|
|
|
1125
1142
|
return this.diagExecutor ? this.diagExecutor(cmd) : { ok: false, code: 'NOT_CONFIGURED', message: '诊断入口未配置' };
|
|
1126
1143
|
case 'menu-client.request':
|
|
1127
1144
|
return this.menuClientExecutor ? this.menuClientExecutor(cmd) : { ok: false, code: 'NOT_CONFIGURED', error: 'Managed Menu client is not configured' };
|
|
1145
|
+
case 'provider.op': {
|
|
1146
|
+
const { executeProviderOperation } = await import('./config/provider-ipc-service.js');
|
|
1147
|
+
return executeProviderOperation({ argv: cmd.argv });
|
|
1148
|
+
}
|
|
1128
1149
|
case 'ecweb.providers': {
|
|
1129
1150
|
const { handleProvidersService } = await import('./ecweb/providers-service.js');
|
|
1130
1151
|
return handleProvidersService(cmd.request);
|
|
1131
1152
|
}
|
|
1153
|
+
case 'ecweb.init': {
|
|
1154
|
+
const { handleInitService } = await import('./core/initialization/service.js');
|
|
1155
|
+
return handleInitService(cmd.request);
|
|
1156
|
+
}
|
|
1132
1157
|
case 'ecweb.basic-settings': {
|
|
1133
1158
|
const { handleBasicSettingsService } = await import('./ecweb/basic-settings-service.js');
|
|
1134
1159
|
return handleBasicSettingsService(cmd.request);
|
|
@@ -1329,11 +1354,20 @@ export class IpcServer {
|
|
|
1329
1354
|
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')) {
|
|
1330
1355
|
return { ok: false, code: 'INVALID_ARGUMENT', error: 'Ownership argv is required' };
|
|
1331
1356
|
}
|
|
1332
|
-
|
|
1357
|
+
const hasDelegation = cmd.sessionId !== undefined || cmd.delegationToken !== undefined;
|
|
1358
|
+
if (cmd.authMode !== 'local-control') {
|
|
1359
|
+
if (cmd.authMode !== undefined || cmd.controlToken !== undefined
|
|
1360
|
+
|| typeof cmd.sessionId !== 'string' || !cmd.sessionId.trim()
|
|
1361
|
+
|| typeof cmd.delegationToken !== 'string' || !cmd.delegationToken.trim()) {
|
|
1362
|
+
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Ownership requires valid task delegation or explicit host control authentication' };
|
|
1363
|
+
}
|
|
1333
1364
|
if (!this.aidOwnershipExecutor)
|
|
1334
1365
|
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Managed ownership is unavailable' };
|
|
1335
1366
|
return this.aidOwnershipExecutor(cmd.argv, cmd.sessionId, cmd.delegationToken, cmd.delegationCommandHash);
|
|
1336
1367
|
}
|
|
1368
|
+
if (hasDelegation || !this.hasValidControlToken(cmd.controlToken)) {
|
|
1369
|
+
return { ok: false, code: 'INVALID_CONTROL_TOKEN', error: 'Host control requires its own credential without task delegation' };
|
|
1370
|
+
}
|
|
1337
1371
|
try {
|
|
1338
1372
|
const command = parseOwnershipCommand(cmd.argv);
|
|
1339
1373
|
return { ok: true, state: await executeOwnershipCommand(command, ownerResolver.getDaemonAid()) };
|
|
@@ -1588,10 +1622,13 @@ export class IpcServer {
|
|
|
1588
1622
|
if (!context?.selfAid || !context.peerRole || context.peerRole === 'none') {
|
|
1589
1623
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Current task identity and role are unavailable' };
|
|
1590
1624
|
}
|
|
1591
|
-
|
|
1625
|
+
const fullAccessTask = context.processRole === 'fullaccess-run'
|
|
1626
|
+
&& context.dataScope === 'daemon' && context.permissionMode === 'fullaccess';
|
|
1627
|
+
if (cmd.argv[0] === 'stats' && !fullAccessTask
|
|
1628
|
+
&& cmd.argv.some((value) => /^--(?:sql|rebuild)(?:=|$)/.test(value))) {
|
|
1592
1629
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed stats cannot use --sql or --rebuild' };
|
|
1593
1630
|
}
|
|
1594
|
-
if (cmd.argv[0] === 'skill' && context.permissionMode === 'readonly'
|
|
1631
|
+
if (cmd.argv[0] === 'skill' && !fullAccessTask && context.permissionMode === 'readonly'
|
|
1595
1632
|
&& ['create', 'install', 'remove', 'enable', 'disable'].includes(cmd.argv[1])) {
|
|
1596
1633
|
return { ok: false, code: 'NOT_ALLOWED', error: 'Readonly tasks cannot modify skills' };
|
|
1597
1634
|
}
|
|
@@ -1976,7 +2013,7 @@ export class IpcServer {
|
|
|
1976
2013
|
return guard.error;
|
|
1977
2014
|
const { createMemory, sourceMemoryDirOf } = await import('./core/memory/memory-writer.js');
|
|
1978
2015
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
1979
|
-
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/
|
|
2016
|
+
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/consolidation-ops-records.js');
|
|
1980
2017
|
// forget 下 create 只用于合并:被替换的每条旧记忆都要记遗忘理由。
|
|
1981
2018
|
// 不带 --replaces 等于在遗忘会话里新建记忆,既不是遗忘也没有理由可记,直接拒绝。
|
|
1982
2019
|
// 其他模式的 --replaces 是记忆产生 / 泛化的过程,不进遗忘日志。
|
|
@@ -2042,7 +2079,7 @@ export class IpcServer {
|
|
|
2042
2079
|
return guard.error;
|
|
2043
2080
|
const { updateMemory } = await import('./core/memory/memory-writer.js');
|
|
2044
2081
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
2045
|
-
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/
|
|
2082
|
+
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/consolidation-ops-records.js');
|
|
2046
2083
|
// forget 下 update 只有续期一种用法:不许改标签(那是 notes 模式的事),每条都要带理由
|
|
2047
2084
|
let forgetReason;
|
|
2048
2085
|
if (guard.taskCtx.memoryMode === 'forget') {
|
|
@@ -2098,7 +2135,7 @@ export class IpcServer {
|
|
|
2098
2135
|
return guard.error;
|
|
2099
2136
|
const { archiveMemory, sourceMemoryDirOf } = await import('./core/memory/memory-writer.js');
|
|
2100
2137
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
2101
|
-
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/
|
|
2138
|
+
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/consolidation-ops-records.js');
|
|
2102
2139
|
// forget 下一次只归档一条:理由是针对这一条记忆的,多条共用一个理由就失去了意义
|
|
2103
2140
|
let forgetReason;
|
|
2104
2141
|
if (guard.taskCtx.memoryMode === 'forget') {
|
|
@@ -2212,7 +2249,7 @@ export class IpcServer {
|
|
|
2212
2249
|
if (delegationToken !== undefined && typeof delegationToken !== 'string') {
|
|
2213
2250
|
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
|
|
2214
2251
|
}
|
|
2215
|
-
return await this.configOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2252
|
+
return await this.configOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined, requestId);
|
|
2216
2253
|
}
|
|
2217
2254
|
case 'contact.op': {
|
|
2218
2255
|
if (!this.contactOperationExecutor)
|
|
@@ -2248,7 +2285,7 @@ export class IpcServer {
|
|
|
2248
2285
|
if (delegationToken !== undefined && typeof delegationToken !== 'string') {
|
|
2249
2286
|
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
|
|
2250
2287
|
}
|
|
2251
|
-
return await this.aidOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2288
|
+
return await this.aidOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined, requestId);
|
|
2252
2289
|
}
|
|
2253
2290
|
case 'group.op': {
|
|
2254
2291
|
if (!this.groupOperationExecutor)
|
|
@@ -2802,7 +2839,31 @@ export class IpcTransportError extends Error {
|
|
|
2802
2839
|
this.name = 'IpcTransportError';
|
|
2803
2840
|
}
|
|
2804
2841
|
}
|
|
2805
|
-
/**
|
|
2842
|
+
/**
|
|
2843
|
+
* Explicit host capability. The OS account able to read control.token is the
|
|
2844
|
+
* trust boundary; this is not proof of a human or isolation from a same-UID
|
|
2845
|
+
* fullaccess process. Never use environment-variable absence as authentication.
|
|
2846
|
+
*/
|
|
2847
|
+
export async function ipcHostQuery(socketPath, cmd, timeoutMs = 3000, options = {}) {
|
|
2848
|
+
let authenticatedCmd = cmd;
|
|
2849
|
+
const managed = cmd.delegationToken !== undefined
|
|
2850
|
+
|| [SESSION_ID_ENV, AGENT_DELEGATION_TOKEN_ENV, CODEX_SESSION_TOKEN_ENV]
|
|
2851
|
+
.some(key => process.env[key] !== undefined)
|
|
2852
|
+
|| (cmd.sessionId !== undefined && cmd.type !== 'debug-issue-token'
|
|
2853
|
+
&& !(MEMORY_COMMAND_ENDPOINTS.has(cmd.type) && cmd.debug === true));
|
|
2854
|
+
if (!managed && typeof cmd.controlToken !== 'string'
|
|
2855
|
+
&& (requiresLocalControlToken(cmd) || cmd.authMode === 'local-control'
|
|
2856
|
+
|| (MEMORY_COMMAND_ENDPOINTS.has(cmd.type) && cmd.debug === true))) {
|
|
2857
|
+
try {
|
|
2858
|
+
const controlToken = fs.readFileSync(resolvePaths().controlToken, 'utf8').trim();
|
|
2859
|
+
if (controlToken)
|
|
2860
|
+
authenticatedCmd = { ...cmd, controlToken };
|
|
2861
|
+
}
|
|
2862
|
+
catch { /* The daemon rejects a missing credential. */ }
|
|
2863
|
+
}
|
|
2864
|
+
return ipcQuery(socketPath, authenticatedCmd, timeoutMs, options);
|
|
2865
|
+
}
|
|
2866
|
+
/** Query the daemon without acquiring credentials; callers supply authentication. */
|
|
2806
2867
|
/** Pass `null` as timeoutMs to wait without a client-side deadline. */
|
|
2807
2868
|
export async function ipcQuery(socketPath, cmd, timeoutMs = 3000, options = {}) {
|
|
2808
2869
|
const endpoint = normalizeIpcEndpoint(socketPath);
|
|
@@ -2844,7 +2905,7 @@ export async function ipcQuery(socketPath, cmd, timeoutMs = 3000, options = {})
|
|
|
2844
2905
|
}
|
|
2845
2906
|
function ipcQueryOnce(socketPath, cmd, timeoutMs = 3000) {
|
|
2846
2907
|
let authenticatedCmd = cmd;
|
|
2847
|
-
if (!process.env
|
|
2908
|
+
if (cmd.type !== 'aid.ownership' && !process.env[SESSION_ID_ENV]
|
|
2848
2909
|
&& (requiresLocalControlToken(cmd) || (MEMORY_COMMAND_ENDPOINTS.has(cmd.type) && cmd.debug === true))
|
|
2849
2910
|
&& typeof cmd.controlToken !== 'string') {
|
|
2850
2911
|
try {
|
|
@@ -2865,9 +2926,8 @@ function ipcQueryOnce(socketPath, cmd, timeoutMs = 3000) {
|
|
|
2865
2926
|
const executionSpec = typeof authenticatedCmd.delegationToken === 'string'
|
|
2866
2927
|
? readDelegatedExecutionSpec()
|
|
2867
2928
|
: undefined;
|
|
2868
|
-
// executionSpec
|
|
2869
|
-
//
|
|
2870
|
-
// 必然不同;指纹必须以 spec 为准,否则两端都算不出哈希而把合法调用判成 mismatch。
|
|
2929
|
+
// executionSpec 存在时,指纹必须绑定 preflight 批准并实际 spawn 的执行规格;
|
|
2930
|
+
// 其余请求使用原始命令 argv,保证审批、上下文查询和实际操作采用同一基准。
|
|
2871
2931
|
const hashArgv = executionSpec?.argv ?? requestArgv;
|
|
2872
2932
|
const delegationCommandHash = typeof authenticatedCmd.delegationToken === 'string'
|
|
2873
2933
|
&& typeof authenticatedCmd.delegationCommandHash !== 'string'
|
package/dist/paths.js
CHANGED
|
@@ -161,6 +161,9 @@ export function agentCodexTokenPath(aid, threadId) {
|
|
|
161
161
|
export function agentGroupInviteReviewsPath(aid) {
|
|
162
162
|
return path.join(agentDataDir(aid), 'aun', 'group-invite-reviews.json');
|
|
163
163
|
}
|
|
164
|
+
export function agentOwnerBindingRejectionPath(aid, ownerAid) {
|
|
165
|
+
return path.join(agentDataDir(aid), 'aun', 'owner-binding-rejections', `${encodeURIComponent(ownerAid)}.json`);
|
|
166
|
+
}
|
|
164
167
|
export function agentOutboxPath(aid) {
|
|
165
168
|
return path.join(agentDataDir(aid), 'outbox', 'delivery.jsonl');
|
|
166
169
|
}
|
package/dist/proxy/manager.js
CHANGED
|
@@ -431,9 +431,9 @@ export class ServiceProxyManager {
|
|
|
431
431
|
return;
|
|
432
432
|
}
|
|
433
433
|
this.activeProxy = handle;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (this.activeProxy !== handle)
|
|
434
|
+
// 控制通道可能仍在后台连接,不能让网络就绪阻塞后续配置应用和停止操作。
|
|
435
|
+
void handle.ready.then(result => {
|
|
436
|
+
if (this.stopped || this.activeProxy !== handle)
|
|
437
437
|
return;
|
|
438
438
|
this.proxyTransport.gatewayRegistered = result.gatewayRegistered;
|
|
439
439
|
this.proxyTransport.proxyServer = 'unconfirmed';
|
|
@@ -451,13 +451,12 @@ export class ServiceProxyManager {
|
|
|
451
451
|
}
|
|
452
452
|
this.proxyTransport.state = result.gatewayRegistered ? 'active' : 'degraded';
|
|
453
453
|
this.proxyTransport.error = result.gatewayRegistered ? undefined : 'Gateway registration has not been confirmed';
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (this.activeProxy !== handle)
|
|
454
|
+
}).catch(error => {
|
|
455
|
+
if (this.stopped || this.activeProxy !== handle)
|
|
457
456
|
return;
|
|
458
457
|
this.proxyTransport.state = 'degraded';
|
|
459
458
|
this.proxyTransport.error = error instanceof Error ? error.message : String(error);
|
|
460
|
-
}
|
|
459
|
+
});
|
|
461
460
|
}
|
|
462
461
|
readActiveProxyNames() {
|
|
463
462
|
return [...this.activeProxyNames];
|
|
@@ -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');
|