evolcore 0.0.43-test.3 → 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 +82 -0
- package/bin/ecmsg.js +492 -0
- package/bin/install-codex-managed-hooks.mjs +130 -8
- package/dist/ability/application-service.js +37 -0
- package/dist/ability/resources.js +28 -0
- package/dist/ability/runtime.js +6 -1
- package/dist/agents/claude-runner.js +7 -5
- package/dist/agents/codex/app-server-client.js +0 -12
- package/dist/agents/codex-runner.js +12 -54
- package/dist/agents/ecagent-runner.js +130 -35
- package/dist/aun/aid/agentmd.js +56 -12
- 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/aun/menu/client.js +8 -7
- package/dist/aun/menu/index.js +1 -1
- package/dist/aun/menu/transport.js +8 -5
- package/dist/aun/service-proxy.js +3 -0
- package/dist/channels/aun.js +56 -22
- package/dist/channels/daemon.js +12 -4
- package/dist/cli/agent-command.js +5 -0
- package/dist/cli/agent-create.js +32 -8
- package/dist/cli/agent.js +9 -3
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +12 -5
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -21
- package/dist/cli/directory.js +7 -8
- package/dist/cli/ecmsg-gateway.js +204 -0
- package/dist/cli/getmeta-command.js +2 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +58 -18
- 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/cli/trigger-command.js +20 -14
- package/dist/config/boot-log.js +23 -2
- package/dist/config/config-field-policy.js +2 -0
- package/dist/config/config-manager.js +13 -17
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- 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/role-schema.js +3 -3
- package/dist/config/schema-migration.js +188 -3
- package/dist/core/agent-application-service.js +11 -0
- package/dist/core/agent-ipc-registration.js +2 -0
- package/dist/core/agent-runtime.js +45 -11
- package/dist/core/auth/auth-gateway.js +8 -6
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +5 -2
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +11 -3
- package/dist/core/bootstrap-service.js +8 -0
- package/dist/core/channel-loader.js +61 -23
- package/dist/core/command/agent-control.js +4 -1
- package/dist/core/command/chatmode-config.js +46 -0
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -20
- package/dist/core/command/daemon-diagnostics.js +2 -1
- package/dist/core/command/menu-catalog.js +1 -1
- package/dist/core/command/menu-handler.js +16 -16
- 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 +56 -42
- package/dist/core/daemon-lifecycle.js +35 -17
- package/dist/core/event-catalog.js +19 -0
- package/dist/core/evolagent-registry.js +3 -0
- package/dist/core/handoff/runtime.js +9 -3
- package/dist/core/initialization/service.js +4 -3
- package/dist/core/ipc-registration.js +6 -0
- package/dist/core/message/aun-ipc-sender.js +81 -3
- package/dist/core/message/im-renderer.js +24 -19
- package/dist/core/message/message-admission.js +13 -2
- package/dist/core/message/response-engine.js +40 -41
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +310 -0
- package/dist/core/model/model-capabilities.js +37 -0
- package/dist/core/model/model-catalog.js +6 -2
- package/dist/core/ownership/owner-resolver.js +117 -14
- package/dist/core/permission/ec-command-parser.js +195 -27
- 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/plugin-lifecycle.js +6 -2
- package/dist/core/relation/pa-team.js +7 -2
- 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 +690 -99
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +7 -9
- 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 +38 -5
- package/dist/ecweb/runtime/supervisor.js +157 -49
- package/dist/index.js +202 -38
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +2 -0
- package/dist/proxy/service-supervisor.js +379 -143
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +1 -0
- package/dist/trigger/audit.js +3 -2
- package/dist/trigger/authorization.js +2 -3
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +4 -3
- package/dist/trigger/ipc-service.js +24 -19
- package/dist/trigger/manager.js +3 -5
- package/dist/trigger/parser.js +4 -21
- package/dist/trigger/patch.js +3 -15
- package/dist/trigger/scheduler.js +48 -13
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -13
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +36 -8
- package/dist/utils/error-utils.js +8 -0
- package/dist/utils/macos-autostart.js +31 -0
- package/dist/utils/model-prices.jsonl +15 -8
- package/dist/utils/process-introspect.js +21 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +7 -1
- package/dist/utils/windows-autostart.js +42 -7
- package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
- package/ecagent/dist/harness/compaction/compaction.js +4 -4
- 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 +3 -2
- 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/file-navigation.md +63 -49
- package/kits/docs/evolcore/group.md +6 -6
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +33 -3
- package/kits/docs/evolcore/model.md +5 -3
- package/kits/docs/evolcore/msg.md +28 -27
- package/kits/docs/evolcore/provider.md +39 -5
- package/kits/docs/evolcore/response.md +3 -1
- package/kits/docs/evolcore/thread-chain.md +12 -14
- package/kits/docs/evolcore/tool-authorization.md +21 -1
- package/kits/docs/evolcore/trigger.md +12 -9
- 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 -49
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/rules/01-overview.md +43 -45
- package/kits/rules/02-navigation.md +44 -53
- package/kits/rules/03-identity.md +21 -25
- package/kits/rules/04-relation.md +23 -33
- package/kits/rules/05-venue.md +24 -25
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +20 -27
- package/kits/schemas/agent-config.schema.19.json +10 -6
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/relation-config.schema.12.json +2 -2
- package/kits/schemas/role-config.schema.2.json +5 -5
- 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 -0
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- 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/identity.md +0 -1
- 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 +17 -13
- package/kits/schemas/agent-config.schema.20.json +0 -925
- package/kits/schemas/relation-config.schema.13.json +0 -289
- package/kits/schemas/role-config.schema.3.json +0 -1038
|
@@ -67,9 +67,10 @@ export class OwnerResolver {
|
|
|
67
67
|
else
|
|
68
68
|
this.configuredOwners.delete(subjectAid);
|
|
69
69
|
const subject = this.subjects.get(subjectAid);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
// Retiring compatibility targets must not invalidate the freshly verified protocol Owner.
|
|
71
|
+
const removesConfirmedTargets = normalized.length === 0 && subject?.view.consensusStatus === 'consensus'
|
|
72
|
+
&& this.isCacheFresh(subject, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS);
|
|
73
|
+
if (subject && !removesConfirmedTargets) {
|
|
73
74
|
this.invalidate(subject, 'Configured Owners changed; fresh consensus is required', true);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
@@ -425,7 +426,7 @@ export class OwnerResolver {
|
|
|
425
426
|
return this.snapshot(subjectAid);
|
|
426
427
|
}
|
|
427
428
|
const ownerAid = consensus.status === 'consensus' && consensus.sub_aid === subjectAid
|
|
428
|
-
&& typeof consensus.owner_aid === 'string' && isValidAid(consensus.owner_aid)
|
|
429
|
+
&& typeof consensus.owner_aid === 'string' && isValidAid(consensus.owner_aid) && consensus.owner_aid !== subjectAid
|
|
429
430
|
? consensus.owner_aid : undefined;
|
|
430
431
|
if (consensus.sub_aid !== subjectAid || (consensus.status === 'consensus' && !ownerAid)) {
|
|
431
432
|
throw new Error('Ownership consensus contains a mismatched subject or invalid owner');
|
|
@@ -606,6 +607,29 @@ export class OwnerResolver {
|
|
|
606
607
|
this.assertAid(ownerAid);
|
|
607
608
|
return fs.existsSync(agentOwnerBindingRejectionPath(subjectAid, ownerAid));
|
|
608
609
|
}
|
|
610
|
+
/** Explicit local reset; never submits a bind or resets the channel's per-process attempts. */
|
|
611
|
+
resetRejectedOwnerBinding(subjectAid, ownerAid) {
|
|
612
|
+
this.assertAid(subjectAid);
|
|
613
|
+
this.assertAid(ownerAid);
|
|
614
|
+
let cleared = false;
|
|
615
|
+
try {
|
|
616
|
+
fs.unlinkSync(agentOwnerBindingRejectionPath(subjectAid, ownerAid));
|
|
617
|
+
cleared = true;
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
if (error.code !== 'ENOENT')
|
|
621
|
+
throw error;
|
|
622
|
+
}
|
|
623
|
+
const subject = this.subject(subjectAid);
|
|
624
|
+
if (subject.view.task?.operation === 'bind' && subject.view.task.owner_aid === ownerAid
|
|
625
|
+
&& subject.view.task.status === 'rejected') {
|
|
626
|
+
subject.view.task = undefined;
|
|
627
|
+
subject.view.requestStatus = undefined;
|
|
628
|
+
subject.view.requestedOwnerAid = undefined;
|
|
629
|
+
}
|
|
630
|
+
logOwnershipEvent('rejection.reset', { subjectAid, ownerAid });
|
|
631
|
+
return { ...this.snapshot(subjectAid), rejectionReset: { ownerAid, cleared } };
|
|
632
|
+
}
|
|
609
633
|
rememberRejectedOwnerBinding(task) {
|
|
610
634
|
const file = agentOwnerBindingRejectionPath(task.sub_aid, task.owner_aid);
|
|
611
635
|
try {
|
|
@@ -768,7 +792,14 @@ export class OwnerResolver {
|
|
|
768
792
|
return await this.withSubjectClient(subjectAid, async (client, attached) => {
|
|
769
793
|
// SDK 0.5.24 can recover an authenticated request from message history;
|
|
770
794
|
// this in-memory projection is only used to detect mismatched results.
|
|
771
|
-
const request = subject.requests.get(operationId) ?? subject.decisionTasks.get(operationId)
|
|
795
|
+
const request = subject.requests.get(operationId) ?? subject.decisionTasks.get(operationId)
|
|
796
|
+
?? (decision === 'accept' ? await this.readDecisionPreflight(subjectAid, client, operationId) : undefined);
|
|
797
|
+
if (decision === 'accept' && request) {
|
|
798
|
+
await this.assertAgentOwner(request.sub_aid, request.new_owner_aid ?? request.owner_aid);
|
|
799
|
+
}
|
|
800
|
+
if (subject.generation !== generation || (attached && subject.client !== client)) {
|
|
801
|
+
throw new OwnershipError('CLIENT_REPLACED', 'Subject SDK client changed during approval preparation');
|
|
802
|
+
}
|
|
772
803
|
const result = decision === 'accept'
|
|
773
804
|
? await client.acceptOwnershipRequest(operationId)
|
|
774
805
|
: await client.rejectOwnershipRequest(operationId, reason);
|
|
@@ -917,6 +948,8 @@ export class OwnerResolver {
|
|
|
917
948
|
let replaced = false;
|
|
918
949
|
subject.view = { ...subject.view, requestedOwnerAid: ownerAid, requestStatus: 'requesting', task: undefined };
|
|
919
950
|
try {
|
|
951
|
+
await this.assertAgentOwner(subjectAid, ownerAid);
|
|
952
|
+
assertCurrent();
|
|
920
953
|
const local = await this.tryLocalBind(subjectAid, ownerAid, assertCurrent);
|
|
921
954
|
if (local) {
|
|
922
955
|
if (subject.client && subject.generation !== generation) {
|
|
@@ -1004,6 +1037,8 @@ export class OwnerResolver {
|
|
|
1004
1037
|
targetConsensus = current;
|
|
1005
1038
|
subject.view.targetConsensus = current;
|
|
1006
1039
|
assertCurrent();
|
|
1040
|
+
await this.assertAgentOwner(subAid, newOwnerAid);
|
|
1041
|
+
assertCurrent();
|
|
1007
1042
|
const local = await this.tryLocalTransfer(ownerAid, subAid, newOwnerAid, current, assertCurrent);
|
|
1008
1043
|
if (local) {
|
|
1009
1044
|
subject.view.task = local.task;
|
|
@@ -1153,6 +1188,73 @@ export class OwnerResolver {
|
|
|
1153
1188
|
throw new OwnershipError('INVALID_OWNER', 'The new Owner must differ from the current Owner');
|
|
1154
1189
|
}
|
|
1155
1190
|
}
|
|
1191
|
+
async assertAgentOwner(subjectAid, ownerAid) {
|
|
1192
|
+
if (subjectAid === this.daemonAid)
|
|
1193
|
+
return;
|
|
1194
|
+
const { loadAgent } = await import('../../config-store.js');
|
|
1195
|
+
const client = this.subjects.get(subjectAid)?.client;
|
|
1196
|
+
if (!loadAgent(subjectAid) && client?.getType && client.getType() !== 'agent')
|
|
1197
|
+
return;
|
|
1198
|
+
const { assertHumanAgentOwner } = await import('../../aun/aid/agentmd.js');
|
|
1199
|
+
await assertHumanAgentOwner(ownerAid);
|
|
1200
|
+
}
|
|
1201
|
+
/** Only identifies the human-type preflight target. The SDK still authenticates the original request. */
|
|
1202
|
+
async readDecisionPreflight(subjectAid, client, operationId) {
|
|
1203
|
+
const query = { filter: 'all', limit: 200 };
|
|
1204
|
+
const tokens = new Set();
|
|
1205
|
+
for (;;) {
|
|
1206
|
+
const catalog = await client.call('message.peers', query);
|
|
1207
|
+
for (const peer of Array.isArray(catalog.peers) ? catalog.peers : []) {
|
|
1208
|
+
const sender = String(peer.sender_aid ?? '');
|
|
1209
|
+
const head = Number(peer.head_seq);
|
|
1210
|
+
const snapshot = Number.isSafeInteger(head) && head > 0 && head < Number.MAX_SAFE_INTEGER
|
|
1211
|
+
? { snapshot_head_seq: head } : {};
|
|
1212
|
+
let before = snapshot.snapshot_head_seq === undefined ? Number.MAX_SAFE_INTEGER : head + 1;
|
|
1213
|
+
for (;;) {
|
|
1214
|
+
const history = await client.call('message.history', {
|
|
1215
|
+
sender_aid: sender, before_seq: before, ...snapshot, limit: 200,
|
|
1216
|
+
});
|
|
1217
|
+
for (const row of Array.isArray(history.messages) ? history.messages : []) {
|
|
1218
|
+
let value = row.payload ?? row;
|
|
1219
|
+
try {
|
|
1220
|
+
if (value?.type === 'text' && typeof value.text === 'string')
|
|
1221
|
+
value = JSON.parse(value.text);
|
|
1222
|
+
if (typeof value === 'string')
|
|
1223
|
+
value = JSON.parse(value);
|
|
1224
|
+
}
|
|
1225
|
+
catch {
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1228
|
+
if (value?.type !== 'aun.ownership.sdk.v1' || value.operation_id !== operationId
|
|
1229
|
+
|| !['bind.request', 'transfer.request'].includes(value.action))
|
|
1230
|
+
continue;
|
|
1231
|
+
const task = this.bindingTask({ ...value, status: 'pending', step: 'approval' });
|
|
1232
|
+
if (!task || String(row.from_aid ?? row.from ?? row.sender_aid ?? '') !== sender
|
|
1233
|
+
|| ![task.sub_aid, task.owner_aid, task.new_owner_aid].includes(subjectAid)) {
|
|
1234
|
+
throw new OwnershipError('TASK_MISMATCH', 'Ownership history preflight does not match the local subject');
|
|
1235
|
+
}
|
|
1236
|
+
return task;
|
|
1237
|
+
}
|
|
1238
|
+
if (history.has_older !== true)
|
|
1239
|
+
break;
|
|
1240
|
+
const next = Number(history.next_before_seq);
|
|
1241
|
+
if (!Number.isSafeInteger(next) || next <= 0 || next >= before) {
|
|
1242
|
+
throw new OwnershipError('REQUEST_NOT_FOUND', 'Ownership history pagination did not advance');
|
|
1243
|
+
}
|
|
1244
|
+
before = next;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
if (catalog.has_more !== true)
|
|
1248
|
+
break;
|
|
1249
|
+
const token = catalog.next_page_token;
|
|
1250
|
+
if (typeof token !== 'string' || !token || tokens.has(token)) {
|
|
1251
|
+
throw new OwnershipError('REQUEST_NOT_FOUND', 'Ownership peer pagination did not advance');
|
|
1252
|
+
}
|
|
1253
|
+
tokens.add(token);
|
|
1254
|
+
query.page_token = token;
|
|
1255
|
+
}
|
|
1256
|
+
throw new OwnershipError('REQUEST_NOT_FOUND', 'Cannot identify the Owner of the original ownership request');
|
|
1257
|
+
}
|
|
1156
1258
|
async tryLocalTransfer(ownerAid, subAid, newOwnerAid, current, assertCurrent) {
|
|
1157
1259
|
let store;
|
|
1158
1260
|
let ownerClient;
|
|
@@ -1173,7 +1275,8 @@ export class OwnerResolver {
|
|
|
1173
1275
|
ownerClient = await sdkStore.loadClient(store, ownerAid);
|
|
1174
1276
|
subClient = await sdkStore.loadClient(store, subAid);
|
|
1175
1277
|
newOwnerClient = await sdkStore.loadClient(store, newOwnerAid);
|
|
1176
|
-
if (
|
|
1278
|
+
if (!['agent', 'human'].includes(ownerClient.getType()) || subClient.getType() !== 'agent'
|
|
1279
|
+
|| !['agent', 'human'].includes(newOwnerClient.getType())
|
|
1177
1280
|
|| typeof ownerClient.transferLocalSubaid !== 'function')
|
|
1178
1281
|
return undefined;
|
|
1179
1282
|
assertCurrent();
|
|
@@ -1246,7 +1349,7 @@ export class OwnerResolver {
|
|
|
1246
1349
|
ownerClient = await sdkStore.loadClient(store, ownerAid);
|
|
1247
1350
|
subClient = await sdkStore.loadClient(store, subjectAid);
|
|
1248
1351
|
if (typeof ownerClient.bindSubaid !== 'function'
|
|
1249
|
-
|| ownerClient.getType()
|
|
1352
|
+
|| !['agent', 'human'].includes(ownerClient.getType()) || subClient.getType() !== 'agent')
|
|
1250
1353
|
return undefined;
|
|
1251
1354
|
assertCurrent();
|
|
1252
1355
|
invoked = true;
|
|
@@ -1298,7 +1401,7 @@ export class OwnerResolver {
|
|
|
1298
1401
|
throw new OwnershipError('TASK_MISMATCH', 'Ownership consensus subject does not match');
|
|
1299
1402
|
}
|
|
1300
1403
|
const ownerAid = consensus.status === 'consensus' && typeof consensus.owner_aid === 'string'
|
|
1301
|
-
&& isValidAid(consensus.owner_aid) ? consensus.owner_aid : undefined;
|
|
1404
|
+
&& isValidAid(consensus.owner_aid) && consensus.owner_aid !== subjectAid ? consensus.owner_aid : undefined;
|
|
1302
1405
|
if (consensus.status === 'consensus' && !ownerAid) {
|
|
1303
1406
|
this.invalidate(subject, 'Ownership consensus owner is invalid');
|
|
1304
1407
|
throw new OwnershipError('TASK_MISMATCH', 'Ownership consensus owner is invalid');
|
|
@@ -1613,19 +1716,19 @@ export async function refreshOwnershipForAuthorization(subjectAid, options = {})
|
|
|
1613
1716
|
}
|
|
1614
1717
|
}
|
|
1615
1718
|
export async function assertOwnershipAuthorization(context) {
|
|
1616
|
-
if (context?.
|
|
1617
|
-
const {
|
|
1719
|
+
if (context?.internalContactAuthorization && context.selfAid && context.actor?.principalId) {
|
|
1720
|
+
const { prepareSameOwnerProof } = await import('../relation/same-owner-proof.js');
|
|
1618
1721
|
const { resolvePeerRoleDetail } = await import('../../config/peer-role-resolver.js');
|
|
1619
1722
|
const { getRoleDefinition } = await import('../../config/roles.js');
|
|
1620
|
-
await
|
|
1723
|
+
await prepareSameOwnerProof(context.selfAid, context.actor.principalId);
|
|
1621
1724
|
const current = resolvePeerRoleDetail({
|
|
1622
1725
|
selfAid: context.selfAid, channelKey: context.actor.operatorChannelKey, channelType: 'aun',
|
|
1623
1726
|
chatType: 'private', actorId: context.actor.principalId, conversationId: context.actor.principalId,
|
|
1624
1727
|
});
|
|
1625
1728
|
if (!current.allowAccess || current.effectiveRole !== context.role
|
|
1626
|
-
|| (context.
|
|
1627
|
-
|| (context.
|
|
1628
|
-
throw new OwnershipError('
|
|
1729
|
+
|| (context.internalContactDefaultRole && current.source !== 'internal-contact-default')
|
|
1730
|
+
|| (context.internalContactPolicy !== undefined && context.internalContactPolicy !== JSON.stringify(getRoleDefinition(context.role ?? '', context.selfAid)))) {
|
|
1731
|
+
throw new OwnershipError('INTERNAL_CONTACT_AUTHORIZATION_CHANGED', 'Internal-contact authorization changed; start a new task with the current role');
|
|
1629
1732
|
}
|
|
1630
1733
|
}
|
|
1631
1734
|
const authorization = context?.executionPermission;
|
|
@@ -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);
|
|
@@ -328,6 +367,16 @@ const CODEX_POWERSHELL_INERT_SWITCHES = new Set([
|
|
|
328
367
|
// intentionally not treated as a trusted Codex carrier.
|
|
329
368
|
const CODEX_CMD_INERT_SWITCHES = new Set(['/d', '/s', '/q', '/a', '/u']);
|
|
330
369
|
const EVOLCORE_EXECUTABLE_ALIASES = new Set(['ec', 'ec.cmd', 'ec.exe', 'ec.ps1']);
|
|
370
|
+
/**
|
|
371
|
+
* 轻量发送入口 `ecmsg` 的前缀映射:`ecmsg <args...>` 等价于 `ec msg <args...>`。
|
|
372
|
+
*
|
|
373
|
+
* 必须在这里归一,不能只做一个独立脚本——委托审批是按规范化 argv 的哈希
|
|
374
|
+
* arm 的(codex-runner 的 armApprovedDelegationCommand)。若 `ecmsg` 不归一到
|
|
375
|
+
* `['ec','msg',...]`,策略层会把它当普通命令(kind: 'none'),既不 arm 审批,
|
|
376
|
+
* daemon 侧也算不出匹配的哈希,最终必然 INVALID_DELEGATION;更糟的是它会绕过
|
|
377
|
+
* ec_shell_composite_command 与会话身份绑定,成为冒充发送的后门。
|
|
378
|
+
*/
|
|
379
|
+
const EVOLCORE_MSG_ENTRY_ALIASES = new Set(['ecmsg', 'ecmsg.cmd', 'ecmsg.exe', 'ecmsg.ps1']);
|
|
331
380
|
const EVOLCORE_NODE_EXECUTABLES = new Set(['node', 'node.exe']);
|
|
332
381
|
const APPLY_PATCH_EXECUTABLE_BASENAMES = new Set([
|
|
333
382
|
'apply_patch',
|
|
@@ -396,10 +445,12 @@ function stripHeredocBodies(command) {
|
|
|
396
445
|
// This is intentionally limited to the command boundary. It is not a search
|
|
397
446
|
// for `ec` anywhere in the input: quoted arguments, regexps and log text must
|
|
398
447
|
// never establish an EC invocation.
|
|
399
|
-
|
|
448
|
+
const POWERSHELL_ASSIGNMENT_PREFIX = /^\$(?:[A-Za-z_][\w:]*|\{[^{}\r\n]+\})\s*=(?!=)/u;
|
|
449
|
+
function hasEcCommandPrefix(command, dialect = 'posix') {
|
|
400
450
|
let quote = null;
|
|
401
451
|
let escaped = false;
|
|
402
452
|
let boundary = true;
|
|
453
|
+
const powerShell = dialect === 'powershell';
|
|
403
454
|
for (let index = 0; index < command.length; index++) {
|
|
404
455
|
const char = command[index];
|
|
405
456
|
if (escaped) {
|
|
@@ -408,37 +459,83 @@ function hasEcCommandPrefix(command) {
|
|
|
408
459
|
continue;
|
|
409
460
|
}
|
|
410
461
|
if (quote === 'single') {
|
|
411
|
-
if (char === "'")
|
|
412
|
-
|
|
462
|
+
if (powerShell ? isPowerShellSingleQuote(char) : char === "'") {
|
|
463
|
+
if (powerShell && isPowerShellSingleQuote(command[index + 1]))
|
|
464
|
+
index++;
|
|
465
|
+
else
|
|
466
|
+
quote = null;
|
|
467
|
+
}
|
|
413
468
|
continue;
|
|
414
469
|
}
|
|
415
470
|
if (quote === 'double') {
|
|
416
|
-
if (char === '\\') {
|
|
471
|
+
if (char === (powerShell ? '`' : '\\')) {
|
|
417
472
|
escaped = true;
|
|
418
473
|
continue;
|
|
419
474
|
}
|
|
420
|
-
if (char === '"')
|
|
475
|
+
if (powerShell ? isPowerShellDoubleQuote(char) : char === '"')
|
|
421
476
|
quote = null;
|
|
422
477
|
continue;
|
|
423
478
|
}
|
|
424
|
-
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 === "'") {
|
|
425
507
|
quote = 'single';
|
|
426
508
|
boundary = false;
|
|
427
509
|
continue;
|
|
428
510
|
}
|
|
429
|
-
if (char === '"') {
|
|
511
|
+
if (powerShell ? isPowerShellDoubleQuote(char) : char === '"') {
|
|
430
512
|
quote = 'double';
|
|
431
513
|
boundary = false;
|
|
432
514
|
continue;
|
|
433
515
|
}
|
|
516
|
+
if (powerShell && /[{}\r\n]/.test(char)) {
|
|
517
|
+
boundary = true;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
434
520
|
if (/[;&|`()<>]/.test(char)) {
|
|
435
521
|
boundary = true;
|
|
436
522
|
continue;
|
|
437
523
|
}
|
|
438
524
|
if (boundary && /\s/.test(char))
|
|
439
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
|
+
}
|
|
440
533
|
if (boundary && /^ec(?:\.cmd|\.exe|\.ps1)?(?=$|\s|[;&|`()<>])/i.test(command.slice(index)))
|
|
441
534
|
return true;
|
|
535
|
+
// `ecmsg` 是 `ec msg` 的同义词,同样算 EC 命令边界——否则
|
|
536
|
+
// `ecmsg ... && rm -rf /` 会落成 kind:'none',绕过复合命令拦截。
|
|
537
|
+
if (boundary && /^ecmsg(?:\.cmd|\.exe|\.ps1)?(?=$|\s|[;&|`()<>])/i.test(command.slice(index)))
|
|
538
|
+
return true;
|
|
442
539
|
boundary = false;
|
|
443
540
|
}
|
|
444
541
|
return false;
|
|
@@ -686,7 +783,7 @@ function isShellParameterExpansionStart(value) {
|
|
|
686
783
|
}
|
|
687
784
|
function hasCarrierEcCommandPrefix(command, dialect) {
|
|
688
785
|
if (dialect !== 'cmd')
|
|
689
|
-
return hasEcCommandPrefix(command);
|
|
786
|
+
return hasEcCommandPrefix(command, dialect);
|
|
690
787
|
const input = trimShellSpacing(command);
|
|
691
788
|
const inner = input.length >= 2 && input.startsWith('"') && input.endsWith('"')
|
|
692
789
|
? input.slice(1, -1)
|
|
@@ -694,6 +791,17 @@ function hasCarrierEcCommandPrefix(command, dialect) {
|
|
|
694
791
|
return /^\s*ec(?:\.cmd|\.exe|\.ps1)?(?:\s|$)/i.test(inner);
|
|
695
792
|
}
|
|
696
793
|
/** Normalize the Windows npm shims to the canonical EvolCore CLI name. */
|
|
794
|
+
/**
|
|
795
|
+
* 取可执行名的 basename(小写)。与 hasEcCommandPrefix 里的算法一致:
|
|
796
|
+
* 兼容 `C:\path\ecmsg.cmd` 与 `./ecmsg` 这类调用形态。
|
|
797
|
+
*/
|
|
798
|
+
function executableBasename(value) {
|
|
799
|
+
if (!value)
|
|
800
|
+
return undefined;
|
|
801
|
+
const normalized = value.replaceAll('\\', '/');
|
|
802
|
+
const base = normalized.slice(normalized.lastIndexOf('/') + 1).toLowerCase();
|
|
803
|
+
return base || undefined;
|
|
804
|
+
}
|
|
697
805
|
export function normalizeEvolcoreCommandArgv(argv) {
|
|
698
806
|
if (argv.length === 0)
|
|
699
807
|
return [];
|
|
@@ -702,6 +810,12 @@ export function normalizeEvolcoreCommandArgv(argv) {
|
|
|
702
810
|
if (typeof executable === 'string' && EVOLCORE_EXECUTABLE_ALIASES.has(executable.toLowerCase())) {
|
|
703
811
|
return ['ec', ...materialized.slice(1)];
|
|
704
812
|
}
|
|
813
|
+
// `ecmsg` 是 `ec msg` 的同义词:归一到 EC 命令族,才能进入同一条
|
|
814
|
+
// 审批、委托与复合命令拦截链路(见 EVOLCORE_MSG_ENTRY_ALIASES 注释)。
|
|
815
|
+
const entryAlias = executableBasename(executable);
|
|
816
|
+
if (entryAlias && EVOLCORE_MSG_ENTRY_ALIASES.has(entryAlias)) {
|
|
817
|
+
return ['ec', 'msg', ...materialized.slice(1)];
|
|
818
|
+
}
|
|
705
819
|
if (typeof executable === 'string' && isNodeExecutable(executable) && materialized.length >= 2
|
|
706
820
|
&& typeof materialized[1] === 'string' && normalizeNodeWrapperPath(materialized[1])) {
|
|
707
821
|
return ['ec', ...materialized.slice(2)];
|
|
@@ -1279,7 +1393,10 @@ function parseLiteralPowerShellCommand(command, options = {}) {
|
|
|
1279
1393
|
? { ...parsed, argv: normalizeEvolcoreCommandArgv(parsed.argv) }
|
|
1280
1394
|
: { ...parsed, inputLength: input.length };
|
|
1281
1395
|
}
|
|
1282
|
-
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
|
+
}
|
|
1283
1400
|
const argv = [];
|
|
1284
1401
|
let token = '';
|
|
1285
1402
|
let tokenStarted = false;
|
|
@@ -1567,17 +1684,18 @@ function resolveCodexPowerShellCarrierString(command) {
|
|
|
1567
1684
|
let nested = match[4].trim();
|
|
1568
1685
|
let failure;
|
|
1569
1686
|
if (nested.startsWith('"') || nested.startsWith("'")) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1687
|
+
// The outer `-Command` argument is a PowerShell string literal. Strip
|
|
1688
|
+
// that one transport-level pair without tokenizing the body as POSIX
|
|
1689
|
+
// shell: doing so removes the `$env:` assignment marker and collapses
|
|
1690
|
+
// doubled single quotes around the credential token before the
|
|
1691
|
+
// PowerShell credential-prefix parser sees them.
|
|
1692
|
+
const quote = nested[0];
|
|
1693
|
+
if (nested.length >= 2 && nested.endsWith(quote)) {
|
|
1694
|
+
nested = nested.slice(1, -1);
|
|
1573
1695
|
}
|
|
1574
1696
|
else {
|
|
1575
|
-
failure =
|
|
1576
|
-
|
|
1577
|
-
: { ...parsed, dialect: 'powershell' };
|
|
1578
|
-
nested = nested.length > 1 && nested.endsWith(nested[0])
|
|
1579
|
-
? nested.slice(1, -1)
|
|
1580
|
-
: nested.slice(1);
|
|
1697
|
+
failure = parseFailure('invalid-quote', nested, 0, 0, 'powershell');
|
|
1698
|
+
nested = nested.slice(1);
|
|
1581
1699
|
}
|
|
1582
1700
|
}
|
|
1583
1701
|
const switches = match[3].trim().split(/[ \t]+/);
|
|
@@ -2965,12 +3083,15 @@ export function parseCdPrefixedEcCommand(input) {
|
|
|
2965
3083
|
*/
|
|
2966
3084
|
function parseEcTail(segment) {
|
|
2967
3085
|
const literal = parseLiteralShellArgv(segment);
|
|
3086
|
+
// 归一化后再判首元素:`ecmsg ...` 等价于 `ec msg ...`,必须与 ec 同权进审批链。
|
|
3087
|
+
// 返回的 argv 也必须是归一化后的形态,否则审批哈希与 daemon 侧解析会错位。
|
|
2968
3088
|
if (literal && literal.length > 0 && normalizeEvolcoreCommandArgv(literal)[0] === 'ec') {
|
|
2969
|
-
return { argv: literal, mergeStderr: false };
|
|
3089
|
+
return { argv: normalizeEvolcoreCommandArgv(literal), mergeStderr: false };
|
|
2970
3090
|
}
|
|
2971
3091
|
const bounded = parseBoundedOutputShellCommand(segment);
|
|
2972
|
-
if (bounded && bounded.argv[0] === 'ec')
|
|
2973
|
-
return bounded;
|
|
3092
|
+
if (bounded && normalizeEvolcoreCommandArgv(bounded.argv)[0] === 'ec') {
|
|
3093
|
+
return { ...bounded, argv: normalizeEvolcoreCommandArgv(bounded.argv) };
|
|
3094
|
+
}
|
|
2974
3095
|
return null;
|
|
2975
3096
|
}
|
|
2976
3097
|
/**
|
|
@@ -3066,7 +3187,7 @@ export function classifyEvolcoreShellCommand(command, options = {}) {
|
|
|
3066
3187
|
// Only a command-boundary prefix is enough to preserve a useful syntax
|
|
3067
3188
|
// error for a malformed direct EC invocation. Never scan for EC tokens in
|
|
3068
3189
|
// arbitrary raw text after parsing fails.
|
|
3069
|
-
return hasEcCommandPrefix(stripped)
|
|
3190
|
+
return hasEcCommandPrefix(stripped, options.dialect)
|
|
3070
3191
|
? { kind: 'composite', issue: literal.issue }
|
|
3071
3192
|
: { kind: 'none' };
|
|
3072
3193
|
}
|
|
@@ -3132,7 +3253,7 @@ export function resolveCanonicalEvolcoreToolInput(input, options = {}) {
|
|
|
3132
3253
|
}
|
|
3133
3254
|
if (classification.kind === 'composite')
|
|
3134
3255
|
return { kind: 'invalid', ...(!parsed.ok ? { failure: parsed } : {}) };
|
|
3135
|
-
if (!parsed.ok && hasEcCommandPrefix(command))
|
|
3256
|
+
if (!parsed.ok && hasEcCommandPrefix(command, dialect))
|
|
3136
3257
|
return { kind: 'invalid', failure: parsed };
|
|
3137
3258
|
return { kind: 'not-ec' };
|
|
3138
3259
|
}
|
|
@@ -3253,17 +3374,45 @@ export function containsLiteralManagedTmpDirOutsideSendContent(argv) {
|
|
|
3253
3374
|
return true;
|
|
3254
3375
|
return literalIndexes.some(index => !textIndexes.has(index));
|
|
3255
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
|
+
}
|
|
3256
3405
|
/** Shell-escaped TMPDIR references are literal text and must not authorize file paths. */
|
|
3257
3406
|
export function containsUnresolvedManagedTmpDirReference(argv) {
|
|
3258
3407
|
return argv.some(value => /(?:\\\$TMPDIR|\\\$\{TMPDIR\})/i.test(value));
|
|
3259
3408
|
}
|
|
3260
|
-
function hasExecutableProactiveSendPayload(argv, scope) {
|
|
3409
|
+
function hasExecutableProactiveSendPayload(argv, scope, bodyStart = 5) {
|
|
3261
3410
|
if (!argv || argv[0] !== 'ec' || argv[1] !== scope || argv[2] !== 'send')
|
|
3262
3411
|
return false;
|
|
3263
3412
|
const positionals = [];
|
|
3264
3413
|
const modes = new Map();
|
|
3265
3414
|
let endOfOptions = false;
|
|
3266
|
-
for (let index =
|
|
3415
|
+
for (let index = bodyStart; index < argv.length; index++) {
|
|
3267
3416
|
const value = argv[index];
|
|
3268
3417
|
if (endOfOptions) {
|
|
3269
3418
|
positionals.push(value);
|
|
@@ -3390,6 +3539,19 @@ export function isEvolcoreSendCommandForSession(toolName, input, channelId) {
|
|
|
3390
3539
|
return true;
|
|
3391
3540
|
return parsed.targetId === channelId;
|
|
3392
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
|
+
}
|
|
3393
3555
|
/** Proactive first-send guard: exact channel kind and current target only. */
|
|
3394
3556
|
export function isExactEvolcoreSendCommandForSession(toolName, input, channelId, chatType, selfAid) {
|
|
3395
3557
|
// Codex app-server exposes shell items as `Shell`; the desktop custom tool
|
|
@@ -3398,14 +3560,20 @@ export function isExactEvolcoreSendCommandForSession(toolName, input, channelId,
|
|
|
3398
3560
|
return false;
|
|
3399
3561
|
const result = parseProactiveToolCommand(toolName, input);
|
|
3400
3562
|
const argv = result?.ok ? result.argv : null;
|
|
3401
|
-
|
|
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);
|
|
3402
3571
|
if (!parsed || parsed.action !== 'send')
|
|
3403
3572
|
return false;
|
|
3404
3573
|
const expectedScope = chatType === 'group' ? 'group' : 'msg';
|
|
3405
3574
|
return parsed.scope === expectedScope
|
|
3406
3575
|
&& parsed.targetId === channelId
|
|
3407
3576
|
&& parsed.sourceId === selfAid
|
|
3408
|
-
&& !!argv
|
|
3409
3577
|
&& hasExecutableProactiveSendPayload(argv, expectedScope);
|
|
3410
3578
|
}
|
|
3411
3579
|
/**
|