evolcore 0.0.41-test.0 → 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 +49 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +20 -43
- package/dist/agents/claude-runner.js +177 -92
- package/dist/agents/codex-runner.js +84 -28
- package/dist/agents/ecagent-runner.js +1 -1
- package/dist/agents/gemini-runner.js +1 -1
- package/dist/aun/group/fs-download.js +39 -0
- package/dist/aun/group/identity.js +36 -21
- package/dist/aun/group/operations.js +5 -0
- package/dist/aun/msg/managed-operation.js +68 -7
- package/dist/aun/msg/p2p.js +5 -0
- package/dist/aun/service-proxy.js +36 -12
- package/dist/channels/aun.js +334 -20
- package/dist/channels/daemon.js +15 -1
- package/dist/cli/aun-commands.js +4 -20
- package/dist/cli/daemon-commands.js +678 -697
- 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/role.js +85 -0
- package/dist/config/access-policy.js +7 -2
- 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 +5 -19
- 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 +88 -594
- package/dist/config/peer-role-resolver.js +13 -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-runtime.js +1 -1
- package/dist/core/auth/agent-delegation.js +2 -1
- package/dist/core/auth/auth-gateway.js +1 -1
- package/dist/core/auth/authorization-audit.js +17 -6
- 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 +31 -6
- package/dist/core/command/agent-control.js +3 -7
- 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 +48 -99
- package/dist/core/command/connect-menu.js +11 -3
- 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 +5 -6
- package/dist/core/command/menu-handler.js +49 -62
- package/dist/core/command/role-menu.js +147 -30
- package/dist/core/command/slash-handler.js +123 -254
- package/dist/core/daemon-control.js +8 -14
- 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 +6 -2
- 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 +189 -189
- 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 +8 -2
- package/dist/core/message/im-renderer.js +7 -4
- package/dist/core/message/message-admission.js +89 -4
- package/dist/core/message/message-bridge.js +31 -18
- package/dist/core/message/response-engine.js +77 -8
- 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 +30 -41
- 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 +23 -21
- package/dist/core/permission/ec-command-parser.js +30 -2
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +14 -3
- 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 +1 -1
- package/dist/core/session/session-idle-monitor.js +1 -1
- package/dist/core/session/session-manager.js +20 -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 +76 -14
- package/dist/ipc.js +170 -12
- 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/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +2 -2
- package/dist/utils/logger.js +24 -5
- package/dist/utils/package-version-info.js +4 -2
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +17 -6
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/fs.md +11 -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 +4 -0
- package/kits/docs/evolcore/model.md +23 -20
- package/kits/docs/evolcore/msg.md +4 -7
- 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 +8 -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/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/system-fragments/baseagent.md +2 -2
- package/kits/templates/system-fragments/memory.md +4 -4
- package/package.json +6 -2
package/dist/ipc.js
CHANGED
|
@@ -74,6 +74,8 @@ const LOCAL_CONTROL_COMMANDS = new Set([
|
|
|
74
74
|
'menu.exec',
|
|
75
75
|
'ecweb.providers',
|
|
76
76
|
'ecweb.basic-settings',
|
|
77
|
+
'ecweb.message.context',
|
|
78
|
+
'ecweb.session.runner-tasks',
|
|
77
79
|
'model.catalog',
|
|
78
80
|
'baseagent.snapshot',
|
|
79
81
|
'monitor-snapshot',
|
|
@@ -90,7 +92,7 @@ const MEMORY_COMMAND_ENDPOINTS = new Set([
|
|
|
90
92
|
'memory.create', 'memory.update', 'memory.archive', 'memory.demote', 'memory.consolidate',
|
|
91
93
|
]);
|
|
92
94
|
const DELEGATED_ARGV_ENDPOINTS = new Set([
|
|
93
|
-
'agent.op', 'config.op', 'contact.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op',
|
|
95
|
+
'agent.op', 'config.op', 'contact.op', 'aid.op', 'aid.ownership', 'group.op', 'msg.op', 'fs.op', 'proxy.op',
|
|
94
96
|
'ctl', 'diag', 'menu-client.request', 'task.resume', 'queue.op', 'storage.auth', 'storage.upload',
|
|
95
97
|
'trigger.op', 'skill.refresh', 'thread.op', 'local-command-context', 'evolagent.bootstrapComplete', 'status.auth', ...MEMORY_COMMAND_ENDPOINTS,
|
|
96
98
|
'handoff-return', 'handoff-recover-return', 'handoff-status', 'handoff-list', 'handoff-trace',
|
|
@@ -182,6 +184,7 @@ export class IpcServer {
|
|
|
182
184
|
aunAidStatsProvider;
|
|
183
185
|
aunAidStatsRecorder;
|
|
184
186
|
menuExecutor;
|
|
187
|
+
ecwebMessageContextProvider;
|
|
185
188
|
agentOperationExecutor;
|
|
186
189
|
skillRefreshExecutor;
|
|
187
190
|
initializationExecutor;
|
|
@@ -195,6 +198,7 @@ export class IpcServer {
|
|
|
195
198
|
storageAuthorizationExecutor;
|
|
196
199
|
storageUploadExecutor;
|
|
197
200
|
triggerExecutor;
|
|
201
|
+
proxyExecutor;
|
|
198
202
|
consolidationLaunchExecutor;
|
|
199
203
|
consolidationCheckExecutor;
|
|
200
204
|
bootstrapCompleteExecutor;
|
|
@@ -219,6 +223,7 @@ export class IpcServer {
|
|
|
219
223
|
aidOwnershipExecutor;
|
|
220
224
|
configOperationExecutor;
|
|
221
225
|
contactOperationExecutor;
|
|
226
|
+
roleOperationExecutor;
|
|
222
227
|
aidOperationExecutor;
|
|
223
228
|
groupOperationExecutor;
|
|
224
229
|
msgOperationExecutor;
|
|
@@ -309,12 +314,18 @@ export class IpcServer {
|
|
|
309
314
|
setMenuExecutor(executor) {
|
|
310
315
|
this.menuExecutor = executor;
|
|
311
316
|
}
|
|
317
|
+
setEcwebMessageContextProvider(provider) {
|
|
318
|
+
this.ecwebMessageContextProvider = provider;
|
|
319
|
+
}
|
|
312
320
|
setInitializationExecutor(executor) {
|
|
313
321
|
this.initializationExecutor = executor;
|
|
314
322
|
}
|
|
315
323
|
setAgentOperationExecutor(executor) {
|
|
316
324
|
this.agentOperationExecutor = executor;
|
|
317
325
|
}
|
|
326
|
+
setRoleOperationExecutor(executor) {
|
|
327
|
+
this.roleOperationExecutor = executor;
|
|
328
|
+
}
|
|
318
329
|
setSkillRefreshExecutor(executor) {
|
|
319
330
|
this.skillRefreshExecutor = executor;
|
|
320
331
|
}
|
|
@@ -474,6 +485,9 @@ export class IpcServer {
|
|
|
474
485
|
setTriggerExecutor(executor) {
|
|
475
486
|
this.triggerExecutor = executor;
|
|
476
487
|
}
|
|
488
|
+
setProxyExecutor(executor) {
|
|
489
|
+
this.proxyExecutor = executor;
|
|
490
|
+
}
|
|
477
491
|
/** Inject daemon-level consolidation launcher (BackgroundSessionLauncher, via executor closure). */
|
|
478
492
|
setConsolidationLaunchExecutor(executor) {
|
|
479
493
|
this.consolidationLaunchExecutor = executor;
|
|
@@ -1014,17 +1028,21 @@ export class IpcServer {
|
|
|
1014
1028
|
if (!Array.isArray(cmd.argv) || cmd.argv.some(value => typeof value !== 'string')) {
|
|
1015
1029
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Invalid command argv' };
|
|
1016
1030
|
}
|
|
1017
|
-
const expectedArgv = [
|
|
1018
|
-
MAIN_CLI_BIN,
|
|
1019
|
-
...(cmd.type === 'menu-client.request' ? ['menu-client'] : []),
|
|
1020
|
-
...cmd.argv,
|
|
1021
|
-
];
|
|
1022
1031
|
const executionSpec = cmd.executionSpec === undefined
|
|
1023
1032
|
? undefined
|
|
1024
1033
|
: parseDelegatedExecutionSpec(cmd.executionSpec);
|
|
1025
1034
|
if (cmd.executionSpec !== undefined && !executionSpec) {
|
|
1026
1035
|
return { ok: false, code: 'INVALID_REQUEST', error: 'Invalid delegated execution spec' };
|
|
1027
1036
|
}
|
|
1037
|
+
// 与客户端同一基准:有 spec 时指纹绑定 spec.argv(preflight 批准并实际 spawn 的
|
|
1038
|
+
// argv),cmd.argv 可能已被 CLI 合法补全(如 msg send --thread 推导收发方)。
|
|
1039
|
+
const expectedArgv = executionSpec
|
|
1040
|
+
? [...executionSpec.argv]
|
|
1041
|
+
: [
|
|
1042
|
+
MAIN_CLI_BIN,
|
|
1043
|
+
...(cmd.type === 'menu-client.request' ? ['menu-client'] : []),
|
|
1044
|
+
...cmd.argv,
|
|
1045
|
+
];
|
|
1028
1046
|
const expectedHash = hashDelegatedCommandArgv(expectedArgv, executionSpec);
|
|
1029
1047
|
if (!expectedHash || cmd.delegationCommandHash !== expectedHash) {
|
|
1030
1048
|
return this.diagnosticRejection('command_hash_mismatch', cmd);
|
|
@@ -1115,6 +1133,36 @@ export class IpcServer {
|
|
|
1115
1133
|
const { handleBasicSettingsService } = await import('./ecweb/basic-settings-service.js');
|
|
1116
1134
|
return handleBasicSettingsService(cmd.request);
|
|
1117
1135
|
}
|
|
1136
|
+
case 'ecweb.message.context': {
|
|
1137
|
+
if (!cmd.request || typeof cmd.request !== 'object' || Array.isArray(cmd.request)) {
|
|
1138
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'request must be an object' };
|
|
1139
|
+
}
|
|
1140
|
+
if (!this.ecwebMessageContextProvider) {
|
|
1141
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'ECWeb message context provider is unavailable' };
|
|
1142
|
+
}
|
|
1143
|
+
try {
|
|
1144
|
+
return { ok: true, ...(await this.ecwebMessageContextProvider(cmd.request)) };
|
|
1145
|
+
}
|
|
1146
|
+
catch (error) {
|
|
1147
|
+
return {
|
|
1148
|
+
ok: false,
|
|
1149
|
+
code: error?.code === 'INVALID_REQUEST' ? 'INVALID_REQUEST' : 'MESSAGE_CONTEXT_UNAVAILABLE',
|
|
1150
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
case 'ecweb.session.runner-tasks': {
|
|
1155
|
+
if (typeof cmd.sessionId !== 'string' || !cmd.sessionId.trim() || cmd.sessionId.length > 256) {
|
|
1156
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'sessionId must be a non-empty string of at most 256 characters' };
|
|
1157
|
+
}
|
|
1158
|
+
try {
|
|
1159
|
+
const { readRunnerEventSummary } = await import('./core/session/runner-event-summary.js');
|
|
1160
|
+
return { ok: true, tasks: readRunnerEventSummary(resolvePaths().logs, cmd.sessionId.trim()) };
|
|
1161
|
+
}
|
|
1162
|
+
catch (error) {
|
|
1163
|
+
return { ok: false, code: 'SESSION_TASK_SUMMARY_UNAVAILABLE', error: error instanceof Error ? error.message : String(error) };
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1118
1166
|
case 'model.catalog': {
|
|
1119
1167
|
if ((cmd.self !== undefined && typeof cmd.self !== 'string')
|
|
1120
1168
|
|| (cmd.baseagent !== undefined && !['claude', 'codex', 'ecagent', 'gemini'].includes(cmd.baseagent))) {
|
|
@@ -1926,8 +1974,24 @@ export class IpcServer {
|
|
|
1926
1974
|
const guard = await this.assertMemoryWriteSession(sessionId, scope, 'create', replaces, cmd.debug === true);
|
|
1927
1975
|
if ('error' in guard)
|
|
1928
1976
|
return guard.error;
|
|
1929
|
-
const { createMemory } = await import('./core/memory/memory-writer.js');
|
|
1977
|
+
const { createMemory, sourceMemoryDirOf } = await import('./core/memory/memory-writer.js');
|
|
1930
1978
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
1979
|
+
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/forget-log.js');
|
|
1980
|
+
// forget 下 create 只用于合并:被替换的每条旧记忆都要记遗忘理由。
|
|
1981
|
+
// 不带 --replaces 等于在遗忘会话里新建记忆,既不是遗忘也没有理由可记,直接拒绝。
|
|
1982
|
+
// 其他模式的 --replaces 是记忆产生 / 泛化的过程,不进遗忘日志。
|
|
1983
|
+
const isForgetMode = guard.taskCtx.memoryMode === 'forget';
|
|
1984
|
+
if (isForgetMode && !(Array.isArray(replaces) && replaces.length > 0)) {
|
|
1985
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: "forget 模式的 create 只用于合并:必须带 --replaces 指定被合并的旧记忆(遗忘日志按旧记忆逐条记理由)" };
|
|
1986
|
+
}
|
|
1987
|
+
const forgetMerge = isForgetMode;
|
|
1988
|
+
let forgetReason;
|
|
1989
|
+
if (forgetMerge) {
|
|
1990
|
+
const checked = checkForgetReason(reason);
|
|
1991
|
+
if (!checked.ok)
|
|
1992
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: checked.error };
|
|
1993
|
+
forgetReason = checked.reason;
|
|
1994
|
+
}
|
|
1931
1995
|
let createResult;
|
|
1932
1996
|
try {
|
|
1933
1997
|
createResult = await createMemory({
|
|
@@ -1950,8 +2014,18 @@ export class IpcServer {
|
|
|
1950
2014
|
throw e;
|
|
1951
2015
|
}
|
|
1952
2016
|
const batchDir = guard.taskCtx.consolidationBatchDir;
|
|
2017
|
+
let forgetLogged = false;
|
|
2018
|
+
if (forgetReason) {
|
|
2019
|
+
for (const src of createResult.archivedSources) {
|
|
2020
|
+
const ok = appendForgetLog(sourceMemoryDirOf(src), {
|
|
2021
|
+
action: `合并归档→${slug}`, slug: slugOfMemoryFile(src), reason: forgetReason, source: batchSourceLabel(batchDir),
|
|
2022
|
+
});
|
|
2023
|
+
forgetLogged = forgetLogged || ok;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
const opsReason = forgetReason ?? reason;
|
|
1953
2027
|
if (batchDir)
|
|
1954
|
-
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'create', scope: scope ?? '', target: slug ?? '', filePath: createResult.filePath, archivedFiles: createResult.archived.map((dest, i) => ({ source: createResult.archivedSources[i] ?? dest, archivedTo: dest })), tags: Array.isArray(tags) ? tags : [], memoryDir: createResult.scopeDirs.memoryDir, ok: true, ...(
|
|
2028
|
+
appendOpsRecord(batchDir, { ts: new Date().toISOString(), op: 'create', scope: scope ?? '', target: slug ?? '', filePath: createResult.filePath, archivedFiles: createResult.archived.map((dest, i) => ({ source: createResult.archivedSources[i] ?? dest, archivedTo: dest })), tags: Array.isArray(tags) ? tags : [], memoryDir: createResult.scopeDirs.memoryDir, ok: true, ...(opsReason ? { reason: opsReason } : {}), ...(forgetLogged ? { forgetLogged } : {}) });
|
|
1955
2029
|
return { ok: true, filePath: createResult.filePath, archived: createResult.archived };
|
|
1956
2030
|
}
|
|
1957
2031
|
catch (e) {
|
|
@@ -1968,6 +2042,18 @@ export class IpcServer {
|
|
|
1968
2042
|
return guard.error;
|
|
1969
2043
|
const { updateMemory } = await import('./core/memory/memory-writer.js');
|
|
1970
2044
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
2045
|
+
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/forget-log.js');
|
|
2046
|
+
// forget 下 update 只有续期一种用法:不许改标签(那是 notes 模式的事),每条都要带理由
|
|
2047
|
+
let forgetReason;
|
|
2048
|
+
if (guard.taskCtx.memoryMode === 'forget') {
|
|
2049
|
+
if (Array.isArray(tags) || !touch) {
|
|
2050
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: "forget 模式的 update 只能用于续期:ec memory update <路径> --touch --reason '<理由>',不能改标签" };
|
|
2051
|
+
}
|
|
2052
|
+
const checked = checkForgetReason(reason);
|
|
2053
|
+
if (!checked.ok)
|
|
2054
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: checked.error };
|
|
2055
|
+
forgetReason = checked.reason;
|
|
2056
|
+
}
|
|
1971
2057
|
let updateResult;
|
|
1972
2058
|
try {
|
|
1973
2059
|
updateResult = await updateMemory({
|
|
@@ -1988,8 +2074,14 @@ export class IpcServer {
|
|
|
1988
2074
|
const batchDirU = guard.taskCtx.consolidationBatchDir;
|
|
1989
2075
|
// target 记解析后的绝对路径:回滚直接拿它读写文件,argv 原文(如 consolidated/x.md)
|
|
1990
2076
|
// 会相对 daemon 的 cwd 解析而找不到。memoryDir 记文件实际所在层,供收尾重建索引。
|
|
2077
|
+
const forgetLogged = forgetReason
|
|
2078
|
+
? appendForgetLog(updateResult.targetMemoryDir, {
|
|
2079
|
+
action: '续期', slug: slugOfMemoryFile(updateResult.filePath), reason: forgetReason, source: batchSourceLabel(batchDirU),
|
|
2080
|
+
})
|
|
2081
|
+
: false;
|
|
2082
|
+
const opsReasonU = forgetReason ?? reason;
|
|
1991
2083
|
if (batchDirU)
|
|
1992
|
-
appendOpsRecord(batchDirU, { ts: new Date().toISOString(), op: 'update', scope: guard.writeScope, target: updateResult.filePath, tags: Array.isArray(tags) ? tags : undefined, prevTags: updateResult.prevTags, memoryDir: updateResult.targetMemoryDir, ok: true, ...(
|
|
2084
|
+
appendOpsRecord(batchDirU, { ts: new Date().toISOString(), op: 'update', scope: guard.writeScope, target: updateResult.filePath, tags: Array.isArray(tags) ? tags : undefined, prevTags: updateResult.prevTags, prevMtimeMs: updateResult.prevMtimeMs, ...(updateResult.prevUpdatedAt !== undefined ? { prevUpdatedAt: updateResult.prevUpdatedAt } : {}), ...(touch ? { touch: true } : {}), memoryDir: updateResult.targetMemoryDir, ok: true, ...(opsReasonU ? { reason: opsReasonU } : {}), ...(forgetLogged ? { forgetLogged } : {}) });
|
|
1993
2085
|
return { ok: true, filePath: updateResult.filePath };
|
|
1994
2086
|
}
|
|
1995
2087
|
catch (e) {
|
|
@@ -2006,6 +2098,18 @@ export class IpcServer {
|
|
|
2006
2098
|
return guard.error;
|
|
2007
2099
|
const { archiveMemory, sourceMemoryDirOf } = await import('./core/memory/memory-writer.js');
|
|
2008
2100
|
const { appendOpsRecord } = await import('./core/memory/consolidation-ops-records.js');
|
|
2101
|
+
const { appendForgetLog, batchSourceLabel, checkForgetReason, slugOfMemoryFile } = await import('./core/memory/forget-log.js');
|
|
2102
|
+
// forget 下一次只归档一条:理由是针对这一条记忆的,多条共用一个理由就失去了意义
|
|
2103
|
+
let forgetReason;
|
|
2104
|
+
if (guard.taskCtx.memoryMode === 'forget') {
|
|
2105
|
+
if (!Array.isArray(filePaths) || filePaths.length !== 1) {
|
|
2106
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: "forget 模式一次只能归档一条记忆,每条各带 --reason:ec memory archive <路径> --reason '<理由>'" };
|
|
2107
|
+
}
|
|
2108
|
+
const checked = checkForgetReason(reason);
|
|
2109
|
+
if (!checked.ok)
|
|
2110
|
+
return { ok: false, code: 'INVALID_ARGUMENT', error: checked.error };
|
|
2111
|
+
forgetReason = checked.reason;
|
|
2112
|
+
}
|
|
2009
2113
|
let archiveResult;
|
|
2010
2114
|
try {
|
|
2011
2115
|
archiveResult = await archiveMemory({
|
|
@@ -2031,7 +2135,21 @@ export class IpcServer {
|
|
|
2031
2135
|
// memoryDir 取**源文件所属层**,不是本作用域:collectAffectedScopes 靠它
|
|
2032
2136
|
// 决定收尾重建哪几层索引,写成本作用域会导致关系级索引不重建。
|
|
2033
2137
|
const srcMemoryDir = sourceMemoryDirOf(sourceFile);
|
|
2034
|
-
|
|
2138
|
+
const forgetLogged = forgetReason
|
|
2139
|
+
? appendForgetLog(srcMemoryDir, {
|
|
2140
|
+
action: '归档', slug: slugOfMemoryFile(sourceFile), reason: forgetReason, source: batchSourceLabel(batchDirA),
|
|
2141
|
+
})
|
|
2142
|
+
: false;
|
|
2143
|
+
const opsReasonA = forgetReason ?? reason;
|
|
2144
|
+
appendOpsRecord(batchDirA, { ts: new Date().toISOString(), op: 'archive', scope: guard.writeScope, target: archivedTo, sourceFile, archivedTo, memoryDir: srcMemoryDir, ok: true, ...(opsReasonA ? { reason: opsReasonA } : {}), ...(forgetLogged ? { forgetLogged } : {}) });
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
else if (forgetReason) {
|
|
2148
|
+
// 没有批次目录(如 --debug 重建的上下文)也照样记遗忘日志
|
|
2149
|
+
for (const sourceFile of archiveResult.archivedSources) {
|
|
2150
|
+
appendForgetLog(sourceMemoryDirOf(sourceFile), {
|
|
2151
|
+
action: '归档', slug: slugOfMemoryFile(sourceFile), reason: forgetReason, source: batchSourceLabel(undefined),
|
|
2152
|
+
});
|
|
2035
2153
|
}
|
|
2036
2154
|
}
|
|
2037
2155
|
return { ok: true, archived: archiveResult.archived };
|
|
@@ -2108,6 +2226,18 @@ export class IpcServer {
|
|
|
2108
2226
|
}
|
|
2109
2227
|
return await this.contactOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2110
2228
|
}
|
|
2229
|
+
case 'role.op': {
|
|
2230
|
+
if (!this.roleOperationExecutor)
|
|
2231
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'role.op not configured' };
|
|
2232
|
+
const { argv, sessionId, delegationToken } = cmd;
|
|
2233
|
+
if (!Array.isArray(argv) || argv.some(value => typeof value !== 'string') || !sessionId) {
|
|
2234
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'missing argv or sessionId' };
|
|
2235
|
+
}
|
|
2236
|
+
if (delegationToken !== undefined && typeof delegationToken !== 'string') {
|
|
2237
|
+
return { ok: false, code: 'INVALID_DELEGATION', error: 'delegationToken must be a string' };
|
|
2238
|
+
}
|
|
2239
|
+
return await this.roleOperationExecutor(argv, sessionId, delegationToken, typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined);
|
|
2240
|
+
}
|
|
2111
2241
|
case 'aid.op': {
|
|
2112
2242
|
if (!this.aidOperationExecutor)
|
|
2113
2243
|
return { ok: false, code: 'NOT_CONFIGURED', error: 'aid.op not configured' };
|
|
@@ -2232,6 +2362,30 @@ export class IpcServer {
|
|
|
2232
2362
|
return { ok: false, error: e?.message || String(e) };
|
|
2233
2363
|
}
|
|
2234
2364
|
}
|
|
2365
|
+
case 'proxy.op': {
|
|
2366
|
+
if (!this.proxyExecutor)
|
|
2367
|
+
return { ok: false, code: 'NOT_CONFIGURED', error: 'proxy manager is unavailable' };
|
|
2368
|
+
const delegated = typeof cmd.sessionId === 'string' && !!cmd.sessionId
|
|
2369
|
+
&& typeof cmd.delegationToken === 'string' && !!cmd.delegationToken;
|
|
2370
|
+
const localControl = !delegated && this.hasValidControlToken(cmd.controlToken);
|
|
2371
|
+
if (!localControl && !delegated)
|
|
2372
|
+
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'proxy operations require host control or task delegation' };
|
|
2373
|
+
if (!Array.isArray(cmd.argv) || cmd.argv.some((value) => typeof value !== 'string')
|
|
2374
|
+
|| cmd.argv[0] !== 'proxy') {
|
|
2375
|
+
return { ok: false, code: 'INVALID_REQUEST', error: 'proxy.op requires argv beginning with proxy' };
|
|
2376
|
+
}
|
|
2377
|
+
try {
|
|
2378
|
+
return await this.proxyExecutor(cmd, { localControl });
|
|
2379
|
+
}
|
|
2380
|
+
catch (error) {
|
|
2381
|
+
return {
|
|
2382
|
+
ok: false,
|
|
2383
|
+
code: String(error?.code ?? 'PROXY_OPERATION_FAILED'),
|
|
2384
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2385
|
+
...(error?.data === undefined ? {} : { data: error.data }),
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2235
2389
|
case 'evolagent.list': {
|
|
2236
2390
|
if (this.agentApplicationService) {
|
|
2237
2391
|
return { ok: true, agents: this.agentApplicationService.list() };
|
|
@@ -2711,10 +2865,14 @@ function ipcQueryOnce(socketPath, cmd, timeoutMs = 3000) {
|
|
|
2711
2865
|
const executionSpec = typeof authenticatedCmd.delegationToken === 'string'
|
|
2712
2866
|
? readDelegatedExecutionSpec()
|
|
2713
2867
|
: undefined;
|
|
2868
|
+
// executionSpec 存在时,spec.argv 才是 preflight 批准并实际 spawn 的 argv。CLI 之后
|
|
2869
|
+
// 仍可能补全 argv(例如 msg send --thread 推导收发方后 splice),那份 argv 与 spec.argv
|
|
2870
|
+
// 必然不同;指纹必须以 spec 为准,否则两端都算不出哈希而把合法调用判成 mismatch。
|
|
2871
|
+
const hashArgv = executionSpec?.argv ?? requestArgv;
|
|
2714
2872
|
const delegationCommandHash = typeof authenticatedCmd.delegationToken === 'string'
|
|
2715
2873
|
&& typeof authenticatedCmd.delegationCommandHash !== 'string'
|
|
2716
|
-
?
|
|
2717
|
-
? hashDelegatedCommandArgv(
|
|
2874
|
+
? hashArgv
|
|
2875
|
+
? hashDelegatedCommandArgv(hashArgv, executionSpec)
|
|
2718
2876
|
: hashCurrentDelegatedCommand()
|
|
2719
2877
|
: undefined;
|
|
2720
2878
|
const request = {
|
package/dist/paths.js
CHANGED
|
@@ -33,6 +33,7 @@ export function resolvePaths() {
|
|
|
33
33
|
// this directory is retained only for explicit data migration.
|
|
34
34
|
outboxDir: path.join(root, 'data', 'outbox'),
|
|
35
35
|
dataDir: path.join(root, 'data'),
|
|
36
|
+
proxyDir: path.join(root, 'data', 'proxy'),
|
|
36
37
|
claudeModelCache: path.join(root, 'data', 'claude-model-cache.json'),
|
|
37
38
|
providersConfig: path.join(root, 'providers.json'),
|
|
38
39
|
logs: path.join(root, 'logs'),
|
|
@@ -114,6 +115,9 @@ export function agentRolesIndex(aid) {
|
|
|
114
115
|
export function agentRoleConfig(aid, roleId) {
|
|
115
116
|
return path.join(agentRolesDir(aid), `${roleId}.json`);
|
|
116
117
|
}
|
|
118
|
+
export function agentRoleRequestsPath(aid) {
|
|
119
|
+
return path.join(agentDataDir(aid), 'roles', 'requests.json');
|
|
120
|
+
}
|
|
117
121
|
export function agentRelationsDir(aid) {
|
|
118
122
|
return path.join(agentDir(aid), 'relations');
|
|
119
123
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
const COMMANDS = new Set([
|
|
3
|
+
'list', 'show', 'status', 'access', 'options', 'build', 'update', 'apply',
|
|
4
|
+
'publish', 'unpublish', 'remove', 'start', 'stop', 'restart', 'reload',
|
|
5
|
+
'reset-failure', 'job',
|
|
6
|
+
]);
|
|
7
|
+
const VALUE_FLAGS = new Set(['--file', '--json', '--if-rev', '--operation-id', '--format']);
|
|
8
|
+
function parseArgs(args) {
|
|
9
|
+
const positionals = [];
|
|
10
|
+
const values = new Map();
|
|
11
|
+
const switches = new Set();
|
|
12
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
13
|
+
const token = args[index];
|
|
14
|
+
if (token === '--dry-run' || token === '--all') {
|
|
15
|
+
switches.add(token);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const equal = token.indexOf('=');
|
|
19
|
+
const flag = equal > 0 ? token.slice(0, equal) : token;
|
|
20
|
+
if (VALUE_FLAGS.has(flag)) {
|
|
21
|
+
const value = equal > 0 ? token.slice(equal + 1) : args[++index];
|
|
22
|
+
if (typeof value !== 'string' || !value)
|
|
23
|
+
throw Object.assign(new Error(flag + ' requires a value'), { code: 'INVALID_ARGUMENT' });
|
|
24
|
+
if (values.has(flag))
|
|
25
|
+
throw Object.assign(new Error(flag + ' may only be specified once'), { code: 'INVALID_ARGUMENT' });
|
|
26
|
+
values.set(flag, value);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (token.startsWith('-'))
|
|
30
|
+
throw Object.assign(new Error('unsupported proxy option: ' + token), { code: 'INVALID_ARGUMENT' });
|
|
31
|
+
positionals.push(token);
|
|
32
|
+
}
|
|
33
|
+
const format = values.get('--format');
|
|
34
|
+
if (format !== undefined && format !== 'json')
|
|
35
|
+
throw Object.assign(new Error('--format only accepts json'), { code: 'INVALID_ARGUMENT' });
|
|
36
|
+
if (values.has('--json') && values.has('--file'))
|
|
37
|
+
throw Object.assign(new Error('--json and --file are mutually exclusive'), { code: 'INVALID_ARGUMENT' });
|
|
38
|
+
return { positionals, values, switches };
|
|
39
|
+
}
|
|
40
|
+
export function proxyOperationForArgv(argv) {
|
|
41
|
+
const args = argv[0] === 'proxy' ? argv.slice(1) : [...argv];
|
|
42
|
+
const operation = args[0];
|
|
43
|
+
if (!operation || !COMMANDS.has(operation)) {
|
|
44
|
+
throw Object.assign(new Error('usage: ec proxy <' + [...COMMANDS].join('|') + '>'), { code: 'INVALID_ARGUMENT' });
|
|
45
|
+
}
|
|
46
|
+
return operation;
|
|
47
|
+
}
|
|
48
|
+
export function parseProxyCommand(argv, options = {}) {
|
|
49
|
+
const args = argv[0] === 'proxy' ? argv.slice(1) : [...argv];
|
|
50
|
+
const operation = proxyOperationForArgv(argv);
|
|
51
|
+
const parsed = parseArgs(args.slice(1));
|
|
52
|
+
const { positionals, values, switches } = parsed;
|
|
53
|
+
const name = positionals[0];
|
|
54
|
+
const requiresName = new Set(['show', 'status', 'access', 'update', 'publish', 'unpublish', 'remove', 'start', 'stop', 'restart', 'reload', 'reset-failure', 'job']);
|
|
55
|
+
if (requiresName.has(operation) && !name)
|
|
56
|
+
throw Object.assign(new Error(operation + ' requires a service name or job id'), { code: 'INVALID_ARGUMENT' });
|
|
57
|
+
const ifRev = values.get('--if-rev');
|
|
58
|
+
const operationId = values.get('--operation-id');
|
|
59
|
+
const mutations = new Set(['build', 'update', 'apply', 'publish', 'unpublish', 'remove', 'start', 'stop', 'restart', 'reload', 'reset-failure']);
|
|
60
|
+
if (mutations.has(operation) && operation !== 'apply' && ifRev === undefined && !switches.has('--dry-run')) {
|
|
61
|
+
throw Object.assign(new Error('write operations require --if-rev'), { code: 'REVISION_REQUIRED' });
|
|
62
|
+
}
|
|
63
|
+
if (mutations.has(operation) && operation !== 'apply' && !operationId && !switches.has('--dry-run')) {
|
|
64
|
+
throw Object.assign(new Error('write operations require --operation-id'), { code: 'OPERATION_ID_REQUIRED' });
|
|
65
|
+
}
|
|
66
|
+
if (operation === 'apply' && !operationId && !switches.has('--dry-run')) {
|
|
67
|
+
throw Object.assign(new Error('apply requires --operation-id'), { code: 'OPERATION_ID_REQUIRED' });
|
|
68
|
+
}
|
|
69
|
+
const file = values.get('--file');
|
|
70
|
+
const json = values.get('--json');
|
|
71
|
+
if ((operation === 'build' || operation === 'update') && !file && !json) {
|
|
72
|
+
throw Object.assign(new Error(operation + ' requires --file or --json'), { code: 'INVALID_ARGUMENT' });
|
|
73
|
+
}
|
|
74
|
+
if (file && (!options.allowFile || !options.readInput)) {
|
|
75
|
+
throw Object.assign(new Error('managed proxy operations must use --json so approved argv binds the exact definition'), { code: 'DELEGATED_FILE_INPUT_UNSUPPORTED' });
|
|
76
|
+
}
|
|
77
|
+
let definition;
|
|
78
|
+
let inputFile;
|
|
79
|
+
if (file) {
|
|
80
|
+
inputFile = file;
|
|
81
|
+
definition = options.readInput(file);
|
|
82
|
+
}
|
|
83
|
+
else if (json) {
|
|
84
|
+
try {
|
|
85
|
+
definition = JSON.parse(json);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw Object.assign(new Error('--json must contain valid JSON'), { code: 'INVALID_ARGUMENT' });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (definition !== undefined && (!definition || typeof definition !== 'object' || Array.isArray(definition))) {
|
|
92
|
+
throw Object.assign(new Error('proxy definition must be a JSON object'), { code: 'INVALID_ARGUMENT' });
|
|
93
|
+
}
|
|
94
|
+
const request = {
|
|
95
|
+
operation,
|
|
96
|
+
...(name ? { name } : {}),
|
|
97
|
+
...(ifRev ? { ifRev } : {}),
|
|
98
|
+
...(operationId ? { operationId } : {}),
|
|
99
|
+
...(switches.has('--dry-run') ? { dryRun: true } : {}),
|
|
100
|
+
...(switches.has('--all') ? { all: true } : {}),
|
|
101
|
+
...(operation === 'job' && name ? { jobId: name } : {}),
|
|
102
|
+
};
|
|
103
|
+
if (operation === 'build' && definition)
|
|
104
|
+
request.service = definition;
|
|
105
|
+
if (operation === 'update' && definition)
|
|
106
|
+
request.patch = definition;
|
|
107
|
+
if (operation === 'build' && request.service && name && request.service.name !== name) {
|
|
108
|
+
throw Object.assign(new Error('service.name must match the requested name'), { code: 'INVALID_ARGUMENT' });
|
|
109
|
+
}
|
|
110
|
+
if (operation === 'build' && !name && request.service)
|
|
111
|
+
request.name = request.service.name;
|
|
112
|
+
if (operation === 'apply' && name)
|
|
113
|
+
request.name = name;
|
|
114
|
+
if (operationId === undefined && mutations.has(operation) && !switches.has('--dry-run'))
|
|
115
|
+
request.operationId = crypto.randomUUID();
|
|
116
|
+
return {
|
|
117
|
+
request,
|
|
118
|
+
format: values.get('--format') === 'json' || values.has('--json') ? 'json' : 'text',
|
|
119
|
+
...(inputFile ? { inputFile } : {}),
|
|
120
|
+
...(json ? { inlineJson: json } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isHClassPath, isLClassPath, isSameOrDescendant } from '../core/permission/protected-paths.js';
|
|
4
|
+
import { parseProxyCommand, proxyOperationForArgv } from './command.js';
|
|
5
|
+
function authorizationOperation(operation) {
|
|
6
|
+
if (['list', 'show', 'status', 'access', 'options', 'job'].includes(operation))
|
|
7
|
+
return 'proxy.read';
|
|
8
|
+
if (['start', 'stop', 'restart', 'reload', 'reset-failure'].includes(operation))
|
|
9
|
+
return 'proxy.lifecycle';
|
|
10
|
+
return 'proxy.configure';
|
|
11
|
+
}
|
|
12
|
+
function readDefinition(inputPath, session) {
|
|
13
|
+
const base = session?.projectPath ?? process.cwd();
|
|
14
|
+
const requested = path.resolve(base, inputPath);
|
|
15
|
+
const requestedStat = fs.lstatSync(requested);
|
|
16
|
+
if (!requestedStat.isFile() || requestedStat.isSymbolicLink() || requestedStat.nlink > 1) {
|
|
17
|
+
throw Object.assign(new Error('proxy definition must be a regular non-symlink file'), { code: 'INVALID_LOCAL_FILE' });
|
|
18
|
+
}
|
|
19
|
+
const realPath = fs.realpathSync(requested);
|
|
20
|
+
if (isHClassPath(realPath) || isLClassPath(realPath)) {
|
|
21
|
+
throw Object.assign(new Error('protected files cannot be used as proxy definitions'), { code: 'INVALID_LOCAL_PATH' });
|
|
22
|
+
}
|
|
23
|
+
if (session) {
|
|
24
|
+
const roots = [fs.realpathSync(session.projectPath)];
|
|
25
|
+
if (process.env.TMPDIR && fs.existsSync(process.env.TMPDIR))
|
|
26
|
+
roots.push(fs.realpathSync(process.env.TMPDIR));
|
|
27
|
+
if (!roots.some(root => isSameOrDescendant(realPath, root))) {
|
|
28
|
+
throw Object.assign(new Error('proxy definition must be in the session project or current TMPDIR'), { code: 'INVALID_LOCAL_PATH' });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const stat = fs.statSync(realPath);
|
|
32
|
+
if (stat.size > 256 * 1024)
|
|
33
|
+
throw Object.assign(new Error('proxy definition exceeds 256 KiB'), { code: 'INVALID_LOCAL_FILE' });
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(fs.readFileSync(realPath, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw Object.assign(new Error('proxy definition is not valid JSON'), { code: 'INVALID_ARGUMENT' });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function registerProxyIpcExecutor(ipcServer, dependencies) {
|
|
42
|
+
ipcServer.setProxyExecutor(async (cmd, auth) => {
|
|
43
|
+
const argv = cmd.argv;
|
|
44
|
+
const operation = proxyOperationForArgv(argv);
|
|
45
|
+
let session;
|
|
46
|
+
if (!auth.localControl) {
|
|
47
|
+
if (typeof cmd.sessionId !== 'string' || typeof cmd.delegationToken !== 'string') {
|
|
48
|
+
return { ok: false, code: 'DELEGATION_REQUIRED', error: 'proxy operation requires a delegated session' };
|
|
49
|
+
}
|
|
50
|
+
const authorization = await dependencies.authorizeManagedOperation({
|
|
51
|
+
sessionId: cmd.sessionId,
|
|
52
|
+
delegationToken: cmd.delegationToken,
|
|
53
|
+
delegationCommandHash: typeof cmd.delegationCommandHash === 'string' ? cmd.delegationCommandHash : undefined,
|
|
54
|
+
}, authorizationOperation(operation));
|
|
55
|
+
if (!authorization.ok)
|
|
56
|
+
return authorization;
|
|
57
|
+
session = await dependencies.getSession(cmd.sessionId);
|
|
58
|
+
if (!session)
|
|
59
|
+
return { ok: false, code: 'SESSION_NOT_FOUND', error: 'current session not found' };
|
|
60
|
+
}
|
|
61
|
+
const parsed = parseProxyCommand(argv, {
|
|
62
|
+
allowFile: auth.localControl,
|
|
63
|
+
...(auth.localControl ? { readInput: file => readDefinition(file, undefined) } : {}),
|
|
64
|
+
});
|
|
65
|
+
const result = await dependencies.manager.execute(parsed.request);
|
|
66
|
+
return { ok: true, ...result, format: parsed.format };
|
|
67
|
+
});
|
|
68
|
+
}
|