evolcore 0.0.43-test.4 → 0.0.43-test.6
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 +93 -0
- package/bin/ecmsg.js +437 -91
- package/dist/agents/baseagent-availability.js +19 -4
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +19 -4
- package/dist/agents/codex/app-server-client.js +14 -3
- package/dist/agents/codex-runner.js +18 -23
- package/dist/aun/aid/agentmd.js +25 -0
- package/dist/aun/aid/control-aid.js +15 -0
- package/dist/aun/aid/identity.js +8 -0
- package/dist/aun/aid/ownership-operation.js +12 -3
- package/dist/aun/group/invite-service.js +3 -2
- package/dist/aun/service-proxy.js +18 -6
- package/dist/channels/aun.js +99 -23
- package/dist/channels/daemon.js +2 -2
- package/dist/cli/agent-create.js +19 -7
- package/dist/cli/aid-bind-command.js +3 -0
- package/dist/cli/aun-commands.js +19 -4
- package/dist/cli/code-stats.js +451 -213
- package/dist/cli/ctl-command.js +1 -3
- package/dist/cli/daemon-commands.js +42 -4
- package/dist/cli/directory.js +3 -1
- package/dist/cli/ecmsg-gateway.js +206 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/init.js +120 -13
- package/dist/cli/provider-command.js +82 -5
- package/dist/cli/restart-monitor.js +35 -24
- package/dist/cli/stats.js +8 -1
- package/dist/cli/task-context.js +41 -1
- package/dist/cli/watch-logs.js +6 -4
- package/dist/config/boot-log.js +16 -3
- package/dist/config/builtin-roles.js +2 -2
- package/dist/config/config-manager.js +5 -14
- package/dist/config/daemon-services.js +1 -0
- package/dist/config/peer-role-resolver.js +6 -6
- package/dist/config/provider-identity-migration.js +277 -0
- package/dist/config/provider-identity.js +37 -0
- package/dist/config/provider-ipc-service.js +40 -3
- package/dist/config/provider-local-sync.js +155 -0
- package/dist/config/providers-config.js +45 -4
- package/dist/config/providers-management.js +242 -76
- package/dist/config/providers.js +4 -1
- package/dist/config/role-service.js +8 -8
- package/dist/config/role-store.js +22 -22
- package/dist/config/schema-migration.js +143 -86
- package/dist/config/snapshot.js +70 -41
- package/dist/core/agent-runtime.js +48 -9
- package/dist/core/auth/auth-gateway.js +5 -3
- package/dist/core/auth/delegation-diagnostics.js +6 -2
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/auth/operation-catalog.js +6 -4
- package/dist/core/baseagent-loader.js +114 -11
- package/dist/core/channel-loader.js +36 -13
- package/dist/core/channel-runtime.js +112 -42
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +16 -11
- package/dist/core/command/menu-handler.js +8 -3
- package/dist/core/command/menu-protocol.js +80 -7
- package/dist/core/command/provider-menu.js +4 -2
- package/dist/core/command/role-menu.js +29 -17
- package/dist/core/command/slash-handler.js +52 -16
- package/dist/core/daemon-control.js +42 -15
- package/dist/core/daemon-lifecycle.js +411 -67
- package/dist/core/handoff/dispatcher.js +9 -3
- package/dist/core/handoff/runtime.js +139 -45
- package/dist/core/handoff/store.js +190 -2
- package/dist/core/handoff/types.js +5 -0
- package/dist/core/initialization/service.js +7 -6
- package/dist/core/ipc-registration.js +5 -4
- package/dist/core/lifecycle-notice.js +10 -4
- package/dist/core/message/aun-ipc-sender.js +83 -5
- package/dist/core/message/message-admission.js +2 -0
- package/dist/core/message/message-bridge.js +53 -4
- package/dist/core/message/message-queue.js +46 -4
- package/dist/core/message/pending-hints.js +4 -10
- package/dist/core/message/response-engine.js +33 -25
- package/dist/core/message/send-options.js +40 -0
- package/dist/core/message/send-routing.js +320 -0
- package/dist/core/ownership/owner-resolver.js +112 -8
- package/dist/core/permission/ec-command-parser.js +159 -16
- package/dist/core/permission/readonly-shell-query.js +66 -7
- package/dist/core/permission/tool-error-code.js +13 -1
- package/dist/core/permission/tool-policy.js +74 -20
- package/dist/core/relation/same-owner-proof.js +131 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
- package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
- package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
- package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
- package/dist/core/session/session-fs-store.js +164 -3
- package/dist/core/session/session-idle-monitor.js +103 -17
- package/dist/core/session/session-manager.js +105 -18
- package/dist/core/thread/thread-route.js +5 -2
- package/dist/directory/owner-directory-admission.js +26 -1
- package/dist/directory/owner-directory-cache.js +739 -109
- package/dist/directory/owner-directory-markdown.js +146 -36
- package/dist/directory/owner-directory-query-operation.js +6 -3
- package/dist/directory/owner-directory-scope.js +12 -0
- package/dist/directory/owner-directory-search.js +5 -1
- package/dist/directory/owner-directory-store.js +28 -0
- package/dist/ecweb/basic-settings-service.js +15 -1
- package/dist/ecweb/message-context-service.js +2 -2
- package/dist/ecweb/providers-service.js +3 -1
- package/dist/ecweb/runtime/lifecycle.js +26 -15
- package/dist/ecweb/runtime/supervisor.js +120 -51
- package/dist/index.js +551 -250
- package/dist/paths.js +2 -1
- package/dist/proxy/manager.js +40 -17
- package/dist/proxy/service-supervisor.js +67 -33
- package/dist/response-system/engines/v1/proactive-flow.js +4 -0
- package/dist/trigger/application-service.js +4 -1
- package/dist/trigger/audit.js +19 -4
- package/dist/trigger/authorization.js +14 -5
- package/dist/trigger/event-source.js +4 -0
- package/dist/trigger/feedback.js +26 -2
- package/dist/trigger/history.js +176 -7
- package/dist/trigger/manager.js +1 -3
- package/dist/trigger/scheduler.js +81 -8
- package/dist/trigger/system-definitions.js +2 -2
- package/dist/trigger/validation.js +4 -0
- package/dist/utils/autostart.js +2 -2
- package/dist/utils/cross-platform.js +188 -12
- package/dist/utils/host-info.js +11 -8
- package/dist/utils/npm-ops.js +48 -0
- package/dist/utils/process-introspect.js +64 -1
- package/dist/utils/public-suffix.js +5811 -0
- package/dist/utils/startup-trace.js +160 -19
- package/dist/utils/windows-autostart.js +41 -7
- package/ecagent/dist/harness/env/nodejs.js +46 -2
- package/kits/docs/aun/ABILITY_CALLING.md +6 -6
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/channels/feishu.md +2 -2
- package/kits/docs/context-assembly.md +20 -4
- package/kits/docs/evolcore/INDEX.md +5 -3
- package/kits/docs/evolcore/agent.md +2 -2
- package/kits/docs/evolcore/aid.md +8 -2
- package/kits/docs/evolcore/ctl.md +15 -5
- package/kits/docs/evolcore/directory.md +48 -15
- package/kits/docs/evolcore/group.md +8 -8
- package/kits/docs/evolcore/memory-consolidation.md +1 -1
- package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +32 -3
- package/kits/docs/evolcore/msg.md +38 -30
- package/kits/docs/evolcore/provider.md +57 -5
- package/kits/docs/evolcore/response.md +2 -2
- package/kits/docs/evolcore/thread-chain.md +11 -13
- package/kits/docs/evolcore/tool-authorization.md +17 -0
- package/kits/docs/evolcore/trigger.md +2 -2
- package/kits/docs/identity/ROLE_DETAIL.md +1 -1
- package/kits/docs/prompt-loading-architecture.md +30 -20
- package/kits/eck_manifest.auxiliary.json +5 -5
- package/kits/eck_manifest.json +44 -32
- package/kits/eck_manifest.memory.json +18 -18
- package/kits/eck_message_manifest.json +3 -3
- package/kits/rules/01-overview.md +1 -1
- package/kits/rules/06-channel.md +7 -8
- package/kits/schemas/_meta.json +7 -1
- package/kits/schemas/daemon.schema.1.json +5 -0
- package/kits/schemas/daemon.schema.2.json +5 -0
- package/kits/schemas/daemon.schema.3.json +2 -1
- package/kits/schemas/daemon.schema.4.json +2 -1
- package/kits/schemas/daemon.schema.5.json +2 -1
- package/kits/schemas/daemon.schema.6.json +1 -1
- package/kits/schemas/daemon.schema.7.json +1 -1
- package/kits/schemas/daemon.schema.8.json +2 -1
- package/kits/schemas/daemon.schema.9.json +2 -1
- package/kits/schemas/providers.schema.2.json +74 -0
- package/kits/schemas/role-registry.schema.1.json +2 -2
- package/kits/schemas/single-session.schema.1.json +1 -1
- package/kits/schemas/single-session.schema.2.json +1 -1
- package/kits/schemas/single-session.schema.3.json +1 -1
- package/kits/skills/aid-ability/SKILL.md +7 -7
- package/kits/skills/ec-agent-create/SKILL.md +1 -0
- package/kits/skills/ec-group/SKILL.md +8 -5
- package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
- package/kits/skills/ec-service-proxy/SKILL.md +3 -10
- package/kits/skills/ec-trigger/SKILL.md +9 -9
- package/kits/skills/ec-trigger/references/examples.md +1 -1
- package/kits/skills/thread-ops/SKILL.md +10 -10
- package/kits/templates/system-fragments/channel.md +5 -5
- package/kits/templates/system-fragments/commands.md +7 -6
- package/kits/templates/system-fragments/directory-contacts.md +10 -3
- package/kits/templates/system-fragments/personal-assistant.md +22 -3
- package/kits/templates/system-fragments/reply.md +48 -28
- package/kits/templates/system-fragments/session.md +3 -10
- package/kits/templates/system-fragments/thread.md +5 -5
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getRunnerCatalog, peekRunnerCatalog, catalogEfforts, resolveCatalogModel, assertCatalogSelectable } from '../core/model/model-catalog.js';
|
|
2
2
|
import { query, forkSession as sdkForkSession, getSessionMessages as sdkGetSessionMessages, resolveSettings as sdkResolveSettings, } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
-
import { spawn
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
5
|
import { ensureDir } from '../utils/atomic-write.js';
|
|
6
6
|
import { resolveAnthropicConfig } from './baseagent.js';
|
|
@@ -22,7 +22,7 @@ import { checkBashDescription, checkDangerousCommand, checkReadonly, evaluateToo
|
|
|
22
22
|
import { sanitizeShellExecutionEnvironment } from '../core/permission/shell-environment.js';
|
|
23
23
|
import { summarizeToolInput, summarizeToolInputForAudit } from '../utils/tool-summary.js';
|
|
24
24
|
import { renderToolTime } from './tool-time-context.js';
|
|
25
|
-
import { encodePath } from '../utils/cross-platform.js';
|
|
25
|
+
import { encodePath, probeCli, probeCliSync } from '../utils/cross-platform.js';
|
|
26
26
|
import { getPackageRoot, resolvePaths } from '../paths.js';
|
|
27
27
|
import { resolveEffective } from '../config/config-manager.js';
|
|
28
28
|
import { sanitizeSessionTitle } from '../core/session/session-title.js';
|
|
@@ -165,8 +165,23 @@ export function probeBundledClaudeVersion() {
|
|
|
165
165
|
if (!executable)
|
|
166
166
|
return undefined;
|
|
167
167
|
try {
|
|
168
|
-
const raw =
|
|
169
|
-
|
|
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()),
|
|
170
185
|
});
|
|
171
186
|
return raw.trim().split(/\s+/)[0] || undefined;
|
|
172
187
|
}
|
|
@@ -92,6 +92,7 @@ export class CodexAppServerClient {
|
|
|
92
92
|
return this.request('thread/start', {
|
|
93
93
|
cwd: projectPath,
|
|
94
94
|
model: options?.model ?? this.options.model ?? null,
|
|
95
|
+
...(this.runtimeModelProvider() ? { modelProvider: this.runtimeModelProvider() } : {}),
|
|
95
96
|
approvalPolicy: options?.approvalPolicy ?? null,
|
|
96
97
|
approvalsReviewer: options?.approvalsReviewer ?? this.options.approvalsReviewer ?? null,
|
|
97
98
|
...(configUsesPermissionProfile
|
|
@@ -116,6 +117,7 @@ export class CodexAppServerClient {
|
|
|
116
117
|
threadId,
|
|
117
118
|
cwd: projectPath,
|
|
118
119
|
model: options?.model ?? this.options.model ?? null,
|
|
120
|
+
...(this.runtimeModelProvider() ? { modelProvider: this.runtimeModelProvider() } : {}),
|
|
119
121
|
approvalPolicy: options?.approvalPolicy ?? null,
|
|
120
122
|
approvalsReviewer: options?.approvalsReviewer ?? this.options.approvalsReviewer ?? null,
|
|
121
123
|
...(configUsesPermissionProfile
|
|
@@ -239,6 +241,7 @@ export class CodexAppServerClient {
|
|
|
239
241
|
threadId,
|
|
240
242
|
cwd: projectPath,
|
|
241
243
|
model: options?.model ?? this.options.model ?? null,
|
|
244
|
+
...(this.runtimeModelProvider() ? { modelProvider: this.runtimeModelProvider() } : {}),
|
|
242
245
|
approvalPolicy: options?.approvalPolicy ?? null,
|
|
243
246
|
approvalsReviewer: options?.approvalsReviewer ?? this.options.approvalsReviewer ?? null,
|
|
244
247
|
...(options?.permissions && !configUsesPermissionProfile
|
|
@@ -260,6 +263,9 @@ export class CodexAppServerClient {
|
|
|
260
263
|
}
|
|
261
264
|
buildThreadConfig(effort, config) {
|
|
262
265
|
const merged = { ...(config ?? {}) };
|
|
266
|
+
const provider = this.runtimeModelProvider();
|
|
267
|
+
if (provider)
|
|
268
|
+
merged.model_provider = provider;
|
|
263
269
|
if (effort)
|
|
264
270
|
merged.model_reasoning_effort = effort;
|
|
265
271
|
return Object.keys(merged).length > 0 ? merged : null;
|
|
@@ -756,6 +762,13 @@ export class CodexAppServerClient {
|
|
|
756
762
|
+ 'Restart EvolCore to install missing hooks and reload the Codex policy.');
|
|
757
763
|
}
|
|
758
764
|
}
|
|
765
|
+
runtimeModelProvider() {
|
|
766
|
+
if (!this.options.baseUrl && !this.options.provider
|
|
767
|
+
&& !Object.keys(this.options.headers ?? {}).length && !Object.keys(this.options.queryParams ?? {}).length)
|
|
768
|
+
return undefined;
|
|
769
|
+
const provider = this.options.provider?.trim();
|
|
770
|
+
return provider && !BUILT_IN_CODEX_PROVIDER_IDS.has(provider.toLowerCase()) ? provider : runtimeProviderId(this.options.baseUrl);
|
|
771
|
+
}
|
|
759
772
|
buildProcessArgs() {
|
|
760
773
|
const args = ['app-server', '--listen', 'stdio://'];
|
|
761
774
|
// 记忆只走 EvolCore(ec memory):显式关闭 Codex 原生 memories,
|
|
@@ -773,9 +786,7 @@ export class CodexAppServerClient {
|
|
|
773
786
|
if (hasHeaders || hasQueryParams || this.options.baseUrl || this.options.provider) {
|
|
774
787
|
const configuredProvider = this.options.provider?.trim();
|
|
775
788
|
const useRuntimeProvider = !configuredProvider || BUILT_IN_CODEX_PROVIDER_IDS.has(configuredProvider.toLowerCase());
|
|
776
|
-
const providerName =
|
|
777
|
-
? configuredProvider
|
|
778
|
-
: runtimeProviderId(this.options.baseUrl);
|
|
789
|
+
const providerName = this.runtimeModelProvider();
|
|
779
790
|
const provider = tomlProviderKey(providerName);
|
|
780
791
|
args.push('--config', `model_provider=${JSON.stringify(providerName)}`);
|
|
781
792
|
args.push('--config', `model_providers.${provider}.name=${JSON.stringify('EvolCore runtime gateway')}`);
|
|
@@ -32,7 +32,7 @@ import { ensureSessionRuntimeDir, getManagedTaskTempDir } from '../cli/task-cont
|
|
|
32
32
|
import { buildTranscriptTurns } from '../core/session/session-transcript.js';
|
|
33
33
|
import { CodexSessionFileAdapter } from '../core/session/adapters/codex-session-file-adapter.js';
|
|
34
34
|
import { execFileSync } from 'child_process';
|
|
35
|
-
import { probeCli, probeCliSync } from '../utils/cross-platform.js';
|
|
35
|
+
import { probeCli, probeCliSync, CODEX_CLI_PROBE_TIMEOUT_MS, CODEX_CLI_PROBE_RETRY_TIMEOUT_MS } from '../utils/cross-platform.js';
|
|
36
36
|
import { createHash, randomBytes } from 'crypto';
|
|
37
37
|
import { buildModelRequestHeaders } from './request-identity.js';
|
|
38
38
|
import { extractStructuredToolErrorMarker, normalizeToolErrorClassification, normalizeToolErrorCode, normalizeToolErrorDetailCode, } from '../core/permission/tool-error-code.js';
|
|
@@ -111,8 +111,9 @@ function parseCodexRetryProgress(message) {
|
|
|
111
111
|
return undefined;
|
|
112
112
|
return { count, limit };
|
|
113
113
|
}
|
|
114
|
-
function createCodexRetryMetadataError(message, state) {
|
|
114
|
+
function createCodexRetryMetadataError(message, state, executionOutcome) {
|
|
115
115
|
const error = new Error(message);
|
|
116
|
+
error.codexExecutionOutcome = executionOutcome;
|
|
116
117
|
if (state.modelRetryCount !== undefined)
|
|
117
118
|
error.codexRetryCount = state.modelRetryCount;
|
|
118
119
|
if (state.modelRetryLimit !== undefined)
|
|
@@ -302,9 +303,6 @@ export function parseCodexCliVersion(output) {
|
|
|
302
303
|
export function isCodexCliVersionSupported(version) {
|
|
303
304
|
return compareVersions(version, MIN_CODEX_CLI_VERSION) >= 0;
|
|
304
305
|
}
|
|
305
|
-
// Windows shim/process startup can exceed the quick probe deadline under load.
|
|
306
|
-
const CODEX_CLI_PROBE_TIMEOUT_MS = 3000;
|
|
307
|
-
const CODEX_CLI_PROBE_RETRY_TIMEOUT_MS = 15_000;
|
|
308
306
|
function compactCodexProbeText(value, maxLength = 600) {
|
|
309
307
|
if (Buffer.isBuffer(value))
|
|
310
308
|
value = value.toString('utf-8');
|
|
@@ -334,22 +332,14 @@ function logCodexProbeFailure(args, startedAt, error, timeoutMs, launch) {
|
|
|
334
332
|
})}`);
|
|
335
333
|
}
|
|
336
334
|
function probeCodexCli(args, executable) {
|
|
337
|
-
return probeCliSync('codex', args, {
|
|
335
|
+
return probeCliSync('codex', args, {
|
|
336
|
+
executable, onFailure: logCodexProbeFailure,
|
|
337
|
+
validateOutput: args[0] === '--version' ? output => parseCodexCliVersion(output) !== null : undefined,
|
|
338
|
+
});
|
|
338
339
|
}
|
|
339
340
|
export function getCodexCliVersion(executable) {
|
|
340
|
-
const startedAt = Date.now();
|
|
341
341
|
try {
|
|
342
|
-
|
|
343
|
-
const version = parseCodexCliVersion(output);
|
|
344
|
-
if (!version) {
|
|
345
|
-
logCodexProbeFailure(['--version'], startedAt, {
|
|
346
|
-
code: 'INVALID_VERSION_OUTPUT',
|
|
347
|
-
message: 'Codex CLI version output could not be parsed',
|
|
348
|
-
status: 0,
|
|
349
|
-
stdout: output,
|
|
350
|
-
}, CODEX_CLI_PROBE_TIMEOUT_MS);
|
|
351
|
-
}
|
|
352
|
-
return version;
|
|
342
|
+
return parseCodexCliVersion(probeCodexCli(['--version'], executable));
|
|
353
343
|
}
|
|
354
344
|
catch {
|
|
355
345
|
return null;
|
|
@@ -444,7 +434,9 @@ async function probeCodexAppServerAvailabilityAsync() {
|
|
|
444
434
|
// version gate passes, so the decision order is unchanged.
|
|
445
435
|
const appServerProbe = probeCli('codex', ['app-server', '--help'], options);
|
|
446
436
|
appServerProbe.catch(() => { });
|
|
447
|
-
version = parseCodexCliVersion(await probeCli('codex', ['--version'],
|
|
437
|
+
version = parseCodexCliVersion(await probeCli('codex', ['--version'], {
|
|
438
|
+
...options, validateOutput: output => parseCodexCliVersion(output) !== null,
|
|
439
|
+
})) ?? undefined;
|
|
448
440
|
if (!version)
|
|
449
441
|
return { available: false, reason: '无法读取 Codex CLI 版本。' };
|
|
450
442
|
if (!isCodexCliVersionSupported(version)) {
|
|
@@ -3351,7 +3343,10 @@ export class CodexRunner {
|
|
|
3351
3343
|
const mode = normalizePermissionMode(context?.permissionMode).mode;
|
|
3352
3344
|
const executionSandbox = this.buildExecutionSandboxOptions(sessionKey, mode, projectPath, undefined, undefined, context ?? {});
|
|
3353
3345
|
const capabilityConfig = await this.resolveCapabilityThreadConfig(projectPath);
|
|
3354
|
-
|
|
3346
|
+
// Fork against the connection that owns the source thread. Codex keeps
|
|
3347
|
+
// normal and full-access threads on separate app-server clients; using the
|
|
3348
|
+
// default client here makes full-access forks time out or lose the thread.
|
|
3349
|
+
const appServer = this.getAppServerClientForThread(agentSessionId);
|
|
3355
3350
|
const externalToolConfig = await this.resolveExternalToolApprovalConfig(appServer, projectPath, capabilityConfig, mode);
|
|
3356
3351
|
if (sessionKey)
|
|
3357
3352
|
await this.assertProactiveHookAvailability(sessionKey, appServer);
|
|
@@ -3380,7 +3375,7 @@ export class CodexRunner {
|
|
|
3380
3375
|
async forkSessionAt(agentSessionId, projectPath, assistantMessageId, title, context) {
|
|
3381
3376
|
const release = await this.acquireThreadOperation(this.threadOperationKey(agentSessionId), 'forkAt');
|
|
3382
3377
|
try {
|
|
3383
|
-
const appServer = this.
|
|
3378
|
+
const appServer = this.getAppServerClientForThread(agentSessionId);
|
|
3384
3379
|
const history = await this.readForkHistory(appServer, agentSessionId);
|
|
3385
3380
|
const messages = this.mapThreadToSessionMessages(history, agentSessionId);
|
|
3386
3381
|
const turns = buildTranscriptTurns(messages);
|
|
@@ -5638,7 +5633,7 @@ export class CodexRunner {
|
|
|
5638
5633
|
lastReportedUsage: state.tokenUsage?.last,
|
|
5639
5634
|
})}`);
|
|
5640
5635
|
if (isRetryableError(new Error(turn.error.message))) {
|
|
5641
|
-
throw createCodexRetryMetadataError(turn.error.message, state);
|
|
5636
|
+
throw createCodexRetryMetadataError(turn.error.message, state, 'failed');
|
|
5642
5637
|
}
|
|
5643
5638
|
yield { type: 'error', error: turn.error.message, errorType: toAgentErrorType(turn.error.message) };
|
|
5644
5639
|
}
|
|
@@ -5674,7 +5669,7 @@ export class CodexRunner {
|
|
|
5674
5669
|
break;
|
|
5675
5670
|
}
|
|
5676
5671
|
if (isRetryableError(new Error(message))) {
|
|
5677
|
-
throw createCodexRetryMetadataError(message, state);
|
|
5672
|
+
throw createCodexRetryMetadataError(message, state, params.willRetry === false ? 'failed' : 'unknown');
|
|
5678
5673
|
}
|
|
5679
5674
|
yield { type: 'error', error: message, errorType: toAgentErrorType(message) };
|
|
5680
5675
|
break;
|
package/dist/aun/aid/agentmd.js
CHANGED
|
@@ -705,6 +705,31 @@ export async function agentmdGet(aid, opts) {
|
|
|
705
705
|
catch { /* ignore */ }
|
|
706
706
|
}
|
|
707
707
|
}
|
|
708
|
+
/** Ordinary Agent ownership targets require a freshly verified human card. */
|
|
709
|
+
export async function assertHumanAgentOwner(ownerAid, opts = {}) {
|
|
710
|
+
let card;
|
|
711
|
+
try {
|
|
712
|
+
card = await agentmdGet(ownerAid, { ...opts, withVerification: true, remoteOnly: true });
|
|
713
|
+
}
|
|
714
|
+
catch (cause) {
|
|
715
|
+
throw Object.assign(new Error(`Cannot verify the Owner identity for ${ownerAid}`), {
|
|
716
|
+
code: 'OWNER_IDENTITY_UNAVAILABLE', cause,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
const frontmatter = card.content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
|
|
720
|
+
const document = parseDocument(frontmatter ?? '');
|
|
721
|
+
const fields = document.errors.length === 0 ? document.toJS() : undefined;
|
|
722
|
+
if (card.verification.status !== 'verified' || document.errors.length > 0
|
|
723
|
+
|| !fields || typeof fields !== 'object' || Array.isArray(fields) || fields.aid !== ownerAid
|
|
724
|
+
|| typeof fields.type !== 'string' || !fields.type.trim()) {
|
|
725
|
+
throw Object.assign(new Error(`Cannot verify the Owner identity for ${ownerAid}`), {
|
|
726
|
+
code: 'OWNER_IDENTITY_UNAVAILABLE',
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
if (fields.type !== 'human') {
|
|
730
|
+
throw Object.assign(new Error('An Agent Owner must have type human'), { code: 'INVALID_OWNER' });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
708
733
|
/** Check an existing identity before Agent creation can overwrite its signed card. */
|
|
709
734
|
export async function assertAgentIdentityReusable(aid, opts = {}) {
|
|
710
735
|
let card;
|
|
@@ -14,6 +14,21 @@ import { agentmdPutInitializationProfile, buildInitialAgentMd, invalidateAgentDi
|
|
|
14
14
|
import { logger, logOwnershipEvent } from '../../utils/logger.js';
|
|
15
15
|
const MAX_ATTEMPTS = 5;
|
|
16
16
|
export { DEFAULT_AID_DOMAIN } from './domain.js';
|
|
17
|
+
export function hasLocalControlIdentity(aid, root = resolvePaths().root) {
|
|
18
|
+
if (!isValidAid(aid))
|
|
19
|
+
return false;
|
|
20
|
+
return [['private', 'key.json'], ['public', 'cert.pem']].every(parts => {
|
|
21
|
+
try {
|
|
22
|
+
return fs.statSync(path.join(root, 'AIDs', aid, ...parts)).isFile();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function missingControlIdentityMessage(aid) {
|
|
30
|
+
return `控制 AID ${aid} 的本地证书或私钥缺失。重装 npm 包不能恢复身份;请从可信备份恢复该 AID 的证书和私钥,或明确选择卸载菜单的“完全清除”后重新安装(会删除所有 AIDs、配置与数据)。未自动重新生成 AID。`;
|
|
31
|
+
}
|
|
17
32
|
/** Human-facing platform label used in the control AID's agent.md name. */
|
|
18
33
|
export function controlHostPlatformLabel(platform = process.platform) {
|
|
19
34
|
switch (String(platform).trim().toLowerCase()) {
|
package/dist/aun/aid/identity.js
CHANGED
|
@@ -252,6 +252,10 @@ export async function aidEnsureOwnerBinding(client, aid, ownerAid) {
|
|
|
252
252
|
code: current.code || 'OWNER_BIND_STATE_UNAVAILABLE',
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
|
+
if (client.getType() === 'agent') {
|
|
256
|
+
const { assertHumanAgentOwner } = await import('./agentmd.js');
|
|
257
|
+
await assertHumanAgentOwner(owner);
|
|
258
|
+
}
|
|
255
259
|
const binding = await client.bindOwneraid(owner);
|
|
256
260
|
if (binding.status === 'error' || binding.status === 'rejected' || binding.status === 'stopped') {
|
|
257
261
|
throw Object.assign(new Error(binding.reason || `Owner binding ${binding.status}`), {
|
|
@@ -336,6 +340,10 @@ export async function aidCreate(aid, opts) {
|
|
|
336
340
|
// 新注册流程:AIDStore.register → downloadCaRoot → load → authenticate
|
|
337
341
|
const store = await getAidStore({ slotId: SLOT.cli, aunPath });
|
|
338
342
|
try {
|
|
343
|
+
if ((opts?.type ?? 'agent') === 'agent' && opts?.owner?.trim()) {
|
|
344
|
+
const { assertHumanAgentOwner } = await import('./agentmd.js');
|
|
345
|
+
await assertHumanAgentOwner(opts.owner.trim(), { aunPath, store });
|
|
346
|
+
}
|
|
339
347
|
const regResult = await store.register(aid, {
|
|
340
348
|
type: opts?.type ?? 'agent',
|
|
341
349
|
...(opts?.owner?.trim() ? { owner: opts.owner.trim() } : {}),
|
|
@@ -17,13 +17,17 @@ export function parseOwnershipCommand(argv) {
|
|
|
17
17
|
if (!args[0] || !args[1] || !['bind', 'transfer'].includes(args[0])) {
|
|
18
18
|
throw new OwnershipError('INVALID_ARGUMENT', `Use ${MAIN_CLI_BIN} aid bind <ownerAid>, transfer <subAid> <newOwnerAid>, status, accept, or reject`);
|
|
19
19
|
}
|
|
20
|
-
const action = args[0] === '
|
|
21
|
-
: [
|
|
20
|
+
const action = args[0] === 'bind' && args[1] === 'reject' && args[2] === '--reset' ? 'reset-rejection'
|
|
21
|
+
: args[0] === 'transfer' ? 'transfer'
|
|
22
|
+
: ['status', 'accept', 'reject'].includes(args[1]) ? args[1] : 'bind';
|
|
22
23
|
if (action === 'bind' && !isValidAid(args[1]))
|
|
23
24
|
throw new OwnershipError('INVALID_AID', 'A valid owner AID is required');
|
|
24
25
|
if (action === 'transfer' && (!isValidAid(args[1]) || !isValidAid(args[2] ?? ''))) {
|
|
25
26
|
throw new OwnershipError('INVALID_AID', 'Valid sub and new owner AIDs are required');
|
|
26
27
|
}
|
|
28
|
+
if (action === 'reset-rejection' && !isValidAid(args[3] ?? '')) {
|
|
29
|
+
throw new OwnershipError('INVALID_AID', 'A valid owner AID is required to reset a rejection');
|
|
30
|
+
}
|
|
27
31
|
if ((action === 'accept' || action === 'reject') && !OWNERSHIP_OPERATION_ID.test(args[2] ?? '')) {
|
|
28
32
|
throw new OwnershipError('INVALID_OPERATION', 'A valid ownership operation ID is required');
|
|
29
33
|
}
|
|
@@ -31,7 +35,7 @@ export function parseOwnershipCommand(argv) {
|
|
|
31
35
|
let reason;
|
|
32
36
|
let refresh = false;
|
|
33
37
|
let formatSeen = false;
|
|
34
|
-
const positionalEnd = action === 'bind' || action === 'status' ? 2 : 3;
|
|
38
|
+
const positionalEnd = action === 'reset-rejection' ? 4 : action === 'bind' || action === 'status' ? 2 : 3;
|
|
35
39
|
for (let index = positionalEnd; index < args.length;) {
|
|
36
40
|
const flag = args[index];
|
|
37
41
|
if (flag === '--refresh' && action === 'status' && !refresh) {
|
|
@@ -57,6 +61,8 @@ export function parseOwnershipCommand(argv) {
|
|
|
57
61
|
}
|
|
58
62
|
if (action === 'status')
|
|
59
63
|
return { action, subjectAid, ...(refresh ? { refresh } : {}) };
|
|
64
|
+
if (action === 'reset-rejection')
|
|
65
|
+
return { action, subjectAid, ownerAid: args[3] };
|
|
60
66
|
if (action === 'transfer')
|
|
61
67
|
return { action, subAid: args[1], newOwnerAid: args[2], subjectAid };
|
|
62
68
|
if (action === 'accept')
|
|
@@ -72,6 +78,9 @@ export async function executeOwnershipCommand(command, defaultSubjectAid) {
|
|
|
72
78
|
if (command.action === 'status') {
|
|
73
79
|
return ownerResolver.status(subjectAid, { force: command.refresh === true });
|
|
74
80
|
}
|
|
81
|
+
if (command.action === 'reset-rejection') {
|
|
82
|
+
return ownerResolver.resetRejectedOwnerBinding(subjectAid, command.ownerAid);
|
|
83
|
+
}
|
|
75
84
|
if (command.action === 'accept' || command.action === 'reject') {
|
|
76
85
|
return ownerResolver.decide(subjectAid, command.operationId, command.action, command.action === 'reject' ? command.reason : undefined);
|
|
77
86
|
}
|
|
@@ -285,9 +285,10 @@ export class GroupInviteReviewService {
|
|
|
285
285
|
this.router = router;
|
|
286
286
|
this.store = store;
|
|
287
287
|
this.timer = setInterval(() => {
|
|
288
|
-
for (const runtime of this.bindings.values())
|
|
289
|
-
if (runtime.nextSync <= Date.now())
|
|
288
|
+
for (const runtime of this.bindings.values()) {
|
|
289
|
+
if (runtime.channel.isConnected() && runtime.nextSync <= Date.now())
|
|
290
290
|
this.wake(runtime);
|
|
291
|
+
}
|
|
291
292
|
}, RECONCILE_TICK_MS);
|
|
292
293
|
this.timer.unref?.();
|
|
293
294
|
}
|
|
@@ -21,7 +21,7 @@ import { ServiceProxyClient, EndpointPolicy } from '@agentunion/fastaun';
|
|
|
21
21
|
import { resolvePaths } from '../paths.js';
|
|
22
22
|
import { logger } from '../utils/logger.js';
|
|
23
23
|
import { parseEcwebInstanceRecord } from '../contracts/ecweb-instance.js';
|
|
24
|
-
import {
|
|
24
|
+
import { getProcessStartTimeAsync, startTimeMatches } from '../utils/process-introspect.js';
|
|
25
25
|
const LOG = '[ServiceProxy]';
|
|
26
26
|
const INSTANCE_DISCOVERY_TIMEOUT_MS = 10_000;
|
|
27
27
|
const INSTANCE_DISCOVERY_INTERVAL_MS = 250;
|
|
@@ -33,7 +33,7 @@ function sleep(ms) {
|
|
|
33
33
|
* 读 data/instance/ 下指定服务的存活实例端口。
|
|
34
34
|
* 取 startedAt 最新的一条(多实例保护下通常只有一条存活)。
|
|
35
35
|
*/
|
|
36
|
-
function discoverInstancePort(serviceName, expectedPort) {
|
|
36
|
+
async function discoverInstancePort(serviceName, expectedPort) {
|
|
37
37
|
const dir = resolvePaths().instanceDir;
|
|
38
38
|
let files;
|
|
39
39
|
try {
|
|
@@ -64,14 +64,15 @@ function discoverInstancePort(serviceName, expectedPort) {
|
|
|
64
64
|
&& Number.isFinite(rec.startedAt)
|
|
65
65
|
&& (raw.owner !== 'evolcore-service-supervisor'
|
|
66
66
|
|| ((raw.state === undefined || raw.state === 'ready')
|
|
67
|
-
&& startTimeMatches(rec.startedAt,
|
|
68
|
-
&& (serviceName !== 'ecweb' || !('schemaVersion' in rec) || startTimeMatches(rec.startedAt,
|
|
67
|
+
&& startTimeMatches(rec.startedAt, await getProcessStartTimeAsync(rec.pid))))
|
|
68
|
+
&& (serviceName !== 'ecweb' || !('schemaVersion' in rec) || startTimeMatches(rec.startedAt, await getProcessStartTimeAsync(rec.pid)))
|
|
69
69
|
&& rec.startedAt >= 0
|
|
70
70
|
&& Number.isInteger(rec.port)
|
|
71
71
|
&& rec.port >= 1
|
|
72
72
|
&& rec.port <= 65535
|
|
73
73
|
&& (expectedPort === undefined || rec.port === expectedPort)) {
|
|
74
|
-
|
|
74
|
+
if (isProcessAlive(rec.pid))
|
|
75
|
+
records.push({ pid: rec.pid, port: rec.port, startedAt: rec.startedAt });
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
catch {
|
|
@@ -97,7 +98,7 @@ async function waitForInstancePort(serviceName, expectedPort) {
|
|
|
97
98
|
const deadline = Date.now() + INSTANCE_DISCOVERY_TIMEOUT_MS;
|
|
98
99
|
let loggedWait = false;
|
|
99
100
|
while (Date.now() <= deadline) {
|
|
100
|
-
const port = discoverInstancePort(serviceName, expectedPort);
|
|
101
|
+
const port = await discoverInstancePort(serviceName, expectedPort);
|
|
101
102
|
if (port)
|
|
102
103
|
return port;
|
|
103
104
|
if (!loggedWait) {
|
|
@@ -130,6 +131,14 @@ async function resolveEndpoint(svc) {
|
|
|
130
131
|
logger.warn(`${LOG} 服务 "${svc.name}" 未配置有效 proxy.source,跳过`);
|
|
131
132
|
return null;
|
|
132
133
|
}
|
|
134
|
+
/** Current endpoint only; watching instance files must not start discovery waits. */
|
|
135
|
+
export async function readServiceProxyEndpoint(svc) {
|
|
136
|
+
if (svc.proxy?.source === 'instance') {
|
|
137
|
+
const port = await discoverInstancePort(svc.name, svc.port);
|
|
138
|
+
return port ? `http://127.0.0.1:${port}` : null;
|
|
139
|
+
}
|
|
140
|
+
return svc.proxy?.source === 'static' ? svc.proxy.endpoint?.trim() || null : null;
|
|
141
|
+
}
|
|
133
142
|
/** Probe the local service root without exposing the local endpoint to callers. */
|
|
134
143
|
export async function probeServiceRoot(service) {
|
|
135
144
|
const endpoint = await resolveEndpoint(service);
|
|
@@ -168,6 +177,7 @@ export function startServiceProxy(controlChannel, providerAid, configuredService
|
|
|
168
177
|
let stopped = false;
|
|
169
178
|
let proxyClient = null;
|
|
170
179
|
const startupAbort = new AbortController();
|
|
180
|
+
const endpoints = {};
|
|
171
181
|
const run = async () => {
|
|
172
182
|
try {
|
|
173
183
|
// 控制 AID 与本地服务并行启动;等待认证连接完成,避免把正常启动阶段当作隧道故障。
|
|
@@ -240,6 +250,7 @@ export function startServiceProxy(controlChannel, providerAid, configuredService
|
|
|
240
250
|
metadata: svc.proxy?.metadata ?? {},
|
|
241
251
|
});
|
|
242
252
|
registered += 1;
|
|
253
|
+
endpoints[svc.name] = endpoint;
|
|
243
254
|
logger.info(`${LOG} 注册服务 "${svc.name}" → ${endpoint} (type=${svc.proxy?.serviceType ?? 'http'}, visibility=${svc.proxy?.visibility ?? 'private'})`);
|
|
244
255
|
}
|
|
245
256
|
catch (e) {
|
|
@@ -286,6 +297,7 @@ export function startServiceProxy(controlChannel, providerAid, configuredService
|
|
|
286
297
|
void ready.catch(() => { });
|
|
287
298
|
return {
|
|
288
299
|
ready,
|
|
300
|
+
endpoints,
|
|
289
301
|
unregister: async (serviceNames) => {
|
|
290
302
|
if (!proxyClient || serviceNames.length === 0)
|
|
291
303
|
return;
|