@staix/agent-hub 0.50.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +1 -1
- package/docs/adding-an-ai-tool.md +26 -4
- package/docs/agent-notes/README.md +1 -0
- package/docs/agent-notes/adapters.md +4 -3
- package/docs/agent-notes/budget.md +8 -2
- package/docs/agent-notes/daemon.md +13 -8
- package/docs/agent-notes/local-worker.md +3 -3
- package/docs/agent-notes/security-review.md +6 -5
- package/docs/agent-notes/tasks.md +10 -3
- package/docs/agent-notes/tests.md +4 -3
- package/docs/cooperbench.md +1 -1
- package/docs/design/adapters.md +21 -0
- package/docs/design/cli-output-inventory.md +165 -150
- package/docs/design/cli-output.md +4 -3
- package/docs/design/guidance-probes.md +1 -0
- package/docs/design/roadmap.md +3 -1
- package/docs/design/task-board.md +35 -0
- package/docs/dogfood.md +21 -3
- package/docs/events.md +4 -2
- package/docs/memory.md +5 -3
- package/docs/operations.md +259 -19
- package/docs/quickstart.md +29 -2
- package/docs/roadmap.json +20 -20
- package/docs/roadmap.md +2 -2
- package/docs/roles.md +1 -1
- package/docs/sdlc.md +29 -5
- package/docs/security.md +11 -5
- package/docs/specs/2026-09-19-agent-hub-design.md +44 -0
- package/docs/specs/2026-09-19-multi-project-design.md +4 -0
- package/docs/specs/2026-09-20-upgrade-recovery-design.md +17 -0
- package/docs/specs/mcp-endpoint.md +63 -0
- package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
- package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
- package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
- package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
- package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
- package/docs/verification/2026-11-30-0.51.0.md +91 -0
- package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
- package/docs/verification/2026-11-30-capability-listing-shape-1808.md +45 -0
- package/docs/verification/2026-11-30-upgrade-keep-1807.md +174 -0
- package/docs/verification/2026-12-01-1811-confirmation-receipt.md +19 -0
- package/docs/verification/2026-12-01-1811-orca-agent-list.md +20 -0
- package/docs/verification/2026-12-01-1811-orca-pane-key.md +21 -0
- package/docs/verification/2026-12-02-1819-claude-process-after-renewal.md +54 -0
- package/docs/verification/2026-12-02-agy-1.5.21.md +74 -0
- package/docs/verification/2026-12-02-claude-implementer-2.1.334.md +44 -0
- package/docs/verification/2026-12-02-cli-import-graph.md +33 -0
- package/docs/verification/2026-12-03-0.52.0.md +150 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-isolation.md +53 -0
- package/docs/verification/2026-12-03-codex-0173-reviewer-tool-call.md +34 -0
- package/docs/verification/2026-12-03-jcode-1.3.0.md +25 -0
- package/docs/verification/agy/README.md +17 -0
- package/docs/verification/agy/cli-surface.ts +68 -0
- package/docs/verification/agy/interactive-bridge.ts +92 -0
- package/docs/verification/agy/interactive-session.ts +131 -0
- package/docs/verification/agy/launcher-nonce.ts +215 -0
- package/docs/verification/agy/native-hooks.ts +210 -0
- package/docs/verification/agy/originals/agent-hub-681/cli-surface.ts +87 -0
- package/docs/verification/agy/originals/agent-hub-681/native-hooks-adapted.ts +91 -0
- package/docs/verification/agy/originals/agent-hub-681/tui-actual.ts +200 -0
- package/docs/verification/agy/originals/agent-hub-684/probe.ts +107 -0
- package/docs/verification/agy/originals.json +25 -0
- package/docs/verification/agy/permission-new-functions.ts +128 -0
- package/docs/verification/agy/run-probe.py +108 -0
- package/docs/verification/agy/runtime.ts +171 -0
- package/docs/verification/agy/tmux-helper-control.ts +6 -0
- package/docs/verification/agy/tmux-session.ts +235 -0
- package/docs/verified.json +87 -42
- package/package.json +3 -3
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/compat.json +157 -0
- package/plugins/agent-hub/kimi-hook.js +1416 -24985
- package/plugins/agent-hub/server.js +17415 -32755
- package/scripts/check-docs.mjs +1 -1
- package/src/adapters/acp.ts +13 -13
- package/src/adapters/agy/definition.ts +9 -26
- package/src/adapters/agy/entry.ts +2 -0
- package/src/adapters/channel-peer.ts +3 -1
- package/src/adapters/claude-channel-evidence.ts +7 -3
- package/src/adapters/claude-channel.ts +38 -257
- package/src/adapters/claude-implementer.ts +3 -1
- package/src/adapters/codex-appserver.ts +77 -15
- package/src/adapters/compat.ts +78 -14
- package/src/adapters/configured-acp.ts +23 -163
- package/src/adapters/configured-adapter-policy.ts +160 -0
- package/src/adapters/configured-pull-entry.ts +53 -0
- package/src/adapters/configured-pull.ts +38 -0
- package/src/adapters/conformance/fakes/app-server.ts +9 -2
- package/src/adapters/declaration-catalog.ts +25 -0
- package/src/adapters/declaration-data.ts +342 -0
- package/src/adapters/declaration-resolution.ts +53 -0
- package/src/adapters/definitions/builtin-metadata.ts +62 -84
- package/src/adapters/definitions/jcode-launch.ts +13 -0
- package/src/adapters/definitions/native-adapter-policy.ts +390 -0
- package/src/adapters/definitions/native-cli-claude-launch.ts +6 -3
- package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
- package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
- package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-jcode.ts +6 -2
- package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
- package/src/adapters/definitions/native-cli-entry-types.ts +12 -3
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
- package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
- package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
- package/src/adapters/definitions/native-cli-retained.ts +1 -1
- package/src/adapters/definitions/native-config-defaults.ts +1 -1
- package/src/adapters/definitions/native-configuration.ts +18 -0
- package/src/adapters/definitions/native-help.ts +24 -0
- package/src/adapters/definitions/native-launch-declarations.ts +34 -0
- package/src/adapters/definitions/native-launch-policy.ts +4 -0
- package/src/adapters/definitions/native-launch-settings.ts +72 -0
- package/src/adapters/definitions/native-light-cli.ts +18 -0
- package/src/adapters/definitions/native-light-preview.ts +10 -0
- package/src/adapters/definitions/native-wrapper-launch.ts +10 -0
- package/src/adapters/definitions/qwen.ts +6 -29
- package/src/adapters/definitions/reviewer-variants.ts +7 -8
- package/src/adapters/external-declarations.ts +31 -0
- package/src/adapters/external-modules.ts +4 -29
- package/src/adapters/jcode.ts +19 -12
- package/src/adapters/native-capabilities.ts +18 -8
- package/src/adapters/native-facts-hooks.ts +12 -0
- package/src/adapters/native-proof-ports.ts +1 -1
- package/src/adapters/presets.ts +136 -0
- package/src/adapters/qwen-dual.ts +2 -2
- package/src/adapters/registry-types.ts +3 -0
- package/src/adapters/registry.ts +20 -81
- package/src/adapters/reviewer-print.ts +26 -9
- package/src/adapters/role-eligibility.ts +2 -1
- package/src/cli/accounts-import.ts +72 -0
- package/src/cli/agents-latest-table.ts +88 -0
- package/src/cli/agents-latest.ts +22 -0
- package/src/cli/agents-output.ts +10 -0
- package/src/cli/agents-presets.ts +100 -0
- package/src/cli/agents.ts +1 -1
- package/src/cli/attention.ts +3 -2
- package/src/cli/autonomy-homes.ts +7 -2
- package/src/cli/autonomy-offline.ts +1 -1
- package/src/cli/bench.ts +1 -1
- package/src/cli/budget-renew-guidance.ts +129 -0
- package/src/cli/claude-homes.ts +9 -5
- package/src/cli/claude-profile-hook.ts +31 -11
- package/src/cli/command-context.ts +3 -0
- package/src/cli/command-table.ts +123 -0
- package/src/cli/commands/accounts.ts +8 -0
- package/src/cli/commands/agents.ts +18 -0
- package/src/cli/commands/answer.ts +28 -0
- package/src/cli/commands/ask.ts +17 -0
- package/src/cli/commands/autonomy.ts +83 -0
- package/src/cli/commands/backlog.ts +46 -0
- package/src/cli/commands/bench.ts +60 -0
- package/src/cli/commands/board.ts +48 -0
- package/src/cli/commands/broker.ts +9 -0
- package/src/cli/commands/budget.ts +96 -0
- package/src/cli/commands/capabilities.ts +12 -0
- package/src/cli/commands/check-path.ts +55 -0
- package/src/cli/commands/completion.ts +8 -0
- package/src/cli/commands/console.ts +12 -0
- package/src/cli/commands/daemon.ts +8 -0
- package/src/cli/commands/deliverables.ts +25 -0
- package/src/cli/commands/doctor.ts +249 -0
- package/src/cli/commands/down.ts +3 -0
- package/src/cli/commands/export.ts +15 -0
- package/src/cli/commands/facts.ts +15 -0
- package/src/cli/commands/goal.ts +22 -0
- package/src/cli/commands/guidance.ts +102 -0
- package/src/cli/commands/help.ts +17 -0
- package/src/cli/commands/host.ts +45 -0
- package/src/cli/commands/init.ts +121 -0
- package/src/cli/commands/instructed.ts +19 -0
- package/src/cli/commands/instruction-hook.ts +15 -0
- package/src/cli/commands/intake.ts +24 -0
- package/src/cli/commands/kill.ts +15 -0
- package/src/cli/commands/learn.ts +23 -0
- package/src/cli/commands/lineage.ts +30 -0
- package/src/cli/commands/logs.ts +21 -0
- package/src/cli/commands/manager.ts +15 -0
- package/src/cli/commands/memory.ts +21 -0
- package/src/cli/commands/model.ts +25 -0
- package/src/cli/commands/models.ts +40 -0
- package/src/cli/commands/native.ts +39 -0
- package/src/cli/commands/pause.ts +5 -0
- package/src/cli/commands/peer.ts +32 -0
- package/src/cli/commands/permission.ts +26 -0
- package/src/cli/commands/permit.ts +12 -0
- package/src/cli/commands/pet.ts +24 -0
- package/src/cli/commands/projects.ts +49 -0
- package/src/cli/commands/queue.ts +70 -0
- package/src/cli/commands/recovery-run.ts +13 -0
- package/src/cli/commands/recovery.ts +130 -0
- package/src/cli/commands/release.ts +23 -0
- package/src/cli/commands/releases.ts +91 -0
- package/src/cli/commands/remember.ts +6 -0
- package/src/cli/commands/report.ts +27 -0
- package/src/cli/commands/research.ts +53 -0
- package/src/cli/commands/reset.ts +89 -0
- package/src/cli/commands/restart.ts +5 -0
- package/src/cli/commands/results.ts +31 -0
- package/src/cli/commands/resume.ts +5 -0
- package/src/cli/commands/review.ts +24 -0
- package/src/cli/commands/roadmap.ts +21 -0
- package/src/cli/commands/role.ts +34 -0
- package/src/cli/commands/roles.ts +30 -0
- package/src/cli/commands/room.ts +14 -0
- package/src/cli/commands/roster.ts +48 -0
- package/src/cli/commands/route.ts +9 -0
- package/src/cli/commands/say.ts +21 -0
- package/src/cli/commands/schedule.ts +17 -0
- package/src/cli/commands/sdlc.ts +321 -0
- package/src/cli/commands/settings.ts +148 -0
- package/src/cli/commands/setup.ts +89 -0
- package/src/cli/commands/shared-refusals.ts +25 -0
- package/src/cli/commands/smoke.ts +44 -0
- package/src/cli/commands/source.ts +64 -0
- package/src/cli/commands/specs.ts +13 -0
- package/src/cli/commands/status.ts +28 -0
- package/src/cli/commands/stop.ts +17 -0
- package/src/cli/commands/structure.ts +60 -0
- package/src/cli/commands/study.ts +39 -0
- package/src/cli/commands/tail.ts +19 -0
- package/src/cli/commands/task.ts +114 -0
- package/src/cli/commands/title.ts +17 -0
- package/src/cli/commands/turns.ts +10 -0
- package/src/cli/commands/ui.ts +47 -0
- package/src/cli/commands/undo.ts +77 -0
- package/src/cli/commands/up.ts +39 -0
- package/src/cli/commands/upgrade.ts +5 -0
- package/src/cli/commands/usage.ts +33 -0
- package/src/cli/commands/version.ts +5 -0
- package/src/cli/commands/watch.ts +30 -0
- package/src/cli/commands/worktrees.ts +31 -0
- package/src/cli/conductor-recovery.ts +1 -1
- package/src/cli/console-state.ts +5 -138
- package/src/cli/console-versions.ts +1 -1
- package/src/cli/facts-hook.ts +11 -4
- package/src/cli/help.ts +44 -20
- package/src/cli/identity.ts +27 -4
- package/src/cli/init-prompt.ts +1 -1
- package/src/cli/init-settings.ts +4 -35
- package/src/cli/init.ts +1 -1
- package/src/cli/json-text-spans.ts +57 -0
- package/src/cli/launch-check.ts +156 -0
- package/src/cli/launch.ts +19 -70
- package/src/cli/light-dispatch.ts +29 -0
- package/src/cli/main.js +8 -1
- package/src/cli/main.ts +257 -2799
- package/src/cli/memory.ts +1 -1
- package/src/cli/orca-probe.ts +119 -0
- package/src/cli/output.ts +45 -3
- package/src/cli/preview.ts +11 -6
- package/src/cli/recovery-launch.ts +1 -1
- package/src/cli/recovery-version-preflight.ts +28 -9
- package/src/cli/replace-process.ts +22 -0
- package/src/cli/report-layout.ts +142 -0
- package/src/cli/roadmap-usage.ts +16 -0
- package/src/cli/roadmap.ts +3 -16
- package/src/cli/sdlc-doctor.ts +27 -0
- package/src/cli/sdlc-output.ts +55 -1
- package/src/cli/setup-homes.ts +2 -2
- package/src/cli/start-agents-run.ts +85 -7
- package/src/cli/start-check.ts +28 -0
- package/src/cli/statusline-tee.ts +25 -4
- package/src/cli/terminal-recovery.ts +53 -10
- package/src/cli/upgrade-interactive.ts +1 -0
- package/src/cli/upgrade-runtime.ts +12 -1
- package/src/cli/upgrade.ts +4 -15
- package/src/cli/warn-line.ts +1 -1
- package/src/hub/accounts.ts +148 -0
- package/src/hub/addons.ts +20 -0
- package/src/hub/agent-drift.ts +2 -1
- package/src/hub/budget-projection.ts +39 -7
- package/src/hub/budget.ts +231 -16
- package/src/hub/channel-project.ts +3 -3
- package/src/hub/ci-watch.ts +311 -79
- package/src/hub/conductor-peer.ts +24 -0
- package/src/hub/conductor.ts +2 -21
- package/src/hub/config-apply.ts +25 -14
- package/src/hub/config-edit.ts +1 -1
- package/src/hub/config-tier.ts +2 -0
- package/src/hub/config.ts +535 -0
- package/src/hub/control-client.ts +49 -1
- package/src/hub/daemon.ts +492 -569
- package/src/hub/delivery-public.ts +11 -0
- package/src/hub/events.ts +3 -0
- package/src/hub/home-tag.ts +12 -0
- package/src/hub/host.ts +217 -0
- package/src/hub/hub-check.ts +125 -0
- package/src/hub/hub-tools.ts +2 -1
- package/src/hub/instance-budget.ts +2 -2
- package/src/hub/instance-config.ts +15 -126
- package/src/hub/instances.ts +22 -6
- package/src/hub/instruction-receipt.ts +2 -2
- package/src/hub/kimi-usage.ts +38 -11
- package/src/hub/lifecycle.ts +86 -4
- package/src/hub/mcp-bridge-core.ts +98 -0
- package/src/hub/mcp-channel-push.ts +20 -0
- package/src/hub/mcp-endpoint-serve.ts +178 -0
- package/src/hub/mcp-endpoint.ts +226 -0
- package/src/hub/mcp-tool-call.ts +181 -0
- package/src/hub/operational-settings.ts +2 -0
- package/src/hub/orca-env.ts +6 -0
- package/src/hub/orca-state.ts +84 -0
- package/src/hub/path-policy.ts +1 -1
- package/src/hub/peers.ts +5 -1
- package/src/hub/permission-mode.ts +5 -41
- package/src/hub/permission-paths.ts +41 -0
- package/src/hub/project.ts +20 -0
- package/src/hub/protocol-window.ts +58 -0
- package/src/hub/quota-origin.ts +20 -0
- package/src/hub/recovery-policy.ts +1 -1
- package/src/hub/registry.ts +36 -2
- package/src/hub/releases-inventory.ts +198 -0
- package/src/hub/report.ts +1 -1
- package/src/hub/research.ts +1 -1
- package/src/hub/review-brief.ts +47 -2
- package/src/hub/roster.ts +6 -3
- package/src/hub/routing.ts +9 -2
- package/src/hub/runtime-capture-prune.ts +25 -3
- package/src/hub/runtime-prune-health.ts +8 -1
- package/src/hub/sdlc-check.ts +205 -0
- package/src/hub/sdlc-release-authorization.ts +42 -21
- package/src/hub/sdlc-release-diagnostics.ts +5 -0
- package/src/hub/sdlc-release-policy.ts +21 -7
- package/src/hub/sdlc-release.ts +80 -20
- package/src/hub/sdlc-sync.ts +146 -0
- package/src/hub/sdlc.ts +38 -5
- package/src/hub/settings.ts +7 -4
- package/src/hub/start-agents.ts +1 -1
- package/src/hub/start-mode.ts +11 -4
- package/src/hub/structure-budget.ts +131 -0
- package/src/hub/structure-scan.ts +149 -0
- package/src/hub/tasks-experiment.ts +455 -0
- package/src/hub/tasks-guidance.ts +606 -0
- package/src/hub/tasks-roadmap-plan.ts +419 -0
- package/src/hub/tasks-roadmap.ts +491 -0
- package/src/hub/tasks-study.ts +661 -0
- package/src/hub/tasks-survey.ts +192 -0
- package/src/hub/tasks.ts +457 -2584
- package/src/hub/terminal-open.ts +5 -3
- package/src/hub/tooling.ts +3 -19
- package/src/hub/usage-rollup.ts +9 -3
- package/src/local/tools.ts +5 -0
- package/src/ui/index.html +1 -1
- package/src/ui/needs.ts +17 -5
- package/src/ui/peer-palette.ts +2 -4
- package/src/ui/plugin.ts +1 -1
- package/templates/presets/agents.json +60 -0
- package/templates/presets/confirmation-matrix.json +8 -8
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
// #1830 S4b: the roadmap and milestone methods of `Tasks` that read, edit, export, check and sync the milestone tree, moved whole. `Tasks` builds one `RoadmapDomain` with its deps and an explicit host (the callbacks the moved
|
|
2
|
+
// bodies reach), keeps a one-line delegating method for each member it, the planning half (`tasks-roadmap-plan.ts`) or a caller still uses, and stays the only board writer. No module-level state: the spec cache lives on the instance.
|
|
3
|
+
import { instructedHistory } from "./instructed-exact.ts";
|
|
4
|
+
import { parseMilestoneInput, parseMilestonePatch, milestoneId, milestoneRevision, milestoneLinkRef, githubRepo, MILESTONE_STATES, type Milestone, type MilestoneLinkKind, type MilestonePatch, type MilestoneState } from "./roadmap.ts";
|
|
5
|
+
import { milestoneViews, type MilestoneView, type RoadmapSnapshot } from "./roadmap-view.ts";
|
|
6
|
+
import { readMirrorSnapshot, planRoadmapMirror, recoverMirrorBinding } from "./roadmap-sync.ts";
|
|
7
|
+
import { roadmapExport } from "./roadmap-export.ts";
|
|
8
|
+
import { roadmapIssueStates } from "./roadmap-issue-states.ts";
|
|
9
|
+
import { checkRoadmap, type DriftMilestone, type RoadmapDrift } from "./roadmap-check.ts";
|
|
10
|
+
import { withTree, type ReadyToClose, type TreeRollup } from "./roadmap-unplaced.ts";
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { matchesPolicy } from "./path-policy.ts";
|
|
13
|
+
import { DeliverableRefusal, readGuardedDeliverable } from "./deliverable-files.ts";
|
|
14
|
+
import { TASK_REASONS, type TaskReason, isClosedTaskState, type TaskRefs } from "./board.ts";
|
|
15
|
+
import { HUB, USER, type PeerId } from "./envelope.ts";
|
|
16
|
+
import { githubOriginRepository } from "./task-repository.ts";
|
|
17
|
+
import { PreEffectToolRefusal } from "./tool-refusal.ts";
|
|
18
|
+
import { type SpecsCheckReport, type SpecsCoverReport } from "./specs.ts";
|
|
19
|
+
import { sdlcGh, type SdlcGh } from "./sdlc.ts";
|
|
20
|
+
import type { Task, TaskPlan, SpecTaskReport } from "./board.ts";
|
|
21
|
+
import type { GitHubSource } from "./github-import.ts";
|
|
22
|
+
import type { PiiVerdict } from "./inference.ts";
|
|
23
|
+
import type { TaskRepositories } from "./task-repository.ts";
|
|
24
|
+
import type { Tasks, TasksDeps } from "./tasks.ts";
|
|
25
|
+
|
|
26
|
+
/** #1738: how long one working-tree spec check serves the roadmap snapshot. */
|
|
27
|
+
const ROADMAP_SPECS_REUSE_MS = 60_000;
|
|
28
|
+
/** #1647: how many overlapping paths a parallel-sibling refusal names, so the text stays one line. */
|
|
29
|
+
const PARALLEL_PATHS_NAMED = 5;
|
|
30
|
+
|
|
31
|
+
/** What the moved methods call back into `Tasks` for: each member is the `Tasks` member of that name, unchanged. */
|
|
32
|
+
export interface RoadmapHost {
|
|
33
|
+
configuredManualConductor(by: PeerId): boolean;
|
|
34
|
+
currentSpecReport(task: Task): SpecTaskReport | undefined;
|
|
35
|
+
isConfiguredPlanner(peer: PeerId): boolean;
|
|
36
|
+
readonly isPii: (task: Pick<Task, "signals">) => boolean;
|
|
37
|
+
observerExcluded(by: PeerId): boolean;
|
|
38
|
+
planIssueIdentity(task: Task): { repo: string; issue: number } | undefined;
|
|
39
|
+
readonly publicMetadataText: (text: string) => boolean;
|
|
40
|
+
readonly repositories: TaskRepositories;
|
|
41
|
+
requestCheck(by: PeerId, fence?: () => string | undefined): () => void;
|
|
42
|
+
requireLocalTaskPeer(peer: unknown): void;
|
|
43
|
+
reviewObserverTurn(by: PeerId, task?: number): boolean;
|
|
44
|
+
samePlace(a: string, b: string): boolean;
|
|
45
|
+
screenCall(text: string): Promise<PiiVerdict>;
|
|
46
|
+
readonly screenOn: () => boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class RoadmapDomain {
|
|
50
|
+
constructor(private readonly d: TasksDeps, private readonly host: RoadmapHost) {}
|
|
51
|
+
roadmapReadAuthority(by: PeerId): void {
|
|
52
|
+
this.host.requireLocalTaskPeer(by);
|
|
53
|
+
if (this.d.privateTurn?.(by) || this.host.observerExcluded(by) || this.host.reviewObserverTurn(by)) throw new PreEffectToolRefusal("roadmap is unavailable during private or review-observer input; use ahub roadmap list after that turn");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
roadmapWriteAuthority(by: PeerId): () => void {
|
|
57
|
+
const check = this.host.requestCheck(by, () => this.d.sweepHeld?.() || this.d.bus.isRecoveryHeld || this.d.bus.storageError ? "roadmap writes are held by recovery, shutdown or storage; retry ahub roadmap list after recovery" : undefined);
|
|
58
|
+
const current = () => {
|
|
59
|
+
check(); this.roadmapReadAuthority(by);
|
|
60
|
+
if (by !== USER && (!this.d.bus.isRostered(by) || !this.host.isConfiguredPlanner(by) && !this.host.configuredManualConductor(by)))
|
|
61
|
+
throw new PreEffectToolRefusal("roadmap writes require a configured planner or the unique conductor; ask the person to run ahub roadmap");
|
|
62
|
+
};
|
|
63
|
+
current(); return current;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
roadmapParsed<T>(read: () => T): T {
|
|
67
|
+
try { return read(); }
|
|
68
|
+
catch (error) { throw new PreEffectToolRefusal(`${error instanceof Error ? error.message : "invalid roadmap input"}; check ahub roadmap show and correct the fields`); }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
roadmapCurrent(id: unknown, state?: MilestoneState): Milestone {
|
|
72
|
+
const row = this.d.board.milestone(this.roadmapParsed(() => milestoneId(id)));
|
|
73
|
+
if (!row) throw new PreEffectToolRefusal("roadmap milestone does not exist; use ahub roadmap list");
|
|
74
|
+
if (["done", "dropped"].includes(row.state) && state !== row.state) throw new PreEffectToolRefusal("a settled milestone is final; create new work with ahub roadmap new");
|
|
75
|
+
return row;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
roadmapStateAuthority(by: PeerId, state: MilestoneState | undefined): void {
|
|
79
|
+
if (state !== undefined && !(MILESTONE_STATES as readonly string[]).includes(state)) throw new PreEffectToolRefusal("invalid milestone state; use proposed, planned, active, done or dropped with ahub roadmap state");
|
|
80
|
+
if (by !== USER && (state === "done" || state === "dropped")) throw new PreEffectToolRefusal("done and dropped require the person; ask them to run ahub roadmap state");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
roadmapTextCurrent(fields: MilestonePatch): string {
|
|
84
|
+
const text = [fields.title, fields.outcome].filter((value): value is string => value !== undefined).join("\n");
|
|
85
|
+
if (text && !this.host.publicMetadataText(text))
|
|
86
|
+
throw new PreEffectToolRefusal("milestone text was not cleared for public planning; remove private content before ahub roadmap new or edit");
|
|
87
|
+
return text;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async roadmapScreen(fields: MilestonePatch): Promise<void> {
|
|
91
|
+
const text = this.roadmapTextCurrent(fields);
|
|
92
|
+
if (text && this.host.screenOn() && (await this.host.screenCall(text)).label !== "clear")
|
|
93
|
+
throw new PreEffectToolRefusal("milestone text was not cleared for public planning; remove private content before ahub roadmap new or edit");
|
|
94
|
+
this.roadmapTextCurrent(fields);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
roadmapResult(by: PeerId, id: number): MilestoneView {
|
|
98
|
+
try { return this.milestoneShow(by, id); }
|
|
99
|
+
catch { throw new Error("roadmap operation finished but public readback is unavailable; inspect ahub roadmap show before retrying"); }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async milestoneNew(by: PeerId, raw: unknown): Promise<MilestoneView> {
|
|
103
|
+
const current = this.roadmapWriteAuthority(by), fields = this.roadmapParsed(() => parseMilestoneInput(raw));
|
|
104
|
+
this.roadmapStateAuthority(by, fields.state);
|
|
105
|
+
await this.roadmapScreen(fields); current(); this.roadmapStateAuthority(by, fields.state); this.roadmapTextCurrent(fields);
|
|
106
|
+
const row = this.d.board.newMilestone(fields, by, this.d.now?.() ?? Date.now());
|
|
107
|
+
return this.roadmapResult(by, row.id);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async milestoneEdit(by: PeerId, id: number, revision: number, raw: unknown): Promise<MilestoneView> {
|
|
111
|
+
const current = this.roadmapWriteAuthority(by), fields = this.roadmapParsed(() => parseMilestonePatch(raw));
|
|
112
|
+
this.roadmapParsed(() => milestoneRevision(revision)); this.roadmapStateAuthority(by, fields.state);
|
|
113
|
+
const validate = () => {
|
|
114
|
+
current(); this.roadmapStateAuthority(by, fields.state);
|
|
115
|
+
const row = this.roadmapCurrent(id);
|
|
116
|
+
if (row.revision !== revision) throw new PreEffectToolRefusal("roadmap revision changed; reload ahub roadmap show before editing");
|
|
117
|
+
return row;
|
|
118
|
+
};
|
|
119
|
+
validate(); await this.roadmapScreen(fields); const row = validate(); this.roadmapTextCurrent(fields);
|
|
120
|
+
if (Object.entries(fields).every(([key, value]) => row[key as keyof Milestone] === value)) return this.milestoneShow(by, id);
|
|
121
|
+
this.d.board.updateMilestone(id, fields, revision, { by, at: this.d.now?.() ?? Date.now(), event: "edited", fields: Object.keys(fields) });
|
|
122
|
+
return this.roadmapResult(by, id);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
milestoneLink(by: PeerId, id: number, kind: MilestoneLinkKind, raw: string): MilestoneView {
|
|
126
|
+
this.roadmapWriteAuthority(by);
|
|
127
|
+
const row = this.roadmapCurrent(id), ref = this.roadmapParsed(() => milestoneLinkRef(kind, raw));
|
|
128
|
+
if (!this.host.publicMetadataText(ref)) throw new PreEffectToolRefusal("roadmap reference is private; use a public reference with ahub roadmap link");
|
|
129
|
+
if (kind === "task" && !this.d.board.get(Number(ref)) || kind === "release" && !this.d.board.release(Number(ref)))
|
|
130
|
+
throw new PreEffectToolRefusal("roadmap target does not exist; inspect ahub board or ahub release list before linking");
|
|
131
|
+
this.d.board.linkMilestone(id, kind, ref, by, row.revision, this.d.now?.() ?? Date.now());
|
|
132
|
+
return this.roadmapResult(by, id);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
milestoneUnlink(by: PeerId, id: number, kind: MilestoneLinkKind, raw: string): MilestoneView {
|
|
136
|
+
this.roadmapWriteAuthority(by);
|
|
137
|
+
const row = this.roadmapCurrent(id), ref = this.roadmapParsed(() => milestoneLinkRef(kind, raw));
|
|
138
|
+
this.d.board.unlinkMilestone(id, kind, ref, by, row.revision, this.d.now?.() ?? Date.now());
|
|
139
|
+
return this.roadmapResult(by, id);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
milestoneOrder(by: PeerId, id: number, order: number): MilestoneView {
|
|
143
|
+
this.roadmapWriteAuthority(by);
|
|
144
|
+
const row = this.roadmapCurrent(id), fields = this.roadmapParsed(() => parseMilestonePatch({ order }));
|
|
145
|
+
if (row.order !== order) this.d.board.updateMilestone(id, fields, row.revision, { by, at: this.d.now?.() ?? Date.now(), event: "ordered", fields: ["order"] });
|
|
146
|
+
return this.roadmapResult(by, id);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
milestoneState(by: PeerId, id: number, state: MilestoneState): MilestoneView {
|
|
150
|
+
this.roadmapWriteAuthority(by); this.roadmapStateAuthority(by, state);
|
|
151
|
+
this.roadmapParsed(() => parseMilestonePatch({ state }));
|
|
152
|
+
const row = this.roadmapCurrent(id, state);
|
|
153
|
+
// #1622 family 4: an instructed person verdict records the same three provenance keys task history does, for done and dropped only.
|
|
154
|
+
const instruction = by === USER && (state === "done" || state === "dropped") ? instructedHistory(by) : {};
|
|
155
|
+
if (row.state !== state) this.d.board.updateMilestone(id, { state }, row.revision, { by, at: this.d.now?.() ?? Date.now(), event: "state", fields: ["state"], ...instruction });
|
|
156
|
+
return this.roadmapResult(by, id);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** #1738: the hub's own roadmap pass (the five-minute sweep and each task change's notice) runs milestoneList several times (the sweep, roadmapNotify, roadmapCheck and each
|
|
160
|
+
* finding's recheck), and a working-tree spec check runs one synchronous git per spec path, so hub reads reuse one check for ROADMAP_SPECS_REUSE_MS. A thrown check is not
|
|
161
|
+
* kept. Reads by the person and peers, and explicit `specs check`, stay uncached.
|
|
162
|
+
* ponytail: a time window, not a repository key; key it on HEAD and index state, or run the check off the event loop, if a minute of stale freshness ever matters. */
|
|
163
|
+
roadmapSpecs: { at: number; report: SpecsCheckReport | SpecsCoverReport | undefined } | undefined;
|
|
164
|
+
roadmapSpecsCheck(): SpecsCheckReport | SpecsCoverReport | undefined {
|
|
165
|
+
const now = this.d.now?.() ?? Date.now(), kept = this.roadmapSpecs;
|
|
166
|
+
if (kept && now >= kept.at && now - kept.at < ROADMAP_SPECS_REUSE_MS) return kept.report;
|
|
167
|
+
const report = this.d.specsRead?.("check", []);
|
|
168
|
+
this.roadmapSpecs = { at: now, report };
|
|
169
|
+
return report;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
roadmapSpecsFor(by: PeerId): SpecsCheckReport | SpecsCoverReport | undefined {
|
|
173
|
+
return by === HUB ? this.roadmapSpecsCheck() : this.d.specsRead?.("check", []);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
roadmapSnapshot(by: PeerId, specs = () => this.roadmapSpecsFor(by)): RoadmapSnapshot {
|
|
177
|
+
let freshness: SpecsCheckReport["freshness"] | undefined;
|
|
178
|
+
try { const report = specs(); if (report && "freshness" in report && !report.truncated && report.errors === 0)
|
|
179
|
+
freshness = report.freshness.filter(row => this.host.publicMetadataText(row.path) && (row.id === undefined || this.host.publicMetadataText(row.id))); } catch { /* unavailable evidence stays unknown */ }
|
|
180
|
+
return { milestones: this.d.board.milestones(), links: this.d.board.milestoneLinks(), tasks: this.d.board.list(), releases: this.d.board.releases(), freshness,
|
|
181
|
+
issueOf: task => { try { const source = this.host.planIssueIdentity(task); return source ? `${source.repo.toLowerCase()}#${source.issue}` : undefined; } catch { return undefined; } },
|
|
182
|
+
privateTask: task => this.host.isPii(task) || task.signals.includes("pii") || task.state === "backlog" && by !== USER && !this.host.isConfiguredPlanner(by),
|
|
183
|
+
publicText: text => this.host.publicMetadataText(text),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
milestoneList(by: PeerId, specs?: () => SpecsCheckReport | SpecsCoverReport | undefined): (MilestoneView & { tree: TreeRollup; readyToClose: ReadyToClose })[] {
|
|
188
|
+
this.roadmapReadAuthority(by);
|
|
189
|
+
const views = withTree(milestoneViews(this.roadmapSnapshot(by, specs)));
|
|
190
|
+
this.roadmapReadAuthority(by); return views;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
milestoneShow(by: PeerId, id: number): MilestoneView {
|
|
194
|
+
this.roadmapParsed(() => milestoneId(id));
|
|
195
|
+
const row = this.milestoneList(by).find(row => row.id === id);
|
|
196
|
+
if (!row) throw new PreEffectToolRefusal("roadmap milestone does not exist; use ahub roadmap list");
|
|
197
|
+
return row;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Host-sampled GitHub authority is never supplied by a tool argument. */
|
|
201
|
+
roadmapRepository(): string {
|
|
202
|
+
const repo = this.roadmapParsed(() => githubRepo(this.d.repository));
|
|
203
|
+
let origin: string | undefined;
|
|
204
|
+
try { origin = this.d.roadmapOrigin ? this.d.roadmapOrigin() : githubOriginRepository(this.d.cwd); } catch { /* unknown is not a trusted origin */ }
|
|
205
|
+
if (!origin || origin.toLowerCase() !== repo) throw new PreEffectToolRefusal("roadmap GitHub origin is unavailable or does not match this project; inspect the local origin before retrying");
|
|
206
|
+
return repo;
|
|
207
|
+
}
|
|
208
|
+
roadmapApplyAuthority(by: PeerId): void {
|
|
209
|
+
this.roadmapReadAuthority(by);
|
|
210
|
+
if (this.d.sweepHeld?.() || this.d.bus.isRecoveryHeld || this.d.bus.storageError) throw new PreEffectToolRefusal("roadmap writes are held; retry after recovery");
|
|
211
|
+
if (by !== USER && (!(this.d.roadmapConfig?.().github_write === "conductor") || !this.host.configuredManualConductor(by) || !this.d.bus.isRostered(by)))
|
|
212
|
+
throw new PreEffectToolRefusal("GitHub roadmap writes require the person or the configured conductor with roadmap.github_write enabled");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
roadmapIssueRefs(views: ReturnType<Tasks["milestoneList"]>): Set<string> {
|
|
216
|
+
const refs = new Set<string>();
|
|
217
|
+
for (const view of views) {
|
|
218
|
+
for (const issue of view.issues) refs.add(issue.ref);
|
|
219
|
+
for (const member of view.tasks) {
|
|
220
|
+
const task = this.d.board.get(member.id); if (!task) continue;
|
|
221
|
+
try { const source = this.host.planIssueIdentity(task); if (source && this.host.publicMetadataText(source.repo)) refs.add(`${source.repo.toLowerCase()}#${source.issue}`); } catch { /* ambiguous identity is unknown */ }
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return refs;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Render only screened views. Issue writes require an exact preview and fresh authority. */
|
|
228
|
+
async roadmapExport(by: PeerId, input: { issue?: number; apply?: boolean; confirm?: string } = {}): Promise<{ json: string; markdown: string; fingerprint: string; call?: string[]; applied: boolean }> {
|
|
229
|
+
const check = this.host.requestCheck(by, () => this.d.sweepHeld?.() || this.d.bus.isRecoveryHeld || this.d.bus.storageError ? "roadmap is held by recovery or storage" : undefined);
|
|
230
|
+
check(); this.roadmapReadAuthority(by);
|
|
231
|
+
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some(key => !["issue", "apply", "confirm"].includes(key)) || input.apply !== undefined && typeof input.apply !== "boolean" || input.confirm !== undefined && (typeof input.confirm !== "string" || !/^[a-f0-9]{64}$/.test(input.confirm))) throw new PreEffectToolRefusal("invalid roadmap export options; preview before applying");
|
|
232
|
+
if (input.issue !== undefined) this.roadmapParsed(() => milestoneId(input.issue));
|
|
233
|
+
if (input.apply && input.issue === undefined) throw new PreEffectToolRefusal("roadmap export --apply needs an issue; preview with --issue first");
|
|
234
|
+
if (input.apply) this.roadmapApplyAuthority(by);
|
|
235
|
+
let pinned: { report: SpecsCheckReport | SpecsCoverReport | undefined } | undefined;
|
|
236
|
+
const specs = () => { if (!pinned) { pinned = { report: undefined }; pinned.report = this.roadmapSpecsFor(by); } return pinned.report; };
|
|
237
|
+
let checkedKey = this.roadmapBoardKey(by);
|
|
238
|
+
const views = this.milestoneList(by, specs), refs = this.roadmapIssueRefs(views);
|
|
239
|
+
const evidence = JSON.stringify([views, [...refs]]);
|
|
240
|
+
const privacy = JSON.stringify([this.d.routing(), this.d.piiPaths, this.d.deny]);
|
|
241
|
+
const current = () => {
|
|
242
|
+
check(); this.roadmapReadAuthority(by);
|
|
243
|
+
const key = this.roadmapBoardKey(by);
|
|
244
|
+
const sameViews = () => {
|
|
245
|
+
if (key === checkedKey) return true;
|
|
246
|
+
const latest = this.milestoneList(by, specs);
|
|
247
|
+
return JSON.stringify([latest, [...this.roadmapIssueRefs(latest)]]) === evidence;
|
|
248
|
+
};
|
|
249
|
+
if (JSON.stringify([this.d.routing(), this.d.piiPaths, this.d.deny]) !== privacy || !sameViews())
|
|
250
|
+
throw new PreEffectToolRefusal("roadmap or privacy policy changed while exporting; retry ahub roadmap export");
|
|
251
|
+
checkedKey = key;
|
|
252
|
+
};
|
|
253
|
+
const issueStates = await roadmapIssueStates(refs, this.roadmapGh(), current);
|
|
254
|
+
current();
|
|
255
|
+
const rendered = roadmapExport(views, issueStates);
|
|
256
|
+
const repo = input.issue === undefined ? undefined : this.roadmapRepository();
|
|
257
|
+
const call = repo === undefined ? undefined : ["api", `repos/${repo}/issues/${input.issue}`, "--hostname", "github.com", "--method", "PATCH", "-f", `body=${rendered.markdown}`];
|
|
258
|
+
const fingerprint = createHash("sha256").update(JSON.stringify({ repo: repo ?? null, issue: input.issue ?? null, markdown: rendered.markdown })).digest("hex");
|
|
259
|
+
if (!input.apply) return { ...rendered, fingerprint, ...(call ? { call } : {}), applied: false };
|
|
260
|
+
if (input.confirm !== fingerprint) throw new PreEffectToolRefusal(`roadmap export preview changed; run ahub roadmap export --issue ${input.issue} and retry with --confirm ${fingerprint}`);
|
|
261
|
+
check(); this.roadmapApplyAuthority(by); if (this.roadmapRepository() !== repo) throw new PreEffectToolRefusal("roadmap GitHub origin changed; preview again");
|
|
262
|
+
let result: Awaited<ReturnType<SdlcGh>>;
|
|
263
|
+
try { result = await this.roadmapGh()(call!, 10_000, undefined, 64 * 1024); }
|
|
264
|
+
catch { throw new Error("roadmap issue update outcome is unknown; inspect the issue before retrying"); }
|
|
265
|
+
if (result.code !== 0) throw new Error("roadmap issue update was not confirmed; inspect the issue before retrying");
|
|
266
|
+
try { current(); this.roadmapApplyAuthority(by); if (this.roadmapRepository() !== repo) throw new Error("changed"); }
|
|
267
|
+
catch { throw new Error("roadmap or authority changed after issue update; inspect the issue and preview again"); }
|
|
268
|
+
return { ...rendered, fingerprint, call, applied: true };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Build drift only from the same screened views and host-owned evidence as roadmap reads. */
|
|
272
|
+
async roadmapCheck(by: PeerId, include?: (finding: RoadmapDrift) => boolean): Promise<ReturnType<typeof checkRoadmap>> {
|
|
273
|
+
const check = this.host.requestCheck(by); check(); this.roadmapReadAuthority(by);
|
|
274
|
+
// #1741: one spec check per roadmap check. current() rebuilds the views before and after every issue read, and an uncached working-tree check is a
|
|
275
|
+
// synchronous git per spec path (about a second on this repository), so it ran up to 200 times per call. A thrown check is kept as unavailable.
|
|
276
|
+
let pinned: { report: SpecsCheckReport | SpecsCoverReport | undefined } | undefined;
|
|
277
|
+
const specs = () => { if (!pinned) { pinned = { report: undefined }; pinned.report = this.roadmapSpecsFor(by); } return pinned.report; };
|
|
278
|
+
const boardKey = () => this.roadmapBoardKey(by);
|
|
279
|
+
let checkedKey = boardKey(); // taken before the views, so a write between the two is compared, not skipped
|
|
280
|
+
const views = this.milestoneList(by, specs), config = this.d.roadmapConfig?.() ?? { github_mirror: false, github_write: "off" as const }, privacy = JSON.stringify([this.d.routing(), this.d.piiPaths, this.d.deny]);
|
|
281
|
+
const snapshot = (rows: typeof views) => JSON.stringify([rows, rows.flatMap(view => view.tasks.map(member => this.d.board.get(member.id)))]);
|
|
282
|
+
const evidence = snapshot(views);
|
|
283
|
+
// #1741: building the views runs issueOf over every board task (a regex scan of its text), about 140 ms on a 1156-task board, and current() runs before
|
|
284
|
+
// and after each issue read. Rebuild only when a task write (statusRevision), a milestone, link or release row, or the caller's planner role (it screens backlog tasks) says the views can differ; config and privacy are compared on every call below.
|
|
285
|
+
const sameViews = () => { const key = boardKey(); if (key === checkedKey) return true; if (snapshot(this.milestoneList(by, specs)) !== evidence) return false; checkedKey = key; return true; };
|
|
286
|
+
const current = () => { check(); this.roadmapReadAuthority(by); if (!sameViews() || JSON.stringify(this.d.roadmapConfig?.() ?? { github_mirror: false, github_write: "off" }) !== JSON.stringify(config) || JSON.stringify([this.d.routing(), this.d.piiPaths, this.d.deny]) !== privacy) throw new PreEffectToolRefusal("roadmap or privacy policy changed while checking; retry ahub roadmap check"); };
|
|
287
|
+
const issueStates = await roadmapIssueStates(this.roadmapIssueRefs(views), this.roadmapGh(), current);
|
|
288
|
+
const rendered = roadmapExport(views, issueStates), exportStates: (boolean | undefined)[] = [];
|
|
289
|
+
for (const [path, expected] of [["docs/roadmap.json", rendered.json], ["docs/roadmap.md", rendered.markdown]] as const) {
|
|
290
|
+
try {
|
|
291
|
+
const file = await readGuardedDeliverable(path, { cwd: this.d.cwd, deny: this.d.deny ?? [], private: name => matchesPolicy(this.d.cwd, name, this.d.piiPaths ?? [], true) });
|
|
292
|
+
current(); exportStates.push(Buffer.from(file.data).toString("utf8") === expected);
|
|
293
|
+
} catch (error) { if (error instanceof PreEffectToolRefusal) throw error; exportStates.push(error instanceof DeliverableRefusal && error.message.includes("does not exist") ? false : undefined); }
|
|
294
|
+
}
|
|
295
|
+
const exportMatches = exportStates.includes(false) ? false : exportStates.every(value => value === true) ? true : undefined;
|
|
296
|
+
current();
|
|
297
|
+
let mirror: Awaited<ReturnType<typeof readMirrorSnapshot>> | undefined, repo: string | undefined;
|
|
298
|
+
if (config.github_mirror) {
|
|
299
|
+
try { repo = this.roadmapRepository(); mirror = await readMirrorSnapshot(repo, this.roadmapGh()); }
|
|
300
|
+
catch { /* partial or unavailable evidence stays unknown */ }
|
|
301
|
+
current();
|
|
302
|
+
}
|
|
303
|
+
const milestones: DriftMilestone[] = views.map(view => {
|
|
304
|
+
const tasks = view.tasks.map(member => {
|
|
305
|
+
const task = this.d.board.get(member.id)!;
|
|
306
|
+
let issue: string | null | undefined;
|
|
307
|
+
try { const source = this.host.planIssueIdentity(task); issue = source ? `${source.repo.toLowerCase()}#${source.issue}` : null; } catch { issue = undefined; }
|
|
308
|
+
const issueState: "open" | "closed" | "unknown" = issue ? issueStates.get(issue) ?? "unknown" : "unknown";
|
|
309
|
+
const merge = task.sdlc?.merge?.state === "merged" ? task.sdlc.merge : task.sdlc?.mergeReadback;
|
|
310
|
+
const mergedAt = merge?.state === "merged" ? merge.cost?.mergedAt ?? undefined : task.sdlc?.pr && task.state === "approved" ? undefined : null;
|
|
311
|
+
const report = merge?.state === "merged" ? this.host.currentSpecReport(task) : undefined;
|
|
312
|
+
const unchangedSpecs = mergedAt === null ? [] : report?.complete && report.errors === 0 && !report.truncated && report.head === merge?.head
|
|
313
|
+
? report.unchanged.filter(row => !row.reason?.trim()).map(row => row.id) : undefined;
|
|
314
|
+
return { id: task.id, state: task.state, issue, issueState, feature: /^feat(?:\([^)]*\))?:/i.test(task.title), specIssue: !!task.sdlc?.issue, mergedAt, unchangedSpecs };
|
|
315
|
+
});
|
|
316
|
+
const children = view.children.map(id => views.find(row => row.id === id));
|
|
317
|
+
const open = view.tasks.some(row => !["approved", "cancelled"].includes(row.state)) || view.issues.some(row => issueStates.get(row.ref) === "open") || view.releases.some(row => !["shipped", "dropped", "unknown"].includes(row.state)) || children.some(row => row && !["done", "dropped"].includes(row.state));
|
|
318
|
+
const uncertain = !!view.withheld || view.issues.some(row => !issueStates.has(row.ref)) || view.releases.some(row => row.state === "unknown") || children.some(row => !row);
|
|
319
|
+
const merged = view.tasks.some(row => { const task = this.d.board.get(row.id); return task?.sdlc?.merge?.state === "merged" || task?.sdlc?.mergeReadback?.state === "merged"; });
|
|
320
|
+
let mirrorDiff: boolean | undefined;
|
|
321
|
+
if (mirror && repo && !view.withheld && view.title !== "[withheld]") {
|
|
322
|
+
try {
|
|
323
|
+
const marker = `<!-- ahub-roadmap:${this.d.project}:${view.id} -->`, bound = this.d.board.mirrorMilestone(repo, view.id);
|
|
324
|
+
const recovered = bound === undefined ? recoverMirrorBinding(marker, view.title, mirror.milestones) : undefined;
|
|
325
|
+
if (recovered?.kind === "ambiguous" || recovered?.titleConflicts.length) mirrorDiff = true;
|
|
326
|
+
else {
|
|
327
|
+
const number = bound ?? (recovered?.kind === "bind" ? recovered.number : undefined), remote = number === undefined ? null : mirror.milestones.find(row => row.number === number);
|
|
328
|
+
if (number === undefined || remote) mirrorDiff = bound === undefined || planRoadmapMirror(repo, { title: view.title, state: view.state === "done" || view.state === "dropped" ? "closed" : "open", marker, issues: view.issues.filter(row => row.ref.startsWith(`${repo}#`)).map(row => Number(row.ref.slice(repo!.length + 1))) }, remote ?? null, mirror.issues).calls.length > 0;
|
|
329
|
+
}
|
|
330
|
+
} catch { /* unknown mirror evidence */ }
|
|
331
|
+
}
|
|
332
|
+
return { id: view.id, state: view.state, tasks, openItems: open ? true : uncertain ? undefined : false, mergedCode: merged ? true : tasks.some(row => row.mergedAt === undefined) ? undefined : false, specs: view.specs, mirrorDiff };
|
|
333
|
+
});
|
|
334
|
+
current(); return checkRoadmap({ milestones, now: this.d.now?.() ?? Date.now(), closeLagMs: 24 * 60 * 60_000, mirrorEnabled: config.github_mirror, exportMatches }, include);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** #1741: what the milestone views are built from, apart from config, privacy and the spec report: equal keys build equal views. */
|
|
338
|
+
roadmapBoardKey(by: PeerId): string {
|
|
339
|
+
return JSON.stringify([this.d.board.statusRevision(), this.d.board.milestones(), this.d.board.milestoneLinks(), this.d.board.releases(), this.host.isConfiguredPlanner(by)]);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Serialize at the host caller. Persist only admitted ids-only notices, so unavailable feeds can retry. */
|
|
343
|
+
async roadmapNotify(taskIds: readonly number[], send: (task: number, milestone: number | null, rule: number, marker: string) => boolean): Promise<number> {
|
|
344
|
+
if (!taskIds.length) return 0;
|
|
345
|
+
const views = this.milestoneList(HUB);
|
|
346
|
+
if (!views.some(view => view.tasks.some(task => taskIds.includes(task.id)))) return 0;
|
|
347
|
+
const select = (finding: RoadmapDrift) => {
|
|
348
|
+
const referenced = finding.items.filter(item => /^task:[1-9][0-9]*$/.test(item)).map(item => Number(item.slice(5)));
|
|
349
|
+
const eligible = views.filter(view => finding.milestone === null || view.id === finding.milestone).flatMap(view => view.tasks.map(task => task.id));
|
|
350
|
+
const marker = createHash("sha256").update(JSON.stringify([finding.rule, finding.milestone, finding.items, finding.cause])).digest("hex");
|
|
351
|
+
return !this.d.board.hasRoadmapNotice(marker) && taskIds.some(id => eligible.includes(id) && (!referenced.length || referenced.includes(id)));
|
|
352
|
+
};
|
|
353
|
+
const checked = await this.roadmapCheck(HUB, select);
|
|
354
|
+
// #1741: each finding rechecks membership against the current views; rebuild them only when the board key moved (a build is ~140 ms on a 1156-task board, once per finding before).
|
|
355
|
+
let latestViews: ReturnType<Tasks["milestoneList"]> | undefined, latestKey: string | undefined;
|
|
356
|
+
const currentViews = () => { const key = this.roadmapBoardKey(HUB); if (key !== latestKey || !latestViews) { latestKey = key; latestViews = this.milestoneList(HUB); } return latestViews; };
|
|
357
|
+
let sent = 0;
|
|
358
|
+
for (const finding of checked.findings) {
|
|
359
|
+
const referenced = finding.items.filter(item => /^task:[1-9][0-9]*$/.test(item)).map(item => Number(item.slice(5)));
|
|
360
|
+
const eligible = views.filter(view => finding.milestone === null || view.id === finding.milestone).flatMap(view => view.tasks.map(task => task.id));
|
|
361
|
+
const task = taskIds.find(id => eligible.includes(id) && (!referenced.length || referenced.includes(id)));
|
|
362
|
+
if (task === undefined) continue;
|
|
363
|
+
const marker = createHash("sha256").update(JSON.stringify([finding.rule, finding.milestone, finding.items, finding.cause])).digest("hex");
|
|
364
|
+
if (this.d.board.hasRoadmapNotice(marker)) continue;
|
|
365
|
+
const latest = this.d.board.get(task);
|
|
366
|
+
if (!latest || this.host.isPii(latest) || !currentViews().some(view => (finding.milestone === null || view.id === finding.milestone) && view.tasks.some(row => row.id === task))) continue;
|
|
367
|
+
if (send(task, finding.milestone, finding.rule, marker) && this.d.board.recordRoadmapNotice(marker)) sent++;
|
|
368
|
+
}
|
|
369
|
+
return sent;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** #1647: the optional reason a task was split off. Absent stays legal; anything outside the closed set is refused before any effect, naming the allowed values. */
|
|
373
|
+
proposalReason(value: unknown): TaskReason | undefined {
|
|
374
|
+
if (value === undefined || value === null || value === "") return undefined;
|
|
375
|
+
if (typeof value !== "string" || !(TASK_REASONS as readonly string[]).includes(value)) throw new PreEffectToolRefusal(`reason must be one of ${TASK_REASONS.join(", ")}; omit it when no reason applies, then call hub_task_propose again`);
|
|
376
|
+
return value as TaskReason;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* #1647 AC2: siblings proposed for one plan, by one planner with the same dependencies and `reason: "parallel"`, must touch disjoint `refs.paths` (prefix overlap, `samePlace`).
|
|
381
|
+
* Refused before the new task exists, naming both tasks and the paths.
|
|
382
|
+
* ponytail: the board has no plan-revision id on a task, so "one plan" is the same proposer, the same `after` set, the same repository and an open state; ceiling: two unrelated
|
|
383
|
+
* parallel batches by one planner with equal dependencies read as siblings; upgrade: record the planning revision on the task and compare within it.
|
|
384
|
+
*/
|
|
385
|
+
parallelSiblingsDisjoint(by: PeerId, title: string, refs: TaskRefs, deps: number[]): void {
|
|
386
|
+
const mine = refs.paths ?? [];
|
|
387
|
+
if (!mine.length) return;
|
|
388
|
+
const scope = this.host.repositories.scope(refs), key = [...deps].sort((a, b) => a - b).join(",");
|
|
389
|
+
for (const other of this.d.board.list()) {
|
|
390
|
+
if (other.reason !== "parallel" || isClosedTaskState(other.state) || other.history[0]?.by !== by || this.host.isPii(other)) continue;
|
|
391
|
+
if ([...(other.deps ?? [])].sort((a, b) => a - b).join(",") !== key || this.host.repositories.scope(other.refs).key !== scope.key) continue;
|
|
392
|
+
const shared = mine.filter(path => (other.refs.paths ?? []).some(theirs => this.host.samePlace(path, theirs)));
|
|
393
|
+
if (shared.length) throw new PreEffectToolRefusal(`parallel siblings must touch disjoint paths: "${title}" and task #${other.id} both touch ${shared.slice(0, PARALLEL_PATHS_NAMED).join(", ")}; call hub_task_propose again with disjoint refs.paths, or without reason parallel, or keep the work as one task you own`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** Preview every fixed GitHub call from a complete inventory; confirmation binds both calls and local bindings. */
|
|
398
|
+
async roadmapSync(by: PeerId, input: { apply?: boolean; confirm?: string } = {}): Promise<{ repo: string; calls: string[][]; bindings: { milestone: number; number: number }[]; fingerprint: string; applied: boolean }> {
|
|
399
|
+
this.roadmapReadAuthority(by);
|
|
400
|
+
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some(key => key !== "apply" && key !== "confirm") || typeof input.apply !== "undefined" && typeof input.apply !== "boolean" || input.confirm !== undefined && (typeof input.confirm !== "string" || !/^[a-f0-9]{64}$/.test(input.confirm))) throw new PreEffectToolRefusal("invalid roadmap sync options; preview before applying");
|
|
401
|
+
if (input.apply) this.roadmapApplyAuthority(by);
|
|
402
|
+
const config = this.d.roadmapConfig?.() ?? { github_mirror: false, github_write: "off" as const };
|
|
403
|
+
if (!config.github_mirror) throw new PreEffectToolRefusal("roadmap GitHub mirror is off; enable roadmap.github_mirror in trusted configuration before syncing");
|
|
404
|
+
const repo = this.roadmapRepository(), views = this.milestoneList(by);
|
|
405
|
+
if (views.length > 100) throw new PreEffectToolRefusal("roadmap mirror exceeds 100 milestones; narrow the roadmap before syncing");
|
|
406
|
+
const deadline = performance.now() + 50_000;
|
|
407
|
+
const stamp = () => createHash("sha256").update(JSON.stringify([this.d.board.milestones(), this.d.board.milestoneLinks(), this.d.board.list(), views.map(view => [view.id, this.d.board.mirrorMilestone(repo, view.id)]), this.d.roadmapConfig?.(), this.d.routing(), this.d.piiPaths, this.d.deny])).digest("hex");
|
|
408
|
+
let before = stamp(); const check = this.host.requestCheck(by, () => this.d.sweepHeld?.() || this.d.bus.isRecoveryHeld || this.d.bus.storageError ? "roadmap is held by recovery or storage" : undefined);
|
|
409
|
+
const current = () => { check(); this.roadmapReadAuthority(by); if (input.apply) this.roadmapApplyAuthority(by); if (this.roadmapRepository() !== repo || stamp() !== before) throw new PreEffectToolRefusal("roadmap, origin or authority changed; preview sync again"); };
|
|
410
|
+
const run = this.roadmapGh();
|
|
411
|
+
const snapshot = await readMirrorSnapshot(repo, async (...args) => { current(); const result = await run(...args); current(); return result; });
|
|
412
|
+
current();
|
|
413
|
+
const bindings: { milestone: number; number: number }[] = [], calls: string[][] = [], createIds: (number | undefined)[] = [], issueOwners = new Set<number>();
|
|
414
|
+
for (const view of views) for (const issue of view.issues) if (issue.ref.startsWith(`${repo}#`)) {
|
|
415
|
+
const id = milestoneId(Number(issue.ref.slice(repo.length + 1)));
|
|
416
|
+
if (issueOwners.has(id)) throw new PreEffectToolRefusal("an issue is linked to multiple roadmap milestones; settle its placement before syncing");
|
|
417
|
+
issueOwners.add(id);
|
|
418
|
+
}
|
|
419
|
+
for (const view of views) {
|
|
420
|
+
if (view.withheld || view.title === "[withheld]" || view.outcome === "[withheld]") throw new PreEffectToolRefusal("roadmap mirror contains withheld membership or metadata; inspect privacy before syncing");
|
|
421
|
+
const marker = `<!-- ahub-roadmap:${this.d.project}:${view.id} -->`, bound = this.d.board.mirrorMilestone(repo, view.id);
|
|
422
|
+
const matching = bound === undefined ? recoverMirrorBinding(marker, view.title, snapshot.milestones) : undefined;
|
|
423
|
+
if (matching?.kind === "ambiguous" || matching?.titleConflicts.length) throw new PreEffectToolRefusal("roadmap GitHub milestone identity is ambiguous; inspect matching milestones before syncing");
|
|
424
|
+
const remoteId = bound ?? (matching?.kind === "bind" ? matching.number : undefined);
|
|
425
|
+
if (bound === undefined && remoteId !== undefined) bindings.push({ milestone: view.id, number: remoteId });
|
|
426
|
+
const remote = remoteId === undefined ? null : snapshot.milestones.find(row => row.number === remoteId);
|
|
427
|
+
if (remoteId !== undefined && !remote) throw new PreEffectToolRefusal("recorded GitHub milestone is missing from the complete inventory; inspect the binding");
|
|
428
|
+
const issues = view.issues.filter(row => row.ref.startsWith(`${repo}#`)).map(row => Number(row.ref.slice(repo.length + 1)));
|
|
429
|
+
const planned = planRoadmapMirror(repo, { title: view.title, state: view.state === "done" || view.state === "dropped" ? "closed" : "open", issues, marker }, remote ?? null, snapshot.issues);
|
|
430
|
+
for (const call of planned.calls) {
|
|
431
|
+
const detached = /^repos\/[^/]+\/[^/]+\/issues\/([1-9][0-9]*)$/.exec(call[1] ?? "");
|
|
432
|
+
if (detached && call.includes("milestone=null") && issueOwners.has(Number(detached[1]))) continue;
|
|
433
|
+
calls.push(call); createIds.push(remoteId === undefined ? view.id : undefined);
|
|
434
|
+
if (calls.length > 200) throw new PreEffectToolRefusal("roadmap mirror exceeds 200 writes; narrow the roadmap before syncing");
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const hiddenIssues = new Set<number>();
|
|
438
|
+
for (const task of this.d.board.list()) if (this.host.isPii(task) || task.signals.includes("pii") || task.signals.includes("pii_path")) {
|
|
439
|
+
try { const issue = this.host.planIssueIdentity(task); if (issue?.repo.toLowerCase() === repo) hiddenIssues.add(issue.issue); }
|
|
440
|
+
catch { throw new PreEffectToolRefusal("private issue placement is unknown; inspect privacy before syncing"); }
|
|
441
|
+
}
|
|
442
|
+
if (calls.some(call => { const match = /^repos\/[^/]+\/[^/]+\/issues\/([1-9][0-9]*)$/.exec(call[1] ?? ""); return !!match && hiddenIssues.has(Number(match[1])); })) throw new PreEffectToolRefusal("roadmap mirror would change private issue membership; inspect privacy before syncing");
|
|
443
|
+
const fingerprint = createHash("sha256").update(JSON.stringify({ repo, bindings, calls })).digest("hex");
|
|
444
|
+
if (!input.apply) return { repo, calls, bindings, fingerprint, applied: false };
|
|
445
|
+
if (input.confirm !== fingerprint) throw new PreEffectToolRefusal(`roadmap sync preview changed; run ahub roadmap sync and retry with --confirm ${fingerprint}`);
|
|
446
|
+
let effects = false;
|
|
447
|
+
const effectCurrent = () => { try { current(); } catch (error) { if (effects) throw new Error("roadmap sync authority changed after effects; inspect the mirror and preview again before retrying"); throw error; } };
|
|
448
|
+
effectCurrent();
|
|
449
|
+
for (const binding of bindings) {
|
|
450
|
+
effectCurrent();
|
|
451
|
+
try { this.d.board.bindMirrorMilestone(repo, binding.milestone, binding.number); effects = true; before = stamp(); }
|
|
452
|
+
catch (error) { if (effects) throw new Error("roadmap binding changed after effects; inspect the mirror and preview again"); throw error; }
|
|
453
|
+
}
|
|
454
|
+
for (let index = 0; index < calls.length; index++) {
|
|
455
|
+
effectCurrent();
|
|
456
|
+
let result: Awaited<ReturnType<SdlcGh>>;
|
|
457
|
+
const remaining = deadline - performance.now();
|
|
458
|
+
if (remaining <= 0) { if (effects) throw new Error("roadmap sync reached its deadline after effects; inspect the mirror and preview again"); throw new PreEffectToolRefusal("roadmap sync deadline expired before writes; preview again"); }
|
|
459
|
+
effects = true;
|
|
460
|
+
try { result = await run(calls[index]!, Math.min(10_000, remaining), undefined, 64 * 1024); }
|
|
461
|
+
catch { throw new Error("roadmap GitHub write outcome is unknown; inspect the mirror and preview again before retrying"); }
|
|
462
|
+
if (result.code !== 0 || Buffer.byteLength(result.stdout) > 64 * 1024) throw new Error("roadmap GitHub write was not confirmed; inspect the mirror and preview again before retrying");
|
|
463
|
+
const local = createIds[index];
|
|
464
|
+
if (local !== undefined) {
|
|
465
|
+
let number: number;
|
|
466
|
+
try {
|
|
467
|
+
const created = JSON.parse(result.stdout) as Record<string, unknown>, call = calls[index]!;
|
|
468
|
+
number = milestoneId(created.number);
|
|
469
|
+
if (created.title !== call.find(value => value.startsWith("title="))?.slice(6) || created.description !== call.find(value => value.startsWith("description="))?.slice(12) || created.state !== call.find(value => value.startsWith("state="))?.slice(6) || typeof created.html_url !== "string" || created.html_url.toLowerCase() !== `https://github.com/${repo}/milestone/${number}`) throw new Error("mismatch");
|
|
470
|
+
} catch { throw new Error("roadmap milestone creation was not confirmed; preview again to recover its marker"); }
|
|
471
|
+
effectCurrent();
|
|
472
|
+
try { this.d.board.bindMirrorMilestone(repo, local, number); before = stamp(); }
|
|
473
|
+
catch { throw new Error("roadmap milestone was created but its binding is uncertain; preview again to recover its marker"); }
|
|
474
|
+
}
|
|
475
|
+
effectCurrent();
|
|
476
|
+
}
|
|
477
|
+
return { repo, calls, bindings, fingerprint, applied: true };
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// ---- R3 (#1481): bottom-up placement. Reads are the roadmap read authority; every write below is the R1 writer, never a new one. ----
|
|
481
|
+
|
|
482
|
+
/** The one repository the roadmap reads from GitHub: the caller's choice, else the project's. Never derived from model text. */
|
|
483
|
+
roadmapRepo(raw: unknown): string | undefined {
|
|
484
|
+
if (raw === undefined) return undefined;
|
|
485
|
+
return this.roadmapParsed(() => githubRepo(raw));
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
roadmapGh(run?: SdlcGh): SdlcGh {
|
|
489
|
+
return run ?? this.d.roadmapGh ?? this.d.sdlc?.gh ?? ((args, timeout, _cwd, bound) => sdlcGh(args, timeout, this.d.cwd, bound));
|
|
490
|
+
}
|
|
491
|
+
}
|