@fantasticit/sumi 0.14.5 → 0.14.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters.d.ts +9 -0
- package/dist/adapters.js +88 -12
- package/dist/adapters.js.map +1 -1
- package/dist/agent-hooks.js +15 -2
- package/dist/agent-hooks.js.map +1 -1
- package/dist/agents.js +19 -11
- package/dist/agents.js.map +1 -1
- package/dist/cli.js +20 -3
- package/dist/cli.js.map +1 -1
- package/dist/codex-trust.d.ts +8 -0
- package/dist/codex-trust.js +27 -0
- package/dist/codex-trust.js.map +1 -0
- package/dist/codex-user-hook-entry.d.ts +1 -0
- package/dist/codex-user-hook-entry.js +134 -0
- package/dist/codex-user-hook-entry.js.map +1 -0
- package/dist/codex-user-hook.cjs +137 -0
- package/dist/codex-user-hook.d.ts +2 -0
- package/dist/codex-user-hook.js +85 -0
- package/dist/codex-user-hook.js.map +1 -0
- package/dist/context.d.ts +3 -1
- package/dist/context.js +20 -20
- package/dist/context.js.map +1 -1
- package/dist/declared-hooks.d.ts +3 -1
- package/dist/declared-hooks.js +11 -0
- package/dist/declared-hooks.js.map +1 -1
- package/dist/doctor-wiring.d.ts +1 -6
- package/dist/doctor-wiring.js +4 -25
- package/dist/doctor-wiring.js.map +1 -1
- package/dist/hub/board.d.ts +123 -0
- package/dist/hub/board.js +303 -0
- package/dist/hub/board.js.map +1 -0
- package/dist/hub/commands.d.ts +13 -0
- package/dist/hub/commands.js +86 -0
- package/dist/hub/commands.js.map +1 -0
- package/dist/hub/pages.d.ts +2 -0
- package/dist/hub/pages.js +182 -0
- package/dist/hub/pages.js.map +1 -0
- package/dist/hub/server.d.ts +23 -0
- package/dist/hub/server.js +128 -0
- package/dist/hub/server.js.map +1 -0
- package/dist/hub/snapshot.d.ts +56 -0
- package/dist/hub/snapshot.js +161 -0
- package/dist/hub/snapshot.js.map +1 -0
- package/dist/hub/start.d.ts +13 -0
- package/dist/hub/start.js +59 -0
- package/dist/hub/start.js.map +1 -0
- package/dist/hub/state.d.ts +49 -0
- package/dist/hub/state.js +144 -0
- package/dist/hub/state.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +2 -2
- package/dist/mcp-hosts.d.ts +25 -0
- package/dist/mcp-hosts.js +64 -0
- package/dist/mcp-hosts.js.map +1 -0
- package/dist/run-stats.d.ts +20 -0
- package/dist/run-stats.js +58 -6
- package/dist/run-stats.js.map +1 -1
- package/dist/task.js +16 -5
- package/dist/task.js.map +1 -1
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/create/template/control/flows/check.flow.yaml +4 -0
- package/node_modules/@sumi/create/template/control/rubrics/behavior.yaml +16 -0
- package/node_modules/@sumi/create/template/control/rules/core-modules.json +5 -0
- package/node_modules/@sumi/create/template/control/rules/development.md +13 -9
- package/node_modules/@sumi/create/template/control/rules/testing.md +56 -0
- package/node_modules/@sumi/create/template/init/control/flows/check.flow.yaml +1 -0
- package/node_modules/@sumi/create/template/init/control/rubrics/behavior.yaml +16 -0
- package/node_modules/@sumi/kernel/dist/brief.d.ts +2 -0
- package/node_modules/@sumi/kernel/dist/brief.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/engine.js +1 -0
- package/node_modules/@sumi/kernel/dist/engine.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/runner.js +3 -3
- package/node_modules/@sumi/kernel/dist/runner.js.map +1 -1
- package/node_modules/@sumi/kernel/package.json +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.d.ts +11 -6
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js +35 -3
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js +29 -23
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/env.d.ts +8 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js +13 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/git.d.ts +8 -0
- package/node_modules/@sumi/plugin-sdk/dist/git.js +48 -0
- package/node_modules/@sumi/plugin-sdk/dist/git.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/hub.d.ts +33 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js +32 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.d.ts +22 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.js +118 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js +12 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/project.d.ts +5 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js +5 -0
- package/node_modules/@sumi/plugin-sdk/dist/project.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/protocol.d.ts +10 -0
- package/node_modules/@sumi/plugin-sdk/dist/protocol.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-context.d.ts +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js +10 -7
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-env.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/session-env.js +3 -0
- package/node_modules/@sumi/plugin-sdk/dist/session-env.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/shell.d.ts +11 -5
- package/node_modules/@sumi/plugin-sdk/dist/shell.js +132 -23
- package/node_modules/@sumi/plugin-sdk/dist/shell.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/trace.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/trace.js +39 -5
- package/node_modules/@sumi/plugin-sdk/dist/trace.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/validate.js +15 -0
- package/node_modules/@sumi/plugin-sdk/dist/validate.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/package.json +1 -1
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js +20 -5
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/change-impact.js +1 -13
- package/node_modules/@sumi/plugins-core/dist/change-impact.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.js +10 -0
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/context-provider.js +17 -1
- package/node_modules/@sumi/plugins-core/dist/context-provider.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/core-modules.d.ts +5 -0
- package/node_modules/@sumi/plugins-core/dist/core-modules.js +28 -0
- package/node_modules/@sumi/plugins-core/dist/core-modules.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/layer-boundary.js +2 -2
- package/node_modules/@sumi/plugins-core/dist/plugins/layer-boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js +26 -7
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/plugins/test-scope.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/test-scope.js +41 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/test-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/test-scope.d.ts +3 -1
- package/node_modules/@sumi/plugins-core/dist/test-scope.js +14 -3
- package/node_modules/@sumi/plugins-core/dist/test-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/testing-rules-upgrade.d.ts +10 -0
- package/node_modules/@sumi/plugins-core/dist/testing-rules-upgrade.js +29 -0
- package/node_modules/@sumi/plugins-core/dist/testing-rules-upgrade.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/upgrade-command.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/upgrade-command.js +13 -0
- package/node_modules/@sumi/plugins-core/dist/upgrade-command.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js +16 -0
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js.map +1 -1
- package/node_modules/@sumi/plugins-core/instructions/bugfix.md +4 -4
- package/node_modules/@sumi/plugins-core/instructions/feature.md +2 -2
- package/node_modules/@sumi/plugins-core/package.json +3 -2
- package/node_modules/@sumi/plugins-core/sumi-plugins.yaml +13 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.js +76 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.d.ts +6 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.js +128 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js +231 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.d.ts +10 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.js +183 -33
- package/node_modules/@sumi/plugins-governance/dist/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.d.ts +9 -0
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js +64 -0
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.js +13 -3
- package/node_modules/@sumi/plugins-governance/dist/checkout.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js +59 -9
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js +16 -11
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.js +4 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js +3 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.d.ts +2 -1
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js +11 -2
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/guard.js +147 -19
- package/node_modules/@sumi/plugins-governance/dist/guard.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js +44 -0
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/index.d.ts +3 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js +3 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js +21 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js +4 -2
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js +2 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js +34 -4
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/preflight.js +2 -2
- package/node_modules/@sumi/plugins-governance/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/protected.js +2 -1
- package/node_modules/@sumi/plugins-governance/dist/protected.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/instructions/boundary.md +17 -2
- package/node_modules/@sumi/plugins-governance/package.json +4 -4
- package/node_modules/@sumi/plugins-governance/sumi-plugins.yaml +8 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.d.ts +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.js +4 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.d.ts +4 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.js +34 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.d.ts +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.js +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-openspec/dist/plugins/impact-consistency.js +2 -0
- package/node_modules/@sumi/plugins-openspec/dist/plugins/impact-consistency.js.map +1 -1
- package/node_modules/@sumi/plugins-openspec/package.json +6 -6
- package/node_modules/@sumi/plugins-openspec/sumi-plugins.yaml +4 -0
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js +10 -11
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/candidates.d.ts +9 -3
- package/node_modules/@sumi/plugins-precedent/dist/candidates.js +12 -6
- package/node_modules/@sumi/plugins-precedent/dist/candidates.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/promote.js +20 -5
- package/node_modules/@sumi/plugins-precedent/dist/commands/promote.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-output.d.ts +15 -8
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js +93 -34
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js +7 -3
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.d.ts +2 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js +5 -4
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact.d.ts +7 -6
- package/node_modules/@sumi/plugins-precedent/dist/impact.js +33 -29
- package/node_modules/@sumi/plugins-precedent/dist/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/matching.d.ts +12 -0
- package/node_modules/@sumi/plugins-precedent/dist/matching.js +90 -0
- package/node_modules/@sumi/plugins-precedent/dist/matching.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/plugins/harvest.js +44 -13
- package/node_modules/@sumi/plugins-precedent/dist/plugins/harvest.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/impact.js +15 -10
- package/node_modules/@sumi/plugins-precedent/dist/plugins/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/planner.js +47 -6
- package/node_modules/@sumi/plugins-precedent/dist/plugins/planner.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.d.ts +3 -0
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.js +40 -0
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-review/dist/command-input.d.ts +1 -1
- package/node_modules/@sumi/plugins-review/dist/command-input.js +4 -4
- package/node_modules/@sumi/plugins-review/dist/command-input.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js +3 -3
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js +6 -0
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/convergence.d.ts +7 -2
- package/node_modules/@sumi/plugins-review/dist/convergence.js +43 -5
- package/node_modules/@sumi/plugins-review/dist/convergence.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/dispatch.js +2 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/precedent-context.d.ts +7 -0
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js +28 -0
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.js +15 -5
- package/node_modules/@sumi/plugins-review/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/report.d.ts +9 -0
- package/node_modules/@sumi/plugins-review/dist/report.js +28 -7
- package/node_modules/@sumi/plugins-review/dist/report.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.d.ts +9 -0
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.js +50 -0
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/review-scope.d.ts +1 -3
- package/node_modules/@sumi/plugins-review/dist/review-scope.js +1 -24
- package/node_modules/@sumi/plugins-review/dist/review-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review-slices.js +1 -0
- package/node_modules/@sumi/plugins-review/dist/review-slices.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review.d.ts +47 -8
- package/node_modules/@sumi/plugins-review/dist/review.js +215 -34
- package/node_modules/@sumi/plugins-review/dist/review.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js +71 -32
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/stats.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/stats.js +11 -15
- package/node_modules/@sumi/plugins-review/dist/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submission.js +24 -8
- package/node_modules/@sumi/plugins-review/dist/submission.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submit-files.d.ts +3 -0
- package/node_modules/@sumi/plugins-review/dist/submit-files.js +55 -0
- package/node_modules/@sumi/plugins-review/dist/submit-files.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/validation-receipt.js +4 -2
- package/node_modules/@sumi/plugins-review/dist/validation-receipt.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -6
- package/package.json +10 -10
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { waitForBoundaryAnswer } from './boundary-browser.js';
|
|
3
|
+
import { desktopAvailable } from './view-page.js';
|
|
4
|
+
import { boundaryAnswer, boundaryReceipt, cancelBoundaryAnswer, submitBoundaryAnswer } from './boundary.js';
|
|
5
|
+
import { boundaryAnswerPage, boundaryForm } from './boundary-answer-page.js';
|
|
6
|
+
const URI = 'ui://sumi/boundary-answer.html';
|
|
7
|
+
const MIME = 'text/html;profile=mcp-app';
|
|
8
|
+
const properties = { session: { type: 'string' }, id: { type: 'string' } };
|
|
9
|
+
const inputSchema = { type: 'object', properties, required: ['session', 'id'], additionalProperties: false };
|
|
10
|
+
const tools = [
|
|
11
|
+
{
|
|
12
|
+
name: 'show_boundary',
|
|
13
|
+
description: '在当前桌面会话展示 Sumi 边界表单。传入 boundary propose --no-open 返回的会话和提案 ID,展示后等待用户在表单里确认;宿主不能内嵌表单时改为打开浏览器页面并等待回传。',
|
|
14
|
+
inputSchema,
|
|
15
|
+
annotations: { readOnlyHint: true },
|
|
16
|
+
_meta: { ui: { resourceUri: URI } },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'read_boundary_answer',
|
|
20
|
+
description: '按会话和提案 ID 读取 Sumi 已保存的确认结果。收到表单提交回执后调用此工具,再按答案继续。',
|
|
21
|
+
inputSchema,
|
|
22
|
+
annotations: { readOnlyHint: true },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'submit_boundary_answer',
|
|
26
|
+
description: '表单按钮提交或取消当前边界提案。',
|
|
27
|
+
inputSchema: {
|
|
28
|
+
...inputSchema,
|
|
29
|
+
properties: { ...properties, action: { enum: ['confirm', 'defaults', 'cancel'] }, answers: { type: 'object' } },
|
|
30
|
+
required: [...inputSchema.required, 'action', 'answers'],
|
|
31
|
+
},
|
|
32
|
+
_meta: { ui: { visibility: ['app'] } },
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
const mcpTransport = String.raw `
|
|
36
|
+
let proposal;
|
|
37
|
+
let cursor = 0;
|
|
38
|
+
let ready = false;
|
|
39
|
+
const pending = new Map();
|
|
40
|
+
const rpc = (method, params, id) => parent.postMessage({
|
|
41
|
+
jsonrpc: '2.0', method, params, ...(id === undefined ? {} : { id })
|
|
42
|
+
}, '*');
|
|
43
|
+
function call(method, params) {
|
|
44
|
+
const id = ++cursor;
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const timeout = setTimeout(() => {
|
|
47
|
+
pending.delete(id);
|
|
48
|
+
reject(new Error('宿主响应超时。'));
|
|
49
|
+
}, 15000);
|
|
50
|
+
pending.set(id, (message) => {
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
if (message.error) reject(new Error(message.error.message));
|
|
53
|
+
else resolve(message.result);
|
|
54
|
+
});
|
|
55
|
+
rpc(method, params, id);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
addEventListener('message', ({ source, data }) => {
|
|
59
|
+
if (source !== parent || data?.jsonrpc !== '2.0') return;
|
|
60
|
+
if (data.method === 'ui/notifications/tool-result') {
|
|
61
|
+
const result = data.params?.structuredContent;
|
|
62
|
+
if (!result || typeof result.html !== 'string') return;
|
|
63
|
+
proposal = {session: result.session, id: result.id};
|
|
64
|
+
document.querySelector('#questions').innerHTML = result.html;
|
|
65
|
+
status.textContent = '';
|
|
66
|
+
fields.disabled = false;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const callback = pending.get(data.id);
|
|
70
|
+
if (callback) {
|
|
71
|
+
pending.delete(data.id);
|
|
72
|
+
callback(data);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
async function submit(action, answers) {
|
|
76
|
+
const result = await call('tools/call', {
|
|
77
|
+
name: 'submit_boundary_answer', arguments: {...proposal, action, answers}
|
|
78
|
+
});
|
|
79
|
+
if (result?.isError || !result?.structuredContent) throw new Error(result?.content?.[0]?.text || '提交失败。');
|
|
80
|
+
return result.structuredContent;
|
|
81
|
+
}
|
|
82
|
+
async function notifyHost(receipt) {
|
|
83
|
+
const text = receipt.status === 'confirmed'
|
|
84
|
+
? '我已提交 Sumi 边界确认。请读取刚才表单对应的已保存答案,并按答案继续当前任务。提案 ID ' + proposal.id
|
|
85
|
+
: '我已取消 Sumi 边界表单。请回到会话内确认边界。';
|
|
86
|
+
const response = await call('ui/message', {role: 'user', content: [{type: 'text', text}]});
|
|
87
|
+
if (response?.isError) throw new Error('宿主拒绝自动回传');
|
|
88
|
+
}
|
|
89
|
+
// 提交后收起为一行回执;高度变化由下面的观察器通知宿主
|
|
90
|
+
function done(state, note) {
|
|
91
|
+
const time = new Date().toLocaleTimeString('zh-CN', {hour12: false, hour: '2-digit', minute: '2-digit'});
|
|
92
|
+
const line = document.createElement('p');
|
|
93
|
+
line.id = 'status';
|
|
94
|
+
line.setAttribute('role', 'status');
|
|
95
|
+
line.textContent = (state === 'confirmed' ? '已确认' : '已取消') + '(' + time + ')' + note;
|
|
96
|
+
document.querySelector('main').replaceChildren(line);
|
|
97
|
+
}
|
|
98
|
+
new ResizeObserver(() => {
|
|
99
|
+
if (ready) rpc('ui/notifications/size-changed', {height: Math.ceil(document.body.getBoundingClientRect().height)});
|
|
100
|
+
}).observe(document.body);
|
|
101
|
+
call('ui/initialize', {appInfo: {name: 'sumi-boundary', version: '1.0.0'}, appCapabilities: {}, protocolVersion: '2026-01-26'})
|
|
102
|
+
.then(() => {
|
|
103
|
+
ready = true;
|
|
104
|
+
rpc('ui/notifications/initialized', {});
|
|
105
|
+
rpc('ui/notifications/size-changed', {height: Math.ceil(document.body.getBoundingClientRect().height)});
|
|
106
|
+
})
|
|
107
|
+
.catch(error => {status.textContent = error.message;});
|
|
108
|
+
`;
|
|
109
|
+
function toolResult(text, structuredContent) {
|
|
110
|
+
return { content: [{ type: 'text', text }], ...(structuredContent ? { structuredContent } : {}) };
|
|
111
|
+
}
|
|
112
|
+
/** 等待浏览器答复页回传的最长时间,与 `boundary propose --wait` 一致。 */
|
|
113
|
+
const BROWSER_WAIT_MS = 5 * 60_000;
|
|
114
|
+
/** 客户端按 MCP Apps 规范在 initialize 的 capabilities.extensions 中声明能渲染 `text/html;profile=mcp-app`。 */
|
|
115
|
+
function supportsMcpApps(params) {
|
|
116
|
+
const capabilities = params.capabilities;
|
|
117
|
+
const mimeTypes = capabilities?.extensions?.['io.modelcontextprotocol/ui']?.mimeTypes;
|
|
118
|
+
return Array.isArray(mimeTypes) && mimeTypes.includes(MIME);
|
|
119
|
+
}
|
|
120
|
+
/** 宿主不能内嵌表单:打开浏览器答复页并在工具调用内等待回传。 */
|
|
121
|
+
async function showInBrowser(root, session, id, signal) {
|
|
122
|
+
const fallback = '请在会话内用问答确认边界,或重新发起提案。';
|
|
123
|
+
if (!desktopAvailable())
|
|
124
|
+
return toolResult(`当前环境无法打开答复页。${fallback}已确认后调用 read_boundary_answer 读取答案。`);
|
|
125
|
+
const timer = AbortSignal.timeout(BROWSER_WAIT_MS);
|
|
126
|
+
let url = '';
|
|
127
|
+
try {
|
|
128
|
+
const record = await waitForBoundaryAnswer(root, session, id, {
|
|
129
|
+
signal: AbortSignal.any([signal, timer]),
|
|
130
|
+
output: (address) => (url = address),
|
|
131
|
+
});
|
|
132
|
+
if (record)
|
|
133
|
+
return toolResult(boundaryReceipt(record), { status: record.status, id });
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return toolResult(`无法使用浏览器答复页:${error.message}。${fallback}`);
|
|
137
|
+
}
|
|
138
|
+
return toolResult(`浏览器答复页已取消或超时(${url}),提案已取消。${fallback}`);
|
|
139
|
+
}
|
|
140
|
+
async function callTool(root, name, args, apps, signal) {
|
|
141
|
+
const { session, id } = args;
|
|
142
|
+
if (typeof session !== 'string' || !session || session.length > 407 || typeof id !== 'string' || !id) {
|
|
143
|
+
throw new Error('需要当前会话和边界提案 ID');
|
|
144
|
+
}
|
|
145
|
+
if (name === 'submit_boundary_answer') {
|
|
146
|
+
if (args.action === 'cancel') {
|
|
147
|
+
cancelBoundaryAnswer(root, session, id);
|
|
148
|
+
return toolResult('已取消', { status: 'cancelled' });
|
|
149
|
+
}
|
|
150
|
+
if (args.action !== 'confirm' && args.action !== 'defaults')
|
|
151
|
+
throw new Error('未知操作');
|
|
152
|
+
const receipt = submitBoundaryAnswer(root, session, id, args.action === 'defaults' ? {} : args.answers);
|
|
153
|
+
return toolResult(boundaryReceipt(receipt), { status: receipt.status, id });
|
|
154
|
+
}
|
|
155
|
+
const record = boundaryAnswer(root, session, id);
|
|
156
|
+
if (name === 'read_boundary_answer') {
|
|
157
|
+
if (record.status !== 'confirmed')
|
|
158
|
+
return toolResult('当前提案尚未确认');
|
|
159
|
+
return toolResult(boundaryReceipt(record), { status: record.status, id });
|
|
160
|
+
}
|
|
161
|
+
if (name !== 'show_boundary')
|
|
162
|
+
throw new Error('未知工具');
|
|
163
|
+
if (record.status !== 'proposed')
|
|
164
|
+
throw new Error('边界提案已经结束');
|
|
165
|
+
if (!apps)
|
|
166
|
+
return showInBrowser(root, session, id, signal);
|
|
167
|
+
return toolResult('边界表单已交给宿主展示。若宿主没有显示表单,请用会话内问答确认。收到提交回执后调用 read_boundary_answer。', {
|
|
168
|
+
html: boundaryForm(record),
|
|
169
|
+
session,
|
|
170
|
+
id,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export async function serveBoundaryMcp(root) {
|
|
174
|
+
let apps = false;
|
|
175
|
+
const shutdown = new AbortController();
|
|
176
|
+
async function route(method, params) {
|
|
177
|
+
switch (method) {
|
|
178
|
+
case 'initialize':
|
|
179
|
+
apps = supportsMcpApps(params);
|
|
180
|
+
return {
|
|
181
|
+
protocolVersion: params.protocolVersion === '2025-06-18' ? '2025-06-18' : '2025-11-25',
|
|
182
|
+
capabilities: { tools: {}, resources: {}, extensions: { 'io.modelcontextprotocol/ui': { mimeTypes: [MIME] } } },
|
|
183
|
+
serverInfo: { name: 'sumi-boundary', version: '1.0.0' },
|
|
184
|
+
};
|
|
185
|
+
case 'ping':
|
|
186
|
+
return {};
|
|
187
|
+
case 'tools/list':
|
|
188
|
+
return { tools };
|
|
189
|
+
case 'resources/list':
|
|
190
|
+
return { resources: [{ uri: URI, name: 'Sumi 边界确认', mimeType: MIME }] };
|
|
191
|
+
case 'resources/templates/list':
|
|
192
|
+
return { resourceTemplates: [] };
|
|
193
|
+
case 'resources/read':
|
|
194
|
+
if (params.uri !== URI)
|
|
195
|
+
throw new Error('未知资源');
|
|
196
|
+
return { contents: [{ uri: URI, mimeType: MIME, text: boundaryAnswerPage('', mcpTransport) }] };
|
|
197
|
+
case 'tools/call':
|
|
198
|
+
try {
|
|
199
|
+
return await callTool(root, params.name, (params.arguments ?? {}), apps, shutdown.signal);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return { ...toolResult(error instanceof Error ? error.message : '工具调用失败'), isError: true };
|
|
203
|
+
}
|
|
204
|
+
default:
|
|
205
|
+
throw new Error('未知 MCP 方法');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// 浏览器等待期间仍要响应其他请求,逐条并发处理;输入关闭后中止等待并等已发出的请求收尾
|
|
209
|
+
const inflight = new Set();
|
|
210
|
+
async function handle(line) {
|
|
211
|
+
let id = null;
|
|
212
|
+
try {
|
|
213
|
+
const message = JSON.parse(line);
|
|
214
|
+
if (message.id === undefined)
|
|
215
|
+
return;
|
|
216
|
+
id = message.id;
|
|
217
|
+
const result = await route(message.method, message.params ?? {});
|
|
218
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, result })}\n`);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, error: { code: -32603, message: error.message } })}\n`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for await (const line of createInterface({ input: process.stdin, crlfDelay: Infinity })) {
|
|
225
|
+
const task = handle(line).finally(() => inflight.delete(task));
|
|
226
|
+
inflight.add(task);
|
|
227
|
+
}
|
|
228
|
+
shutdown.abort();
|
|
229
|
+
await Promise.all(inflight);
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=boundary-mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bound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,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAClI,CAAC;IACH,CAAC;IACD,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/D,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -12,6 +12,9 @@ export interface BoundaryRecord {
|
|
|
12
12
|
change?: string;
|
|
13
13
|
reason?: string;
|
|
14
14
|
at: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
project?: string;
|
|
17
|
+
submitted?: string;
|
|
15
18
|
}
|
|
16
19
|
/** 与评审的既有关联规则共用:显式 change、唯一进行中 change、改动路径。 */
|
|
17
20
|
export declare function scopeChanges(root: string, files: string[], change?: string): string[];
|
|
@@ -21,6 +24,8 @@ export declare function boundarySources(root: string, changes: string[]): {
|
|
|
21
24
|
text: string;
|
|
22
25
|
}[];
|
|
23
26
|
export declare function parseBoundary(markdown: string): BoundaryRow[];
|
|
27
|
+
/** 只读该会话自己的边界记录,不回退到 change 的记录。 */
|
|
28
|
+
export declare function readRecord(root: string, session: string): BoundaryRecord | null;
|
|
24
29
|
export declare function boundaryRecord(root: string, session?: string | undefined, changes?: string[]): BoundaryRecord | null;
|
|
25
30
|
export declare function boundaryStatus(root: string, session?: string, changes?: string[]): string;
|
|
26
31
|
export declare function proposeBoundary(root: string, session: string, markdown: string, options?: {
|
|
@@ -28,6 +33,7 @@ export declare function proposeBoundary(root: string, session: string, markdown:
|
|
|
28
33
|
noOpen?: boolean;
|
|
29
34
|
open?: (path: string) => void;
|
|
30
35
|
}): {
|
|
36
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
31
37
|
path: string;
|
|
32
38
|
guidance: string;
|
|
33
39
|
};
|
|
@@ -37,6 +43,10 @@ export declare function confirmBoundary(root: string, session: string, options:
|
|
|
37
43
|
unconfirmed?: boolean;
|
|
38
44
|
change?: string;
|
|
39
45
|
}): BoundaryRecord;
|
|
46
|
+
export declare function boundaryReceipt(record: BoundaryRecord): string;
|
|
47
|
+
export declare function boundaryAnswer(root: string, session: string, id: string): BoundaryRecord;
|
|
48
|
+
export declare function submitBoundaryAnswer(root: string, session: string, id: string, answers: unknown): BoundaryRecord;
|
|
49
|
+
export declare function cancelBoundaryAnswer(root: string, session: string, id: string): void;
|
|
40
50
|
export declare function skipBoundary(root: string, session: string, reason: string, change?: string): void;
|
|
41
51
|
export declare function boundaryDecision(root: string, session: string | undefined, paths: string[]): string | null;
|
|
42
52
|
export declare function boundaryContext(root: string, paths: string[], session?: string | undefined, change?: string): ContextItem[];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync } from 'node:fs';
|
|
2
3
|
import { dirname, join } from 'node:path';
|
|
3
|
-
import { configFile, envSession, readContextSession, saveContextMetadata } from '@sumi/plugin-sdk';
|
|
4
|
+
import { configFile, envSession, readContextSession, saveContextMetadata, withFileLock, writeFileAtomic, } from '@sumi/plugin-sdk';
|
|
4
5
|
import { parse } from 'yaml';
|
|
5
6
|
import picomatch from 'picomatch';
|
|
6
7
|
import { boundaryPage, openPage, desktopAvailable } from './view-page.js';
|
|
8
|
+
import { stateDir } from './state.js';
|
|
7
9
|
export const BOUNDARY_HEADINGS = ['支持', '不处理', '可接受的异常', '兼容范围', '人工兜底'];
|
|
8
10
|
const KEY = 'gov/boundary';
|
|
9
11
|
const changeSession = (change) => `boundary:change:${change}`;
|
|
@@ -40,6 +42,7 @@ export function boundarySources(root, changes) {
|
|
|
40
42
|
}
|
|
41
43
|
return sources;
|
|
42
44
|
}
|
|
45
|
+
const DEFAULT_ANSWER = /(建议默认[::]\s*)([^;;\n]+)/;
|
|
43
46
|
export function parseBoundary(markdown) {
|
|
44
47
|
const rows = [];
|
|
45
48
|
for (const section of BOUNDARY_HEADINGS) {
|
|
@@ -50,7 +53,7 @@ export function parseBoundary(markdown) {
|
|
|
50
53
|
if (!entries.length)
|
|
51
54
|
throw new Error(`${section} 至少需要一个列表条目`);
|
|
52
55
|
for (const entry of entries) {
|
|
53
|
-
const suggested =
|
|
56
|
+
const suggested = DEFAULT_ANSWER.exec(entry)?.[2]?.trim();
|
|
54
57
|
const decision = /需拍板[::]\s*(是|否)/.exec(entry)?.[1];
|
|
55
58
|
if (!suggested || !decision)
|
|
56
59
|
throw new Error(`${section} 每条必须包含“建议默认:…”与“需拍板:是/否”`);
|
|
@@ -67,15 +70,21 @@ export function parseBoundary(markdown) {
|
|
|
67
70
|
}
|
|
68
71
|
return rows;
|
|
69
72
|
}
|
|
70
|
-
|
|
73
|
+
/** 只读该会话自己的边界记录,不回退到 change 的记录。 */
|
|
74
|
+
export function readRecord(root, session) {
|
|
71
75
|
const value = readContextSession(root, session)?.metadata?.[KEY];
|
|
72
76
|
if (!value || typeof value !== 'object')
|
|
73
77
|
return null;
|
|
74
78
|
const record = value;
|
|
75
79
|
return ['proposed', 'confirmed', 'unconfirmed', 'skipped'].includes(record.status) && typeof record.markdown === 'string' ? record : null;
|
|
76
80
|
}
|
|
81
|
+
/** 会话记录存在所有 worktree 共用的状态目录;属于另一个工作区的记录不参与当前工作区的读取与确认。 */
|
|
82
|
+
function ownRecord(root, session) {
|
|
83
|
+
const record = readRecord(root, session);
|
|
84
|
+
return record && (!record.project || record.project === realpathSync(root)) ? record : null;
|
|
85
|
+
}
|
|
77
86
|
export function boundaryRecord(root, session = envSession(), changes) {
|
|
78
|
-
const local = session ?
|
|
87
|
+
const local = session ? ownRecord(root, session) : null;
|
|
79
88
|
// 显式目标不能被环境会话中另一 change 的记录覆盖。
|
|
80
89
|
if (changes?.length) {
|
|
81
90
|
return (changes.map((change) => readRecord(root, changeSession(change))).find((record) => record !== null) ??
|
|
@@ -87,11 +96,19 @@ export function boundaryRecord(root, session = envSession(), changes) {
|
|
|
87
96
|
const targets = scopeChanges(root, [], typeof associated === 'string' ? associated : undefined);
|
|
88
97
|
return targets.map((change) => readRecord(root, changeSession(change))).find((record) => record !== null) ?? null;
|
|
89
98
|
}
|
|
99
|
+
function boundaryWrite(root, write) {
|
|
100
|
+
return withFileLock(join(stateDir(root), 'boundary-write.lock'), write, { required: true });
|
|
101
|
+
}
|
|
90
102
|
function save(root, session, record) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
103
|
+
const target = record.change ? changeSession(record.change) : undefined;
|
|
104
|
+
const previous = target ? readRecord(root, target) : null;
|
|
105
|
+
if (target && !saveContextMetadata(root, target, KEY, record))
|
|
94
106
|
throw new Error('无法保存 change 边界记录');
|
|
107
|
+
if (saveContextMetadata(root, session, KEY, record))
|
|
108
|
+
return;
|
|
109
|
+
if (target && !saveContextMetadata(root, target, KEY, previous))
|
|
110
|
+
throw new Error('无法恢复 change 边界记录');
|
|
111
|
+
throw new Error('无法保存边界记录');
|
|
95
112
|
}
|
|
96
113
|
export function boundaryStatus(root, session, changes) {
|
|
97
114
|
const record = boundaryRecord(root, session, changes);
|
|
@@ -109,7 +126,15 @@ export function proposeBoundary(root, session, markdown, options = {}) {
|
|
|
109
126
|
const change = options.change ?? (typeof associated === 'string' ? associated : scopeChanges(root, [])[0]);
|
|
110
127
|
if (change)
|
|
111
128
|
scopeChanges(root, [], change);
|
|
112
|
-
|
|
129
|
+
const id = randomUUID();
|
|
130
|
+
boundaryWrite(root, () => save(root, session, {
|
|
131
|
+
id,
|
|
132
|
+
project: realpathSync(root),
|
|
133
|
+
status: 'proposed',
|
|
134
|
+
markdown,
|
|
135
|
+
...(change ? { change } : {}),
|
|
136
|
+
at: new Date().toISOString(),
|
|
137
|
+
}));
|
|
113
138
|
const path = boundaryPage(root, change ?? session, markdown, '边界约定未经用户确认');
|
|
114
139
|
if (!options.noOpen && (options.open || desktopAvailable())) {
|
|
115
140
|
try {
|
|
@@ -124,46 +149,171 @@ export function proposeBoundary(root, session, markdown, options = {}) {
|
|
|
124
149
|
.map((row) => `- ${row.section}:${row.text} 建议默认:${row.suggested}`)
|
|
125
150
|
.join('\n');
|
|
126
151
|
return {
|
|
152
|
+
id,
|
|
127
153
|
path,
|
|
128
154
|
guidance: `边界确认页:${path}\n将以下需拍板条目一次性交给宿主提问工具向用户提问(没有工具时直接在对话提问),附页面路径;用户可回复“按建议”或逐条修改,也可在页面上逐条选择后复制答复粘贴回对话:\n${questions || '无额外需拍板条目,说明沿用常设边界。'}\n回答后运行 sumi boundary confirm <答案文件> 或 --defaults(用户粘贴的“边界确认答复”即五节答案原文,存为答案文件);非交互运行使用 --unconfirmed,不等待审批。`,
|
|
129
155
|
};
|
|
130
156
|
}
|
|
131
157
|
export function confirmBoundary(root, session, options) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
158
|
+
return boundaryWrite(root, () => {
|
|
159
|
+
const changes = options.change ? scopeChanges(root, [], options.change) : undefined;
|
|
160
|
+
const prior = boundaryRecord(root, session, changes);
|
|
161
|
+
if (!prior)
|
|
162
|
+
throw new Error('先运行 sumi boundary propose <草稿文件>');
|
|
163
|
+
if (!options.markdown && !options.defaults && !options.unconfirmed)
|
|
164
|
+
throw new Error('提供答案文件或 --defaults / --unconfirmed');
|
|
165
|
+
const markdown = options.markdown ?? prior.markdown;
|
|
166
|
+
return persistConfirmation(root, session, {
|
|
167
|
+
status: options.unconfirmed ? 'unconfirmed' : 'confirmed',
|
|
168
|
+
markdown,
|
|
169
|
+
change: options.change ?? prior.change,
|
|
170
|
+
project: realpathSync(root),
|
|
171
|
+
at: new Date().toISOString(),
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const CONFIRMED_HEADER = /^确认:用户[^\n]*$/m;
|
|
176
|
+
const entryText = (line) => line.replace(/^\s*[-*] /, '').trim();
|
|
177
|
+
/**
|
|
178
|
+
* 已确认的支持范围按小节合并:保留原有条目与说明,只追加新答案中原来没有的条目。
|
|
179
|
+
* 原节未经用户确认(或是旧式自由文本)时属于临时内容,整节替换。
|
|
180
|
+
*/
|
|
181
|
+
function mergedSupport(existing, markdown, confirmation) {
|
|
182
|
+
const fresh = `确认:${confirmation}\n\n${markdown.trim()}`;
|
|
183
|
+
const header = existing?.match(CONFIRMED_HEADER)?.[0];
|
|
184
|
+
if (!existing || !header || !/^### /m.test(existing))
|
|
185
|
+
return fresh;
|
|
186
|
+
let merged = existing;
|
|
187
|
+
let added = false;
|
|
188
|
+
for (const heading of BOUNDARY_HEADINGS) {
|
|
189
|
+
const block = (text) => new RegExp(`^### ${heading}[ \\t]*\\r?\\n([\\s\\S]*?)(?=^#{1,3} |$(?![\\s\\S]))`, 'm').exec(text);
|
|
190
|
+
const entries = (block(markdown)?.[1] ?? '').split(/\r?\n/).filter((line) => /^\s*[-*] /.test(line));
|
|
191
|
+
const current = block(merged);
|
|
192
|
+
const known = new Set((current?.[1] ?? '')
|
|
193
|
+
.split(/\r?\n/)
|
|
194
|
+
.filter((line) => /^\s*[-*] /.test(line))
|
|
195
|
+
.map(entryText));
|
|
196
|
+
const missing = entries.filter((line) => !known.has(entryText(line)));
|
|
197
|
+
if (!missing.length)
|
|
198
|
+
continue;
|
|
199
|
+
added = true;
|
|
200
|
+
// 条目是用户文本,替换值用函数形式,避免 `$&` 等被当作替换模式。
|
|
201
|
+
merged = current
|
|
202
|
+
? merged.replace(current[0], () => `${current[0].trimEnd()}\n${missing.join('\n')}\n\n`)
|
|
203
|
+
: `${merged.trimEnd()}\n\n### ${heading}\n\n${missing.join('\n')}`;
|
|
204
|
+
}
|
|
205
|
+
const note = confirmation.startsWith('用户,') ? `${confirmation.slice('用户,'.length)} 追加` : `追加条目${confirmation}`;
|
|
206
|
+
return (added ? merged.replace(header, () => `${header};${note}`) : merged).trim();
|
|
207
|
+
}
|
|
208
|
+
function persistConfirmation(root, session, record) {
|
|
209
|
+
const { change, markdown, at, status } = record;
|
|
139
210
|
parseBoundary(markdown);
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
211
|
+
const dir = change ? join(root, 'openspec/changes', scopeChanges(root, [], change)[0]) : undefined;
|
|
212
|
+
if (dir && !existsSync(dir))
|
|
213
|
+
throw new Error(`当前工作区没有 OpenSpec change ${change},边界不写入`);
|
|
214
|
+
const file = dir ? join(dir, 'design.md') : undefined;
|
|
215
|
+
const old = file && existsSync(file) ? readFileSync(file, 'utf8') : undefined;
|
|
216
|
+
if (file) {
|
|
217
|
+
const confirmation = status === 'unconfirmed' ? '未经用户确认(非交互运行)' : `用户,${at.slice(0, 10)}`;
|
|
218
|
+
const existing = old === undefined ? undefined : supportSection(old);
|
|
219
|
+
const section = `## 支持范围\n\n${mergedSupport(existing, markdown, confirmation)}\n\n`;
|
|
220
|
+
const next = existing !== undefined
|
|
221
|
+
? old.replace(/^## 支持范围[^\n]*\n[\s\S]*?(?=^#{1,2} |$(?![\s\S]))/m, () => section)
|
|
222
|
+
: `${old?.trimEnd() ?? ''}\n\n${section}`;
|
|
151
223
|
mkdirSync(dirname(file), { recursive: true });
|
|
152
|
-
|
|
224
|
+
writeFileAtomic(file, next);
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
save(root, session, record);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
if (file && old !== undefined)
|
|
231
|
+
writeFileAtomic(file, old);
|
|
232
|
+
else if (file)
|
|
233
|
+
rmSync(file);
|
|
234
|
+
throw error;
|
|
153
235
|
}
|
|
154
|
-
save(root, session, record);
|
|
155
236
|
return record;
|
|
156
237
|
}
|
|
238
|
+
export function boundaryReceipt(record) {
|
|
239
|
+
return `边界约定:已确认\n确认时间:${record.at}\n${record.markdown}`;
|
|
240
|
+
}
|
|
241
|
+
export function boundaryAnswer(root, session, id) {
|
|
242
|
+
const record = readRecord(root, session);
|
|
243
|
+
if (!id || !record || record.id !== id || record.project !== realpathSync(root))
|
|
244
|
+
throw new Error('边界提案已替换或不属于当前会话');
|
|
245
|
+
return record;
|
|
246
|
+
}
|
|
247
|
+
export function submitBoundaryAnswer(root, session, id, answers) {
|
|
248
|
+
if (!answers || typeof answers !== 'object' || Array.isArray(answers))
|
|
249
|
+
throw new Error('答案格式无效');
|
|
250
|
+
const entries = Object.entries(answers).sort(([a], [b]) => a.localeCompare(b));
|
|
251
|
+
if (entries.length > 200 || entries.some(([, value]) => typeof value !== 'string' || value.length > 2000)) {
|
|
252
|
+
throw new Error('答案格式或长度无效');
|
|
253
|
+
}
|
|
254
|
+
const submitted = createHash('sha256').update(JSON.stringify(entries)).digest('hex');
|
|
255
|
+
return boundaryWrite(root, () => {
|
|
256
|
+
const prior = boundaryAnswer(root, session, id);
|
|
257
|
+
if (prior.status === 'confirmed' && prior.submitted === submitted)
|
|
258
|
+
return prior;
|
|
259
|
+
if (prior.status !== 'proposed')
|
|
260
|
+
throw new Error('边界提案已经结束');
|
|
261
|
+
if (Date.now() - Date.parse(prior.at) > 30 * 60_000)
|
|
262
|
+
throw new Error('边界提案已过期');
|
|
263
|
+
if (prior.change && readRecord(root, changeSession(prior.change))?.id !== id)
|
|
264
|
+
throw new Error('关联 change 已有更新的边界提案');
|
|
265
|
+
const rows = parseBoundary(prior.markdown);
|
|
266
|
+
const edits = new Map();
|
|
267
|
+
for (const [key, answer] of entries) {
|
|
268
|
+
const index = Number(key);
|
|
269
|
+
if (String(index) !== key || !rows[index]?.decision || !answer.trim() || /[\r\n;;]|(?:建议默认|需拍板)[::]/.test(answer))
|
|
270
|
+
throw new Error('条目或答案无效');
|
|
271
|
+
if (answer.trim() !== rows[index].suggested)
|
|
272
|
+
edits.set(index, answer.trim());
|
|
273
|
+
}
|
|
274
|
+
const markdown = edits.size ? applyBoundaryEdits(prior.markdown, edits) : prior.markdown;
|
|
275
|
+
return persistConfirmation(root, session, { ...prior, status: 'confirmed', markdown, submitted, at: new Date().toISOString() });
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
export function cancelBoundaryAnswer(root, session, id) {
|
|
279
|
+
boundaryWrite(root, () => {
|
|
280
|
+
const prior = boundaryAnswer(root, session, id);
|
|
281
|
+
if (prior.status !== 'proposed')
|
|
282
|
+
throw new Error('边界提案已经结束');
|
|
283
|
+
const { id: _id, ...draft } = prior;
|
|
284
|
+
if (!saveContextMetadata(root, session, KEY, draft))
|
|
285
|
+
throw new Error('无法取消边界提案');
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function applyBoundaryEdits(markdown, edits) {
|
|
289
|
+
let section = '';
|
|
290
|
+
const counters = new Map();
|
|
291
|
+
const rows = parseBoundary(markdown);
|
|
292
|
+
return markdown.replace(/^.*$/gm, (line) => {
|
|
293
|
+
const heading = /^(#{1,3}) (.+?)\s*$/.exec(line);
|
|
294
|
+
if (heading)
|
|
295
|
+
section = heading[1] === '###' ? heading[2] : '';
|
|
296
|
+
if (!/^\s*[-*] /.test(line))
|
|
297
|
+
return line;
|
|
298
|
+
const offset = counters.get(section) ?? 0;
|
|
299
|
+
const start = rows.findIndex((row) => row.section === section);
|
|
300
|
+
if (start < 0)
|
|
301
|
+
return line;
|
|
302
|
+
counters.set(section, offset + 1);
|
|
303
|
+
const answer = edits.get(start + offset);
|
|
304
|
+
return answer === undefined ? line : line.replace(DEFAULT_ANSWER, (_match, prefix) => prefix + answer);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
157
307
|
export function skipBoundary(root, session, reason, change) {
|
|
158
308
|
if (!reason.trim())
|
|
159
309
|
throw new Error('boundary skip 需要 --reason');
|
|
160
310
|
if (change)
|
|
161
311
|
scopeChanges(root, [], change);
|
|
162
|
-
save(root, session, { status: 'skipped', markdown: '', reason, at: new Date().toISOString(), ...(change ? { change } : {}) });
|
|
312
|
+
boundaryWrite(root, () => save(root, session, { status: 'skipped', markdown: '', reason, at: new Date().toISOString(), ...(change ? { change } : {}) }));
|
|
163
313
|
}
|
|
164
314
|
export function boundaryDecision(root, session, paths) {
|
|
165
|
-
//
|
|
166
|
-
if (session &&
|
|
315
|
+
// 编辑护栏是会话级一次性约束,当前工作区的任何既有记录都足以放行。
|
|
316
|
+
if (session && ownRecord(root, session))
|
|
167
317
|
return null;
|
|
168
318
|
if (boundaryRecord(root, session, scopeChanges(root, paths)))
|
|
169
319
|
return null;
|
|
@@ -183,7 +333,7 @@ export function boundaryDecision(root, session, paths) {
|
|
|
183
333
|
export function boundaryContext(root, paths, session = envSession(), change) {
|
|
184
334
|
if (session && change && !saveContextMetadata(root, session, 'gov/change', change))
|
|
185
335
|
throw new Error('无法关联 change');
|
|
186
|
-
const prior = session ?
|
|
336
|
+
const prior = session ? ownRecord(root, session) : null;
|
|
187
337
|
const associated = session ? readContextSession(root, session)?.metadata?.['gov/change'] : undefined;
|
|
188
338
|
const changes = scopeChanges(root, paths, change ?? (typeof associated === 'string' ? associated : prior?.change));
|
|
189
339
|
const sources = boundarySources(root, changes);
|