evolcore 0.0.50 → 0.0.51
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 +39 -2
- package/bin/ec-build.mjs +60 -0
- package/bin/ecmsg.js +65 -63
- package/dist/ability/caller/command.js +24 -15
- package/dist/ability/caller/contract.js +24 -9
- package/dist/ability/caller/credential-files.js +132 -0
- package/dist/ability/caller/daemon.js +32 -7
- package/dist/ability/caller/schema-view.js +157 -0
- package/dist/ability/caller/service.js +202 -63
- package/dist/ability/interop-v1.js +156 -113
- package/dist/agent-template/jobs.js +14 -110
- package/dist/agent-template/runtime.js +331 -193
- package/dist/agent-template/service.js +1029 -1104
- package/dist/agent-template/share.js +103 -0
- package/dist/agent-template/tool-runner.js +25 -0
- package/dist/agent-template/types.js +10 -3
- package/dist/agents/claude/availability.js +94 -0
- package/dist/agents/claude/capability-provider.js +154 -0
- package/dist/agents/claude/index.js +145 -0
- package/dist/agents/{claude-runner.js → claude/runner.js} +74 -158
- package/dist/agents/claude/session-file-adapter.js +246 -0
- package/dist/agents/codex/app-server-client.js +90 -10
- package/dist/agents/codex/availability.js +164 -0
- package/dist/agents/codex/capability-provider.js +138 -0
- package/dist/agents/codex/cli.js +38 -0
- package/dist/agents/codex/index.js +345 -0
- package/dist/agents/codex/mcp-elicitation.js +135 -0
- package/dist/agents/{codex-runner.js → codex/runner.js} +648 -382
- package/dist/agents/codex/session-file-adapter.js +834 -0
- package/dist/agents/dsh/availability.js +28 -0
- package/dist/agents/dsh/capability-provider.js +56 -0
- package/dist/agents/dsh/desktop-locations.ps1 +66 -0
- package/dist/agents/dsh/desktop-probe.cjs +37 -0
- package/dist/agents/dsh/index.js +98 -0
- package/dist/agents/dsh/installation.js +400 -0
- package/dist/agents/dsh/resources.js +755 -0
- package/dist/agents/dsh/runner.js +1183 -0
- package/dist/agents/dsh/runtime/README.md +243 -0
- package/dist/agents/dsh/runtime/authorization.js +23 -0
- package/dist/agents/dsh/runtime/bridge.js +837 -0
- package/dist/agents/dsh/runtime/config.js +271 -0
- package/dist/agents/dsh/runtime/entry.js +229 -0
- package/dist/agents/dsh/runtime/session-inspector.js +340 -0
- package/dist/agents/dsh/runtime/tool-policy.js +49 -0
- package/dist/agents/dsh/session-file-adapter.js +145 -0
- package/dist/agents/ecagent/index.js +215 -0
- package/dist/agents/{ecagent-runner.js → ecagent/runner.js} +592 -106
- package/dist/agents/ecagent/session-file-adapter.js +134 -0
- package/dist/agents/gemini/index.js +55 -10
- package/dist/agents/gemini/{gemini-runner.js → runner.js} +4 -9
- package/dist/aun/ability-device-routing.js +11 -17
- package/dist/aun/aid/agentmd.js +27 -1
- package/dist/aun/aid/managed-operation.js +6 -4
- package/dist/aun/group/invite-service.js +1 -1
- package/dist/aun/menu/client.js +1 -1
- package/dist/aun/msg/history.js +1 -1
- package/dist/aun/msg/managed-operation.js +93 -21
- package/dist/aun/msg/p2p.js +6 -6
- package/dist/aun/service-proxy.js +1 -1
- package/dist/aun/storage/index.js +242 -0
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +180 -43
- package/dist/channels/daemon.js +3 -2
- package/dist/channels/dingtalk.js +1 -1
- package/dist/channels/feishu.js +9 -9
- package/dist/channels/qqbot.js +1 -1
- package/dist/channels/wechat.js +2 -2
- package/dist/channels/wecom.js +1 -1
- package/dist/{agents/claude-gateway → claude-gateway}/agent-registration.js +13 -13
- package/dist/{agents/claude-gateway → claude-gateway}/binding.js +3 -3
- package/dist/{agents/claude-gateway → claude-gateway}/inbox.js +1 -1
- package/dist/{agents/claude-gateway → claude-gateway}/index.js +2 -2
- package/dist/{agents/claude-gateway → claude-gateway}/listing.js +3 -3
- package/dist/{agents/claude-gateway → claude-gateway}/router.js +4 -4
- package/dist/{agents/claude-gateway → claude-gateway}/sessions.js +2 -2
- package/dist/{agents/claude-gateway → claude-gateway}/terminal.js +1 -1
- package/dist/{agents/claude-gateway → claude-gateway}/transcript.js +1 -1
- package/dist/cli/ability-command.js +8 -5
- package/dist/cli/ability-output.js +182 -0
- package/dist/cli/agent-command.js +1 -1
- package/dist/cli/agent-create.js +123 -42
- package/dist/cli/agent-template.js +400 -29
- package/dist/cli/agent.js +14 -11
- package/dist/cli/aun-commands.js +167 -111
- package/dist/cli/daemon-commands.js +38 -8
- package/dist/cli/data-command.js +1 -1
- package/dist/cli/debug-mode.js +9 -0
- package/dist/cli/directory.js +1 -2
- package/dist/cli/ecmsg-gateway.js +55 -19
- package/dist/cli/fs-command.js +67 -39
- package/dist/cli/index.js +25 -11
- package/dist/cli/init.js +124 -29
- package/dist/cli/managed-command-guard.js +2 -0
- package/dist/cli/model.js +1 -1
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/services-command.js +24 -1
- package/dist/cli/skill-command.js +4 -4
- package/dist/cli/task-context.js +24 -14
- package/dist/cli/team-workspace-command.js +50 -52
- package/dist/cli/thread-command.js +3 -2
- package/dist/cli/trigger-command.js +47 -12
- package/dist/cli/watch-logs.js +2 -1
- package/dist/config/boot-log.js +3 -0
- package/dist/config/builtin-role-templates.js +1 -1
- package/dist/config/config-field-policy.js +10 -6
- package/dist/config/config-manager.js +33 -12
- package/dist/config/gateway-config.js +21 -37
- package/dist/config/invoke-ipc-service.js +1 -1
- package/dist/config/owner-config.js +5 -3
- package/dist/config/peer-book-store.js +2 -3
- package/dist/config/peer-book.js +2 -2
- package/dist/config/peer-role-resolver.js +2 -2
- package/dist/config/provider-identity-migration.js +24 -105
- package/dist/config/provider-ipc-service.js +13 -3
- package/dist/config/provider-local-sync.js +4 -1
- package/dist/config/provider-menu-request.js +21 -3
- package/dist/config/provider-templates.js +1 -1
- package/dist/config/providers-config.js +39 -15
- package/dist/config/providers-import.js +3 -3
- package/dist/config/providers-management.js +74 -99
- package/dist/config/schema-migration.js +177 -11
- package/dist/config/schema-registry.js +1 -1
- package/dist/config-store.js +38 -50
- package/dist/core/{agent-application-service.js → agent/agent-application-service.js} +9 -9
- package/dist/core/{agent-create-status.js → agent/agent-create-status.js} +112 -4
- package/dist/core/{agent-creation-claim.js → agent/agent-creation-claim.js} +3 -3
- package/dist/core/{agent-ipc-registration.js → agent/agent-ipc-registration.js} +102 -25
- package/dist/core/{agent-reload-coordinator.js → agent/agent-reload-coordinator.js} +61 -1
- package/dist/core/{agent-runtime.js → agent/agent-runtime.js} +53 -27
- package/dist/core/{evolagent-registry.js → agent/evolagent-registry.js} +12 -12
- package/dist/core/{evolagent.js → agent/evolagent.js} +11 -11
- package/dist/core/auth/agent-delegation.js +1 -8
- package/dist/core/auth/delegation-authorization.js +28 -0
- package/dist/core/auth/operation-authorizer.js +7 -4
- package/dist/core/auth/operation-catalog.js +34 -5
- package/dist/core/baseagent/baseagent-availability.js +197 -0
- package/dist/core/baseagent/baseagent-capability-adapter.js +288 -0
- package/dist/core/baseagent/baseagent-config-shared.js +56 -0
- package/dist/core/baseagent/baseagent-identity.js +68 -0
- package/dist/core/{baseagent-loader.js → baseagent/baseagent-loader.js} +62 -6
- package/dist/core/baseagent/baseagent-model-defaults.js +26 -0
- package/dist/{agents → core/baseagent}/baseagent-plugin-descriptor.js +107 -24
- package/dist/core/baseagent/baseagent-plugin-loader.js +367 -0
- package/dist/core/baseagent/baseagent.js +157 -0
- package/dist/{agents → core/baseagent}/runner-types.js +36 -4
- package/dist/core/capability/capability-manager.js +79 -30
- package/dist/core/capability/providers/claude-capability-provider.js +2 -154
- package/dist/core/capability/providers/codex-capability-provider.js +2 -136
- package/dist/core/{channel-loader.js → channel/channel-loader.js} +226 -38
- package/dist/core/{channel-runtime.js → channel/channel-runtime.js} +18 -18
- package/dist/core/command/agent-control.js +60 -15
- package/dist/core/command/agent-template-menu.js +21 -9
- package/dist/core/command/agentmd-menu-request.js +19 -8
- package/dist/core/command/agentmd-menu.js +14 -5
- package/dist/core/command/command-handler.js +127 -57
- package/dist/core/command/context-policy-menu.js +122 -0
- package/dist/core/command/data-root-resolver.js +157 -20
- package/dist/core/command/memory-slash.js +6 -6
- package/dist/core/command/menu-catalog.js +80 -20
- package/dist/core/command/menu-handler.js +305 -25
- package/dist/core/command/menu-protocol.js +42 -8
- package/dist/core/command/menu-query-batch.js +9 -5
- package/dist/core/command/provider-menu.js +7 -11
- package/dist/core/command/role-menu.js +1 -1
- package/dist/core/command/skill-slash.js +17 -5
- package/dist/core/command/slash-gate.js +2 -4
- package/dist/core/command/slash-handler.js +127 -96
- package/dist/core/command/team-workspace-team.js +3 -3
- package/dist/core/command/topic-slash.js +10 -10
- package/dist/core/{daemon-bootstrap.js → daemon/daemon-bootstrap.js} +14 -14
- package/dist/core/{daemon-control.js → daemon/daemon-control.js} +46 -20
- package/dist/core/{daemon-lifecycle.js → daemon/daemon-lifecycle.js} +15 -15
- package/dist/core/{host-snapshot.js → daemon/host-snapshot.js} +3 -3
- package/dist/core/{ipc-registration.js → daemon/ipc-registration.js} +98 -38
- package/dist/core/{lifecycle-notice.js → daemon/lifecycle-notice.js} +4 -5
- package/dist/core/file-integrity/store.js +1 -1
- package/dist/core/handoff/ipc-registration.js +3 -3
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/{agents → core/inference}/request-identity.js +2 -2
- package/dist/core/inference/text-inference.js +4 -4
- package/dist/core/{bootstrap-messages.js → initialization/bootstrap-messages.js} +10 -10
- package/dist/core/{bootstrap-service.js → initialization/bootstrap-service.js} +24 -23
- package/dist/core/initialization/service.js +54 -9
- package/dist/core/invoke/executors/media.js +1 -1
- package/dist/core/invoke/executors/text.js +1 -1
- package/dist/core/memory/consolidation-context.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +9 -3
- package/dist/core/memory/consolidation.js +4 -4
- package/dist/core/memory/memory-admin.js +6 -6
- package/dist/core/memory/memory-writer.js +1 -1
- package/dist/core/memory/relation-idle-monitor.js +1 -1
- package/dist/core/message/aun-ipc-sender.js +114 -75
- package/dist/core/message/aun-request-registry.js +13 -5
- package/dist/core/message/auto-mention-gate.js +1 -1
- package/dist/core/message/contact-admission.js +1 -1
- package/dist/core/message/im-renderer.js +19 -0
- package/dist/core/{interaction-router.js → message/interaction-router.js} +4 -4
- package/dist/core/message/items-formatter.js +5 -5
- package/dist/core/message/message-admission.js +1 -1
- package/dist/core/message/message-bridge.js +135 -54
- package/dist/core/message/message-queue.js +83 -4
- package/dist/core/message/message-utils.js +1 -1
- package/dist/core/message/peer-mode.js +1 -1
- package/dist/core/message/response-engine.js +347 -163
- package/dist/core/message/send-options.js +9 -6
- package/dist/core/message/send-routing.js +45 -109
- package/dist/core/message/stream-idle-monitor.js +1 -1
- package/dist/core/{data-migration.js → migration/data-migration.js} +29 -1
- package/dist/core/model/catalog-service.js +29 -8
- package/dist/core/model/model-capabilities.js +88 -0
- package/dist/core/model/model-catalog.js +14 -3
- package/dist/core/model/model-diagnostics.js +4 -4
- package/dist/core/ownership/owner-resolver.js +95 -15
- package/dist/core/{pack-auth.js → pack/pack-auth.js} +30 -3
- package/dist/core/{pack-install.js → pack/pack-install.js} +95 -17
- package/dist/core/permission/approval-gateway.js +9 -18
- package/dist/core/permission/ec-command-parser.js +70 -34
- package/dist/core/permission/managed-file.js +234 -0
- package/dist/core/permission/protected-paths.js +56 -0
- package/dist/core/permission/sandbox-runtime.js +267 -3
- package/dist/core/permission/session-path-grants.js +1 -1
- package/dist/core/permission/shell-environment.js +15 -1
- package/dist/core/plugin/plugin-lifecycle.js +442 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +2 -246
- package/dist/core/session/adapters/codex-session-file-adapter.js +2 -566
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +2 -134
- package/dist/core/{background-session → session/background}/session-cleanup.js +2 -2
- package/dist/core/{background-session → session/background}/types.js +1 -1
- package/dist/core/session/session-file-health.js +2 -272
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +29 -2
- package/dist/core/session/session-terminal.js +185 -0
- package/dist/core/session/session-title.js +8 -11
- package/dist/core/{system-session → session/system}/memory.js +43 -9
- package/dist/core/{system-session → session/system}/registry.js +1 -1
- package/dist/core/{system-session → session/system}/types.js +1 -1
- package/dist/core/skill/index-generator.js +1 -0
- package/dist/core/task/task-activity-store.js +112 -0
- package/dist/core/task/task-recovery-service.js +2 -2
- package/dist/core/thread/ipc-operation.js +2 -2
- package/dist/core/thread/thread-operation.js +2 -1
- package/dist/core/thread/thread-route.js +5 -3
- package/dist/core/thread/thread-service.js +14 -4
- package/dist/directory/{owner-directory-admission.js → admission.js} +3 -3
- package/dist/directory/{owner-directory-cache.js → cache.js} +90 -8
- package/dist/directory/{owner-directory-markdown.js → markdown.js} +2 -2
- package/dist/directory/{owner-directory-query-operation.js → query-operation.js} +83 -9
- package/dist/directory/{owner-directory-search.js → search.js} +50 -2
- package/dist/directory/{owner-directory-store.js → store.js} +2 -2
- package/dist/eck/kit-renderer.js +1 -1
- package/dist/eck/manifest-engine.js +64 -2
- package/dist/eck/message-renderer.js +35 -0
- package/dist/ecweb/basic-settings-service.js +9 -3
- package/dist/{contracts → ecweb/contracts}/ecweb-service-protocol.js +2 -1
- package/dist/ecweb/dsh-native-service.js +413 -0
- package/dist/ecweb/providers-service.js +1 -1
- package/dist/ecweb/runtime/lifecycle.js +1 -1
- package/dist/ecweb/runtime/supervisor.js +1 -1
- package/dist/event-center/center-config.js +2 -2
- package/dist/event-center/dispatcher.js +1 -1
- package/dist/event-center/ipc-operation.js +12 -3
- package/dist/event-center/pack-loader.js +2 -2
- package/dist/event-center/registry.js +6 -6
- package/dist/event-center/runtime.js +2 -2
- package/dist/index.js +71 -42
- package/dist/ipc.js +103 -10
- package/dist/outputs/authorization.js +27 -0
- package/dist/outputs/events.js +10 -1
- package/dist/outputs/panel-cards.js +960 -0
- package/dist/paths.js +12 -0
- package/dist/pay/command.js +1 -1
- package/dist/pay/runtime.js +18 -10
- package/dist/response-system/engines/v1/proactive-flow.js +1 -1
- package/dist/services/dispatcher.js +2 -2
- package/dist/services/host/main.js +10 -1
- package/dist/services/host/protocol.js +9 -2
- package/dist/services/host/resident.js +37 -0
- package/dist/services/host-client.js +12 -0
- package/dist/services/host-recycle.js +8 -3
- package/dist/services/host-runtime.js +54 -15
- package/dist/services/index.js +83 -19
- package/dist/services/ipc-operation.js +303 -38
- package/dist/services/pack-manager.js +2 -2
- package/dist/services/router.js +43 -3
- package/dist/services/script-runner.js +34 -25
- package/dist/services/service-payload.js +28 -1
- package/dist/services/validation.js +28 -2
- package/dist/stats/context-usage.js +110 -0
- package/dist/stats/model-resolver.js +103 -17
- package/dist/stats/query.js +5 -0
- package/dist/trigger/application-service.js +3 -2
- package/dist/trigger/authorization.js +36 -33
- package/dist/trigger/ipc-service.js +4 -4
- package/dist/trigger/local-files.js +8 -176
- package/dist/trigger/manager.js +2 -2
- package/dist/trigger/parser.js +48 -0
- package/dist/trigger/scheduler.js +14 -2
- package/dist/trigger/script-executor.js +21 -0
- package/dist/trigger/script-sandbox.js +57 -243
- package/dist/trigger/system-definitions.js +25 -0
- package/dist/trigger/validation.js +1 -1
- package/dist/utils/atomic-write.js +88 -1
- package/dist/utils/cross-platform.js +4 -42
- package/dist/utils/error-dict.json +22 -1
- package/dist/utils/error-utils.js +193 -6
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +1 -1
- package/dist/utils/logger.js +3 -1
- package/dist/utils/media-cache.js +99 -4
- package/dist/utils/startup-trace.js +20 -4
- package/dist/utils/welcome.js +64 -20
- package/ecagent/README.md +35 -0
- package/ecagent/dist/agent-loop.js +80 -30
- package/ecagent/dist/harness/env/nodejs.d.ts +16 -0
- package/ecagent/dist/harness/env/nodejs.js +49 -20
- package/ecagent/dist/harness/messages.js +3 -2
- package/ecagent/dist/harness/types.d.ts +1 -0
- package/ecagent/dist/runtime/types.d.ts +2 -0
- package/ecagent/dist/runtime/utils/validation.d.ts +7 -1
- package/ecagent/dist/runtime/utils/validation.js +42 -0
- package/ecagent/dist/types.d.ts +2 -0
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/channels/feishu.md +1 -1
- package/kits/docs/evolcore/INDEX.md +10 -7
- package/kits/docs/evolcore/agent-create.md +2 -0
- package/kits/docs/evolcore/agent.md +100 -13
- package/kits/docs/evolcore/aid.md +19 -3
- package/kits/docs/evolcore/config.md +94 -0
- package/kits/docs/evolcore/ctl.md +2 -1
- package/kits/docs/evolcore/ec-capabilities.md +7 -10
- package/kits/docs/evolcore/ecweb-lifecycle.md +5 -1
- package/kits/docs/evolcore/event.md +1 -1
- package/kits/docs/evolcore/fs.md +49 -3
- package/kits/docs/evolcore/group.md +3 -3
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +24 -2
- package/kits/docs/evolcore/model.md +9 -1
- package/kits/docs/evolcore/msg.md +30 -28
- package/kits/docs/evolcore/pay.md +8 -20
- package/kits/docs/evolcore/plugin.md +74 -0
- package/kits/docs/evolcore/provider.md +8 -2
- package/kits/docs/evolcore/rpc.md +2 -2
- package/kits/docs/evolcore/skill.md +17 -1
- package/kits/docs/evolcore/stats.md +5 -0
- package/kits/docs/evolcore/storage.md +22 -0
- package/kits/docs/evolcore/thread-chain.md +19 -10
- package/kits/docs/evolcore/tool-authorization.md +4 -0
- package/kits/docs/evolcore/trigger.md +89 -13
- package/kits/docs/identity/AID_PROFILE_SPEC.md +1 -1
- package/kits/docs/venues/feishu-group.md +3 -2
- package/kits/docs/venues/feishu-private.md +3 -2
- package/kits/rules/02-navigation.md +20 -13
- package/kits/rules/06-channel.md +18 -2
- package/kits/schemas/_meta.json +8 -4
- package/kits/schemas/agent-config.schema.23.json +19 -3
- package/kits/schemas/agent-config.schema.24.json +986 -0
- package/kits/schemas/agent-config.schema.25.json +986 -0
- package/kits/schemas/daemon.schema.11.json +487 -0
- package/kits/schemas/daemon.schema.12.json +505 -0
- package/kits/schemas/defaults.schema.8.json +484 -0
- package/kits/schemas/providers.schema.1.json +1 -1
- package/kits/schemas/providers.schema.2.json +1 -1
- package/kits/schemas/providers.schema.3.json +8 -2
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ability/SKILL.md +194 -27
- package/kits/skills/ability/STRUCTURE.md +5 -0
- package/kits/skills/agent-output-cards/SKILL.md +90 -54
- package/kits/skills/agent-output-cards/examples/html-surface.json +11 -0
- package/kits/skills/agent-output-cards/examples/meeting-followups.json +16 -0
- package/kits/skills/agent-output-cards/examples/meeting-latest.json +24 -0
- package/kits/skills/agent-output-cards/examples/project-metrics.json +16 -0
- package/kits/skills/agent-output-cards/examples/quick-links.json +18 -0
- package/kits/skills/agent-output-cards/examples/surface.html +8 -0
- package/kits/skills/agent-template-project/SKILL.md +51 -0
- package/kits/skills/agent-template-project/references/01-collect-and-pack.md +174 -0
- package/kits/skills/agent-template-project/references/02-upload-and-share.md +109 -0
- package/kits/skills/agent-template-project/references/03-download-and-install.md +189 -0
- package/kits/skills/agent-template-project/references/04-upgrade-and-recovery.md +74 -0
- package/kits/skills/agent-template-project/references/05-publish-to-platform.md +62 -0
- package/kits/skills/ec-group/SKILL.md +3 -3
- package/kits/skills/ec-group-collaboration/SKILL.md +4 -4
- package/kits/skills/ec-identity/SKILL.md +9 -6
- package/kits/skills/ec-pay/SKILL.md +163 -41
- package/kits/skills/ec-provider/SKILL.md +5 -5
- package/kits/skills/ec-service-call/SKILL.md +3 -0
- package/kits/skills/ec-skill/SKILL.md +25 -9
- package/kits/skills/ec-skill/scripts/cli.mjs +7 -7
- package/kits/skills/ec-skill/scripts/skill.mjs +55 -41
- package/kits/skills/ec-skill/scripts/template/SKILL.md.tmpl +9 -0
- package/kits/skills/ec-trigger/SKILL.md +2 -2
- package/kits/skills/personal-assistant/SKILL.md +22 -22
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +1 -1
- package/kits/skills/scrapling-article-fetch/SKILL.md +5 -5
- package/kits/skills/thread-ops/SKILL.md +19 -9
- package/kits/skills/wechat-article-media-download/SKILL.md +2 -2
- package/kits/skills/wechat-article-reader/SKILL.md +2 -2
- package/kits/templates/system-fragments/commands.md +1 -1
- package/kits/templates/system-fragments/personal-assistant.md +2 -2
- package/kits/templates/system-fragments/reply.md +14 -9
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +10 -5
- package/package.json +6 -5
- package/scripts/agent-template/index.mjs +7 -1
- package/scripts/agent-template/inspect.mjs +81 -35
- package/scripts/agent-template/overlay.mjs +110 -4
- package/scripts/agent-template/shared/common.mjs +36 -4
- package/scripts/agent-template/shared/plan.mjs +4 -2
- package/scripts/agent-template/shared/service-packs.mjs +104 -0
- package/scripts/agent-template/shared/team-schema.json +467 -54
- package/scripts/agent-template/shared/template-contract.mjs +70 -68
- package/scripts/agent-template/shared/template-package.mjs +153 -36
- package/scripts/agent-template/shared/template-runtime.mjs +76 -64
- package/scripts/agent-template/shared/template.mjs +11 -46
- package/scripts/agent-template/team-pack.mjs +451 -35
- package/scripts/agent-template/team-preview.mjs +75 -226
- package/scripts/aid-batch/identity-batch.mjs +1 -1
- package/dist/agents/baseagent-availability.js +0 -176
- package/dist/agents/baseagent-capability-adapter.js +0 -102
- package/dist/agents/baseagent-plugin-loader.js +0 -145
- package/dist/agents/baseagent.js +0 -816
- package/dist/agents/codex/catalog.js +0 -80
- package/dist/agents/ecagent-plugin-lazy.js +0 -41
- package/dist/agents/tool-time-context.js +0 -55
- package/dist/core/legacy-rename.js +0 -41
- package/dist/core/plugin-lifecycle.js +0 -137
- package/dist/core/rate-window.js +0 -53
- package/dist/core/runner-reload-transaction.js +0 -60
- package/dist/core/runtime-lock.js +0 -90
- package/dist/core/soul.js +0 -66
- package/dist/core/system-session/grants.js +0 -40
- package/dist/directory/owner-directory-agentmd-sync.js +0 -89
- package/dist/directory/owner-directory-request-operation.js +0 -79
- package/dist/directory/owner-directory-text.js +0 -60
- package/kits/skills/ec-pay/references/pay-cli.md +0 -110
- /package/dist/agents/gemini/{gemini-capability-provider.js → capability-provider.js} +0 -0
- /package/dist/agents/gemini/{gemini-session-file-adapter.js → session-file-adapter.js} +0 -0
- /package/dist/{agents/claude-gateway → claude-gateway}/types.js +0 -0
- /package/dist/core/{system-channels.js → channel/system-channels.js} +0 -0
- /package/dist/core/{daemon-file-cache.js → daemon/daemon-file-cache.js} +0 -0
- /package/dist/core/{event-bus.js → event/event-bus.js} +0 -0
- /package/dist/core/{event-catalog.js → event/event-catalog.js} +0 -0
- /package/dist/core/{pack-ledger.js → pack/pack-ledger.js} +0 -0
- /package/dist/directory/{owner-directory-identity.js → identity.js} +0 -0
- /package/dist/directory/{owner-directory-policy.js → policy.js} +0 -0
- /package/dist/directory/{owner-directory-remarks.js → remarks.js} +0 -0
- /package/dist/directory/{owner-directory-scope.js → scope.js} +0 -0
- /package/dist/{contracts → ecweb/contracts}/ecweb-instance.js +0 -0
- /package/kits/templates/{bootstrap-welcome.md → bootstrap-intro.md} +0 -0
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveBundledClaudeExecutable } from './availability.js';
|
|
2
|
+
export { resolveBundledClaudeExecutable, probeBundledClaudeVersion, probeBundledClaudeVersionAsync } from './availability.js';
|
|
3
|
+
import { assertRunnerModelAllowed, getRunnerCatalog, peekRunnerCatalog, catalogEfforts, resolveCatalogModel, assertCatalogSelectable } from '../../core/model/model-catalog.js';
|
|
2
4
|
import { spawn } from 'child_process';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { resolveProviderService } from '
|
|
7
|
-
import { buildModelRequestHeaders } from '
|
|
8
|
-
import { DEFAULT_PERMISSION_MODE } from '
|
|
9
|
-
import { renderActionAsText } from '
|
|
10
|
-
import { sessionTopicThreadId } from '
|
|
11
|
-
import { buildEnvelope, isInteractionSendAccepted, sendInteractionPayload } from '
|
|
5
|
+
import { ensureDir } from '../../utils/atomic-write.js';
|
|
6
|
+
import { resolveAnthropicConfig } from './index.js';
|
|
7
|
+
import { resolveRunInference } from '../../core/baseagent/runner-types.js';
|
|
8
|
+
import { resolveProviderService } from '../../config/providers.js';
|
|
9
|
+
import { buildModelRequestHeaders } from '../../core/inference/request-identity.js';
|
|
10
|
+
import { DEFAULT_PERMISSION_MODE } from '../../types.js';
|
|
11
|
+
import { renderActionAsText } from '../../core/message/interaction-router.js';
|
|
12
|
+
import { sessionTopicThreadId } from '../../core/thread/topic-id.js';
|
|
13
|
+
import { buildEnvelope, isInteractionSendAccepted, sendInteractionPayload } from '../../core/message/message-utils.js';
|
|
12
14
|
import path from 'path';
|
|
13
15
|
import fs from 'fs';
|
|
14
|
-
import { assertOwnershipAuthorization } from '
|
|
16
|
+
import { assertOwnershipAuthorization } from '../../core/ownership/owner-resolver.js';
|
|
15
17
|
import os from 'os';
|
|
16
18
|
import crypto from 'crypto';
|
|
17
|
-
import { logger } from '
|
|
18
|
-
import { resolveProjectDefaultPath } from '
|
|
19
|
-
import { createClaudeStartupArgumentsTooLongError, isClaudeStartupArgumentsTooLong, createClaudeCodeStartupError, isClaudeCodeStartupProcessError, } from '
|
|
20
|
-
import { requestDangerousCommandPermission } from '
|
|
21
|
-
import { checkBashDescription, checkDangerousCommand, checkReadonly, evaluateToolPreflight } from '
|
|
22
|
-
import { sanitizeShellExecutionEnvironment } from '
|
|
23
|
-
import { summarizeToolInput, summarizeToolInputForAudit } from '
|
|
24
|
-
import { renderToolTime } from '
|
|
25
|
-
import { encodePath
|
|
26
|
-
import { getPackageRoot, resolvePaths } from '
|
|
27
|
-
import { resolveEffective } from '
|
|
28
|
-
import { sanitizeSessionTitle } from '
|
|
29
|
-
import { resolveClaudeCapabilityRunOptionsForProject } from '
|
|
30
|
-
import { normalizeExecutionPermissionMode, normalizePermissionMode, resolvePhaseOneExecutionSandbox } from '
|
|
31
|
-
import { buildClaudeProtectedFilesystem, containsHClassReference, containsLClassReference, isHClassPath, isLClassPath, isSameOrDescendant, resolveProtectedCandidate, } from '
|
|
32
|
-
import { buildHClassGuardCommand, collectSandboxGuardDiagnostics, createSandboxInitializationError, createClaudeSandboxDependencyError, inspectClaudeSandboxDependencies, getActiveSandboxInitializationFailure, isSandboxInitializationFailure, isSandboxInitializationToolResult, recordSandboxInitializationFailure, getSandboxInitializationFailureCounters, SANDBOX_INITIALIZATION_COOLDOWN_MS, SANDBOX_INITIALIZATION_FAILED, ensureClaudeGitWorktreeConfig, prependExecutableDirectory, resolveBubblewrapPath, summarizeBubblewrapArgsForLog, summarizeSandboxGuardDiagnostics, shouldEnableClaudeWeakerNestedSandbox, shouldFailIfClaudeSandboxUnavailable, shouldLogSandboxCircuitNotice, } from '
|
|
33
|
-
import { buildClaudeUnixSocketAllowlist } from '
|
|
34
|
-
import { auditToolInfrastructureFailure, auditToolPreflightDenial } from '
|
|
35
|
-
import { getManagedTaskTempDir, isManagedSessionRuntimeDir } from '
|
|
36
|
-
import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext } from '
|
|
37
|
-
import { getGatewayPricing as getSharedGatewayPricing } from '
|
|
38
|
-
import { contextTokensForUsage, usageForContext, realContextWindowForModel } from '
|
|
39
|
-
import { CLAUDE_AUTO_COMPACT_MAX_TOKENS, CLAUDE_AUTO_COMPACT_MIN_TOKENS, resolveCatalogAutoCompactPolicy, resolveModelCapabilities, } from '
|
|
40
|
-
import { hasContextWindowSuffix } from '
|
|
41
|
-
const resolveModule = createRequire(import.meta.url);
|
|
19
|
+
import { logger } from '../../utils/logger.js';
|
|
20
|
+
import { resolveProjectDefaultPath } from '../../utils/project-path.js';
|
|
21
|
+
import { createClaudeStartupArgumentsTooLongError, isClaudeStartupArgumentsTooLong, createClaudeCodeStartupError, isClaudeCodeStartupProcessError, } from '../../utils/error-utils.js';
|
|
22
|
+
import { requestDangerousCommandPermission } from '../../core/permission/approval-gateway.js';
|
|
23
|
+
import { checkBashDescription, checkDangerousCommand, checkReadonly, evaluateToolPreflight } from '../../core/permission/tool-policy.js';
|
|
24
|
+
import { sanitizeShellExecutionEnvironment } from '../../core/permission/shell-environment.js';
|
|
25
|
+
import { summarizeToolInput, summarizeToolInputForAudit } from '../../utils/tool-summary.js';
|
|
26
|
+
import { renderToolTime } from '../../eck/message-renderer.js';
|
|
27
|
+
import { encodePath } from '../../utils/cross-platform.js';
|
|
28
|
+
import { getPackageRoot, resolvePaths } from '../../paths.js';
|
|
29
|
+
import { resolveEffective } from '../../config/config-manager.js';
|
|
30
|
+
import { sanitizeSessionTitle } from '../../core/session/session-title.js';
|
|
31
|
+
import { resolveClaudeCapabilityRunOptionsForProject } from '../../core/capability/capability-manager.js';
|
|
32
|
+
import { normalizeExecutionPermissionMode, normalizePermissionMode, resolvePhaseOneExecutionSandbox } from '../../core/permission/mode.js';
|
|
33
|
+
import { buildClaudeProtectedFilesystem, containsHClassReference, containsLClassReference, isHClassPath, isLClassPath, isSameOrDescendant, resolveProtectedCandidate, } from '../../core/permission/protected-paths.js';
|
|
34
|
+
import { buildHClassGuardCommand, collectSandboxGuardDiagnostics, createSandboxInitializationError, createClaudeSandboxDependencyError, inspectClaudeSandboxDependencies, getActiveSandboxInitializationFailure, isSandboxInitializationFailure, isSandboxInitializationToolResult, recordSandboxInitializationFailure, getSandboxInitializationFailureCounters, SANDBOX_INITIALIZATION_COOLDOWN_MS, SANDBOX_INITIALIZATION_FAILED, ensureClaudeGitWorktreeConfig, prependExecutableDirectory, resolveBubblewrapPath, summarizeBubblewrapArgsForLog, summarizeSandboxGuardDiagnostics, shouldEnableClaudeWeakerNestedSandbox, shouldFailIfClaudeSandboxUnavailable, shouldLogSandboxCircuitNotice, } from '../../core/permission/sandbox-runtime.js';
|
|
35
|
+
import { buildClaudeUnixSocketAllowlist } from '../../core/permission/unix-socket-policy.js';
|
|
36
|
+
import { auditToolInfrastructureFailure, auditToolPreflightDenial } from '../../core/auth/authorization-audit.js';
|
|
37
|
+
import { getManagedTaskTempDir, isManagedSessionRuntimeDir } from '../../cli/task-context.js';
|
|
38
|
+
import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext } from '../../core/baseagent/runner-types.js';
|
|
39
|
+
import { getGatewayPricing as getSharedGatewayPricing } from '../../stats/model-resolver.js';
|
|
40
|
+
import { contextTokensForUsage, usageForContext, realContextWindowForModel } from '../../core/baseagent/runner-types.js';
|
|
41
|
+
import { CLAUDE_AUTO_COMPACT_MAX_TOKENS, CLAUDE_AUTO_COMPACT_MIN_TOKENS, resolveCatalogAutoCompactPolicy, resolveModelCapabilities, readAgentCompactThreshold, resolveAgentContextPolicy } from '../../core/model/model-capabilities.js';
|
|
42
|
+
import { hasContextWindowSuffix } from '../../core/model/context-window-suffix.js';
|
|
42
43
|
const CLAUDE_INTERRUPT_TIMEOUT_MS = 5_000;
|
|
44
|
+
function applyConfiguredCompactEnv(env, window) {
|
|
45
|
+
if (window === undefined)
|
|
46
|
+
return env;
|
|
47
|
+
return { ...env, CLAUDE_CODE_AUTO_COMPACT_WINDOW: String(window), CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: undefined };
|
|
48
|
+
}
|
|
43
49
|
export function summarizeClaudeQueryOptions(options, context) {
|
|
44
50
|
const sha256 = (value) => crypto.createHash('sha256').update(value).digest('hex');
|
|
45
51
|
const rawBaseUrl = options.env?.ANTHROPIC_BASE_URL;
|
|
@@ -121,75 +127,7 @@ export function summarizeClaudeQueryOptions(options, context) {
|
|
|
121
127
|
nativeDebugOptionsEnabled: options.debug === true || !!options.debugFile,
|
|
122
128
|
};
|
|
123
129
|
}
|
|
124
|
-
|
|
125
|
-
* Resolve the platform package explicitly instead of relying on the SDK's
|
|
126
|
-
* internal optional-dependency lookup. The latter is sensitive to the module
|
|
127
|
-
* installation/loader context and can report a missing binary even when the
|
|
128
|
-
* package is present in the same node_modules tree.
|
|
129
|
-
*/
|
|
130
|
-
export function resolveBundledClaudeExecutable() {
|
|
131
|
-
if (process.platform !== 'win32')
|
|
132
|
-
return undefined;
|
|
133
|
-
const nativePackage = process.arch === 'arm64'
|
|
134
|
-
? '@anthropic-ai/claude-agent-sdk-win32-arm64'
|
|
135
|
-
: process.arch === 'x64'
|
|
136
|
-
? '@anthropic-ai/claude-agent-sdk-win32-x64'
|
|
137
|
-
: undefined;
|
|
138
|
-
if (!nativePackage)
|
|
139
|
-
return undefined;
|
|
140
|
-
const binarySpecifier = `${nativePackage}/claude.exe`;
|
|
141
|
-
try {
|
|
142
|
-
const executable = resolveModule.resolve(binarySpecifier);
|
|
143
|
-
if (fs.existsSync(executable))
|
|
144
|
-
return executable;
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
// Fall through to a direct sibling lookup for package layouts where the
|
|
148
|
-
// optional package does not expose its binary through exports.
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
const sdkEntry = resolveModule.resolve('@anthropic-ai/claude-agent-sdk');
|
|
152
|
-
const executable = path.resolve(path.dirname(sdkEntry), '..', '@anthropic-ai', nativePackage.slice('@anthropic-ai/'.length), 'claude.exe');
|
|
153
|
-
return fs.existsSync(executable) ? executable : undefined;
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 探测内置 claude.exe 的版本。检测层与执行层共用同一份二进制,所以这里探到的
|
|
161
|
-
* 版本就是会话真正会跑的那个版本,可与 SDK 锁定的 claudeCodeVersion 对照。
|
|
162
|
-
*/
|
|
163
|
-
export function probeBundledClaudeVersion() {
|
|
164
|
-
const executable = resolveBundledClaudeExecutable();
|
|
165
|
-
if (!executable)
|
|
166
|
-
return undefined;
|
|
167
|
-
try {
|
|
168
|
-
const raw = probeCliSync('bundled-claude', ['--version'], {
|
|
169
|
-
executable, validateOutput: output => /^\d+\.\d+\.\d+\b/.test(output.trim()),
|
|
170
|
-
});
|
|
171
|
-
return raw.trim().split(/\s+/)[0] || undefined;
|
|
172
|
-
}
|
|
173
|
-
catch {
|
|
174
|
-
return undefined;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/** Shares the installation-aware probe cache and in-flight request with other readers. */
|
|
178
|
-
export async function probeBundledClaudeVersionAsync() {
|
|
179
|
-
const executable = resolveBundledClaudeExecutable();
|
|
180
|
-
if (!executable)
|
|
181
|
-
return undefined;
|
|
182
|
-
try {
|
|
183
|
-
const raw = await probeCli('bundled-claude', ['--version'], {
|
|
184
|
-
executable, validateOutput: output => /^\d+\.\d+\.\d+\b/.test(output.trim()),
|
|
185
|
-
});
|
|
186
|
-
return raw.trim().split(/\s+/)[0] || undefined;
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return undefined;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
export { hasCompact, hasModelSwitcher, hasPermissionController } from './runner-types.js';
|
|
130
|
+
export { hasCompact, hasModelSwitcher, hasPermissionController } from '../../core/baseagent/runner-types.js';
|
|
193
131
|
// Built-in tools execute inside the Claude runtime and are covered by the
|
|
194
132
|
// runner's filesystem/shell policy. MCP and future unknown tools can perform
|
|
195
133
|
// side effects in another process or service, outside that sandbox, so they
|
|
@@ -475,17 +413,19 @@ function applyContextWindow(modelId, contextWindow) {
|
|
|
475
413
|
return `${modelId}[1m]`;
|
|
476
414
|
return modelId;
|
|
477
415
|
}
|
|
478
|
-
function resolveClaudeModelContext(modelId, catalog) {
|
|
416
|
+
function resolveClaudeModelContext(modelId, catalog, threshold) {
|
|
479
417
|
const capabilities = resolveModelCapabilities(resolvePaths().root, modelId, {
|
|
480
418
|
catalog,
|
|
481
419
|
fallbackContextWindow: realContextWindowForModel(modelId),
|
|
482
420
|
});
|
|
483
421
|
const policy = resolveCatalogAutoCompactPolicy(catalog, modelId);
|
|
484
422
|
const contextWindow = policy?.contextWindow ?? capabilities.contextWindow;
|
|
423
|
+
const explicit = threshold === undefined ? undefined : resolveAgentContextPolicy('claude', modelId, catalog, threshold);
|
|
485
424
|
return {
|
|
486
|
-
sdkModel: applyContextWindow(capabilities.model, contextWindow),
|
|
487
|
-
contextWindow,
|
|
488
|
-
autoCompactTokens: policy?.autoCompactTokens,
|
|
425
|
+
sdkModel: applyContextWindow(capabilities.model, explicit?.executionContextWindowTokens ?? contextWindow),
|
|
426
|
+
contextWindow: explicit?.executionContextWindowTokens ?? contextWindow,
|
|
427
|
+
autoCompactTokens: explicit?.effectiveAutoCompactThresholdTokens ?? policy?.autoCompactTokens,
|
|
428
|
+
nativeAutoCompactWindow: explicit?.claudeAutoCompactWindowTokens ?? policy?.autoCompactTokens,
|
|
489
429
|
};
|
|
490
430
|
}
|
|
491
431
|
class MessageStream {
|
|
@@ -542,7 +482,7 @@ class MessageStream {
|
|
|
542
482
|
}
|
|
543
483
|
export class AgentRunner {
|
|
544
484
|
name = 'claude';
|
|
545
|
-
capabilities = { taskRecovery: true, fullaccess: true,
|
|
485
|
+
capabilities = { taskRecovery: true, fullaccess: true, compact: true, fork: true, forkAtTurn: true, forkAtMessage: true, askUserQuestion: true, planApproval: true, fileRewind: 'checkpoint' };
|
|
546
486
|
apiKey;
|
|
547
487
|
model;
|
|
548
488
|
effort;
|
|
@@ -1355,7 +1295,7 @@ export class AgentRunner {
|
|
|
1355
1295
|
if (files.length > 0) {
|
|
1356
1296
|
const planContent = fs.readFileSync(path.join(plansDir, files[0].name), 'utf-8');
|
|
1357
1297
|
if (planContent.trim()) {
|
|
1358
|
-
await sendPrompt(
|
|
1298
|
+
await sendPrompt(`**计划内容**\n\n${planContent}`);
|
|
1359
1299
|
}
|
|
1360
1300
|
}
|
|
1361
1301
|
}
|
|
@@ -1369,7 +1309,7 @@ export class AgentRunner {
|
|
|
1369
1309
|
id: requestId,
|
|
1370
1310
|
kind: {
|
|
1371
1311
|
kind: 'action',
|
|
1372
|
-
title: '
|
|
1312
|
+
title: '计划审批',
|
|
1373
1313
|
body: 'AI 已完成规划,等待审批。\n请查看以上计划内容后决定。',
|
|
1374
1314
|
buttons: [
|
|
1375
1315
|
{ key: 'approve', label: '✅ 批准执行', style: 'primary' },
|
|
@@ -1396,7 +1336,7 @@ export class AgentRunner {
|
|
|
1396
1336
|
chatmode: permCtx.chatmode,
|
|
1397
1337
|
replyContext: permCtx.replyContext,
|
|
1398
1338
|
});
|
|
1399
|
-
const fallbackText = '
|
|
1339
|
+
const fallbackText = '计划审批:AI 已完成规划,等待审批。\n回复 /ask 1 批准 / /ask 2 拒绝';
|
|
1400
1340
|
const result = await sendInteractionPayload(permCtx.adapter, envelope, interaction, fallbackText, permCtx.replyContext);
|
|
1401
1341
|
cardSent = isInteractionSendAccepted(result);
|
|
1402
1342
|
}
|
|
@@ -1420,7 +1360,7 @@ export class AgentRunner {
|
|
|
1420
1360
|
blocking: true,
|
|
1421
1361
|
kind: {
|
|
1422
1362
|
kind: 'action',
|
|
1423
|
-
title: '
|
|
1363
|
+
title: '计划审批',
|
|
1424
1364
|
body: 'AI 已完成规划,等待审批。',
|
|
1425
1365
|
buttons: [
|
|
1426
1366
|
{ key: 'approve', label: '✅ 批准执行', style: 'primary' },
|
|
@@ -1501,7 +1441,7 @@ export class AgentRunner {
|
|
|
1501
1441
|
? event.event.message
|
|
1502
1442
|
: undefined;
|
|
1503
1443
|
if (responseMessage) {
|
|
1504
|
-
logger.
|
|
1444
|
+
logger.debug('[ClaudeResponseDiagnostic]', JSON.stringify({
|
|
1505
1445
|
type: 'claude_sdk_response',
|
|
1506
1446
|
evidence: 'sdk_response',
|
|
1507
1447
|
wireRequestCaptured: false,
|
|
@@ -2079,6 +2019,7 @@ export class AgentRunner {
|
|
|
2079
2019
|
}
|
|
2080
2020
|
}
|
|
2081
2021
|
async runQuery(sessionId, prompt, projectPath, initialClaudeSessionId, images, systemPromptAppend, sessionManager, modelOverride, runtimeEnv) {
|
|
2022
|
+
const inference = resolveRunInference('claude', modelOverride?.inference);
|
|
2082
2023
|
// Validate the daemon-injected session namespace before the SDK inherits
|
|
2083
2024
|
// the process environment for any temporary state.
|
|
2084
2025
|
getManagedTaskTempDir(runtimeEnv);
|
|
@@ -2780,8 +2721,14 @@ export class AgentRunner {
|
|
|
2780
2721
|
logger.info(`[AgentRunner] systemPromptAppend: none`);
|
|
2781
2722
|
}
|
|
2782
2723
|
const catalogModel = resolveCatalogModel(runCatalog, callModel);
|
|
2783
|
-
const
|
|
2784
|
-
const
|
|
2724
|
+
const configuredThreshold = readAgentCompactThreshold(this.agentAid, 'claude');
|
|
2725
|
+
const { sdkModel, contextWindow, autoCompactTokens, nativeAutoCompactWindow } = resolveClaudeModelContext(catalogModel, runCatalog, configuredThreshold);
|
|
2726
|
+
if (configuredThreshold !== undefined)
|
|
2727
|
+
logger.info(`[AgentRunner] Context policy: ${JSON.stringify(resolveAgentContextPolicy('claude', catalogModel, runCatalog, configuredThreshold))}`);
|
|
2728
|
+
const agentEnv = applyConfiguredCompactEnv(this.getAgentEnv(runtimeEnv, sessionId, callPermissionMode, modelOverride?.provider), configuredThreshold === undefined ? undefined : nativeAutoCompactWindow);
|
|
2729
|
+
if (inference.maxOutputTokens !== undefined) {
|
|
2730
|
+
agentEnv.CLAUDE_CODE_MAX_OUTPUT_TOKENS = String(inference.maxOutputTokens);
|
|
2731
|
+
}
|
|
2785
2732
|
const dependencies = executionSandbox.state !== 'off' && !sandboxFallback
|
|
2786
2733
|
? inspectClaudeSandboxDependencies(agentEnv)
|
|
2787
2734
|
: undefined;
|
|
@@ -2883,10 +2830,10 @@ export class AgentRunner {
|
|
|
2883
2830
|
&& callPermissionMode !== 'fullaccess' && process.platform === 'linux' ? {
|
|
2884
2831
|
spawnClaudeCodeProcess: (options) => spawnClaudeWithHClassGuard(options, resolvePaths().root, handleClaudeStderr, runPermissionContext?.selfAid ?? this.agentAid),
|
|
2885
2832
|
} : {}),
|
|
2886
|
-
...(
|
|
2833
|
+
...(nativeAutoCompactWindow !== undefined && nativeAutoCompactWindow >= CLAUDE_AUTO_COMPACT_MIN_TOKENS ? {
|
|
2887
2834
|
extraArgs: {
|
|
2888
2835
|
...capabilityExtraArgs,
|
|
2889
|
-
autocompact: String(Math.min(
|
|
2836
|
+
autocompact: String(Math.min(nativeAutoCompactWindow, CLAUDE_AUTO_COMPACT_MAX_TOKENS)),
|
|
2890
2837
|
},
|
|
2891
2838
|
} : {}),
|
|
2892
2839
|
advisorModel: 'haiku',
|
|
@@ -2934,7 +2881,7 @@ export class AgentRunner {
|
|
|
2934
2881
|
}
|
|
2935
2882
|
}
|
|
2936
2883
|
const logQueryOptions = (options) => {
|
|
2937
|
-
logger.
|
|
2884
|
+
logger.debug('[ClaudeQueryDiagnostic]', JSON.stringify(summarizeClaudeQueryOptions(options, {
|
|
2938
2885
|
sessionId,
|
|
2939
2886
|
inputId,
|
|
2940
2887
|
taskId: modelOverride?.turn?.taskId ?? runPermissionContext?.taskId,
|
|
@@ -3385,6 +3332,7 @@ export class AgentRunner {
|
|
|
3385
3332
|
});
|
|
3386
3333
|
}
|
|
3387
3334
|
async runSessionCommand(prompt, agentSessionId, projectPath, modelOverride, useModel = true) {
|
|
3335
|
+
const inference = resolveRunInference('claude', modelOverride?.inference);
|
|
3388
3336
|
const callModel = modelOverride?.model || (useModel ? this.model : undefined);
|
|
3389
3337
|
const callEffort = (modelOverride?.effortMode === 'model_default'
|
|
3390
3338
|
? undefined
|
|
@@ -3396,8 +3344,9 @@ export class AgentRunner {
|
|
|
3396
3344
|
await assertRunnerModelAllowed('claude', callModel, { providerId: modelOverride?.provider ?? this.catalogConnection().providerId });
|
|
3397
3345
|
if (catalog)
|
|
3398
3346
|
assertCatalogSelectable(catalog);
|
|
3347
|
+
const configuredThreshold = readAgentCompactThreshold(this.agentAid, 'claude');
|
|
3399
3348
|
const resolvedModel = catalog && callModel
|
|
3400
|
-
? resolveClaudeModelContext(resolveCatalogModel(catalog, callModel), catalog)
|
|
3349
|
+
? resolveClaudeModelContext(resolveCatalogModel(catalog, callModel), catalog, configuredThreshold)
|
|
3401
3350
|
: undefined;
|
|
3402
3351
|
const { query } = await import('@anthropic-ai/claude-agent-sdk');
|
|
3403
3352
|
return query({
|
|
@@ -3405,6 +3354,8 @@ export class AgentRunner {
|
|
|
3405
3354
|
options: {
|
|
3406
3355
|
cwd: projectPath,
|
|
3407
3356
|
...(resolvedModel ? { model: resolvedModel.sdkModel } : {}),
|
|
3357
|
+
...(configuredThreshold !== undefined && resolvedModel?.nativeAutoCompactWindow !== undefined
|
|
3358
|
+
? { extraArgs: { autocompact: String(resolvedModel.nativeAutoCompactWindow) } } : {}),
|
|
3408
3359
|
resume: agentSessionId,
|
|
3409
3360
|
maxTurns: 1,
|
|
3410
3361
|
tools: [],
|
|
@@ -3415,7 +3366,8 @@ export class AgentRunner {
|
|
|
3415
3366
|
managedSettings: buildClaudeManagedLockdownSettings(),
|
|
3416
3367
|
...(catalog && callEffort ? { effort: callEffort } : {}),
|
|
3417
3368
|
permissionMode: this.toSdkPermissionMode(),
|
|
3418
|
-
env: this.getAgentEnv(),
|
|
3369
|
+
env: applyConfiguredCompactEnv({ ...(configuredThreshold === undefined ? this.getAgentEnv() : this.getAgentEnv(undefined, undefined, undefined, modelOverride?.provider)),
|
|
3370
|
+
...(inference.maxOutputTokens !== undefined ? { CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(inference.maxOutputTokens) } : {}) }, configuredThreshold === undefined ? undefined : resolvedModel?.nativeAutoCompactWindow),
|
|
3419
3371
|
...(this.claudeExecutablePath
|
|
3420
3372
|
? { pathToClaudeCodeExecutable: this.claudeExecutablePath }
|
|
3421
3373
|
: {})
|
|
@@ -3495,42 +3447,6 @@ export class AgentRunner {
|
|
|
3495
3447
|
return result;
|
|
3496
3448
|
}
|
|
3497
3449
|
}
|
|
3498
|
-
/**
|
|
3499
|
-
* 通过 SDK /clear 命令清空会话历史
|
|
3500
|
-
*/
|
|
3501
|
-
async clearSession(sessionId, agentSessionId, projectPath) {
|
|
3502
|
-
try {
|
|
3503
|
-
logger.info(`[AgentRunner] Clearing session via SDK: ${agentSessionId}`);
|
|
3504
|
-
// Clearing is a backend lifecycle operation. It does not depend on any
|
|
3505
|
-
// Session model or model configuration/selection.
|
|
3506
|
-
const stream = await this.runSessionCommand('/clear', agentSessionId, projectPath, undefined, false);
|
|
3507
|
-
this.activeStreams.set(sessionId, stream);
|
|
3508
|
-
try {
|
|
3509
|
-
let cleared = false;
|
|
3510
|
-
for await (const event of stream) {
|
|
3511
|
-
logger.debug(`[AgentRunner] Clear event: type=${event.type}, subtype=${event.subtype || 'none'}`);
|
|
3512
|
-
if (event.session_id && event.session_id !== agentSessionId) {
|
|
3513
|
-
cleared = true;
|
|
3514
|
-
}
|
|
3515
|
-
}
|
|
3516
|
-
if (cleared) {
|
|
3517
|
-
this.activeSessions.delete(sessionId);
|
|
3518
|
-
await this.onSessionIdUpdate?.(sessionId, '');
|
|
3519
|
-
}
|
|
3520
|
-
else {
|
|
3521
|
-
logger.warn('[AgentRunner] Clear stream ended without session reset signal');
|
|
3522
|
-
}
|
|
3523
|
-
return cleared;
|
|
3524
|
-
}
|
|
3525
|
-
finally {
|
|
3526
|
-
this.activeStreams.delete(sessionId);
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3529
|
-
catch (error) {
|
|
3530
|
-
logger.error('[AgentRunner] Clear session failed:', error);
|
|
3531
|
-
return false;
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
3450
|
async closeSession(sessionId) {
|
|
3535
3451
|
const capturedAgentSessionId = this.activeSessions.get(sessionId);
|
|
3536
3452
|
const capturedPermissionContext = this.permissionContexts.get(sessionId);
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude SessionFileAdapter
|
|
3
|
+
*
|
|
4
|
+
* Reads Claude Agent SDK session files from ~/.claude/projects/{encodedPath}/{sessionId}.jsonl
|
|
5
|
+
* and wraps sdkListSessions for name synchronization.
|
|
6
|
+
*/
|
|
7
|
+
import { encodePath } from '../../utils/cross-platform.js';
|
|
8
|
+
import { logger } from '../../utils/logger.js';
|
|
9
|
+
import { buildCliSessionPreview } from '../../core/session/session-title.js';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import fs from 'fs';
|
|
12
|
+
import os from 'os';
|
|
13
|
+
import { visitSessionHistory } from '../../core/session/session-fs-store.js';
|
|
14
|
+
/** One SDK query seam for managed-session adapters and the local terminal gateway. */
|
|
15
|
+
export async function listClaudeSdkSessions(options) {
|
|
16
|
+
const { listSessions } = await import('@anthropic-ai/claude-agent-sdk');
|
|
17
|
+
return listSessions(options);
|
|
18
|
+
}
|
|
19
|
+
export class ClaudeSessionFileAdapter {
|
|
20
|
+
baseagent = 'claude';
|
|
21
|
+
getSessionFilePath(projectPath, agentSessionId) {
|
|
22
|
+
const homeDir = os.homedir();
|
|
23
|
+
const encodedPath = encodePath(projectPath);
|
|
24
|
+
return path.join(homeDir, '.claude', 'projects', encodedPath, `${agentSessionId}.jsonl`);
|
|
25
|
+
}
|
|
26
|
+
checkExists(projectPath, agentSessionId) {
|
|
27
|
+
const sessionFile = this.getSessionFilePath(projectPath, agentSessionId);
|
|
28
|
+
return fs.existsSync(sessionFile);
|
|
29
|
+
}
|
|
30
|
+
getFileInfo(projectPath, agentSessionId) {
|
|
31
|
+
const sessionFile = this.getSessionFilePath(projectPath, agentSessionId);
|
|
32
|
+
if (!fs.existsSync(sessionFile))
|
|
33
|
+
return { turns: 0 };
|
|
34
|
+
try {
|
|
35
|
+
const content = fs.readFileSync(sessionFile, 'utf-8');
|
|
36
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
37
|
+
let turns = 0;
|
|
38
|
+
let title;
|
|
39
|
+
for (const line of lines) {
|
|
40
|
+
const event = JSON.parse(line);
|
|
41
|
+
if (event.type === 'user' && event.message?.role === 'user') {
|
|
42
|
+
const msgContent = event.message.content;
|
|
43
|
+
const isToolResult = Array.isArray(msgContent) && msgContent.every((c) => c.type === 'tool_result');
|
|
44
|
+
if (!isToolResult) {
|
|
45
|
+
turns++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (event.title && !title) {
|
|
49
|
+
title = event.title;
|
|
50
|
+
}
|
|
51
|
+
if (event.sessionTitle && !title) {
|
|
52
|
+
title = event.sessionTitle;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { turns, title };
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.warn(`[ClaudeAdapter] Failed to read session file info: ${sessionFile}`, error);
|
|
59
|
+
return { turns: 0 };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
readFirstMessage(projectPath, agentSessionId) {
|
|
63
|
+
const sessionFile = this.getSessionFilePath(projectPath, agentSessionId);
|
|
64
|
+
if (!fs.existsSync(sessionFile))
|
|
65
|
+
return null;
|
|
66
|
+
return this.readSessionPreview(sessionFile).title;
|
|
67
|
+
}
|
|
68
|
+
async readMenuSummary(projectPath, agentSessionId) {
|
|
69
|
+
let turns = 0;
|
|
70
|
+
let validInfo = true;
|
|
71
|
+
const messages = [];
|
|
72
|
+
try {
|
|
73
|
+
await visitSessionHistory(this.getSessionFilePath(projectPath, agentSessionId), event => {
|
|
74
|
+
if (event?.type !== 'user' || event.message?.role !== 'user')
|
|
75
|
+
return;
|
|
76
|
+
const content = event.message.content;
|
|
77
|
+
if (!(Array.isArray(content) && content.every((part) => part.type === 'tool_result')))
|
|
78
|
+
turns++;
|
|
79
|
+
const text = this.extractRawUserText(content);
|
|
80
|
+
if (text)
|
|
81
|
+
messages.push(text);
|
|
82
|
+
}, () => { validInfo = false; });
|
|
83
|
+
return { turns: validInfo ? turns : 0, firstMessage: buildCliSessionPreview(messages, 'claude').title };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error.code !== 'ENOENT')
|
|
87
|
+
logger.warn('[ClaudeAdapter] Failed to read menu summary', error);
|
|
88
|
+
return { turns: 0, firstMessage: null };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 单遍扫描会话文件,返回预览标题及是否含真人消息。
|
|
93
|
+
* - title:第一条真人消息(跳过脚手架 prompt);全是脚手架时退回首条脚手架文本作兜底
|
|
94
|
+
* - hasReal:是否存在至少一条真人 user 消息(非 tool_result、非脚手架 prompt)
|
|
95
|
+
* 读失败时 title=null、hasReal=true(保守放行,避免误杀正常会话)。
|
|
96
|
+
*/
|
|
97
|
+
readSessionPreview(sessionFile) {
|
|
98
|
+
try {
|
|
99
|
+
const content = fs.readFileSync(sessionFile, 'utf-8');
|
|
100
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
101
|
+
const messages = [];
|
|
102
|
+
for (const line of lines) {
|
|
103
|
+
let event;
|
|
104
|
+
try {
|
|
105
|
+
event = JSON.parse(line);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (event.type === 'user' && event.message?.role === 'user') {
|
|
111
|
+
const raw = this.extractRawUserText(event.message.content);
|
|
112
|
+
if (!raw)
|
|
113
|
+
continue;
|
|
114
|
+
messages.push(raw);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return buildCliSessionPreview(messages, 'claude');
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
logger.warn(`[ClaudeAdapter] Failed to read session file: ${sessionFile}`, error);
|
|
121
|
+
return { title: null, hasReal: true };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
readLastUserMessage(projectPath, agentSessionId) {
|
|
125
|
+
const sessionFile = this.getSessionFilePath(projectPath, agentSessionId);
|
|
126
|
+
if (!fs.existsSync(sessionFile))
|
|
127
|
+
return null;
|
|
128
|
+
try {
|
|
129
|
+
const content = fs.readFileSync(sessionFile, 'utf-8');
|
|
130
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
131
|
+
let lastMessage = null;
|
|
132
|
+
for (const line of lines) {
|
|
133
|
+
const event = JSON.parse(line);
|
|
134
|
+
if (event.type === 'user' && event.message?.role === 'user') {
|
|
135
|
+
lastMessage = this.extractUserMessageText(event.message.content) ?? lastMessage;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return lastMessage;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
logger.warn(`[ClaudeAdapter] Failed to read last message from session file: ${sessionFile}`, error);
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
// CLI 会话白名单:只有真正由人手发起的终端会话才值得导入。
|
|
146
|
+
// 其它 entrypoint(sdk-ts=EvolCore 自身、sdk-py=security-guidance 等插件的后台 SDK 会话)
|
|
147
|
+
// 同样把 JSONL 写进项目目录,但不是用户会话,导入它们没有意义。
|
|
148
|
+
static CLI_ENTRYPOINTS = new Set(['cli', 'sdk-cli']);
|
|
149
|
+
// entrypoint 不可变,进程内缓存 filePath→entrypoint,避免重复读文件头部
|
|
150
|
+
entrypointCache = new Map();
|
|
151
|
+
// entrypoint 字段位于首个 user 事件行(实测恒在前 4 行内,cli 会话首次出现 < 8KB)。
|
|
152
|
+
// 插件会话首行 queue-operation 可能携带巨大 diff(数百 KB),把 entrypoint 推到很后面,
|
|
153
|
+
// 因此读取上限设为 32KB:cli 会话必命中,插件会话要么命中 sdk-py、要么读不到 → 一律排除。
|
|
154
|
+
static ENTRYPOINT_SCAN_BYTES = 32 * 1024;
|
|
155
|
+
/** 读取会话文件的 entrypoint,结果缓存在实例内(entrypoint 不可变,无需失效)。 */
|
|
156
|
+
readEntrypoint(filePath) {
|
|
157
|
+
if (this.entrypointCache.has(filePath))
|
|
158
|
+
return this.entrypointCache.get(filePath);
|
|
159
|
+
let fd;
|
|
160
|
+
let result = null;
|
|
161
|
+
try {
|
|
162
|
+
fd = fs.openSync(filePath, 'r');
|
|
163
|
+
const buf = Buffer.allocUnsafe(ClaudeSessionFileAdapter.ENTRYPOINT_SCAN_BYTES);
|
|
164
|
+
const bytesRead = fs.readSync(fd, buf, 0, buf.length, 0);
|
|
165
|
+
const head = buf.toString('utf-8', 0, bytesRead);
|
|
166
|
+
const m = head.match(/"entrypoint":"([^"]*)"/);
|
|
167
|
+
result = m ? m[1] : null;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// keep null
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
if (fd !== undefined)
|
|
174
|
+
fs.closeSync(fd);
|
|
175
|
+
}
|
|
176
|
+
this.entrypointCache.set(filePath, result);
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
scanCliSessions(projectPath, limit = 10) {
|
|
180
|
+
const homeDir = os.homedir();
|
|
181
|
+
const encodedPath = encodePath(projectPath);
|
|
182
|
+
const sessionDir = path.join(homeDir, '.claude', 'projects', encodedPath);
|
|
183
|
+
if (!fs.existsSync(sessionDir))
|
|
184
|
+
return [];
|
|
185
|
+
const candidates = fs.readdirSync(sessionDir)
|
|
186
|
+
.filter(f => f.endsWith('.jsonl'))
|
|
187
|
+
.filter(f => !f.startsWith('agent-'))
|
|
188
|
+
.map(f => {
|
|
189
|
+
const filePath = path.join(sessionDir, f);
|
|
190
|
+
const stat = fs.statSync(filePath);
|
|
191
|
+
return { uuid: f.replace('.jsonl', ''), filePath, mtime: stat.mtimeMs, size: stat.size };
|
|
192
|
+
})
|
|
193
|
+
.filter(f => f.size > 0)
|
|
194
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
195
|
+
// 按 mtime 降序惰性判定 entrypoint,凑够调用方要求的数量即停,避免读取全部文件。
|
|
196
|
+
// 通过 entrypoint 白名单后,单遍扫描文件取预览标题并判定是否含真人消息,
|
|
197
|
+
// 排除整段都是 Claude Code 脚手架 prompt(斜杠命令 / skill / hook 探测)的空壳会话。
|
|
198
|
+
const result = [];
|
|
199
|
+
for (const f of candidates) {
|
|
200
|
+
const entrypoint = this.readEntrypoint(f.filePath);
|
|
201
|
+
if (entrypoint && ClaudeSessionFileAdapter.CLI_ENTRYPOINTS.has(entrypoint)) {
|
|
202
|
+
const preview = this.readSessionPreview(f.filePath);
|
|
203
|
+
if (!preview.hasReal)
|
|
204
|
+
continue;
|
|
205
|
+
result.push({ uuid: f.uuid, mtime: f.mtime, title: preview.title || undefined });
|
|
206
|
+
if (result.length >= limit)
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
async listSdkSessions(projectPath) {
|
|
213
|
+
try {
|
|
214
|
+
const sessions = await listClaudeSdkSessions({ dir: projectPath });
|
|
215
|
+
return sessions.map(s => ({
|
|
216
|
+
sessionId: s.sessionId,
|
|
217
|
+
title: s.customTitle || undefined,
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
logger.debug('[ClaudeAdapter] SDK listSessions failed (non-critical):', error);
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** 提取 user 事件的原始文本(未截断),用于合成 prompt 判定。 */
|
|
226
|
+
extractRawUserText(messageContent) {
|
|
227
|
+
if (typeof messageContent === 'string') {
|
|
228
|
+
const text = messageContent.trim().replace(/\s+/g, ' ');
|
|
229
|
+
return text || null;
|
|
230
|
+
}
|
|
231
|
+
else if (Array.isArray(messageContent)) {
|
|
232
|
+
const textContent = messageContent.find((c) => c.type === 'text');
|
|
233
|
+
if (textContent?.text) {
|
|
234
|
+
const text = textContent.text.trim().replace(/\s+/g, ' ');
|
|
235
|
+
return text || null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
extractUserMessageText(messageContent) {
|
|
241
|
+
const text = this.extractRawUserText(messageContent);
|
|
242
|
+
if (!text)
|
|
243
|
+
return null;
|
|
244
|
+
return text.substring(0, 50) + (text.length > 50 ? '...' : '');
|
|
245
|
+
}
|
|
246
|
+
}
|