delegation-helpers.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 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
2 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago