# azhi-ss/feishu-agent architecture

> Architecture diagram of the GitHub repository azhi-ss/feishu-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azhi-ss/feishu-agent
- Repository: https://github.com/azhi-ss/feishu-agent

## Overview

Feishu Agent is a CLI/TUI shell around Pi’s agent runtime for natural-language Feishu work via lark-cli. A user initializes local configuration and skills, then starts an interactive or Print session; the CLI selects a project-scoped session, assembles prompts/resources and extensions, and runs the agent. The product also includes high-risk-action guards, optional scheduled automation, and an optional remote bridge. Edges reflect shown imports/calls or README-documented capabilities; several package internals are unsampled, so their links are limited to documented relationships.

Main entry points: [`src/cli.ts`](https://github.com/azhi-ss/feishu-agent/blob/master/src/cli.ts) (CLI commands), [`src/runtime.ts`](https://github.com/azhi-ss/feishu-agent/blob/master/src/runtime.ts) (Session runtime), [`src/resources.ts`](https://github.com/azhi-ss/feishu-agent/blob/master/src/resources.ts) (Resource loader), [`packages/feishu-remote/extensions/remote-bridge.ts`](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-bridge.ts) (Remote bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and setup"]
  node_cli["CLI commands<br/>[cli.ts]"]
  node_init["Initialization<br/>[init.ts]"]
  node_readiness["Readiness checks<br/>[readiness.ts]"]
  node_settings[("Settings storage<br/>[settings.ts]")]
end

subgraph group_agent["Agent runtime"]
  node_runtime["Session runtime<br/>[runtime.ts]"]
  node_resources["Resource loader<br/>[resources.ts]"]
  node_sessions["Session selection<br/>[sessions.ts]"]
  node_tasks["Task refresh<br/>[tasks.ts]"]
end

subgraph group_capabilities["Skills and safeguards"]
  node_defaultskills["Bundled skills<br/>[default-skills.ts]"]
  node_officialskills["Official skills sync<br/>[official-skills.ts]"]
  node_skillsearch["Skill search<br/>[find-skill.ts]"]
  node_guards["High-risk approval<br/>[high-risk.ts]"]
  node_policy["Project policy<br/>[policy.ts]"]
  node_subagents["Subagent context<br/>[subagents.ts]"]
end

subgraph group_automation["Scheduled automation"]
  node_automationcommands["Automation commands"]
  node_automationstate[("Schedule state<br/>[automation.ts]")]
  node_trigger["Schedule trigger"]
  node_runner["Run supervisor"]
  node_service["Service manager"]
end

subgraph group_remote["Remote bridge"]
  node_remote["Remote bridge<br/>[remote-bridge.ts]"]
  node_gateway["Remote gateway<br/>[remote-gateway.ts]"]
  node_lock["Remote lock<br/>[remote-lock.ts]"]
  node_stream["Stream cards<br/>[stream-card.ts]"]
end

node_user(("Feishu user"))
node_pi["Pi SDK and TUI"]
node_lark["lark-cli"]

node_user -->|"invokes"| node_cli
node_cli -->|"initializes"| node_init
node_cli -->|"checks readiness"| node_readiness
node_cli -->|"starts session"| node_runtime
node_cli -->|"dispatches config"| node_settings
node_init -->|"installs skills"| node_defaultskills
node_init -->|"stores preferences"| node_settings
node_readiness -->|"checks CLI"| node_lark
node_runtime -->|"selects session"| node_sessions
node_runtime -->|"loads resources"| node_resources
node_runtime -->|"loads settings"| node_settings
node_runtime -->|"runs agent"| node_pi
node_resources -->|"checks approval"| node_guards
node_resources -->|"publishes context"| node_subagents
node_resources -.->|"offers search"| node_skillsearch
node_resources -.->|"loads skills"| node_defaultskills
node_cli -->|"syncs skills"| node_officialskills
node_officialskills -.->|"synchronizes from"| node_lark
node_guards -.->|"guards writes"| node_lark
node_tasks -->|"refreshes tasks"| node_lark
node_cli -.->|"refreshes tasks"| node_tasks
node_user -.->|"schedules work"| node_automationcommands
node_automationcommands -->|"reads schedule state"| node_automationstate
node_automationcommands -.->|"manages schedules"| node_trigger
node_trigger -->|"reads and settles"| node_automationstate
node_trigger -->|"starts scheduled run"| node_runner
node_runner -->|"reads schedule"| node_automationstate
node_runner -.->|"launches child"| node_cli
node_service -->|"supervises trigger"| node_trigger
node_user -->|"delegates task"| node_remote
node_remote -->|"routes requests"| node_gateway
node_remote -->|"uses lock"| node_lock
node_remote -->|"renders updates"| node_stream

click node_cli "https://github.com/azhi-ss/feishu-agent/blob/master/src/cli.ts"
click node_init "https://github.com/azhi-ss/feishu-agent/blob/master/src/init.ts"
click node_readiness "https://github.com/azhi-ss/feishu-agent/blob/master/src/readiness.ts"
click node_settings "https://github.com/azhi-ss/feishu-agent/blob/master/src/settings.ts"
click node_runtime "https://github.com/azhi-ss/feishu-agent/blob/master/src/runtime.ts"
click node_resources "https://github.com/azhi-ss/feishu-agent/blob/master/src/resources.ts"
click node_sessions "https://github.com/azhi-ss/feishu-agent/blob/master/src/sessions.ts"
click node_tasks "https://github.com/azhi-ss/feishu-agent/blob/master/src/tasks.ts"
click node_defaultskills "https://github.com/azhi-ss/feishu-agent/blob/master/src/default-skills.ts"
click node_officialskills "https://github.com/azhi-ss/feishu-agent/blob/master/src/official-skills.ts"
click node_skillsearch "https://github.com/azhi-ss/feishu-agent/blob/master/src/find-skill.ts"
click node_guards "https://github.com/azhi-ss/feishu-agent/blob/master/src/high-risk.ts"
click node_policy "https://github.com/azhi-ss/feishu-agent/blob/master/src/policy.ts"
click node_subagents "https://github.com/azhi-ss/feishu-agent/blob/master/src/subagents.ts"
click node_automationcommands "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-commands.ts"
click node_automationstate "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation.ts"
click node_trigger "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-trigger.ts"
click node_runner "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-runner.ts"
click node_service "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-service.ts"
click node_remote "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-bridge.ts"
click node_gateway "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-gateway.ts"
click node_lock "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-lock.ts"
click node_stream "https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/stream-card.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_init,node_readiness,node_settings,node_user,node_pi toneBlue
class node_runtime,node_resources,node_sessions,node_tasks toneAmber
class node_defaultskills,node_officialskills,node_skillsearch,node_guards,node_policy,node_subagents toneMint
class node_automationcommands,node_automationstate,node_trigger,node_runner,node_service toneRose
class node_remote,node_gateway,node_lock,node_stream,node_lark toneIndigo
```

## Components

### CLI and setup

- [CLI commands](https://github.com/azhi-ss/feishu-agent/blob/master/src/cli.ts): `src/cli.ts`
- [Initialization](https://github.com/azhi-ss/feishu-agent/blob/master/src/init.ts): `src/init.ts`
- [Readiness checks](https://github.com/azhi-ss/feishu-agent/blob/master/src/readiness.ts): `src/readiness.ts`
- [Settings storage](https://github.com/azhi-ss/feishu-agent/blob/master/src/settings.ts): `src/settings.ts`

### Agent runtime

- [Session runtime](https://github.com/azhi-ss/feishu-agent/blob/master/src/runtime.ts): `src/runtime.ts`
- [Resource loader](https://github.com/azhi-ss/feishu-agent/blob/master/src/resources.ts): `src/resources.ts`
- [Session selection](https://github.com/azhi-ss/feishu-agent/blob/master/src/sessions.ts): `src/sessions.ts`
- [Task refresh](https://github.com/azhi-ss/feishu-agent/blob/master/src/tasks.ts): `src/tasks.ts`

### Skills and safeguards

- [Bundled skills](https://github.com/azhi-ss/feishu-agent/blob/master/src/default-skills.ts): `src/default-skills.ts`
- [Official skills sync](https://github.com/azhi-ss/feishu-agent/blob/master/src/official-skills.ts): `src/official-skills.ts`
- [Skill search](https://github.com/azhi-ss/feishu-agent/blob/master/src/find-skill.ts): `src/find-skill.ts`
- [High-risk approval](https://github.com/azhi-ss/feishu-agent/blob/master/src/high-risk.ts): `src/high-risk.ts`
- [Project policy](https://github.com/azhi-ss/feishu-agent/blob/master/src/policy.ts): `src/policy.ts`
- [Subagent context](https://github.com/azhi-ss/feishu-agent/blob/master/src/subagents.ts): `src/subagents.ts`

### Scheduled automation

- [Automation commands](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-commands.ts): `packages/feishu-automation/src/automation-commands.ts`
- [Schedule state](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation.ts): `packages/feishu-automation/src/automation.ts`
- [Schedule trigger](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-trigger.ts): `packages/feishu-automation/src/automation-trigger.ts`
- [Run supervisor](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-runner.ts): `packages/feishu-automation/src/automation-runner.ts`
- [Service manager](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-automation/src/automation-service.ts): `packages/feishu-automation/src/automation-service.ts`

### Remote bridge

- [Remote bridge](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-bridge.ts): `packages/feishu-remote/extensions/remote-bridge.ts`
- [Remote gateway](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-gateway.ts): `packages/feishu-remote/extensions/remote-gateway.ts`
- [Remote lock](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/remote-lock.ts): `packages/feishu-remote/extensions/remote-lock.ts`
- [Stream cards](https://github.com/azhi-ss/feishu-agent/blob/master/packages/feishu-remote/extensions/stream-card.ts): `packages/feishu-remote/extensions/stream-card.ts`

### Other components

- **Feishu user**
- **Pi SDK and TUI**
- **lark-cli**

## Connections

- Feishu user → CLI commands: invokes (evidence: `README.md`)
- CLI commands → Initialization: initializes (evidence: `src/cli.ts`)
- CLI commands → Readiness checks: checks readiness (evidence: `src/cli.ts`)
- CLI commands → Session runtime: starts session (evidence: `src/cli.ts`)
- CLI commands → Settings storage: dispatches config (evidence: `src/cli.ts`)
- Initialization → Bundled skills: installs skills (evidence: `src/init.ts`)
- Initialization → Settings storage: stores preferences (evidence: `src/init.ts`)
- Readiness checks → lark-cli: checks CLI (evidence: `README.md`)
- Session runtime → Session selection: selects session (evidence: `src/runtime.ts`)
- Session runtime → Resource loader: loads resources (evidence: `src/runtime.ts`)
- Session runtime → Settings storage: loads settings (evidence: `src/runtime.ts`)
- Session runtime → Pi SDK and TUI: runs agent (evidence: `src/runtime.ts`)
- Resource loader → High-risk approval: checks approval (evidence: `src/resources.ts`)
- Resource loader → Subagent context: publishes context (evidence: `src/resources.ts`)
- Resource loader → Skill search: offers search (evidence: `src/resources.ts`)
- Resource loader → Bundled skills: loads skills (evidence: `README.md`)
- CLI commands → Official skills sync: syncs skills (evidence: `src/cli.ts`)
- Official skills sync → lark-cli: synchronizes from (evidence: `README.md`)
- High-risk approval → lark-cli: guards writes (evidence: `README.md`)
- Task refresh → lark-cli: refreshes tasks (evidence: `src/tasks.ts`)
- CLI commands → Task refresh: refreshes tasks (evidence: `README.md`)
- Feishu user → Automation commands: schedules work (evidence: `README.md`)
- Automation commands → Schedule state: reads schedule state (evidence: `packages/feishu-automation/src/automation-commands.ts`)
- Automation commands → Schedule trigger: manages schedules (evidence: `README.md`)
- Schedule trigger → Schedule state: reads and settles (evidence: `packages/feishu-automation/src/automation-trigger.ts`)
- Schedule trigger → Run supervisor: starts scheduled run (evidence: `packages/feishu-automation/src/automation-trigger.ts`)
- Run supervisor → Schedule state: reads schedule (evidence: `packages/feishu-automation/src/automation-runner.ts`)
- Run supervisor → CLI commands: launches child (evidence: `README.md`)
- Service manager → Schedule trigger: supervises trigger (evidence: `packages/feishu-automation/src/automation-service.ts`)
- Feishu user → Remote bridge: delegates task (evidence: `README.md`)
- Remote bridge → Remote gateway: routes requests (evidence: `packages/feishu-remote/extensions/remote-bridge.ts`)
- Remote bridge → Remote lock: uses lock (evidence: `packages/feishu-remote/extensions/remote-bridge.ts`)
- Remote bridge → Stream cards: renders updates (evidence: `packages/feishu-remote/extensions/remote-bridge.ts`)
