# lan-device-ops **Repository Path**: henrydontbb/lan-device-ops ## Basic Information - **Project Name**: lan-device-ops - **Description**: 公开仓库的当前发布树(v1.0.0 起)不含任何真实设备、IP、账号、密钥或运维报告;示例均为匿名占位。历史 PR 引用可能指向重构前的旧历史,不在本声明范围内。 - **Primary Language**: Python - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-26 - **Last Updated**: 2026-11-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LAN Device Ops [English](README.en.md) | [中文](README.md) ![stars](https://gitee.com/henrydontbb/lan-device-ops/badge/star.svg?theme=dark) ![forks](https://gitee.com/henrydontbb/lan-device-ops/badge/fork.svg?theme=dark) `v1.2.2` · MIT · Python 3.12+ 用于维护**私有设备清单**的本地优先 Python CLI 和自包含 Agent Skill。它可读取本地状态、导出已登记的 SSH/RDP/ToDesk 连接元数据,并在明确请求时执行固定、受限的只读 SSH 检查。 > 公开仓库的**当前发布树(v1.0.0 起)**不包含真实设备、IP、账号、密钥路径、`known_hosts`、运行报告或设备运维记录(示例均为匿名占位)。历史 PR 引用可能指向重构前的旧历史,不在本声明的覆盖范围内。 ## 能力边界 - `resolve` 是 lookup-only:读取已登记连接元数据,不连接、不执行 SSH,也不向调用它的 Agent 施加本项目的权限策略。 - 已登记且唯一匹配的设备直接复用连接信息,不重复询问或重新登记 IP、账号、密钥、端口;找不到设备是数据缺口,不是权限拒绝。 - `status`、`fleet-status`、`access-contract` 和 `doctor` 默认只读取本地文件。 - `--refresh` 和 `run-readonly` 仅使用内置的固定只读计划,不能执行任意远端命令。 - This CLI does not start browsers or execute browser automation. This CLI does not provide generic remote write or deployment operations. MCP 是本项目的 long-term NO-GO。只有独立提案同时证明 local-only 调用方、版本化 I/O schema、enforced no-refresh/no-remote boundaries 和独立测试后才可重新评估。 ## 安装 要求 Python 3.12+;CLI 运行时依赖为精确版本 `PyYAML==6.0.3`(import name 为 `yaml`)。发布的 Skill zip 是 checkout-independent,但不是 dependency-free:使用同一个 Python 解释器按包内 `requirements.txt` 安装依赖;launcher 会在读取 inventory 或尝试 SSH 前执行 preflight,缺依赖时返回 `dependency_missing` 并停止路由。 ```powershell python -m pip install -e . lan-device-ops --version lan-device-ops doctor --json ``` 源代码兼容入口: ```powershell python scripts/lan_device_ops.py --version python scripts/lan_device_ops.py doctor --json ``` 当前版本由 `VERSION` 单一来源管理;仓库内 Skill 元数据必须与其一致。 ## 私有 inventory 真实 inventory 是 canonical inventory,Windows 上所有 Agent 和所有默认命令统一使用: ```text %LOCALAPPDATA%\lan-device-ops\devices.local.yaml ``` 首次准备时从匿名示例复制到系统目录,再只在该文件中维护真实设备信息: ```powershell $canonical = Join-Path $env:LOCALAPPDATA 'lan-device-ops\devices.local.yaml' New-Item -ItemType Directory -Force (Split-Path $canonical) | Out-Null Copy-Item configs/devices.example.yaml $canonical ``` canonical inventory 不进入仓库、Skill 目录或发布包;禁止提交真实 host、账号、密钥路径、token、密码、`known_hosts` 或 HMAC key。不要为不同 Agent 配置不同 inventory 环境变量;默认发现不会读取 `LAN_DEVICE_OPS_INVENTORY`、`LAN_DEVICE_OPS_SHARED_INVENTORY` 或工作区 `configs/devices.local.yaml`。 显式 `--inventory` 仅用于测试或明确的受控覆盖;它不会改变 canonical inventory。 ## 常用命令 ```powershell # 本地检查,不连接远端;默认读取 canonical inventory lan-device-ops validate lan-device-ops doctor --json lan-device-ops status --device --json lan-device-ops status --device --summary zh-ascii # 供其他已安装 Skill / Agent 复用的连接注册表 lan-device-ops resolve --device --json # 为 SSH 调用方导出已登记的连接目标,不重新配置、不自动连接 lan-device-ops connect --device --json lan-device-ops ssh-target --device --json # 仅在明确需要实时证据时使用固定只读 SSH 检查 lan-device-ops status --device --refresh --summary zh-ascii --output-dir outputs ``` `access-contract --device --json` 导出本项目侧的连接契约;它不证明外部工具或第三方远程会话可用。 ## 本地报告维护 `clean-reports` 仅管理本地报告保留期,不读取 inventory、不执行 SSH,也不会影响远端设备。先预览候选报告,再用 `--confirm` 确认;默认保留每个设备和 profile 最近两份结构有效报告。 ```powershell lan-device-ops clean-reports --reports-dir outputs --older-than 30d --json lan-device-ops clean-reports --reports-dir outputs --older-than 30d --confirm ``` 需要定位明确的磁盘或目录问题时,`storage-report` 是高成本、受边界限制的只读诊断,不应作为日常刷新替代方案。 ## 新设备登记 `add-device` 默认写入已存在的 canonical inventory。它默认预览,只有 `--confirm` 才会原子写入;新设备始终 `enabled: false`。`--inventory` 只用于测试或明确的受控本地覆盖,且目标必须是已存在的 `.local.yaml` / `.local.yml`。 ```powershell lan-device-ops add-device --name example-linux-node --type linux --host 192.0.2.42 --policy read_only lan-device-ops add-device --name example-linux-node --type linux --host 192.0.2.42 --policy read_only --confirm lan-device-ops completion --shell bash ``` 该命令不会收集密码、私钥内容、host key 或 HMAC key。需先带外验证主机指纹,再由操作员在仓库外维护 `known_hosts`。 ### 已登记设备身份更新 设备重置但仍是同一台设备时,使用 `update-device` 按名称或 alias 更新原记录的连接身份。它不会新增设备,也不会改变正式名称、aliases、`enabled`、type、policy 或 external refs;默认只预览,只有 `--confirm` 才原子写盘。 ```powershell lan-device-ops update-device --device 88 --host 192.0.2.188 --port 22 --user-hint readonly-user --auth-hint ssh_key_preferred --key-path C:/operator/keys/mac-88 lan-device-ops update-device --device 88 --host 192.0.2.188 --port 22 --user-hint readonly-user --auth-hint ssh_key_preferred --key-path C:/operator/keys/mac-88 --confirm ``` 只传入重置后实际变化且已核实的字段;新 host key 仍须先带外验证,再更新仓库外的 `known_hosts`。 ## 状态标签 - `正常` (`normal`) - `可用,需观察` (`usable, observe`) - `待验证` (`pending verification`) - `报告过期` (`stale report`) - `没有本地报告` (`no local report`) 机器判断以 `health_reason`、`report_integrity` 和 `evidence.trust_state` 为准。终端中文显示不可靠时,优先 `status --json` 或 `status --summary zh-ascii`。 ## 健康原因 `status --json` 的 `health_reason` 取值固定为以下九种,机器判断以此为准: - `missing_report`:缺少本地报告 - `invalid_report`:报告结构无效 - `report_fallback`:使用了回退报告 - `unverified_report`:报告完整性未验证 - `clock_skew`:采集时间与当前时钟偏差过大 - `latest_failed`:最近一次检查失败 - `stale_report`:报告已过期 - `recent_instability`:近期不稳定 - `healthy`:健康 报告的 `report_integrity` 与 `evidence.trust_state` 给出证据可信度。 ## 批量与 fleet 检查 `status`、`fleet-status` 和 `fleet-check` 默认只读取本地报告,不连接远端。`fleet-status` 汇总所有设备的最新只读报告;`fleet-check --device ...` 批量检查多台设备并给出每台的健康结论。`source_ready` 与 `target_in_sync` 是 `publish-skill` 的校验输出,用于判断本地来源是否就绪、目标是否已与来源一致。 ## 安全与维护 - 禁止提交私有材料;使用 `--redact` 脱敏展示输出。 - HMAC sidecar 只证明本地报告采集后的完整性,不是远端可信证明。报告完整性密钥由 `report-key init` 创建(32 字节本地密钥),`report-key check` 校验其安全性;sidecar 使用 HMAC-SHA256 仅证明本地报告采集后的完整性。 - 重启、关机、刷固件、格式化、删除系统目录、禁用防火墙、修改 SSH daemon、创建远端用户和通用远端写操作均不在本项目能力范围。 - Maintenance / Adaptation:先确认需求是否属于固定只读能力;否则应建立独立的写操作方案,明确目标、影响、回滚与最终确认。 详见:[架构](docs/zh-CN/architecture.md) · [安全边界](docs/zh-CN/safety-boundaries.md) · [路线图](docs/zh-CN/roadmap.md) · [私有设备记录模板](docs/zh-CN/guides/device-notes-template.md)。 ## 开发与发布 `publish-skill` 默认以原子方式同步三个固定本机目标:WorkBuddy(`%USERPROFILE%\.workbuddy\skills\lan-device-ops`)、Codex(`%USERPROFILE%\.codex\skills\lan-device-ops`)和 OpenCode(`%USERPROFILE%\.config\opencode\skills\lan-device-ops`)。`doctor --json` 会对这些目标执行完整 payload hash 审计;未配置的独立 DeepSeek harness 保持 `unconfigured`,不会猜测路径。 ```powershell python -m pytest tests -q python -m pyright python scripts/lan_device_ops.py publish-skill --dry-run ``` 发布前必须通过测试、静态检查、文档契约和公开面扫描。公开基线将使用新的无父 Git 历史;旧私有历史、旧 tag、旧 Release 和真实运维材料不会迁移。