evolcore 0.0.41-test.0 → 0.0.41-test.2
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 +62 -0
- package/dist/agents/baseagent-availability.js +1 -1
- package/dist/agents/baseagent.js +88 -49
- package/dist/agents/claude-runner.js +177 -92
- package/dist/agents/codex-runner.js +146 -71
- package/dist/agents/ecagent-runner.js +1 -1
- package/dist/agents/gemini-runner.js +1 -1
- package/dist/aun/aid/agentmd.js +98 -11
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/aid/control-aid.js +26 -2
- package/dist/aun/aid/identity.js +91 -0
- package/dist/aun/aid/index.js +1 -1
- package/dist/aun/aid/managed-operation.js +1 -1
- package/dist/aun/aid/ownership-operation.js +23 -22
- 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/menu/client.js +27 -0
- package/dist/aun/msg/managed-operation.js +68 -7
- package/dist/aun/msg/p2p.js +8 -8
- package/dist/aun/service-proxy.js +53 -12
- package/dist/channels/aun.js +633 -32
- package/dist/channels/daemon.js +15 -1
- package/dist/cli/agent-command.js +5 -2
- package/dist/cli/agent-create.js +991 -233
- package/dist/cli/agent.js +49 -10
- package/dist/cli/aid-bind-command.js +48 -19
- package/dist/cli/aun-commands.js +48 -36
- package/dist/cli/daemon-commands.js +679 -697
- package/dist/cli/fs-command.js +64 -2
- package/dist/cli/index.js +72 -5
- package/dist/cli/init-channel.js +1 -1
- package/dist/cli/init.js +75 -1
- package/dist/cli/managed-command-guard.js +17 -1
- package/dist/cli/model.js +40 -40
- package/dist/cli/provider-command.js +57 -0
- package/dist/cli/proxy-command.js +92 -0
- package/dist/cli/restart-monitor.js +4 -2
- package/dist/cli/role.js +85 -0
- package/dist/cli/stats.js +10 -3
- package/dist/cli/task-context.js +19 -0
- package/dist/config/access-policy.js +7 -2
- package/dist/config/boot-log.js +39 -1
- package/dist/config/config-field-policy.js +17 -39
- package/dist/config/config-manager.js +183 -44
- 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/owner-config.js +2 -2
- package/dist/config/peer-role-resolver.js +15 -12
- package/dist/config/provider-ipc-service.js +132 -0
- package/dist/config/provider-menu-request.js +58 -0
- package/dist/config/providers-config.js +12 -7
- package/dist/config/providers-import.js +3 -21
- package/dist/config/providers-management.js +78 -5
- package/dist/config/resolved-config-op.js +11 -1
- package/dist/config/role-command-service.js +166 -0
- package/dist/config/role-request-service.js +193 -0
- package/dist/config/schema-migration.js +1000 -25
- package/dist/config-store.js +89 -4
- package/dist/contracts/ecweb-instance.js +41 -0
- package/dist/contracts/ecweb-service-protocol.js +4 -1
- package/dist/core/agent-application-service.js +60 -11
- package/dist/core/agent-create-status.js +203 -0
- package/dist/core/agent-creation-claim.js +177 -0
- package/dist/core/agent-ipc-registration.js +39 -18
- package/dist/core/agent-runtime.js +194 -24
- package/dist/core/auth/agent-delegation.js +6 -3
- package/dist/core/auth/auth-gateway.js +67 -2
- package/dist/core/auth/authorization-audit.js +58 -11
- package/dist/core/auth/delegation-authorization.js +5 -2
- package/dist/core/auth/operation-authorizer.js +43 -6
- package/dist/core/auth/operation-catalog.js +45 -7
- package/dist/core/channel-loader.js +2 -0
- package/dist/core/command/agent-control.js +260 -21
- package/dist/core/command/agent-storage-menu.js +5 -3
- package/dist/core/command/cli-intent-parser.js +8 -3
- package/dist/core/command/command-handler.js +112 -154
- 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 +10 -6
- package/dist/core/command/menu-handler.js +106 -73
- package/dist/core/command/menu-protocol.js +15 -1
- package/dist/core/command/provider-menu.js +46 -0
- package/dist/core/command/role-menu.js +147 -30
- package/dist/core/command/slash-handler.js +125 -255
- package/dist/core/daemon-control.js +26 -27
- package/dist/core/event-catalog.js +10 -0
- package/dist/core/evolagent-registry.js +7 -5
- package/dist/core/evolagent.js +10 -8
- package/dist/core/file-integrity/store.js +11 -0
- package/dist/core/handoff/ipc-registration.js +3 -0
- package/dist/core/inference/text-inference.js +31 -40
- package/dist/core/initialization/service.js +491 -0
- package/dist/core/ipc-registration.js +40 -24
- package/dist/core/memory/consolidation-context.js +51 -5
- package/dist/core/memory/consolidation-ops-records.js +96 -1
- package/dist/core/memory/consolidation-trigger.js +208 -191
- package/dist/core/memory/consolidation.js +333 -35
- 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 +55 -45
- package/dist/core/message/aun-ipc-sender.js +81 -69
- package/dist/core/message/im-renderer.js +25 -4
- package/dist/core/message/message-admission.js +89 -4
- package/dist/core/message/message-bridge.js +66 -21
- package/dist/core/message/response-engine.js +108 -35
- package/dist/core/model/catalog-service.js +5 -3
- package/dist/core/model/config-scope.js +29 -71
- 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 +772 -158
- package/dist/core/permission/approval-gateway.js +103 -403
- package/dist/core/permission/ec-command-parser.js +62 -6
- package/dist/core/permission/index.js +1 -0
- package/dist/core/permission/permission-result.js +78 -0
- package/dist/core/permission/sandbox-runtime.js +18 -1
- package/dist/core/permission/tool-policy.js +21 -46
- 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 +43 -8
- 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/init-menu.js +32 -0
- package/dist/ecweb/message-context-service.js +110 -0
- package/dist/index.js +93 -19
- package/dist/ipc.js +247 -29
- package/dist/paths.js +7 -0
- package/dist/proxy/command.js +122 -0
- package/dist/proxy/ipc-service.js +68 -0
- package/dist/proxy/manager.js +484 -0
- package/dist/proxy/service-supervisor.js +603 -0
- package/dist/response-system/engines/v1/proactive-flow.js +16 -6
- package/dist/trigger/authorization.js +27 -17
- package/dist/trigger/feedback.js +2 -3
- package/dist/trigger/ipc-service.js +105 -78
- package/dist/trigger/local-files.js +2 -1
- package/dist/trigger/manager.js +5 -3
- package/dist/trigger/scheduler.js +88 -6
- package/dist/utils/atomic-write.js +28 -0
- package/dist/utils/cross-platform.js +14 -0
- package/dist/utils/ecweb-supervisor.js +258 -83
- package/dist/utils/error-utils.js +26 -2
- package/dist/utils/logger.js +92 -6
- package/dist/utils/package-version-info.js +4 -2
- package/dist/utils/welcome.js +1 -1
- package/kits/docs/INDEX.md +1 -0
- package/kits/docs/aun/SDK.md +4 -1
- package/kits/docs/channels/aun.md +9 -0
- package/kits/docs/evolcore/INDEX.md +1 -0
- package/kits/docs/evolcore/agent.md +8 -1
- package/kits/docs/evolcore/aid.md +67 -17
- package/kits/docs/evolcore/config.md +28 -7
- package/kits/docs/evolcore/contact.md +3 -0
- package/kits/docs/evolcore/fs.md +11 -0
- package/kits/docs/evolcore/group.md +1 -1
- 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/docs/evolcore/provider.md +50 -0
- package/kits/docs/identity/AID_PROFILE_SPEC.md +52 -17
- package/kits/migrations/migrate-contact-book-v2.mjs +30 -11
- package/kits/rules/01-overview.md +3 -0
- package/kits/rules/04-relation.md +1 -1
- 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 +277 -0
- package/kits/schemas/role-config.schema.1.json +7 -7
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/ec-agent-create/SKILL.md +3 -0
- package/kits/skills/ec-identity/SKILL.md +2 -2
- package/kits/skills/ec-service-proxy/SKILL.md +118 -0
- package/kits/skills/ec-skill/scripts/skill.mjs +6 -0
- 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/skills/thread-ops/SKILL.md +5 -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/kits/templates/system-fragments/venue.md +1 -1
- package/package.json +7 -3
- package/dist/core/message/create-status.js +0 -96
|
@@ -11,7 +11,7 @@ import { isValidAid } from './validation.js';
|
|
|
11
11
|
import { agentMdPath, resolvePaths } from '../../paths.js';
|
|
12
12
|
import { PeerIdentityCache } from '../../core/relation/peer-identity.js';
|
|
13
13
|
import { agentmdPut, buildInitialAgentMd, invalidateAgentDisplayName, stripAgentMdSignature } from './agentmd.js';
|
|
14
|
-
import { logger } from '../../utils/logger.js';
|
|
14
|
+
import { logger, logOwnershipEvent } from '../../utils/logger.js';
|
|
15
15
|
const MAX_ATTEMPTS = 5;
|
|
16
16
|
export { DEFAULT_AID_DOMAIN } from './domain.js';
|
|
17
17
|
/** Human-facing platform label used in the control AID's agent.md name. */
|
|
@@ -135,7 +135,30 @@ export async function ensureControlAgentMd(aid, opts = {}) {
|
|
|
135
135
|
catch { /* missing */ }
|
|
136
136
|
const metadata = readJsonFile(metadataPath);
|
|
137
137
|
const remoteMissing = String(metadata?.remote_status ?? '').trim().toLowerCase() === 'missing';
|
|
138
|
-
const
|
|
138
|
+
const canonical = !!existing && hasCanonicalControlFrontmatter(existing, normalizedAid, name, aunRoot);
|
|
139
|
+
const needsPublish = !canonical || remoteMissing;
|
|
140
|
+
let hadOwnershipFields;
|
|
141
|
+
if (existing) {
|
|
142
|
+
try {
|
|
143
|
+
const frontmatter = stripAgentMdSignature(existing).match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
|
|
144
|
+
if (frontmatter) {
|
|
145
|
+
const document = parseDocument(frontmatter);
|
|
146
|
+
if (document.errors.length === 0) {
|
|
147
|
+
const fields = document.toJS();
|
|
148
|
+
if (fields && typeof fields === 'object' && !Array.isArray(fields)) {
|
|
149
|
+
hadOwnershipFields = Object.hasOwn(fields, 'owner') || Object.hasOwn(fields, 'ownership');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
}
|
|
156
|
+
const diagnostic = {
|
|
157
|
+
subjectAid: normalizedAid, processId: process.pid, publicationRequired: needsPublish,
|
|
158
|
+
publicationReason: !existing ? 'missing' : !canonical ? 'noncanonical' : remoteMissing ? 'remote_missing' : 'current',
|
|
159
|
+
hadOwnershipFields,
|
|
160
|
+
};
|
|
161
|
+
logOwnershipEvent('control.card.checked', diagnostic);
|
|
139
162
|
if (!needsPublish)
|
|
140
163
|
return { aid: normalizedAid, name, published: false };
|
|
141
164
|
const content = buildInitialAgentMd({
|
|
@@ -147,6 +170,7 @@ export async function ensureControlAgentMd(aid, opts = {}) {
|
|
|
147
170
|
});
|
|
148
171
|
try {
|
|
149
172
|
await agentmdPut(content, { aid: normalizedAid, store: opts.store, aunPath: aunRoot });
|
|
173
|
+
logOwnershipEvent('control.card.published', diagnostic);
|
|
150
174
|
}
|
|
151
175
|
catch (error) {
|
|
152
176
|
// agentmdPut intentionally keeps edits to an existing card on failure;
|
package/dist/aun/aid/identity.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import { getAidStore, loadAid, loadClient, AidLoadError, SLOT } from './store.js';
|
|
5
5
|
import { downloadCaRoot } from './client.js';
|
|
6
|
+
import { AUN_KEYSTORE_ENCRYPTION_SEED } from './encryption-seed-policy.js';
|
|
6
7
|
import { resolvePaths, agentMdPath, aunPath as defaultAunPath } from '../../paths.js';
|
|
7
8
|
// ==================== Validation ====================
|
|
8
9
|
export function isValidAid(name) {
|
|
@@ -263,6 +264,96 @@ export async function aidCreate(aid, opts) {
|
|
|
263
264
|
throw e;
|
|
264
265
|
}
|
|
265
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Bootstrap an agent's PKI identity without publishing agent.md or binding an
|
|
269
|
+
* Owner. One-shot initialization performs those operations separately and must
|
|
270
|
+
* retain the operation ID returned by its explicit Owner bind.
|
|
271
|
+
*
|
|
272
|
+
* RegisterFlow keeps the SDK's existing-key and pending-registration recovery;
|
|
273
|
+
* unlike the legacy force path, this entry point never deletes a local key.
|
|
274
|
+
* The caller owns the returned client and store and must close them in order.
|
|
275
|
+
*/
|
|
276
|
+
export async function aidCreateIdentityOnly(aid, opts) {
|
|
277
|
+
const target = aid.trim();
|
|
278
|
+
const aunPath = opts?.aunPath ?? defaultAunPath();
|
|
279
|
+
const { RegisterFlow, LocalIdentityStore, CryptoProvider, GatewayDiscovery } = await import('@agentunion/fastaun');
|
|
280
|
+
RegisterFlow.validateAidName(target);
|
|
281
|
+
const alreadyExisted = fs.existsSync(path.join(aunPath, 'AIDs', target, 'private'));
|
|
282
|
+
const authenticate = async (gateway = '') => {
|
|
283
|
+
// Recreate through the common factory after registration/CA download so
|
|
284
|
+
// slot, encryption seed, SSL verification and the current CA all agree.
|
|
285
|
+
const store = await getAidStore({ slotId: SLOT.cli, aunPath });
|
|
286
|
+
let client;
|
|
287
|
+
try {
|
|
288
|
+
client = await loadClient(store, target);
|
|
289
|
+
const auth = await client.authenticate();
|
|
290
|
+
return { aid: target, alreadyExisted, gateway: String(auth?.gateway ?? gateway), client, store };
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
// Closing must not hide the registration/authentication failure.
|
|
294
|
+
try {
|
|
295
|
+
await client?.close();
|
|
296
|
+
}
|
|
297
|
+
catch { /* preserve original error */ }
|
|
298
|
+
try {
|
|
299
|
+
store.close();
|
|
300
|
+
}
|
|
301
|
+
catch { /* preserve original error */ }
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
if (alreadyExisted && (await verifySignAbility(target, { aunPath })).ok) {
|
|
306
|
+
// A network/auth failure here is not permission to register again.
|
|
307
|
+
return authenticate();
|
|
308
|
+
}
|
|
309
|
+
let gateway = '';
|
|
310
|
+
const keystore = new LocalIdentityStore(aunPath, { encryptionSeed: AUN_KEYSTORE_ENCRYPTION_SEED });
|
|
311
|
+
let registrationCompleted = false;
|
|
312
|
+
try {
|
|
313
|
+
const discovery = new GatewayDiscovery({ verifySsl: true });
|
|
314
|
+
const issuer = target.slice(target.indexOf('.') + 1);
|
|
315
|
+
let discoveryError;
|
|
316
|
+
// Match AIDStore's discovery fallback for an AID that is not registered yet.
|
|
317
|
+
for (const url of [
|
|
318
|
+
`https://${target}/.well-known/aun-gateway`,
|
|
319
|
+
`https://gateway.${issuer}/.well-known/aun-gateway`,
|
|
320
|
+
]) {
|
|
321
|
+
try {
|
|
322
|
+
gateway = await discovery.discover(url);
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
discoveryError = error;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (!gateway)
|
|
330
|
+
throw discoveryError instanceof Error ? discoveryError : new Error(String(discoveryError));
|
|
331
|
+
const flow = new RegisterFlow({ keystore, crypto: new CryptoProvider(), verifySsl: true });
|
|
332
|
+
keystore.saveMetadata(target, { identity_type: 'agent', identity_exttype: '' });
|
|
333
|
+
const registered = await flow.registerAid(gateway, target);
|
|
334
|
+
// Follow AIDStore.register's public persistence contract. In particular,
|
|
335
|
+
// registerAid can return a recovered certificate for an existing keypair.
|
|
336
|
+
if (registered.cert)
|
|
337
|
+
keystore.saveCert(target, registered.cert);
|
|
338
|
+
keystore.saveKeyPair(target, {
|
|
339
|
+
private_key_pem: registered.private_key_pem,
|
|
340
|
+
public_key_der_b64: registered.public_key_der_b64,
|
|
341
|
+
curve: registered.curve,
|
|
342
|
+
});
|
|
343
|
+
registrationCompleted = true;
|
|
344
|
+
}
|
|
345
|
+
finally {
|
|
346
|
+
try {
|
|
347
|
+
keystore.close();
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
if (registrationCompleted)
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
await downloadCaRoot(aunPath, gateway, '', opts?.silent === true);
|
|
355
|
+
return authenticate(gateway);
|
|
356
|
+
}
|
|
266
357
|
// ==================== Show ====================
|
|
267
358
|
export async function aidShow(aid, opts) {
|
|
268
359
|
const aunPath = opts?.aunPath ?? defaultAunPath();
|
package/dist/aun/aid/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AgentMdVersionUnavailableError, AgentMdVersionConflictError } from './agentmd.js';
|
|
2
|
-
export {
|
|
2
|
+
export { AGENT_TAG_MAX_LENGTH, validateAgentTag, validateAgentTags, } from './agentmd.js';
|
|
3
3
|
export { isValidAid, aidList, aidListVerified, aidCreate, aidShow, aidDelete, aidLookup, verifySignAbility, probePkiRecoverability, appendAidLifecycle, readAidLifecycle } from './identity.js';
|
|
4
4
|
export { AGENT_TYPES, DEFAULT_AGENT_DESCRIPTION, DEFAULT_AGENT_TYPE, normalizeAgentType, validateAgentType, buildInitialAgentMd, validateAgentMdFrontmatter, agentmdGet, agentmdPut, agentmdSet, agentmdSync, invalidateAgentDisplayName, parseAgentDisplayName, refreshAgentDisplayName, resolveAgentDisplayName, stripAgentMdSignature, updateAgentMdFrontmatterAvatar, updateAgentMdFrontmatterFieldValue, updateAgentMdFrontmatterName, } from './agentmd.js';
|
|
5
5
|
export { MIN_AUN_CORE_SDK, AUN_CORE_SDK_PKG, isAunSdkVersionOk, resolveAunCoreSdkPkg, ensureAunSdk, isAunSdkReady, downloadCaRoot, suppressSdkLogs, } from './client.js';
|
|
@@ -55,7 +55,7 @@ function parseAvatar(args) {
|
|
|
55
55
|
},
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
const AGENTMD_EDITABLE_FIELDS = new Set(['name', 'type', 'description', 'version', 'tags']);
|
|
58
|
+
const AGENTMD_EDITABLE_FIELDS = new Set(['name', 'type', 'description', 'version', 'tags', 'exttype']);
|
|
59
59
|
function parseAgentmdSet(args) {
|
|
60
60
|
const aidResult = parseAid(args[2]);
|
|
61
61
|
if (!aidResult.ok)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isValidAid } from './validation.js';
|
|
2
2
|
import { ownerResolver, OwnershipError } from '../../core/ownership/owner-resolver.js';
|
|
3
|
-
import { logger } from '../../utils/logger.js';
|
|
4
3
|
import { MAIN_CLI_BIN } from '../../product.js';
|
|
5
4
|
const OWNERSHIP_OPERATION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
6
5
|
export function ownershipFailure(error) {
|
|
@@ -15,21 +14,31 @@ export function ownershipFailure(error) {
|
|
|
15
14
|
}
|
|
16
15
|
export function parseOwnershipCommand(argv) {
|
|
17
16
|
const args = argv[0] === 'aid' ? argv.slice(1) : [...argv];
|
|
18
|
-
if (args[0]
|
|
19
|
-
throw new OwnershipError('INVALID_ARGUMENT', `Use ${MAIN_CLI_BIN} aid bind <ownerAid>, status, accept, or reject`);
|
|
17
|
+
if (!args[0] || !args[1] || !['bind', 'transfer'].includes(args[0])) {
|
|
18
|
+
throw new OwnershipError('INVALID_ARGUMENT', `Use ${MAIN_CLI_BIN} aid bind <ownerAid>, transfer <subAid> <newOwnerAid>, status, accept, or reject`);
|
|
20
19
|
}
|
|
21
|
-
const action = [
|
|
20
|
+
const action = args[0] === 'transfer' ? 'transfer'
|
|
21
|
+
: ['status', 'accept', 'reject'].includes(args[1]) ? args[1] : 'bind';
|
|
22
22
|
if (action === 'bind' && !isValidAid(args[1]))
|
|
23
23
|
throw new OwnershipError('INVALID_AID', 'A valid owner AID is required');
|
|
24
|
+
if (action === 'transfer' && (!isValidAid(args[1]) || !isValidAid(args[2] ?? ''))) {
|
|
25
|
+
throw new OwnershipError('INVALID_AID', 'Valid sub and new owner AIDs are required');
|
|
26
|
+
}
|
|
24
27
|
if ((action === 'accept' || action === 'reject') && !OWNERSHIP_OPERATION_ID.test(args[2] ?? '')) {
|
|
25
28
|
throw new OwnershipError('INVALID_OPERATION', 'A valid ownership operation ID is required');
|
|
26
29
|
}
|
|
27
30
|
let subjectAid;
|
|
28
31
|
let reason;
|
|
32
|
+
let refresh = false;
|
|
29
33
|
let formatSeen = false;
|
|
30
34
|
const positionalEnd = action === 'bind' || action === 'status' ? 2 : 3;
|
|
31
|
-
for (let index = positionalEnd; index < args.length;
|
|
35
|
+
for (let index = positionalEnd; index < args.length;) {
|
|
32
36
|
const flag = args[index];
|
|
37
|
+
if (flag === '--refresh' && action === 'status' && !refresh) {
|
|
38
|
+
refresh = true;
|
|
39
|
+
index += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
33
42
|
const value = args[index + 1];
|
|
34
43
|
if (flag === '--subject' && !subjectAid && isValidAid(value ?? '')) {
|
|
35
44
|
subjectAid = value;
|
|
@@ -42,11 +51,14 @@ export function parseOwnershipCommand(argv) {
|
|
|
42
51
|
reason = value;
|
|
43
52
|
}
|
|
44
53
|
else {
|
|
45
|
-
throw new OwnershipError('INVALID_ARGUMENT', 'Supported options are --subject <subjectAid>, --reason <text>, and --format json');
|
|
54
|
+
throw new OwnershipError('INVALID_ARGUMENT', 'Supported options are --subject <subjectAid>, --reason <text>, --refresh (status only), and --format json');
|
|
46
55
|
}
|
|
56
|
+
index += 2;
|
|
47
57
|
}
|
|
48
58
|
if (action === 'status')
|
|
49
|
-
return { action, subjectAid };
|
|
59
|
+
return { action, subjectAid, ...(refresh ? { refresh } : {}) };
|
|
60
|
+
if (action === 'transfer')
|
|
61
|
+
return { action, subAid: args[1], newOwnerAid: args[2], subjectAid };
|
|
50
62
|
if (action === 'accept')
|
|
51
63
|
return { action, operationId: args[2], subjectAid };
|
|
52
64
|
if (action === 'reject')
|
|
@@ -58,24 +70,13 @@ export async function executeOwnershipCommand(command, defaultSubjectAid) {
|
|
|
58
70
|
if (!subjectAid)
|
|
59
71
|
throw new OwnershipError('SUBJECT_REQUIRED', 'No local subject AID is available');
|
|
60
72
|
if (command.action === 'status') {
|
|
61
|
-
return ownerResolver.status(subjectAid);
|
|
73
|
+
return ownerResolver.status(subjectAid, { force: command.refresh === true });
|
|
62
74
|
}
|
|
63
75
|
if (command.action === 'accept' || command.action === 'reject') {
|
|
64
76
|
return ownerResolver.decide(subjectAid, command.operationId, command.action, command.action === 'reject' ? command.reason : undefined);
|
|
65
77
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const result = await ownerResolver.bind(subjectAid, command.ownerAid);
|
|
69
|
-
const task = result.task;
|
|
70
|
-
const log = task && ['rejected', 'stopped', 'error'].includes(task.status) ? logger.warn : logger.info;
|
|
71
|
-
log(`[ownership] bind result ${JSON.stringify({ subjectAid, ownerAid: command.ownerAid, operationId: task?.operation_id,
|
|
72
|
-
taskStatus: task?.status, step: task?.step, consensusStatus: result.consensusStatus, requestStatus: result.requestStatus,
|
|
73
|
-
code: task?.code, reason: task?.reason })}`);
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
const details = ownershipFailure(error);
|
|
78
|
-
logger.warn(`[ownership] bind failed subject=${subjectAid} owner=${command.ownerAid} code=${details.code} error=${JSON.stringify(details.error)}`);
|
|
79
|
-
throw error;
|
|
78
|
+
if (command.action === 'transfer') {
|
|
79
|
+
return ownerResolver.transfer(subjectAid, command.subAid, command.newOwnerAid);
|
|
80
80
|
}
|
|
81
|
+
return ownerResolver.bind(subjectAid, command.ownerAid);
|
|
81
82
|
}
|
|
@@ -56,6 +56,45 @@ export async function readPersonalFsBytesWithinBudget(client, path, maxBytes, op
|
|
|
56
56
|
throw new FsReadBudgetError(maxBytes);
|
|
57
57
|
return bytes;
|
|
58
58
|
}
|
|
59
|
+
export class AuthoritativeFsReadError extends Error {
|
|
60
|
+
code;
|
|
61
|
+
constructor(code, message) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.code = code;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Full authenticated RPC read for private ACLs; never requests an HTTP ticket. */
|
|
67
|
+
export async function readAuthoritativePersonalFsObject(client, path, owner, maxBytes) {
|
|
68
|
+
validateFsReadBudget(maxBytes);
|
|
69
|
+
if (!path.startsWith('/') || path.endsWith('/') || path.includes('\\') ||
|
|
70
|
+
/[\u0000-\u001f\u007f]/.test(path) || path.slice(1).split('/').some(p => !p || p === '.' || p === '..')) {
|
|
71
|
+
throw new AuthoritativeFsReadError('INVALID_PATH', 'authoritative cat requires a canonical absolute object path');
|
|
72
|
+
}
|
|
73
|
+
const key = path.slice(1);
|
|
74
|
+
const value = await client.call('storage.get_object', {
|
|
75
|
+
owner_aid: owner, bucket: 'default', object_key: key, consistency: 'authoritative',
|
|
76
|
+
});
|
|
77
|
+
if (!isRecord(value) || value.owner_aid !== owner || value.bucket !== 'default' ||
|
|
78
|
+
(value.object_key ?? (typeof value.path === 'string' ? value.path.replace(/^\//, '') : undefined)) !== key) {
|
|
79
|
+
throw new AuthoritativeFsReadError('FS_INVALID_OBJECT', 'authoritative response identity/path mismatch');
|
|
80
|
+
}
|
|
81
|
+
if (value.exists === false)
|
|
82
|
+
throw new AuthoritativeFsReadError('FS_NOT_FOUND', 'authoritative object is absent or inaccessible');
|
|
83
|
+
if (value.exists !== true || !Number.isSafeInteger(value.version) || value.version < 1 ||
|
|
84
|
+
!Number.isSafeInteger(value.size_bytes) || value.size_bytes < 0 || typeof value.content !== 'string' ||
|
|
85
|
+
typeof value.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(value.sha256)) {
|
|
86
|
+
throw new AuthoritativeFsReadError('FS_INVALID_OBJECT', 'authoritative response metadata is incomplete');
|
|
87
|
+
}
|
|
88
|
+
if (value.size_bytes > maxBytes || value.content.length > 4 * Math.ceil(maxBytes / 3)) {
|
|
89
|
+
throw new FsReadBudgetError(maxBytes);
|
|
90
|
+
}
|
|
91
|
+
const bytes = Buffer.from(value.content, 'base64');
|
|
92
|
+
if (bytes.toString('base64') !== value.content || bytes.length !== value.size_bytes || sha256Hex(bytes) !== value.sha256) {
|
|
93
|
+
throw new AuthoritativeFsReadError('FS_INVALID_OBJECT', 'authoritative content encoding, size or hash mismatch');
|
|
94
|
+
}
|
|
95
|
+
const { content: _content, ...metadata } = value;
|
|
96
|
+
return { bytes, metadata };
|
|
97
|
+
}
|
|
59
98
|
export class GroupFsDownloadError extends Error {
|
|
60
99
|
code;
|
|
61
100
|
constructor(code, message) {
|
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
/** Resolve a peer kind from authoritative evidence; AID spelling is never evidence. */
|
|
4
|
+
export function resolveAunTargetKind(evidence) {
|
|
5
|
+
const candidates = [];
|
|
6
|
+
const sources = [];
|
|
7
|
+
for (const [source, kind] of [['route', evidence.routeKind], ['relation', evidence.targetKind]]) {
|
|
8
|
+
if (kind === undefined)
|
|
9
|
+
continue;
|
|
10
|
+
if (kind !== 'private' && kind !== 'group')
|
|
11
|
+
return { kind: 'unknown', reason: 'invalid', sources };
|
|
12
|
+
candidates.push(kind);
|
|
13
|
+
sources.push(source);
|
|
14
|
+
}
|
|
15
|
+
if (evidence.verifiedType !== undefined) {
|
|
16
|
+
if (typeof evidence.verifiedType !== 'string' || !evidence.verifiedType.trim()) {
|
|
17
|
+
return { kind: 'unknown', reason: 'invalid', sources };
|
|
18
|
+
}
|
|
19
|
+
if (evidence.verifiedType.trim().toLowerCase() === 'unknown') {
|
|
20
|
+
return { kind: 'unknown', reason: 'invalid', sources };
|
|
21
|
+
}
|
|
22
|
+
candidates.push(evidence.verifiedType.trim().toLowerCase() === 'group' ? 'group' : 'private');
|
|
23
|
+
sources.push('agentmd');
|
|
24
|
+
}
|
|
25
|
+
if (!candidates.length)
|
|
26
|
+
return { kind: 'unknown', reason: 'missing', sources };
|
|
27
|
+
if (candidates.some(kind => kind !== candidates[0]))
|
|
28
|
+
return { kind: 'unknown', reason: 'conflict', sources };
|
|
29
|
+
return { kind: candidates[0], reason: 'resolved', sources };
|
|
30
|
+
}
|
|
31
|
+
/** Accept cached type evidence only after signature verification for this exact AID. */
|
|
32
|
+
export function verifiedPeerType(targetAid, identity) {
|
|
33
|
+
if (identity?.aid !== targetAid || identity.source !== 'agentmd'
|
|
34
|
+
|| !Number.isFinite(identity.verifiedAt) || !(identity.verifiedAt > 0) || identity.lastCheckedAt === 0) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return typeof identity.type === 'string' && identity.type.trim() ? identity.type.trim() : undefined;
|
|
38
|
+
}
|
|
3
39
|
const requireSdk = createRequire(import.meta.url);
|
|
4
40
|
let groupValidator;
|
|
5
41
|
/** Validate a group command argument, expanding a local base to a full AID. */
|
|
@@ -28,24 +64,3 @@ export function sameGroupAid(left, right) {
|
|
|
28
64
|
return false;
|
|
29
65
|
}
|
|
30
66
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Legacy group identity hint, NOT a format validator. Canonical group AIDs and
|
|
33
|
-
* private AIDs share a syntax; prefer trusted chat/targetKind information.
|
|
34
|
-
* Do not broaden this predicate to every SDK-valid group argument.
|
|
35
|
-
*/
|
|
36
|
-
export function isExplicitGroupId(value) {
|
|
37
|
-
const id = value.trim();
|
|
38
|
-
if (!id)
|
|
39
|
-
return false;
|
|
40
|
-
return /^\d+\.[a-z0-9.-]+$/i.test(id)
|
|
41
|
-
|| /^grp_[a-z0-9_-]+$/i.test(id)
|
|
42
|
-
|| /^g-[a-z0-9_-]+(?:[.@][a-z0-9.-]+)?$/i.test(id);
|
|
43
|
-
}
|
|
44
|
-
/** Legacy named-group hint for generic relation data without authoritative type metadata. */
|
|
45
|
-
export function isLegacyNamedGroupIdHint(value) {
|
|
46
|
-
const id = value.trim();
|
|
47
|
-
if (!id)
|
|
48
|
-
return false;
|
|
49
|
-
return /^grp_[a-z0-9_-]+$/i.test(id)
|
|
50
|
-
|| /^g-[a-z0-9_-]+(?:[.@][a-z0-9.-]+)?$/i.test(id);
|
|
51
|
-
}
|
|
@@ -63,6 +63,11 @@ export function applyGroupRoutingPayloadFields(payload, args, runtimeContext) {
|
|
|
63
63
|
payload.thread_id = threadId;
|
|
64
64
|
else if (payload.thread_id !== undefined)
|
|
65
65
|
delete payload.thread_id;
|
|
66
|
+
// Mark the final user-visible text message so the wire ext carries isFinal.
|
|
67
|
+
// buildWireExt (daemon side) merges this into the outgoing ext dictionary.
|
|
68
|
+
if (payload.type === 'text') {
|
|
69
|
+
payload.ext = { isFinal: true, ...(payload.ext && typeof payload.ext === 'object' && !Array.isArray(payload.ext) ? payload.ext : {}) };
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
function groupSendLogMetadata(args, payload, runtimeContext) {
|
|
68
73
|
const classified = payload ? classifyAunPayloadForLog(payload) : undefined;
|
package/dist/aun/menu/client.js
CHANGED
|
@@ -13,6 +13,8 @@ const MAX_TIMEOUT_MS = 120_000;
|
|
|
13
13
|
const POLL_INTERVAL_MS = 200;
|
|
14
14
|
const PULL_LIMIT = 50;
|
|
15
15
|
const LOCK_STALE_MS = 5 * 60_000;
|
|
16
|
+
const DENIAL_CACHE_TTL_MS = 30 * 60_000;
|
|
17
|
+
const DENIAL_CACHE_LIMIT = 128;
|
|
16
18
|
export class MenuClientError extends Error {
|
|
17
19
|
code;
|
|
18
20
|
data;
|
|
@@ -28,6 +30,7 @@ export class ManagedMenuClient {
|
|
|
28
30
|
send;
|
|
29
31
|
pending = new Map();
|
|
30
32
|
eventHandlers = new Map();
|
|
33
|
+
deniedQueries = new Map();
|
|
31
34
|
constructor(send) {
|
|
32
35
|
this.send = send;
|
|
33
36
|
}
|
|
@@ -68,6 +71,7 @@ export class ManagedMenuClient {
|
|
|
68
71
|
for (const entry of this.eventHandlers.values())
|
|
69
72
|
clearTimeout(entry.timer);
|
|
70
73
|
this.eventHandlers.clear();
|
|
74
|
+
this.deniedQueries.clear();
|
|
71
75
|
}
|
|
72
76
|
async request(options) {
|
|
73
77
|
if (!isValidAid(options.fromAid) || !isValidAid(options.targetAid))
|
|
@@ -85,6 +89,23 @@ export class ManagedMenuClient {
|
|
|
85
89
|
if (this.pending.has(key))
|
|
86
90
|
throw new MenuClientError('CLIENT_BUSY', 'Request ID is already in flight for this daemon');
|
|
87
91
|
const headers = buildMenuClientProtectedHeaders({ clientName: 'ec-menu-client', clientVersion: readInstalledEvolcoreVersion(), remoteAccessToken: options.remoteAccessToken ?? options.ecwebToken });
|
|
92
|
+
const denialKey = request.type === 'menu.query' || request.type === 'menu.options'
|
|
93
|
+
? crypto.createHash('sha256').update(JSON.stringify([
|
|
94
|
+
options.fromAid, options.targetAid, headers,
|
|
95
|
+
Object.fromEntries(Object.entries(request).filter(([field]) => field !== 'id')),
|
|
96
|
+
])).digest('hex')
|
|
97
|
+
: undefined;
|
|
98
|
+
for (const [cachedKey, expires] of this.deniedQueries) {
|
|
99
|
+
if (expires <= Date.now())
|
|
100
|
+
this.deniedQueries.delete(cachedKey);
|
|
101
|
+
}
|
|
102
|
+
if (denialKey && this.deniedQueries.has(denialKey)) {
|
|
103
|
+
options.beforeSend?.();
|
|
104
|
+
return {
|
|
105
|
+
type: 'menu.response', id: request.id, name: request.name,
|
|
106
|
+
error: { code: 'NOT_ALLOWED', message: 'Remote query was denied; authorization denial cached for up to 30 minutes or until reconnect.' },
|
|
107
|
+
};
|
|
108
|
+
}
|
|
88
109
|
if (options.onEvent && request.type === 'menu.action' && request.action === 'upgrade' && request.args?.mode === 'update') {
|
|
89
110
|
const existing = this.eventHandlers.get(key);
|
|
90
111
|
if (existing)
|
|
@@ -112,6 +133,12 @@ export class ManagedMenuClient {
|
|
|
112
133
|
});
|
|
113
134
|
try {
|
|
114
135
|
const [, value] = await Promise.all([sent, response]);
|
|
136
|
+
if (denialKey && value.error?.code === 'NOT_ALLOWED') {
|
|
137
|
+
if (this.deniedQueries.size >= DENIAL_CACHE_LIMIT) {
|
|
138
|
+
this.deniedQueries.delete(this.deniedQueries.keys().next().value);
|
|
139
|
+
}
|
|
140
|
+
this.deniedQueries.set(denialKey, Date.now() + DENIAL_CACHE_TTL_MS);
|
|
141
|
+
}
|
|
115
142
|
if (value.error || !(value.data && typeof value.data === 'object' && typeof value.data.jobId === 'string')) {
|
|
116
143
|
const handler = this.eventHandlers.get(key);
|
|
117
144
|
if (handler) {
|
|
@@ -9,7 +9,7 @@ import { isValidAid } from '../aid/validation.js';
|
|
|
9
9
|
import { tryParseChannelKey } from '../../core/channel-loader.js';
|
|
10
10
|
import { normalizeThreadOptionValue } from '../../core/thread/topic-id.js';
|
|
11
11
|
import { parseTimeArg, TIME_ARG_FORMATS } from '../../cli/cli-argv.js';
|
|
12
|
-
import { DEFAULT_FS_CAT_BYTES, MAX_FS_CAT_BYTES, FsReadBudgetError, downloadGroupFsBytes, readPersonalFsBytesWithinBudget, } from '../group/fs-download.js';
|
|
12
|
+
import { DEFAULT_FS_CAT_BYTES, MAX_FS_CAT_BYTES, FsReadBudgetError, downloadGroupFsBytes, readPersonalFsBytesWithinBudget, readAuthoritativePersonalFsObject, AuthoritativeFsReadError, } from '../group/fs-download.js';
|
|
13
13
|
import { groupBan, groupBanlist, groupBlock, groupUnblock, groupBlocklist, groupReportStatus, groupMemberStatuses, groupCreate, groupDissolve, groupInfo, groupInvite, groupJoin, groupKick, groupLeave, groupList, groupMembers, groupOnline, groupPull, groupAck, groupAcceptInvite, groupInvites, groupRejectInvite, groupRevokeInvite, groupResume, groupRules, groupRulesFileGet, groupRulesFilePublish, groupRulesFileSet, groupSetRole, groupSuspend, groupTransferOwner, groupUnban, groupUpdate, groupUpdateRules, } from '../group/operations.js';
|
|
14
14
|
import { handleGroupMenu, GroupMenuError } from '../../core/command/group-menu.js';
|
|
15
15
|
import { readRolesConfig } from '../../config/roles.js';
|
|
@@ -803,9 +803,9 @@ export class ManagedFsOperationError extends Error {
|
|
|
803
803
|
}
|
|
804
804
|
const FS_VALUE_FLAGS = new Set([
|
|
805
805
|
'--as', '--format', '--max-bytes', '--head-bytes', '--name', '--pattern', '--type', '--node-type',
|
|
806
|
-
'--size', '--mtime', '--page', '--page-size', '-m', '-x',
|
|
806
|
+
'--size', '--mtime', '--page', '--page-size', '-m', '-x', '--expires',
|
|
807
807
|
]);
|
|
808
|
-
const FS_BOOLEAN_FLAGS = new Set(['-p', '--parents', '-r', '--recursive', '-f', '--force', '--overwrite']);
|
|
808
|
+
const FS_BOOLEAN_FLAGS = new Set(['-p', '--parents', '-r', '--recursive', '-f', '--force', '--overwrite', '--authoritative']);
|
|
809
809
|
function failFs(code, reason) {
|
|
810
810
|
return { ok: false, code, reason };
|
|
811
811
|
}
|
|
@@ -820,6 +820,26 @@ function positiveInteger(value, flag, max) {
|
|
|
820
820
|
}
|
|
821
821
|
return number;
|
|
822
822
|
}
|
|
823
|
+
const MAX_MANAGED_LINK_SECONDS = 7 * 24 * 3600;
|
|
824
|
+
/** Parse --expires: bare seconds, or a duration such as 30m / 12h / 7d; 0 means no expiry. */
|
|
825
|
+
function parseManagedLinkExpiry(value) {
|
|
826
|
+
if (value === undefined)
|
|
827
|
+
return undefined;
|
|
828
|
+
const text = value.trim().toLowerCase();
|
|
829
|
+
if (!text)
|
|
830
|
+
return failFs('INVALID_ARGUMENT', '--expires requires a duration');
|
|
831
|
+
const match = /^(\d+)([smhd])?$/.exec(text);
|
|
832
|
+
if (!match)
|
|
833
|
+
return failFs('INVALID_ARGUMENT', '--expires accepts seconds, 30m, 12h, 7d, or 0 for a non-expiring link');
|
|
834
|
+
const unit = match[2] === undefined
|
|
835
|
+
? 1
|
|
836
|
+
: { s: 1, m: 60, h: 3600, d: 86400 }[match[2]];
|
|
837
|
+
const seconds = Number(match[1]) * unit;
|
|
838
|
+
if (!Number.isSafeInteger(seconds) || seconds < 0 || seconds > MAX_MANAGED_LINK_SECONDS) {
|
|
839
|
+
return failFs('INVALID_ARGUMENT', `--expires must be between 0 and ${MAX_MANAGED_LINK_SECONDS} seconds`);
|
|
840
|
+
}
|
|
841
|
+
return seconds;
|
|
842
|
+
}
|
|
823
843
|
function parseRemote(value, allowEmpty) {
|
|
824
844
|
if (!value)
|
|
825
845
|
return failFs('INVALID_ARGUMENT', 'missing remote storage path');
|
|
@@ -849,7 +869,7 @@ function parseRemote(value, allowEmpty) {
|
|
|
849
869
|
export function resolveManagedFsOperation(argv) {
|
|
850
870
|
const raw = argv[0] === 'fs' ? argv.slice(1) : argv;
|
|
851
871
|
const rawKind = raw[0];
|
|
852
|
-
if (!rawKind || !['ls', 'stat', 'lstat', 'cat', 'find', 'df', 'getfacl', 'setfacl', 'mkdir', 'cp', 'mv', 'rm'].includes(rawKind)) {
|
|
872
|
+
if (!rawKind || !['ls', 'stat', 'lstat', 'cat', 'find', 'df', 'getfacl', 'setfacl', 'mkdir', 'cp', 'mv', 'rm', 'link'].includes(rawKind)) {
|
|
853
873
|
return failFs('NOT_ALLOWED', `unsupported managed fs command: ${rawKind || '<missing>'}`);
|
|
854
874
|
}
|
|
855
875
|
const values = new Map();
|
|
@@ -903,9 +923,10 @@ export function resolveManagedFsOperation(argv) {
|
|
|
903
923
|
df: new Set(['--as', '--format']), mkdir: new Set(['--as', '--format']), cp: new Set(['--as', '--format']),
|
|
904
924
|
mv: new Set(['--as', '--format']), rm: new Set(['--as', '--format']),
|
|
905
925
|
getfacl: new Set(['--as', '--format']), setfacl: new Set(['--as', '--format', '-m', '-x']),
|
|
926
|
+
link: new Set(['--as', '--format', '--expires']),
|
|
906
927
|
};
|
|
907
928
|
const allowedBoolean = {
|
|
908
|
-
ls: new Set(), stat: new Set(), lstat: new Set(), cat: new Set(), find: new Set(), df: new Set(), getfacl: new Set(), setfacl: new Set(),
|
|
929
|
+
ls: new Set(), stat: new Set(), lstat: new Set(), cat: new Set(['--authoritative']), find: new Set(), df: new Set(), getfacl: new Set(), setfacl: new Set(), link: new Set(),
|
|
909
930
|
mkdir: new Set(['-p', '--parents']), cp: new Set(['-r', '--recursive', '-f', '--force', '--overwrite']),
|
|
910
931
|
mv: new Set(['-f', '--force', '--overwrite']), rm: new Set(['-r', '--recursive', '-f', '--force', '--overwrite']),
|
|
911
932
|
};
|
|
@@ -986,6 +1007,20 @@ export function resolveManagedFsOperation(argv) {
|
|
|
986
1007
|
const remote = remoteOrError(positionals[0], rawKind === 'df');
|
|
987
1008
|
if (!('targetAid' in remote))
|
|
988
1009
|
return remote;
|
|
1010
|
+
if (rawKind === 'link') {
|
|
1011
|
+
if (remote.remotePath === '/' || remote.remotePath === '') {
|
|
1012
|
+
return failFs('INVALID_PATH', 'managed link requires a file path, not the storage root');
|
|
1013
|
+
}
|
|
1014
|
+
const expires = parseManagedLinkExpiry(values.get('--expires'));
|
|
1015
|
+
if (expires !== undefined && typeof expires === 'object')
|
|
1016
|
+
return expires;
|
|
1017
|
+
return { ok: true, command: {
|
|
1018
|
+
kind: 'link', operationId: 'ec.fs.link',
|
|
1019
|
+
canonicalArgv: ['fs', 'link', positionals[0], ...(expires !== undefined ? ['--expires', String(expires)] : []), ...(actorAid ? ['--as', actorAid] : [])],
|
|
1020
|
+
actorAid, targetAid: remote.targetAid, remotePath: remote.remotePath,
|
|
1021
|
+
...(expires !== undefined ? { expiresSeconds: expires } : {}),
|
|
1022
|
+
} };
|
|
1023
|
+
}
|
|
989
1024
|
if (rawKind === 'mkdir')
|
|
990
1025
|
return { ok: true, command: {
|
|
991
1026
|
kind: 'mkdir', operationId: 'ec.fs.mkdir', canonicalArgv: ['fs', 'mkdir', positionals[0], ...(actorAid ? ['--as', actorAid] : [])],
|
|
@@ -1015,8 +1050,9 @@ export function resolveManagedFsOperation(argv) {
|
|
|
1015
1050
|
if (nodeType !== undefined && !['f', 'd', 'l'].includes(nodeType))
|
|
1016
1051
|
return failFs('INVALID_ARGUMENT', '--type only supports f|d|l');
|
|
1017
1052
|
return { ok: true, command: {
|
|
1018
|
-
kind: effectiveKind, operationId: `ec.fs.${effectiveKind}`, canonicalArgv: ['fs', effectiveKind, positionals[0], ...(actorAid ? ['--as', actorAid] : [])],
|
|
1053
|
+
kind: effectiveKind, operationId: `ec.fs.${effectiveKind}`, canonicalArgv: ['fs', effectiveKind, positionals[0], ...(actorAid ? ['--as', actorAid] : []), ...(booleanFlags.has('--authoritative') ? ['--authoritative'] : [])],
|
|
1019
1054
|
actorAid, targetAid: remote.targetAid, remotePath: remote.remotePath, maxBytes, headBytes,
|
|
1055
|
+
authoritative: booleanFlags.has('--authoritative'),
|
|
1020
1056
|
name: values.get('--name') ?? values.get('--pattern'), nodeType, size: values.get('--size'), mtime: values.get('--mtime'), page, pageSize,
|
|
1021
1057
|
} };
|
|
1022
1058
|
}
|
|
@@ -1076,6 +1112,9 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1076
1112
|
if (!command.storageBackend)
|
|
1077
1113
|
throw new ManagedFsOperationError('INVALID_TARGET', 'managed fs storage backend must be resolved before execution');
|
|
1078
1114
|
const ref = `${command.targetAid}:${command.remotePath}`;
|
|
1115
|
+
if (command.authoritative && (command.kind !== 'cat' || command.storageBackend !== 'personal')) {
|
|
1116
|
+
throw new ManagedFsOperationError('NOT_ALLOWED', 'authoritative reads require personal storage cat');
|
|
1117
|
+
}
|
|
1079
1118
|
try {
|
|
1080
1119
|
return await (async () => {
|
|
1081
1120
|
if (command.storageBackend === 'personal') {
|
|
@@ -1126,12 +1165,30 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1126
1165
|
}) };
|
|
1127
1166
|
case 'df':
|
|
1128
1167
|
return { ok: true, command: 'df', path: `${owner}:`, usage: await client.storage.df({ owner }) };
|
|
1168
|
+
case 'link': {
|
|
1169
|
+
// The SDK wrapper fixes the ticket lifetime, so call the RPC directly to honor --expires.
|
|
1170
|
+
const ticket = await client.call('storage.create_download_ticket', {
|
|
1171
|
+
owner_aid: owner,
|
|
1172
|
+
bucket: 'default',
|
|
1173
|
+
object_key: command.remotePath.replace(/^\/+/, ''),
|
|
1174
|
+
...(command.expiresSeconds !== undefined ? { expire_in_seconds: command.expiresSeconds } : {}),
|
|
1175
|
+
});
|
|
1176
|
+
const record = (ticket && typeof ticket === 'object' ? ticket : {});
|
|
1177
|
+
const url = typeof record.download_url === 'string' && record.download_url
|
|
1178
|
+
? record.download_url
|
|
1179
|
+
: typeof record.url === 'string' ? record.url : '';
|
|
1180
|
+
if (!url)
|
|
1181
|
+
throw new ManagedFsOperationError('DEPENDENCY_UNAVAILABLE', 'storage did not return a download url');
|
|
1182
|
+
return { ok: true, command: 'link', path: ref, url, expireAt: record.expire_at ?? null };
|
|
1183
|
+
}
|
|
1129
1184
|
case 'getfacl':
|
|
1130
1185
|
return { ok: true, command: 'getfacl', path: ref, result: await client.storage.listAcl(command.remotePath, { owner }) };
|
|
1131
1186
|
case 'setfacl':
|
|
1132
1187
|
throw new ManagedFsOperationError('NOT_ALLOWED', 'Managed personal storage ACL changes are not supported');
|
|
1133
1188
|
case 'cat': {
|
|
1134
|
-
const bytes =
|
|
1189
|
+
const bytes = command.authoritative
|
|
1190
|
+
? (await readAuthoritativePersonalFsObject(client, command.remotePath, owner, command.maxBytes ?? DEFAULT_FS_CAT_BYTES)).bytes
|
|
1191
|
+
: await readPersonalFsBytesWithinBudget(client, command.remotePath, command.maxBytes ?? DEFAULT_FS_CAT_BYTES, { owner });
|
|
1135
1192
|
const headBytes = Math.min(command.headBytes ?? 256, MAX_MANAGED_FS_HEAD_BYTES, bytes.byteLength);
|
|
1136
1193
|
if (bytes.subarray(0, Math.min(bytes.byteLength, 8192)).some(byte => byte === 0)) {
|
|
1137
1194
|
return {
|
|
@@ -1206,6 +1263,8 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1206
1263
|
}
|
|
1207
1264
|
case 'df':
|
|
1208
1265
|
return { ok: true, command: 'df', path: `${command.targetAid}:`, usage: await client.group.fs.df(`${command.targetAid}:`) };
|
|
1266
|
+
case 'link':
|
|
1267
|
+
throw new ManagedFsOperationError('NOT_ALLOWED', 'managed link is only supported for personal storage');
|
|
1209
1268
|
case 'getfacl':
|
|
1210
1269
|
return { ok: true, command: 'getfacl', path: ref, result: await client.group.fs.getAcl(ref) };
|
|
1211
1270
|
case 'setfacl': {
|
|
@@ -1248,6 +1307,8 @@ export async function executeManagedFsOperationWithClient(command, client) {
|
|
|
1248
1307
|
throw error;
|
|
1249
1308
|
if (error instanceof FsReadBudgetError)
|
|
1250
1309
|
throw new ManagedFsOperationError(error.code, error.message);
|
|
1310
|
+
if (error instanceof AuthoritativeFsReadError)
|
|
1311
|
+
throw new ManagedFsOperationError(error.code, error.message);
|
|
1251
1312
|
throw new ManagedFsOperationError('FS_OPERATION_FAILED', error instanceof Error ? error.message : String(error));
|
|
1252
1313
|
}
|
|
1253
1314
|
}
|