@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
package/dist/agent-hooks.js
CHANGED
|
@@ -1,11 +1,165 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
2
3
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
5
|
import { loadConfig, loadRegistry, resolveArgv } from '@sumi/kernel';
|
|
5
|
-
import { cleanEnv, contextSession, hostEvent, parseAfterEditResult, readHookInput, recordDelivery, recordTrace, resetContextSession, spawnCommandSync, traceFields, } from '@sumi/plugin-sdk';
|
|
6
|
+
import { cleanEnv, isContextScope, saveContextScope, contextSession, firstHostString, hostEvent, parseAfterEditResult, readHookInput, recordDelivery, recordTrace, resetContextSession, spawnCommandSync, traceFields, } from '@sumi/plugin-sdk';
|
|
6
7
|
import { registerCommand, requireRoot } from './cli.js';
|
|
7
8
|
import { declaredHooks } from './adapters.js';
|
|
8
|
-
import { routeToOwners } from './hook-routing.js';
|
|
9
|
+
import { acknowledgeRouted, editTool, ROUTED_ENV, routeToOwners, withReceipt, } from './hook-routing.js';
|
|
10
|
+
import { inheritedSubagentHistory } from './subagent-history.js';
|
|
11
|
+
import { clearCompaction, markCompaction, takeCompaction } from './compaction-marker.js';
|
|
12
|
+
import { HOST_ADAPTERS, parseBeforeToolResponse } from './host-adapters.js';
|
|
13
|
+
import { writeHookOutput } from './hook-output.js';
|
|
14
|
+
import { stopHintMessages } from './stop-hint.js';
|
|
15
|
+
/** 约束正文几乎都是中文,上下文接近预算时也要远低于这个上限。 */
|
|
16
|
+
const MAX_COMMAND_OUTPUT = 1024 * 1024;
|
|
17
|
+
function runHookCommand(root, input, name, registry, timeout) {
|
|
18
|
+
const command = registry.commands.get(name);
|
|
19
|
+
if (!command)
|
|
20
|
+
return Promise.resolve({ code: null, stdout: '', stderr: `hook 命令 ${name} 未注册` });
|
|
21
|
+
const [bin, ...argv] = resolveArgv(command.argv, command.dir);
|
|
22
|
+
return new Promise((resolveResult) => {
|
|
23
|
+
const child = spawn(bin, argv, {
|
|
24
|
+
cwd: root,
|
|
25
|
+
env: { ...cleanEnv(), SUMI_ROOT: root, SUMI_BIN: process.env.SUMI_BIN ?? process.argv[1] ?? '' },
|
|
26
|
+
windowsHide: true,
|
|
27
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
28
|
+
});
|
|
29
|
+
let stdout = '';
|
|
30
|
+
let stderr = '';
|
|
31
|
+
let truncated = false;
|
|
32
|
+
let settled = false;
|
|
33
|
+
const finish = (code, diagnostic = '') => {
|
|
34
|
+
if (settled)
|
|
35
|
+
return;
|
|
36
|
+
settled = true;
|
|
37
|
+
if (timer)
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
const notice = truncated ? `hook 命令 ${name} 的输出超过上限,已截断` : '';
|
|
40
|
+
resolveResult({ code, stdout, stderr: [stderr, diagnostic, notice].filter(Boolean).join('\n') });
|
|
41
|
+
};
|
|
42
|
+
const capped = (text, chunk) => {
|
|
43
|
+
truncated ||= text.length + chunk.length > MAX_COMMAND_OUTPUT;
|
|
44
|
+
return (text + chunk).slice(0, MAX_COMMAND_OUTPUT);
|
|
45
|
+
};
|
|
46
|
+
const timer = timeout === undefined
|
|
47
|
+
? null
|
|
48
|
+
: setTimeout(() => {
|
|
49
|
+
child.kill();
|
|
50
|
+
finish(null, 'hook 命令超时');
|
|
51
|
+
}, timeout);
|
|
52
|
+
// 按流解码:多字节字符可能落在两个数据块之间,逐块转字符串会变成乱码
|
|
53
|
+
child.stdout.setEncoding('utf8').on('data', (chunk) => {
|
|
54
|
+
stdout = capped(stdout, chunk);
|
|
55
|
+
});
|
|
56
|
+
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
57
|
+
stderr = capped(stderr, chunk);
|
|
58
|
+
});
|
|
59
|
+
child.on('error', (error) => finish(null, error.message));
|
|
60
|
+
child.on('close', (code) => finish(code));
|
|
61
|
+
child.stdin.on('error', () => { });
|
|
62
|
+
child.stdin.end(input);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** 插件命令并发运行,结果按声明顺序合并;宿主只见一个原生响应。 */
|
|
66
|
+
export async function runBeforeToolChecks(root, input, host) {
|
|
67
|
+
const config = loadConfig(root);
|
|
68
|
+
const registry = loadRegistry(root, config);
|
|
69
|
+
const event = HOST_ADAPTERS[host].normalizeInput('PreToolUse', input);
|
|
70
|
+
// 没有工具名说明负载损坏:不能当作无关工具放行,要让闭合命令判断
|
|
71
|
+
const ignored = event.tool !== null && event.tool !== 'Bash' && !editTool(event.tool);
|
|
72
|
+
if (ignored)
|
|
73
|
+
return { contexts: [], ownContexts: [], denied: null, diagnostics: [], deliveries: [], evidence: {}, receipts: [] };
|
|
74
|
+
const hooks = declaredHooks(registry, config).beforeTool.filter((hook) => hook.tools === 'all' || event.tool === null || editTool(event.tool));
|
|
75
|
+
const results = await Promise.all(hooks.map((hook) => runHookCommand(root, event.pluginInput, hook.command, registry, 10000)));
|
|
76
|
+
const contexts = [];
|
|
77
|
+
const diagnostics = [];
|
|
78
|
+
const denials = [];
|
|
79
|
+
const deliveries = [];
|
|
80
|
+
const evidence = {};
|
|
81
|
+
results.forEach((result, index) => {
|
|
82
|
+
const hook = hooks[index];
|
|
83
|
+
const reason = result.stderr.trim() || `前置命令 ${hook.command} 未正常完成`;
|
|
84
|
+
if (result.code === 2)
|
|
85
|
+
denials.push(reason);
|
|
86
|
+
else if (result.code !== 0 && hook.failure === 'closed')
|
|
87
|
+
denials.push(reason);
|
|
88
|
+
else if (result.code !== 0)
|
|
89
|
+
diagnostics.push(reason);
|
|
90
|
+
if (result.code !== 0 || !result.stdout.trim())
|
|
91
|
+
return;
|
|
92
|
+
try {
|
|
93
|
+
const native = parseBeforeToolResponse(result.stdout, reason);
|
|
94
|
+
if (native.context)
|
|
95
|
+
contexts.push(native.context);
|
|
96
|
+
const parsed = parseAfterEditResult(result.stdout);
|
|
97
|
+
if (parsed) {
|
|
98
|
+
if (parsed.warning)
|
|
99
|
+
diagnostics.push(parsed.warning);
|
|
100
|
+
mergeEvidence(evidence, parsed);
|
|
101
|
+
const command = registry.commands.get(hook.command);
|
|
102
|
+
if (command && parsed.deliveryKeys?.length) {
|
|
103
|
+
const [bin, ...argv] = resolveArgv(command.argv, command.dir);
|
|
104
|
+
deliveries.push({
|
|
105
|
+
argv: [bin, ...argv],
|
|
106
|
+
dir: command.dir,
|
|
107
|
+
keys: parsed.deliveryKeys,
|
|
108
|
+
scopes: parsed.deliveryScopes,
|
|
109
|
+
records: parsed.deliveryRecords,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (native.denied)
|
|
114
|
+
denials.push(native.denied);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
if (hook.failure === 'closed')
|
|
118
|
+
denials.push(`前置命令 ${hook.command} 输出无效 JSON`);
|
|
119
|
+
else
|
|
120
|
+
diagnostics.push(`前置命令 ${hook.command} 输出无效 JSON`);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const ownContexts = [...contexts];
|
|
124
|
+
const routed = denials.length
|
|
125
|
+
? { denied: false, stderr: [], stdout: [], receipts: [] }
|
|
126
|
+
: routeToOwners(root, ['hook', 'before-tool', host], event.pluginInput);
|
|
127
|
+
if (routed.denied)
|
|
128
|
+
denials.push(...routed.stderr);
|
|
129
|
+
else
|
|
130
|
+
diagnostics.push(...routed.stderr);
|
|
131
|
+
for (const output of routed.stdout) {
|
|
132
|
+
try {
|
|
133
|
+
const value = JSON.parse(output);
|
|
134
|
+
const context = firstHostString([value.hookSpecificOutput?.additionalContext, value.additional_context]);
|
|
135
|
+
if (context && !routed.denied)
|
|
136
|
+
contexts.push(context);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
diagnostics.push('转交的前置 hook 输出无效 JSON');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
contexts,
|
|
144
|
+
ownContexts,
|
|
145
|
+
denied: denials.length ? denials.join('\n') : null,
|
|
146
|
+
diagnostics,
|
|
147
|
+
deliveries,
|
|
148
|
+
evidence,
|
|
149
|
+
receipts: routed.receipts,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function acknowledgeBeforeTool(root, input, decision) {
|
|
153
|
+
for (const delivery of decision.deliveries) {
|
|
154
|
+
spawnCommandSync(delivery.argv[0], delivery.argv.slice(1), {
|
|
155
|
+
cwd: root,
|
|
156
|
+
input: JSON.stringify({ originalInput: input, keys: delivery.keys, scopes: delivery.scopes, records: delivery.records }),
|
|
157
|
+
encoding: 'utf8',
|
|
158
|
+
env: { ...cleanEnv(), SUMI_ROOT: root, SUMI_BEFORE_EDIT_DELIVERED: '1' },
|
|
159
|
+
windowsHide: true,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
9
163
|
function mergeEvidence(evidence, result) {
|
|
10
164
|
const items = result.items ?? (result.deliveryKeys ?? []).map((key) => ({ key }));
|
|
11
165
|
if (items.length)
|
|
@@ -30,87 +184,78 @@ function afterEditCommands(registry, shell = false) {
|
|
|
30
184
|
return commands;
|
|
31
185
|
}
|
|
32
186
|
/** 提示词阶段只接受插件成功返回的上下文;失败不影响用户输入。 */
|
|
33
|
-
export function runPromptChecks(root, input, registry
|
|
187
|
+
export async function runPromptChecks(root, input, registry) {
|
|
188
|
+
const config = loadConfig(root);
|
|
189
|
+
const activeRegistry = registry ?? loadRegistry(root, config);
|
|
190
|
+
const names = declaredHooks(activeRegistry, config).onPrompt;
|
|
191
|
+
const results = await Promise.all(names.map((name) => runHookCommand(root, input, name, activeRegistry, 10000)));
|
|
34
192
|
const contexts = [];
|
|
35
193
|
const deliveries = [];
|
|
36
194
|
const evidence = {};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
windowsHide: true,
|
|
50
|
-
});
|
|
51
|
-
if (child.status !== 0 || child.error)
|
|
52
|
-
continue;
|
|
53
|
-
const result = parseAfterEditResult(child.stdout ?? '');
|
|
54
|
-
if (result) {
|
|
55
|
-
contexts.push(result.additionalContext);
|
|
56
|
-
mergeEvidence(evidence, result);
|
|
57
|
-
if (result.deliveryKeys?.length)
|
|
58
|
-
deliveries.push({ argv: [bin, ...argv], dir: command.dir, keys: result.deliveryKeys });
|
|
195
|
+
results.forEach((child, index) => {
|
|
196
|
+
if (child.code !== 0)
|
|
197
|
+
return;
|
|
198
|
+
const result = parseAfterEditResult(child.stdout);
|
|
199
|
+
if (!result)
|
|
200
|
+
return;
|
|
201
|
+
contexts.push(result.additionalContext);
|
|
202
|
+
mergeEvidence(evidence, result);
|
|
203
|
+
const command = activeRegistry.commands.get(names[index]);
|
|
204
|
+
if (command && result.deliveryKeys?.length) {
|
|
205
|
+
const [bin, ...argv] = resolveArgv(command.argv, command.dir);
|
|
206
|
+
deliveries.push({ argv: [bin, ...argv], dir: command.dir, keys: result.deliveryKeys, records: result.deliveryRecords });
|
|
59
207
|
}
|
|
60
|
-
}
|
|
208
|
+
});
|
|
61
209
|
return { contexts, deliveries, evidence };
|
|
62
210
|
}
|
|
63
211
|
export function acknowledgePrompt(root, input, decision) {
|
|
64
212
|
for (const delivery of decision.deliveries ?? []) {
|
|
65
213
|
spawnCommandSync(delivery.argv[0], delivery.argv.slice(1), {
|
|
66
214
|
cwd: root,
|
|
67
|
-
input: JSON.stringify({ originalInput: input, keys: delivery.keys }),
|
|
215
|
+
input: JSON.stringify({ originalInput: input, keys: delivery.keys, records: delivery.records }),
|
|
68
216
|
encoding: 'utf8',
|
|
69
217
|
env: { ...cleanEnv(), SUMI_ROOT: root, SUMI_PROMPT_DELIVERED: '1' },
|
|
70
218
|
windowsHide: true,
|
|
71
219
|
});
|
|
72
220
|
}
|
|
73
221
|
}
|
|
74
|
-
/**
|
|
75
|
-
export function runAfterEditChecks(root, input
|
|
222
|
+
/** 编辑后插件并发执行;显式退出码 2 阻断。 */
|
|
223
|
+
export async function runAfterEditChecks(root, input) {
|
|
224
|
+
const registry = loadRegistry(root, loadConfig(root));
|
|
225
|
+
const commands = afterEditCommands(registry, hostEvent(input)?.tool === 'Bash');
|
|
226
|
+
const results = await Promise.all(commands.map((command) => runHookCommand(root, input, command.name, registry)));
|
|
76
227
|
const contexts = [];
|
|
77
228
|
const deliveries = [];
|
|
78
229
|
const evidence = {};
|
|
79
230
|
const errors = [];
|
|
80
231
|
let code = 0;
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
encoding: 'utf8',
|
|
87
|
-
env: { ...cleanEnv(), SUMI_ROOT: root, SUMI_BIN: process.env.SUMI_BIN ?? process.argv[1] ?? '' },
|
|
88
|
-
windowsHide: true,
|
|
89
|
-
});
|
|
90
|
-
if (child.status !== 0) {
|
|
91
|
-
const detail = child.stderr || child.error?.message || `编辑后命令 ${command.name} 被信号终止或未正常退出`;
|
|
92
|
-
errors.push(detail);
|
|
93
|
-
if (child.status === 2)
|
|
232
|
+
results.forEach((child, index) => {
|
|
233
|
+
const command = commands[index];
|
|
234
|
+
if (child.code !== 0) {
|
|
235
|
+
errors.push(child.stderr || `编辑后命令 ${command.name} 被信号终止或未正常退出`);
|
|
236
|
+
if (child.code === 2)
|
|
94
237
|
code = 2;
|
|
95
|
-
else if (code
|
|
96
|
-
code = child.
|
|
97
|
-
|
|
238
|
+
else if (code === 0)
|
|
239
|
+
code = child.code ?? 1;
|
|
240
|
+
return;
|
|
98
241
|
}
|
|
99
|
-
const result = parseAfterEditResult(child.stdout
|
|
100
|
-
if (result)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
242
|
+
const result = parseAfterEditResult(child.stdout);
|
|
243
|
+
if (!result)
|
|
244
|
+
return;
|
|
245
|
+
contexts.push(result.additionalContext);
|
|
246
|
+
mergeEvidence(evidence, result);
|
|
247
|
+
if (result.deliveryKeys?.length) {
|
|
248
|
+
const [bin, ...argv] = resolveArgv(command.argv, command.dir);
|
|
249
|
+
deliveries.push({ argv: [bin, ...argv], dir: command.dir, keys: result.deliveryKeys, records: result.deliveryRecords });
|
|
105
250
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
108
253
|
code,
|
|
109
254
|
contexts,
|
|
110
|
-
...(Object.keys(evidence).length ? { evidence } : {}),
|
|
111
255
|
stderr: errors.reduce((all, detail) => `${all}${all && !all.endsWith('\n') ? '\n' : ''}${detail}`, ''),
|
|
256
|
+
...(deliveries.length ? { deliveries } : {}),
|
|
257
|
+
...(Object.keys(evidence).length ? { evidence } : {}),
|
|
112
258
|
};
|
|
113
|
-
return deliveries.length ? { ...decision, deliveries } : decision;
|
|
114
259
|
}
|
|
115
260
|
export function renderAfterEditResponse(agent, decision) {
|
|
116
261
|
if (decision.code !== 0) {
|
|
@@ -121,20 +266,17 @@ export function renderAfterEditResponse(agent, decision) {
|
|
|
121
266
|
stderr: context ? `${decision.stderr}${decision.stderr.endsWith('\n') ? '' : '\n'}${context}` : decision.stderr,
|
|
122
267
|
};
|
|
123
268
|
}
|
|
124
|
-
if (!decision.contexts.length
|
|
269
|
+
if (!decision.contexts.length)
|
|
125
270
|
return { code: 0, stdout: '', stderr: '' };
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
stdout: JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: decision.contexts.join('\n\n') } }),
|
|
129
|
-
stderr: '',
|
|
130
|
-
};
|
|
271
|
+
const event = agent === 'cursor' ? 'postToolUse' : 'PostToolUse';
|
|
272
|
+
return { code: 0, stdout: HOST_ADAPTERS[agent].formatOutput(event, { contexts: decision.contexts }), stderr: '' };
|
|
131
273
|
}
|
|
132
274
|
/** 只有输出已交给适配层,才通知插件记录本次实际送达的键。 */
|
|
133
275
|
export function acknowledgeAfterEdit(root, input, decision) {
|
|
134
276
|
for (const delivery of decision.deliveries ?? []) {
|
|
135
277
|
spawnCommandSync(delivery.argv[0], delivery.argv.slice(1), {
|
|
136
278
|
cwd: root,
|
|
137
|
-
input: JSON.stringify({ originalInput: input, keys: delivery.keys }),
|
|
279
|
+
input: JSON.stringify({ originalInput: input, keys: delivery.keys, records: delivery.records }),
|
|
138
280
|
encoding: 'utf8',
|
|
139
281
|
env: { ...cleanEnv(), SUMI_ROOT: root, SUMI_AFTER_EDIT_DELIVERED: '1' },
|
|
140
282
|
windowsHide: true,
|
|
@@ -155,31 +297,24 @@ function stopCommands(registry) {
|
|
|
155
297
|
}
|
|
156
298
|
return commands;
|
|
157
299
|
}
|
|
158
|
-
/**
|
|
159
|
-
export function runStopChecks(root, input
|
|
300
|
+
/** 停止检查并发运行;没有固定超时,显式退出码 2 阻断。 */
|
|
301
|
+
export async function runStopChecks(root, input) {
|
|
302
|
+
const registry = loadRegistry(root, loadConfig(root));
|
|
303
|
+
const commands = stopCommands(registry);
|
|
304
|
+
const results = await Promise.all(commands.map((command) => runHookCommand(root, input, command.name, registry)));
|
|
160
305
|
const reasons = [];
|
|
161
306
|
const warnings = [];
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
cwd: root,
|
|
166
|
-
input,
|
|
167
|
-
encoding: 'utf8',
|
|
168
|
-
env: { ...cleanEnv(), SUMI_ROOT: root, SUMI_BIN: process.env.SUMI_BIN ?? process.argv[1] ?? '' },
|
|
169
|
-
windowsHide: true,
|
|
170
|
-
});
|
|
171
|
-
const detail = `${child.stderr ?? ''}${child.stdout ?? ''}`.trim();
|
|
172
|
-
if (child.status === 0) {
|
|
307
|
+
results.forEach((child, index) => {
|
|
308
|
+
const detail = `${child.stderr}${child.stdout}`.trim();
|
|
309
|
+
if (child.code === 0) {
|
|
173
310
|
if (detail)
|
|
174
311
|
warnings.push(detail);
|
|
175
312
|
}
|
|
176
|
-
else if (child.
|
|
177
|
-
reasons.push(detail || `停止检查 ${
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
}
|
|
313
|
+
else if (child.code === 2)
|
|
314
|
+
reasons.push(detail || `停止检查 ${commands[index].name} 请求继续处理`);
|
|
315
|
+
else
|
|
316
|
+
warnings.push(detail || `停止检查 ${commands[index].name} 无法完成(退出码 ${child.code ?? '未知'})`);
|
|
317
|
+
});
|
|
183
318
|
return { blocked: reasons.length > 0, reasons, ...(warnings.length ? { warnings } : {}) };
|
|
184
319
|
}
|
|
185
320
|
function stopPayload(input) {
|
|
@@ -196,7 +331,8 @@ function retryFile(root, agent, session) {
|
|
|
196
331
|
const common = spawnCommandSync('git', ['rev-parse', '--git-common-dir'], { cwd: root, encoding: 'utf8', windowsHide: true });
|
|
197
332
|
const oid = head.stdout?.trim();
|
|
198
333
|
const dir = common.stdout?.trim();
|
|
199
|
-
|
|
334
|
+
const validHead = head.status === 0 && Boolean(oid) && /^[0-9a-f]{40,64}$/i.test(oid ?? '');
|
|
335
|
+
if (!validHead || common.status !== 0 || !dir)
|
|
200
336
|
return null;
|
|
201
337
|
const key = createHash('sha256')
|
|
202
338
|
.update(JSON.stringify([agent, session, oid.toLowerCase()]))
|
|
@@ -204,14 +340,14 @@ function retryFile(root, agent, session) {
|
|
|
204
340
|
return join(resolve(root, dir), 'sumi', 'agent-stop-retries', key);
|
|
205
341
|
}
|
|
206
342
|
/** 跨进程 Stop 续跑熔断:稳定会话和同一 HEAD 最多阻断一次。 */
|
|
207
|
-
export function runAgentStop(root, agent, input) {
|
|
343
|
+
export async function runAgentStop(root, agent, input, checks) {
|
|
208
344
|
const payload = stopPayload(input);
|
|
209
345
|
if (payload?.stop_hook_active === true || (typeof payload?.loop_count === 'number' && payload.loop_count > 0)) {
|
|
210
346
|
return { blocked: false, reasons: [] };
|
|
211
347
|
}
|
|
212
|
-
const session = [payload?.session_id, payload?.thread_id, payload?.conversation_id]
|
|
348
|
+
const session = firstHostString([payload?.session_id, payload?.thread_id, payload?.conversation_id], 512);
|
|
213
349
|
const file = session ? retryFile(root, agent, session) : null;
|
|
214
|
-
const decision = runStopChecks(root, input);
|
|
350
|
+
const decision = checks ?? (await runStopChecks(root, input));
|
|
215
351
|
if (!decision.blocked)
|
|
216
352
|
return decision;
|
|
217
353
|
if (file && existsSync(file)) {
|
|
@@ -251,136 +387,352 @@ export function runAgentStop(root, agent, input) {
|
|
|
251
387
|
}
|
|
252
388
|
/** 把策略中立的阻断结论转换为各工具的原生 Stop 响应。 */
|
|
253
389
|
export function renderStopResponse(agent, decision) {
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
390
|
+
const denied = decision.blocked ? decision.reasons.join('\n\n') : undefined;
|
|
391
|
+
const warning = decision.warnings?.length ? `Sumi Stop 提醒:${decision.warnings.join('\n')}` : undefined;
|
|
392
|
+
return { code: 0, stdout: HOST_ADAPTERS[agent].formatOutput(agent === 'cursor' ? 'stop' : 'Stop', { denied, warning }), stderr: '' };
|
|
393
|
+
}
|
|
394
|
+
const NEW_EVENTS = {
|
|
395
|
+
'before-tool': { claude: 'PreToolUse', codex: 'PreToolUse', cursor: 'preToolUse' },
|
|
396
|
+
'after-tool': { claude: 'PostToolUse', codex: 'PostToolUse', cursor: 'postToolUse' },
|
|
397
|
+
'session-start': { claude: 'SessionStart', codex: 'SessionStart', cursor: 'sessionStart' },
|
|
398
|
+
'subagent-start': { claude: 'SubagentStart', codex: 'SubagentStart', cursor: 'subagentStart' },
|
|
399
|
+
'post-compact': { claude: 'PostCompact', codex: 'PostCompact', cursor: 'postCompact' },
|
|
400
|
+
'model-switch': { claude: 'PostModelSwitch', codex: 'PostModelSwitch', cursor: 'postModelSwitch' },
|
|
401
|
+
'user-prompt': { claude: 'UserPromptSubmit', codex: 'UserPromptSubmit', cursor: 'beforeSubmitPrompt' },
|
|
402
|
+
stop: { claude: 'Stop', codex: 'Stop', cursor: 'stop' },
|
|
403
|
+
};
|
|
404
|
+
const HOOK_OPERATIONS = [
|
|
405
|
+
'agent-stop',
|
|
406
|
+
'agent-after-edit',
|
|
407
|
+
'agent-after-read',
|
|
408
|
+
'agent-user-prompt',
|
|
409
|
+
'agent-session-start',
|
|
410
|
+
'agent-subagent-start',
|
|
411
|
+
'context-before-edit',
|
|
412
|
+
...Object.keys(NEW_EVENTS),
|
|
413
|
+
];
|
|
414
|
+
const HOOK_USAGE = `sumi hook <${HOOK_OPERATIONS.join('|')}> <claude|codex|cursor>`;
|
|
415
|
+
function recordContexts(ctx, channel, decision) {
|
|
280
416
|
if (!decision.contexts.length)
|
|
281
417
|
return;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
418
|
+
recordDelivery(ctx.root, ctx.raw, {
|
|
419
|
+
channel,
|
|
420
|
+
method: 'additional-context',
|
|
421
|
+
content: decision.contexts.join('\n\n'),
|
|
422
|
+
host: ctx.host,
|
|
423
|
+
...decision.evidence,
|
|
424
|
+
});
|
|
287
425
|
}
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (!
|
|
293
|
-
|
|
294
|
-
|
|
426
|
+
async function compactContext(ctx) {
|
|
427
|
+
const { root, raw, host, normalized } = ctx;
|
|
428
|
+
if (host !== 'codex' || !normalized.session)
|
|
429
|
+
return null;
|
|
430
|
+
if (!takeCompaction(root, normalized.session, normalized.agentId))
|
|
431
|
+
return null;
|
|
432
|
+
const session = contextSession(raw);
|
|
433
|
+
if (session)
|
|
434
|
+
resetContextSession(root, session);
|
|
435
|
+
return runPromptChecks(root, normalized.pluginInput);
|
|
436
|
+
}
|
|
437
|
+
async function writeOutcome(ctx, output, pending) {
|
|
438
|
+
try {
|
|
439
|
+
await writeHookOutput(ctx.io, output);
|
|
295
440
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
441
|
+
catch (error) {
|
|
442
|
+
if (pending && ctx.normalized.session)
|
|
443
|
+
markCompaction(ctx.root, ctx.normalized.session, ctx.normalized.agentId);
|
|
444
|
+
throw error;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async function runBeforeTool(ctx) {
|
|
448
|
+
const decision = await runBeforeToolChecks(ctx.root, ctx.raw, ctx.host);
|
|
449
|
+
for (const diagnostic of decision.diagnostics)
|
|
450
|
+
ctx.io.err(diagnostic);
|
|
451
|
+
const routedChild = process.env[ROUTED_ENV] === '1';
|
|
452
|
+
if (decision.denied) {
|
|
453
|
+
await writeHookOutput(ctx.io, ctx.adapter.formatOutput(ctx.event, { denied: decision.denied }));
|
|
454
|
+
ctx.io.err(decision.denied);
|
|
455
|
+
// 转交子进程靠退出码把拒绝交回发起方,由发起方按宿主回应
|
|
456
|
+
return routedChild ? 2 : ctx.adapter.denyExitCode;
|
|
457
|
+
}
|
|
458
|
+
const pending = ctx.host === 'cursor' || routedChild ? null : await compactContext(ctx);
|
|
459
|
+
const contexts = [...decision.contexts, ...(pending?.contexts ?? [])];
|
|
460
|
+
const output = ctx.adapter.formatOutput(ctx.event, { contexts });
|
|
461
|
+
// Cursor 的 preToolUse 仅拒绝时能给代理消息,上下文留给 postToolUse,这里不算送达。
|
|
462
|
+
const delivered = ctx.host !== 'cursor' && decision.ownContexts.length > 0;
|
|
463
|
+
if (routedChild) {
|
|
464
|
+
const receipt = { kind: 'before', channel: 'before-edit', contexts: decision.ownContexts, deliveries: decision.deliveries };
|
|
465
|
+
await writeHookOutput(ctx.io, delivered ? withReceipt(output, { ...receipt, evidence: decision.evidence }) : output);
|
|
301
466
|
return 0;
|
|
302
467
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
468
|
+
await writeOutcome(ctx, output, pending);
|
|
469
|
+
if (delivered) {
|
|
470
|
+
recordContexts(ctx, 'before-edit', { contexts: decision.ownContexts, evidence: decision.evidence });
|
|
471
|
+
acknowledgeBeforeTool(ctx.root, ctx.raw, decision);
|
|
472
|
+
}
|
|
473
|
+
if (pending?.contexts.length) {
|
|
474
|
+
recordContexts(ctx, 'compact', pending);
|
|
475
|
+
acknowledgePrompt(ctx.root, ctx.raw, pending);
|
|
476
|
+
}
|
|
477
|
+
acknowledgeRouted(decision.receipts);
|
|
478
|
+
return 0;
|
|
479
|
+
}
|
|
480
|
+
async function selectContext(ctx, names, registry) {
|
|
481
|
+
const choices = await Promise.all(names.map((name) => runHookCommand(ctx.root, ctx.normalized.pluginInput, name, registry, 10_000)));
|
|
482
|
+
const selected = choices.flatMap((child) => {
|
|
483
|
+
if (child.code !== 0)
|
|
484
|
+
return [];
|
|
485
|
+
try {
|
|
486
|
+
const value = JSON.parse(child.stdout);
|
|
487
|
+
if (value.contextScope !== undefined && !isContextScope(value.contextScope))
|
|
488
|
+
return [];
|
|
489
|
+
return value.exclusive === true && typeof value.additionalContext === 'string'
|
|
490
|
+
? [{ context: value.additionalContext, scope: isContextScope(value.contextScope) ? value.contextScope : undefined }]
|
|
491
|
+
: [];
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
return [];
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return selected.length === 1 ? selected[0] : undefined;
|
|
498
|
+
}
|
|
499
|
+
function acknowledgeSelectedContext(ctx, choice, channel, merge = false) {
|
|
500
|
+
const session = contextSession(ctx.raw);
|
|
501
|
+
if (session)
|
|
502
|
+
saveContextScope(ctx.root, session, choice.scope, { merge });
|
|
503
|
+
if (choice.context)
|
|
504
|
+
recordContexts(ctx, channel, { contexts: [choice.context] });
|
|
505
|
+
}
|
|
506
|
+
async function runStart(ctx, subagent) {
|
|
507
|
+
const { root, raw, host, normalized } = ctx;
|
|
508
|
+
if (host === 'cursor' && subagent)
|
|
307
509
|
return 0;
|
|
510
|
+
if (subagent) {
|
|
511
|
+
const registry = loadRegistry(root, loadConfig(root));
|
|
512
|
+
const names = [...registry.plugins.values()].flatMap(({ decl }) => decl.hooks?.agent?.subagentContext ?? []);
|
|
513
|
+
const choice = await selectContext(ctx, names, registry);
|
|
514
|
+
if (choice) {
|
|
515
|
+
await writeHookOutput(ctx.io, ctx.adapter.formatOutput(ctx.event, { contexts: choice.context ? [choice.context] : [] }));
|
|
516
|
+
acknowledgeSelectedContext(ctx, choice, 'subagent-start');
|
|
517
|
+
return 0;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const sessionScope = contextSession(raw);
|
|
521
|
+
if (sessionScope)
|
|
522
|
+
saveContextScope(root, sessionScope);
|
|
523
|
+
if (!subagent) {
|
|
524
|
+
const config = loadConfig(root);
|
|
525
|
+
const registry = loadRegistry(root, config);
|
|
526
|
+
const names = declaredHooks(registry, config).sessionStart;
|
|
527
|
+
await Promise.all(names.map((name) => runHookCommand(root, normalized.pluginInput, name, registry)));
|
|
308
528
|
}
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
529
|
+
if (host === 'codex' && !subagent && normalized.session)
|
|
530
|
+
clearCompaction(root, normalized.session, normalized.agentId);
|
|
531
|
+
if (normalized.source === 'resume')
|
|
532
|
+
return 0;
|
|
533
|
+
if (host === 'codex' && subagent && inheritedSubagentHistory(normalized.transcript))
|
|
534
|
+
return 0;
|
|
535
|
+
const session = contextSession(raw);
|
|
536
|
+
if (session && (normalized.source === 'compact' || normalized.source === 'clear'))
|
|
537
|
+
resetContextSession(root, session);
|
|
538
|
+
const decision = await runPromptChecks(root, normalized.pluginInput);
|
|
539
|
+
if (!decision.contexts.length)
|
|
540
|
+
return 0;
|
|
541
|
+
await writeHookOutput(ctx.io, ctx.adapter.formatOutput(ctx.event, decision));
|
|
542
|
+
recordContexts(ctx, subagent ? 'subagent-start' : (normalized.source ?? 'session-start'), decision);
|
|
543
|
+
acknowledgePrompt(root, raw, decision);
|
|
544
|
+
return 0;
|
|
545
|
+
}
|
|
546
|
+
async function runAfterTool(ctx) {
|
|
547
|
+
const read = agentReadOf(ctx.root, ctx.normalized.pluginInput);
|
|
548
|
+
if (ctx.normalized.tool === 'Read') {
|
|
549
|
+
if (read)
|
|
550
|
+
recordTrace(ctx.root, { kind: 'agent-read', source: read.path, channel: ctx.host, content: read.content, ...traceFields(ctx.raw) });
|
|
551
|
+
const pending = ctx.host === 'cursor' ? null : await compactContext(ctx);
|
|
552
|
+
const registry = loadRegistry(ctx.root, loadConfig(ctx.root));
|
|
553
|
+
const agentType = JSON.parse(ctx.normalized.pluginInput).agent_type;
|
|
554
|
+
const names = declaredHooks(registry)
|
|
555
|
+
.afterRead.filter((hook) => hook.agentType === undefined || hook.agentType === agentType)
|
|
556
|
+
.map((hook) => hook.command);
|
|
557
|
+
const choice = await selectContext(ctx, names, registry);
|
|
558
|
+
const contexts = [...(pending?.contexts ?? []), ...(choice?.context ? [choice.context] : [])];
|
|
559
|
+
await writeOutcome(ctx, ctx.adapter.formatOutput(ctx.event, { contexts }), pending);
|
|
560
|
+
if (choice)
|
|
561
|
+
acknowledgeSelectedContext(ctx, choice, 'after-read', true);
|
|
562
|
+
if (pending?.contexts.length) {
|
|
563
|
+
recordContexts(ctx, 'compact', pending);
|
|
564
|
+
acknowledgePrompt(ctx.root, ctx.raw, pending);
|
|
325
565
|
}
|
|
326
566
|
return 0;
|
|
327
567
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
568
|
+
if (ctx.normalized.tool && ctx.normalized.tool !== 'Bash' && !editTool(ctx.normalized.tool)) {
|
|
569
|
+
await writeHookOutput(ctx.io, ctx.adapter.formatOutput(ctx.event, {}));
|
|
570
|
+
return 0;
|
|
571
|
+
}
|
|
572
|
+
if (ctx.normalized.tool && editTool(ctx.normalized.tool))
|
|
573
|
+
recordTrace(ctx.root, { kind: 'agent-edit', ...traceFields(ctx.raw), host: ctx.host });
|
|
574
|
+
const local = await runAfterEditChecks(ctx.root, ctx.normalized.pluginInput);
|
|
575
|
+
const decision = withRoutedAfterEdit(ctx.root, ctx.host, ctx.normalized.pluginInput, local);
|
|
576
|
+
if (decision.code !== 0) {
|
|
577
|
+
const detail = renderAfterEditResponse(ctx.host, decision).stderr;
|
|
578
|
+
await writeHookOutput(ctx.io, ctx.adapter.formatOutput(ctx.event, { denied: decision.code === 2 ? detail : undefined }));
|
|
579
|
+
if (detail)
|
|
580
|
+
ctx.io.err(detail);
|
|
581
|
+
if (decision.code === 2 && detail)
|
|
582
|
+
recordDelivery(ctx.root, ctx.raw, { channel: 'after-edit', method: 'denial', content: detail, host: ctx.host });
|
|
583
|
+
// Cursor 只在退出 0 时读输出,非零退出会让上面写的上下文作废
|
|
584
|
+
return ctx.host === 'cursor' ? 0 : decision.code;
|
|
585
|
+
}
|
|
586
|
+
const routedChild = process.env[ROUTED_ENV] === '1';
|
|
587
|
+
const pending = ctx.host === 'cursor' || routedChild ? null : await compactContext(ctx);
|
|
588
|
+
const contexts = [...decision.contexts, ...(pending?.contexts ?? [])];
|
|
589
|
+
const output = ctx.adapter.formatOutput(ctx.event, { contexts });
|
|
590
|
+
if (routedChild) {
|
|
591
|
+
const receipt = { kind: 'after', channel: 'after-edit', contexts: local.contexts, deliveries: local.deliveries ?? [] };
|
|
592
|
+
await writeHookOutput(ctx.io, local.contexts.length ? withReceipt(output, { ...receipt, evidence: local.evidence }) : output);
|
|
593
|
+
return 0;
|
|
594
|
+
}
|
|
595
|
+
await writeOutcome(ctx, output, pending);
|
|
596
|
+
if (local.contexts.length) {
|
|
597
|
+
recordContexts(ctx, 'after-edit', local);
|
|
598
|
+
acknowledgeAfterEdit(ctx.root, ctx.raw, local);
|
|
599
|
+
}
|
|
600
|
+
if (pending?.contexts.length) {
|
|
601
|
+
recordContexts(ctx, 'compact', pending);
|
|
602
|
+
acknowledgePrompt(ctx.root, ctx.raw, pending);
|
|
603
|
+
}
|
|
604
|
+
acknowledgeRouted(decision.receipts ?? []);
|
|
605
|
+
return 0;
|
|
606
|
+
}
|
|
607
|
+
async function runUserPrompt(ctx) {
|
|
608
|
+
if (!ctx.normalized.valid)
|
|
609
|
+
return 0;
|
|
610
|
+
if (ctx.normalized.prompt)
|
|
611
|
+
recordTrace(ctx.root, { kind: 'prompt', source: ctx.host, content: ctx.normalized.prompt, ...traceFields(ctx.raw), host: ctx.host });
|
|
612
|
+
if (ctx.host === 'cursor')
|
|
613
|
+
return 0;
|
|
614
|
+
const pending = await compactContext(ctx);
|
|
615
|
+
const decision = pending ?? (await runPromptChecks(ctx.root, ctx.normalized.pluginInput));
|
|
616
|
+
if (!decision.contexts.length)
|
|
617
|
+
return 0;
|
|
618
|
+
await writeOutcome(ctx, ctx.adapter.formatOutput(ctx.event, decision), pending);
|
|
619
|
+
recordContexts(ctx, pending ? 'compact' : 'prompt', decision);
|
|
620
|
+
acknowledgePrompt(ctx.root, ctx.raw, decision);
|
|
621
|
+
return 0;
|
|
622
|
+
}
|
|
623
|
+
async function runStop(ctx) {
|
|
624
|
+
const stopState = stopPayload(ctx.raw);
|
|
625
|
+
const stopActive = stopState?.stop_hook_active === true || (typeof stopState?.loop_count === 'number' && stopState.loop_count > 0);
|
|
626
|
+
const checks = stopActive ? { blocked: false, reasons: [] } : await runStopChecks(ctx.root, ctx.normalized.pluginInput);
|
|
627
|
+
const decision = await runAgentStop(ctx.root, ctx.host, ctx.raw, checks);
|
|
628
|
+
const session = ctx.normalized.session;
|
|
629
|
+
const hints = stopHintMessages(ctx.root, session);
|
|
630
|
+
const response = renderStopResponse(ctx.host, { ...decision, warnings: [...hints, ...(decision.warnings ?? [])] });
|
|
631
|
+
await writeHookOutput(ctx.io, response.stdout);
|
|
632
|
+
for (const message of decision.warnings ?? [])
|
|
633
|
+
ctx.io.err(`Sumi Stop 提醒:${message}`);
|
|
634
|
+
if (ctx.host === 'cursor')
|
|
635
|
+
for (const message of hints)
|
|
636
|
+
ctx.io.err(`Sumi Stop 提醒:${message}`);
|
|
637
|
+
return 0;
|
|
638
|
+
}
|
|
639
|
+
async function runModelSwitch(ctx) {
|
|
640
|
+
const config = loadConfig(ctx.root);
|
|
641
|
+
const registry = loadRegistry(ctx.root, config);
|
|
642
|
+
const names = declaredHooks(registry, config).modelSwitch;
|
|
643
|
+
await Promise.all(names.map((name) => runHookCommand(ctx.root, ctx.normalized.pluginInput, name, registry)));
|
|
644
|
+
return 0;
|
|
645
|
+
}
|
|
646
|
+
async function runPostCompact(ctx) {
|
|
647
|
+
if (ctx.host === 'codex' && ctx.normalized.session)
|
|
648
|
+
markCompaction(ctx.root, ctx.normalized.session, ctx.normalized.agentId);
|
|
649
|
+
return 0;
|
|
650
|
+
}
|
|
651
|
+
const EVENT_HANDLERS = {
|
|
652
|
+
'before-tool': runBeforeTool,
|
|
653
|
+
'after-tool': runAfterTool,
|
|
654
|
+
'session-start': (ctx) => runStart(ctx, false),
|
|
655
|
+
'subagent-start': (ctx) => runStart(ctx, true),
|
|
656
|
+
'post-compact': runPostCompact,
|
|
657
|
+
'model-switch': runModelSwitch,
|
|
658
|
+
'user-prompt': runUserPrompt,
|
|
659
|
+
stop: runStop,
|
|
660
|
+
};
|
|
661
|
+
async function runtimeHook(args, io, root) {
|
|
662
|
+
const operation = args.positionals[0];
|
|
663
|
+
const requestedHost = args.positionals[1];
|
|
664
|
+
if (!operation || !EVENT_HANDLERS[operation])
|
|
665
|
+
return 3;
|
|
666
|
+
const projectRoot = requireRoot(root);
|
|
667
|
+
// 身份错误必须在消费负载前交回 CLI,恢复处理才能读取同一次工具请求。
|
|
668
|
+
loadConfig(projectRoot);
|
|
669
|
+
const raw = await readHookInput();
|
|
670
|
+
const host = requestedHost === 'auto' ? (hostEvent(raw)?.host ?? 'claude') : requestedHost;
|
|
671
|
+
if (!HOST_ADAPTERS[host])
|
|
672
|
+
return 3;
|
|
673
|
+
const event = NEW_EVENTS[operation][host];
|
|
674
|
+
const adapter = HOST_ADAPTERS[host];
|
|
675
|
+
return EVENT_HANDLERS[operation]({ root: projectRoot, raw, host, event, adapter, io, normalized: adapter.normalizeInput(event, raw) });
|
|
676
|
+
}
|
|
677
|
+
/** 目标项目收到回执:父进程的输出已写出,这时才记账并标记已送达。回执里的命令必须是本项目注册的。 */
|
|
678
|
+
async function receiveRoutedReceipt(root) {
|
|
679
|
+
const { raw, receipt } = JSON.parse(await readHookInput());
|
|
680
|
+
const config = loadConfig(root);
|
|
681
|
+
const registered = [...loadRegistry(root, config).commands.values()].map((command) => JSON.stringify(resolveArgv(command.argv, command.dir)));
|
|
682
|
+
const deliveries = receipt.deliveries.filter((delivery) => registered.includes(JSON.stringify(delivery.argv)));
|
|
683
|
+
recordDelivery(root, raw, {
|
|
684
|
+
channel: receipt.channel,
|
|
685
|
+
method: 'additional-context',
|
|
686
|
+
content: receipt.contexts.join('\n\n'),
|
|
687
|
+
...receipt.evidence,
|
|
688
|
+
});
|
|
689
|
+
if (receipt.kind === 'before')
|
|
690
|
+
acknowledgeBeforeTool(root, raw, { deliveries });
|
|
691
|
+
else
|
|
692
|
+
acknowledgeAfterEdit(root, raw, { deliveries });
|
|
693
|
+
return 0;
|
|
694
|
+
}
|
|
695
|
+
registerCommand('context-before-edit', '旧接线的前置 hook 别名', (_args, io, root) => runtimeHook({ positionals: ['before-tool', 'auto'] }, io, root));
|
|
696
|
+
registerCommand('hook', `运行工具适配 hook:${HOOK_USAGE}`, async (args, io, root) => {
|
|
697
|
+
const operation = args.positionals[0];
|
|
698
|
+
// 内部操作:父进程转交写入后回执给目标项目,不写进用法
|
|
699
|
+
if (operation === 'routed-receipt')
|
|
700
|
+
return receiveRoutedReceipt(requireRoot(root));
|
|
701
|
+
if (!HOOK_OPERATIONS.includes(operation ?? '') || !['claude', 'codex', 'cursor'].includes(args.positionals[1] ?? '')) {
|
|
702
|
+
io.err(`用法:${HOOK_USAGE}`);
|
|
703
|
+
return 3;
|
|
704
|
+
}
|
|
705
|
+
const agent = args.positionals[1];
|
|
706
|
+
if (NEW_EVENTS[operation])
|
|
707
|
+
return runtimeHook(args, io, root);
|
|
708
|
+
const alias = {
|
|
709
|
+
'agent-stop': 'stop',
|
|
710
|
+
'agent-after-edit': 'after-tool',
|
|
711
|
+
'agent-after-read': 'after-tool',
|
|
712
|
+
'agent-user-prompt': 'user-prompt',
|
|
713
|
+
'agent-session-start': 'session-start',
|
|
714
|
+
'agent-subagent-start': 'subagent-start',
|
|
715
|
+
'context-before-edit': 'before-tool',
|
|
716
|
+
};
|
|
717
|
+
return runtimeHook({ positionals: [alias[operation], agent] }, io, root);
|
|
349
718
|
});
|
|
350
|
-
/** 写入目标属于其他已接入项目时,并入那些项目编辑后 hook
|
|
719
|
+
/** 写入目标属于其他已接入项目时,并入那些项目编辑后 hook 的补充上下文与阻断;它们的账本与回执在输出写出后再做。 */
|
|
351
720
|
function withRoutedAfterEdit(root, agent, input, local) {
|
|
352
|
-
const routed = routeToOwners(root, ['hook', '
|
|
721
|
+
const routed = routeToOwners(root, ['hook', 'after-tool', agent], input);
|
|
353
722
|
const contexts = [...local.contexts];
|
|
354
723
|
for (const out of routed.stdout) {
|
|
355
724
|
try {
|
|
356
725
|
const value = JSON.parse(out);
|
|
357
|
-
|
|
358
|
-
|
|
726
|
+
const context = firstHostString([value.hookSpecificOutput?.additionalContext, value.additional_context]);
|
|
727
|
+
if (context)
|
|
728
|
+
contexts.push(context);
|
|
359
729
|
}
|
|
360
730
|
catch {
|
|
361
731
|
/* 没有补充上下文 */
|
|
362
732
|
}
|
|
363
733
|
}
|
|
364
734
|
const stderr = [local.stderr, ...routed.stderr].filter(Boolean).join('\n');
|
|
365
|
-
return { ...local, code: routed.denied ? 2 : local.code, contexts, stderr };
|
|
366
|
-
}
|
|
367
|
-
function toolName(input) {
|
|
368
|
-
try {
|
|
369
|
-
const value = JSON.parse(input);
|
|
370
|
-
return typeof value.tool_name === 'string' ? value.tool_name : undefined;
|
|
371
|
-
}
|
|
372
|
-
catch {
|
|
373
|
-
return undefined;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function promptOf(input) {
|
|
377
|
-
try {
|
|
378
|
-
const value = JSON.parse(input);
|
|
379
|
-
return typeof value.prompt === 'string' && value.prompt.length ? value.prompt : undefined;
|
|
380
|
-
}
|
|
381
|
-
catch {
|
|
382
|
-
return undefined;
|
|
383
|
-
}
|
|
735
|
+
return { ...local, code: routed.denied ? 2 : local.code, contexts, stderr, receipts: routed.receipts };
|
|
384
736
|
}
|
|
385
737
|
function agentReadOf(root, input) {
|
|
386
738
|
try {
|
|
@@ -390,7 +742,7 @@ function agentReadOf(root, input) {
|
|
|
390
742
|
const path = relative(root, resolve(value.tool_input.file_path));
|
|
391
743
|
if (!path || path === '..' || path.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`) || isAbsolute(path))
|
|
392
744
|
return undefined;
|
|
393
|
-
const response = value.tool_response;
|
|
745
|
+
const response = value.tool_response ?? value.tool_output;
|
|
394
746
|
const content = typeof response === 'string'
|
|
395
747
|
? response
|
|
396
748
|
: response && typeof response === 'object' && 'content' in response && typeof response.content === 'string'
|