diff --git a/.agent b/.agent deleted file mode 120000 index c0ca468..0000000 --- a/.agent +++ /dev/null @@ -1 +0,0 @@ -.agents \ No newline at end of file diff --git a/.agents/README.md b/.agents/README.md deleted file mode 100644 index f2a015d..0000000 --- a/.agents/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Agent Customizations & Modular Rules Policy - -This directory (`.agents/`) maintains modular configuration, skills, and guidelines for AI coding assistants working in the `hose-use` repository. - ---- - -## 1. Directory Structure - -``` -.agents/ -├── README.md # This document: architecture & trigger policy -├── skills.json # Declarative skill path and exclusion filters -└── rules/ # Modular, domain-specific rule definitions (trigger: "manual") - ├── production-safety.md # 生产环境安全红线、免读源码与写操作防护原则 - ├── cli-protocol.md # CLI stdout/stderr stream contract & exit codes - ├── tenant-and-credential.md # 多租户凭据管理、协助链接与单据检索最佳实践 - ├── testing-and-dev-hygiene.md # 单元测试规范、非交互环境防护与发布流程 - └── typescript-style.md # ESM, explicit .js imports, and TypeScript styles -``` - ---- - -## 2. Trigger Strategy & Context Budget Management - -### Why `trigger: "manual"`? - -In Antigravity (`agy`), rule files located in `.agents/rules/*.md` support YAML frontmatter: - -```yaml ---- -description: "..." -globs: "src/..." -trigger: "manual" ---- -``` - -1. **Token Economy**: If set to `trigger: "always_on"`, every turn of the conversation unconditionally injects all rules into the system prompt (``), consuming substantial context tokens on every request regardless of task relevance. -2. **On-Demand Activation**: Setting `trigger: "manual"` prevents automatic background injection into the prompt budget. The rules remain available on-demand when explicitly referenced or requested by the user or agent. -3. **Cross-Agent Neutrality**: Non-agy agents (e.g. OpenAI Codex, Claude Code, Cursor, generic LLMs) do not recognize `agy`'s private frontmatter triggers. Storing modular guidelines as plain Markdown with a manual trigger ensures they function as clean, standalone reference docs that any agent can read on demand via standard file reading tools without unexpected prompt pollution. - ---- - -## 3. Modular Rules Inventory - -| Rule File | Domain / Scope | Key Responsibilities | -| :--- | :--- | :--- | -| [`rules/production-safety.md`](./rules/production-safety.md) | 全局行为 | **生产安全最高红线**、严禁私自翻阅源码配置 (Zero Source-Reading)、两阶段确认写保护。 | -| [`rules/tenant-and-credential.md`](./rules/tenant-and-credential.md) | 凭证与单据 | 同等凭据原则、协助链接导入与 `--overwrite` 保护、个人单据 (`task submitted` / `bill list --mine`) 快速通道。 | -| [`rules/cli-protocol.md`](./rules/cli-protocol.md) | `src/cli/**/*.ts` | 严格 `stdout` JSON vs `stderr` 诊断输出契约、200KB 大报文防爆拦截、退出码规范。 | -| [`rules/testing-and-dev-hygiene.md`](./rules/testing-and-dev-hygiene.md) | 测试与流程 | `bun:test` 规范、测试环境禁止阻塞交互输入、`bun run check` + `bun test` 门禁与发布更新规范。 | -| [`rules/typescript-style.md`](./rules/typescript-style.md) | `src/**/*.ts` | ES Modules、强制携带 `.js` 后缀、Zod 运行时校验与代码规范。 | - ---- - -## 4. Usage Instructions for AI Agents - -- **Production Operations**: Always consult [`rules/production-safety.md`](./rules/production-safety.md) and [`rules/tenant-and-credential.md`](./rules/tenant-and-credential.md) before interacting with configured enterprise tenants. -- **CLI Development**: When adding or refactoring CLI commands under `src/cli/`, consult [`rules/cli-protocol.md`](./rules/cli-protocol.md). -- **Writing Tests**: When creating or modifying tests, consult [`rules/testing-and-dev-hygiene.md`](./rules/testing-and-dev-hygiene.md). -- **TypeScript & Modules**: When adding new TypeScript files or resolving local imports, refer to [`rules/typescript-style.md`](./rules/typescript-style.md). diff --git a/.agents/rules/cli-protocol.md b/.agents/rules/cli-protocol.md deleted file mode 100644 index 10265f6..0000000 --- a/.agents/rules/cli-protocol.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -description: "CLI stdout/stderr stream contract, volume explosion protection, and exit codes for hose-use commands" -globs: "src/cli/**/*.ts" -trigger: "manual" ---- - -# CLI 输出流协议与退出码规范 - -在实现或重构 `src/cli/` 下的命令行交互时: - -1. **机器解析通道 (`stdout`)**: - - 数据类命令在 `--json` 模式下,`stdout` 必须仅输出纯净、可解析的 JSON 结构体; - - 严禁将调试日志、进度动画、交互式提示语输出到 `stdout`,确保下游脚本和 Agent Harness 能够直接可靠解析。 - -2. **诊断与引导通道 (`stderr`)**: - - 运行时警告、网络诊断信息以及下一步操作引导(如 `下一步: hose-use ...`)统一写入 `stderr`。 - -3. **大报文体积保护(Volume Explosion Protection)**: - - 默认受 200KB 体积防爆限制,防止海量单据明细一次性撑爆上下文; - - 提示并支持通过 `--limit` 分页、`--output-file / -o` 直接落盘至本地文件,或通过 `--mine` 筛选关键子集。 - -4. **退出码规范**: - - 正常执行成功退出码为 `0`; - - 语法错误、参数缺失、上游 API 报错退出码为非 0(如 `1`); - - 写操作未确认拦截退出码为 `10`(`MutationConfirmationRequired`); - - 不要在领域代码深处直接调用 `process.exit()`,应抛出带有结构化语义的错误,由外层统一捕获和分配退出码。 diff --git a/.agents/rules/production-safety.md b/.agents/rules/production-safety.md deleted file mode 100644 index 7e8a89c..0000000 --- a/.agents/rules/production-safety.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -description: "生产环境安全红线、免读源码(Zero Source-Reading)与写操作防护原则" -globs: "**/*" -trigger: "manual" ---- - -# 生产环境安全与行为红线 - -在操作、排错或开发 `hose-use` 时,必须严格恪守以下生产安全与操作红线: - -1. **生产环境安全第一(Production Safety First)**: - - 企业租户(如“转转正式”、“钰泰半导体”等)多为生产真实业务环境,**严禁**未经用户明确确认擅自执行写操作(包括但不限于单据同意、驳回、转交、前/后加签、费用类型修改/停用、数据记录编辑等)。 - - 单据检索与排障默认仅使用只读查询(如 `probe`、`task submitted`、`bill list --mine`、`bill get`、`bill flow` 等)。 - -2. **零源码翻阅自省(Zero Source-Reading)**: - - **严禁翻阅用户的本地配置文件、凭证快照(如 `~/.config/hose-use/enterprises/*.json`、`seal_tokens.json`)、SQLite 数据库或源码目录来探查企业和员工信息**。 - - 探查配置与上下文必须统一使用标准 CLI 命令(如 `hose-use context`、`hose-use corps list`、`hose-use probe`)。 - -3. **两阶段确认与写操作防护**: - - 所有写操作必须严格遵循两阶段确认机制: - - 第一阶段:使用 `--dry-run` 预览操作目标与变更明细; - - 第二阶段:经用户明确确认后,追加 `--yes`(或 `--confirm`)执行写入。 - - 导入链接若检测到目标企业已存在,必须在第一阶段提示中直接给出带有 `--overwrite` 的命令,杜绝二次报错阻断。 - -4. **敏感信息与凭证脱敏**: - - 严禁将明文密码、`appSecurity`、完整 `accessToken`、会话 Cookie 或第三方授权直链打印到公共日志、提交到代码仓库或在回复中裸露传播。 - - CLI 默认输出必须进行严格掩码脱敏。 diff --git a/.agents/rules/tenant-and-credential.md b/.agents/rules/tenant-and-credential.md deleted file mode 100644 index 7f048a2..0000000 --- a/.agents/rules/tenant-and-credential.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -description: "多租户凭据管理、合思免密/协助链接导入与个人单据检索最佳实践" -globs: "src/{domains,core,cli}/**/*.{ts,md}" -trigger: "manual" ---- - -# 租户凭据与业务操作最佳实践 - -1. **同等凭据原则(Equal Credential Scope Principle)**: - - 合思第三方免密/协助链接 (`https://.../web/thirdparty.html?...`) 与在合思管理员后台抓取的 cURL 在凭据范围上等价,均携带完整的 Web 前台会话权限(`accessToken` / `ekbCorpId`)。 - - 面对协助链接或 cURL 时,可通过 `corps add-link ` 直接导入或更新租户。 - -2. **协助链接导入与覆盖(add-link)**: - - 导入协助链接时,系统会自动预解析 `ekbCorpId` 与 JWT Session。 - - 若本地已存在该企业配置,必须显式追加 `--overwrite` 参数(如 `hose-use corps add-link --overwrite --yes`)。 - -3. **单据查询的业务分流与避坑**: - - **查“我的单据” / 当前员工发起的单据**: - - 优先使用 `hose-use task submitted` 或 `hose-use bill list --mine`; - - 响应速度为秒级,包含完整表单明细、提交时间、审批状态与金额。 - - **查“待办任务”**: - - 使用 `hose-use task todo`,支持分页与节点状态查看。 - - **全局发票大盘(`bill list`)**: - - 底层调用全量账表接口 `/api/v2/invoice/search`;在像转转这样的大企业或发票量级巨大的租户中耗时较长,避免在无过滤条件时频繁调用;遇超时应引导使用轻量化的 `task submitted` / `bill list --mine`。 diff --git a/.agents/rules/testing-and-dev-hygiene.md b/.agents/rules/testing-and-dev-hygiene.md deleted file mode 100644 index 6517088..0000000 --- a/.agents/rules/testing-and-dev-hygiene.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -description: "测试套件规范、非交互环境防护与版本发布更新全流程" -globs: "{src,scripts}/**/*.test.ts" -trigger: "manual" ---- - -# 测试与开发发布流程规范 - -1. **测试框架与单测编写**: - - 统一采用 `bun:test`(`describe`, `test`, `it`, `expect`); - - 测试文件与被测模块同级存放,命名为 `*.test.ts`; - - 测试若修改了 `process.env` 或全局状态,必须在 `afterEach()` 中完成自愈清理。 - -2. **非交互测试环境防挂起**: - - 包含终端输入提示(`prompt()` / `readline`)的命令逻辑中,必须加入 `process.env.NODE_ENV === "test"` 或 `process.env.CI` 保护,在单测环境下直接抛出确认错误,绝对禁止阻塞等待 stdin。 - -3. **提交前双重门禁验收**: - - 任何代码改动在提交前必须 100% 通过以下检查: - ```bash - bun run check # tsc --noEmit 静态类型检查零错误 - bun test # 完整测试套件全部通过 - ``` - -4. **版本发布与全局更新标准流程**: - - 若涉及功能增强、Bug 修复或结构变更: - 1. 运行 `bun run bump patch`(或 minor)同步各文件版本号并重建 bundles; - 2. 运行 `bun run check:version` 确认版本严格一致; - 3. 创建特性分支并提交 PR,合入 `main` 主分支; - 4. 双远端同步:推送 `main` 分支至 GitHub (`origin`) 与内部镜像 (`home`); - 5. 打正式发布 Tag(如 `v0.8.7`)并推送到双远端; - 6. 运行 `bun run dev:override` 重新构建本机全局二进制(`/opt/homebrew/bin/hose-use`)并同步 Agent Skill(`~/.agents/skills/hose-use`)。 diff --git a/.agents/rules/typescript-style.md b/.agents/rules/typescript-style.md deleted file mode 100644 index f48f14e..0000000 --- a/.agents/rules/typescript-style.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -description: "TypeScript and ESM coding conventions for hose-use codebase" -globs: "src/**/*.ts" -trigger: "manual" ---- - -# TypeScript & ESM Conventions - -When modifying or adding TypeScript files in `src/`: - -1. **Module System & Import Extensions**: - - Use ES modules exclusively (`"type": "module"` in `package.json`). - - Local file imports MUST include explicit `.js` extensions (e.g. `import { getGlobalDb } from "../db/connection.js"`). - - Do NOT omit the `.js` extension, or runtime Node/Bun ESM resolution will fail. - -2. **Validation & Typing**: - - Validate external inputs, environment variables, and external HTTP/JSON responses using Zod schemas or strictly typed models. - - Avoid `any`. Prefer precise domain types defined in `src/domains/*/types.ts` or `src/types.ts`. - - Never suppress type errors with `// @ts-ignore`; resolve type discrepancies cleanly. - -3. **Code Style & Formatting**: - - 2-space indentation. - - Double quotes (`"`). - - `camelCase` for functions and variables, `PascalCase` for classes, types, and interfaces. - - Kebab-case filenames (e.g. `query-options.ts`, `task-service.ts`). - -4. **Architecture & Separation of Concerns**: - - `src/core/`: Database (SQLite), HTTP client factory, encryption, global configuration, logger. - - `src/domains/`: Domain services, models, and business logic (e.g. `bill`, `corps`, `task`, `workflow`, `key-center`). - - `src/cli/`: Command-line definitions, option parsing, user feedback, table rendering, exit handling. - - Keep domain services independent of CLI formatting. diff --git a/.agents/skills.json b/.agents/skills.json deleted file mode 100644 index 466ffab..0000000 --- a/.agents/skills.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "entries": [ - { - "path": "~/.agents/skills", - "exclude": [ - "^\\..*", - ".*-(deprecated|draft|backup|bak|old|test|tmp)$", - "^lark.*", - "^dingtalk.*", - "^dws.*", - "^seal.*", - "^yingqing.*" - ] - } - ] -} diff --git a/.gitignore b/.gitignore index 891383c..7ba29a8 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ data/ # Local roadmaps & scratch notes *.local.md +.agents/ +