evolcore 0.0.48 → 0.0.50
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 +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { requireTrustedWindowsShellExecutable, WindowsShellTrustError } from '../../utils/windows-shell-trust.js';
|
|
4
|
+
import { parseRemoteCommand } from '../../ability/caller/command.js';
|
|
4
5
|
export function parseJsonObjectArgument(raw, optionName = '--payload') {
|
|
5
6
|
let parsed;
|
|
6
7
|
try {
|
|
@@ -391,7 +392,7 @@ const EVOLCORE_SUBCOMMANDS = new Set([
|
|
|
391
392
|
'mode', 'model', 'msg', 'mv', 'net', 'queue', 'response', 'restart',
|
|
392
393
|
'restart-monitor', 'rpc', 'start', 'stats', 'status', 'stop', 'storage', 'task',
|
|
393
394
|
'trigger', 'proxy', 'version', 'watch', 'session', 'team', 'upgrade', 'update',
|
|
394
|
-
'directory', 'getmeta', 'integrity', 'invoke', 'memory', 'provider', 'role', 'skill', 'thread',
|
|
395
|
+
'directory', 'getmeta', 'integrity', 'invoke', 'memory', 'provider', 'role', 'skill', 'thread', 'pay',
|
|
395
396
|
]);
|
|
396
397
|
// Development/install entrypoints that are part of this repository's CLI.
|
|
397
398
|
// Only these exact relative paths are canonicalized; arbitrary Node scripts
|
|
@@ -681,8 +682,16 @@ function isCodexPosixShellExecutable(value) {
|
|
|
681
682
|
if (!value)
|
|
682
683
|
return false;
|
|
683
684
|
return CODEX_POSIX_SHELL_EXECUTABLES.has(value.toLowerCase())
|
|
685
|
+
|| isCodexZshExecutable(value)
|
|
684
686
|
|| isAbsoluteCustomShellPath(value, CODEX_CUSTOM_POSIX_SHELL_NAMES);
|
|
685
687
|
}
|
|
688
|
+
function isCodexZshExecutable(value) {
|
|
689
|
+
// Custom POSIX paths are explicit, normalized paths with an exact basename;
|
|
690
|
+
// neither relative lookalikes nor Windows zsh.exe are supported carriers.
|
|
691
|
+
return value === 'zsh' || (value.startsWith('/') && !value.startsWith('//')
|
|
692
|
+
&& path.posix.normalize(value) === value && value.endsWith('/zsh')
|
|
693
|
+
&& !/[\x00-\x1f\x7f\\"'<>|?*`$;&(){}\[\]]/u.test(value));
|
|
694
|
+
}
|
|
686
695
|
function isCodexPowerShellExecutable(value) {
|
|
687
696
|
if (!value)
|
|
688
697
|
return false;
|
|
@@ -791,6 +800,24 @@ function hasCarrierEcCommandPrefix(command, dialect) {
|
|
|
791
800
|
: input;
|
|
792
801
|
return /^\s*ec(?:\.cmd|\.exe|\.ps1)?(?:\s|$)/i.test(inner);
|
|
793
802
|
}
|
|
803
|
+
/** Identify nested EC intent only for denial; never authorize an eval/shell. */
|
|
804
|
+
function hasNestedZshEcIntent(command) {
|
|
805
|
+
let body = command;
|
|
806
|
+
while (body) {
|
|
807
|
+
if (hasEcCommandPrefix(body))
|
|
808
|
+
return true;
|
|
809
|
+
const carrier = resolveCodexShellCarrierString(body);
|
|
810
|
+
if (carrier) {
|
|
811
|
+
body = carrier.command;
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
const parsed = parseLiteralShellCommand(body, { posixShell: 'zsh' });
|
|
815
|
+
if (!parsed.ok || parsed.argv[0] !== 'eval')
|
|
816
|
+
return false;
|
|
817
|
+
body = parsed.argv.slice(1).join(' ');
|
|
818
|
+
}
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
794
821
|
/** Normalize the Windows npm shims to the canonical EvolCore CLI name. */
|
|
795
822
|
/**
|
|
796
823
|
* 取可执行名的 basename(小写)。与 hasEcCommandPrefix 里的算法一致:
|
|
@@ -891,7 +918,7 @@ const INLINE_TEXT_FLAGS = {
|
|
|
891
918
|
const MESSAGE_POSITIONAL_FLAGS = new Set([
|
|
892
919
|
'--file', '--payload', '--payload-file', '--as', '--content-type', '--text', '--transcript',
|
|
893
920
|
'--thread', '--title', '--description', '--text-from-file',
|
|
894
|
-
'--handoff-context', '--aun-path', '--app', '--format', '--encrypt',
|
|
921
|
+
'--handoff-context', '--aun-path', '--app', '--format', '--encrypt',
|
|
895
922
|
'--return', '--timeout',
|
|
896
923
|
]);
|
|
897
924
|
/** Decode the EC inline text contract exactly once, after shell parsing. */
|
|
@@ -1013,7 +1040,7 @@ function canonicalizeCommaOnlyFlags(argv, flags) {
|
|
|
1013
1040
|
index++;
|
|
1014
1041
|
}
|
|
1015
1042
|
}
|
|
1016
|
-
const LOCAL_FILE_VALUE_FLAGS = new Set(['--file', '--text-from-file', '--payload-file']);
|
|
1043
|
+
const LOCAL_FILE_VALUE_FLAGS = new Set(['--file', '--text-from-file', '--payload-file', '--params-file']);
|
|
1017
1044
|
function normalizeWindowsFilePath(value) {
|
|
1018
1045
|
if (process.platform !== 'win32' || !/^[A-Za-z]:[\\/]/u.test(value))
|
|
1019
1046
|
return value;
|
|
@@ -1023,7 +1050,7 @@ function canonicalizeLocalFilePathFlags(argv) {
|
|
|
1023
1050
|
for (let index = 2; index < argv.length; index++) {
|
|
1024
1051
|
if (argv[index] === '--')
|
|
1025
1052
|
break;
|
|
1026
|
-
const inline = argv[index].match(/^(--(?:file|text-from-file|payload-file))=(.*)$/u);
|
|
1053
|
+
const inline = argv[index].match(/^(--(?:file|text-from-file|payload-file|params-file))=(.*)$/u);
|
|
1027
1054
|
if (inline) {
|
|
1028
1055
|
argv[index] = `${inline[1]}=${normalizeWindowsFilePath(inline[2])}`;
|
|
1029
1056
|
continue;
|
|
@@ -1192,12 +1219,20 @@ function unwrapPowerShellCredentialPrefix(command) {
|
|
|
1192
1219
|
}
|
|
1193
1220
|
export function parseCodexCarrierCommand(carrier, options = {}) {
|
|
1194
1221
|
if (options.verifyShellExecutable) {
|
|
1195
|
-
if (!carrier.executable) {
|
|
1196
|
-
return parseFailure('untrusted-shell', carrier.command, 0, 0, carrier.dialect);
|
|
1197
|
-
}
|
|
1198
1222
|
const kind = carrier.dialect === 'posix' ? 'bash' : carrier.dialect;
|
|
1199
|
-
|
|
1200
|
-
|
|
1223
|
+
try {
|
|
1224
|
+
if (!carrier.executable) {
|
|
1225
|
+
throw new WindowsShellTrustError('SHELL_PATH_UNRESOLVED', 'Shell carrier 缺少可执行文件路径');
|
|
1226
|
+
}
|
|
1227
|
+
requireTrustedWindowsShellExecutable(carrier.executable, kind);
|
|
1228
|
+
}
|
|
1229
|
+
catch (error) {
|
|
1230
|
+
const failure = error instanceof WindowsShellTrustError ? error
|
|
1231
|
+
: new WindowsShellTrustError('SHELL_TRUST_CHECK_FAILED', error instanceof Error ? error.message : String(error), { path: carrier.executable }, error);
|
|
1232
|
+
return {
|
|
1233
|
+
...parseFailure('untrusted-shell', carrier.command, 0, 0, carrier.dialect),
|
|
1234
|
+
shellTrustFailure: { reason: failure.reason, message: failure.message, diagnostics: failure.diagnostics },
|
|
1235
|
+
};
|
|
1201
1236
|
}
|
|
1202
1237
|
}
|
|
1203
1238
|
if (carrier.parseFailure)
|
|
@@ -1222,6 +1257,7 @@ export function parseCodexCarrierCommand(carrier, options = {}) {
|
|
|
1222
1257
|
const materialized = parseLiteralShellCommand(unwrapped.command, {
|
|
1223
1258
|
...options,
|
|
1224
1259
|
dialect: carrier.dialect,
|
|
1260
|
+
posixShell: carrier.posixShell ?? options.posixShell,
|
|
1225
1261
|
});
|
|
1226
1262
|
if (materialized.ok && carrier.dialect === 'powershell') {
|
|
1227
1263
|
const nestedCarrier = resolveCodexCmdCarrierString(unwrapped.command);
|
|
@@ -1267,6 +1303,9 @@ export function literalShellParseRemedy(failure) {
|
|
|
1267
1303
|
if (failure.issue === 'shell-composition') {
|
|
1268
1304
|
return '一次调用只执行一条完整命令;查询和操作请拆成独立工具调用,不要拼接管道、重定向、分号或子表达式。';
|
|
1269
1305
|
}
|
|
1306
|
+
if (failure.dialect === 'posix' && failure.issue === 'unsupported-escape') {
|
|
1307
|
+
return 'Shell 转义无法按字面量解析;请使用单引号,或受支持的 ANSI-C 转义:\\n、\\t、\\r、\\\\、\\\'。';
|
|
1308
|
+
}
|
|
1270
1309
|
if (failure.dialect !== 'powershell')
|
|
1271
1310
|
return undefined;
|
|
1272
1311
|
if (['invalid-quote', 'unsafe-expansion', 'unsupported-escape', 'structural-newline'].includes(failure.issue)) {
|
|
@@ -1733,6 +1772,7 @@ function resolveCodexPosixShellCarrierString(command) {
|
|
|
1733
1772
|
command: nested,
|
|
1734
1773
|
dialect: 'posix',
|
|
1735
1774
|
executable,
|
|
1775
|
+
...(isCodexZshExecutable(executable) ? { posixShell: 'zsh' } : {}),
|
|
1736
1776
|
parseFailure: parsed.ok
|
|
1737
1777
|
? parseFailure('shell-composition', input, 0, 0, 'posix')
|
|
1738
1778
|
: parsed,
|
|
@@ -1864,6 +1904,11 @@ export function parseLiteralShellCommand(command, options = {}) {
|
|
|
1864
1904
|
const char = input[index];
|
|
1865
1905
|
if (quote === 'single') {
|
|
1866
1906
|
if (char === "'") {
|
|
1907
|
+
// RC_QUOTES makes adjacent single quotes literal apostrophes in zsh.
|
|
1908
|
+
// Require an unambiguous boundary regardless of that startup option.
|
|
1909
|
+
if (options.posixShell === 'zsh' && input[index + 1] === "'") {
|
|
1910
|
+
return parseFailure('unsupported-escape', input, index, argv.length, 'posix');
|
|
1911
|
+
}
|
|
1867
1912
|
if (!isPosixQuotedTokenBoundary(input[index + 1]))
|
|
1868
1913
|
return parseFailure('invalid-quote', input, index, argv.length, 'posix');
|
|
1869
1914
|
quote = null;
|
|
@@ -1879,6 +1924,9 @@ export function parseLiteralShellCommand(command, options = {}) {
|
|
|
1879
1924
|
quote = null;
|
|
1880
1925
|
continue;
|
|
1881
1926
|
}
|
|
1927
|
+
if (options.posixShell === 'zsh' && char === '$' && /[=~^+\[]/u.test(input[index + 1] ?? '')) {
|
|
1928
|
+
return parseFailure('unsafe-expansion', input, index, argv.length, 'posix');
|
|
1929
|
+
}
|
|
1882
1930
|
const issue = doubleQuotedIssueAt(input, index);
|
|
1883
1931
|
if (issue)
|
|
1884
1932
|
return parseFailure(issue, input, index, argv.length, 'posix');
|
|
@@ -1964,6 +2012,9 @@ export function parseLiteralShellCommand(command, options = {}) {
|
|
|
1964
2012
|
token += "'";
|
|
1965
2013
|
break;
|
|
1966
2014
|
default:
|
|
2015
|
+
if (options.posixShell === 'zsh') {
|
|
2016
|
+
return parseFailure('unsupported-escape', input, index, argv.length, 'posix');
|
|
2017
|
+
}
|
|
1967
2018
|
token += `\\${esc}`;
|
|
1968
2019
|
break;
|
|
1969
2020
|
}
|
|
@@ -1979,6 +2030,13 @@ export function parseLiteralShellCommand(command, options = {}) {
|
|
|
1979
2030
|
return parseFailure('invalid-quote', input, index, argv.length, 'posix');
|
|
1980
2031
|
continue;
|
|
1981
2032
|
}
|
|
2033
|
+
// zsh has equals expansion and option-dependent extended glob/named-dir
|
|
2034
|
+
// expansion. Check source quoting here, before it is lost in argv.
|
|
2035
|
+
if (options.posixShell === 'zsh'
|
|
2036
|
+
&& (['~', '^', '#', '!'].includes(char)
|
|
2037
|
+
|| (char === '=' && (!tokenStarted || /[=:]$/u.test(token))))) {
|
|
2038
|
+
return parseFailure('unsafe-expansion', input, index, argv.length, 'posix');
|
|
2039
|
+
}
|
|
1982
2040
|
// `#` starts a shell comment only at the beginning of a word. Channel
|
|
1983
2041
|
// peer keys such as `aun#alice` are ordinary literal arguments.
|
|
1984
2042
|
if ((SHELL_UNQUOTED_META.has(char) && (char !== '#' || !tokenStarted))
|
|
@@ -2004,6 +2062,19 @@ export function parseLiteralShellArgv(command, options = {}) {
|
|
|
2004
2062
|
return result.ok ? result.argv : null;
|
|
2005
2063
|
}
|
|
2006
2064
|
export function resolveCodexShellCarrierArgv(argv) {
|
|
2065
|
+
if (argv[0] && isCodexZshExecutable(argv[0])) {
|
|
2066
|
+
const executeIndex = argv.findIndex((value, index) => index > 0 && /^-[A-Za-z]*c[A-Za-z]*$/u.test(value));
|
|
2067
|
+
if (executeIndex > 0 && argv[executeIndex + 1] !== undefined) {
|
|
2068
|
+
const command = argv[executeIndex + 1];
|
|
2069
|
+
const supported = argv.length === 3 && executeIndex === 1
|
|
2070
|
+
&& (argv[1] === '-c' || argv[1] === '-lc');
|
|
2071
|
+
return {
|
|
2072
|
+
command, dialect: 'posix', posixShell: 'zsh', executable: argv[0],
|
|
2073
|
+
...(!supported ? { parseFailure: parseFailure('shell-composition', command, 0, 0, 'posix') } : {}),
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
return undefined;
|
|
2077
|
+
}
|
|
2007
2078
|
if (argv.length === 3
|
|
2008
2079
|
&& (argv[1] === '-lc' || argv[1] === '-c')
|
|
2009
2080
|
&& isCodexPosixShellExecutable(argv[0])) {
|
|
@@ -2818,8 +2889,8 @@ function scanBoundedOutputOperators(command) {
|
|
|
2818
2889
|
* Returns the full filter argv (executable included) so the spawn helper can
|
|
2819
2890
|
* execute exactly what policy validated.
|
|
2820
2891
|
*/
|
|
2821
|
-
export function parseStdinOnlyFilterArgv(segment) {
|
|
2822
|
-
const argv = parseLiteralShellArgv(segment);
|
|
2892
|
+
export function parseStdinOnlyFilterArgv(segment, options = {}) {
|
|
2893
|
+
const argv = parseLiteralShellArgv(segment, options);
|
|
2823
2894
|
if (!argv)
|
|
2824
2895
|
return null;
|
|
2825
2896
|
const executable = normalizeStdoutFilterExecutable(argv[0]);
|
|
@@ -2900,10 +2971,13 @@ export function parseStdinOnlyFilterArgv(segment) {
|
|
|
2900
2971
|
* optional stderr merge, one trusted stdin-only stdout filter, and one
|
|
2901
2972
|
* create-only output path.
|
|
2902
2973
|
*/
|
|
2903
|
-
export function parseBoundedOutputShellCommand(command) {
|
|
2974
|
+
export function parseBoundedOutputShellCommand(command, options = {}) {
|
|
2904
2975
|
const input = trimShellSpacing(substituteManagedTmpDirToken(command));
|
|
2905
2976
|
if (!input)
|
|
2906
2977
|
return null;
|
|
2978
|
+
// The wrapper owns TMPDIR substitution. Keep its sentinel intact until
|
|
2979
|
+
// source-argument rejection and output-path restoration have completed.
|
|
2980
|
+
const literalOptions = { ...options, allowManagedTmpDir: false };
|
|
2907
2981
|
const operators = scanBoundedOutputOperators(input);
|
|
2908
2982
|
if (!operators || operators.length === 0)
|
|
2909
2983
|
return null;
|
|
@@ -2920,7 +2994,7 @@ export function parseBoundedOutputShellCommand(command) {
|
|
|
2920
2994
|
// 所以两种情况都切在 operators[0].start,绝不能按 end 切——那会把 `2>&1` 混进 argv。
|
|
2921
2995
|
const first = operators[0];
|
|
2922
2996
|
const sourceText = trimShellSpacing(input.slice(0, first.start));
|
|
2923
|
-
const argv = parseLiteralShellArgv(sourceText);
|
|
2997
|
+
const argv = parseLiteralShellArgv(sourceText, literalOptions);
|
|
2924
2998
|
if (!argv)
|
|
2925
2999
|
return null;
|
|
2926
3000
|
// `$TMPDIR` is a transport-level path reference, never an argument
|
|
@@ -2940,7 +3014,7 @@ export function parseBoundedOutputShellCommand(command) {
|
|
|
2940
3014
|
if (operator.kind === 'redirect' || operator.kind === 'redirect-stderr') {
|
|
2941
3015
|
const next = operators[cursor + 1];
|
|
2942
3016
|
const segmentEnd = next ? next.start : input.length;
|
|
2943
|
-
const outputArgv = parseLiteralShellArgv(trimShellSpacing(input.slice(operator.end, segmentEnd)));
|
|
3017
|
+
const outputArgv = parseLiteralShellArgv(trimShellSpacing(input.slice(operator.end, segmentEnd)), literalOptions);
|
|
2944
3018
|
if (!outputArgv || outputArgv.length !== 1)
|
|
2945
3019
|
return null;
|
|
2946
3020
|
if (outputArgv[0].includes('$') && !outputArgv[0].includes(MANAGED_TMPDIR_TOKEN))
|
|
@@ -2970,7 +3044,7 @@ export function parseBoundedOutputShellCommand(command) {
|
|
|
2970
3044
|
// 该管道的下游终点:下一个操作符起点,或输入末尾。
|
|
2971
3045
|
const next = operators[cursor + 1];
|
|
2972
3046
|
const segmentEnd = next ? next.start : input.length;
|
|
2973
|
-
const parsedArgs = parseStdinOnlyFilterArgv(trimShellSpacing(input.slice(operator.end, segmentEnd)));
|
|
3047
|
+
const parsedArgs = parseStdinOnlyFilterArgv(trimShellSpacing(input.slice(operator.end, segmentEnd)), literalOptions);
|
|
2974
3048
|
if (parsedArgs === null)
|
|
2975
3049
|
return null;
|
|
2976
3050
|
filterChain.push(parsedArgs);
|
|
@@ -2993,11 +3067,11 @@ export function parseBoundedOutputShellCommand(command) {
|
|
|
2993
3067
|
* 通配、括号、重定向、管道、以及 `&&`/`;` 本身。引号包裹的普通文本(如
|
|
2994
3068
|
* `echo "extra"`)合法;`echo $?`、`echo \`id\``、`echo *` 一律不合法。
|
|
2995
3069
|
*/
|
|
2996
|
-
function parseInertSegment(segment) {
|
|
3070
|
+
function parseInertSegment(segment, options) {
|
|
2997
3071
|
const text = trimShellSpacing(segment);
|
|
2998
3072
|
if (!text)
|
|
2999
3073
|
return null;
|
|
3000
|
-
const argv = parseLiteralShellArgv(text);
|
|
3074
|
+
const argv = parseLiteralShellArgv(text, { posixShell: options.posixShell });
|
|
3001
3075
|
if (!argv || argv.length === 0)
|
|
3002
3076
|
return null;
|
|
3003
3077
|
// 字面量解析已处理引号;拒绝任何仍可能造成展开或结构变化的字符。
|
|
@@ -3026,7 +3100,7 @@ function isInertSegment(argv) {
|
|
|
3026
3100
|
* 返回 ec 段的 argv(调用方按 bounded-output 同样的方式直接 spawn,不经 shell)。
|
|
3027
3101
|
* 前后的零副作用段只用来判定结构,不参与执行。
|
|
3028
3102
|
*/
|
|
3029
|
-
export function parseCdPrefixedEcCommand(input) {
|
|
3103
|
+
export function parseCdPrefixedEcCommand(input, options = {}) {
|
|
3030
3104
|
const text = trimShellSpacing(input);
|
|
3031
3105
|
if (!text)
|
|
3032
3106
|
return null;
|
|
@@ -3048,7 +3122,7 @@ export function parseCdPrefixedEcCommand(input) {
|
|
|
3048
3122
|
let ecIndex = -1;
|
|
3049
3123
|
for (let index = 0; index < segments.length; index++) {
|
|
3050
3124
|
const segment = segments[index];
|
|
3051
|
-
const parsed = parseEcTail(segment);
|
|
3125
|
+
const parsed = parseEcTail(segment, options);
|
|
3052
3126
|
if (parsed) {
|
|
3053
3127
|
if (ecCommand)
|
|
3054
3128
|
return null; // 两条 ec,拒绝
|
|
@@ -3057,7 +3131,7 @@ export function parseCdPrefixedEcCommand(input) {
|
|
|
3057
3131
|
continue;
|
|
3058
3132
|
}
|
|
3059
3133
|
// 非 ec 段:只允许零副作用形态。
|
|
3060
|
-
const argv = parseInertSegment(segment);
|
|
3134
|
+
const argv = parseInertSegment(segment, options);
|
|
3061
3135
|
if (!argv || !isInertSegment(argv))
|
|
3062
3136
|
return null;
|
|
3063
3137
|
if (argv[0] === 'cd') {
|
|
@@ -3092,14 +3166,14 @@ export function parseCdPrefixedEcCommand(input) {
|
|
|
3092
3166
|
* 2. `ec ... 2>&1 | head` 这类已有受控过滤器(bounded-output)
|
|
3093
3167
|
* 两者都直接产出 argv 交给运行器,不再经 shell。其它一律返回 null。
|
|
3094
3168
|
*/
|
|
3095
|
-
function parseEcTail(segment) {
|
|
3096
|
-
const literal = parseLiteralShellArgv(segment);
|
|
3169
|
+
function parseEcTail(segment, options) {
|
|
3170
|
+
const literal = parseLiteralShellArgv(segment, { posixShell: options.posixShell });
|
|
3097
3171
|
// 归一化后再判首元素:`ecmsg ...` 等价于 `ec msg ...`,必须与 ec 同权进审批链。
|
|
3098
3172
|
// 返回的 argv 也必须是归一化后的形态,否则审批哈希与 daemon 侧解析会错位。
|
|
3099
3173
|
if (literal && literal.length > 0 && normalizeEvolcoreCommandArgv(literal)[0] === 'ec') {
|
|
3100
3174
|
return { argv: normalizeEvolcoreCommandArgv(literal), mergeStderr: false };
|
|
3101
3175
|
}
|
|
3102
|
-
const bounded = parseBoundedOutputShellCommand(segment);
|
|
3176
|
+
const bounded = parseBoundedOutputShellCommand(segment, options);
|
|
3103
3177
|
if (bounded && normalizeEvolcoreCommandArgv(bounded.argv)[0] === 'ec') {
|
|
3104
3178
|
return { ...bounded, argv: normalizeEvolcoreCommandArgv(bounded.argv) };
|
|
3105
3179
|
}
|
|
@@ -3137,12 +3211,22 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3137
3211
|
}
|
|
3138
3212
|
const stringCarrier = resolveCodexShellCarrierString(stripped);
|
|
3139
3213
|
if (stringCarrier) {
|
|
3214
|
+
if (options.posixShell === 'zsh') {
|
|
3215
|
+
// Only the app-server's outer carrier is supported. Recognize nested
|
|
3216
|
+
// EC intent for an explicit denial without granting a nested shell.
|
|
3217
|
+
return hasNestedZshEcIntent(stringCarrier.command)
|
|
3218
|
+
? { kind: 'composite', issue: 'shell-composition' }
|
|
3219
|
+
: { kind: 'none' };
|
|
3220
|
+
}
|
|
3140
3221
|
const nested = parseCodexCarrierCommand(stringCarrier, parseOptions);
|
|
3141
3222
|
if (nested.ok && nested.argv[0] === 'ec')
|
|
3142
3223
|
return { kind: 'literal' };
|
|
3143
3224
|
if (!nested.ok && (hasCarrierEcCommandPrefix(stringCarrier.command, stringCarrier.dialect)
|
|
3144
3225
|
|| (stringCarrier.dialect === 'powershell' && hasPowerShellCredentialAssignment(stringCarrier.command)))) {
|
|
3145
|
-
return {
|
|
3226
|
+
return {
|
|
3227
|
+
kind: 'composite', issue: nested.issue,
|
|
3228
|
+
...(nested.shellTrustFailure ? { shellTrustFailure: nested.shellTrustFailure } : {}),
|
|
3229
|
+
};
|
|
3146
3230
|
}
|
|
3147
3231
|
return { kind: 'none' };
|
|
3148
3232
|
}
|
|
@@ -3150,6 +3234,11 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3150
3234
|
if (literal.ok) {
|
|
3151
3235
|
if (normalizeEvolcoreCommandArgv(literal.argv)[0] === 'ec')
|
|
3152
3236
|
return { kind: 'literal' };
|
|
3237
|
+
if (options.posixShell === 'zsh' && literal.argv[0] === 'eval') {
|
|
3238
|
+
return hasNestedZshEcIntent(literal.argv.slice(1).join(' '))
|
|
3239
|
+
? { kind: 'composite', issue: 'shell-composition' }
|
|
3240
|
+
: { kind: 'none' };
|
|
3241
|
+
}
|
|
3153
3242
|
const carrier = resolveCodexShellCarrierArgv(literal.argv);
|
|
3154
3243
|
if (carrier !== undefined) {
|
|
3155
3244
|
const nested = parseCodexCarrierCommand(carrier, parseOptions);
|
|
@@ -3157,7 +3246,10 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3157
3246
|
return { kind: 'literal' };
|
|
3158
3247
|
if (!nested.ok && (hasCarrierEcCommandPrefix(carrier.command, carrier.dialect)
|
|
3159
3248
|
|| (carrier.dialect === 'powershell' && hasPowerShellCredentialAssignment(carrier.command)))) {
|
|
3160
|
-
return {
|
|
3249
|
+
return {
|
|
3250
|
+
kind: 'composite', issue: nested.issue,
|
|
3251
|
+
...(nested.shellTrustFailure ? { shellTrustFailure: nested.shellTrustFailure } : {}),
|
|
3252
|
+
};
|
|
3161
3253
|
}
|
|
3162
3254
|
}
|
|
3163
3255
|
const malformedCmdBody = extractCodexCmdCarrierBody(stripped);
|
|
@@ -3184,7 +3276,7 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3184
3276
|
}
|
|
3185
3277
|
const boundedOutput = options.dialect === 'powershell' || options.dialect === 'cmd'
|
|
3186
3278
|
? null
|
|
3187
|
-
: parseBoundedOutputShellCommand(stripped);
|
|
3279
|
+
: parseBoundedOutputShellCommand(stripped, parseOptions);
|
|
3188
3280
|
if (boundedOutput && boundedOutput.argv[0] === 'ec') {
|
|
3189
3281
|
return { kind: 'bounded-output', command: boundedOutput };
|
|
3190
3282
|
}
|
|
@@ -3192,7 +3284,7 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3192
3284
|
// 只放宽前缀,ec 段仍走完整的字面量解析。
|
|
3193
3285
|
const cdPrefixed = options.dialect === 'powershell' || options.dialect === 'cmd'
|
|
3194
3286
|
? null
|
|
3195
|
-
: parseCdPrefixedEcCommand(stripped);
|
|
3287
|
+
: parseCdPrefixedEcCommand(stripped, parseOptions);
|
|
3196
3288
|
if (cdPrefixed)
|
|
3197
3289
|
return { kind: 'cd-prefixed', command: cdPrefixed.command, cwd: cdPrefixed.cwd };
|
|
3198
3290
|
// Only a command-boundary prefix is enough to preserve a useful syntax
|
|
@@ -3234,9 +3326,30 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3234
3326
|
: resolveCodexShellCarrierString(rawCommand);
|
|
3235
3327
|
const command = carrier?.command ?? rawCommand;
|
|
3236
3328
|
const dialect = carrier?.dialect ?? options.dialect;
|
|
3237
|
-
const parseOptions = {
|
|
3238
|
-
|
|
3239
|
-
|
|
3329
|
+
const parseOptions = {
|
|
3330
|
+
...options,
|
|
3331
|
+
...(dialect ? { dialect } : {}),
|
|
3332
|
+
...(carrier?.posixShell ? { posixShell: carrier.posixShell } : {}),
|
|
3333
|
+
};
|
|
3334
|
+
const intent = classifyEvolcoreShellCommand(command, { ...parseOptions, verifyShellExecutable: false });
|
|
3335
|
+
// Ordinary shell commands do not request the privileged EC path. Their
|
|
3336
|
+
// approval and filesystem rules must not depend on EC carrier signatures.
|
|
3337
|
+
const ecParseOptions = {
|
|
3338
|
+
...parseOptions,
|
|
3339
|
+
verifyShellExecutable: options.verifyShellExecutable === true
|
|
3340
|
+
&& (intent.kind !== 'none'
|
|
3341
|
+
|| carrier?.dialect === 'powershell' && hasPowerShellCredentialAssignment(command)),
|
|
3342
|
+
};
|
|
3343
|
+
const classification = ecParseOptions.verifyShellExecutable
|
|
3344
|
+
? classifyEvolcoreShellCommand(command, ecParseOptions) : intent;
|
|
3345
|
+
const parsed = carrier
|
|
3346
|
+
? parseCodexCarrierCommand(carrier, ecParseOptions)
|
|
3347
|
+
: parseCodexToolCommand(input, ecParseOptions);
|
|
3348
|
+
// Validate the outer carrier before accepting a bounded-output rewrite too.
|
|
3349
|
+
if (!parsed.ok && parsed.issue === 'untrusted-shell')
|
|
3350
|
+
return { kind: 'invalid', failure: parsed };
|
|
3351
|
+
if (!carrier?.parseFailure
|
|
3352
|
+
&& (classification.kind === 'bounded-output' || classification.kind === 'cd-prefixed')) {
|
|
3240
3353
|
if (normalizeEvolcoreCommandArgv(classification.command.argv)[0] !== 'ec')
|
|
3241
3354
|
return { kind: 'not-ec' };
|
|
3242
3355
|
const spec = buildCanonicalEvolcoreExecutionSpec({
|
|
@@ -3248,9 +3361,6 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3248
3361
|
});
|
|
3249
3362
|
return { kind: 'ec', spec };
|
|
3250
3363
|
}
|
|
3251
|
-
const parsed = carrier
|
|
3252
|
-
? parseCodexCarrierCommand(carrier, parseOptions)
|
|
3253
|
-
: parseCodexToolCommand(input, parseOptions);
|
|
3254
3364
|
if (parsed.ok && normalizeEvolcoreCommandArgv(parsed.argv)[0] === 'ec') {
|
|
3255
3365
|
const spec = buildCanonicalEvolcoreExecutionSpec({
|
|
3256
3366
|
argv: parsed.argv,
|
|
@@ -3263,9 +3373,16 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3263
3373
|
};
|
|
3264
3374
|
}
|
|
3265
3375
|
if (classification.kind === 'composite')
|
|
3266
|
-
return {
|
|
3267
|
-
|
|
3376
|
+
return {
|
|
3377
|
+
kind: 'invalid',
|
|
3378
|
+
failure: parsed.ok
|
|
3379
|
+
? parseFailure(classification.issue, command, 0, 0, dialect ?? 'posix')
|
|
3380
|
+
: parsed,
|
|
3381
|
+
};
|
|
3382
|
+
if (!parsed.ok && (hasEcCommandPrefix(command, dialect)
|
|
3383
|
+
|| carrier?.dialect === 'powershell' && hasPowerShellCredentialAssignment(command))) {
|
|
3268
3384
|
return { kind: 'invalid', failure: parsed };
|
|
3385
|
+
}
|
|
3269
3386
|
return { kind: 'not-ec' };
|
|
3270
3387
|
}
|
|
3271
3388
|
function isDeterministicFilePath(value) {
|
|
@@ -3308,8 +3425,20 @@ const PROACTIVE_SEND_VALUE_FLAGS = new Set([
|
|
|
3308
3425
|
'--check-every', '--trigger-prompt', '--return', '--timeout',
|
|
3309
3426
|
]);
|
|
3310
3427
|
const PROACTIVE_SEND_BOOLEAN_FLAGS = new Set([
|
|
3311
|
-
'--
|
|
3428
|
+
'--mention-all',
|
|
3312
3429
|
]);
|
|
3430
|
+
/**
|
|
3431
|
+
* 三态取值选项:`--encrypt yes|no|auto`,必须带取值;不写该参数才是默认 `auto`。
|
|
3432
|
+
*
|
|
3433
|
+
* 必须单独成一类而不是并进取值表:并进取值表会让裸 `--encrypt` 因缺值被判失败,
|
|
3434
|
+
* 并进布尔表则会把 `--encrypt yes` 的 `yes` 读成正文,和 `--payload-file`
|
|
3435
|
+
* 撞成正文冲突——那正是文档示例被判违规、重试后触发熔断的原因。
|
|
3436
|
+
*/
|
|
3437
|
+
const PROACTIVE_SEND_TRISTATE_FLAGS = new Set([
|
|
3438
|
+
'--encrypt',
|
|
3439
|
+
]);
|
|
3440
|
+
/** `--encrypt` 的合法取值,与 send-options 的 ENCRYPT_MODES 同口径。 */
|
|
3441
|
+
const PROACTIVE_ENCRYPT_MODES = new Set(['yes', 'no', 'auto']);
|
|
3313
3442
|
const SEND_CONTENT_VALUE_FLAGS = new Set([
|
|
3314
3443
|
'--payload', '--title', '--description', '--text', '--transcript', '--handoff-context',
|
|
3315
3444
|
]);
|
|
@@ -3370,6 +3499,13 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
|
|
|
3370
3499
|
endOfOptions = true;
|
|
3371
3500
|
continue;
|
|
3372
3501
|
}
|
|
3502
|
+
if (PROACTIVE_SEND_TRISTATE_FLAGS.has(value)) {
|
|
3503
|
+
// 三态选项的取值不是正文:`--encrypt yes` 的 `yes` 必须和 flag 一起跳过。
|
|
3504
|
+
const next = argv[index + 1];
|
|
3505
|
+
if (next !== undefined && PROACTIVE_ENCRYPT_MODES.has(next))
|
|
3506
|
+
index++;
|
|
3507
|
+
continue;
|
|
3508
|
+
}
|
|
3373
3509
|
if (PROACTIVE_SEND_BOOLEAN_FLAGS.has(value))
|
|
3374
3510
|
continue;
|
|
3375
3511
|
if (PROACTIVE_SEND_VALUE_FLAGS.has(value)) {
|
|
@@ -3411,6 +3547,15 @@ export function isReadOnlyEcCommand(toolName, input) {
|
|
|
3411
3547
|
return false;
|
|
3412
3548
|
if (argv.includes('--help') || argv.includes('-h'))
|
|
3413
3549
|
return true;
|
|
3550
|
+
if (argv[1] === 'ability' && argv[2] === 'remote') {
|
|
3551
|
+
try {
|
|
3552
|
+
const command = parseRemoteCommand(argv.slice(1));
|
|
3553
|
+
return ['list', 'info', 'devices', 'result'].includes(command.action) || command.action === 'call' && command.options['dry-run'] === 'true';
|
|
3554
|
+
}
|
|
3555
|
+
catch {
|
|
3556
|
+
return false;
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3414
3559
|
const head = `${argv[1] ?? ''}.${argv[2] ?? ''}`;
|
|
3415
3560
|
return READ_ONLY_SUBCOMMANDS.has(head);
|
|
3416
3561
|
}
|
|
@@ -3418,9 +3563,9 @@ export function isReadOnlyEcCommand(toolName, input) {
|
|
|
3418
3563
|
export function containsUnresolvedManagedTmpDirReference(argv) {
|
|
3419
3564
|
return argv.some(value => /(?:\\\$TMPDIR|\\\$\{TMPDIR\})/i.test(value));
|
|
3420
3565
|
}
|
|
3421
|
-
function
|
|
3566
|
+
function diagnoseProactiveSendPayload(argv, scope, bodyStart = 5, options = {}) {
|
|
3422
3567
|
if (!argv || argv[0] !== 'ec' || argv[1] !== scope || argv[2] !== 'send')
|
|
3423
|
-
return false;
|
|
3568
|
+
return { ok: false, problem: 'not_send_command' };
|
|
3424
3569
|
const positionals = [];
|
|
3425
3570
|
const modes = new Map();
|
|
3426
3571
|
let endOfOptions = false;
|
|
@@ -3434,6 +3579,16 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5, options =
|
|
|
3434
3579
|
endOfOptions = true;
|
|
3435
3580
|
continue;
|
|
3436
3581
|
}
|
|
3582
|
+
if (PROACTIVE_SEND_TRISTATE_FLAGS.has(value)) {
|
|
3583
|
+
// 三态取值:必须紧跟 yes|no|auto。裸写是参数错误,不能落到下面的
|
|
3584
|
+
// 「未知 --flag」分支——那里会把下一个词当正文吞掉,判定就失真了。
|
|
3585
|
+
const next = argv[index + 1];
|
|
3586
|
+
if (next === undefined || !PROACTIVE_ENCRYPT_MODES.has(next)) {
|
|
3587
|
+
return { ok: false, problem: 'encrypt_mode_invalid', detail: value };
|
|
3588
|
+
}
|
|
3589
|
+
index++;
|
|
3590
|
+
continue;
|
|
3591
|
+
}
|
|
3437
3592
|
if (PROACTIVE_SEND_BOOLEAN_FLAGS.has(value))
|
|
3438
3593
|
continue;
|
|
3439
3594
|
if (!PROACTIVE_SEND_VALUE_FLAGS.has(value)) {
|
|
@@ -3449,68 +3604,120 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5, options =
|
|
|
3449
3604
|
}
|
|
3450
3605
|
const operand = argv[++index];
|
|
3451
3606
|
if (operand === undefined || operand.startsWith('--'))
|
|
3452
|
-
return false;
|
|
3607
|
+
return { ok: false, problem: 'missing_operand', detail: value };
|
|
3453
3608
|
if (value === '--file' || value === '--text-from-file') {
|
|
3454
3609
|
// 文件附件同样是向对端的意图表达:它和正文一起出现时不改变语义,
|
|
3455
3610
|
// 单独出现时也把内容真实投递给了对端。只保留路径的确定性校验。
|
|
3456
|
-
if (!options.allowAttachment
|
|
3457
|
-
return false;
|
|
3611
|
+
if (!options.allowAttachment)
|
|
3612
|
+
return { ok: false, problem: 'attachment_not_allowed', detail: value };
|
|
3613
|
+
if (!isDeterministicFilePath(operand))
|
|
3614
|
+
return { ok: false, problem: 'file_path_uncertain', detail: operand };
|
|
3458
3615
|
if (modes.has('file'))
|
|
3459
|
-
return false;
|
|
3616
|
+
return { ok: false, problem: 'duplicate_file', detail: value };
|
|
3460
3617
|
modes.set('file', operand);
|
|
3461
3618
|
continue;
|
|
3462
3619
|
}
|
|
3463
|
-
if (value === '--app'
|
|
3464
|
-
return false;
|
|
3620
|
+
if (value === '--app')
|
|
3621
|
+
return { ok: false, problem: 'unsupported_app_option', detail: value };
|
|
3622
|
+
if (value === '--aun-path')
|
|
3623
|
+
return { ok: false, problem: 'unsupported_aun_path_option', detail: value };
|
|
3465
3624
|
if (value === '--format' && operand !== 'json')
|
|
3466
|
-
return false;
|
|
3625
|
+
return { ok: false, problem: 'format_not_json', detail: operand };
|
|
3467
3626
|
if (value === '--link') {
|
|
3468
|
-
if (scope !== 'msg'
|
|
3469
|
-
return false;
|
|
3627
|
+
if (scope !== 'msg')
|
|
3628
|
+
return { ok: false, problem: 'link_not_private', detail: value };
|
|
3629
|
+
if (modes.has('link'))
|
|
3630
|
+
return { ok: false, problem: 'duplicate_link', detail: value };
|
|
3470
3631
|
modes.set('link', operand);
|
|
3471
3632
|
}
|
|
3472
3633
|
if (value === '--payload') {
|
|
3473
3634
|
if (modes.has('payload'))
|
|
3474
|
-
return false;
|
|
3635
|
+
return { ok: false, problem: 'duplicate_payload', detail: value };
|
|
3475
3636
|
modes.set('payload', operand);
|
|
3476
3637
|
}
|
|
3477
3638
|
if (value === '--payload-file') {
|
|
3478
|
-
if (scope !== 'msg'
|
|
3479
|
-
return false;
|
|
3639
|
+
if (scope !== 'msg')
|
|
3640
|
+
return { ok: false, problem: 'payload_file_not_private', detail: value };
|
|
3641
|
+
if (modes.has('payload-file'))
|
|
3642
|
+
return { ok: false, problem: 'duplicate_payload_file', detail: value };
|
|
3643
|
+
if (!isManagedPayloadFilePath(operand))
|
|
3644
|
+
return { ok: false, problem: 'payload_file_path_uncertain', detail: operand };
|
|
3480
3645
|
modes.set('payload-file', operand);
|
|
3481
3646
|
}
|
|
3482
3647
|
}
|
|
3483
3648
|
// 正文、链接、payload、payload-file 之间互斥;文件附件允许和正文一起出现。
|
|
3484
3649
|
const contentModes = [...modes.keys()].filter(key => key !== 'file');
|
|
3485
3650
|
if (contentModes.length > 1)
|
|
3486
|
-
return false;
|
|
3487
|
-
if (contentModes.length > 0 && positionals.length > 0)
|
|
3488
|
-
return false;
|
|
3489
|
-
|
|
3490
|
-
|
|
3651
|
+
return { ok: false, problem: 'mode_conflict', detail: contentModes.map(key => `--${key}`).join(' + ') };
|
|
3652
|
+
if (contentModes.length > 0 && positionals.length > 0) {
|
|
3653
|
+
return { ok: false, problem: 'body_with_content_mode', detail: `--${contentModes[0]} + 位置正文 "${positionals.join(' ')}"` };
|
|
3654
|
+
}
|
|
3655
|
+
if (contentModes.length > 0 && modes.has('file')) {
|
|
3656
|
+
return { ok: false, problem: 'file_with_content_mode', detail: `--${contentModes[0]} + --file` };
|
|
3657
|
+
}
|
|
3491
3658
|
if (modes.has('link')) {
|
|
3492
3659
|
try {
|
|
3493
3660
|
const url = new URL(modes.get('link'));
|
|
3494
|
-
return url.protocol === 'http:' || url.protocol === 'https:'
|
|
3661
|
+
return url.protocol === 'http:' || url.protocol === 'https:'
|
|
3662
|
+
? { ok: true }
|
|
3663
|
+
: { ok: false, problem: 'link_not_http', detail: modes.get('link') };
|
|
3495
3664
|
}
|
|
3496
3665
|
catch {
|
|
3497
|
-
return false;
|
|
3666
|
+
return { ok: false, problem: 'link_not_http', detail: modes.get('link') };
|
|
3498
3667
|
}
|
|
3499
3668
|
}
|
|
3500
3669
|
if (modes.has('payload')) {
|
|
3501
3670
|
try {
|
|
3502
3671
|
parseJsonObjectArgument(modes.get('payload'));
|
|
3503
|
-
return true;
|
|
3672
|
+
return { ok: true };
|
|
3504
3673
|
}
|
|
3505
3674
|
catch {
|
|
3506
|
-
return false;
|
|
3675
|
+
return { ok: false, problem: 'payload_not_object', detail: modes.get('payload') };
|
|
3507
3676
|
}
|
|
3508
3677
|
}
|
|
3509
3678
|
if (modes.has('payload-file'))
|
|
3510
|
-
return true;
|
|
3679
|
+
return { ok: true };
|
|
3511
3680
|
if (modes.has('file'))
|
|
3512
|
-
return true;
|
|
3513
|
-
return positionals.join(' ').length > 0;
|
|
3681
|
+
return { ok: true };
|
|
3682
|
+
return positionals.join(' ').length > 0 ? { ok: true } : { ok: false, problem: 'empty_body' };
|
|
3683
|
+
}
|
|
3684
|
+
function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5, options = {}) {
|
|
3685
|
+
return diagnoseProactiveSendPayload(argv, scope, bodyStart, options).ok;
|
|
3686
|
+
}
|
|
3687
|
+
/** 发送内容的合法写法清单;简化式与完整式诊断共用,避免两处枚举漂移。 */
|
|
3688
|
+
const SEND_CONTENT_FORMS_HINT = '正文不能为空(可用位置正文、--file、--text-from-file、--payload 或 --payload-file 之一);'
|
|
3689
|
+
+ '--link 的值必须是 http(s) URL;--payload 的值必须是 JSON 对象;'
|
|
3690
|
+
+ '--payload-file 的值必须是 $TMPDIR 或项目目录下的确定文件路径;'
|
|
3691
|
+
+ '--file/--text-from-file 的值必须是确定的文件路径。';
|
|
3692
|
+
const SEND_PAYLOAD_PROBLEM_HINTS = {
|
|
3693
|
+
not_send_command: '不是发送命令。',
|
|
3694
|
+
missing_operand: '参数缺少取值:{detail} 后面必须紧跟一个值。',
|
|
3695
|
+
attachment_not_allowed: '当前发送场景不允许带附件:{detail}。',
|
|
3696
|
+
file_path_uncertain: '附件路径不确定或缺少引号:{detail}。请用引号包裹完整路径。',
|
|
3697
|
+
duplicate_file: '一次只能带一个附件,--file/--text-from-file 重复出现:{detail}。',
|
|
3698
|
+
unsupported_app_option: '发送时不能用 --app(非托管拉取入口):{detail}。',
|
|
3699
|
+
unsupported_aun_path_option: '发送时不能用 --aun-path:{detail}。',
|
|
3700
|
+
format_not_json: '--format 只接受 json,收到:{detail}。',
|
|
3701
|
+
link_not_private: '--link 只能用于私聊发送:{detail}。',
|
|
3702
|
+
duplicate_link: '一次只能带一个 --link:{detail}。',
|
|
3703
|
+
duplicate_payload: '一次只能带一个 --payload:{detail}。',
|
|
3704
|
+
payload_file_not_private: '--payload-file 只用于私聊发送:{detail}。',
|
|
3705
|
+
duplicate_payload_file: '一次只能带一个 --payload-file:{detail}。',
|
|
3706
|
+
payload_file_path_uncertain: '--payload-file 的路径不确定:{detail}。必须是 $TMPDIR 或项目目录下的确定文件路径,不能包含未解析的变量或通配符。',
|
|
3707
|
+
mode_conflict: '发送内容写法互相冲突:{detail}。正文、--link、--payload、--payload-file 只能选一种。',
|
|
3708
|
+
body_with_content_mode: '位置正文和内容参数不能同时使用:{detail}。去掉位置正文,或改用其中一种。',
|
|
3709
|
+
file_with_content_mode: '附件和内容参数不能同时使用:{detail}。正文或 payload 与 --file 只能选一种。',
|
|
3710
|
+
link_not_http: '--link 必须是 http(s) URL,收到:{detail}。',
|
|
3711
|
+
payload_not_object: '--payload 的值必须是 JSON 对象,收到:{detail}。',
|
|
3712
|
+
empty_body: '没有可发送的内容:正文为空,也没有给出 --file/--text-from-file/--payload/--payload-file/--link。',
|
|
3713
|
+
encrypt_mode_invalid: '--encrypt 只接受 yes|no|auto,必须带取值。',
|
|
3714
|
+
};
|
|
3715
|
+
function describeSendPayloadProblem(diagnosis) {
|
|
3716
|
+
if (diagnosis.problem) {
|
|
3717
|
+
const template = SEND_PAYLOAD_PROBLEM_HINTS[diagnosis.problem];
|
|
3718
|
+
return `发送命令被拒:${template.replace('{detail}', diagnosis.detail ?? '')}`;
|
|
3719
|
+
}
|
|
3720
|
+
return `发送命令被拒:${SEND_CONTENT_FORMS_HINT}`;
|
|
3514
3721
|
}
|
|
3515
3722
|
function parseEvolcoreSendArgv(argv) {
|
|
3516
3723
|
if (!argv || argv[0] !== 'ec')
|
|
@@ -3641,15 +3848,18 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3641
3848
|
// 托管简化式(`ecmsg send '<正文>'`):from/to 由当前会话推断,
|
|
3642
3849
|
// 不应再按"缺少发送者与目标"给建议,只可能是发送内容或参数无效。
|
|
3643
3850
|
if (isManagedSimplifiedSend(argv)) {
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3851
|
+
const diagnosis = diagnoseProactiveSendPayload(argv, argv[1], 3, { allowAttachment: true });
|
|
3852
|
+
// 诊断通过说明内容本身合法,被拒的原因不在这一层,交给调用方按缺省处理。
|
|
3853
|
+
return diagnosis.ok ? undefined : describeSendPayloadProblem(diagnosis);
|
|
3647
3854
|
}
|
|
3648
3855
|
const scope = argv[1];
|
|
3649
3856
|
const prefix = '发送命令被拒:';
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3857
|
+
// 面向模型的推荐写法统一是 `ecmsg send`:本端恒为会话本端,不写 from;
|
|
3858
|
+
// 目标在非默认话题时用 --to。位置式 `ec msg send <from> <to>` 仍然可用,
|
|
3859
|
+
// 但只在宿主终端和历史脚本里出现,不再作为提示内容教给模型。
|
|
3860
|
+
const expectedForm = scope === 'group'
|
|
3861
|
+
? `ecmsg send ${session?.channelId ? `--to ${session.channelId}` : '(群会话内直接省略 --to)'} "<正文>"`
|
|
3862
|
+
: `ecmsg send${session?.channelId ? ` --to ${session.channelId}` : ''} "<正文>"`;
|
|
3653
3863
|
// 带 --thread 的发送走话题路由校验,允许省略 from/to;走到这里说明话题本身没解析通过。
|
|
3654
3864
|
if (sendOptionValue(argv, '--thread')) {
|
|
3655
3865
|
return `${prefix}带 --thread 的跨话题发送未通过校验——话题必须已存在于本端:话题写裸 id,`
|
|
@@ -3660,14 +3870,14 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3660
3870
|
// 私聊/群聊用错了 scope。
|
|
3661
3871
|
if (session?.chatType && (session.chatType === 'group') !== (scope === 'group')) {
|
|
3662
3872
|
return session.chatType === 'group'
|
|
3663
|
-
? `${prefix}
|
|
3664
|
-
+
|
|
3665
|
-
: `${prefix}当前是私聊会话,回复用 ${expectedForm}
|
|
3873
|
+
? `${prefix}当前是群聊会话,公开回复直接写 ecmsg send "<正文>"(群会话里即群内公开发送);`
|
|
3874
|
+
+ `要私下联系本条消息的发送者,用 ecmsg send --to <对方AID> "<正文>"。`
|
|
3875
|
+
: `${prefix}当前是私聊会话,回复用 ${expectedForm};群回复在群会话里同样用 ecmsg send。`;
|
|
3666
3876
|
}
|
|
3667
3877
|
const from = argv[3];
|
|
3668
3878
|
const to = argv[4];
|
|
3669
3879
|
const fullFormHint = `${prefix}缺少发送者与目标。完整形式为 ${expectedForm};`
|
|
3670
|
-
+
|
|
3880
|
+
+ `普通回复直接写 ecmsg send '<正文>'(省略 from/to 即发往当前会话对端);跨话题发送才需要 --thread。`;
|
|
3671
3881
|
if (!from || from.startsWith('--')) {
|
|
3672
3882
|
return fullFormHint;
|
|
3673
3883
|
}
|
|
@@ -3675,7 +3885,7 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3675
3885
|
return looksLikeAid(from)
|
|
3676
3886
|
? fullFormHint
|
|
3677
3887
|
: `${prefix}缺少发送者与目标("${from}" 是正文而非 AID)。完整形式为 ${expectedForm};`
|
|
3678
|
-
+
|
|
3888
|
+
+ `普通回复直接写 ecmsg send '<正文>'(省略 from/to 即发往当前会话对端);跨话题发送才需要 --thread。`;
|
|
3679
3889
|
}
|
|
3680
3890
|
if (!looksLikeAid(from) || !looksLikeAid(to)) {
|
|
3681
3891
|
return `${prefix}发送者/目标不是合法 AID(收到 from="${from}" to="${to}")。完整形式为 ${expectedForm}。`;
|
|
@@ -3687,9 +3897,10 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3687
3897
|
return `${prefix}目标必须是当前会话${scope === 'group' ? '群' : '对端'} ${session.channelId},命令里写的是 ${to};`
|
|
3688
3898
|
+ `要联系其他对象请走 --thread 跨话题发送(ec thread list <对方AID> 选中话题后加 --check-every)。`;
|
|
3689
3899
|
}
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3900
|
+
const payloadDiagnosis = diagnoseProactiveSendPayload(argv, scope, 5, { allowAttachment: true });
|
|
3901
|
+
if (payloadDiagnosis.ok)
|
|
3902
|
+
return undefined;
|
|
3903
|
+
return `${prefix}发送者与目标正确,但${describeSendPayloadProblem(payloadDiagnosis).replace(/^发送命令被拒:/, '')}`;
|
|
3693
3904
|
}
|
|
3694
3905
|
/** 与 CLI `isValidAid` 同一规则;parser 不依赖 AID 模块,避免引入身份存储副作用。 */
|
|
3695
3906
|
function looksLikeAid(value) {
|