evolcore 0.0.26 → 0.0.28
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 +36 -0
- package/bin/codex-managed-acl.ps1 +43 -0
- package/dist/agents/baseagent-availability.js +68 -0
- package/dist/agents/baseagent.js +10 -5
- package/dist/agents/claude-runner.js +123 -22
- package/dist/agents/codex/app-server-client.js +70 -26
- package/dist/agents/codex/catalog.js +7 -1
- package/dist/agents/codex-runner.js +363 -421
- package/dist/agents/ecagent-runner.js +170 -25
- package/dist/agents/gemini-runner.js +6 -0
- package/dist/agents/runner-types.js +50 -2
- package/dist/aun/aid/agentmd.js +73 -31
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +180 -1
- package/dist/aun/aid/identity.js +3 -3
- package/dist/aun/group/history.js +303 -0
- package/dist/aun/group/identity.js +43 -0
- package/dist/aun/group/index.js +5 -0
- package/dist/aun/{msg/group.js → group/operations.js} +161 -38
- package/dist/aun/{menu-client.js → menu/client.js} +13 -7
- package/dist/aun/menu/index.js +2 -0
- package/dist/aun/menu/transport.js +49 -0
- package/dist/aun/msg/index.js +2 -1
- package/dist/aun/msg/managed-operation.js +84 -18
- package/dist/aun/msg/mention-schema.js +51 -0
- package/dist/aun/msg/p2p.js +13 -8
- package/dist/aun/msg/upload.js +43 -88
- package/dist/aun/outbox.js +29 -7
- package/dist/aun/rpc/client.js +1 -0
- package/dist/aun/storage/client.js +39 -50
- package/dist/channels/aun.js +544 -239
- package/dist/channels/daemon.js +10 -6
- package/dist/cli/agent-command.js +108 -6
- package/dist/cli/agent-create.js +515 -2
- package/dist/cli/agent.js +109 -8
- package/dist/cli/aun-commands.js +191 -42
- package/dist/cli/config.js +8 -5
- package/dist/cli/contact.js +2 -2
- package/dist/cli/ctl-command.js +2 -2
- package/dist/cli/daemon-commands.js +111 -162
- package/dist/cli/diag.js +3 -3
- package/dist/cli/fs-command.js +3 -3
- package/dist/cli/handoff-command.js +6 -6
- package/dist/cli/index.js +8 -2
- package/dist/cli/init.js +34 -1
- package/dist/cli/managed-command-guard.js +2 -1
- package/dist/cli/menu-client.js +13 -5
- package/dist/cli/model.js +3 -3
- package/dist/cli/queue-command.js +2 -2
- package/dist/cli/response.js +2 -2
- package/dist/cli/restart-monitor.js +81 -19
- package/dist/cli/task-command.js +59 -0
- package/dist/cli/task-context.js +97 -49
- package/dist/cli/trigger-command.js +20 -10
- package/dist/config/builtin-roles.js +10 -0
- package/dist/config/config-field-policy.js +11 -0
- package/dist/config/config-manager.js +32 -4
- package/dist/config/config-operation-service.js +20 -5
- package/dist/config/contact-book-store.js +1 -1
- package/dist/config/contact-book.js +1 -1
- package/dist/config/contact-operation-service.js +1 -1
- package/dist/config/peer-role-resolver.js +1 -1
- package/dist/config/resolved-config-op.js +3 -0
- package/dist/config-store.js +1 -1
- package/dist/core/agent-application-service.js +5 -0
- package/dist/core/audit/event-key.js +17 -2
- package/dist/core/audit/log-integrity.js +34 -8
- package/dist/core/auth/agent-delegation.js +48 -14
- package/dist/core/auth/auth-gateway.js +2 -0
- package/dist/core/auth/authorization-audit.js +34 -38
- package/dist/core/auth/operation-authorizer.js +67 -5
- package/dist/core/auth/operation-catalog.js +110 -0
- package/dist/core/auth/remote-access-store.js +115 -9
- package/dist/core/bootstrap-messages.js +66 -7
- package/dist/core/bootstrap-service.js +110 -19
- package/dist/core/command/agent-control.js +88 -7
- package/dist/core/command/agent-storage-menu.js +443 -0
- package/dist/core/command/cli-intent-parser.js +19 -0
- package/dist/core/command/command-handler.js +105 -40
- package/dist/core/command/data-root-resolver.js +273 -0
- package/dist/core/command/diag-service.js +292 -27
- package/dist/core/command/group-menu.js +7 -2
- package/dist/core/command/menu-catalog.js +34 -4
- package/dist/core/command/menu-handler.js +364 -96
- package/dist/core/command/menu-protocol.js +43 -6
- package/dist/core/command/role-menu.js +2 -2
- package/dist/core/command/slash-handler.js +61 -37
- package/dist/core/event-catalog.js +4 -0
- package/dist/core/evolagent-registry.js +28 -2
- package/dist/core/group/invite-service.js +924 -0
- package/dist/core/interaction-router.js +22 -8
- package/dist/core/message/im-renderer.js +94 -16
- package/dist/core/message/message-bridge.js +140 -13
- package/dist/core/message/message-log.js +5 -3
- package/dist/core/message/message-queue.js +73 -41
- package/dist/core/message/response-engine.js +729 -118
- package/dist/core/permission/approval-gateway.js +36 -3
- package/dist/core/permission/ec-command-parser.js +76 -36
- package/dist/core/permission/protected-paths.js +134 -16
- package/dist/core/permission/sandbox-runtime.js +72 -3
- package/dist/core/permission/tool-error-code.js +15 -0
- package/dist/core/permission/tool-policy.js +8 -8
- package/dist/core/relation/peer-identity.js +57 -6
- package/dist/core/relation/shared-data.js +106 -0
- package/dist/core/role/runtime-policy.js +64 -0
- package/dist/core/runtime-lock.js +10 -26
- package/dist/core/session/runner-task-history.js +170 -0
- package/dist/core/session/session-manager.js +38 -6
- package/dist/core/session/session-mapper.js +41 -0
- package/dist/core/session/session-turn-coordinator.js +37 -7
- package/dist/core/session/session-turns.js +48 -7
- package/dist/core/task/task-recovery-service.js +176 -0
- package/dist/core/task/task-resume-operation.js +32 -0
- package/dist/eck/group-rules-sync.js +5 -3
- package/dist/eck/kit-renderer.js +1 -0
- package/dist/index.js +322 -207
- package/dist/ipc.js +141 -15
- package/dist/paths.js +17 -4
- package/dist/product.js +3 -0
- package/dist/trigger/event-source.js +19 -0
- package/dist/trigger/feedback.js +233 -40
- package/dist/trigger/parser.js +55 -5
- package/dist/trigger/patch.js +9 -0
- package/dist/trigger/scheduler.js +30 -4
- package/dist/trigger/validation.js +20 -3
- package/dist/utils/atomic-write.js +98 -0
- package/dist/utils/cross-platform.js +87 -16
- package/dist/utils/ecweb-utils.js +1 -0
- package/dist/utils/error-utils.js +40 -2
- package/dist/utils/logger.js +23 -13
- package/dist/utils/npm-ops.js +119 -4
- package/dist/utils/package-version-info.js +244 -0
- package/dist/utils/tool-summary.js +59 -3
- package/dist/utils/welcome.js +174 -1
- package/dist/utils/windows-shell-trust.js +37 -0
- package/ecagent/dist/harness/agent-harness.js +3 -0
- package/ecagent/dist/harness/session/jsonl-storage.js +21 -2
- package/kits/docs/INDEX.md +0 -6
- package/kits/docs/channels/aun.md +23 -2
- package/kits/docs/channels/feishu.md +1 -1
- package/kits/docs/context-assembly.md +29 -17
- package/kits/docs/evolcore/INDEX.md +8 -3
- package/kits/docs/evolcore/agent-create.md +39 -7
- package/kits/docs/evolcore/agent.md +33 -1
- package/kits/docs/evolcore/aid.md +9 -1
- package/kits/docs/evolcore/config.md +40 -1
- package/kits/docs/evolcore/group-collaboration.md +1 -1
- package/kits/docs/evolcore/group.md +117 -2
- package/kits/docs/evolcore/menu-client.md +16 -0
- package/kits/docs/evolcore/msg.md +3 -0
- package/kits/docs/evolcore/storage.md +3 -0
- package/kits/docs/evolcore/task.md +14 -0
- package/kits/docs/evolcore/trigger.md +51 -3
- package/kits/docs/venues/group.md +5 -0
- package/kits/eck_manifest.json +27 -0
- package/kits/rules/01-overview.md +11 -7
- package/kits/rules/04-relation.md +2 -1
- package/kits/rules/05-venue.md +1 -1
- package/kits/rules/06-channel.md +6 -4
- package/kits/schemas/agent-config.schema.12.json +25 -1
- package/kits/schemas/daemon.schema.6.json +2 -2
- package/kits/schemas/defaults.schema.5.json +1 -1
- package/kits/schemas/relation-config.schema.1.json +1 -1
- package/kits/schemas/relation-config.schema.5.json +1 -1
- package/kits/schemas/role-config.schema.1.json +14 -0
- package/kits/templates/roles/member.json +5 -0
- package/kits/templates/roles/visitor.json +5 -0
- package/kits/templates/system-fragments/baseagent.md +1 -1
- package/kits/templates/system-fragments/bootstrap.md +26 -9
- package/kits/templates/system-fragments/channel.md +8 -44
- package/kits/templates/system-fragments/commands.md +10 -2
- package/kits/templates/system-fragments/group-unread-history.md +7 -0
- package/kits/templates/system-fragments/reply.md +56 -0
- package/package.json +7 -3
- package/dist/aun/group-identity.js +0 -9
- /package/dist/aun/{group-fs-download.js → group/fs-download.js} +0 -0
- /package/dist/aun/{msg/group-index.js → group/index-rpc.js} +0 -0
|
@@ -2,7 +2,7 @@ import { logger } from '../../utils/logger.js';
|
|
|
2
2
|
import { LogWriter } from '../../utils/log-writer.js';
|
|
3
3
|
import { resolvePaths } from '../../paths.js';
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
|
-
import { buildAuthorizationEventKey, buildToolLifecycleEventKey } from '../audit/event-key.js';
|
|
5
|
+
import { buildAuthorizationEventKey, buildToolLifecycleEventKey, normalizeToolCorrelation } from '../audit/event-key.js';
|
|
6
6
|
import { normalizeExecutionPermissionMode } from '../permission/mode.js';
|
|
7
7
|
export function auditCommandAuthorization(event) {
|
|
8
8
|
const shouldAudit = event.source === 'menu.cli' ||
|
|
@@ -14,6 +14,8 @@ export function auditCommandAuthorization(event) {
|
|
|
14
14
|
event.operation === 'permission.runtime' ||
|
|
15
15
|
event.operation.startsWith('fullaccess.') ||
|
|
16
16
|
event.operation.startsWith('role.') ||
|
|
17
|
+
event.operation === 'file.root.storage' ||
|
|
18
|
+
event.operation.startsWith('file.storage.') ||
|
|
17
19
|
event.operation === 'cli.exec.raw';
|
|
18
20
|
if (!shouldAudit)
|
|
19
21
|
return;
|
|
@@ -25,6 +27,8 @@ export function auditFullAccessEvent(input) {
|
|
|
25
27
|
|| input.event === 'fullaccess.trigger.deescalated';
|
|
26
28
|
const executionEvent = input.event === 'fullaccess.execution.started'
|
|
27
29
|
|| input.event === 'fullaccess.execution.ended'
|
|
30
|
+
|| input.event === 'fullaccess.agent-policy.execution.started'
|
|
31
|
+
|| input.event === 'fullaccess.agent-policy.execution.ended'
|
|
28
32
|
|| input.event === 'fullaccess.trigger.execution.started'
|
|
29
33
|
|| input.event === 'fullaccess.trigger.execution.ended';
|
|
30
34
|
// The scheduler triggers a run, but the executing subject is the task-bound
|
|
@@ -39,7 +43,7 @@ export function auditFullAccessEvent(input) {
|
|
|
39
43
|
ts: Date.now(),
|
|
40
44
|
callId: input.attemptId ?? input.runId ?? input.taskId ?? input.messageId,
|
|
41
45
|
correlationId: input.runId ?? input.taskId,
|
|
42
|
-
source: input.source === '
|
|
46
|
+
source: input.source === 'fullaccess-command' ? 'slash' : 'agent-tool',
|
|
43
47
|
operation: input.event,
|
|
44
48
|
// CommandScope has no separate daemon value; process is the closest
|
|
45
49
|
// existing scope for daemon-owner authorization and keeps audit records
|
|
@@ -97,20 +101,11 @@ export function auditFullAccessEvent(input) {
|
|
|
97
101
|
* denials otherwise only reach `logger.warn` and `TriggerExecutionAnomaly`.
|
|
98
102
|
*/
|
|
99
103
|
export function auditToolPreflightDenial(input) {
|
|
100
|
-
const lifecycleId = input.callId ?? input.correlationId ?? input.requestId;
|
|
101
104
|
auditCommandAuthorization({
|
|
102
105
|
ts: Date.now(),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
callId: input.callId,
|
|
107
|
-
correlationId: input.correlationId,
|
|
108
|
-
requestId: input.requestId,
|
|
109
|
-
}),
|
|
110
|
-
eventPhase: 'preflight',
|
|
111
|
-
} : {}),
|
|
112
|
-
callId: input.callId ?? input.requestId,
|
|
113
|
-
correlationId: input.correlationId ?? input.callId ?? input.requestId,
|
|
106
|
+
eventKey: buildToolLifecycleEventKey(input),
|
|
107
|
+
eventPhase: 'preflight',
|
|
108
|
+
...normalizeToolCorrelation(input),
|
|
114
109
|
source: 'agent-tool',
|
|
115
110
|
operation: 'tool.preflight.deny',
|
|
116
111
|
scope: 'filesystem',
|
|
@@ -138,29 +133,20 @@ export function auditToolPreflightDenial(input) {
|
|
|
138
133
|
role: input.role ?? 'unknown',
|
|
139
134
|
selfAid: input.selfAid,
|
|
140
135
|
peerKey: input.peerKey,
|
|
141
|
-
requestId: input.requestId,
|
|
142
136
|
taskId: input.taskId,
|
|
143
137
|
});
|
|
144
138
|
}
|
|
145
139
|
/**
|
|
146
140
|
* Emit one canonical, structured record for every Codex app-server approval
|
|
147
|
-
* decision.
|
|
141
|
+
* decision. Prefer the tool call id over the approval request id; method and
|
|
148
142
|
* decision source make policy, user, and infrastructure denials distinct.
|
|
149
143
|
*/
|
|
150
144
|
export function auditCodexApprovalDecision(input) {
|
|
151
|
-
const lifecycleId = input.callId ?? input.correlationId ?? input.requestId;
|
|
152
145
|
auditCommandAuthorization({
|
|
153
146
|
ts: Date.now(),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
callId: input.callId,
|
|
158
|
-
correlationId: input.correlationId,
|
|
159
|
-
requestId: input.requestId,
|
|
160
|
-
}),
|
|
161
|
-
eventPhase: 'approval',
|
|
162
|
-
} : {}),
|
|
163
|
-
callId: input.callId ?? input.correlationId ?? input.requestId,
|
|
147
|
+
eventKey: buildToolLifecycleEventKey(input),
|
|
148
|
+
eventPhase: 'approval',
|
|
149
|
+
...normalizeToolCorrelation(input),
|
|
164
150
|
source: 'agent-tool',
|
|
165
151
|
operation: 'codex.approval',
|
|
166
152
|
scope: input.toolName === 'PermissionGrant' ? 'agent' : 'filesystem',
|
|
@@ -172,8 +158,6 @@ export function auditCodexApprovalDecision(input) {
|
|
|
172
158
|
errorCode: input.decision === 'deny'
|
|
173
159
|
? input.decisionSource === 'approval' ? 'USER_DENIED' : input.decisionSource === 'policy' ? 'POLICY_DENIED' : infrastructureErrorCode(input.policyCode)
|
|
174
160
|
: undefined,
|
|
175
|
-
requestId: input.requestId,
|
|
176
|
-
correlationId: input.correlationId ?? input.callId ?? input.requestId,
|
|
177
161
|
sessionId: input.sessionId ?? 'unknown',
|
|
178
162
|
agentAid: input.agentAid ?? 'unknown',
|
|
179
163
|
agentName: input.agentName,
|
|
@@ -204,6 +188,8 @@ export function auditPermissionDecision(input) {
|
|
|
204
188
|
auditPermissionLifecycle({
|
|
205
189
|
phase: 'final',
|
|
206
190
|
requestId,
|
|
191
|
+
callId: input.callId,
|
|
192
|
+
correlationId: input.correlationId,
|
|
207
193
|
sessionId: input.sessionId,
|
|
208
194
|
agentAid: input.agentAid,
|
|
209
195
|
agentName: input.agentName,
|
|
@@ -235,9 +221,7 @@ export function auditPermissionLifecycle(input) {
|
|
|
235
221
|
requestId: input.requestId,
|
|
236
222
|
}),
|
|
237
223
|
eventPhase: input.phase,
|
|
238
|
-
|
|
239
|
-
correlationId: input.correlationId ?? input.callId ?? input.requestId,
|
|
240
|
-
requestId: input.requestId,
|
|
224
|
+
...normalizeToolCorrelation(input),
|
|
241
225
|
sessionId,
|
|
242
226
|
agentAid: input.agentAid ?? 'unknown',
|
|
243
227
|
agentName: input.agentName,
|
|
@@ -279,6 +263,8 @@ export function auditPermissionLifecycle(input) {
|
|
|
279
263
|
export function auditToolInfrastructureFailure(input) {
|
|
280
264
|
auditCommandAuthorization({
|
|
281
265
|
ts: Date.now(),
|
|
266
|
+
eventKey: buildToolLifecycleEventKey(input),
|
|
267
|
+
eventPhase: 'final',
|
|
282
268
|
source: 'agent-tool',
|
|
283
269
|
operation: 'tool.execution.blocked',
|
|
284
270
|
scope: 'filesystem',
|
|
@@ -288,9 +274,7 @@ export function auditToolInfrastructureFailure(input) {
|
|
|
288
274
|
errorCode: infrastructureErrorCode(input.policyCode),
|
|
289
275
|
executed: false,
|
|
290
276
|
executionState: 'blocked',
|
|
291
|
-
|
|
292
|
-
correlationId: input.callId,
|
|
293
|
-
requestId: input.callId,
|
|
277
|
+
...normalizeToolCorrelation(input),
|
|
294
278
|
sessionId: input.sessionId ?? 'unknown',
|
|
295
279
|
agentAid: input.agentAid ?? 'unknown',
|
|
296
280
|
agentName: input.agentName,
|
|
@@ -300,8 +284,20 @@ export function auditToolInfrastructureFailure(input) {
|
|
|
300
284
|
reason: input.reason,
|
|
301
285
|
role: input.role ?? 'unknown',
|
|
302
286
|
taskId: input.taskId,
|
|
303
|
-
argsSummary: input.occurrences
|
|
304
|
-
? {
|
|
287
|
+
argsSummary: input.occurrences || input.sandboxFailure
|
|
288
|
+
? {
|
|
289
|
+
...(input.occurrences ? { occurrences: input.occurrences } : {}),
|
|
290
|
+
// Flat primitive fields survive the audit argument redactor and can
|
|
291
|
+
// be aggregated without reparsing (possibly truncated) stderr.
|
|
292
|
+
...(input.sandboxFailure ? {
|
|
293
|
+
sandboxFailureKind: input.sandboxFailure.kind,
|
|
294
|
+
sandboxFailureObservation: input.sandboxFailure.observation,
|
|
295
|
+
sandboxInitializationFailures: input.sandboxFailure.counters.total,
|
|
296
|
+
sandboxApplySeccompFailures: input.sandboxFailure.counters.applySeccomp,
|
|
297
|
+
...Object.fromEntries(Object.entries(input.sandboxFailure.counters.byKind)
|
|
298
|
+
.map(([kind, count]) => [`sandboxFailures_${kind}`, count])),
|
|
299
|
+
} : {}),
|
|
300
|
+
}
|
|
305
301
|
: undefined,
|
|
306
302
|
});
|
|
307
303
|
}
|
|
@@ -335,7 +331,7 @@ function buildAuditRecord(event) {
|
|
|
335
331
|
: 'authorized');
|
|
336
332
|
const ecwebRequestId = event.source === 'ecweb' ? event.ecwebRequestId : undefined;
|
|
337
333
|
const requestId = event.requestId ?? ecwebRequestId;
|
|
338
|
-
const correlationId = event.correlationId ?? requestId;
|
|
334
|
+
const correlationId = event.correlationId ?? event.callId ?? requestId;
|
|
339
335
|
const lifecycleId = event.callId ?? correlationId ?? requestId;
|
|
340
336
|
return {
|
|
341
337
|
ts: event.ts,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { getRoleDefinition } from '../../config/roles.js';
|
|
2
2
|
import { isManagementRole } from '../../config/builtin-roles.js';
|
|
3
|
-
import { relationFieldWriteOperation, resolveRoleFieldPermission, } from '../../config/config-field-policy.js';
|
|
3
|
+
import { isUnsupportedBaseagentConfigField, relationFieldWriteOperation, resolveRoleFieldPermission, } from '../../config/config-field-policy.js';
|
|
4
4
|
import { isResolvedConfigMutation, } from '../../config/resolved-config-op.js';
|
|
5
5
|
import { normalizePeer } from '../model/config-scope.js';
|
|
6
6
|
import { getOperationMeta } from './operation-catalog.js';
|
|
7
7
|
import { formatPeerKey, parsePeerKey } from '../relation/peer-identity.js';
|
|
8
|
+
import { sameGroupAid } from '../../aun/group/index.js';
|
|
8
9
|
const DAEMON_OWNER_PROCESS_OPERATIONS = new Set([
|
|
9
10
|
'agent.list',
|
|
10
11
|
'agent.create',
|
|
12
|
+
'agent.initialize',
|
|
11
13
|
'agent.delete',
|
|
12
14
|
'agent.enable',
|
|
13
15
|
'agent.disable',
|
|
@@ -99,6 +101,12 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
|
|
|
99
101
|
&& (resolvedConfigCommand.operationId !== operation || resolvedConfigCommand.commandScope !== intent.scope)) {
|
|
100
102
|
return denyDecision(ctx, 'NOT_ALLOWED', 'Resolved config operation does not match the command intent', operation, intent.scope, opMeta.dangerous);
|
|
101
103
|
}
|
|
104
|
+
if (resolvedConfigCommand?.kind === 'field'
|
|
105
|
+
&& resolvedConfigCommand.configScope === 'agent'
|
|
106
|
+
&& (resolvedConfigCommand.field === 'fullaccess' || resolvedConfigCommand.field.startsWith('fullaccess.'))
|
|
107
|
+
&& resolvedConfigCommand.subcommand !== 'get') {
|
|
108
|
+
return denyDecision(ctx, 'NOT_ALLOWED', 'Agent fullaccess can only be configured in ECWeb Agent settings', operation, intent.scope, true);
|
|
109
|
+
}
|
|
102
110
|
// A fullaccess task is deliberately a daemon-scoped runtime identity. It
|
|
103
111
|
// still has to name a known operation and pass structural command parsing,
|
|
104
112
|
// but relation/Agent role rules, source lists, and daemon-owner gates are
|
|
@@ -224,11 +232,30 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
|
|
|
224
232
|
matchedRule: role === 'owner' ? 'agent-owner-persona' : 'daemon-owner-persona',
|
|
225
233
|
};
|
|
226
234
|
}
|
|
235
|
+
if (operation === 'agent.welcome') {
|
|
236
|
+
if (!isCurrentAgentTarget(ctx) || ctx.chatType !== 'private'
|
|
237
|
+
|| (role !== 'owner' && !(role === 'admin' && intent.args.action === 'show'))) {
|
|
238
|
+
return denyDecision(ctx, 'NOT_ALLOWED', 'welcome requires the current Agent Owner in private (admin may read)', operation, intent.scope, opMeta.dangerous);
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
allow: true,
|
|
242
|
+
operation,
|
|
243
|
+
scope: intent.scope,
|
|
244
|
+
role,
|
|
245
|
+
dangerous: opMeta.dangerous,
|
|
246
|
+
matchedRule: 'self-agent-welcome',
|
|
247
|
+
};
|
|
248
|
+
}
|
|
227
249
|
if (resolvedConfigCommand) {
|
|
228
250
|
const targetCheck = checkResolvedConfigTarget(ctx, resolvedConfigCommand);
|
|
229
251
|
if (!targetCheck.ok) {
|
|
230
252
|
return denyDecision(ctx, intent.scope === 'relation' ? 'ARGUMENT_MISMATCH' : 'SCOPE_MISMATCH', targetCheck.reason || 'Config target is outside the current task context', operation, intent.scope, opMeta.dangerous);
|
|
231
253
|
}
|
|
254
|
+
if (resolvedConfigCommand.kind === 'field'
|
|
255
|
+
&& resolvedConfigCommand.subcommand === 'get'
|
|
256
|
+
&& isUnsupportedBaseagentConfigField(resolvedConfigCommand.field)) {
|
|
257
|
+
return denyDecision(ctx, 'UNSUPPORTED_FIELD', `Config field ${resolvedConfigCommand.field} is not supported by this version`, operation, intent.scope, opMeta.dangerous);
|
|
258
|
+
}
|
|
232
259
|
const identityMutationCheck = checkManagementIdentityMutation(ctx, resolvedConfigCommand);
|
|
233
260
|
if (!identityMutationCheck.ok) {
|
|
234
261
|
return denyDecision(ctx, 'NOT_ALLOWED', identityMutationCheck.reason || 'Static management identities cannot be changed by this role', operation, intent.scope, opMeta.dangerous);
|
|
@@ -236,7 +263,9 @@ function authorizeCommandInternal(ctx, resolvedConfigCommand) {
|
|
|
236
263
|
if (!isManagementRole(role) && intent.scope !== 'relation') {
|
|
237
264
|
return denyDecision(ctx, 'SCOPE_MISMATCH', `Role ${role} may only access relation-scoped config`, operation, intent.scope, opMeta.dangerous);
|
|
238
265
|
}
|
|
239
|
-
if (role === 'owner'
|
|
266
|
+
if (role === 'owner'
|
|
267
|
+
&& isCurrentAgentTarget(ctx)
|
|
268
|
+
&& !isCrossRelationConfigRead(ctx, resolvedConfigCommand)) {
|
|
240
269
|
return {
|
|
241
270
|
allow: true,
|
|
242
271
|
operation,
|
|
@@ -636,6 +665,19 @@ function checkConfigFieldPolicy(ctx, policy, resolvedConfigOp) {
|
|
|
636
665
|
}
|
|
637
666
|
return { ok: true };
|
|
638
667
|
}
|
|
668
|
+
function isCrossRelationConfigRead(ctx, command) {
|
|
669
|
+
if (!command || command.kind !== 'field' || command.subcommand !== 'get' || command.configScope !== 'relation') {
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
if (!command.peerKey || !ctx.peerKey)
|
|
673
|
+
return true;
|
|
674
|
+
try {
|
|
675
|
+
return normalizeRelationPeer(command.peerKey) !== normalizeRelationPeer(ctx.peerKey);
|
|
676
|
+
}
|
|
677
|
+
catch {
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
639
681
|
function checkResolvedConfigTarget(ctx, command) {
|
|
640
682
|
if (command.kind === 'global' || command.configScope === 'process' || command.configScope === 'defaults') {
|
|
641
683
|
return { ok: true };
|
|
@@ -652,8 +694,12 @@ function checkResolvedConfigTarget(ctx, command) {
|
|
|
652
694
|
return { ok: true };
|
|
653
695
|
}
|
|
654
696
|
if (ctx.allowExplicitRelationTarget
|
|
655
|
-
&& (ctx.role
|
|
656
|
-
&&
|
|
697
|
+
&& isManagementRole(ctx.role)
|
|
698
|
+
&& command.kind === 'field'
|
|
699
|
+
&& (command.operationId.startsWith('role.') || command.subcommand === 'get')) {
|
|
700
|
+
// Management reads may select another relation of this Agent. This only
|
|
701
|
+
// relaxes target matching; admin field grants/constraints are checked later.
|
|
702
|
+
// Ordinary config writes and whole-config commands remain current-relation only.
|
|
657
703
|
if (!ctx.selfAid || !command.self || command.self !== ctx.selfAid) {
|
|
658
704
|
return { ok: false, reason: 'Only the current agent relation can be targeted' };
|
|
659
705
|
}
|
|
@@ -693,7 +739,8 @@ function checkCurrentRelation(ctx, resolvedConfigCommand) {
|
|
|
693
739
|
return { ok: false, reason: 'Current relation context is required' };
|
|
694
740
|
}
|
|
695
741
|
try {
|
|
696
|
-
if (normalizeRelationPeer(requestedPeer) !== normalizeRelationPeer(ctx.peerKey)
|
|
742
|
+
if (normalizeRelationPeer(requestedPeer) !== normalizeRelationPeer(ctx.peerKey)
|
|
743
|
+
&& !sameAunGroupRelation(ctx, requestedPeer, ctx.peerKey)) {
|
|
697
744
|
if (ctx.intent.operation.startsWith('ec.group.')) {
|
|
698
745
|
const currentGroup = peerIdFromArg(ctx.peerKey);
|
|
699
746
|
const targetGroup = stringArg(ctx.intent.args.targetId) ?? peerIdFromArg(requestedPeer);
|
|
@@ -788,6 +835,20 @@ function collectStringValues(value, out) {
|
|
|
788
835
|
out.add(item);
|
|
789
836
|
}
|
|
790
837
|
}
|
|
838
|
+
function sameAunGroupRelation(ctx, requested, current) {
|
|
839
|
+
if (ctx.chatType !== 'group'
|
|
840
|
+
|| (!ctx.intent.operation.startsWith('ec.group.') && !ctx.intent.operation.startsWith('ec.fs.')))
|
|
841
|
+
return false;
|
|
842
|
+
try {
|
|
843
|
+
const target = parsePeerKey(requested);
|
|
844
|
+
const relation = parsePeerKey(current);
|
|
845
|
+
return target.channelType === 'aun' && relation.channelType === 'aun'
|
|
846
|
+
&& sameGroupAid(target.channelId, relation.channelId);
|
|
847
|
+
}
|
|
848
|
+
catch {
|
|
849
|
+
return false;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
791
852
|
function checkOwnPeer(ctx) {
|
|
792
853
|
const argPeer = stringArg(ctx.intent.args.peer);
|
|
793
854
|
const argPeerKey = stringArg(ctx.intent.args.peerKey);
|
|
@@ -812,6 +873,7 @@ function checkOwnPeer(ctx) {
|
|
|
812
873
|
candidateKeys.add(`${legacyChannelType}::${argPeer}`);
|
|
813
874
|
}
|
|
814
875
|
return candidateKeys.has(expectedPeerKey)
|
|
876
|
+
|| [...candidateKeys].some(key => sameAunGroupRelation(ctx, key, expectedPeerKey))
|
|
815
877
|
? { ok: true }
|
|
816
878
|
: { ok: false, reason: 'Only the current group relation can be targeted' };
|
|
817
879
|
}
|
|
@@ -25,6 +25,7 @@ const GROUP_MANAGEMENT_OPERATIONS = [
|
|
|
25
25
|
['ec.group.list', 'read', ['agent'], 'List groups joined by the current Agent'],
|
|
26
26
|
['ec.group.info', 'read', ['relation', 'agent'], 'Read group information'],
|
|
27
27
|
['ec.group.pull', 'read', ['relation', 'agent'], 'Pull group messages'],
|
|
28
|
+
['ec.group.history', 'read', ['relation', 'agent'], 'Read local group conversation history'],
|
|
28
29
|
['ec.group.members', 'read', ['relation', 'agent'], 'List group members'],
|
|
29
30
|
['ec.group.online', 'read', ['relation', 'agent'], 'List online group members'],
|
|
30
31
|
['ec.group.rules.get', 'read', ['relation', 'agent'], 'Read the published group rules file'],
|
|
@@ -47,6 +48,11 @@ const GROUP_MANAGEMENT_OPERATIONS = [
|
|
|
47
48
|
['ec.group.owner', 'write-agent', ['agent'], 'Transfer group ownership'],
|
|
48
49
|
['ec.group.ban', 'write-agent', ['agent'], 'Read or update the group ban list'],
|
|
49
50
|
['ec.group.unban', 'write-agent', ['agent'], 'Remove a group ban'],
|
|
51
|
+
['ec.group.block', 'write-own', ['relation', 'agent'], 'Block group message reception'],
|
|
52
|
+
['ec.group.unblock', 'write-own', ['relation', 'agent'], 'Unblock group message reception'],
|
|
53
|
+
['ec.group.blocklist', 'read', ['agent'], 'Read the group block list'],
|
|
54
|
+
['ec.group.report-status', 'write-own', ['relation', 'agent'], 'Report the current Agent group status'],
|
|
55
|
+
['ec.group.member-statuses', 'read', ['relation', 'agent'], 'Read reported group member statuses'],
|
|
50
56
|
['ec.group.rules.set', 'write-agent', ['agent'], 'Upload and publish group rules content'],
|
|
51
57
|
['ec.group.rules.publish', 'write-agent', ['agent'], 'Publish the current group rules file'],
|
|
52
58
|
['ec.group.rules.update', 'write-agent', ['agent'], 'Update group join rules'],
|
|
@@ -365,6 +371,86 @@ const OPERATIONS = [
|
|
|
365
371
|
description: '获取文件内容(需路径沙箱检查)',
|
|
366
372
|
sources: ['slash', 'menu'],
|
|
367
373
|
},
|
|
374
|
+
{
|
|
375
|
+
id: 'file.root.agent',
|
|
376
|
+
category: 'read',
|
|
377
|
+
dangerous: false,
|
|
378
|
+
defaultScopes: ['agent'],
|
|
379
|
+
description: '获取 Agent 内部数据根目录句柄',
|
|
380
|
+
sources: ['menu'],
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
id: 'file.root.relation',
|
|
384
|
+
category: 'read',
|
|
385
|
+
dangerous: false,
|
|
386
|
+
defaultScopes: ['relation', 'agent'],
|
|
387
|
+
description: '获取当前或 owner 指定关系的共享数据根目录句柄',
|
|
388
|
+
sources: ['menu'],
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
id: 'file.data.list',
|
|
392
|
+
category: 'read',
|
|
393
|
+
dangerous: false,
|
|
394
|
+
defaultScopes: ['relation', 'agent'],
|
|
395
|
+
description: '列出已授权内部数据根目录',
|
|
396
|
+
sources: ['menu'],
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
id: 'file.data.query',
|
|
400
|
+
category: 'read',
|
|
401
|
+
dangerous: false,
|
|
402
|
+
defaultScopes: ['relation', 'agent'],
|
|
403
|
+
description: '查询已授权内部数据根文件元信息',
|
|
404
|
+
sources: ['menu'],
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
id: 'file.data.fetch',
|
|
408
|
+
category: 'read',
|
|
409
|
+
dangerous: false,
|
|
410
|
+
defaultScopes: ['relation', 'agent'],
|
|
411
|
+
description: '下载已授权内部数据根文件',
|
|
412
|
+
sources: ['menu'],
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
id: 'file.root.storage',
|
|
416
|
+
category: 'read',
|
|
417
|
+
dangerous: false,
|
|
418
|
+
defaultScopes: ['agent'],
|
|
419
|
+
description: '获取 Agent 自有云存储根句柄',
|
|
420
|
+
sources: ['menu'],
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
id: 'file.storage.list',
|
|
424
|
+
category: 'read',
|
|
425
|
+
dangerous: false,
|
|
426
|
+
defaultScopes: ['agent'],
|
|
427
|
+
description: '列出 Agent 自有云存储目录',
|
|
428
|
+
sources: ['menu'],
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
id: 'file.storage.query',
|
|
432
|
+
category: 'read',
|
|
433
|
+
dangerous: false,
|
|
434
|
+
defaultScopes: ['agent'],
|
|
435
|
+
description: '查询 Agent 自有云存储元信息',
|
|
436
|
+
sources: ['menu'],
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
id: 'file.storage.fetch',
|
|
440
|
+
category: 'read',
|
|
441
|
+
dangerous: false,
|
|
442
|
+
defaultScopes: ['agent'],
|
|
443
|
+
description: '获取 Agent 自有云存储短时下载链接',
|
|
444
|
+
sources: ['menu'],
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
id: 'file.storage.quota',
|
|
448
|
+
category: 'read',
|
|
449
|
+
dangerous: false,
|
|
450
|
+
defaultScopes: ['agent'],
|
|
451
|
+
description: '查询 Agent 自有云存储配额',
|
|
452
|
+
sources: ['menu'],
|
|
453
|
+
},
|
|
368
454
|
// ── Trigger Operations ──
|
|
369
455
|
{
|
|
370
456
|
id: 'trigger.list',
|
|
@@ -624,6 +710,14 @@ const OPERATIONS = [
|
|
|
624
710
|
description: '读取或更新当前 Agent 的 persona.md',
|
|
625
711
|
sources: ['agent-tool', 'control'],
|
|
626
712
|
},
|
|
713
|
+
{
|
|
714
|
+
id: 'agent.welcome',
|
|
715
|
+
category: 'write-agent',
|
|
716
|
+
dangerous: false,
|
|
717
|
+
defaultScopes: ['agent'],
|
|
718
|
+
description: '读取或更新当前 Agent 的 Bootstrap welcome.md',
|
|
719
|
+
sources: ['agent-tool', 'control'],
|
|
720
|
+
},
|
|
627
721
|
{
|
|
628
722
|
id: 'agent.create',
|
|
629
723
|
category: 'process',
|
|
@@ -632,6 +726,14 @@ const OPERATIONS = [
|
|
|
632
726
|
description: '创建新 agent',
|
|
633
727
|
sources: ['menu', 'menu.cli', 'agent-tool', 'control'],
|
|
634
728
|
},
|
|
729
|
+
{
|
|
730
|
+
id: 'agent.initialize',
|
|
731
|
+
category: 'process',
|
|
732
|
+
dangerous: true,
|
|
733
|
+
defaultScopes: ['control'],
|
|
734
|
+
description: 'Create and initialize an Agent from an explicit final plan',
|
|
735
|
+
sources: ['menu', 'menu.cli', 'agent-tool', 'control'],
|
|
736
|
+
},
|
|
635
737
|
{
|
|
636
738
|
id: 'agent.enable',
|
|
637
739
|
category: 'process',
|
|
@@ -935,6 +1037,14 @@ const OPERATIONS = [
|
|
|
935
1037
|
...HANDOFF_READ_OPERATIONS,
|
|
936
1038
|
...HANDOFF_WRITE_OPERATIONS,
|
|
937
1039
|
...QUEUE_OPERATIONS,
|
|
1040
|
+
{
|
|
1041
|
+
id: 'ec.task.resume',
|
|
1042
|
+
category: 'write-agent',
|
|
1043
|
+
dangerous: false,
|
|
1044
|
+
defaultScopes: ['agent'],
|
|
1045
|
+
description: 'Resume a paused or abnormally interrupted Agent session task',
|
|
1046
|
+
sources: ['agent-tool', 'control'],
|
|
1047
|
+
},
|
|
938
1048
|
{
|
|
939
1049
|
id: 'ec.version',
|
|
940
1050
|
category: 'read',
|
|
@@ -12,13 +12,21 @@ export function remoteAccessTokenStorePath() {
|
|
|
12
12
|
function loadStore() {
|
|
13
13
|
try {
|
|
14
14
|
const value = JSON.parse(fs.readFileSync(remoteAccessTokenStorePath(), 'utf8'));
|
|
15
|
-
if (Array.isArray(value.tokens))
|
|
16
|
-
return
|
|
15
|
+
if (Array.isArray(value.tokens)) {
|
|
16
|
+
return {
|
|
17
|
+
tokens: value.tokens,
|
|
18
|
+
pairingIssuances: Array.isArray(value.pairingIssuances) ? value.pairingIssuances : [],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
catch { }
|
|
19
|
-
return { tokens: [] };
|
|
23
|
+
return { tokens: [], pairingIssuances: [] };
|
|
20
24
|
}
|
|
21
25
|
function saveStore(store) {
|
|
26
|
+
// Issuance history contains no credentials. Keep 30 days; live tokens retain
|
|
27
|
+
// their own provenance even after the corresponding history is pruned.
|
|
28
|
+
const cutoff = Date.now() - 30 * 24 * 60 * 60 * 1000;
|
|
29
|
+
store.pairingIssuances = store.pairingIssuances.filter(record => record.expiresAt >= cutoff);
|
|
22
30
|
const file = remoteAccessTokenStorePath();
|
|
23
31
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
24
32
|
const temporary = `${file}.${process.pid}.tmp`;
|
|
@@ -87,6 +95,12 @@ export class RemoteAccessService {
|
|
|
87
95
|
pairingCode = '';
|
|
88
96
|
pairingExpiresAt = 0;
|
|
89
97
|
pairingAuthorizedBy;
|
|
98
|
+
pairingId = '';
|
|
99
|
+
pairingIssuedAt = 0;
|
|
100
|
+
pairingIssuers = [];
|
|
101
|
+
// Do not recycle consumed codes during their original validity window,
|
|
102
|
+
// including when other sources have issued intervening codes.
|
|
103
|
+
recentPairingCodes = new Map();
|
|
90
104
|
/** Synchronous reservation: concurrent invitations cannot issue two grants. */
|
|
91
105
|
issueDiagnosticToken(controlAid, agentAid, ownerAid, now = Date.now()) {
|
|
92
106
|
const store = loadStore();
|
|
@@ -124,18 +138,62 @@ export class RemoteAccessService {
|
|
|
124
138
|
saveStore(store);
|
|
125
139
|
return record;
|
|
126
140
|
}
|
|
127
|
-
getPairingCode(authorizedBy, now = Date.now()) {
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
getPairingCode(authorizedBy, now = Date.now(), source = 'host-cli') {
|
|
142
|
+
const owner = validOwner(authorizedBy);
|
|
143
|
+
if (!['host-cli', 'pair', 'menu', 'ecweb-local'].includes(source)
|
|
144
|
+
|| ((source === 'pair' || source === 'menu') && !owner)) {
|
|
145
|
+
throw new Error('pairing source requires a valid source and an owner for /pair or Menu');
|
|
146
|
+
}
|
|
147
|
+
const generated = !this.pairingCode || now >= this.pairingExpiresAt;
|
|
148
|
+
if (generated) {
|
|
149
|
+
for (const [code, expiresAt] of this.recentPairingCodes) {
|
|
150
|
+
if (now >= expiresAt)
|
|
151
|
+
this.recentPairingCodes.delete(code);
|
|
152
|
+
}
|
|
153
|
+
// Choose uniformly from unused values without an unbounded retry loop.
|
|
154
|
+
let code = crypto.randomInt(0, 1_000_000 - this.recentPairingCodes.size);
|
|
155
|
+
for (const occupied of [...this.recentPairingCodes.keys()].sort((a, b) => a - b)) {
|
|
156
|
+
if (occupied > code)
|
|
157
|
+
break;
|
|
158
|
+
code++;
|
|
159
|
+
}
|
|
160
|
+
this.pairingCode = String(code).padStart(6, '0');
|
|
161
|
+
this.pairingId = crypto.randomUUID();
|
|
162
|
+
this.pairingIssuedAt = now;
|
|
130
163
|
this.pairingExpiresAt = now + REMOTE_ACCESS_PAIRING_TTL_MS;
|
|
164
|
+
this.recentPairingCodes.set(code, this.pairingExpiresAt);
|
|
131
165
|
this.pairingAuthorizedBy = undefined;
|
|
166
|
+
this.pairingIssuers = [];
|
|
132
167
|
}
|
|
133
|
-
const
|
|
168
|
+
const previousOwner = this.pairingAuthorizedBy;
|
|
134
169
|
if (!this.pairingAuthorizedBy && owner)
|
|
135
170
|
this.pairingAuthorizedBy = owner;
|
|
171
|
+
const issuer = {
|
|
172
|
+
source,
|
|
173
|
+
issuedAt: now,
|
|
174
|
+
...((source === 'pair' || source === 'menu') && owner ? { authorizedBy: owner } : {}),
|
|
175
|
+
};
|
|
176
|
+
const addedIssuer = !this.pairingIssuers.some(candidate => candidate.source === issuer.source
|
|
177
|
+
&& candidate.authorizedBy === issuer.authorizedBy);
|
|
178
|
+
if (addedIssuer) {
|
|
179
|
+
this.pairingIssuers.push(issuer);
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
this.recordPairingIssuance();
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (generated)
|
|
186
|
+
this.clearPairingCode();
|
|
187
|
+
else {
|
|
188
|
+
this.pairingAuthorizedBy = previousOwner;
|
|
189
|
+
if (addedIssuer)
|
|
190
|
+
this.pairingIssuers.pop();
|
|
191
|
+
}
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
136
194
|
return { code: this.pairingCode, expiresAt: this.pairingExpiresAt };
|
|
137
195
|
}
|
|
138
|
-
redeemPairingCode(code, label,
|
|
196
|
+
redeemPairingCode(code, label, now = Date.now()) {
|
|
139
197
|
if (typeof code !== 'string' || !/^\d{6}$/.test(code)) {
|
|
140
198
|
return { ok: false, code: 'INVALID_ARGUMENT', error: 'pairing code must be six digits' };
|
|
141
199
|
}
|
|
@@ -149,17 +207,65 @@ export class RemoteAccessService {
|
|
|
149
207
|
const token = crypto.randomBytes(32).toString('hex');
|
|
150
208
|
const store = loadStore();
|
|
151
209
|
pruneExpired(store, now);
|
|
152
|
-
const owner =
|
|
210
|
+
const owner = this.pairingAuthorizedBy;
|
|
211
|
+
const pairingId = this.pairingId;
|
|
212
|
+
const pairingIssuers = this.pairingIssuers.map(issuer => ({ ...issuer }));
|
|
153
213
|
store.tokens.push({
|
|
154
214
|
token,
|
|
155
215
|
createdAt,
|
|
156
216
|
lastActive: createdAt,
|
|
157
217
|
label: validLabel(label),
|
|
158
218
|
...(owner ? { authorizedBy: owner } : {}),
|
|
219
|
+
pairingId,
|
|
220
|
+
pairingIssuers,
|
|
159
221
|
});
|
|
222
|
+
const issuance = store.pairingIssuances.find(record => record.pairingId === pairingId);
|
|
223
|
+
if (issuance) {
|
|
224
|
+
issuance.redeemedAt = createdAt;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
store.pairingIssuances.push({
|
|
228
|
+
pairingId,
|
|
229
|
+
issuedAt: this.pairingIssuedAt,
|
|
230
|
+
expiresAt: this.pairingExpiresAt,
|
|
231
|
+
issuers: pairingIssuers,
|
|
232
|
+
redeemedAt: createdAt,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
160
235
|
saveStore(store);
|
|
236
|
+
// A pairing code is a one-time capability. Clear it only after the token
|
|
237
|
+
// and provenance record have been atomically saved. No await separates
|
|
238
|
+
// validation, persistence and consumption, so concurrent IPC calls cannot
|
|
239
|
+
// grant the same code twice.
|
|
240
|
+
this.clearPairingCode();
|
|
161
241
|
return { ok: true, token, expiresAt: createdAt + REMOTE_ACCESS_TOKEN_TTL_MS };
|
|
162
242
|
}
|
|
243
|
+
clearPairingCode() {
|
|
244
|
+
this.pairingCode = '';
|
|
245
|
+
this.pairingExpiresAt = 0;
|
|
246
|
+
this.pairingAuthorizedBy = undefined;
|
|
247
|
+
this.pairingId = '';
|
|
248
|
+
this.pairingIssuedAt = 0;
|
|
249
|
+
this.pairingIssuers = [];
|
|
250
|
+
}
|
|
251
|
+
recordPairingIssuance() {
|
|
252
|
+
if (!this.pairingId || !this.pairingCode)
|
|
253
|
+
return;
|
|
254
|
+
const store = loadStore();
|
|
255
|
+
const existing = store.pairingIssuances.find(record => record.pairingId === this.pairingId);
|
|
256
|
+
const record = {
|
|
257
|
+
pairingId: this.pairingId,
|
|
258
|
+
issuedAt: this.pairingIssuedAt,
|
|
259
|
+
expiresAt: this.pairingExpiresAt,
|
|
260
|
+
issuers: this.pairingIssuers.map(issuer => ({ ...issuer })),
|
|
261
|
+
...(existing?.redeemedAt ? { redeemedAt: existing.redeemedAt } : {}),
|
|
262
|
+
};
|
|
263
|
+
if (existing)
|
|
264
|
+
Object.assign(existing, record);
|
|
265
|
+
else
|
|
266
|
+
store.pairingIssuances.push(record);
|
|
267
|
+
saveStore(store);
|
|
268
|
+
}
|
|
163
269
|
issueLocalToken(label, now = Date.now()) {
|
|
164
270
|
const token = crypto.randomBytes(32).toString('hex');
|
|
165
271
|
const store = loadStore();
|