evolcore 0.0.49 → 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 +64 -1
- 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 +280 -6
- 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 +4 -1
- 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 +29 -1
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +537 -189
- 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/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +23 -4
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +1 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +11 -9
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +17 -8
- package/dist/config/config-manager.js +86 -46
- 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 +99 -16
- package/dist/config/providers-management.js +35 -19
- package/dist/config/resolved-config-op.js +1 -42
- 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/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +50 -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 +15 -0
- 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 +91 -72
- package/dist/core/command/menu-protocol.js +5 -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/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 +2 -1
- package/dist/core/daemon-lifecycle.js +13 -5
- package/dist/core/evolagent-registry.js +12 -7
- 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 +4 -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 +98 -21
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/message-bridge.js +105 -6
- package/dist/core/message/message-log.js +8 -0
- package/dist/core/message/message-queue.js +5 -3
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +23 -8
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +4 -0
- package/dist/core/permission/ec-command-parser.js +182 -58
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +9 -2
- package/dist/core/permission/tool-policy.js +21 -9
- 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/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 +52 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/eck/kit-renderer.js +2 -1
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/index.js +116 -41
- package/dist/ipc.js +58 -2
- 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 +176 -18
- package/dist/services/ipc-operation.js +204 -44
- package/dist/services/script-runner.js +515 -83
- package/dist/services/validation.js +109 -4
- 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 -20
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +73 -0
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- 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/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 +7 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +20 -3
- package/kits/docs/evolcore/config.md +1 -1
- 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 +68 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +21 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -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.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 +13 -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 +12 -5
- 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 +1 -1
- 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/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +4 -3
- 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 -129
- package/kits/templates/system-fragments/venue.md +16 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +37 -23
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +16 -4
- package/scripts/agent-template/shared/team-schema.json +20 -4
- package/scripts/agent-template/shared/template-contract.mjs +53 -13
- package/scripts/agent-template/shared/template-package.mjs +90 -26
- package/scripts/agent-template/shared/template-runtime.mjs +111 -1
- package/scripts/agent-template/shared/template.mjs +65 -7
- package/scripts/agent-template/team-pack.mjs +89 -33
- 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
|
|
@@ -917,7 +918,7 @@ const INLINE_TEXT_FLAGS = {
|
|
|
917
918
|
const MESSAGE_POSITIONAL_FLAGS = new Set([
|
|
918
919
|
'--file', '--payload', '--payload-file', '--as', '--content-type', '--text', '--transcript',
|
|
919
920
|
'--thread', '--title', '--description', '--text-from-file',
|
|
920
|
-
'--handoff-context', '--aun-path', '--app', '--format', '--encrypt',
|
|
921
|
+
'--handoff-context', '--aun-path', '--app', '--format', '--encrypt',
|
|
921
922
|
'--return', '--timeout',
|
|
922
923
|
]);
|
|
923
924
|
/** Decode the EC inline text contract exactly once, after shell parsing. */
|
|
@@ -1039,7 +1040,7 @@ function canonicalizeCommaOnlyFlags(argv, flags) {
|
|
|
1039
1040
|
index++;
|
|
1040
1041
|
}
|
|
1041
1042
|
}
|
|
1042
|
-
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']);
|
|
1043
1044
|
function normalizeWindowsFilePath(value) {
|
|
1044
1045
|
if (process.platform !== 'win32' || !/^[A-Za-z]:[\\/]/u.test(value))
|
|
1045
1046
|
return value;
|
|
@@ -1049,7 +1050,7 @@ function canonicalizeLocalFilePathFlags(argv) {
|
|
|
1049
1050
|
for (let index = 2; index < argv.length; index++) {
|
|
1050
1051
|
if (argv[index] === '--')
|
|
1051
1052
|
break;
|
|
1052
|
-
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);
|
|
1053
1054
|
if (inline) {
|
|
1054
1055
|
argv[index] = `${inline[1]}=${normalizeWindowsFilePath(inline[2])}`;
|
|
1055
1056
|
continue;
|
|
@@ -1218,12 +1219,20 @@ function unwrapPowerShellCredentialPrefix(command) {
|
|
|
1218
1219
|
}
|
|
1219
1220
|
export function parseCodexCarrierCommand(carrier, options = {}) {
|
|
1220
1221
|
if (options.verifyShellExecutable) {
|
|
1221
|
-
if (!carrier.executable) {
|
|
1222
|
-
return parseFailure('untrusted-shell', carrier.command, 0, 0, carrier.dialect);
|
|
1223
|
-
}
|
|
1224
1222
|
const kind = carrier.dialect === 'posix' ? 'bash' : carrier.dialect;
|
|
1225
|
-
|
|
1226
|
-
|
|
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
|
+
};
|
|
1227
1236
|
}
|
|
1228
1237
|
}
|
|
1229
1238
|
if (carrier.parseFailure)
|
|
@@ -3214,7 +3223,10 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3214
3223
|
return { kind: 'literal' };
|
|
3215
3224
|
if (!nested.ok && (hasCarrierEcCommandPrefix(stringCarrier.command, stringCarrier.dialect)
|
|
3216
3225
|
|| (stringCarrier.dialect === 'powershell' && hasPowerShellCredentialAssignment(stringCarrier.command)))) {
|
|
3217
|
-
return {
|
|
3226
|
+
return {
|
|
3227
|
+
kind: 'composite', issue: nested.issue,
|
|
3228
|
+
...(nested.shellTrustFailure ? { shellTrustFailure: nested.shellTrustFailure } : {}),
|
|
3229
|
+
};
|
|
3218
3230
|
}
|
|
3219
3231
|
return { kind: 'none' };
|
|
3220
3232
|
}
|
|
@@ -3234,7 +3246,10 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3234
3246
|
return { kind: 'literal' };
|
|
3235
3247
|
if (!nested.ok && (hasCarrierEcCommandPrefix(carrier.command, carrier.dialect)
|
|
3236
3248
|
|| (carrier.dialect === 'powershell' && hasPowerShellCredentialAssignment(carrier.command)))) {
|
|
3237
|
-
return {
|
|
3249
|
+
return {
|
|
3250
|
+
kind: 'composite', issue: nested.issue,
|
|
3251
|
+
...(nested.shellTrustFailure ? { shellTrustFailure: nested.shellTrustFailure } : {}),
|
|
3252
|
+
};
|
|
3238
3253
|
}
|
|
3239
3254
|
}
|
|
3240
3255
|
const malformedCmdBody = extractCodexCmdCarrierBody(stripped);
|
|
@@ -3316,7 +3331,23 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3316
3331
|
...(dialect ? { dialect } : {}),
|
|
3317
3332
|
...(carrier?.posixShell ? { posixShell: carrier.posixShell } : {}),
|
|
3318
3333
|
};
|
|
3319
|
-
const
|
|
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 };
|
|
3320
3351
|
if (!carrier?.parseFailure
|
|
3321
3352
|
&& (classification.kind === 'bounded-output' || classification.kind === 'cd-prefixed')) {
|
|
3322
3353
|
if (normalizeEvolcoreCommandArgv(classification.command.argv)[0] !== 'ec')
|
|
@@ -3330,9 +3361,6 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3330
3361
|
});
|
|
3331
3362
|
return { kind: 'ec', spec };
|
|
3332
3363
|
}
|
|
3333
|
-
const parsed = carrier
|
|
3334
|
-
? parseCodexCarrierCommand(carrier, parseOptions)
|
|
3335
|
-
: parseCodexToolCommand(input, parseOptions);
|
|
3336
3364
|
if (parsed.ok && normalizeEvolcoreCommandArgv(parsed.argv)[0] === 'ec') {
|
|
3337
3365
|
const spec = buildCanonicalEvolcoreExecutionSpec({
|
|
3338
3366
|
argv: parsed.argv,
|
|
@@ -3351,8 +3379,10 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3351
3379
|
? parseFailure(classification.issue, command, 0, 0, dialect ?? 'posix')
|
|
3352
3380
|
: parsed,
|
|
3353
3381
|
};
|
|
3354
|
-
if (!parsed.ok && hasEcCommandPrefix(command, dialect)
|
|
3382
|
+
if (!parsed.ok && (hasEcCommandPrefix(command, dialect)
|
|
3383
|
+
|| carrier?.dialect === 'powershell' && hasPowerShellCredentialAssignment(command))) {
|
|
3355
3384
|
return { kind: 'invalid', failure: parsed };
|
|
3385
|
+
}
|
|
3356
3386
|
return { kind: 'not-ec' };
|
|
3357
3387
|
}
|
|
3358
3388
|
function isDeterministicFilePath(value) {
|
|
@@ -3395,8 +3425,20 @@ const PROACTIVE_SEND_VALUE_FLAGS = new Set([
|
|
|
3395
3425
|
'--check-every', '--trigger-prompt', '--return', '--timeout',
|
|
3396
3426
|
]);
|
|
3397
3427
|
const PROACTIVE_SEND_BOOLEAN_FLAGS = new Set([
|
|
3398
|
-
'--
|
|
3428
|
+
'--mention-all',
|
|
3399
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']);
|
|
3400
3442
|
const SEND_CONTENT_VALUE_FLAGS = new Set([
|
|
3401
3443
|
'--payload', '--title', '--description', '--text', '--transcript', '--handoff-context',
|
|
3402
3444
|
]);
|
|
@@ -3457,6 +3499,13 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
|
|
|
3457
3499
|
endOfOptions = true;
|
|
3458
3500
|
continue;
|
|
3459
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
|
+
}
|
|
3460
3509
|
if (PROACTIVE_SEND_BOOLEAN_FLAGS.has(value))
|
|
3461
3510
|
continue;
|
|
3462
3511
|
if (PROACTIVE_SEND_VALUE_FLAGS.has(value)) {
|
|
@@ -3498,6 +3547,15 @@ export function isReadOnlyEcCommand(toolName, input) {
|
|
|
3498
3547
|
return false;
|
|
3499
3548
|
if (argv.includes('--help') || argv.includes('-h'))
|
|
3500
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
|
+
}
|
|
3501
3559
|
const head = `${argv[1] ?? ''}.${argv[2] ?? ''}`;
|
|
3502
3560
|
return READ_ONLY_SUBCOMMANDS.has(head);
|
|
3503
3561
|
}
|
|
@@ -3505,9 +3563,9 @@ export function isReadOnlyEcCommand(toolName, input) {
|
|
|
3505
3563
|
export function containsUnresolvedManagedTmpDirReference(argv) {
|
|
3506
3564
|
return argv.some(value => /(?:\\\$TMPDIR|\\\$\{TMPDIR\})/i.test(value));
|
|
3507
3565
|
}
|
|
3508
|
-
function
|
|
3566
|
+
function diagnoseProactiveSendPayload(argv, scope, bodyStart = 5, options = {}) {
|
|
3509
3567
|
if (!argv || argv[0] !== 'ec' || argv[1] !== scope || argv[2] !== 'send')
|
|
3510
|
-
return false;
|
|
3568
|
+
return { ok: false, problem: 'not_send_command' };
|
|
3511
3569
|
const positionals = [];
|
|
3512
3570
|
const modes = new Map();
|
|
3513
3571
|
let endOfOptions = false;
|
|
@@ -3521,6 +3579,16 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5, options =
|
|
|
3521
3579
|
endOfOptions = true;
|
|
3522
3580
|
continue;
|
|
3523
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
|
+
}
|
|
3524
3592
|
if (PROACTIVE_SEND_BOOLEAN_FLAGS.has(value))
|
|
3525
3593
|
continue;
|
|
3526
3594
|
if (!PROACTIVE_SEND_VALUE_FLAGS.has(value)) {
|
|
@@ -3536,68 +3604,120 @@ function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5, options =
|
|
|
3536
3604
|
}
|
|
3537
3605
|
const operand = argv[++index];
|
|
3538
3606
|
if (operand === undefined || operand.startsWith('--'))
|
|
3539
|
-
return false;
|
|
3607
|
+
return { ok: false, problem: 'missing_operand', detail: value };
|
|
3540
3608
|
if (value === '--file' || value === '--text-from-file') {
|
|
3541
3609
|
// 文件附件同样是向对端的意图表达:它和正文一起出现时不改变语义,
|
|
3542
3610
|
// 单独出现时也把内容真实投递给了对端。只保留路径的确定性校验。
|
|
3543
|
-
if (!options.allowAttachment
|
|
3544
|
-
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 };
|
|
3545
3615
|
if (modes.has('file'))
|
|
3546
|
-
return false;
|
|
3616
|
+
return { ok: false, problem: 'duplicate_file', detail: value };
|
|
3547
3617
|
modes.set('file', operand);
|
|
3548
3618
|
continue;
|
|
3549
3619
|
}
|
|
3550
|
-
if (value === '--app'
|
|
3551
|
-
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 };
|
|
3552
3624
|
if (value === '--format' && operand !== 'json')
|
|
3553
|
-
return false;
|
|
3625
|
+
return { ok: false, problem: 'format_not_json', detail: operand };
|
|
3554
3626
|
if (value === '--link') {
|
|
3555
|
-
if (scope !== 'msg'
|
|
3556
|
-
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 };
|
|
3557
3631
|
modes.set('link', operand);
|
|
3558
3632
|
}
|
|
3559
3633
|
if (value === '--payload') {
|
|
3560
3634
|
if (modes.has('payload'))
|
|
3561
|
-
return false;
|
|
3635
|
+
return { ok: false, problem: 'duplicate_payload', detail: value };
|
|
3562
3636
|
modes.set('payload', operand);
|
|
3563
3637
|
}
|
|
3564
3638
|
if (value === '--payload-file') {
|
|
3565
|
-
if (scope !== 'msg'
|
|
3566
|
-
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 };
|
|
3567
3645
|
modes.set('payload-file', operand);
|
|
3568
3646
|
}
|
|
3569
3647
|
}
|
|
3570
3648
|
// 正文、链接、payload、payload-file 之间互斥;文件附件允许和正文一起出现。
|
|
3571
3649
|
const contentModes = [...modes.keys()].filter(key => key !== 'file');
|
|
3572
3650
|
if (contentModes.length > 1)
|
|
3573
|
-
return false;
|
|
3574
|
-
if (contentModes.length > 0 && positionals.length > 0)
|
|
3575
|
-
return false;
|
|
3576
|
-
|
|
3577
|
-
|
|
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
|
+
}
|
|
3578
3658
|
if (modes.has('link')) {
|
|
3579
3659
|
try {
|
|
3580
3660
|
const url = new URL(modes.get('link'));
|
|
3581
|
-
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') };
|
|
3582
3664
|
}
|
|
3583
3665
|
catch {
|
|
3584
|
-
return false;
|
|
3666
|
+
return { ok: false, problem: 'link_not_http', detail: modes.get('link') };
|
|
3585
3667
|
}
|
|
3586
3668
|
}
|
|
3587
3669
|
if (modes.has('payload')) {
|
|
3588
3670
|
try {
|
|
3589
3671
|
parseJsonObjectArgument(modes.get('payload'));
|
|
3590
|
-
return true;
|
|
3672
|
+
return { ok: true };
|
|
3591
3673
|
}
|
|
3592
3674
|
catch {
|
|
3593
|
-
return false;
|
|
3675
|
+
return { ok: false, problem: 'payload_not_object', detail: modes.get('payload') };
|
|
3594
3676
|
}
|
|
3595
3677
|
}
|
|
3596
3678
|
if (modes.has('payload-file'))
|
|
3597
|
-
return true;
|
|
3679
|
+
return { ok: true };
|
|
3598
3680
|
if (modes.has('file'))
|
|
3599
|
-
return true;
|
|
3600
|
-
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}`;
|
|
3601
3721
|
}
|
|
3602
3722
|
function parseEvolcoreSendArgv(argv) {
|
|
3603
3723
|
if (!argv || argv[0] !== 'ec')
|
|
@@ -3728,15 +3848,18 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3728
3848
|
// 托管简化式(`ecmsg send '<正文>'`):from/to 由当前会话推断,
|
|
3729
3849
|
// 不应再按"缺少发送者与目标"给建议,只可能是发送内容或参数无效。
|
|
3730
3850
|
if (isManagedSimplifiedSend(argv)) {
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3851
|
+
const diagnosis = diagnoseProactiveSendPayload(argv, argv[1], 3, { allowAttachment: true });
|
|
3852
|
+
// 诊断通过说明内容本身合法,被拒的原因不在这一层,交给调用方按缺省处理。
|
|
3853
|
+
return diagnosis.ok ? undefined : describeSendPayloadProblem(diagnosis);
|
|
3734
3854
|
}
|
|
3735
3855
|
const scope = argv[1];
|
|
3736
3856
|
const prefix = '发送命令被拒:';
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
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}` : ''} "<正文>"`;
|
|
3740
3863
|
// 带 --thread 的发送走话题路由校验,允许省略 from/to;走到这里说明话题本身没解析通过。
|
|
3741
3864
|
if (sendOptionValue(argv, '--thread')) {
|
|
3742
3865
|
return `${prefix}带 --thread 的跨话题发送未通过校验——话题必须已存在于本端:话题写裸 id,`
|
|
@@ -3747,14 +3870,14 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3747
3870
|
// 私聊/群聊用错了 scope。
|
|
3748
3871
|
if (session?.chatType && (session.chatType === 'group') !== (scope === 'group')) {
|
|
3749
3872
|
return session.chatType === 'group'
|
|
3750
|
-
? `${prefix}
|
|
3751
|
-
+
|
|
3752
|
-
: `${prefix}当前是私聊会话,回复用 ${expectedForm}
|
|
3873
|
+
? `${prefix}当前是群聊会话,公开回复直接写 ecmsg send "<正文>"(群会话里即群内公开发送);`
|
|
3874
|
+
+ `要私下联系本条消息的发送者,用 ecmsg send --to <对方AID> "<正文>"。`
|
|
3875
|
+
: `${prefix}当前是私聊会话,回复用 ${expectedForm};群回复在群会话里同样用 ecmsg send。`;
|
|
3753
3876
|
}
|
|
3754
3877
|
const from = argv[3];
|
|
3755
3878
|
const to = argv[4];
|
|
3756
3879
|
const fullFormHint = `${prefix}缺少发送者与目标。完整形式为 ${expectedForm};`
|
|
3757
|
-
+
|
|
3880
|
+
+ `普通回复直接写 ecmsg send '<正文>'(省略 from/to 即发往当前会话对端);跨话题发送才需要 --thread。`;
|
|
3758
3881
|
if (!from || from.startsWith('--')) {
|
|
3759
3882
|
return fullFormHint;
|
|
3760
3883
|
}
|
|
@@ -3762,7 +3885,7 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3762
3885
|
return looksLikeAid(from)
|
|
3763
3886
|
? fullFormHint
|
|
3764
3887
|
: `${prefix}缺少发送者与目标("${from}" 是正文而非 AID)。完整形式为 ${expectedForm};`
|
|
3765
|
-
+
|
|
3888
|
+
+ `普通回复直接写 ecmsg send '<正文>'(省略 from/to 即发往当前会话对端);跨话题发送才需要 --thread。`;
|
|
3766
3889
|
}
|
|
3767
3890
|
if (!looksLikeAid(from) || !looksLikeAid(to)) {
|
|
3768
3891
|
return `${prefix}发送者/目标不是合法 AID(收到 from="${from}" to="${to}")。完整形式为 ${expectedForm}。`;
|
|
@@ -3774,9 +3897,10 @@ export function describeProactiveSendCommandFailure(toolName, input, session) {
|
|
|
3774
3897
|
return `${prefix}目标必须是当前会话${scope === 'group' ? '群' : '对端'} ${session.channelId},命令里写的是 ${to};`
|
|
3775
3898
|
+ `要联系其他对象请走 --thread 跨话题发送(ec thread list <对方AID> 选中话题后加 --check-every)。`;
|
|
3776
3899
|
}
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3900
|
+
const payloadDiagnosis = diagnoseProactiveSendPayload(argv, scope, 5, { allowAttachment: true });
|
|
3901
|
+
if (payloadDiagnosis.ok)
|
|
3902
|
+
return undefined;
|
|
3903
|
+
return `${prefix}发送者与目标正确,但${describeSendPayloadProblem(payloadDiagnosis).replace(/^发送命令被拒:/, '')}`;
|
|
3780
3904
|
}
|
|
3781
3905
|
/** 与 CLI `isValidAid` 同一规则;parser 不依赖 AID 模块,避免引入身份存储副作用。 */
|
|
3782
3906
|
function looksLikeAid(value) {
|
|
@@ -9,7 +9,10 @@ const H_CLASS_RELATIVE_PATTERNS = [
|
|
|
9
9
|
/^(?:AIDs|aids)(?:\/|$)/,
|
|
10
10
|
/^\.snapshots(?:\/|$)/,
|
|
11
11
|
/^CA(?:\/|$)/,
|
|
12
|
-
|
|
12
|
+
// The SDK keeps a `.device_id.hmac` guard beside `.device_id` and refuses to
|
|
13
|
+
// resolve a device identity when the pair disagrees, so the suffix belongs to
|
|
14
|
+
// the same secret root. Mirrors the `.seed(?:\.|$)` form below.
|
|
15
|
+
/^\.device_id(?:\.|$)/,
|
|
13
16
|
/^\.env$/,
|
|
14
17
|
/^providers\.json(?:_|__|\.lock(?:\..*)?)?$/,
|
|
15
18
|
/^\.seed(?:\.|$)/,
|
|
@@ -18,14 +21,15 @@ const H_CLASS_RELATIVE_PATTERNS = [
|
|
|
18
21
|
/^daemon\.pid$/,
|
|
19
22
|
/^agents\/[^/]+\/data\/codex-tokens(?:\/|$)/,
|
|
20
23
|
/^agents\/[^/]+\/data\/task-resources(?:\/|$)/,
|
|
24
|
+
/^agents\/[^/]+\/data\/payments(?:\/|$)/,
|
|
21
25
|
/^agents\/[^/]+\/data\/(?:.*\/)?(?:context-tokens|menu-tokens)\.json(?:_|__|\.tmp-.*)?$/,
|
|
22
26
|
];
|
|
23
27
|
const H_CLASS_REFERENCE_PATTERNS = [
|
|
24
28
|
/(?:^|[^A-Za-z0-9_.-])providers\.json(?:_|__|\.lock(?:\.[^/\\\s"']*)?)?(?=$|[\s"';&|<>)},])/,
|
|
25
29
|
/(?:^|[/\\\s"'=<>])data[\\/]/,
|
|
26
30
|
/(?:^|[/\\\s"'=<>])(?:AIDs|aids)[\\/]/,
|
|
27
|
-
/(?:^|[^A-Za-z0-9_.-])(?:\.device_id
|
|
28
|
-
/(?:^|[/\\\s"'=<>])agents[\\/][^/\\\s"']+[\\/]data[\\/](?:codex-tokens|task-resources|(?:.*[\\/])?(?:context-tokens|menu-tokens)\.json)(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
31
|
+
/(?:^|[^A-Za-z0-9_.-])(?:\.device_id(?:\.[^/\\\s"']*)?|\.env|\.seed(?:\.[^/\\\s"']*)?|\.migrated-[^/\\\s"']*|\.lock|daemon\.pid)(?=$|[\s"';&|<>)},])/,
|
|
32
|
+
/(?:^|[/\\\s"'=<>])agents[\\/][^/\\\s"']+[\\/]data[\\/](?:codex-tokens|task-resources|payments|(?:.*[\\/])?(?:context-tokens|menu-tokens)\.json)(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
29
33
|
];
|
|
30
34
|
// H-class directory roots are kept separately from the full path matcher so
|
|
31
35
|
// an exact metadata query can distinguish a protected directory from a
|
|
@@ -38,6 +42,7 @@ const H_CLASS_DIRECTORY_RELATIVE_PATTERNS = [
|
|
|
38
42
|
/^CA(?:\/|$)/,
|
|
39
43
|
/^agents\/[^/]+\/data\/codex-tokens(?:\/|$)/,
|
|
40
44
|
/^agents\/[^/]+\/data\/task-resources(?:\/|$)/,
|
|
45
|
+
/^agents\/[^/]+\/data\/payments(?:\/|$)/,
|
|
41
46
|
];
|
|
42
47
|
const L_CLASS_RELATIVE_PATTERNS = [
|
|
43
48
|
/^daemon\.json$/,
|
|
@@ -164,7 +169,7 @@ const SELF_AWARE_H_CLASS_RELATIVE_PATTERNS = [
|
|
|
164
169
|
/^data(?:\/|$)/,
|
|
165
170
|
/^(?:AIDs|aids)(?:\/|$)/,
|
|
166
171
|
/^CA(?:\/|$)/,
|
|
167
|
-
/^\.device_id
|
|
172
|
+
/^\.device_id(?:\.|$)/,
|
|
168
173
|
/^\.env$/,
|
|
169
174
|
/^\.seed(?:\.|$)/,
|
|
170
175
|
/^\.lock$/,
|
|
@@ -179,7 +184,7 @@ function matchesSelfAwareHClassRelative(relative, selfAid) {
|
|
|
179
184
|
if (!own)
|
|
180
185
|
return false;
|
|
181
186
|
const escaped = own.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
182
|
-
return new RegExp(`^agents/${escaped}/data/(?:codex-tokens|task-resources)(?:/|$)`).test(relative)
|
|
187
|
+
return new RegExp(`^agents/${escaped}/data/(?:codex-tokens|task-resources|payments)(?:/|$)`).test(relative)
|
|
183
188
|
|| new RegExp(`^agents/${escaped}/data/(?:.*\/)?(?:context-tokens|menu-tokens)\\.json(?:_|__|\\.tmp-.*)?$`).test(relative);
|
|
184
189
|
}
|
|
185
190
|
export function isSameOrDescendant(candidate, parent) {
|
|
@@ -387,7 +392,7 @@ function getLegacyHClassSandboxPatterns(root) {
|
|
|
387
392
|
path.join('aids', '*', 'cert'), path.join('aids', '*', 'cert', '**'),
|
|
388
393
|
path.join('aids', '*', 'keys'), path.join('aids', '*', 'keys', '**'),
|
|
389
394
|
path.join('aids', '*', 'private'), path.join('aids', '*', 'private', '**'),
|
|
390
|
-
'.device_id', '.env', '.seed', '.seed.*', '.migrated-*',
|
|
395
|
+
'.device_id', '.device_id.*', '.env', '.seed', '.seed.*', '.migrated-*',
|
|
391
396
|
path.join('**', '*.json_'), path.join('**', '*.json.migrated'),
|
|
392
397
|
path.join('agents', 'defaults_*.json'), '.lock', 'daemon.pid',
|
|
393
398
|
path.join('data', 'causation-aun.json*'), path.join('data', 'contact-book-audit.jsonl'),
|
|
@@ -401,6 +406,7 @@ function getLegacyHClassSandboxPatterns(root) {
|
|
|
401
406
|
path.join('agents', '*', 'data', 'handoff', '**'), path.join('agents', '*', 'data', 'async-questions', '**'),
|
|
402
407
|
path.join('agents', '*', 'data', 'task-activity', '**'), path.join('agents', '*', 'data', 'aun', '**'),
|
|
403
408
|
path.join('agents', '*', 'data', 'task-resources', '**'),
|
|
409
|
+
path.join('agents', '*', 'data', 'payments'), path.join('agents', '*', 'data', 'payments', '**'),
|
|
404
410
|
path.join('agents', '*', 'data', 'outbox.jsonl*'), path.join('agents', '*', 'data', 'activity-outbox.jsonl*'),
|
|
405
411
|
path.join('agents', '*', 'data', 'contact-audit.jsonl'),
|
|
406
412
|
];
|
|
@@ -417,11 +423,13 @@ export function getHClassSandboxPatterns(root = resolveRoot(), options = {}) {
|
|
|
417
423
|
'aids', path.join('aids', '**'),
|
|
418
424
|
'CA',
|
|
419
425
|
path.join('CA', '**'),
|
|
420
|
-
'.device_id', '.env', '.seed', '.seed.*', '.lock', 'daemon.pid',
|
|
426
|
+
'.device_id', '.device_id.*', '.env', '.seed', '.seed.*', '.lock', 'daemon.pid',
|
|
421
427
|
path.join('agents', options.selfAid, 'data', 'codex-tokens'),
|
|
422
428
|
path.join('agents', options.selfAid, 'data', 'codex-tokens', '**'),
|
|
423
429
|
path.join('agents', options.selfAid, 'data', 'task-resources'),
|
|
424
430
|
path.join('agents', options.selfAid, 'data', 'task-resources', '**'),
|
|
431
|
+
path.join('agents', options.selfAid, 'data', 'payments'),
|
|
432
|
+
path.join('agents', options.selfAid, 'data', 'payments', '**'),
|
|
425
433
|
path.join('agents', options.selfAid, 'data', '**', 'context-tokens.json'),
|
|
426
434
|
path.join('agents', options.selfAid, 'data', '**', 'menu-tokens.json'),
|
|
427
435
|
];
|
|
@@ -479,6 +487,15 @@ function getAgentAwareHClassMaskTargets(root, selfAid) {
|
|
|
479
487
|
'.device_id', '.env', '.seed', '.lock', 'daemon.pid',
|
|
480
488
|
])
|
|
481
489
|
addExistingTarget(targets, path.join(absoluteRoot, relative));
|
|
490
|
+
// `.device_id` carries a sibling guard (`<name>.<suffix>`), so mirror the
|
|
491
|
+
// `.seed.*` scan below instead of listing one literal name.
|
|
492
|
+
try {
|
|
493
|
+
for (const entry of fs.readdirSync(absoluteRoot)) {
|
|
494
|
+
if (entry.startsWith('.device_id.'))
|
|
495
|
+
addExistingTarget(targets, path.join(absoluteRoot, entry));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
catch { }
|
|
482
499
|
const agentsDir = path.join(absoluteRoot, 'agents');
|
|
483
500
|
try {
|
|
484
501
|
for (const entry of fs.readdirSync(agentsDir, { withFileTypes: true })) {
|
|
@@ -491,6 +508,7 @@ function getAgentAwareHClassMaskTargets(root, selfAid) {
|
|
|
491
508
|
}
|
|
492
509
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'codex-tokens'));
|
|
493
510
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'task-resources'));
|
|
511
|
+
addExistingTarget(targets, path.join(agentRoot, 'data', 'payments'));
|
|
494
512
|
const walk = (directory, depth = 0) => {
|
|
495
513
|
if (depth > 8)
|
|
496
514
|
return;
|
|
@@ -536,7 +554,8 @@ export function getExistingHClassMaskTargets(root = resolveRoot(), options = {})
|
|
|
536
554
|
}
|
|
537
555
|
try {
|
|
538
556
|
for (const entry of fs.readdirSync(absoluteRoot)) {
|
|
539
|
-
if (entry.startsWith('.seed.') || entry.startsWith('.
|
|
557
|
+
if (entry.startsWith('.seed.') || entry.startsWith('.device_id.')
|
|
558
|
+
|| entry.startsWith('.migrated-') || entry.endsWith('.json.migrated')) {
|
|
540
559
|
addExistingTarget(targets, path.join(absoluteRoot, entry));
|
|
541
560
|
}
|
|
542
561
|
}
|
|
@@ -578,6 +597,7 @@ export function getExistingHClassMaskTargets(root = resolveRoot(), options = {})
|
|
|
578
597
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'channels'));
|
|
579
598
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'handoff'));
|
|
580
599
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'async-questions'));
|
|
600
|
+
addExistingTarget(targets, path.join(agentRoot, 'data', 'payments'));
|
|
581
601
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'task-activity'));
|
|
582
602
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'task-resources'));
|
|
583
603
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'aun'));
|
|
@@ -670,13 +690,48 @@ export function getExistingRelationAttachmentDirs(root = resolveRoot(), options
|
|
|
670
690
|
catch { }
|
|
671
691
|
return [...targets];
|
|
672
692
|
}
|
|
693
|
+
/**
|
|
694
|
+
* Agent 级附件目录:`agents/<aid>/attachments`。
|
|
695
|
+
*
|
|
696
|
+
* 收发附件的文件本体都落在这里(按内容去重,与关系无关)。它是普通可读内容——
|
|
697
|
+
* 模型需要 Read 才能看图片和文件——因此只进 denyWrite,不进 denyRead:
|
|
698
|
+
* 防止模型改写附件,但不阻断读取。
|
|
699
|
+
*/
|
|
700
|
+
export function getExistingAgentAttachmentDirs(root = resolveRoot(), options = {}) {
|
|
701
|
+
const absoluteRoot = resolveThroughExistingAncestor(root);
|
|
702
|
+
const agentsDir = path.join(absoluteRoot, 'agents');
|
|
703
|
+
const targets = new Set();
|
|
704
|
+
try {
|
|
705
|
+
for (const agent of fs.readdirSync(agentsDir, { withFileTypes: true })) {
|
|
706
|
+
if (!agent.isDirectory())
|
|
707
|
+
continue;
|
|
708
|
+
if (options.selfAid) {
|
|
709
|
+
const isSelf = agent.name.toLowerCase() === options.selfAid.toLowerCase();
|
|
710
|
+
if (options.onlyOtherAgents ? isSelf : !isSelf)
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
const attachments = path.join(agentsDir, agent.name, 'attachments');
|
|
714
|
+
try {
|
|
715
|
+
if (fs.lstatSync(attachments).isDirectory())
|
|
716
|
+
targets.add(attachments);
|
|
717
|
+
}
|
|
718
|
+
catch { }
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
catch { }
|
|
722
|
+
return [...targets];
|
|
723
|
+
}
|
|
673
724
|
export function buildClaudeProtectedFilesystem(root = resolveRoot(), options = {}) {
|
|
674
725
|
const hClassPaths = [
|
|
675
726
|
...getExistingHClassMaskTargets(root, options).map(target => target.path),
|
|
676
727
|
];
|
|
677
728
|
const relationAttachmentPaths = getExistingRelationAttachmentDirs(root, options);
|
|
729
|
+
const agentAttachmentPaths = getExistingAgentAttachmentDirs(root, options);
|
|
678
730
|
const lClassPaths = getExistingLClassReadOnlyTargets(root, options).map(target => target.path);
|
|
679
|
-
|
|
731
|
+
// Agent 级附件只防写:模型要 Read 附件内容,但不应改写原始凭证。
|
|
732
|
+
const allPaths = [...new Set([
|
|
733
|
+
...hClassPaths, ...lClassPaths, ...relationAttachmentPaths, ...agentAttachmentPaths,
|
|
734
|
+
])];
|
|
680
735
|
// Self-Agent relation attachments are ordinary readable content. They stay
|
|
681
736
|
// in denyWrite so the nested Claude sandbox cannot mutate an uploaded asset;
|
|
682
737
|
// callers without identity context retain the legacy deny-read behavior.
|
|
@@ -20,8 +20,15 @@
|
|
|
20
20
|
*
|
|
21
21
|
* ## 为什么 DENY 不含读位
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* **先澄清实测事实**:沙箱身份本来就读不到 `services/` 树。`agents/<aid>` 根上有
|
|
24
|
+
* `CodexSandboxUsers:(DENY)(R)`(非继承)与 `(OI)(CI)(IO)(DENY)(R,GR)`(只对子对象),
|
|
25
|
+
* 两者继承下来,`services/` 及其下每个文件对沙箱组都是 `EPERM`——读写皆不可。
|
|
26
|
+
* 服务脚本能跑,是因为脚本被 `stageScriptSnapshot` 复制到 `runDir/script` 后执行,
|
|
27
|
+
* 输入全部走 stdin,不依赖读取包目录。
|
|
28
|
+
*
|
|
29
|
+
* 因此这条 DENY 只补写位:读位已经被父目录的 DENY(R) 关掉了,再重复一遍没有意义;
|
|
30
|
+
* 而如果将来有人把父目录的读权限放开,这条写 DENY 仍然留在原地,写保护不会跟着失效。
|
|
31
|
+
* 只拒写数据 / 追加 / 写扩展属性 / 写属性 / 删除 / 删子项 / 改 DACL / 改所有者。
|
|
25
32
|
*
|
|
26
33
|
* 平台:仅 `win32`。其他平台 `hardenServicesAcl` 直接返回 `changed: false`。
|
|
27
34
|
*/
|