evolcore 0.0.41-test.0 → 0.0.41-test.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +88 -49
- package/dist/agents/claude-runner.js +177 -92
- package/dist/agents/codex-runner.js +146 -71
- package/dist/agents/ecagent-runner.js +1 -1
- package/dist/agents/gemini-runner.js +1 -1
- package/dist/aun/aid/agentmd.js +98 -11
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +26 -2
- package/dist/aun/aid/identity.js +91 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/managed-operation.js +1 -1
- package/dist/aun/aid/ownership-operation.js +23 -22
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -21
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/menu/client.js +27 -0
- package/dist/aun/msg/managed-operation.js +68 -7
- package/dist/aun/msg/p2p.js +8 -8
- package/dist/aun/service-proxy.js +53 -12
- package/dist/channels/aun.js +633 -32
- package/dist/channels/daemon.js +15 -1
- package/dist/cli/agent-command.js +5 -2
- package/dist/cli/agent-create.js +991 -233
- package/dist/cli/agent.js +49 -10
- package/dist/cli/aid-bind-command.js +48 -19
- package/dist/cli/aun-commands.js +48 -36
- package/dist/cli/daemon-commands.js +679 -697
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +72 -5
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +17 -1
- package/dist/cli/model.js +40 -40
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/role.js +85 -0
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/access-policy.js +7 -2
- package/dist/config/boot-log.js +39 -1
- package/dist/config/config-field-policy.js +17 -39
- package/dist/config/config-manager.js +183 -44
- package/dist/config/config-operation-service.js +5 -19
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +88 -594
- package/dist/config/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +15 -12
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +11 -1
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +1000 -25
- package/dist/config-store.js +89 -4
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +4 -1
- package/dist/core/agent-application-service.js +60 -11
- package/dist/core/agent-create-status.js +203 -0
- package/dist/core/agent-creation-claim.js +177 -0
- package/dist/core/agent-ipc-registration.js +39 -18
- package/dist/core/agent-runtime.js +194 -24
- package/dist/core/auth/agent-delegation.js +6 -3
- package/dist/core/auth/auth-gateway.js +67 -2
- package/dist/core/auth/authorization-audit.js +58 -11
- package/dist/core/auth/delegation-authorization.js +5 -2
- package/dist/core/auth/operation-authorizer.js +43 -6
- package/dist/core/auth/operation-catalog.js +45 -7
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +260 -21
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +8 -3
- package/dist/core/command/command-handler.js +112 -154
- package/dist/core/command/connect-menu.js +11 -3
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +10 -6
- package/dist/core/command/menu-handler.js +106 -73
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/role-menu.js +147 -30
- package/dist/core/command/slash-handler.js +125 -255
- package/dist/core/daemon-control.js +26 -27
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +7 -5
- package/dist/core/evolagent.js +10 -8
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +40 -24
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +96 -1
- package/dist/core/memory/consolidation-trigger.js +208 -191
- package/dist/core/memory/consolidation.js +333 -35
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +55 -45
- package/dist/core/message/aun-ipc-sender.js +81 -69
- package/dist/core/message/im-renderer.js +25 -4
- package/dist/core/message/message-admission.js +89 -4
- package/dist/core/message/message-bridge.js +66 -21
- package/dist/core/message/response-engine.js +108 -35
- package/dist/core/model/catalog-service.js +5 -3
- package/dist/core/model/config-scope.js +29 -71
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +30 -41
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +772 -158
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +62 -6
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +21 -46
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +1 -1
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +20 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +43 -8
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/init-menu.js +32 -0
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +93 -19
- package/dist/ipc.js +247 -29
- package/dist/paths.js +7 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +484 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/trigger/authorization.js +27 -17
- package/dist/trigger/feedback.js +2 -3
- package/dist/trigger/ipc-service.js +105 -78
- package/dist/trigger/local-files.js +2 -1
- package/dist/trigger/manager.js +5 -3
- package/dist/trigger/scheduler.js +88 -6
- package/dist/utils/atomic-write.js +28 -0
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +26 -2
- package/dist/utils/logger.js +92 -6
- package/dist/utils/package-version-info.js +4 -2
- package/dist/utils/welcome.js +1 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/aun/SDK.md +4 -1
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +1 -0
- package/kits/docs/evolcore/agent.md +8 -1
- package/kits/docs/evolcore/aid.md +67 -17
- package/kits/docs/evolcore/config.md +28 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/fs.md +11 -0
- package/kits/docs/evolcore/group.md +1 -1
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +4 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +4 -7
- package/kits/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +8 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +277 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/skills/thread-ops/SKILL.md +5 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/memory.md +4 -4
- package/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +7 -3
- package/dist/core/message/create-status.js +0 -96
|
@@ -25,11 +25,13 @@ export function parseJsonObjectArgument(raw, optionName = '--payload') {
|
|
|
25
25
|
return parsed;
|
|
26
26
|
}
|
|
27
27
|
export function buildCanonicalEvolcoreExecutionSpec(input) {
|
|
28
|
+
const argv = normalizeEvolcoreCommandArgv(input.argv);
|
|
29
|
+
canonicalizeLocalFilePathFlags(argv);
|
|
28
30
|
const spec = {
|
|
29
31
|
version: 1,
|
|
30
32
|
dialect: input.dialect,
|
|
31
33
|
wrapper: input.wrapper,
|
|
32
|
-
argv
|
|
34
|
+
argv,
|
|
33
35
|
};
|
|
34
36
|
if (input.cwd !== undefined)
|
|
35
37
|
spec.cwd = input.cwd;
|
|
@@ -335,7 +337,7 @@ const EVOLCORE_SUBCOMMANDS = new Set([
|
|
|
335
337
|
'fs', 'gateway', 'group', 'handoff', 'init', 'link-rules', 'logs', 'menu-client',
|
|
336
338
|
'mode', 'model', 'msg', 'mv', 'net', 'queue', 'response', 'restart',
|
|
337
339
|
'restart-monitor', 'rpc', 'start', 'stats', 'status', 'stop', 'storage', 'task',
|
|
338
|
-
'trigger', 'version', 'watch', 'session',
|
|
340
|
+
'trigger', 'proxy', 'version', 'watch', 'session',
|
|
339
341
|
]);
|
|
340
342
|
// Development/install entrypoints that are part of this repository's CLI.
|
|
341
343
|
// Only these exact relative paths are canonicalized; arbitrary Node scripts
|
|
@@ -914,6 +916,27 @@ function canonicalizeHandoffText(argv) {
|
|
|
914
916
|
argv[index] = decodeEvolcoreInlineText(argv[index]);
|
|
915
917
|
}
|
|
916
918
|
}
|
|
919
|
+
const LOCAL_FILE_VALUE_FLAGS = new Set(['--file', '--text-from-file', '--payload-file']);
|
|
920
|
+
function normalizeWindowsFilePath(value) {
|
|
921
|
+
if (process.platform !== 'win32' || !/^[A-Za-z]:[\\/]/u.test(value))
|
|
922
|
+
return value;
|
|
923
|
+
return value.replace(/\\{2,}/gu, '\\').replace(/\/{2,}/gu, '/');
|
|
924
|
+
}
|
|
925
|
+
function canonicalizeLocalFilePathFlags(argv) {
|
|
926
|
+
for (let index = 2; index < argv.length; index++) {
|
|
927
|
+
if (argv[index] === '--')
|
|
928
|
+
break;
|
|
929
|
+
const inline = argv[index].match(/^(--(?:file|text-from-file|payload-file))=(.*)$/u);
|
|
930
|
+
if (inline) {
|
|
931
|
+
argv[index] = `${inline[1]}=${normalizeWindowsFilePath(inline[2])}`;
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
if (!LOCAL_FILE_VALUE_FLAGS.has(argv[index]) || argv[index + 1] === undefined)
|
|
935
|
+
continue;
|
|
936
|
+
argv[index + 1] = normalizeWindowsFilePath(argv[index + 1]);
|
|
937
|
+
index++;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
917
940
|
/**
|
|
918
941
|
* Convert an EC invocation to the one argv representation shared by approval,
|
|
919
942
|
* delegation hashing, IPC, and command execution. Shell syntax is already
|
|
@@ -926,6 +949,7 @@ export function canonicalizeEvolcoreCommandArgv(argv) {
|
|
|
926
949
|
if (canonical[0] !== 'ec')
|
|
927
950
|
return canonical;
|
|
928
951
|
const result = [...canonical];
|
|
952
|
+
canonicalizeLocalFilePathFlags(result);
|
|
929
953
|
const command = result[1];
|
|
930
954
|
const subcommand = result[2];
|
|
931
955
|
if (command === 'agent') {
|
|
@@ -1147,6 +1171,19 @@ export function parseCodexCarrierCommand(carrier, options = {}) {
|
|
|
1147
1171
|
}
|
|
1148
1172
|
: parsed;
|
|
1149
1173
|
}
|
|
1174
|
+
export function literalShellParseRemedy(failure) {
|
|
1175
|
+
if (failure.issue === 'shell-composition') {
|
|
1176
|
+
return '一次调用只执行一条完整命令;查询和操作请拆成独立工具调用,不要拼接管道、重定向、分号或子表达式。';
|
|
1177
|
+
}
|
|
1178
|
+
if (failure.dialect !== 'powershell')
|
|
1179
|
+
return undefined;
|
|
1180
|
+
if (['invalid-quote', 'unsafe-expansion', 'unsupported-escape', 'structural-newline'].includes(failure.issue)) {
|
|
1181
|
+
return 'PowerShell 把 U+2018/U+2019/U+201A/U+201B 也当作单引号定界符。'
|
|
1182
|
+
+ '纯文字用半角单引号包住,内部单引号定界符需双写;不要使用 Bash 的 ANSI-C quoting。'
|
|
1183
|
+
+ '复杂正文可写入当前会话 $env:TMPDIR,再通过支持 --text-from-file 的命令读取;不要替换原文字符。';
|
|
1184
|
+
}
|
|
1185
|
+
return undefined;
|
|
1186
|
+
}
|
|
1150
1187
|
function parseFailure(issue, input, offset, tokenIndex, dialect) {
|
|
1151
1188
|
return {
|
|
1152
1189
|
ok: false,
|
|
@@ -1941,7 +1978,7 @@ export function parseCodexToolCommand(input, options = {}) {
|
|
|
1941
1978
|
if (stringCarrier) {
|
|
1942
1979
|
return parseCodexCarrierCommand(stringCarrier, { allowManagedTmpDir: true, ...options });
|
|
1943
1980
|
}
|
|
1944
|
-
const outer = parseLiteralShellCommand(command, { allowManagedTmpDir: true });
|
|
1981
|
+
const outer = parseLiteralShellCommand(command, { allowManagedTmpDir: true, ...options });
|
|
1945
1982
|
if (outer.ok) {
|
|
1946
1983
|
const carrier = resolveCodexShellCarrierArgv(outer.argv);
|
|
1947
1984
|
if (carrier !== undefined) {
|
|
@@ -2545,6 +2582,10 @@ export function parseCodexExecToolCommand(input) {
|
|
|
2545
2582
|
function classifyCompositeProactiveSend(commandText, options) {
|
|
2546
2583
|
const classified = classifyEvolcoreShellCommand(commandText, options);
|
|
2547
2584
|
if (classified.kind === 'cd-prefixed' || classified.kind === 'bounded-output') {
|
|
2585
|
+
// 带尾部命令(suffixArgv)的结构不允许作为 proactive send 放行:
|
|
2586
|
+
// 尾部段可以是任意 echo/pwd,拼接意图不可证。
|
|
2587
|
+
if (classified.command.suffixArgv?.length)
|
|
2588
|
+
return null;
|
|
2548
2589
|
const argv = normalizeEvolcoreCommandArgv(classified.command.argv);
|
|
2549
2590
|
if (argv[0] === 'ec')
|
|
2550
2591
|
return { ok: true, argv };
|
|
@@ -3122,9 +3163,12 @@ const SEND_CONTENT_VALUE_FLAGS = new Set([
|
|
|
3122
3163
|
'--payload', '--title', '--description', '--text', '--transcript', '--handoff-context',
|
|
3123
3164
|
]);
|
|
3124
3165
|
const TRIGGER_CONTENT_VALUE_FLAGS = new Set(['--prompt']);
|
|
3166
|
+
const THREAD_SUMMARY_CONTROL_FLAGS = new Set([
|
|
3167
|
+
'--if-rev', '--name', '--self', '--as-session', '--format', '--json', '--help', '-h',
|
|
3168
|
+
]);
|
|
3125
3169
|
/**
|
|
3126
|
-
* A shell-escaped `$TMPDIR` in a msg/group text body
|
|
3127
|
-
* ordinary content, not a path reference. Keep every other unresolved
|
|
3170
|
+
* A shell-escaped `$TMPDIR` in a msg/group text body, trigger prompt, or thread
|
|
3171
|
+
* summary is ordinary content, not a path reference. Keep every other unresolved
|
|
3128
3172
|
* occurrence fail-closed so file and control arguments cannot bypass
|
|
3129
3173
|
* managed-path checks.
|
|
3130
3174
|
*/
|
|
@@ -3138,9 +3182,21 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
|
|
|
3138
3182
|
&& (argv[1] === 'msg' || argv[1] === 'group')
|
|
3139
3183
|
&& argv[2] === 'send';
|
|
3140
3184
|
const isTriggerCommand = argv[0] === 'ec' && argv[1] === 'trigger';
|
|
3141
|
-
|
|
3185
|
+
const isThreadSummarySetCommand = argv[0] === 'ec' && argv[1] === 'thread'
|
|
3186
|
+
&& argv[2] === 'summary' && argv[3] === 'set';
|
|
3187
|
+
if (!isSendCommand && !isTriggerCommand && !isThreadSummarySetCommand)
|
|
3142
3188
|
return true;
|
|
3143
3189
|
const textIndexes = new Set();
|
|
3190
|
+
if (isThreadSummarySetCommand) {
|
|
3191
|
+
// Match runThreadCommand's contentArgs filtering: the ref, known flags,
|
|
3192
|
+
// and their following arguments are control data rather than summary text.
|
|
3193
|
+
for (let index = 5; index < argv.length; index++) {
|
|
3194
|
+
if (THREAD_SUMMARY_CONTROL_FLAGS.has(argv[index])
|
|
3195
|
+
|| index > 5 && THREAD_SUMMARY_CONTROL_FLAGS.has(argv[index - 1]))
|
|
3196
|
+
continue;
|
|
3197
|
+
textIndexes.add(index);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3144
3200
|
if (isTriggerCommand) {
|
|
3145
3201
|
for (let index = 2; index < argv.length; index++) {
|
|
3146
3202
|
if (!TRIGGER_CONTENT_VALUE_FLAGS.has(argv[index]))
|
|
@@ -2,6 +2,7 @@ export * from './tool-policy.js';
|
|
|
2
2
|
export * from './ec-command-parser.js';
|
|
3
3
|
export * from './readonly-shell-query.js';
|
|
4
4
|
export * from './approval-gateway.js';
|
|
5
|
+
export * from './permission-result.js';
|
|
5
6
|
export * from './mode.js';
|
|
6
7
|
// Tool summaries live in utils; keep the historical permission import path compatible.
|
|
7
8
|
export { summarizeToolInput } from '../../utils/tool-summary.js';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const failureMessages = {
|
|
2
|
+
no_requester_approver: '无法发起审批:未能确定作为审批人的申请人;操作未执行。',
|
|
3
|
+
no_agent_owner_configured: '无法发起审批:未能确定 Agent owner 审批人;操作未执行。',
|
|
4
|
+
no_agent_manager_configured: '无法发起审批:未配置符合条件的 Agent 管理审批人;操作未执行。',
|
|
5
|
+
no_aun_owner_available: '无法发起审批:未找到符合条件的 owner 审批人;操作未执行。',
|
|
6
|
+
approver_candidates_unavailable: '无法发起审批:审批人候选身份查询失败;操作未执行。',
|
|
7
|
+
approval_identity_missing: '无法发起审批:申请人身份缺失;操作未执行。',
|
|
8
|
+
actor_operator_mismatch: '无法发起审批:申请人身份与审批上下文不一致;操作未执行。',
|
|
9
|
+
actor_channel_mismatch: '无法发起审批:申请人的认证渠道与当前审批渠道不一致;操作未执行。',
|
|
10
|
+
owner_approval_channel_unavailable: '无法发起审批:owner 审批接收渠道不可用;操作未执行。',
|
|
11
|
+
approval_gateway_unavailable: '无法发起审批:审批网关未初始化;操作未执行。',
|
|
12
|
+
approval_prompt_unavailable: '无法发起审批:审批消息发送回调不可用;操作未执行。',
|
|
13
|
+
approval_router_unavailable: '无法发起审批:审批交互路由不可用;操作未执行。',
|
|
14
|
+
approval_routing_context_unavailable: '无法发起审批:审批路由上下文缺失;操作未执行。',
|
|
15
|
+
channel_disconnected: '审批渠道连接已断开;操作未执行。',
|
|
16
|
+
delivery_failed: '审批请求投递失败:接收渠道未接受请求;操作未执行。',
|
|
17
|
+
expired: '审批已超时;操作未执行。',
|
|
18
|
+
timeout: '审批已超时;操作未执行。',
|
|
19
|
+
cancelled: '审批已取消;操作未执行。',
|
|
20
|
+
user_cancelled: '审批交互已取消;操作未执行。',
|
|
21
|
+
new_message: '收到新消息,原审批已取消;操作未执行。',
|
|
22
|
+
interrupted: '会话已中断,审批已终止;操作未执行。',
|
|
23
|
+
task_error: '任务发生错误,审批已终止;操作未执行。',
|
|
24
|
+
task_completed: '任务已结束,待处理审批已取消;操作未执行。',
|
|
25
|
+
tool_cancelled: '工具调用已取消,审批终止;操作未执行。',
|
|
26
|
+
daemon_restart: '宿主重启,审批已终止;操作未执行。',
|
|
27
|
+
permission_mode_denied: '当前权限策略禁止发起交互审批;操作未执行。',
|
|
28
|
+
ownership_authorization_failed: '当前会话的所有权授权校验失败;操作未执行。',
|
|
29
|
+
challenge_not_grantable: '当前权限策略不允许批准此请求;操作未执行。',
|
|
30
|
+
approver_role_requirement_invalid: '审批人角色要求无效;操作未执行。',
|
|
31
|
+
approver_identity_incomplete: '审批人身份信息不完整;操作未执行。',
|
|
32
|
+
approver_reauthorization_unavailable: '审批人身份重新校验服务不可用;操作未执行。',
|
|
33
|
+
approver_reauthorization_failed: '审批人身份重新校验发生错误;操作未执行。',
|
|
34
|
+
approver_identity_mismatch: '审批人身份校验不匹配;操作未执行。',
|
|
35
|
+
approver_identity_changed: '审批人身份已变更,本次审批失效;操作未执行。',
|
|
36
|
+
approver_identity_untrusted: '审批人身份未通过可信校验;操作未执行。',
|
|
37
|
+
principal_mapping_removed: '审批人的身份映射已移除;操作未执行。',
|
|
38
|
+
principal_mapping_conflict: '审批人的身份映射存在冲突;操作未执行。',
|
|
39
|
+
principal_mapping_changed: '审批人的身份映射已变更;操作未执行。',
|
|
40
|
+
approver_role_changed: '审批人已不具备本次请求要求的角色;操作未执行。',
|
|
41
|
+
approver_revoked: '审批人的授权资格已被撤销;操作未执行。',
|
|
42
|
+
approver_not_host_owner: '审批人不具备本次请求要求的宿主所有者资格;操作未执行。',
|
|
43
|
+
origin_authorization_changed: '申请人的原始授权已变更,本次审批失效;操作未执行。',
|
|
44
|
+
};
|
|
45
|
+
const policyFailures = new Set([
|
|
46
|
+
'permission_mode_denied', 'ownership_authorization_failed', 'challenge_not_grantable',
|
|
47
|
+
'actor_operator_mismatch', 'actor_channel_mismatch', 'approver_role_requirement_invalid',
|
|
48
|
+
'approver_identity_incomplete', 'approver_identity_mismatch', 'approver_identity_changed',
|
|
49
|
+
'approver_identity_untrusted', 'principal_mapping_removed', 'principal_mapping_conflict',
|
|
50
|
+
'principal_mapping_changed', 'approver_role_changed', 'approver_revoked',
|
|
51
|
+
'approver_not_host_owner', 'origin_authorization_changed',
|
|
52
|
+
]);
|
|
53
|
+
export function permissionFailureResult(requestId, failure, approver = {}, policyCode) {
|
|
54
|
+
const known = Object.hasOwn(failureMessages, failure);
|
|
55
|
+
return {
|
|
56
|
+
decision: 'deny',
|
|
57
|
+
decisionSource: policyFailures.has(failure) ? 'policy' : 'infrastructure',
|
|
58
|
+
requestId,
|
|
59
|
+
policyCode: policyCode ?? (known ? `approval_${failure}` : 'approval_failure_unknown'),
|
|
60
|
+
errorDetailCode: known ? failure.toUpperCase() : 'APPROVAL_FAILURE_UNKNOWN',
|
|
61
|
+
reason: known ? failureMessages[failure] : '审批失败,具体原因未知;操作未执行。',
|
|
62
|
+
approverOperatorId: approver.approverOperatorId,
|
|
63
|
+
approverChannelKey: approver.approverChannelKey,
|
|
64
|
+
approverPrincipalId: approver.approverPrincipalId,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function permissionApprovalResult(requestId, decision, approver = {}) {
|
|
68
|
+
return {
|
|
69
|
+
decision,
|
|
70
|
+
decisionSource: 'approval',
|
|
71
|
+
requestId,
|
|
72
|
+
reason: decision === 'deny' ? '审批人明确拒绝了本次操作;操作未执行。' : '审批人已批准本次操作。',
|
|
73
|
+
...(decision === 'deny' ? { policyCode: 'user_approval_denied', errorDetailCode: 'USER_APPROVAL_DENIED' } : {}),
|
|
74
|
+
approverOperatorId: approver.approverOperatorId,
|
|
75
|
+
approverChannelKey: approver.approverChannelKey,
|
|
76
|
+
approverPrincipalId: approver.approverPrincipalId,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -115,6 +115,22 @@ export function isSandboxInitializationFailure(error, stderr = []) {
|
|
|
115
115
|
|| /(?:^|\n)\s*bwrap:\s*(?:can't|cannot) create (?:file|directory) at [^\n]+: read-only file system/.test(text)
|
|
116
116
|
|| /(?:^|\n)\s*bwrap:\s*(?:can't|cannot) mkdir parents for [^\n]+: read-only file system/.test(text);
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Recognize failures from a task runner's nested sandbox. The outer EvolCore
|
|
120
|
+
* H-class guard is already running when this is used, so generic outer guard
|
|
121
|
+
* launch failures must not be treated as safe fallback candidates.
|
|
122
|
+
*/
|
|
123
|
+
export function isNestedSandboxInitializationFailure(error, stderr = []) {
|
|
124
|
+
const text = [error instanceof Error ? error.message : String(error ?? ''), ...stderr]
|
|
125
|
+
.join('\n')
|
|
126
|
+
.toLowerCase();
|
|
127
|
+
return text.includes(CODEX_SANDBOX_USER_NAMESPACE_UNAVAILABLE)
|
|
128
|
+
|| text.includes(CODEX_SANDBOX_USER_NAMESPACE_DISABLED_BY_APPARMOR)
|
|
129
|
+
|| /fs sandbox helper failed/.test(text)
|
|
130
|
+
|| /failed to initialize session[\s\S]*sandbox/.test(text)
|
|
131
|
+
|| /(?:apply-seccomp|seccomp)[\s\S]*(?:uid_map|gid_map|operation not permitted|permission denied)/.test(text)
|
|
132
|
+
|| /(?:uid_map|gid_map)[\s\S]*(?:operation not permitted|permission denied)/.test(text);
|
|
133
|
+
}
|
|
118
134
|
export function isCodexSandboxUserNamespaceFailure(error) {
|
|
119
135
|
const record = error && typeof error === 'object'
|
|
120
136
|
? error
|
|
@@ -318,7 +334,8 @@ export function formatCodexSandboxAvailability(check) {
|
|
|
318
334
|
return `Codex Linux sandbox check not applicable on ${check.platform}`;
|
|
319
335
|
if (check.status === 'missing') {
|
|
320
336
|
return 'Codex Linux sandbox is unavailable: bubblewrap (bwrap) was not found; '
|
|
321
|
-
+ 'install or provision the Codex sandbox runtime.
|
|
337
|
+
+ 'install or provision the Codex nested sandbox runtime. Managed Linux sessions may retry '
|
|
338
|
+
+ 'behind the EvolCore H-class guard; direct app-server callers remain fail-closed.';
|
|
322
339
|
}
|
|
323
340
|
const apparmor = check.apparmorRestrictsUnprivilegedUserns === true
|
|
324
341
|
? ' AppArmor restricts unprivileged user namespaces on this host; the probe below confirms whether the active profile permits Codex.'
|
|
@@ -6,7 +6,7 @@ import { randomUUID } from 'crypto';
|
|
|
6
6
|
import { logger } from '../../utils/logger.js';
|
|
7
7
|
import { resolveRoot } from '../../paths.js';
|
|
8
8
|
import { containsHClassReference, containsAgentScopeReference, containsLClassReference, checkProtectedPathAccess, getExistingHClassMaskTargets, hClassGrantIncludesProtectedPath, isHClassPath, isSameOrDescendant, isLClassPath, lClassGrantIncludesProtectedPath, resolveProtectedCandidate, resolveProtectedCandidateWithoutFinalSymlink, } from './protected-paths.js';
|
|
9
|
-
import { classifyEvolcoreShellCommand, canonicalizeEvolcoreCommandArgv, hasCodexCmdCarrierEcIntent, hasPowerShellCredentialAssignment, normalizeEvolcoreCommandArgv, parseCodexToolCommand, parseBoundedOutputShellCommand, buildCanonicalEvolcoreExecutionSpec, serializeCanonicalEvolcoreExecutionSpec, parseShellApplyPatchInvocation, parseLiteralShellArgv, resolveCodexShellCarrierArgv, resolveCodexShellCarrierString, } from './ec-command-parser.js';
|
|
9
|
+
import { classifyEvolcoreShellCommand, canonicalizeEvolcoreCommandArgv, hasCodexCmdCarrierEcIntent, hasPowerShellCredentialAssignment, normalizeEvolcoreCommandArgv, parseCodexToolCommand, literalShellParseRemedy, parseBoundedOutputShellCommand, buildCanonicalEvolcoreExecutionSpec, serializeCanonicalEvolcoreExecutionSpec, parseShellApplyPatchInvocation, parseLiteralShellArgv, resolveCodexShellCarrierArgv, resolveCodexShellCarrierString, } from './ec-command-parser.js';
|
|
10
10
|
import { analyzeReadonlyShellQuery, } from './readonly-shell-query.js';
|
|
11
11
|
import { applyPatchChangePaths, collectFileChangePaths } from './tool-canonical.js';
|
|
12
12
|
/** Resolve the session-owned temporary root supplied by the execution host. */
|
|
@@ -1330,48 +1330,21 @@ function analyzeShellProtectedOperands(command, options) {
|
|
|
1330
1330
|
analysis,
|
|
1331
1331
|
hClass: !!hClassPath,
|
|
1332
1332
|
lClass: !!lClassPath,
|
|
1333
|
-
pathHClass: !!hClassPath,
|
|
1334
|
-
lockDiagnostic: false,
|
|
1335
1333
|
hClassPath,
|
|
1336
1334
|
lClassPath,
|
|
1337
1335
|
};
|
|
1338
1336
|
}
|
|
1339
1337
|
const operands = queryPathOperands(analysis);
|
|
1340
|
-
// Only parsed path operands can establish a lock-file diagnostic. Searching
|
|
1341
|
-
// the raw command would mistake a grep/rg pattern or report text for an
|
|
1342
|
-
// actual protected filesystem target.
|
|
1343
|
-
const lockDiagnostic = operands.some(({ operand }) => containsLockPathReference(operand.value))
|
|
1344
|
-
|| hasFindLockPattern(analysis);
|
|
1345
1338
|
const hClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'h', options, accessKind)).find(Boolean);
|
|
1346
1339
|
const lClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'l', options, accessKind)).find(Boolean);
|
|
1347
1340
|
return {
|
|
1348
1341
|
analysis,
|
|
1349
|
-
hClass:
|
|
1342
|
+
hClass: !!hClassPath,
|
|
1350
1343
|
lClass: !!lClassPath,
|
|
1351
|
-
pathHClass: !!hClassPath,
|
|
1352
|
-
lockDiagnostic,
|
|
1353
1344
|
hClassPath,
|
|
1354
1345
|
lClassPath,
|
|
1355
1346
|
};
|
|
1356
1347
|
}
|
|
1357
|
-
/** Detect a find pattern such as `-name '*.lock'` from parsed argv only. */
|
|
1358
|
-
function hasFindLockPattern(analysis) {
|
|
1359
|
-
if (analysis.kind !== 'proven-readonly')
|
|
1360
|
-
return false;
|
|
1361
|
-
return analysis.ir.pipelines.some(pipeline => pipeline.some(command => {
|
|
1362
|
-
if (command.executable !== 'find')
|
|
1363
|
-
return false;
|
|
1364
|
-
for (let index = 0; index < command.argv.length - 1; index++) {
|
|
1365
|
-
if (!['-name', '-iname', '-path', '-ipath', '-wholename'].includes(command.argv[index]))
|
|
1366
|
-
continue;
|
|
1367
|
-
if (/(?:^|[\\/])[^\\/]*\.lock(?:$|[\\/])/i.test(command.argv[index + 1]))
|
|
1368
|
-
return true;
|
|
1369
|
-
if (/^EVOLCORE_RUNTIME_LOCK_DIR$/i.test(command.argv[index + 1]))
|
|
1370
|
-
return true;
|
|
1371
|
-
}
|
|
1372
|
-
return false;
|
|
1373
|
-
}));
|
|
1374
|
-
}
|
|
1375
1348
|
function protectedReadToolPaths(toolName, input) {
|
|
1376
1349
|
if (toolName === 'Read') {
|
|
1377
1350
|
return typeof input.file_path === 'string' ? [input.file_path] : [];
|
|
@@ -1514,7 +1487,6 @@ function readonlySourceDiagnosticAllowed(analysis, projectPath) {
|
|
|
1514
1487
|
if (!first || !READONLY_SOURCE_ROOTS.has(first) || segments.includes('node_modules'))
|
|
1515
1488
|
return false;
|
|
1516
1489
|
return !containsHClassReference(operand.value) && !containsLClassReference(operand.value)
|
|
1517
|
-
&& !containsLockPathReference(operand.value)
|
|
1518
1490
|
&& !isHClassPath(candidate, { root: resolveRoot() })
|
|
1519
1491
|
&& !isLClassPath(candidate, { root: resolveRoot() });
|
|
1520
1492
|
});
|
|
@@ -1567,12 +1539,6 @@ function boundedRootSourceEnumeration(analysis, projectPath) {
|
|
|
1567
1539
|
return pipeline.slice(1).every(command => ['head', 'sort', 'grep', 'wc'].includes(command.executable)
|
|
1568
1540
|
&& command.pathOperands.length === 0);
|
|
1569
1541
|
}
|
|
1570
|
-
/** A lock filename used as a query pattern is safe; an operand naming the
|
|
1571
|
-
* actual lock path is still protected. */
|
|
1572
|
-
function containsLockPathReference(value) {
|
|
1573
|
-
return /(?:^|[\\/])(?:[^\\/]*\.lock|EVOLCORE_RUNTIME_LOCK_DIR)(?:$|[\\/])/i.test(value)
|
|
1574
|
-
|| /^(?:[^\\/]*\.lock|EVOLCORE_RUNTIME_LOCK_DIR)$/i.test(value);
|
|
1575
|
-
}
|
|
1576
1542
|
/**
|
|
1577
1543
|
* 只读模式检查(用于 PreToolUse hook 和 canUseTool callback)。普通
|
|
1578
1544
|
* 路径上的受限查询 Bash 可自动执行;H/L-class 和未建模 Shell 仍拒绝。
|
|
@@ -1633,8 +1599,7 @@ export function checkReadonly(toolName, input, projectPath, context) {
|
|
|
1633
1599
|
const boundedSourceQueryAllowed = boundedRootSourceEnumeration(protectedOperands.analysis, projectPath);
|
|
1634
1600
|
const sourceDiagnosticAllowed = context?.allowReadonlySourceDiagnostics
|
|
1635
1601
|
&& (!protectedOperands.lClass || boundedSourceQueryAllowed)
|
|
1636
|
-
&& ((sourceQueryAllowed
|
|
1637
|
-
&& (!protectedOperands.hClass || (protectedOperands.lockDiagnostic && !protectedOperands.pathHClass)))
|
|
1602
|
+
&& ((sourceQueryAllowed && !protectedOperands.hClass)
|
|
1638
1603
|
|| boundedSourceQueryAllowed);
|
|
1639
1604
|
if (sourceDiagnosticAllowed) {
|
|
1640
1605
|
return { behavior: 'allow' };
|
|
@@ -1928,8 +1893,7 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1928
1893
|
const sourceDiagnosticAllowed = context?.permissionMode === 'readonly'
|
|
1929
1894
|
&& context.allowReadonlySourceDiagnostics === true
|
|
1930
1895
|
&& (!protectedOperands.lClass || boundedSourceQueryAllowed)
|
|
1931
|
-
&& ((sourceQueryAllowed
|
|
1932
|
-
&& (!protectedOperands.hClass || (protectedOperands.lockDiagnostic && !protectedOperands.pathHClass)))
|
|
1896
|
+
&& ((sourceQueryAllowed && !protectedOperands.hClass)
|
|
1933
1897
|
|| boundedSourceQueryAllowed);
|
|
1934
1898
|
if (protectedOperands.hClass && !sourceDiagnosticAllowed) {
|
|
1935
1899
|
logger.warn(`[H-Class Protection] 🔒 Protected filesystem operand in shell command: tool=${toolName} ` +
|
|
@@ -2107,7 +2071,7 @@ export function checkLClassWrite(toolName, input, context) {
|
|
|
2107
2071
|
behavior: 'deny',
|
|
2108
2072
|
message: context?.permissionMode === 'readonly'
|
|
2109
2073
|
? '🔒 只读模式:visitor 最低权限不允许读取 L-class 路径'
|
|
2110
|
-
:
|
|
2074
|
+
: `🔒 L-class 路径允许读取,但当前 Bash 命令无法证明为只读${protectedOperands.analysis.kind === 'unproven' ? `(原因码:${protectedOperands.analysis.reason})` : ''},已拒绝执行。请改用受控的 EvolCore 读取命令或白名单只读命令`,
|
|
2111
2075
|
matchedPath: protectedOperands.lClassPath,
|
|
2112
2076
|
};
|
|
2113
2077
|
}
|
|
@@ -2369,6 +2333,7 @@ export function checkBashDescription(toolName, input) {
|
|
|
2369
2333
|
/** Shared fail-closed preflight used before runner-specific mode and approval handling. */
|
|
2370
2334
|
export function evaluateToolPreflight(toolName, input, context) {
|
|
2371
2335
|
let applyPatchFileChanges;
|
|
2336
|
+
let protectedPolicyCommand;
|
|
2372
2337
|
const managedPathCheck = checkManagedTempToolPaths(toolName, input, managedTempOptions(context));
|
|
2373
2338
|
if (managedPathCheck.kind === 'deny') {
|
|
2374
2339
|
const currentTmpDir = resolveManagedTempDir(managedTempOptions(context).env);
|
|
@@ -2418,6 +2383,13 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2418
2383
|
?? (explicitCommandArgv ? undefined : resolveCodexShellCarrierString(command));
|
|
2419
2384
|
const wrappedCommand = stringShellCarrier?.parseFailure ? undefined : stringShellCarrier?.command;
|
|
2420
2385
|
const policyCommand = wrappedCommand ?? commandForPolicy;
|
|
2386
|
+
// The class checks must inspect the same inner command used by command
|
|
2387
|
+
// classification. Otherwise Codex's outer `bash -lc` carrier makes a
|
|
2388
|
+
// valid single read look like an unsupported composite shell command.
|
|
2389
|
+
protectedPolicyCommand = wrappedCommand
|
|
2390
|
+
?? (!shellCarrier && explicitCommandArgv
|
|
2391
|
+
? explicitCommandArgv.map(quotePosixShellArg).join(' ')
|
|
2392
|
+
: undefined);
|
|
2421
2393
|
if (context.sessionId && /^\s*(?:command\s+-v|which|type)\s+ec\s*$/i.test(policyCommand)) {
|
|
2422
2394
|
return {
|
|
2423
2395
|
behavior: 'deny',
|
|
@@ -2554,7 +2526,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2554
2526
|
&& managedAidArgv[3] === 'set'
|
|
2555
2527
|
&& !!context.selfAid
|
|
2556
2528
|
&& managedAidArgv[4]?.replace(/^@/, '') === context.selfAid.replace(/^@/, '')
|
|
2557
|
-
&& ['name', 'type', 'description', 'version', 'tags'].includes(managedAidArgv[5] ?? '')
|
|
2529
|
+
&& ['name', 'type', 'description', 'version', 'tags', 'exttype'].includes(managedAidArgv[5] ?? '')
|
|
2558
2530
|
&& managedAidArgv[6] !== undefined;
|
|
2559
2531
|
const avatarFileIndex = managedAidArgv?.indexOf('--file') ?? -1;
|
|
2560
2532
|
const avatarUrlIndex = managedAidArgv?.indexOf('--url') ?? -1;
|
|
@@ -2576,7 +2548,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2576
2548
|
const canUploadSelfAvatar = isSelfAvatarUpload
|
|
2577
2549
|
&& ['request', 'bypass'].includes(context.permissionMode ?? '');
|
|
2578
2550
|
let isManagedOwnership = false;
|
|
2579
|
-
if (managedAidArgs?.[0] === 'bind') {
|
|
2551
|
+
if (managedAidArgs?.[0] === 'bind' || managedAidArgs?.[0] === 'transfer') {
|
|
2580
2552
|
try {
|
|
2581
2553
|
const ownership = parseOwnershipCommand(managedAidArgs);
|
|
2582
2554
|
isManagedOwnership = ownership.action === 'status'
|
|
@@ -2642,7 +2614,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2642
2614
|
}
|
|
2643
2615
|
if (ecCommand.issue === 'invalid-quote') {
|
|
2644
2616
|
const message = shellDialect === 'powershell'
|
|
2645
|
-
?
|
|
2617
|
+
? `🔒 EC 命令引号未闭合或存在错误嵌套。${literalShellParseRemedy({ issue: 'invalid-quote', dialect: 'powershell' })}`
|
|
2646
2618
|
: shellDialect === 'cmd'
|
|
2647
2619
|
? '🔒 EC 命令引号未闭合或存在错误嵌套;cmd.exe carrier 的命令正文请保持一个完整参数,不要用未配对的双引号'
|
|
2648
2620
|
: '🔒 EC 命令引号未闭合或存在错误嵌套。自由文本参数用单引号包住;正文含单引号时改用 $\'…\' 语法,内部用 \\\' 转义,如 $\'it\\\'s fine\'。';
|
|
@@ -2693,7 +2665,10 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2693
2665
|
? { ...checkedInput, fileChanges: applyPatchFileChanges }
|
|
2694
2666
|
: checkedInput;
|
|
2695
2667
|
const policyToolName = applyPatchFileChanges ? 'FileChange' : toolName;
|
|
2696
|
-
const
|
|
2668
|
+
const protectedPolicyInput = policyToolName === 'Bash' && protectedPolicyCommand
|
|
2669
|
+
? { ...policyInput, command: protectedPolicyCommand }
|
|
2670
|
+
: policyInput;
|
|
2671
|
+
const hClass = checkHClassWrite(policyToolName, protectedPolicyInput, {
|
|
2697
2672
|
sessionId: context.sessionId,
|
|
2698
2673
|
channel: context.channel,
|
|
2699
2674
|
peerId: context.userId,
|
|
@@ -2710,7 +2685,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2710
2685
|
if (hClass.behavior === 'deny') {
|
|
2711
2686
|
return { behavior: 'deny', input: checkedInput, message: hClass.message, policyCode: 'h_class_protection', matchedPath: hClass.matchedPath };
|
|
2712
2687
|
}
|
|
2713
|
-
const lClass = checkLClassWrite(policyToolName,
|
|
2688
|
+
const lClass = checkLClassWrite(policyToolName, protectedPolicyInput, {
|
|
2714
2689
|
sessionId: context.sessionId,
|
|
2715
2690
|
channel: context.channel,
|
|
2716
2691
|
peerId: context.userId,
|
|
@@ -66,7 +66,10 @@ import * as path from 'path';
|
|
|
66
66
|
import * as crypto from 'crypto';
|
|
67
67
|
import { parse as parseYaml } from 'yaml';
|
|
68
68
|
import { logger } from '../../utils/logger.js';
|
|
69
|
-
import { agentMdPath } from '../../paths.js';
|
|
69
|
+
import { agentDir as resolveAgentDir, agentMdPath } from '../../paths.js';
|
|
70
|
+
import { ConfigTarget, mutateConfig, read } from '../../config/config-manager.js';
|
|
71
|
+
import { isValidAid } from '../../aun/aid/validation.js';
|
|
72
|
+
import { resolveAunTargetKind, verifiedPeerType, } from '../../aun/group/identity.js';
|
|
70
73
|
/**
|
|
71
74
|
* peerKey: 关系层路由键,格式 `<channelType>#<urlEncode(channelId)>`。
|
|
72
75
|
* 群聊场景下 channelId = groupId,所有发言者共用同一个 peerKey。
|
|
@@ -83,6 +86,58 @@ export function parsePeerKey(key) {
|
|
|
83
86
|
channelId: decodeURIComponent(key.slice(idx + 1)),
|
|
84
87
|
};
|
|
85
88
|
}
|
|
89
|
+
/** Read type evidence without network access or any AID-shape fallback. */
|
|
90
|
+
export function readAunPeerKind(selfAid, peerAid, options = {}) {
|
|
91
|
+
if (!isValidAid(selfAid) || !isValidAid(peerAid)) {
|
|
92
|
+
return { kind: 'unknown', reason: 'invalid', sources: [] };
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const relation = options.relation !== undefined ? options.relation
|
|
96
|
+
: read(ConfigTarget.Relation, { self: selfAid, peerKey: formatPeerKey('aun', peerAid) });
|
|
97
|
+
return resolveAunTargetKind({
|
|
98
|
+
routeKind: options.routeKind,
|
|
99
|
+
targetKind: relation?.targetKind,
|
|
100
|
+
verifiedType: verifiedPeerType(peerAid, PeerIdentityCache.get('aun', peerAid, resolveAgentDir(selfAid))),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { kind: 'unknown', reason: 'unavailable', sources: [] };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Fetch and cache a verified card only when local evidence is missing. Never resolve a conflict by guessing. */
|
|
108
|
+
export async function resolveAunPeerKind(selfAid, peerAid, options = {}) {
|
|
109
|
+
const current = readAunPeerKind(selfAid, peerAid, options);
|
|
110
|
+
if (current.reason !== 'missing')
|
|
111
|
+
return current;
|
|
112
|
+
try {
|
|
113
|
+
const { agentmdGet } = await import('../../aun/aid/agentmd.js');
|
|
114
|
+
const result = await agentmdGet(peerAid, { withVerification: true });
|
|
115
|
+
if (result.verification.status !== 'verified')
|
|
116
|
+
return { ...current, reason: 'unavailable' };
|
|
117
|
+
const metadata = parseAgentMdFrontmatter(result.content);
|
|
118
|
+
if (metadata.aid !== peerAid || typeof metadata.type !== 'string' || !metadata.type.trim()) {
|
|
119
|
+
return { kind: 'unknown', reason: 'invalid', sources: [] };
|
|
120
|
+
}
|
|
121
|
+
PeerIdentityCache.cacheVerifiedAgentMd('aun', peerAid, resolveAgentDir(selfAid), result.content);
|
|
122
|
+
// Re-read relation metadata because it may have changed during the remote lookup.
|
|
123
|
+
return readAunPeerKind(selfAid, peerAid, options);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return { ...current, reason: 'unavailable' };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Persist a trusted runtime kind, without overwriting conflicting evidence. */
|
|
130
|
+
export function recordAunPeerRoute(selfAid, peerAid, routeKind) {
|
|
131
|
+
const current = readAunPeerKind(selfAid, peerAid, { routeKind });
|
|
132
|
+
if (current.kind !== routeKind)
|
|
133
|
+
return current;
|
|
134
|
+
return mutateConfig(ConfigTarget.Relation, { self: selfAid, peerKey: formatPeerKey('aun', peerAid) }, relation => {
|
|
135
|
+
const resolution = readAunPeerKind(selfAid, peerAid, { routeKind, relation });
|
|
136
|
+
if (resolution.kind === routeKind)
|
|
137
|
+
relation.targetKind = routeKind;
|
|
138
|
+
return resolution;
|
|
139
|
+
}).value;
|
|
140
|
+
}
|
|
86
141
|
/**
|
|
87
142
|
* 对端身份缓存管理器
|
|
88
143
|
*/
|
|
@@ -114,6 +169,14 @@ export class PeerIdentityCache {
|
|
|
114
169
|
return null;
|
|
115
170
|
}
|
|
116
171
|
}
|
|
172
|
+
/** Internal callers must pass bytes returned by agentmdGet with verification.status=verified. */
|
|
173
|
+
static cacheVerifiedAgentMd(channelType, peerId, agentDir, content) {
|
|
174
|
+
const metadata = parseAgentMdFrontmatter(content);
|
|
175
|
+
if (metadata.aid !== peerId || typeof metadata.type !== 'string' || !metadata.type.trim()) {
|
|
176
|
+
throw new Error('Verified agent.md must declare the requested AID and its type');
|
|
177
|
+
}
|
|
178
|
+
return this.updateFromAgentMd(channelType, peerId, agentDir, content, Date.now(), 'agentmd');
|
|
179
|
+
}
|
|
117
180
|
/** Expire only the freshness check; retain the last snapshot and its trust level. */
|
|
118
181
|
static invalidate(channelType, peerId, agentDir) {
|
|
119
182
|
const cached = this.get(channelType, peerId, agentDir);
|