agentlock-harness 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +211 -2
- package/README.zh-CN.md +211 -0
- package/RELEASE_NOTES.md +35 -0
- package/bin/agentlock-harness.mjs +249 -0
- package/harness-templates/en-US/common/CLAUDE.md.tmpl +7 -0
- package/harness-templates/en-US/common/GEMINI.md.tmpl +7 -0
- package/harness-templates/en-US/common/agentlock-harness.json.tmpl +45 -0
- package/harness-templates/en-US/common/claude-settings.json +36 -0
- package/harness-templates/en-US/common/codex-config.toml.tmpl +11 -0
- package/harness-templates/en-US/common/copilot-instructions.md.tmpl +3 -0
- package/harness-templates/en-US/common/gemini-settings.json +42 -0
- package/harness-templates/en-US/common/git-hooks/pre-commit +24 -0
- package/harness-templates/en-US/common/git-hooks/pre-push +11 -0
- package/harness-templates/en-US/common/harness-gitignore +3 -0
- package/harness-templates/en-US/common/hooks/post-edit-check.mjs +57 -0
- package/harness-templates/en-US/common/hooks/pre-tool-guard.mjs +122 -0
- package/harness-templates/en-US/common/hooks/rules-drift-check.mjs +69 -0
- package/harness-templates/en-US/common/hooks/staged-guard.mjs +197 -0
- package/harness-templates/en-US/common/hooks/stop-gate.mjs +164 -0
- package/harness-templates/en-US/common/rules/00-testing-integrity.md +11 -0
- package/harness-templates/en-US/common/rules/01-security-boundaries.md +11 -0
- package/harness-templates/en-US/common/skills/atomic-tdd/SKILL.md +21 -0
- package/harness-templates/en-US/common/skills/brainstorming/SKILL.md +24 -0
- package/harness-templates/en-US/common/skills/code-grounding/SKILL.md +20 -0
- package/harness-templates/en-US/common/skills/cross-model-review/SKILL.md +22 -0
- package/harness-templates/en-US/common/skills/worktree-isolation/SKILL.md +19 -0
- package/harness-templates/en-US/dual-core/HARNESS_GUIDE.md +19 -0
- package/harness-templates/en-US/dual-core/scripts/cross-review.mjs +141 -0
- package/harness-templates/en-US/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
- package/harness-templates/en-US/enterprise-platform/governance/mcp-gateway.template.json +18 -0
- package/harness-templates/en-US/enterprise-platform/governance/policy.json +26 -0
- package/harness-templates/en-US/ralph-factory/PROMPT.loop.md.tmpl +12 -0
- package/harness-templates/en-US/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
- package/harness-templates/en-US/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
- package/harness-templates/en-US/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
- package/harness-templates/en-US/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
- package/harness-templates/zh-CN/common/CLAUDE.md.tmpl +7 -0
- package/harness-templates/zh-CN/common/GEMINI.md.tmpl +7 -0
- package/harness-templates/zh-CN/common/agentlock-harness.json.tmpl +45 -0
- package/harness-templates/zh-CN/common/claude-settings.json +36 -0
- package/harness-templates/zh-CN/common/codex-config.toml.tmpl +11 -0
- package/harness-templates/zh-CN/common/copilot-instructions.md.tmpl +3 -0
- package/harness-templates/zh-CN/common/gemini-settings.json +42 -0
- package/harness-templates/zh-CN/common/git-hooks/pre-commit +24 -0
- package/harness-templates/zh-CN/common/git-hooks/pre-push +11 -0
- package/harness-templates/zh-CN/common/harness-gitignore +3 -0
- package/harness-templates/zh-CN/common/hooks/post-edit-check.mjs +57 -0
- package/harness-templates/zh-CN/common/hooks/pre-tool-guard.mjs +122 -0
- package/harness-templates/zh-CN/common/hooks/rules-drift-check.mjs +69 -0
- package/harness-templates/zh-CN/common/hooks/staged-guard.mjs +197 -0
- package/harness-templates/zh-CN/common/hooks/stop-gate.mjs +164 -0
- package/harness-templates/zh-CN/common/rules/00-testing-integrity.md +11 -0
- package/harness-templates/zh-CN/common/rules/01-security-boundaries.md +11 -0
- package/harness-templates/zh-CN/common/skills/atomic-tdd/SKILL.md +21 -0
- package/harness-templates/zh-CN/common/skills/brainstorming/SKILL.md +24 -0
- package/harness-templates/zh-CN/common/skills/code-grounding/SKILL.md +20 -0
- package/harness-templates/zh-CN/common/skills/cross-model-review/SKILL.md +22 -0
- package/harness-templates/zh-CN/common/skills/worktree-isolation/SKILL.md +19 -0
- package/harness-templates/zh-CN/dual-core/HARNESS_GUIDE.md +19 -0
- package/harness-templates/zh-CN/dual-core/scripts/cross-review.mjs +141 -0
- package/harness-templates/zh-CN/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
- package/harness-templates/zh-CN/enterprise-platform/governance/mcp-gateway.template.json +18 -0
- package/harness-templates/zh-CN/enterprise-platform/governance/policy.json +26 -0
- package/harness-templates/zh-CN/ralph-factory/PROMPT.loop.md.tmpl +12 -0
- package/harness-templates/zh-CN/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
- package/harness-templates/zh-CN/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
- package/harness-templates/zh-CN/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
- package/harness-templates/zh-CN/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
- package/package.json +64 -4
- package/scripts/bootstrap.ps1 +13 -0
- package/scripts/bootstrap.sh +23 -0
- package/src/cli/colors.mjs +42 -0
- package/src/cli/commands/adopt.mjs +378 -0
- package/src/cli/commands/change.mjs +92 -0
- package/src/cli/commands/doctor.mjs +56 -0
- package/src/cli/commands/eval.mjs +193 -0
- package/src/cli/commands/hooks.mjs +97 -0
- package/src/cli/commands/init.mjs +231 -0
- package/src/cli/commands/passthrough.mjs +27 -0
- package/src/cli/commands/ralph.mjs +208 -0
- package/src/cli/commands/rules.mjs +73 -0
- package/src/cli/commands/stats.mjs +71 -0
- package/src/cli/commands/task.mjs +123 -0
- package/src/cli/commands/ui.mjs +84 -0
- package/src/cli/commands/verify.mjs +267 -0
- package/src/cli/prompt.mjs +55 -0
- package/src/core/adopt.mjs +807 -0
- package/src/core/agent-runner.mjs +118 -0
- package/src/core/audit.mjs +181 -0
- package/src/core/catalog.mjs +160 -0
- package/src/core/change-flow.mjs +344 -0
- package/src/core/detector.mjs +141 -0
- package/src/core/doc-drift.mjs +94 -0
- package/src/core/eval-fixtures.mjs +676 -0
- package/src/core/eval-frontier-fixtures.mjs +657 -0
- package/src/core/eval-hard-fixtures.mjs +923 -0
- package/src/core/eval-runner.mjs +754 -0
- package/src/core/eval-telemetry.mjs +338 -0
- package/src/core/harness-writer.mjs +286 -0
- package/src/core/installer.mjs +42 -0
- package/src/core/rules-compiler.mjs +356 -0
- package/src/core/task-ledger.mjs +327 -0
- package/src/core/version.mjs +10 -0
- package/src/ui/public/app.mjs +2199 -0
- package/src/ui/public/index.html +203 -0
- package/src/ui/public/styles.css +1200 -0
- package/src/ui/server.mjs +457 -0
- package/src/ui/service.mjs +860 -0
- package/templates/en-US/AGENTS.md +38 -0
- package/templates/en-US/DOCS_MAINTENANCE.md +65 -0
- package/templates/en-US/MIGRATION.md +46 -0
- package/templates/en-US/NEW_PROJECT_CHECKLIST.md +46 -0
- package/templates/en-US/README.md +41 -0
- package/templates/en-US/SESSION.md +29 -0
- package/templates/en-US/docs/00-context.md +38 -0
- package/templates/en-US/docs/01-vision/README.md +36 -0
- package/templates/en-US/docs/02-requirements/PRD.md +24 -0
- package/templates/en-US/docs/02-requirements/glossary.md +20 -0
- package/templates/en-US/docs/02-requirements/use-cases.md +36 -0
- package/templates/en-US/docs/03-architecture/composite-ai-framework.md +36 -0
- package/templates/en-US/docs/03-architecture/integration-architecture.md +36 -0
- package/templates/en-US/docs/03-architecture/system-architecture.md +16 -0
- package/templates/en-US/docs/04-design/README.md +21 -0
- package/templates/en-US/docs/04-design/a2a-integration-spec.md +36 -0
- package/templates/en-US/docs/04-design/agent-specs.md +36 -0
- package/templates/en-US/docs/04-design/data-model.md +18 -0
- package/templates/en-US/docs/04-design/external-api-spec.md +26 -0
- package/templates/en-US/docs/04-design/mcp-interface-spec.md +36 -0
- package/templates/en-US/docs/04-design/phase1-minimal-implementation-interfaces.md +36 -0
- package/templates/en-US/docs/04-design/responsibility-model.md +36 -0
- package/templates/en-US/docs/04-design/runtime-control-plane-spec.md +36 -0
- package/templates/en-US/docs/04-design/safety-governance.md +18 -0
- package/templates/en-US/docs/04-design/sample-scenarios-architecture-refinement.md +20 -0
- package/templates/en-US/docs/04-design/skill-syntax-spec.md +36 -0
- package/templates/en-US/docs/04-design/storage-schema.md +18 -0
- package/templates/en-US/docs/04-design/task-capability-architecture-and-evolution.md +36 -0
- package/templates/en-US/docs/05-project/adr/ADR-000-template.md +32 -0
- package/templates/en-US/docs/05-project/adr/README.md +15 -0
- package/templates/en-US/docs/05-project/doc-code-map.md +17 -0
- package/templates/en-US/docs/05-project/evolution-backlog.md +14 -0
- package/templates/en-US/docs/05-project/feature-registry.md +16 -0
- package/templates/en-US/docs/05-project/master-delivery-tracker.md +14 -0
- package/templates/en-US/docs/05-project/risk-register.md +36 -0
- package/templates/en-US/docs/05-project/roadmap.md +36 -0
- package/templates/en-US/docs/05-project/stage-view.md +14 -0
- package/templates/en-US/docs/05-project/tech-stack.md +36 -0
- package/templates/en-US/docs/06-dev-guide/SPEC.md +18 -0
- package/templates/en-US/docs/06-dev-guide/coding-standards.md +36 -0
- package/templates/en-US/docs/06-dev-guide/deployment-architecture.md +20 -0
- package/templates/en-US/docs/06-dev-guide/project-scaffold.md +16 -0
- package/templates/en-US/docs/06-dev-guide/testing-strategy.md +42 -0
- package/templates/en-US/docs/07-frontend/README.md +36 -0
- package/templates/en-US/docs/07-frontend/user-personas.md +36 -0
- package/templates/en-US/docs/08-process/README.md +27 -0
- package/templates/en-US/docs/08-process/ai-collaboration-protocol.md +28 -0
- package/templates/en-US/docs/08-process/autopilot.md +18 -0
- package/templates/en-US/docs/08-process/code-grounding.md +32 -0
- package/templates/en-US/docs/08-process/context-loading-strategy.md +35 -0
- package/templates/en-US/docs/08-process/conventions.md +75 -0
- package/templates/en-US/docs/08-process/debugging.md +25 -0
- package/templates/en-US/docs/08-process/design-gate.md +22 -0
- package/templates/en-US/docs/08-process/git-protocol.md +20 -0
- package/templates/en-US/docs/08-process/multi-agent-orchestration.md +27 -0
- package/templates/en-US/docs/08-process/planning.md +18 -0
- package/templates/en-US/docs/08-process/project-intake.md +47 -0
- package/templates/en-US/docs/08-process/reflection.md +18 -0
- package/templates/en-US/docs/08-process/review.md +30 -0
- package/templates/en-US/docs/08-process/session-handoff.md +27 -0
- package/templates/en-US/docs/08-process/tdd.md +24 -0
- package/templates/en-US/docs/08-process/tool-execution.md +32 -0
- package/templates/en-US/docs/08-process/workflow-contract.md +46 -0
- package/templates/en-US/docs/08-process/workflow.md +23 -0
- package/templates/en-US/docs/README.md +58 -0
- package/templates/en-US/docs/design-checklist.md +36 -0
- package/templates/en-US/docs/discussions/README.md +13 -0
- package/templates/en-US/docs/plans/README.md +13 -0
- package/templates/en-US/docs/proposed-design/README.md +13 -0
- package/templates/en-US/docs/temp-reference/README.md +11 -0
- package/templates/en-US/docs.config.json +46 -0
- package/templates/en-US/profiles/README.md +23 -0
- package/templates/en-US/profiles/agent-platform/README.md +23 -0
- package/templates/en-US/profiles/cli-tool/README.md +23 -0
- package/templates/en-US/profiles/library-sdk/README.md +23 -0
- package/templates/en-US/profiles/multi-agent/README.md +23 -0
- package/templates/en-US/profiles/profiles.json +31 -0
- package/templates/en-US/profiles/software-automation/README.md +23 -0
- package/templates/en-US/profiles/web-saas/README.md +23 -0
- package/templates/en-US/scripts/README.md +89 -0
- package/templates/en-US/scripts/doc-find.mjs +156 -0
- package/templates/en-US/scripts/doc-map.mjs +50 -0
- package/templates/en-US/scripts/doc-tools.mjs +311 -0
- package/templates/en-US/scripts/init-docs.mjs +214 -0
- package/templates/en-US/scripts/validate-docs.mjs +141 -0
- package/templates/zh-CN/AGENTS.md +38 -0
- package/templates/zh-CN/DOCS_MAINTENANCE.md +77 -0
- package/templates/zh-CN/MIGRATION.md +45 -0
- package/templates/zh-CN/NEW_PROJECT_CHECKLIST.md +54 -0
- package/templates/zh-CN/README.md +55 -0
- package/templates/zh-CN/SESSION.md +29 -0
- package/templates/zh-CN/docs/00-context.md +42 -0
- package/templates/zh-CN/docs/01-vision/README.md +33 -0
- package/templates/zh-CN/docs/02-requirements/PRD.md +26 -0
- package/templates/zh-CN/docs/02-requirements/glossary.md +35 -0
- package/templates/zh-CN/docs/02-requirements/use-cases.md +31 -0
- package/templates/zh-CN/docs/03-architecture/composite-ai-framework.md +27 -0
- package/templates/zh-CN/docs/03-architecture/integration-architecture.md +30 -0
- package/templates/zh-CN/docs/03-architecture/system-architecture.md +26 -0
- package/templates/zh-CN/docs/04-design/README.md +21 -0
- package/templates/zh-CN/docs/04-design/a2a-integration-spec.md +45 -0
- package/templates/zh-CN/docs/04-design/agent-specs.md +46 -0
- package/templates/zh-CN/docs/04-design/data-model.md +18 -0
- package/templates/zh-CN/docs/04-design/external-api-spec.md +34 -0
- package/templates/zh-CN/docs/04-design/mcp-interface-spec.md +44 -0
- package/templates/zh-CN/docs/04-design/phase1-minimal-implementation-interfaces.md +38 -0
- package/templates/zh-CN/docs/04-design/responsibility-model.md +37 -0
- package/templates/zh-CN/docs/04-design/runtime-control-plane-spec.md +47 -0
- package/templates/zh-CN/docs/04-design/safety-governance.md +18 -0
- package/templates/zh-CN/docs/04-design/sample-scenarios-architecture-refinement.md +38 -0
- package/templates/zh-CN/docs/04-design/skill-syntax-spec.md +43 -0
- package/templates/zh-CN/docs/04-design/storage-schema.md +18 -0
- package/templates/zh-CN/docs/04-design/task-capability-architecture-and-evolution.md +46 -0
- package/templates/zh-CN/docs/05-project/adr/ADR-000-template.md +34 -0
- package/templates/zh-CN/docs/05-project/adr/README.md +35 -0
- package/templates/zh-CN/docs/05-project/doc-code-map.md +19 -0
- package/templates/zh-CN/docs/05-project/evolution-backlog.md +14 -0
- package/templates/zh-CN/docs/05-project/feature-registry.md +16 -0
- package/templates/zh-CN/docs/05-project/master-delivery-tracker.md +14 -0
- package/templates/zh-CN/docs/05-project/risk-register.md +21 -0
- package/templates/zh-CN/docs/05-project/roadmap.md +31 -0
- package/templates/zh-CN/docs/05-project/stage-view.md +14 -0
- package/templates/zh-CN/docs/05-project/tech-stack.md +36 -0
- package/templates/zh-CN/docs/06-dev-guide/SPEC.md +24 -0
- package/templates/zh-CN/docs/06-dev-guide/coding-standards.md +29 -0
- package/templates/zh-CN/docs/06-dev-guide/deployment-architecture.md +22 -0
- package/templates/zh-CN/docs/06-dev-guide/project-scaffold.md +16 -0
- package/templates/zh-CN/docs/06-dev-guide/testing-strategy.md +46 -0
- package/templates/zh-CN/docs/07-frontend/README.md +29 -0
- package/templates/zh-CN/docs/07-frontend/user-personas.md +27 -0
- package/templates/zh-CN/docs/08-process/README.md +29 -0
- package/templates/zh-CN/docs/08-process/ai-collaboration-protocol.md +30 -0
- package/templates/zh-CN/docs/08-process/autopilot.md +18 -0
- package/templates/zh-CN/docs/08-process/code-grounding.md +40 -0
- package/templates/zh-CN/docs/08-process/context-loading-strategy.md +35 -0
- package/templates/zh-CN/docs/08-process/conventions.md +77 -0
- package/templates/zh-CN/docs/08-process/debugging.md +27 -0
- package/templates/zh-CN/docs/08-process/design-gate.md +22 -0
- package/templates/zh-CN/docs/08-process/git-protocol.md +20 -0
- package/templates/zh-CN/docs/08-process/multi-agent-orchestration.md +27 -0
- package/templates/zh-CN/docs/08-process/planning.md +18 -0
- package/templates/zh-CN/docs/08-process/project-intake.md +53 -0
- package/templates/zh-CN/docs/08-process/reflection.md +18 -0
- package/templates/zh-CN/docs/08-process/review.md +30 -0
- package/templates/zh-CN/docs/08-process/session-handoff.md +29 -0
- package/templates/zh-CN/docs/08-process/tdd.md +24 -0
- package/templates/zh-CN/docs/08-process/tool-execution.md +34 -0
- package/templates/zh-CN/docs/08-process/workflow-contract.md +48 -0
- package/templates/zh-CN/docs/08-process/workflow.md +23 -0
- package/templates/zh-CN/docs/README.md +62 -0
- package/templates/zh-CN/docs/design-checklist.md +18 -0
- package/templates/zh-CN/docs/discussions/README.md +36 -0
- package/templates/zh-CN/docs/plans/README.md +15 -0
- package/templates/zh-CN/docs/proposed-design/README.md +41 -0
- package/templates/zh-CN/docs/temp-reference/README.md +13 -0
- package/templates/zh-CN/docs.config.json +46 -0
- package/templates/zh-CN/profiles/README.md +23 -0
- package/templates/zh-CN/profiles/agent-platform/README.md +23 -0
- package/templates/zh-CN/profiles/cli-tool/README.md +23 -0
- package/templates/zh-CN/profiles/library-sdk/README.md +23 -0
- package/templates/zh-CN/profiles/multi-agent/README.md +23 -0
- package/templates/zh-CN/profiles/profiles.json +31 -0
- package/templates/zh-CN/profiles/software-automation/README.md +23 -0
- package/templates/zh-CN/profiles/web-saas/README.md +23 -0
- package/templates/zh-CN/scripts/README.md +97 -0
- package/templates/zh-CN/scripts/doc-find.mjs +156 -0
- package/templates/zh-CN/scripts/doc-map.mjs +50 -0
- package/templates/zh-CN/scripts/doc-tools.mjs +311 -0
- package/templates/zh-CN/scripts/init-docs.mjs +214 -0
- package/templates/zh-CN/scripts/validate-docs.mjs +141 -0
|
@@ -0,0 +1,2199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentLock Harness v3.5.0 — Zero-Dependency Local Web Console Frontend
|
|
3
|
+
*
|
|
4
|
+
* Pure ES Module, zero external packages, zero untrusted innerHTML sinks.
|
|
5
|
+
* Token is extracted once from URL query into closure memory and scrubbed via history.replaceState.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// 1. Extract & scrub one-time session token immediately
|
|
9
|
+
const SESSION_TOKEN = (() => {
|
|
10
|
+
const params = new URLSearchParams(window.location.search);
|
|
11
|
+
const fromUrl = params.get("token");
|
|
12
|
+
if (fromUrl) {
|
|
13
|
+
try {
|
|
14
|
+
sessionStorage.setItem("alh-session-token", fromUrl);
|
|
15
|
+
} catch (_) {}
|
|
16
|
+
window.history.replaceState(null, "", window.location.pathname + window.location.hash);
|
|
17
|
+
return fromUrl;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return sessionStorage.getItem("alh-session-token") || "";
|
|
21
|
+
} catch (_) {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
|
|
26
|
+
// 2. Bilingual I18N dictionary
|
|
27
|
+
const I18N = {
|
|
28
|
+
"zh-CN": {
|
|
29
|
+
"nav.health": "健康度与护栏",
|
|
30
|
+
"nav.onboarding": "向导接入与体检",
|
|
31
|
+
"nav.changes": "Spec 变更与 DAG",
|
|
32
|
+
"nav.eval": "消融评测实验室",
|
|
33
|
+
"theme.system": "自动",
|
|
34
|
+
"theme.light": "浅色",
|
|
35
|
+
"theme.dark": "深色",
|
|
36
|
+
"action.quickVerify": "快速校验",
|
|
37
|
+
"common.cancel": "取消",
|
|
38
|
+
"common.switch": "切换目录",
|
|
39
|
+
"common.create": "创建变更包",
|
|
40
|
+
"common.confirm": "确认执行",
|
|
41
|
+
"common.copy": "复制",
|
|
42
|
+
"common.copied": "已复制",
|
|
43
|
+
"common.cliEquiv": "查看等效 CLI 命令",
|
|
44
|
+
"dialog.workspaceTitle": "切换本地工作区目录",
|
|
45
|
+
"dialog.workspaceDesc": "仅切换当前控制台查看的目标项目路径,绝不会向该目录写入任何 UI 文件。",
|
|
46
|
+
"dialog.workspacePath": "绝对路径",
|
|
47
|
+
"dialog.newChangeTitle": "新建轻量 Spec 变更包",
|
|
48
|
+
"dialog.newChangeDesc": "仅生成 delta.md 与 acceptance.md 两份轻量文件,归档后自动沉淀至 SPEC.md。",
|
|
49
|
+
"dialog.changeTitleLabel": "变更标题",
|
|
50
|
+
"view.health.title": "健康度与护栏仪表盘",
|
|
51
|
+
"view.health.sub": "实时监控入口预算、规则零漂移、通用 Git 护栏与背压校验",
|
|
52
|
+
"view.onboarding.title": "向导式接入与环境体检",
|
|
53
|
+
"view.onboarding.sub": "自动区分存量仓与空目录,先预览变更文件树再安全落盘,一键补齐 CLI 工具链",
|
|
54
|
+
"view.changes.title": "Spec 变更看板与 DAG 任务账本",
|
|
55
|
+
"view.changes.sub": "可视化编辑 delta.md、勾选 acceptance.md 验收项并一键归档沉淀 SPEC.md",
|
|
56
|
+
"view.eval.title": "行为与 Token 消融评测实验室",
|
|
57
|
+
"view.eval.sub": "实时运行 core / hard / frontier 套件,原生 SVG 图表对比通过率、有效计费 Token 与缓存命中率",
|
|
58
|
+
},
|
|
59
|
+
"en-US": {
|
|
60
|
+
"nav.health": "Health & Guardrails",
|
|
61
|
+
"nav.onboarding": "Onboarding & Doctor",
|
|
62
|
+
"nav.changes": "Spec & DAG Board",
|
|
63
|
+
"nav.eval": "Eval Lab",
|
|
64
|
+
"theme.system": "Auto",
|
|
65
|
+
"theme.light": "Light",
|
|
66
|
+
"theme.dark": "Dark",
|
|
67
|
+
"action.quickVerify": "Quick Verify",
|
|
68
|
+
"common.cancel": "Cancel",
|
|
69
|
+
"common.switch": "Switch",
|
|
70
|
+
"common.create": "Create Change",
|
|
71
|
+
"common.confirm": "Confirm",
|
|
72
|
+
"common.copy": "Copy",
|
|
73
|
+
"common.copied": "Copied",
|
|
74
|
+
"common.cliEquiv": "View equivalent CLI command",
|
|
75
|
+
"dialog.workspaceTitle": "Switch Local Workspace",
|
|
76
|
+
"dialog.workspaceDesc": "Changes only the inspected directory in memory. Zero UI files are ever written to your repository.",
|
|
77
|
+
"dialog.workspacePath": "Absolute path",
|
|
78
|
+
"dialog.newChangeTitle": "New Lightweight Spec Change",
|
|
79
|
+
"dialog.newChangeDesc": "Creates only delta.md + acceptance.md; archiving crystallizes verified contracts into SPEC.md.",
|
|
80
|
+
"dialog.changeTitleLabel": "Change Title",
|
|
81
|
+
"view.health.title": "Health & Guardrails",
|
|
82
|
+
"view.health.sub": "Live doc entry budgets, 6-host rule zero-drift, universal Git hooks, and streaming verification",
|
|
83
|
+
"view.onboarding.title": "Onboarding & Toolchain Doctor",
|
|
84
|
+
"view.onboarding.sub": "Auto-detects brownfield vs empty repos, previews file changes before writing, and audits local CLIs",
|
|
85
|
+
"view.changes.title": "Spec Change Board & DAG Ledger",
|
|
86
|
+
"view.changes.sub": "Edit delta.md, check off acceptance.md interactively, and crystallize into SPEC.md on archive",
|
|
87
|
+
"view.eval.title": "Behavioral & Token Eval Lab",
|
|
88
|
+
"view.eval.sub": "Stream core / hard / frontier ablation suites with native SVG token, cache, and pass-rate charts",
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const state = {
|
|
93
|
+
lang: (() => {
|
|
94
|
+
try {
|
|
95
|
+
return localStorage.getItem("alh-ui-lang") === "en-US" ? "en-US" : "zh-CN";
|
|
96
|
+
} catch (_) {
|
|
97
|
+
return "zh-CN";
|
|
98
|
+
}
|
|
99
|
+
})(),
|
|
100
|
+
theme: (() => {
|
|
101
|
+
try {
|
|
102
|
+
const v = localStorage.getItem("alh-color-scheme");
|
|
103
|
+
return v === "light" || v === "dark" ? v : "system";
|
|
104
|
+
} catch (_) {
|
|
105
|
+
return "system";
|
|
106
|
+
}
|
|
107
|
+
})(),
|
|
108
|
+
view: "health",
|
|
109
|
+
meta: null,
|
|
110
|
+
health: null,
|
|
111
|
+
doctor: null,
|
|
112
|
+
adoptPreview: null,
|
|
113
|
+
changes: { active: [], archived: [] },
|
|
114
|
+
selectedSlug: null,
|
|
115
|
+
changeDetail: null,
|
|
116
|
+
tasksData: { tasks: [], readyCount: 0, hasCycle: false },
|
|
117
|
+
evalCatalog: null,
|
|
118
|
+
evalReports: [],
|
|
119
|
+
activeReport: null,
|
|
120
|
+
evalRunning: false,
|
|
121
|
+
evalProgress: { done: 0, total: 0, runs: [] },
|
|
122
|
+
verifyLogs: [],
|
|
123
|
+
verifyRunning: false,
|
|
124
|
+
verifyStrict: false,
|
|
125
|
+
verifyRunChecks: false,
|
|
126
|
+
onboardingForm: {
|
|
127
|
+
mode: "dual-core",
|
|
128
|
+
profile: "minimal",
|
|
129
|
+
stack: "node-ts",
|
|
130
|
+
locale: "zh-CN",
|
|
131
|
+
hosts: ["codex"],
|
|
132
|
+
lean: true,
|
|
133
|
+
installGitHooks: true,
|
|
134
|
+
docsStrategy: "thin-route",
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const t = (key) => I18N[state.lang]?.[key] || I18N["zh-CN"][key] || key;
|
|
139
|
+
const zh = (zhText, enText) => (state.lang === "en-US" ? enText : zhText);
|
|
140
|
+
|
|
141
|
+
// 3. Safe DOM helper (never uses untrusted innerHTML)
|
|
142
|
+
function el(tag, attrs = {}, ...children) {
|
|
143
|
+
const node = document.createElement(tag);
|
|
144
|
+
if (attrs) {
|
|
145
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
146
|
+
if (v === null || v === undefined || v === false) continue;
|
|
147
|
+
if (k === "class") node.className = v;
|
|
148
|
+
else if (k === "text") node.textContent = String(v);
|
|
149
|
+
else if (k.startsWith("on") && typeof v === "function") node.addEventListener(k.slice(2).toLowerCase(), v);
|
|
150
|
+
else if (k === "checked" || k === "disabled" || k === "selected" || k === "open") node[k] = Boolean(v);
|
|
151
|
+
else if (k === "style" && typeof v === "object") Object.assign(node.style, v);
|
|
152
|
+
else if (k === "style" && typeof v === "string") {
|
|
153
|
+
for (const decl of v.split(";")) {
|
|
154
|
+
const idx = decl.indexOf(":");
|
|
155
|
+
if (idx > 0) {
|
|
156
|
+
const prop = decl.slice(0, idx).trim();
|
|
157
|
+
const val = decl.slice(idx + 1).trim();
|
|
158
|
+
if (prop && val) node.style.setProperty(prop, val);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (k === "value") node.value = String(v);
|
|
163
|
+
else node.setAttribute(k, v === true ? "" : String(v));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const child of children.flat()) {
|
|
167
|
+
if (child === null || child === undefined || child === false) continue;
|
|
168
|
+
node.append(typeof child === "string" || typeof child === "number" ? document.createTextNode(String(child)) : child);
|
|
169
|
+
}
|
|
170
|
+
return node;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function svgEl(tag, attrs = {}, ...children) {
|
|
174
|
+
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
175
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
176
|
+
if (v !== null && v !== undefined) node.setAttribute(k, String(v));
|
|
177
|
+
}
|
|
178
|
+
for (const child of children.flat()) {
|
|
179
|
+
if (child === null || child === undefined) continue;
|
|
180
|
+
node.append(typeof child === "string" || typeof child === "number" ? document.createTextNode(String(child)) : child);
|
|
181
|
+
}
|
|
182
|
+
return node;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 4. Toast notifications
|
|
186
|
+
function toast(message, kind = "info") {
|
|
187
|
+
const region = document.getElementById("toast-region");
|
|
188
|
+
const item = el(
|
|
189
|
+
"div",
|
|
190
|
+
{ class: `toast toast-${kind}` },
|
|
191
|
+
el("span", { text: message }),
|
|
192
|
+
el("button", {
|
|
193
|
+
type: "button",
|
|
194
|
+
class: "btn btn-ghost btn-xs",
|
|
195
|
+
text: "×",
|
|
196
|
+
"aria-label": "Dismiss",
|
|
197
|
+
onclick: () => item.remove(),
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
region.append(item);
|
|
201
|
+
setTimeout(() => item.remove(), 4200);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 5. Equivalent CLI collapsible block
|
|
205
|
+
function cliDisclosure(command) {
|
|
206
|
+
const copyBtn = el("button", {
|
|
207
|
+
type: "button",
|
|
208
|
+
class: "btn btn-ghost btn-xs",
|
|
209
|
+
text: t("common.copy"),
|
|
210
|
+
onclick: async () => {
|
|
211
|
+
try {
|
|
212
|
+
await navigator.clipboard.writeText(command);
|
|
213
|
+
copyBtn.textContent = t("common.copied");
|
|
214
|
+
setTimeout(() => {
|
|
215
|
+
copyBtn.textContent = t("common.copy");
|
|
216
|
+
}, 1500);
|
|
217
|
+
} catch {
|
|
218
|
+
toast(zh("复制失败,请手动选中命令复制", "Copy failed; select manually"), "err");
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
return el(
|
|
223
|
+
"details",
|
|
224
|
+
{ class: "cli-details" },
|
|
225
|
+
el("summary", { text: t("common.cliEquiv") }),
|
|
226
|
+
el("div", { class: "cli-box" }, el("code", { text: command }), copyBtn)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 6. Native confirm dialog helper
|
|
231
|
+
function confirmAction({ title, desc, cliCommand = "" }) {
|
|
232
|
+
return new Promise((resolve) => {
|
|
233
|
+
const dlg = document.getElementById("dialog-confirm");
|
|
234
|
+
document.getElementById("dialog-confirm-title").textContent = title;
|
|
235
|
+
document.getElementById("dialog-confirm-desc").textContent = desc;
|
|
236
|
+
const cliPre = document.getElementById("dialog-confirm-cli");
|
|
237
|
+
if (cliCommand) {
|
|
238
|
+
cliPre.textContent = cliCommand;
|
|
239
|
+
cliPre.hidden = false;
|
|
240
|
+
} else {
|
|
241
|
+
cliPre.hidden = true;
|
|
242
|
+
}
|
|
243
|
+
const onClose = () => {
|
|
244
|
+
const ok = dlg.returnValue === "confirm";
|
|
245
|
+
dlg.returnValue = "";
|
|
246
|
+
dlg.removeEventListener("close", onClose);
|
|
247
|
+
resolve(ok);
|
|
248
|
+
};
|
|
249
|
+
dlg.addEventListener("close", onClose);
|
|
250
|
+
dlg.showModal();
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// 7. Authenticated Fetch & Fetch-SSE Helpers
|
|
255
|
+
async function api(url, { method = "GET", body = null } = {}) {
|
|
256
|
+
const headers = { "X-ALH-Token": SESSION_TOKEN };
|
|
257
|
+
if (body !== null) headers["Content-Type"] = "application/json";
|
|
258
|
+
const res = await fetch(url, {
|
|
259
|
+
method,
|
|
260
|
+
headers,
|
|
261
|
+
body: body !== null ? JSON.stringify(body) : undefined,
|
|
262
|
+
});
|
|
263
|
+
const data = await res.json().catch(() => ({ ok: false, error: `HTTP ${res.status}` }));
|
|
264
|
+
if (!res.ok) {
|
|
265
|
+
throw new Error(data.error || `HTTP ${res.status}`);
|
|
266
|
+
}
|
|
267
|
+
return data;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function apiStream(url, body, onEvent) {
|
|
271
|
+
const res = await fetch(url, {
|
|
272
|
+
method: "POST",
|
|
273
|
+
headers: {
|
|
274
|
+
"Content-Type": "application/json",
|
|
275
|
+
"X-ALH-Token": SESSION_TOKEN,
|
|
276
|
+
},
|
|
277
|
+
body: JSON.stringify(body || {}),
|
|
278
|
+
});
|
|
279
|
+
if (!res.ok) {
|
|
280
|
+
const err = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
|
|
281
|
+
throw new Error(err.error || `HTTP ${res.status}`);
|
|
282
|
+
}
|
|
283
|
+
const reader = res.body.getReader();
|
|
284
|
+
const decoder = new TextDecoder();
|
|
285
|
+
let buf = "";
|
|
286
|
+
while (true) {
|
|
287
|
+
const { done, value } = await reader.read();
|
|
288
|
+
if (done) break;
|
|
289
|
+
buf += decoder.decode(value, { stream: true });
|
|
290
|
+
let idx;
|
|
291
|
+
while ((idx = buf.indexOf("\n\n")) !== -1) {
|
|
292
|
+
const frame = buf.slice(0, idx);
|
|
293
|
+
buf = buf.slice(idx + 2);
|
|
294
|
+
let eventName = "message";
|
|
295
|
+
let dataStr = "";
|
|
296
|
+
for (const line of frame.split("\n")) {
|
|
297
|
+
if (line.startsWith("event:")) eventName = line.slice(6).trim();
|
|
298
|
+
else if (line.startsWith("data:")) dataStr += line.slice(5).trim();
|
|
299
|
+
}
|
|
300
|
+
if (dataStr) {
|
|
301
|
+
try {
|
|
302
|
+
onEvent(eventName, JSON.parse(dataStr));
|
|
303
|
+
} catch (_) {}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// 8. Theme & Language Management (Modern Web Guidance compliant)
|
|
310
|
+
function applyTheme(mode) {
|
|
311
|
+
state.theme = mode;
|
|
312
|
+
const meta = document.querySelector('meta[name="color-scheme"]');
|
|
313
|
+
if (mode === "system") {
|
|
314
|
+
meta.content = "light dark";
|
|
315
|
+
try {
|
|
316
|
+
localStorage.removeItem("alh-color-scheme");
|
|
317
|
+
} catch (_) {}
|
|
318
|
+
} else {
|
|
319
|
+
meta.content = mode;
|
|
320
|
+
try {
|
|
321
|
+
localStorage.setItem("alh-color-scheme", mode);
|
|
322
|
+
} catch (_) {}
|
|
323
|
+
}
|
|
324
|
+
document.querySelectorAll(".seg-btn[data-theme]").forEach((btn) => {
|
|
325
|
+
btn.classList.toggle("active", btn.dataset.theme === mode);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function applyStaticI18n() {
|
|
330
|
+
document.documentElement.lang = state.lang;
|
|
331
|
+
document.querySelectorAll("[data-i18n]").forEach((node) => {
|
|
332
|
+
node.textContent = t(node.dataset.i18n);
|
|
333
|
+
});
|
|
334
|
+
updateTopbarHeader();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function updateTopbarHeader() {
|
|
338
|
+
document.getElementById("view-title").textContent = t(`view.${state.view}.title`);
|
|
339
|
+
document.getElementById("view-subtitle").textContent = t(`view.${state.view}.sub`);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 9. Data Loaders
|
|
343
|
+
async function loadAllData() {
|
|
344
|
+
const warnEl = document.getElementById("auth-warning");
|
|
345
|
+
if (!SESSION_TOKEN) {
|
|
346
|
+
warnEl.hidden = false;
|
|
347
|
+
warnEl.textContent = zh(
|
|
348
|
+
"缺少会话安全令牌(Token)。请通过终端运行 `alh ui` 打印的完整 URL(含 ?token=...)打开本页面。",
|
|
349
|
+
"Missing session token. Open this console using the full URL printed by `alh ui` (including ?token=...)."
|
|
350
|
+
);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
warnEl.hidden = true;
|
|
354
|
+
try {
|
|
355
|
+
const [meta, health, changes, tasksData] = await Promise.all([
|
|
356
|
+
api("/api/meta"),
|
|
357
|
+
api("/api/health"),
|
|
358
|
+
api("/api/changes"),
|
|
359
|
+
api("/api/tasks"),
|
|
360
|
+
]);
|
|
361
|
+
state.meta = meta;
|
|
362
|
+
state.health = health;
|
|
363
|
+
state.changes = { active: changes.active || [], archived: changes.archived || [] };
|
|
364
|
+
state.tasksData = tasksData;
|
|
365
|
+
|
|
366
|
+
// Seed onboarding defaults from scan once per workspace
|
|
367
|
+
if (meta.scan) {
|
|
368
|
+
state.onboardingForm.profile = meta.harnessConfig?.profile || meta.scan.suggestedProfile || "minimal";
|
|
369
|
+
state.onboardingForm.mode = meta.harnessConfig?.mode || "dual-core";
|
|
370
|
+
state.onboardingForm.locale = meta.harnessConfig?.locale || state.lang;
|
|
371
|
+
state.onboardingForm.docsStrategy = "thin-route";
|
|
372
|
+
if (Array.isArray(meta.harnessConfig?.hosts) && meta.harnessConfig.hosts.length > 0) {
|
|
373
|
+
state.onboardingForm.hosts = [...meta.harnessConfig.hosts];
|
|
374
|
+
} else if (Array.isArray(meta.scan.suggestedHosts) && meta.scan.suggestedHosts.length > 0) {
|
|
375
|
+
state.onboardingForm.hosts = [meta.scan.suggestedHosts[0]];
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (state.changes.active.length > 0) {
|
|
380
|
+
const stillExists = state.changes.active.some((c) => c.slug === state.selectedSlug);
|
|
381
|
+
if (!stillExists) state.selectedSlug = state.changes.active[0].slug;
|
|
382
|
+
await loadChangeDetail(state.selectedSlug);
|
|
383
|
+
} else {
|
|
384
|
+
state.selectedSlug = null;
|
|
385
|
+
state.changeDetail = null;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
renderChrome();
|
|
389
|
+
renderActivePanel();
|
|
390
|
+
} catch (err) {
|
|
391
|
+
warnEl.hidden = false;
|
|
392
|
+
warnEl.textContent = `${zh("加载失败", "Failed to load")}: ${err.message}`;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function loadChangeDetail(slug) {
|
|
397
|
+
if (!slug) {
|
|
398
|
+
state.changeDetail = null;
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const res = await api(`/api/changes/${encodeURIComponent(slug)}`);
|
|
402
|
+
state.changeDetail = res.change;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function loadDoctorIfNeeded(force = false) {
|
|
406
|
+
if (state.doctor && !force) return;
|
|
407
|
+
state.doctor = await api("/api/doctor");
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
async function loadEvalIfNeeded(force = false) {
|
|
411
|
+
if (!state.evalCatalog || force) {
|
|
412
|
+
state.evalCatalog = await api("/api/eval/cases");
|
|
413
|
+
}
|
|
414
|
+
const rep = await api("/api/eval/reports");
|
|
415
|
+
state.evalReports = rep.reports || [];
|
|
416
|
+
if (!state.activeReport && state.evalReports.length > 0) {
|
|
417
|
+
state.activeReport = state.evalReports[0].report;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// 10. Sidebar & Topbar Chrome
|
|
422
|
+
function renderChrome() {
|
|
423
|
+
if (!state.meta || !state.health) return;
|
|
424
|
+
document.getElementById("version-badge").textContent = `v${state.meta.version}`;
|
|
425
|
+
document.getElementById("workspace-name").textContent = state.meta.workspaceName;
|
|
426
|
+
document.getElementById("workspace-path").textContent = state.meta.workspace;
|
|
427
|
+
document.getElementById("host-indicator").textContent = `${window.location.host} · Local`;
|
|
428
|
+
|
|
429
|
+
const kindPill = document.getElementById("workspace-kind-pill");
|
|
430
|
+
const kind = state.meta.dirInfo.kind;
|
|
431
|
+
kindPill.className = `pill ${kind === "adopted" ? "pill-ok" : kind === "empty" ? "pill-accent" : "pill-warn"}`;
|
|
432
|
+
kindPill.textContent =
|
|
433
|
+
kind === "adopted"
|
|
434
|
+
? zh("已接入", "Adopted")
|
|
435
|
+
: kind === "empty"
|
|
436
|
+
? zh("空目录", "Empty")
|
|
437
|
+
: zh("存量仓", "Brownfield");
|
|
438
|
+
|
|
439
|
+
const dot = document.getElementById("nav-health-dot");
|
|
440
|
+
const lvl = state.health.summaryStatus.level;
|
|
441
|
+
dot.className = `status-dot ${lvl === "healthy" ? "dot-ok" : lvl === "warn" ? "dot-warn" : lvl === "unadopted" ? "dot-muted" : "dot-err"}`;
|
|
442
|
+
|
|
443
|
+
const badge = document.getElementById("nav-changes-badge");
|
|
444
|
+
const activeCount = state.changes.active.length;
|
|
445
|
+
badge.hidden = activeCount === 0;
|
|
446
|
+
badge.textContent = String(activeCount);
|
|
447
|
+
|
|
448
|
+
const chip = document.getElementById("topbar-mode-chip");
|
|
449
|
+
if (state.meta.harnessConfig) {
|
|
450
|
+
chip.hidden = false;
|
|
451
|
+
chip.textContent = `${state.meta.harnessConfig.mode || "dual-core"} · ${(state.meta.harnessConfig.hosts || []).join(",")}`;
|
|
452
|
+
} else {
|
|
453
|
+
chip.hidden = true;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// 11. Panel 1 — Health & Guardrails
|
|
458
|
+
function renderHealthPanel() {
|
|
459
|
+
const root = document.getElementById("panel-health");
|
|
460
|
+
root.replaceChildren();
|
|
461
|
+
const h = state.health;
|
|
462
|
+
if (!h) return;
|
|
463
|
+
|
|
464
|
+
// KPI Row
|
|
465
|
+
const lvl = h.summaryStatus.level;
|
|
466
|
+
const statusLabel =
|
|
467
|
+
lvl === "unadopted"
|
|
468
|
+
? zh("待接入", "Not Adopted")
|
|
469
|
+
: lvl === "healthy"
|
|
470
|
+
? zh("全部绿灯", "Healthy")
|
|
471
|
+
: lvl === "warn"
|
|
472
|
+
? zh("存在提示", "Advisory")
|
|
473
|
+
: zh("需要处理", "Action Needed");
|
|
474
|
+
const statusPillClass =
|
|
475
|
+
lvl === "unadopted" ? "pill-accent" : lvl === "healthy" ? "pill-ok" : lvl === "warn" ? "pill-warn" : "pill-err";
|
|
476
|
+
|
|
477
|
+
if (lvl === "unadopted") {
|
|
478
|
+
root.append(
|
|
479
|
+
el(
|
|
480
|
+
"div",
|
|
481
|
+
{ class: "banner banner-info" },
|
|
482
|
+
el("span", {
|
|
483
|
+
text: zh(
|
|
484
|
+
"当前工作区尚未接入 AgentLock Harness(已跳过 v1 强规则校验以避免误报)。点击右侧按钮可预览无损接入方案。",
|
|
485
|
+
"This workspace has not adopted AgentLock Harness yet (strict v1 checks skipped to avoid false alarms). Preview non-destructive onboarding anytime."
|
|
486
|
+
),
|
|
487
|
+
}),
|
|
488
|
+
el("button", {
|
|
489
|
+
type: "button",
|
|
490
|
+
class: "btn btn-primary btn-sm",
|
|
491
|
+
text: zh("前往向导接入", "Open Onboarding"),
|
|
492
|
+
onclick: () => switchView("onboarding"),
|
|
493
|
+
})
|
|
494
|
+
)
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const hooksActive = Boolean(h.hooks?.active);
|
|
499
|
+
const hooksSwitch = el("button", {
|
|
500
|
+
type: "button",
|
|
501
|
+
role: "switch",
|
|
502
|
+
class: "switch-btn",
|
|
503
|
+
"aria-checked": String(hooksActive),
|
|
504
|
+
"aria-label": zh("切换通用 Git Hooks", "Toggle universal Git hooks"),
|
|
505
|
+
disabled: !h.dirInfo.hasGit || !h.harnessConfig,
|
|
506
|
+
onclick: async () => {
|
|
507
|
+
try {
|
|
508
|
+
const res = await api("/api/hooks/toggle", { method: "POST", body: { enable: !hooksActive } });
|
|
509
|
+
if (!res.ok) {
|
|
510
|
+
toast(zh(`操作未执行: ${res.reason || "请检查自定义 hooksPath"}`, `Skipped: ${res.reason || "custom hooksPath"}`), "err");
|
|
511
|
+
} else {
|
|
512
|
+
toast(
|
|
513
|
+
!hooksActive ? zh("已启用跨工具通用 Git Hooks 护栏", "Universal Git Hooks enabled") : zh("已停用 AgentLock Git Hooks", "AgentLock Git Hooks disabled"),
|
|
514
|
+
"ok"
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
await loadAllData();
|
|
518
|
+
} catch (err) {
|
|
519
|
+
toast(err.message, "err");
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
const existingBudgets = h.budgets.filter((b) => b.exists);
|
|
525
|
+
const okBudgets = existingBudgets.filter((b) => b.status === "ok").length;
|
|
526
|
+
|
|
527
|
+
root.append(
|
|
528
|
+
el(
|
|
529
|
+
"div",
|
|
530
|
+
{ class: "kpi-grid" },
|
|
531
|
+
el(
|
|
532
|
+
"div",
|
|
533
|
+
{ class: "card kpi-card" },
|
|
534
|
+
el("div", { class: "kpi-head" }, zh("综合健康状态", "Overall Health"), el("span", { class: `pill ${statusPillClass}`, text: statusLabel })),
|
|
535
|
+
el("div", { class: "kpi-value", text: `${h.summaryStatus.criticalIssues} / ${h.summaryStatus.advisoryIssues}` }),
|
|
536
|
+
el("div", { class: "kpi-sub", text: zh("阻断项 / 提示项", "Critical / Advisories") })
|
|
537
|
+
),
|
|
538
|
+
el(
|
|
539
|
+
"div",
|
|
540
|
+
{ class: "card kpi-card" },
|
|
541
|
+
el("div", { class: "kpi-head" }, zh("入口文档预算", "Entry Budgets"), el("span", { class: "pill pill-accent", text: `${okBudgets}/${existingBudgets.length || 3}` })),
|
|
542
|
+
el("div", { class: "kpi-value", text: h.v1Docs.checked ? `${h.v1Docs.files}` : "—" }),
|
|
543
|
+
el("div", { class: "kpi-sub", text: zh("v1 扫描文档总数", "v1 Scanned Markdown Files") })
|
|
544
|
+
),
|
|
545
|
+
el(
|
|
546
|
+
"div",
|
|
547
|
+
{ class: "card kpi-card" },
|
|
548
|
+
el(
|
|
549
|
+
"div",
|
|
550
|
+
{ class: "kpi-head" },
|
|
551
|
+
zh("规则零漂移", "Rules Drift"),
|
|
552
|
+
el("span", {
|
|
553
|
+
class: `pill ${h.rules.ok ? "pill-ok" : "pill-err"}`,
|
|
554
|
+
text: h.rules.ok ? zh("零漂移", "Synced") : `${h.rules.driftCount} ${zh("漂移", "drifted")}`,
|
|
555
|
+
})
|
|
556
|
+
),
|
|
557
|
+
el("div", { class: "kpi-value", text: String(h.rules.sourceCount) }),
|
|
558
|
+
el("div", { class: "kpi-sub", text: zh("单源路径级规则文件", "Single-Source Rule Files") })
|
|
559
|
+
),
|
|
560
|
+
el(
|
|
561
|
+
"div",
|
|
562
|
+
{ class: "card kpi-card" },
|
|
563
|
+
el("div", { class: "kpi-head" }, zh("通用 Git Hooks", "Universal Git Hooks"), hooksSwitch),
|
|
564
|
+
el("div", { class: "kpi-value", text: hooksActive ? "ON" : "OFF" }),
|
|
565
|
+
el("div", {
|
|
566
|
+
class: "kpi-sub",
|
|
567
|
+
text: !h.dirInfo.hasGit
|
|
568
|
+
? zh("非 Git 仓库", "Not a Git repo")
|
|
569
|
+
: hooksActive
|
|
570
|
+
? "pre-commit + pre-push"
|
|
571
|
+
: zh("未接管 core.hooksPath", "Not active"),
|
|
572
|
+
})
|
|
573
|
+
)
|
|
574
|
+
)
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
// Diagnostics Details Card (transparent breakdown of every critical & advisory item)
|
|
578
|
+
const diag = h.diagnostics || { critical: [], advisory: [] };
|
|
579
|
+
if (diag.critical.length > 0 || diag.advisory.length > 0) {
|
|
580
|
+
const diagBlocks = [];
|
|
581
|
+
if (diag.critical.length > 0) {
|
|
582
|
+
diagBlocks.push(
|
|
583
|
+
el(
|
|
584
|
+
"div",
|
|
585
|
+
{ class: "item-list" },
|
|
586
|
+
diag.critical.map((item) =>
|
|
587
|
+
el(
|
|
588
|
+
"div",
|
|
589
|
+
{ class: "list-row" },
|
|
590
|
+
el(
|
|
591
|
+
"div",
|
|
592
|
+
{ style: "display:flex;align-items:center;gap:8px;flex-wrap:wrap" },
|
|
593
|
+
el("span", { class: "pill pill-err", text: item.category }),
|
|
594
|
+
el("span", { class: "mono-xs", text: item.message })
|
|
595
|
+
)
|
|
596
|
+
)
|
|
597
|
+
)
|
|
598
|
+
)
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
if (diag.advisory.length > 0) {
|
|
602
|
+
diagBlocks.push(
|
|
603
|
+
el(
|
|
604
|
+
"details",
|
|
605
|
+
{ class: "cli-details", open: diag.critical.length === 0 && diag.advisory.length <= 5 },
|
|
606
|
+
el("summary", { text: `${zh("展开提示项明细", "Show advisory details")} (${diag.advisory.length})` }),
|
|
607
|
+
el(
|
|
608
|
+
"div",
|
|
609
|
+
{ class: "item-list", style: "margin-top:8px" },
|
|
610
|
+
diag.advisory.map((item) =>
|
|
611
|
+
el(
|
|
612
|
+
"div",
|
|
613
|
+
{ class: "list-row" },
|
|
614
|
+
el(
|
|
615
|
+
"div",
|
|
616
|
+
{ style: "display:flex;align-items:center;gap:8px;flex-wrap:wrap" },
|
|
617
|
+
el("span", { class: "pill pill-warn", text: item.category }),
|
|
618
|
+
el("span", { class: "mono-xs", text: item.message })
|
|
619
|
+
)
|
|
620
|
+
)
|
|
621
|
+
)
|
|
622
|
+
)
|
|
623
|
+
)
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
root.append(
|
|
627
|
+
el(
|
|
628
|
+
"div",
|
|
629
|
+
{ class: "card" },
|
|
630
|
+
el(
|
|
631
|
+
"div",
|
|
632
|
+
{ class: "card-header" },
|
|
633
|
+
el(
|
|
634
|
+
"div",
|
|
635
|
+
{},
|
|
636
|
+
el("h2", { class: "card-title", text: zh("诊断明细(阻断项与提示项)", "Diagnostics Breakdown") }),
|
|
637
|
+
el("p", {
|
|
638
|
+
class: "card-desc",
|
|
639
|
+
text: `${zh("阻断项", "Critical")}: ${diag.critical.length} · ${zh("提示项", "Advisories")}: ${diag.advisory.length}`,
|
|
640
|
+
})
|
|
641
|
+
)
|
|
642
|
+
),
|
|
643
|
+
diagBlocks
|
|
644
|
+
)
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Row 2: Entry Budget Meters + Spec & Rules Card
|
|
649
|
+
const budgetRows = h.budgets.map((b) => {
|
|
650
|
+
const pct = Math.min(100, Math.round(Math.max(b.lineRatio, b.charRatio) * 100));
|
|
651
|
+
const fillCls = b.status === "over" ? "fill-err" : b.status === "warn" ? "fill-warn" : b.exists ? "fill-ok" : "fill-muted";
|
|
652
|
+
const pillCls = b.status === "over" ? "pill-err" : b.status === "warn" ? "pill-warn" : b.exists ? "pill-ok" : "pill-muted";
|
|
653
|
+
const statusText = !b.exists ? zh("未创建", "Missing") : b.status === "over" ? zh("超预算", "Over") : b.status === "warn" ? zh("接近上限", "Near Cap") : zh("健康", "OK");
|
|
654
|
+
return el(
|
|
655
|
+
"div",
|
|
656
|
+
{ class: "meter-row" },
|
|
657
|
+
el(
|
|
658
|
+
"div",
|
|
659
|
+
{ class: "meter-meta" },
|
|
660
|
+
el(
|
|
661
|
+
"div",
|
|
662
|
+
{ class: "card-actions" },
|
|
663
|
+
el("span", { class: "mono", text: b.path }),
|
|
664
|
+
b.exists && b.detectedLocale ? el("span", { class: "pill pill-muted", text: b.detectedLocale === "en-US" ? "EN" : "ZH" }) : null
|
|
665
|
+
),
|
|
666
|
+
el(
|
|
667
|
+
"div",
|
|
668
|
+
{ class: "card-actions" },
|
|
669
|
+
el("span", { class: "mono-xs num", text: `${b.lines}/${b.maxLines}L · ${b.chars}/${b.maxChars}C` }),
|
|
670
|
+
el("span", { class: `pill ${pillCls}`, text: statusText })
|
|
671
|
+
)
|
|
672
|
+
),
|
|
673
|
+
el("div", { class: "meter-track" }, el("div", { class: `meter-fill ${fillCls}`, style: `width:${b.exists ? Math.max(4, pct) : 0}%` }))
|
|
674
|
+
);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
const budgetCard = el(
|
|
678
|
+
"div",
|
|
679
|
+
{ class: "card" },
|
|
680
|
+
el(
|
|
681
|
+
"div",
|
|
682
|
+
{ class: "card-header" },
|
|
683
|
+
el(
|
|
684
|
+
"div",
|
|
685
|
+
{},
|
|
686
|
+
el("h2", { class: "card-title", text: zh("入口上下文预算(哑铃零税红绿灯)", "Entry Context Budgets (Zero-Tax Meters)") }),
|
|
687
|
+
el("p", { class: "card-desc", text: zh("严控高频常读入口体积,避免拖慢强模型并保护 KV Cache 前缀", "Keep high-frequency entrypoints lean to preserve speed and KV-cache hit rate") })
|
|
688
|
+
)
|
|
689
|
+
),
|
|
690
|
+
el("div", { class: "meter-list" }, budgetRows),
|
|
691
|
+
h.v1Docs.errors.length > 0
|
|
692
|
+
? el(
|
|
693
|
+
"div",
|
|
694
|
+
{ class: "banner banner-error", style: "margin-top:14px" },
|
|
695
|
+
el("span", { text: `v1 Docs: ${h.v1Docs.errors[0]}${h.v1Docs.errors.length > 1 ? ` (+${h.v1Docs.errors.length - 1})` : ""}` })
|
|
696
|
+
)
|
|
697
|
+
: null,
|
|
698
|
+
cliDisclosure(`alh verify "${h.workspace}"`)
|
|
699
|
+
);
|
|
700
|
+
|
|
701
|
+
const compileBtn = el("button", {
|
|
702
|
+
type: "button",
|
|
703
|
+
class: "btn btn-sm",
|
|
704
|
+
text: zh("一键重编译规则", "Compile Rules"),
|
|
705
|
+
disabled: h.rules.sourceCount === 0,
|
|
706
|
+
onclick: async () => {
|
|
707
|
+
try {
|
|
708
|
+
const res = await api("/api/rules/compile", { method: "POST", body: {} });
|
|
709
|
+
toast(zh(`编译完成:写入 ${res.written.length} 份,未变 ${res.unchanged.length} 份`, `Compiled: ${res.written.length} written, ${res.unchanged.length} unchanged`), "ok");
|
|
710
|
+
await loadAllData();
|
|
711
|
+
} catch (err) {
|
|
712
|
+
toast(err.message, "err");
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
const specSummary = h.specDiscovery?.hasExistingSpecs
|
|
718
|
+
? `${zh("已发现规范", "Discovered")}: ${h.specDiscovery.specFiles.join(", ")}`
|
|
719
|
+
: zh("未发现既有 SPEC:自动使用内置 alh change 懒沉淀", "No existing SPEC: built-in alh change flow active");
|
|
720
|
+
|
|
721
|
+
const rulesCard = el(
|
|
722
|
+
"div",
|
|
723
|
+
{ class: "card" },
|
|
724
|
+
el(
|
|
725
|
+
"div",
|
|
726
|
+
{ class: "card-header" },
|
|
727
|
+
el(
|
|
728
|
+
"div",
|
|
729
|
+
{},
|
|
730
|
+
el("h2", { class: "card-title", text: zh("规范发现 & 6 宿主路径级规则", "Spec Discovery & 6-Host Scoped Rules") }),
|
|
731
|
+
el("p", { class: "card-desc", text: specSummary })
|
|
732
|
+
),
|
|
733
|
+
compileBtn
|
|
734
|
+
),
|
|
735
|
+
h.rules.sources.length === 0
|
|
736
|
+
? el("div", { class: "empty-state", text: zh("尚无 .agentlock-harness/rules/*.md 规则源,请先接入项目。", "No .agentlock-harness/rules/*.md source rules yet.") })
|
|
737
|
+
: el(
|
|
738
|
+
"div",
|
|
739
|
+
{ class: "item-list" },
|
|
740
|
+
h.rules.sources.map((r) =>
|
|
741
|
+
el(
|
|
742
|
+
"div",
|
|
743
|
+
{ class: "list-row" },
|
|
744
|
+
el("span", { class: "mono-xs", text: r.relPath }),
|
|
745
|
+
el("span", {
|
|
746
|
+
class: `pill ${r.alwaysApply ? "pill-accent" : "pill-muted"}`,
|
|
747
|
+
text: r.alwaysApply ? "alwaysApply" : (r.globs || []).join(", ") || "scoped",
|
|
748
|
+
})
|
|
749
|
+
)
|
|
750
|
+
)
|
|
751
|
+
),
|
|
752
|
+
cliDisclosure(`alh rules compile "${h.workspace}"`)
|
|
753
|
+
);
|
|
754
|
+
|
|
755
|
+
root.append(el("div", { class: "grid-2" }, budgetCard, rulesCard));
|
|
756
|
+
|
|
757
|
+
// Row 3: Live Verify/Review Stream + Stats Telemetry Chart
|
|
758
|
+
const verifyTerminal = el(
|
|
759
|
+
"pre",
|
|
760
|
+
{ class: "terminal" },
|
|
761
|
+
state.verifyLogs.length === 0
|
|
762
|
+
? zh("点击上方按钮即可流式运行 alh verify 或异构只读 alh review...", "Click a button above to stream alh verify or cross-model alh review...")
|
|
763
|
+
: state.verifyLogs.map((l) =>
|
|
764
|
+
el("div", {
|
|
765
|
+
class: l.stream === "stderr" ? "terminal-line-err" : l.line.includes("✓") || l.line.includes("通过") ? "terminal-line-ok" : "",
|
|
766
|
+
text: l.line,
|
|
767
|
+
})
|
|
768
|
+
)
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
const verifyCard = el(
|
|
772
|
+
"div",
|
|
773
|
+
{ class: "card" },
|
|
774
|
+
el(
|
|
775
|
+
"div",
|
|
776
|
+
{ class: "card-header" },
|
|
777
|
+
el(
|
|
778
|
+
"div",
|
|
779
|
+
{},
|
|
780
|
+
el("h2", { class: "card-title", text: zh("实时确定性校验 & 异构审校", "Live Verify & Cross-Model Review") }),
|
|
781
|
+
el("p", { class: "card-desc", text: zh("通过 SSE 实时输出校验与代码背压日志", "Streams deterministic checks and read-only diff review via SSE") })
|
|
782
|
+
),
|
|
783
|
+
el(
|
|
784
|
+
"div",
|
|
785
|
+
{ class: "card-actions" },
|
|
786
|
+
el(
|
|
787
|
+
"label",
|
|
788
|
+
{ class: "check-pill" },
|
|
789
|
+
el("input", {
|
|
790
|
+
type: "checkbox",
|
|
791
|
+
checked: state.verifyStrict,
|
|
792
|
+
onchange: (e) => {
|
|
793
|
+
state.verifyStrict = e.target.checked;
|
|
794
|
+
renderHealthPanel();
|
|
795
|
+
},
|
|
796
|
+
}),
|
|
797
|
+
"--strict"
|
|
798
|
+
),
|
|
799
|
+
el(
|
|
800
|
+
"label",
|
|
801
|
+
{ class: "check-pill" },
|
|
802
|
+
el("input", {
|
|
803
|
+
type: "checkbox",
|
|
804
|
+
checked: state.verifyRunChecks,
|
|
805
|
+
onchange: (e) => {
|
|
806
|
+
state.verifyRunChecks = e.target.checked;
|
|
807
|
+
renderHealthPanel();
|
|
808
|
+
},
|
|
809
|
+
}),
|
|
810
|
+
"--run-checks"
|
|
811
|
+
),
|
|
812
|
+
el("button", {
|
|
813
|
+
type: "button",
|
|
814
|
+
class: "btn btn-primary btn-sm",
|
|
815
|
+
disabled: state.verifyRunning,
|
|
816
|
+
text: state.verifyRunning ? zh("执行中...", "Running...") : zh("运行 Verify", "Run Verify"),
|
|
817
|
+
onclick: () => runStreamAction("/api/verify", { strict: state.verifyStrict, runChecks: state.verifyRunChecks }),
|
|
818
|
+
}),
|
|
819
|
+
el("button", {
|
|
820
|
+
type: "button",
|
|
821
|
+
class: "btn btn-sm",
|
|
822
|
+
disabled: state.verifyRunning || !h.dirInfo.hasGit,
|
|
823
|
+
text: zh("异构审校", "Cross Review"),
|
|
824
|
+
onclick: () => runStreamAction("/api/review", {}),
|
|
825
|
+
})
|
|
826
|
+
)
|
|
827
|
+
),
|
|
828
|
+
verifyTerminal,
|
|
829
|
+
cliDisclosure(`alh verify "${h.workspace}"${state.verifyStrict ? " --strict" : ""}${state.verifyRunChecks ? " --run-checks" : ""}`)
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
const stats = h.stats || { totalEvents: 0, totalBlocks: 0, totalPasses: 0, totalFails: 0, topBlockedRules: [] };
|
|
833
|
+
const statsCard = el(
|
|
834
|
+
"div",
|
|
835
|
+
{ class: "card" },
|
|
836
|
+
el(
|
|
837
|
+
"div",
|
|
838
|
+
{ class: "card-header" },
|
|
839
|
+
el(
|
|
840
|
+
"div",
|
|
841
|
+
{},
|
|
842
|
+
el("h2", { class: "card-title", text: zh("护栏拦截可观测性 (alh stats)", "Guardrail Telemetry (alh stats)") }),
|
|
843
|
+
el("p", { class: "card-desc", text: zh("零 PII 本地事件日志聚合", "Zero-PII local event telemetry") })
|
|
844
|
+
)
|
|
845
|
+
),
|
|
846
|
+
el(
|
|
847
|
+
"div",
|
|
848
|
+
{ class: "kpi-grid", style: "grid-template-columns:repeat(3,1fr);margin-bottom:14px" },
|
|
849
|
+
el("div", { class: "list-row" }, el("span", { text: zh("事件", "Events") }), el("strong", { class: "num", text: String(stats.totalEvents || 0) })),
|
|
850
|
+
el("div", { class: "list-row" }, el("span", { text: zh("拦截", "Blocks") }), el("strong", { class: "num", style: "color:var(--err)", text: String(stats.totalBlocks || 0) })),
|
|
851
|
+
el("div", { class: "list-row" }, el("span", { text: zh("放行", "Passes") }), el("strong", { class: "num", style: "color:var(--ok)", text: String(stats.totalPasses || 0) }))
|
|
852
|
+
),
|
|
853
|
+
renderTopBlockedSvg(stats.topBlockedRules || []),
|
|
854
|
+
cliDisclosure(`alh stats "${h.workspace}"`)
|
|
855
|
+
);
|
|
856
|
+
|
|
857
|
+
root.append(el("div", { class: "grid-2" }, verifyCard, statsCard));
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function renderTopBlockedSvg(rows) {
|
|
861
|
+
if (!rows || rows.length === 0) {
|
|
862
|
+
return el("div", { class: "empty-state", text: zh("暂无护栏拦截记录(工作区洁净或尚未触发拦截)", "No guardrail blocks recorded yet.") });
|
|
863
|
+
}
|
|
864
|
+
const top = rows.slice(0, 6);
|
|
865
|
+
const maxVal = Math.max(1, ...top.map((r) => r.count || 0));
|
|
866
|
+
const rowH = 30;
|
|
867
|
+
const h = top.length * rowH + 12;
|
|
868
|
+
const svg = svgEl("svg", { class: "svg-chart", viewBox: `0 0 440 ${h}`, role: "img", "aria-label": "Top blocked guardrail rules" });
|
|
869
|
+
top.forEach((r, i) => {
|
|
870
|
+
const y = i * rowH + 6;
|
|
871
|
+
const barW = Math.max(8, Math.round(((r.count || 0) / maxVal) * 200));
|
|
872
|
+
svg.append(
|
|
873
|
+
svgEl("text", { x: 4, y: y + 16, fill: "currentColor", "font-size": 11.5, opacity: 0.85 }, String(r.rule || "unknown").slice(0, 26)),
|
|
874
|
+
svgEl("rect", { x: 195, y: y + 5, width: 200, height: 14, rx: 4, fill: "currentColor", opacity: 0.08 }),
|
|
875
|
+
svgEl("rect", { x: 195, y: y + 5, width: barW, height: 14, rx: 4, fill: "#f43f5e" }),
|
|
876
|
+
svgEl("text", { x: 405, y: y + 16, fill: "currentColor", "font-size": 11.5, "font-weight": 600 }, String(r.count || 0))
|
|
877
|
+
);
|
|
878
|
+
});
|
|
879
|
+
return svg;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
async function runStreamAction(endpoint, payload) {
|
|
883
|
+
state.verifyRunning = true;
|
|
884
|
+
state.verifyLogs = [];
|
|
885
|
+
renderHealthPanel();
|
|
886
|
+
try {
|
|
887
|
+
await apiStream(endpoint, payload, (evName, data) => {
|
|
888
|
+
if (evName === "start") {
|
|
889
|
+
state.verifyLogs.push({ stream: "stdout", line: `$ ${data.command}` });
|
|
890
|
+
} else if (evName === "log") {
|
|
891
|
+
state.verifyLogs.push({ stream: data.stream, line: data.line });
|
|
892
|
+
} else if (evName === "done") {
|
|
893
|
+
toast(data.ok ? zh("校验通过", "Verification passed") : zh("校验发现问题,请查看日志", "Verification reported issues"), data.ok ? "ok" : "err");
|
|
894
|
+
} else if (evName === "error") {
|
|
895
|
+
state.verifyLogs.push({ stream: "stderr", line: `Error: ${data.message}` });
|
|
896
|
+
}
|
|
897
|
+
renderHealthPanel();
|
|
898
|
+
});
|
|
899
|
+
} catch (err) {
|
|
900
|
+
toast(err.message, "err");
|
|
901
|
+
} finally {
|
|
902
|
+
state.verifyRunning = false;
|
|
903
|
+
await loadAllData();
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// 12. Panel 2 — Onboarding & Doctor
|
|
908
|
+
async function renderOnboardingPanel() {
|
|
909
|
+
const root = document.getElementById("panel-onboarding");
|
|
910
|
+
root.replaceChildren();
|
|
911
|
+
if (!state.meta) return;
|
|
912
|
+
if (!state.doctor) {
|
|
913
|
+
root.append(el("div", { class: "card", text: zh("正在体检本机工具链...", "Scanning local toolchain...") }));
|
|
914
|
+
await loadDoctorIfNeeded();
|
|
915
|
+
}
|
|
916
|
+
root.replaceChildren();
|
|
917
|
+
|
|
918
|
+
const { dirInfo, catalog, scan, workspace } = state.meta;
|
|
919
|
+
const f = state.onboardingForm;
|
|
920
|
+
const isInitFlow = dirInfo.isEmpty;
|
|
921
|
+
|
|
922
|
+
const bannerMsg =
|
|
923
|
+
dirInfo.kind === "empty"
|
|
924
|
+
? zh("当前为空目录:将采用「绿地新项目初始化 (alh init)」流程。", "Empty directory detected: Greenfield `alh init` flow.")
|
|
925
|
+
: dirInfo.kind === "adopted"
|
|
926
|
+
? zh("当前仓库已接入 AgentLock Harness:你可以预览增量更新或重新配置目标宿主。", "Repository already adopted: preview incremental updates or reconfigure hosts.")
|
|
927
|
+
: zh("检测到存量业务仓库:将采用「零填表无损接入 (alh adopt --lean)」,绝不覆盖既有文档。", "Brownfield repository detected: zero-tax non-destructive `alh adopt --lean` flow.");
|
|
928
|
+
|
|
929
|
+
root.append(el("div", { class: `banner ${dirInfo.kind === "adopted" ? "banner-ok" : "banner-info"}` }, el("span", { text: bannerMsg })));
|
|
930
|
+
|
|
931
|
+
// Wizard Card
|
|
932
|
+
const modeSelect = el(
|
|
933
|
+
"select",
|
|
934
|
+
{
|
|
935
|
+
class: "select",
|
|
936
|
+
onchange: (e) => {
|
|
937
|
+
f.mode = e.target.value;
|
|
938
|
+
state.adoptPreview = null;
|
|
939
|
+
renderOnboardingPanel();
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
catalog.modes.map((m) => el("option", { value: m.id, selected: f.mode === m.id, text: `${m.id} — ${state.lang === "en-US" ? m.enName : m.name}` }))
|
|
943
|
+
);
|
|
944
|
+
|
|
945
|
+
const profileSelect = el(
|
|
946
|
+
"select",
|
|
947
|
+
{
|
|
948
|
+
class: "select",
|
|
949
|
+
onchange: (e) => {
|
|
950
|
+
f.profile = e.target.value;
|
|
951
|
+
state.adoptPreview = null;
|
|
952
|
+
renderOnboardingPanel();
|
|
953
|
+
},
|
|
954
|
+
},
|
|
955
|
+
catalog.profiles.map((p) => el("option", { value: p.value, selected: f.profile === p.value, text: `${p.value} (${p.label})` }))
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
const stackSelect = el(
|
|
959
|
+
"select",
|
|
960
|
+
{
|
|
961
|
+
class: "select",
|
|
962
|
+
onchange: (e) => {
|
|
963
|
+
f.stack = e.target.value;
|
|
964
|
+
state.adoptPreview = null;
|
|
965
|
+
renderOnboardingPanel();
|
|
966
|
+
},
|
|
967
|
+
},
|
|
968
|
+
catalog.stacks.map((s) => el("option", { value: s.value, selected: f.stack === s.value, text: s.label }))
|
|
969
|
+
);
|
|
970
|
+
|
|
971
|
+
const hostPills = el(
|
|
972
|
+
"div",
|
|
973
|
+
{ class: "host-pills" },
|
|
974
|
+
catalog.hosts.map((host) =>
|
|
975
|
+
el(
|
|
976
|
+
"label",
|
|
977
|
+
{ class: "check-pill" },
|
|
978
|
+
el("input", {
|
|
979
|
+
type: "checkbox",
|
|
980
|
+
checked: f.hosts.includes(host),
|
|
981
|
+
onchange: (e) => {
|
|
982
|
+
if (e.target.checked) f.hosts = [...new Set([...f.hosts, host])];
|
|
983
|
+
else f.hosts = f.hosts.filter((x) => x !== host);
|
|
984
|
+
if (f.hosts.length === 0) f.hosts = ["codex"];
|
|
985
|
+
state.adoptPreview = null;
|
|
986
|
+
renderOnboardingPanel();
|
|
987
|
+
},
|
|
988
|
+
}),
|
|
989
|
+
host
|
|
990
|
+
)
|
|
991
|
+
)
|
|
992
|
+
);
|
|
993
|
+
|
|
994
|
+
const optRow = el(
|
|
995
|
+
"div",
|
|
996
|
+
{ class: "host-pills", style: "margin-top:12px" },
|
|
997
|
+
el(
|
|
998
|
+
"label",
|
|
999
|
+
{ class: "check-pill" },
|
|
1000
|
+
el("input", {
|
|
1001
|
+
type: "checkbox",
|
|
1002
|
+
checked: f.lean,
|
|
1003
|
+
onchange: (e) => {
|
|
1004
|
+
f.lean = e.target.checked;
|
|
1005
|
+
state.adoptPreview = null;
|
|
1006
|
+
renderOnboardingPanel();
|
|
1007
|
+
},
|
|
1008
|
+
}),
|
|
1009
|
+
zh("哑铃零税 (--lean,跳过常驻 Skills 税)", "Dumbbell Zero-Tax (--lean)")
|
|
1010
|
+
),
|
|
1011
|
+
el(
|
|
1012
|
+
"label",
|
|
1013
|
+
{ class: "check-pill" },
|
|
1014
|
+
el("input", {
|
|
1015
|
+
type: "checkbox",
|
|
1016
|
+
checked: f.installGitHooks,
|
|
1017
|
+
onchange: (e) => {
|
|
1018
|
+
f.installGitHooks = e.target.checked;
|
|
1019
|
+
state.adoptPreview = null;
|
|
1020
|
+
renderOnboardingPanel();
|
|
1021
|
+
},
|
|
1022
|
+
}),
|
|
1023
|
+
zh("自动挂载通用 Git Hooks", "Auto-install Git Hooks")
|
|
1024
|
+
),
|
|
1025
|
+
el(
|
|
1026
|
+
"label",
|
|
1027
|
+
{ class: "check-pill" },
|
|
1028
|
+
el("input", {
|
|
1029
|
+
type: "checkbox",
|
|
1030
|
+
checked: f.locale === "en-US",
|
|
1031
|
+
onchange: (e) => {
|
|
1032
|
+
f.locale = e.target.checked ? "en-US" : "zh-CN";
|
|
1033
|
+
state.adoptPreview = null;
|
|
1034
|
+
renderOnboardingPanel();
|
|
1035
|
+
},
|
|
1036
|
+
}),
|
|
1037
|
+
"en-US Templates"
|
|
1038
|
+
)
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
const previewBtn = el("button", {
|
|
1042
|
+
type: "button",
|
|
1043
|
+
class: "btn",
|
|
1044
|
+
text: zh("1. 预览变更文件树 (Dry-Run)", "1. Preview Changes (Dry-Run)"),
|
|
1045
|
+
onclick: async () => {
|
|
1046
|
+
try {
|
|
1047
|
+
const endpoint = isInitFlow ? "/api/init/preview" : "/api/adopt/preview";
|
|
1048
|
+
const body = {
|
|
1049
|
+
mode: f.mode,
|
|
1050
|
+
profile: f.profile,
|
|
1051
|
+
stack: f.stack,
|
|
1052
|
+
hosts: f.hosts,
|
|
1053
|
+
lean: f.lean,
|
|
1054
|
+
locale: f.locale,
|
|
1055
|
+
docsStrategy: f.docsStrategy,
|
|
1056
|
+
noGitHooks: !f.installGitHooks,
|
|
1057
|
+
installGitHooks: f.installGitHooks,
|
|
1058
|
+
skipEnvCheck: true,
|
|
1059
|
+
};
|
|
1060
|
+
state.adoptPreview = await api(endpoint, { method: "POST", body });
|
|
1061
|
+
if (state.adoptPreview.ok === false) {
|
|
1062
|
+
toast(state.adoptPreview.error || zh("预览失败", "Preview failed"), "err");
|
|
1063
|
+
} else {
|
|
1064
|
+
toast(zh("只读预览完成,尚未写入或移动任何文件", "Dry-run preview ready (0 files mutated)"), "info");
|
|
1065
|
+
}
|
|
1066
|
+
renderOnboardingPanel();
|
|
1067
|
+
} catch (err) {
|
|
1068
|
+
toast(err.message, "err");
|
|
1069
|
+
}
|
|
1070
|
+
},
|
|
1071
|
+
});
|
|
1072
|
+
|
|
1073
|
+
const isArchiveSwitch = !isInitFlow && f.docsStrategy === "archive-switch";
|
|
1074
|
+
const applyBtn = el("button", {
|
|
1075
|
+
type: "button",
|
|
1076
|
+
class: "btn btn-primary",
|
|
1077
|
+
text: isInitFlow
|
|
1078
|
+
? zh("2. 确认初始化写入", "2. Apply Init")
|
|
1079
|
+
: isArchiveSwitch
|
|
1080
|
+
? zh("2. 确认归档并切换全套体系", "2. Archive & Switch")
|
|
1081
|
+
: zh("2. 确认无损接入写入", "2. Apply Adopt"),
|
|
1082
|
+
onclick: async () => {
|
|
1083
|
+
const cliCmd =
|
|
1084
|
+
state.adoptPreview?.cliCommand ||
|
|
1085
|
+
(isInitFlow
|
|
1086
|
+
? `alh init "${workspace}" --mode ${f.mode} --profile ${f.profile} --stack ${f.stack} --hosts ${f.hosts.join(",")}${f.lean ? " --lean" : ""} -y`
|
|
1087
|
+
: `alh adopt "${workspace}" --hosts ${f.hosts.join(",")}${f.lean ? " --lean" : ""}${isArchiveSwitch ? ` --profile ${f.profile} --docs-strategy archive-switch --confirm-archive` : ""}`);
|
|
1088
|
+
const archivedCount = state.adoptPreview?.archivePlan?.moves?.length ?? scan?.existingDocs?.length ?? 0;
|
|
1089
|
+
const ok = await confirmAction({
|
|
1090
|
+
title: isInitFlow
|
|
1091
|
+
? zh("确认初始化项目脚手架?", "Confirm Project Initialization?")
|
|
1092
|
+
: isArchiveSwitch
|
|
1093
|
+
? zh("二次确认:归档旧文档并切换全套 AgentLock 体系?", "Double-Confirm: Archive Legacy Docs & Switch?")
|
|
1094
|
+
: zh("确认写入 AgentLock Harness 接入文件?", "Confirm Repository Adoption?"),
|
|
1095
|
+
desc: isArchiveSwitch
|
|
1096
|
+
? zh(
|
|
1097
|
+
`将把既有文档(约 ${archivedCount} 项)非破坏性移入 docs/legacy-archive/(自动排除检索,不删除任何文件),生成 Profile=${f.profile} 纯净骨架与「旧文档 × 源码」双向蒸馏 DAG 任务。建议先在独立 Git 分支操作!`,
|
|
1098
|
+
`Safely moves ~${archivedCount} legacy doc item(s) to docs/legacy-archive/ (auto-excluded from validation/search, 0 files deleted), scaffolds Profile=${f.profile}, and seeds dual-source (archive x live code) DAG distillation tasks. Use a dedicated Git branch!`
|
|
1099
|
+
)
|
|
1100
|
+
: zh("将依据所选配置写入受控文件(已存在的用户手写文档不会被覆盖)。", "Writes managed harness files only; existing hand-authored docs are preserved."),
|
|
1101
|
+
cliCommand: cliCmd,
|
|
1102
|
+
});
|
|
1103
|
+
if (!ok) return;
|
|
1104
|
+
try {
|
|
1105
|
+
const endpoint = isInitFlow ? "/api/init/apply" : "/api/adopt/apply";
|
|
1106
|
+
const res = await api(endpoint, {
|
|
1107
|
+
method: "POST",
|
|
1108
|
+
body: {
|
|
1109
|
+
confirmed: true,
|
|
1110
|
+
confirmArchive: isArchiveSwitch,
|
|
1111
|
+
docsStrategy: f.docsStrategy,
|
|
1112
|
+
mode: f.mode,
|
|
1113
|
+
profile: f.profile,
|
|
1114
|
+
stack: f.stack,
|
|
1115
|
+
hosts: f.hosts,
|
|
1116
|
+
lean: f.lean,
|
|
1117
|
+
locale: f.locale,
|
|
1118
|
+
noGitHooks: !f.installGitHooks,
|
|
1119
|
+
installGitHooks: f.installGitHooks,
|
|
1120
|
+
skipEnvCheck: true,
|
|
1121
|
+
},
|
|
1122
|
+
});
|
|
1123
|
+
state.adoptPreview = res;
|
|
1124
|
+
toast(
|
|
1125
|
+
isArchiveSwitch
|
|
1126
|
+
? zh("归档切换完成!已生成 MIGRATION_PLAN.md 与双向蒸馏 DAG 任务。", "Archive-switch complete! MIGRATION_PLAN.md & DAG tasks created.")
|
|
1127
|
+
: zh("写入完成!已刷新项目健康度。", "Applied successfully! Health refreshed."),
|
|
1128
|
+
"ok"
|
|
1129
|
+
);
|
|
1130
|
+
await loadAllData();
|
|
1131
|
+
} catch (err) {
|
|
1132
|
+
toast(err.message, "err");
|
|
1133
|
+
}
|
|
1134
|
+
},
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
const previewSection = (() => {
|
|
1138
|
+
if (!state.adoptPreview) return null;
|
|
1139
|
+
if (state.adoptPreview.ok === false) {
|
|
1140
|
+
return el("div", { class: "banner banner-error", style: "margin-top:14px" }, el("span", { text: state.adoptPreview.error || "Preview blocked" }));
|
|
1141
|
+
}
|
|
1142
|
+
const isDry = Boolean(state.adoptPreview.dryRun);
|
|
1143
|
+
const files = isDry
|
|
1144
|
+
? state.adoptPreview.harnessPlanned ||
|
|
1145
|
+
(state.adoptPreview.harnessResult?.actions || [])
|
|
1146
|
+
.filter((a) => a.action === "create" || a.action === "update")
|
|
1147
|
+
.map((a) => a.path)
|
|
1148
|
+
: state.adoptPreview.harnessWritten || state.adoptPreview.harnessResult?.writtenFiles || [];
|
|
1149
|
+
const ruleFiles = state.adoptPreview.rulesResult?.written || state.adoptPreview.rulesResult?.plannedStarterRules || [];
|
|
1150
|
+
const ap = state.adoptPreview.archivePlan;
|
|
1151
|
+
const blocks = [];
|
|
1152
|
+
|
|
1153
|
+
if (ap && ap.ok) {
|
|
1154
|
+
blocks.push(
|
|
1155
|
+
el(
|
|
1156
|
+
"div",
|
|
1157
|
+
{ style: "display:flex;flex-direction:column;gap:6px" },
|
|
1158
|
+
el(
|
|
1159
|
+
"div",
|
|
1160
|
+
{ class: "meter-meta" },
|
|
1161
|
+
el("strong", { text: zh(`归档移动计划 → ${ap.archiveDir}/(自动加入 docs.config.json exclude)`, `Archive Move Plan → ${ap.archiveDir}/ (auto-excluded)`) }),
|
|
1162
|
+
el("span", { class: "pill pill-warn", text: `${ap.moves.length} ${zh("项移动", "moves")}` })
|
|
1163
|
+
),
|
|
1164
|
+
el(
|
|
1165
|
+
"div",
|
|
1166
|
+
{ class: "file-tree" },
|
|
1167
|
+
ap.moves.length === 0
|
|
1168
|
+
? el("span", { text: zh("(无需要移动的既有旧文档)", "(No legacy docs to move)") })
|
|
1169
|
+
: ap.moves.map((m) => el("div", { text: `→ ${m.from} ⇒ ${m.to}` }))
|
|
1170
|
+
)
|
|
1171
|
+
)
|
|
1172
|
+
);
|
|
1173
|
+
if (ap.plannedTasks?.length > 0) {
|
|
1174
|
+
blocks.push(
|
|
1175
|
+
el(
|
|
1176
|
+
"div",
|
|
1177
|
+
{ style: "display:flex;flex-direction:column;gap:6px" },
|
|
1178
|
+
el(
|
|
1179
|
+
"div",
|
|
1180
|
+
{ class: "meter-meta" },
|
|
1181
|
+
el("strong", { text: zh("将自动创建的「旧文档 × 源码」双向蒸馏 DAG 任务", "Planned Dual-Source Distillation DAG Tasks") }),
|
|
1182
|
+
el("span", { class: "pill pill-accent", text: `${ap.plannedTasks.length} tasks` })
|
|
1183
|
+
),
|
|
1184
|
+
el(
|
|
1185
|
+
"div",
|
|
1186
|
+
{ class: "file-tree" },
|
|
1187
|
+
ap.plannedTasks.map((tk) => el("div", { text: `[${tk.priority}] ${tk.title}` }))
|
|
1188
|
+
)
|
|
1189
|
+
)
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
blocks.push(
|
|
1195
|
+
el(
|
|
1196
|
+
"div",
|
|
1197
|
+
{ style: "display:flex;flex-direction:column;gap:6px" },
|
|
1198
|
+
el(
|
|
1199
|
+
"div",
|
|
1200
|
+
{ class: "meter-meta" },
|
|
1201
|
+
el("strong", { text: isDry ? zh("预览计划写入受控文件", "Planned Managed Files (Dry-Run)") : zh("实际已写入受控文件", "Written Managed Files") }),
|
|
1202
|
+
el("span", { class: "pill pill-accent", text: `${files.length + ruleFiles.length} ${zh("份", "files")}` })
|
|
1203
|
+
),
|
|
1204
|
+
el(
|
|
1205
|
+
"div",
|
|
1206
|
+
{ class: "file-tree" },
|
|
1207
|
+
files.length + ruleFiles.length === 0
|
|
1208
|
+
? el("span", { text: zh("(所有受控文件均为最新,无需变更)", "(All managed files up to date)") })
|
|
1209
|
+
: [...files, ...ruleFiles].map((p) => el("div", { text: `+ ${p}` }))
|
|
1210
|
+
)
|
|
1211
|
+
)
|
|
1212
|
+
);
|
|
1213
|
+
|
|
1214
|
+
return el("div", { style: "margin-top:14px;display:flex;flex-direction:column;gap:12px" }, blocks);
|
|
1215
|
+
})();
|
|
1216
|
+
|
|
1217
|
+
const selectedModeObj = catalog.modes.find((m) => m.id === f.mode);
|
|
1218
|
+
const selectedProfileObj = catalog.profiles.find((p) => p.value === f.profile);
|
|
1219
|
+
const profileDocsHint =
|
|
1220
|
+
selectedProfileObj?.docs?.length > 0
|
|
1221
|
+
? `${zh("额外注入专题模板", "Adds topic templates")}: ${selectedProfileObj.docs.join(", ")}`
|
|
1222
|
+
: zh("0 份额外空壳专题(仅核心入口与只读工具,存量仓防冗余首选)", "0 extra topic templates (lean core entries only; best for brownfield)");
|
|
1223
|
+
|
|
1224
|
+
const strategyPicker =
|
|
1225
|
+
!isInitFlow && scan?.hasLegacyDocs
|
|
1226
|
+
? el(
|
|
1227
|
+
"div",
|
|
1228
|
+
{ style: "margin-top:14px" },
|
|
1229
|
+
el("div", {
|
|
1230
|
+
class: "field-label",
|
|
1231
|
+
text: zh(
|
|
1232
|
+
`检测到存量旧文档(docs/ 下 ${scan.existingDocs?.length || 0} 份${scan.hasUntrackedCoreDocs ? " + 根入口文档" : ""})— 请选择接入策略`,
|
|
1233
|
+
`Existing legacy docs detected (${scan.existingDocs?.length || 0} in docs/${scan.hasUntrackedCoreDocs ? " + root entries" : ""}) — Choose Strategy`
|
|
1234
|
+
),
|
|
1235
|
+
}),
|
|
1236
|
+
el(
|
|
1237
|
+
"div",
|
|
1238
|
+
{ class: "strategy-grid" },
|
|
1239
|
+
el(
|
|
1240
|
+
"button",
|
|
1241
|
+
{
|
|
1242
|
+
type: "button",
|
|
1243
|
+
class: `strategy-card ${f.docsStrategy === "thin-route" ? "active" : ""}`,
|
|
1244
|
+
onclick: () => {
|
|
1245
|
+
f.docsStrategy = "thin-route";
|
|
1246
|
+
f.profile = "minimal";
|
|
1247
|
+
state.adoptPreview = null;
|
|
1248
|
+
renderOnboardingPanel();
|
|
1249
|
+
},
|
|
1250
|
+
},
|
|
1251
|
+
el(
|
|
1252
|
+
"div",
|
|
1253
|
+
{ class: "strategy-title" },
|
|
1254
|
+
el("span", { text: zh("策略 1:薄路由保留旧文档", "Strategy 1: Thin-Route (Preserve)") }),
|
|
1255
|
+
el("span", { class: "pill pill-ok", text: zh("推荐默认", "Recommended") })
|
|
1256
|
+
),
|
|
1257
|
+
el("div", {
|
|
1258
|
+
class: "strategy-desc",
|
|
1259
|
+
text: zh(
|
|
1260
|
+
"绝不移动或覆盖原有文档,自动降级为 minimal 避免生成平行空壳模板;在 00-context.md 建立旧文档索引,立即启用全部 0 Token 护栏。",
|
|
1261
|
+
"Leaves existing docs untouched, locks minimal to avoid duplicate Drafts, indexes existing docs in 00-context.md, and enables all zero-token guardrails."
|
|
1262
|
+
),
|
|
1263
|
+
})
|
|
1264
|
+
),
|
|
1265
|
+
el(
|
|
1266
|
+
"button",
|
|
1267
|
+
{
|
|
1268
|
+
type: "button",
|
|
1269
|
+
class: `strategy-card ${f.docsStrategy === "archive-switch" ? "active-warn" : ""}`,
|
|
1270
|
+
onclick: () => {
|
|
1271
|
+
f.docsStrategy = "archive-switch";
|
|
1272
|
+
if (f.profile === "minimal" && scan.stackSuggestedProfile) {
|
|
1273
|
+
f.profile = scan.stackSuggestedProfile;
|
|
1274
|
+
}
|
|
1275
|
+
state.adoptPreview = null;
|
|
1276
|
+
renderOnboardingPanel();
|
|
1277
|
+
},
|
|
1278
|
+
},
|
|
1279
|
+
el(
|
|
1280
|
+
"div",
|
|
1281
|
+
{ class: "strategy-title" },
|
|
1282
|
+
el("span", { text: zh("策略 2:归档隔离 + 双向蒸馏切换", "Strategy 2: Archive & Cross-Distill") }),
|
|
1283
|
+
el("span", { class: "pill pill-warn", text: zh("需二次确认", "Confirm Required") })
|
|
1284
|
+
),
|
|
1285
|
+
el("div", {
|
|
1286
|
+
class: "strategy-desc",
|
|
1287
|
+
text: zh(
|
|
1288
|
+
"将旧文档非破坏性移入 docs/legacy-archive/(自动排除检索防错乱),按所选领域模板建新骨架,并生成「旧文档 × 源码」双向蒸馏 DAG 任务(绝不盲信代码把 Bug 洗白成规范)。",
|
|
1289
|
+
"Safely moves old docs to docs/legacy-archive/ (auto-excluded), scaffolds chosen Domain Profile, and seeds Archive x Live-Code DAG distillation tasks."
|
|
1290
|
+
),
|
|
1291
|
+
})
|
|
1292
|
+
)
|
|
1293
|
+
),
|
|
1294
|
+
f.docsStrategy === "archive-switch"
|
|
1295
|
+
? el(
|
|
1296
|
+
"div",
|
|
1297
|
+
{ class: "banner banner-warn", style: "margin-top:10px" },
|
|
1298
|
+
el("span", {
|
|
1299
|
+
text: zh(
|
|
1300
|
+
"提醒:归档移动会改变原 docs/ 路径,可能影响外部链接或静态站构建。强烈建议先切独立 Git 分支,并先点「1. 预览变更文件树」核对移动清单。",
|
|
1301
|
+
"Notice: Moving docs/ may affect external links or static-site builds. Switch to a dedicated Git branch and click Preview first."
|
|
1302
|
+
),
|
|
1303
|
+
})
|
|
1304
|
+
)
|
|
1305
|
+
: null
|
|
1306
|
+
)
|
|
1307
|
+
: null;
|
|
1308
|
+
|
|
1309
|
+
const defaultCli = isInitFlow
|
|
1310
|
+
? `alh init "${workspace}" --mode ${f.mode} --profile ${f.profile} --stack ${f.stack} --hosts ${f.hosts.join(",")}${f.lean ? " --lean" : ""}${f.installGitHooks ? " --install-git-hooks" : ""} -y`
|
|
1311
|
+
: `alh adopt "${workspace}"${f.lean ? " --lean" : ""} --hosts ${f.hosts.join(",")}${f.mode !== "dual-core" ? ` --mode ${f.mode}` : ""}${isArchiveSwitch ? ` --profile ${f.profile} --docs-strategy archive-switch --confirm-archive` : ""}${!f.installGitHooks ? " --no-git-hooks" : ""}`;
|
|
1312
|
+
|
|
1313
|
+
root.append(
|
|
1314
|
+
el(
|
|
1315
|
+
"div",
|
|
1316
|
+
{ class: "card" },
|
|
1317
|
+
el(
|
|
1318
|
+
"div",
|
|
1319
|
+
{ class: "card-header" },
|
|
1320
|
+
el(
|
|
1321
|
+
"div",
|
|
1322
|
+
{},
|
|
1323
|
+
el("h2", { class: "card-title", text: isInitFlow ? zh("绿地项目初始化向导", "Greenfield Init Wizard") : zh("存量仓库零税接入向导", "Brownfield Adoption Wizard") }),
|
|
1324
|
+
el("p", {
|
|
1325
|
+
class: "card-desc",
|
|
1326
|
+
text: `${zh("探测技术栈", "Detected stack")}: ${(scan?.detectedStacks || []).map((s) => s.label).join(" + ") || "Custom"} | test: ${scan?.commands?.test || "—"}`,
|
|
1327
|
+
})
|
|
1328
|
+
),
|
|
1329
|
+
el("div", { class: "card-actions" }, previewBtn, applyBtn)
|
|
1330
|
+
),
|
|
1331
|
+
strategyPicker,
|
|
1332
|
+
el(
|
|
1333
|
+
"div",
|
|
1334
|
+
{ class: "form-grid", style: "margin-top:14px" },
|
|
1335
|
+
el(
|
|
1336
|
+
"label",
|
|
1337
|
+
{ class: "field" },
|
|
1338
|
+
el("span", { class: "field-label", text: zh("工程模式 (Mode)", "Harness Mode") }),
|
|
1339
|
+
modeSelect,
|
|
1340
|
+
selectedModeObj ? el("span", { class: "field-hint", text: selectedModeObj.description }) : null
|
|
1341
|
+
),
|
|
1342
|
+
el(
|
|
1343
|
+
"label",
|
|
1344
|
+
{ class: "field" },
|
|
1345
|
+
el("span", { class: "field-label", text: zh("领域模板 (Profile)", "Domain Profile") }),
|
|
1346
|
+
profileSelect,
|
|
1347
|
+
el("span", { class: "field-hint", text: profileDocsHint })
|
|
1348
|
+
),
|
|
1349
|
+
isInitFlow ? el("label", { class: "field" }, el("span", { class: "field-label", text: zh("技术栈 (Stack)", "Tech Stack") }), stackSelect) : el("div", {})
|
|
1350
|
+
),
|
|
1351
|
+
el("div", { style: "margin-top:12px" }, el("div", { class: "field-label", style: "margin-bottom:6px", text: zh("目标 AI 宿主(建议 --lean 仅选主力宿主)", "Target AI Hosts (keep lean)") }), hostPills),
|
|
1352
|
+
optRow,
|
|
1353
|
+
previewSection,
|
|
1354
|
+
cliDisclosure(state.adoptPreview?.cliCommand || defaultCli)
|
|
1355
|
+
)
|
|
1356
|
+
);
|
|
1357
|
+
|
|
1358
|
+
// Doctor Card
|
|
1359
|
+
const doc = state.doctor;
|
|
1360
|
+
const activePkgManagers = Array.isArray(doc.pkgManagers)
|
|
1361
|
+
? doc.pkgManagers
|
|
1362
|
+
: Object.entries(doc.pkgManagers || {})
|
|
1363
|
+
.filter(([, ok]) => Boolean(ok))
|
|
1364
|
+
.map(([name]) => name);
|
|
1365
|
+
root.append(
|
|
1366
|
+
el(
|
|
1367
|
+
"div",
|
|
1368
|
+
{ class: "card" },
|
|
1369
|
+
el(
|
|
1370
|
+
"div",
|
|
1371
|
+
{ class: "card-header" },
|
|
1372
|
+
el(
|
|
1373
|
+
"div",
|
|
1374
|
+
{},
|
|
1375
|
+
el("h2", { class: "card-title", text: zh("本机工具链与 AI CLI 体检 (alh doctor)", "Local Toolchain & CLI Doctor") }),
|
|
1376
|
+
el("p", { class: "card-desc", text: `${doc.platform} (${doc.arch}) · Package Managers: ${activePkgManagers.join(", ") || "none"}` })
|
|
1377
|
+
),
|
|
1378
|
+
el("button", {
|
|
1379
|
+
type: "button",
|
|
1380
|
+
class: "btn btn-sm",
|
|
1381
|
+
text: zh("重新体检", "Re-scan"),
|
|
1382
|
+
onclick: async () => {
|
|
1383
|
+
await loadDoctorIfNeeded(true);
|
|
1384
|
+
renderOnboardingPanel();
|
|
1385
|
+
},
|
|
1386
|
+
})
|
|
1387
|
+
),
|
|
1388
|
+
el(
|
|
1389
|
+
"div",
|
|
1390
|
+
{ class: "doctor-grid" },
|
|
1391
|
+
(doc.tools || []).map((tool) =>
|
|
1392
|
+
el(
|
|
1393
|
+
"div",
|
|
1394
|
+
{ class: "doctor-card" },
|
|
1395
|
+
el(
|
|
1396
|
+
"div",
|
|
1397
|
+
{ class: "kpi-head" },
|
|
1398
|
+
el("strong", { text: tool.name }),
|
|
1399
|
+
el("span", { class: `pill ${tool.installed ? "pill-ok" : "pill-warn"}`, text: tool.installed ? zh("已就绪", "Ready") : zh("缺失", "Missing") })
|
|
1400
|
+
),
|
|
1401
|
+
el("div", { class: "mono-xs", style: "color:var(--text-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap", text: tool.installed ? tool.version || tool.cmd : tool.resolvedInstallCmd || "Manual install" }),
|
|
1402
|
+
!tool.installed && tool.resolvedInstallCmd
|
|
1403
|
+
? el("button", {
|
|
1404
|
+
type: "button",
|
|
1405
|
+
class: "btn btn-xs",
|
|
1406
|
+
style: "margin-top:4px;align-self:flex-start",
|
|
1407
|
+
text: zh("一键安装", "Install"),
|
|
1408
|
+
onclick: async () => {
|
|
1409
|
+
const ok = await confirmAction({
|
|
1410
|
+
title: `${zh("安装工具", "Install")} ${tool.name}?`,
|
|
1411
|
+
desc: zh("将在本机执行以下安装命令,请确认安全后再继续。", "Executes the install command below on this machine."),
|
|
1412
|
+
cliCommand: tool.resolvedInstallCmd,
|
|
1413
|
+
});
|
|
1414
|
+
if (!ok) return;
|
|
1415
|
+
try {
|
|
1416
|
+
toast(`${zh("正在安装", "Installing")} ${tool.id}...`, "info");
|
|
1417
|
+
const res = await api("/api/doctor/install", { method: "POST", body: { toolId: tool.id } });
|
|
1418
|
+
toast(res.ok ? `${tool.id} ${zh("安装成功", "installed")}` : `${tool.id} ${zh("安装失败", "failed")}: ${res.stderr || ""}`, res.ok ? "ok" : "err");
|
|
1419
|
+
await loadDoctorIfNeeded(true);
|
|
1420
|
+
renderOnboardingPanel();
|
|
1421
|
+
} catch (err) {
|
|
1422
|
+
toast(err.message, "err");
|
|
1423
|
+
}
|
|
1424
|
+
},
|
|
1425
|
+
})
|
|
1426
|
+
: null
|
|
1427
|
+
)
|
|
1428
|
+
)
|
|
1429
|
+
),
|
|
1430
|
+
cliDisclosure("alh doctor --fix")
|
|
1431
|
+
)
|
|
1432
|
+
);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// 13. Panel 3 — Spec Change Board & DAG Ledger
|
|
1436
|
+
function renderChangesPanel() {
|
|
1437
|
+
const root = document.getElementById("panel-changes");
|
|
1438
|
+
root.replaceChildren();
|
|
1439
|
+
|
|
1440
|
+
const { active, archived } = state.changes;
|
|
1441
|
+
const detail = state.changeDetail;
|
|
1442
|
+
|
|
1443
|
+
// Left List
|
|
1444
|
+
const listCard = el(
|
|
1445
|
+
"div",
|
|
1446
|
+
{ class: "card" },
|
|
1447
|
+
el(
|
|
1448
|
+
"div",
|
|
1449
|
+
{ class: "card-header" },
|
|
1450
|
+
el("h2", { class: "card-title", text: zh("变更包列表", "Changes") }),
|
|
1451
|
+
el("button", {
|
|
1452
|
+
type: "button",
|
|
1453
|
+
class: "btn btn-primary btn-xs",
|
|
1454
|
+
text: zh("+ 新建", "+ New"),
|
|
1455
|
+
onclick: () => {
|
|
1456
|
+
document.getElementById("new-change-error").hidden = true;
|
|
1457
|
+
document.getElementById("input-change-slug").value = "";
|
|
1458
|
+
document.getElementById("input-change-title").value = "";
|
|
1459
|
+
document.getElementById("dialog-new-change").showModal();
|
|
1460
|
+
},
|
|
1461
|
+
})
|
|
1462
|
+
),
|
|
1463
|
+
active.length === 0
|
|
1464
|
+
? el("div", { class: "empty-state", text: zh("暂无活跃变更包。点击「+ 新建」开启轻量 Spec 变更流。", "No active changes. Click '+ New' to start a lightweight change flow.") })
|
|
1465
|
+
: el(
|
|
1466
|
+
"div",
|
|
1467
|
+
{ class: "item-list" },
|
|
1468
|
+
active.map((ch) =>
|
|
1469
|
+
el(
|
|
1470
|
+
"button",
|
|
1471
|
+
{
|
|
1472
|
+
type: "button",
|
|
1473
|
+
class: `change-nav-btn ${ch.slug === state.selectedSlug ? "active" : ""}`,
|
|
1474
|
+
onclick: async () => {
|
|
1475
|
+
state.selectedSlug = ch.slug;
|
|
1476
|
+
await loadChangeDetail(ch.slug);
|
|
1477
|
+
renderChangesPanel();
|
|
1478
|
+
},
|
|
1479
|
+
},
|
|
1480
|
+
el(
|
|
1481
|
+
"div",
|
|
1482
|
+
{ class: "kpi-head" },
|
|
1483
|
+
el("strong", { class: "mono-xs", text: ch.slug }),
|
|
1484
|
+
el("span", {
|
|
1485
|
+
class: `pill ${ch.readyToArchive ? "pill-ok" : "pill-warn"}`,
|
|
1486
|
+
text: `${ch.acceptance.checked}/${ch.acceptance.total}`,
|
|
1487
|
+
})
|
|
1488
|
+
),
|
|
1489
|
+
el("span", { style: "font-size:12px;color:var(--text-muted)", text: ch.readyToArchive ? zh("可归档沉淀 SPEC", "Ready to archive") : zh("待完成验收项", "Pending acceptance") })
|
|
1490
|
+
)
|
|
1491
|
+
)
|
|
1492
|
+
),
|
|
1493
|
+
archived.length > 0
|
|
1494
|
+
? el(
|
|
1495
|
+
"div",
|
|
1496
|
+
{ style: "margin-top:14px" },
|
|
1497
|
+
el("div", { class: "field-label", style: "margin-bottom:6px", text: `${zh("已归档", "Archived")} (${archived.length})` }),
|
|
1498
|
+
el(
|
|
1499
|
+
"div",
|
|
1500
|
+
{ class: "item-list" },
|
|
1501
|
+
archived.slice(0, 6).map((name) => el("div", { class: "list-row mono-xs", text: name }))
|
|
1502
|
+
)
|
|
1503
|
+
)
|
|
1504
|
+
: null
|
|
1505
|
+
);
|
|
1506
|
+
|
|
1507
|
+
// Right Editor
|
|
1508
|
+
let editorCard;
|
|
1509
|
+
if (!detail) {
|
|
1510
|
+
editorCard = el(
|
|
1511
|
+
"div",
|
|
1512
|
+
{ class: "card" },
|
|
1513
|
+
el("div", { class: "empty-state", text: zh("请在左侧选择或创建一个活跃变更包,以编辑 delta.md 并勾选 acceptance.md。", "Select or create an active change on the left to edit delta.md and check off acceptance.md.") })
|
|
1514
|
+
);
|
|
1515
|
+
} else {
|
|
1516
|
+
const deltaArea = el("textarea", { class: "textarea", value: detail.delta });
|
|
1517
|
+
const allChecked = detail.readyToArchive;
|
|
1518
|
+
const saveDeltaBtn = el("button", {
|
|
1519
|
+
type: "button",
|
|
1520
|
+
class: "btn btn-sm",
|
|
1521
|
+
text: zh("保存 delta.md", "Save delta.md"),
|
|
1522
|
+
onclick: async () => {
|
|
1523
|
+
try {
|
|
1524
|
+
const res = await api(`/api/changes/${encodeURIComponent(detail.slug)}`, {
|
|
1525
|
+
method: "PUT",
|
|
1526
|
+
body: { delta: deltaArea.value },
|
|
1527
|
+
});
|
|
1528
|
+
state.changeDetail = res.change;
|
|
1529
|
+
toast(zh("已保存 delta.md", "Saved delta.md"), "ok");
|
|
1530
|
+
} catch (err) {
|
|
1531
|
+
toast(err.message, "err");
|
|
1532
|
+
}
|
|
1533
|
+
},
|
|
1534
|
+
});
|
|
1535
|
+
|
|
1536
|
+
const archiveBtn = el("button", {
|
|
1537
|
+
type: "button",
|
|
1538
|
+
class: `btn btn-sm ${allChecked ? "btn-success" : ""}`,
|
|
1539
|
+
disabled: !allChecked,
|
|
1540
|
+
text: zh("归档并沉淀至 SPEC.md", "Archive & Crystallize SPEC.md"),
|
|
1541
|
+
onclick: async () => {
|
|
1542
|
+
const ok = await confirmAction({
|
|
1543
|
+
title: `${zh("归档变更包", "Archive Change")} "${detail.slug}"?`,
|
|
1544
|
+
desc: zh("将归档至 changes/archive/ 并自动把验证通过的契约沉淀至 docs/06-dev-guide/SPEC.md。", "Moves change to archive/ and crystallizes verified contracts into docs/06-dev-guide/SPEC.md."),
|
|
1545
|
+
cliCommand: `alh change archive ${detail.slug}`,
|
|
1546
|
+
});
|
|
1547
|
+
if (!ok) return;
|
|
1548
|
+
try {
|
|
1549
|
+
const res = await api(`/api/changes/${encodeURIComponent(detail.slug)}/archive`, {
|
|
1550
|
+
method: "POST",
|
|
1551
|
+
body: { syncSpec: true },
|
|
1552
|
+
});
|
|
1553
|
+
toast(zh(`归档成功!已同步 ${res.specSync?.path || "SPEC.md"}`, `Archived & synced ${res.specSync?.path || "SPEC.md"}`), "ok");
|
|
1554
|
+
state.selectedSlug = null;
|
|
1555
|
+
await loadAllData();
|
|
1556
|
+
} catch (err) {
|
|
1557
|
+
toast(err.message, "err");
|
|
1558
|
+
}
|
|
1559
|
+
},
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1562
|
+
const checklistEl =
|
|
1563
|
+
detail.checklist.length === 0
|
|
1564
|
+
? el("div", { class: "empty-state", text: zh("acceptance.md 中尚未定义 - [ ] 复选框条目。", "No - [ ] checklist items found in acceptance.md.") })
|
|
1565
|
+
: el(
|
|
1566
|
+
"div",
|
|
1567
|
+
{ class: "ac-list" },
|
|
1568
|
+
detail.checklist.map((item) =>
|
|
1569
|
+
el(
|
|
1570
|
+
"label",
|
|
1571
|
+
{ class: `ac-item ${item.checked ? "checked" : ""}` },
|
|
1572
|
+
el("input", {
|
|
1573
|
+
type: "checkbox",
|
|
1574
|
+
checked: item.checked,
|
|
1575
|
+
onchange: async (e) => {
|
|
1576
|
+
try {
|
|
1577
|
+
const res = await api(`/api/changes/${encodeURIComponent(detail.slug)}`, {
|
|
1578
|
+
method: "PUT",
|
|
1579
|
+
body: { toggleLineIndex: item.lineIndex, checked: e.target.checked },
|
|
1580
|
+
});
|
|
1581
|
+
state.changeDetail = res.change;
|
|
1582
|
+
const listRes = await api("/api/changes");
|
|
1583
|
+
state.changes = { active: listRes.active || [], archived: listRes.archived || [] };
|
|
1584
|
+
renderChangesPanel();
|
|
1585
|
+
} catch (err) {
|
|
1586
|
+
toast(err.message, "err");
|
|
1587
|
+
}
|
|
1588
|
+
},
|
|
1589
|
+
}),
|
|
1590
|
+
el("span", { class: "ac-text", text: item.text })
|
|
1591
|
+
)
|
|
1592
|
+
)
|
|
1593
|
+
);
|
|
1594
|
+
|
|
1595
|
+
editorCard = el(
|
|
1596
|
+
"div",
|
|
1597
|
+
{ class: "card" },
|
|
1598
|
+
el(
|
|
1599
|
+
"div",
|
|
1600
|
+
{ class: "card-header" },
|
|
1601
|
+
el(
|
|
1602
|
+
"div",
|
|
1603
|
+
{},
|
|
1604
|
+
el("h2", { class: "card-title mono", text: detail.slug }),
|
|
1605
|
+
el("p", {
|
|
1606
|
+
class: "card-desc",
|
|
1607
|
+
text: `${zh("验收进度", "Acceptance")}: ${detail.acceptance.checked}/${detail.acceptance.total}${allChecked ? zh(" · 已全部勾选,可归档!", " · All checked, ready to archive!") : ""}`,
|
|
1608
|
+
})
|
|
1609
|
+
),
|
|
1610
|
+
el("div", { class: "card-actions" }, saveDeltaBtn, archiveBtn)
|
|
1611
|
+
),
|
|
1612
|
+
el(
|
|
1613
|
+
"div",
|
|
1614
|
+
{ class: "grid-2" },
|
|
1615
|
+
el("div", { class: "field" }, el("span", { class: "field-label", text: "delta.md" }), deltaArea),
|
|
1616
|
+
el("div", { class: "field" }, el("span", { class: "field-label", text: "acceptance.md" }), checklistEl)
|
|
1617
|
+
),
|
|
1618
|
+
cliDisclosure(`alh change status ${detail.slug} && alh change archive ${detail.slug}`)
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
root.append(el("div", { class: "grid-split" }, listCard, editorCard));
|
|
1623
|
+
|
|
1624
|
+
// DAG Task Ledger Card
|
|
1625
|
+
const td = state.tasksData;
|
|
1626
|
+
const titleInput = el("input", { class: "input", placeholder: zh("新任务标题...", "New task title...") });
|
|
1627
|
+
const prioSelect = el(
|
|
1628
|
+
"select",
|
|
1629
|
+
{ class: "select", style: "width:90px" },
|
|
1630
|
+
["P0", "P1", "P2"].map((p) => el("option", { value: p, selected: p === "P1", text: p }))
|
|
1631
|
+
);
|
|
1632
|
+
const depsInput = el("input", { class: "input mono", style: "width:160px", placeholder: zh("依赖 ID (如 T-001)", "Depends (e.g. T-001)") });
|
|
1633
|
+
const addTaskBtn = el("button", {
|
|
1634
|
+
type: "button",
|
|
1635
|
+
class: "btn btn-primary btn-sm",
|
|
1636
|
+
text: zh("添加任务", "Add Task"),
|
|
1637
|
+
onclick: async () => {
|
|
1638
|
+
const title = titleInput.value.trim();
|
|
1639
|
+
if (!title) return;
|
|
1640
|
+
try {
|
|
1641
|
+
await api("/api/tasks", {
|
|
1642
|
+
method: "POST",
|
|
1643
|
+
body: { title, priority: prioSelect.value, dependsOn: depsInput.value, change: state.selectedSlug },
|
|
1644
|
+
});
|
|
1645
|
+
toast(zh("已添加 DAG 任务", "DAG task added"), "ok");
|
|
1646
|
+
await loadAllData();
|
|
1647
|
+
} catch (err) {
|
|
1648
|
+
toast(err.message, "err");
|
|
1649
|
+
}
|
|
1650
|
+
},
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
const taskRows =
|
|
1654
|
+
td.tasks.length === 0
|
|
1655
|
+
? el("div", { class: "empty-state", text: zh("DAG 任务账本为空。适合多步骤依赖任务调度与 Ralph 循环。", "DAG task ledger is empty.") })
|
|
1656
|
+
: el(
|
|
1657
|
+
"div",
|
|
1658
|
+
{ class: "item-list" },
|
|
1659
|
+
td.tasks.map((task) => {
|
|
1660
|
+
const stClass = task.status === "done" ? "pill-ok" : task.status === "blocked" ? "pill-err" : task.isReady ? "pill-accent" : "pill-muted";
|
|
1661
|
+
const acts = [];
|
|
1662
|
+
if (task.status === "todo" && task.isReady) {
|
|
1663
|
+
acts.push(
|
|
1664
|
+
el("button", {
|
|
1665
|
+
type: "button",
|
|
1666
|
+
class: "btn btn-xs",
|
|
1667
|
+
text: "Claim",
|
|
1668
|
+
onclick: () => doTaskAction(task.id, "claim"),
|
|
1669
|
+
})
|
|
1670
|
+
);
|
|
1671
|
+
}
|
|
1672
|
+
if (task.status === "in_progress" || task.status === "todo") {
|
|
1673
|
+
acts.push(
|
|
1674
|
+
el("button", {
|
|
1675
|
+
type: "button",
|
|
1676
|
+
class: "btn btn-success btn-xs",
|
|
1677
|
+
text: "Done",
|
|
1678
|
+
onclick: () => doTaskAction(task.id, "done"),
|
|
1679
|
+
})
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
if (task.status === "in_progress" || task.status === "blocked") {
|
|
1683
|
+
acts.push(
|
|
1684
|
+
el("button", {
|
|
1685
|
+
type: "button",
|
|
1686
|
+
class: "btn btn-ghost btn-xs",
|
|
1687
|
+
text: "Release",
|
|
1688
|
+
onclick: () => doTaskAction(task.id, "release"),
|
|
1689
|
+
})
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
return el(
|
|
1693
|
+
"div",
|
|
1694
|
+
{ class: "list-row" },
|
|
1695
|
+
el(
|
|
1696
|
+
"div",
|
|
1697
|
+
{ style: "display:flex;align-items:center;gap:8px;flex-wrap:wrap" },
|
|
1698
|
+
el("span", { class: "mono-xs", style: "font-weight:700", text: task.id }),
|
|
1699
|
+
el("span", { class: "pill pill-muted", text: task.priority }),
|
|
1700
|
+
el("span", { class: `pill ${stClass}`, text: task.isReady && task.status === "todo" ? "ready" : task.status }),
|
|
1701
|
+
el("span", { text: task.title }),
|
|
1702
|
+
task.dependsOn?.length ? el("span", { class: "mono-xs", style: "color:var(--text-muted)", text: `← ${task.dependsOn.join(", ")}` }) : null
|
|
1703
|
+
),
|
|
1704
|
+
el("div", { class: "card-actions" }, acts)
|
|
1705
|
+
);
|
|
1706
|
+
})
|
|
1707
|
+
);
|
|
1708
|
+
|
|
1709
|
+
root.append(
|
|
1710
|
+
el(
|
|
1711
|
+
"div",
|
|
1712
|
+
{ class: "card" },
|
|
1713
|
+
el(
|
|
1714
|
+
"div",
|
|
1715
|
+
{ class: "card-header" },
|
|
1716
|
+
el(
|
|
1717
|
+
"div",
|
|
1718
|
+
{},
|
|
1719
|
+
el("h2", { class: "card-title", text: zh("零依赖 DAG 任务账本 (alh task)", "Zero-DB DAG Task Ledger (alh task)") }),
|
|
1720
|
+
el("p", {
|
|
1721
|
+
class: "card-desc",
|
|
1722
|
+
text: `${zh("总计", "Total")}: ${td.tasks.length} · ${zh("就绪可执行", "Ready")}: ${td.readyCount}${td.hasCycle ? " · ⚠ CYCLE DETECTED" : ""}`,
|
|
1723
|
+
})
|
|
1724
|
+
)
|
|
1725
|
+
),
|
|
1726
|
+
el("div", { style: "display:flex;gap:8px;margin-bottom:14px;flex-wrap:wrap" }, titleInput, prioSelect, depsInput, addTaskBtn),
|
|
1727
|
+
taskRows,
|
|
1728
|
+
cliDisclosure(`alh task graph "${state.meta?.workspace || "."}"`)
|
|
1729
|
+
)
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
async function doTaskAction(id, action) {
|
|
1734
|
+
try {
|
|
1735
|
+
await api(`/api/tasks/${encodeURIComponent(id)}/action`, { method: "POST", body: { action } });
|
|
1736
|
+
toast(`${id} → ${action}`, "ok");
|
|
1737
|
+
await loadAllData();
|
|
1738
|
+
} catch (err) {
|
|
1739
|
+
toast(err.message, "err");
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
// 14. Panel 4 — Eval Lab
|
|
1744
|
+
const evalConfig = { suite: "core", agent: "mock-oracle", arms: ["baseline", "v1", "v3"] };
|
|
1745
|
+
|
|
1746
|
+
async function renderEvalPanel() {
|
|
1747
|
+
const root = document.getElementById("panel-eval");
|
|
1748
|
+
if (!state.evalCatalog) {
|
|
1749
|
+
root.replaceChildren(el("div", { class: "card", text: zh("正在加载评测套件目录...", "Loading eval suites...") }));
|
|
1750
|
+
await loadEvalIfNeeded();
|
|
1751
|
+
}
|
|
1752
|
+
root.replaceChildren();
|
|
1753
|
+
|
|
1754
|
+
const cat = state.evalCatalog;
|
|
1755
|
+
const suiteSelect = el(
|
|
1756
|
+
"select",
|
|
1757
|
+
{
|
|
1758
|
+
class: "select",
|
|
1759
|
+
onchange: (e) => {
|
|
1760
|
+
evalConfig.suite = e.target.value;
|
|
1761
|
+
renderEvalPanel();
|
|
1762
|
+
},
|
|
1763
|
+
},
|
|
1764
|
+
Object.entries(cat.suites).map(([k, list]) => el("option", { value: k, selected: evalConfig.suite === k, text: `${k} (${list.length} cases: ${list.join(", ")})` }))
|
|
1765
|
+
);
|
|
1766
|
+
|
|
1767
|
+
const driverSelect = el(
|
|
1768
|
+
"select",
|
|
1769
|
+
{
|
|
1770
|
+
class: "select",
|
|
1771
|
+
onchange: (e) => {
|
|
1772
|
+
evalConfig.agent = e.target.value;
|
|
1773
|
+
renderEvalPanel();
|
|
1774
|
+
},
|
|
1775
|
+
},
|
|
1776
|
+
cat.drivers.map((d) =>
|
|
1777
|
+
el("option", {
|
|
1778
|
+
value: d.id,
|
|
1779
|
+
selected: evalConfig.agent === d.id,
|
|
1780
|
+
text: `${d.id}${d.isSimulator ? " (Simulator)" : d.available ? " (CLI Ready)" : " (Not Installed)"}`,
|
|
1781
|
+
})
|
|
1782
|
+
)
|
|
1783
|
+
);
|
|
1784
|
+
|
|
1785
|
+
const armPills = el(
|
|
1786
|
+
"div",
|
|
1787
|
+
{ class: "host-pills" },
|
|
1788
|
+
cat.arms.map((arm) =>
|
|
1789
|
+
el(
|
|
1790
|
+
"label",
|
|
1791
|
+
{ class: "check-pill" },
|
|
1792
|
+
el("input", {
|
|
1793
|
+
type: "checkbox",
|
|
1794
|
+
checked: evalConfig.arms.includes(arm),
|
|
1795
|
+
onchange: (e) => {
|
|
1796
|
+
if (e.target.checked) evalConfig.arms = [...new Set([...evalConfig.arms, arm])];
|
|
1797
|
+
else evalConfig.arms = evalConfig.arms.filter((a) => a !== arm);
|
|
1798
|
+
if (evalConfig.arms.length === 0) evalConfig.arms = ["baseline", "v3"];
|
|
1799
|
+
renderEvalPanel();
|
|
1800
|
+
},
|
|
1801
|
+
}),
|
|
1802
|
+
arm
|
|
1803
|
+
)
|
|
1804
|
+
)
|
|
1805
|
+
);
|
|
1806
|
+
|
|
1807
|
+
const runBtn = el("button", {
|
|
1808
|
+
type: "button",
|
|
1809
|
+
class: "btn btn-primary btn-sm",
|
|
1810
|
+
disabled: state.evalRunning,
|
|
1811
|
+
text: state.evalRunning ? zh("消融运行中...", "Running Suite...") : zh("启动消融评测", "Run Eval Suite"),
|
|
1812
|
+
onclick: runEvalFromUi,
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
const historySelect =
|
|
1816
|
+
state.evalReports.length > 0
|
|
1817
|
+
? el(
|
|
1818
|
+
"select",
|
|
1819
|
+
{
|
|
1820
|
+
class: "select",
|
|
1821
|
+
style: "max-width:260px",
|
|
1822
|
+
onchange: (e) => {
|
|
1823
|
+
const found = state.evalReports.find((r) => r.id === e.target.value);
|
|
1824
|
+
if (found) {
|
|
1825
|
+
state.activeReport = found.report;
|
|
1826
|
+
renderEvalPanel();
|
|
1827
|
+
}
|
|
1828
|
+
},
|
|
1829
|
+
},
|
|
1830
|
+
el("option", { value: "", text: zh("加载本地历史 report.json...", "Load local report.json...") }),
|
|
1831
|
+
state.evalReports.map((r) => el("option", { value: r.id, text: `${r.name} (${r.agent})` }))
|
|
1832
|
+
)
|
|
1833
|
+
: null;
|
|
1834
|
+
|
|
1835
|
+
const cliCmd = `alh eval run --suite ${evalConfig.suite} --agent ${evalConfig.agent} --compare ${evalConfig.arms.join(",")}`;
|
|
1836
|
+
|
|
1837
|
+
root.append(
|
|
1838
|
+
el(
|
|
1839
|
+
"div",
|
|
1840
|
+
{ class: "card" },
|
|
1841
|
+
el(
|
|
1842
|
+
"div",
|
|
1843
|
+
{ class: "card-header" },
|
|
1844
|
+
el(
|
|
1845
|
+
"div",
|
|
1846
|
+
{},
|
|
1847
|
+
el("h2", { class: "card-title", text: zh("消融评测配置", "Ablation Benchmark Runner") }),
|
|
1848
|
+
el("p", {
|
|
1849
|
+
class: "card-desc",
|
|
1850
|
+
text: evalConfig.agent.startsWith("mock-")
|
|
1851
|
+
? zh("提示:mock-oracle / mock-naive 仅用于验证本地夹具与判分器,不代表真实 LLM 精度。", "Note: mock-oracle / mock-naive test graders only, not real LLM accuracy.")
|
|
1852
|
+
: zh("将通过真实 CLI 驱动隔离运行对照实验,并采集 Token 与 KV Cache 指标。", "Runs isolated Git fixtures against real CLI driver with Token & Cache telemetry."),
|
|
1853
|
+
})
|
|
1854
|
+
),
|
|
1855
|
+
el("div", { class: "card-actions" }, historySelect, runBtn)
|
|
1856
|
+
),
|
|
1857
|
+
el(
|
|
1858
|
+
"div",
|
|
1859
|
+
{ class: "grid-2" },
|
|
1860
|
+
el("label", { class: "field" }, el("span", { class: "field-label", text: zh("评测套件 (Suite)", "Suite") }), suiteSelect),
|
|
1861
|
+
el("label", { class: "field" }, el("span", { class: "field-label", text: zh("驱动 (Driver)", "Driver") }), driverSelect)
|
|
1862
|
+
),
|
|
1863
|
+
el("div", { style: "margin-top:12px" }, el("div", { class: "field-label", style: "margin-bottom:6px", text: zh("对照组 (Arms)", "Comparison Arms") }), armPills),
|
|
1864
|
+
state.evalRunning || state.evalProgress.total > 0
|
|
1865
|
+
? el(
|
|
1866
|
+
"div",
|
|
1867
|
+
{ style: "margin-top:14px" },
|
|
1868
|
+
el(
|
|
1869
|
+
"div",
|
|
1870
|
+
{ class: "meter-meta" },
|
|
1871
|
+
el("span", { text: zh("执行进度", "Progress") }),
|
|
1872
|
+
el("span", { class: "mono-xs num", text: `${state.evalProgress.done} / ${state.evalProgress.total}` })
|
|
1873
|
+
),
|
|
1874
|
+
el(
|
|
1875
|
+
"div",
|
|
1876
|
+
{ class: "meter-track", style: "margin-top:6px" },
|
|
1877
|
+
el("div", {
|
|
1878
|
+
class: "meter-fill fill-accent",
|
|
1879
|
+
style: `width:${state.evalProgress.total ? Math.round((state.evalProgress.done / state.evalProgress.total) * 100) : 0}%`,
|
|
1880
|
+
})
|
|
1881
|
+
)
|
|
1882
|
+
)
|
|
1883
|
+
: null,
|
|
1884
|
+
cliDisclosure(cliCmd)
|
|
1885
|
+
)
|
|
1886
|
+
);
|
|
1887
|
+
|
|
1888
|
+
// Results & Native SVG Comparison Charts
|
|
1889
|
+
const rep = state.activeReport;
|
|
1890
|
+
if (!rep || !rep.summaryByArm) {
|
|
1891
|
+
root.append(el("div", { class: "card" }, el("div", { class: "empty-state", text: zh("尚未加载评测结果。可先用 mock-oracle 体验完整流程,或加载已有 report.json。", "No benchmark report loaded yet. Run a quick mock-oracle suite or load a local report.json.") })));
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
const isSim = String(rep.agent || "").startsWith("mock-");
|
|
1896
|
+
root.append(
|
|
1897
|
+
el(
|
|
1898
|
+
"div",
|
|
1899
|
+
{ class: `banner ${isSim ? "banner-warn" : "banner-ok"}` },
|
|
1900
|
+
el("span", {
|
|
1901
|
+
text: isSim
|
|
1902
|
+
? zh(`当前展示为模拟器自检结果(${rep.agent})— 仅证明判分器与护栏接线正常,不代表真实模型精度。`, `Simulator self-test (${rep.agent}) — verifies graders & guardrails only, not real LLM accuracy.`)
|
|
1903
|
+
: zh(`真实模型成对消融报告:${rep.agent} (${rep.driverVersion || "CLI"}) · ${rep.v3Profile || ""}`, `Real-model paired ablation report: ${rep.agent} (${rep.driverVersion || "CLI"})`),
|
|
1904
|
+
})
|
|
1905
|
+
)
|
|
1906
|
+
);
|
|
1907
|
+
|
|
1908
|
+
const arms = rep.arms || Object.keys(rep.summaryByArm);
|
|
1909
|
+
const summaries = arms.map((arm) => ({ arm, ...(rep.summaryByArm[arm] || {}) }));
|
|
1910
|
+
|
|
1911
|
+
root.append(
|
|
1912
|
+
el(
|
|
1913
|
+
"div",
|
|
1914
|
+
{ class: "grid-2" },
|
|
1915
|
+
el(
|
|
1916
|
+
"div",
|
|
1917
|
+
{ class: "card" },
|
|
1918
|
+
el("h2", { class: "card-title", style: "margin-bottom:12px", text: zh("通过率 & 缓存命中对比 (%)", "Pass Rate & Cache Hit (%)") }),
|
|
1919
|
+
renderGroupedBarSvg(summaries, [
|
|
1920
|
+
{ key: "passRatePct", label: zh("通过率", "Pass %"), color: "#10b981", max: 100 },
|
|
1921
|
+
{ key: "avgCacheHitPct", label: zh("缓存命中", "Cache %"), color: "#6366f1", max: 100 },
|
|
1922
|
+
])
|
|
1923
|
+
),
|
|
1924
|
+
el(
|
|
1925
|
+
"div",
|
|
1926
|
+
{ class: "card" },
|
|
1927
|
+
el("h2", { class: "card-title", style: "margin-bottom:12px", text: zh("平均耗时 (ms) & 有效计费 Token", "Avg Duration (ms) & Billable Tokens") }),
|
|
1928
|
+
renderGroupedBarSvg(summaries, [
|
|
1929
|
+
{ key: "avgDurationMs", label: zh("耗时 ms", "Duration ms"), color: "#f59e0b" },
|
|
1930
|
+
{ key: "avgBillableTokens", label: zh("有效 Token", "Billable Tok"), color: "#0ea5e9" },
|
|
1931
|
+
])
|
|
1932
|
+
)
|
|
1933
|
+
)
|
|
1934
|
+
);
|
|
1935
|
+
|
|
1936
|
+
// Summary Table
|
|
1937
|
+
const fmt = (v, suffix = "") => (v === null || v === undefined ? "—" : `${v}${suffix}`);
|
|
1938
|
+
root.append(
|
|
1939
|
+
el(
|
|
1940
|
+
"div",
|
|
1941
|
+
{ class: "card" },
|
|
1942
|
+
el("h2", { class: "card-title", style: "margin-bottom:12px", text: zh("严格成对统计汇总表", "Strict Paired Arm Summary") }),
|
|
1943
|
+
el(
|
|
1944
|
+
"table",
|
|
1945
|
+
{ class: "data-table" },
|
|
1946
|
+
el(
|
|
1947
|
+
"thead",
|
|
1948
|
+
{},
|
|
1949
|
+
el(
|
|
1950
|
+
"tr",
|
|
1951
|
+
{},
|
|
1952
|
+
el("th", { text: "Arm" }),
|
|
1953
|
+
el("th", { class: "num", text: zh("通过率", "Pass Rate") }),
|
|
1954
|
+
el("th", { class: "num", text: zh("平均耗时", "Avg ms") }),
|
|
1955
|
+
el("th", { class: "num", text: zh("总 Token", "Total Tok") }),
|
|
1956
|
+
el("th", { class: "num", text: zh("有效计费", "Fresh+Out") }),
|
|
1957
|
+
el("th", { class: "num", text: zh("缓存命中", "Cache Hit") }),
|
|
1958
|
+
el("th", { class: "num", text: zh("工具调用", "Tool Calls") })
|
|
1959
|
+
)
|
|
1960
|
+
),
|
|
1961
|
+
el(
|
|
1962
|
+
"tbody",
|
|
1963
|
+
{},
|
|
1964
|
+
summaries.map((s) =>
|
|
1965
|
+
el(
|
|
1966
|
+
"tr",
|
|
1967
|
+
{},
|
|
1968
|
+
el("td", { class: "mono", style: "font-weight:700", text: s.arm }),
|
|
1969
|
+
el("td", { class: "num", text: `${s.passRatePct ?? 0}% (${s.passed ?? 0}/${s.total ?? 0})` }),
|
|
1970
|
+
el("td", { class: "num", text: fmt(s.avgDurationMs, "ms") }),
|
|
1971
|
+
el("td", { class: "num", text: fmt(s.avgTotalTokens) }),
|
|
1972
|
+
el("td", { class: "num", text: fmt(s.avgBillableTokens) }),
|
|
1973
|
+
el("td", { class: "num", text: fmt(s.avgCacheHitPct, "%") }),
|
|
1974
|
+
el("td", { class: "num", text: fmt(s.avgToolCalls) })
|
|
1975
|
+
)
|
|
1976
|
+
)
|
|
1977
|
+
)
|
|
1978
|
+
)
|
|
1979
|
+
)
|
|
1980
|
+
);
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
function renderGroupedBarSvg(summaries, metrics) {
|
|
1984
|
+
const width = 460;
|
|
1985
|
+
const height = 216;
|
|
1986
|
+
const padLeft = 36;
|
|
1987
|
+
const padBottom = 32;
|
|
1988
|
+
const padTop = 46;
|
|
1989
|
+
const chartH = height - padTop - padBottom;
|
|
1990
|
+
const groupW = (width - padLeft - 16) / Math.max(1, summaries.length);
|
|
1991
|
+
const barW = Math.min(34, (groupW - 22) / metrics.length);
|
|
1992
|
+
|
|
1993
|
+
const svg = svgEl("svg", { class: "svg-chart", viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": "Evaluation comparison chart" });
|
|
1994
|
+
|
|
1995
|
+
// Legend
|
|
1996
|
+
metrics.forEach((m, idx) => {
|
|
1997
|
+
const lx = padLeft + idx * 145;
|
|
1998
|
+
svg.append(
|
|
1999
|
+
svgEl("rect", { x: lx, y: 6, width: 10, height: 10, rx: 2, fill: m.color }),
|
|
2000
|
+
svgEl("text", { x: lx + 15, y: 15, fill: "currentColor", "font-size": 11, opacity: 0.85 }, m.label)
|
|
2001
|
+
);
|
|
2002
|
+
});
|
|
2003
|
+
|
|
2004
|
+
// Subtle horizontal guide lines + baseline axis
|
|
2005
|
+
svg.append(
|
|
2006
|
+
svgEl("line", { x1: padLeft, y1: padTop, x2: width - 10, y2: padTop, stroke: "currentColor", opacity: 0.08, "stroke-dasharray": "3 3" }),
|
|
2007
|
+
svgEl("line", { x1: padLeft, y1: padTop + chartH / 2, x2: width - 10, y2: padTop + chartH / 2, stroke: "currentColor", opacity: 0.08, "stroke-dasharray": "3 3" }),
|
|
2008
|
+
svgEl("line", { x1: padLeft, y1: height - padBottom, x2: width - 10, y2: height - padBottom, stroke: "currentColor", opacity: 0.2 })
|
|
2009
|
+
);
|
|
2010
|
+
|
|
2011
|
+
metrics.forEach((m, mIdx) => {
|
|
2012
|
+
const computedMax = m.max || Math.max(1, ...summaries.map((s) => Number(s[m.key]) || 0));
|
|
2013
|
+
summaries.forEach((s, gIdx) => {
|
|
2014
|
+
const raw = s[m.key];
|
|
2015
|
+
const hasVal = raw !== null && raw !== undefined;
|
|
2016
|
+
const val = hasVal ? Number(raw) : 0;
|
|
2017
|
+
const h = hasVal && val > 0 ? Math.max(4, Math.round((val / computedMax) * chartH)) : 2;
|
|
2018
|
+
const gx = padLeft + gIdx * groupW + 14;
|
|
2019
|
+
const x = gx + mIdx * (barW + 6);
|
|
2020
|
+
const y = height - padBottom - h;
|
|
2021
|
+
svg.append(
|
|
2022
|
+
svgEl("rect", { x, y, width: barW, height: h, rx: 4, fill: m.color, opacity: hasVal && val > 0 ? 0.92 : 0.2 }),
|
|
2023
|
+
svgEl("text", { x: x + barW / 2, y: y - 5, "text-anchor": "middle", fill: "currentColor", "font-size": 10.5, opacity: 0.85 }, hasVal ? String(val) : "—")
|
|
2024
|
+
);
|
|
2025
|
+
});
|
|
2026
|
+
});
|
|
2027
|
+
|
|
2028
|
+
summaries.forEach((s, gIdx) => {
|
|
2029
|
+
const cx = padLeft + gIdx * groupW + 14 + (metrics.length * (barW + 6)) / 2 - 3;
|
|
2030
|
+
svg.append(svgEl("text", { x: cx, y: height - 10, "text-anchor": "middle", fill: "currentColor", "font-size": 11.5, "font-weight": 600 }, s.arm));
|
|
2031
|
+
});
|
|
2032
|
+
|
|
2033
|
+
return svg;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
async function runEvalFromUi() {
|
|
2037
|
+
state.evalRunning = true;
|
|
2038
|
+
state.evalProgress = { done: 0, total: 0, runs: [] };
|
|
2039
|
+
renderEvalPanel();
|
|
2040
|
+
try {
|
|
2041
|
+
await apiStream(
|
|
2042
|
+
"/api/eval/run",
|
|
2043
|
+
{ suite: evalConfig.suite, agent: evalConfig.agent, arms: evalConfig.arms, locale: state.lang },
|
|
2044
|
+
(evName, data) => {
|
|
2045
|
+
if (evName === "start") {
|
|
2046
|
+
state.evalProgress.total = data.totalRuns || 0;
|
|
2047
|
+
} else if (evName === "progress") {
|
|
2048
|
+
state.evalProgress.done = data.index || state.evalProgress.done + 1;
|
|
2049
|
+
state.evalProgress.total = data.total || state.evalProgress.total;
|
|
2050
|
+
if (data.run) state.evalProgress.runs.push(data.run);
|
|
2051
|
+
} else if (evName === "done") {
|
|
2052
|
+
state.activeReport = data.report;
|
|
2053
|
+
toast(zh("消融评测完成!", "Eval suite finished!"), "ok");
|
|
2054
|
+
} else if (evName === "error") {
|
|
2055
|
+
toast(data.message, "err");
|
|
2056
|
+
}
|
|
2057
|
+
renderEvalPanel();
|
|
2058
|
+
}
|
|
2059
|
+
);
|
|
2060
|
+
} catch (err) {
|
|
2061
|
+
toast(err.message, "err");
|
|
2062
|
+
} finally {
|
|
2063
|
+
state.evalRunning = false;
|
|
2064
|
+
renderEvalPanel();
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
// 15. View Routing & Event Wiring
|
|
2069
|
+
function switchView(view) {
|
|
2070
|
+
state.view = view;
|
|
2071
|
+
document.querySelectorAll(".nav-item").forEach((btn) => {
|
|
2072
|
+
const active = btn.dataset.view === view;
|
|
2073
|
+
btn.classList.toggle("active", active);
|
|
2074
|
+
btn.setAttribute("aria-selected", String(active));
|
|
2075
|
+
});
|
|
2076
|
+
["health", "onboarding", "changes", "eval"].forEach((name) => {
|
|
2077
|
+
document.getElementById(`panel-${name}`).hidden = name !== view;
|
|
2078
|
+
});
|
|
2079
|
+
updateTopbarHeader();
|
|
2080
|
+
renderActivePanel();
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
function renderActivePanel() {
|
|
2084
|
+
if (state.view === "health") renderHealthPanel();
|
|
2085
|
+
else if (state.view === "onboarding") renderOnboardingPanel();
|
|
2086
|
+
else if (state.view === "changes") renderChangesPanel();
|
|
2087
|
+
else if (state.view === "eval") renderEvalPanel();
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
function bindEvents() {
|
|
2091
|
+
document.querySelectorAll(".nav-item").forEach((btn) => {
|
|
2092
|
+
btn.addEventListener("click", () => switchView(btn.dataset.view));
|
|
2093
|
+
});
|
|
2094
|
+
|
|
2095
|
+
document.querySelectorAll(".seg-btn[data-theme]").forEach((btn) => {
|
|
2096
|
+
btn.addEventListener("click", () => applyTheme(btn.dataset.theme));
|
|
2097
|
+
});
|
|
2098
|
+
|
|
2099
|
+
document.getElementById("lang-toggle").addEventListener("click", () => {
|
|
2100
|
+
state.lang = state.lang === "zh-CN" ? "en-US" : "zh-CN";
|
|
2101
|
+
try {
|
|
2102
|
+
localStorage.setItem("alh-ui-lang", state.lang);
|
|
2103
|
+
} catch (_) {}
|
|
2104
|
+
applyStaticI18n();
|
|
2105
|
+
renderChrome();
|
|
2106
|
+
renderActivePanel();
|
|
2107
|
+
});
|
|
2108
|
+
|
|
2109
|
+
document.getElementById("btn-refresh").addEventListener("click", () => {
|
|
2110
|
+
state.doctor = null;
|
|
2111
|
+
loadAllData();
|
|
2112
|
+
toast(zh("已刷新工作区数据", "Workspace refreshed"), "info");
|
|
2113
|
+
});
|
|
2114
|
+
|
|
2115
|
+
document.getElementById("btn-quick-verify").addEventListener("click", () => {
|
|
2116
|
+
switchView("health");
|
|
2117
|
+
runStreamAction("/api/verify", { strict: state.verifyStrict, runChecks: false });
|
|
2118
|
+
});
|
|
2119
|
+
|
|
2120
|
+
// Workspace switcher dialog
|
|
2121
|
+
const wsDialog = document.getElementById("dialog-workspace");
|
|
2122
|
+
document.getElementById("workspace-trigger").addEventListener("click", () => {
|
|
2123
|
+
document.getElementById("workspace-error").hidden = true;
|
|
2124
|
+
document.getElementById("input-workspace-path").value = state.meta?.workspace || "";
|
|
2125
|
+
wsDialog.showModal();
|
|
2126
|
+
});
|
|
2127
|
+
document.getElementById("btn-workspace-cancel").addEventListener("click", () => wsDialog.close());
|
|
2128
|
+
document.getElementById("form-workspace").addEventListener("submit", async (e) => {
|
|
2129
|
+
e.preventDefault();
|
|
2130
|
+
const errBox = document.getElementById("workspace-error");
|
|
2131
|
+
errBox.hidden = true;
|
|
2132
|
+
const p = document.getElementById("input-workspace-path").value.trim();
|
|
2133
|
+
try {
|
|
2134
|
+
await api("/api/workspace", { method: "POST", body: { path: p } });
|
|
2135
|
+
state.adoptPreview = null;
|
|
2136
|
+
state.selectedSlug = null;
|
|
2137
|
+
wsDialog.close();
|
|
2138
|
+
toast(zh("已切换本地工作区", "Workspace switched"), "ok");
|
|
2139
|
+
await loadAllData();
|
|
2140
|
+
} catch (err) {
|
|
2141
|
+
errBox.textContent = err.message;
|
|
2142
|
+
errBox.hidden = false;
|
|
2143
|
+
}
|
|
2144
|
+
});
|
|
2145
|
+
|
|
2146
|
+
// New Change dialog
|
|
2147
|
+
const chDialog = document.getElementById("dialog-new-change");
|
|
2148
|
+
document.getElementById("btn-change-cancel").addEventListener("click", () => chDialog.close());
|
|
2149
|
+
document.getElementById("form-new-change").addEventListener("submit", async (e) => {
|
|
2150
|
+
e.preventDefault();
|
|
2151
|
+
const errBox = document.getElementById("new-change-error");
|
|
2152
|
+
errBox.hidden = true;
|
|
2153
|
+
try {
|
|
2154
|
+
const slug = document.getElementById("input-change-slug").value.trim();
|
|
2155
|
+
const title = document.getElementById("input-change-title").value.trim();
|
|
2156
|
+
const res = await api("/api/changes", {
|
|
2157
|
+
method: "POST",
|
|
2158
|
+
body: { slug, title, locale: state.lang },
|
|
2159
|
+
});
|
|
2160
|
+
state.selectedSlug = res.slug;
|
|
2161
|
+
chDialog.close();
|
|
2162
|
+
toast(zh(`已创建变更包 ${res.slug}`, `Created change ${res.slug}`), "ok");
|
|
2163
|
+
await loadAllData();
|
|
2164
|
+
} catch (err) {
|
|
2165
|
+
errBox.textContent = err.message;
|
|
2166
|
+
errBox.hidden = false;
|
|
2167
|
+
}
|
|
2168
|
+
});
|
|
2169
|
+
|
|
2170
|
+
// Cross-tab theme sync
|
|
2171
|
+
window.addEventListener("storage", (e) => {
|
|
2172
|
+
if (e.key === "alh-color-scheme") {
|
|
2173
|
+
applyTheme(e.newValue === "light" || e.newValue === "dark" ? e.newValue : "system");
|
|
2174
|
+
}
|
|
2175
|
+
});
|
|
2176
|
+
|
|
2177
|
+
// Light-dismiss fallback for browsers without native closedby="any"
|
|
2178
|
+
if (!("closedBy" in HTMLDialogElement.prototype)) {
|
|
2179
|
+
const outside = (e, dlg) => {
|
|
2180
|
+
const r = dlg.getBoundingClientRect();
|
|
2181
|
+
return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom;
|
|
2182
|
+
};
|
|
2183
|
+
for (const dlg of document.querySelectorAll('dialog[closedby="any"]')) {
|
|
2184
|
+
let pressedOutside = false;
|
|
2185
|
+
dlg.addEventListener("pointerdown", (e) => {
|
|
2186
|
+
pressedOutside = outside(e, dlg);
|
|
2187
|
+
});
|
|
2188
|
+
dlg.addEventListener("pointerup", (e) => {
|
|
2189
|
+
if (pressedOutside && outside(e, dlg)) dlg.close();
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
// 16. Boot
|
|
2196
|
+
applyTheme(state.theme);
|
|
2197
|
+
applyStaticI18n();
|
|
2198
|
+
bindEvents();
|
|
2199
|
+
loadAllData();
|