evolcore 0.0.43-test.2 → 0.0.43-test.4

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.
Files changed (173) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/bin/ecmsg.js +229 -0
  3. package/bin/install-codex-managed-hooks.mjs +130 -8
  4. package/dist/ability/application-service.js +37 -0
  5. package/dist/ability/resources.js +28 -0
  6. package/dist/ability/runtime.js +6 -1
  7. package/dist/agents/claude-runner.js +7 -5
  8. package/dist/agents/codex/app-server-client.js +0 -12
  9. package/dist/agents/codex-runner.js +0 -37
  10. package/dist/agents/ecagent-runner.js +138 -36
  11. package/dist/aun/aid/agentmd.js +52 -13
  12. package/dist/aun/menu/client.js +8 -7
  13. package/dist/aun/menu/index.js +1 -1
  14. package/dist/aun/menu/transport.js +8 -5
  15. package/dist/aun/msg/p2p.js +4 -2
  16. package/dist/aun/service-proxy.js +3 -0
  17. package/dist/channels/aun.js +105 -53
  18. package/dist/channels/daemon.js +14 -2
  19. package/dist/cli/agent-command.js +5 -0
  20. package/dist/cli/agent-create.js +31 -11
  21. package/dist/cli/agent.js +9 -3
  22. package/dist/cli/aun-commands.js +19 -21
  23. package/dist/cli/daemon-commands.js +30 -18
  24. package/dist/cli/directory.js +98 -56
  25. package/dist/cli/getmeta-command.js +2 -1
  26. package/dist/cli/index.js +1 -1
  27. package/dist/cli/init.js +13 -5
  28. package/dist/cli/peer.js +2 -1
  29. package/dist/cli/task-context.js +3 -1
  30. package/dist/cli/trigger-command.js +20 -14
  31. package/dist/config/access-policy.js +0 -1
  32. package/dist/config/boot-log.js +12 -2
  33. package/dist/config/builtin-role-templates.js +2 -2
  34. package/dist/config/builtin-roles.js +2 -1
  35. package/dist/config/config-field-policy.js +7 -0
  36. package/dist/config/config-manager.js +30 -10
  37. package/dist/config/peer-role-resolver.js +23 -1
  38. package/dist/config/role-schema.js +25 -1
  39. package/dist/config/role-service.js +9 -4
  40. package/dist/config/role-store.js +30 -8
  41. package/dist/config/schema-migration.js +121 -0
  42. package/dist/core/agent-application-service.js +11 -0
  43. package/dist/core/agent-ipc-registration.js +2 -0
  44. package/dist/core/agent-runtime.js +41 -9
  45. package/dist/core/auth/auth-gateway.js +14 -4
  46. package/dist/core/auth/operation-authorizer.js +19 -1
  47. package/dist/core/auth/operation-catalog.js +12 -2
  48. package/dist/core/baseagent-loader.js +11 -3
  49. package/dist/core/bootstrap-service.js +8 -0
  50. package/dist/core/channel-loader.js +61 -23
  51. package/dist/core/channel-runtime.js +5 -0
  52. package/dist/core/command/agent-control.js +5 -2
  53. package/dist/core/command/agentmd-menu-request.js +50 -0
  54. package/dist/core/command/agentmd-menu.js +156 -0
  55. package/dist/core/command/chatmode-config.js +46 -0
  56. package/dist/core/command/command-handler.js +44 -17
  57. package/dist/core/command/daemon-diagnostics.js +2 -1
  58. package/dist/core/command/menu-catalog.js +14 -1
  59. package/dist/core/command/menu-handler.js +74 -24
  60. package/dist/core/command/menu-protocol.js +8 -0
  61. package/dist/core/command/role-menu.js +23 -9
  62. package/dist/core/command/slash-handler.js +52 -47
  63. package/dist/core/daemon-lifecycle.js +43 -17
  64. package/dist/core/event-catalog.js +19 -0
  65. package/dist/core/evolagent-registry.js +3 -0
  66. package/dist/core/evolagent.js +5 -4
  67. package/dist/core/ipc-registration.js +6 -0
  68. package/dist/core/lifecycle-notice.js +185 -0
  69. package/dist/core/message/aun-ipc-sender.js +30 -24
  70. package/dist/core/message/contact-admission.js +1 -19
  71. package/dist/core/message/im-renderer.js +81 -40
  72. package/dist/core/message/message-admission.js +21 -62
  73. package/dist/core/message/message-bridge.js +18 -5
  74. package/dist/core/message/message-utils.js +9 -0
  75. package/dist/core/message/peer-mode.js +16 -8
  76. package/dist/core/message/response-engine.js +67 -47
  77. package/dist/core/model/model-capabilities.js +37 -0
  78. package/dist/core/model/model-catalog.js +6 -2
  79. package/dist/core/ownership/owner-resolver.js +74 -36
  80. package/dist/core/permission/ec-command-parser.js +62 -13
  81. package/dist/core/plugin-lifecycle.js +6 -2
  82. package/dist/core/relation/pa-team.js +132 -0
  83. package/dist/core/role/runtime-policy.js +4 -3
  84. package/dist/core/thread/thread-service.js +6 -4
  85. package/dist/directory/owner-directory-admission.js +0 -3
  86. package/dist/directory/owner-directory-cache.js +201 -17
  87. package/dist/directory/owner-directory-markdown.js +44 -21
  88. package/dist/directory/owner-directory-policy.js +1 -1
  89. package/dist/directory/owner-directory-query-operation.js +218 -98
  90. package/dist/directory/owner-directory-request-operation.js +76 -0
  91. package/dist/directory/owner-directory-scope.js +35 -4
  92. package/dist/directory/owner-directory-search.js +76 -23
  93. package/dist/directory/owner-directory-store.js +5 -38
  94. package/dist/directory/owner-directory-text.js +60 -0
  95. package/dist/eck/kit-renderer.js +6 -3
  96. package/dist/eck/message-renderer.js +2 -5
  97. package/dist/ecweb/message-context-service.js +4 -0
  98. package/dist/ecweb/runtime/lifecycle.js +29 -5
  99. package/dist/ecweb/runtime/supervisor.js +83 -27
  100. package/dist/index.js +209 -38
  101. package/dist/paths.js +4 -2
  102. package/dist/product.js +1 -0
  103. package/dist/proxy/service-supervisor.js +377 -141
  104. package/dist/response-system/engines/v1/index.js +2 -4
  105. package/dist/response-system/modes/single-session/index.js +1 -1
  106. package/dist/trigger/audit.js +3 -2
  107. package/dist/trigger/authorization.js +2 -3
  108. package/dist/trigger/history.js +4 -3
  109. package/dist/trigger/ipc-service.js +24 -19
  110. package/dist/trigger/manager.js +3 -5
  111. package/dist/trigger/parser.js +4 -21
  112. package/dist/trigger/patch.js +3 -15
  113. package/dist/trigger/scheduler.js +53 -13
  114. package/dist/trigger/validation.js +0 -13
  115. package/dist/utils/error-utils.js +15 -5
  116. package/dist/utils/macos-autostart.js +31 -0
  117. package/dist/utils/model-prices.jsonl +15 -8
  118. package/dist/utils/process-introspect.js +21 -1
  119. package/dist/utils/startup-trace.js +7 -1
  120. package/dist/utils/windows-autostart.js +1 -0
  121. package/ecagent/README.md +18 -0
  122. package/ecagent/dist/harness/agent-harness.d.ts +2 -0
  123. package/ecagent/dist/harness/agent-harness.js +24 -8
  124. package/ecagent/dist/harness/compaction/branch-summarization.js +1 -1
  125. package/ecagent/dist/harness/compaction/compaction.js +7 -4
  126. package/ecagent/dist/harness/types.d.ts +1 -0
  127. package/kits/docs/channels/aun.md +1 -1
  128. package/kits/docs/context-assembly.md +1 -1
  129. package/kits/docs/evolcore/INDEX.md +5 -2
  130. package/kits/docs/evolcore/directory.md +125 -35
  131. package/kits/docs/evolcore/ecweb-lifecycle.md +26 -0
  132. package/kits/docs/evolcore/file-navigation.md +279 -0
  133. package/kits/docs/evolcore/menu-protocol.md +1 -0
  134. package/kits/docs/evolcore/model.md +5 -3
  135. package/kits/docs/evolcore/msg.md +1 -0
  136. package/kits/docs/evolcore/peer.md +2 -1
  137. package/kits/docs/evolcore/response.md +4 -2
  138. package/kits/docs/evolcore/task.md +2 -0
  139. package/kits/docs/evolcore/thread-chain.md +1 -1
  140. package/kits/docs/evolcore/tool-authorization.md +4 -1
  141. package/kits/docs/evolcore/trigger.md +10 -7
  142. package/kits/docs/identity/ROLE_DETAIL.md +2 -0
  143. package/kits/eck_manifest.json +6 -23
  144. package/kits/eck_manifest.memory.json +26 -1
  145. package/kits/rules/01-overview.md +42 -44
  146. package/kits/rules/02-navigation.md +44 -53
  147. package/kits/rules/03-identity.md +21 -25
  148. package/kits/rules/04-relation.md +23 -33
  149. package/kits/rules/05-venue.md +24 -25
  150. package/kits/schemas/_meta.json +10 -10
  151. package/kits/schemas/agent-config.schema.19.json +10 -6
  152. package/kits/schemas/relation-config.schema.12.json +2 -2
  153. package/kits/schemas/role-config.schema.2.json +5 -5
  154. package/kits/schemas/role-registry.schema.1.json +3 -2
  155. package/kits/skills/ec-service-proxy/SKILL.md +10 -0
  156. package/kits/skills/ec-trigger/SKILL.md +1 -1
  157. package/kits/templates/soul/00-GUIDE.md +20 -42
  158. package/kits/templates/system-fragments/channel.md +2 -2
  159. package/kits/templates/system-fragments/commands.md +1 -1
  160. package/kits/templates/system-fragments/directory-contacts.md +1 -1
  161. package/kits/templates/system-fragments/identity.md +0 -1
  162. package/kits/templates/system-fragments/personal-assistant.md +2 -17
  163. package/kits/templates/system-fragments/reply.md +7 -0
  164. package/kits/templates/system-fragments/session.md +6 -2
  165. package/package.json +18 -13
  166. package/dist/eck/paactive-context.js +0 -45
  167. package/dist/response-system/engines/v1/paactive-flow.js +0 -18
  168. package/kits/eck_manifest.paactive.json +0 -528
  169. package/kits/eck_message_manifest.paactive.json +0 -233
  170. package/kits/templates/message-fragments/paactive/item.md +0 -3
  171. package/kits/templates/system-fragments/paactive/channel.md +0 -25
  172. package/kits/templates/system-fragments/paactive/reply.md +0 -25
  173. package/kits/templates/system-fragments/paactive/session.md +0 -32
package/dist/cli/peer.js CHANGED
@@ -83,7 +83,8 @@ Options:
83
83
  --format json 输出 JSON
84
84
  --help, -h 显示帮助
85
85
 
86
- 添加联系人、审批联系人申请由 Owner 在 Evol App 名录中完成,Agent 侧不提供入口。`);
86
+ 添加联系人、审批联系人申请由 Evol App 名录流程处理。
87
+ 发起 app-v1 加好友申请:ec directory request <target-aid> --self <agent-aid> [--note <申请介绍>]。`);
87
88
  }
88
89
  function withDefaultSelf(args) {
89
90
  if (args.includes('--self'))
@@ -7,6 +7,7 @@ import os from 'node:os';
7
7
  import path from 'node:path';
8
8
  import { readDelegationCredential } from '../core/auth/agent-delegation.js';
9
9
  import { resolveRoot } from '../paths.js';
10
+ import { TEST_TMPDIR_ENV } from '../product.js';
10
11
  export const TASK_RUNTIME_CONTEXT_ENV = 'EVOLCORE_TASK_RUNTIME_CONTEXT';
11
12
  export const SESSION_RUNTIME_DIR_ENV = 'EVOLCORE_SESSION_RUNTIME_DIR';
12
13
  export const DAEMON_RUNTIME_EPOCH_ENV = 'EVOLCORE_DAEMON_RUNTIME_EPOCH';
@@ -189,7 +190,8 @@ function canonicalHome() {
189
190
  return process.platform === 'win32' ? canonical.toLowerCase() : canonical;
190
191
  }
191
192
  function systemTempRoot() {
192
- const testRoot = process.env.EVOLCORE_TEST === '1' && process.env.TMPDIR?.trim();
193
+ const testRoot = process.env.EVOLCORE_TEST === '1'
194
+ && (process.env.TMPDIR || process.env[TEST_TMPDIR_ENV])?.trim();
193
195
  const candidate = testRoot && path.isAbsolute(testRoot)
194
196
  ? testRoot
195
197
  : process.platform === 'win32'
@@ -57,9 +57,12 @@ export async function cmdTrigger(args) {
57
57
  if (response.result.error)
58
58
  console.log(response.result.error);
59
59
  }
60
+ else if (sub === 'cancel') {
61
+ console.log(`✓ interrupted ${response.runId ?? response.result?.runId ?? rest[0] ?? ''}`);
62
+ }
60
63
  else {
61
64
  const verb = { create: 'created', set: 'created', update: 'updated', enable: 'enabled',
62
- disable: 'disabled', cancel: 'disabled', delete: 'deleted', remove: 'deleted', rm: 'deleted' }[sub];
65
+ disable: 'disabled', delete: 'deleted', remove: 'deleted', rm: 'deleted' }[sub];
63
66
  console.log(`✓ ${verb} ${response.trigger.id}${['create', 'set', 'update'].includes(sub) ? ` (${response.trigger.name})` : ''}`);
64
67
  }
65
68
  return;
@@ -122,7 +125,7 @@ function printHelp() {
122
125
  update [--agent <aid>] <triggerId> <参数...> [--if-revision <sha256:...>] [--json]
123
126
  enable [--agent <aid>] <triggerId>
124
127
  disable [--agent <aid>] <triggerId>
125
- cancel [--agent <aid>] <triggerId> (disable 的兼容别名)
128
+ cancel [--agent <aid>] <runId> (中止当前活动运行)
126
129
  delete|remove|rm [--agent <aid>] <triggerId>
127
130
  run [--agent <aid>] <triggerId> [--dry-run] [--json]
128
131
  template list|show <name> [--json]
@@ -136,7 +139,6 @@ Create 参数模式支持:
136
139
  --script-path <路径> --script-runtime <node|python|bash>
137
140
  --script-args <JSON> --script-timeout <时长>
138
141
  --feedback <target|event-session> (event-session 使用事件来源会话)
139
- --baseagent <name> (仅 --exec trigger-session)
140
142
  --execution-timeout <时长>(模型类 Trigger 单次执行总时限)
141
143
  --model <模型> --effort <low|medium|high|xhigh|max>
142
144
  --max-runs <次数> --max-duration <时长: 30s|15m|2h|1d>
@@ -166,7 +168,7 @@ Update 参数:
166
168
  --feedback <origin|target|event-session|silent>
167
169
  --target-channel <channelKey> --target-channel-id <ID> (必须同时指定)
168
170
  --target-chat-type <private|group> --target-session <main|thread> [--target-thread-id <threadId>]
169
- --trigger-thread <by-run|by-trigger> --baseagent <name> (仅 trigger_session 之间)
171
+ --trigger-thread <by-run|by-trigger>
170
172
  --on-error <fail|retry> --noop-sentinel <文本>
171
173
  --retry-attempts <次数> --retry-backoff <毫秒>
172
174
  --script-runtime <node|python|bash> --script-args <JSON> --script-timeout <时长>
@@ -225,7 +227,7 @@ async function showTrigger(args, json, response) {
225
227
  }
226
228
  console.log(`execution: ${t.execution.type}`);
227
229
  if (t.execution.type === 'trigger_session')
228
- console.log(`baseagent: ${t.execution.baseagent ?? 'legacy/inherit'}`);
230
+ console.log('baseagent: inherit (所属 Agent 当前基座)');
229
231
  if (t.execution.type === 'script')
230
232
  console.log(`script: ${scriptCommandLabel(t.execution.script)}`);
231
233
  console.log(`model: ${t.execution.model ?? 'inherit'}`);
@@ -350,7 +352,6 @@ export async function buildTriggerCreateRequest(args, fileScope, defaultAgentAid
350
352
  ...(parsed.permissionMode ? { permissionMode: parsed.permissionMode } : {}),
351
353
  ...(parsed.executionType === 'trigger_session' ? {
352
354
  thread: parsed.triggerThread ?? 'by_trigger',
353
- ...(parsed.baseagent ? { baseagent: parsed.baseagent } : {}),
354
355
  } : {}),
355
356
  onError: 'retry',
356
357
  noopSentinel: '[[NOOP]]',
@@ -504,14 +505,19 @@ export function resolveTriggerCommandArgv(argv, defaultAgentAid) {
504
505
  throw new Error(`Unknown trigger command: ${sub}`);
505
506
  const agentAid = flagValue(args, '--agent') ?? defaultAgentAid;
506
507
  const valueFlags = ['--agent', '--format', '--limit', '--if-revision', '--prompt-file', '--script-file'];
507
- const triggerId = ['list', 'create', 'set'].includes(sub) ? undefined : optionalPositional(args, 0, valueFlags);
508
- if (!['list', 'history', 'create', 'set'].includes(sub) && !triggerId)
509
- throw new Error('missing triggerId');
508
+ const positional = ['list', 'create', 'set'].includes(sub) ? undefined : optionalPositional(args, 0, valueFlags);
509
+ if (!['list', 'history', 'create', 'set'].includes(sub) && !positional) {
510
+ throw new Error(sub === 'cancel' ? 'missing runId' : 'missing triggerId');
511
+ }
510
512
  const limit = Number(flagValue(args, '--limit') ?? 100);
511
513
  if (!Number.isInteger(limit) || limit <= 0 || limit > 10_000)
512
514
  throw new Error('Invalid history limit');
513
- return { type: types[sub], agentAid, triggerId, limit, all: hasFlag(args, '--all'),
514
- enabled: sub === 'enable', dryRun: hasFlag(args, '--dry-run') };
515
+ return {
516
+ type: types[sub], agentAid,
517
+ ...(sub === 'cancel' ? { runId: positional } : { triggerId: positional }),
518
+ limit, all: hasFlag(args, '--all'),
519
+ enabled: sub === 'enable', dryRun: hasFlag(args, '--dry-run')
520
+ };
515
521
  }
516
522
  function triggerUpdateArgs(args) {
517
523
  const out = [];
@@ -585,11 +591,11 @@ async function setEnabled(args, enabled, json) {
585
591
  }
586
592
  async function cancelTrigger(args, json) {
587
593
  const agentAid = resolveAgentAid(args);
588
- const triggerId = positional(args, 0, ['--agent', '--format']);
589
- const res = await request({ type: 'trigger.cancel', agentAid, triggerId });
594
+ const runId = positional(args, 0, ['--agent', '--format']);
595
+ const res = await request({ type: 'trigger.cancel', agentAid, runId });
590
596
  if (json)
591
597
  return printJson(res);
592
- console.log(`✓ disabled ${res.trigger.id}`);
598
+ console.log(`✓ interrupted ${res.runId ?? res.result?.runId ?? runId}`);
593
599
  }
594
600
  async function deleteTrigger(args, json) {
595
601
  const agentAid = resolveAgentAid(args);
@@ -112,7 +112,6 @@ function assertAccessPolicyWrite(input, agent, policy) {
112
112
  }
113
113
  function clonePolicy(policy) {
114
114
  return {
115
- ...(policy.contactAdmission ? { contactAdmission: policy.contactAdmission } : {}),
116
115
  allowInternalContacts: policy.allowInternalContacts ?? true,
117
116
  allowExternalContacts: policy.allowExternalContacts ?? false,
118
117
  allowAllContacts: policy.allowAllContacts ?? false,
@@ -15,7 +15,7 @@ import { logger } from '../utils/logger.js';
15
15
  import { autoMigrateIfNeeded } from '../config-store.js';
16
16
  import { ConfigTarget, initConfigManager, notifyConfigWrite } from './config-manager.js';
17
17
  import { ensureRoleConfigV4OnStartup, ensureRoleConfigV5OnStartup } from './role-migration-startup.js';
18
- import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensurePeerFileRenameOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup, invalidateMigrationReadCache, withMigrationReadCache, } from './schema-migration.js';
18
+ import { ensureAccessPolicyMigrationOnStartup, ensureAgentModelProviderMigrationOnStartup, ensureAgentOnlyModelMigrationOnStartup, ensureAuxiliaryModelMigrationOnStartup, ensurePeerFileRenameOnStartup, ensurePublishedSchemaConsolidationMigrationOnStartup, ensureProviderServiceTypeMigrationOnStartup, ensureRelationConfigVersionMigrationOnStartup, invalidateMigrationReadCache, withMigrationReadCache, } from './schema-migration.js';
19
19
  import { ensureContactBookV2OnStartup } from './peer-book-v2-startup.js';
20
20
  import { synchronizeAllManagementPeersSync } from './peer-book-store.js';
21
21
  import { readInstalledEvolcoreVersion, readFastaunVersion } from '../utils/evolcore-version.js';
@@ -38,7 +38,10 @@ export async function prepareStartupConfig(recoverRoleMutations, onStep) {
38
38
  step('auxiliaryModel');
39
39
  // 任一迁移真的落盘后立刻丢弃缓存:这三个迁移改的是同一批 relation 配置,
40
40
  // 后一个迁移若沿用写盘前的旧文本做整文件覆盖,会把前一个的改动回滚掉。
41
- const { auxiliaryModelMigration, agentOnlyModelMigration, relationVersionMigration } = await withMigrationReadCache(async () => {
41
+ const { publishedSchemaConsolidationMigration, auxiliaryModelMigration, agentOnlyModelMigration, relationVersionMigration } = await withMigrationReadCache(async () => {
42
+ const publishedSchemaConsolidation = await ensurePublishedSchemaConsolidationMigrationOnStartup();
43
+ if (publishedSchemaConsolidation)
44
+ invalidateMigrationReadCache();
42
45
  const auxiliary = await ensureAuxiliaryModelMigrationOnStartup();
43
46
  if (auxiliary)
44
47
  invalidateMigrationReadCache();
@@ -49,11 +52,18 @@ export async function prepareStartupConfig(recoverRoleMutations, onStep) {
49
52
  if (relationVersion)
50
53
  invalidateMigrationReadCache();
51
54
  return {
55
+ publishedSchemaConsolidationMigration: publishedSchemaConsolidation,
52
56
  auxiliaryModelMigration: auxiliary,
53
57
  agentOnlyModelMigration: agentOnly,
54
58
  relationVersionMigration: relationVersion,
55
59
  };
56
60
  });
61
+ if (publishedSchemaConsolidationMigration) {
62
+ const message = `✓ Published schema consolidation applied automatically: ${publishedSchemaConsolidationMigration.changedFiles} file(s) restamped`
63
+ + (publishedSchemaConsolidationMigration.backup ? `; backup: ${publishedSchemaConsolidationMigration.backup}` : '');
64
+ logger.info(message);
65
+ console.error(message);
66
+ }
57
67
  if (auxiliaryModelMigration) {
58
68
  const message = `✓ Session Renew auxiliary model migration applied automatically: ${auxiliaryModelMigration.changedFiles} file(s)`
59
69
  + (auxiliaryModelMigration.backup ? `; backup: ${auxiliaryModelMigration.backup}` : '');
@@ -1,11 +1,11 @@
1
1
  import path from 'path';
2
2
  import { kitsRoleTemplatesDir } from '../paths.js';
3
3
  import { createErrorCapturingReader, fileCache } from '../core/daemon-file-cache.js';
4
- import { normalizeRoleEffortCompat, validateRoleConfig } from './role-schema.js';
4
+ import { normalizeRoleEffortCompat, normalizeRoleGroupChatmodeCompat, validateRoleConfig } from './role-schema.js';
5
5
  import { expectedRoleRank } from './role-ranks.js';
6
6
  export const BUILTIN_ROLE_IDS = ['owner', 'admin', 'member', 'visitor'];
7
7
  export function validateBuiltinRoleTemplateDefinition(roleId, raw) {
8
- const normalizedRaw = normalizeRoleEffortCompat(raw);
8
+ const normalizedRaw = normalizeRoleGroupChatmodeCompat(normalizeRoleEffortCompat(raw));
9
9
  const issues = validateRoleConfig(normalizedRaw);
10
10
  if (issues.length) {
11
11
  return {
@@ -4,6 +4,7 @@ export { expectedRoleRank, ROLE_RANKS } from './role-ranks.js';
4
4
  export const BUILTIN_USER_ROLES = ['member', 'visitor'];
5
5
  export const MANAGEMENT_ROLES = ['owner', 'admin'];
6
6
  export const DAEMON_OWNER_ROLE = 'daemon-owner';
7
+ export const DEFAULT_PA_TEAM_ROLE = 'member';
7
8
  export function isManagementRole(role) {
8
9
  return role === 'owner' || role === 'admin';
9
10
  }
@@ -17,7 +18,7 @@ export function isReservedRoleName(role) {
17
18
  export function getBuiltinRolesConfig() {
18
19
  return {
19
20
  $schema_version: 1,
20
- defaultRoles: { private: null, group: null },
21
+ defaultRoles: { private: null, group: null, paTeam: DEFAULT_PA_TEAM_ROLE },
21
22
  roles: Object.fromEntries(BUILTIN_USER_ROLES.flatMap(roleId => {
22
23
  const definition = readBuiltinRoleTemplate(roleId).definition;
23
24
  return definition ? [[roleId, definition]] : [];
@@ -146,6 +146,8 @@ export function resolveConfigFieldRule(fieldPath, scope) {
146
146
  // 仅 agent-config 声明该字段,relation/defaults 由 schema 路由拒绝。
147
147
  if (field === 'baseagentSkills')
148
148
  return scalar(field, 'boolean', 'owner-only');
149
+ if (field === 'bootstrapWelcome')
150
+ return scalar(field, 'boolean', 'owner-only');
149
151
  if (field === 'ability')
150
152
  return readonlyObject('ability');
151
153
  if (field === 'ability.codeApproval.enabled')
@@ -321,6 +323,11 @@ export function parseConfigFieldValue(fieldPath, rawValue) {
321
323
  ? { ok: true, value: raw }
322
324
  : { ok: false, reason: `Config field ${fieldPath} must be one of ${[...EFFORTS].join(', ')}; use unset for auto` };
323
325
  case 'chatmode':
326
+ if (fieldPath.trim() === 'chatmode.group') {
327
+ return raw === 'proactive'
328
+ ? { ok: true, value: raw }
329
+ : { ok: false, reason: 'Config field chatmode.group is fixed to proactive' };
330
+ }
324
331
  return raw === 'interactive' || raw === 'proactive' || raw === 'paactive'
325
332
  ? { ok: true, value: raw }
326
333
  : { ok: false, reason: `Config field ${fieldPath} must be interactive, proactive, or paactive` };
@@ -28,6 +28,7 @@ import { normalizeAgentLifecycle } from './lifecycle.js';
28
28
  import { isAgentOnlyBaseagentField, isBehaviorConfigFieldPath } from './config-field-policy.js';
29
29
  import { clearRoleStoreCache, isRoleName } from './role-store.js';
30
30
  import { writeRoleDefinition, writeRoleRegistry } from './role-service.js';
31
+ import { normalizeRoleEffortCompat, normalizeRoleGroupChatmodeCompat } from './role-schema.js';
31
32
  import { mutatePeerBookTransactionSync, resolvePeerAidKind } from './peer-book-store.js';
32
33
  import { DAEMON_SCHEMA_NAME } from '../product.js';
33
34
  import { normalizeDaemonServices } from './daemon-services.js';
@@ -661,10 +662,12 @@ export function read(target, sel, opts = {}) {
661
662
  const normalized = target === ConfigTarget.Process
662
663
  ? normalizeProcessConfigCompat(normalizeDaemonServices(migrated))
663
664
  : target === ConfigTarget.Agent
664
- ? normalizeAgentConfigForRead(migrated, sel?.self)
665
+ ? normalizeGroupChatmodeCompat(normalizeAgentConfigForRead(migrated, sel?.self), 18)
665
666
  : target === ConfigTarget.Relation
666
- ? foldLegacyProactiveBlock(migrated)
667
- : migrated;
667
+ ? normalizeGroupChatmodeCompat(foldLegacyProactiveBlock(migrated), 11)
668
+ : target === ConfigTarget.Role
669
+ ? normalizeRoleGroupChatmodeCompat(normalizeRoleEffortCompat(migrated))
670
+ : migrated;
668
671
  // Agent read compatibility may move the legacy top-level `agents` block to
669
672
  // `baseagents`, so canonicalize effort after that structural migration.
670
673
  // config.json 不做 ${VAR} 展开:网关凭证与端点只在 providers.json,那里有独立展开实现。
@@ -879,6 +882,16 @@ function normalizeRelationConfigForWrite(value) {
879
882
  normalizeShowActivitiesCompat(mutable);
880
883
  return mutable;
881
884
  }
885
+ /** A version limit keeps schema-backed reads compatible only with published configs. */
886
+ function normalizeGroupChatmodeCompat(value, maxLegacyVersion) {
887
+ const version = value?.$schema_version;
888
+ if (maxLegacyVersion !== undefined && version !== undefined
889
+ && (typeof version !== 'number' || version > maxLegacyVersion))
890
+ return value;
891
+ if (value?.chatmode?.group !== 'interactive')
892
+ return value;
893
+ return { ...value, chatmode: { ...value.chatmode, group: 'proactive' } };
894
+ }
882
895
  function normalizeShowActivitiesCompat(value) {
883
896
  if (value.show_activities === true)
884
897
  value.show_activities = 'all';
@@ -1429,6 +1442,13 @@ export function validateConfigFile(target, sel) {
1429
1442
  catch (error) {
1430
1443
  return { exists: true, errors: [error instanceof Error ? error.message : String(error)] };
1431
1444
  }
1445
+ if ((target === ConfigTarget.Agent || target === ConfigTarget.Relation)
1446
+ && sanitized && typeof sanitized === 'object') {
1447
+ sanitized = normalizeGroupChatmodeCompat(sanitized, target === ConfigTarget.Agent ? 18 : 11);
1448
+ }
1449
+ if (target === ConfigTarget.Role) {
1450
+ sanitized = normalizeRoleGroupChatmodeCompat(normalizeRoleEffortCompat(sanitized));
1451
+ }
1432
1452
  return { exists: true, errors: validateConfig(target, sanitized) };
1433
1453
  }
1434
1454
  function fileCacheAvailable() {
@@ -1534,18 +1554,18 @@ function mergeBaseagentBlocks(layers) {
1534
1554
  * the normal agent/relation merge chain without leaking the compatibility
1535
1555
  * container itself into EffectiveAgentConfig.
1536
1556
  *
1537
- * Explicit canonical fields (if a future schema adds them) always win. A
1538
- * single default chat mode applies to the three peer categories because this
1539
- * compatibility field predates the per-category `chatmode` dictionary.
1557
+ * Explicit canonical fields (if a future schema adds them) always win.
1558
+ * Legacy default modes apply to private chats; group delivery is always proactive.
1540
1559
  */
1541
1560
  export function normalizeDefaultsBehaviorCompat(defaults) {
1542
- if (!defaults || !defaults.config || typeof defaults.config !== 'object' || Array.isArray(defaults.config))
1543
- return defaults;
1561
+ if (!defaults || !defaults.config || typeof defaults.config !== 'object' || Array.isArray(defaults.config)) {
1562
+ return defaults ? normalizeGroupChatmodeCompat(defaults) : defaults;
1563
+ }
1544
1564
  const { config, ...rest } = defaults;
1545
1565
  const normalized = { ...rest };
1546
1566
  const chatMode = config.chatMode;
1547
1567
  if (!normalized.chatmode && (chatMode === 'interactive' || chatMode === 'proactive')) {
1548
- normalized.chatmode = { private: chatMode, group: chatMode, nothuman: chatMode };
1568
+ normalized.chatmode = { private: chatMode, group: 'proactive', nothuman: chatMode };
1549
1569
  }
1550
1570
  else if (!normalized.chatmode && chatMode === 'paactive') {
1551
1571
  normalized.chatmode = { private: 'paactive', group: 'proactive', nothuman: 'proactive' };
@@ -1556,7 +1576,7 @@ export function normalizeDefaultsBehaviorCompat(defaults) {
1556
1576
  if (normalized.show_activities === undefined && ['all', 'text', 'none'].includes(config.show_activities)) {
1557
1577
  normalized.show_activities = config.show_activities;
1558
1578
  }
1559
- return normalized;
1579
+ return normalizeGroupChatmodeCompat(normalized);
1560
1580
  }
1561
1581
  function stripStaticOwnerField(config) {
1562
1582
  if (!config)
@@ -13,6 +13,8 @@ import { configuredOwnerList } from './owner-config.js';
13
13
  import { tryParseChannelKey } from '../core/channel-loader.js';
14
14
  import { isValidAid } from '../aun/aid/validation.js';
15
15
  import { getOwners, ownerResolver } from '../core/ownership/owner-resolver.js';
16
+ import { paTeamQualification, paTeamRevision, requiresPaTeamVerification } from '../core/relation/pa-team.js';
17
+ import { readRoleStore } from './role-store.js';
16
18
  export function isAuthenticated(userId) {
17
19
  return isValidAid(String(userId || '').trim());
18
20
  }
@@ -58,7 +60,8 @@ export function getFirstStaticAgentOwner(aid) {
58
60
  }
59
61
  /** Revision for security-sensitive owner/contact/relation authorization inputs. */
60
62
  export function authorizationConfigRevision(aid) {
61
- const fingerprints = [ownerResolver.revision(aid), fileRevision(agentConfig(aid)), fileRevision(agentPeerConfig(aid))];
63
+ const fingerprints = [ownerResolver.revision(aid), paTeamRevision(aid),
64
+ JSON.stringify(readRoleStore(aid)), fileRevision(agentConfig(aid)), fileRevision(agentPeerConfig(aid))];
62
65
  const relations = agentRelationsDir(aid);
63
66
  try {
64
67
  for (const entry of fs.readdirSync(relations, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
@@ -101,6 +104,25 @@ export function resolvePeerRoleDetail(ctx) {
101
104
  candidates.push({ role: 'owner', source: 'agent-owner', sourcePriority: 100 });
102
105
  }
103
106
  const actorRole = resolveActorDirectRole(ctx.selfAid, actor, channelType, operatorId);
107
+ if (channelType === 'aun' && ctx.chatType === 'private' && hasTrustedPrincipal(actor)
108
+ && (paTeamQualification(ctx.selfAid, actor.principalId) === 'matched'
109
+ || requiresPaTeamVerification(ctx.selfAid, actor.principalId))) {
110
+ const ownerCandidate = candidates.find(candidate => candidate.role === 'owner');
111
+ if (ownerCandidate)
112
+ return resultFor('owner', 'agent-owner', actor, ctx.selfAid);
113
+ const relation = read(ConfigTarget.Relation, { self: ctx.selfAid, peerKey: formatPeerKey('aun', actor.principalId) }, { cache: true });
114
+ if (relation?.role !== undefined && relation.role !== null) {
115
+ return resultFor(actorRole, 'relation-actor', actor, ctx.selfAid);
116
+ }
117
+ if (paTeamQualification(ctx.selfAid, actor.principalId) !== 'matched') {
118
+ return resultFor(null, 'none', actor, ctx.selfAid);
119
+ }
120
+ const store = readRoleStore(ctx.selfAid);
121
+ const valid = !store.diagnostics.some(diagnostic => diagnostic.code === 'INVALID_ROLE_REGISTRY'
122
+ || diagnostic.code === 'MISSING_ROLE_REGISTRY');
123
+ const role = valid ? normalizeDefaultRole(store.registry.defaultRoles.paTeam ?? 'member', ctx.selfAid) : null;
124
+ return resultFor(role, 'internal-contact-default', actor, ctx.selfAid);
125
+ }
104
126
  if (ctx.chatType === 'private') {
105
127
  if (actorRole)
106
128
  candidates.push({ role: actorRole, source: 'relation-actor', sourcePriority: 80 });
@@ -33,6 +33,30 @@ export function rolePermissionFields() {
33
33
  patterns: field.patterns?.map((pattern) => ({ ...pattern, kind: 'pattern' })),
34
34
  }));
35
35
  }
36
+ /** Read compatibility for published v1 policies; current policies validate strictly. */
37
+ export function normalizeRoleGroupChatmodeCompat(value) {
38
+ if (!isRecord(value) || !isRecord(value.permissions))
39
+ return value;
40
+ const version = value.$schema_version ?? 1;
41
+ if (version !== 1)
42
+ return value;
43
+ const group = value.permissions['chatmode.group'];
44
+ if (!isRecord(group))
45
+ return value;
46
+ return {
47
+ ...value,
48
+ permissions: {
49
+ ...value.permissions,
50
+ 'chatmode.group': {
51
+ ...group,
52
+ default: group.default === 'interactive' ? 'proactive' : group.default,
53
+ ...(Array.isArray(group.allowedValues) ? {
54
+ allowedValues: [...new Set(group.allowedValues.map(item => item === 'interactive' ? 'proactive' : item))],
55
+ } : {}),
56
+ },
57
+ },
58
+ };
59
+ }
36
60
  function isDescriptor(value) {
37
61
  if (!value || typeof value !== 'object')
38
62
  return false;
@@ -55,7 +79,7 @@ export function rolePermissionFieldPatterns(field) {
55
79
  }
56
80
  /** Shared RoleService/Menu validation backed by the published role schema. */
57
81
  export function validateRoleConfig(value) {
58
- const compatible = normalizeRoleEffortCompat(value);
82
+ const compatible = normalizeRoleGroupChatmodeCompat(normalizeRoleEffortCompat(value));
59
83
  const schema = loadSchema('role-config');
60
84
  const normalized = isRecord(compatible)
61
85
  && (!Object.hasOwn(compatible, '$schema_version') || compatible.$schema_version === 1)
@@ -5,7 +5,7 @@ import { agentRelationConfig, agentRelationsDir, agentRoleConfig, agentRolesInde
5
5
  import { registerFile, unregisterFile } from '../core/file-integrity/store.js';
6
6
  import { currentVersion, loadSchema } from './schema-registry.js';
7
7
  import { clearRoleStoreCache, getStoredRoleRegistry, isRoleName, readRoleStore, roleRegistryExists, } from './role-store.js';
8
- import { expectedRoleRank, isManagementRole } from './builtin-roles.js';
8
+ import { DEFAULT_PA_TEAM_ROLE, expectedRoleRank, isManagementRole } from './builtin-roles.js';
9
9
  import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
10
10
  import { normalizeRoleEffortCompat, validateRoleConfig } from './role-schema.js';
11
11
  export class RoleServiceError extends Error {
@@ -30,7 +30,7 @@ export function ensureInitialRoleRegistry(selfAid) {
30
30
  writeRoleRegistry(selfAid, {
31
31
  $schema_version: 1,
32
32
  roles: ['owner', 'admin', 'member', 'visitor'],
33
- defaultRoles: { private: null, group: null },
33
+ defaultRoles: { private: null, group: null, paTeam: DEFAULT_PA_TEAM_ROLE },
34
34
  });
35
35
  return true;
36
36
  }
@@ -125,8 +125,11 @@ export function unregisterRole(selfAid, roleId, replacementRoleId) {
125
125
  defaultRoles: {
126
126
  private: registry.defaultRoles.private === roleId ? (replacement ?? null) : registry.defaultRoles.private,
127
127
  group: registry.defaultRoles.group === roleId ? (replacement ?? null) : registry.defaultRoles.group,
128
+ paTeam: (registry.defaultRoles.paTeam ?? DEFAULT_PA_TEAM_ROLE) === roleId
129
+ ? (replacement ?? DEFAULT_PA_TEAM_ROLE) : registry.defaultRoles.paTeam,
128
130
  },
129
131
  };
132
+ validateRegistry(selfAid, nextRegistry);
130
133
  if (hasReplacement) {
131
134
  const relations = agentRelationsDir(selfAid);
132
135
  if (fs.existsSync(relations)) {
@@ -171,8 +174,8 @@ function validateRegistry(selfAid, value) {
171
174
  const registry = normalized;
172
175
  if (!registry.roles.includes('visitor'))
173
176
  throw new RoleServiceError('VISITOR_REQUIRED', 'visitor must remain registered');
174
- for (const role of ['private', 'group']) {
175
- const selected = registry.defaultRoles[role];
177
+ for (const role of ['private', 'group', 'paTeam']) {
178
+ const selected = role === 'paTeam' ? registry.defaultRoles.paTeam ?? DEFAULT_PA_TEAM_ROLE : registry.defaultRoles[role];
176
179
  if (selected !== null && (selected === 'owner' || !registry.roles.includes(selected))) {
177
180
  throw new RoleServiceError('INVALID_DEFAULT_ROLE', `defaultRoles.${role} must reference an assignable registered role`);
178
181
  }
@@ -203,6 +206,8 @@ function findRoleReferences(selfAid, roleId, registry) {
203
206
  references.push('defaultRoles.private');
204
207
  if (registry.defaultRoles.group === roleId)
205
208
  references.push('defaultRoles.group');
209
+ if ((registry.defaultRoles.paTeam ?? DEFAULT_PA_TEAM_ROLE) === roleId)
210
+ references.push('defaultRoles.paTeam');
206
211
  const relations = agentRelationsDir(selfAid);
207
212
  if (!fs.existsSync(relations))
208
213
  return references;
@@ -2,10 +2,10 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { atomicReadJson } from '../utils/atomic-write.js';
4
4
  import { agentRoleConfig, agentRolesDir, agentRolesIndex, kitsRoleTemplatesDir, resolvePaths, } from '../paths.js';
5
- import { applyManagementRoleCeiling, expectedRoleRank, getManagementRoleDefinition } from './builtin-roles.js';
5
+ import { applyManagementRoleCeiling, DEFAULT_PA_TEAM_ROLE, expectedRoleRank, getManagementRoleDefinition } from './builtin-roles.js';
6
6
  import { readBuiltinRoleTemplate } from './builtin-role-templates.js';
7
7
  import { loadSchema } from './schema-registry.js';
8
- import { normalizeRoleEffortCompat, validateRoleConfig } from './role-schema.js';
8
+ import { normalizeRoleEffortCompat, normalizeRoleGroupChatmodeCompat, validateRoleConfig } from './role-schema.js';
9
9
  const ROLE_NAME_RE = /^[a-z0-9_-]+$/;
10
10
  const BUILTIN_ROLES = ['owner', 'admin', 'member', 'visitor'];
11
11
  const cache = new Map();
@@ -88,6 +88,7 @@ export function roleIsAssignable(selfAid, roleId) {
88
88
  function readRegistry(selfAid, diagnostics) {
89
89
  const file = agentRolesIndex(selfAid);
90
90
  let raw;
91
+ let invalidPaTeam = false;
91
92
  try {
92
93
  raw = atomicReadJson(file);
93
94
  }
@@ -101,11 +102,30 @@ function readRegistry(selfAid, diagnostics) {
101
102
  }
102
103
  if (raw !== null) {
103
104
  const schema = loadSchema('role-registry');
105
+ if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
106
+ const record = raw;
107
+ if (record.defaultRoles && typeof record.defaultRoles === 'object' && !Array.isArray(record.defaultRoles)
108
+ && !schema.validate(raw)) {
109
+ const defaults = { ...record.defaultRoles };
110
+ if (Object.hasOwn(defaults, 'paTeam')) {
111
+ delete defaults.paTeam;
112
+ const compatible = { ...record, defaultRoles: defaults };
113
+ if (schema.validate(compatible)) {
114
+ diagnostics.push({ code: 'INVALID_ROLE_ASSIGNMENT', file: path.relative(resolvePaths().root, file),
115
+ message: 'defaultRoles.paTeam is invalid; PA team authorization is disabled' });
116
+ raw = compatible;
117
+ invalidPaTeam = true;
118
+ }
119
+ }
120
+ }
121
+ }
104
122
  if (schema.validate(raw)) {
105
123
  const value = raw;
106
124
  const roles = [...new Set(value.roles)];
107
- const defaultRoles = { ...value.defaultRoles };
108
- for (const scene of ['private', 'group']) {
125
+ const defaultRoles = { ...value.defaultRoles, paTeam: invalidPaTeam ? '' : value.defaultRoles.paTeam ?? DEFAULT_PA_TEAM_ROLE };
126
+ for (const scene of ['private', 'group', 'paTeam']) {
127
+ if (scene === 'paTeam' && invalidPaTeam)
128
+ continue;
109
129
  const selected = defaultRoles[scene];
110
130
  if (selected === null || (roles.includes(selected) && selected !== 'owner'))
111
131
  continue;
@@ -113,9 +133,11 @@ function readRegistry(selfAid, diagnostics) {
113
133
  code: 'INVALID_ROLE_ASSIGNMENT',
114
134
  roleId: selected,
115
135
  file: path.relative(resolvePaths().root, file),
116
- message: `defaultRoles.${scene} references invalid or unregistered role ${selected}; using ${scene === 'group' ? 'member' : 'visitor'} fallback`,
136
+ message: `defaultRoles.${scene} references invalid or unregistered role ${selected}; ${scene === 'paTeam'
137
+ ? 'PA team authorization is disabled' : `using ${scene === 'group' ? 'member' : 'visitor'} fallback`}`,
117
138
  });
118
- defaultRoles[scene] = null;
139
+ if (scene !== 'paTeam')
140
+ defaultRoles[scene] = null;
119
141
  }
120
142
  return { ...value, roles, defaultRoles };
121
143
  }
@@ -134,7 +156,7 @@ function readRegistry(selfAid, diagnostics) {
134
156
  return fallbackRegistry();
135
157
  }
136
158
  function fallbackRegistry() {
137
- return { $schema_version: 1, roles: [...BUILTIN_ROLES], defaultRoles: { private: null, group: null } };
159
+ return { $schema_version: 1, roles: [...BUILTIN_ROLES], defaultRoles: { private: null, group: null, paTeam: DEFAULT_PA_TEAM_ROLE } };
138
160
  }
139
161
  function readDefinition(selfAid, roleId, diagnostics) {
140
162
  const local = agentRoleConfig(selfAid, roleId);
@@ -154,7 +176,7 @@ function readDefinition(selfAid, roleId, diagnostics) {
154
176
  }
155
177
  if (raw === null)
156
178
  continue;
157
- const normalizedRaw = normalizeRoleEffortCompat(raw);
179
+ const normalizedRaw = normalizeRoleGroupChatmodeCompat(normalizeRoleEffortCompat(raw));
158
180
  const issues = validateRoleConfig(normalizedRaw);
159
181
  if (issues.length === 0) {
160
182
  const { $schema_version: _schemaVersion, ...definition } = normalizedRaw;