@fantasticit/sumi 0.13.0 → 0.14.1
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/README.md +7 -7
- package/dist/adapters.d.ts +3 -27
- package/dist/adapters.js +75 -134
- package/dist/adapters.js.map +1 -1
- package/dist/agent-hooks.d.ts +32 -11
- package/dist/agent-hooks.js +546 -194
- package/dist/agent-hooks.js.map +1 -1
- package/dist/agents.d.ts +1 -3
- package/dist/agents.js +12 -15
- package/dist/agents.js.map +1 -1
- package/dist/bin.js +14 -10
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +135 -7
- package/dist/cli.js.map +1 -1
- package/dist/compaction-marker.d.ts +4 -0
- package/dist/compaction-marker.js +37 -0
- package/dist/compaction-marker.js.map +1 -0
- package/dist/config-text.d.ts +1 -1
- package/dist/config-text.js +21 -13
- package/dist/config-text.js.map +1 -1
- package/dist/constraint-list.js +1 -1
- package/dist/constraint-list.js.map +1 -1
- package/dist/context-providers.js +12 -0
- package/dist/context-providers.js.map +1 -0
- package/dist/context.js +49 -51
- package/dist/context.js.map +1 -1
- package/dist/declared-hooks.d.ts +29 -0
- package/dist/declared-hooks.js +99 -0
- package/dist/declared-hooks.js.map +1 -0
- package/dist/hook-output.d.ts +3 -0
- package/dist/hook-output.js +5 -0
- package/dist/hook-output.js.map +1 -0
- package/dist/hook-routing.d.ts +29 -1
- package/dist/hook-routing.js +106 -15
- package/dist/hook-routing.js.map +1 -1
- package/dist/host-adapters.d.ts +32 -0
- package/dist/host-adapters.js +97 -0
- package/dist/host-adapters.js.map +1 -0
- package/dist/instructions.js +7 -5
- package/dist/instructions.js.map +1 -1
- package/dist/launcher.cjs +350 -158
- package/dist/launcher.js +13 -2
- package/dist/launcher.js.map +1 -1
- package/dist/run-stats.d.ts +6 -0
- package/dist/run-stats.js +44 -3
- package/dist/run-stats.js.map +1 -1
- package/dist/scaffold-commands.js +18 -7
- package/dist/scaffold-commands.js.map +1 -1
- package/dist/stop-hint.d.ts +4 -0
- package/dist/stop-hint.js +29 -0
- package/dist/stop-hint.js.map +1 -0
- package/dist/subagent-history.d.ts +2 -0
- package/dist/subagent-history.js +35 -0
- package/dist/subagent-history.js.map +1 -0
- package/dist/task.js +45 -37
- package/dist/task.js.map +1 -1
- package/dist/vendor.js +10 -4
- package/dist/vendor.js.map +1 -1
- package/dist/visualize-page.js +2 -25
- package/dist/visualize-page.js.map +1 -1
- package/node_modules/@sumi/create/dist/scaffold.js +5 -4
- package/node_modules/@sumi/create/dist/scaffold.js.map +1 -1
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/create/template/AGENTS.md +1 -1
- package/node_modules/@sumi/create/template/control/config.yaml +3 -0
- package/node_modules/@sumi/create/template/control/flows/change.flow.yaml +8 -5
- package/node_modules/@sumi/create/template/control/flows/check.flow.yaml +7 -21
- package/node_modules/@sumi/create/template/control/rubrics/behavior.yaml +14 -1
- package/node_modules/@sumi/create/template/control/rubrics/omission.yaml +1 -1
- package/node_modules/@sumi/create/template/control/rubrics/{clean-code.yaml → quality.yaml} +12 -4
- package/node_modules/@sumi/create/template/control/rules/boundaries.md +25 -0
- package/node_modules/@sumi/create/template/control/rules/codecheck.md +1 -1
- package/node_modules/@sumi/create/template/control/rules/development.md +7 -2
- package/node_modules/@sumi/create/template/init/AGENTS.md +1 -1
- package/node_modules/@sumi/create/template/init/control/flows/change.flow.yaml +7 -4
- package/node_modules/@sumi/create/template/init/control/flows/check.flow.yaml +3 -0
- package/node_modules/@sumi/create/template/init/control/rubrics/behavior.yaml +30 -0
- package/node_modules/@sumi/create/template/init/control/rubrics/omission.yaml +13 -0
- package/node_modules/@sumi/create/template/init/control/rubrics/quality.yaml +22 -0
- package/node_modules/@sumi/create/template/init/control/rubrics/security.yaml +20 -0
- package/node_modules/@sumi/create/template/init/openspec/config.yaml +6 -0
- package/node_modules/@sumi/create/template/openspec/config.yaml +6 -0
- package/node_modules/@sumi/kernel/dist/config.d.ts +19 -0
- package/node_modules/@sumi/kernel/dist/config.js +72 -17
- package/node_modules/@sumi/kernel/dist/config.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/context-providers.d.ts +17 -0
- package/node_modules/@sumi/kernel/dist/context-providers.js +74 -0
- package/node_modules/@sumi/kernel/dist/context-providers.js.map +1 -0
- package/node_modules/@sumi/kernel/dist/engine.js +119 -71
- package/node_modules/@sumi/kernel/dist/engine.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/flow.d.ts +7 -0
- package/node_modules/@sumi/kernel/dist/flow.js +16 -0
- package/node_modules/@sumi/kernel/dist/flow.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/index.d.ts +3 -0
- package/node_modules/@sumi/kernel/dist/index.js +3 -0
- package/node_modules/@sumi/kernel/dist/index.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/plan.d.ts +12 -0
- package/node_modules/@sumi/kernel/dist/plan.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/record.d.ts +10 -1
- package/node_modules/@sumi/kernel/dist/record.js +133 -3
- package/node_modules/@sumi/kernel/dist/record.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/resume.d.ts +3 -1
- package/node_modules/@sumi/kernel/dist/resume.js +35 -27
- package/node_modules/@sumi/kernel/dist/resume.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/runtime.d.ts +2 -0
- package/node_modules/@sumi/kernel/dist/runtime.js +30 -0
- package/node_modules/@sumi/kernel/dist/runtime.js.map +1 -0
- package/node_modules/@sumi/kernel/dist/scope.d.ts +2 -1
- package/node_modules/@sumi/kernel/dist/scope.js +2 -2
- package/node_modules/@sumi/kernel/dist/scope.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/source-monitor.d.ts +20 -0
- package/node_modules/@sumi/kernel/dist/source-monitor.js +105 -0
- package/node_modules/@sumi/kernel/dist/source-monitor.js.map +1 -0
- package/node_modules/@sumi/kernel/dist/step-cache.d.ts +1 -1
- package/node_modules/@sumi/kernel/dist/step-cache.js +62 -51
- package/node_modules/@sumi/kernel/dist/step-cache.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/step.d.ts +61 -0
- package/node_modules/@sumi/kernel/dist/step.js +55 -0
- package/node_modules/@sumi/kernel/dist/step.js.map +1 -0
- package/node_modules/@sumi/kernel/package.json +6 -2
- package/node_modules/@sumi/plugin-sdk/README.md +3 -3
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.d.ts +15 -0
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js +28 -0
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/context-scope.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/context-scope.js +49 -0
- package/node_modules/@sumi/plugin-sdk/dist/context-scope.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js +54 -0
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/files.d.ts +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/files.js +64 -13
- package/node_modules/@sumi/plugin-sdk/dist/files.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/host-event.d.ts +9 -2
- package/node_modules/@sumi/plugin-sdk/dist/host-event.js +41 -16
- package/node_modules/@sumi/plugin-sdk/dist/host-event.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/html-page.d.ts +5 -0
- package/node_modules/@sumi/plugin-sdk/dist/html-page.js +93 -0
- package/node_modules/@sumi/plugin-sdk/dist/html-page.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/html-style.d.ts +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/html-style.js +27 -0
- package/node_modules/@sumi/plugin-sdk/dist/html-style.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.d.ts +7 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js +7 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.d.ts +7 -0
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js +41 -0
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/protocol.d.ts +39 -4
- package/node_modules/@sumi/plugin-sdk/dist/protocol.js +12 -4
- package/node_modules/@sumi/plugin-sdk/dist/protocol.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/sdk.js +3 -1
- package/node_modules/@sumi/plugin-sdk/dist/sdk.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-context.d.ts +26 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js +98 -17
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/shell.js +2 -1
- package/node_modules/@sumi/plugin-sdk/dist/shell.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.d.ts +12 -0
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.js +29 -5
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/trace.d.ts +7 -2
- package/node_modules/@sumi/plugin-sdk/dist/trace.js +21 -1
- package/node_modules/@sumi/plugin-sdk/dist/trace.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/validate.js +25 -1
- package/node_modules/@sumi/plugin-sdk/dist/validate.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/yaml-text.d.ts +7 -0
- package/node_modules/@sumi/plugin-sdk/dist/yaml-text.js +116 -0
- package/node_modules/@sumi/plugin-sdk/dist/yaml-text.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/package.json +3 -2
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js +2 -2
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/commands/adopt.js +7 -5
- package/node_modules/@sumi/plugins-core/dist/commands/adopt.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/commands/context-impact.js +9 -21
- package/node_modules/@sumi/plugins-core/dist/commands/context-impact.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/context-provider.d.ts +3 -0
- package/node_modules/@sumi/plugins-core/dist/context-provider.js +45 -0
- package/node_modules/@sumi/plugins-core/dist/context-provider.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/coverage.js +110 -15
- package/node_modules/@sumi/plugins-core/dist/plugins/coverage.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js +32 -5
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js +1 -0
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js.map +1 -1
- package/node_modules/@sumi/plugins-core/instructions/bugfix.md +4 -0
- package/node_modules/@sumi/plugins-core/instructions/feature.md +2 -0
- package/node_modules/@sumi/plugins-core/package.json +2 -2
- package/node_modules/@sumi/plugins-core/sumi-plugins.yaml +1 -0
- package/node_modules/@sumi/plugins-governance/assets/hook-bootstrap.cjs +195 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-hooks.d.ts +12 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-hooks.js +76 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-hooks.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.d.ts +42 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.js +206 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.js +16 -6
- package/node_modules/@sumi/plugins-governance/dist/checkout.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary-after-edit.js +14 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary-after-edit.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary-before-edit.js +22 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary-before-edit.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary-prompt.js +12 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary-prompt.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js +48 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/context-state.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/context-state.js +4 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/context-state.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js +168 -24
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report-check.js +5 -2
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report-check.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js +5 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/resume-work.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/resume-work.js +6 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/resume-work.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/run-policy.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/run-policy.js +19 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/run-policy.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/stop-work.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/stop-work.js +12 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/stop-work.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/view.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/view.js +45 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/view.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/config-recovery.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/config-recovery.js +15 -0
- package/node_modules/@sumi/plugins-governance/dist/config-recovery.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/context-provider.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/context-provider.js +22 -0
- package/node_modules/@sumi/plugins-governance/dist/context-provider.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js +10 -2
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/guard.js +4 -4
- package/node_modules/@sumi/plugins-governance/dist/guard.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/human-stop.d.ts +4 -0
- package/node_modules/@sumi/plugins-governance/dist/human-stop.js +39 -0
- package/node_modules/@sumi/plugins-governance/dist/human-stop.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/index.d.ts +5 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js +5 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/plugins/state-writable.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/plugins/state-writable.js +4 -0
- package/node_modules/@sumi/plugins-governance/dist/plugins/state-writable.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.d.ts +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js +2 -1
- 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 +1 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js +1 -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 +4 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-status.d.ts +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-status.js +22 -3
- package/node_modules/@sumi/plugins-governance/dist/pr-report-status.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/preflight.d.ts +18 -0
- package/node_modules/@sumi/plugins-governance/dist/preflight.js +120 -0
- package/node_modules/@sumi/plugins-governance/dist/preflight.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/protected.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/protected.js +1 -0
- package/node_modules/@sumi/plugins-governance/dist/protected.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/report-view.d.ts +12 -0
- package/node_modules/@sumi/plugins-governance/dist/report-view.js +59 -0
- package/node_modules/@sumi/plugins-governance/dist/report-view.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/state-access.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/state-access.js +35 -0
- package/node_modules/@sumi/plugins-governance/dist/state-access.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/state.js +1 -4
- package/node_modules/@sumi/plugins-governance/dist/state.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/upgrade-command.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/upgrade-command.js +30 -0
- package/node_modules/@sumi/plugins-governance/dist/upgrade-command.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/view-page.d.ts +4 -0
- package/node_modules/@sumi/plugins-governance/dist/view-page.js +51 -0
- package/node_modules/@sumi/plugins-governance/dist/view-page.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/instructions/boundary.md +35 -0
- package/node_modules/@sumi/plugins-governance/instructions/push.md +11 -8
- package/node_modules/@sumi/plugins-governance/package.json +6 -3
- package/node_modules/@sumi/plugins-governance/sumi-plugins.yaml +30 -1
- package/node_modules/@sumi/plugins-openspec/package.json +4 -4
- package/node_modules/@sumi/plugins-precedent/README.md +6 -4
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.d.ts +6 -23
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js +48 -156
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/before-edit-context.js +16 -13
- package/node_modules/@sumi/plugins-precedent/dist/commands/before-edit-context.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/context.js +3 -44
- package/node_modules/@sumi/plugins-precedent/dist/commands/context.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/impact-submit.js +2 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/impact-submit.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-output.d.ts +65 -0
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js +186 -0
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.d.ts +3 -0
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js +48 -0
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js +4 -6
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact.js +1 -2
- package/node_modules/@sumi/plugins-precedent/dist/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/index.d.ts +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/index.js +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/model.d.ts +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/model.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/context-read.js +2 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/context-read.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-precedent/sumi-plugins.yaml +3 -2
- package/node_modules/@sumi/plugins-review/README.md +17 -4
- package/node_modules/@sumi/plugins-review/dist/batch-request.d.ts +22 -0
- package/node_modules/@sumi/plugins-review/dist/batch-request.js +30 -0
- package/node_modules/@sumi/plugins-review/dist/batch-request.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/claude-review-agent.d.ts +8 -0
- package/node_modules/@sumi/plugins-review/dist/claude-review-agent.js +51 -0
- package/node_modules/@sumi/plugins-review/dist/claude-review-agent.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/command-hint.d.ts +7 -0
- package/node_modules/@sumi/plugins-review/dist/command-hint.js +21 -0
- package/node_modules/@sumi/plugins-review/dist/command-hint.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/command-input.d.ts +3 -0
- package/node_modules/@sumi/plugins-review/dist/command-input.js +32 -0
- package/node_modules/@sumi/plugins-review/dist/command-input.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/context.js +3 -69
- package/node_modules/@sumi/plugins-review/dist/commands/context.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/host-model-hook.js +4 -3
- package/node_modules/@sumi/plugins-review/dist/commands/host-model-hook.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/model-recheck.js +37 -25
- package/node_modules/@sumi/plugins-review/dist/commands/model-recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/preflight.js +13 -0
- package/node_modules/@sumi/plugins-review/dist/commands/preflight.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/request-read.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/request-read.js +6 -0
- package/node_modules/@sumi/plugins-review/dist/commands/request-read.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/review-batch.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/review-batch.js +8 -0
- package/node_modules/@sumi/plugins-review/dist/commands/review-batch.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/startup-context.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/startup-context.js +6 -0
- package/node_modules/@sumi/plugins-review/dist/commands/startup-context.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/stats.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js +10 -0
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js +79 -32
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/context-provider.d.ts +3 -0
- package/node_modules/@sumi/plugins-review/dist/context-provider.js +84 -0
- package/node_modules/@sumi/plugins-review/dist/context-provider.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/convergence.d.ts +17 -0
- package/node_modules/@sumi/plugins-review/dist/convergence.js +114 -0
- package/node_modules/@sumi/plugins-review/dist/convergence.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/cost-advice.d.ts +2 -0
- package/node_modules/@sumi/plugins-review/dist/cost-advice.js +35 -0
- package/node_modules/@sumi/plugins-review/dist/cost-advice.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.d.ts +38 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.js +235 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/dispute.d.ts +4 -0
- package/node_modules/@sumi/plugins-review/dist/dispute.js +38 -4
- package/node_modules/@sumi/plugins-review/dist/dispute.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/instructions.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/instructions.js +2 -0
- package/node_modules/@sumi/plugins-review/dist/instructions.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/model-execution.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/model-execution.js +51 -46
- package/node_modules/@sumi/plugins-review/dist/model-execution.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/dispatch.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/plugins/dispatch.js +41 -0
- package/node_modules/@sumi/plugins-review/dist/plugins/dispatch.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js +62 -39
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/rubric.js +3 -337
- package/node_modules/@sumi/plugins-review/dist/plugins/rubric.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/preflight.d.ts +31 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.js +172 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/recheck-tickets.d.ts +26 -0
- package/node_modules/@sumi/plugins-review/dist/recheck-tickets.js +48 -0
- package/node_modules/@sumi/plugins-review/dist/recheck-tickets.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/recheck.d.ts +15 -0
- package/node_modules/@sumi/plugins-review/dist/recheck.js +33 -16
- package/node_modules/@sumi/plugins-review/dist/recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/report.d.ts +5 -1
- package/node_modules/@sumi/plugins-review/dist/report.js +25 -5
- package/node_modules/@sumi/plugins-review/dist/report.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review-evidence.js +2 -2
- package/node_modules/@sumi/plugins-review/dist/review-evidence.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review.d.ts +53 -7
- package/node_modules/@sumi/plugins-review/dist/review.js +100 -38
- package/node_modules/@sumi/plugins-review/dist/review.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/rubric-check.d.ts +4 -0
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js +382 -0
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/startup-context.d.ts +21 -0
- package/node_modules/@sumi/plugins-review/dist/startup-context.js +94 -0
- package/node_modules/@sumi/plugins-review/dist/startup-context.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/stats.d.ts +19 -0
- package/node_modules/@sumi/plugins-review/dist/stats.js +99 -0
- package/node_modules/@sumi/plugins-review/dist/stats.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/submission.js +34 -18
- package/node_modules/@sumi/plugins-review/dist/submission.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/support-scope.d.ts +4 -0
- package/node_modules/@sumi/plugins-review/dist/support-scope.js +9 -0
- package/node_modules/@sumi/plugins-review/dist/support-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/tickets.d.ts +12 -0
- package/node_modules/@sumi/plugins-review/dist/tickets.js +98 -0
- package/node_modules/@sumi/plugins-review/dist/tickets.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/upgrade-flow-plan.js +34 -9
- package/node_modules/@sumi/plugins-review/dist/upgrade-flow-plan.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/upgrade-flow-render.js +2 -3
- package/node_modules/@sumi/plugins-review/dist/upgrade-flow-render.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/upgrade.d.ts +2 -0
- package/node_modules/@sumi/plugins-review/dist/upgrade.js +12 -83
- package/node_modules/@sumi/plugins-review/dist/upgrade.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -5
- package/node_modules/@sumi/plugins-review/sumi-plugins.yaml +22 -1
- package/package.json +10 -10
- package/dist/trace.d.ts +0 -16
- package/dist/trace.js +0 -30
- package/dist/trace.js.map +0 -1
- package/node_modules/@sumi/create/dist/bin.d.ts +0 -2
- package/node_modules/@sumi/create/dist/bin.js +0 -52
- package/node_modules/@sumi/create/dist/bin.js.map +0 -1
- package/node_modules/@sumi/create/template/control/rubrics/architecture.yaml +0 -15
- package/node_modules/@sumi/create/template/control/rubrics/business-impact.yaml +0 -6
- package/node_modules/@sumi/create/template/control/rubrics/device-acceptance.yaml +0 -10
- package/node_modules/@sumi/create/template/control/rubrics/domain.yaml +0 -9
- package/node_modules/@sumi/create/template/init/control/rubrics/architecture.yaml +0 -15
- package/node_modules/@sumi/create/template/init/control/rubrics/business-impact.yaml +0 -6
- package/node_modules/@sumi/plugins-core/dist/tool-batches.d.ts +0 -11
- package/node_modules/@sumi/plugins-core/dist/tool-batches.js +0 -41
- package/node_modules/@sumi/plugins-core/dist/tool-batches.js.map +0 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/approve.js +0 -29
- package/node_modules/@sumi/plugins-governance/dist/commands/approve.js.map +0 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/protected-after-shell.js +0 -20
- package/node_modules/@sumi/plugins-governance/dist/commands/protected-after-shell.js.map +0 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/unlock.js +0 -23
- package/node_modules/@sumi/plugins-governance/dist/commands/unlock.js.map +0 -1
- package/node_modules/@sumi/plugins-governance/dist/hooks.d.ts +0 -2
- package/node_modules/@sumi/plugins-governance/dist/hooks.js +0 -4
- package/node_modules/@sumi/plugins-governance/dist/hooks.js.map +0 -1
- package/node_modules/@sumi/plugins-governance/dist/protected-shell.d.ts +0 -12
- package/node_modules/@sumi/plugins-governance/dist/protected-shell.js +0 -152
- package/node_modules/@sumi/plugins-governance/dist/protected-shell.js.map +0 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/session-start-context.js +0 -6
- package/node_modules/@sumi/plugins-precedent/dist/commands/session-start-context.js.map +0 -1
- /package/{node_modules/@sumi/plugins-governance/dist/commands/approve.d.ts → dist/context-providers.d.ts} +0 -0
- /package/node_modules/@sumi/plugins-governance/dist/commands/{protected-after-shell.d.ts → boundary-after-edit.d.ts} +0 -0
- /package/node_modules/@sumi/plugins-governance/dist/commands/{unlock.d.ts → boundary-before-edit.d.ts} +0 -0
- /package/node_modules/@sumi/{plugins-precedent/dist/commands/session-start-context.d.ts → plugins-governance/dist/commands/boundary-prompt.d.ts} +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/* global process, __dirname */
|
|
2
|
+
/* eslint no-redeclare: ["error", { "builtinGlobals": false }] */
|
|
3
|
+
// generated-by: sumi update
|
|
4
|
+
// 此资产不依赖 node_modules,允许新 worktree 安装依赖后恢复正常守卫。
|
|
5
|
+
async function readInput() {
|
|
6
|
+
const { clearTimeout, setTimeout } = await import('node:timers');
|
|
7
|
+
return new Promise((done) => {
|
|
8
|
+
let raw = '';
|
|
9
|
+
const finish = () => {
|
|
10
|
+
clearTimeout(timer);
|
|
11
|
+
process.stdin.destroy();
|
|
12
|
+
done(raw);
|
|
13
|
+
};
|
|
14
|
+
const timer = setTimeout(finish, 5000);
|
|
15
|
+
process.stdin.setEncoding('utf8');
|
|
16
|
+
process.stdin
|
|
17
|
+
.on('end', finish)
|
|
18
|
+
.on('error', finish)
|
|
19
|
+
.on('data', (chunk) => {
|
|
20
|
+
raw += chunk;
|
|
21
|
+
if (raw.length > 1024 * 1024) return finish();
|
|
22
|
+
try {
|
|
23
|
+
JSON.parse(raw);
|
|
24
|
+
finish();
|
|
25
|
+
} catch {
|
|
26
|
+
// 完整 JSON 到达前继续读取,宿主可以保持 stdin 打开。
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function simpleWords(command) {
|
|
33
|
+
// 动态与复合 shell 输入在无依赖状态下一律拒绝。
|
|
34
|
+
if (typeof command !== 'string' || /[\n\r;&|<>`$%!\\(){}]/.test(command)) return null;
|
|
35
|
+
const parts = command.trim().match(/'[^']*'|"[^"]*"|[^\s'"]+/g);
|
|
36
|
+
if (!parts || parts.join(' ').replace(/\s+/g, ' ') !== command.trim().replace(/\s+/g, ' ')) return null;
|
|
37
|
+
// shell 展开可能把文件名变成 --output / --pre 等选项;只保留完整引号内的字面参数。
|
|
38
|
+
const quoted = (part) => part.startsWith("'") || part.startsWith('"');
|
|
39
|
+
if (parts.some((part) => !quoted(part) && /[*?[\]~]/.test(part))) return null;
|
|
40
|
+
return parts.map((part) => part.replace(/^(['"])(.*)\1$/, '$2'));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function allowedCommand(command, configRecovery = false) {
|
|
44
|
+
const words = simpleWords(command);
|
|
45
|
+
if (!words) return false;
|
|
46
|
+
const [program, operation, ...args] = words;
|
|
47
|
+
if (allowedRecovery(words, configRecovery)) return true;
|
|
48
|
+
if (!configRecovery && ['pnpm', 'npm', 'yarn', 'bun'].includes(program)) {
|
|
49
|
+
if (operation === 'install') return true;
|
|
50
|
+
return (['pnpm', 'npm'].includes(program) && operation === 'i') || (program === 'npm' && operation === 'ci');
|
|
51
|
+
}
|
|
52
|
+
if (['pwd', 'ls', 'cat', 'head', 'tail', 'wc'].includes(program)) return true;
|
|
53
|
+
if (program === 'rg') return !words.some((word) => /^--(?:pre|pre-glob|hostname-bin)(?:=|$)/.test(word));
|
|
54
|
+
if (program !== 'git') return false;
|
|
55
|
+
if (words.some((word) => /^--(?:output|ext-diff|textconv|exec-path|config-env)(?:=|$)/.test(word))) return false;
|
|
56
|
+
if (operation === 'branch') return args.length === 1 && args[0] === '--show-current';
|
|
57
|
+
return ['status', 'diff', 'log', 'show', 'ls-files', 'ls-tree', 'rev-parse'].includes(operation);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function allowedRecovery(words, configRecovery) {
|
|
61
|
+
let args = words;
|
|
62
|
+
if (
|
|
63
|
+
args[0] === 'node' &&
|
|
64
|
+
/^(?:\.\/)?(?:node_modules\/(?:@fantasticit\/sumi|@sumi\/cli)\/dist\/bin\.js|control\/bin\/sumi\.cjs)$/.test(args[1] ?? '')
|
|
65
|
+
)
|
|
66
|
+
args = args.slice(2);
|
|
67
|
+
else if (args[0] === 'sumi') args = args.slice(1);
|
|
68
|
+
else if (['pnpm', 'npm', 'yarn', 'bun'].includes(args[0]) && args[1] === 'exec' && args[2] === 'sumi') args = args.slice(3);
|
|
69
|
+
else return false;
|
|
70
|
+
if (args[0] === 'vendor') return !configRecovery && args.length === 2 && args[1] === '--dependency';
|
|
71
|
+
if (args[0] === '--version') return args.length === 1 || (args.length === 2 && args[1] === '--json');
|
|
72
|
+
if (args[0] === 'update') return !configRecovery && args.slice(1).every((arg) => ['--check', '--json'].includes(arg));
|
|
73
|
+
return args[0] === 'doctor' && args.slice(1).every((arg) => ['--json'].includes(arg));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function allowedInput(raw, configRecovery, { resolve, dirname, basename, realpathSync }) {
|
|
77
|
+
try {
|
|
78
|
+
const input = JSON.parse(raw);
|
|
79
|
+
if (['Read', 'Glob', 'Grep'].includes(input.tool_name)) return true;
|
|
80
|
+
const patchTool = ['apply_patch', 'functions.apply_patch'].includes(input.tool_name);
|
|
81
|
+
const data =
|
|
82
|
+
typeof input.tool_input === 'string' ? (patchTool ? { patch: input.tool_input } : JSON.parse(input.tool_input)) : input.tool_input;
|
|
83
|
+
const shellTool = ['Bash', 'Shell', 'exec_command', 'functions.exec_command'].includes(input.tool_name);
|
|
84
|
+
if (configRecovery) {
|
|
85
|
+
const root = realpathSync(process.cwd());
|
|
86
|
+
const cwd = typeof input.cwd === 'string' ? resolve(root, input.cwd) : root;
|
|
87
|
+
const base = typeof data?.workdir === 'string' ? resolve(cwd, data.workdir) : cwd;
|
|
88
|
+
const configPath = (path) => {
|
|
89
|
+
if (typeof path !== 'string') return false;
|
|
90
|
+
const absolute = resolve(base, path);
|
|
91
|
+
const canonical = resolve(realpathSync(dirname(absolute)), basename(absolute));
|
|
92
|
+
return ['control/config.yaml', 'sumi.config.yaml'].some((file) => canonical === resolve(root, file));
|
|
93
|
+
};
|
|
94
|
+
if (['Edit', 'Write', 'MultiEdit', 'StrReplace'].includes(input.tool_name)) return configPath(data?.file_path);
|
|
95
|
+
if (patchTool) {
|
|
96
|
+
const patch = data?.patch ?? data?.input ?? data?.command;
|
|
97
|
+
if (typeof patch !== 'string' || /^\*\*\* (?:Delete|Move)/m.test(patch)) return false;
|
|
98
|
+
const paths = [...patch.matchAll(/^\*\*\* (?:Add|Update) File: (.+)$/gm)].map((match) => match[1]);
|
|
99
|
+
return paths.length > 0 && paths.every(configPath);
|
|
100
|
+
}
|
|
101
|
+
const words = simpleWords(data?.command ?? data?.cmd);
|
|
102
|
+
if (shellTool && words?.[0] === 'git' && words[1] === 'checkout' && words[2] === '--')
|
|
103
|
+
return words.length > 3 && words.slice(3).every(configPath);
|
|
104
|
+
}
|
|
105
|
+
if (!shellTool) return false;
|
|
106
|
+
return allowedCommand(data?.command ?? data?.cmd, configRecovery);
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function main() {
|
|
113
|
+
const { spawnSync } = await import('node:child_process');
|
|
114
|
+
const { existsSync, realpathSync } = await import('node:fs');
|
|
115
|
+
const { resolve, dirname, basename } = await import('node:path');
|
|
116
|
+
const configRecovery = process.argv[2] === '--recover-config';
|
|
117
|
+
const recovery = process.argv[2] === '--recover' || configRecovery;
|
|
118
|
+
const original = recovery ? JSON.parse(process.argv[3]) : process.argv.slice(2);
|
|
119
|
+
let host = recovery ? original[2] : process.argv[4];
|
|
120
|
+
const entry = recovery ? process.argv[4] : process.argv[5];
|
|
121
|
+
const raw = await readInput();
|
|
122
|
+
const input = (() => {
|
|
123
|
+
try {
|
|
124
|
+
const value = JSON.parse(raw);
|
|
125
|
+
return value && typeof value === 'object' ? value : {};
|
|
126
|
+
} catch {
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
})();
|
|
130
|
+
const detectedHost =
|
|
131
|
+
input.sumi_host ?? (input.conversation_id || input.cursor_version ? 'cursor' : input.thread_id || input.turn_id ? 'codex' : 'claude');
|
|
132
|
+
host = ['claude', 'codex', 'cursor'].includes(host) ? host : detectedHost;
|
|
133
|
+
const runtime = recovery ? null : resolve(__dirname, '../..', entry);
|
|
134
|
+
if (runtime && existsSync(runtime)) {
|
|
135
|
+
const child = spawnSync(process.execPath, [runtime, 'hook', 'before-tool', host], {
|
|
136
|
+
input: raw,
|
|
137
|
+
encoding: 'utf8',
|
|
138
|
+
maxBuffer: 1024 * 1024,
|
|
139
|
+
windowsHide: true,
|
|
140
|
+
});
|
|
141
|
+
const diagnostic = `${child.stdout ?? ''}\n${child.stderr ?? ''}`;
|
|
142
|
+
const incompatible =
|
|
143
|
+
child.status === 3 &&
|
|
144
|
+
(/当前 sumi .*不满足项目要求/.test(diagnostic) ||
|
|
145
|
+
/(?:用法[::]|Usage:).*sumi hook|(?:未知|unknown|unrecognized).*(?:hook|before-tool)/i.test(diagnostic));
|
|
146
|
+
if (!incompatible) {
|
|
147
|
+
process.stdout.write(child.stdout ?? '');
|
|
148
|
+
process.stderr.write(child.stderr ?? '');
|
|
149
|
+
process.exitCode = child.status ?? 2;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const allow = allowedInput(raw, configRecovery, { resolve, dirname, basename, realpathSync });
|
|
154
|
+
const reason = configRecovery
|
|
155
|
+
? process.argv[6]
|
|
156
|
+
: runtime && !existsSync(runtime)
|
|
157
|
+
? `缺少项目依赖 ${entry},请先在仓库根目录安装依赖(例如 pnpm install)。安装与可识别的只读命令可以继续执行`
|
|
158
|
+
: `Sumi runtime 与项目锁定或 hook 协议不兼容,请在仓库根目录执行 node ./${entry} vendor --dependency;缺少或需要升级依赖时先运行 pnpm install`;
|
|
159
|
+
const operation = original[1];
|
|
160
|
+
const notification = recovery && original[0] === 'hook' && !['before-tool', 'context-before-edit'].includes(operation);
|
|
161
|
+
const notificationEvent = [
|
|
162
|
+
'SessionStart',
|
|
163
|
+
'sessionStart',
|
|
164
|
+
'PostModelSwitch',
|
|
165
|
+
'postModelSwitch',
|
|
166
|
+
'Stop',
|
|
167
|
+
'PostToolUse',
|
|
168
|
+
'postToolUse',
|
|
169
|
+
'UserPromptSubmit',
|
|
170
|
+
].includes(input.hook_event_name);
|
|
171
|
+
const declaredNotification = recovery && process.argv[5] === 'notification';
|
|
172
|
+
const legacyNotification = recovery && original[0] !== 'hook' && notificationEvent;
|
|
173
|
+
if (notification || declaredNotification || legacyNotification) {
|
|
174
|
+
process.stderr.write(`${reason}\n`);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (host === 'cursor') {
|
|
178
|
+
process.stdout.write(
|
|
179
|
+
JSON.stringify(allow ? { permission: 'allow' } : { permission: 'deny', user_message: reason, agent_message: reason }),
|
|
180
|
+
);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!allow) {
|
|
184
|
+
process.stdout.write(
|
|
185
|
+
JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: reason } }),
|
|
186
|
+
);
|
|
187
|
+
process.stderr.write(`${reason}\n`);
|
|
188
|
+
process.exitCode = 2;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
main().catch((error) => {
|
|
193
|
+
process.stderr.write(`${error.message}\n`);
|
|
194
|
+
process.exitCode = 2;
|
|
195
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ContextItem, type AfterEditResult } from '@sumi/plugin-sdk';
|
|
2
|
+
export declare const BOUNDARY_PROMPT = "\u82E5\u672C\u6B21\u662F\u9700\u6C42\u5F00\u53D1\u6216\u7F3A\u9677\u4FEE\u590D\uFF0C\u5148\u8D77\u8349\u8FB9\u754C\u7EA6\u5B9A\u5E76\u8FD0\u884C `sumi boundary propose`\uFF0C\u5411\u7528\u6237\u786E\u8BA4\u540E\u518D\u6539\u4EE3\u7801";
|
|
3
|
+
export declare function boundarySummary(root: string, session: string | undefined, paths?: string[], reserved?: number, items?: ContextItem[]): string;
|
|
4
|
+
export declare function boundaryPrompt(root: string, raw: string): AfterEditResult | null;
|
|
5
|
+
export declare function boundaryInjection(root: string, raw: string, paths?: string[], prompt?: boolean): AfterEditResult | null;
|
|
6
|
+
export declare function boundaryBeforeEdit(root: string, raw: string): {
|
|
7
|
+
denial?: string;
|
|
8
|
+
context?: string;
|
|
9
|
+
deliveryKeys?: string[];
|
|
10
|
+
deliveryRecords?: AfterEditResult['deliveryRecords'];
|
|
11
|
+
};
|
|
12
|
+
export declare function boundaryReceipt(root: string, raw: string): void;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { configFile, contextScopeCovers, contextSession, editedPaths, payloadWrites, readContextSession, saveContextSession, contextItemDigest, deliveryRecords, partitionContextRows, isContextDelivery, } from '@sumi/plugin-sdk';
|
|
4
|
+
import { parse } from 'yaml';
|
|
5
|
+
import { boundaryContext, boundaryDecision, boundaryRecord } from './boundary.js';
|
|
6
|
+
import { stopMessage } from './human-stop.js';
|
|
7
|
+
export const BOUNDARY_PROMPT = '若本次是需求开发或缺陷修复,先起草边界约定并运行 `sumi boundary propose`,向用户确认后再改代码';
|
|
8
|
+
export function boundarySummary(root, session, paths = [], reserved = 0, items = boundaryContext(root, paths, session)) {
|
|
9
|
+
return renderBoundary(root, items, reserved).text;
|
|
10
|
+
}
|
|
11
|
+
function renderBoundary(root, items, reserved = 0) {
|
|
12
|
+
const file = configFile(root);
|
|
13
|
+
const config = file ? parse(readFileSync(join(root, file), 'utf8')) : null;
|
|
14
|
+
const configured = config?.agentContext?.outputBudget;
|
|
15
|
+
const budget = Math.max(100, (typeof configured === 'number' ? Math.min(configured, 1800) : 1800) - reserved);
|
|
16
|
+
const header = '边界约定(change 补充或覆盖项目常设边界):';
|
|
17
|
+
const footer = '…边界摘要已截断,请按来源读取原文。';
|
|
18
|
+
const fitted = [];
|
|
19
|
+
const rows = [];
|
|
20
|
+
let used = header.length + footer.length + 2;
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
const row = `- ${item.text.replace(/\s+/g, ' ').slice(0, 150)}${item.source ? `(${item.source})` : ''}`;
|
|
23
|
+
if (used + row.length + 1 > budget)
|
|
24
|
+
break;
|
|
25
|
+
fitted.push(item);
|
|
26
|
+
rows.push(row);
|
|
27
|
+
used += row.length + 1;
|
|
28
|
+
}
|
|
29
|
+
const text = [header, ...rows, ...(fitted.length < items.length ? [footer] : [])].join('\n');
|
|
30
|
+
return { text, fitted };
|
|
31
|
+
}
|
|
32
|
+
export function boundaryPrompt(root, raw) {
|
|
33
|
+
return boundaryInjection(root, raw, [], true);
|
|
34
|
+
}
|
|
35
|
+
export function boundaryInjection(root, raw, paths = [], prompt = false) {
|
|
36
|
+
const session = contextSession(raw) ?? undefined;
|
|
37
|
+
const items = boundaryContext(root, paths, session);
|
|
38
|
+
if (!items.length)
|
|
39
|
+
items.push({ ref: 'boundary:missing', text: '边界文件缺失;按常设边界与保守默认起草,缺失文件只提示。' });
|
|
40
|
+
if (prompt && !boundaryRecord(root, session))
|
|
41
|
+
items.unshift({ ref: 'boundary:prompt', text: BOUNDARY_PROMPT });
|
|
42
|
+
const rows = items.map((item) => ({ key: `item:${item.ref}`, digest: contextItemDigest(item), item }));
|
|
43
|
+
const state = session ? readContextSession(root, session) : null;
|
|
44
|
+
const { fresh } = partitionContextRows(rows, state?.deliveries);
|
|
45
|
+
if (!fresh.length)
|
|
46
|
+
return null;
|
|
47
|
+
const notice = fresh.find((row) => row.item.ref === 'boundary:prompt')?.item.text;
|
|
48
|
+
const content = fresh.filter((row) => row.item.ref !== 'boundary:prompt').map((row) => row.item);
|
|
49
|
+
const rendered = renderBoundary(root, content, BOUNDARY_PROMPT.length + 1);
|
|
50
|
+
const sent = fresh.filter((row) => row.item.ref === 'boundary:prompt' || rendered.fitted.includes(row.item));
|
|
51
|
+
const text = [notice, content.length ? rendered.text : ''].filter(Boolean).join('\n');
|
|
52
|
+
return { additionalContext: text, deliveryKeys: sent.map((row) => row.key), deliveryRecords: deliveryRecords(sent) };
|
|
53
|
+
}
|
|
54
|
+
export function boundaryBeforeEdit(root, raw) {
|
|
55
|
+
if (!payloadWrites(root, raw))
|
|
56
|
+
return {};
|
|
57
|
+
const stopped = stopMessage(root);
|
|
58
|
+
if (stopped)
|
|
59
|
+
return { context: stopped };
|
|
60
|
+
if (contextScopeCovers(root, raw))
|
|
61
|
+
return {};
|
|
62
|
+
const paths = editedPaths(root, raw);
|
|
63
|
+
const session = contextSession(raw) ?? undefined;
|
|
64
|
+
const denial = boundaryDecision(root, session, paths);
|
|
65
|
+
if (denial)
|
|
66
|
+
return { denial };
|
|
67
|
+
const result = boundaryInjection(root, raw, paths);
|
|
68
|
+
return result ? { context: result.additionalContext, deliveryKeys: result.deliveryKeys, deliveryRecords: result.deliveryRecords } : {};
|
|
69
|
+
}
|
|
70
|
+
export function boundaryReceipt(root, raw) {
|
|
71
|
+
const value = JSON.parse(raw);
|
|
72
|
+
const session = contextSession(value.originalInput ?? '{}');
|
|
73
|
+
if (session && Array.isArray(value.keys) && value.keys.every((key) => typeof key === 'string'))
|
|
74
|
+
saveContextSession(root, session, value.keys, undefined, false, Array.isArray(value.records) ? value.records.filter(isContextDelivery) : []);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=boundary-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary-hooks.js","sourceRoot":"","sources":["../src/boundary-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAA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OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IACjD,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,IAAI,MAAM;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,iBAAiB,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACzI,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,GAAW;IACvD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAkE,CAAC;IAC/F,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC;IAC5D,IAAI,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC;QAC5F,kBAAkB,CAChB,IAAI,EACJ,OAAO,EACP,KAAK,CAAC,IAAI,EACV,SAAS,EACT,KAAK,EACL,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAC5E,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ContextItem } from '@sumi/plugin-sdk';
|
|
2
|
+
export declare const BOUNDARY_HEADINGS: readonly ["支持", "不处理", "可接受的异常", "兼容范围", "人工兜底"];
|
|
3
|
+
export interface BoundaryRow {
|
|
4
|
+
section: string;
|
|
5
|
+
text: string;
|
|
6
|
+
suggested: string;
|
|
7
|
+
decision: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface BoundaryRecord {
|
|
10
|
+
status: 'proposed' | 'confirmed' | 'unconfirmed' | 'skipped';
|
|
11
|
+
markdown: string;
|
|
12
|
+
change?: string;
|
|
13
|
+
reason?: string;
|
|
14
|
+
at: string;
|
|
15
|
+
}
|
|
16
|
+
/** 与评审的既有关联规则共用:显式 change、唯一进行中 change、改动路径。 */
|
|
17
|
+
export declare function scopeChanges(root: string, files: string[], change?: string): string[];
|
|
18
|
+
export declare function supportSection(text: string): string | undefined;
|
|
19
|
+
export declare function boundarySources(root: string, changes: string[]): {
|
|
20
|
+
source: string;
|
|
21
|
+
text: string;
|
|
22
|
+
}[];
|
|
23
|
+
export declare function parseBoundary(markdown: string): BoundaryRow[];
|
|
24
|
+
export declare function boundaryRecord(root: string, session?: string | undefined, changes?: string[]): BoundaryRecord | null;
|
|
25
|
+
export declare function boundaryStatus(root: string, session?: string, changes?: string[]): string;
|
|
26
|
+
export declare function proposeBoundary(root: string, session: string, markdown: string, options?: {
|
|
27
|
+
change?: string;
|
|
28
|
+
noOpen?: boolean;
|
|
29
|
+
open?: (path: string) => void;
|
|
30
|
+
}): {
|
|
31
|
+
path: string;
|
|
32
|
+
guidance: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function confirmBoundary(root: string, session: string, options: {
|
|
35
|
+
markdown?: string;
|
|
36
|
+
defaults?: boolean;
|
|
37
|
+
unconfirmed?: boolean;
|
|
38
|
+
change?: string;
|
|
39
|
+
}): BoundaryRecord;
|
|
40
|
+
export declare function skipBoundary(root: string, session: string, reason: string, change?: string): void;
|
|
41
|
+
export declare function boundaryDecision(root: string, session: string | undefined, paths: string[]): string | null;
|
|
42
|
+
export declare function boundaryContext(root: string, paths: string[], session?: string | undefined, change?: string): ContextItem[];
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { configFile, envSession, readContextSession, saveContextMetadata } from '@sumi/plugin-sdk';
|
|
4
|
+
import { parse } from 'yaml';
|
|
5
|
+
import picomatch from 'picomatch';
|
|
6
|
+
import { boundaryPage, openPage, desktopAvailable } from './view-page.js';
|
|
7
|
+
export const BOUNDARY_HEADINGS = ['支持', '不处理', '可接受的异常', '兼容范围', '人工兜底'];
|
|
8
|
+
const KEY = 'gov/boundary';
|
|
9
|
+
const changeSession = (change) => `boundary:change:${change}`;
|
|
10
|
+
/** 与评审的既有关联规则共用:显式 change、唯一进行中 change、改动路径。 */
|
|
11
|
+
export function scopeChanges(root, files, change) {
|
|
12
|
+
if (change) {
|
|
13
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(change))
|
|
14
|
+
throw new Error('OpenSpec change 名称无效');
|
|
15
|
+
return [change];
|
|
16
|
+
}
|
|
17
|
+
const dir = join(root, 'openspec/changes');
|
|
18
|
+
if (!existsSync(dir))
|
|
19
|
+
return [];
|
|
20
|
+
const changes = readdirSync(dir, { withFileTypes: true })
|
|
21
|
+
.filter((e) => e.isDirectory() && e.name !== 'archive')
|
|
22
|
+
.map((e) => e.name)
|
|
23
|
+
.sort();
|
|
24
|
+
return changes.length === 1 ? changes : changes.filter((name) => files.some((f) => f.startsWith(`openspec/changes/${name}/`)));
|
|
25
|
+
}
|
|
26
|
+
export function supportSection(text) {
|
|
27
|
+
return /^## 支持范围[ \t]*\r?\n([\s\S]*?)(?=^#{1,2} |$(?![\s\S]))/m.exec(text)?.[1]?.trim();
|
|
28
|
+
}
|
|
29
|
+
export function boundarySources(root, changes) {
|
|
30
|
+
const project = 'control/rules/boundaries.md';
|
|
31
|
+
const sources = existsSync(join(root, project)) ? [{ source: project, text: readFileSync(join(root, project), 'utf8').trim() }] : [];
|
|
32
|
+
for (const change of changes) {
|
|
33
|
+
scopeChanges(root, [], change);
|
|
34
|
+
const source = `openspec/changes/${change}/design.md`;
|
|
35
|
+
if (!existsSync(join(root, source)))
|
|
36
|
+
continue;
|
|
37
|
+
const text = supportSection(readFileSync(join(root, source), 'utf8'));
|
|
38
|
+
if (text)
|
|
39
|
+
sources.push({ source, text });
|
|
40
|
+
}
|
|
41
|
+
return sources;
|
|
42
|
+
}
|
|
43
|
+
export function parseBoundary(markdown) {
|
|
44
|
+
const rows = [];
|
|
45
|
+
for (const section of BOUNDARY_HEADINGS) {
|
|
46
|
+
const content = new RegExp(`^### ${section}[ \\t]*\\r?\\n([\\s\\S]*?)(?=^#{1,3} |$(?![\\s\\S]))`, 'm').exec(markdown)?.[1];
|
|
47
|
+
if (!content?.trim())
|
|
48
|
+
throw new Error(`边界草稿缺少小节:### ${section}`);
|
|
49
|
+
const entries = content.split(/\r?\n/).filter((line) => /^\s*[-*] /.test(line));
|
|
50
|
+
if (!entries.length)
|
|
51
|
+
throw new Error(`${section} 至少需要一个列表条目`);
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
const suggested = /建议默认[::]\s*([^;;\n]+)/.exec(entry)?.[1]?.trim();
|
|
54
|
+
const decision = /需拍板[::]\s*(是|否)/.exec(entry)?.[1];
|
|
55
|
+
if (!suggested || !decision)
|
|
56
|
+
throw new Error(`${section} 每条必须包含“建议默认:…”与“需拍板:是/否”`);
|
|
57
|
+
rows.push({
|
|
58
|
+
section,
|
|
59
|
+
text: entry
|
|
60
|
+
.replace(/^\s*[-*] /, '')
|
|
61
|
+
.split(/建议默认[::]/)[0]
|
|
62
|
+
.trim(),
|
|
63
|
+
suggested,
|
|
64
|
+
decision: decision === '是',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return rows;
|
|
69
|
+
}
|
|
70
|
+
function readRecord(root, session) {
|
|
71
|
+
const value = readContextSession(root, session)?.metadata?.[KEY];
|
|
72
|
+
if (!value || typeof value !== 'object')
|
|
73
|
+
return null;
|
|
74
|
+
const record = value;
|
|
75
|
+
return ['proposed', 'confirmed', 'unconfirmed', 'skipped'].includes(record.status) && typeof record.markdown === 'string' ? record : null;
|
|
76
|
+
}
|
|
77
|
+
export function boundaryRecord(root, session = envSession(), changes) {
|
|
78
|
+
const local = session ? readRecord(root, session) : null;
|
|
79
|
+
// 显式目标不能被环境会话中另一 change 的记录覆盖。
|
|
80
|
+
if (changes?.length) {
|
|
81
|
+
return (changes.map((change) => readRecord(root, changeSession(change))).find((record) => record !== null) ??
|
|
82
|
+
(local && (!local.change || changes.includes(local.change)) ? local : null));
|
|
83
|
+
}
|
|
84
|
+
if (local)
|
|
85
|
+
return local;
|
|
86
|
+
const associated = session ? readContextSession(root, session)?.metadata?.['gov/change'] : undefined;
|
|
87
|
+
const targets = scopeChanges(root, [], typeof associated === 'string' ? associated : undefined);
|
|
88
|
+
return targets.map((change) => readRecord(root, changeSession(change))).find((record) => record !== null) ?? null;
|
|
89
|
+
}
|
|
90
|
+
function save(root, session, record) {
|
|
91
|
+
if (!saveContextMetadata(root, session, KEY, record))
|
|
92
|
+
throw new Error('无法保存边界记录');
|
|
93
|
+
if (record.change && !saveContextMetadata(root, changeSession(record.change), KEY, record))
|
|
94
|
+
throw new Error('无法保存 change 边界记录');
|
|
95
|
+
}
|
|
96
|
+
export function boundaryStatus(root, session, changes) {
|
|
97
|
+
const record = boundaryRecord(root, session, changes);
|
|
98
|
+
if (!record)
|
|
99
|
+
return '边界约定:无记录';
|
|
100
|
+
if (record.status === 'confirmed')
|
|
101
|
+
return '边界约定:已确认';
|
|
102
|
+
if (record.status === 'skipped')
|
|
103
|
+
return `边界约定:已跳过(${record.reason})`;
|
|
104
|
+
return '边界约定未经用户确认';
|
|
105
|
+
}
|
|
106
|
+
export function proposeBoundary(root, session, markdown, options = {}) {
|
|
107
|
+
const rows = parseBoundary(markdown);
|
|
108
|
+
const associated = readContextSession(root, session)?.metadata?.['gov/change'];
|
|
109
|
+
const change = options.change ?? (typeof associated === 'string' ? associated : scopeChanges(root, [])[0]);
|
|
110
|
+
if (change)
|
|
111
|
+
scopeChanges(root, [], change);
|
|
112
|
+
save(root, session, { status: 'proposed', markdown, ...(change ? { change } : {}), at: new Date().toISOString() });
|
|
113
|
+
const path = boundaryPage(root, change ?? session, markdown, '边界约定未经用户确认');
|
|
114
|
+
if (!options.noOpen && (options.open || desktopAvailable())) {
|
|
115
|
+
try {
|
|
116
|
+
(options.open ?? openPage)(path);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
/* 页面已生成,打开失败只保留路径。 */
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const questions = rows
|
|
123
|
+
.filter((row) => row.decision)
|
|
124
|
+
.map((row) => `- ${row.section}:${row.text} 建议默认:${row.suggested}`)
|
|
125
|
+
.join('\n');
|
|
126
|
+
return {
|
|
127
|
+
path,
|
|
128
|
+
guidance: `边界确认页:${path}\n将以下需拍板条目一次性交给宿主提问工具向用户提问(没有工具时直接在对话提问),附页面路径;用户可回复“按建议”或逐条修改:\n${questions || '无额外需拍板条目,说明沿用常设边界。'}\n回答后运行 sumi boundary confirm <答案文件> 或 --defaults;非交互运行使用 --unconfirmed,不等待审批。`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export function confirmBoundary(root, session, options) {
|
|
132
|
+
const changes = options.change ? scopeChanges(root, [], options.change) : undefined;
|
|
133
|
+
const prior = boundaryRecord(root, session, changes);
|
|
134
|
+
if (!prior)
|
|
135
|
+
throw new Error('先运行 sumi boundary propose <草稿文件>');
|
|
136
|
+
if (!options.markdown && !options.defaults && !options.unconfirmed)
|
|
137
|
+
throw new Error('提供答案文件或 --defaults / --unconfirmed');
|
|
138
|
+
const markdown = options.markdown ?? prior.markdown;
|
|
139
|
+
parseBoundary(markdown);
|
|
140
|
+
const change = options.change ?? prior.change;
|
|
141
|
+
const at = new Date().toISOString();
|
|
142
|
+
const record = { status: options.unconfirmed ? 'unconfirmed' : 'confirmed', markdown, at, ...(change ? { change } : {}) };
|
|
143
|
+
if (change) {
|
|
144
|
+
scopeChanges(root, [], change);
|
|
145
|
+
const file = join(root, `openspec/changes/${change}/design.md`);
|
|
146
|
+
const old = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
147
|
+
const section = `## 支持范围\n\n确认:${options.unconfirmed ? '未经用户确认(非交互运行)' : `用户,${at.slice(0, 10)}`}\n\n${markdown.trim()}\n\n`;
|
|
148
|
+
const next = supportSection(old) !== undefined
|
|
149
|
+
? old.replace(/^## 支持范围[^\n]*\n[\s\S]*?(?=^#{1,2} |$(?![\s\S]))/m, section)
|
|
150
|
+
: `${old.trimEnd()}\n\n${section}`;
|
|
151
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
152
|
+
writeFileSync(file, next);
|
|
153
|
+
}
|
|
154
|
+
save(root, session, record);
|
|
155
|
+
return record;
|
|
156
|
+
}
|
|
157
|
+
export function skipBoundary(root, session, reason, change) {
|
|
158
|
+
if (!reason.trim())
|
|
159
|
+
throw new Error('boundary skip 需要 --reason');
|
|
160
|
+
if (change)
|
|
161
|
+
scopeChanges(root, [], change);
|
|
162
|
+
save(root, session, { status: 'skipped', markdown: '', reason, at: new Date().toISOString(), ...(change ? { change } : {}) });
|
|
163
|
+
}
|
|
164
|
+
export function boundaryDecision(root, session, paths) {
|
|
165
|
+
// 编辑护栏是会话级一次性约束,任何既有记录都足以放行。
|
|
166
|
+
if (session && readRecord(root, session))
|
|
167
|
+
return null;
|
|
168
|
+
if (boundaryRecord(root, session, scopeChanges(root, paths)))
|
|
169
|
+
return null;
|
|
170
|
+
const file = configFile(root);
|
|
171
|
+
const config = file ? parse(readFileSync(join(root, file), 'utf8')) : null;
|
|
172
|
+
const match = (globs, path) => !!globs?.length && picomatch.isMatch(path, globs, { dot: true });
|
|
173
|
+
const business = paths.some((path) => {
|
|
174
|
+
if (/\.(md|mdx|rst|txt)$|\.(test|spec)\.[^/]+$|(^|\/)(tests?|__tests__|fixtures|docs?|control)(\/|$)/i.test(path))
|
|
175
|
+
return false;
|
|
176
|
+
const others = Object.entries(config?.zones ?? {}).flatMap(([zone, globs]) => (zone === 'business' ? [] : globs));
|
|
177
|
+
return match(config?.zones?.business, path) && !match(others, path) && !match(config?.exclude, path);
|
|
178
|
+
});
|
|
179
|
+
return business
|
|
180
|
+
? '开发前先确认边界:起草边界约定,运行 `sumi boundary propose`,按输出向用户提问;纯格式或文档改动运行 `sumi boundary skip --reason …`'
|
|
181
|
+
: null;
|
|
182
|
+
}
|
|
183
|
+
export function boundaryContext(root, paths, session = envSession(), change) {
|
|
184
|
+
if (session && change && !saveContextMetadata(root, session, 'gov/change', change))
|
|
185
|
+
throw new Error('无法关联 change');
|
|
186
|
+
const prior = session ? readRecord(root, session) : null;
|
|
187
|
+
const associated = session ? readContextSession(root, session)?.metadata?.['gov/change'] : undefined;
|
|
188
|
+
const changes = scopeChanges(root, paths, change ?? (typeof associated === 'string' ? associated : prior?.change));
|
|
189
|
+
const sources = boundarySources(root, changes);
|
|
190
|
+
if (prior?.markdown && (!prior.change || (changes.includes(prior.change) && prior.status === 'proposed'))) {
|
|
191
|
+
const source = prior.change ? `openspec/changes/${prior.change}/design.md` : '共享会话边界记录(sumi boundary)';
|
|
192
|
+
const existing = sources.find((entry) => entry.source === source);
|
|
193
|
+
if (existing)
|
|
194
|
+
existing.text = prior.markdown;
|
|
195
|
+
else
|
|
196
|
+
sources.push({ source, text: prior.markdown });
|
|
197
|
+
}
|
|
198
|
+
return sources.flatMap(({ source, text }, i) => {
|
|
199
|
+
const sections = BOUNDARY_HEADINGS.flatMap((section) => {
|
|
200
|
+
const content = new RegExp(`^### ${section}[ \\t]*\\r?\\n([\\s\\S]*?)(?=^#{1,3} |$(?![\\s\\S]))`, 'm').exec(text)?.[1]?.trim();
|
|
201
|
+
return content ? [{ ref: `boundary:${i}-${section}`, text: `${section}:${content}`, source, global: true }] : [];
|
|
202
|
+
});
|
|
203
|
+
return sections.length ? sections : [{ ref: `boundary:${i}`, text, source, global: true }];
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.js","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,mBAAmB,EAAoB,MAAM,kBAAkB,CAAC;AACrH,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAclF,MAAM,GAAG,GAAG,cAAc,CAAC;AAC3B,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,mBAAmB,MAAM,EAAE,CAAC;AAEtE,gDAAgD;AAChD,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAAe,EAAE,MAAe;IACzE,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC9E,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAC3C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,MAAM,OAA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,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;YAC/H,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,IAAI,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,IAAI,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACnH,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -81,6 +81,7 @@ export declare function defaultPrepare(wt: string): string[];
|
|
|
81
81
|
*/
|
|
82
82
|
export declare function runGateFlow(root: string, oid: string, base: string | null, log?: (line: string) => void, options?: {
|
|
83
83
|
force?: boolean;
|
|
84
|
+
beforeCheckout?: () => string | null;
|
|
84
85
|
}): CheckoutRun;
|
|
85
86
|
/** 与门禁同一范围的工作区命令:同一流程与档位、同一基准(无基准时为全量)。 */
|
|
86
87
|
export declare function workspaceCommand(run: CheckoutRun, base: string | null): string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { reportPermissionFailure } from '@sumi/plugin-sdk';
|
|
1
2
|
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { tmpdir } from 'node:os';
|
|
3
4
|
import { basename, dirname, join } from 'node:path';
|
|
4
5
|
import { gitOutput, isCliPackageName, projectEntryPath, projectSumi, spawnCommandSync } from '@sumi/plugin-sdk';
|
|
5
|
-
import { configAt, configBrokenAt } from './protected.js';
|
|
6
|
+
import { DEFAULT_GATE_FLOW, configAt, configBrokenAt } from './protected.js';
|
|
6
7
|
import { gateCacheKey, invalidateGateCache, readGateCache, writeGateCache } from './gate-cache.js';
|
|
7
8
|
// status、worktree list 的输出随文件数与检出数增长,统一用带上限的 gitOutput,不因默认 1MB 上限崩溃。
|
|
8
9
|
const git = (root, args, cwd = root) => gitOutput(cwd, args).trim();
|
|
@@ -199,13 +200,18 @@ export function runGateFlow(root, oid, base, log = () => { }, options = {}) {
|
|
|
199
200
|
if (!config) {
|
|
200
201
|
// 配置损坏或被删除时不能按“尚未接入”放行,否则改坏配置就能跳过全部检查
|
|
201
202
|
if (configBrokenAt(root, oid))
|
|
202
|
-
return { flow:
|
|
203
|
+
return { flow: DEFAULT_GATE_FLOW, wt: '', conclusion: 'fail', brief: `被检提交 ${oid.slice(0, 8)} 的项目配置无法解析,修复后再推送` };
|
|
203
204
|
if (base && configAt(root, base))
|
|
204
|
-
return {
|
|
205
|
-
|
|
205
|
+
return {
|
|
206
|
+
flow: DEFAULT_GATE_FLOW,
|
|
207
|
+
wt: '',
|
|
208
|
+
conclusion: 'fail',
|
|
209
|
+
brief: `被检提交 ${oid.slice(0, 8)} 删除了项目配置,基准提交已接入 sumi`,
|
|
210
|
+
};
|
|
211
|
+
return { flow: DEFAULT_GATE_FLOW, wt: '', conclusion: 'pass', brief: '被检提交没有项目配置(尚未接入 sumi),不运行检查流程' };
|
|
206
212
|
}
|
|
207
213
|
const gate = config.gate ?? {};
|
|
208
|
-
const flow = gate.flow ??
|
|
214
|
+
const flow = gate.flow ?? DEFAULT_GATE_FLOW;
|
|
209
215
|
const key = gate.cache === false ? null : gateCacheKey(root, oid, base, flow, gate.tier);
|
|
210
216
|
const cached = key && !options.force ? readGateCache(root, key) : null;
|
|
211
217
|
if (cached) {
|
|
@@ -221,6 +227,9 @@ export function runGateFlow(root, oid, base, log = () => { }, options = {}) {
|
|
|
221
227
|
...(cached.timing ? { timing: cached.timing } : {}),
|
|
222
228
|
};
|
|
223
229
|
}
|
|
230
|
+
const pending = options.beforeCheckout?.();
|
|
231
|
+
if (pending)
|
|
232
|
+
return { flow, ...(gate.tier ? { tier: gate.tier } : {}), wt: '', conclusion: 'pending', brief: pending };
|
|
224
233
|
const checkoutStart = Date.now();
|
|
225
234
|
const wt = createGateWorktree(root, oid);
|
|
226
235
|
const checkoutMs = Date.now() - checkoutStart;
|
|
@@ -245,7 +254,8 @@ export function runGateFlow(root, oid, base, log = () => { }, options = {}) {
|
|
|
245
254
|
...(run.timing ? { timing: run.timing } : {}),
|
|
246
255
|
});
|
|
247
256
|
}
|
|
248
|
-
catch {
|
|
257
|
+
catch (error) {
|
|
258
|
+
reportPermissionFailure(error);
|
|
249
259
|
// 缓存是优化;无法写入时本次门禁结论仍以现场运行结果为准。
|
|
250
260
|
}
|
|
251
261
|
}
|