evolcore 0.0.40 → 0.0.41-test.1
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 +94 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +197 -197
- package/dist/agents/codex-runner.js +535 -259
- package/dist/agents/ecagent-runner.js +31 -12
- package/dist/agents/gemini-runner.js +27 -7
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -13
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +72 -11
- package/dist/aun/msg/p2p.js +32 -7
- package/dist/aun/service-proxy.js +36 -12
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +367 -24
- package/dist/channels/daemon.js +39 -5
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +85 -41
- package/dist/cli/daemon-commands.js +678 -688
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +48 -4
- package/dist/cli/managed-command-guard.js +4 -0
- package/dist/cli/model.js +40 -40
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/role.js +85 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +8 -1
- package/dist/config/boot-log.js +38 -1
- package/dist/config/config-field-policy.js +5 -32
- package/dist/config/config-manager.js +46 -39
- package/dist/config/config-operation-service.js +8 -11
- package/dist/config/contact-book-store.js +47 -21
- package/dist/config/contact-book.js +18 -12
- package/dist/config/contact-operation-service.js +3 -4
- package/dist/config/contact-request-service.js +11 -0
- package/dist/config/daemon-services.js +11 -0
- package/dist/config/gateway-config.js +89 -595
- package/dist/config/peer-role-resolver.js +15 -11
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +686 -25
- package/dist/config-store.js +79 -3
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +3 -1
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/agent-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +82 -6
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +37 -9
- package/dist/core/auth/delegation-authorization.js +3 -1
- package/dist/core/auth/operation-authorizer.js +15 -0
- package/dist/core/auth/operation-catalog.js +39 -6
- package/dist/core/command/agent-control.js +94 -19
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +2 -1
- package/dist/core/command/command-handler.js +105 -145
- package/dist/core/command/connect-menu.js +31 -2
- package/dist/core/command/data-root-resolver.js +5 -4
- package/dist/core/command/memory-slash.js +16 -8
- package/dist/core/command/menu-catalog.js +6 -6
- package/dist/core/command/menu-handler.js +87 -163
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +148 -30
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +157 -352
- package/dist/core/daemon-control.js +8 -14
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/evolagent-registry.js +4 -4
- package/dist/core/evolagent.js +2 -2
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/ipc-registration.js +24 -3
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +1 -1
- package/dist/core/memory/consolidation-trigger.js +190 -190
- package/dist/core/memory/consolidation.js +316 -29
- package/dist/core/memory/forget-log.js +96 -0
- package/dist/core/memory/index-manager.js +27 -5
- package/dist/core/memory/memory-admin.js +45 -5
- package/dist/core/memory/memory-writer.js +163 -18
- package/dist/core/memory/relation-idle-monitor.js +119 -58
- package/dist/core/memory/relation-sweep.js +44 -39
- package/dist/core/message/aun-ipc-sender.js +34 -7
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +11 -4
- package/dist/core/message/message-admission.js +97 -8
- package/dist/core/message/message-bridge.js +71 -24
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +387 -144
- package/dist/core/model/catalog-service.js +4 -2
- package/dist/core/model/config-scope.js +24 -64
- package/dist/core/model/field-scope.js +1 -1
- package/dist/core/model/model-catalog.js +37 -47
- package/dist/core/model/model-diagnostics.js +4 -3
- package/dist/core/model/model-fallback.js +10 -7
- package/dist/core/model/model-permission.js +3 -2
- package/dist/core/ownership/owner-resolver.js +25 -23
- package/dist/core/permission/ec-command-parser.js +138 -5
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +42 -10
- package/dist/core/relation/peer-identity.js +64 -1
- package/dist/core/role/runtime-policy.js +72 -13
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +168 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/core/session/session-renew.js +3 -3
- package/dist/core/skill/index-generator.js +15 -5
- package/dist/core/system-session/memory.js +6 -1
- package/dist/core/thread/thread-service.js +19 -6
- package/dist/directory/owner-directory-admission.js +95 -0
- package/dist/directory/owner-directory-authorization.js +309 -0
- package/dist/directory/owner-directory-cache.js +635 -0
- package/dist/eck/kit-renderer.js +2 -2
- package/dist/ecweb/basic-settings-service.js +33 -40
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +79 -17
- package/dist/ipc.js +189 -17
- package/dist/paths.js +4 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +485 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +16 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +5 -3
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +18 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +16 -0
- package/kits/docs/evolcore/memory-architecture.md +2 -2
- package/kits/docs/evolcore/memory-consolidation.md +32 -8
- package/kits/docs/evolcore/memory.md +1 -1
- package/kits/docs/evolcore/menu-protocol.md +36 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +21 -8
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/schemas/_meta.json +37 -4
- package/kits/schemas/agent-config.schema.13.json +23 -3
- package/kits/schemas/agent-config.schema.16.json +891 -0
- package/kits/schemas/daemon.schema.9.json +366 -0
- package/kits/schemas/defaults.schema.5.json +406 -127
- package/kits/schemas/relation-config.schema.11.json +260 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +3 -7
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-trigger/SKILL.md +13 -5
- package/kits/skills/personal-assistant/SKILL.md +176 -0
- package/kits/skills/personal-assistant/references/01-workspace-spec.md +333 -0
- package/kits/skills/personal-assistant/references/02-bootstrap.md +205 -0
- package/kits/skills/personal-assistant/references/03-data-flow-and-gaps.md +177 -0
- package/kits/skills/personal-assistant/references/04-frontend-contract.md +439 -0
- package/kits/skills/personal-assistant/references/05-directory-reference.md +292 -0
- package/kits/skills/personal-assistant/references/06-render-config.md +350 -0
- package/kits/skills/personal-assistant/schema/workspace.schema.json +85 -0
- package/kits/skills/personal-assistant/schema/workspace.v1.json +66 -0
- package/kits/skills/personal-assistant/scripts/archive.mjs +154 -0
- package/kits/skills/personal-assistant/scripts/check.mjs +114 -0
- package/kits/skills/personal-assistant/scripts/index-rebuild.mjs +252 -0
- package/kits/skills/personal-assistant/scripts/ingest.mjs +344 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +270 -0
- package/kits/skills/personal-assistant/scripts/lib/apply.mjs +92 -0
- package/kits/skills/personal-assistant/scripts/lib/schema.mjs +96 -0
- package/kits/skills/personal-assistant/scripts/lib/time.mjs +28 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/search.mjs +172 -0
- package/kits/skills/personal-assistant/scripts/verify.mjs +196 -0
- package/kits/skills/personal-assistant/templates/INDEX.md.tpl +24 -0
- package/kits/skills/personal-assistant/templates/README.md.tpl +108 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/memory-consolidate.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-daily.json +23 -0
- package/kits/skills/personal-assistant/triggers/report-weekly.json +23 -0
- package/kits/templates/memory-consolidation/forget.md +19 -6
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/memory-consolidation/profile.md +2 -2
- package/kits/templates/memory-consolidation/promote.md +20 -3
- package/kits/templates/roles/member.json +8 -1
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +7 -3
- package/dist/stats/billing.js +0 -215
|
@@ -19,8 +19,8 @@ import { auditToolPreflightDenial } from '../core/auth/authorization-audit.js';
|
|
|
19
19
|
import { resolveEcagentConfig } from './baseagent.js';
|
|
20
20
|
import { resolveProviderServiceForBaseagent } from '../config/providers.js';
|
|
21
21
|
import { buildModelRequestHeaders } from './request-identity.js';
|
|
22
|
+
import { getGatewayPricing as getSharedGatewayPricing, resolveModelSpec } from '../stats/price-resolver.js';
|
|
22
23
|
import { appendRequestPath } from './request-identity.js';
|
|
23
|
-
import { resolveModelSpec } from '../stats/billing.js';
|
|
24
24
|
import { getManagedTaskTempDir } from '../cli/task-context.js';
|
|
25
25
|
import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext } from './runner-types.js';
|
|
26
26
|
const PROVIDER_ID = 'evolcore-gateway';
|
|
@@ -795,11 +795,17 @@ export class EcagentRunner {
|
|
|
795
795
|
setSendPrompt(fn) { this.sendPromptFn = fn; }
|
|
796
796
|
setPermissionContext(sessionId, context) { this.permissionContexts.set(sessionId, context); }
|
|
797
797
|
setCompactStartCallback(callback) { this.onCompactStart = callback; }
|
|
798
|
+
/** 返回当前网关 /v1/models 的价格缓存(1h TTL,stale-while-revalidate)。
|
|
799
|
+
* 缺失/过期时异步触发刷新,本轮先返回旧值或 undefined(回退本地价表)。 */
|
|
800
|
+
getGatewayPricing() {
|
|
801
|
+
const conn = this.currentProviderConfig();
|
|
802
|
+
return getSharedGatewayPricing(conn.baseUrl, conn.apiKey, conn.headers);
|
|
803
|
+
}
|
|
798
804
|
currentProviderConfig(providerOverride) {
|
|
799
805
|
const providerId = providerOverride ?? this.config.providerId;
|
|
800
806
|
if (!providerId)
|
|
801
807
|
return this.config;
|
|
802
|
-
const provider = resolveProviderServiceForBaseagent(providerId, 'ecagent'
|
|
808
|
+
const provider = resolveProviderServiceForBaseagent(providerId, 'ecagent');
|
|
803
809
|
if (provider.style !== 'openai-compatible') {
|
|
804
810
|
throw new Error(`Provider ${providerId} uses unsupported ecagent style: ${provider.style}`);
|
|
805
811
|
}
|
|
@@ -925,7 +931,13 @@ export class EcagentRunner {
|
|
|
925
931
|
const connection = this.currentProviderConfig(request.modelOverride?.provider);
|
|
926
932
|
await fs.promises.mkdir(request.projectPath, { recursive: true });
|
|
927
933
|
const previousRuntime = this.runtimes.get(request.sessionId);
|
|
928
|
-
const runtime = await this.getOrCreateRuntime(request.sessionId, request.projectPath, request.initialAgentSessionId, request.modelOverride)
|
|
934
|
+
const runtime = await this.getOrCreateRuntime(request.sessionId, request.projectPath, request.initialAgentSessionId, request.modelOverride, async (oldId) => {
|
|
935
|
+
if (!request.modelOverride?.capsule)
|
|
936
|
+
return;
|
|
937
|
+
const recovered = await request.modelOverride.capsule.recover(oldId, request.prompt, request.systemPromptAppend);
|
|
938
|
+
request.prompt = recovered.prompt;
|
|
939
|
+
request.systemPromptAppend = recovered.systemPrompt;
|
|
940
|
+
});
|
|
929
941
|
if (lifecycle.cancelled)
|
|
930
942
|
throw new Error('ecagent run interrupted');
|
|
931
943
|
if (previousRuntime !== runtime) {
|
|
@@ -989,13 +1001,20 @@ export class EcagentRunner {
|
|
|
989
1001
|
const decision = await this.authorizeTool(request.sessionId, request.projectPath, permissionMode, event.toolName, event.input, stats.numTurns + 1);
|
|
990
1002
|
return lifecycle.cancelled || signal?.aborted ? { block: true, reason: '工具调用已取消' } : decision;
|
|
991
1003
|
});
|
|
992
|
-
|
|
1004
|
+
let inputAccepted = false;
|
|
1005
|
+
const unsubscribe = harness.subscribe(event => {
|
|
1006
|
+
// The harness persists a user message before publishing message_end.
|
|
1007
|
+
// Failures in createTurnState/before_agent_start must leave context pending.
|
|
1008
|
+
if (!inputAccepted && event.type === 'message_end' && event.message.role === 'user') {
|
|
1009
|
+
inputAccepted = true;
|
|
1010
|
+
if (request.modelOverride?.turn?.inputId) {
|
|
1011
|
+
queue.push({ type: 'input_accepted', inputId: request.modelOverride.turn.inputId });
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
this.mapHarnessEvent(queue, event, stats, model, effort);
|
|
1015
|
+
});
|
|
993
1016
|
queue.push({ type: 'state_changed', state: 'running' });
|
|
994
1017
|
queue.push({ type: 'status', subtype: 'started', message: `ecagent is using ${modelId}` });
|
|
995
|
-
// Ecagent 输入在 harness.prompt 调用时提交,在此前报告
|
|
996
|
-
if (request.modelOverride?.turn?.inputId) {
|
|
997
|
-
queue.push({ type: 'input_accepted', inputId: request.modelOverride.turn.inputId });
|
|
998
|
-
}
|
|
999
1018
|
const ecImages = request.images?.map(image => ({
|
|
1000
1019
|
type: 'image', data: image.data, mimeType: image.mimeType || 'image/png',
|
|
1001
1020
|
}));
|
|
@@ -1071,7 +1090,7 @@ export class EcagentRunner {
|
|
|
1071
1090
|
queue.end();
|
|
1072
1091
|
}
|
|
1073
1092
|
}
|
|
1074
|
-
async getOrCreateRuntime(sessionId, projectPath, requestedId, modelOverride) {
|
|
1093
|
+
async getOrCreateRuntime(sessionId, projectPath, requestedId, modelOverride, recover) {
|
|
1075
1094
|
const current = this.runtimes.get(sessionId);
|
|
1076
1095
|
const topicBinding = modelOverride?.backend?.kind === 'topic';
|
|
1077
1096
|
const requestedTopicAgentSessionId = topicBinding
|
|
@@ -1086,6 +1105,7 @@ export class EcagentRunner {
|
|
|
1086
1105
|
}
|
|
1087
1106
|
if (current && !recoverySessionId
|
|
1088
1107
|
&& current.projectPath === projectPath
|
|
1108
|
+
&& !!this.resolveSessionFile(current.agentSessionId, projectPath)
|
|
1089
1109
|
&& (!targetId || current.agentSessionId === targetId)
|
|
1090
1110
|
&& (!topicBinding || (!!targetId && current.agentSessionId === targetId)))
|
|
1091
1111
|
return current;
|
|
@@ -1104,6 +1124,7 @@ export class EcagentRunner {
|
|
|
1104
1124
|
throw error;
|
|
1105
1125
|
}
|
|
1106
1126
|
logger.warn(`[EcagentRunner] backing session ${targetId} was not found; creating a new session`);
|
|
1127
|
+
await recover?.(targetId);
|
|
1107
1128
|
session = await repo.create({ cwd: projectPath });
|
|
1108
1129
|
}
|
|
1109
1130
|
else
|
|
@@ -1113,9 +1134,7 @@ export class EcagentRunner {
|
|
|
1113
1134
|
// Topic UNBOUND is an explicit backend boundary. Let ecagent allocate a
|
|
1114
1135
|
// fresh provider ID; reusing the EvolCore Session ID would make every
|
|
1115
1136
|
// /renew cycle reopen the same provider session under a new filename.
|
|
1116
|
-
session =
|
|
1117
|
-
? await repo.create({ cwd: projectPath })
|
|
1118
|
-
: await repo.create({ cwd: projectPath, id: sessionId });
|
|
1137
|
+
session = await repo.create({ cwd: projectPath });
|
|
1119
1138
|
}
|
|
1120
1139
|
const metadata = await session.getMetadata();
|
|
1121
1140
|
if (recoverySessionId && metadata.id !== recoverySessionId) {
|
|
@@ -26,6 +26,7 @@ import { GeminiSessionFileAdapter } from '../core/session/adapters/gemini-sessio
|
|
|
26
26
|
import { logger } from '../utils/logger.js';
|
|
27
27
|
import { normalizeExecutionPermissionMode, normalizePermissionMode } from '../core/permission/mode.js';
|
|
28
28
|
import { resolveRoot } from '../paths.js';
|
|
29
|
+
import { getGatewayPricing as getSharedGatewayPricing } from '../stats/price-resolver.js';
|
|
29
30
|
import { workspaceContainsHClassPaths } from '../core/permission/protected-paths.js';
|
|
30
31
|
import { buildBubblewrapCommand } from '../core/permission/sandbox-runtime.js';
|
|
31
32
|
import { getManagedTaskTempDir } from '../cli/task-context.js';
|
|
@@ -337,6 +338,12 @@ export class GeminiRunner {
|
|
|
337
338
|
// ── ModelSwitcher ──
|
|
338
339
|
setModel(model) { this.model = stripContextWindowSuffix(model); }
|
|
339
340
|
getModel() { return this.model; }
|
|
341
|
+
/** 返回当前网关 /v1/models 的价格缓存(1h TTL,stale-while-revalidate)。
|
|
342
|
+
* 缺失/过期时异步触发刷新,本轮先返回旧值或 undefined(回退本地价表)。 */
|
|
343
|
+
getGatewayPricing() {
|
|
344
|
+
const conn = this.currentProviderConfig();
|
|
345
|
+
return getSharedGatewayPricing(conn.baseUrl, conn.apiKey, conn.headers);
|
|
346
|
+
}
|
|
340
347
|
getModelCatalog() {
|
|
341
348
|
return getRunnerCatalog('gemini', this.agentAid, this.currentProviderConfig());
|
|
342
349
|
}
|
|
@@ -362,7 +369,7 @@ export class GeminiRunner {
|
|
|
362
369
|
}
|
|
363
370
|
currentProviderConfig(providerOverride) {
|
|
364
371
|
const config = this.agentAid
|
|
365
|
-
? { agents: { gemini: resolveEffective({ self: this.agentAid }, { cache: true
|
|
372
|
+
? { agents: { gemini: resolveEffective({ self: this.agentAid }, { cache: true }).baseagents?.gemini ?? this.config.agents?.gemini } }
|
|
366
373
|
: this.config;
|
|
367
374
|
return resolveGoogleConfig(config, providerOverride ? { provider: providerOverride } : undefined);
|
|
368
375
|
}
|
|
@@ -413,6 +420,18 @@ export class GeminiRunner {
|
|
|
413
420
|
let geminiSessionId = topicBinding
|
|
414
421
|
? (topicAgentSessionId || undefined)
|
|
415
422
|
: initialAgentSessionId || cachedSessionId;
|
|
423
|
+
if (!topicBinding && !initialAgentSessionId && typeof sessionManager?.getSessionById === 'function') {
|
|
424
|
+
const latest = await sessionManager.getSessionById(sessionId);
|
|
425
|
+
geminiSessionId = latest?.agentSessionId || undefined;
|
|
426
|
+
}
|
|
427
|
+
if (!topicBinding && geminiSessionId && modelOverride?.capsule
|
|
428
|
+
&& !this.resolveSessionFile(geminiSessionId, projectPath)) {
|
|
429
|
+
const recovered = await modelOverride.capsule.recover(geminiSessionId, prompt, systemPromptAppend);
|
|
430
|
+
prompt = recovered.prompt;
|
|
431
|
+
systemPromptAppend = recovered.systemPrompt;
|
|
432
|
+
this.activeSessions.delete(sessionId);
|
|
433
|
+
geminiSessionId = undefined;
|
|
434
|
+
}
|
|
416
435
|
// per-call 权限模式/模型:优先 override,缺省回落实例级(多会话并发互不污染)
|
|
417
436
|
const requestedPermissionMode = modelOverride?.permissionMode || this.currentMode;
|
|
418
437
|
const executionPermissionMode = normalizeExecutionPermissionMode(requestedPermissionMode);
|
|
@@ -539,10 +558,7 @@ export class GeminiRunner {
|
|
|
539
558
|
const pendingToolNames = new Map(); // toolId → toolName
|
|
540
559
|
const recordedDeniedToolIds = new Set();
|
|
541
560
|
const startTime = Date.now();
|
|
542
|
-
|
|
543
|
-
if (turn?.inputId) {
|
|
544
|
-
yield { type: 'input_accepted', inputId: turn.inputId };
|
|
545
|
-
}
|
|
561
|
+
let inputAccepted = false;
|
|
546
562
|
const rl = createInterface({ input: child.stdout });
|
|
547
563
|
// Build async queue from readline
|
|
548
564
|
const queue = [];
|
|
@@ -631,9 +647,13 @@ export class GeminiRunner {
|
|
|
631
647
|
break;
|
|
632
648
|
}
|
|
633
649
|
case 'message': {
|
|
634
|
-
|
|
635
|
-
|
|
650
|
+
if (event.role === 'user') {
|
|
651
|
+
if (!inputAccepted && turn?.inputId) {
|
|
652
|
+
inputAccepted = true;
|
|
653
|
+
yield { type: 'input_accepted', inputId: turn.inputId };
|
|
654
|
+
}
|
|
636
655
|
break;
|
|
656
|
+
}
|
|
637
657
|
// Assistant message (delta=true → streaming)
|
|
638
658
|
// Accumulate into textBuffer; will flush on boundary event
|
|
639
659
|
if (event.role === 'assistant' && event.content) {
|
|
@@ -119,20 +119,28 @@ export function hasClearSession(agent) {
|
|
|
119
119
|
export function numericToken(value) {
|
|
120
120
|
return typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
121
121
|
}
|
|
122
|
-
export function contextTokensForUsage(usage,
|
|
122
|
+
export function contextTokensForUsage(usage, model) {
|
|
123
123
|
if (!usage)
|
|
124
124
|
return 0;
|
|
125
|
-
|
|
125
|
+
// GPT keeps its reported input count; other models report cache separately.
|
|
126
|
+
if (isGptContextUsageModel(model))
|
|
126
127
|
return numericToken(usage.input_tokens);
|
|
127
128
|
return numericToken(usage.input_tokens)
|
|
129
|
+
+ numericToken(usage.output_tokens)
|
|
128
130
|
+ numericToken(usage.cache_creation_input_tokens)
|
|
129
131
|
+ numericToken(usage.cache_read_input_tokens);
|
|
130
132
|
}
|
|
131
133
|
export function usageForContext(usage) {
|
|
132
134
|
const iterations = Array.isArray(usage?.iterations) ? usage.iterations : undefined;
|
|
133
|
-
const lastIteration = iterations?.slice().reverse().find(it => contextTokensForUsage(it
|
|
135
|
+
const lastIteration = iterations?.slice().reverse().find(it => contextTokensForUsage(it) > 0);
|
|
134
136
|
return lastIteration ?? usage;
|
|
135
137
|
}
|
|
138
|
+
export function isGptContextUsageModel(model) {
|
|
139
|
+
if (!model)
|
|
140
|
+
return false;
|
|
141
|
+
const modelId = stripContextWindowSuffix(model).trim().split(/[/:]/).at(-1) ?? '';
|
|
142
|
+
return /^(?:gpt|chatgpt|o[134])(?:[-.]|$)/i.test(modelId);
|
|
143
|
+
}
|
|
136
144
|
/** Models whose base ID uses a 1M context window when sent to the SDK with [1m]. */
|
|
137
145
|
export const ONE_M_CONTEXT_MODEL_PREFIXES = ['claude-opus-5', 'claude-opus-4-8', 'claude-sonnet-4-6'];
|
|
138
146
|
const ONE_M_CONTEXT_MODEL_ALIASES = ['opus', 'sonnet'];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Only this read-only query collects responses from every online device. */
|
|
2
|
+
export function isAidWideDeviceStatusQuery(payload) {
|
|
3
|
+
const params = payload?.params;
|
|
4
|
+
return payload?.type === 'ability' && payload.role === 'call'
|
|
5
|
+
&& payload.ability_path === 'device/status'
|
|
6
|
+
&& !!params && typeof params === 'object' && !Array.isArray(params)
|
|
7
|
+
&& params.action === 'read';
|
|
8
|
+
}
|
|
9
|
+
/** Device routing belongs to message.send, never to the Ability payload. */
|
|
10
|
+
export function resolveAunSendDevice(deviceId, scope, payload) {
|
|
11
|
+
if (deviceId !== undefined && (scope !== 'msg' || typeof deviceId !== 'string'
|
|
12
|
+
|| !deviceId || deviceId.length > 256 || /[\s\x00-\x1f\x7f]/.test(deviceId))) {
|
|
13
|
+
throw Object.assign(new Error('--device-id requires a nonempty private target device ID'), { code: 'INVALID_DEVICE_ID' });
|
|
14
|
+
}
|
|
15
|
+
if (isAidWideDeviceStatusQuery(payload)) {
|
|
16
|
+
if (scope !== 'msg' || deviceId !== undefined) {
|
|
17
|
+
throw Object.assign(new Error('device/status queries the AID online devices; omit --device-id and use a private AID target'), { code: 'ABILITY_DEVICE_NOT_ALLOWED' });
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (payload?.type === 'ability' && payload.role === 'call'
|
|
22
|
+
&& payload.ability_path !== 'protocol/discover' && !deviceId) {
|
|
23
|
+
throw Object.assign(new Error('Select a device from the Provider ability index and pass --device-id; business Ability calls cannot broadcast to every device'), { code: 'ABILITY_DEVICE_REQUIRED' });
|
|
24
|
+
}
|
|
25
|
+
return deviceId;
|
|
26
|
+
}
|
package/dist/aun/aid/client.js
CHANGED
|
@@ -39,7 +39,7 @@ export function suppressSdkLogs() {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
// ==================== SDK package ====================
|
|
42
|
-
export const MIN_AUN_CORE_SDK = [0, 5,
|
|
42
|
+
export const MIN_AUN_CORE_SDK = [0, 5, 26];
|
|
43
43
|
export const AUN_CORE_SDK_PKG = '@agentunion/fastaun';
|
|
44
44
|
function compareVersion(a, min) {
|
|
45
45
|
const parts = a.split('.').map(n => parseInt(n, 10));
|
|
@@ -56,6 +56,45 @@ export async function readPersonalFsBytesWithinBudget(client, path, maxBytes, op
|
|
|
56
56
|
throw new FsReadBudgetError(maxBytes);
|
|
57
57
|
return bytes;
|
|
58
58
|
}
|
|
59
|
+
export class AuthoritativeFsReadError extends Error {
|
|
60
|
+
code;
|
|
61
|
+
constructor(code, message) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.code = code;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Full authenticated RPC read for private ACLs; never requests an HTTP ticket. */
|
|
67
|
+
export async function readAuthoritativePersonalFsObject(client, path, owner, maxBytes) {
|
|
68
|
+
validateFsReadBudget(maxBytes);
|
|
69
|
+
if (!path.startsWith('/') || path.endsWith('/') || path.includes('\\') ||
|
|
70
|
+
/[\u0000-\u001f\u007f]/.test(path) || path.slice(1).split('/').some(p => !p || p === '.' || p === '..')) {
|
|
71
|
+
throw new AuthoritativeFsReadError('INVALID_PATH', 'authoritative cat requires a canonical absolute object path');
|
|
72
|
+
}
|
|
73
|
+
const key = path.slice(1);
|
|
74
|
+
const value = await client.call('storage.get_object', {
|
|
75
|
+
owner_aid: owner, bucket: 'default', object_key: key, consistency: 'authoritative',
|
|
76
|
+
});
|
|
77
|
+
if (!isRecord(value) || value.owner_aid !== owner || value.bucket !== 'default' ||
|
|
78
|
+
(value.object_key ?? (typeof value.path === 'string' ? value.path.replace(/^\//, '') : undefined)) !== key) {
|
|
79
|
+
throw new AuthoritativeFsReadError('FS_INVALID_OBJECT', 'authoritative response identity/path mismatch');
|
|
80
|
+
}
|
|
81
|
+
if (value.exists === false)
|
|
82
|
+
throw new AuthoritativeFsReadError('FS_NOT_FOUND', 'authoritative object is absent or inaccessible');
|
|
83
|
+
if (value.exists !== true || !Number.isSafeInteger(value.version) || value.version < 1 ||
|
|
84
|
+
!Number.isSafeInteger(value.size_bytes) || value.size_bytes < 0 || typeof value.content !== 'string' ||
|
|
85
|
+
typeof value.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(value.sha256)) {
|
|
86
|
+
throw new AuthoritativeFsReadError('FS_INVALID_OBJECT', 'authoritative response metadata is incomplete');
|
|
87
|
+
}
|
|
88
|
+
if (value.size_bytes > maxBytes || value.content.length > 4 * Math.ceil(maxBytes / 3)) {
|
|
89
|
+
throw new FsReadBudgetError(maxBytes);
|
|
90
|
+
}
|
|
91
|
+
const bytes = Buffer.from(value.content, 'base64');
|
|
92
|
+
if (bytes.toString('base64') !== value.content || bytes.length !== value.size_bytes || sha256Hex(bytes) !== value.sha256) {
|
|
93
|
+
throw new AuthoritativeFsReadError('FS_INVALID_OBJECT', 'authoritative content encoding, size or hash mismatch');
|
|
94
|
+
}
|
|
95
|
+
const { content: _content, ...metadata } = value;
|
|
96
|
+
return { bytes, metadata };
|
|
97
|
+
}
|
|
59
98
|
export class GroupFsDownloadError extends Error {
|
|
60
99
|
code;
|
|
61
100
|
constructor(code, message) {
|
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
/** Resolve a peer kind from authoritative evidence; AID spelling is never evidence. */
|
|
4
|
+
export function resolveAunTargetKind(evidence) {
|
|
5
|
+
const candidates = [];
|
|
6
|
+
const sources = [];
|
|
7
|
+
for (const [source, kind] of [['route', evidence.routeKind], ['relation', evidence.targetKind]]) {
|
|
8
|
+
if (kind === undefined)
|
|
9
|
+
continue;
|
|
10
|
+
if (kind !== 'private' && kind !== 'group')
|
|
11
|
+
return { kind: 'unknown', reason: 'invalid', sources };
|
|
12
|
+
candidates.push(kind);
|
|
13
|
+
sources.push(source);
|
|
14
|
+
}
|
|
15
|
+
if (evidence.verifiedType !== undefined) {
|
|
16
|
+
if (typeof evidence.verifiedType !== 'string' || !evidence.verifiedType.trim()) {
|
|
17
|
+
return { kind: 'unknown', reason: 'invalid', sources };
|
|
18
|
+
}
|
|
19
|
+
if (evidence.verifiedType.trim().toLowerCase() === 'unknown') {
|
|
20
|
+
return { kind: 'unknown', reason: 'invalid', sources };
|
|
21
|
+
}
|
|
22
|
+
candidates.push(evidence.verifiedType.trim().toLowerCase() === 'group' ? 'group' : 'private');
|
|
23
|
+
sources.push('agentmd');
|
|
24
|
+
}
|
|
25
|
+
if (!candidates.length)
|
|
26
|
+
return { kind: 'unknown', reason: 'missing', sources };
|
|
27
|
+
if (candidates.some(kind => kind !== candidates[0]))
|
|
28
|
+
return { kind: 'unknown', reason: 'conflict', sources };
|
|
29
|
+
return { kind: candidates[0], reason: 'resolved', sources };
|
|
30
|
+
}
|
|
31
|
+
/** Accept cached type evidence only after signature verification for this exact AID. */
|
|
32
|
+
export function verifiedPeerType(targetAid, identity) {
|
|
33
|
+
if (identity?.aid !== targetAid || identity.source !== 'agentmd'
|
|
34
|
+
|| !Number.isFinite(identity.verifiedAt) || !(identity.verifiedAt > 0) || identity.lastCheckedAt === 0) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return typeof identity.type === 'string' && identity.type.trim() ? identity.type.trim() : undefined;
|
|
38
|
+
}
|
|
3
39
|
const requireSdk = createRequire(import.meta.url);
|
|
4
40
|
let groupValidator;
|
|
5
41
|
/** Validate a group command argument, expanding a local base to a full AID. */
|
|
@@ -28,16 +64,3 @@ export function sameGroupAid(left, right) {
|
|
|
28
64
|
return false;
|
|
29
65
|
}
|
|
30
66
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Legacy group identity hint, NOT a format validator. Canonical group AIDs and
|
|
33
|
-
* private AIDs share a syntax; prefer trusted chat/targetKind information.
|
|
34
|
-
* Do not broaden this predicate to every SDK-valid group argument.
|
|
35
|
-
*/
|
|
36
|
-
export function isExplicitGroupId(value) {
|
|
37
|
-
const id = value.trim();
|
|
38
|
-
if (!id)
|
|
39
|
-
return false;
|
|
40
|
-
return /^\d+\.[a-z0-9.-]+$/i.test(id)
|
|
41
|
-
|| /^grp_[a-z0-9_-]+$/i.test(id)
|
|
42
|
-
|| /^g-[a-z0-9_-]+(?:[.@][a-z0-9.-]+)?$/i.test(id);
|
|
43
|
-
}
|
|
@@ -63,6 +63,11 @@ export function applyGroupRoutingPayloadFields(payload, args, runtimeContext) {
|
|
|
63
63
|
payload.thread_id = threadId;
|
|
64
64
|
else if (payload.thread_id !== undefined)
|
|
65
65
|
delete payload.thread_id;
|
|
66
|
+
// Mark the final user-visible text message so the wire ext carries isFinal.
|
|
67
|
+
// buildWireExt (daemon side) merges this into the outgoing ext dictionary.
|
|
68
|
+
if (payload.type === 'text') {
|
|
69
|
+
payload.ext = { isFinal: true, ...(payload.ext && typeof payload.ext === 'object' && !Array.isArray(payload.ext) ? payload.ext : {}) };
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
function groupSendLogMetadata(args, payload, runtimeContext) {
|
|
68
73
|
const classified = payload ? classifyAunPayloadForLog(payload) : undefined;
|
|
@@ -9,7 +9,7 @@ import { isValidAid } from '../aid/validation.js';
|
|
|
9
9
|
import { tryParseChannelKey } from '../../core/channel-loader.js';
|
|
10
10
|
import { normalizeThreadOptionValue } from '../../core/thread/topic-id.js';
|
|
11
11
|
import { parseTimeArg, TIME_ARG_FORMATS } from '../../cli/cli-argv.js';
|
|
12
|
-
import { DEFAULT_FS_CAT_BYTES, MAX_FS_CAT_BYTES, FsReadBudgetError, downloadGroupFsBytes, readPersonalFsBytesWithinBudget, } from '../group/fs-download.js';
|
|
12
|
+
import { DEFAULT_FS_CAT_BYTES, MAX_FS_CAT_BYTES, FsReadBudgetError, downloadGroupFsBytes, readPersonalFsBytesWithinBudget, readAuthoritativePersonalFsObject, AuthoritativeFsReadError, } from '../group/fs-download.js';
|
|
13
13
|
import { groupBan, groupBanlist, groupBlock, groupUnblock, groupBlocklist, groupReportStatus, groupMemberStatuses, groupCreate, groupDissolve, groupInfo, groupInvite, groupJoin, groupKick, groupLeave, groupList, groupMembers, groupOnline, groupPull, groupAck, groupAcceptInvite, groupInvites, groupRejectInvite, groupRevokeInvite, groupResume, groupRules, groupRulesFileGet, groupRulesFilePublish, groupRulesFileSet, groupSetRole, groupSuspend, groupTransferOwner, groupUnban, groupUpdate, groupUpdateRules, } from '../group/operations.js';
|
|
14
14
|
import { handleGroupMenu, GroupMenuError } from '../../core/command/group-menu.js';
|
|
15
15
|
import { readRolesConfig } from '../../config/roles.js';
|
|
@@ -803,9 +803,9 @@ export class ManagedFsOperationError extends Error {
|
|
|
803
803
|
}
|
|
804
804
|
const FS_VALUE_FLAGS = new Set([
|
|
805
805
|
'--as', '--format', '--max-bytes', '--head-bytes', '--name', '--pattern', '--type', '--node-type',
|
|
806
|
-
'--size', '--mtime', '--page', '--page-size', '-m', '-x',
|
|
806
|
+
'--size', '--mtime', '--page', '--page-size', '-m', '-x', '--expires',
|
|
807
807
|
]);
|
|
808
|
-
const FS_BOOLEAN_FLAGS = new Set(['-p', '--parents', '-r', '--recursive', '-f', '--force', '--overwrite']);
|
|
808
|
+
const FS_BOOLEAN_FLAGS = new Set(['-p', '--parents', '-r', '--recursive', '-f', '--force', '--overwrite', '--authoritative']);
|
|
809
809
|
function failFs(code, reason) {
|
|
810
810
|
return { ok: false, code, reason };
|
|
811
811
|
}
|
|
@@ -820,12 +820,32 @@ function positiveInteger(value, flag, max) {
|
|
|
820
820
|
}
|
|
821
821
|
return number;
|
|
822
822
|
}
|
|
823
|
+
const MAX_MANAGED_LINK_SECONDS = 7 * 24 * 3600;
|
|
824
|
+
/** Parse --expires: bare seconds, or a duration such as 30m / 12h / 7d; 0 means no expiry. */
|
|
825
|
+
function parseManagedLinkExpiry(value) {
|
|
826
|
+
if (value === undefined)
|
|
827
|
+
return undefined;
|
|
828
|
+
const text = value.trim().toLowerCase();
|
|
829
|
+
if (!text)
|
|
830
|
+
return failFs('INVALID_ARGUMENT', '--expires requires a duration');
|
|
831
|
+
const match = /^(\d+)([smhd])?$/.exec(text);
|
|
832
|
+
if (!match)
|
|
833
|
+
return failFs('INVALID_ARGUMENT', '--expires accepts seconds, 30m, 12h, 7d, or 0 for a non-expiring link');
|
|
834
|
+
const unit = match[2] === undefined
|
|
835
|
+
? 1
|
|
836
|
+
: { s: 1, m: 60, h: 3600, d: 86400 }[match[2]];
|
|
837
|
+
const seconds = Number(match[1]) * unit;
|
|
838
|
+
if (!Number.isSafeInteger(seconds) || seconds < 0 || seconds > MAX_MANAGED_LINK_SECONDS) {
|
|
839
|
+
return failFs('INVALID_ARGUMENT', `--expires must be between 0 and ${MAX_MANAGED_LINK_SECONDS} seconds`);
|
|
840
|
+
}
|
|
841
|
+
return seconds;
|
|
842
|
+
}
|
|
823
843
|
function parseRemote(value, allowEmpty) {
|
|
824
844
|
if (!value)
|
|
825
845
|
return failFs('INVALID_ARGUMENT', 'missing remote storage path');
|
|
826
846
|
const separator = value.indexOf(':');
|
|
827
847
|
if (separator <= 0)
|
|
828
|
-
return failFs('INVALID_PATH', 'remote path must use <
|
|
848
|
+
return failFs('INVALID_PATH', 'remote path must use <AID>:<absolute-path>');
|
|
829
849
|
let targetAid;
|
|
830
850
|
const remotePath = value.slice(separator + 1);
|
|
831
851
|
const rawId = value.slice(0, separator).trim();
|
|
@@ -834,7 +854,7 @@ function parseRemote(value, allowEmpty) {
|
|
|
834
854
|
}
|
|
835
855
|
catch (error) {
|
|
836
856
|
if (!isValidAid(rawId))
|
|
837
|
-
return failFs('
|
|
857
|
+
return failFs('INVALID_AID', `invalid AID: ${error.message}`);
|
|
838
858
|
targetAid = rawId;
|
|
839
859
|
}
|
|
840
860
|
if (remotePath === '' && allowEmpty)
|
|
@@ -849,7 +869,7 @@ function parseRemote(value, allowEmpty) {
|
|
|
849
869
|
export function resolveManagedFsOperation(argv) {
|
|
850
870
|
const raw = argv[0] === 'fs' ? argv.slice(1) : argv;
|
|
851
871
|
const rawKind = raw[0];
|
|
852
|
-
if (!rawKind || !['ls', 'stat', 'lstat', 'cat', 'find', 'df', 'getfacl', 'setfacl', 'mkdir', 'cp', 'mv', 'rm'].includes(rawKind)) {
|
|
872
|
+
if (!rawKind || !['ls', 'stat', 'lstat', 'cat', 'find', 'df', 'getfacl', 'setfacl', 'mkdir', 'cp', 'mv', 'rm', 'link'].includes(rawKind)) {
|
|
853
873
|
return failFs('NOT_ALLOWED', `unsupported managed fs command: ${rawKind || '<missing>'}`);
|
|
854
874
|
}
|
|
855
875
|
const values = new Map();
|
|
@@ -903,9 +923,10 @@ export function resolveManagedFsOperation(argv) {
|
|
|
903
923
|
df: new Set(['--as', '--format']), mkdir: new Set(['--as', '--format']), cp: new Set(['--as', '--format']),
|
|
904
924
|
mv: new Set(['--as', '--format']), rm: new Set(['--as', '--format']),
|
|
905
925
|
getfacl: new Set(['--as', '--format']), setfacl: new Set(['--as', '--format', '-m', '-x']),
|
|
926
|
+
link: new Set(['--as', '--format', '--expires']),
|
|
906
927
|
};
|
|
907
928
|
const allowedBoolean = {
|
|
908
|
-
ls: new Set(), stat: new Set(), lstat: new Set(), cat: new Set(), find: new Set(), df: new Set(), getfacl: new Set(), setfacl: new Set(),
|
|
929
|
+
ls: new Set(), stat: new Set(), lstat: new Set(), cat: new Set(['--authoritative']), find: new Set(), df: new Set(), getfacl: new Set(), setfacl: new Set(), link: new Set(),
|
|
909
930
|
mkdir: new Set(['-p', '--parents']), cp: new Set(['-r', '--recursive', '-f', '--force', '--overwrite']),
|
|
910
931
|
mv: new Set(['-f', '--force', '--overwrite']), rm: new Set(['-r', '--recursive', '-f', '--force', '--overwrite']),
|
|
911
932
|
};
|
|
@@ -960,7 +981,7 @@ export function resolveManagedFsOperation(argv) {
|
|
|
960
981
|
if (source && !('targetAid' in source))
|
|
961
982
|
return source;
|
|
962
983
|
if (source && source.targetAid !== destination.targetAid)
|
|
963
|
-
return failFs('
|
|
984
|
+
return failFs('INVALID_ARGUMENT', 'managed cp cannot cross targets');
|
|
964
985
|
const kind = source ? 'copy' : 'upload';
|
|
965
986
|
return { ok: true, command: {
|
|
966
987
|
kind, operationId: `ec.fs.${kind}`, canonicalArgv: ['fs', 'cp', positionals[0], positionals[1], ...(actorAid ? ['--as', actorAid] : [])],
|
|
@@ -976,7 +997,7 @@ export function resolveManagedFsOperation(argv) {
|
|
|
976
997
|
if (!('targetAid' in destination))
|
|
977
998
|
return destination;
|
|
978
999
|
if (source.targetAid !== destination.targetAid)
|
|
979
|
-
return failFs('
|
|
1000
|
+
return failFs('INVALID_ARGUMENT', 'managed mv cannot cross targets');
|
|
980
1001
|
return { ok: true, command: {
|
|
981
1002
|
kind: 'move', operationId: 'ec.fs.move', canonicalArgv: ['fs', 'mv', positionals[0], positionals[1], ...(actorAid ? ['--as', actorAid] : [])],
|
|
982
1003
|
actorAid, targetAid: destination.targetAid, remotePath: destination.remotePath, destinationPath: destination.remotePath,
|
|
@@ -986,6 +1007,20 @@ export function resolveManagedFsOperation(argv) {
|
|
|
986
1007
|
const remote = remoteOrError(positionals[0], rawKind === 'df');
|
|
987
1008
|
if (!('targetAid' in remote))
|
|
988
1009
|
return remote;
|
|
1010
|
+
if (rawKind === 'link') {
|
|
1011
|
+
if (remote.remotePath === '/' || remote.remotePath === '') {
|
|
1012
|
+
return failFs('INVALID_PATH', 'managed link requires a file path, not the storage root');
|
|
1013
|
+
}
|
|
1014
|
+
const expires = parseManagedLinkExpiry(values.get('--expires'));
|
|
1015
|
+
if (expires !== undefined && typeof expires === 'object')
|
|
1016
|
+
return expires;
|
|
1017
|
+
return { ok: true, command: {
|
|
1018
|
+
kind: 'link', operationId: 'ec.fs.link',
|
|
1019
|
+
canonicalArgv: ['fs', 'link', positionals[0], ...(expires !== undefined ? ['--expires', String(expires)] : []), ...(actorAid ? ['--as', actorAid] : [])],
|
|
1020
|
+
actorAid, targetAid: remote.targetAid, remotePath: remote.remotePath,
|
|
1021
|
+
...(expires !== undefined ? { expiresSeconds: expires } : {}),
|
|
1022
|
+
} };
|
|
1023
|
+
}
|
|
989
1024
|
if (rawKind === 'mkdir')
|
|
990
1025
|
return { ok: true, command: {
|
|
991
1026
|
kind: 'mkdir', operationId: 'ec.fs.mkdir', canonicalArgv: ['fs', 'mkdir', positionals[0], ...(actorAid ? ['--as', actorAid] : [])],
|
|
@@ -1015,8 +1050,9 @@ export function resolveManagedFsOperation(argv) {
|
|
|
1015
1050
|
if (nodeType !== undefined && !['f', 'd', 'l'].includes(nodeType))
|
|
1016
1051
|
return failFs('INVALID_ARGUMENT', '--type only supports f|d|l');
|
|
1017
1052
|
return { ok: true, command: {
|
|
1018
|
-
kind: effectiveKind, operationId: `ec.fs.${effectiveKind}`, canonicalArgv: ['fs', effectiveKind, positionals[0], ...(actorAid ? ['--as', actorAid] : [])],
|
|
1053
|
+
kind: effectiveKind, operationId: `ec.fs.${effectiveKind}`, canonicalArgv: ['fs', effectiveKind, positionals[0], ...(actorAid ? ['--as', actorAid] : []), ...(booleanFlags.has('--authoritative') ? ['--authoritative'] : [])],
|
|
1019
1054
|
actorAid, targetAid: remote.targetAid, remotePath: remote.remotePath, maxBytes, headBytes,
|
|
1055
|
+
authoritative: booleanFlags.has('--authoritative'),
|
|
1020
1056
|
name: values.get('--name') ?? values.get('--pattern'), nodeType, size: values.get('--size'), mtime: values.get('--mtime'), page, pageSize,
|
|
1021
1057
|
} };
|
|
1022
1058
|
}
|
|
@@ -1076,6 +1112,9 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1076
1112
|
if (!command.storageBackend)
|
|
1077
1113
|
throw new ManagedFsOperationError('INVALID_TARGET', 'managed fs storage backend must be resolved before execution');
|
|
1078
1114
|
const ref = `${command.targetAid}:${command.remotePath}`;
|
|
1115
|
+
if (command.authoritative && (command.kind !== 'cat' || command.storageBackend !== 'personal')) {
|
|
1116
|
+
throw new ManagedFsOperationError('NOT_ALLOWED', 'authoritative reads require personal storage cat');
|
|
1117
|
+
}
|
|
1079
1118
|
try {
|
|
1080
1119
|
return await (async () => {
|
|
1081
1120
|
if (command.storageBackend === 'personal') {
|
|
@@ -1126,12 +1165,30 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1126
1165
|
}) };
|
|
1127
1166
|
case 'df':
|
|
1128
1167
|
return { ok: true, command: 'df', path: `${owner}:`, usage: await client.storage.df({ owner }) };
|
|
1168
|
+
case 'link': {
|
|
1169
|
+
// The SDK wrapper fixes the ticket lifetime, so call the RPC directly to honor --expires.
|
|
1170
|
+
const ticket = await client.call('storage.create_download_ticket', {
|
|
1171
|
+
owner_aid: owner,
|
|
1172
|
+
bucket: 'default',
|
|
1173
|
+
object_key: command.remotePath.replace(/^\/+/, ''),
|
|
1174
|
+
...(command.expiresSeconds !== undefined ? { expire_in_seconds: command.expiresSeconds } : {}),
|
|
1175
|
+
});
|
|
1176
|
+
const record = (ticket && typeof ticket === 'object' ? ticket : {});
|
|
1177
|
+
const url = typeof record.download_url === 'string' && record.download_url
|
|
1178
|
+
? record.download_url
|
|
1179
|
+
: typeof record.url === 'string' ? record.url : '';
|
|
1180
|
+
if (!url)
|
|
1181
|
+
throw new ManagedFsOperationError('DEPENDENCY_UNAVAILABLE', 'storage did not return a download url');
|
|
1182
|
+
return { ok: true, command: 'link', path: ref, url, expireAt: record.expire_at ?? null };
|
|
1183
|
+
}
|
|
1129
1184
|
case 'getfacl':
|
|
1130
1185
|
return { ok: true, command: 'getfacl', path: ref, result: await client.storage.listAcl(command.remotePath, { owner }) };
|
|
1131
1186
|
case 'setfacl':
|
|
1132
1187
|
throw new ManagedFsOperationError('NOT_ALLOWED', 'Managed personal storage ACL changes are not supported');
|
|
1133
1188
|
case 'cat': {
|
|
1134
|
-
const bytes =
|
|
1189
|
+
const bytes = command.authoritative
|
|
1190
|
+
? (await readAuthoritativePersonalFsObject(client, command.remotePath, owner, command.maxBytes ?? DEFAULT_FS_CAT_BYTES)).bytes
|
|
1191
|
+
: await readPersonalFsBytesWithinBudget(client, command.remotePath, command.maxBytes ?? DEFAULT_FS_CAT_BYTES, { owner });
|
|
1135
1192
|
const headBytes = Math.min(command.headBytes ?? 256, MAX_MANAGED_FS_HEAD_BYTES, bytes.byteLength);
|
|
1136
1193
|
if (bytes.subarray(0, Math.min(bytes.byteLength, 8192)).some(byte => byte === 0)) {
|
|
1137
1194
|
return {
|
|
@@ -1206,6 +1263,8 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1206
1263
|
}
|
|
1207
1264
|
case 'df':
|
|
1208
1265
|
return { ok: true, command: 'df', path: `${command.targetAid}:`, usage: await client.group.fs.df(`${command.targetAid}:`) };
|
|
1266
|
+
case 'link':
|
|
1267
|
+
throw new ManagedFsOperationError('NOT_ALLOWED', 'managed link is only supported for personal storage');
|
|
1209
1268
|
case 'getfacl':
|
|
1210
1269
|
return { ok: true, command: 'getfacl', path: ref, result: await client.group.fs.getAcl(ref) };
|
|
1211
1270
|
case 'setfacl': {
|
|
@@ -1248,6 +1307,8 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1248
1307
|
throw error;
|
|
1249
1308
|
if (error instanceof FsReadBudgetError)
|
|
1250
1309
|
throw new ManagedFsOperationError(error.code, error.message);
|
|
1310
|
+
if (error instanceof AuthoritativeFsReadError)
|
|
1311
|
+
throw new ManagedFsOperationError(error.code, error.message);
|
|
1251
1312
|
throw new ManagedFsOperationError('FS_OPERATION_FAILED', error instanceof Error ? error.message : String(error));
|
|
1252
1313
|
}
|
|
1253
1314
|
}
|