evolcore 0.0.43-test.4 → 0.0.43-test.5
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 +46 -0
- package/bin/ecmsg.js +354 -91
- package/dist/agents/codex-runner.js +12 -17
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/channels/aun.js +30 -17
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +4 -2
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +10 -3
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +12 -3
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +45 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +11 -19
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +3 -0
- package/dist/config/boot-log.js +12 -1
- package/dist/config/config-manager.js +4 -13
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +5 -5
- package/dist/config/provider-identity-migration.js +202 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +153 -0
- package/dist/config/providers-config.js +32 -4
- package/dist/config/providers-management.js +144 -68
- package/dist/config/providers.js +4 -1
- package/dist/config/schema-migration.js +67 -3
- package/dist/core/agent-runtime.js +4 -2
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +11 -6
- package/dist/core/command/menu-protocol.js +4 -2
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/response-engine.js +23 -23
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/ownership/owner-resolver.js +111 -8
- package/dist/core/permission/ec-command-parser.js +148 -15
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/session-idle-monitor.js +94 -16
- package/dist/core/session/session-manager.js +69 -16
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-cache.js +686 -97
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +2 -2
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +18 -9
- package/dist/ecweb/runtime/supervisor.js +76 -24
- package/dist/index.js +4 -0
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +2 -2
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/scheduler.js +3 -3
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +3 -3
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +13 -4
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +1 -1
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +28 -28
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +1 -1
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +5 -5
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +47 -28
- package/kits/templates/system-fragments/session.md +2 -9
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +2 -3
|
@@ -53,6 +53,22 @@ export function buildCanonicalEvolcoreExecutionSpec(input) {
|
|
|
53
53
|
export function serializeCanonicalEvolcoreExecutionSpec(spec) {
|
|
54
54
|
return JSON.stringify(spec);
|
|
55
55
|
}
|
|
56
|
+
function parsePosixSingleQuotedPatchArgument(source) {
|
|
57
|
+
if (!source.startsWith("'") || source.includes('\0'))
|
|
58
|
+
return undefined;
|
|
59
|
+
const segments = /'([^']*)'|\\'|"'"/gy;
|
|
60
|
+
let document = '';
|
|
61
|
+
let offset = 0;
|
|
62
|
+
while (offset < source.length) {
|
|
63
|
+
segments.lastIndex = offset;
|
|
64
|
+
const segment = segments.exec(source);
|
|
65
|
+
if (!segment)
|
|
66
|
+
return undefined;
|
|
67
|
+
document += segment[1] ?? "'";
|
|
68
|
+
offset = segments.lastIndex;
|
|
69
|
+
}
|
|
70
|
+
return document;
|
|
71
|
+
}
|
|
56
72
|
function parseApplyPatchCommand(command, options = {}) {
|
|
57
73
|
const input = command.trim();
|
|
58
74
|
let commandText = input;
|
|
@@ -67,10 +83,27 @@ function parseApplyPatchCommand(command, options = {}) {
|
|
|
67
83
|
const remainder = commandText.slice(executableMatch[0].length).trimStart();
|
|
68
84
|
if (!remainder)
|
|
69
85
|
return parseApplyPatchArgv([executable]);
|
|
86
|
+
const dialect = options.dialect ?? (process.platform === 'win32' ? 'powershell' : 'posix');
|
|
87
|
+
if (dialect === 'powershell' && remainder.startsWith("@'")) {
|
|
88
|
+
const body = remainder.match(/^@'\r?\n([\s\S]*)$/u)?.[1];
|
|
89
|
+
const lines = body?.split(/\r?\n/u);
|
|
90
|
+
const delimiterIndex = lines?.findIndex(line => line.startsWith("'@")) ?? -1;
|
|
91
|
+
if (!lines || delimiterIndex < 0 || lines[delimiterIndex].trimEnd() !== "'@"
|
|
92
|
+
|| lines.slice(delimiterIndex + 1).some(line => line.trim() !== '')
|
|
93
|
+
|| remainder.includes('\0')) {
|
|
94
|
+
return { kind: 'invalid', reason: 'PowerShell patch requires one complete single-quoted here-string without trailing commands' };
|
|
95
|
+
}
|
|
96
|
+
return parseApplyPatchArgv([executable, lines.slice(0, delimiterIndex).join('\n')]);
|
|
97
|
+
}
|
|
70
98
|
const literal = parseLiteralShellCommand(commandText, { ...options, allowManagedTmpDir: true });
|
|
71
99
|
if (literal.ok && argvUsesShellApplyPatch(literal.argv)) {
|
|
72
100
|
return parseApplyPatchArgv(literal.argv);
|
|
73
101
|
}
|
|
102
|
+
if (dialect === 'posix') {
|
|
103
|
+
const document = parsePosixSingleQuotedPatchArgument(remainder);
|
|
104
|
+
if (document !== undefined)
|
|
105
|
+
return parseApplyPatchArgv([executable, document]);
|
|
106
|
+
}
|
|
74
107
|
const heredoc = remainder.match(/^<<-?\s*(?:'([^']+)'|"([^"]+)"|([^\s]+))\s*\r?\n([\s\S]*)$/u);
|
|
75
108
|
if (!heredoc)
|
|
76
109
|
return { kind: 'invalid', reason: 'apply_patch must use one literal patch document' };
|
|
@@ -158,6 +191,12 @@ export function parseShellApplyPatchInvocation(input, options = {}, parsedArgv)
|
|
|
158
191
|
const carrier = rawCommandArgv
|
|
159
192
|
? resolveCodexShellCarrierArgv(rawCommandArgv)
|
|
160
193
|
: resolveCodexShellCarrierString(rawCommand);
|
|
194
|
+
if (carrier?.parseFailure) {
|
|
195
|
+
const executable = leadingShellExecutable(carrier.command);
|
|
196
|
+
if (executable && isApplyPatchExecutable(executable)) {
|
|
197
|
+
return { kind: 'invalid', reason: 'apply_patch shell carrier has invalid quoting or command composition' };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
161
200
|
if (rawCommandArgv) {
|
|
162
201
|
if (argvUsesShellApplyPatch(rawCommandArgv)) {
|
|
163
202
|
return parseApplyPatchArgv(rawCommandArgv);
|
|
@@ -406,10 +445,12 @@ function stripHeredocBodies(command) {
|
|
|
406
445
|
// This is intentionally limited to the command boundary. It is not a search
|
|
407
446
|
// for `ec` anywhere in the input: quoted arguments, regexps and log text must
|
|
408
447
|
// never establish an EC invocation.
|
|
409
|
-
|
|
448
|
+
const POWERSHELL_ASSIGNMENT_PREFIX = /^\$(?:[A-Za-z_][\w:]*|\{[^{}\r\n]+\})\s*=(?!=)/u;
|
|
449
|
+
function hasEcCommandPrefix(command, dialect = 'posix') {
|
|
410
450
|
let quote = null;
|
|
411
451
|
let escaped = false;
|
|
412
452
|
let boundary = true;
|
|
453
|
+
const powerShell = dialect === 'powershell';
|
|
413
454
|
for (let index = 0; index < command.length; index++) {
|
|
414
455
|
const char = command[index];
|
|
415
456
|
if (escaped) {
|
|
@@ -418,35 +459,77 @@ function hasEcCommandPrefix(command) {
|
|
|
418
459
|
continue;
|
|
419
460
|
}
|
|
420
461
|
if (quote === 'single') {
|
|
421
|
-
if (char === "'")
|
|
422
|
-
|
|
462
|
+
if (powerShell ? isPowerShellSingleQuote(char) : char === "'") {
|
|
463
|
+
if (powerShell && isPowerShellSingleQuote(command[index + 1]))
|
|
464
|
+
index++;
|
|
465
|
+
else
|
|
466
|
+
quote = null;
|
|
467
|
+
}
|
|
423
468
|
continue;
|
|
424
469
|
}
|
|
425
470
|
if (quote === 'double') {
|
|
426
|
-
if (char === '\\') {
|
|
471
|
+
if (char === (powerShell ? '`' : '\\')) {
|
|
427
472
|
escaped = true;
|
|
428
473
|
continue;
|
|
429
474
|
}
|
|
430
|
-
if (char === '"')
|
|
475
|
+
if (powerShell ? isPowerShellDoubleQuote(char) : char === '"')
|
|
431
476
|
quote = null;
|
|
432
477
|
continue;
|
|
433
478
|
}
|
|
434
|
-
if (char ===
|
|
479
|
+
if (powerShell && char === '`') {
|
|
480
|
+
escaped = true;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (powerShell && command.startsWith('<#', index)) {
|
|
484
|
+
const end = command.indexOf('#>', index + 2);
|
|
485
|
+
if (end < 0)
|
|
486
|
+
return false;
|
|
487
|
+
index = end + 1;
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
if (powerShell && char === '#' && (index === 0 || /\s/.test(command[index - 1]))) {
|
|
491
|
+
const end = command.indexOf('\n', index);
|
|
492
|
+
if (end < 0)
|
|
493
|
+
return false;
|
|
494
|
+
index = end - 1;
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
if (powerShell && char === '@' && /['"]/.test(command[index + 1] ?? '')
|
|
498
|
+
&& /^\r?\n/.test(command.slice(index + 2))) {
|
|
499
|
+
const end = new RegExp(`^${command[index + 1]}@`, 'm').exec(command.slice(index + 2));
|
|
500
|
+
if (!end)
|
|
501
|
+
return false;
|
|
502
|
+
index += end.index + 3;
|
|
503
|
+
boundary = false;
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (powerShell ? isPowerShellSingleQuote(char) : char === "'") {
|
|
435
507
|
quote = 'single';
|
|
436
508
|
boundary = false;
|
|
437
509
|
continue;
|
|
438
510
|
}
|
|
439
|
-
if (char === '"') {
|
|
511
|
+
if (powerShell ? isPowerShellDoubleQuote(char) : char === '"') {
|
|
440
512
|
quote = 'double';
|
|
441
513
|
boundary = false;
|
|
442
514
|
continue;
|
|
443
515
|
}
|
|
516
|
+
if (powerShell && /[{}\r\n]/.test(char)) {
|
|
517
|
+
boundary = true;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
444
520
|
if (/[;&|`()<>]/.test(char)) {
|
|
445
521
|
boundary = true;
|
|
446
522
|
continue;
|
|
447
523
|
}
|
|
448
524
|
if (boundary && /\s/.test(char))
|
|
449
525
|
continue;
|
|
526
|
+
if (boundary && powerShell && char === '$') {
|
|
527
|
+
const assignment = POWERSHELL_ASSIGNMENT_PREFIX.exec(command.slice(index));
|
|
528
|
+
if (assignment) {
|
|
529
|
+
index += assignment[0].length - 1;
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
450
533
|
if (boundary && /^ec(?:\.cmd|\.exe|\.ps1)?(?=$|\s|[;&|`()<>])/i.test(command.slice(index)))
|
|
451
534
|
return true;
|
|
452
535
|
// `ecmsg` 是 `ec msg` 的同义词,同样算 EC 命令边界——否则
|
|
@@ -700,7 +783,7 @@ function isShellParameterExpansionStart(value) {
|
|
|
700
783
|
}
|
|
701
784
|
function hasCarrierEcCommandPrefix(command, dialect) {
|
|
702
785
|
if (dialect !== 'cmd')
|
|
703
|
-
return hasEcCommandPrefix(command);
|
|
786
|
+
return hasEcCommandPrefix(command, dialect);
|
|
704
787
|
const input = trimShellSpacing(command);
|
|
705
788
|
const inner = input.length >= 2 && input.startsWith('"') && input.endsWith('"')
|
|
706
789
|
? input.slice(1, -1)
|
|
@@ -1310,7 +1393,10 @@ function parseLiteralPowerShellCommand(command, options = {}) {
|
|
|
1310
1393
|
? { ...parsed, argv: normalizeEvolcoreCommandArgv(parsed.argv) }
|
|
1311
1394
|
: { ...parsed, inputLength: input.length };
|
|
1312
1395
|
}
|
|
1313
|
-
const isEcCommand = hasEcCommandPrefix(input);
|
|
1396
|
+
const isEcCommand = hasEcCommandPrefix(input, 'powershell');
|
|
1397
|
+
if (isEcCommand && POWERSHELL_ASSIGNMENT_PREFIX.test(input)) {
|
|
1398
|
+
return parseFailure('shell-composition', input, 0, 0, 'powershell');
|
|
1399
|
+
}
|
|
1314
1400
|
const argv = [];
|
|
1315
1401
|
let token = '';
|
|
1316
1402
|
let tokenStarted = false;
|
|
@@ -3101,7 +3187,7 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3101
3187
|
// Only a command-boundary prefix is enough to preserve a useful syntax
|
|
3102
3188
|
// error for a malformed direct EC invocation. Never scan for EC tokens in
|
|
3103
3189
|
// arbitrary raw text after parsing fails.
|
|
3104
|
-
return hasEcCommandPrefix(stripped)
|
|
3190
|
+
return hasEcCommandPrefix(stripped, options.dialect)
|
|
3105
3191
|
? { kind: 'composite', issue: literal.issue }
|
|
3106
3192
|
: { kind: 'none' };
|
|
3107
3193
|
}
|
|
@@ -3167,7 +3253,7 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3167
3253
|
}
|
|
3168
3254
|
if (classification.kind === 'composite')
|
|
3169
3255
|
return { kind: 'invalid', ...(!parsed.ok ? { failure: parsed } : {}) };
|
|
3170
|
-
if (!parsed.ok && hasEcCommandPrefix(command))
|
|
3256
|
+
if (!parsed.ok && hasEcCommandPrefix(command, dialect))
|
|
3171
3257
|
return { kind: 'invalid', failure: parsed };
|
|
3172
3258
|
return { kind: 'not-ec' };
|
|
3173
3259
|
}
|
|
@@ -3288,17 +3374,45 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
|
|
|
3288
3374
|
return true;
|
|
3289
3375
|
return literalIndexes.some(index => !textIndexes.has(index));
|
|
3290
3376
|
}
|
|
3377
|
+
/** 只读子命令:查询类,不产生任何副作用。 */
|
|
3378
|
+
const READ_ONLY_SUBCOMMANDS = new Set([
|
|
3379
|
+
'thread.list', 'thread.show', 'thread.history', 'thread.peers',
|
|
3380
|
+
'thread.summary', 'msg.history', 'msg.online', 'trigger.list', 'trigger.show',
|
|
3381
|
+
'directory.list', 'directory.info', 'aid.show', 'aid.list', 'aid.lookup',
|
|
3382
|
+
'peer.list', 'help', 'status',
|
|
3383
|
+
]);
|
|
3384
|
+
/**
|
|
3385
|
+
* 该工具调用是否是**只读**的 EC 命令。
|
|
3386
|
+
*
|
|
3387
|
+
* 意图表达门禁只应拦"有副作用但没表态"的调用;帮助与查询类命令既没有副作用,
|
|
3388
|
+
* 又往往是模型在学习正确用法时的必要动作。把它们一起拦掉,模型会不断试错,
|
|
3389
|
+
* 连续违规直接熔断——这在本项目已经真实发生过。
|
|
3390
|
+
*/
|
|
3391
|
+
export function isReadOnlyEcCommand(toolName, input) {
|
|
3392
|
+
if (!['Bash', 'Shell', 'exec'].includes(toolName) || !input || typeof input !== 'object')
|
|
3393
|
+
return false;
|
|
3394
|
+
const result = parseProactiveToolCommand(toolName, input);
|
|
3395
|
+
if (!result?.ok)
|
|
3396
|
+
return false;
|
|
3397
|
+
const argv = result.argv;
|
|
3398
|
+
if (argv[0] !== 'ec')
|
|
3399
|
+
return false;
|
|
3400
|
+
if (argv.includes('--help') || argv.includes('-h'))
|
|
3401
|
+
return true;
|
|
3402
|
+
const head = `${argv[1] ?? ''}.${argv[2] ?? ''}`;
|
|
3403
|
+
return READ_ONLY_SUBCOMMANDS.has(head);
|
|
3404
|
+
}
|
|
3291
3405
|
/** Shell-escaped TMPDIR references are literal text and must not authorize file paths. */
|
|
3292
3406
|
export function containsUnresolvedManagedTmpDirReference(argv) {
|
|
3293
3407
|
return argv.some(value => /(?:\\\$TMPDIR|\\\$\{TMPDIR\})/i.test(value));
|
|
3294
3408
|
}
|
|
3295
|
-
function hasExecutableProactiveSendPayload(argv, scope) {
|
|
3409
|
+
function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
|
|
3296
3410
|
if (!argv || argv[0] !== 'ec' || argv[1] !== scope || argv[2] !== 'send')
|
|
3297
3411
|
return false;
|
|
3298
3412
|
const positionals = [];
|
|
3299
3413
|
const modes = new Map();
|
|
3300
3414
|
let endOfOptions = false;
|
|
3301
|
-
for (let index =
|
|
3415
|
+
for (let index = bodyStart; index < argv.length; index++) {
|
|
3302
3416
|
const value = argv[index];
|
|
3303
3417
|
if (endOfOptions) {
|
|
3304
3418
|
positionals.push(value);
|
|
@@ -3425,6 +3539,19 @@ export function isEvolcoreSendCommandForSession(toolName, input, channelId) {
|
|
|
3425
3539
|
return true;
|
|
3426
3540
|
return parsed.targetId === channelId;
|
|
3427
3541
|
}
|
|
3542
|
+
/**
|
|
3543
|
+
* 托管简化式:`ec msg|group send <正文...>`,省略 from/to,目标由当前会话决定。
|
|
3544
|
+
*
|
|
3545
|
+
* 判据是"argv[3] 不是 AID"——完整式这里一定是发送者 AID。带 `--thread` 的
|
|
3546
|
+
* 跨话题发送由 `isThreadRoutedEvolcoreSendCommand` 单独处理,这里排除。
|
|
3547
|
+
*/
|
|
3548
|
+
function isManagedSimplifiedSend(argv) {
|
|
3549
|
+
if (argv[0] !== 'ec' || (argv[1] !== 'msg' && argv[1] !== 'group') || argv[2] !== 'send')
|
|
3550
|
+
return false;
|
|
3551
|
+
if (sendOptionValue(argv, '--thread'))
|
|
3552
|
+
return false;
|
|
3553
|
+
return !looksLikeAid(argv[3]);
|
|
3554
|
+
}
|
|
3428
3555
|
/** Proactive first-send guard: exact channel kind and current target only. */
|
|
3429
3556
|
export function isExactEvolcoreSendCommandForSession(toolName, input, channelId, chatType, selfAid) {
|
|
3430
3557
|
// Codex app-server exposes shell items as `Shell`; the desktop custom tool
|
|
@@ -3433,14 +3560,20 @@ export function isExactEvolcoreSendCommandForSession(toolName, input, channelId,
|
|
|
3433
3560
|
return false;
|
|
3434
3561
|
const result = parseProactiveToolCommand(toolName, input);
|
|
3435
3562
|
const argv = result?.ok ? result.argv : null;
|
|
3436
|
-
|
|
3563
|
+
if (!argv)
|
|
3564
|
+
return false;
|
|
3565
|
+
// 托管简化式:目标就是当前会话对端,无需在 argv 里写 from/to。
|
|
3566
|
+
// 这正是 `ecmsg send '<正文>'` 归一后的形态,必须被认作意图表达。
|
|
3567
|
+
if (isManagedSimplifiedSend(argv)) {
|
|
3568
|
+
return hasExecutableProactiveSendPayload(argv, argv[1], 3);
|
|
3569
|
+
}
|
|
3570
|
+
const parsed = parseEvolcoreSendArgv(argv);
|
|
3437
3571
|
if (!parsed || parsed.action !== 'send')
|
|
3438
3572
|
return false;
|
|
3439
3573
|
const expectedScope = chatType === 'group' ? 'group' : 'msg';
|
|
3440
3574
|
return parsed.scope === expectedScope
|
|
3441
3575
|
&& parsed.targetId === channelId
|
|
3442
3576
|
&& parsed.sourceId === selfAid
|
|
3443
|
-
&& !!argv
|
|
3444
3577
|
&& hasExecutableProactiveSendPayload(argv, expectedScope);
|
|
3445
3578
|
}
|
|
3446
3579
|
/**
|
|
@@ -5,6 +5,7 @@ const MAX_PIPELINE_STAGES = 3;
|
|
|
5
5
|
const SUPPORTED_EXECUTABLES = new Set([
|
|
6
6
|
'echo', 'pwd', 'ls', 'cat', 'grep', 'rg', 'find', 'sed', 'head', 'tail', 'sort', 'uniq', 'git', 'wc', 'stat', 'lstat', 'awk',
|
|
7
7
|
'bash', 'sh',
|
|
8
|
+
'ps', 'pgrep', 'env',
|
|
8
9
|
]);
|
|
9
10
|
const FIND_MUTATING_PRIMARY_RE = /^-(?:delete|exec|execdir|ok|okdir|fprint|fprint0|fprintf|fls)$/;
|
|
10
11
|
const RG_PROCESS_SPAWNING_OPTION_RE = /^(?:--pre|--hostname-bin|--pre-glob|--search-zip)(?:=|$)/;
|
|
@@ -279,6 +280,8 @@ function analyzeGrep(args) {
|
|
|
279
280
|
return paths;
|
|
280
281
|
}
|
|
281
282
|
function analyzeRg(args, hasPipelineInput = false) {
|
|
283
|
+
if (args.length === 1 && ['--help', '-h', '--version', '-V', '--type-list'].includes(args[0]))
|
|
284
|
+
return [];
|
|
282
285
|
if (args.some(argument => RG_PROCESS_SPAWNING_OPTION_RE.test(argument)
|
|
283
286
|
|| argument === '--follow'
|
|
284
287
|
// `-z` is the short form of `--search-zip`; it may also appear in a
|
|
@@ -367,15 +370,64 @@ function analyzeRg(args, hasPipelineInput = false) {
|
|
|
367
370
|
}
|
|
368
371
|
if (!filesMode && !hasExplicitPattern && !implicitPatternSeen)
|
|
369
372
|
return null;
|
|
370
|
-
// Enumeration modes ignore the incoming stream and are never stdin filters.
|
|
371
|
-
if (hasPipelineInput && filesMode)
|
|
372
|
-
return null;
|
|
373
373
|
// Without an explicit path, ripgrep reads stdin when used after a pipe.
|
|
374
374
|
// Standalone searches and `--files` still default to the current directory.
|
|
375
|
-
if (!inputOperandSeen && !hasPipelineInput)
|
|
376
|
-
paths.push(recursive('.'));
|
|
375
|
+
if (!inputOperandSeen && (!hasPipelineInput || filesMode))
|
|
376
|
+
paths.push({ ...recursive('.'), implicit: true });
|
|
377
377
|
return paths;
|
|
378
378
|
}
|
|
379
|
+
/** Process/environment queries have no filesystem operands or child command. */
|
|
380
|
+
function analyzeProcessQuery(executable, args) {
|
|
381
|
+
if (executable === 'env') {
|
|
382
|
+
// `env NAME=value command`, -S and -C can execute/change scope. Only
|
|
383
|
+
// printing the current environment is a passthrough query.
|
|
384
|
+
return args.every(arg => ['-0', '--null'].includes(arg)) ? [] : null;
|
|
385
|
+
}
|
|
386
|
+
if (executable === 'ps') {
|
|
387
|
+
const flags = new Set(['-e', '-A', '-a', '-x', '-f', '-l', '-w', '-ww', '--no-headers', '--headers', '--forest']);
|
|
388
|
+
const values = new Set(['-o', '-eo', '-efo', '--format', '-p', '--pid', '--ppid', '-u', '--user', '-U', '--User', '-C', '--sort']);
|
|
389
|
+
for (let index = 0; index < args.length; index++) {
|
|
390
|
+
const arg = args[index];
|
|
391
|
+
const option = arg.split('=', 1)[0];
|
|
392
|
+
if (values.has(option)) {
|
|
393
|
+
const value = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : args[++index];
|
|
394
|
+
if (!value || value.startsWith('-'))
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
else if (!flags.has(arg) && !/^-[eAaxflw]+$/.test(arg) && !/^[auxflw]+$/.test(arg))
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
return [];
|
|
401
|
+
}
|
|
402
|
+
// pgrep -F/--pidfile and --logpidfile read files; -L depends on them.
|
|
403
|
+
// Keep only process selectors and one literal matching expression.
|
|
404
|
+
let pattern = false;
|
|
405
|
+
let optionsEnded = false;
|
|
406
|
+
const values = new Set(['-P', '--parent', '-u', '--euid', '-U', '--uid', '-g', '--pgroup', '-s', '--session', '-t', '--terminal', '-d', '--delimiter', '-r', '--runstates']);
|
|
407
|
+
const flags = new Set(['--full', '--list-full', '--list-name', '--count', '--exact', '--ignore-case', '--newest', '--oldest', '--inverse']);
|
|
408
|
+
for (let index = 0; index < args.length; index++) {
|
|
409
|
+
const arg = args[index];
|
|
410
|
+
if (!optionsEnded && arg === '--') {
|
|
411
|
+
optionsEnded = true;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const option = arg.split('=', 1)[0];
|
|
415
|
+
if (!optionsEnded && values.has(option)) {
|
|
416
|
+
const value = arg.includes('=') ? arg.slice(arg.indexOf('=') + 1) : args[++index];
|
|
417
|
+
if (!value || value.startsWith('-'))
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
else if (!optionsEnded && (flags.has(arg) || /^-[aflcxinov]+$/.test(arg))) {
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
if ((!optionsEnded && arg.startsWith('-')) || pattern)
|
|
425
|
+
return null;
|
|
426
|
+
pattern = true;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return pattern ? [] : null;
|
|
430
|
+
}
|
|
379
431
|
function analyzeFind(args) {
|
|
380
432
|
if (args.some(argument => FIND_MUTATING_PRIMARY_RE.test(argument)))
|
|
381
433
|
return null;
|
|
@@ -859,6 +911,12 @@ function analyzeCommand(argv, hasPipelineInput = false) {
|
|
|
859
911
|
let accessKind = 'content';
|
|
860
912
|
let purpose = 'unknown';
|
|
861
913
|
switch (executable) {
|
|
914
|
+
case 'ps':
|
|
915
|
+
case 'pgrep':
|
|
916
|
+
case 'env':
|
|
917
|
+
pathOperands = analyzeProcessQuery(executable, args);
|
|
918
|
+
purpose = 'passthrough';
|
|
919
|
+
break;
|
|
862
920
|
case 'echo':
|
|
863
921
|
pathOperands = [];
|
|
864
922
|
purpose = 'passthrough';
|
|
@@ -940,7 +998,8 @@ function analyzeCommand(argv, hasPipelineInput = false) {
|
|
|
940
998
|
// 无路径操作数的命令是纯 stdin→stdout 变换,可安全出现在管道任意位置。
|
|
941
999
|
// 对于 sort/wc/awk/grep/head/tail/sed:有路径参数时读文件,无路径参数时为 stdin 变换。
|
|
942
1000
|
const stdinTransform = pathOperands.length === 0
|
|
943
|
-
&& ['sort', 'uniq', 'wc', 'awk', 'grep', 'rg', 'head', 'tail', 'sed'].includes(executable)
|
|
1001
|
+
&& ['sort', 'uniq', 'wc', 'awk', 'grep', 'rg', 'head', 'tail', 'sed'].includes(executable)
|
|
1002
|
+
&& !(executable === 'rg' && args.some(arg => ['--files', '--type-list', '--help', '-h', '--version', '-V'].includes(arg)));
|
|
944
1003
|
// 修正 purpose:stdin 变换时统一标记,避免 'metadata-read'/'content-read' 歧义
|
|
945
1004
|
const resolvedPurpose = stdinTransform ? 'stdin-transform' : purpose;
|
|
946
1005
|
return {
|
|
@@ -966,7 +1025,7 @@ export function analyzeReadonlyShellQuery(command, options = {}) {
|
|
|
966
1025
|
const argv = parseStageArgv(stages[index], options);
|
|
967
1026
|
if (!argv)
|
|
968
1027
|
return { kind: 'unproven', reason: 'non-literal-command' };
|
|
969
|
-
const analyzed = analyzeCommand(argv, index > 0);
|
|
1028
|
+
const analyzed = analyzeCommand(argv, index > 0 || options.hasPipelineInput === true);
|
|
970
1029
|
if (!analyzed)
|
|
971
1030
|
return { kind: 'unproven', reason: 'unsupported-command-or-option' };
|
|
972
1031
|
if (index > 0) {
|
|
@@ -44,12 +44,19 @@ const PERMISSION_ERROR_CODES = new Set([
|
|
|
44
44
|
'APPROVAL_TIMEOUT',
|
|
45
45
|
'DELEGATION_FAILED',
|
|
46
46
|
]);
|
|
47
|
+
const INVALID_ARGUMENT_POLICY_CODES = new Set([
|
|
48
|
+
'apply_patch_invalid_argument',
|
|
49
|
+
'apply_patch_unparseable',
|
|
50
|
+
'file_change_invalid_argument',
|
|
51
|
+
]);
|
|
47
52
|
const DETAIL_CODE_BY_POLICY_CODE = {
|
|
48
53
|
h_class_protection: 'H_CLASS_PROTECTION',
|
|
54
|
+
shell_implicit_cwd: 'IMPLICIT_CWD',
|
|
49
55
|
l_class_protection: 'L_CLASS_PROTECTION',
|
|
50
56
|
native_file_change_required: 'NATIVE_FILE_CHANGE_REQUIRED',
|
|
51
57
|
apply_patch_invalid_argument: 'INVALID_ARGUMENT',
|
|
52
58
|
apply_patch_unparseable: 'APPLY_PATCH_UNPARSEABLE',
|
|
59
|
+
file_change_invalid_argument: 'INVALID_ARGUMENT',
|
|
53
60
|
apply_patch_workspace_escape: 'APPLY_PATCH_WORKSPACE_ESCAPE',
|
|
54
61
|
ec_shell_invalid_quote: 'INVALID_QUOTE',
|
|
55
62
|
ec_command_not_canonical: 'INVALID_ARGUMENT',
|
|
@@ -121,7 +128,12 @@ export function normalizeToolErrorClassification(input) {
|
|
|
121
128
|
if (explicitPermission && facts.started)
|
|
122
129
|
classificationConflict = true;
|
|
123
130
|
let errorCode;
|
|
124
|
-
if (
|
|
131
|
+
if (decisionSource === 'policy' && facts.blocked && !facts.started
|
|
132
|
+
&& typeof input.policyCode === 'string' && INVALID_ARGUMENT_POLICY_CODES.has(input.policyCode)
|
|
133
|
+
&& (explicit === undefined || explicit === 'POLICY_DENIED' || explicit === 'INVALID_ARGUMENT')) {
|
|
134
|
+
errorCode = 'INVALID_ARGUMENT';
|
|
135
|
+
}
|
|
136
|
+
else if (explicitPermission) {
|
|
125
137
|
errorCode = exactPermissionBlock && !facts.started
|
|
126
138
|
? explicit
|
|
127
139
|
: 'EXECUTION_FAILED';
|