evolcore 0.0.43-test.0 → 0.0.43-test.2
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 +31 -2
- package/README.md +22 -0
- package/dist/agents/claude-runner.js +26 -2
- package/dist/agents/codex/app-server-client.js +12 -0
- package/dist/agents/codex-runner.js +49 -8
- package/dist/agents/ecagent-runner.js +26 -9
- package/dist/agents/gemini-runner.js +15 -12
- package/dist/agents/tool-time-context.js +55 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/model-headers.js +17 -0
- package/dist/aun/msg/p2p.js +3 -0
- package/dist/channels/aun.js +484 -43
- package/dist/channels/builtin-plugins.js +16 -11
- package/dist/channels/dingtalk.js +83 -31
- package/dist/channels/feishu.js +29 -13
- package/dist/channels/qqbot.js +32 -11
- package/dist/channels/wechat.js +13 -3
- package/dist/channels/wecom.js +67 -27
- package/dist/cli/agent-command.js +3 -86
- package/dist/cli/agent-create.js +22 -6
- package/dist/cli/agent.js +1 -79
- package/dist/cli/aun-commands.js +1 -0
- package/dist/cli/config.js +1 -1
- package/dist/cli/daemon-commands.js +47 -2
- package/dist/cli/data-command.js +9 -1
- package/dist/cli/debug-mode.js +1 -1
- package/dist/cli/diag.js +1 -1
- package/dist/cli/directory.js +77 -64
- package/dist/cli/getmeta-command.js +1 -1
- package/dist/cli/index.js +79 -22
- package/dist/cli/init.js +1 -23
- package/dist/cli/link-rules.js +1 -1
- package/dist/cli/managed-command-guard.js +0 -1
- package/dist/cli/pa-workspace-command.js +36 -2
- package/dist/cli/peer.js +1 -1
- package/dist/cli/restart-monitor.js +17 -3
- package/dist/cli/role.js +1 -1
- package/dist/cli/session-command.js +1 -1
- package/dist/cli/stats.js +2 -2
- package/dist/cli/thread-command.js +1 -1
- package/dist/cli/watch-msg.js +1 -1
- package/dist/config/access-policy.js +1 -0
- package/dist/config/config-field-policy.js +2 -2
- package/dist/config/config-manager.js +7 -0
- package/dist/config/role-schema.js +4 -3
- package/dist/config/role-service.js +3 -3
- package/dist/config-store.js +75 -4
- package/dist/core/agent-ipc-registration.js +16 -59
- package/dist/core/agent-runtime.js +2 -1
- package/dist/core/auth/authorization-audit.js +52 -14
- package/dist/core/auth/operation-authorizer.js +0 -11
- package/dist/core/auth/operation-catalog.js +0 -18
- package/dist/core/channel-loader.js +152 -16
- package/dist/core/command/agent-control.js +2 -1
- package/dist/core/command/cli-intent-parser.js +0 -8
- package/dist/core/command/command-handler.js +17 -46
- package/dist/core/command/connect-menu.js +7 -3
- package/dist/core/command/menu-catalog.js +3 -2
- package/dist/core/command/menu-handler.js +51 -8
- package/dist/core/command/menu-protocol.js +20 -0
- package/dist/core/command/slash-handler.js +101 -40
- package/dist/core/daemon-file-cache.js +3 -3
- package/dist/core/evolagent-registry.js +5 -4
- package/dist/core/evolagent.js +5 -8
- package/dist/core/handoff/argv-parse.js +115 -0
- package/dist/core/handoff/ipc-registration.js +1 -1
- package/dist/core/ipc-registration.js +19 -2
- package/dist/core/memory/consolidation.js +8 -1
- package/dist/core/memory/relation-sweep.js +20 -8
- package/dist/core/message/aun-ipc-sender.js +28 -1
- package/dist/core/message/contact-admission.js +548 -0
- package/dist/core/message/im-renderer.js +69 -10
- package/dist/core/message/message-admission.js +28 -3
- package/dist/core/message/message-bridge.js +46 -5
- package/dist/core/message/message-utils.js +0 -5
- package/dist/core/message/peer-mode.js +44 -10
- package/dist/core/message/response-engine.js +268 -69
- package/dist/core/message/retry-scheduler.js +4 -0
- package/dist/core/permission/ec-command-parser.js +1 -28
- package/dist/core/permission/readonly-shell-query.js +34 -8
- package/dist/core/permission/tool-policy.js +50 -5
- package/dist/core/role/runtime-policy.js +14 -2
- package/dist/core/session/session-manager.js +9 -1
- package/dist/core/soul.js +66 -0
- package/dist/core/system-session/memory.js +2 -2
- package/dist/directory/contact-admission-paths.js +9 -0
- package/dist/directory/owner-directory-admission.js +128 -29
- package/dist/directory/owner-directory-cache.js +364 -50
- package/dist/directory/owner-directory-identity.js +60 -0
- package/dist/directory/owner-directory-markdown.js +120 -47
- package/dist/directory/owner-directory-policy.js +108 -0
- package/dist/directory/owner-directory-query-operation.js +219 -32
- package/dist/directory/owner-directory-remarks.js +29 -2
- package/dist/directory/owner-directory-search.js +50 -18
- package/dist/directory/owner-directory-store.js +150 -30
- package/dist/eck/kit-renderer.js +12 -5
- package/dist/eck/manifest-engine.js +55 -6
- package/dist/eck/message-renderer.js +5 -2
- package/dist/eck/paactive-context.js +45 -0
- package/dist/ecweb/basic-settings-service.js +2 -2
- package/dist/ecweb/message-context-service.js +24 -16
- package/dist/index.js +9 -5
- package/dist/ipc.js +1 -1
- package/dist/paths.js +26 -0
- package/dist/response-system/config-resolver.js +1 -1
- package/dist/response-system/engines/v1/index.js +4 -1
- package/dist/response-system/engines/v1/paactive-flow.js +18 -0
- package/dist/response-system/modes/single-session/index.js +7 -2
- package/dist/trigger/scheduler.js +3 -5
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/error-utils.js +5 -2
- package/dist/utils/logger.js +13 -4
- package/dist/utils/npm-ops.js +2 -2
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/dist/agent-loop.js +43 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/context-assembly.md +21 -6
- package/kits/docs/eck_templates/INDEX.template.md +1 -2
- package/kits/docs/evolcore/INDEX.md +1 -1
- package/kits/docs/evolcore/agent-create.md +5 -5
- package/kits/docs/evolcore/agent.md +4 -9
- package/kits/docs/evolcore/directory.md +137 -0
- package/kits/docs/evolcore/menu-protocol.md +55 -0
- package/kits/docs/evolcore/response.md +7 -1
- package/kits/docs/evolcore/tool-authorization.md +1 -1
- package/kits/docs/evolcore/trigger.md +4 -0
- package/kits/docs/prompt-loading-architecture.md +6 -2
- package/kits/eck_manifest.auxiliary.json +1 -0
- package/kits/eck_manifest.json +57 -4
- package/kits/eck_manifest.memory.json +67 -3
- package/kits/eck_manifest.paactive.json +528 -0
- package/kits/eck_message_manifest.paactive.json +233 -0
- package/kits/rules/01-overview.md +2 -2
- package/kits/rules/03-identity.md +10 -9
- package/kits/rules/05-venue.md +2 -4
- package/kits/rules/06-channel.md +1 -1
- package/kits/schemas/_meta.json +31 -3
- package/kits/schemas/agent-config.schema.18.json +5 -0
- package/kits/schemas/agent-config.schema.19.json +924 -0
- package/kits/schemas/relation-config.schema.12.json +289 -0
- package/kits/schemas/role-config.schema.2.json +215 -0
- package/kits/skills/ec-skill/scripts/cli.mjs +3 -2
- package/kits/skills/ec-trigger/SKILL.md +4 -4
- package/kits/skills/personal-assistant/SKILL.md +109 -53
- package/kits/skills/personal-assistant/references/02-bootstrap.md +73 -30
- package/kits/skills/personal-assistant/scripts/clean.mjs +35 -18
- package/kits/skills/personal-assistant/scripts/init.mjs +41 -2
- package/kits/skills/personal-assistant/scripts/lib/persona.mjs +185 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +55 -4
- package/kits/skills/personal-assistant/scripts/pa.mjs +173 -0
- package/kits/skills/personal-assistant/scripts/uninstall.mjs +130 -0
- package/kits/skills/personal-assistant/templates/persona-section.md +3 -3
- package/kits/templates/message-fragments/handoff-request-to-target.md +1 -1
- package/kits/templates/message-fragments/paactive/item.md +3 -0
- package/kits/templates/soul/00-GUIDE.md +61 -0
- package/kits/templates/soul/01-identity.md +5 -0
- package/kits/templates/soul/02-persona.md +11 -0
- package/kits/templates/soul/03-duties.md +5 -0
- package/kits/templates/soul/04-working-style.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +7 -7
- package/kits/templates/system-fragments/commands.md +3 -2
- package/kits/templates/system-fragments/directory-contacts.md +9 -0
- package/kits/templates/system-fragments/memory.md +1 -1
- package/kits/templates/system-fragments/paactive/channel.md +25 -0
- package/kits/templates/system-fragments/paactive/reply.md +25 -0
- package/kits/templates/system-fragments/paactive/session.md +32 -0
- package/kits/templates/system-fragments/personal-assistant.md +65 -0
- package/package.json +4 -3
- package/dist/cli/handoff-command.js +0 -353
- package/dist/directory/owner-directory-remark-operation.js +0 -147
- package/kits/docs/evolcore/self-summary.md +0 -29
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export const API_RETRY_DELAYS_MS = [5_000, 10_000, 30_000];
|
|
6
6
|
export const MAX_PROTOCOL_REPLAY_ATTEMPTS = 1;
|
|
7
|
+
export function isRecoverableProtocolFailure(subtype, reason) {
|
|
8
|
+
return subtype === 'protocol_incomplete'
|
|
9
|
+
&& (reason === 'input_not_consumed' || reason === 'empty_success');
|
|
10
|
+
}
|
|
7
11
|
export class RetryScheduler {
|
|
8
12
|
resolveModelId;
|
|
9
13
|
currentProvider;
|
|
@@ -338,7 +338,7 @@ const APPLY_PATCH_EXECUTABLE_BASENAMES = new Set([
|
|
|
338
338
|
]);
|
|
339
339
|
const EVOLCORE_SUBCOMMANDS = new Set([
|
|
340
340
|
'ability', 'agent', 'aid', 'bench', 'config', 'peer', 'ctl', 'data', 'diag', 'diagnose',
|
|
341
|
-
'fs', 'gateway', 'group', '
|
|
341
|
+
'fs', 'gateway', 'group', 'init', 'link-rules', 'logs', 'menu-client',
|
|
342
342
|
'mode', 'model', 'msg', 'mv', 'net', 'queue', 'response', 'restart',
|
|
343
343
|
'restart-monitor', 'rpc', 'start', 'stats', 'status', 'stop', 'storage', 'task',
|
|
344
344
|
'trigger', 'proxy', 'version', 'watch', 'session', 'pa-workspace', 'upgrade', 'update',
|
|
@@ -762,7 +762,6 @@ function materializeEvolcoreCmdShimArgv(argv) {
|
|
|
762
762
|
}
|
|
763
763
|
const INLINE_TEXT_FLAGS = {
|
|
764
764
|
agentNew: new Set(['--description', '--persona-text', '--handoff']),
|
|
765
|
-
agentPersona: new Set(['--text']),
|
|
766
765
|
agentWelcome: new Set(['--text']),
|
|
767
766
|
msgSend: new Set(['--description', '--text', '--transcript', '--handoff-context']),
|
|
768
767
|
groupSend: new Set(['--text', '--transcript']),
|
|
@@ -899,27 +898,6 @@ function canonicalizeCommaOnlyFlags(argv, flags) {
|
|
|
899
898
|
index++;
|
|
900
899
|
}
|
|
901
900
|
}
|
|
902
|
-
function canonicalizeHandoffText(argv) {
|
|
903
|
-
const action = argv[2];
|
|
904
|
-
if (action !== 'return' && action !== 'recover-return')
|
|
905
|
-
return;
|
|
906
|
-
const delimiter = argv.indexOf('--', 2);
|
|
907
|
-
if (delimiter >= 0) {
|
|
908
|
-
for (let index = delimiter + 1; index < argv.length; index++) {
|
|
909
|
-
argv[index] = decodeEvolcoreInlineText(argv[index]);
|
|
910
|
-
}
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
const fileIndex = argv.indexOf('--text-from-file', 2);
|
|
914
|
-
for (let index = 2; index < argv.length; index++) {
|
|
915
|
-
if (index === fileIndex) {
|
|
916
|
-
index++;
|
|
917
|
-
continue;
|
|
918
|
-
}
|
|
919
|
-
if (!argv[index].startsWith('--'))
|
|
920
|
-
argv[index] = decodeEvolcoreInlineText(argv[index]);
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
901
|
const LOCAL_FILE_VALUE_FLAGS = new Set(['--file', '--text-from-file', '--payload-file']);
|
|
924
902
|
function normalizeWindowsFilePath(value) {
|
|
925
903
|
if (process.platform !== 'win32' || !/^[A-Za-z]:[\\/]/u.test(value))
|
|
@@ -959,8 +937,6 @@ export function canonicalizeEvolcoreCommandArgv(argv) {
|
|
|
959
937
|
if (command === 'agent') {
|
|
960
938
|
if (subcommand === 'new')
|
|
961
939
|
decodeInlineFlags(result, INLINE_TEXT_FLAGS.agentNew);
|
|
962
|
-
else if (subcommand === 'persona')
|
|
963
|
-
decodeInlineFlags(result, INLINE_TEXT_FLAGS.agentPersona);
|
|
964
940
|
else if (subcommand === 'welcome')
|
|
965
941
|
decodeInlineFlags(result, INLINE_TEXT_FLAGS.agentWelcome);
|
|
966
942
|
}
|
|
@@ -992,9 +968,6 @@ export function canonicalizeEvolcoreCommandArgv(argv) {
|
|
|
992
968
|
else if (subcommand === 'update')
|
|
993
969
|
decodeInlineFlags(result, INLINE_TEXT_FLAGS.triggerUpdate);
|
|
994
970
|
}
|
|
995
|
-
else if (command === 'handoff') {
|
|
996
|
-
canonicalizeHandoffText(result);
|
|
997
|
-
}
|
|
998
971
|
else if (command === 'memory') {
|
|
999
972
|
canonicalizeListFlags(result, MEMORY_LIST_FLAGS);
|
|
1000
973
|
canonicalizeCommaOnlyFlags(result, MEMORY_COMMA_ONLY_FLAGS);
|
|
@@ -3,7 +3,7 @@ import { parseLiteralShellArgv } from './ec-command-parser.js';
|
|
|
3
3
|
const MAX_QUERY_LISTS = 8;
|
|
4
4
|
const MAX_PIPELINE_STAGES = 3;
|
|
5
5
|
const SUPPORTED_EXECUTABLES = new Set([
|
|
6
|
-
'echo', 'pwd', 'ls', 'cat', 'grep', 'rg', 'find', 'sed', 'head', 'tail', 'sort', 'git', 'wc', 'stat', 'lstat', 'awk',
|
|
6
|
+
'echo', 'pwd', 'ls', 'cat', 'grep', 'rg', 'find', 'sed', 'head', 'tail', 'sort', 'uniq', 'git', 'wc', 'stat', 'lstat', 'awk',
|
|
7
7
|
'bash', 'sh',
|
|
8
8
|
]);
|
|
9
9
|
const FIND_MUTATING_PRIMARY_RE = /^-(?:delete|exec|execdir|ok|okdir|fprint|fprint0|fprintf|fls)$/;
|
|
@@ -278,7 +278,7 @@ function analyzeGrep(args) {
|
|
|
278
278
|
paths.push(recursive('.'));
|
|
279
279
|
return paths;
|
|
280
280
|
}
|
|
281
|
-
function analyzeRg(args) {
|
|
281
|
+
function analyzeRg(args, hasPipelineInput = false) {
|
|
282
282
|
if (args.some(argument => RG_PROCESS_SPAWNING_OPTION_RE.test(argument)
|
|
283
283
|
|| argument === '--follow'
|
|
284
284
|
// `-z` is the short form of `--search-zip`; it may also appear in a
|
|
@@ -316,7 +316,7 @@ function analyzeRg(args) {
|
|
|
316
316
|
}
|
|
317
317
|
if (!optionsEnded && argument.startsWith('-') && argument !== '-') {
|
|
318
318
|
const option = argument.split('=', 1)[0];
|
|
319
|
-
if (
|
|
319
|
+
if (option === '--files' || option === '--type-list')
|
|
320
320
|
filesMode = true;
|
|
321
321
|
const inlineShort = !argument.startsWith('--') && argument.length > 2
|
|
322
322
|
&& (argument[1] === 'e' || argument[1] === 'f' || argument[1] === 'g');
|
|
@@ -367,7 +367,12 @@ function analyzeRg(args) {
|
|
|
367
367
|
}
|
|
368
368
|
if (!filesMode && !hasExplicitPattern && !implicitPatternSeen)
|
|
369
369
|
return null;
|
|
370
|
-
|
|
370
|
+
// Enumeration modes ignore the incoming stream and are never stdin filters.
|
|
371
|
+
if (hasPipelineInput && filesMode)
|
|
372
|
+
return null;
|
|
373
|
+
// Without an explicit path, ripgrep reads stdin when used after a pipe.
|
|
374
|
+
// Standalone searches and `--files` still default to the current directory.
|
|
375
|
+
if (!inputOperandSeen && !hasPipelineInput)
|
|
371
376
|
paths.push(recursive('.'));
|
|
372
377
|
return paths;
|
|
373
378
|
}
|
|
@@ -493,6 +498,23 @@ function analyzeSort(args) {
|
|
|
493
498
|
}
|
|
494
499
|
return paths;
|
|
495
500
|
}
|
|
501
|
+
function analyzeUniq(args) {
|
|
502
|
+
const valueOptions = new Set(['-f', '-s', '-w', '--skip-fields', '--skip-chars', '--check-chars']);
|
|
503
|
+
const allowedFlags = new Set(['-c', '-d', '-D', '-u', '-i', '--count', '--repeated', '--all-repeated', '--unique', '--ignore-case']);
|
|
504
|
+
for (let index = 0; index < args.length; index++) {
|
|
505
|
+
const argument = args[index];
|
|
506
|
+
const option = argument.split('=', 1)[0];
|
|
507
|
+
if (valueOptions.has(option)) {
|
|
508
|
+
const value = argument.includes('=') ? argument.slice(argument.indexOf('=') + 1) : args[++index];
|
|
509
|
+
if (!value || !/^\d+$/.test(value))
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
else if (!allowedFlags.has(argument)) {
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return [];
|
|
517
|
+
}
|
|
496
518
|
/**
|
|
497
519
|
* Git metadata queries do not expose file contents and their output paths are
|
|
498
520
|
* controlled by the repository, not by arbitrary shell operands. Keep this
|
|
@@ -828,7 +850,7 @@ function analyzeShellSyntaxCheck(args) {
|
|
|
828
850
|
}
|
|
829
851
|
return paths;
|
|
830
852
|
}
|
|
831
|
-
function analyzeCommand(argv) {
|
|
853
|
+
function analyzeCommand(argv, hasPipelineInput = false) {
|
|
832
854
|
const executable = normalizeExecutable(argv[0]);
|
|
833
855
|
if (!executable)
|
|
834
856
|
return null;
|
|
@@ -858,7 +880,7 @@ function analyzeCommand(argv) {
|
|
|
858
880
|
purpose = 'search';
|
|
859
881
|
break;
|
|
860
882
|
case 'rg':
|
|
861
|
-
pathOperands = analyzeRg(args);
|
|
883
|
+
pathOperands = analyzeRg(args, hasPipelineInput);
|
|
862
884
|
purpose = 'search';
|
|
863
885
|
break;
|
|
864
886
|
case 'find':
|
|
@@ -882,6 +904,10 @@ function analyzeCommand(argv) {
|
|
|
882
904
|
// sort 有路径参数时是文件读取,无路径参数时是纯 stdin 排序
|
|
883
905
|
purpose = 'stdin-transform';
|
|
884
906
|
break;
|
|
907
|
+
case 'uniq':
|
|
908
|
+
pathOperands = analyzeUniq(args);
|
|
909
|
+
purpose = 'stdin-transform';
|
|
910
|
+
break;
|
|
885
911
|
case 'git':
|
|
886
912
|
pathOperands = analyzeGit(args);
|
|
887
913
|
purpose = 'vcs-query';
|
|
@@ -914,7 +940,7 @@ function analyzeCommand(argv) {
|
|
|
914
940
|
// 无路径操作数的命令是纯 stdin→stdout 变换,可安全出现在管道任意位置。
|
|
915
941
|
// 对于 sort/wc/awk/grep/head/tail/sed:有路径参数时读文件,无路径参数时为 stdin 变换。
|
|
916
942
|
const stdinTransform = pathOperands.length === 0
|
|
917
|
-
&& ['sort', 'wc', 'awk', 'grep', 'rg', 'head', 'tail', 'sed'].includes(executable);
|
|
943
|
+
&& ['sort', 'uniq', 'wc', 'awk', 'grep', 'rg', 'head', 'tail', 'sed'].includes(executable);
|
|
918
944
|
// 修正 purpose:stdin 变换时统一标记,避免 'metadata-read'/'content-read' 歧义
|
|
919
945
|
const resolvedPurpose = stdinTransform ? 'stdin-transform' : purpose;
|
|
920
946
|
return {
|
|
@@ -940,7 +966,7 @@ export function analyzeReadonlyShellQuery(command, options = {}) {
|
|
|
940
966
|
const argv = parseStageArgv(stages[index], options);
|
|
941
967
|
if (!argv)
|
|
942
968
|
return { kind: 'unproven', reason: 'non-literal-command' };
|
|
943
|
-
const analyzed = analyzeCommand(argv);
|
|
969
|
+
const analyzed = analyzeCommand(argv, index > 0);
|
|
944
970
|
if (!analyzed)
|
|
945
971
|
return { kind: 'unproven', reason: 'unsupported-command-or-option' };
|
|
946
972
|
if (index > 0) {
|
|
@@ -1337,7 +1337,33 @@ function hClassReadScopeIncludesProtectedPath(value, options) {
|
|
|
1337
1337
|
return getExistingHClassMaskTargets(root, { selfAid: options.selfAid }).some(target => isSameOrDescendant(target.path, scope));
|
|
1338
1338
|
}
|
|
1339
1339
|
function analyzeShellProtectedOperands(command, options) {
|
|
1340
|
-
|
|
1340
|
+
let analyzedOptions = options;
|
|
1341
|
+
let logDiagnosticRoot;
|
|
1342
|
+
let analysis = analyzeReadonlyShellQuery(command, { managedTempDir: options.managedTempDir });
|
|
1343
|
+
const cdPrefix = command.match(/^\s*cd\s+("(?:[^"\\]|\\.)*"|'[^']*'|[^\s;&|]+)\s*&&\s*([\s\S]+)$/);
|
|
1344
|
+
if (cdPrefix) {
|
|
1345
|
+
const cdArgv = parseLiteralShellArgv(`cd ${cdPrefix[1]}`);
|
|
1346
|
+
const nestedAnalysis = analyzeReadonlyShellQuery(cdPrefix[2], { managedTempDir: options.managedTempDir });
|
|
1347
|
+
const logRoot = resolveProtectedCandidate(path.join(options.root ?? resolveRoot(), 'logs'));
|
|
1348
|
+
if (cdArgv?.length === 2 && !cdArgv[1].startsWith('-') && nestedAnalysis.kind === 'proven-readonly'
|
|
1349
|
+
&& isSameOrDescendant(resolveProtectedCandidate(cdArgv[1], options.cwd), logRoot)) {
|
|
1350
|
+
const cwd = resolveProtectedCandidate(cdArgv[1], options.cwd);
|
|
1351
|
+
analyzedOptions = { ...options, cwd };
|
|
1352
|
+
logDiagnosticRoot = logRoot;
|
|
1353
|
+
const pipelines = nestedAnalysis.ir.pipelines.map(pipeline => pipeline.map(query => ({
|
|
1354
|
+
...query,
|
|
1355
|
+
pathOperands: query.pathOperands.map(operand => ({
|
|
1356
|
+
...operand,
|
|
1357
|
+
value: resolveProtectedCandidate(operand.value, cwd),
|
|
1358
|
+
})),
|
|
1359
|
+
})));
|
|
1360
|
+
pipelines.unshift([{
|
|
1361
|
+
executable: 'cd', argv: cdArgv, pathOperands: [{ value: cwd, access: 'exact' }],
|
|
1362
|
+
stdinTransform: false, purpose: 'metadata-read', accessKind: 'metadata',
|
|
1363
|
+
}]);
|
|
1364
|
+
analysis = { kind: 'proven-readonly', ir: { pipelines, pathOperands: pipelines.flatMap(pipeline => pipeline.flatMap(query => query.pathOperands)) } };
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1341
1367
|
if (analysis.kind === 'unproven') {
|
|
1342
1368
|
const pathOptions = { cwd: options.cwd, root: options.root, selfAid: options.selfAid };
|
|
1343
1369
|
const hClassPath = literalProtectedShellOperand(command, 'h', pathOptions);
|
|
@@ -1351,14 +1377,17 @@ function analyzeShellProtectedOperands(command, options) {
|
|
|
1351
1377
|
};
|
|
1352
1378
|
}
|
|
1353
1379
|
const operands = analysis.ir.pipelines.flatMap(pipeline => pipeline.flatMap(query => {
|
|
1354
|
-
const scopes = boundedRgSourceScopes(query,
|
|
1380
|
+
const scopes = boundedRgSourceScopes(query, analyzedOptions);
|
|
1355
1381
|
return (scopes ?? query.pathOperands).map(operand => ({
|
|
1356
1382
|
operand,
|
|
1357
1383
|
accessKind: query.accessKind ?? (operand.access === 'recursive' ? 'enumerate' : 'content'),
|
|
1358
1384
|
}));
|
|
1359
1385
|
}));
|
|
1360
|
-
const hClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'h',
|
|
1361
|
-
const lClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'l',
|
|
1386
|
+
const hClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'h', analyzedOptions, accessKind)).find(Boolean);
|
|
1387
|
+
const lClassPath = operands.map(({ operand, accessKind }) => shellOperandMatchesClass(operand, 'l', analyzedOptions, accessKind)).find(Boolean);
|
|
1388
|
+
if (logDiagnosticRoot && operands.some(({ operand }) => !isSameOrDescendant(resolveProtectedCandidate(operand.value, analyzedOptions.cwd), logDiagnosticRoot))) {
|
|
1389
|
+
analysis = { kind: 'unproven', reason: 'log-diagnostic-scope-escape' };
|
|
1390
|
+
}
|
|
1362
1391
|
return {
|
|
1363
1392
|
analysis,
|
|
1364
1393
|
hClass: !!hClassPath,
|
|
@@ -2250,6 +2279,14 @@ function managedTempOptions(context) {
|
|
|
2250
2279
|
: process.env,
|
|
2251
2280
|
};
|
|
2252
2281
|
}
|
|
2282
|
+
function summarizeShellSegments(command) {
|
|
2283
|
+
const safeExecutables = new Set(['ec', 'head', 'tail', 'echo', 'rg', 'grep', 'sort', 'uniq', 'cut', 'wc', 'tr', 'pwd', 'cd']);
|
|
2284
|
+
return splitShellCommandSegments(command).slice(0, 8).map((segment, index) => {
|
|
2285
|
+
const words = parseShellWords(segment);
|
|
2286
|
+
const executable = safeExecutables.has(words[0]) ? words[0] : 'unknown';
|
|
2287
|
+
return `${index + 1}:${executable}/${Math.max(0, words.length - 1)}`;
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2253
2290
|
/**
|
|
2254
2291
|
* 校验 `cd <dir> && ec ...` 白名单里的目录。
|
|
2255
2292
|
*
|
|
@@ -2482,6 +2519,7 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2482
2519
|
message: '🔒 文件修改目标必须位于当前 workspace 或会话 $TMPDIR 内',
|
|
2483
2520
|
policyCode: fileMutation.source === 'file-change' ? 'file_change_workspace_escape' : 'apply_patch_workspace_escape',
|
|
2484
2521
|
errorDetailCode: 'APPLY_PATCH_WORKSPACE_ESCAPE', matchedPath: escapedPath,
|
|
2522
|
+
matchedRule: 'file-mutation-workspace-boundary',
|
|
2485
2523
|
};
|
|
2486
2524
|
}
|
|
2487
2525
|
for (const candidate of fileMutation.paths) {
|
|
@@ -2611,7 +2649,12 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2611
2649
|
if (ecCommand.kind === 'cd-prefixed') {
|
|
2612
2650
|
const cwdError = validateCdPrefixedCwd(ecCommand.cwd, context);
|
|
2613
2651
|
if (cwdError) {
|
|
2614
|
-
return {
|
|
2652
|
+
return {
|
|
2653
|
+
behavior: 'deny', input, message: cwdError, policyCode: 'ec_shell_composite_command',
|
|
2654
|
+
matchedPath: resolveProtectedCandidate(ecCommand.cwd, context.projectPath),
|
|
2655
|
+
matchedRule: 'ec-cwd-outside-workspace',
|
|
2656
|
+
parsedSegments: summarizeShellSegments(policyCommand),
|
|
2657
|
+
};
|
|
2615
2658
|
}
|
|
2616
2659
|
return prepareBoundedOutputInput(input, ecCommand.command, 'ec', context);
|
|
2617
2660
|
}
|
|
@@ -2666,6 +2709,8 @@ export function evaluateToolPreflight(toolName, input, context) {
|
|
|
2666
2709
|
input,
|
|
2667
2710
|
message,
|
|
2668
2711
|
policyCode: 'ec_shell_composite_command',
|
|
2712
|
+
matchedRule: `ec-shell-${ecCommand.issue}`,
|
|
2713
|
+
parsedSegments: summarizeShellSegments(policyCommand),
|
|
2669
2714
|
};
|
|
2670
2715
|
}
|
|
2671
2716
|
const boundedOutput = parseBoundedOutputShellCommand(command);
|
|
@@ -218,7 +218,11 @@ export function readSessionFullAccessOverride(session) {
|
|
|
218
218
|
const config = value;
|
|
219
219
|
return typeof config.enabled === 'boolean'
|
|
220
220
|
&& typeof config.authorizedBy === 'string' && !!config.authorizedBy.trim()
|
|
221
|
-
? {
|
|
221
|
+
? {
|
|
222
|
+
enabled: config.enabled,
|
|
223
|
+
authorizedBy: config.authorizedBy,
|
|
224
|
+
...(typeof config.promptedSessionId === 'string' ? { promptedSessionId: config.promptedSessionId } : {}),
|
|
225
|
+
}
|
|
222
226
|
: undefined;
|
|
223
227
|
}
|
|
224
228
|
function mainSessionFullAccessSelector(session) {
|
|
@@ -237,7 +241,15 @@ export function updateRelationSessionFullAccess(session, config) {
|
|
|
237
241
|
throw Object.assign(new Error('invalid session fullaccess configuration'), { code: 'INVALID_ARGUMENT' });
|
|
238
242
|
}
|
|
239
243
|
mutateConfig(ConfigTarget.Relation, selector, current => {
|
|
240
|
-
current.sessionFullAccess
|
|
244
|
+
const previous = current.sessionFullAccess;
|
|
245
|
+
const promptedSessionId = config.promptedSessionId
|
|
246
|
+
?? (config.enabled && previous?.enabled && previous.authorizedBy === config.authorizedBy
|
|
247
|
+
? previous.promptedSessionId : undefined);
|
|
248
|
+
current.sessionFullAccess = {
|
|
249
|
+
enabled: config.enabled,
|
|
250
|
+
authorizedBy: config.authorizedBy,
|
|
251
|
+
...(config.enabled && promptedSessionId ? { promptedSessionId } : {}),
|
|
252
|
+
};
|
|
241
253
|
});
|
|
242
254
|
}
|
|
243
255
|
export function createSessionFullAccessAuthorization(input) {
|
|
@@ -1574,7 +1574,15 @@ export class SessionManager {
|
|
|
1574
1574
|
if (!isTopicSession(current)) {
|
|
1575
1575
|
throw Object.assign(new Error('session fullaccess requires a topic session'), { code: 'INVALID_CONTEXT' });
|
|
1576
1576
|
}
|
|
1577
|
-
|
|
1577
|
+
const previous = current.metadata?.sessionFullAccess;
|
|
1578
|
+
const promptedSessionId = config.promptedSessionId
|
|
1579
|
+
?? (config.enabled && previous?.enabled && previous.authorizedBy === config.authorizedBy
|
|
1580
|
+
? previous.promptedSessionId : undefined);
|
|
1581
|
+
current.metadata = { ...(current.metadata ?? {}), sessionFullAccess: {
|
|
1582
|
+
enabled: config.enabled,
|
|
1583
|
+
authorizedBy: config.authorizedBy,
|
|
1584
|
+
...(config.enabled && promptedSessionId ? { promptedSessionId } : {}),
|
|
1585
|
+
} };
|
|
1578
1586
|
this.persistSession(current, 'none', { sessionFullAccessMutation: true });
|
|
1579
1587
|
return current;
|
|
1580
1588
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { agentSoulDir, kitsTemplatesDir, SOUL_GUIDE_FILE } from '../paths.js';
|
|
4
|
+
import { fileCache } from './daemon-file-cache.js';
|
|
5
|
+
/** 分册骨架的模板目录(与运行时目录同名同文件名)。 */
|
|
6
|
+
const SOUL_TEMPLATE_DIR = 'soul';
|
|
7
|
+
/**
|
|
8
|
+
* 判断一个分册是否「还没被写过」。
|
|
9
|
+
*
|
|
10
|
+
* 新建 agent 时每个分册都会带一份占位说明(写什么、谁写、不写什么),
|
|
11
|
+
* 方便 agent 直接看到自己该往哪写。但占位说明不是设定,不能算作已写入:
|
|
12
|
+
* - 去掉 HTML 注释后为空 → 未写入;
|
|
13
|
+
* - 与 `kits/templates/soul/<同名文件>` 完全一致 → 仍是未改动的骨架;
|
|
14
|
+
* - 每条非标题行都是 `>` 引用说明 → 只写了占位提示。
|
|
15
|
+
*/
|
|
16
|
+
export function isSoulPlaceholder(name, body) {
|
|
17
|
+
const meaningful = body
|
|
18
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
19
|
+
.split('\n')
|
|
20
|
+
.map(line => line.trim())
|
|
21
|
+
.filter(line => line !== '' && !line.startsWith('#') && !line.startsWith('>'));
|
|
22
|
+
if (meaningful.length === 0)
|
|
23
|
+
return true;
|
|
24
|
+
try {
|
|
25
|
+
// 模板是随包发布的只读文件,走 kits 组缓存(reload 后才刷新)。
|
|
26
|
+
const template = fileCache.getText(path.join(kitsTemplatesDir(), SOUL_TEMPLATE_DIR, name), { policy: 'on-reload', group: 'kits' });
|
|
27
|
+
return template !== null && body.trim() === template.trim();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 读取 soul 目录内容。
|
|
35
|
+
*
|
|
36
|
+
* - 跳过机制指南 `00-GUIDE.md`:它是写文件的说明,不是自我定义。
|
|
37
|
+
* - 跳过未写入的分册(见 `isSoulPlaceholder`)。
|
|
38
|
+
* - 目录不存在返回空结果。
|
|
39
|
+
*/
|
|
40
|
+
export function readSoulFiles(aid, group = `agent-files:${aid}`) {
|
|
41
|
+
const soulDir = agentSoulDir(aid);
|
|
42
|
+
let names;
|
|
43
|
+
try {
|
|
44
|
+
names = fs.readdirSync(soulDir).filter(name => name.toLowerCase().endsWith('.md')).sort();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { names: [], content: null };
|
|
48
|
+
}
|
|
49
|
+
const parts = [];
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
if (name === SOUL_GUIDE_FILE)
|
|
52
|
+
continue;
|
|
53
|
+
const raw = fileCache.getText(path.join(soulDir, name), { policy: 'mtime', group });
|
|
54
|
+
if (raw === null)
|
|
55
|
+
continue;
|
|
56
|
+
const body = raw.replace(/<!--[\s\S]*?-->/g, '').trim();
|
|
57
|
+
if (!body || isSoulPlaceholder(name, raw))
|
|
58
|
+
continue;
|
|
59
|
+
parts.push(body);
|
|
60
|
+
}
|
|
61
|
+
return { names, content: parts.length > 0 ? parts.join('\n\n') : null };
|
|
62
|
+
}
|
|
63
|
+
/** 只要能拼进 prompt / 喂给判定模型的正文。 */
|
|
64
|
+
export function readSoulContent(aid) {
|
|
65
|
+
return readSoulFiles(aid).content;
|
|
66
|
+
}
|
|
@@ -252,8 +252,8 @@ function readonlyDenialHint(command, policyCode, ctx) {
|
|
|
252
252
|
case 'unsupported-command-or-option':
|
|
253
253
|
return '命令或选项不在只读查询白名单内。不需要 `cd`:把绝对路径直接写进命令里。'
|
|
254
254
|
+ (isPowerShell
|
|
255
|
-
?
|
|
256
|
-
: '
|
|
255
|
+
? '列目录请改用 Glob 工具(path 传绝对路径);读单个文件请用 Read 工具或 `pwsh -NoProfile -Command "Get-Content -LiteralPath <绝对路径> [-Raw]"`;包装内不接受 `Get-ChildItem` / `ls`,也不接受 `;` 连接的多段查询。'
|
|
256
|
+
: '列文件请改用 Glob 工具(path 传绝对路径);读文件用 cat 或 Read 工具;有文件工具时优先用 Read / Glob / Grep。');
|
|
257
257
|
case 'unsupported-pipeline-filter':
|
|
258
258
|
return '管道 `|` 后面的命令不是纯 stdin 过滤命令。';
|
|
259
259
|
case 'pipeline-filter-must-use-stdin':
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { resolveRoot } from '../paths.js';
|
|
3
|
+
import { isValidAid } from '../aun/aid/validation.js';
|
|
4
|
+
/** Runtime authority is daemon-owned H-class data, outside Agent-editable content. */
|
|
5
|
+
export function contactAdmissionDirectory(selfAid) {
|
|
6
|
+
if (!isValidAid(selfAid))
|
|
7
|
+
throw new TypeError('contact admission requires a valid Agent AID');
|
|
8
|
+
return path.join(resolveRoot(), 'data', 'contact-admission', selfAid);
|
|
9
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { agentDir } from '../paths.js';
|
|
3
4
|
import { existsAtomic } from '../utils/atomic-write.js';
|
|
4
5
|
import { ownerResolver } from '../core/ownership/owner-resolver.js';
|
|
5
|
-
import {
|
|
6
|
+
import { logger } from '../utils/logger.js';
|
|
7
|
+
import { readAccessPolicy } from '../config/access-policy.js';
|
|
6
8
|
import { isInternalEntry, ownerRefAid } from './owner-directory-scope.js';
|
|
9
|
+
import { isPersonalAssistantSnapshot, resolveAllowExternalContacts } from './owner-directory-policy.js';
|
|
7
10
|
import { OwnerDirectoryCache, OWNER_DIRECTORY_INITIAL_WAIT_MS, OWNER_DIRECTORY_SCOPES, } from './owner-directory-cache.js';
|
|
8
11
|
const liveDirectories = new Map();
|
|
9
12
|
// Coalesce negative lookups from unrelated senders as well as concurrent calls.
|
|
@@ -30,21 +33,96 @@ export function liveOwnerDirectoryCache(selfAid) {
|
|
|
30
33
|
return live.cache;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
|
-
*
|
|
36
|
+
* `access` 开关变更后重算 `directory.md` 与 `identity.json`。
|
|
34
37
|
*
|
|
35
|
-
*
|
|
36
|
-
* 准入读的是 `config.json
|
|
37
|
-
*
|
|
38
|
+
* 会改变注入内容的开关有五个:内部档、外部档、总开关、白名单、黑名单。
|
|
39
|
+
* 准入读的是 `config.json`(每次现读,立刻生效),而注入内容来自渲染产物,
|
|
40
|
+
* 不重算就会停在旧版本——Owner 打开开关后,来客能联系了,agent 却看不到是谁。
|
|
38
41
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
42
|
+
* 优先复用 channel 注册着的活缓存;没有活缓存(channel 未连、命令走 CLI 进程)
|
|
43
|
+
* 时按 AID 临时读一次本地快照重新渲染,产出同样的字节。后者多一次读盘,
|
|
44
|
+
* 但保证"配置一改,注入就变",不必等到下一条入站消息。
|
|
45
|
+
*
|
|
46
|
+
* **ownerAid 必须取自 authorization.json,不能用 `ownerResolver` 猜。** 离线时
|
|
47
|
+
* 解析器只能给出 known owner(可能来自过期缓存或另一条关系),一旦与授权文件里的
|
|
48
|
+
* grantee/owner 对不上,`scopeAccess` 就不是 authorized,`directoryGone()` 随之
|
|
49
|
+
* 判真,`refreshMarkdown` 会把 `directory.md` 删掉——一个只读的开关变更变成删注入源。
|
|
50
|
+
* 授权文件缺失时直接返回 false:没有授权就没有可渲染的内容,也不该动现有文件。
|
|
41
51
|
*/
|
|
42
52
|
export function refreshDirectoryMarkdown(selfAid) {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
53
|
+
const live = liveOwnerDirectoryCache(selfAid);
|
|
54
|
+
if (live) {
|
|
55
|
+
live.refreshMarkdown();
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const directory = path.join(agentDir(selfAid), 'directory');
|
|
59
|
+
const ownerAid = authorizedOwnerAid(directory, selfAid);
|
|
60
|
+
if (!ownerAid)
|
|
61
|
+
return false;
|
|
62
|
+
try {
|
|
63
|
+
const cache = new OwnerDirectoryCache({ selfAid, ownerAid, directory });
|
|
64
|
+
cache.refreshMarkdown();
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
45
68
|
return false;
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 从 `authorization.json` 读出授权是的哪个 Owner。只认与本 agent 匹配的凭证。
|
|
73
|
+
*
|
|
74
|
+
* 与 `OwnerDirectoryCache.loadGrant` 同一条判据,但不依赖缓存实例——这里只是
|
|
75
|
+
* 为了在无活缓存时找到一个与磁盘授权一致的 ownerAid,好让 `scopeAccess` 有据可查。
|
|
76
|
+
*/
|
|
77
|
+
export function authorizedOwnerAid(directory, selfAid) {
|
|
78
|
+
try {
|
|
79
|
+
const raw = JSON.parse(fs.readFileSync(path.join(directory, 'authorization.json'), 'utf8'));
|
|
80
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
81
|
+
return undefined;
|
|
82
|
+
const record = raw;
|
|
83
|
+
if (record.granteeAid !== selfAid)
|
|
84
|
+
return undefined;
|
|
85
|
+
const ownerAid = typeof record.ownerAid === 'string' ? record.ownerAid.trim() : '';
|
|
86
|
+
return ownerAid || undefined;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* `ec directory refresh`:拉一次最新名录并重算注入文件。
|
|
94
|
+
*
|
|
95
|
+
* 两件事分开看:
|
|
96
|
+
* - **重算**(`directory.md` / `identity.json`)是纯本地 I/O,永远能做,不依赖连接。
|
|
97
|
+
* 直接改写 `remarks/*.md` 之后调它,改动立刻进注入。
|
|
98
|
+
* - **拉取**(远端 → 共享缓存 → 落地)需要活的 channel;没有连接时跳过,
|
|
99
|
+
* 但重算照做,返回 `pulled: false` 让调用方知道"没拉到新的"。
|
|
100
|
+
*/
|
|
101
|
+
export async function refreshOwnerDirectory(selfAid) {
|
|
102
|
+
const live = liveOwnerDirectoryCache(selfAid);
|
|
103
|
+
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
104
|
+
if (live) {
|
|
105
|
+
if (live.scopeAccess(scope) !== 'authorized')
|
|
106
|
+
return { pulled: false, regenerated: false };
|
|
107
|
+
let timer;
|
|
108
|
+
try {
|
|
109
|
+
// 空 digests = 无条件拉取,不做摘要比对。
|
|
110
|
+
await Promise.race([
|
|
111
|
+
live.pullAndApply({}).catch(() => undefined),
|
|
112
|
+
new Promise(resolve => { timer = setTimeout(resolve, OWNER_DIRECTORY_INITIAL_WAIT_MS); }),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
if (timer)
|
|
117
|
+
clearTimeout(timer);
|
|
118
|
+
}
|
|
119
|
+
// 落地本身会重算;再显式算一次兜住"拉取失败但备注改过"的情形。
|
|
120
|
+
const regenerated = refreshDirectoryMarkdown(selfAid);
|
|
121
|
+
const snapshot = live.readSnapshot(scope);
|
|
122
|
+
return { pulled: !!snapshot, ...(snapshot ? { total: snapshot.total } : {}), regenerated };
|
|
123
|
+
}
|
|
124
|
+
// 没有连接:拉不动,但本地重算照做——手工改备注之后最需要的正是这一步。
|
|
125
|
+
return { pulled: false, regenerated: refreshDirectoryMarkdown(selfAid) };
|
|
48
126
|
}
|
|
49
127
|
/**
|
|
50
128
|
* 触发一次有界同步:处理待办的 pending 标记(拉取 + 落盘),最多等
|
|
@@ -79,6 +157,8 @@ export async function syncOwnerDirectoryForLookup(selfAid) {
|
|
|
79
157
|
}
|
|
80
158
|
/** Cache misses get one bounded synchronization attempt before admission, using the live channel. */
|
|
81
159
|
export async function prepareOwnerDirectoryAdmission(selfAid, aid) {
|
|
160
|
+
if (readAccessPolicy(selfAid).contactAdmission === 'app-v1')
|
|
161
|
+
return;
|
|
82
162
|
const live = liveDirectories.get(selfAid);
|
|
83
163
|
if (!live)
|
|
84
164
|
return;
|
|
@@ -114,18 +194,10 @@ export async function prepareOwnerDirectoryAdmission(selfAid, aid) {
|
|
|
114
194
|
}
|
|
115
195
|
}
|
|
116
196
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* 个人助理要联系 Owner 之外的人,所以对自己默认打开;其余 agent 默认关闭,
|
|
120
|
-
* 只有明确有外部业务需求时才由 Owner 打开。准入、注入、查询三处共用这一个判据。
|
|
197
|
+
* 外部联系开关的最终值、个人助理判据都搬到了 `owner-directory-policy`,
|
|
198
|
+
* 这里只做转出:老调用方(channel、查询命令、测试)仍从本模块 import。
|
|
121
199
|
*/
|
|
122
|
-
export
|
|
123
|
-
/** 显式配置;缺省时从配置文件读。测试用来固定优先级。 */
|
|
124
|
-
explicit = readExplicitAllowExternalContacts(selfAid)) {
|
|
125
|
-
if (explicit !== undefined)
|
|
126
|
-
return explicit;
|
|
127
|
-
return !!snapshot?.personalAssistant?.aid && snapshot.personalAssistant.aid === selfAid;
|
|
128
|
-
}
|
|
200
|
+
export { isPersonalAssistantSnapshot, resolveAllowExternalContacts };
|
|
129
201
|
/**
|
|
130
202
|
* 本地判定一条 AID 在名录中的身份。只读本地快照,不发起网络请求。
|
|
131
203
|
*
|
|
@@ -136,26 +208,44 @@ explicit = readExplicitAllowExternalContacts(selfAid)) {
|
|
|
136
208
|
* 返回 undefined 表示这个 Agent 从未接入名录(无授权也无快照),调用方应保持
|
|
137
209
|
* 旧的准入行为。
|
|
138
210
|
*/
|
|
139
|
-
export function readOwnerDirectoryMembership(selfAid, aid) {
|
|
211
|
+
export function readOwnerDirectoryMembership(selfAid, aid, appOwned = false) {
|
|
140
212
|
const directory = path.join(agentDir(selfAid), 'directory');
|
|
141
213
|
// "从未接入名录"与"接入过但当前不可用"是两种结论,判据是盘上有没有痕迹。
|
|
142
214
|
// 原子写的热备名(`*.json_`)由 existsAtomic 负责,业务层不关心后缀。
|
|
143
215
|
const configured = existsAtomic(path.join(directory, 'authorization.json'))
|
|
144
216
|
|| existsAtomic(path.join(directory, 'contacts.json'));
|
|
145
|
-
if (!configured)
|
|
217
|
+
if (!configured && !appOwned)
|
|
146
218
|
return undefined;
|
|
147
219
|
const ownerAid = ownerResolver.owner(selfAid);
|
|
148
|
-
if (!ownerAid)
|
|
220
|
+
if (!ownerAid) {
|
|
221
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, 'owner_unresolved');
|
|
149
222
|
return { category: 'unavailable' };
|
|
223
|
+
}
|
|
150
224
|
try {
|
|
151
|
-
const
|
|
225
|
+
const relationVersion = appOwned ? ownerResolver.snapshot(selfAid).consensus?.relation_version : undefined;
|
|
226
|
+
if (appOwned && (!Number.isSafeInteger(relationVersion) || (relationVersion ?? 0) <= 0))
|
|
227
|
+
return { category: 'unavailable' };
|
|
228
|
+
const cache = new OwnerDirectoryCache({ selfAid, ownerAid, directory, relationVersion });
|
|
152
229
|
const scope = OWNER_DIRECTORY_SCOPES[0];
|
|
153
|
-
|
|
230
|
+
const accessReason = cache.scopeAccessUnavailableReason(scope);
|
|
231
|
+
if (accessReason) {
|
|
232
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, accessReason, ownerAid);
|
|
154
233
|
return { category: 'unavailable' };
|
|
234
|
+
}
|
|
155
235
|
const snapshot = cache.readSnapshot(scope);
|
|
156
|
-
if (!snapshot)
|
|
236
|
+
if (!snapshot) {
|
|
237
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, existsAtomic(path.join(directory, `${scope}.json`)) ? 'snapshot_invalid' : 'snapshot_missing', ownerAid);
|
|
157
238
|
return { category: 'unavailable' };
|
|
239
|
+
}
|
|
158
240
|
const effectiveAllowExternalContacts = resolveAllowExternalContacts(selfAid, snapshot);
|
|
241
|
+
if (appOwned) {
|
|
242
|
+
const entry = snapshot.entries.find(item => item.aid === aid);
|
|
243
|
+
const blocked = snapshot.blockedAids?.includes(aid) ?? false;
|
|
244
|
+
const scopeExcluded = entry?.agent_scope?.mode === 'selected' && !entry.agent_scope.agent_aids.includes(selfAid);
|
|
245
|
+
const internal = entry ? isInternalEntry(entry, ownerRefAid(snapshot, ownerAid)) : undefined;
|
|
246
|
+
return { category: entry ? (entry.type === 'agent' ? 'agent' : entry.type === 'human' ? 'human' : 'other') : 'not_found',
|
|
247
|
+
entry, blocked, scopeExcluded, internal, effectiveAllowExternalContacts };
|
|
248
|
+
}
|
|
159
249
|
if (aid === ownerAid || snapshot.owner?.aid === aid) {
|
|
160
250
|
return { category: 'owner', internal: true, effectiveAllowExternalContacts };
|
|
161
251
|
}
|
|
@@ -180,7 +270,16 @@ export function readOwnerDirectoryMembership(selfAid, aid) {
|
|
|
180
270
|
// 准入仍按内外分档(与宿主类型一致),只是不假装知道它是什么。
|
|
181
271
|
return { category: 'other', internal, entry, effectiveAllowExternalContacts };
|
|
182
272
|
}
|
|
183
|
-
catch {
|
|
273
|
+
catch (error) {
|
|
274
|
+
const code = error && typeof error === 'object' && 'code' in error
|
|
275
|
+
&& typeof error.code === 'string' && /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code)
|
|
276
|
+
? error.code
|
|
277
|
+
: error instanceof Error ? error.name : 'unknown';
|
|
278
|
+
logDirectoryAdmissionUnavailable(selfAid, aid, 'read_error', ownerAid, code);
|
|
184
279
|
return { category: 'unavailable' };
|
|
185
280
|
}
|
|
186
281
|
}
|
|
282
|
+
function logDirectoryAdmissionUnavailable(selfAid, targetAid, reason, ownerAid, errorCode) {
|
|
283
|
+
logger.warn(`[OwnerDirectoryAdmission] unavailable self=${selfAid} target=${targetAid}`
|
|
284
|
+
+ ` owner=${ownerAid ?? '<unresolved>'} reason=${reason}${errorCode ? ` error=${errorCode}` : ''}`);
|
|
285
|
+
}
|