evolcore 0.0.42 → 0.0.43-test.1
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 +35 -0
- package/bin/ec-safe-output.js +4 -1
- package/dist/ability/application-service.js +882 -0
- package/dist/ability/authorization.js +70 -0
- package/dist/ability/command-contract.js +105 -0
- package/dist/ability/daemon.js +137 -0
- package/dist/ability/development.js +450 -0
- package/dist/ability/environment.js +75 -0
- package/dist/ability/interop-v1.js +547 -0
- package/dist/ability/management.js +79 -0
- package/dist/ability/package.js +264 -0
- package/dist/ability/provider.js +73 -0
- package/dist/ability/publication.js +107 -0
- package/dist/ability/resources.js +106 -0
- package/dist/ability/runtime.js +212 -0
- package/dist/ability/secrets.js +47 -0
- package/dist/ability/store.js +112 -0
- package/dist/ability/toolchain.js +69 -0
- package/dist/ability/types.js +14 -0
- package/dist/ability/versions.js +32 -0
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +4 -0
- package/dist/agents/codex-runner.js +81 -17
- package/dist/agents/ecagent-plugin-lazy.js +41 -0
- package/dist/agents/ecagent-runner.js +18 -11
- package/dist/aun/ability-device-routing.js +12 -1
- package/dist/aun/aid/agentmd.js +2 -2
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/identity.js +45 -0
- package/dist/aun/aid/index.js +1 -0
- package/dist/aun/aid/managed-operation.js +73 -2
- package/dist/channels/aun.js +64 -18
- package/dist/channels/builtin-plugins.js +14 -0
- package/dist/channels/dingtalk.js +78 -26
- package/dist/channels/feishu.js +89 -14
- package/dist/channels/qqbot.js +84 -19
- package/dist/channels/wechat.js +77 -19
- package/dist/channels/wecom.js +67 -22
- package/dist/cli/ability-command.js +92 -0
- package/dist/cli/aun-commands.js +124 -85
- package/dist/cli/daemon-commands.js +37 -85
- package/dist/cli/index.js +14 -0
- package/dist/cli/init.js +11 -13
- package/dist/cli/managed-command-guard.js +6 -0
- package/dist/cli/model.js +101 -104
- package/dist/cli/provider-command.js +6 -4
- package/dist/cli/restart-monitor.js +52 -11
- package/dist/cli/upgrade-command.js +102 -0
- package/dist/cli/version.js +1 -1
- package/dist/config/access-policy.js +4 -2
- package/dist/config/builtin-roles.js +1 -0
- package/dist/config/config-field-policy.js +4 -0
- package/dist/config/config-manager.js +7 -0
- package/dist/config/provider-ipc-service.js +10 -0
- package/dist/config/providers-config.js +12 -3
- package/dist/config/providers-management.js +45 -9
- package/dist/config/schema-migration.js +40 -22
- package/dist/contracts/ecweb-service-protocol.js +2 -1
- package/dist/core/agent-runtime.js +2 -1
- package/dist/core/auth/agent-delegation.js +21 -5
- package/dist/core/auth/auth-gateway.js +31 -9
- package/dist/core/auth/authorization-audit.js +52 -4
- package/dist/core/auth/delegation-authorization.js +140 -4
- package/dist/core/auth/operation-authorizer.js +114 -13
- package/dist/core/auth/operation-catalog.js +118 -4
- package/dist/core/baseagent-loader.js +14 -1
- package/dist/core/channel-loader.js +47 -9
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/cli-intent-parser.js +26 -13
- package/dist/core/command/command-handler.js +232 -76
- package/dist/core/command/connect-menu.js +10 -4
- package/dist/core/command/daemon-diagnostics.js +3 -3
- package/dist/core/command/data-root-resolver.js +2 -3
- package/dist/core/command/menu-catalog.js +10 -3
- package/dist/core/command/menu-handler.js +321 -46
- package/dist/core/command/menu-protocol.js +53 -7
- package/dist/core/command/pa-workspace-calendar.js +1 -2
- package/dist/core/command/pa-workspace-items.js +486 -0
- package/dist/core/command/pa-workspace-store.js +10 -1
- package/dist/core/command/slash-gate.js +2 -2
- package/dist/core/command/slash-handler.js +67 -25
- package/dist/core/contact-bind-registry.js +27 -0
- package/dist/core/daemon-control.js +3 -3
- package/dist/core/daemon-lifecycle.js +2 -1
- package/dist/core/event-bus.js +9 -2
- package/dist/core/handoff/ipc-registration.js +1 -0
- package/dist/core/host-snapshot.js +1 -2
- package/dist/core/initialization/service.js +32 -11
- package/dist/core/ipc-registration.js +18 -5
- package/dist/core/memory/consolidation-context.js +2 -2
- package/dist/core/message/aun-request-registry.js +99 -18
- package/dist/core/message/im-renderer.js +16 -11
- package/dist/core/message/message-admission.js +25 -20
- package/dist/core/message/message-bridge.js +21 -47
- package/dist/core/message/message-queue.js +3 -0
- package/dist/core/message/response-engine.js +7 -5
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/permission/ec-command-parser.js +41 -9
- package/dist/core/permission/permission-result.js +1 -0
- package/dist/core/permission/protected-paths.js +25 -14
- package/dist/core/permission/tool-policy.js +108 -107
- package/dist/core/plugin-lifecycle.js +133 -0
- package/dist/core/runner-reload-transaction.js +4 -1
- package/dist/core/system-session/memory.js +16 -3
- package/dist/core/task/task-activity-store.js +50 -0
- package/dist/core/task/task-image-resources.js +140 -0
- package/dist/core/thread/ipc-operation.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/directory/canonical-digest.js +5 -3
- package/dist/directory/owner-directory-admission.js +22 -2
- package/dist/directory/owner-directory-cache.js +394 -60
- package/dist/directory/owner-directory-markdown.js +29 -2
- package/dist/directory/owner-directory-scope.js +35 -16
- package/dist/ecweb/basic-settings-service.js +4 -1
- package/dist/ecweb/pairing.js +41 -0
- package/dist/ecweb/providers-service.js +8 -1
- package/dist/{utils/ecweb-utils.js → ecweb/runtime/launch.js} +3 -27
- package/dist/ecweb/runtime/lifecycle.js +184 -0
- package/dist/{utils/ecweb-supervisor.js → ecweb/runtime/supervisor.js} +32 -27
- package/dist/index.js +34 -25
- package/dist/ipc.js +124 -7
- package/dist/response-system/engines/v1/proactive-flow.js +1 -1
- package/dist/trigger/authorization.js +2 -2
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/avatar-upload.js +3 -1
- package/dist/utils/cross-platform.js +31 -2
- package/dist/utils/host-info.js +36 -0
- package/dist/utils/instance-registry.js +38 -11
- package/dist/utils/logger.js +9 -0
- package/dist/utils/{process-tree-stats.js → process-tree.js} +29 -0
- package/dist/utils/tool-summary.js +9 -1
- package/dist/utils/upgrade-jobs.js +96 -15
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/README.md +19 -0
- package/ecagent/dist/harness/agent-harness.js +9 -0
- package/ecagent/dist/harness/env/nodejs.js +71 -11
- package/ecagent/dist/harness/env/windows-shell.d.ts +7 -0
- package/ecagent/dist/harness/env/windows-shell.js +132 -0
- package/kits/docs/aun/ABILITY_CALLING.md +38 -9
- package/kits/docs/evolcore/INDEX.md +5 -1
- package/kits/docs/evolcore/ability.md +181 -0
- package/kits/docs/evolcore/aid.md +20 -0
- package/kits/docs/evolcore/config.md +10 -6
- package/kits/docs/evolcore/menu-protocol.md +40 -1
- package/kits/docs/evolcore/provider.md +2 -2
- package/kits/docs/evolcore/tool-authorization.md +270 -0
- package/kits/runtime/ability-job.ps1 +41 -0
- package/kits/runtime/ability-runner.mjs +67 -0
- package/kits/runtime/ability-secret.ps1 +59 -0
- package/kits/runtime/ability-templates/go/main.go +59 -0
- package/kits/runtime/ability-templates/java/Json.java +67 -0
- package/kits/runtime/ability-templates/java/Runner.java +42 -0
- package/kits/runtime/ability-templates/python/runner.py +48 -0
- package/kits/runtime/ability-templates/rust/json.rs +87 -0
- package/kits/runtime/ability-templates/rust/runner.rs +35 -0
- package/kits/schemas/_meta.json +12 -1
- package/kits/schemas/ability-plugin.schema.1.json +107 -0
- package/kits/schemas/ability-project.schema.1.json +31 -0
- package/kits/schemas/agent-config.schema.16.json +20 -0
- package/kits/schemas/agent-config.schema.17.json +20 -0
- package/kits/schemas/agent-config.schema.18.json +917 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/aid-ability/SKILL.md +5 -4
- package/kits/skills/ec-ability/SKILL.md +67 -0
- package/kits/skills/ec-ability/references/contract-checklist.md +37 -0
- package/kits/skills/ec-ability/references/development.md +104 -0
- package/kits/skills/ec-ability/references/management.md +117 -0
- package/kits/skills/ec-ability/references/recovery.md +27 -0
- package/kits/skills/ec-ability/references/runtime-protocol.md +109 -0
- package/kits/skills/ec-ability/references/workflows.md +15 -0
- package/kits/skills/ec-service-proxy/SKILL.md +12 -0
- package/kits/skills/personal-assistant/SKILL.md +240 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +78 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +397 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +113 -25
- package/kits/skills/personal-assistant/scripts/lock.mjs +189 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +35 -10
- package/kits/skills/personal-assistant/scripts/verify.mjs +2 -1
- package/kits/skills/personal-assistant/templates/persona-section.md +54 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +1 -1
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/system-fragments/channel.md +2 -1
- package/kits/templates/system-fragments/commands.md +1 -0
- package/package.json +5 -3
- package/dist/core/command/data-root-error.js +0 -10
- package/dist/utils/machine-info.js +0 -46
- package/dist/utils/process-tree-worker.js +0 -31
- package/dist/utils/windows-output.js +0 -36
|
@@ -37,6 +37,10 @@ export function buildCanonicalEvolcoreExecutionSpec(input) {
|
|
|
37
37
|
spec.cwd = input.cwd;
|
|
38
38
|
if (input.command?.mergeStderr)
|
|
39
39
|
spec.mergeStderr = true;
|
|
40
|
+
if (input.command?.discardStdout)
|
|
41
|
+
spec.discardStdout = true;
|
|
42
|
+
if (input.command?.discardStderr)
|
|
43
|
+
spec.discardStderr = true;
|
|
40
44
|
if (input.command?.filterChain?.length)
|
|
41
45
|
spec.filterChain = input.command.filterChain.map(stage => [...stage]);
|
|
42
46
|
if (input.command?.suffixArgv?.length)
|
|
@@ -333,11 +337,11 @@ const APPLY_PATCH_EXECUTABLE_BASENAMES = new Set([
|
|
|
333
337
|
'apply_patch.ps1',
|
|
334
338
|
]);
|
|
335
339
|
const EVOLCORE_SUBCOMMANDS = new Set([
|
|
336
|
-
'agent', 'aid', 'bench', 'config', 'peer', 'ctl', 'data', 'diag', 'diagnose',
|
|
340
|
+
'ability', 'agent', 'aid', 'bench', 'config', 'peer', 'ctl', 'data', 'diag', 'diagnose',
|
|
337
341
|
'fs', 'gateway', 'group', 'handoff', 'init', 'link-rules', 'logs', 'menu-client',
|
|
338
342
|
'mode', 'model', 'msg', 'mv', 'net', 'queue', 'response', 'restart',
|
|
339
343
|
'restart-monitor', 'rpc', 'start', 'stats', 'status', 'stop', 'storage', 'task',
|
|
340
|
-
'trigger', 'proxy', 'version', 'watch', 'session', 'pa-workspace',
|
|
344
|
+
'trigger', 'proxy', 'version', 'watch', 'session', 'pa-workspace', 'upgrade', 'update',
|
|
341
345
|
]);
|
|
342
346
|
// Development/install entrypoints that are part of this repository's CLI.
|
|
343
347
|
// Only these exact relative paths are canonicalized; arbitrary Node scripts
|
|
@@ -2668,7 +2672,16 @@ function scanBoundedOutputOperators(command) {
|
|
|
2668
2672
|
if (char === '>') {
|
|
2669
2673
|
if (command[index + 1] === '>')
|
|
2670
2674
|
return null;
|
|
2671
|
-
|
|
2675
|
+
// An adjacent, unquoted IO number is shell syntax, never an EC argv
|
|
2676
|
+
// operand. Do not mistake `2 > ...` or a quoted '2' for stderr.
|
|
2677
|
+
const fd = command.slice(0, index).match(/(?:^|[ \t])(\d+)$/)?.[1];
|
|
2678
|
+
if (fd && fd !== '1' && fd !== '2')
|
|
2679
|
+
return null;
|
|
2680
|
+
operators.push({
|
|
2681
|
+
kind: fd === '2' ? 'redirect-stderr' : 'redirect',
|
|
2682
|
+
start: fd ? index - fd.length : index,
|
|
2683
|
+
end: index + 1,
|
|
2684
|
+
});
|
|
2672
2685
|
continue;
|
|
2673
2686
|
}
|
|
2674
2687
|
if (char === '$' || char === '`' || char === ';' || char === '&' || char === '<'
|
|
@@ -2800,22 +2813,39 @@ export function parseBoundedOutputShellCommand(command) {
|
|
|
2800
2813
|
return null;
|
|
2801
2814
|
const filterChain = [];
|
|
2802
2815
|
let outputPath;
|
|
2816
|
+
let discardStdout = false;
|
|
2817
|
+
let discardStderr = false;
|
|
2803
2818
|
let prevEnd = mergeStderr ? operators[0].end : first.start;
|
|
2804
2819
|
while (cursor < operators.length) {
|
|
2805
2820
|
const operator = operators[cursor];
|
|
2806
2821
|
// 段与段之间只允许空白(合并 stderr 与首个管道之间同理)。
|
|
2807
2822
|
if (trimShellSpacing(input.slice(prevEnd, operator.start)))
|
|
2808
2823
|
return null;
|
|
2809
|
-
if (operator.kind === 'redirect') {
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
const outputArgv = parseLiteralShellArgv(trimShellSpacing(input.slice(operator.end)));
|
|
2824
|
+
if (operator.kind === 'redirect' || operator.kind === 'redirect-stderr') {
|
|
2825
|
+
const next = operators[cursor + 1];
|
|
2826
|
+
const segmentEnd = next ? next.start : input.length;
|
|
2827
|
+
const outputArgv = parseLiteralShellArgv(trimShellSpacing(input.slice(operator.end, segmentEnd)));
|
|
2814
2828
|
if (!outputArgv || outputArgv.length !== 1)
|
|
2815
2829
|
return null;
|
|
2816
2830
|
if (outputArgv[0].includes('$') && !outputArgv[0].includes(MANAGED_TMPDIR_TOKEN))
|
|
2817
2831
|
return null;
|
|
2818
|
-
|
|
2832
|
+
if (operator.kind === 'redirect-stderr') {
|
|
2833
|
+
// Only the source process' stderr may be discarded. A redirection
|
|
2834
|
+
// on a filter, a file target, or a merge/discard ordering is unproven.
|
|
2835
|
+
if (cursor !== 0 || mergeStderr || outputArgv[0] !== '/dev/null')
|
|
2836
|
+
return null;
|
|
2837
|
+
discardStderr = true;
|
|
2838
|
+
prevEnd = segmentEnd;
|
|
2839
|
+
cursor++;
|
|
2840
|
+
continue;
|
|
2841
|
+
}
|
|
2842
|
+
// stdout belongs to the last filter (or the source without filters).
|
|
2843
|
+
if (next)
|
|
2844
|
+
return null;
|
|
2845
|
+
if (outputArgv[0] === '/dev/null')
|
|
2846
|
+
discardStdout = true;
|
|
2847
|
+
else
|
|
2848
|
+
outputPath = restoreManagedTmpDirToken(outputArgv[0]);
|
|
2819
2849
|
cursor++;
|
|
2820
2850
|
break;
|
|
2821
2851
|
}
|
|
@@ -2834,6 +2864,8 @@ export function parseBoundedOutputShellCommand(command) {
|
|
|
2834
2864
|
return {
|
|
2835
2865
|
argv,
|
|
2836
2866
|
mergeStderr,
|
|
2867
|
+
...(discardStdout ? { discardStdout } : {}),
|
|
2868
|
+
...(discardStderr ? { discardStderr } : {}),
|
|
2837
2869
|
...(filterChain.length > 0 ? { filterChain } : {}),
|
|
2838
2870
|
...(outputPath ? { outputPath } : {}),
|
|
2839
2871
|
};
|
|
@@ -69,6 +69,7 @@ export function permissionApprovalResult(requestId, decision, approver = {}) {
|
|
|
69
69
|
decision,
|
|
70
70
|
decisionSource: 'approval',
|
|
71
71
|
requestId,
|
|
72
|
+
approvalMechanism: 'human',
|
|
72
73
|
reason: decision === 'deny' ? '审批人明确拒绝了本次操作;操作未执行。' : '审批人已批准本次操作。',
|
|
73
74
|
...(decision === 'deny' ? { policyCode: 'user_approval_denied', errorDetailCode: 'USER_APPROVAL_DENIED' } : {}),
|
|
74
75
|
approverOperatorId: approver.approverOperatorId,
|
|
@@ -17,6 +17,7 @@ const H_CLASS_RELATIVE_PATTERNS = [
|
|
|
17
17
|
/^\.lock$/,
|
|
18
18
|
/^daemon\.pid$/,
|
|
19
19
|
/^agents\/[^/]+\/data\/codex-tokens(?:\/|$)/,
|
|
20
|
+
/^agents\/[^/]+\/data\/task-resources(?:\/|$)/,
|
|
20
21
|
/^agents\/[^/]+\/data\/(?:.*\/)?(?:context-tokens|menu-tokens)\.json(?:_|__|\.tmp-.*)?$/,
|
|
21
22
|
];
|
|
22
23
|
const H_CLASS_REFERENCE_PATTERNS = [
|
|
@@ -24,7 +25,7 @@ const H_CLASS_REFERENCE_PATTERNS = [
|
|
|
24
25
|
/(?:^|[/\\\s"'=<>])data[\\/]/,
|
|
25
26
|
/(?:^|[/\\\s"'=<>])(?:AIDs|aids)[\\/]/,
|
|
26
27
|
/(?:^|[^A-Za-z0-9_.-])(?:\.device_id|\.env|\.seed(?:\.[^/\\\s"']*)?|\.migrated-[^/\\\s"']*|\.lock|daemon\.pid)(?=$|[\s"';&|<>)},])/,
|
|
27
|
-
/(?:^|[/\\\s"'=<>])agents[\\/][^/\\\s"']+[\\/]data[\\/](?:codex-tokens|(?:.*[\\/])?(?:context-tokens|menu-tokens)\.json)(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
28
|
+
/(?:^|[/\\\s"'=<>])agents[\\/][^/\\\s"']+[\\/]data[\\/](?:codex-tokens|task-resources|(?:.*[\\/])?(?:context-tokens|menu-tokens)\.json)(?:[\\/]|$|[\s"';&|<>)},])/,
|
|
28
29
|
];
|
|
29
30
|
// H-class directory roots are kept separately from the full path matcher so
|
|
30
31
|
// an exact metadata query can distinguish a protected directory from a
|
|
@@ -36,6 +37,7 @@ const H_CLASS_DIRECTORY_RELATIVE_PATTERNS = [
|
|
|
36
37
|
/^\.snapshots(?:\/|$)/,
|
|
37
38
|
/^CA(?:\/|$)/,
|
|
38
39
|
/^agents\/[^/]+\/data\/codex-tokens(?:\/|$)/,
|
|
40
|
+
/^agents\/[^/]+\/data\/task-resources(?:\/|$)/,
|
|
39
41
|
];
|
|
40
42
|
const L_CLASS_RELATIVE_PATTERNS = [
|
|
41
43
|
/^daemon\.json$/,
|
|
@@ -59,6 +61,12 @@ function normalizeForComparison(value) {
|
|
|
59
61
|
const resolved = path.resolve(value);
|
|
60
62
|
return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
61
63
|
}
|
|
64
|
+
function normalizeWindowsDrivePath(value) {
|
|
65
|
+
if (process.platform !== 'win32')
|
|
66
|
+
return value;
|
|
67
|
+
const match = value.match(/^\/([A-Za-z])(?:\/(.*))?$/);
|
|
68
|
+
return match ? `${match[1].toUpperCase()}:\\${(match[2] ?? '').replace(/\//g, '\\')}` : value;
|
|
69
|
+
}
|
|
62
70
|
function resolveThroughExistingAncestor(value) {
|
|
63
71
|
const absolute = path.resolve(value);
|
|
64
72
|
const missing = [];
|
|
@@ -119,7 +127,7 @@ function agentScopeCandidate(value, options = {}) {
|
|
|
119
127
|
if (!normalizeAid(options.selfAid))
|
|
120
128
|
return undefined;
|
|
121
129
|
const root = resolveThroughExistingAncestor(options.root ?? resolveRoot());
|
|
122
|
-
const lexical =
|
|
130
|
+
const lexical = resolveLexicalCandidate(value, options.cwd);
|
|
123
131
|
if (isSameOrDescendant(lexical, root)) {
|
|
124
132
|
const relative = path.relative(root, lexical).split(path.sep).join('/');
|
|
125
133
|
if (matchesAgentScopeRelative(relative, options.selfAid))
|
|
@@ -167,7 +175,7 @@ function matchesSelfAwareHClassRelative(relative, selfAid) {
|
|
|
167
175
|
if (!own)
|
|
168
176
|
return false;
|
|
169
177
|
const escaped = own.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
170
|
-
return new RegExp(`^agents/${escaped}/data/codex-tokens(?:/|$)`).test(relative)
|
|
178
|
+
return new RegExp(`^agents/${escaped}/data/(?:codex-tokens|task-resources)(?:/|$)`).test(relative)
|
|
171
179
|
|| new RegExp(`^agents/${escaped}/data/(?:.*\/)?(?:context-tokens|menu-tokens)\\.json(?:_|__|\\.tmp-.*)?$`).test(relative);
|
|
172
180
|
}
|
|
173
181
|
export function isSameOrDescendant(candidate, parent) {
|
|
@@ -177,14 +185,13 @@ export function isSameOrDescendant(candidate, parent) {
|
|
|
177
185
|
return relative === '' || (!relative.startsWith('..' + path.sep) && relative !== '..' && !path.isAbsolute(relative));
|
|
178
186
|
}
|
|
179
187
|
export function resolveProtectedCandidate(value, cwd = process.cwd()) {
|
|
180
|
-
const
|
|
188
|
+
const normalized = normalizeWindowsDrivePath(value);
|
|
189
|
+
const absolute = path.isAbsolute(normalized) ? normalized : path.resolve(cwd, normalized);
|
|
181
190
|
return resolveThroughExistingAncestor(absolute);
|
|
182
191
|
}
|
|
183
192
|
export function isHClassPath(value, options = {}) {
|
|
184
193
|
const root = resolveThroughExistingAncestor(options.root ?? resolveRoot());
|
|
185
|
-
const lexicalCandidate =
|
|
186
|
-
? path.resolve(value)
|
|
187
|
-
: path.resolve(options.cwd ?? process.cwd(), value);
|
|
194
|
+
const lexicalCandidate = resolveLexicalCandidate(value, options.cwd);
|
|
188
195
|
if (hasInvalidExplicitSelfAid(options))
|
|
189
196
|
return isSameOrDescendant(lexicalCandidate, root);
|
|
190
197
|
if (agentScopeCandidate(value, options))
|
|
@@ -205,11 +212,12 @@ export function isHClassPath(value, options = {}) {
|
|
|
205
212
|
function hasPathSyntax(value) {
|
|
206
213
|
return /[\0\r\n$`*?\[\]{}<>|;&]/.test(value);
|
|
207
214
|
}
|
|
208
|
-
function
|
|
209
|
-
|
|
215
|
+
function resolveLexicalCandidate(value, cwd = process.cwd()) {
|
|
216
|
+
const normalized = normalizeWindowsDrivePath(value);
|
|
217
|
+
return path.isAbsolute(normalized) ? path.resolve(normalized) : path.resolve(cwd, normalized);
|
|
210
218
|
}
|
|
211
219
|
function resolveWithoutFinalSymlink(value, cwd = process.cwd()) {
|
|
212
|
-
const absolute =
|
|
220
|
+
const absolute = resolveLexicalCandidate(value, cwd);
|
|
213
221
|
const basename = path.basename(absolute);
|
|
214
222
|
const parent = resolveThroughExistingAncestor(path.dirname(absolute));
|
|
215
223
|
return basename ? path.join(parent, basename) : parent;
|
|
@@ -337,9 +345,7 @@ export function isLClassPath(value, options = {}) {
|
|
|
337
345
|
if (hasInvalidExplicitSelfAid(options))
|
|
338
346
|
return false;
|
|
339
347
|
const root = resolveThroughExistingAncestor(options.root ?? resolveRoot());
|
|
340
|
-
const lexicalCandidate =
|
|
341
|
-
? path.resolve(value)
|
|
342
|
-
: path.resolve(options.cwd ?? process.cwd(), value);
|
|
348
|
+
const lexicalCandidate = resolveLexicalCandidate(value, options.cwd);
|
|
343
349
|
if (isSameOrDescendant(lexicalCandidate, root)) {
|
|
344
350
|
const lexicalRelative = path.relative(root, lexicalCandidate).split(path.sep).join('/');
|
|
345
351
|
if (!matchesAgentScopeRelative(lexicalRelative, options.selfAid)
|
|
@@ -390,6 +396,7 @@ function getLegacyHClassSandboxPatterns(root) {
|
|
|
390
396
|
path.join('agents', '*', 'sessions', '**'), path.join('agents', '*', 'data', 'channels', '**'),
|
|
391
397
|
path.join('agents', '*', 'data', 'handoff', '**'), path.join('agents', '*', 'data', 'async-questions', '**'),
|
|
392
398
|
path.join('agents', '*', 'data', 'task-activity', '**'), path.join('agents', '*', 'data', 'aun', '**'),
|
|
399
|
+
path.join('agents', '*', 'data', 'task-resources', '**'),
|
|
393
400
|
path.join('agents', '*', 'data', 'outbox.jsonl*'), path.join('agents', '*', 'data', 'activity-outbox.jsonl*'),
|
|
394
401
|
path.join('agents', '*', 'data', 'contact-audit.jsonl'),
|
|
395
402
|
];
|
|
@@ -409,6 +416,8 @@ export function getHClassSandboxPatterns(root = resolveRoot(), options = {}) {
|
|
|
409
416
|
'.device_id', '.env', '.seed', '.seed.*', '.lock', 'daemon.pid',
|
|
410
417
|
path.join('agents', options.selfAid, 'data', 'codex-tokens'),
|
|
411
418
|
path.join('agents', options.selfAid, 'data', 'codex-tokens', '**'),
|
|
419
|
+
path.join('agents', options.selfAid, 'data', 'task-resources'),
|
|
420
|
+
path.join('agents', options.selfAid, 'data', 'task-resources', '**'),
|
|
412
421
|
path.join('agents', options.selfAid, 'data', '**', 'context-tokens.json'),
|
|
413
422
|
path.join('agents', options.selfAid, 'data', '**', 'menu-tokens.json'),
|
|
414
423
|
];
|
|
@@ -473,6 +482,7 @@ function getAgentAwareHClassMaskTargets(root, selfAid) {
|
|
|
473
482
|
continue;
|
|
474
483
|
}
|
|
475
484
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'codex-tokens'));
|
|
485
|
+
addExistingTarget(targets, path.join(agentRoot, 'data', 'task-resources'));
|
|
476
486
|
const walk = (directory, depth = 0) => {
|
|
477
487
|
if (depth > 8)
|
|
478
488
|
return;
|
|
@@ -561,6 +571,7 @@ export function getExistingHClassMaskTargets(root = resolveRoot(), options = {})
|
|
|
561
571
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'handoff'));
|
|
562
572
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'async-questions'));
|
|
563
573
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'task-activity'));
|
|
574
|
+
addExistingTarget(targets, path.join(agentRoot, 'data', 'task-resources'));
|
|
564
575
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'aun'));
|
|
565
576
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'outbox.jsonl'));
|
|
566
577
|
addExistingTarget(targets, path.join(agentRoot, 'data', 'activity-outbox.jsonl'));
|
|
@@ -965,7 +976,7 @@ export function hClassGrantIncludesProtectedPath(value, options = {}) {
|
|
|
965
976
|
return true;
|
|
966
977
|
if (relative.length <= 2)
|
|
967
978
|
return true;
|
|
968
|
-
if (relative[2] === 'data' && (!relative[3] || ['codex-tokens', 'channels'].includes(relative[3])))
|
|
979
|
+
if (relative[2] === 'data' && (!relative[3] || ['codex-tokens', 'channels', 'task-resources'].includes(relative[3])))
|
|
969
980
|
return true;
|
|
970
981
|
}
|
|
971
982
|
// A grant scoped to an ordinary self-Agent subtree does not automatically
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import { parseOwnershipCommand } from '../../aun/aid/ownership-operation.js';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import os from 'os';
|
|
5
4
|
import { randomUUID } from 'crypto';
|
|
@@ -1207,7 +1206,7 @@ function literalProtectedShellOperand(command, className, options, depth = 0) {
|
|
|
1207
1206
|
const segmentAnalysis = analyzeReadonlyShellQuery(segment);
|
|
1208
1207
|
if (segmentAnalysis.kind === 'proven-readonly') {
|
|
1209
1208
|
for (const operand of queryPathOperands(segmentAnalysis)) {
|
|
1210
|
-
const matched =
|
|
1209
|
+
const matched = shellOperandMatchesClass(operand.operand, className, options, operand.accessKind);
|
|
1211
1210
|
if (matched)
|
|
1212
1211
|
return matched;
|
|
1213
1212
|
}
|
|
@@ -1225,6 +1224,15 @@ function literalProtectedShellOperand(command, className, options, depth = 0) {
|
|
|
1225
1224
|
const matched = protectedClassPath(value, className, options);
|
|
1226
1225
|
if (matched)
|
|
1227
1226
|
return matched;
|
|
1227
|
+
if (className === 'h' && commandName(argv[0]) === 'rg'
|
|
1228
|
+
&& hClassReadScopeIncludesProtectedPath(value, options)) {
|
|
1229
|
+
const root = resolveProtectedCandidate(options.root ?? resolveRoot());
|
|
1230
|
+
const scope = resolveProtectedCandidate(value, options.cwd);
|
|
1231
|
+
const target = getExistingHClassMaskTargets(root, { selfAid: options.selfAid })
|
|
1232
|
+
.find(candidate => isSameOrDescendant(candidate.path, scope));
|
|
1233
|
+
if (target)
|
|
1234
|
+
return target.path;
|
|
1235
|
+
}
|
|
1228
1236
|
}
|
|
1229
1237
|
for (const value of literalScriptFilesystemOperands(argv)) {
|
|
1230
1238
|
const matched = protectedClassPath(value, className, options);
|
|
@@ -1294,6 +1302,14 @@ function shellOperandMatchesClass(operand, className, options, accessKind = oper
|
|
|
1294
1302
|
if (reference)
|
|
1295
1303
|
return resolveProtectedCandidate(operand.value, options.cwd);
|
|
1296
1304
|
if (operand.access === 'recursive') {
|
|
1305
|
+
if (className === 'h') {
|
|
1306
|
+
const scope = resolveProtectedCandidate(operand.value, options.cwd);
|
|
1307
|
+
const root = resolveProtectedCandidate(options.root ?? resolveRoot());
|
|
1308
|
+
const target = getExistingHClassMaskTargets(root, { selfAid: options.selfAid })
|
|
1309
|
+
.find(candidate => isSameOrDescendant(candidate.path, scope));
|
|
1310
|
+
if (target)
|
|
1311
|
+
return target.path;
|
|
1312
|
+
}
|
|
1297
1313
|
const matched = className === 'h'
|
|
1298
1314
|
? hClassReadScopeIncludesProtectedPath(operand.value, options)
|
|
1299
1315
|
: lClassGrantIncludesProtectedPath(operand.value, options);
|
|
@@ -1334,7 +1350,13 @@ function analyzeShellProtectedOperands(command, options) {
|
|
|
1334
1350
|
lClassPath,
|
|
1335
1351
|
};
|
|
1336
1352
|
}
|
|
1337
|
-
const operands =
|
|
1353
|
+
const operands = analysis.ir.pipelines.flatMap(pipeline => pipeline.flatMap(query => {
|
|
1354
|
+
const scopes = boundedRgSourceScopes(query, options);
|
|
1355
|
+
return (scopes ?? query.pathOperands).map(operand => ({
|
|
1356
|
+
operand,
|
|
1357
|
+
accessKind: query.accessKind ?? (operand.access === 'recursive' ? 'enumerate' : 'content'),
|
|
1358
|
+
}));
|
|
1359
|
+
}));
|
|
1338
1360
|
const hClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'h', options, accessKind)).find(Boolean);
|
|
1339
1361
|
const lClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'l', options, accessKind)).find(Boolean);
|
|
1340
1362
|
return {
|
|
@@ -1539,6 +1561,63 @@ function boundedRootSourceEnumeration(analysis, projectPath) {
|
|
|
1539
1561
|
return pipeline.slice(1).every(command => ['head', 'sort', 'grep', 'wc'].includes(command.executable)
|
|
1540
1562
|
&& command.pathOperands.length === 0);
|
|
1541
1563
|
}
|
|
1564
|
+
function boundedRgSourceScopes(query, options) {
|
|
1565
|
+
if (query.executable !== 'rg' || !options.cwd || query.pathOperands.length !== 1
|
|
1566
|
+
|| query.pathOperands[0].access !== 'recursive')
|
|
1567
|
+
return undefined;
|
|
1568
|
+
const workspace = resolveProtectedCandidate(options.cwd);
|
|
1569
|
+
if (resolveProtectedCandidate(query.pathOperands[0].value, options.cwd) !== workspace)
|
|
1570
|
+
return undefined;
|
|
1571
|
+
const sourceRoots = new Set(['src', 'kits', 'docs', 'tests', 'test', 'lib', 'scripts']);
|
|
1572
|
+
const sourceGlob = /^(?:src|kits|docs|tests|test|lib|scripts)\/\*\*$/;
|
|
1573
|
+
const scopes = new Set();
|
|
1574
|
+
const flags = new Set(['--no-config', '-n', '--line-number', '--files', '--hidden', '--no-ignore', '-i', '--ignore-case', '-F', '--fixed-strings']);
|
|
1575
|
+
let noConfig = false;
|
|
1576
|
+
let sawPattern = false;
|
|
1577
|
+
let files = false;
|
|
1578
|
+
let optionsEnded = false;
|
|
1579
|
+
for (let index = 1; index < query.argv.length; index++) {
|
|
1580
|
+
const argument = query.argv[index];
|
|
1581
|
+
if (!optionsEnded && argument === '--') {
|
|
1582
|
+
optionsEnded = true;
|
|
1583
|
+
continue;
|
|
1584
|
+
}
|
|
1585
|
+
if (!optionsEnded && (argument === '-g' || argument === '--glob')) {
|
|
1586
|
+
const glob = query.argv[++index];
|
|
1587
|
+
if (!glob || !sourceGlob.test(glob))
|
|
1588
|
+
return undefined;
|
|
1589
|
+
const prefix = glob.split('/')[0];
|
|
1590
|
+
if (!sourceRoots.has(prefix) || !glob.startsWith(`${prefix}/`))
|
|
1591
|
+
return undefined;
|
|
1592
|
+
scopes.add(path.join(workspace, prefix));
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
if (!optionsEnded && (argument === '-e' || argument === '--regexp')) {
|
|
1596
|
+
if (++index >= query.argv.length)
|
|
1597
|
+
return undefined;
|
|
1598
|
+
sawPattern = true;
|
|
1599
|
+
continue;
|
|
1600
|
+
}
|
|
1601
|
+
if (!optionsEnded && argument.startsWith('-')) {
|
|
1602
|
+
if (!flags.has(argument))
|
|
1603
|
+
return undefined;
|
|
1604
|
+
if (argument === '--no-config')
|
|
1605
|
+
noConfig = true;
|
|
1606
|
+
if (argument === '--files')
|
|
1607
|
+
files = true;
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
if (!files && !sawPattern) {
|
|
1611
|
+
sawPattern = true;
|
|
1612
|
+
continue;
|
|
1613
|
+
}
|
|
1614
|
+
if (argument !== query.pathOperands[0].value)
|
|
1615
|
+
return undefined;
|
|
1616
|
+
}
|
|
1617
|
+
if (!noConfig || scopes.size === 0)
|
|
1618
|
+
return undefined;
|
|
1619
|
+
return [...scopes].map(value => ({ value, access: 'recursive' }));
|
|
1620
|
+
}
|
|
1542
1621
|
/**
|
|
1543
1622
|
* 只读模式检查(用于 PreToolUse hook 和 canUseTool callback)。普通
|
|
1544
1623
|
* 路径上的受限查询 Bash 可自动执行;H/L-class 和未建模 Shell 仍拒绝。
|
|
@@ -1833,6 +1912,9 @@ function requestsFilesystemRoot(value) {
|
|
|
1833
1912
|
}
|
|
1834
1913
|
return Object.values(record).some(requestsFilesystemRoot);
|
|
1835
1914
|
}
|
|
1915
|
+
const PROTECTED_READ_SEARCH_HINT = '\n\n💡 只读检索请显式指定普通源码目录,例如:' +
|
|
1916
|
+
"\n rg -n -g '!*.json_' -g '!*.json.migrated' -- '<关键词>' src tests kits docs" +
|
|
1917
|
+
'\n 不要把项目根目录作为递归搜索范围;若子目录仍含受保护文件,请继续缩小到明确文件。';
|
|
1836
1918
|
export function checkHClassWrite(toolName, input, context) {
|
|
1837
1919
|
const paths = [];
|
|
1838
1920
|
const grantPaths = [];
|
|
@@ -1872,6 +1954,7 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1872
1954
|
behavior: 'deny',
|
|
1873
1955
|
message: '🔒 临时文件必须位于当前会话的 $TMPDIR 内',
|
|
1874
1956
|
matchedPath: tempCheck.paths[0],
|
|
1957
|
+
matchedRule: 'managed-temp-boundary',
|
|
1875
1958
|
};
|
|
1876
1959
|
}
|
|
1877
1960
|
// A managed temp write is intentionally allowed to contain names such as
|
|
@@ -1900,8 +1983,10 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1900
1983
|
`session=${context?.sessionId} channel=${context?.channel} peer=${context?.peerId} role=${context?.role}`);
|
|
1901
1984
|
return {
|
|
1902
1985
|
behavior: 'deny',
|
|
1903
|
-
message: '🔒 Shell 命令涉及受保护的 H 类配置/证书/快照路径,agent 不可直接操作'
|
|
1986
|
+
message: '🔒 Shell 命令涉及受保护的 H 类配置/证书/快照路径,agent 不可直接操作' +
|
|
1987
|
+
(protectedOperands.analysis.kind === 'proven-readonly' ? PROTECTED_READ_SEARCH_HINT : ''),
|
|
1904
1988
|
matchedPath: protectedOperands.hClassPath,
|
|
1989
|
+
matchedRule: protectedOperands.hClassPath ? 'h-class-shell-operand' : 'h-class-shell-unproven',
|
|
1905
1990
|
};
|
|
1906
1991
|
}
|
|
1907
1992
|
collectFilesystemGrantPaths(input.additionalPermissions, grantPaths, projectRootGrantSubpaths);
|
|
@@ -1927,8 +2012,9 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1927
2012
|
`session=${context?.sessionId} channel=${context?.channel} peer=${context?.peerId} role=${context?.role}`);
|
|
1928
2013
|
return {
|
|
1929
2014
|
behavior: 'deny',
|
|
1930
|
-
message: '🔒 文件读取范围包含受保护的 H 类配置/证书/快照路径,agent 不可直接操作',
|
|
2015
|
+
message: '🔒 文件读取范围包含受保护的 H 类配置/证书/快照路径,agent 不可直接操作' + PROTECTED_READ_SEARCH_HINT,
|
|
1931
2016
|
matchedPath: matchedReadPath,
|
|
2017
|
+
matchedRule: 'h-class-read-scope',
|
|
1932
2018
|
};
|
|
1933
2019
|
}
|
|
1934
2020
|
}
|
|
@@ -1938,6 +2024,7 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1938
2024
|
return {
|
|
1939
2025
|
behavior: 'deny',
|
|
1940
2026
|
message: '🔒 请求的文件系统根权限包含受保护的 H 类路径,已拒绝授权',
|
|
2027
|
+
matchedRule: 'h-class-filesystem-root-grant',
|
|
1941
2028
|
};
|
|
1942
2029
|
}
|
|
1943
2030
|
for (const grantPath of grantPaths) {
|
|
@@ -1951,6 +2038,7 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1951
2038
|
behavior: 'deny',
|
|
1952
2039
|
message: '🔒 请求的文件系统权限范围包含受保护的 H 类路径,已拒绝授权',
|
|
1953
2040
|
matchedPath: resolveProtectedCandidate(grantPath, pathOptions.cwd),
|
|
2041
|
+
matchedRule: 'h-class-grant',
|
|
1954
2042
|
};
|
|
1955
2043
|
}
|
|
1956
2044
|
}
|
|
@@ -1976,6 +2064,7 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
1976
2064
|
behavior: 'deny',
|
|
1977
2065
|
message: '🔒 请求的 project_roots 权限范围包含受保护的 H 类路径,已拒绝授权',
|
|
1978
2066
|
matchedPath: resolveProtectedCandidate(candidate, permissionWorkspace),
|
|
2067
|
+
matchedRule: 'h-class-project-root-grant',
|
|
1979
2068
|
};
|
|
1980
2069
|
}
|
|
1981
2070
|
}
|
|
@@ -2011,9 +2100,10 @@ export function checkHClassWrite(toolName, input, context) {
|
|
|
2011
2100
|
return {
|
|
2012
2101
|
behavior: 'deny',
|
|
2013
2102
|
message: `🔒 此文件受保护,agent 不可直接写入\n\n` +
|
|
2014
|
-
`文件:${filePath}\n` +
|
|
2103
|
+
`文件:${resolveProtectedCandidate(filePath, pathOptions.cwd)}\n` +
|
|
2015
2104
|
`类型:配置/快照/证书等系统关键文件${suggestion}`,
|
|
2016
2105
|
matchedPath: resolveProtectedCandidate(filePath, pathOptions.cwd),
|
|
2106
|
+
matchedRule: 'h-class-file-path',
|
|
2017
2107
|
};
|
|
2018
2108
|
}
|
|
2019
2109
|
}
|
|
@@ -2028,7 +2118,7 @@ export function checkLClassWrite(toolName, input, context) {
|
|
|
2028
2118
|
const pathOptions = { cwd: context?.projectPath, root: context?.root, selfAid: context?.selfAid };
|
|
2029
2119
|
const lClassRead = protectedReadToolMatchesLClass(toolName, input, pathOptions);
|
|
2030
2120
|
if (lClassRead && context?.permissionMode === 'readonly') {
|
|
2031
|
-
return { behavior: 'deny', message: '🔒 只读模式:visitor 最低权限不允许读取 L-class 路径', matchedPath: lClassRead };
|
|
2121
|
+
return { behavior: 'deny', message: '🔒 只读模式:visitor 最低权限不允许读取 L-class 路径', matchedPath: lClassRead, matchedRule: 'l-class-read' };
|
|
2032
2122
|
}
|
|
2033
2123
|
return { behavior: 'allow' };
|
|
2034
2124
|
}
|
|
@@ -2073,6 +2163,9 @@ export function checkLClassWrite(toolName, input, context) {
|
|
|
2073
2163
|
? '🔒 只读模式:visitor 最低权限不允许读取 L-class 路径'
|
|
2074
2164
|
: `🔒 L-class 路径允许读取,但当前 Bash 命令无法证明为只读${protectedOperands.analysis.kind === 'unproven' ? `(原因码:${protectedOperands.analysis.reason})` : ''},已拒绝执行。请改用受控的 EvolCore 读取命令或白名单只读命令`,
|
|
2075
2165
|
matchedPath: protectedOperands.lClassPath,
|
|
2166
|
+
matchedRule: protectedOperands.analysis.kind === 'unproven'
|
|
2167
|
+
? `l-class-shell-unproven:${protectedOperands.analysis.reason}`
|
|
2168
|
+
: 'l-class-shell-operand',
|
|
2076
2169
|
};
|
|
2077
2170
|
}
|
|
2078
2171
|
collectFilesystemWriteGrantPaths(input.additionalPermissions, writeGrantPaths, projectRootWriteSubpaths);
|
|
@@ -2092,6 +2185,7 @@ export function checkLClassWrite(toolName, input, context) {
|
|
|
2092
2185
|
behavior: 'deny',
|
|
2093
2186
|
message: '🔒 请求的文件系统写权限包含 L-class 只读路径,已拒绝授权',
|
|
2094
2187
|
matchedPath: resolveProtectedCandidate(grantPath, pathOptions.cwd),
|
|
2188
|
+
matchedRule: 'l-class-grant',
|
|
2095
2189
|
};
|
|
2096
2190
|
}
|
|
2097
2191
|
}
|
|
@@ -2102,7 +2196,7 @@ export function checkLClassWrite(toolName, input, context) {
|
|
|
2102
2196
|
}
|
|
2103
2197
|
const candidate = path.isAbsolute(subpath) ? subpath : path.resolve(permissionWorkspace, subpath);
|
|
2104
2198
|
if (lClassGrantIncludesProtectedPath(candidate, { root: context?.root, selfAid: context?.selfAid })) {
|
|
2105
|
-
return { behavior: 'deny', message: '🔒 请求的 project_roots 写权限包含 L-class 只读路径,已拒绝授权' };
|
|
2199
|
+
return { behavior: 'deny', message: '🔒 请求的 project_roots 写权限包含 L-class 只读路径,已拒绝授权', matchedRule: 'l-class-project-root-grant' };
|
|
2106
2200
|
}
|
|
2107
2201
|
}
|
|
2108
2202
|
for (const filePath of paths) {
|
|
@@ -2112,8 +2206,9 @@ export function checkLClassWrite(toolName, input, context) {
|
|
|
2112
2206
|
`session=${context?.sessionId} channel=${context?.channel} peer=${context?.peerId} role=${context?.role}`);
|
|
2113
2207
|
return {
|
|
2114
2208
|
behavior: 'deny',
|
|
2115
|
-
message: `🔒 L-class 路径允许读取但禁止 Agent 直接修改、删除或移动\n\n文件:${filePath}\n\n💡 请使用对应的 EvolCore 受控命令修改`,
|
|
2209
|
+
message: `🔒 L-class 路径允许读取但禁止 Agent 直接修改、删除或移动\n\n文件:${resolveProtectedCandidate(filePath, pathOptions.cwd)}\n\n💡 请使用对应的 EvolCore 受控命令修改`,
|
|
2116
2210
|
matchedPath: resolveProtectedCandidate(filePath, pathOptions.cwd),
|
|
2211
|
+
matchedRule: 'l-class-file-path',
|
|
2117
2212
|
};
|
|
2118
2213
|
}
|
|
2119
2214
|
return { behavior: 'allow' };
|
|
@@ -2283,6 +2378,8 @@ function prepareBoundedOutputInput(input, command, kind, context) {
|
|
|
2283
2378
|
cwd: executionCwd,
|
|
2284
2379
|
argv: executionArgv,
|
|
2285
2380
|
mergeStderr: command.mergeStderr,
|
|
2381
|
+
...(command.discardStdout ? { discardStdout: true } : {}),
|
|
2382
|
+
...(command.discardStderr ? { discardStderr: true } : {}),
|
|
2286
2383
|
...(command.filterChain?.length ? { filterChain: command.filterChain } : {}),
|
|
2287
2384
|
...(command.suffixArgv?.length ? { suffixArgv: command.suffixArgv } : {}),
|
|
2288
2385
|
...(executionOutputPath ? { outputPath: executionOutputPath } : {}),
|
|
@@ -2505,102 +2602,6 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2505
2602
|
const argv = parsedCodex?.ok
|
|
2506
2603
|
? parsedCodex.argv
|
|
2507
2604
|
: classifiedEcArgv ? normalizeEvolcoreCommandArgv(classifiedEcArgv) : null;
|
|
2508
|
-
const managedAidArgs = argv?.[0] === 'ec' && argv[1] === 'aid'
|
|
2509
|
-
? argv.slice(2)
|
|
2510
|
-
: undefined;
|
|
2511
|
-
const managedAidHelpEnd = managedAidArgs?.indexOf('--') ?? -1;
|
|
2512
|
-
const managedAidHelpArgs = managedAidArgs?.slice(0, managedAidHelpEnd < 0 ? undefined : managedAidHelpEnd) ?? [];
|
|
2513
|
-
const isManagedAidHelp = managedAidArgs !== undefined && (managedAidArgs.length === 0
|
|
2514
|
-
|| managedAidHelpArgs.some(arg => arg === '--help' || arg === '-h')
|
|
2515
|
-
|| managedAidHelpArgs[0] === 'help'
|
|
2516
|
-
|| (managedAidHelpArgs[0] === 'agentmd'
|
|
2517
|
-
&& (managedAidArgs.length === 1 || managedAidHelpArgs[1] === 'help')));
|
|
2518
|
-
const managedAidArgv = argv?.at(-2) === '--format' && argv.at(-1) === 'json'
|
|
2519
|
-
? argv.slice(0, -2)
|
|
2520
|
-
: argv;
|
|
2521
|
-
const ownAid = !!managedAidArgv
|
|
2522
|
-
&& !!context.selfAid
|
|
2523
|
-
&& managedAidArgv.at(-1)?.replace(/^@/, '') === context.selfAid.replace(/^@/, '');
|
|
2524
|
-
const isManagedAidPublicRead = !!context.selfAid
|
|
2525
|
-
&& !!managedAidArgv
|
|
2526
|
-
&& managedAidArgv[0] === 'ec'
|
|
2527
|
-
&& managedAidArgv[1] === 'aid'
|
|
2528
|
-
&& ((managedAidArgv.length === 4 && managedAidArgv[2] === 'lookup')
|
|
2529
|
-
|| (managedAidArgv.length === 5
|
|
2530
|
-
&& managedAidArgv[2] === 'agentmd'
|
|
2531
|
-
&& managedAidArgv[3] === 'get'));
|
|
2532
|
-
const isSelfManagedAidShow = !!managedAidArgv
|
|
2533
|
-
&& managedAidArgv.length === 4
|
|
2534
|
-
&& managedAidArgv[0] === 'ec'
|
|
2535
|
-
&& managedAidArgv[1] === 'aid'
|
|
2536
|
-
&& managedAidArgv[2] === 'show'
|
|
2537
|
-
&& ownAid;
|
|
2538
|
-
const isSelfAgentMdPublish = !!managedAidArgv
|
|
2539
|
-
&& managedAidArgv.length === 5
|
|
2540
|
-
&& managedAidArgv[0] === 'ec'
|
|
2541
|
-
&& managedAidArgv[1] === 'aid'
|
|
2542
|
-
&& managedAidArgv[2] === 'agentmd'
|
|
2543
|
-
&& managedAidArgv[3] === 'put'
|
|
2544
|
-
&& ownAid;
|
|
2545
|
-
const isSelfAgentMdSet = !!managedAidArgv
|
|
2546
|
-
&& managedAidArgv.length === 7
|
|
2547
|
-
&& managedAidArgv[0] === 'ec'
|
|
2548
|
-
&& managedAidArgv[1] === 'aid'
|
|
2549
|
-
&& managedAidArgv[2] === 'agentmd'
|
|
2550
|
-
&& managedAidArgv[3] === 'set'
|
|
2551
|
-
&& !!context.selfAid
|
|
2552
|
-
&& managedAidArgv[4]?.replace(/^@/, '') === context.selfAid.replace(/^@/, '')
|
|
2553
|
-
&& ['name', 'type', 'description', 'version', 'tags', 'exttype'].includes(managedAidArgv[5] ?? '')
|
|
2554
|
-
&& managedAidArgv[6] !== undefined;
|
|
2555
|
-
const avatarFileIndex = managedAidArgv?.indexOf('--file') ?? -1;
|
|
2556
|
-
const avatarUrlIndex = managedAidArgv?.indexOf('--url') ?? -1;
|
|
2557
|
-
const avatarSourceIndex = avatarFileIndex >= 0 ? avatarFileIndex : avatarUrlIndex;
|
|
2558
|
-
const isSelfAvatarUpload = !!managedAidArgv
|
|
2559
|
-
&& (avatarSourceIndex === 4)
|
|
2560
|
-
&& managedAidArgv.length === 6
|
|
2561
|
-
&& managedAidArgv[0] === 'ec'
|
|
2562
|
-
&& managedAidArgv[1] === 'aid'
|
|
2563
|
-
&& managedAidArgv[2] === 'avatar'
|
|
2564
|
-
&& !!context.selfAid
|
|
2565
|
-
&& managedAidArgv[3]?.replace(/^@/, '') === context.selfAid.replace(/^@/, '')
|
|
2566
|
-
&& !!managedAidArgv[5]
|
|
2567
|
-
&& !managedAidArgv[5].startsWith('-');
|
|
2568
|
-
const canPublishSelfAgentMd = isSelfAgentMdPublish
|
|
2569
|
-
&& ['request', 'bypass'].includes(context.permissionMode ?? '');
|
|
2570
|
-
const canSetSelfAgentMd = isSelfAgentMdSet
|
|
2571
|
-
&& ['request', 'bypass'].includes(context.permissionMode ?? '');
|
|
2572
|
-
const canUploadSelfAvatar = isSelfAvatarUpload
|
|
2573
|
-
&& ['request', 'bypass'].includes(context.permissionMode ?? '');
|
|
2574
|
-
let isManagedOwnership = false;
|
|
2575
|
-
if (managedAidArgs?.[0] === 'bind' || managedAidArgs?.[0] === 'transfer') {
|
|
2576
|
-
try {
|
|
2577
|
-
const ownership = parseOwnershipCommand(managedAidArgs);
|
|
2578
|
-
isManagedOwnership = ownership.action === 'status'
|
|
2579
|
-
|| ['request', 'bypass'].includes(context.permissionMode ?? '');
|
|
2580
|
-
}
|
|
2581
|
-
catch { }
|
|
2582
|
-
}
|
|
2583
|
-
const isAllowedManagedAidCommand = isManagedAidPublicRead
|
|
2584
|
-
|| isManagedOwnership
|
|
2585
|
-
|| isSelfManagedAidShow
|
|
2586
|
-
|| canPublishSelfAgentMd
|
|
2587
|
-
|| canSetSelfAgentMd
|
|
2588
|
-
|| canUploadSelfAvatar;
|
|
2589
|
-
if (context.sessionId && managedAidArgs !== undefined
|
|
2590
|
-
&& !isManagedAidHelp && !isAllowedManagedAidCommand) {
|
|
2591
|
-
return {
|
|
2592
|
-
behavior: 'deny',
|
|
2593
|
-
input,
|
|
2594
|
-
message: isSelfAgentMdPublish && (context.permissionMode === 'readonly' || context.permissionMode === 'auto')
|
|
2595
|
-
? `🔒 ${context.permissionMode} 模式禁止发布 agent.md;请切换到 request 或 bypass 后再执行 \`ec aid agentmd put <当前 self AID>\`。`
|
|
2596
|
-
: isSelfAgentMdSet && (context.permissionMode === 'readonly' || context.permissionMode === 'auto')
|
|
2597
|
-
? `🔒 ${context.permissionMode} 模式禁止修改 agent.md;请切换到 request 或 bypass 后再执行 \`ec aid agentmd set <当前 self AID> <field> <value>\`。`
|
|
2598
|
-
: isSelfAvatarUpload && (context.permissionMode === 'readonly' || context.permissionMode === 'auto')
|
|
2599
|
-
? `🔒 ${context.permissionMode} 模式禁止上传头像;请切换到 request 或 bypass 后再执行 \`ec aid avatar <当前 self AID> (--file <path> 或 --url <https-url>)\`。`
|
|
2600
|
-
: '🔒 EvolCore 托管会话允许 `ec aid show <当前 self AID>`、`ec aid lookup <任意合法 AID>` 或 `ec aid agentmd get <任意合法 AID>`;`ec aid agentmd put/set` 及 `ec aid avatar` 还要求针对当前 self AID 且处于 request 或 bypass。可选后缀仅限 `--format json`。禁止列举本地身份、切换身份或对其它 AID 执行 show/put/set/avatar。',
|
|
2601
|
-
policyCode: 'managed_ec_aid_scope_forbidden',
|
|
2602
|
-
};
|
|
2603
|
-
}
|
|
2604
2605
|
if (ecCommand.kind === 'literal') {
|
|
2605
2606
|
return { behavior: 'allow', input, reason: 'ec-command' };
|
|
2606
2607
|
}
|
|
@@ -2707,7 +2708,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2707
2708
|
allowProtectedMetadata: context.allowProtectedMetadata,
|
|
2708
2709
|
});
|
|
2709
2710
|
if (hClass.behavior === 'deny') {
|
|
2710
|
-
return { behavior: 'deny', input: checkedInput, message: hClass.message
|
|
2711
|
+
return { behavior: 'deny', input: checkedInput, message: `${hClass.message}${hClass.matchedRule ? ` (matchedRule=${hClass.matchedRule})` : ''}`, policyCode: 'h_class_protection', matchedPath: hClass.matchedPath, matchedRule: hClass.matchedRule };
|
|
2711
2712
|
}
|
|
2712
2713
|
const lClass = checkLClassWrite(policyToolName, protectedPolicyInput, {
|
|
2713
2714
|
sessionId: context.sessionId,
|
|
@@ -2723,7 +2724,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2723
2724
|
allowReadonlySourceDiagnostics: context.allowReadonlySourceDiagnostics,
|
|
2724
2725
|
});
|
|
2725
2726
|
if (lClass.behavior === 'deny') {
|
|
2726
|
-
return { behavior: 'deny', input: checkedInput, message: lClass.message
|
|
2727
|
+
return { behavior: 'deny', input: checkedInput, message: `${lClass.message}${lClass.matchedRule ? ` (matchedRule=${lClass.matchedRule})` : ''}`, policyCode: 'l_class_protection', matchedPath: lClass.matchedPath, matchedRule: lClass.matchedRule };
|
|
2727
2728
|
}
|
|
2728
2729
|
const dangerous = checkDangerousCommand(toolName, checkedInput);
|
|
2729
2730
|
if (dangerous.isDangerous
|