host-ports.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Permission host-ports: structural interfaces the host (local-runtime today)
  3. * implements and injects via {@link configurePermissionHost}. Mirrors the cron
  4. * host-port pattern (`cron/host-ports.ts`).
  5. *
  6. * Ports: the cloud-classifier managed-auth token getter, the prompt resolver,
  7. * and the rule store / session / agent / message resolvers.
  8. */
  9. // ── Service orchestration ports (consumed by the host wiring) ──
  10. import type { ToolPermissionContext, PermissionUpdate } from './types.js';
  11. import type { AgentMessageProtocol } from '@mavis/agent-core/protocol/agent-message';
  12. // ── Prompt content port ─────────────────────────────────────────────────────
  13. /**
  14. * Host-owned prompt resolver for permission classifier prompts.
  15. *
  16. * agent-core decides when a prompt is needed, but the host owns filesystem or
  17. * bundle lookup (including `{dataDir}/internal/prompts/*.md` overrides).
  18. */
  19. export interface PermissionPromptProvider {
  20. resolvePrompt(name: string): string | undefined;
  21. }
  22. // ── Managed-auth token port (cloud classifier Bearer) ──
  23. /**
  24. * Returns the managed-login auth token used as the cloud classifier's Bearer
  25. * credential. Returns undefined when no managed token is available (BYO-key /
  26. * offline) — the cloud classifier then fail-closes to `confirm`/ask, matching
  27. * the original daemon behavior.
  28. */
  29. export type ManagedAuthTokenGetter = () => string | undefined;
  30. export type { PermissionRequestStore } from './permission-request-store.js';
  31. export type { PermissionRequestRecord } from './permission-request-store.js';
  32. /**
  33. * Rule store: builds the merged (global+agent+session) permission context and
  34. * applies rule mutations. Implemented by local-runtime's rule store adapter.
  35. */
  36. export interface PermissionStorePort {
  37. getContext(agentName?: string, sessionId?: string): Promise<ToolPermissionContext>;
  38. applyUpdate(update: PermissionUpdate): Promise<void>;
  39. }
  40. /** Session lookup used to resolve workspace dir + translate framework ids. */
  41. export interface SessionResolverPort {
  42. get(
  43. sessionId: string,
  44. ): Promise<{ session_id: string; workspace_dir?: string; agent_name?: string } | undefined>;
  45. }
  46. /** Agent lookup used to resolve the agent's source project as a fallback cwd. */
  47. export interface AgentResolverPort {
  48. get(agentName: string): Promise<{ source_project?: string } | undefined>;
  49. }
  50. /** Recent-message lookup for classifier context + user-locale detection. */
  51. export interface MessageStorePort {
  52. getRecent(
  53. sessionId: string,
  54. limit: number,
  55. role?: string,
  56. options?: { excludePermissionResponses?: boolean },
  57. ): Promise<AgentMessageProtocol[]>;
  58. }
  59. /** Config mutation used by setMode() to persist the permission mode. */
  60. export interface ConfigWriterPort {
  61. updateConfigFile(patch: { permissionMode: string }): Promise<void>;
  62. }