evolcore 0.0.43-test.0 → 0.0.43-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 +31 -2
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +26 -9
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +3 -0
- package/dist/channels/aun.js +484 -43
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +22 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +1 -0
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +77 -64
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +1 -1
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/access-policy.js +1 -0
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +7 -0
- package/dist/config/role-schema.js +4 -3
- package/dist/config/role-service.js +3 -3
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/agent-runtime.js +2 -1
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +0 -11
- package/dist/core/auth/operation-catalog.js +0 -18
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +17 -46
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +3 -2
- package/dist/core/command/menu-handler.js +51 -8
- package/dist/core/command/menu-protocol.js +20 -0
- package/dist/core/command/slash-handler.js +101 -40
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +5 -8
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +28 -1
- package/dist/core/message/contact-admission.js +548 -0
- package/dist/core/message/im-renderer.js +69 -10
- package/dist/core/message/message-admission.js +28 -3
- package/dist/core/message/message-bridge.js +46 -5
- package/dist/core/message/message-utils.js +0 -5
- package/dist/core/message/peer-mode.js +44 -10
- package/dist/core/message/response-engine.js +268 -69
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/permission/ec-command-parser.js +1 -28
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/role/runtime-policy.js +14 -2
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +128 -29
- package/dist/directory/owner-directory-cache.js +364 -50
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +120 -47
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +219 -32
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-search.js +50 -18
- package/dist/directory/owner-directory-store.js +150 -30
- package/dist/eck/kit-renderer.js +12 -5
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/eck/message-renderer.js +5 -2
- package/dist/eck/paactive-context.js +45 -0
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +24 -16
- package/dist/index.js +9 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +26 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +4 -1
- package/dist/response-system/engines/v1/paactive-flow.js +18 -0
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +3 -5
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +5 -2
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/dist/agent-loop.js +43 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +1 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +137 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +57 -4
- package/kits/eck_manifest.memory.json +67 -3
- package/kits/eck_manifest.paactive.json +528 -0
- package/kits/eck_message_manifest.paactive.json +233 -0
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +31 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/message-fragments/paactive/item.md +3 -0
- package/kits/templates/soul/00-GUIDE.md +61 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/paactive/channel.md +25 -0
- package/kits/templates/system-fragments/paactive/reply.md +25 -0
- package/kits/templates/system-fragments/paactive/session.md +32 -0
- package/kits/templates/system-fragments/personal-assistant.md +65 -0
- package/package.json +4 -3
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
|
@@ -9,6 +9,7 @@ const USAGE = `用法: ec pa-workspace init --workspace <绝对路径> [--force]
|
|
|
9
9
|
ec pa-workspace navigation show
|
|
10
10
|
ec pa-workspace navigation update --expected-revision <n> --entries-json <json>
|
|
11
11
|
|
|
12
|
+
所有子命令都只输出 JSON,--format json / --json 可省略。
|
|
12
13
|
仅限当前 Agent 的 AUN owner 私聊托管会话。`;
|
|
13
14
|
const MAX_SKILL_OUTPUT_CHARS = 2 * 1024 * 1024;
|
|
14
15
|
export class PaWorkspaceCommandError extends Error {
|
|
@@ -101,6 +102,38 @@ function value(args, flag) {
|
|
|
101
102
|
const index = args.indexOf(flag);
|
|
102
103
|
return index >= 0 ? args[index + 1] : undefined;
|
|
103
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* 摘掉输出格式参数。
|
|
107
|
+
*
|
|
108
|
+
* 本命令**只输出 JSON**,所以 `--format json` 和 `--json` 都不改变行为。
|
|
109
|
+
* 但别的命令(`ec thread`、`ec agent welcome show` …)都接受这两个参数,
|
|
110
|
+
* 调用方很容易顺手写上;直接报 INVALID_ARGUMENT 只会让人以为是用法错误。
|
|
111
|
+
* 这里统一接受,真正的非法值(如 `--format text`)才报错并说清原因。
|
|
112
|
+
*/
|
|
113
|
+
function normalizeFormatArgs(args) {
|
|
114
|
+
const out = [];
|
|
115
|
+
for (let index = 0; index < args.length; index++) {
|
|
116
|
+
const argument = args[index];
|
|
117
|
+
if (argument === '--json')
|
|
118
|
+
continue;
|
|
119
|
+
if (argument === '--format') {
|
|
120
|
+
const format = args[++index];
|
|
121
|
+
if (format !== 'json') {
|
|
122
|
+
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', `ec pa-workspace 只输出 JSON,--format 只能取 json(收到 ${format ?? '空'})`);
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (argument.startsWith('--format=')) {
|
|
127
|
+
const format = argument.slice('--format='.length);
|
|
128
|
+
if (format !== 'json') {
|
|
129
|
+
throw new PaWorkspaceCommandError('INVALID_ARGUMENT', `ec pa-workspace 只输出 JSON,--format 只能取 json(收到 ${format || '空'})`);
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
out.push(argument);
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
104
137
|
function assertOwnerPrivateRuntime(context) {
|
|
105
138
|
if (context.channel !== 'aun' || context.chatType !== 'private' || context.peerRole !== 'owner'
|
|
106
139
|
|| !context.selfAid || !context.peerId) {
|
|
@@ -110,12 +143,13 @@ function assertOwnerPrivateRuntime(context) {
|
|
|
110
143
|
function output(value) {
|
|
111
144
|
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
112
145
|
}
|
|
113
|
-
export async function cmdPaWorkspace(
|
|
114
|
-
if (
|
|
146
|
+
export async function cmdPaWorkspace(rawArgs) {
|
|
147
|
+
if (rawArgs.length === 0 || rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
115
148
|
console.log(USAGE);
|
|
116
149
|
return;
|
|
117
150
|
}
|
|
118
151
|
try {
|
|
152
|
+
const args = normalizeFormatArgs(rawArgs);
|
|
119
153
|
const context = await authorizeLocalCommand(['pa-workspace', ...args]);
|
|
120
154
|
assertOwnerPrivateRuntime(context);
|
|
121
155
|
if (args[0] === 'init') {
|
package/dist/cli/peer.js
CHANGED
|
@@ -70,7 +70,7 @@ function fail(message, code = 'INVALID_ARGUMENT', data) {
|
|
|
70
70
|
throw error;
|
|
71
71
|
}
|
|
72
72
|
function printHelp() {
|
|
73
|
-
console.log(
|
|
73
|
+
console.log(`用法:
|
|
74
74
|
ec peer block <primaryId> --self <agent-aid>
|
|
75
75
|
ec peer unblock <primaryId> --self <agent-aid>
|
|
76
76
|
ec peer list --blocked [--self <agent-aid>]
|
|
@@ -17,7 +17,7 @@ import { readRestartRequest, updateRestartRequest, removeRestartRequest, shouldS
|
|
|
17
17
|
import { rotateStdoutLog } from '../utils/log-writer.js';
|
|
18
18
|
import { applyDataMigration, finalizeDataMigration, planDataMigration, verifyDataMigration, } from '../core/data-migration.js';
|
|
19
19
|
import { DAEMON_SHUTDOWN_TIMEOUT_MS, requestDaemonShutdown, stopCodexAppServerOrphans } from './daemon-commands.js';
|
|
20
|
-
import { getProcessStartTime, startTimeMatches } from '../utils/process-introspect.js';
|
|
20
|
+
import { getProcessStartTime, invalidateProcessSnapshot, startTimeMatches } from '../utils/process-introspect.js';
|
|
21
21
|
import { DEFAULT_ECWEB_PORT, ecwebService, serviceRuntimeMode } from '../config/daemon-services.js';
|
|
22
22
|
import { probeEcwebRestartReadiness, stopEcwebForRestart } from '../ecweb/runtime/lifecycle.js';
|
|
23
23
|
import { resolveGlobalPkg } from '../utils/npm-ops.js';
|
|
@@ -398,9 +398,23 @@ export async function cmdRestartMonitor() {
|
|
|
398
398
|
// Preserve CLI restart's final ownership guards and optional orphan cleanup
|
|
399
399
|
// here, after election/shutdown, so no launcher stops a daemon before a
|
|
400
400
|
// watchdog has successfully loaded.
|
|
401
|
+
// Shutdown changed the process table. A cached pre-shutdown snapshot can
|
|
402
|
+
// otherwise classify the exited daemon as an unregistered runtime process.
|
|
403
|
+
invalidateProcessSnapshot();
|
|
401
404
|
const remaining = findOrphanProcesses();
|
|
402
|
-
|
|
403
|
-
|
|
405
|
+
const remainingMains = scanInstances().mains.filter(item => item.alive);
|
|
406
|
+
const remainingRuntime = remaining.filter(belongsToRuntime);
|
|
407
|
+
if (remainingMains.length || remainingRuntime.length) {
|
|
408
|
+
const pids = [...new Set([
|
|
409
|
+
...remainingMains.map(item => item.record.pid),
|
|
410
|
+
...remainingRuntime.map(item => item.pid),
|
|
411
|
+
])].join(', ');
|
|
412
|
+
const reason = `Restart aborted: a runtime process appeared or survived shutdown (PID: ${pids})`;
|
|
413
|
+
log(reason);
|
|
414
|
+
if (upgradeJob)
|
|
415
|
+
updateUpgradeJob(upgradeJob.jobId, {
|
|
416
|
+
lifecycle: { status: 'failed', reason, at: new Date().toISOString() },
|
|
417
|
+
});
|
|
404
418
|
cleanupPendingFile(pendingFile, log, hasCorrelatedRequest ? requestId : undefined);
|
|
405
419
|
process.exit(1);
|
|
406
420
|
}
|
package/dist/cli/role.js
CHANGED
|
@@ -65,7 +65,7 @@ function fail(message, code = 'INVALID_ARGUMENT', data) {
|
|
|
65
65
|
throw error;
|
|
66
66
|
}
|
|
67
67
|
function printHelp() {
|
|
68
|
-
console.log(
|
|
68
|
+
console.log(`用法:
|
|
69
69
|
ec role request <peer-aid> --role <role-id> [--reason '<text>'] [--self <agent-aid>]
|
|
70
70
|
ec role list [--status pending|approved|rejected|expired] [--self <agent-aid>]
|
|
71
71
|
ec role approve <request-id> [--reason '<text>'] [--self <agent-aid>]
|
|
@@ -5,7 +5,7 @@ import { authorizeLocalCommand } from './task-context.js';
|
|
|
5
5
|
import { findSessionCapsule, materializeSessionCapsules } from '../core/session/session-capsule.js';
|
|
6
6
|
import { scanChatDirs, readLastJsonlLine, } from '../core/session/session-fs-store.js';
|
|
7
7
|
const HELP_TEXT = `
|
|
8
|
-
ec session <command> [options]
|
|
8
|
+
用法: ec session <command> [options]
|
|
9
9
|
|
|
10
10
|
本地会话文件查询(读取 $EVOLCORE_HOME/agents/ 下的存档;托管任务先经 daemon 鉴权)。
|
|
11
11
|
|
package/dist/cli/stats.js
CHANGED
|
@@ -7,9 +7,9 @@ import { authorizeLocalCommand } from './task-context.js';
|
|
|
7
7
|
import { queryAggregated, querySessionTurns, queryContextBreakdown, queryTopPeers, queryTopModels, queryMessageAggregated, queryPeerList, querySummary, queryPeerDaily, queryTaskModelCalls, querySessionModelCalls, queryTaskSummary } from '../stats/query.js';
|
|
8
8
|
import { getBudgetStatus } from '../stats/budget.js';
|
|
9
9
|
import { normalizeUsage } from '../stats/normalizer.js';
|
|
10
|
-
const HELP =
|
|
10
|
+
const HELP = `用法: ec stats [options]
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
ec stats — Token 用量与费用统计
|
|
13
13
|
|
|
14
14
|
时间范围:
|
|
15
15
|
(无参数) 今日概览
|
|
@@ -8,7 +8,7 @@ import { readTaskRuntimeContextFromEnv } from './task-context.js';
|
|
|
8
8
|
const TOPIC_STATUSES = ['pending', 'in_progress', 'completed', 'archived'];
|
|
9
9
|
const SORT_ORDERS = ['recent', 'created'];
|
|
10
10
|
const HELP_TEXT = `
|
|
11
|
-
ec thread <command> [options]
|
|
11
|
+
用法: ec thread <command> [options]
|
|
12
12
|
|
|
13
13
|
命令:
|
|
14
14
|
peers 列出有话题记录的所有对端(先用这个选对端)
|
package/dist/cli/watch-msg.js
CHANGED
|
@@ -302,7 +302,7 @@ function renderMessagesPanel(state, width, height) {
|
|
|
302
302
|
const isGroup = m.chatType === 'group';
|
|
303
303
|
const chatTag = isGroup ? `${MAGENTA}[群聊]${RST}` : '';
|
|
304
304
|
const encLabel = m.encrypt ? '密文' : '明文';
|
|
305
|
-
const modeLabel = m.chatmode === 'proactive' ? '自主' : '响应';
|
|
305
|
+
const modeLabel = m.chatmode === 'paactive' ? 'PA' : m.chatmode === 'proactive' ? '自主' : '响应';
|
|
306
306
|
const metaTags = (m.encrypt != null || m.chatmode) ? `${MAGENTA}[${encLabel}|${modeLabel}]${RST}` : '';
|
|
307
307
|
// observer 插话:醒目标记,与对端真实消息区分
|
|
308
308
|
const injectTag = m.source === 'owner-inject' ? `${YELLOW}[插话]${RST}` : '';
|
|
@@ -112,6 +112,7 @@ function assertAccessPolicyWrite(input, agent, policy) {
|
|
|
112
112
|
}
|
|
113
113
|
function clonePolicy(policy) {
|
|
114
114
|
return {
|
|
115
|
+
...(policy.contactAdmission ? { contactAdmission: policy.contactAdmission } : {}),
|
|
115
116
|
allowInternalContacts: policy.allowInternalContacts ?? true,
|
|
116
117
|
allowExternalContacts: policy.allowExternalContacts ?? false,
|
|
117
118
|
allowAllContacts: policy.allowAllContacts ?? false,
|
|
@@ -321,9 +321,9 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
|
|
|
321
321
|
? { ok: true, value: raw }
|
|
322
322
|
: { ok: false, reason: `Config field ${fieldPath} must be one of ${[...EFFORTS].join(', ')}; use unset for auto` };
|
|
323
323
|
case 'chatmode':
|
|
324
|
-
return raw === 'interactive' || raw === 'proactive'
|
|
324
|
+
return raw === 'interactive' || raw === 'proactive' || raw === 'paactive'
|
|
325
325
|
? { ok: true, value: raw }
|
|
326
|
-
: { ok: false, reason: `Config field ${fieldPath} must be interactive or
|
|
326
|
+
: { ok: false, reason: `Config field ${fieldPath} must be interactive, proactive, or paactive` };
|
|
327
327
|
case 'mention-mode':
|
|
328
328
|
return raw === 'disabled' || raw === 'mention-only' || raw === 'auto'
|
|
329
329
|
? { ok: true, value: raw }
|
|
@@ -965,6 +965,10 @@ export function write(target, value, sel, opts = {}) {
|
|
|
965
965
|
// 1. Schema 校验
|
|
966
966
|
if (!opts.skipValidate) {
|
|
967
967
|
validateOrThrow(schema, normalized, target);
|
|
968
|
+
if (target === ConfigTarget.Relation && normalized.chatmode?.private === 'paactive'
|
|
969
|
+
&& (!sel?.peerKey?.startsWith('aun#') || normalized.targetKind !== 'private')) {
|
|
970
|
+
throw new ConfigError('SCHEMA_INVALID', 'paactive only supports AUN private relations');
|
|
971
|
+
}
|
|
968
972
|
if (target === ConfigTarget.Defaults || target === ConfigTarget.Agent || target === ConfigTarget.Relation) {
|
|
969
973
|
const previous = atomicReadJson(file) ?? {};
|
|
970
974
|
const inherited = target === ConfigTarget.Defaults ? {}
|
|
@@ -1543,6 +1547,9 @@ export function normalizeDefaultsBehaviorCompat(defaults) {
|
|
|
1543
1547
|
if (!normalized.chatmode && (chatMode === 'interactive' || chatMode === 'proactive')) {
|
|
1544
1548
|
normalized.chatmode = { private: chatMode, group: chatMode, nothuman: chatMode };
|
|
1545
1549
|
}
|
|
1550
|
+
else if (!normalized.chatmode && chatMode === 'paactive') {
|
|
1551
|
+
normalized.chatmode = { private: 'paactive', group: 'proactive', nothuman: 'proactive' };
|
|
1552
|
+
}
|
|
1546
1553
|
if (normalized.mentionMode === undefined && (config.mentionMode === 'disabled' || config.mentionMode === 'mention-only' || config.mentionMode === 'auto')) {
|
|
1547
1554
|
normalized.mentionMode = config.mentionMode;
|
|
1548
1555
|
}
|
|
@@ -56,10 +56,11 @@ export function rolePermissionFieldPatterns(field) {
|
|
|
56
56
|
/** Shared RoleService/Menu validation backed by the published role schema. */
|
|
57
57
|
export function validateRoleConfig(value) {
|
|
58
58
|
const compatible = normalizeRoleEffortCompat(value);
|
|
59
|
-
const normalized = isRecord(compatible) && !Object.hasOwn(compatible, '$schema_version')
|
|
60
|
-
? { ...compatible, $schema_version: 1 }
|
|
61
|
-
: compatible;
|
|
62
59
|
const schema = loadSchema('role-config');
|
|
60
|
+
const normalized = isRecord(compatible)
|
|
61
|
+
&& (!Object.hasOwn(compatible, '$schema_version') || compatible.$schema_version === 1)
|
|
62
|
+
? { ...compatible, $schema_version: schema.version }
|
|
63
|
+
: compatible;
|
|
63
64
|
if (!schema.validate(normalized)) {
|
|
64
65
|
return (schema.validate.errors ?? []).map(error => ({
|
|
65
66
|
field: schemaErrorField(error),
|
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { atomicReadJson, atomicWriteJson } from '../utils/atomic-write.js';
|
|
4
4
|
import { agentRelationConfig, agentRelationsDir, agentRoleConfig, agentRolesIndex } from '../paths.js';
|
|
5
5
|
import { registerFile, unregisterFile } from '../core/file-integrity/store.js';
|
|
6
|
-
import { loadSchema } from './schema-registry.js';
|
|
6
|
+
import { currentVersion, loadSchema } from './schema-registry.js';
|
|
7
7
|
import { clearRoleStoreCache, getStoredRoleRegistry, isRoleName, readRoleStore, roleRegistryExists, } from './role-store.js';
|
|
8
8
|
import { expectedRoleRank, isManagementRole } from './builtin-roles.js';
|
|
9
9
|
import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
|
|
@@ -48,7 +48,7 @@ export function writeRoleRegistry(selfAid, value) {
|
|
|
48
48
|
export function writeRoleDefinition(selfAid, roleId, value) {
|
|
49
49
|
if (!isRoleName(roleId))
|
|
50
50
|
throw new RoleServiceError('INVALID_ROLE_ID', `Invalid role id: ${roleId}`);
|
|
51
|
-
const normalized = normalizeRoleEffortCompat({ ...value, rank: expectedRoleRank(roleId), $schema_version:
|
|
51
|
+
const normalized = normalizeRoleEffortCompat({ ...value, rank: expectedRoleRank(roleId), $schema_version: currentVersion('role-config') });
|
|
52
52
|
validateRoleDefinition(normalized);
|
|
53
53
|
const registry = readRoleRegistry(selfAid);
|
|
54
54
|
if (!registry.roles.includes(roleId)) {
|
|
@@ -157,7 +157,7 @@ export function listRoleDiagnostics(selfAid) {
|
|
|
157
157
|
return readRoleStore(selfAid).diagnostics;
|
|
158
158
|
}
|
|
159
159
|
function writeRoleDefinitionFile(selfAid, roleId, value) {
|
|
160
|
-
const normalized = normalizeRoleEffortCompat({ ...value, rank: expectedRoleRank(roleId), $schema_version:
|
|
160
|
+
const normalized = normalizeRoleEffortCompat({ ...value, rank: expectedRoleRank(roleId), $schema_version: currentVersion('role-config') });
|
|
161
161
|
validateRoleDefinition(normalized);
|
|
162
162
|
const file = agentRoleConfig(selfAid, roleId);
|
|
163
163
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
package/dist/config-store.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import fs from 'fs';
|
|
19
19
|
import path from 'path';
|
|
20
|
-
import { resolvePaths, agentDir, } from './paths.js';
|
|
20
|
+
import { resolvePaths, agentDir, agentPersonalDir, kitsTemplatesDir, SOUL_PERSONA_FILE, } from './paths.js';
|
|
21
21
|
import { atomicReadJson, atomicWriteJson } from './utils/atomic-write.js';
|
|
22
22
|
import { registerFile as registerFileIntegrity } from './core/file-integrity/store.js';
|
|
23
23
|
import { checkAgentDir, isValidAid } from './aun/aid/validation.js';
|
|
@@ -644,18 +644,21 @@ export function validateAgentConfig(cfg) {
|
|
|
644
644
|
// ── 合并 ───────────────────────────────────────────────────────────────
|
|
645
645
|
// ── 目录骨架 ───────────────────────────────────────────────────────────
|
|
646
646
|
/**
|
|
647
|
-
* 为某个 self-agent 创建文档约定的子目录骨架(personal/、identities/、venues/
|
|
647
|
+
* 为某个 self-agent 创建文档约定的子目录骨架(personal/、identities/、venues/ 等),
|
|
648
|
+
* 并保证 `personal/soul/` 存在且有机制指南与分文件骨架。
|
|
648
649
|
* 已存在则跳过,幂等可重复调用。
|
|
649
650
|
*
|
|
650
|
-
*
|
|
651
|
+
* 注:本函数不建 config.json——由 saveAgent(创建路径)
|
|
651
652
|
* 或 ConfigManager.ensureFile(设计目标)负责。
|
|
652
|
-
*
|
|
653
|
+
* soul 下的文件直接写盘,不走命令行:每轮都会注入 system prompt,
|
|
654
|
+
* 空文件不注入,所以骨架文件刻意保持 0 字节。
|
|
653
655
|
*/
|
|
654
656
|
export function ensureAgentDirSkeleton(aid) {
|
|
655
657
|
const root = agentDir(aid);
|
|
656
658
|
const subs = [
|
|
657
659
|
'personal',
|
|
658
660
|
'personal/memory',
|
|
661
|
+
'personal/soul',
|
|
659
662
|
'personal/skills',
|
|
660
663
|
'relations/contacts',
|
|
661
664
|
'relations/_observed',
|
|
@@ -672,6 +675,74 @@ export function ensureAgentDirSkeleton(aid) {
|
|
|
672
675
|
for (const sub of subs) {
|
|
673
676
|
fs.mkdirSync(path.join(root, sub), { recursive: true });
|
|
674
677
|
}
|
|
678
|
+
ensureSoulDir(aid);
|
|
679
|
+
}
|
|
680
|
+
/** soul 目录骨架:模板位于 `kits/templates/soul/`,文件名与目标完全一致。 */
|
|
681
|
+
export const SOUL_TEMPLATE_DIR = 'soul';
|
|
682
|
+
/** 只有指南有正文;分文件模板刻意为空(空文件不注入,等于还没写)。 */
|
|
683
|
+
const SOUL_TEMPLATE_FILES = ['00-GUIDE.md', '01-identity.md', '02-persona.md', '03-duties.md', '04-working-style.md'];
|
|
684
|
+
/** 旧版合集文件名(`$PERSONAL_DIR/persona.md`)。已废除:内容并进 soul 的「性格」分册。 */
|
|
685
|
+
const LEGACY_PERSONA_FILE = 'persona.md';
|
|
686
|
+
/** 并入时加的分隔标题;重复迁移不会重复追加(按它判断是否已并入)。 */
|
|
687
|
+
const LEGACY_MERGE_MARKER = '## 旧版合集(自动并入)';
|
|
688
|
+
function ensureSoulDir(aid) {
|
|
689
|
+
const personalDir = agentPersonalDir(aid);
|
|
690
|
+
const soulDir = path.join(personalDir, 'soul');
|
|
691
|
+
for (const name of SOUL_TEMPLATE_FILES) {
|
|
692
|
+
ensureSoulFile(soulDir, name);
|
|
693
|
+
}
|
|
694
|
+
mergeLegacyPersona(personalDir, soulDir);
|
|
695
|
+
}
|
|
696
|
+
function ensureSoulFile(soulDir, name) {
|
|
697
|
+
const target = path.join(soulDir, name);
|
|
698
|
+
if (fs.existsSync(target))
|
|
699
|
+
return;
|
|
700
|
+
let content = '';
|
|
701
|
+
try {
|
|
702
|
+
content = fs.readFileSync(path.join(kitsTemplatesDir(), SOUL_TEMPLATE_DIR, name), 'utf-8');
|
|
703
|
+
}
|
|
704
|
+
catch {
|
|
705
|
+
logger.warn(`[soul] 模板缺失:${path.join(kitsTemplatesDir(), SOUL_TEMPLATE_DIR, name)}`);
|
|
706
|
+
}
|
|
707
|
+
try {
|
|
708
|
+
fs.writeFileSync(target, content, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
709
|
+
}
|
|
710
|
+
catch (error) {
|
|
711
|
+
// wx 撞车(并发初始化)或权限失败都不该阻断目录骨架,只记日志。
|
|
712
|
+
logger.warn(`[soul] 写入 ${name} 失败 ${target}: ${error?.message || error}`);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* 废除旧合集:把 `$PERSONAL_DIR/persona.md` 的内容追加进 `soul/02-persona.md` 后删除原文件。
|
|
717
|
+
* 幂等:靠 LEGACY_MERGE_MARKER 判断是否已经并入过,不会重复追加。
|
|
718
|
+
*/
|
|
719
|
+
function mergeLegacyPersona(personalDir, soulDir) {
|
|
720
|
+
const legacy = path.join(personalDir, LEGACY_PERSONA_FILE);
|
|
721
|
+
if (!fs.existsSync(legacy))
|
|
722
|
+
return;
|
|
723
|
+
let legacyContent = '';
|
|
724
|
+
try {
|
|
725
|
+
legacyContent = fs.readFileSync(legacy, 'utf-8').trim();
|
|
726
|
+
}
|
|
727
|
+
catch (error) {
|
|
728
|
+
logger.warn(`[soul] 读取旧合集失败 ${legacy}: ${error?.message || error}`);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const target = path.join(soulDir, SOUL_PERSONA_FILE);
|
|
732
|
+
try {
|
|
733
|
+
if (legacyContent) {
|
|
734
|
+
const current = fs.existsSync(target) ? fs.readFileSync(target, 'utf-8') : '';
|
|
735
|
+
if (!current.includes(LEGACY_MERGE_MARKER)) {
|
|
736
|
+
const merged = `${current.trimEnd()}${current.trim() ? '\n\n' : ''}${LEGACY_MERGE_MARKER}\n\n${legacyContent}\n`;
|
|
737
|
+
fs.writeFileSync(target, merged, { encoding: 'utf8', mode: 0o600 });
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
fs.unlinkSync(legacy);
|
|
741
|
+
logger.info(`[soul] 已并入 ${legacy} → ${target} 并删除旧合集`);
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
logger.warn(`[soul] 并入旧合集失败 ${legacy}: ${error?.message || error}`);
|
|
745
|
+
}
|
|
675
746
|
}
|
|
676
747
|
// ── identities → relations 迁移 ──────────────────────────────────────
|
|
677
748
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { parseAgentWelcomeArgs, parseInitializationArgs, resolveAgentCreateMode, resolveInitializationPlan,
|
|
3
|
+
import { parseAgentWelcomeArgs, parseInitializationArgs, resolveAgentCreateMode, resolveInitializationPlan, } from '../cli/agent-create.js';
|
|
4
4
|
import { hasTrustedFullAccessDelegation, trustedExecutionIdentityInput } from './auth/agent-delegation.js';
|
|
5
5
|
import { authorizeFreshOperation as authorizeOperation, buildAuthSubject } from './auth/auth-gateway.js';
|
|
6
6
|
import { getDaemonOwners } from './ownership/owner-resolver.js';
|
|
@@ -55,15 +55,13 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
55
55
|
}
|
|
56
56
|
const targetAid = sub === 'list'
|
|
57
57
|
? undefined
|
|
58
|
-
: sub === '
|
|
58
|
+
: sub === 'welcome'
|
|
59
59
|
? taskAid
|
|
60
|
-
: sub === '
|
|
61
|
-
? taskAid
|
|
62
|
-
: sub === '
|
|
63
|
-
? (argv[2] && !argv[2].startsWith('--') ? argv[2] :
|
|
64
|
-
:
|
|
65
|
-
? (argv[2] && !argv[2].startsWith('--') ? argv[2] : undefined)
|
|
66
|
-
: (argv[2] && !argv[2].startsWith('--') ? argv[2] : undefined);
|
|
60
|
+
: sub === 'show'
|
|
61
|
+
? (argv[2] && !argv[2].startsWith('--') ? argv[2] : taskAid)
|
|
62
|
+
: sub === 'reload'
|
|
63
|
+
? (argv[2] && !argv[2].startsWith('--') ? argv[2] : undefined)
|
|
64
|
+
: (argv[2] && !argv[2].startsWith('--') ? argv[2] : undefined);
|
|
67
65
|
let createMode;
|
|
68
66
|
if (sub === 'new') {
|
|
69
67
|
try {
|
|
@@ -75,15 +73,14 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
75
73
|
}
|
|
76
74
|
const operation = sub === 'list' ? 'agent.list'
|
|
77
75
|
: sub === 'show' ? 'agent.show'
|
|
78
|
-
: sub === '
|
|
79
|
-
: sub === '
|
|
80
|
-
: sub === '
|
|
81
|
-
: sub === '
|
|
82
|
-
: sub === '
|
|
83
|
-
: sub === '
|
|
84
|
-
: sub === '
|
|
85
|
-
: sub === '
|
|
86
|
-
: sub === 'delete' ? 'agent.delete' : undefined;
|
|
76
|
+
: sub === 'welcome' ? 'agent.welcome'
|
|
77
|
+
: sub === 'rename' ? 'agent.rename'
|
|
78
|
+
: sub === 'initialize' || createMode === 'initialize' ? 'agent.initialize'
|
|
79
|
+
: sub === 'new' ? 'agent.create'
|
|
80
|
+
: sub === 'enable' ? 'agent.enable'
|
|
81
|
+
: sub === 'disable' ? 'agent.disable'
|
|
82
|
+
: sub === 'reload' ? 'agent.reload'
|
|
83
|
+
: sub === 'delete' ? 'agent.delete' : undefined;
|
|
87
84
|
if (!operation)
|
|
88
85
|
return fail('INVALID_ARGS', `unsupported managed agent command: ${sub}`);
|
|
89
86
|
if (sub === 'delete' && argv.includes('--purge') && !argv.includes('--confirm-purge')) {
|
|
@@ -112,7 +109,7 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
112
109
|
subject,
|
|
113
110
|
intent: {
|
|
114
111
|
operation,
|
|
115
|
-
scope: operation === 'agent.show' || operation === 'agent.
|
|
112
|
+
scope: operation === 'agent.show' || operation === 'agent.welcome' || operation === 'agent.rename'
|
|
116
113
|
? 'agent'
|
|
117
114
|
: operation === 'agent.reload' && targetAid
|
|
118
115
|
? 'agent'
|
|
@@ -188,46 +185,6 @@ export function registerAgentOperationExecutor({ ipcServer, sessionManager, agen
|
|
|
188
185
|
...(agent.initialization ? { initialization: agent.initialization } : {}),
|
|
189
186
|
} };
|
|
190
187
|
}
|
|
191
|
-
if (operation === 'agent.persona') {
|
|
192
|
-
const rawPersonaArgs = argv.slice(2);
|
|
193
|
-
const hasFormatSuffix = rawPersonaArgs.length >= 2
|
|
194
|
-
&& rawPersonaArgs.at(-2) === '--format'
|
|
195
|
-
&& rawPersonaArgs.at(-1) === 'json';
|
|
196
|
-
const personaArgs = hasFormatSuffix ? rawPersonaArgs.slice(0, -2) : rawPersonaArgs;
|
|
197
|
-
if (!hasFormatSuffix && rawPersonaArgs.includes('--format')) {
|
|
198
|
-
return fail('INVALID_ARGS', 'persona 仅支持末尾的 --format json');
|
|
199
|
-
}
|
|
200
|
-
const wantsShow = personaArgs.length === 1 && personaArgs[0] === 'show';
|
|
201
|
-
let text = personaArgs.length === 2 && personaArgs[0] === '--text'
|
|
202
|
-
? personaArgs[1]
|
|
203
|
-
: undefined;
|
|
204
|
-
const file = personaArgs.length === 2 && personaArgs[0] === '--file' ? personaArgs[1] : undefined;
|
|
205
|
-
if (file !== undefined) {
|
|
206
|
-
try {
|
|
207
|
-
text = readInitializationPersona(file, true, {
|
|
208
|
-
projectCwd: taskSession.projectPath, tempDir: delegation.grant.sessionRuntimeDir,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
return fail('INVALID_ARGS', error.message);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (!wantsShow && !(personaArgs.length === 2 && (personaArgs[0] === '--text' || personaArgs[0] === '--file'))) {
|
|
216
|
-
return fail('INVALID_ARGS', '用法: ec agent persona show | --text <text> | --file <path>');
|
|
217
|
-
}
|
|
218
|
-
if (text === undefined && !wantsShow)
|
|
219
|
-
return fail('INVALID_ARGS', 'persona --text 缺少参数');
|
|
220
|
-
const { agentPersona } = await import('../cli/agent.js');
|
|
221
|
-
const result = await agentPersona(taskAid, wantsShow ? { trustedLocal: true } : { text, trustedLocal: true });
|
|
222
|
-
if (!result.ok)
|
|
223
|
-
return fail(result.code ?? 'INTERNAL', result.error);
|
|
224
|
-
return { ok: true, result: {
|
|
225
|
-
ok: true,
|
|
226
|
-
aid: taskAid,
|
|
227
|
-
content: result.content,
|
|
228
|
-
...(result.saved ? { saved: true } : {}),
|
|
229
|
-
} };
|
|
230
|
-
}
|
|
231
188
|
if (operation === 'agent.welcome') {
|
|
232
189
|
if (subject.role !== 'owner' && !(welcomeArgs?.action === 'show' && subject.role === 'admin')) {
|
|
233
190
|
return fail('NOT_ALLOWED', 'welcome requires the current Agent Owner (admin may read)');
|
|
@@ -511,7 +511,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
511
511
|
};
|
|
512
512
|
return { hotLoad, resync };
|
|
513
513
|
}
|
|
514
|
-
// fastaun
|
|
514
|
+
// Audited fastaun start()/capture() only read and verify documents. All writes
|
|
515
515
|
// and notifications occur in execute(), which converts transport failures to
|
|
516
516
|
// an error task with its original operation_id. Only this audited artifact
|
|
517
517
|
// therefore proves that a raw ECONNRESET rejection preceded submission.
|
|
@@ -520,6 +520,7 @@ export function createAgentRuntimeOperations({ agentRegistry, agentLoader, sessi
|
|
|
520
520
|
const AUDITED_WORKFLOW_SHA256 = {
|
|
521
521
|
'0.5.28': 'cd736d1fcce0812013ba7d7c2148f86c8f3d3d2d39e451e52a0f9cc2a4d4fb51',
|
|
522
522
|
'0.5.29': '24ac11a456607019dbbf5e7d247f4632520d7bd70bf0e49d4efa36d2898e7648',
|
|
523
|
+
'0.5.30': '4f63c8116035ec509ffea67dd0a8fc3f0300a78ba89eefdd8c65af6d9da91517',
|
|
523
524
|
};
|
|
524
525
|
export function initializationBindPreflightFailure(error) {
|
|
525
526
|
if (!(error instanceof Error) || error.code !== 'ECONNRESET')
|
|
@@ -5,6 +5,20 @@ import crypto from 'node:crypto';
|
|
|
5
5
|
import { buildAuthorizationEventKey, buildToolLifecycleEventKey, normalizeToolCorrelation } from '../audit/event-key.js';
|
|
6
6
|
import { normalizeExecutionPermissionMode } from '../permission/mode.js';
|
|
7
7
|
import { normalizeToolErrorClassification } from '../permission/tool-error-code.js';
|
|
8
|
+
const auditProjectionKeys = new Set();
|
|
9
|
+
const MAX_AUDIT_PROJECTION_KEYS = 20_000;
|
|
10
|
+
function markAuditProjection(canonicalEventKey) {
|
|
11
|
+
const isMirror = auditProjectionKeys.has(canonicalEventKey);
|
|
12
|
+
if (!isMirror) {
|
|
13
|
+
auditProjectionKeys.add(canonicalEventKey);
|
|
14
|
+
if (auditProjectionKeys.size > MAX_AUDIT_PROJECTION_KEYS) {
|
|
15
|
+
const oldest = auditProjectionKeys.values().next().value;
|
|
16
|
+
if (oldest !== undefined)
|
|
17
|
+
auditProjectionKeys.delete(oldest);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return isMirror;
|
|
21
|
+
}
|
|
8
22
|
function permissionAuditDetails(input) {
|
|
9
23
|
return Object.fromEntries(Object.entries({
|
|
10
24
|
approvalRequestId: input.approvalRequestId,
|
|
@@ -156,6 +170,7 @@ export function auditToolPreflightDenial(input) {
|
|
|
156
170
|
// regex/string literals in an otherwise harmless diagnostic command.
|
|
157
171
|
matchedPath: input.matchedPath,
|
|
158
172
|
matchedRule: input.matchedRule,
|
|
173
|
+
parsedSegments: input.parsedSegments?.slice(0, 8).map(segment => segment.replace(/[\u0000-\u001f\u007f]/g, '').slice(0, 64)),
|
|
159
174
|
reason,
|
|
160
175
|
argsSummary: input.summary ? { summary: input.summary } : undefined,
|
|
161
176
|
sessionId: input.sessionId ?? 'unknown',
|
|
@@ -408,30 +423,43 @@ function buildAuditRecord(event) {
|
|
|
408
423
|
const sourceRequestId = event.requestId ?? ecwebRequestId;
|
|
409
424
|
const requestId = namespaceAuditRequestId(event.source, event.sessionId, sourceRequestId);
|
|
410
425
|
const correlationId = event.correlationId ?? event.callId ?? sourceRequestId;
|
|
426
|
+
const contextSessionId = knownAuditContextValue(event.sessionId);
|
|
427
|
+
const contextAgentAid = knownAuditContextValue(event.agentAid) ?? knownAuditContextValue(event.selfAid);
|
|
428
|
+
const contextMissing = event.source === 'agent-tool'
|
|
429
|
+
? [
|
|
430
|
+
...(!contextSessionId ? ['sessionId'] : []),
|
|
431
|
+
...(!contextAgentAid ? ['agentAid'] : []),
|
|
432
|
+
...(!knownAuditContextValue(event.permissionMode) ? ['permissionMode'] : []),
|
|
433
|
+
]
|
|
434
|
+
: [];
|
|
435
|
+
const eventKey = event.eventKey ?? (ecwebRequestId
|
|
436
|
+
? `ecweb:${crypto.createHash('sha256').update(JSON.stringify([
|
|
437
|
+
ecwebRequestId, event.targetAgentAid ?? event.selfAid, event.operation,
|
|
438
|
+
])).digest('hex').slice(0, 20)}`
|
|
439
|
+
: buildAuthorizationEventKey({
|
|
440
|
+
sessionId: event.sessionId,
|
|
441
|
+
callId: event.callId,
|
|
442
|
+
correlationId,
|
|
443
|
+
requestId: sourceRequestId,
|
|
444
|
+
operation: event.operation,
|
|
445
|
+
}));
|
|
446
|
+
const canonicalEventKey = `${eventKey}:decision:${event.decision}`;
|
|
411
447
|
return {
|
|
412
448
|
type: 'authorization:audit',
|
|
413
449
|
ts: event.ts,
|
|
414
|
-
eventKey
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
])).digest('hex').slice(0, 20)}`
|
|
418
|
-
: buildAuthorizationEventKey({
|
|
419
|
-
sessionId: event.sessionId,
|
|
420
|
-
callId: event.callId,
|
|
421
|
-
correlationId,
|
|
422
|
-
requestId: sourceRequestId,
|
|
423
|
-
operation: event.operation,
|
|
424
|
-
})),
|
|
450
|
+
eventKey,
|
|
451
|
+
canonicalEventKey,
|
|
452
|
+
isMirror: markAuditProjection(canonicalEventKey),
|
|
425
453
|
eventPhase: event.eventPhase,
|
|
426
454
|
callId: event.callId,
|
|
427
455
|
correlationId,
|
|
428
456
|
requestId,
|
|
429
457
|
sourceRequestId,
|
|
430
458
|
sessionId: event.sessionId,
|
|
431
|
-
...(!
|
|
459
|
+
...(!contextSessionId ? {
|
|
432
460
|
sessionScope: event.source === 'ecweb' ? 'not_applicable' : 'unknown',
|
|
433
461
|
} : {}),
|
|
434
|
-
agentAid: redactIdentifier(event.agentAid ?? event.selfAid),
|
|
462
|
+
agentAid: redactIdentifier(contextAgentAid ?? event.agentAid ?? event.selfAid),
|
|
435
463
|
agentName: resolveAgentName(event) ?? 'unknown',
|
|
436
464
|
permissionMode: normalizeAuditPermissionMode(event.permissionMode),
|
|
437
465
|
toolName: event.toolName,
|
|
@@ -440,10 +468,12 @@ function buildAuditRecord(event) {
|
|
|
440
468
|
errorDetailCode: classification?.errorDetailCode,
|
|
441
469
|
classificationMissing: classification?.classificationMissing || event.classificationMissing,
|
|
442
470
|
classificationConflict: classification?.classificationConflict || event.classificationConflict,
|
|
471
|
+
...(contextMissing.length > 0 ? { contextMissing } : {}),
|
|
443
472
|
policyCode: event.policyCode ?? event.code,
|
|
444
473
|
protectionClass: event.protectionClass,
|
|
445
474
|
matchedPath: event.matchedPath,
|
|
446
475
|
matchedRule: event.matchedRule,
|
|
476
|
+
parsedSegments: event.parsedSegments,
|
|
447
477
|
parseFailure: sanitizeParseFailure(event.parseFailure),
|
|
448
478
|
commandIntent: event.commandIntent,
|
|
449
479
|
canonicalizationStage: event.canonicalizationStage,
|
|
@@ -549,8 +579,12 @@ function resolveAgentName(event) {
|
|
|
549
579
|
function isUnknownAgentLabel(value) {
|
|
550
580
|
return value === 'unknown' || value === '<unknown>' || value === '<none>' || value === 'undefined' || value === 'null';
|
|
551
581
|
}
|
|
582
|
+
function knownAuditContextValue(value) {
|
|
583
|
+
const normalized = value?.trim();
|
|
584
|
+
return normalized && !isUnknownAgentLabel(normalized.toLowerCase()) ? normalized : undefined;
|
|
585
|
+
}
|
|
552
586
|
function normalizeAuditPermissionMode(value) {
|
|
553
|
-
if (!value
|
|
587
|
+
if (!knownAuditContextValue(value))
|
|
554
588
|
return value;
|
|
555
589
|
return normalizeExecutionPermissionMode(value);
|
|
556
590
|
}
|
|
@@ -597,8 +631,11 @@ function logAuditEvent(record) {
|
|
|
597
631
|
record.callId ? `call=${record.callId}` : null,
|
|
598
632
|
record.correlationId ? `correlation=${record.correlationId}` : null,
|
|
599
633
|
record.eventKey ? `eventKey=${record.eventKey}` : null,
|
|
634
|
+
record.canonicalEventKey ? `canonicalEventKey=${record.canonicalEventKey}` : null,
|
|
635
|
+
record.isMirror !== undefined ? `isMirror=${record.isMirror}` : null,
|
|
600
636
|
record.eventPhase ? `eventPhase=${record.eventPhase}` : null,
|
|
601
637
|
record.sessionScope ? `sessionScope=${record.sessionScope}` : null,
|
|
638
|
+
record.contextMissing?.length ? `contextMissing=${record.contextMissing.join(',')}` : null,
|
|
602
639
|
record.sessionId ? `session=${record.sessionId}` : null,
|
|
603
640
|
record.agentName ? `agentName=${JSON.stringify(record.agentName)}` : null,
|
|
604
641
|
record.agentAid ? `agent=${record.agentAid}` : null,
|
|
@@ -613,6 +650,7 @@ function logAuditEvent(record) {
|
|
|
613
650
|
record.protectionClass ? `protectionClass=${record.protectionClass}` : null,
|
|
614
651
|
record.matchedPath ? `matchedPath=${JSON.stringify(record.matchedPath)}` : null,
|
|
615
652
|
record.matchedRule ? `matchedRule=${JSON.stringify(record.matchedRule)}` : null,
|
|
653
|
+
record.parsedSegments ? `parsedSegments=${JSON.stringify(record.parsedSegments)}` : null,
|
|
616
654
|
record.parseFailure ? `parseFailure=${JSON.stringify(record.parseFailure)}` : null,
|
|
617
655
|
record.commandIntent ? `commandIntent=${record.commandIntent}` : null,
|
|
618
656
|
record.canonicalizationStage ? `canonicalizationStage=${record.canonicalizationStage}` : null,
|
|
@@ -292,17 +292,6 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
|
|
|
292
292
|
&& !hasDaemonOwnerRole(ctx)) {
|
|
293
293
|
return denyDecision(ctx, 'NOT_ALLOWED', `${operation} may only target the current Agent from a managed Agent task.`, operation, intent.scope, opMeta.dangerous, undefined, 'TARGET_SELF_ONLY');
|
|
294
294
|
}
|
|
295
|
-
if (operation === 'agent.persona' && isCurrentAgentTarget(ctx)
|
|
296
|
-
&& (role === 'owner' || (ctx.fromControlChannel && hasDaemonOwnerRole(ctx)))) {
|
|
297
|
-
return {
|
|
298
|
-
allow: true,
|
|
299
|
-
operation,
|
|
300
|
-
scope: intent.scope,
|
|
301
|
-
role,
|
|
302
|
-
dangerous: opMeta.dangerous,
|
|
303
|
-
matchedRule: role === 'owner' ? 'agent-owner-persona' : 'daemon-owner-persona',
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
295
|
if (operation === 'agent.welcome') {
|
|
307
296
|
if (!isCurrentAgentTarget(ctx) || ctx.chatType !== 'private'
|
|
308
297
|
|| (role !== 'owner' && !(role === 'admin' && intent.args.action === 'show'))) {
|