@fantasticit/sumi 0.14.5 → 0.14.7
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/dist/adapters.d.ts +9 -0
- package/dist/adapters.js +88 -12
- package/dist/adapters.js.map +1 -1
- package/dist/agent-hooks.js +15 -2
- package/dist/agent-hooks.js.map +1 -1
- package/dist/agents.js +19 -11
- package/dist/agents.js.map +1 -1
- package/dist/cli.js +20 -3
- package/dist/cli.js.map +1 -1
- package/dist/codex-trust.d.ts +8 -0
- package/dist/codex-trust.js +27 -0
- package/dist/codex-trust.js.map +1 -0
- package/dist/codex-user-hook-entry.d.ts +1 -0
- package/dist/codex-user-hook-entry.js +134 -0
- package/dist/codex-user-hook-entry.js.map +1 -0
- package/dist/codex-user-hook.cjs +137 -0
- package/dist/codex-user-hook.d.ts +2 -0
- package/dist/codex-user-hook.js +85 -0
- package/dist/codex-user-hook.js.map +1 -0
- package/dist/context.d.ts +3 -1
- package/dist/context.js +20 -20
- package/dist/context.js.map +1 -1
- package/dist/declared-hooks.d.ts +3 -1
- package/dist/declared-hooks.js +11 -0
- package/dist/declared-hooks.js.map +1 -1
- package/dist/doctor-wiring.d.ts +1 -6
- package/dist/doctor-wiring.js +4 -25
- package/dist/doctor-wiring.js.map +1 -1
- package/dist/hub/board.d.ts +123 -0
- package/dist/hub/board.js +303 -0
- package/dist/hub/board.js.map +1 -0
- package/dist/hub/commands.d.ts +13 -0
- package/dist/hub/commands.js +86 -0
- package/dist/hub/commands.js.map +1 -0
- package/dist/hub/pages.d.ts +2 -0
- package/dist/hub/pages.js +182 -0
- package/dist/hub/pages.js.map +1 -0
- package/dist/hub/server.d.ts +23 -0
- package/dist/hub/server.js +128 -0
- package/dist/hub/server.js.map +1 -0
- package/dist/hub/snapshot.d.ts +56 -0
- package/dist/hub/snapshot.js +161 -0
- package/dist/hub/snapshot.js.map +1 -0
- package/dist/hub/start.d.ts +13 -0
- package/dist/hub/start.js +59 -0
- package/dist/hub/start.js.map +1 -0
- package/dist/hub/state.d.ts +49 -0
- package/dist/hub/state.js +144 -0
- package/dist/hub/state.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +2 -2
- package/dist/mcp-hosts.d.ts +25 -0
- package/dist/mcp-hosts.js +64 -0
- package/dist/mcp-hosts.js.map +1 -0
- package/dist/run-stats.d.ts +20 -0
- package/dist/run-stats.js +58 -6
- package/dist/run-stats.js.map +1 -1
- package/dist/task.js +16 -5
- package/dist/task.js.map +1 -1
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/create/template/control/flows/check.flow.yaml +4 -0
- package/node_modules/@sumi/create/template/control/rubrics/behavior.yaml +16 -0
- package/node_modules/@sumi/create/template/control/rules/core-modules.json +5 -0
- package/node_modules/@sumi/create/template/control/rules/development.md +13 -9
- package/node_modules/@sumi/create/template/control/rules/testing.md +56 -0
- package/node_modules/@sumi/create/template/init/control/flows/check.flow.yaml +1 -0
- package/node_modules/@sumi/create/template/init/control/rubrics/behavior.yaml +16 -0
- package/node_modules/@sumi/kernel/dist/brief.d.ts +2 -0
- package/node_modules/@sumi/kernel/dist/brief.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/engine.js +1 -0
- package/node_modules/@sumi/kernel/dist/engine.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/runner.js +3 -3
- package/node_modules/@sumi/kernel/dist/runner.js.map +1 -1
- package/node_modules/@sumi/kernel/package.json +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.d.ts +11 -6
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js +35 -3
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js +29 -23
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/env.d.ts +8 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js +13 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/git.d.ts +8 -0
- package/node_modules/@sumi/plugin-sdk/dist/git.js +48 -0
- package/node_modules/@sumi/plugin-sdk/dist/git.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/hub.d.ts +33 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js +32 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.d.ts +22 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.js +118 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js +12 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/project.d.ts +5 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js +5 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/protocol.d.ts +10 -0
- package/node_modules/@sumi/plugin-sdk/dist/protocol.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-context.d.ts +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js +10 -7
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-env.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/session-env.js +3 -0
- package/node_modules/@sumi/plugin-sdk/dist/session-env.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/shell.d.ts +11 -5
- package/node_modules/@sumi/plugin-sdk/dist/shell.js +132 -23
- package/node_modules/@sumi/plugin-sdk/dist/shell.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/trace.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/trace.js +39 -5
- package/node_modules/@sumi/plugin-sdk/dist/trace.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/validate.js +15 -0
- package/node_modules/@sumi/plugin-sdk/dist/validate.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/package.json +1 -1
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js +20 -5
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/change-impact.js +1 -13
- package/node_modules/@sumi/plugins-core/dist/change-impact.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.js +10 -0
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/context-provider.js +17 -1
- package/node_modules/@sumi/plugins-core/dist/context-provider.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/core-modules.d.ts +5 -0
- package/node_modules/@sumi/plugins-core/dist/core-modules.js +28 -0
- package/node_modules/@sumi/plugins-core/dist/core-modules.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/layer-boundary.js +2 -2
- package/node_modules/@sumi/plugins-core/dist/plugins/layer-boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js +26 -7
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/plugins/test-scope.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/test-scope.js +41 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/test-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/test-scope.d.ts +3 -1
- package/node_modules/@sumi/plugins-core/dist/test-scope.js +14 -3
- package/node_modules/@sumi/plugins-core/dist/test-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/testing-rules-upgrade.d.ts +10 -0
- package/node_modules/@sumi/plugins-core/dist/testing-rules-upgrade.js +29 -0
- package/node_modules/@sumi/plugins-core/dist/testing-rules-upgrade.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/upgrade-command.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/upgrade-command.js +13 -0
- package/node_modules/@sumi/plugins-core/dist/upgrade-command.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js +16 -0
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js.map +1 -1
- package/node_modules/@sumi/plugins-core/instructions/bugfix.md +4 -4
- package/node_modules/@sumi/plugins-core/instructions/feature.md +2 -2
- package/node_modules/@sumi/plugins-core/package.json +3 -2
- package/node_modules/@sumi/plugins-core/sumi-plugins.yaml +13 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.js +76 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.d.ts +6 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.js +128 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js +231 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.d.ts +10 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.js +183 -33
- package/node_modules/@sumi/plugins-governance/dist/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.d.ts +9 -0
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js +64 -0
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.js +13 -3
- package/node_modules/@sumi/plugins-governance/dist/checkout.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js +59 -9
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js +16 -11
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.js +4 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js +3 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.d.ts +2 -1
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js +11 -2
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/guard.js +147 -19
- package/node_modules/@sumi/plugins-governance/dist/guard.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js +44 -0
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/index.d.ts +3 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js +3 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js +21 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js +4 -2
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js +2 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js +34 -4
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/preflight.js +2 -2
- package/node_modules/@sumi/plugins-governance/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/protected.js +2 -1
- package/node_modules/@sumi/plugins-governance/dist/protected.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/instructions/boundary.md +17 -2
- package/node_modules/@sumi/plugins-governance/package.json +4 -4
- package/node_modules/@sumi/plugins-governance/sumi-plugins.yaml +8 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.d.ts +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.js +4 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.d.ts +4 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.js +34 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.d.ts +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.js +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-openspec/dist/plugins/impact-consistency.js +2 -0
- package/node_modules/@sumi/plugins-openspec/dist/plugins/impact-consistency.js.map +1 -1
- package/node_modules/@sumi/plugins-openspec/package.json +6 -6
- package/node_modules/@sumi/plugins-openspec/sumi-plugins.yaml +4 -0
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js +10 -11
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/candidates.d.ts +9 -3
- package/node_modules/@sumi/plugins-precedent/dist/candidates.js +12 -6
- package/node_modules/@sumi/plugins-precedent/dist/candidates.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/promote.js +20 -5
- package/node_modules/@sumi/plugins-precedent/dist/commands/promote.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-output.d.ts +15 -8
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js +93 -34
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js +7 -3
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.d.ts +2 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js +5 -4
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact.d.ts +7 -6
- package/node_modules/@sumi/plugins-precedent/dist/impact.js +33 -29
- package/node_modules/@sumi/plugins-precedent/dist/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/matching.d.ts +12 -0
- package/node_modules/@sumi/plugins-precedent/dist/matching.js +90 -0
- package/node_modules/@sumi/plugins-precedent/dist/matching.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/plugins/harvest.js +44 -13
- package/node_modules/@sumi/plugins-precedent/dist/plugins/harvest.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/impact.js +15 -10
- package/node_modules/@sumi/plugins-precedent/dist/plugins/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/planner.js +47 -6
- package/node_modules/@sumi/plugins-precedent/dist/plugins/planner.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.d.ts +3 -0
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.js +40 -0
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-review/dist/command-input.d.ts +1 -1
- package/node_modules/@sumi/plugins-review/dist/command-input.js +4 -4
- package/node_modules/@sumi/plugins-review/dist/command-input.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js +3 -3
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js +6 -0
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/convergence.d.ts +7 -2
- package/node_modules/@sumi/plugins-review/dist/convergence.js +43 -5
- package/node_modules/@sumi/plugins-review/dist/convergence.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/dispatch.js +2 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/precedent-context.d.ts +7 -0
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js +28 -0
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.js +15 -5
- package/node_modules/@sumi/plugins-review/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/report.d.ts +9 -0
- package/node_modules/@sumi/plugins-review/dist/report.js +28 -7
- package/node_modules/@sumi/plugins-review/dist/report.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.d.ts +9 -0
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.js +50 -0
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/review-scope.d.ts +1 -3
- package/node_modules/@sumi/plugins-review/dist/review-scope.js +1 -24
- package/node_modules/@sumi/plugins-review/dist/review-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review-slices.js +1 -0
- package/node_modules/@sumi/plugins-review/dist/review-slices.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review.d.ts +47 -8
- package/node_modules/@sumi/plugins-review/dist/review.js +215 -34
- package/node_modules/@sumi/plugins-review/dist/review.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js +71 -32
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/stats.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/stats.js +11 -15
- package/node_modules/@sumi/plugins-review/dist/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submission.js +24 -8
- package/node_modules/@sumi/plugins-review/dist/submission.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submit-files.d.ts +3 -0
- package/node_modules/@sumi/plugins-review/dist/submit-files.js +55 -0
- package/node_modules/@sumi/plugins-review/dist/submit-files.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/validation-receipt.js +4 -2
- package/node_modules/@sumi/plugins-review/dist/validation-receipt.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -6
- package/package.json +10 -10
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// hub 的两个自包含只读页面:无外部字体与脚本,数据来自同源的 JSON 接口,动态内容一律用 textContent(图标是内联的常量 SVG,不含外部输入)。
|
|
2
|
+
// 版式与配色来自设计稿;所有按钮只用于导航、筛选与展开,没有提交类控件。
|
|
3
|
+
const STYLE = `:root{--bg:#F6F6F4;--surface:#fff;--soft:#EFEFEC;--line:#E4E4E0;--ink:#1F1F1C;--ink2:#3A3A36;--muted:#6B6B66;--faint:#8A8A84;--blue:#1D4ED8;--blue-soft:#EEF2FF;--blue-ink:#3730A3;--dev-bg:#F2F6FE;--dev-line:#C9D8F8;--orange:#C2410C;--auto-bg:#FFF8F1;--auto-line:#F1D9C2;--red:#B42318;--red-bg:#FDF1F0;--red-line:#F0C4BF;--green:#15803D;--green-soft:#E7F5EC;--green-ink:#166534;--shadow:0 1px 2px rgba(20,20,18,.05),0 1px 1px rgba(20,20,18,.03);--shadow-hover:0 4px 14px rgba(20,20,18,.10),0 1px 3px rgba(20,20,18,.06);--skel:#ECECE8;--skel-hi:#F6F6F3;color-scheme:light;font-family:Inter,"PingFang SC","Microsoft YaHei","Noto Sans SC",system-ui,sans-serif}
|
|
4
|
+
@media (prefers-color-scheme:dark){:root{--bg:#161614;--surface:#20201D;--soft:#2A2A26;--line:#34342F;--ink:#ECECE8;--ink2:#D2D2CC;--muted:#A2A29A;--faint:#85857D;--blue:#7BA0FF;--blue-soft:#232A45;--blue-ink:#B6C6FF;--dev-bg:#1C2338;--dev-line:#2F3C63;--orange:#F0985F;--auto-bg:#2D241C;--auto-line:#4A3926;--red:#FF8E84;--red-bg:#3A2321;--red-line:#5F3531;--green:#6FCF8D;--green-soft:#1F3427;--green-ink:#8FE0A9;--shadow:0 1px 2px rgba(0,0,0,.35);--shadow-hover:0 6px 18px rgba(0,0,0,.45),0 1px 3px rgba(0,0,0,.4);--skel:#2A2A26;--skel-hi:#34342F;color-scheme:dark}}
|
|
5
|
+
*{box-sizing:border-box}html,body{height:100%}body{margin:0;background:var(--bg);color:var(--ink);font-size:14px;display:flex;flex-direction:column;overflow:hidden}
|
|
6
|
+
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
|
7
|
+
a{color:var(--blue)}button,select{font:inherit;color:inherit}
|
|
8
|
+
.ic{display:inline-flex;flex:none;vertical-align:-3px}.ic svg{width:1em;height:1em;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round}
|
|
9
|
+
.ic.s14{font-size:14px}.ic.s16{font-size:16px}.ic.s18{font-size:18px}.ic.s22{font-size:22px}
|
|
10
|
+
header.top{flex:none;display:flex;flex-wrap:wrap;align-items:center;gap:16px;padding:10px 24px;background:var(--surface);border-bottom:1px solid var(--line)}
|
|
11
|
+
.brand{display:flex;align-items:center;gap:10px;flex:1 1 200px;min-width:0}.brand strong{font-size:18px;letter-spacing:.2px}.brand span.sum{font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
12
|
+
nav.tabs{display:flex;gap:2px;padding:3px;background:var(--soft);border-radius:10px}
|
|
13
|
+
nav.tabs a{display:inline-flex;align-items:center;gap:7px;padding:6px 16px;border-radius:8px;font-size:14px;font-weight:500;color:var(--muted);text-decoration:none;transition:color .12s,background .12s}
|
|
14
|
+
nav.tabs a:hover{color:var(--ink)}
|
|
15
|
+
nav.tabs a[aria-current="page"]{background:var(--surface);color:var(--ink);box-shadow:0 1px 2px rgba(0,0,0,.12)}
|
|
16
|
+
nav.tabs a:focus-visible,.card:focus-visible,.pill:focus-visible,.sess:focus-visible,.row:focus-visible{outline:2px solid var(--blue);outline-offset:2px}
|
|
17
|
+
.right{flex:1 1 200px;display:flex;justify-content:flex-end;gap:8px}
|
|
18
|
+
#need{display:inline-flex;gap:6px;align-items:center;padding:6px 12px;border-radius:8px;background:var(--red-bg);color:var(--red);font-weight:600;font-size:13px}#need[hidden]{display:none}
|
|
19
|
+
.alerts{flex:none;display:flex;flex-direction:column}.alerts:empty{display:none}
|
|
20
|
+
.alert{display:flex;align-items:flex-start;gap:10px;padding:8px 24px;font-size:13px;background:var(--auto-bg);color:var(--ink2);border-bottom:1px solid var(--auto-line)}.alert .ic{color:var(--orange);margin-top:2px}.alert b{font-weight:600}.alert.bad{background:var(--red-bg);border-bottom-color:var(--red-line)}.alert.bad .ic{color:var(--red)}
|
|
21
|
+
.filters{flex:none;display:flex;flex-wrap:wrap;align-items:center;gap:10px;padding:8px 24px;background:var(--surface);border-bottom:1px solid var(--line);font-size:13px}
|
|
22
|
+
.filters label{color:var(--muted)}.filters select{padding:5px 8px;border-radius:8px;border:1px solid var(--line);background:var(--surface)}
|
|
23
|
+
.projects{display:flex;gap:8px;overflow-x:auto;flex:1 1 400px;min-width:0;padding:2px 0}
|
|
24
|
+
.proj{display:flex;gap:8px;align-items:center;padding:4px 10px;border-radius:8px;border:1px solid var(--line);background:var(--bg);white-space:nowrap;font-size:13px}.proj .mono{color:var(--blue);font-weight:500}.proj em{font-style:normal;color:var(--muted)}.proj.warn em{color:var(--orange)}
|
|
25
|
+
.body{flex:1 1 auto;min-height:0;display:flex}
|
|
26
|
+
.board{flex:1 1 0;min-width:0;display:flex;gap:16px;padding:16px 20px 0 24px;overflow-x:auto;overflow-y:hidden}
|
|
27
|
+
.col{flex:1 0 224px;min-width:224px;display:flex;flex-direction:column;min-height:0}
|
|
28
|
+
.col>header{flex:none;display:flex;flex-direction:column;gap:3px;padding-bottom:10px}
|
|
29
|
+
.col h2{margin:0;font-size:14px;font-weight:600;display:flex;align-items:center;gap:8px}.col h2 .ic{color:var(--faint)}.col h2 .n{margin-left:auto;min-width:22px;text-align:center;padding:1px 7px;border-radius:999px;background:var(--soft);color:var(--muted);font-size:12px;font-weight:600}
|
|
30
|
+
.col p.hint{margin:0;font-size:12px;color:var(--muted)}
|
|
31
|
+
.stack{flex:1 1 auto;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding:3px 6px 20px 3px;margin:0 -6px 0 -3px}
|
|
32
|
+
.lane{display:flex;flex-direction:column;gap:2px;margin-top:4px}.lane strong{font-size:13px;display:flex;align-items:center;gap:6px}.lane span{font-size:12px;color:var(--muted)}.lane.urgent strong{color:var(--red)}
|
|
33
|
+
.empty{font-size:12px;color:var(--faint);padding:10px 2px}
|
|
34
|
+
.card{all:unset;box-sizing:border-box;display:flex;flex-direction:column;gap:7px;width:100%;padding:12px 14px;border-radius:12px;background:var(--surface);border:1px solid var(--line);box-shadow:var(--shadow);cursor:pointer;text-align:left;transition:box-shadow .15s,border-color .15s,transform .15s}
|
|
35
|
+
.card:hover{border-color:var(--faint);box-shadow:var(--shadow-hover);transform:translateY(-1px)}.card[aria-pressed="true"]{box-shadow:0 0 0 2px var(--blue)}
|
|
36
|
+
.card.dev{background:var(--dev-bg);border-color:var(--dev-line)}.card.auto{background:var(--auto-bg);border-color:var(--auto-line)}.card.need{background:var(--red-bg);border-color:var(--red-line)}
|
|
37
|
+
.card .t{display:flex;justify-content:space-between;gap:8px;align-items:flex-start}.card .t strong{font-size:15px;line-height:21px;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
38
|
+
.chip{display:inline-flex;align-items:center;gap:5px;padding:2px 7px;border-radius:6px;font-size:12px;font-weight:500;line-height:18px;background:var(--soft);color:var(--ink2);max-width:100%}
|
|
39
|
+
.card .t .chip{flex:none;max-width:45%;background:var(--surface);border:1px solid var(--line)}.card .t .chip b{font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
40
|
+
.line{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted);min-width:0}.line>.tx{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.line .ic{color:var(--faint)}
|
|
41
|
+
.card .m{font-size:12px;color:var(--ink2);overflow-wrap:anywhere}.card.need .m{color:var(--red);font-weight:600}
|
|
42
|
+
.foot{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;color:var(--muted);padding-top:7px;border-top:1px solid var(--line);margin-top:1px}.foot .line{flex:1 1 auto}.foot .when{flex:none;display:inline-flex;align-items:center;gap:8px;white-space:nowrap}.tm{display:inline-flex;align-items:center;gap:4px}
|
|
43
|
+
.card.dev .foot{border-top-color:var(--dev-line)}.card.auto .foot{border-top-color:var(--auto-line)}.card.need .foot{border-top-color:var(--red-line)}
|
|
44
|
+
.badge{display:inline-flex;align-items:center;gap:4px;padding:1px 7px;border-radius:999px;font-size:12px;font-weight:600;line-height:18px;flex:none;white-space:nowrap}
|
|
45
|
+
.badge.pass{background:var(--green-soft);color:var(--green-ink)}.badge.fail,.badge.blocked{background:var(--red-bg);color:var(--red)}.badge.pending{background:var(--soft);color:var(--muted)}
|
|
46
|
+
.bar{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--muted)}.bar .track{flex:1 1 auto;height:4px;border-radius:2px;background:var(--line);overflow:hidden}.bar .track b{display:block;height:4px;background:var(--orange)}
|
|
47
|
+
aside.detail{flex:0 0 380px;min-width:0;background:var(--surface);border-left:1px solid var(--line);padding:22px 24px;display:flex;flex-direction:column;gap:18px;overflow-y:auto}
|
|
48
|
+
aside.detail h1{margin:0;font-size:22px;line-height:30px;overflow-wrap:anywhere}aside.detail h2{margin:0;font-size:15px;display:flex;align-items:center;gap:7px}
|
|
49
|
+
.chips{display:flex;flex-wrap:wrap;gap:6px}.status{font-size:13px;font-weight:600}
|
|
50
|
+
.runs{display:flex;flex-direction:column;gap:8px;padding-top:14px;border-top:1px solid var(--line)}.run{display:flex;align-items:center;gap:10px;font-size:13px}.run .mono{flex:1 1 auto;overflow-wrap:anywhere}
|
|
51
|
+
.facts{display:grid;grid-template-columns:72px minmax(0,1fr);row-gap:8px;font-size:13px;margin:0;padding-top:14px;border-top:1px solid var(--line)}.facts dt{color:var(--muted)}.facts dd{margin:0;overflow-wrap:anywhere}
|
|
52
|
+
.note{margin:0;color:var(--muted);font-size:12px;line-height:1.7}
|
|
53
|
+
.skel{display:block;border-radius:8px;background:linear-gradient(90deg,var(--skel),var(--skel-hi),var(--skel));background-size:200% 100%;animation:shimmer 1.4s infinite linear}
|
|
54
|
+
@keyframes shimmer{to{background-position:-200% 0}}@media(prefers-reduced-motion:reduce){.skel{animation:none}}
|
|
55
|
+
.skelcard{display:flex;flex-direction:column;gap:9px;padding:14px;border-radius:12px;background:var(--surface);border:1px solid var(--line)}
|
|
56
|
+
.layout{flex:1 1 auto;min-height:0;display:flex}
|
|
57
|
+
nav.list{flex:0 0 300px;min-width:0;padding:12px 10px;background:var(--surface);border-right:1px solid var(--line);display:flex;flex-direction:column;gap:2px;overflow-y:auto}
|
|
58
|
+
.sess{all:unset;box-sizing:border-box;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:3px 10px;align-items:baseline;width:100%;padding:9px 12px;border-radius:10px;cursor:pointer;min-height:44px;transition:background .12s}.sess:hover{background:var(--soft)}.sess[aria-current="true"]{background:var(--blue-soft)}
|
|
59
|
+
.sess strong{font-size:14px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.sess time{font-size:12px;color:var(--muted);white-space:nowrap;text-align:right}
|
|
60
|
+
.sess .m{grid-column:1/-1;font-size:12px;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.sess .m .ic{margin-right:2px;color:var(--faint)}.sess .m i{font-style:normal;margin:0 4px;color:var(--line)}
|
|
61
|
+
main.sessions{flex:1 1 0;min-width:0;padding:22px 28px;display:flex;flex-direction:column;gap:18px;overflow-y:auto}
|
|
62
|
+
main.sessions h1{margin:0;font-size:24px;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.meta{font-size:13px;color:var(--muted);overflow-wrap:anywhere}
|
|
63
|
+
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px}.stat{padding:14px;border-radius:12px;background:var(--surface);border:1px solid var(--line);box-shadow:var(--shadow);display:flex;flex-direction:column;gap:4px}.stat span{font-size:12px;color:var(--muted)}.stat strong{font-size:24px}
|
|
64
|
+
.pills{display:flex;flex-wrap:wrap;gap:8px;align-items:center}.pill{all:unset;box-sizing:border-box;display:inline-flex;gap:6px;align-items:center;padding:6px 12px;border-radius:999px;font-size:13px;cursor:pointer;border:1px solid var(--line);min-height:32px;background:var(--surface)}.pill:hover{border-color:var(--faint)}.pill[aria-pressed="true"]{background:var(--ink);border-color:var(--ink);color:var(--surface)}
|
|
65
|
+
ol.events{margin:0;padding:0;list-style:none;background:var(--surface);border:1px solid var(--line);border-radius:12px;box-shadow:var(--shadow);overflow:hidden;flex:none}
|
|
66
|
+
ol.events li{border-bottom:1px solid var(--line);padding:12px 14px}ol.events li:last-child{border-bottom:0}
|
|
67
|
+
ol.events[data-view="deliveries"] li.hidden-by-view{display:none}
|
|
68
|
+
.row{display:flex;gap:12px;align-items:flex-start;flex-wrap:wrap}.row time{font-size:12px;color:var(--muted);width:56px;flex:none;padding-top:2px}
|
|
69
|
+
.kind{flex:none;background:var(--blue-soft);color:var(--blue-ink)}.kind.read{background:var(--green-soft);color:var(--green-ink)}.kind.prompt{background:#FFF1E3;color:#9A3412}.kind.plain{background:var(--soft);color:var(--ink2)}
|
|
70
|
+
.what{display:flex;flex-direction:column;gap:3px;flex:1 1 200px;min-width:0}.what b{font-weight:500;overflow-wrap:anywhere}.what small{font-size:12px;color:var(--muted)}
|
|
71
|
+
.tag{font-size:11px;font-weight:650;padding:2px 7px;border-radius:5px;background:var(--soft);color:var(--ink2)}.tag.ok{background:var(--green-soft);color:var(--green-ink)}.tag.bad{background:var(--red-bg);color:var(--red)}
|
|
72
|
+
details{margin:8px 0 0 68px}summary{cursor:pointer;font-size:12px;color:var(--blue);font-weight:600}
|
|
73
|
+
pre{white-space:pre-wrap;overflow-wrap:anywhere;font:12px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--bg);border-radius:8px;padding:11px;max-height:480px;overflow:auto;margin:8px 0 0}
|
|
74
|
+
@media(max-width:820px){html,body{height:auto}body{overflow:auto}.body,.layout{flex-direction:column}.board{overflow:visible;flex-direction:column;padding:14px 16px}.col{flex:none;min-width:0}.stack{overflow:visible}aside.detail{flex:none;border-left:0;border-top:1px solid var(--line);overflow:visible}nav.list{flex:none;border-right:0;border-bottom:1px solid var(--line);max-height:300px}main.sessions{overflow:visible}header.top,.filters,.alert{padding-left:16px;padding-right:16px}details{margin-left:0}}`;
|
|
75
|
+
// 内联线性图标(24×24、1.5 描边,风格取自 lucide),页面离线可用;只接受下表中的常量,不拼接外部输入。
|
|
76
|
+
const ICONS = `const PATHS={logo:'<path d="M4 6h16M4 12h10M4 18h6"/>',board:'<rect x="3" y="3" width="7" height="9" rx="1"/><rect x="14" y="3" width="7" height="5" rx="1"/><rect x="14" y="12" width="7" height="9" rx="1"/><rect x="3" y="16" width="7" height="5" rx="1"/>',session:'<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',folder:'<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',branch:'<line x1="6" x2="6" y1="3" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',commit:'<circle cx="12" cy="12" r="3"/><line x1="3" x2="9" y1="12" y2="12"/><line x1="15" x2="21" y1="12" y2="12"/>',clock:'<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',host:'<path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2M20 14h2M15 13v2M9 13v2"/>',pass:'<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>',fail:'<circle cx="12" cy="12" r="10"/><path d="m15 9-6 6M9 9l6 6"/>',pending:'<path d="M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"/>',alert:'<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4M12 17h.01"/>',awaiting:'<circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3M12 17h.01"/>',dev:'<path d="m16 18 6-6-6-6M8 6l-6 6 6 6"/>',review:'<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/><path d="m9 12 2 2 4-4"/>',done:'<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M6 21V9a9 9 0 0 0 9 9"/>',spec:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z"/><path d="M14 2v4a2 2 0 0 0 2 2h4M8 13h8M8 17h5"/>'};
|
|
77
|
+
const icon=(name,size)=>{const node=make('span','ic');node.style.fontSize=(size||14)+'px';node.setAttribute('aria-hidden','true');node.innerHTML='<svg viewBox="0 0 24 24">'+(PATHS[name]||'')+'</svg>';return node};
|
|
78
|
+
const iconText=(name,text,size)=>{const node=make('span');node.append(icon(name,size||14),document.createTextNode(' '+text));return node};`;
|
|
79
|
+
const shell = (title, active, content, script) => `<!doctype html>
|
|
80
|
+
<html lang="zh-CN">
|
|
81
|
+
<head>
|
|
82
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
83
|
+
<title>${title}</title>
|
|
84
|
+
<style>${STYLE}</style>
|
|
85
|
+
</head><body>
|
|
86
|
+
<header class="top">
|
|
87
|
+
<div class="brand"><span class="ic s22" data-icon="logo"></span><strong>Sumi</strong><span class="sum" id="summary">读取中…</span></div>
|
|
88
|
+
<nav class="tabs" aria-label="视图"><a href="/"${active === 'board' ? ' aria-current="page"' : ''}><span class="ic s16" data-icon="board"></span>看板</a><a href="/sessions"${active === 'sessions' ? ' aria-current="page"' : ''}><span class="ic s16" data-icon="session"></span>会话</a></nav>
|
|
89
|
+
<div class="right"><span id="need" hidden></span></div>
|
|
90
|
+
</header>
|
|
91
|
+
<div id="alerts" class="alerts" role="status"></div>
|
|
92
|
+
${content}
|
|
93
|
+
<script>
|
|
94
|
+
const byId=(id)=>document.getElementById(id);
|
|
95
|
+
const make=(tag,className,value)=>{const node=document.createElement(tag);if(className)node.className=className;if(value!==undefined)node.textContent=String(value);return node};
|
|
96
|
+
${ICONS}
|
|
97
|
+
const clock=(value)=>{const date=new Date(value);return Number.isNaN(date.getTime())?'时间未知':date.toLocaleTimeString('zh-CN',{hour12:false})};
|
|
98
|
+
const stamp=(value)=>{const date=new Date(value);return Number.isNaN(date.getTime())?'':date.toLocaleString('zh-CN',{hour12:false,month:'numeric',day:'numeric',hour:'2-digit',minute:'2-digit'})};
|
|
99
|
+
const ago=(value)=>{const time=Date.parse(value);if(Number.isNaN(time))return '';const sec=Math.max(0,(Date.now()-time)/1000);if(sec<60)return '刚刚';if(sec<3600)return Math.floor(sec/60)+' 分钟前';if(sec<86400)return Math.floor(sec/3600)+' 小时前';if(sec<2592000)return Math.floor(sec/86400)+' 天前';return stamp(value)};
|
|
100
|
+
const getJson=async(url)=>{const response=await fetch(url,{cache:'no-store'});if(!response.ok)throw new Error(String(response.status));return response.json()};
|
|
101
|
+
function showAlerts(items){byId('alerts').replaceChildren(...items.map(([tone,name,text])=>{const row=make('div','alert '+tone);row.setAttribute('role','alert');const body=make('span');if(name)body.append(make('b','',name+':'));body.append(document.createTextNode(text));row.append(icon('alert',14),body);return row}))}
|
|
102
|
+
function projectAlerts(board){return board.projects.filter((entry)=>entry.status!=='ok').map((entry)=>[entry.status==='stale'||entry.status==='error'?'bad':'',entry.name,(entry.message||'读取失败')+(entry.readAt?'(上次读取 '+ago(new Date(entry.readAt).toISOString())+')':'')])}
|
|
103
|
+
for(const node of document.querySelectorAll('[data-icon]'))node.replaceWith(icon(node.dataset.icon,Number(node.className.replace(/\\D/g,''))||16));
|
|
104
|
+
${script}
|
|
105
|
+
</script></body></html>`;
|
|
106
|
+
const BOARD_SCRIPT = `
|
|
107
|
+
const COLUMNS=[['awaiting','待确认','awaiting','代理在等你确认后才继续'],['dev','开发中','dev','还没有完整的检查,或任务没做完'],['review','检查与评审','review',''],['done','可合并与已合并','done','检查通过且任务完成,或已合并进默认分支']];
|
|
108
|
+
const RUN={pass:'通过',fail:'失败',blocked:'受阻',pending:'进行中'};
|
|
109
|
+
const RUN_ICON={pass:'pass',fail:'fail',blocked:'alert',pending:'pending'};
|
|
110
|
+
let board=null;let project='';let selected='';
|
|
111
|
+
const visible=()=>board.cards.filter((card)=>!project||card.projectId===project);
|
|
112
|
+
const latestRun=(card)=>(card.runs||[]).find((run)=>!run.partial);
|
|
113
|
+
function runBadge(run){const badge=make('span','badge '+run.conclusion);badge.append(icon(RUN_ICON[run.conclusion]||'pending',13),document.createTextNode(RUN[run.conclusion]||run.conclusion));return badge}
|
|
114
|
+
function sessionLabel(card){const link=card.linkedSession;if(!link)return null;return [link.host,link.title].filter(Boolean).join(' · ')}
|
|
115
|
+
function branchLabel(card){return card.detached?'分离提交 '+card.detached:card.branch||''}
|
|
116
|
+
function renderCard(card){const button=make('button','card '+(card.lane==='needs-you'?'need':card.lane==='auto'?'auto':card.column==='dev'?'dev':''));button.type='button';button.setAttribute('aria-pressed',String(card.id===selected));
|
|
117
|
+
const top=make('span','t');const chip=make('span','chip mono');chip.append(icon('folder',13),make('b','',card.project));top.append(make('strong','',card.title),chip);button.append(top);
|
|
118
|
+
if(card.kind==='branch'){const label=branchLabel(card);if(label&&label!==card.title){const line=make('span','line');line.append(icon(card.detached?'commit':'branch',13),make('span','tx mono',label));button.append(line)}
|
|
119
|
+
if(card.commit&&card.commit.subject&&card.commit.subject!==card.title){const line=make('span','line');line.append(icon('commit',13),make('span','tx',card.commit.subject));button.append(line)}}
|
|
120
|
+
if(card.kind==='branch'&&card.progress&&card.progress.length){const bar=make('span','bar');const track=make('span','track');const fill=make('b');fill.style.width=pct(card)+'%';track.append(fill);const done=card.progress.reduce((sum,item)=>sum+item.done,0);const total=card.progress.reduce((sum,item)=>sum+item.total,0);bar.append(track,document.createTextNode('任务 '+done+'/'+total+(card.progress.length>1?'('+card.progress.length+' 个 change)':'')));button.append(bar)}
|
|
121
|
+
button.append(make('span','m',card.reason));
|
|
122
|
+
const foot=make('span','foot');const who=make('span','line');if(card.kind==='session'){who.append(icon('host',13),make('span','tx',card.host||'宿主未知'))}else{const label=sessionLabel(card);who.append(icon('session',13),make('span','tx',label||'没有关联会话'))}foot.append(who);
|
|
123
|
+
const right=make('span','when');const run=card.kind==='branch'?latestRun(card):null;if(run)right.append(runBadge(run));const at=card.activityAt||card.updatedAt;if(at){const time=make('span','tm');time.append(icon('clock',13),document.createTextNode(ago(at)));right.append(time)}foot.append(right);button.append(foot);
|
|
124
|
+
button.addEventListener('click',()=>{selected=card.id;render()});return button}
|
|
125
|
+
function pct(card){const items=card.progress||[];const total=items.reduce((sum,item)=>sum+item.total,0);return total?Math.round(items.reduce((sum,item)=>sum+item.done,0)/total*100):0}
|
|
126
|
+
function column(def,count){const section=make('section','col');const head=make('header');const heading=make('h2');heading.append(icon(def[2],16),document.createTextNode(def[1]),make('span','n',count));head.append(heading);if(def[3])head.append(make('p','hint',def[3]));const stack=make('div','stack');section.append(head,stack);return [section,stack]}
|
|
127
|
+
function render(){if(!board)return;const cards=visible();const root=byId('board');root.replaceChildren();for(const def of COLUMNS){const mine=cards.filter((card)=>card.column===def[0]);const [section,stack]=column(def,mine.length);if(def[0]==='review'){const need=mine.filter((card)=>card.lane==='needs-you');const auto=mine.filter((card)=>card.lane!=='needs-you');const a=make('div','lane urgent');const title=make('strong');title.append(icon('alert',14),document.createTextNode('需要你 '+need.length));a.append(title,make('span','','代理处理不了:检查受阻或连续两次失败'));stack.append(a,...need.map(renderCard));const b=make('div','lane');b.append(make('strong','','自动处理中 '+auto.length),make('span','','检查在跑或刚失败一次,先不用看'));stack.append(b,...auto.map(renderCard))}else{stack.append(...mine.map(renderCard));if(!mine.length)stack.append(make('div','empty','暂无'))}root.append(section)}
|
|
128
|
+
const branches=board.cards.filter((card)=>card.kind==='branch').length;byId('summary').textContent='本机 '+board.projects.length+' 个项目 · '+branches+' 个分支';const need=byId('need');need.hidden=!board.needsYou;need.replaceChildren(icon('alert',14),document.createTextNode('需要你 '+board.needsYou));showAlerts(projectAlerts(board));
|
|
129
|
+
const picker=byId('project');if(picker.options.length!==board.projects.length+1){picker.replaceChildren(new Option('全部项目',''),...board.projects.map((entry)=>new Option(entry.name,entry.id)));picker.value=project}
|
|
130
|
+
byId('projects').replaceChildren(...board.projects.map((entry)=>{const box=make('div','proj'+(entry.status==='ok'?'':' warn'));box.append(icon('folder',14),make('span','mono',entry.name),make('em','',entry.status==='ok'?'读取于 '+clock(entry.readAt):(entry.message||'')+(entry.readAt?' · 上次读取 '+clock(entry.readAt):'')));return box}));
|
|
131
|
+
renderDetail(cards.find((card)=>card.id===selected))}
|
|
132
|
+
function fact(list,key,value){if(!value)return;list.append(make('dt','',key),make('dd','',value))}
|
|
133
|
+
function renderDetail(card){const box=byId('detail');box.replaceChildren();if(!card){box.append(make('p','note','选择一张卡片查看详情。看板只读:要回答问题或做决定,请回到对应的 AI 会话。'));return}
|
|
134
|
+
const chips=make('div','chips');const branch=make('span','chip mono');branch.append(icon('branch',13),document.createTextNode(branchLabel(card)||card.title));const proj=make('span','chip');proj.append(icon('folder',13),document.createTextNode(card.project));chips.append(branch,proj);if(card.host){const host=make('span','chip');host.append(icon('host',13),document.createTextNode(card.host));chips.append(host)}box.append(chips);
|
|
135
|
+
const head=make('div');head.style.cssText='display:flex;flex-direction:column;gap:6px';const status=make('span','status',COLUMNS.find((def)=>def[0]===card.column)[1]+(card.lane==='needs-you'?' · 需要你':card.lane==='auto'?' · 自动处理中':''));status.style.color=card.lane==='needs-you'?'var(--red)':'var(--ink)';head.append(status,make('h1','',card.title),make('p','note',card.reason));box.append(head);
|
|
136
|
+
const facts=make('dl','facts');fact(facts,'提交',card.commit?card.commit.sha+(card.commit.subject?' '+card.commit.subject:''):'');fact(facts,'change',card.changes&&card.changes.length?card.changes.join('、'):'');fact(facts,'会话',sessionLabel(card)||'');fact(facts,'最近活动',card.activityAt||card.updatedAt?ago(card.activityAt||card.updatedAt):'');if(facts.children.length)box.append(facts);
|
|
137
|
+
if(card.progress&&card.progress.length){const section=make('section','runs');const h=make('h2');h.append(icon('spec',16),document.createTextNode('任务进度'));section.append(h);for(const item of card.progress){const bar=make('div','bar');const track=make('span','track');const fill=make('b');fill.style.width=(item.total?Math.round(item.done/item.total*100):0)+'%';track.append(fill);bar.append(track,document.createTextNode(item.label+' '+item.done+'/'+item.total));section.append(bar)}box.append(section)}
|
|
138
|
+
if(card.runs&&card.runs.length){const section=make('section','runs');const h=make('h2');h.append(icon('review',16),document.createTextNode('最近检查'));section.append(h);for(const run of card.runs){const row=make('div','run');row.append(runBadge(run),make('span','mono',run.runId+(run.partial?'(部分运行)':'')),make('span','note',stamp(run.finishedAt||run.startedAt)));section.append(row)}box.append(section)}
|
|
139
|
+
if(card.kind==='session'){const link=make('a','','在会话页查看');link.href='/sessions#'+card.id;box.append(link)}}
|
|
140
|
+
byId('project').addEventListener('change',(event)=>{project=event.target.value;render()});
|
|
141
|
+
async function refresh(){try{board=await getJson('/api/board');render()}catch{byId('summary').textContent='无法读取 hub 数据';showAlerts([['bad','','无法读取 hub 数据,稍后会自动重试']])}}
|
|
142
|
+
refresh();setInterval(refresh,5000);`;
|
|
143
|
+
const SKELETON_CARD = '<div class="skelcard"><span class="skel" style="height:16px;width:70%"></span><span class="skel" style="height:12px;width:45%"></span><span class="skel" style="height:12px;width:90%"></span></div>';
|
|
144
|
+
const skeletonColumns = ['待确认', '开发中', '检查与评审', '可合并与已合并']
|
|
145
|
+
.map((name) => `<section class="col" aria-busy="true"><header><h2>${name}</h2></header><div class="stack">${SKELETON_CARD}${SKELETON_CARD}</div></section>`)
|
|
146
|
+
.join('');
|
|
147
|
+
export const BOARD_PAGE = shell('Sumi 看板', 'board', `<div class="filters"><label for="project">项目</label><select id="project"><option value="">全部项目</option></select><div id="projects" class="projects" aria-label="项目读取状态"></div></div>
|
|
148
|
+
<div class="body"><main id="board" class="board" aria-label="看板" aria-live="polite">${skeletonColumns}</main><aside id="detail" class="detail" aria-label="详情"><span class="skel" style="height:22px;width:60%"></span><span class="skel" style="height:14px;width:90%"></span><span class="skel" style="height:14px;width:75%"></span></aside></div>`, BOARD_SCRIPT);
|
|
149
|
+
const SESSIONS_SCRIPT = `
|
|
150
|
+
const CHANNELS={prompt:'提示词',startup:'会话开始','session-start':'会话开始',clear:'清空后',compact:'压缩后','subagent-start':'子代理启动','before-edit':'编辑前','after-edit':'编辑后','rules-fallback':'规则兜底','read-gate':'读取门槛','task-select':'任务选择','context-read':'路径查询'};
|
|
151
|
+
const METHODS={'additional-context':['上下文注入',''],denial:['拒绝工具调用','bad'],'tool-output':['AI 主动读取','']};
|
|
152
|
+
const CONFIRM={confirmed:['已进入会话记录','ok'],missing:['未找到','bad'],unknown:['无法核对','']};
|
|
153
|
+
const KINDS={prompt:['你的提示','prompt'],injection:['Sumi 送达',''],'agent-read':['AI 读取','read'],document:['Sumi 读取','plain'],command:['Sumi 命令','plain']};
|
|
154
|
+
const FILTERS=[['deliveries','送达与读取'],['all','全部事件']];
|
|
155
|
+
let sessions=[];let selected=decodeURIComponent(location.hash.slice(1));let events=[];let next=0;let confirmations={};let host='';let project='';let view='deliveries';
|
|
156
|
+
const keyOf=(item)=>item.projectId+':'+item.id;const chars=(value)=>value>=10000?(value/10000).toFixed(1)+' 万':String(value);
|
|
157
|
+
const current=()=>sessions.find((item)=>keyOf(item)===selected);
|
|
158
|
+
function filtered(){return sessions.filter((item)=>(!host||item.host===host)&&(!project||item.projectId===project))}
|
|
159
|
+
function renderList(){const list=byId('list');const items=filtered();list.replaceChildren(...items.map((item)=>{const button=make('button','sess');button.type='button';button.setAttribute('aria-current',String(keyOf(item)===selected));button.title=item.title||'';button.append(make('strong','',item.title||item.session||item.id),make('time','',item.updatedAt?ago(item.updatedAt):''));const meta=make('span','m');const bits=[['folder',item.project],['host',item.host||'宿主未知'],['session','送达 '+item.deliveries+' 次']];if(item.awaiting)bits.push(['awaiting',item.awaiting]);bits.forEach(([name,text],index)=>{if(index)meta.append(make('i','','·'));meta.append(icon(name,13),document.createTextNode(' '+text))});button.append(meta);button.addEventListener('click',()=>select(keyOf(item)));return button}));if(!items.length)list.append(make('div','empty','没有会话。接线 hook 后,新的会话会出现在这里。'))}
|
|
160
|
+
function renderFilters(board){const hosts=[...new Set(sessions.map((item)=>item.host).filter(Boolean))];const projectBox=byId('project');if(projectBox.options.length!==board.projects.length+1){projectBox.replaceChildren(new Option('全部项目',''),...board.projects.map((entry)=>new Option(entry.name,entry.id)));projectBox.value=project}const hostBox=byId('host');if(hostBox.options.length!==hosts.length+1){hostBox.replaceChildren(new Option('全部',''),...hosts.map((name)=>new Option(name,name)));hostBox.value=host}}
|
|
161
|
+
function renderHeader(){const item=current();byId('title').textContent=item?item.title||'未记录提示词的会话':'选择一个会话';byId('title').title=item&&item.title?item.title:'';byId('meta').textContent=item?[item.project,item.host,item.session,(item.checkouts.length>2?item.checkouts.slice(0,2).join('、')+' 等 '+item.checkouts.length+' 个检出':item.checkouts.join('、')),item.agents.length?'子代理 '+item.agents.length+' 个':''].filter(Boolean).join(' · '):'';const stats=byId('stats');if(!item){stats.replaceChildren();return}const count=(state)=>Object.values(confirmations).filter((value)=>value===state).length;stats.replaceChildren(...[[chars(item.chars),'送达字符'],[item.deliveries,'送达次数'],[item.prompts,'你的提示'],[count('confirmed'),'已进入会话记录'],[count('missing'),'未找到'],[item.reads,'AI 主动读取'],[item.denials,'拒绝式送达']].map(([value,label])=>{const box=make('div','stat');box.append(make('span','',label),make('strong','',value));return box}))}
|
|
162
|
+
function groups(items){const map=new Map();for(const entry of items){if(entry.key==='catalog:complete')continue;const prefix=entry.key.split(':')[0];map.set(prefix,[...(map.get(prefix)||[]),entry])}return map}
|
|
163
|
+
function title(event){if(event.kind==='injection')return (CHANNELS[event.channel]||event.channel||'上下文')+(event.agent?' · 子代理':'');if(event.kind==='command')return 'sumi '+(event.command||'')+(Array.isArray(event.args)&&event.args.length?' '+event.args.join(' ').slice(0,80):'');if(event.kind==='prompt')return (event.content||'').split('\\n')[0].slice(0,160);return event.source||''}
|
|
164
|
+
function renderEvent(event){const row=make('li',event.kind==='injection'||event.kind==='prompt'||event.kind==='agent-read'?'':'hidden-by-view');row.dataset.at=event.at||'';const head=make('div','row');const time=make('time','',clock(event.at));if(event.at)time.dateTime=event.at;const kind=KINDS[event.kind]||[event.kind,'plain'];const what=make('span','what');what.append(make('b','',title(event)));const notes=[];if(event.kind==='injection'){const method=METHODS[event.method]||[event.method||'方式未知',''];notes.push(method[0]);if(event.checkout)notes.push('检出 '+event.checkout)}if(event.paths&&event.paths.length)notes.push('触发路径 '+event.paths.slice(0,4).join('、')+(event.paths.length>4?' 等 '+event.paths.length+' 个':''));if(event.selected&&event.selected.length)notes.push('选中 '+event.selected.join('、'));if(notes.length)what.append(make('small','',notes.join(' · ')));head.append(time,make('span','chip kind '+kind[1],kind[0]),what);if(event.kind==='injection'){const state=make('span','tag','核对中');state.dataset.confirm=event.id;head.append(state)}const text=event.kind==='command'?event.output||'':event.content||'';if(text)head.append(make('span','mono note',text.length+' 字'));row.append(head);const lines=[];for(const [prefix,group] of groups(event.items||[]))lines.push('送达 '+group.length+' 条:'+group.slice(0,6).map((entry)=>entry.key).join('、')+(group.length>6?' 等':''));const skipped=event.skipped||[];if(skipped.length)lines.push('跳过 '+skipped.length+' 条:'+skipped.slice(0,4).map((entry)=>entry.key+'('+entry.reason+')').join('、'));if(lines.length){const box=make('div','note');box.style.margin='6px 0 0 68px';box.textContent=lines.join(';');row.append(box)}if(text){const details=make('details');details.append(make('summary','','查看全文'),make('pre','',text));row.append(details)}return row}
|
|
165
|
+
function insert(event){const target=byId('timeline');const row=renderEvent(event);let before=null;for(let node=target.lastElementChild;node;node=node.previousElementSibling){if((node.dataset.at||'')<=(event.at||''))break;before=node}target.insertBefore(row,before)}
|
|
166
|
+
function applyConfirmations(){for(const [id,state] of Object.entries(confirmations)){const node=document.querySelector('[data-confirm="'+id+'"]');if(!node)continue;const def=CONFIRM[state];node.textContent=def[0];node.className='tag '+def[1]}}
|
|
167
|
+
async function loadEvents(key){const item=current();if(!item)return;for(let more=true;more&&key===selected;){const page=await getJson('/api/projects/'+item.projectId+'/sessions/'+item.id+'/events?after='+next);if(key!==selected)return;for(const event of page.events){events.push(event);insert(event)}more=page.more&&page.next>next;next=page.next}byId('count').textContent='共 '+events.length+' 条事件'}
|
|
168
|
+
async function loadConfirmations(key){const item=current();if(!item)return;try{const value=await getJson('/api/projects/'+item.projectId+'/sessions/'+item.id+'/confirmations');if(key!==selected)return;confirmations=value;applyConfirmations();renderHeader()}catch{}}
|
|
169
|
+
async function select(key){if(selected===key)return;selected=key;history.replaceState(null,'','#'+encodeURIComponent(key));events=[];next=0;confirmations={};byId('timeline').replaceChildren();renderList();renderHeader();try{await loadEvents(key);await loadConfirmations(key)}catch{byId('count').textContent='无法读取该会话'}}
|
|
170
|
+
async function refresh(){try{const board=await getJson('/api/board');sessions=board.sessions;byId('summary').textContent='本机 '+board.projects.length+' 个项目 · '+sessions.length+' 个会话';const need=byId('need');need.hidden=!board.needsYou;need.replaceChildren(icon('alert',14),document.createTextNode('需要你 '+board.needsYou));showAlerts(projectAlerts(board));renderFilters(board);if(!current()&&sessions[0]){selected='';await select(keyOf(sessions[0]));return}renderList();renderHeader();if(current()){history.replaceState(null,'','#'+encodeURIComponent(selected));await loadEvents(selected)}}catch{byId('summary').textContent='无法读取 hub 数据';showAlerts([['bad','','无法读取 hub 数据,稍后会自动重试']])}}
|
|
171
|
+
byId('project').addEventListener('change',(event)=>{project=event.target.value;renderList()});byId('host').addEventListener('change',(event)=>{host=event.target.value;renderList()});
|
|
172
|
+
byId('pills').replaceChildren(...FILTERS.map(([id,label])=>{const button=make('button','pill',label);button.type='button';button.setAttribute('aria-pressed',String(id===view));button.addEventListener('click',()=>{view=id;byId('timeline').dataset.view=id;for(const option of byId('pills').children)option.setAttribute('aria-pressed',String(option===button))});return button}));
|
|
173
|
+
addEventListener('hashchange',()=>{const key=decodeURIComponent(location.hash.slice(1));selected='';select(key)});
|
|
174
|
+
refresh();setInterval(refresh,3000);setInterval(()=>{if(selected)loadConfirmations(selected)},8000);`;
|
|
175
|
+
export const SESSIONS_PAGE = shell('Sumi 会话', 'sessions', `<div class="filters"><label for="project">项目</label><select id="project"><option value="">全部项目</option></select><label for="host">代理</label><select id="host"><option value="">全部</option></select></div>
|
|
176
|
+
<div class="layout"><nav id="list" class="list" aria-label="会话列表" aria-busy="true"><span class="skel" style="height:44px"></span><span class="skel" style="height:44px"></span><span class="skel" style="height:44px"></span></nav>
|
|
177
|
+
<main class="sessions"><div><div id="meta" class="meta"></div><h1 id="title">选择一个会话</h1></div>
|
|
178
|
+
<section id="stats" class="stats" aria-label="送达总量"></section>
|
|
179
|
+
<div id="pills" class="pills" role="group" aria-label="筛选事件"></div><span id="count" class="meta"></span>
|
|
180
|
+
<ol id="timeline" class="events" data-view="deliveries" aria-label="事件时间线"></ol>
|
|
181
|
+
<p class="note"><strong>证据范围</strong>:“已进入会话记录”表示这段正文出现在宿主的会话记录文件里,不表示 AI 理解或遵循了它。“无法核对”表示宿主没有提供会话记录。“AI 读取”来自宿主 Read 工具;Shell、MCP 和宿主自动加载的读取不在观测范围内。“Sumi 读取”只表示 Sumi 打开了文档。事件保存在各项目 git 公共目录的 sumi/sessions 下,hub 只读取,可能包含提示词和开发上下文。</p></main></div>`, SESSIONS_SCRIPT);
|
|
182
|
+
//# sourceMappingURL=pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.js","sourceRoot":"","sources":["../../src/hub/pages.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sCAAsC;AAEtC,M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ector } from './board.js';
|
|
3
|
+
export interface HubOptions {
|
|
4
|
+
/** 首选端口;被占用时顺延。0 表示由系统分配(测试用)。 */
|
|
5
|
+
port?: number;
|
|
6
|
+
idleMs?: number;
|
|
7
|
+
checkEveryMs?: number;
|
|
8
|
+
now?: () => number;
|
|
9
|
+
collector?: Collector;
|
|
10
|
+
}
|
|
11
|
+
/** 同一用户已有 hub 在运行。 */
|
|
12
|
+
export declare class HubRunningError extends KernelError {
|
|
13
|
+
}
|
|
14
|
+
export declare const IDLE_MS: number;
|
|
15
|
+
export interface RunningHub {
|
|
16
|
+
url: string;
|
|
17
|
+
port: number;
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
/** 服务关闭(主动关闭或空闲退出)后完成。 */
|
|
20
|
+
closed: Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/** 启动 hub:单实例、只绑定回环地址、只读。进程号锁与状态文件由本函数持有并在关闭时清理。 */
|
|
23
|
+
export declare function startHub(options?: HubOptions): Promise<RunningHub>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { KernelError } from '@sumi/kernel';
|
|
3
|
+
import { buildBoard, createCollector, projectId } from './board.js';
|
|
4
|
+
import { BOARD_PAGE, SESSIONS_PAGE } from './pages.js';
|
|
5
|
+
import { acquireHubLock, HEALTH, HUB_PORT, readProjects, releaseHubFiles, writeHubState } from './state.js';
|
|
6
|
+
/** 同一用户已有 hub 在运行。 */
|
|
7
|
+
export class HubRunningError extends KernelError {
|
|
8
|
+
}
|
|
9
|
+
export const IDLE_MS = 8 * 3600_000;
|
|
10
|
+
const PORT_SPAN = 20;
|
|
11
|
+
function listen(server, first) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
let port = first;
|
|
14
|
+
const attempt = () => {
|
|
15
|
+
server.once('error', (error) => {
|
|
16
|
+
if (error.code === 'EADDRINUSE' && first !== 0 && port < first + PORT_SPAN) {
|
|
17
|
+
port += 1;
|
|
18
|
+
attempt();
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
reject(error);
|
|
22
|
+
});
|
|
23
|
+
server.listen(port, '127.0.0.1', () => {
|
|
24
|
+
server.removeAllListeners('error');
|
|
25
|
+
resolve(server.address().port);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
attempt();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** 启动 hub:单实例、只绑定回环地址、只读。进程号锁与状态文件由本函数持有并在关闭时清理。 */
|
|
32
|
+
export async function startHub(options = {}) {
|
|
33
|
+
if (!acquireHubLock())
|
|
34
|
+
throw new HubRunningError('已有 hub 在运行(sumi hub status 查看,sumi hub stop 停止)');
|
|
35
|
+
const now = options.now ?? Date.now;
|
|
36
|
+
const collector = options.collector ?? createCollector({});
|
|
37
|
+
const startedAt = now();
|
|
38
|
+
let port = 0;
|
|
39
|
+
const server = createServer((req, res) => {
|
|
40
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
41
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
42
|
+
res.setHeader('Content-Security-Policy', "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'");
|
|
43
|
+
if (req.headers.host !== `127.0.0.1:${port}`) {
|
|
44
|
+
res.statusCode = 403;
|
|
45
|
+
res.end('Forbidden');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (req.method !== 'GET') {
|
|
49
|
+
res.statusCode = 405;
|
|
50
|
+
res.end('Method Not Allowed');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
54
|
+
const json = (value) => {
|
|
55
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
56
|
+
if (value === null || value === undefined)
|
|
57
|
+
res.statusCode = 404;
|
|
58
|
+
res.end(JSON.stringify(value ?? null));
|
|
59
|
+
};
|
|
60
|
+
const html = (page) => {
|
|
61
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
62
|
+
res.end(page);
|
|
63
|
+
};
|
|
64
|
+
const detail = /^\/api\/projects\/([A-Za-z0-9_-]+)\/sessions\/([0-9a-f]{32})\/(events|confirmations)$/.exec(url.pathname);
|
|
65
|
+
const fail = () => {
|
|
66
|
+
res.statusCode = 500;
|
|
67
|
+
res.end('Internal Error');
|
|
68
|
+
};
|
|
69
|
+
if (url.pathname === '/api/health')
|
|
70
|
+
json({ ...HEALTH, pid: process.pid });
|
|
71
|
+
else if (url.pathname === '/api/board')
|
|
72
|
+
buildBoard(readProjects(), collector).then(json, fail);
|
|
73
|
+
else if (detail) {
|
|
74
|
+
const entry = readProjects().find((project) => projectId(project.path) === detail[1]);
|
|
75
|
+
const after = Number(url.searchParams.get('after'));
|
|
76
|
+
const args = [
|
|
77
|
+
'--session',
|
|
78
|
+
detail[2],
|
|
79
|
+
...(detail[3] === 'confirmations'
|
|
80
|
+
? ['--confirmations']
|
|
81
|
+
: ['--after', String(Number.isSafeInteger(after) && after >= 0 ? after : 0)]),
|
|
82
|
+
];
|
|
83
|
+
if (!entry)
|
|
84
|
+
json(null);
|
|
85
|
+
else
|
|
86
|
+
collector.detail(entry.path, args).then((result) => json(result?.[detail[3]] ?? null), () => json(null));
|
|
87
|
+
}
|
|
88
|
+
else if (url.pathname === '/')
|
|
89
|
+
html(BOARD_PAGE);
|
|
90
|
+
else if (url.pathname === '/sessions')
|
|
91
|
+
html(SESSIONS_PAGE);
|
|
92
|
+
else {
|
|
93
|
+
res.statusCode = 404;
|
|
94
|
+
res.end('Not found');
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
let closing = null;
|
|
98
|
+
let finished;
|
|
99
|
+
const closed = new Promise((resolve) => (finished = resolve));
|
|
100
|
+
const close = () => (closing ??= (async () => {
|
|
101
|
+
clearInterval(timer);
|
|
102
|
+
server.closeAllConnections();
|
|
103
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
104
|
+
releaseHubFiles(process.pid);
|
|
105
|
+
finished();
|
|
106
|
+
})());
|
|
107
|
+
try {
|
|
108
|
+
port = await listen(server, options.port ?? HUB_PORT);
|
|
109
|
+
writeHubState({ pid: process.pid, port, startedAt, lastActivityAt: startedAt });
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
113
|
+
releaseHubFiles();
|
|
114
|
+
throw error instanceof KernelError ? error : new KernelError(`无法启动 hub:${error.message}`);
|
|
115
|
+
}
|
|
116
|
+
// 最近的会话活动取登记表里最晚的会话开始时间;浏览页面不算
|
|
117
|
+
const idleMs = options.idleMs ?? IDLE_MS;
|
|
118
|
+
const timer = setInterval(() => {
|
|
119
|
+
const lastActivityAt = Math.max(startedAt, ...readProjects().map((project) => project.lastSeenAt));
|
|
120
|
+
if (now() - lastActivityAt > idleMs)
|
|
121
|
+
void close();
|
|
122
|
+
else
|
|
123
|
+
writeHubState({ pid: process.pid, port, startedAt, lastActivityAt });
|
|
124
|
+
}, options.checkEveryMs ?? 60_000);
|
|
125
|
+
timer.unref();
|
|
126
|
+
return { url: `http://127.0.0.1:${port}`, port, close, closed };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/hub/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAW5G,sBAAsB;AACtB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ribution } from '@sumi/plugin-sdk';
|
|
2
|
+
import { type SessionSummary } from '../visualize-sessions.js';
|
|
3
|
+
export declare const SNAPSHOT_SCHEMA = 1;
|
|
4
|
+
export interface RunSummary {
|
|
5
|
+
runId: string;
|
|
6
|
+
flow: string;
|
|
7
|
+
conclusion: string;
|
|
8
|
+
partial: boolean;
|
|
9
|
+
startedAt: string;
|
|
10
|
+
finishedAt: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface CheckoutSnapshot {
|
|
13
|
+
path: string;
|
|
14
|
+
branch: string | null;
|
|
15
|
+
isDefault: boolean;
|
|
16
|
+
merged: boolean;
|
|
17
|
+
/** 最近的运行,新的在前。 */
|
|
18
|
+
runs: RunSummary[];
|
|
19
|
+
contribution: HubContribution;
|
|
20
|
+
/** 本分支相对默认分支改动过的 OpenSpec change 名,最近改动的在前;默认分支或不知道默认分支时缺失。 */
|
|
21
|
+
changes?: string[];
|
|
22
|
+
/** 检出当前提交的短 SHA、主题与提交时间;旧版快照没有此字段,读取方需容错。 */
|
|
23
|
+
lastCommit?: {
|
|
24
|
+
sha: string;
|
|
25
|
+
subject: string;
|
|
26
|
+
at: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export type SessionSnapshot = SessionSummary & {
|
|
30
|
+
awaiting?: string;
|
|
31
|
+
};
|
|
32
|
+
export interface ProjectSnapshot {
|
|
33
|
+
schemaVersion: typeof SNAPSHOT_SCHEMA;
|
|
34
|
+
name: string;
|
|
35
|
+
root: string;
|
|
36
|
+
checkouts: CheckoutSnapshot[];
|
|
37
|
+
sessions: SessionSnapshot[];
|
|
38
|
+
diagnostics: string[];
|
|
39
|
+
}
|
|
40
|
+
/** 项目自己的只读快照:检出与分支、最近运行、会话列表及插件贡献。不修改任何项目数据。 */
|
|
41
|
+
export declare function buildSnapshot(root: string, now?: number): ProjectSnapshot;
|
|
42
|
+
/** 会话明细:直接复用单项目页的账本读取。 */
|
|
43
|
+
export declare function sessionDetail(root: string, id: string, view: {
|
|
44
|
+
confirmations: boolean;
|
|
45
|
+
after: number;
|
|
46
|
+
}): {
|
|
47
|
+
confirmations: Record<string, import("../visualize-sessions.js").Confirmation> | null;
|
|
48
|
+
schemaVersion: number;
|
|
49
|
+
} | {
|
|
50
|
+
events: {
|
|
51
|
+
events: import("../visualize-sessions.js").LedgerEvent[];
|
|
52
|
+
next: number;
|
|
53
|
+
more: boolean;
|
|
54
|
+
} | null;
|
|
55
|
+
schemaVersion: number;
|
|
56
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { loadConfig, loadRegistry, readRecords, resolveArgv } from '@sumi/kernel';
|
|
3
|
+
import { HUB_SNAPSHOT_CAPABILITY, cleanEnv, parseHubContributions, projectWorktrees, spawnCommandSync, withoutSessionEnv, } from '@sumi/plugin-sdk';
|
|
4
|
+
import { sessionReader } from '../visualize-sessions.js';
|
|
5
|
+
export const SNAPSHOT_SCHEMA = 1;
|
|
6
|
+
const RECENT_RUNS = 5;
|
|
7
|
+
const SESSION_WINDOW_MS = 7 * 24 * 3600_000;
|
|
8
|
+
const MAX_SESSIONS = 50;
|
|
9
|
+
const CONTRIBUTION_TIMEOUT_MS = 10_000;
|
|
10
|
+
function git(cwd, args) {
|
|
11
|
+
const result = spawnCommandSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
12
|
+
return { ok: result.status === 0, out: typeof result.stdout === 'string' ? result.stdout.trim() : '' };
|
|
13
|
+
}
|
|
14
|
+
/** 默认分支名:先看 origin/HEAD,再看本地的 main 与 master;都没有时为 null。 */
|
|
15
|
+
function defaultBranch(root) {
|
|
16
|
+
const remote = git(root, ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']);
|
|
17
|
+
if (remote.ok && remote.out.startsWith('origin/'))
|
|
18
|
+
return remote.out.slice('origin/'.length);
|
|
19
|
+
return ['main', 'master'].find((name) => git(root, ['rev-parse', '--verify', '-q', `refs/heads/${name}`]).ok) ?? null;
|
|
20
|
+
}
|
|
21
|
+
/** 分支提交已被默认分支包含,且不是同一个提交(刚从默认分支切出的分支不算已合并)。 */
|
|
22
|
+
function isMerged(checkout, base) {
|
|
23
|
+
if (!base)
|
|
24
|
+
return false;
|
|
25
|
+
const head = git(checkout, ['rev-parse', 'HEAD']);
|
|
26
|
+
if (!head.ok)
|
|
27
|
+
return false;
|
|
28
|
+
return [`origin/${base}`, base].some((ref) => {
|
|
29
|
+
const tip = git(checkout, ['rev-parse', '--verify', '-q', ref]);
|
|
30
|
+
return tip.ok && tip.out !== head.out && git(checkout, ['merge-base', '--is-ancestor', head.out, ref]).ok;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const CHANGE_PATH = /^openspec\/changes\/([a-zA-Z0-9_-]+)\//;
|
|
34
|
+
/** 本分支改动过的 change:未提交的改动在前,其后按提交从新到旧;只看 openspec/changes/<名称>/,不含 archive。 */
|
|
35
|
+
function changedChanges(checkout, base) {
|
|
36
|
+
if (!base)
|
|
37
|
+
return undefined;
|
|
38
|
+
const ref = ['origin/' + base, base].find((name) => git(checkout, ['rev-parse', '--verify', '-q', name]).ok);
|
|
39
|
+
if (!ref)
|
|
40
|
+
return undefined;
|
|
41
|
+
const lines = [
|
|
42
|
+
git(checkout, ['diff', '--name-only', 'HEAD', '--', 'openspec/changes']).out,
|
|
43
|
+
git(checkout, ['ls-files', '--others', '--exclude-standard', '--', 'openspec/changes']).out,
|
|
44
|
+
git(checkout, ['log', '--format=', '--name-only', `${ref}..HEAD`, '--', 'openspec/changes']).out,
|
|
45
|
+
].flatMap((out) => out.split(/\r?\n/));
|
|
46
|
+
const names = lines.flatMap((line) => {
|
|
47
|
+
const name = CHANGE_PATH.exec(line)?.[1];
|
|
48
|
+
return name && name !== 'archive' ? [name] : [];
|
|
49
|
+
});
|
|
50
|
+
return [...new Set(names)];
|
|
51
|
+
}
|
|
52
|
+
function lastCommit(path) {
|
|
53
|
+
const log = git(path, ['log', '-1', '--format=%h%x1f%s%x1f%cI']);
|
|
54
|
+
const [sha, subject, at] = log.out.split('\x1f');
|
|
55
|
+
return log.ok && sha && at ? { sha, subject: subject ?? '', at } : undefined;
|
|
56
|
+
}
|
|
57
|
+
function addContribution(table, key, next) {
|
|
58
|
+
const current = table.get(key) ?? {};
|
|
59
|
+
const awaiting = [current.awaiting, next.awaiting].filter(Boolean).join(';');
|
|
60
|
+
const progress = [...(current.progress ?? []), ...(next.progress ?? [])];
|
|
61
|
+
table.set(key, { ...(awaiting ? { awaiting } : {}), ...(progress.length ? { progress } : {}) });
|
|
62
|
+
}
|
|
63
|
+
/** 调用各插件以 `hub.snapshot` 能力声明的命令并合并结果;某个命令失败只丢弃它的贡献。 */
|
|
64
|
+
function contributions(root, input, diagnostics) {
|
|
65
|
+
const merged = { checkouts: new Map(), sessions: new Map() };
|
|
66
|
+
let registry;
|
|
67
|
+
try {
|
|
68
|
+
registry = loadRegistry(root, loadConfig(root));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
diagnostics.push(`无法加载项目插件:${error.message}`);
|
|
72
|
+
return merged;
|
|
73
|
+
}
|
|
74
|
+
for (const command of registry.commands.values()) {
|
|
75
|
+
if (command.capability !== HUB_SNAPSHOT_CAPABILITY)
|
|
76
|
+
continue;
|
|
77
|
+
const [bin, ...argv] = resolveArgv(command.argv, command.dir);
|
|
78
|
+
const child = spawnCommandSync(bin, argv, {
|
|
79
|
+
cwd: root,
|
|
80
|
+
input: JSON.stringify(input),
|
|
81
|
+
encoding: 'utf8',
|
|
82
|
+
windowsHide: true,
|
|
83
|
+
timeout: CONTRIBUTION_TIMEOUT_MS,
|
|
84
|
+
env: { ...cleanEnv(withoutSessionEnv()), SUMI_ROOT: root },
|
|
85
|
+
});
|
|
86
|
+
const parsed = child.status === 0 && !child.error ? parseHubContributions(child.stdout) : null;
|
|
87
|
+
if (!parsed) {
|
|
88
|
+
diagnostics.push(`快照贡献命令 ${command.name} 失败`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
for (const [key, value] of Object.entries(parsed.checkouts))
|
|
92
|
+
addContribution(merged.checkouts, key, value);
|
|
93
|
+
for (const [key, value] of Object.entries(parsed.sessions))
|
|
94
|
+
addContribution(merged.sessions, key, value);
|
|
95
|
+
}
|
|
96
|
+
return merged;
|
|
97
|
+
}
|
|
98
|
+
/** 项目自己的只读快照:检出与分支、最近运行、会话列表及插件贡献。不修改任何项目数据。 */
|
|
99
|
+
export function buildSnapshot(root, now = Date.now()) {
|
|
100
|
+
const diagnostics = [];
|
|
101
|
+
const base = defaultBranch(root);
|
|
102
|
+
const trees = projectWorktrees(root);
|
|
103
|
+
const checkouts = (trees.length ? trees : [root]).map((path) => {
|
|
104
|
+
const branch = git(path, ['symbolic-ref', '--short', '-q', 'HEAD']);
|
|
105
|
+
const name = branch.ok && branch.out ? branch.out : null;
|
|
106
|
+
return {
|
|
107
|
+
path,
|
|
108
|
+
branch: name,
|
|
109
|
+
isDefault: name !== null && name === base,
|
|
110
|
+
merged: name !== null && name !== base && isMerged(path, base),
|
|
111
|
+
changes: name !== null && name === base ? undefined : changedChanges(path, base),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
const sessions = sessionReader(root)
|
|
115
|
+
.list()
|
|
116
|
+
.filter((session) => session.updatedAt !== null && now - Date.parse(session.updatedAt) <= SESSION_WINDOW_MS)
|
|
117
|
+
.slice(0, MAX_SESSIONS);
|
|
118
|
+
const extra = contributions(root, {
|
|
119
|
+
repoRoot: root,
|
|
120
|
+
checkouts: checkouts.map(({ path, branch, changes }) => ({ path, branch, ...(changes ? { changes } : {}) })),
|
|
121
|
+
sessions: sessions.map(({ id, session }) => ({ id, session })),
|
|
122
|
+
}, diagnostics);
|
|
123
|
+
return {
|
|
124
|
+
schemaVersion: SNAPSHOT_SCHEMA,
|
|
125
|
+
name: basename(root),
|
|
126
|
+
root,
|
|
127
|
+
checkouts: checkouts.map((checkout) => {
|
|
128
|
+
const commit = lastCommit(checkout.path);
|
|
129
|
+
return {
|
|
130
|
+
...checkout,
|
|
131
|
+
runs: readRecords(checkout.path)
|
|
132
|
+
.slice(-RECENT_RUNS)
|
|
133
|
+
.reverse()
|
|
134
|
+
.map((record) => ({
|
|
135
|
+
runId: record.runId,
|
|
136
|
+
flow: record.flow,
|
|
137
|
+
conclusion: record.conclusion,
|
|
138
|
+
partial: record.partial === true,
|
|
139
|
+
startedAt: record.startedAt,
|
|
140
|
+
finishedAt: record.finishedAt ?? null,
|
|
141
|
+
})),
|
|
142
|
+
contribution: extra.checkouts.get(checkout.path) ?? {},
|
|
143
|
+
...(commit ? { lastCommit: commit } : {}),
|
|
144
|
+
};
|
|
145
|
+
}),
|
|
146
|
+
sessions: sessions.map((session) => {
|
|
147
|
+
const awaiting = extra.sessions.get(session.id)?.awaiting;
|
|
148
|
+
return awaiting ? { ...session, awaiting } : session;
|
|
149
|
+
}),
|
|
150
|
+
diagnostics,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** 会话明细:直接复用单项目页的账本读取。 */
|
|
154
|
+
export function sessionDetail(root, id, view) {
|
|
155
|
+
const reader = sessionReader(root);
|
|
156
|
+
return {
|
|
157
|
+
schemaVersion: SNAPSHOT_SCHEMA,
|
|
158
|
+
...(view.confirmations ? { confirmations: reader.confirmations(id) } : { events: reader.events(id, view.after) }),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=snapshot.js.map
|