delegation-helpers.mjs
73 lines 1.9 KB
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor ⚠ breaking 11 days ago
1 /**
2 * Shared helpers for agent delegation tiers (7C-6).
3 */
4 import fs from 'node:fs';
5 import path from 'node:path';
6
7 import {
8 DELEGATION_POLICY_FILE,
9 AGENT_IDENTITY_SCHEMA,
10 DELEGATION_CONSENT_SCHEMA,
11 hashPrincipalRef,
12 } from '../../../lib/agent/delegation.mjs';
13
14 export const TEST_USER_ID = 'test-user-delegation';
15 export const TEST_PRINCIPAL_REF = hashPrincipalRef(TEST_USER_ID);
16
17 /**
18 * @param {string} dataDir
19 */
20 export function writeDelegationPolicy(dataDir) {
21 const fp = path.join(dataDir, DELEGATION_POLICY_FILE);
22 fs.writeFileSync(
23 fp,
24 JSON.stringify({
25 delegation: {
26 enabled: true,
27 default_ttl_seconds: 3600,
28 max_ttl_seconds: 86400,
29 },
30 }),
31 'utf8',
32 );
33 }
34
35 /**
36 * @param {{ agentId?: string, kind?: string, scopeCeiling?: string }} [opts]
37 */
38 export function makeAgentIdentity(opts = {}) {
39 const now = '2026-06-21T00:00:00Z';
40 return {
41 schema: AGENT_IDENTITY_SCHEMA,
42 agent_id: opts.agentId ?? 'agent_tutor_test01',
43 kind: opts.kind ?? 'delegate',
44 owner_ref: TEST_PRINCIPAL_REF,
45 vault_id: 'default',
46 scope_ceiling: opts.scopeCeiling ?? 'project',
47 label: 'Test tutor',
48 status: 'active',
49 created: now,
50 updated: now,
51 };
52 }
53
54 /**
55 * @param {{ consentId?: string, agentId?: string, taskIds?: string[], flowIds?: string[] }} [opts]
56 */
57 export function makeDelegationConsent(opts = {}) {
58 const now = '2026-06-21T00:00:00Z';
59 return {
60 schema: DELEGATION_CONSENT_SCHEMA,
61 consent_id: opts.consentId ?? 'dcons_test_fall01',
62 principal_ref: TEST_PRINCIPAL_REF,
63 delegate_agent_id: opts.agentId ?? 'agent_tutor_test01',
64 scope: 'project',
65 workspace_id: 'ws_class_101',
66 allowed_flow_ids: opts.flowIds ?? ['flow_weekly_review'],
67 allowed_task_ids: opts.taskIds ?? ['task_hw_week3'],
68 expires_at: '2026-12-31T23:59:59Z',
69 revoked_at: null,
70 evidence_ref: 'proposal:prop_test123',
71 created: now,
72 };
73 }
File History 1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882 fix(test): align Band B landing assertion with desktop MCP … Human 11 days ago