evolcore 0.0.1 → 0.0.3
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 +64 -0
- package/LICENSE +21 -0
- package/MIGRATION-0.5.0.md +378 -0
- package/README.md +318 -14
- package/ROLE_ACCESS_CONTROL.md +174 -0
- package/assets/.env.template +4 -0
- package/bin/ec-safe-output.js +161 -0
- package/bin/ec.js +29 -0
- package/dist/agents/baseagent.js +163 -0
- package/dist/agents/claude-runner.js +2565 -0
- package/dist/agents/codex-app-server-client.js +448 -0
- package/dist/agents/codex-runner.js +2682 -0
- package/dist/agents/gemini-runner.js +666 -0
- package/dist/agents/runner-types.js +75 -0
- package/dist/aun/aid/agentmd.js +216 -0
- package/dist/aun/aid/client.js +132 -0
- package/dist/aun/aid/control-aid.js +91 -0
- package/dist/aun/aid/identity.js +518 -0
- package/dist/aun/aid/index.js +4 -0
- package/dist/aun/aid/store.js +74 -0
- package/dist/aun/aid/types.js +1 -0
- package/dist/aun/aid/validation.js +21 -0
- package/dist/aun/group-identity.js +10 -0
- package/dist/aun/msg/group-index.js +6 -0
- package/dist/aun/msg/group.js +1231 -0
- package/dist/aun/msg/history.js +123 -0
- package/dist/aun/msg/index.js +5 -0
- package/dist/aun/msg/p2p.js +393 -0
- package/dist/aun/msg/payload-type.js +27 -0
- package/dist/aun/msg/upload.js +137 -0
- package/dist/aun/outbox.js +168 -0
- package/dist/aun/rpc/caller.js +42 -0
- package/dist/aun/rpc/connection.js +25 -0
- package/dist/aun/rpc/index.js +2 -0
- package/dist/aun/service-proxy.js +225 -0
- package/dist/aun/storage/download.js +29 -0
- package/dist/aun/storage/index.js +3 -0
- package/dist/aun/storage/manage.js +10 -0
- package/dist/aun/storage/upload.js +68 -0
- package/dist/channels/aun.js +4164 -0
- package/dist/channels/contact-bind-code.js +134 -0
- package/dist/channels/daemon.js +422 -0
- package/dist/channels/dingtalk.js +1479 -0
- package/dist/channels/feishu.js +1865 -0
- package/dist/channels/qqbot.js +409 -0
- package/dist/channels/wechat.js +817 -0
- package/dist/channels/wecom-card.js +101 -0
- package/dist/channels/wecom-onboarding.js +82 -0
- package/dist/channels/wecom-state.js +191 -0
- package/dist/channels/wecom.js +1157 -0
- package/dist/cli/agent-command.js +642 -0
- package/dist/cli/agent.js +1059 -0
- package/dist/cli/aun-commands.js +2003 -0
- package/dist/cli/bench.js +1228 -0
- package/dist/cli/cli-argv.js +66 -0
- package/dist/cli/code-stats.js +329 -0
- package/dist/cli/command-log.js +82 -0
- package/dist/cli/config-selector.js +69 -0
- package/dist/cli/config.js +261 -0
- package/dist/cli/contact.js +71 -0
- package/dist/cli/ctl-command.js +62 -0
- package/dist/cli/daemon-commands.js +2750 -0
- package/dist/cli/fs-command.js +1447 -0
- package/dist/cli/handoff-command.js +302 -0
- package/dist/cli/help.js +35 -0
- package/dist/cli/index.js +374 -0
- package/dist/cli/init-channel.js +1372 -0
- package/dist/cli/init.js +590 -0
- package/dist/cli/link-rules.js +240 -0
- package/dist/cli/model.js +591 -0
- package/dist/cli/net-check.js +723 -0
- package/dist/cli/queue-command.js +150 -0
- package/dist/cli/raw-key-input.js +25 -0
- package/dist/cli/response.js +344 -0
- package/dist/cli/restart-monitor.js +480 -0
- package/dist/cli/stats.js +609 -0
- package/dist/cli/task-context.js +80 -0
- package/dist/cli/trigger-command.js +545 -0
- package/dist/cli/version.js +93 -0
- package/dist/cli/watch-logs.js +33 -0
- package/dist/cli/watch-msg.js +673 -0
- package/dist/config/boot-log.js +266 -0
- package/dist/config/builtin-role-templates.js +42 -0
- package/dist/config/builtin-roles.js +91 -0
- package/dist/config/config-batch-get.js +11 -0
- package/dist/config/config-field-policy.js +261 -0
- package/dist/config/config-manager.js +1120 -0
- package/dist/config/config-operation-service.js +384 -0
- package/dist/config/contact-alias.js +68 -0
- package/dist/config/contact-book-store.js +454 -0
- package/dist/config/contact-book-v2-startup.js +35 -0
- package/dist/config/contact-book.js +224 -0
- package/dist/config/contact-operation-service.js +110 -0
- package/dist/config/gateway-config.js +858 -0
- package/dist/config/lifecycle.js +17 -0
- package/dist/config/mention-mode.js +27 -0
- package/dist/config/merge.js +161 -0
- package/dist/config/owner-policy.js +4 -0
- package/dist/config/peer-role-resolver.js +218 -0
- package/dist/config/resolved-config-op.js +483 -0
- package/dist/config/role-config-v4-startup.js +32 -0
- package/dist/config/role-config-v5-startup.js +27 -0
- package/dist/config/role-ranks.js +18 -0
- package/dist/config/role-schema.js +105 -0
- package/dist/config/role-service.js +156 -0
- package/dist/config/role-store.js +215 -0
- package/dist/config/roles.js +64 -0
- package/dist/config/schema-registry.js +154 -0
- package/dist/config/snapshot.js +598 -0
- package/dist/config-store.js +501 -0
- package/dist/core/auth/agent-delegation.js +111 -0
- package/dist/core/auth/auth-gateway.js +166 -0
- package/dist/core/auth/authenticated-actor.js +6 -0
- package/dist/core/auth/authorization-audit.js +119 -0
- package/dist/core/auth/operation-authorizer.js +720 -0
- package/dist/core/auth/operation-catalog.js +731 -0
- package/dist/core/baseagent-loader.js +54 -0
- package/dist/core/bootstrap-service.js +175 -0
- package/dist/core/capability/capability-manager.js +316 -0
- package/dist/core/capability/providers/claude-capability-provider.js +176 -0
- package/dist/core/capability/providers/codex-capability-provider.js +148 -0
- package/dist/core/capability/providers/gemini-capability-provider.js +10 -0
- package/dist/core/capability/types.js +27 -0
- package/dist/core/causation/audit.js +103 -0
- package/dist/core/causation/aun-association.js +111 -0
- package/dist/core/causation/context.js +93 -0
- package/dist/core/causation/index.js +4 -0
- package/dist/core/causation/types.js +2 -0
- package/dist/core/channel-loader.js +277 -0
- package/dist/core/command/agent-control.js +616 -0
- package/dist/core/command/cli-intent-parser.js +225 -0
- package/dist/core/command/command-handler.js +1733 -0
- package/dist/core/command/connect-menu.js +374 -0
- package/dist/core/command/menu-handler.js +3452 -0
- package/dist/core/command/menu-protocol.js +247 -0
- package/dist/core/command/role-menu.js +1623 -0
- package/dist/core/command/slash-gate.js +148 -0
- package/dist/core/command/slash-handler.js +3066 -0
- package/dist/core/daemon-file-cache.js +222 -0
- package/dist/core/event-bus.js +32 -0
- package/dist/core/event-catalog.js +810 -0
- package/dist/core/evolagent-registry.js +545 -0
- package/dist/core/evolagent.js +342 -0
- package/dist/core/handoff/dispatcher.js +229 -0
- package/dist/core/handoff/mutex.js +46 -0
- package/dist/core/handoff/runtime.js +324 -0
- package/dist/core/handoff/store.js +537 -0
- package/dist/core/handoff/types.js +12 -0
- package/dist/core/inference/text-inference.js +173 -0
- package/dist/core/interaction-registration.js +10 -0
- package/dist/core/interaction-router.js +278 -0
- package/dist/core/message/create-status.js +67 -0
- package/dist/core/message/im-renderer.js +659 -0
- package/dist/core/message/items-formatter.js +76 -0
- package/dist/core/message/logical-queue-bridge.js +123 -0
- package/dist/core/message/message-bridge.js +874 -0
- package/dist/core/message/message-cache.js +56 -0
- package/dist/core/message/message-log.js +339 -0
- package/dist/core/message/message-processor.js +4 -0
- package/dist/core/message/message-queue.js +1446 -0
- package/dist/core/message/message-utils.js +76 -0
- package/dist/core/message/peer-mode.js +105 -0
- package/dist/core/message/pending-hints.js +232 -0
- package/dist/core/message/response-depth.js +33 -0
- package/dist/core/message/response-engine.js +4020 -0
- package/dist/core/message/response-snapshot.js +83 -0
- package/dist/core/message/send-receipt.js +24 -0
- package/dist/core/message/stream-debouncer.js +139 -0
- package/dist/core/message/stream-idle-monitor.js +124 -0
- package/dist/core/model/config-scope.js +162 -0
- package/dist/core/model/field-scope.js +78 -0
- package/dist/core/model/model-catalog.js +227 -0
- package/dist/core/model/model-diagnostics.js +182 -0
- package/dist/core/model/model-permission.js +90 -0
- package/dist/core/permission/approval-gateway.js +1017 -0
- package/dist/core/permission/ec-command-parser.js +347 -0
- package/dist/core/permission/execution-sandbox.js +16 -0
- package/dist/core/permission/index.js +6 -0
- package/dist/core/permission/mode.js +24 -0
- package/dist/core/permission/sandbox-runtime.js +265 -0
- package/dist/core/permission/tool-policy.js +1019 -0
- package/dist/core/permission/unix-socket-policy.js +99 -0
- package/dist/core/protected-paths.js +332 -0
- package/dist/core/relation/peer-identity.js +222 -0
- package/dist/core/relation/peer-key.js +1 -0
- package/dist/core/role/runtime-policy.js +141 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +218 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +333 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +181 -0
- package/dist/core/session/session-file-adapter.js +7 -0
- package/dist/core/session/session-file-health.js +45 -0
- package/dist/core/session/session-fs-store.js +273 -0
- package/dist/core/session/session-key.js +24 -0
- package/dist/core/session/session-manager.js +1643 -0
- package/dist/core/session/session-mapper.js +100 -0
- package/dist/core/session/session-renew.js +314 -0
- package/dist/core/session/session-title.js +128 -0
- package/dist/core/session/session-turn-coordinator.js +205 -0
- package/dist/core/session/session-turns.js +67 -0
- package/dist/core/system-channels.js +29 -0
- package/dist/eck/baseagent-caps.js +18 -0
- package/dist/eck/detect.js +47 -0
- package/dist/eck/group-rules-sync.js +345 -0
- package/dist/eck/init.js +77 -0
- package/dist/eck/kit-renderer.js +359 -0
- package/dist/eck/manifest-engine.js +446 -0
- package/dist/eck/message-renderer.js +199 -0
- package/dist/eck/rules-loader.js +28 -0
- package/dist/index.js +2926 -4
- package/dist/ipc.js +777 -0
- package/dist/paths.js +262 -0
- package/dist/product.js +18 -0
- package/dist/response-system/context-builder.js +71 -0
- package/dist/response-system/coordinator.js +117 -0
- package/dist/response-system/decision-executor.js +86 -0
- package/dist/response-system/engines/v1/index.js +21 -0
- package/dist/response-system/engines/v1/interactive-flow.js +27 -0
- package/dist/response-system/engines/v1/proactive-flow.js +137 -0
- package/dist/response-system/engines/v1/types.js +1 -0
- package/dist/response-system/extensions.js +41 -0
- package/dist/response-system/index.js +6 -0
- package/dist/response-system/modes/index.js +7 -0
- package/dist/response-system/modes/single-session/index.js +72 -0
- package/dist/response-system/queues/fifo-queue.js +44 -0
- package/dist/response-system/queues/index.js +6 -0
- package/dist/response-system/queues/lifo-queue.js +42 -0
- package/dist/response-system/queues/priority-queue.js +63 -0
- package/dist/response-system/registry.js +97 -0
- package/dist/response-system/resolver.js +37 -0
- package/dist/response-system/selector.js +23 -0
- package/dist/response-system/types.js +7 -0
- package/dist/stats/billing.js +163 -0
- package/dist/stats/budget.js +93 -0
- package/dist/stats/db.js +403 -0
- package/dist/stats/eck-vars.js +89 -0
- package/dist/stats/index.js +11 -0
- package/dist/stats/normalizer.js +80 -0
- package/dist/stats/price-resolver.js +138 -0
- package/dist/stats/query.js +763 -0
- package/dist/stats/role-budget.js +168 -0
- package/dist/stats/writer.js +151 -0
- package/dist/trigger/anomaly-store.js +258 -0
- package/dist/trigger/audit.js +152 -0
- package/dist/trigger/event-source.js +119 -0
- package/dist/trigger/feedback.js +685 -0
- package/dist/trigger/history.js +290 -0
- package/dist/trigger/manager.js +294 -0
- package/dist/trigger/parser.js +595 -0
- package/dist/trigger/patch.js +155 -0
- package/dist/trigger/scheduler.js +1602 -0
- package/dist/trigger/script-executor.js +155 -0
- package/dist/trigger/state.js +145 -0
- package/dist/trigger/types.js +1 -0
- package/dist/trigger/validation.js +634 -0
- package/dist/types.js +12 -0
- package/dist/utils/aid-bind.js +313 -0
- package/dist/utils/atomic-write.js +95 -0
- package/dist/utils/avatar-upload.js +123 -0
- package/dist/utils/cross-platform.js +297 -0
- package/dist/utils/ecweb-utils.js +73 -0
- package/dist/utils/error-dict.json +153 -0
- package/dist/utils/error-utils.js +349 -0
- package/dist/utils/instance-registry.js +444 -0
- package/dist/utils/locale.js +21 -0
- package/dist/utils/log-writer.js +270 -0
- package/dist/utils/logger.js +89 -0
- package/dist/utils/markdown-to-plain-text.js +20 -0
- package/dist/utils/media-cache.js +274 -0
- package/dist/utils/model-prices.jsonl +20 -0
- package/dist/utils/npm-ops.js +210 -0
- package/dist/utils/process-introspect.js +133 -0
- package/dist/utils/process-tree-stats.js +271 -0
- package/dist/utils/project-path.js +74 -0
- package/dist/utils/restart-safety.js +31 -0
- package/dist/utils/stats.js +410 -0
- package/dist/utils/system-memory.js +62 -0
- package/dist/utils/tool-summary.js +284 -0
- package/dist/utils/welcome.js +268 -0
- package/kits/docs/GUIDE.md +20 -0
- package/kits/docs/INDEX.md +66 -0
- package/kits/docs/aun/CHEATSHEET.md +19 -0
- package/kits/docs/aun/SYNC_PROTOCOL.md +15 -0
- package/kits/docs/channels/aun.md +65 -0
- package/kits/docs/channels/feishu.md +56 -0
- package/kits/docs/context-assembly.md +366 -0
- package/kits/docs/eck_templates/GUIDE.template.md +22 -0
- package/kits/docs/eck_templates/INDEX.template.md +28 -0
- package/kits/docs/eck_templates/path-registry.template.md +33 -0
- package/kits/docs/eck_templates/runtime.template.md +19 -0
- package/kits/docs/evolcore/INDEX.md +68 -0
- package/kits/docs/evolcore/agent.md +77 -0
- package/kits/docs/evolcore/aid.md +52 -0
- package/kits/docs/evolcore/config.md +149 -0
- package/kits/docs/evolcore/contact.md +57 -0
- package/kits/docs/evolcore/ctl.md +46 -0
- package/kits/docs/evolcore/event.md +216 -0
- package/kits/docs/evolcore/fs-architecture.md +1215 -0
- package/kits/docs/evolcore/fs.md +110 -0
- package/kits/docs/evolcore/group-fs.md +17 -0
- package/kits/docs/evolcore/group-rules.md +226 -0
- package/kits/docs/evolcore/group.md +150 -0
- package/kits/docs/evolcore/model.md +50 -0
- package/kits/docs/evolcore/msg.md +136 -0
- package/kits/docs/evolcore/response.md +75 -0
- package/kits/docs/evolcore/rpc.md +37 -0
- package/kits/docs/evolcore/self-summary.md +29 -0
- package/kits/docs/evolcore/stats.md +83 -0
- package/kits/docs/evolcore/storage.md +50 -0
- package/kits/docs/evolcore/trigger.md +539 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +26 -0
- package/kits/docs/identity/PATH_OPS.md +16 -0
- package/kits/docs/identity/ROLE_DETAIL.md +23 -0
- package/kits/docs/identity/identity-tools.md +26 -0
- package/kits/docs/path-registry.md +43 -0
- package/kits/docs/prompt-loading-architecture.md +266 -0
- package/kits/docs/venues/aun-group.md +45 -0
- package/kits/docs/venues/aun-private.md +10 -0
- package/kits/docs/venues/client-desktop.md +10 -0
- package/kits/docs/venues/client-mobile.md +10 -0
- package/kits/docs/venues/feishu-group.md +13 -0
- package/kits/docs/venues/feishu-private.md +9 -0
- package/kits/docs/venues/group.md +25 -0
- package/kits/docs/venues/private.md +10 -0
- package/kits/eck_manifest.auxiliary.json +43 -0
- package/kits/eck_manifest.json +203 -0
- package/kits/eck_message_manifest.json +63 -0
- package/kits/migrations/README-role-config-v4.md +32 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +747 -0
- package/kits/migrations/migrate-role-config-v4.mjs +623 -0
- package/kits/migrations/migrate-role-config-v5.mjs +346 -0
- package/kits/migrations/rename-config-file.mjs +99 -0
- package/kits/rules/01-overview.md +142 -0
- package/kits/rules/02-navigation.md +76 -0
- package/kits/rules/03-identity.md +34 -0
- package/kits/rules/04-relation.md +59 -0
- package/kits/rules/05-venue.md +44 -0
- package/kits/rules/06-channel.md +59 -0
- package/kits/schemas/_meta.json +32 -0
- package/kits/schemas/agent-config.schema.1.json +177 -0
- package/kits/schemas/agent-config.schema.2.json +239 -0
- package/kits/schemas/agent-config.schema.3.json +119 -0
- package/kits/schemas/agent-config.schema.4.json +208 -0
- package/kits/schemas/agent-config.schema.5.json +326 -0
- package/kits/schemas/agent-config.schema.6.json +322 -0
- package/kits/schemas/contact-book.schema.1.json +36 -0
- package/kits/schemas/contact-book.schema.2.json +43 -0
- package/kits/schemas/daemon.schema.1.json +90 -0
- package/kits/schemas/defaults.schema.1.json +81 -0
- package/kits/schemas/menu-exec-schema-commands.md +208 -0
- package/kits/schemas/migrations/README.md +28 -0
- package/kits/schemas/relation-config.schema.1.json +158 -0
- package/kits/schemas/relation-config.schema.2.json +73 -0
- package/kits/schemas/relation-config.schema.3.json +50 -0
- package/kits/schemas/relation-config.schema.4.json +47 -0
- package/kits/schemas/relation-config.schema.5.json +47 -0
- package/kits/schemas/role-config.schema.1.json +201 -0
- package/kits/schemas/role-registry.schema.1.json +35 -0
- package/kits/schemas/single-session.schema.1.json +31 -0
- package/kits/templates/bootstrap-welcome.md +15 -0
- package/kits/templates/message-fragments/handoff-request-to-target.md +13 -0
- package/kits/templates/message-fragments/handoff-response-to-origin.md +10 -0
- package/kits/templates/message-fragments/inject-default.md +2 -0
- package/kits/templates/message-fragments/item.md +2 -0
- package/kits/templates/roles/admin.json +9 -0
- package/kits/templates/roles/member.json +41 -0
- package/kits/templates/roles/owner.json +9 -0
- package/kits/templates/roles/visitor.json +40 -0
- package/kits/templates/system-fragments/baseagent.md +14 -0
- package/kits/templates/system-fragments/bootstrap.md +16 -0
- package/kits/templates/system-fragments/channel.md +48 -0
- package/kits/templates/system-fragments/commands.md +28 -0
- package/kits/templates/system-fragments/identity.md +11 -0
- package/kits/templates/system-fragments/relation.md +19 -0
- package/kits/templates/system-fragments/session.md +53 -0
- package/kits/templates/system-fragments/venue.md +31 -0
- package/package.json +50 -15
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import readline from 'readline';
|
|
3
|
+
import { logger } from '../utils/logger.js';
|
|
4
|
+
import { buildHClassGuardCommand } from '../core/permission/sandbox-runtime.js';
|
|
5
|
+
function hasPermissionProfile(config) {
|
|
6
|
+
if (!config || typeof config.default_permissions !== 'string' || !config.default_permissions)
|
|
7
|
+
return false;
|
|
8
|
+
const profiles = config.permissions;
|
|
9
|
+
return !!profiles && typeof profiles === 'object' && !Array.isArray(profiles)
|
|
10
|
+
&& Object.prototype.hasOwnProperty.call(profiles, config.default_permissions);
|
|
11
|
+
}
|
|
12
|
+
export class CodexAppServerClient {
|
|
13
|
+
options;
|
|
14
|
+
proc = null;
|
|
15
|
+
pending = new Map();
|
|
16
|
+
notificationHandlers = new Set();
|
|
17
|
+
nextId = 1;
|
|
18
|
+
initialized = false;
|
|
19
|
+
initializing = null;
|
|
20
|
+
stderrBuffer = [];
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
onNotification(handler) {
|
|
25
|
+
this.notificationHandlers.add(handler);
|
|
26
|
+
return () => this.notificationHandlers.delete(handler);
|
|
27
|
+
}
|
|
28
|
+
async threadStart(projectPath, options) {
|
|
29
|
+
const effort = options?.effort ?? this.options.effort;
|
|
30
|
+
const configUsesPermissionProfile = hasPermissionProfile(options?.config);
|
|
31
|
+
return this.request('thread/start', {
|
|
32
|
+
cwd: projectPath,
|
|
33
|
+
model: options?.model ?? this.options.model ?? null,
|
|
34
|
+
approvalPolicy: options?.approvalPolicy ?? null,
|
|
35
|
+
approvalsReviewer: options?.approvalsReviewer ?? this.options.approvalsReviewer ?? null,
|
|
36
|
+
...(configUsesPermissionProfile
|
|
37
|
+
? {}
|
|
38
|
+
: options?.permissions
|
|
39
|
+
? { permissions: options.permissions }
|
|
40
|
+
: { sandbox: options?.sandbox ?? null }),
|
|
41
|
+
config: this.buildThreadConfig(effort, options?.config),
|
|
42
|
+
...(options?.baseInstructions ? { baseInstructions: options.baseInstructions } : {}),
|
|
43
|
+
...(options?.developerInstructions ? { developerInstructions: options.developerInstructions } : {}),
|
|
44
|
+
...(options?.selectedCapabilityRoots ? { selectedCapabilityRoots: options.selectedCapabilityRoots } : {}),
|
|
45
|
+
...(options?.dynamicTools ? { dynamicTools: options.dynamicTools } : {}),
|
|
46
|
+
...(options?.environments ? { environments: options.environments } : {}),
|
|
47
|
+
...(options?.ephemeral !== undefined ? { ephemeral: options.ephemeral } : {}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async threadResume(threadId, projectPath, options) {
|
|
51
|
+
const effort = options?.effort ?? this.options.effort;
|
|
52
|
+
const configUsesPermissionProfile = hasPermissionProfile(options?.config);
|
|
53
|
+
return this.request('thread/resume', {
|
|
54
|
+
threadId,
|
|
55
|
+
cwd: projectPath,
|
|
56
|
+
model: options?.model ?? this.options.model ?? null,
|
|
57
|
+
approvalPolicy: options?.approvalPolicy ?? null,
|
|
58
|
+
approvalsReviewer: options?.approvalsReviewer ?? this.options.approvalsReviewer ?? null,
|
|
59
|
+
...(configUsesPermissionProfile
|
|
60
|
+
? {}
|
|
61
|
+
: options?.permissions
|
|
62
|
+
? { permissions: options.permissions }
|
|
63
|
+
: { sandbox: options?.sandbox ?? null }),
|
|
64
|
+
config: this.buildThreadConfig(effort, options?.config),
|
|
65
|
+
...(options?.baseInstructions ? { baseInstructions: options.baseInstructions } : {}),
|
|
66
|
+
...(options?.developerInstructions ? { developerInstructions: options.developerInstructions } : {}),
|
|
67
|
+
...(options?.selectedCapabilityRoots ? { selectedCapabilityRoots: options.selectedCapabilityRoots } : {}),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async turnStart(threadId, input, options) {
|
|
71
|
+
const sandboxPolicy = this.toTurnSandboxPolicy(options?.sandbox);
|
|
72
|
+
return this.request('turn/start', {
|
|
73
|
+
threadId,
|
|
74
|
+
input,
|
|
75
|
+
...(options?.cwd ? { cwd: options.cwd } : {}),
|
|
76
|
+
...(options?.model ? { model: options.model } : {}),
|
|
77
|
+
...(options?.approvalPolicy ? { approvalPolicy: options.approvalPolicy } : {}),
|
|
78
|
+
...(sandboxPolicy ? { sandboxPolicy } : {}),
|
|
79
|
+
...(options?.effort ? { effort: options.effort } : {}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
toTurnSandboxPolicy(sandbox) {
|
|
83
|
+
if (!sandbox)
|
|
84
|
+
return undefined;
|
|
85
|
+
if (sandbox === 'danger-full-access')
|
|
86
|
+
return { type: 'dangerFullAccess' };
|
|
87
|
+
if (sandbox === 'read-only')
|
|
88
|
+
return { type: 'readOnly', networkAccess: true };
|
|
89
|
+
if (sandbox === 'workspace-write') {
|
|
90
|
+
return {
|
|
91
|
+
type: 'workspaceWrite',
|
|
92
|
+
writableRoots: [],
|
|
93
|
+
networkAccess: true,
|
|
94
|
+
excludeTmpdirEnvVar: false,
|
|
95
|
+
excludeSlashTmp: false,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
async threadRead(threadId, includeTurns = true) {
|
|
101
|
+
return this.request('thread/read', { threadId, includeTurns });
|
|
102
|
+
}
|
|
103
|
+
async threadRollback(threadId, numTurns) {
|
|
104
|
+
return this.request('thread/rollback', { threadId, numTurns });
|
|
105
|
+
}
|
|
106
|
+
async threadFork(threadId, projectPath, title, options) {
|
|
107
|
+
const effort = options?.effort ?? this.options.effort;
|
|
108
|
+
const configUsesPermissionProfile = hasPermissionProfile(options?.config);
|
|
109
|
+
const response = await this.request('thread/fork', {
|
|
110
|
+
threadId,
|
|
111
|
+
cwd: projectPath,
|
|
112
|
+
model: options?.model ?? this.options.model ?? null,
|
|
113
|
+
approvalPolicy: options?.approvalPolicy ?? null,
|
|
114
|
+
approvalsReviewer: options?.approvalsReviewer ?? this.options.approvalsReviewer ?? null,
|
|
115
|
+
...(options?.permissions && !configUsesPermissionProfile
|
|
116
|
+
? { permissions: options.permissions }
|
|
117
|
+
: configUsesPermissionProfile
|
|
118
|
+
? {}
|
|
119
|
+
: { sandbox: options?.sandbox ?? null }),
|
|
120
|
+
config: this.buildThreadConfig(effort, options?.config),
|
|
121
|
+
excludeTurns: false,
|
|
122
|
+
persistExtendedHistory: false,
|
|
123
|
+
});
|
|
124
|
+
const forkedThreadId = response.thread?.id;
|
|
125
|
+
if (title && forkedThreadId) {
|
|
126
|
+
await this.threadSetName(forkedThreadId, title).catch(error => {
|
|
127
|
+
logger.debug(`[CodexAppServer] thread/name/set failed after fork: ${error}`);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return response;
|
|
131
|
+
}
|
|
132
|
+
buildThreadConfig(effort, config) {
|
|
133
|
+
const merged = { ...(config ?? {}) };
|
|
134
|
+
if (effort)
|
|
135
|
+
merged.model_reasoning_effort = effort;
|
|
136
|
+
return Object.keys(merged).length > 0 ? merged : null;
|
|
137
|
+
}
|
|
138
|
+
async threadCompactStart(threadId) {
|
|
139
|
+
await this.request('thread/compact/start', { threadId });
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
async threadTurnsList(threadId, limit) {
|
|
143
|
+
return this.request('thread/turns/list', {
|
|
144
|
+
threadId,
|
|
145
|
+
...(limit ? { limit } : {}),
|
|
146
|
+
sortDirection: 'asc',
|
|
147
|
+
itemsView: 'full',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async threadTurnsItemsList(threadId, turnId, limit) {
|
|
151
|
+
return this.request('thread/turns/items/list', {
|
|
152
|
+
threadId,
|
|
153
|
+
turnId,
|
|
154
|
+
...(limit ? { limit } : {}),
|
|
155
|
+
sortDirection: 'asc',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async threadSetName(threadId, name) {
|
|
159
|
+
await this.request('thread/name/set', { threadId, name });
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
async threadMetadataUpdate(threadId, gitInfo) {
|
|
163
|
+
const params = { threadId };
|
|
164
|
+
if (gitInfo) {
|
|
165
|
+
params.gitInfo = Object.fromEntries(Object.entries(gitInfo).filter((entry) => entry[1] !== undefined));
|
|
166
|
+
}
|
|
167
|
+
await this.request('thread/metadata/update', params);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
async turnInterrupt(threadId, turnId) {
|
|
171
|
+
await this.request('turn/interrupt', { threadId, turnId });
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
async modelList(includeHidden = false) {
|
|
175
|
+
return this.request('model/list', { includeHidden });
|
|
176
|
+
}
|
|
177
|
+
async modelProviderCapabilitiesRead() {
|
|
178
|
+
return this.request('modelProvider/capabilities/read', {});
|
|
179
|
+
}
|
|
180
|
+
async configRead(cwd) {
|
|
181
|
+
return this.request('config/read', {
|
|
182
|
+
...(cwd ? { cwd } : {}),
|
|
183
|
+
includeLayers: false,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async pluginInstalled(cwd) {
|
|
187
|
+
return this.request('plugin/installed', {
|
|
188
|
+
...(cwd ? { cwds: [cwd] } : {}),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async pluginRead(pluginName, marketplace) {
|
|
192
|
+
return this.request('plugin/read', {
|
|
193
|
+
pluginName,
|
|
194
|
+
...(marketplace.path
|
|
195
|
+
? { marketplacePath: marketplace.path }
|
|
196
|
+
: marketplace.name
|
|
197
|
+
? { remoteMarketplaceName: marketplace.name }
|
|
198
|
+
: {}),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async close() {
|
|
202
|
+
const proc = this.proc;
|
|
203
|
+
this.proc = null;
|
|
204
|
+
this.initialized = false;
|
|
205
|
+
this.initializing = null;
|
|
206
|
+
for (const pending of this.pending.values()) {
|
|
207
|
+
pending.reject(new Error('Codex app-server closed'));
|
|
208
|
+
}
|
|
209
|
+
this.pending.clear();
|
|
210
|
+
if (!proc)
|
|
211
|
+
return;
|
|
212
|
+
// 优雅关闭:先关闭 stdin,然后发送 SIGTERM,等待进程退出
|
|
213
|
+
proc.stdin.end();
|
|
214
|
+
proc.kill('SIGTERM');
|
|
215
|
+
// 等待进程退出,最多等待 5 秒
|
|
216
|
+
await new Promise((resolve) => {
|
|
217
|
+
const timeout = setTimeout(() => {
|
|
218
|
+
if (!proc.killed) {
|
|
219
|
+
logger.warn('[CodexAppServer] Process did not exit after SIGTERM, sending SIGKILL');
|
|
220
|
+
proc.kill('SIGKILL');
|
|
221
|
+
}
|
|
222
|
+
resolve();
|
|
223
|
+
}, 5000);
|
|
224
|
+
proc.once('exit', () => {
|
|
225
|
+
clearTimeout(timeout);
|
|
226
|
+
resolve();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async ensureStarted() {
|
|
231
|
+
if (this.initialized)
|
|
232
|
+
return;
|
|
233
|
+
if (this.initializing) {
|
|
234
|
+
await this.initializing;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (!this.proc)
|
|
238
|
+
this.startProcess();
|
|
239
|
+
this.initializing = (async () => {
|
|
240
|
+
await this.request('initialize', {
|
|
241
|
+
clientInfo: {
|
|
242
|
+
name: 'evolcore_codex_app_server',
|
|
243
|
+
title: 'EvolCore Codex App Server Client',
|
|
244
|
+
version: '1.0.0',
|
|
245
|
+
},
|
|
246
|
+
capabilities: { experimentalApi: true },
|
|
247
|
+
});
|
|
248
|
+
this.notify('initialized');
|
|
249
|
+
this.initialized = true;
|
|
250
|
+
})();
|
|
251
|
+
try {
|
|
252
|
+
await this.initializing;
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
this.initializing = null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
startProcess() {
|
|
259
|
+
const env = { ...process.env, ...this.options.env };
|
|
260
|
+
env.CODEX_API_KEY = this.options.apiKey;
|
|
261
|
+
if (this.options.baseUrl) {
|
|
262
|
+
env.OPENAI_BASE_URL = this.options.baseUrl;
|
|
263
|
+
}
|
|
264
|
+
const args = this.buildProcessArgs();
|
|
265
|
+
const guardedCommand = buildHClassGuardCommand('codex', args);
|
|
266
|
+
if (process.platform === 'linux' && !guardedCommand) {
|
|
267
|
+
throw new Error('Codex 缺少 EvolCore H 类路径隔离运行时,已拒绝启动 app-server');
|
|
268
|
+
}
|
|
269
|
+
this.proc = spawn(guardedCommand?.command ?? 'codex', guardedCommand?.args ?? args, {
|
|
270
|
+
cwd: this.options.cwd,
|
|
271
|
+
env,
|
|
272
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
273
|
+
});
|
|
274
|
+
this.proc.once('error', error => this.failAll(error));
|
|
275
|
+
this.proc.once('exit', (code, signal) => {
|
|
276
|
+
this.failAll(new Error(`Codex app-server exited: code=${code ?? 'null'} signal=${signal ?? 'null'}`));
|
|
277
|
+
});
|
|
278
|
+
const rl = readline.createInterface({ input: this.proc.stdout, crlfDelay: Infinity });
|
|
279
|
+
rl.on('line', line => this.handleLine(line));
|
|
280
|
+
this.proc.stderr.on('data', chunk => {
|
|
281
|
+
const text = String(chunk).trim();
|
|
282
|
+
if (!text)
|
|
283
|
+
return;
|
|
284
|
+
this.stderrBuffer.push(text);
|
|
285
|
+
if (this.stderrBuffer.length > 20)
|
|
286
|
+
this.stderrBuffer.shift();
|
|
287
|
+
logger.debug(`[CodexAppServer] ${text}`);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
buildProcessArgs() {
|
|
291
|
+
const args = ['app-server', '--listen', 'stdio://'];
|
|
292
|
+
if (this.options.enableRequestUserInput !== false) {
|
|
293
|
+
args.push('--enable', 'default_mode_request_user_input');
|
|
294
|
+
}
|
|
295
|
+
if (this.options.baseUrl) {
|
|
296
|
+
args.push('--config', `openai_base_url=${JSON.stringify(this.options.baseUrl)}`);
|
|
297
|
+
}
|
|
298
|
+
if (this.options.effort) {
|
|
299
|
+
args.push('--config', `model_reasoning_effort=${JSON.stringify(this.options.effort)}`);
|
|
300
|
+
}
|
|
301
|
+
return args;
|
|
302
|
+
}
|
|
303
|
+
async request(method, params) {
|
|
304
|
+
await this.ensureReadyFor(method);
|
|
305
|
+
const proc = this.proc;
|
|
306
|
+
if (!proc)
|
|
307
|
+
throw new Error('Codex app-server is not running');
|
|
308
|
+
const id = String(this.nextId++);
|
|
309
|
+
const payload = { id, method };
|
|
310
|
+
if (params !== undefined && params !== null)
|
|
311
|
+
payload.params = params;
|
|
312
|
+
return new Promise((resolve, reject) => {
|
|
313
|
+
this.pending.set(id, { resolve, reject, method, params });
|
|
314
|
+
proc.stdin.write(`${JSON.stringify(payload)}\n`, error => {
|
|
315
|
+
if (!error)
|
|
316
|
+
return;
|
|
317
|
+
this.pending.delete(id);
|
|
318
|
+
reject(error);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
respond(id, result) {
|
|
323
|
+
if (!this.proc)
|
|
324
|
+
return;
|
|
325
|
+
const payload = JSON.stringify({ id, result }) + '\n';
|
|
326
|
+
this.proc.stdin.write(payload, error => {
|
|
327
|
+
if (error)
|
|
328
|
+
logger.warn(`[CodexAppServer] failed to write response id=${id}: ${error.message}`);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
respondError(id, error) {
|
|
332
|
+
if (!this.proc)
|
|
333
|
+
return;
|
|
334
|
+
const payload = JSON.stringify({ id, error: { message: error.message } }) + '\n';
|
|
335
|
+
this.proc.stdin.write(payload, writeError => {
|
|
336
|
+
if (writeError)
|
|
337
|
+
logger.warn(`[CodexAppServer] failed to write error response id=${id}: ${writeError.message}`);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
notify(method, params) {
|
|
341
|
+
if (!this.proc)
|
|
342
|
+
return;
|
|
343
|
+
const payload = { method };
|
|
344
|
+
if (params !== undefined && params !== null)
|
|
345
|
+
payload.params = params;
|
|
346
|
+
this.proc.stdin.write(`${JSON.stringify(payload)}\n`);
|
|
347
|
+
}
|
|
348
|
+
async ensureReadyFor(method) {
|
|
349
|
+
if (method === 'initialize') {
|
|
350
|
+
if (!this.proc)
|
|
351
|
+
this.startProcess();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
await this.ensureStarted();
|
|
355
|
+
}
|
|
356
|
+
handleLine(line) {
|
|
357
|
+
let message;
|
|
358
|
+
try {
|
|
359
|
+
message = JSON.parse(line);
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
logger.debug(`[CodexAppServer] Ignoring non-JSON line: ${line}`);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const rawId = message.id;
|
|
366
|
+
if (typeof message.method === 'string') {
|
|
367
|
+
if (rawId === undefined) {
|
|
368
|
+
this.emitNotification({ method: message.method, params: message.params });
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
this.handleServerRequest({ id: rawId, method: message.method, params: message.params });
|
|
372
|
+
}
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (rawId === undefined)
|
|
376
|
+
return;
|
|
377
|
+
const messageId = String(rawId);
|
|
378
|
+
const pending = this.pending.get(messageId);
|
|
379
|
+
if (!pending)
|
|
380
|
+
return;
|
|
381
|
+
this.pending.delete(messageId);
|
|
382
|
+
if (message.error) {
|
|
383
|
+
const detail = typeof message.error?.message === 'string' ? message.error.message : JSON.stringify(message.error);
|
|
384
|
+
const stderr = this.stderrBuffer.length ? `\n${this.stderrBuffer.join('\n')}` : '';
|
|
385
|
+
pending.reject(new Error(`${pending.method} failed: ${detail}${stderr}`));
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
pending.resolve(message.result ?? null);
|
|
389
|
+
}
|
|
390
|
+
handleServerRequest(request) {
|
|
391
|
+
const handler = this.options.onServerRequest;
|
|
392
|
+
logger.info(`[CodexAppServer] server request id=${request.id} method=${request.method}`);
|
|
393
|
+
if (!handler) {
|
|
394
|
+
logger.warn(`[CodexAppServer] unsupported server request id=${request.id} method=${request.method}`);
|
|
395
|
+
this.respondError(request.id, new Error('Unsupported Codex app-server request: ' + request.method));
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
Promise.resolve(handler(request))
|
|
399
|
+
.then(result => {
|
|
400
|
+
logger.info(`[CodexAppServer] server response id=${request.id} method=${request.method} result=${JSON.stringify(result ?? null)}`);
|
|
401
|
+
this.respond(request.id, result ?? null);
|
|
402
|
+
})
|
|
403
|
+
.catch(error => {
|
|
404
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
405
|
+
logger.warn(`[CodexAppServer] server request failed id=${request.id} method=${request.method}: ${err.message}`);
|
|
406
|
+
this.respondError(request.id, err);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
emitNotification(notification) {
|
|
410
|
+
this.resolveSyntheticResponses(notification);
|
|
411
|
+
for (const handler of this.notificationHandlers) {
|
|
412
|
+
try {
|
|
413
|
+
handler(notification);
|
|
414
|
+
}
|
|
415
|
+
catch (error) {
|
|
416
|
+
logger.debug(`[CodexAppServer] notification handler failed: ${error}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
resolveSyntheticResponses(notification) {
|
|
421
|
+
if (notification.method !== 'thread/compacted')
|
|
422
|
+
return;
|
|
423
|
+
const threadId = typeof notification.params?.threadId === 'string'
|
|
424
|
+
? notification.params.threadId
|
|
425
|
+
: typeof notification.params?.thread_id === 'string'
|
|
426
|
+
? notification.params.thread_id
|
|
427
|
+
: undefined;
|
|
428
|
+
if (!threadId)
|
|
429
|
+
return;
|
|
430
|
+
for (const [id, pending] of this.pending.entries()) {
|
|
431
|
+
const pendingThreadId = typeof pending.params?.threadId === 'string' ? pending.params.threadId : undefined;
|
|
432
|
+
if (pending.method !== 'thread/compact/start' || pendingThreadId !== threadId)
|
|
433
|
+
continue;
|
|
434
|
+
this.pending.delete(id);
|
|
435
|
+
logger.info(`[CodexAppServer] resolved pending thread/compact/start id=${id} from thread/compacted thread=${threadId}`);
|
|
436
|
+
pending.resolve({});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
failAll(error) {
|
|
440
|
+
if (this.proc)
|
|
441
|
+
this.proc = null;
|
|
442
|
+
this.initialized = false;
|
|
443
|
+
for (const pending of this.pending.values()) {
|
|
444
|
+
pending.reject(error);
|
|
445
|
+
}
|
|
446
|
+
this.pending.clear();
|
|
447
|
+
}
|
|
448
|
+
}
|