diff --git a/scripts/build-binary.mjs b/scripts/build-binary.mjs index a159fcc..c13d09b 100644 --- a/scripts/build-binary.mjs +++ b/scripts/build-binary.mjs @@ -85,6 +85,13 @@ function getBuildInfo(releaseMode) { async function main() { const startTime = Date.now(); + const generatedSkill = spawnSync(bun, [resolve(root, "scripts/generate-embedded-skill.mjs")], { + cwd: root, + stdio: "inherit" + }); + if (generatedSkill.status !== 0) { + throw new Error("Failed to generate embedded skill manifest"); + } const buildInfo = getBuildInfo(isRelease); console.log(`[build:binary] version: ${buildInfo.version} (${buildInfo.channel}, isRelease: ${buildInfo.isRelease})`); diff --git a/scripts/generate-embedded-skill.mjs b/scripts/generate-embedded-skill.mjs new file mode 100644 index 0000000..cee1527 --- /dev/null +++ b/scripts/generate-embedded-skill.mjs @@ -0,0 +1,52 @@ +import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; +import { dirname, extname, relative, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const skillRoot = resolve(root, "skills", "seal-use"); +const output = resolve(root, "src", "core", "embedded-skill.generated.ts"); +const textExtensions = new Set([".md", ".yaml", ".yml", ".json", ".txt"]); + +function walk(dir) { + const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)); + const files = []; + for (const entry of entries) { + const fullPath = resolve(dir, entry.name); + if (entry.isDirectory()) files.push(...walk(fullPath)); + else if (entry.isFile()) files.push(fullPath); + } + return files; +} + +const files = walk(skillRoot).map((fullPath) => ({ + fullPath, + relativePath: relative(skillRoot, fullPath).split("\\").join("/"), + importPath: relative(resolve(root, "src", "core"), fullPath).split("\\").join("/"), + kind: textExtensions.has(extname(fullPath).toLowerCase()) ? "text" : "asset" +})); + +const lines = [ + "// Generated by scripts/generate-embedded-skill.mjs. Do not edit manually.", + "" +]; + +for (const [index, file] of files.entries()) { + const importType = file.kind === "text" ? "text" : "file"; + lines.push(`import file${index} from ${JSON.stringify(file.importPath)} with { type: ${JSON.stringify(importType)} };`); +} + +lines.push("", "export const EMBEDDED_SKILL_TEXT_FILES: Record = {"); +for (const [index, file] of files.entries()) { + if (file.kind === "text") lines.push(` ${JSON.stringify(file.relativePath)}: file${index},`); +} +lines.push("};", "", "export const EMBEDDED_SKILL_ASSET_PATHS: Record = {"); +for (const [index, file] of files.entries()) { + if (file.kind === "asset") lines.push(` ${JSON.stringify(file.relativePath)}: file${index},`); +} +lines.push("};", "", "export const EMBEDDED_SKILL_ALL_PATHS = ["); +for (const file of files) lines.push(` ${JSON.stringify(file.relativePath)},`); +lines.push("];", ""); + +const content = lines.join("\n"); +const previous = existsSync(output) ? readFileSync(output, "utf8").replace(/\r\n/g, "\n") : ""; +if (previous !== content) writeFileSync(output, content, "utf8"); diff --git a/skills/seal-use/SKILL.md b/skills/seal-use/SKILL.md index 905ba7f..7cf04ba 100644 --- a/skills/seal-use/SKILL.md +++ b/skills/seal-use/SKILL.md @@ -51,7 +51,7 @@ seal-use corps list - Treat CLI/MCP as the Agent's execution channel, not the user's interface. Translate natural-language intent into commands yourself; never ask the user to compose CLI syntax, JSON payloads, placeholder values, or internal IDs. - Before asking for enterprise parameters, resolve the target enterprise: when an enterprise is named, hinted, or keyword-identifiable, ALWAYS run `seal-use corps search ` (or `seal-use corps get ` if an exact ID is known) — DO NOT dump the entire enterprise catalog with `seal-use corps list` when the target is already known. Only run `seal-use corps list` (or `corps list --env `) for initial discovery when zero enterprise context is known. Resolve its human name to the returned `id` and pass that value as `--corp`; do not ask the user to know `corpId`. Use `seal-use corps get ` to inspect rich enterprise attributes (URLs, tenant slugs, staff IDs, environment relations, and config file locations) with sensitive secrets safely redacted. -- If no enterprise is configured, the user is installing for the first time, or the user provides credentials, an assistance link, or a browser-copied cURL, read `references/enterprise-onboarding.md` before asking questions or running setup commands. +- If no enterprise is configured, the user is installing for the first time, or the user provides credentials, an assistance link, or a browser-copied cURL, read `references/first-time-user.md` for the plain-language, screenshot-based path first, then read `references/enterprise-onboarding.md` before asking questions or running setup commands. - When the user provides a Hose/合思 `thirdparty.html` assistance link, use `seal-use corps add-link [--name ...]` for temporary session access, or elevate privileges to permanent developer credentials using `seal-use corps extract-keys --save` (or `seal-use corps add-link --as-hose`). This Hose-exclusive capability extracts `appKey`/`appSecurity`. If the enterprise has multiple keys, specify `--app-key ` or `--key-id `. - **同等凭据原则(Equal Credential Scope Principle)**: A Hose assistance link and a cURL copied from an authenticated **Hose admin** page are both Hose web frontend sessions — structurally different in format only, carrying the same `accesstoken`/`corpid` web session credentials. **When a Hose administrator provides a browser cURL, do NOT silently downgrade it to a plain short-lived session import.** Attempt privilege elevation first by extracting `accesstoken`+`corpid`+`baseUrl` from the cURL and invoking the Hose key interface (`/api/innerapi/v1/key`) to retrieve permanent `appKey`/`appSecurity`. Only fall back to temporary session import if the user is not a Hose administrator or the key interface returns no keys. - Keep enterprise identity origin separate from credential acquisition. A Hose/合思-sourced Seal tenant can be accessed with standard Hose app credentials, an assistance link, or a captured web session; receiving a Seal Bearer token does not by itself prove the tenant is Seal-native. Calling key extraction or `keys` on native Seal enterprises is strictly blocked. @@ -89,7 +89,7 @@ seal-use corps list ## Route By Intent - 生产规则安全演进、搭配配置与测试模拟闭环: read `references/staging-simulation-workflow.md`. 适用于:用户提出规则变更需求/客诉修复、生产与测试企业搭配接入与 1 对 1 绑定、生产环境仅改草稿隔离风险、`seal-use corps sync-test` 一键同步测试环境(含合思集成免配同步)、测试靶场运行自动化规则回归测试矩阵(`test regression`)或真实单据模拟验证、验证通过后才在生产正式发布的完整安全生命周期。 -- First install / zero configuration / “how do I connect my enterprise?” / user supplies app credentials, an assistance link, or F12/Network cURL: read `references/enterprise-onboarding.md`. Ask what material the user already has in plain language, then discover all remaining identifiers automatically. +- First install / zero configuration / “how do I connect my enterprise?” / user supplies app credentials, an assistance link, or F12/Network cURL: read `references/first-time-user.md` and `references/enterprise-onboarding.md`. Ask what material the user already has in plain language, then discover all remaining identifiers automatically. - User-facing Seal tenant assistance link (Seal 协助/Seal 授权/委托): resolve the named enterprise first, then run `seal-use delegation create --corp --note ''`; verify the returned hostname is that tenant's Seal hostname. Always provide BOTH a code block (` ```text ... ``` `) AND a hyperlink. - Packaged customer feedback → approval-rule remediation: read `references/customer-feedback-rule-remediation.md`. Use this route for WeChat messages, screenshots, rejection notifications, document numbers, customer complaints, expected approval behavior, rule-only mitigation, exact diffs, or requests to update and publish a rule version. - 自动化规则回归测试矩阵 (Automated Rule Regression Test Matrix): `seal-use test regression [--corp ] [--samples ] [--dry-run] [--fail-on-flips] [--prod-corp ] [--test-corp ]` (快捷别名 `seal-use corps regression`)。采样生产企业历史已完成单据,通过出站 HTTPS 轮询重放到配对测试靶场执行 AI 审核并对比双端决策,计算一致率(Concordance Rate),识别决策翻转(Decision Flips),给出 `safeToPublish` 综合判定。硬性红线:目标环境必须为测试企业且测试点数余额充足,严禁在纯生产环境发起。 @@ -193,6 +193,7 @@ seal-use tool seal_approval_search --corp --json '{"keywords":["差旅" ## References +- `references/first-time-user.md`: 面向完全新手的首次接入图文说明,包含合思开放接口密钥和浏览器 cURL 两条路径;配套图片在同级 `assets/` 目录。 - `references/enterprise-onboarding.md`: 首次安装、零配置、合思来源与 Seal 原生来源的区分、标准密钥/协助链接/F12 cURL 接入、参数责任与安全边界。 - `references/approval-run-lightweight.md`: 单号定位、字段裁剪、摘要、引用规则、单据摘要、附件摘要。 - `references/rule-lightweight.md`: 规则 count/list summary、按版本/编号取单条规则、规则搜索裁剪。 diff --git a/skills/seal-use/assets/hose-curl-copy-as-curl.png b/skills/seal-use/assets/hose-curl-copy-as-curl.png new file mode 100644 index 0000000..bf3d410 Binary files /dev/null and b/skills/seal-use/assets/hose-curl-copy-as-curl.png differ diff --git a/skills/seal-use/assets/hose-curl-network-fetch-xhr.png b/skills/seal-use/assets/hose-curl-network-fetch-xhr.png new file mode 100644 index 0000000..5c5a0d2 Binary files /dev/null and b/skills/seal-use/assets/hose-curl-network-fetch-xhr.png differ diff --git a/skills/seal-use/assets/hose-curl-open-page-check.png b/skills/seal-use/assets/hose-curl-open-page-check.png new file mode 100644 index 0000000..d07763b Binary files /dev/null and b/skills/seal-use/assets/hose-curl-open-page-check.png differ diff --git a/skills/seal-use/references/first-time-user.md b/skills/seal-use/references/first-time-user.md new file mode 100644 index 0000000..cd253c7 --- /dev/null +++ b/skills/seal-use/references/first-time-user.md @@ -0,0 +1,82 @@ +# 第一次接入:看图找到材料 + +这份说明给第一次使用 Seal Use、还不熟悉“合思”“Seal”“appKey”“cURL”等词的用户。 + +用户不需要先知道 `corpId`、`staffId`、域名或内部命令。只要能进入企业网页,助手会负责识别企业和接入方式。 + +## 路径一:从合思开放接口取得接入账号和接入密码 + +这条路径适用于有合思开放平台或应用管理权限的用户。 + +在合思网页中依次完成: + +1. 打开「应用中心」或「应用商店」。 +2. 搜索“接口”。 +3. 进入「开放接口(新)」。 +4. 点击「商品配置」。 +5. 在配置面板中找到: + - **接入账号**:这就是 `appKey`。 + - **接入密码**:这就是 `appSecurity`。需要先点击「显示」再复制。 +6. 将这两项只交给当前本地助手,不要发到群聊、工单、公共文档或代码仓库。 + +![在应用中心搜索并进入开放接口](../assets/hose-open-platform-app-center.png) + +![进入开放接口后点击商品配置](../assets/hose-open-platform-product-config.png) + +![在商品配置中找到接入账号和接入密码](../assets/hose-open-platform-credentials.png) + +助手拿到这两项后,会自动探测合思环境、识别企业、发现管理员绑定,并验证 Seal 会话。用户不需要填写 `corpId`、`staffId` 或域名。 + +## 路径二:从已经登录的网页复制 cURL + +如果用户没有开放平台权限,或者是通过客户协助平台、SSO、普通网页登录、嵌入式页面等方式进入了目标企业网页,可以直接从当前网页复制一条成功的业务请求。 + +这条路径不要求用户理解 cURL。用户只需要把浏览器复制出来的完整文本交给本地助手。 + +### 1. 打开开发者工具 + +在目标企业网页中右键,选择「检查」。 + +macOS 也可以使用 `Option + Command + I`;Windows 常见快捷键是 `F12` 或 `Ctrl + Shift + I`。 + +![在已登录的企业网页中打开检查](../assets/hose-curl-open-page-check.png) + +### 2. 进入网络请求列表 + +在开发者工具中: + +1. 打开「网络」标签。 +2. 选择「Fetch/XHR」。 +3. 刷新网页,或执行一次普通的只读操作,例如打开待办、单据列表或审批记录。 +4. 等待请求列表出现。 + +![在开发者工具中选择网络和 Fetch/XHR](../assets/hose-curl-network-fetch-xhr.png) + +### 3. 复制一条成功的业务请求 + +在请求列表中选择一条成功的业务请求,右键依次选择: + +> 复制 → 以 cURL 格式复制 + +![右键请求并选择以 cURL 格式复制](../assets/hose-curl-copy-as-curl.png) + +优先选择普通查询或列表请求。不要选择静态文件、埋点分析、上传、删除、发布、退出登录等请求。 + +把复制出来的完整 cURL 只交给当前本地助手。它包含当前网页会话信息,应按密码处理,不能粘贴到群聊、工单、公共文档、代码仓库或截图中。 + +### 助手收到 cURL 后会做什么 + +助手会先判断这条请求来自合思网页还是 Seal 网页: + +- **合思网页**:读取请求主机、会话令牌和企业标识。若当前登录人具备管理员权限,优先尝试把短期网页会话提升为长期 OpenAPI 凭据;否则导入为临时会话。 +- **Seal 网页**:读取 Seal 主机和 Bearer 会话,验证当前租户和用户身份。 + +这些步骤由助手完成,用户不需要从 cURL 中手动寻找 token、企业 ID 或员工 ID。 + +## 如果看不到请求 + +先确认已经选中「网络」和「Fetch/XHR」,然后刷新网页或打开一个普通业务列表。不要把空白的开发者工具截图当作接入材料;需要复制一条实际成功的请求。 + +## 安全提醒 + +协助平台、网页登录、SSO 和浏览器 cURL 都可能携带当前用户的访问权限。只把材料交给正在处理本机接入的可信助手,并在接入完成后关闭或刷新该网页会话。不要把原始 cURL、接入密码或完整截图发送到外部渠道。 diff --git a/src/assets.d.ts b/src/assets.d.ts new file mode 100644 index 0000000..9fd6ab6 --- /dev/null +++ b/src/assets.d.ts @@ -0,0 +1,4 @@ +declare module "*.png" { + const path: string; + export default path; +} diff --git a/src/core/embedded-skill.generated.ts b/src/core/embedded-skill.generated.ts new file mode 100644 index 0000000..0a66ab0 --- /dev/null +++ b/src/core/embedded-skill.generated.ts @@ -0,0 +1,74 @@ +// Generated by scripts/generate-embedded-skill.mjs. Do not edit manually. + +import file0 from "../../skills/seal-use/agents/openai.yaml" with { type: "text" }; +import file1 from "../../skills/seal-use/assets/hose-curl-copy-as-curl.png" with { type: "file" }; +import file2 from "../../skills/seal-use/assets/hose-curl-network-fetch-xhr.png" with { type: "file" }; +import file3 from "../../skills/seal-use/assets/hose-curl-open-page-check.png" with { type: "file" }; +import file4 from "../../skills/seal-use/assets/hose-open-platform-app-center.png" with { type: "file" }; +import file5 from "../../skills/seal-use/assets/hose-open-platform-credentials.png" with { type: "file" }; +import file6 from "../../skills/seal-use/assets/hose-open-platform-product-config.png" with { type: "file" }; +import file7 from "../../skills/seal-use/references/approval-attachment-trace.md" with { type: "text" }; +import file8 from "../../skills/seal-use/references/approval-bad-cases.md" with { type: "text" }; +import file9 from "../../skills/seal-use/references/approval-run-lightweight.md" with { type: "text" }; +import file10 from "../../skills/seal-use/references/cli.md" with { type: "text" }; +import file11 from "../../skills/seal-use/references/customer-feedback-rule-remediation.md" with { type: "text" }; +import file12 from "../../skills/seal-use/references/enterprise-onboarding.md" with { type: "text" }; +import file13 from "../../skills/seal-use/references/first-time-user.md" with { type: "text" }; +import file14 from "../../skills/seal-use/references/hose-enterprise-auth.md" with { type: "text" }; +import file15 from "../../skills/seal-use/references/hose-enterprise-deploy.md" with { type: "text" }; +import file16 from "../../skills/seal-use/references/hose-enterprise-init.md" with { type: "text" }; +import file17 from "../../skills/seal-use/references/rule-lightweight.md" with { type: "text" }; +import file18 from "../../skills/seal-use/references/rule-lint.md" with { type: "text" }; +import file19 from "../../skills/seal-use/references/staging-simulation-workflow.md" with { type: "text" }; +import file20 from "../../skills/seal-use/SKILL.md" with { type: "text" }; + +export const EMBEDDED_SKILL_TEXT_FILES: Record = { + "agents/openai.yaml": file0, + "references/approval-attachment-trace.md": file7, + "references/approval-bad-cases.md": file8, + "references/approval-run-lightweight.md": file9, + "references/cli.md": file10, + "references/customer-feedback-rule-remediation.md": file11, + "references/enterprise-onboarding.md": file12, + "references/first-time-user.md": file13, + "references/hose-enterprise-auth.md": file14, + "references/hose-enterprise-deploy.md": file15, + "references/hose-enterprise-init.md": file16, + "references/rule-lightweight.md": file17, + "references/rule-lint.md": file18, + "references/staging-simulation-workflow.md": file19, + "SKILL.md": file20, +}; + +export const EMBEDDED_SKILL_ASSET_PATHS: Record = { + "assets/hose-curl-copy-as-curl.png": file1, + "assets/hose-curl-network-fetch-xhr.png": file2, + "assets/hose-curl-open-page-check.png": file3, + "assets/hose-open-platform-app-center.png": file4, + "assets/hose-open-platform-credentials.png": file5, + "assets/hose-open-platform-product-config.png": file6, +}; + +export const EMBEDDED_SKILL_ALL_PATHS = [ + "agents/openai.yaml", + "assets/hose-curl-copy-as-curl.png", + "assets/hose-curl-network-fetch-xhr.png", + "assets/hose-curl-open-page-check.png", + "assets/hose-open-platform-app-center.png", + "assets/hose-open-platform-credentials.png", + "assets/hose-open-platform-product-config.png", + "references/approval-attachment-trace.md", + "references/approval-bad-cases.md", + "references/approval-run-lightweight.md", + "references/cli.md", + "references/customer-feedback-rule-remediation.md", + "references/enterprise-onboarding.md", + "references/first-time-user.md", + "references/hose-enterprise-auth.md", + "references/hose-enterprise-deploy.md", + "references/hose-enterprise-init.md", + "references/rule-lightweight.md", + "references/rule-lint.md", + "references/staging-simulation-workflow.md", + "SKILL.md", +]; diff --git a/src/core/embedded-skill.test.ts b/src/core/embedded-skill.test.ts index 578eef1..1387610 100644 --- a/src/core/embedded-skill.test.ts +++ b/src/core/embedded-skill.test.ts @@ -4,6 +4,8 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import packageJson from "../../package.json" with { type: "json" }; import { + EMBEDDED_SKILL_ALL_PATHS, + EMBEDDED_SKILL_ASSETS, EMBEDDED_SKILL_FILES, EMBEDDED_SKILL_VERSION, getSkillContent, @@ -18,6 +20,9 @@ describe("embedded-skill", () => { expect(EMBEDDED_SKILL_FILES["SKILL.md"]).toContain("name: seal-use"); expect(EMBEDDED_SKILL_FILES["references/cli.md"]).toBeDefined(); expect(EMBEDDED_SKILL_FILES["references/enterprise-onboarding.md"]).toContain("# Enterprise Onboarding"); + expect(EMBEDDED_SKILL_FILES["references/first-time-user.md"]).toContain("复制 → 以 cURL 格式复制"); + expect(EMBEDDED_SKILL_ASSETS["assets/hose-curl-copy-as-curl.png"]).toBeDefined(); + expect(EMBEDDED_SKILL_ALL_PATHS).toContain("assets/hose-curl-copy-as-curl.png"); expect(getSkillContent()).toContain("name: seal-use"); }); @@ -30,6 +35,8 @@ describe("embedded-skill", () => { expect(existsSync(join(tmp, "SKILL.md"))).toBe(true); expect(existsSync(join(tmp, "references", "cli.md"))).toBe(true); expect(existsSync(join(tmp, "references", "enterprise-onboarding.md"))).toBe(true); + expect(existsSync(join(tmp, "references", "first-time-user.md"))).toBe(true); + expect(existsSync(join(tmp, "assets", "hose-curl-copy-as-curl.png"))).toBe(true); } finally { rmSync(tmp, { recursive: true, force: true }); } diff --git a/src/core/embedded-skill.ts b/src/core/embedded-skill.ts index 0bbb7d9..b7770f5 100644 --- a/src/core/embedded-skill.ts +++ b/src/core/embedded-skill.ts @@ -2,31 +2,17 @@ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node import { homedir } from "node:os"; import { dirname, join } from "node:path"; -import skillMain from "../../skills/seal-use/SKILL.md" with { type: "text" }; -import agentOpenAi from "../../skills/seal-use/agents/openai.yaml" with { type: "text" }; -import refRuleLightweight from "../../skills/seal-use/references/rule-lightweight.md" with { type: "text" }; -import refApprovalBadCases from "../../skills/seal-use/references/approval-bad-cases.md" with { type: "text" }; -import refCli from "../../skills/seal-use/references/cli.md" with { type: "text" }; -import refApprovalRunLightweight from "../../skills/seal-use/references/approval-run-lightweight.md" with { type: "text" }; -import refApprovalAttachmentTrace from "../../skills/seal-use/references/approval-attachment-trace.md" with { type: "text" }; -import refCustomerFeedbackRuleRemediation from "../../skills/seal-use/references/customer-feedback-rule-remediation.md" with { type: "text" }; -import refEnterpriseOnboarding from "../../skills/seal-use/references/enterprise-onboarding.md" with { type: "text" }; -import refHoseEnterpriseAuth from "../../skills/seal-use/references/hose-enterprise-auth.md" with { type: "text" }; -import refHoseEnterpriseInit from "../../skills/seal-use/references/hose-enterprise-init.md" with { type: "text" }; +import { + EMBEDDED_SKILL_ASSET_PATHS, + EMBEDDED_SKILL_TEXT_FILES +} from "./embedded-skill.generated.js"; -export const EMBEDDED_SKILL_FILES: Record = { - "SKILL.md": skillMain, - "agents/openai.yaml": agentOpenAi, - "references/rule-lightweight.md": refRuleLightweight, - "references/approval-bad-cases.md": refApprovalBadCases, - "references/cli.md": refCli, - "references/approval-run-lightweight.md": refApprovalRunLightweight, - "references/approval-attachment-trace.md": refApprovalAttachmentTrace, - "references/customer-feedback-rule-remediation.md": refCustomerFeedbackRuleRemediation, - "references/enterprise-onboarding.md": refEnterpriseOnboarding, - "references/hose-enterprise-auth.md": refHoseEnterpriseAuth, - "references/hose-enterprise-init.md": refHoseEnterpriseInit -}; +export { EMBEDDED_SKILL_ALL_PATHS } from "./embedded-skill.generated.js"; + +export const EMBEDDED_SKILL_FILES = EMBEDDED_SKILL_TEXT_FILES; +export const EMBEDDED_SKILL_ASSETS: Record = Object.fromEntries( + Object.entries(EMBEDDED_SKILL_ASSET_PATHS).map(([relPath, filePath]) => [relPath, readFileSync(filePath)]) +); export function getSkillContent(): string { return EMBEDDED_SKILL_FILES["SKILL.md"] || ""; @@ -91,6 +77,13 @@ export function installSkillFiles(targetDir: string = getDefaultGlobalSkillDir() installed.push(relPath); } + for (const [relPath, content] of Object.entries(EMBEDDED_SKILL_ASSETS)) { + const fullPath = join(targetDir, relPath); + mkdirSync(dirname(fullPath), { recursive: true }); + writeFileSync(fullPath, content); + installed.push(relPath); + } + return { targetDir, files: installed