dsh-tower 2.0.3 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -0
- package/COMPATIBILITY.md +38 -0
- package/CONTRIBUTING.md +150 -2
- package/README.en.md +59 -16
- package/README.md +57 -16
- package/SECURITY.md +31 -1
- package/adapters/default.js +10 -0
- package/adapters/store-fs.js +6 -0
- package/adapters/vcs-git.js +4 -0
- package/app/batch.js +79 -0
- package/app/board.js +25 -0
- package/app/checkCompletion.js +76 -0
- package/app/enrichedMissions.js +26 -0
- package/app/findings.js +78 -0
- package/app/gate.js +108 -0
- package/app/init.js +249 -0
- package/app/merge.js +567 -0
- package/app/messages.js +66 -0
- package/app/mission.js +35 -0
- package/app/missionContext.js +14 -0
- package/app/plan.js +42 -0
- package/app/provision.js +193 -0
- package/app/read.js +57 -0
- package/app/rebase.js +302 -0
- package/app/recording.js +72 -0
- package/app/review.js +145 -0
- package/app/roster.js +123 -0
- package/app/spawn.js +125 -0
- package/app/teardown.js +184 -0
- package/app/tower.js +524 -0
- package/cordis.patch.yml +61 -53
- package/docs/README.md +33 -1
- package/docs/architecture/overview.md +114 -14
- package/docs/board.md +72 -0
- package/docs/examples/first-mission.md +2 -1
- package/docs/faq.md +11 -7
- package/docs/guide/hot-reload.md +1 -1
- package/docs/guide/install-upgrade-migration.md +22 -6
- package/docs/guide/quickstart.md +12 -7
- package/docs/guide/release.md +125 -0
- package/docs/guide/scenarios-and-philosophy.md +86 -69
- package/docs/operations/security.md +65 -14
- package/docs/reference/blockers.md +11 -10
- package/docs/reference/config.generated.md +66 -0
- package/docs/reference/config.md +11 -7
- package/docs/reference/errors.generated.md +39 -0
- package/docs/reference/errors.md +10 -2
- package/docs/reference/events.md +7 -4
- package/docs/reference/testing.md +2 -1
- package/docs/reference/tools.generated.md +33 -0
- package/docs/reference/tools.md +8 -7
- package/docs/zh/README.md +4 -3
- package/docs/zh/faq.md +9 -6
- package/docs/zh/guide/hot-reload.md +1 -1
- package/docs/zh/guide/install-upgrade-migration.md +17 -5
- package/docs/zh/guide/quickstart.md +13 -8
- package/docs/zh/guide/scenarios-and-philosophy.md +55 -50
- package/docs/zh/operations/security.md +43 -7
- package/docs/zh/reference/blockers.md +10 -10
- package/docs/zh/reference/config.md +11 -7
- package/docs/zh/reference/errors.md +4 -1
- package/docs/zh/reference/events.md +6 -3
- package/docs/zh/reference/testing.md +3 -2
- package/docs/zh/reference/tools.md +8 -7
- package/domain/collab/batch.js +112 -0
- package/domain/collab/messages.js +127 -0
- package/domain/collab/roster.js +158 -0
- package/domain/collab/spawn.js +188 -0
- package/domain/config/schema.js +404 -0
- package/domain/contracts/outputs.js +279 -0
- package/domain/contracts/tool-inputs/collaboration.js +58 -0
- package/domain/contracts/tool-inputs/findings.js +29 -0
- package/domain/contracts/tool-inputs/index.js +94 -0
- package/domain/contracts/tool-inputs/integration.js +37 -0
- package/domain/contracts/tool-inputs/missions.js +94 -0
- package/domain/contracts/tool-inputs/ops.js +75 -0
- package/domain/contracts/tool-inputs/shared.js +25 -0
- package/domain/errors.js +96 -0
- package/domain/gate.js +125 -0
- package/domain/integration/gate.js +176 -0
- package/domain/integration/init.js +225 -0
- package/domain/integration/liveness.js +31 -0
- package/domain/integration/merge.js +377 -0
- package/domain/integration/provision.js +124 -0
- package/domain/integration/rebase.js +236 -0
- package/domain/integration/review.js +52 -0
- package/domain/integration/teardown.js +118 -0
- package/domain/mission.js +68 -0
- package/domain/missions/completion.js +114 -0
- package/domain/missions/findings.js +201 -0
- package/domain/missions/lifecycle.js +185 -0
- package/domain/missions/plan.js +149 -0
- package/domain/missions/review.js +179 -0
- package/domain/planning.js +118 -0
- package/domain/read/enrichedMissions.js +58 -0
- package/domain/read/missionContext.js +53 -0
- package/domain/read/views.js +128 -0
- package/domain/report.js +59 -0
- package/domain/roster.js +40 -0
- package/domain/scope.js +105 -0
- package/domain/state/schema.js +233 -0
- package/domain/state/semantics.js +117 -0
- package/domain/state.js +33 -0
- package/domain/summary.js +114 -0
- package/domain/vocabulary.js +179 -0
- package/index.js +86 -34
- package/lib/briefing.js +176 -0
- package/lib/compatibility.js +108 -0
- package/lib/config.js +54 -302
- package/lib/doctor.js +108 -9
- package/lib/git.js +93 -15
- package/lib/hmr.js +4 -3
- package/lib/leases.js +3 -2
- package/lib/legacy.js +20 -9
- package/lib/modeState.js +39 -0
- package/lib/modeStore.js +35 -33
- package/lib/persistence.js +349 -0
- package/lib/presets.js +35 -0
- package/lib/spawn-prechecks.js +168 -0
- package/lib/spawn-support.js +79 -0
- package/lib/store.js +57 -85
- package/lib/tests.js +46 -11
- package/lib/tool-registry.js +544 -0
- package/lib/workspaceLock.js +46 -22
- package/lib/worktreeOwnership.js +5 -4
- package/locale/en.json +23 -1
- package/locale/zh.json +22 -0
- package/package.json +33 -4
- package/ports/clock.js +6 -0
- package/ports/ids.js +7 -0
- package/ports/index.js +2 -0
- package/ports/store.js +11 -0
- package/ports/vcs.js +11 -0
- package/scripts/architecture.mjs +94 -0
- package/scripts/check-docs.mjs +44 -3
- package/scripts/check-pack.mjs +49 -0
- package/scripts/domain-metrics.mjs +48 -0
- package/scripts/generate-config-reference.mjs +46 -0
- package/scripts/generate-error-reference.mjs +29 -0
- package/scripts/generate-tools-reference.mjs +56 -0
- package/scripts/issue-audit.mjs +259 -0
- package/scripts/lib/cli.mjs +76 -0
- package/scripts/lib/tmp.mjs +20 -0
- package/scripts/mount-smoke/fixtures.mjs +162 -0
- package/scripts/mount-smoke/host.json +4 -0
- package/scripts/mount-smoke/probe.mjs +125 -0
- package/scripts/mount-smoke/surface.mjs +141 -0
- package/scripts/mount-smoke.mjs +270 -0
- package/scripts/pack-manifest.txt +203 -0
- package/scripts/release-check.mjs +303 -0
- package/skills/tower-recovery.md +7 -5
- package/tools/adopt.js +72 -0
- package/tools/batch.js +78 -0
- package/tools/complete.js +53 -0
- package/tools/diff.js +39 -0
- package/tools/doctor.js +50 -0
- package/tools/finding.js +40 -0
- package/tools/findings.js +39 -0
- package/tools/import-legacy.js +42 -0
- package/tools/inbox.js +39 -0
- package/tools/index.js +39 -0
- package/tools/init.js +63 -0
- package/tools/interrupt.js +42 -0
- package/tools/legacy-map.js +44 -0
- package/tools/merge.js +39 -0
- package/tools/mission.js +41 -0
- package/tools/plan.js +39 -0
- package/tools/preflight.js +44 -0
- package/tools/rebase.js +39 -0
- package/tools/recover.js +45 -0
- package/tools/reload.js +52 -0
- package/tools/resource.js +54 -0
- package/tools/review.js +45 -0
- package/tools/roster.js +60 -0
- package/tools/send.js +147 -0
- package/tools/spawn.js +196 -0
- package/tools/status.js +94 -0
- package/tools/teardown.js +42 -0
- package/tools/test.js +61 -0
- package/types/cordis.d.ts +6 -0
- package/types/index.d.ts +339 -0
- package/ui-bundle/README.md +111 -0
- package/ui-bundle/client.js +1980 -0
- package/ui-bundle/cordis.patch.yml +3 -0
- package/ui-bundle/icon.svg +6 -0
- package/ui-bundle/index.js +2 -0
- package/ui-bundle/locale/en.json +6 -0
- package/ui-bundle/locale/zh.json +6 -0
- package/ui-bundle/package.json +35 -0
- package/lib/errors.js +0 -111
- package/lib/tools.js +0 -2250
- package/lib/tower.js +0 -2689
- /package/{lib → domain}/batch.js +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// tower_spawn / tower_roster / tower_interrupt / tower_send / tower_inbox /
|
|
2
|
+
// tower_adopt input contracts. Pure TypeBox only; no I/O.
|
|
3
|
+
import { ROLES } from '../../vocabulary.js'
|
|
4
|
+
import { Type, enumOf } from './shared.js'
|
|
5
|
+
|
|
6
|
+
export const SpawnInput = Type.Object({
|
|
7
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
8
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
9
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
10
|
+
role: Type.Optional(enumOf(ROLES, { description: 'worker executes; reviewer audits the mission branch.' })),
|
|
11
|
+
name: Type.Optional(Type.String({ description: 'Unique roster name; defaults to <role>-<missionId>.' })),
|
|
12
|
+
instructions: Type.Optional(Type.String({ description: 'Extra tower instructions appended to the briefing.' })),
|
|
13
|
+
worktreeRoot: Type.Optional(Type.String({ description: 'Optional absolute parent directory for the worktree.' })),
|
|
14
|
+
wait: Type.Optional(Type.Boolean({ description: 'Wait for the child result instead of returning immediately (testing/debug).' })),
|
|
15
|
+
waitMs: Type.Optional(Type.Number({ description: 'Max wait with wait=true, default 180000; clamped to spawn.maxWaitMs (default 90000).' })),
|
|
16
|
+
wait_ms: Type.Optional(Type.Number({ description: 'Alias for waitMs.' })),
|
|
17
|
+
takeover: Type.Optional(Type.Boolean({ description: 'Replace a live worker entry that is no longer running (increments ownerGeneration).' })),
|
|
18
|
+
includeDirtyBase: Type.Optional(Type.Boolean({ description: 'Use the recorded snapshotCommit baseline when true (default true).' })),
|
|
19
|
+
}, { additionalProperties: false })
|
|
20
|
+
|
|
21
|
+
export const RosterInput = Type.Object({
|
|
22
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
23
|
+
}, { additionalProperties: false })
|
|
24
|
+
|
|
25
|
+
export const InterruptInput = Type.Object({
|
|
26
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
27
|
+
to: Type.Optional(Type.String({ description: 'Roster name to interrupt.' })),
|
|
28
|
+
agentId: Type.Optional(Type.String({ description: 'Agent/session id to interrupt (alternative to to).' })),
|
|
29
|
+
agent_id: Type.Optional(Type.String({ description: 'Alias for agentId.' })),
|
|
30
|
+
reason: Type.Optional(Type.String({ description: 'Why the agent is being interrupted (recorded in the roster).' })),
|
|
31
|
+
}, { additionalProperties: false })
|
|
32
|
+
|
|
33
|
+
export const SendInput = Type.Object({
|
|
34
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
35
|
+
to: Type.String({ description: 'Recipient: a roster agent name, "tower", or "all".' }),
|
|
36
|
+
subject: Type.String({ description: 'One-line subject.' }),
|
|
37
|
+
body: Type.String({ description: 'Full message body (markdown).' }),
|
|
38
|
+
scope: Type.Optional(Type.String({ description: 'Optional scope tag, e.g. the mission id.' })),
|
|
39
|
+
interrupt: Type.Optional(
|
|
40
|
+
Type.Boolean({
|
|
41
|
+
description: 'Interrupt the recipient\'s current turn before delivering (Kimi-style "message interrupts the running turn"); default false = queue at the next step boundary.',
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
consentRef: Type.Optional(Type.String({ description: 'Optional audit reference recording who consented to this instruction.' })),
|
|
45
|
+
consent_ref: Type.Optional(Type.String({ description: 'Alias for consentRef.' })),
|
|
46
|
+
}, { additionalProperties: false })
|
|
47
|
+
|
|
48
|
+
export const InboxInput = Type.Object({
|
|
49
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
50
|
+
limit: Type.Optional(Type.Number({ description: 'Max messages to return (default 20), newest first.' })),
|
|
51
|
+
include_read: Type.Optional(Type.Boolean({ description: 'Include previously acknowledged messages for history lookup.' })),
|
|
52
|
+
includeRead: Type.Optional(Type.Boolean({ description: 'Alias for include_read.' })),
|
|
53
|
+
}, { additionalProperties: false })
|
|
54
|
+
|
|
55
|
+
export const AdoptInput = Type.Object({
|
|
56
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
57
|
+
retireMissing: Type.Optional(Type.Boolean({ description: 'Retire provably gone agents (default true); false marks them missing instead.' })),
|
|
58
|
+
}, { additionalProperties: false })
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// tower_finding / tower_findings input contracts. Pure TypeBox only; no I/O.
|
|
2
|
+
import { FINDING_FILTER_STATUSES, FINDING_SEVERITIES, FINDING_TYPES } from '../../vocabulary.js'
|
|
3
|
+
import { Type, enumOf } from './shared.js'
|
|
4
|
+
|
|
5
|
+
export const FindingInput = Type.Object({
|
|
6
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
7
|
+
type: enumOf(FINDING_TYPES, { description: 'Finding category.' }),
|
|
8
|
+
title: Type.String({ description: 'Short finding title.' }),
|
|
9
|
+
severity: Type.Optional(enumOf(FINDING_SEVERITIES, { description: 'Optional severity.' })),
|
|
10
|
+
summary: Type.String({ description: 'What was found, in a sentence or two.' }),
|
|
11
|
+
location: Type.Optional(Type.String({ description: 'File/symbol the finding concerns.' })),
|
|
12
|
+
details: Type.String({ description: 'Full details: evidence, reproduction, impact.' }),
|
|
13
|
+
suggested_fix: Type.String({ description: 'What you would do about it.' }),
|
|
14
|
+
missionId: Type.Optional(Type.String({ description: 'Optional mission this finding relates to (alias: mission_id).' })),
|
|
15
|
+
mission_id: Type.Optional(Type.String({ description: 'Alias for missionId.' })),
|
|
16
|
+
}, { additionalProperties: false })
|
|
17
|
+
|
|
18
|
+
export const FindingsInput = Type.Object({
|
|
19
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
20
|
+
id: Type.Optional(Type.String({ description: 'Finding id, e.g. F1. When present the call reads or updates that finding.' })),
|
|
21
|
+
status: Type.Optional(enumOf(FINDING_FILTER_STATUSES, { description: 'With id: target status. Without id: filter (default all).' })),
|
|
22
|
+
note: Type.Optional(Type.String({ description: 'Optional note recorded together with an update.' })),
|
|
23
|
+
type: Type.Optional(enumOf(FINDING_TYPES, { description: 'Filter by finding type.' })),
|
|
24
|
+
severity: Type.Optional(enumOf(FINDING_SEVERITIES, { description: 'Filter by severity.' })),
|
|
25
|
+
missionId: Type.Optional(Type.String({ description: 'Filter by mission id (alias: mission_id).' })),
|
|
26
|
+
mission_id: Type.Optional(Type.String({ description: 'Alias for missionId.' })),
|
|
27
|
+
open: Type.Optional(Type.Boolean({ description: 'Only findings that are not fixed or wontfix.' })),
|
|
28
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 200, description: 'Max findings to list (default 50).' })),
|
|
29
|
+
}, { additionalProperties: false })
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Tool input contracts (#56 P3c): named schemas grouped by area plus a
|
|
2
|
+
// `ToolInputs` map keyed by registered tool name. Pure data; no I/O.
|
|
3
|
+
import {
|
|
4
|
+
CompleteInput,
|
|
5
|
+
MissionInput,
|
|
6
|
+
PlanInput,
|
|
7
|
+
PreflightInput,
|
|
8
|
+
ReviewInput,
|
|
9
|
+
StatusInput,
|
|
10
|
+
} from './missions.js'
|
|
11
|
+
import {
|
|
12
|
+
AdoptInput,
|
|
13
|
+
InboxInput,
|
|
14
|
+
InterruptInput,
|
|
15
|
+
RosterInput,
|
|
16
|
+
SendInput,
|
|
17
|
+
SpawnInput,
|
|
18
|
+
} from './collaboration.js'
|
|
19
|
+
import { DiffInput, MergeInput, RebaseInput, TeardownInput } from './integration.js'
|
|
20
|
+
import { FindingInput, FindingsInput } from './findings.js'
|
|
21
|
+
import {
|
|
22
|
+
BatchInput,
|
|
23
|
+
DoctorInput,
|
|
24
|
+
ImportLegacyInput,
|
|
25
|
+
InitInput,
|
|
26
|
+
LegacyMapInput,
|
|
27
|
+
RecoverInput,
|
|
28
|
+
ReloadInput,
|
|
29
|
+
ResourceInput,
|
|
30
|
+
TestInput,
|
|
31
|
+
} from './ops.js'
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
CompleteInput,
|
|
35
|
+
MissionInput,
|
|
36
|
+
PlanInput,
|
|
37
|
+
PreflightInput,
|
|
38
|
+
ReviewInput,
|
|
39
|
+
StatusInput,
|
|
40
|
+
AdoptInput,
|
|
41
|
+
InboxInput,
|
|
42
|
+
InterruptInput,
|
|
43
|
+
RosterInput,
|
|
44
|
+
SendInput,
|
|
45
|
+
SpawnInput,
|
|
46
|
+
DiffInput,
|
|
47
|
+
MergeInput,
|
|
48
|
+
RebaseInput,
|
|
49
|
+
TeardownInput,
|
|
50
|
+
FindingInput,
|
|
51
|
+
FindingsInput,
|
|
52
|
+
BatchInput,
|
|
53
|
+
DoctorInput,
|
|
54
|
+
ImportLegacyInput,
|
|
55
|
+
InitInput,
|
|
56
|
+
LegacyMapInput,
|
|
57
|
+
RecoverInput,
|
|
58
|
+
ReloadInput,
|
|
59
|
+
ResourceInput,
|
|
60
|
+
TestInput,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @type {Record<string, import('@sinclair/typebox').TSchema>} */
|
|
64
|
+
const ToolInputs = {
|
|
65
|
+
tower_init: InitInput,
|
|
66
|
+
tower_plan: PlanInput,
|
|
67
|
+
tower_mission: MissionInput,
|
|
68
|
+
tower_status: StatusInput,
|
|
69
|
+
tower_spawn: SpawnInput,
|
|
70
|
+
tower_roster: RosterInput,
|
|
71
|
+
tower_interrupt: InterruptInput,
|
|
72
|
+
tower_adopt: AdoptInput,
|
|
73
|
+
tower_send: SendInput,
|
|
74
|
+
tower_inbox: InboxInput,
|
|
75
|
+
tower_complete: CompleteInput,
|
|
76
|
+
tower_finding: FindingInput,
|
|
77
|
+
tower_findings: FindingsInput,
|
|
78
|
+
tower_diff: DiffInput,
|
|
79
|
+
tower_review: ReviewInput,
|
|
80
|
+
tower_preflight: PreflightInput,
|
|
81
|
+
tower_merge: MergeInput,
|
|
82
|
+
tower_rebase: RebaseInput,
|
|
83
|
+
tower_teardown: TeardownInput,
|
|
84
|
+
tower_doctor: DoctorInput,
|
|
85
|
+
tower_recover: RecoverInput,
|
|
86
|
+
tower_test: TestInput,
|
|
87
|
+
tower_batch: BatchInput,
|
|
88
|
+
tower_resource: ResourceInput,
|
|
89
|
+
tower_import_legacy: ImportLegacyInput,
|
|
90
|
+
tower_legacy_map: LegacyMapInput,
|
|
91
|
+
tower_reload: ReloadInput,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { ToolInputs }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// tower_merge / tower_rebase / tower_teardown / tower_diff input contracts.
|
|
2
|
+
// Pure TypeBox only; no I/O.
|
|
3
|
+
import { Type } from './shared.js'
|
|
4
|
+
|
|
5
|
+
export const MergeInput = Type.Object({
|
|
6
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
7
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
8
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
9
|
+
timeoutMs: Type.Optional(
|
|
10
|
+
Type.Integer({
|
|
11
|
+
minimum: 1000,
|
|
12
|
+
description: 'Optional timeout for the merge command in milliseconds, including pre-merge hooks (default 15 minutes).',
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
timeout_ms: Type.Optional(Type.Integer({ minimum: 1000, description: 'Alias for timeoutMs.' })),
|
|
16
|
+
}, { additionalProperties: false })
|
|
17
|
+
|
|
18
|
+
export const RebaseInput = Type.Object({
|
|
19
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
20
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
21
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
22
|
+
}, { additionalProperties: false })
|
|
23
|
+
|
|
24
|
+
export const TeardownInput = Type.Object({
|
|
25
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
26
|
+
force: Type.Optional(Type.Boolean({ description: 'Remove worktrees that contain uncommitted changes (never a live agent).' })),
|
|
27
|
+
exclude: Type.Optional(Type.Array(Type.String(), { description: 'Mission ids to keep.' })),
|
|
28
|
+
dry_run: Type.Optional(Type.Boolean({ description: 'Preview remove/keep decisions without changing disk or state.' })),
|
|
29
|
+
dryRun: Type.Optional(Type.Boolean({ description: 'Alias for dry_run.' })),
|
|
30
|
+
}, { additionalProperties: false })
|
|
31
|
+
|
|
32
|
+
export const DiffInput = Type.Object({
|
|
33
|
+
repoRoot: Type.String({ description: 'Absolute path to the main checkout root.' }),
|
|
34
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
35
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
36
|
+
maxBytes: Type.Optional(Type.Integer({ minimum: 1024, description: 'Patch cap in bytes (default 65536).' })),
|
|
37
|
+
}, { additionalProperties: false })
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// tower_plan / tower_mission / tower_status / tower_complete / tower_review /
|
|
2
|
+
// tower_preflight input contracts. Pure TypeBox only; no I/O.
|
|
3
|
+
import {
|
|
4
|
+
MERGE_VERDICTS,
|
|
5
|
+
MISSION_KINDS,
|
|
6
|
+
MISSION_STATUSES,
|
|
7
|
+
PAUSE_CAUSES,
|
|
8
|
+
REVIEW_POLICIES,
|
|
9
|
+
STATUS_FORMATS,
|
|
10
|
+
} from '../../vocabulary.js'
|
|
11
|
+
import { Type, enumOf } from './shared.js'
|
|
12
|
+
|
|
13
|
+
export const PlanInput = Type.Object({
|
|
14
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
15
|
+
missions: Type.Array(
|
|
16
|
+
Type.Object({
|
|
17
|
+
title: Type.String({ description: 'Printable ASCII title; used as the mission label.' }),
|
|
18
|
+
scope: Type.Optional(Type.Array(Type.String(), { description: 'Relative file globs this mission may touch; empty only for survey.' })),
|
|
19
|
+
tasks: Type.Optional(Type.Array(Type.String(), { description: 'Verifiable task items the worker ticks off.' })),
|
|
20
|
+
deps: Type.Optional(Type.Array(Type.String(), { description: 'Mission ids that must merge before this one.' })),
|
|
21
|
+
kind: Type.Optional(enumOf(MISSION_KINDS, { description: 'survey = read-only investigation that reserves no scope.' })),
|
|
22
|
+
context: Type.Optional(Type.String({ description: "The user's own key sentences, verbatim (max 4096 chars)." })),
|
|
23
|
+
references: Type.Optional(Type.Array(Type.String(), { maxItems: 20, description: 'Read-only pointers/files the worker should read (max 20); copied into the briefing.' })),
|
|
24
|
+
reviewPolicy: Type.Optional(enumOf(REVIEW_POLICIES, { description: 'required-clean (mission default) means a clean review is required when review.requireReview is on; none needs reviewExemptionReason, and with the review gate on it also needs gates.allowReviewExemption.' })),
|
|
25
|
+
reviewExemptionReason: Type.Optional(Type.String({ description: 'Non-empty justification when reviewPolicy is "none".' })),
|
|
26
|
+
}, { additionalProperties: false }),
|
|
27
|
+
{ description: 'Missions to create, in intended order.' },
|
|
28
|
+
),
|
|
29
|
+
}, { additionalProperties: false })
|
|
30
|
+
|
|
31
|
+
export const MissionInput = Type.Object({
|
|
32
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
33
|
+
id: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: missionId).' })),
|
|
34
|
+
missionId: Type.Optional(Type.String({ description: 'Alias for id; both are accepted.' })),
|
|
35
|
+
status: Type.Optional(enumOf(MISSION_STATUSES, { description: 'New lifecycle status.' })),
|
|
36
|
+
note: Type.Optional(Type.String({ description: 'Append a decision-log note.' })),
|
|
37
|
+
blocker: Type.Optional(Type.String({ description: 'Report a blocker (also sets status to blocked).' })),
|
|
38
|
+
clear_blockers: Type.Optional(Type.Boolean({ description: 'Clear all recorded blockers.' })),
|
|
39
|
+
clearBlockers: Type.Optional(Type.Boolean({ description: 'Alias for clear_blockers.' })),
|
|
40
|
+
task_done: Type.Optional(Type.String({ description: 'Mark the first open task containing this text as done.' })),
|
|
41
|
+
taskDone: Type.Optional(Type.String({ description: 'Alias for task_done.' })),
|
|
42
|
+
task_drop: Type.Optional(Type.String({ description: 'Mark the first open task containing this text as dropped.' })),
|
|
43
|
+
taskDrop: Type.Optional(Type.String({ description: 'Alias for task_drop.' })),
|
|
44
|
+
task_drop_reason: Type.Optional(Type.String({ description: 'Required with task_drop: why the task is legitimately descoped.' })),
|
|
45
|
+
taskDropReason: Type.Optional(Type.String({ description: 'Alias for task_drop_reason.' })),
|
|
46
|
+
scope: Type.Optional(Type.Array(Type.String(), { description: 'Tower only: replacement scope globs; bumps scopeGeneration.' })),
|
|
47
|
+
pause_cause: Type.Optional(enumOf(PAUSE_CAUSES, { description: 'With status=paused: why the mission was paused (default user).' })),
|
|
48
|
+
authorization: Type.Optional(Type.String({ description: 'Authorization reference recorded when resuming a user-paused mission.' })),
|
|
49
|
+
}, { additionalProperties: false })
|
|
50
|
+
|
|
51
|
+
export const StatusInput = Type.Object({
|
|
52
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
53
|
+
missionId: Type.Optional(Type.String({ description: 'Return full detail for one mission instead of the dashboard list.' })),
|
|
54
|
+
offset: Type.Optional(Type.Integer({ minimum: 0, description: 'Mission list offset (default 0).' })),
|
|
55
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100, description: 'Mission list page size (default 20).' })),
|
|
56
|
+
includeGate: Type.Optional(Type.Boolean({ description: 'Compute tower_preflight-style gate digests for missions on this page.' })),
|
|
57
|
+
format: Type.Optional(enumOf(STATUS_FORMATS, { description: 'markdown returns the MISSIONS.md board text.' })),
|
|
58
|
+
}, { additionalProperties: false })
|
|
59
|
+
|
|
60
|
+
export const CompleteInput = Type.Object({
|
|
61
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
62
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
63
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
64
|
+
report: Type.String({ description: 'Full completion report for the tower and the next review round.' }),
|
|
65
|
+
checks: Type.Optional(
|
|
66
|
+
Type.Array(
|
|
67
|
+
Type.Object({
|
|
68
|
+
name: Type.String({ description: 'What was checked.' }),
|
|
69
|
+
command: Type.Optional(Type.String({ description: 'Command or method used.' })),
|
|
70
|
+
exitCode: Type.Optional(Type.Integer({ description: 'Observed exit code.' })),
|
|
71
|
+
evidence: Type.Optional(Type.String({ description: 'Short evidence line/log reference.' })),
|
|
72
|
+
}, { additionalProperties: false }),
|
|
73
|
+
{ description: 'Optional evidence ledger entries: {name, command?, exitCode?, evidence?}.' },
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
}, { additionalProperties: false })
|
|
77
|
+
|
|
78
|
+
export const ReviewInput = Type.Object({
|
|
79
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
80
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
81
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
82
|
+
status: Type.String({ description: 'Verdict: "clean", or "p1-Nitems" / "p2-Nitems" with the number of findings at that priority.' }),
|
|
83
|
+
merge: enumOf(MERGE_VERDICTS, { description: 'Merge recommendation for the tower.' }),
|
|
84
|
+
findings: Type.String({ description: 'Full findings text (markdown); write "none" when clean.' }),
|
|
85
|
+
checks: Type.Optional(Type.Array(Type.String(), { description: 'Checklist items you verified.' })),
|
|
86
|
+
decision: Type.String({ description: 'The reasoning behind your verdict.' }),
|
|
87
|
+
breakGlassReason: Type.Optional(Type.String({ description: 'Tower-only exceptional self-review: why no independent reviewer was used.' })),
|
|
88
|
+
}, { additionalProperties: false })
|
|
89
|
+
|
|
90
|
+
export const PreflightInput = Type.Object({
|
|
91
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
92
|
+
missionId: Type.Optional(Type.String({ description: 'Mission id, e.g. M1 (canonical; alias: id).' })),
|
|
93
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId; both are accepted.' })),
|
|
94
|
+
}, { additionalProperties: false })
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// tower_init / tower_doctor / tower_recover / tower_test / tower_batch /
|
|
2
|
+
// tower_resource / tower_import_legacy / tower_legacy_map / tower_reload input
|
|
3
|
+
// contracts. Pure TypeBox only; no I/O.
|
|
4
|
+
import {
|
|
5
|
+
BATCH_ACTIONS,
|
|
6
|
+
LEASE_ACTIONS,
|
|
7
|
+
LEGACY_MAP_ACTIONS,
|
|
8
|
+
RECOVERY_ACTIONS,
|
|
9
|
+
} from '../../vocabulary.js'
|
|
10
|
+
import { Type, enumOf, untypedObject } from './shared.js'
|
|
11
|
+
|
|
12
|
+
export const InitInput = Type.Object({
|
|
13
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
14
|
+
base: Type.Optional(Type.String({ description: 'Optional local base branch (defaults to the checked-out branch).' })),
|
|
15
|
+
autoGitInit: Type.Optional(Type.Boolean({ description: 'Run git init (and an empty initial commit) when repoRoot is not a repository yet.' })),
|
|
16
|
+
snapshotDirty: Type.Optional(Type.Boolean({ description: 'Snapshot uncommitted tracked changes into a dangling commit used as the mission baseline (untracked files are not included).' })),
|
|
17
|
+
reanchor: Type.Optional(Type.Boolean({ description: 'Update the recorded base when no mission is active.' })),
|
|
18
|
+
}, { additionalProperties: false })
|
|
19
|
+
|
|
20
|
+
export const DoctorInput = Type.Object({
|
|
21
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
22
|
+
}, { additionalProperties: false })
|
|
23
|
+
|
|
24
|
+
export const RecoverInput = Type.Object({
|
|
25
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
26
|
+
action: enumOf(RECOVERY_ACTIONS, { description: 'Recovery action.' }),
|
|
27
|
+
confirm: Type.Optional(Type.String({ description: 'Required literal CLEAR_STALE_LOCK for clear-stale-lock.' })),
|
|
28
|
+
}, { additionalProperties: false })
|
|
29
|
+
|
|
30
|
+
export const TestInput = Type.Object({
|
|
31
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
32
|
+
missionId: Type.String({ description: 'Mission id, e.g. M1 (alias: id).' }),
|
|
33
|
+
id: Type.Optional(Type.String({ description: 'Alias for missionId.' })),
|
|
34
|
+
}, { additionalProperties: false })
|
|
35
|
+
|
|
36
|
+
export const BatchInput = Type.Object({
|
|
37
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
38
|
+
action: enumOf(BATCH_ACTIONS, { description: 'Batch operation.' }),
|
|
39
|
+
missionIds: Type.Optional(Type.Array(Type.String(), { description: 'Exact mission ids in this batch (create).' })),
|
|
40
|
+
exclusions: Type.Optional(Type.Array(Type.String(), { description: 'Paused legacy mission ids excluded from the batch.' })),
|
|
41
|
+
requiredChecks: Type.Optional(Type.Array(Type.String(), { description: 'Check names every build member must record (default ["check"]).' })),
|
|
42
|
+
receiptPaths: Type.Optional(Type.Array(Type.String(), { description: 'Exact relative receipt files checked at close.' })),
|
|
43
|
+
batchId: Type.Optional(Type.String({ description: 'Batch id (status/close/abandon).' })),
|
|
44
|
+
reason: Type.Optional(Type.String({ description: 'Reason recorded when abandoning a batch.' })),
|
|
45
|
+
checks: Type.Optional(Type.Array(untypedObject(), { description: 'Close-time extra check evidence.' })),
|
|
46
|
+
treeTip: Type.Optional(Type.String({ description: 'Expected reviewed/tested commit for close evidence.' })),
|
|
47
|
+
receiptHashes: Type.Optional(untypedObject('Relative receipt path -> sha256 observed by the caller.')),
|
|
48
|
+
}, { additionalProperties: false })
|
|
49
|
+
|
|
50
|
+
export const ResourceInput = Type.Object({
|
|
51
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
52
|
+
action: enumOf(LEASE_ACTIONS, { description: 'Lease operation.' }),
|
|
53
|
+
name: Type.Optional(Type.String({ description: 'Lease name, e.g. plugin-load or heavy-ci.' })),
|
|
54
|
+
holder: Type.Optional(Type.String({ description: 'Holder label (defaults to the caller).' })),
|
|
55
|
+
token: Type.Optional(Type.String({ description: 'Release token; generated on acquire when omitted.' })),
|
|
56
|
+
ttlMs: Type.Optional(Type.Integer({ minimum: 1000, description: 'Lease lifetime (default leases.ttlMs).' })),
|
|
57
|
+
force: Type.Optional(Type.Boolean({ description: 'Explicitly release an expired lease (token still required).' })),
|
|
58
|
+
}, { additionalProperties: false })
|
|
59
|
+
|
|
60
|
+
export const ImportLegacyInput = Type.Object({
|
|
61
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
62
|
+
sourcePath: Type.String({ description: 'Absolute path to the legacy JSON state file.' }),
|
|
63
|
+
}, { additionalProperties: false })
|
|
64
|
+
|
|
65
|
+
export const LegacyMapInput = Type.Object({
|
|
66
|
+
repoRoot: Type.String({ description: 'Absolute path inside the target Git repository.' }),
|
|
67
|
+
action: enumOf(LEGACY_MAP_ACTIONS, { description: 'Mapping operation.' }),
|
|
68
|
+
sourceHash: Type.Optional(Type.String({ description: 'Legacy snapshot sha256 (map).' })),
|
|
69
|
+
oldId: Type.Optional(Type.String({ description: 'Legacy mission id (map).' })),
|
|
70
|
+
newMissionId: Type.Optional(Type.String({ description: 'Current mission id; optional audit pointer.' })),
|
|
71
|
+
}, { additionalProperties: false })
|
|
72
|
+
|
|
73
|
+
export const ReloadInput = Type.Object({
|
|
74
|
+
repoRoot: Type.Optional(Type.String({ description: 'Optional repository root; when present the caller must be the tower.' })),
|
|
75
|
+
}, { additionalProperties: false, required: [] })
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Shared TypeBox helpers for tool input schemas (#45, #56 P3c).
|
|
2
|
+
import { Type } from '@sinclair/typebox'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A string enum that serializes to the same JSON Schema shape as the old
|
|
6
|
+
* inline schemas (type/enum) rather than TypeBox's anyOf union form.
|
|
7
|
+
* @template {string} T
|
|
8
|
+
* @param {readonly T[]} values
|
|
9
|
+
* @param {Record<string, unknown>} [options]
|
|
10
|
+
* @returns {import('@sinclair/typebox').TUnsafe<T>}
|
|
11
|
+
*/
|
|
12
|
+
export function enumOf(values, options = {}) {
|
|
13
|
+
return Type.Unsafe(/** @type {any} */ ({ type: 'string', enum: [...values], ...options }))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Untyped JSON object entries (checks, receiptHashes) must keep their exact
|
|
18
|
+
* `{ type: 'object' }` shape; Type.Object({}) would add a `properties: {}` key.
|
|
19
|
+
* @param {string} [description]
|
|
20
|
+
*/
|
|
21
|
+
export function untypedObject(description) {
|
|
22
|
+
return Type.Unsafe(/** @type {any} */ (description === undefined ? { type: 'object' } : { type: 'object', description }))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { Type }
|
package/domain/errors.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Stable tool error codes.
|
|
2
|
+
//
|
|
3
|
+
// Everything a Tower tool throws reaches the model as
|
|
4
|
+
// [tower:<code>] <original message>
|
|
5
|
+
// so callers (and tests) can branch on the code instead of matching prose.
|
|
6
|
+
// The catalog is documented in docs/reference/errors.md; scripts/check-docs.mjs
|
|
7
|
+
// keeps the two in sync.
|
|
8
|
+
|
|
9
|
+
/** Neutral error type shared by the git adapter and the domain classifier. */
|
|
10
|
+
export class GitError extends Error {
|
|
11
|
+
constructor(args, detail, code, meta = {}) {
|
|
12
|
+
super(`git ${args.join(' ')} failed: ${detail}`)
|
|
13
|
+
this.name = 'GitError'
|
|
14
|
+
this.code = code
|
|
15
|
+
this.timedOut = meta.timedOut === true
|
|
16
|
+
this.bufferOverflow = meta.bufferOverflow === true
|
|
17
|
+
this.stdout = meta.stdout ?? ''
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ERROR_CODES = {
|
|
22
|
+
'invalid-argument': 'A tool argument is missing, malformed, or not allowed.',
|
|
23
|
+
'repo-invalid': 'repoRoot is missing, relative, or not inside a Git repository.',
|
|
24
|
+
'not-initialized': 'Tower is not initialized for this repository; run tower_init.',
|
|
25
|
+
'mission-not-found': 'No mission with that id exists.',
|
|
26
|
+
'finding-not-found': 'No finding with that id exists.',
|
|
27
|
+
'invalid-transition': 'The requested state transition is not allowed.',
|
|
28
|
+
'stale-base': 'The repository state changed while the operation was being prepared; retry.',
|
|
29
|
+
'state-locked': 'Another Tower writer holds the state lock.',
|
|
30
|
+
'state-corrupt': 'The Tower state file is unreadable or invalid.',
|
|
31
|
+
'config-invalid': 'Tower configuration is invalid.',
|
|
32
|
+
'config-unknown-key': 'Tower configuration has an unknown top-level key.',
|
|
33
|
+
'git-failed': 'A git command failed.',
|
|
34
|
+
'git-timeout': 'A git command timed out or exceeded its output buffer.',
|
|
35
|
+
'worktree-dirty': 'The mission worktree has uncommitted changes and cannot complete.',
|
|
36
|
+
'spawn-unavailable': 'The subagents service is unavailable.',
|
|
37
|
+
'provider-missing': 'No subagent provider is registered.',
|
|
38
|
+
'provider-cooldown': 'The provider is throttled; spawn is in a short cooldown.',
|
|
39
|
+
'preset-missing': 'The configured agent preset is not registered.',
|
|
40
|
+
'reviewer-prerequisite': 'The reviewer spawn prerequisite is not met.',
|
|
41
|
+
'not-authorized': 'The calling agent role may not perform this action.',
|
|
42
|
+
'workspace-busy': 'Another Tower session owns this repository workspace lock.',
|
|
43
|
+
'worker-limit': 'The repository reached spawn.maxLiveWorkers live workers.',
|
|
44
|
+
'rate-limited': 'The tower_send per-minute rate limit was reached.',
|
|
45
|
+
'takeover-refused': 'The mission already has a live worker that was not stopped first.',
|
|
46
|
+
'reload-unavailable': 'The DSH HMR service is not available in this profile.',
|
|
47
|
+
'reload-failed': 'The HMR reload failed; check the DSH log and restart if needed.',
|
|
48
|
+
'tests-failed': 'Declared test discovery failed or did not meet its admission requirements.',
|
|
49
|
+
'tests-timeout': 'Test discovery exceeded its time or output budget.',
|
|
50
|
+
'lease-busy': 'Another holder owns the requested advisory lease.',
|
|
51
|
+
'lease-token': 'The lease release token does not match the current holder.',
|
|
52
|
+
'batch-invalid': 'The batch request or its close evidence is invalid.',
|
|
53
|
+
'legacy-invalid': 'The legacy snapshot or mapping is invalid.',
|
|
54
|
+
'tool-internal': 'An unexpected failure; read the message and the activity log.',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const ERROR_CODE_VALUES = Object.freeze(Object.keys(ERROR_CODES))
|
|
58
|
+
export function isErrorCode(value) {
|
|
59
|
+
return typeof value === 'string' && Object.hasOwn(ERROR_CODES, value)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const RETRYABLE_CODES = new Set(['state-locked', 'rate-limited', 'provider-cooldown', 'git-timeout', 'workspace-busy', 'merge-intent-pending', 'stale-base'])
|
|
63
|
+
|
|
64
|
+
export class TowerToolError extends Error {
|
|
65
|
+
constructor(code, message, options = {}) {
|
|
66
|
+
super(`[tower:${code}] ${message}`, options.cause ? { cause: options.cause } : undefined)
|
|
67
|
+
this.name = 'TowerToolError'
|
|
68
|
+
this.code = code
|
|
69
|
+
this.retryable = options.retryable ?? RETRYABLE_CODES.has(code)
|
|
70
|
+
this.nextAction = options.nextAction ?? null
|
|
71
|
+
this.details = options.details ?? null
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function originalMessage(error) {
|
|
76
|
+
return String(error?.message ?? error)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Wrap any thrown value into a TowerToolError with a stable code. */
|
|
80
|
+
export function classifyError(error) {
|
|
81
|
+
if (error instanceof TowerToolError) return error
|
|
82
|
+
if (error && typeof error.code === 'string' && ERROR_CODES[error.code]) {
|
|
83
|
+
return new TowerToolError(error.code, originalMessage(error), {
|
|
84
|
+
cause: error,
|
|
85
|
+
retryable: error.retryable === true,
|
|
86
|
+
nextAction: error.nextAction ?? null,
|
|
87
|
+
details: error.details ?? null,
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
if (error instanceof GitError || error?.name === 'GitError') {
|
|
91
|
+
const message = originalMessage(error)
|
|
92
|
+
const code = error?.timedOut === true || error?.bufferOverflow === true ? 'git-timeout' : 'git-failed'
|
|
93
|
+
return new TowerToolError(code, message, { cause: error })
|
|
94
|
+
}
|
|
95
|
+
return new TowerToolError('tool-internal', originalMessage(error), { cause: error })
|
|
96
|
+
}
|
package/domain/gate.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Pure completion gate checks (#49). No repository I/O.
|
|
2
|
+
// @ts-check
|
|
3
|
+
import { isTerminal } from './mission.js'
|
|
4
|
+
import { isReviewExempt, reviewExemptionInvalid } from './integration/review.js'
|
|
5
|
+
|
|
6
|
+
/** @typedef {import('../types/index.js').Blocker} Blocker */
|
|
7
|
+
/** @typedef {import('../types/index.js').MergeGateOptions} MergeGateOptions */
|
|
8
|
+
/** @typedef {import('../types/index.js').Mission} Mission */
|
|
9
|
+
/** @typedef {import('../types/index.js').Review} Review */
|
|
10
|
+
/** @typedef {import('../types/index.js').TowerConfig} TowerConfig */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Mission} mission
|
|
14
|
+
* @param {TowerConfig} [config]
|
|
15
|
+
* @returns {Blocker[]}
|
|
16
|
+
*/
|
|
17
|
+
export function completionBlockers(mission, config = {}) {
|
|
18
|
+
/** @type {Blocker[]} */
|
|
19
|
+
const blockers = []
|
|
20
|
+
/** @type {(code: string, detail: string) => void} */
|
|
21
|
+
const push = (code, detail) => {
|
|
22
|
+
blockers.push({ code, detail })
|
|
23
|
+
}
|
|
24
|
+
if (isTerminal(mission.status)) {
|
|
25
|
+
push(
|
|
26
|
+
'branch-owned-by-closed-missions',
|
|
27
|
+
`mission ${mission.id} is ${mission.status}; a merge never flips a closed mission — re-plan the work under a new title`,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
if (mission.status !== 'completed') {
|
|
31
|
+
push('mission-not-completed', `mission ${mission.id} is ${mission.status}; completion is required`)
|
|
32
|
+
}
|
|
33
|
+
const openTasks = (mission.tasks ?? []).filter((task) => task.status === 'open')
|
|
34
|
+
if (openTasks.length > 0) {
|
|
35
|
+
push('tasks-open', `${openTasks.length} open task(s): ${openTasks.map((task) => task.text).join('; ')}`)
|
|
36
|
+
}
|
|
37
|
+
const presentBlockers = mission.blockers ?? []
|
|
38
|
+
if (presentBlockers.length > 0) push('blockers-present', presentBlockers.join('; '))
|
|
39
|
+
if (config.gates?.requireChecks === true) {
|
|
40
|
+
const checks = mission.completionReport?.checks ?? []
|
|
41
|
+
if (checks.length === 0) {
|
|
42
|
+
push('no-check-evidence', `mission ${mission.id} has no completion checks; gates.requireChecks is enabled`)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return blockers
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Review, roster, and test-evidence blockers; all inputs are snapshots.
|
|
50
|
+
* @param {MergeGateOptions} options
|
|
51
|
+
* @returns {Blocker[]}
|
|
52
|
+
*/
|
|
53
|
+
export function mergeGateBlockers({
|
|
54
|
+
mission,
|
|
55
|
+
roster = [],
|
|
56
|
+
branch = null,
|
|
57
|
+
branchTip = null,
|
|
58
|
+
review = null,
|
|
59
|
+
config = {},
|
|
60
|
+
activity = {},
|
|
61
|
+
parentStatus = null,
|
|
62
|
+
inactiveStates = [],
|
|
63
|
+
rebaseWaived = false,
|
|
64
|
+
}) {
|
|
65
|
+
/** @type {Blocker[]} */
|
|
66
|
+
const blockers = []
|
|
67
|
+
/** @type {(code: string, detail: string) => void} */
|
|
68
|
+
const push = (code, detail) => {
|
|
69
|
+
blockers.push({ code, detail })
|
|
70
|
+
}
|
|
71
|
+
const inactive = new Set(inactiveStates)
|
|
72
|
+
const requireReview = config.review?.requireReview !== false
|
|
73
|
+
const exempt = isReviewExempt(mission, config)
|
|
74
|
+
if (reviewExemptionInvalid(mission, config)) {
|
|
75
|
+
push('review-exemption-invalid', `mission ${mission.id} requests no review but gates.allowReviewExemption is disabled`)
|
|
76
|
+
}
|
|
77
|
+
if (requireReview && !exempt && !review) {
|
|
78
|
+
push('no-review', `branch ${branch ?? '(none)'} has no review; assign a reviewer first (or set review.requireReview:false)`)
|
|
79
|
+
} else if (requireReview && !exempt) {
|
|
80
|
+
const latest = /** @type {Review} */ (review)
|
|
81
|
+
if (latest.missionId !== mission.id) push('review-mission-mismatch', `latest review belongs to mission ${latest.missionId}`)
|
|
82
|
+
if (latest.status !== 'clean') push('not-clean', `latest review round ${latest.round} is "${latest.status}"`)
|
|
83
|
+
if (latest.mergeVerdict === 'hold') {
|
|
84
|
+
push('review-hold', 'latest review recommends hold — a later clean review must supersede it')
|
|
85
|
+
} else if (latest.status === 'clean' && latest.mergeVerdict !== 'merge') {
|
|
86
|
+
push('review-not-approved', `latest clean review recommends "${latest.mergeVerdict}" — only "merge" approves`)
|
|
87
|
+
}
|
|
88
|
+
if (branchTip && latest.reviewedCommit !== branchTip && !rebaseWaived) {
|
|
89
|
+
push('tip-moved', `reviewed ${latest.reviewedCommit.slice(0, 7)} but tip is ${branchTip.slice(0, 7)}; re-review required`)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const entry of (roster ?? []).filter((row) => row.missionId === mission.id && !inactive.has(row.state))) {
|
|
93
|
+
// Reserved rows can lack an agent id; indexing with undefined is a miss.
|
|
94
|
+
const agentId = /** @type {string} */ (entry.agentId)
|
|
95
|
+
if (activity[agentId] === 'running') push('worker-busy', `agent ${entry.name} is still running`)
|
|
96
|
+
else if (parentStatus && entry.parentSessionId && parentStatus[entry.parentSessionId] !== 'ok') {
|
|
97
|
+
push('worker-status-unknown', `cannot prove agent ${entry.name} is stopped: its parent catalog is unavailable`)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const staleWorkers = (roster ?? []).filter(
|
|
101
|
+
(row) => row.missionId === mission.id && (row.state === 'stale' || (row.stale === true && !inactive.has(row.state))),
|
|
102
|
+
)
|
|
103
|
+
if (staleWorkers.length > 0) {
|
|
104
|
+
push('worker-stale', `stale worker(s) for ${mission.id}: ${staleWorkers.map((row) => row.name).join(', ')}; adopt or interrupt before merge`)
|
|
105
|
+
}
|
|
106
|
+
if (config.gates?.requireTests === true) {
|
|
107
|
+
const runs = (mission.testRuns ?? []).filter((run) => run.ok === true && run.treeTip && branchTip && run.treeTip === branchTip)
|
|
108
|
+
if (runs.length === 0) {
|
|
109
|
+
push('tests-missing', `mission ${mission.id} has no passing test discovery for tip ${branchTip ? branchTip.slice(0, 7) : '(none)'}`)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return blockers
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A conflict-free rebase after the reviewed tip waives the stale-tip blocker.
|
|
117
|
+
* @param {Mission} mission
|
|
118
|
+
* @param {Review} review
|
|
119
|
+
* @returns {boolean}
|
|
120
|
+
*/
|
|
121
|
+
export function rebaseWaived(mission, review) {
|
|
122
|
+
const rebase = mission.rebase
|
|
123
|
+
if (!rebase) return false
|
|
124
|
+
return review.at <= rebase.at && review.reviewedCommit === rebase.oldTip
|
|
125
|
+
}
|