evolcore 0.0.48 → 0.0.50
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 +97 -0
- package/bin/ecmsg.js +9 -4
- package/dist/ability/caller/authorization.js +21 -0
- package/dist/ability/caller/command.js +164 -0
- package/dist/ability/caller/contract.js +102 -0
- package/dist/ability/caller/daemon.js +158 -0
- package/dist/ability/caller/service.js +380 -0
- package/dist/ability/command-contract.js +5 -0
- package/dist/ability/daemon.js +5 -1
- package/dist/ability/interop-v1.js +10 -3
- package/dist/ability/management.js +1 -0
- package/dist/agent-template/jobs.js +173 -1
- package/dist/agent-template/runtime.js +285 -8
- package/dist/agent-template/service.js +1159 -40
- package/dist/agent-template/types.js +2 -1
- package/dist/agents/baseagent-availability.js +27 -3
- package/dist/agents/baseagent-capability-adapter.js +102 -0
- package/dist/agents/baseagent-plugin-descriptor.js +274 -0
- package/dist/agents/baseagent-plugin-loader.js +145 -0
- package/dist/agents/baseagent.js +68 -2
- package/dist/agents/claude-gateway/agent-registration.js +389 -0
- package/dist/agents/claude-gateway/binding.js +96 -0
- package/dist/agents/claude-gateway/inbox.js +138 -0
- package/dist/agents/claude-gateway/index.js +125 -0
- package/dist/agents/claude-gateway/listing.js +330 -0
- package/dist/agents/claude-gateway/router.js +328 -0
- package/dist/agents/claude-gateway/sessions.js +128 -0
- package/dist/agents/claude-gateway/terminal.js +250 -0
- package/dist/agents/claude-gateway/transcript.js +272 -0
- package/dist/agents/claude-gateway/types.js +14 -0
- package/dist/agents/claude-runner.js +6 -10
- package/dist/agents/codex-runner.js +9 -2
- package/dist/agents/{gemini-runner.js → gemini/gemini-runner.js} +17 -17
- package/dist/{core/session/adapters → agents/gemini}/gemini-session-file-adapter.js +2 -2
- package/dist/agents/gemini/index.js +51 -0
- package/dist/aun/aid/control-aid.js +52 -32
- package/dist/aun/group/invite-service.js +6 -36
- package/dist/aun/group/operations.js +6 -0
- package/dist/aun/msg/mention-schema.js +1 -1
- package/dist/aun/msg/p2p.js +31 -2
- package/dist/aun/msg/upload.js +126 -3
- package/dist/build-identity.json +1 -1
- package/dist/channels/aun.js +1175 -457
- package/dist/cli/ability-command.js +42 -0
- package/dist/cli/agent-command.js +20 -1
- package/dist/cli/agent-create.js +78 -18
- package/dist/cli/agent-template.js +5 -3
- package/dist/cli/agent.js +91 -0
- package/dist/cli/aun-commands.js +92 -34
- package/dist/cli/bench.js +5 -2
- package/dist/cli/config.js +22 -6
- package/dist/cli/daemon-commands.js +245 -101
- package/dist/cli/directory.js +6 -1
- package/dist/cli/ecmsg-gateway.js +11 -9
- package/dist/cli/index.js +30 -5
- package/dist/cli/init.js +39 -63
- package/dist/cli/managed-command-guard.js +3 -0
- package/dist/cli/menu-client.js +32 -7
- package/dist/cli/model.js +20 -5
- package/dist/cli/pay-command.js +30 -0
- package/dist/cli/provider-command.js +6 -2
- package/dist/cli/quota.js +89 -0
- package/dist/cli/restart-monitor.js +2 -2
- package/dist/cli/role.js +1 -0
- package/dist/cli/services-command.js +12 -9
- package/dist/cli/team-workspace-command.js +56 -2
- package/dist/cli/thread-command.js +78 -12
- package/dist/config/access-policy.js +16 -3
- package/dist/config/config-field-policy.js +88 -9
- package/dist/config/config-manager.js +97 -47
- package/dist/config/config-operation-service.js +22 -1
- package/dist/config/gateway-config.js +9 -8
- package/dist/config/owner-config.js +0 -16
- package/dist/config/peer-role-resolver.js +1 -7
- package/dist/config/providers-config.js +107 -20
- package/dist/config/providers-management.js +45 -21
- package/dist/config/resolved-config-op.js +4 -44
- package/dist/config/schema-migration.js +78 -5
- package/dist/config/schema-registry.js +52 -7
- package/dist/config-store.js +1309 -17
- package/dist/core/agent-application-service.js +220 -1
- package/dist/core/agent-ipc-registration.js +19 -2
- package/dist/core/agent-reload-coordinator.js +5 -0
- package/dist/core/agent-runtime.js +198 -54
- package/dist/core/auth/agent-delegation.js +14 -0
- package/dist/core/auth/delegation-authorization.js +33 -26
- package/dist/core/auth/operation-authorizer.js +16 -1
- package/dist/core/auth/operation-catalog.js +59 -7
- package/dist/core/baseagent-loader.js +30 -3
- package/dist/core/capability/capability-manager.js +16 -7
- package/dist/core/channel-runtime.js +4 -2
- package/dist/core/command/agent-control.js +20 -2
- package/dist/core/command/agent-template-menu.js +4 -3
- package/dist/core/command/cli-intent-parser.js +28 -0
- package/dist/core/command/command-handler.js +45 -2
- package/dist/core/command/menu-catalog.js +20 -4
- package/dist/core/command/menu-file-path.js +70 -0
- package/dist/core/command/menu-handler.js +97 -73
- package/dist/core/command/menu-protocol.js +29 -0
- package/dist/core/command/menu-query-batch.js +2 -2
- package/dist/core/command/private-mention-menu.js +71 -0
- package/dist/core/command/remote-shell.js +565 -0
- package/dist/core/command/slash-handler.js +17 -26
- package/dist/core/command/team-workspace-bootstrap.js +2 -1
- package/dist/core/command/topic-slash.js +7 -1
- package/dist/core/daemon-bootstrap.js +0 -4
- package/dist/core/daemon-control.js +58 -1
- package/dist/core/daemon-lifecycle.js +29 -7
- package/dist/core/evolagent-registry.js +18 -9
- package/dist/core/handoff/runtime.js +1 -1
- package/dist/core/host-snapshot.js +8 -3
- package/dist/core/initialization/service.js +3 -0
- package/dist/core/interaction-router.js +130 -0
- package/dist/core/ipc-registration.js +5 -0
- package/dist/core/memory/consolidation-context.js +2 -1
- package/dist/core/memory/consolidation.js +35 -64
- package/dist/core/message/aun-ipc-sender.js +213 -74
- package/dist/core/message/aun-request-registry.js +31 -0
- package/dist/core/message/contact-admission.js +91 -6
- package/dist/core/message/contact-pending-inbound.js +113 -0
- package/dist/core/message/contact-thread-approval.js +212 -0
- package/dist/core/message/im-renderer.js +40 -1
- package/dist/core/message/message-admission.js +5 -39
- package/dist/core/message/message-bridge.js +197 -45
- package/dist/core/message/message-log.js +32 -0
- package/dist/core/message/message-queue.js +102 -18
- package/dist/core/message/peer-mode.js +15 -4
- package/dist/core/message/response-engine.js +174 -26
- package/dist/core/message/send-options.js +37 -3
- package/dist/core/message/send-routing.js +11 -7
- package/dist/core/model/config-scope.js +6 -14
- package/dist/core/model/model-catalog.js +5 -5
- package/dist/core/model/model-diagnostics.js +19 -0
- package/dist/core/model/model-fallback.js +13 -2
- package/dist/core/ownership/owner-resolver.js +12 -86
- package/dist/core/pack-auth.js +7 -0
- package/dist/core/pack-install.js +1 -1
- package/dist/core/permission/ec-command-parser.js +288 -77
- package/dist/core/permission/protected-paths.js +64 -9
- package/dist/core/permission/services-path-acl.js +458 -0
- package/dist/core/permission/tool-policy.js +26 -10
- package/dist/core/relation/peer-identity.js +13 -0
- package/dist/core/session/adapters/claude-session-file-adapter.js +6 -2
- package/dist/core/session/adapters/codex-session-file-adapter.js +4 -0
- package/dist/core/session/session-manager.js +47 -10
- package/dist/core/session/session-mapper.js +16 -0
- package/dist/core/skill/index-generator.js +2 -3
- package/dist/core/skill/switch-resolver.js +3 -0
- package/dist/core/task/task-recovery-service.js +1 -0
- package/dist/core/thread/command-parser.js +4 -1
- package/dist/core/thread/ipc-operation.js +4 -2
- package/dist/core/thread/thread-operation.js +25 -10
- package/dist/core/thread/thread-service.js +294 -55
- package/dist/core/thread/topic-id.js +67 -2
- package/dist/core/thread/types.js +15 -1
- package/dist/directory/owner-directory-admission.js +11 -8
- package/dist/directory/owner-directory-cache.js +19 -0
- package/dist/directory/owner-directory-markdown.js +1 -1
- package/dist/directory/owner-directory-policy.js +5 -30
- package/dist/directory/owner-directory-request-operation.js +5 -2
- package/dist/eck/kit-renderer.js +3 -2
- package/dist/eck/message-renderer.js +28 -5
- package/dist/ecweb/basic-settings-service.js +5 -9
- package/dist/ecweb/providers-service.js +4 -2
- package/dist/ecweb/runtime/supervisor.js +36 -8
- package/dist/event-center/center-config.js +9 -5
- package/dist/event-center/dispatcher.js +10 -1
- package/dist/event-center/ipc-operation.js +19 -0
- package/dist/event-center/registry.js +20 -5
- package/dist/event-center/runtime.js +10 -7
- package/dist/index.js +120 -41
- package/dist/ipc.js +83 -3
- package/dist/outputs/authorization.js +16 -0
- package/dist/outputs/cards.js +336 -0
- package/dist/outputs/events.js +3 -2
- package/dist/outputs/protocol.js +1 -0
- package/dist/outputs/service.js +2 -15
- package/dist/paths.js +48 -1
- package/dist/pay/command.js +38 -0
- package/dist/pay/protocol.js +136 -0
- package/dist/pay/runtime.js +188 -0
- package/dist/pay/service.js +384 -0
- package/dist/pay/store.js +81 -0
- package/dist/response-system/engines/v1/proactive-flow.js +29 -2
- package/dist/services/dispatcher.js +23 -5
- package/dist/services/host/main.js +388 -0
- package/dist/services/host/protocol.js +118 -0
- package/dist/services/host/resident.js +310 -0
- package/dist/services/host-client.js +386 -0
- package/dist/services/host-deploy.js +180 -0
- package/dist/services/host-launch.js +117 -0
- package/dist/services/host-recycle.js +203 -0
- package/dist/services/host-runtime.js +802 -0
- package/dist/services/idempotency.js +44 -86
- package/dist/services/index-generator.js +4 -3
- package/dist/services/index.js +204 -22
- package/dist/services/ipc-operation.js +288 -44
- package/dist/services/pack-manager.js +1 -0
- package/dist/services/script-runner.js +515 -83
- package/dist/services/service-payload.js +13 -7
- package/dist/services/validation.js +109 -4
- package/dist/stats/budget.js +1 -1
- package/dist/stats/model-resolver.js +2 -2
- package/dist/stats/quota-query.js +95 -0
- package/dist/trigger/application-service.js +6 -4
- package/dist/trigger/local-files.js +19 -9
- package/dist/trigger/scheduler.js +22 -12
- package/dist/trigger/script-sandbox.js +51 -8
- package/dist/utils/aid-bind.js +3 -0
- package/dist/utils/atomic-write.js +22 -8
- package/dist/utils/evolcore-version.js +2 -2
- package/dist/utils/host-info.js +173 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/media-cache.js +190 -43
- package/dist/utils/npm-ops.js +43 -8
- package/dist/utils/restart-safety.js +14 -1
- package/dist/utils/system-memory.js +113 -25
- package/dist/utils/systemd-lifecycle.js +154 -0
- package/dist/utils/windows-shell-trust.js +7 -3
- package/dist/workbench/service.js +1 -1
- package/kits/docs/INDEX.md +3 -2
- package/kits/docs/aun/AUN/346/266/210/346/201/257/347/261/273/345/236/213/344/270/216/345/261/236/346/200/247.md +1 -0
- package/kits/docs/channels/aun.md +1 -1
- package/kits/docs/evolcore/INDEX.md +9 -6
- package/kits/docs/evolcore/agent.md +36 -1
- package/kits/docs/evolcore/aid.md +45 -3
- package/kits/docs/evolcore/config.md +5 -2
- package/kits/docs/evolcore/directory.md +8 -9
- package/kits/docs/evolcore/group.md +2 -1
- package/kits/docs/evolcore/memory-tags.md +2 -0
- package/kits/docs/evolcore/menu-client.md +3 -3
- package/kits/docs/evolcore/menu-protocol.md +7 -0
- package/kits/docs/evolcore/model.md +3 -0
- package/kits/docs/evolcore/msg.md +77 -10
- package/kits/docs/evolcore/pay.md +34 -0
- package/kits/docs/evolcore/provider.md +22 -1
- package/kits/docs/evolcore/quota.md +54 -0
- package/kits/docs/evolcore/role.md +3 -0
- package/kits/docs/evolcore/services.md +46 -18
- package/kits/docs/evolcore/stats.md +2 -0
- package/kits/docs/evolcore/thread-chain.md +2 -0
- package/kits/docs/evolcore/tool-authorization.md +10 -0
- package/kits/docs/evolcore/trigger.md +2 -0
- package/kits/rules/01-overview.md +11 -32
- package/kits/rules/02-navigation.md +7 -0
- package/kits/rules/06-channel.md +3 -3
- package/kits/schemas/_meta.json +38 -5
- package/kits/schemas/agent-config.schema.20.json +24 -0
- package/kits/schemas/agent-config.schema.21.json +974 -0
- package/kits/schemas/agent-config.schema.22.json +977 -0
- package/kits/schemas/agent-config.schema.23.json +958 -0
- package/kits/schemas/daemon.schema.10.json +373 -0
- package/kits/schemas/daemon.schema.9.json +12 -0
- package/kits/schemas/defaults.schema.7.json +472 -0
- package/kits/schemas/providers.schema.3.json +18 -2
- package/kits/schemas/relation-config.schema.13.json +289 -0
- package/kits/skills/.switches.json +17 -1
- package/kits/skills/ability/SKILL.md +229 -34
- package/kits/skills/ability/STRUCTURE.md +333 -0
- package/kits/skills/ability/references/cli.md +208 -0
- package/kits/skills/ability/references/development.md +107 -37
- package/kits/skills/ability/references/management.md +106 -46
- package/kits/skills/ability/references/runtime-protocol.md +65 -63
- package/kits/skills/agent-output-cards/SKILL.md +64 -0
- package/kits/skills/ec-group/SKILL.md +8 -6
- package/kits/skills/ec-group/TASK.md +186 -0
- package/kits/skills/ec-group/WORKLOG.md +180 -0
- package/kits/skills/ec-group-collaboration/SKILL.md +3 -3
- package/kits/skills/ec-pay/SKILL.md +101 -0
- package/kits/skills/ec-pay/references/pay-cli.md +110 -0
- package/kits/skills/ec-provider/SKILL.md +58 -9
- package/kits/skills/{ec-service-proxy → ec-proxy}/SKILL.md +8 -5
- package/kits/skills/ec-service-call/SKILL.md +135 -0
- package/kits/skills/ec-service-pack/SKILL.md +277 -0
- package/kits/skills/ec-trigger/SKILL.md +1 -1
- package/kits/templates/memory-consolidation/notes.md +2 -2
- package/kits/templates/memory-consolidation/workflow.md +46 -0
- package/kits/templates/roles/visitor.json +1 -0
- package/kits/templates/system-fragments/channel.md +13 -4
- package/kits/templates/system-fragments/commands.md +5 -3
- package/kits/templates/system-fragments/directory-contacts.md +3 -4
- package/kits/templates/system-fragments/reply.md +1 -0
- package/kits/templates/system-fragments/session.md +1 -1
- package/kits/templates/system-fragments/thread.md +27 -128
- package/kits/templates/system-fragments/venue.md +27 -0
- package/package.json +4 -5
- package/scripts/agent-template/inspect.mjs +79 -29
- package/scripts/agent-template/overlay.mjs +20 -2
- package/scripts/agent-template/shared/common.mjs +24 -6
- package/scripts/agent-template/shared/team-schema.json +23 -5
- package/scripts/agent-template/shared/template-contract.mjs +107 -17
- package/scripts/agent-template/shared/template-package.mjs +254 -29
- package/scripts/agent-template/shared/template-runtime.mjs +145 -2
- package/scripts/agent-template/shared/template.mjs +67 -9
- package/scripts/agent-template/team-pack.mjs +132 -41
- package/scripts/agent-template/team-preview.mjs +249 -5
- package/kits/docs/aun/ABILITY_CALLING.md +0 -280
- package/kits/docs/evolcore/ability.md +0 -185
- package/kits/skills/ability/references/calling.md +0 -56
- package/kits/skills/ability/references/contract-checklist.md +0 -37
- package/kits/skills/ability/references/recovery.md +0 -27
- /package/dist/{core/capability/providers → agents/gemini}/gemini-capability-provider.js +0 -0
package/dist/ipc.js
CHANGED
|
@@ -7,6 +7,7 @@ import os from 'os';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
9
|
import { logger, logOwnershipEvent } from './utils/logger.js';
|
|
10
|
+
import { readEffectiveCpuCount } from './utils/host-info.js';
|
|
10
11
|
import { fileCache } from './core/daemon-file-cache.js';
|
|
11
12
|
import { DAEMON_RUNTIME_EPOCH_ENV, isTrustedFullAccessRuntimeContext } from './cli/task-context.js';
|
|
12
13
|
import { HANDOFF_QUERY_MAX_LIMIT, HANDOFF_STATES } from './core/handoff/types.js';
|
|
@@ -78,6 +79,7 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
78
79
|
'upgrade.op',
|
|
79
80
|
'provider.op',
|
|
80
81
|
'agent-template.op',
|
|
82
|
+
'agent-project.op',
|
|
81
83
|
'invoke.op',
|
|
82
84
|
'ecweb.init',
|
|
83
85
|
'ecweb.basic-settings',
|
|
@@ -99,7 +101,9 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
99
101
|
'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
|
|
100
102
|
]);
|
|
101
103
|
const DELEGATED_ARGV_ENDPOINTS = new Set([
|
|
102
|
-
'
|
|
104
|
+
'pay.op',
|
|
105
|
+
'quota.op',
|
|
106
|
+
'agent.op', 'ability.op', 'ability.remote.op', 'config.op', 'peer.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op', 'provider.op', 'invoke.op',
|
|
103
107
|
'upgrade.op',
|
|
104
108
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
105
109
|
'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', 'logs.query', ...MEMORY_COMMAND_ENDPOINTS,
|
|
@@ -138,7 +142,7 @@ function requiresLocalControlToken(cmd) {
|
|
|
138
142
|
// Ownership has an explicit, non-fallback authentication contract below.
|
|
139
143
|
if (type === 'aid.ownership')
|
|
140
144
|
return false;
|
|
141
|
-
if (type === 'skill.refresh' || type === 'thread.op' || type === 'events.op' || type === 'services.op')
|
|
145
|
+
if (type === 'skill.refresh' || type === 'thread.op' || type === 'events.op' || type === 'services.op' || type === 'pay.op')
|
|
142
146
|
return !sessionId || !delegated;
|
|
143
147
|
if (type === 'ability.op')
|
|
144
148
|
return !sessionId && !delegated;
|
|
@@ -234,6 +238,9 @@ export class IpcServer {
|
|
|
234
238
|
codexPreToolUseExecutor;
|
|
235
239
|
aunMsgSender;
|
|
236
240
|
aunRequestGetExecutor;
|
|
241
|
+
abilityRequestSender;
|
|
242
|
+
abilityRequestGetExecutor;
|
|
243
|
+
paymentExecutor;
|
|
237
244
|
diagExecutor;
|
|
238
245
|
menuClientExecutor;
|
|
239
246
|
handoffReturnExecutor;
|
|
@@ -246,6 +253,7 @@ export class IpcServer {
|
|
|
246
253
|
configOperationExecutor;
|
|
247
254
|
peerOperationExecutor;
|
|
248
255
|
roleOperationExecutor;
|
|
256
|
+
quotaOperationExecutor;
|
|
249
257
|
aidOperationExecutor;
|
|
250
258
|
directoryOperationExecutor;
|
|
251
259
|
groupOperationExecutor;
|
|
@@ -368,6 +376,9 @@ export class IpcServer {
|
|
|
368
376
|
setRoleOperationExecutor(executor) {
|
|
369
377
|
this.roleOperationExecutor = executor;
|
|
370
378
|
}
|
|
379
|
+
setQuotaOperationExecutor(executor) {
|
|
380
|
+
this.quotaOperationExecutor = executor;
|
|
381
|
+
}
|
|
371
382
|
setSkillRefreshExecutor(executor) {
|
|
372
383
|
this.skillRefreshExecutor = executor;
|
|
373
384
|
}
|
|
@@ -469,7 +480,7 @@ export class IpcServer {
|
|
|
469
480
|
snapshot: {
|
|
470
481
|
ts: Date.now(),
|
|
471
482
|
uptimeMs: Math.round(process.uptime() * 1000),
|
|
472
|
-
cpuCount:
|
|
483
|
+
cpuCount: readEffectiveCpuCount(),
|
|
473
484
|
memory: {
|
|
474
485
|
rss: processTreeRss,
|
|
475
486
|
heapUsed: mem.heapUsed,
|
|
@@ -607,6 +618,21 @@ export class IpcServer {
|
|
|
607
618
|
setAunRequestGetExecutor(executor) {
|
|
608
619
|
this.aunRequestGetExecutor = executor;
|
|
609
620
|
}
|
|
621
|
+
setAbilityRequestSender(sender) { this.abilityRequestSender = sender; }
|
|
622
|
+
setAbilityRequestGetExecutor(executor) { this.abilityRequestGetExecutor = executor; }
|
|
623
|
+
async sendAbilityRequest(params, originGrant) {
|
|
624
|
+
if (!this.abilityRequestSender)
|
|
625
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'Ability transport is not configured', sent: false };
|
|
626
|
+
return this.abilityRequestSender(params, originGrant);
|
|
627
|
+
}
|
|
628
|
+
async getAbilityRequest(params, originGrant) {
|
|
629
|
+
if (!this.abilityRequestGetExecutor)
|
|
630
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'Ability request registry is not configured' };
|
|
631
|
+
return this.abilityRequestGetExecutor(params, originGrant);
|
|
632
|
+
}
|
|
633
|
+
setPaymentExecutor(executor) {
|
|
634
|
+
this.paymentExecutor = executor;
|
|
635
|
+
}
|
|
610
636
|
hasAunMsgSender() {
|
|
611
637
|
return this.aunMsgSender !== undefined;
|
|
612
638
|
}
|
|
@@ -615,6 +641,12 @@ export class IpcServer {
|
|
|
615
641
|
throw new Error('aunMsgSender not configured');
|
|
616
642
|
return this.aunMsgSender(params);
|
|
617
643
|
}
|
|
644
|
+
/** In-process access retains the same origin and target authorization as IPC queries. */
|
|
645
|
+
async getAunRequest(params) {
|
|
646
|
+
if (!this.aunRequestGetExecutor)
|
|
647
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'AUN request registry is not configured' };
|
|
648
|
+
return this.aunRequestGetExecutor(params);
|
|
649
|
+
}
|
|
618
650
|
setDiagExecutor(executor) { this.diagExecutor = executor; }
|
|
619
651
|
setMenuClientExecutor(executor) { this.menuClientExecutor = executor; }
|
|
620
652
|
/** Inject internal handoff result return executor for `ec handoff return`. */
|
|
@@ -1321,6 +1353,7 @@ export class IpcServer {
|
|
|
1321
1353
|
return handleProvidersService(cmd.request);
|
|
1322
1354
|
}
|
|
1323
1355
|
case 'ability.op':
|
|
1356
|
+
case 'ability.remote.op':
|
|
1324
1357
|
case 'ecweb.ability':
|
|
1325
1358
|
return this.abilityExecutor ? this.abilityExecutor(cmd) : { ok: false, code: 'ABILITY_UNAVAILABLE', error: 'Ability service is unavailable', status: 503 };
|
|
1326
1359
|
case 'ecweb.init': {
|
|
@@ -1891,6 +1924,16 @@ export class IpcServer {
|
|
|
1891
1924
|
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
1892
1925
|
});
|
|
1893
1926
|
}
|
|
1927
|
+
case 'pay.op': {
|
|
1928
|
+
if (!this.paymentExecutor)
|
|
1929
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'Payment runtime is not configured' };
|
|
1930
|
+
if (!Array.isArray(cmd.argv) || !cmd.argv.every((value) => typeof value === 'string')
|
|
1931
|
+
|| typeof cmd.sessionId !== 'string' || !cmd.sessionId || !cmd.delegationToken || !cmd.delegationCommandHash) {
|
|
1932
|
+
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'Payment operations require an approved delegated command' };
|
|
1933
|
+
}
|
|
1934
|
+
return this.paymentExecutor({ argv: cmd.argv, sessionId: cmd.sessionId,
|
|
1935
|
+
delegationToken: cmd.delegationToken, delegationCommandHash: cmd.delegationCommandHash });
|
|
1936
|
+
}
|
|
1894
1937
|
case 'aun-msg-send': {
|
|
1895
1938
|
if (cmd.argv !== undefined) {
|
|
1896
1939
|
if (!this.aunMsgSender)
|
|
@@ -1924,6 +1967,7 @@ export class IpcServer {
|
|
|
1924
1967
|
contentType: typeof rawFile.contentType === 'string' ? rawFile.contentType : undefined,
|
|
1925
1968
|
text: typeof rawFile.text === 'string' ? rawFile.text : undefined,
|
|
1926
1969
|
transcript: typeof rawFile.transcript === 'string' ? rawFile.transcript : undefined,
|
|
1970
|
+
title: typeof rawFile.title === 'string' ? rawFile.title : undefined,
|
|
1927
1971
|
}
|
|
1928
1972
|
: undefined;
|
|
1929
1973
|
if ((!payload && !file) || (payload && file)) {
|
|
@@ -2477,6 +2521,24 @@ export class IpcServer {
|
|
|
2477
2521
|
}
|
|
2478
2522
|
return await this.peerOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2479
2523
|
}
|
|
2524
|
+
case 'quota.op': {
|
|
2525
|
+
if (!this.quotaOperationExecutor)
|
|
2526
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'quota.op not configured; restart the host after building' };
|
|
2527
|
+
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')) {
|
|
2528
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'invalid argv' };
|
|
2529
|
+
}
|
|
2530
|
+
const delegated = cmd.sessionId !== undefined || cmd.delegationToken !== undefined || cmd.actorSessionId !== undefined;
|
|
2531
|
+
if (!delegated) {
|
|
2532
|
+
if (!this.hasValidControlToken(cmd.controlToken))
|
|
2533
|
+
return { ok: false, code: 'CONTROL_TOKEN_REQUIRED', error: 'Host quota queries require a valid control token' };
|
|
2534
|
+
return await this.quotaOperationExecutor(cmd.argv, '', undefined, undefined, true);
|
|
2535
|
+
}
|
|
2536
|
+
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId)
|
|
2537
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'missing sessionId' };
|
|
2538
|
+
if (typeof cmd.delegationToken !== 'string' || !cmd.delegationToken)
|
|
2539
|
+
return { ok: false, code: 'INVALID_DELEGATION', error: 'missing delegationToken' };
|
|
2540
|
+
return await this.quotaOperationExecutor(cmd.argv, cmd.sessionId, cmd.delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2541
|
+
}
|
|
2480
2542
|
case 'role.op': {
|
|
2481
2543
|
if (!this.roleOperationExecutor)
|
|
2482
2544
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'role.op not configured' };
|
|
@@ -2618,6 +2680,24 @@ export class IpcServer {
|
|
|
2618
2680
|
return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message };
|
|
2619
2681
|
}
|
|
2620
2682
|
}
|
|
2683
|
+
case 'agent-project.op': {
|
|
2684
|
+
if (cmd.sessionId !== undefined || cmd.delegationToken !== undefined)
|
|
2685
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'Managed project commands must use agent.op' };
|
|
2686
|
+
if (!this.agentApplicationService)
|
|
2687
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'Agent service unavailable' };
|
|
2688
|
+
try {
|
|
2689
|
+
const { refreshOwnershipForAuthorization, getDaemonOwners } = await import('./core/ownership/owner-resolver.js');
|
|
2690
|
+
await refreshOwnershipForAuthorization(undefined, { force: true, allowTransient: false, source: 'agent-project-cli' });
|
|
2691
|
+
const actor = getDaemonOwners()[0];
|
|
2692
|
+
if (!actor)
|
|
2693
|
+
return { ok: false, code: 'NOT_ALLOWED', error: 'DaemonOwner required' };
|
|
2694
|
+
const { executeAgentProjectOperation } = await import('./cli/agent.js');
|
|
2695
|
+
return await executeAgentProjectOperation(actor, cmd.args, this.agentApplicationService);
|
|
2696
|
+
}
|
|
2697
|
+
catch (error) {
|
|
2698
|
+
return { ok: false, code: error.code ?? 'INVALID_ARGUMENT', error: error.message };
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2621
2701
|
case 'skill.refresh': {
|
|
2622
2702
|
if (!this.skillRefreshExecutor) {
|
|
2623
2703
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'skill.refresh not configured' };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
2
|
+
import { DataRootError } from '../core/command/team-workspace-store.js';
|
|
3
|
+
export async function authorizeOutput(aid, from) {
|
|
4
|
+
const view = await ownerResolver.refresh(aid, { maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, source: 'outputs.read', allowTransient: false });
|
|
5
|
+
if (view.authorizationStatus !== 'verified' || view.ownerAid !== from || view.refreshFailure?.fallbackUsed
|
|
6
|
+
|| (view.validUntil ?? 0) <= Date.now()) {
|
|
7
|
+
throw new DataRootError('OUTPUT_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
8
|
+
}
|
|
9
|
+
return `${view.ownerAid}:${view.revision}`;
|
|
10
|
+
}
|
|
11
|
+
export function currentOutputOwner(aid, from, generation) {
|
|
12
|
+
const view = ownerResolver.snapshot(aid);
|
|
13
|
+
return view.authorizationStatus === 'verified' && !view.refreshFailure?.fallbackUsed
|
|
14
|
+
&& (view.validUntil ?? 0) > Date.now()
|
|
15
|
+
&& view.ownerAid === from && `${view.ownerAid}:${view.revision}` === generation;
|
|
16
|
+
}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { agentOutputDir } from '../paths.js';
|
|
5
|
+
import { atomicRemove, atomicWriteJson } from '../utils/atomic-write.js';
|
|
6
|
+
import { DataRootError } from '../core/command/team-workspace-store.js';
|
|
7
|
+
import { currentOutputOwner, authorizeOutput } from './authorization.js';
|
|
8
|
+
export { OUTPUT_CARDS_EVENT } from './protocol.js';
|
|
9
|
+
import { OUTPUT_CARDS_EVENT } from './protocol.js';
|
|
10
|
+
export const OUTPUT_CARDS_TYPES = ['snapshot', 'list', 'detail', 'changes']
|
|
11
|
+
.map(action => `services.outputs.cards.${action}`);
|
|
12
|
+
export const isOutputCardsType = (type) => OUTPUT_CARDS_TYPES.includes(type);
|
|
13
|
+
const KINDS = ['meeting', 'report', 'document', 'media', 'generic'];
|
|
14
|
+
const ROLES = ['primary', 'summary', 'transcript', 'recording', 'attachment', 'cover'];
|
|
15
|
+
const ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
16
|
+
const MAX_CARDS = 200;
|
|
17
|
+
const MAX_FILES = 8;
|
|
18
|
+
const MAX_CARD_BYTES = 4096;
|
|
19
|
+
const MAX_PAGE = 10;
|
|
20
|
+
function fail(message) {
|
|
21
|
+
throw new DataRootError('INVALID_CARD', message);
|
|
22
|
+
}
|
|
23
|
+
function safeRelative(value) {
|
|
24
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 2048
|
|
25
|
+
&& !value.includes('\\') && !value.includes(':') && !/[\x00-\x1f\x7f]/.test(value)
|
|
26
|
+
&& value.split('/').every(part => part.length > 0 && part !== '.' && part !== '..' && !part.startsWith('.'));
|
|
27
|
+
}
|
|
28
|
+
function validateDraft(value) {
|
|
29
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
30
|
+
return fail('Card must be a JSON object');
|
|
31
|
+
const raw = value;
|
|
32
|
+
if (Object.keys(raw).some(key => !['schemaVersion', 'id', 'kind', 'title', 'summary', 'files'].includes(key))) {
|
|
33
|
+
return fail('Card contains unsupported fields');
|
|
34
|
+
}
|
|
35
|
+
if (raw.schemaVersion !== 1 || typeof raw.id !== 'string' || !ID.test(raw.id))
|
|
36
|
+
return fail('Card schemaVersion or id is invalid');
|
|
37
|
+
if (!KINDS.includes(raw.kind))
|
|
38
|
+
return fail('Card kind must be meeting, report, document, media or generic');
|
|
39
|
+
if (typeof raw.title !== 'string' || !raw.title.trim() || raw.title.length > 160)
|
|
40
|
+
return fail('Card title must contain 1 to 160 characters');
|
|
41
|
+
if (raw.summary !== undefined && (typeof raw.summary !== 'string' || raw.summary.length > 640))
|
|
42
|
+
return fail('Card summary is limited to 640 characters');
|
|
43
|
+
if (!Array.isArray(raw.files) || raw.files.length < 1 || raw.files.length > MAX_FILES)
|
|
44
|
+
return fail(`Card files must contain 1 to ${MAX_FILES} references`);
|
|
45
|
+
const files = [];
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
for (const item of raw.files) {
|
|
48
|
+
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
49
|
+
return fail('Each file reference must be an object');
|
|
50
|
+
const file = item;
|
|
51
|
+
if (Object.keys(file).some(key => !['role', 'path', 'label'].includes(key)))
|
|
52
|
+
return fail('File reference contains unsupported fields');
|
|
53
|
+
if (!ROLES.includes(file.role) || !safeRelative(file.path))
|
|
54
|
+
return fail('File role or relative path is invalid');
|
|
55
|
+
if (seen.has(file.path))
|
|
56
|
+
return fail('Card file paths must be unique');
|
|
57
|
+
seen.add(file.path);
|
|
58
|
+
if (file.label !== undefined && (typeof file.label !== 'string' || file.label.length > 100))
|
|
59
|
+
return fail('File label is limited to 100 characters');
|
|
60
|
+
files.push({ role: file.role, path: file.path, label: file.label?.trim() || path.posix.basename(file.path) });
|
|
61
|
+
}
|
|
62
|
+
if (files.filter(file => file.role === 'primary').length !== 1)
|
|
63
|
+
return fail('Card requires exactly one primary file reference');
|
|
64
|
+
return { schemaVersion: 1, id: raw.id, kind: raw.kind, title: raw.title.trim(), summary: typeof raw.summary === 'string' ? raw.summary.trim() : '', files };
|
|
65
|
+
}
|
|
66
|
+
function outputRoot(aid, resolve = agentOutputDir) {
|
|
67
|
+
let root;
|
|
68
|
+
try {
|
|
69
|
+
root = fs.realpathSync(resolve(aid));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Agent output directory is unavailable');
|
|
73
|
+
}
|
|
74
|
+
if (!fs.statSync(root).isDirectory())
|
|
75
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Agent output directory is unavailable');
|
|
76
|
+
return root;
|
|
77
|
+
}
|
|
78
|
+
function checkedFile(root, relative) {
|
|
79
|
+
const target = path.resolve(root, ...relative.split('/'));
|
|
80
|
+
const resolved = path.relative(root, target);
|
|
81
|
+
if (!resolved || resolved === '..' || resolved.startsWith(`..${path.sep}`) || path.isAbsolute(resolved))
|
|
82
|
+
fail('File reference escapes Agent output');
|
|
83
|
+
let real;
|
|
84
|
+
try {
|
|
85
|
+
real = fs.realpathSync(target);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw new DataRootError('CARD_FILE_NOT_FOUND', `Referenced output file does not exist: ${relative}`);
|
|
89
|
+
}
|
|
90
|
+
const realRelative = path.relative(root, real);
|
|
91
|
+
if (realRelative === '..' || realRelative.startsWith(`..${path.sep}`) || path.isAbsolute(realRelative) || !fs.statSync(real).isFile()) {
|
|
92
|
+
return fail('File reference must resolve to a regular file inside Agent output');
|
|
93
|
+
}
|
|
94
|
+
const normalized = `output/${relative}`;
|
|
95
|
+
return { path: normalized, outputId: crypto.createHash('sha256').update(normalized).digest('hex').slice(0, 32) };
|
|
96
|
+
}
|
|
97
|
+
function cardDir(root) {
|
|
98
|
+
const directory = path.join(root, '.cards');
|
|
99
|
+
if (fs.existsSync(directory)) {
|
|
100
|
+
const real = fs.realpathSync(directory);
|
|
101
|
+
if (path.resolve(real) !== path.resolve(directory) || !fs.statSync(real).isDirectory())
|
|
102
|
+
fail('Card directory cannot be a link');
|
|
103
|
+
}
|
|
104
|
+
return directory;
|
|
105
|
+
}
|
|
106
|
+
function toCard(root, raw, updatedAt) {
|
|
107
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
108
|
+
return fail('Card must be a JSON object');
|
|
109
|
+
const { updatedAt: _updatedAt, ...draftData } = raw;
|
|
110
|
+
const draft = validateDraft(draftData);
|
|
111
|
+
const files = draft.files.map(file => {
|
|
112
|
+
const outputPath = `output/${file.path}`;
|
|
113
|
+
return { ...file, path: outputPath, outputId: crypto.createHash('sha256').update(outputPath).digest('hex').slice(0, 32) };
|
|
114
|
+
});
|
|
115
|
+
const core = { ...draft, updatedAt, files };
|
|
116
|
+
const version = crypto.createHash('sha256').update(JSON.stringify(core)).digest('hex').slice(0, 24);
|
|
117
|
+
return { ...core, version };
|
|
118
|
+
}
|
|
119
|
+
function readCards(root) {
|
|
120
|
+
const directory = cardDir(root);
|
|
121
|
+
if (!fs.existsSync(directory))
|
|
122
|
+
return [];
|
|
123
|
+
const entries = fs.readdirSync(directory, { withFileTypes: true })
|
|
124
|
+
.filter(entry => entry.isFile() && ID.test(entry.name.replace(/\.json$/, '')) && entry.name.endsWith('.json'));
|
|
125
|
+
if (entries.length > MAX_CARDS)
|
|
126
|
+
throw new DataRootError('CARD_LIMIT', `At most ${MAX_CARDS} output cards are allowed`);
|
|
127
|
+
const cards = [];
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
try {
|
|
130
|
+
const file = path.join(directory, entry.name);
|
|
131
|
+
const stat = fs.lstatSync(file);
|
|
132
|
+
if (stat.isSymbolicLink() || stat.size > MAX_CARD_BYTES)
|
|
133
|
+
continue;
|
|
134
|
+
const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
135
|
+
const updatedAt = typeof raw.updatedAt === 'number' && Number.isSafeInteger(raw.updatedAt)
|
|
136
|
+
? Math.max(0, raw.updatedAt) : Math.max(0, Math.floor(stat.mtimeMs));
|
|
137
|
+
const card = toCard(root, raw, updatedAt);
|
|
138
|
+
if (card.id !== entry.name.slice(0, -5))
|
|
139
|
+
continue;
|
|
140
|
+
cards.push(card);
|
|
141
|
+
}
|
|
142
|
+
catch { /* One malformed descriptor must not hide other cards. */ }
|
|
143
|
+
}
|
|
144
|
+
return cards.sort((a, b) => b.updatedAt - a.updatedAt || a.id.localeCompare(b.id));
|
|
145
|
+
}
|
|
146
|
+
export function publishOutputCard(aid, value, resolveRoot = agentOutputDir) {
|
|
147
|
+
const root = outputRoot(aid, resolveRoot);
|
|
148
|
+
const draft = validateDraft(value);
|
|
149
|
+
const directory = cardDir(root);
|
|
150
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
151
|
+
const file = path.join(directory, `${draft.id}.json`);
|
|
152
|
+
if (fs.existsSync(file) && fs.lstatSync(file).isSymbolicLink())
|
|
153
|
+
fail('Card descriptor cannot be a link');
|
|
154
|
+
if (!fs.existsSync(file) && fs.readdirSync(directory, { withFileTypes: true }).filter(item => item.isFile() && item.name.endsWith('.json')).length >= MAX_CARDS) {
|
|
155
|
+
throw new DataRootError('CARD_LIMIT', `At most ${MAX_CARDS} output cards are allowed`);
|
|
156
|
+
}
|
|
157
|
+
for (const item of draft.files)
|
|
158
|
+
checkedFile(root, item.path);
|
|
159
|
+
const valueWithTime = { ...draft, updatedAt: Date.now() };
|
|
160
|
+
if (Buffer.byteLength(JSON.stringify(valueWithTime)) > MAX_CARD_BYTES)
|
|
161
|
+
fail(`Card descriptor exceeds ${MAX_CARD_BYTES} bytes`);
|
|
162
|
+
atomicWriteJson(file, valueWithTime);
|
|
163
|
+
return toCard(root, valueWithTime, valueWithTime.updatedAt);
|
|
164
|
+
}
|
|
165
|
+
export function removeOutputCard(aid, id, resolveRoot = agentOutputDir) {
|
|
166
|
+
if (!ID.test(id))
|
|
167
|
+
fail('Card id is invalid');
|
|
168
|
+
const directory = cardDir(outputRoot(aid, resolveRoot));
|
|
169
|
+
const file = path.join(directory, `${id}.json`);
|
|
170
|
+
const existed = fs.existsSync(file);
|
|
171
|
+
atomicRemove(file);
|
|
172
|
+
return existed;
|
|
173
|
+
}
|
|
174
|
+
export class OutputCardsService {
|
|
175
|
+
aid;
|
|
176
|
+
options;
|
|
177
|
+
projection = { epoch: crypto.randomBytes(12).toString('hex'), seq: 0, revision: '', cards: new Map(), log: [] };
|
|
178
|
+
cached = new Map();
|
|
179
|
+
flights = new Map();
|
|
180
|
+
closed = false;
|
|
181
|
+
constructor(aid, options = {}) {
|
|
182
|
+
this.aid = aid;
|
|
183
|
+
this.options = options;
|
|
184
|
+
}
|
|
185
|
+
async handle(message) {
|
|
186
|
+
if (this.closed)
|
|
187
|
+
throw new DataRootError('OUTPUT_UNAVAILABLE', 'Output cards service is closed');
|
|
188
|
+
if (!isOutputCardsType(message.type))
|
|
189
|
+
throw new DataRootError('UNKNOWN_TYPE', 'Unknown output card query');
|
|
190
|
+
if (!message.encrypted)
|
|
191
|
+
throw new DataRootError('ENCRYPTION_REQUIRED', 'Output card queries require encryption');
|
|
192
|
+
const generation = await (this.options.authorize ?? authorizeOutput)(this.aid, message.fromAid);
|
|
193
|
+
const ensure = () => {
|
|
194
|
+
if (this.closed || !(this.options.current ?? currentOutputOwner)(this.aid, message.fromAid, generation)) {
|
|
195
|
+
this.cached.clear();
|
|
196
|
+
throw new DataRootError('OUTPUT_FORBIDDEN', 'Output authorization changed');
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
ensure();
|
|
200
|
+
const args = message.payload.data;
|
|
201
|
+
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
202
|
+
throw new DataRootError('INVALID_ARGUMENT', 'data must be an object');
|
|
203
|
+
const data = args;
|
|
204
|
+
const action = message.type.split('.').at(-1);
|
|
205
|
+
const allowed = {
|
|
206
|
+
snapshot: ['protocolVersion', 'limit', 'knownRevision'], list: ['protocolVersion', 'limit', 'pageCursor'],
|
|
207
|
+
detail: ['protocolVersion', 'id'], changes: ['protocolVersion', 'cursor'],
|
|
208
|
+
};
|
|
209
|
+
if (data.protocolVersion !== 1 || Object.keys(data).some(key => !allowed[action].includes(key)))
|
|
210
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Unsupported output card query parameters');
|
|
211
|
+
if (action === 'detail' && (typeof data.id !== 'string' || !ID.test(data.id)))
|
|
212
|
+
throw new DataRootError('INVALID_ARGUMENT', 'Invalid output card id');
|
|
213
|
+
if (action === 'changes' && (typeof data.cursor !== 'string' || data.cursor.length > 128))
|
|
214
|
+
throw new DataRootError('INVALID_ARGUMENT', 'A bounded change cursor is required');
|
|
215
|
+
if (data.limit !== undefined && (!Number.isSafeInteger(data.limit) || Number(data.limit) < 1 || Number(data.limit) > MAX_PAGE))
|
|
216
|
+
throw new DataRootError('INVALID_ARGUMENT', `Output card page limit must be between 1 and ${MAX_PAGE}`);
|
|
217
|
+
const fingerprint = JSON.stringify([message.type, data]);
|
|
218
|
+
const key = `${generation}:${message.fromAid}:${message.requestId}`;
|
|
219
|
+
const saved = this.cached.get(key);
|
|
220
|
+
if (saved && saved.until > Date.now()) {
|
|
221
|
+
if (saved.fingerprint !== fingerprint)
|
|
222
|
+
throw new DataRootError('REQUEST_ID_CONFLICT', 'request_id was reused');
|
|
223
|
+
return saved.result;
|
|
224
|
+
}
|
|
225
|
+
const flight = this.flights.get(key);
|
|
226
|
+
if (flight && flight.fingerprint !== fingerprint)
|
|
227
|
+
throw new DataRootError('REQUEST_ID_CONFLICT', 'request_id was reused');
|
|
228
|
+
if (!flight && this.flights.size >= 3)
|
|
229
|
+
throw new DataRootError('RATE_LIMITED', 'Output card query concurrency exceeded');
|
|
230
|
+
const result = flight?.result ?? Promise.resolve().then(() => this.query(action, data));
|
|
231
|
+
if (!flight)
|
|
232
|
+
this.flights.set(key, { fingerprint, result });
|
|
233
|
+
try {
|
|
234
|
+
const response = await result;
|
|
235
|
+
ensure();
|
|
236
|
+
this.cached.set(key, { until: Date.now() + 30_000, fingerprint, result: response });
|
|
237
|
+
while (this.cached.size > 32)
|
|
238
|
+
this.cached.delete(this.cached.keys().next().value);
|
|
239
|
+
return response;
|
|
240
|
+
}
|
|
241
|
+
finally {
|
|
242
|
+
this.flights.delete(key);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
query(action, data) {
|
|
246
|
+
const root = outputRoot(this.aid, this.options.root);
|
|
247
|
+
const cards = readCards(root);
|
|
248
|
+
const next = new Map(cards.map(card => [card.id, card]));
|
|
249
|
+
const revision = crypto.createHash('sha256').update(JSON.stringify(cards.map(card => [card.id, card.version]))).digest('hex').slice(0, 24);
|
|
250
|
+
if (revision !== this.projection.revision) {
|
|
251
|
+
const previous = this.projection.cards;
|
|
252
|
+
const upserts = [...next].filter(([id, card]) => previous.get(id)?.version !== card.version).map(([id]) => id);
|
|
253
|
+
const deletes = [...previous.keys()].filter(id => !next.has(id));
|
|
254
|
+
this.projection.seq++;
|
|
255
|
+
this.projection.revision = revision;
|
|
256
|
+
this.projection.cards = next;
|
|
257
|
+
this.projection.log.push({ seq: this.projection.seq, revision, upserts, deletes, reset: upserts.length > 100 || deletes.length > 100 });
|
|
258
|
+
while (this.projection.log.length > 64)
|
|
259
|
+
this.projection.log.shift();
|
|
260
|
+
}
|
|
261
|
+
const cursor = `${this.projection.epoch}.${this.projection.seq}`;
|
|
262
|
+
const notifications = this.options.notifications?.() ?? hasOutputCardsNotifications(this.aid);
|
|
263
|
+
if (action === 'detail') {
|
|
264
|
+
const card = next.get(data.id);
|
|
265
|
+
if (!card)
|
|
266
|
+
throw new DataRootError('NOT_FOUND', 'Output card was removed');
|
|
267
|
+
return { protocol: 'evol.output-cards', protocolVersion: 1, sourceAid: this.aid, revision, cursor, generatedAt: Date.now(), notifications: notifications ? { busAid: this.aid, event: OUTPUT_CARDS_EVENT } : null, items: [card], nextCursor: null };
|
|
268
|
+
}
|
|
269
|
+
if (action === 'changes') {
|
|
270
|
+
const match = /^([a-f0-9]{24})\.(\d+)$/.exec(data.cursor);
|
|
271
|
+
const seq = match ? Number(match[2]) : -1;
|
|
272
|
+
const reset = !match || match[1] !== this.projection.epoch || seq > this.projection.seq || seq < (this.projection.log[0]?.seq ?? 1) - 1;
|
|
273
|
+
const changes = this.projection.log.filter(row => row.seq > seq);
|
|
274
|
+
const ids = [...new Set(changes.flatMap(row => row.upserts))];
|
|
275
|
+
const deletes = [...new Set(changes.flatMap(row => row.deletes))].filter(id => !next.has(id));
|
|
276
|
+
const needsReset = reset || changes.some(row => row.reset) || ids.length > MAX_PAGE || deletes.length > 100;
|
|
277
|
+
return { protocol: 'evol.output-cards', protocolVersion: 1, sourceAid: this.aid, revision, cursor, generatedAt: Date.now(), notifications: notifications ? { busAid: this.aid, event: OUTPUT_CARDS_EVENT } : null, items: needsReset ? [] : ids.flatMap(id => next.has(id) ? [next.get(id)] : []), nextCursor: null, reset: needsReset, deletes: needsReset ? [] : deletes };
|
|
278
|
+
}
|
|
279
|
+
const limit = Number(data.limit ?? MAX_PAGE);
|
|
280
|
+
let offset = 0;
|
|
281
|
+
if (data.pageCursor !== undefined) {
|
|
282
|
+
try {
|
|
283
|
+
const page = JSON.parse(Buffer.from(String(data.pageCursor), 'base64url').toString());
|
|
284
|
+
if (page.epoch !== this.projection.epoch || page.revision !== revision || !Number.isSafeInteger(page.offset) || Number(page.offset) < 0 || Number(page.offset) > MAX_CARDS)
|
|
285
|
+
throw new Error();
|
|
286
|
+
offset = Number(page.offset);
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
throw new DataRootError('INDEX_CHANGED', 'Restart output card pagination');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const page = cards.slice(offset, offset + limit);
|
|
293
|
+
const response = { protocol: 'evol.output-cards', protocolVersion: 1, sourceAid: this.aid, revision, cursor, generatedAt: Date.now(), notifications: notifications ? { busAid: this.aid, event: OUTPUT_CARDS_EVENT } : null, items: page, nextCursor: offset + page.length < cards.length ? Buffer.from(JSON.stringify({ epoch: this.projection.epoch, revision, offset: offset + page.length })).toString('base64url') : null };
|
|
294
|
+
if (action === 'snapshot' && data.knownRevision === revision) {
|
|
295
|
+
response.items = [];
|
|
296
|
+
response.notModified = true;
|
|
297
|
+
}
|
|
298
|
+
return response;
|
|
299
|
+
}
|
|
300
|
+
close() { this.closed = true; this.cached.clear(); this.flights.clear(); }
|
|
301
|
+
}
|
|
302
|
+
let outputCardsNotificationsAvailable = () => false;
|
|
303
|
+
export function setOutputCardsNotificationsAvailable(available = () => false) {
|
|
304
|
+
outputCardsNotificationsAvailable = available;
|
|
305
|
+
}
|
|
306
|
+
export function hasOutputCardsNotifications(aid) { return outputCardsNotificationsAvailable(aid); }
|
|
307
|
+
export function outputCardsRequestSchema(type) {
|
|
308
|
+
const action = type.split('.').at(-1);
|
|
309
|
+
const properties = { protocolVersion: { const: 1 } };
|
|
310
|
+
const required = ['protocolVersion'];
|
|
311
|
+
if (action === 'snapshot' || action === 'list')
|
|
312
|
+
Object.assign(properties, { limit: { type: 'integer', minimum: 1, maximum: MAX_PAGE }, ...(action === 'snapshot' ? { knownRevision: { type: 'string', maxLength: 128 } } : { pageCursor: { type: 'string', maxLength: 512 } }) });
|
|
313
|
+
if (action === 'detail') {
|
|
314
|
+
properties.id = { type: 'string', pattern: '^[a-z0-9][a-z0-9._-]{0,63}$' };
|
|
315
|
+
required.push('id');
|
|
316
|
+
}
|
|
317
|
+
if (action === 'changes') {
|
|
318
|
+
properties.cursor = { type: 'string', maxLength: 128 };
|
|
319
|
+
required.push('cursor');
|
|
320
|
+
}
|
|
321
|
+
return { type: 'object', additionalProperties: false, required: ['type', 'request_id', 'data'], properties: { type: { const: type }, request_id: { type: 'string', minLength: 1, maxLength: 128 }, data: { type: 'object', additionalProperties: false, required, properties } } };
|
|
322
|
+
}
|
|
323
|
+
export function outputCardsResponseSchema() {
|
|
324
|
+
return { type: 'object', additionalProperties: false,
|
|
325
|
+
required: ['protocol', 'protocolVersion', 'sourceAid', 'revision', 'cursor', 'generatedAt', 'notifications', 'items', 'nextCursor'],
|
|
326
|
+
properties: {
|
|
327
|
+
protocol: { const: 'evol.output-cards' }, protocolVersion: { const: 1 }, sourceAid: { type: 'string', minLength: 3, maxLength: 256 },
|
|
328
|
+
revision: { type: 'string', pattern: '^[a-f0-9]{24}$' }, cursor: { type: 'string', pattern: '^[a-f0-9]{24}\\.\\d+$', maxLength: 128 }, generatedAt: { type: 'integer', minimum: 0 },
|
|
329
|
+
notifications: { anyOf: [{ type: 'null' }, { type: 'object', additionalProperties: false, required: ['busAid', 'event'], properties: { busAid: { type: 'string' }, event: { const: OUTPUT_CARDS_EVENT } } }] },
|
|
330
|
+
items: { type: 'array', maxItems: MAX_PAGE, items: { type: 'object', additionalProperties: false, required: ['schemaVersion', 'id', 'kind', 'title', 'summary', 'updatedAt', 'version', 'files'], properties: {
|
|
331
|
+
schemaVersion: { const: 1 }, id: { type: 'string', pattern: '^[a-z0-9][a-z0-9._-]{0,63}$' }, kind: { enum: KINDS }, title: { type: 'string', maxLength: 160 }, summary: { type: 'string', maxLength: 640 }, updatedAt: { type: 'integer', minimum: 0 }, version: { type: 'string', pattern: '^[a-f0-9]{24}$' },
|
|
332
|
+
files: { type: 'array', minItems: 1, maxItems: MAX_FILES, items: { type: 'object', additionalProperties: false, required: ['role', 'path', 'label', 'outputId'], properties: { role: { enum: ROLES }, path: { type: 'string', maxLength: 2048, pattern: '^output/[^\\\\:\\u0000-\\u001f\\u007f]+$' }, label: { type: 'string', maxLength: 100 }, outputId: { type: 'string', pattern: '^[a-f0-9]{32}$' } } } },
|
|
333
|
+
} } },
|
|
334
|
+
nextCursor: { anyOf: [{ type: 'null' }, { type: 'string', maxLength: 512 }] }, reset: { type: 'boolean' }, notModified: { type: 'boolean' }, deletes: { type: 'array', maxItems: 100, uniqueItems: true, items: { type: 'string', pattern: '^[a-z0-9][a-z0-9._-]{0,63}$' } },
|
|
335
|
+
} };
|
|
336
|
+
}
|
package/dist/outputs/events.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ownerResolver, OWNERSHIP_AUTHORIZATION_MAX_AGE_MS } from '../core/ownership/owner-resolver.js';
|
|
2
2
|
import { OUTPUT_EVENT } from './protocol.js';
|
|
3
|
+
import { OUTPUT_CARDS_EVENT } from './protocol.js';
|
|
3
4
|
import { WORKBENCH_EVENT } from '../workbench/protocol.js';
|
|
4
|
-
export const PRIVATE_PROJECTION_EVENTS = [OUTPUT_EVENT, WORKBENCH_EVENT];
|
|
5
|
+
export const PRIVATE_PROJECTION_EVENTS = [OUTPUT_EVENT, OUTPUT_CARDS_EVENT, WORKBENCH_EVENT];
|
|
5
6
|
/** Fixed event shares the configured Bus. No pack, connection or switch is created. */
|
|
6
7
|
export function registerOutputEvent(state) {
|
|
7
8
|
const conflicts = state.enabledPacks.filter(pack => pack.register.some(item => PRIVATE_PROJECTION_EVENTS.some(event => event === item.event)));
|
|
@@ -12,7 +13,7 @@ export function registerOutputEvent(state) {
|
|
|
12
13
|
state.catalog = state.catalog.filter(item => !PRIVATE_PROJECTION_EVENTS.some(event => event === item.event) && !ids.has(item.sourcePackId));
|
|
13
14
|
for (const event of PRIVATE_PROJECTION_EVENTS)
|
|
14
15
|
state.catalog.push({ event, ttl: 30, maxTtl: 60,
|
|
15
|
-
schemaVersion: 1, sourcePackId: event ===
|
|
16
|
+
schemaVersion: 1, sourcePackId: event === WORKBENCH_EVENT ? 'builtin.workbench' : 'builtin.outputs' });
|
|
16
17
|
}
|
|
17
18
|
export function outputAllowlist(aid, result) {
|
|
18
19
|
const owner = ownerResolver.snapshot(aid);
|
package/dist/outputs/protocol.js
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { parseDocument } from 'yaml';
|
|
4
4
|
export const OUTPUT_EVENT = 'team.outputs.changed';
|
|
5
|
+
export const OUTPUT_CARDS_EVENT = 'team.output-cards.changed';
|
|
5
6
|
export const OUTPUT_TYPES = ['snapshot', 'list', 'detail', 'changes'].map(action => `services.outputs.${action}`);
|
|
6
7
|
export const isOutputType = (type) => OUTPUT_TYPES.includes(type);
|
|
7
8
|
export const outputId = (relative) => crypto.createHash('sha256').update(relative).digest('hex').slice(0, 32);
|
package/dist/outputs/service.js
CHANGED
|
@@ -4,7 +4,7 @@ import crypto from 'node:crypto';
|
|
|
4
4
|
import { agentOutputDir } from '../paths.js';
|
|
5
5
|
import { TeamWorkspaceStore, DataRootError } from '../core/command/team-workspace-store.js';
|
|
6
6
|
import { TeamWorkspaceItemsIndex } from '../core/command/team-workspace-items.js';
|
|
7
|
-
import {
|
|
7
|
+
import { currentOutputOwner, authorizeOutput } from './authorization.js';
|
|
8
8
|
import { isOutputType, outputId, outputItem, outputKind, OUTPUT_EVENT } from './protocol.js';
|
|
9
9
|
let outputChangePublisher;
|
|
10
10
|
let outputNotificationsAvailable = () => false;
|
|
@@ -51,20 +51,7 @@ class OutputStore extends TeamWorkspaceStore {
|
|
|
51
51
|
entries: [{ id: 'output', title: 'Output', path: 'output', kind: 'directory', order: 0 }] };
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
export
|
|
55
|
-
const view = await ownerResolver.refresh(aid, { maxAgeMs: OWNERSHIP_AUTHORIZATION_MAX_AGE_MS, source: 'outputs.read', allowTransient: false });
|
|
56
|
-
if (view.authorizationStatus !== 'verified' || view.ownerAid !== from || view.refreshFailure?.fallbackUsed
|
|
57
|
-
|| (view.validUntil ?? 0) <= Date.now()) {
|
|
58
|
-
throw new DataRootError('OUTPUT_FORBIDDEN', 'Current protocol Owner authorization is required');
|
|
59
|
-
}
|
|
60
|
-
return `${view.ownerAid}:${view.revision}`;
|
|
61
|
-
}
|
|
62
|
-
export function currentOutputOwner(aid, from, generation) {
|
|
63
|
-
const view = ownerResolver.snapshot(aid);
|
|
64
|
-
return view.authorizationStatus === 'verified' && !view.refreshFailure?.fallbackUsed
|
|
65
|
-
&& (view.validUntil ?? 0) > Date.now()
|
|
66
|
-
&& view.ownerAid === from && `${view.ownerAid}:${view.revision}` === generation;
|
|
67
|
-
}
|
|
54
|
+
export { authorizeOutput, currentOutputOwner } from './authorization.js';
|
|
68
55
|
export class OutputService {
|
|
69
56
|
aid;
|
|
70
57
|
options;
|