jackherd 1.15.2 → 1.17.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 +34 -0
- package/INSTALL.md +2 -1
- package/README.md +26 -22
- package/dist/{chunk-4LUFR7RC.js → chunk-N5FAOQZL.js} +7 -0
- package/dist/config.d.ts +33 -1
- package/dist/config.js +57 -5
- package/dist/plan-format.d.ts +18 -6
- package/dist/plan-format.js +8 -1
- package/docs/plan-contract.md +1 -0
- package/herdr-plugin/herdr-plugin.toml +4 -1
- package/herdr-plugin/restore-plans.ts +60 -26
- package/herdr-plugin/resume.ts +18 -0
- package/install.sh +1 -1
- package/kit/hooks/ask-rules.json +11 -0
- package/kit/hooks/hooks/approval-gate/checked-marks.ts +59 -0
- package/kit/hooks/hooks/approval-gate/index.ts +36 -7
- package/kit/hooks/hooks/approval-gate/run.ts +72 -16
- package/kit/hooks/hooks/approval-gate/settings.ts +27 -1
- package/kit/hooks/hooks/approval-gate/standing-history.ts +90 -0
- package/kit/hooks/hooks/approval-gate/standing-sql.ts +58 -0
- package/kit/hooks/hooks/approval-gate/transcripts.ts +11 -5
- package/kit/hooks/hooks/lane-start-guard/decision.ts +74 -0
- package/kit/hooks/hooks/lane-start-guard/index.ts +36 -0
- package/kit/hooks/hooks/merge-guard/always-ask.ts +2 -2
- package/kit/hooks/hooks/merge-guard/approval.ts +25 -13
- package/kit/hooks/hooks/merge-guard/change-id.ts +34 -0
- package/kit/hooks/hooks/merge-guard/decision.ts +438 -35
- package/kit/hooks/hooks/merge-guard/pane-input.ts +61 -0
- package/kit/hooks/hooks/merge-guard/pane-process-info.ts +38 -0
- package/kit/hooks/hooks/merge-guard/run.ts +110 -28
- package/kit/hooks/hooks/merge-guard/standing-approval.ts +15 -78
- package/kit/hooks/hooks/plain-question/form.ts +89 -0
- package/kit/hooks/hooks/plain-question/index.ts +44 -4
- package/kit/hooks/hooks/plain-question/recommendation.ts +73 -0
- package/kit/hooks/hooks/plain-question/run.ts +14 -7
- package/kit/hooks/hooks/shared/standing-mark.ts +104 -0
- package/kit/hooks/hooks.json +11 -2
- package/kit/review/agents/skill-review.md +3 -2
- package/kit/review/skills/pre-commit/SKILL.md +1 -1
- package/kit/rules/rules/kit/code-style.md +6 -6
- package/kit/rules/rules/kit/writing-for-agents.md +3 -0
- package/kit/workflow/skills/follow/SKILL.md +18 -11
- package/kit/workflow/skills/implement/SKILL.md +1 -1
- package/kit/workflow/skills/orchestrate/SKILL.md +124 -300
- package/kit/workflow/skills/orchestrate/references/appointments.md +21 -0
- package/kit/workflow/skills/orchestrate/references/close-lane.md +8 -7
- package/kit/workflow/skills/orchestrate/references/coordinator-handover.md +8 -8
- package/kit/workflow/skills/orchestrate/references/events.md +46 -1
- package/kit/workflow/skills/orchestrate/references/herd-ask.md +10 -0
- package/kit/workflow/skills/orchestrate/references/lane-handover.md +9 -4
- package/kit/workflow/skills/orchestrate/references/lane-session.md +5 -4
- package/kit/workflow/skills/orchestrate/references/lane-setup.md +2 -1
- package/kit/workflow/skills/orchestrate/references/plan-commit.md +9 -2
- package/kit/workflow/skills/orchestrate/references/self-merge.md +26 -0
- package/kit/workflow/skills/orchestrate/references/stage-approval.md +50 -0
- package/kit/workflow/skills/orchestrate/references/standing-approval.md +38 -0
- package/kit/workflow/skills/orchestrate/references/start-lane.md +67 -0
- package/kit/workflow/skills/orchestrate/references/waiting.md +16 -0
- package/kit/workflow/skills/orchestrate/references/watch-without-monitor.md +13 -0
- package/kit/workflow/skills/plan/SKILL.md +3 -2
- package/package.json +3 -1
- package/recipes/README.md +4 -2
- package/recipes/google-calendar.md +30 -0
- package/recipes/jira-cli.md +1 -1
- package/recipes/sources/google-calendar-today.ts +38 -0
- package/recipes/sources/google-calendar.ts +368 -0
- package/recipes/sources/jira.ts +10 -2
- package/recipes/sources/linear.ts +9 -3
- package/recipes/sources/sentry.ts +8 -2
- package/recipes/sources.md +17 -3
- package/schemas/jackherd.schema.json +67 -0
- package/schemas/sources.schema.json +9 -0
- package/src/approval/checked.ts +60 -0
- package/src/approval/command.ts +16 -0
- package/src/check/command.ts +51 -6
- package/src/check/lint-pointers.ts +79 -0
- package/src/check/lint-shaped.ts +196 -0
- package/src/check/plan-structure-check.ts +116 -4
- package/src/check/report.ts +9 -3
- package/src/check/schema.ts +37 -0
- package/src/check/settings.ts +4 -0
- package/src/check/skill-budget-defaults.ts +81 -23
- package/src/check/skill-budgets.ts +58 -10
- package/src/cli.ts +2 -0
- package/src/config/personal-sources.ts +46 -10
- package/src/config/repository-identity.ts +40 -0
- package/src/config/schema.ts +53 -1
- package/src/context/command.ts +33 -2
- package/src/context/options.ts +33 -8
- package/src/context/usage-logs.ts +53 -0
- package/src/context/usage.ts +110 -0
- package/src/lane/base-command.ts +35 -0
- package/src/lane/base.ts +43 -0
- package/src/lane/close-check.ts +49 -15
- package/src/lane/close-command.ts +71 -11
- package/src/lane/close-options.ts +29 -8
- package/src/lane/close-survey.ts +13 -1
- package/src/lane/close.ts +51 -12
- package/src/lane/command.ts +21 -3
- package/src/lane/send-command.ts +32 -0
- package/src/lane/send-herdr.ts +77 -0
- package/src/lane/send-options.ts +23 -0
- package/src/lane/send.ts +90 -0
- package/src/lane/skill-hint.ts +27 -0
- package/src/lane/space-command.ts +30 -0
- package/src/lane/space.ts +49 -0
- package/src/lane/start-lane-hint.ts +18 -0
- package/src/plan-contract/base-check-git.ts +33 -0
- package/src/plan-contract/base-check.ts +17 -0
- package/src/plan-contract/command.ts +25 -4
- package/src/plan-format/plan-structure.ts +17 -5
- package/src/plans/ask-coordinator.ts +23 -13
- package/src/plans/board-rows.ts +9 -4
- package/src/plans/click-hint.ts +4 -0
- package/src/plans/command.ts +6 -5
- package/src/plans/ensure-panes.ts +14 -3
- package/src/plans/git.ts +14 -0
- package/src/plans/github.ts +19 -10
- package/src/plans/layout.ts +191 -25
- package/src/plans/live.ts +57 -14
- package/src/plans/plan-panes.ts +21 -4
- package/src/plans/row-actions.ts +17 -10
- package/src/plans/selection.ts +29 -0
- package/src/plans/settings.ts +4 -0
- package/src/plans/snapshot.ts +8 -3
- package/src/plans/source-rows.ts +35 -2
- package/src/resume/command.ts +213 -0
- package/src/resume/decision.ts +102 -0
- package/src/resume/keeper.ts +65 -0
- package/src/resume/location.ts +22 -0
- package/src/resume/log.ts +27 -0
- package/src/resume/ports.ts +102 -0
- package/src/resume/record.ts +116 -0
- package/src/resume/targets.ts +84 -0
- package/src/resume/texts.ts +27 -0
- package/src/secrets/command.ts +15 -5
- package/src/sync/herdr-plugin.ts +2 -11
- package/src/sync/plan-ask-rules.ts +11 -0
- package/src/sync/render.ts +3 -1
- package/src/vocabulary/index.ts +13 -0
- package/src/waiting/command.ts +13 -4
- package/src/watch/command.ts +177 -78
- package/src/watch/config-reload.ts +119 -0
- package/src/watch/lane-model.ts +11 -1
- package/src/watch/lane-progress.ts +70 -8
- package/src/watch/lane-report.ts +68 -12
- package/src/watch/main-checkout.ts +5 -1
- package/src/watch/merge-duties.ts +33 -0
- package/src/watch/merge-overlap-read.ts +69 -0
- package/src/watch/plan-views.ts +16 -4
- package/src/watch/reference-paths.ts +46 -5
- package/src/watch/report-questions.ts +5 -2
- package/src/watch/single-report.ts +3 -2
- package/src/watch/source-dry-run-command.ts +22 -4
- package/src/watch/source-dry-run.ts +1 -1
- package/src/watch/source-reason.ts +58 -0
- package/src/watch/source-reload.ts +21 -17
- package/src/watch/source-run.ts +24 -7
- package/src/watch/sources.ts +9 -2
- package/src/watch/texts.ts +15 -4
- package/src/watch/waiting-line.ts +4 -3
|
@@ -3,22 +3,29 @@ import { homedir } from 'node:os'
|
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
4
|
import { findProjectRoot } from '../config/location'
|
|
5
5
|
import { readConfig } from '../config/read-config'
|
|
6
|
+
import { installedReferenceHint } from '../lane/skill-hint'
|
|
6
7
|
import { asksForHelp } from '../preview/options'
|
|
7
8
|
import { CLI_NAME } from '../version/release'
|
|
8
9
|
import type { PlanLanguage } from '../vocabulary'
|
|
10
|
+
import { REFERENCE, type Reference, referenceLine } from '../watch/reference-paths'
|
|
11
|
+
import { baseGapLinesFor } from './base-check-git'
|
|
9
12
|
import { contractOf, type PartFinding, type PlanContract } from './contract'
|
|
10
13
|
|
|
11
14
|
const CHECK_SUBCOMMAND = 'check'
|
|
12
15
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Exit codes of `jh plan check`: the contract is met, a part has a gap, the command line or the file is wrong, the
|
|
18
|
+
* contract is met but the plan or a board that links it is not on the base branch.
|
|
19
|
+
*/
|
|
20
|
+
export const PLAN_CHECK_EXIT = { met: 0, gaps: 1, error: 2, notOnBase: 3 } as const
|
|
15
21
|
|
|
16
22
|
export const USAGE = `usage: ${CLI_NAME} plan ${CHECK_SUBCOMMAND} <plan.md>
|
|
17
23
|
|
|
18
24
|
Checks one plan against the plan contract: phases, tasks in every phase, a model for every phase, a dependency
|
|
19
25
|
row for every phase (from two phases on). One line per part, \`file:line\` where a part is incomplete.
|
|
26
|
+
Where git has the base branch, a plan, or a board that links it, that the base branch lacks gets a \`base:\` line with its path.
|
|
20
27
|
The plan language comes from .jackherd/config.json.
|
|
21
|
-
Exit 0 met, 1 with gaps, 2 for a wrong command line or an unreadable file.`
|
|
28
|
+
Exit 0 met, 1 with gaps, 2 for a wrong command line or an unreadable file, 3 met but not on the base branch.`
|
|
22
29
|
|
|
23
30
|
const where = (file: string, line: number | null): string => (line === null ? '' : ` ${file}:${line}`)
|
|
24
31
|
|
|
@@ -45,6 +52,12 @@ const readPlan = (file: string): string | null => {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
55
|
+
/** The line after the findings that names the reference to read for the gap, for exit 1 and exit 3; none without the skill. */
|
|
56
|
+
const printReference = (reference: Reference, home: string): void => {
|
|
57
|
+
const root = findProjectRoot(process.cwd(), home, existsSync) ?? process.cwd()
|
|
58
|
+
for (const line of referenceLine(installedReferenceHint(root, reference, home))) console.log(line)
|
|
59
|
+
}
|
|
60
|
+
|
|
48
61
|
const fail = (message: string): number => {
|
|
49
62
|
console.error(message)
|
|
50
63
|
return PLAN_CHECK_EXIT.error
|
|
@@ -65,5 +78,13 @@ export const run = (args: string[], home: string = homedir()): number => {
|
|
|
65
78
|
if ('error' in result) return fail(result.error)
|
|
66
79
|
const contract = contractOf(markdown, result.language)
|
|
67
80
|
for (const line of contractLines(file, contract)) console.log(line)
|
|
68
|
-
|
|
81
|
+
if (!contract.met) {
|
|
82
|
+
printReference(REFERENCE.adoptPlan, home)
|
|
83
|
+
return PLAN_CHECK_EXIT.gaps
|
|
84
|
+
}
|
|
85
|
+
const gapLines = baseGapLinesFor(file, process.cwd())
|
|
86
|
+
for (const line of gapLines) console.log(line)
|
|
87
|
+
if (gapLines.length === 0) return PLAN_CHECK_EXIT.met
|
|
88
|
+
printReference(REFERENCE.planCommit, home)
|
|
89
|
+
return PLAN_CHECK_EXIT.notOnBase
|
|
69
90
|
}
|
|
@@ -20,11 +20,11 @@ export type PhaseWithoutGate = PhaseHeading
|
|
|
20
20
|
/** A row of the lanes table (1-based line) whose phases cell names no phase id. */
|
|
21
21
|
export type RowWithoutPhase = OpenLaneRow
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
export type MergedPhaseWithOpenBoxes =
|
|
23
|
+
/** A `### Phase` heading (1-based line) whose own section has open checkboxes not moved on with `→ P<n>` (`openLines`, 1-based). */
|
|
24
|
+
export type PhaseWithOpenBoxes = PhaseWithoutGate & { openLines: number[] }
|
|
25
|
+
|
|
26
|
+
/** A `PhaseWithOpenBoxes` whose tasks are all ticked on the base branch. */
|
|
27
|
+
export type MergedPhaseWithOpenBoxes = PhaseWithOpenBoxes
|
|
28
28
|
|
|
29
29
|
type PhaseSection = PhaseWithoutGate & { tasks: boolean; gate: boolean; openLines: number[] }
|
|
30
30
|
|
|
@@ -118,6 +118,18 @@ export const mergedPhasesWithOpenBoxes = (
|
|
|
118
118
|
.map(({ line, id, title, openLines }) => ({ line, id, title, openLines }))
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The phase `id` of `markdown` when its own section still has open checkboxes, gate boxes included, that no `→ P<n>`
|
|
123
|
+
* at their end moves on; null when it has none or the plan lacks the phase. Unlike `mergedPhasesWithOpenBoxes` it
|
|
124
|
+
* does not ask whether the phase counts as merged: the caller knows which phase a branch builds.
|
|
125
|
+
*/
|
|
126
|
+
export const openBoxesOfPhase = (markdown: string, language: PlanLanguage, id: string): PhaseWithOpenBoxes | null => {
|
|
127
|
+
const section = phaseSections(markdown, language).find((candidate) => candidate.id === id)
|
|
128
|
+
return section && section.openLines.length > 0
|
|
129
|
+
? { line: section.line, id: section.id, title: section.title, openLines: section.openLines }
|
|
130
|
+
: null
|
|
131
|
+
}
|
|
132
|
+
|
|
121
133
|
/**
|
|
122
134
|
* The changed rows of open lanes whose phases cell names no phase id (`P10c`), so neither the view nor the watcher
|
|
123
135
|
* can tie that step to a phase.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { TERMINAL_ADAPTER, type TerminalAdapter } from '../config'
|
|
2
2
|
import { resolveCoordinatorName } from '../context/coordinator-name'
|
|
3
|
+
import { installedReferenceHintFor } from '../lane/skill-hint'
|
|
3
4
|
import { laneSenderForAsync } from '../settled/send'
|
|
4
5
|
import { type HerdrAsyncRunner, parseAgentList } from '../terminal/herdr'
|
|
5
6
|
import { PLAN_LANGUAGE, type PlanLanguage } from '../vocabulary'
|
|
7
|
+
import { REFERENCE } from '../watch/reference-paths'
|
|
6
8
|
import { ASK_KIND, type AskTarget, boardRowKey } from './ask-target'
|
|
7
9
|
import { errorText } from './error-text'
|
|
8
10
|
import { isQuestionId } from './question-records'
|
|
@@ -18,29 +20,32 @@ export type AskDependencies = {
|
|
|
18
20
|
/** The repository's directory name, from which the coordinator's herdr name follows. */
|
|
19
21
|
repository: string
|
|
20
22
|
run: HerdrAsyncRunner
|
|
23
|
+
/** Where the repository is looked up for the skill's reference; the working directory when omitted. */
|
|
24
|
+
cwd?: string
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
/** A sentence takes the subject's key and, for an entry of a source, the source it belongs to (else `''`). */
|
|
24
|
-
type AskSentences = Record<AskTarget['kind'], (subject: string, scope: string) => string>
|
|
28
|
+
type AskSentences = Record<AskTarget['kind'], (subject: string, scope: string, hint: string) => string>
|
|
25
29
|
|
|
26
30
|
const ASK_LINES: Record<PlanLanguage, AskSentences> = {
|
|
27
31
|
[PLAN_LANGUAGE.de]: {
|
|
28
|
-
[ASK_KIND.question]: (id) => `Stell mir die offene Frage ${id} jetzt (jh waiting)
|
|
29
|
-
[ASK_KIND.boardRow]: (key) =>
|
|
32
|
+
[ASK_KIND.question]: (id, _scope, hint) => `Stell mir die offene Frage ${id} jetzt (jh waiting).${hint}`,
|
|
33
|
+
[ASK_KIND.boardRow]: (key, _scope, hint) =>
|
|
34
|
+
`Stell mir die offene Board-Zeile \`${key}\` jetzt (jh waiting).${hint}`,
|
|
30
35
|
[ASK_KIND.appointmentRun]: (key) => `Führe den Termin \`${key}\` jetzt aus, unter den Freigaben, die er braucht.`,
|
|
31
36
|
[ASK_KIND.appointmentMove]: (key) =>
|
|
32
37
|
`Frag den User per Dialog nach der neuen Zeit für den Termin \`${key}\` und trag sie ins Board ein (verschobene Zeile = neuer Termin).`,
|
|
33
|
-
[ASK_KIND.sourceEntry]: (title, source) =>
|
|
34
|
-
`Sieh dir die Meldung \`${title}\` der Quelle \`${source}\` an und stell mir, falls nötig, die Frage dazu (jh waiting)
|
|
38
|
+
[ASK_KIND.sourceEntry]: (title, source, hint) =>
|
|
39
|
+
`Sieh dir die Meldung \`${title}\` der Quelle \`${source}\` an und stell mir, falls nötig, die Frage dazu (jh waiting).${hint}`,
|
|
35
40
|
},
|
|
36
41
|
[PLAN_LANGUAGE.en]: {
|
|
37
|
-
[ASK_KIND.question]: (id) => `Ask me the open question ${id} now (jh waiting)
|
|
38
|
-
[ASK_KIND.boardRow]: (key) => `Ask me the open board row \`${key}\` now (jh waiting)
|
|
42
|
+
[ASK_KIND.question]: (id, _scope, hint) => `Ask me the open question ${id} now (jh waiting).${hint}`,
|
|
43
|
+
[ASK_KIND.boardRow]: (key, _scope, hint) => `Ask me the open board row \`${key}\` now (jh waiting).${hint}`,
|
|
39
44
|
[ASK_KIND.appointmentRun]: (key) => `Run the appointment \`${key}\` now, under the approvals it needs.`,
|
|
40
45
|
[ASK_KIND.appointmentMove]: (key) =>
|
|
41
46
|
`Ask the user in a dialog for the new time of the appointment \`${key}\` and write it into the board (a moved row is a new appointment).`,
|
|
42
|
-
[ASK_KIND.sourceEntry]: (title, source) =>
|
|
43
|
-
`Look at the report \`${title}\` of the source \`${source}\` and, if it needs it, put the question about it to me (jh waiting)
|
|
47
|
+
[ASK_KIND.sourceEntry]: (title, source, hint) =>
|
|
48
|
+
`Look at the report \`${title}\` of the source \`${source}\` and, if it needs it, put the question about it to me (jh waiting).${hint}`,
|
|
44
49
|
},
|
|
45
50
|
}
|
|
46
51
|
|
|
@@ -60,10 +65,11 @@ const scopeOf = (target: AskTarget): string =>
|
|
|
60
65
|
/**
|
|
61
66
|
* The line sent to the coordinator: a fixed sentence that carries the id of a question, or the sanitised key of a
|
|
62
67
|
* row (`boardRowKey`), and nothing else from the board or the question, so a prompt line cannot be steered by
|
|
63
|
-
* the file it reads. The caller checks the id with `isQuestionId`.
|
|
68
|
+
* the file it reads. The caller checks the id with `isQuestionId`. The sentences that send the coordinator to `jh waiting` end
|
|
69
|
+
* with `hint`, the reference that says how to put the question (none without the orchestrate skill).
|
|
64
70
|
*/
|
|
65
|
-
export const askLine = (target: AskTarget, language: PlanLanguage): string =>
|
|
66
|
-
ASK_LINES[language][target.kind](subjectKeyOf(target), scopeOf(target))
|
|
71
|
+
export const askLine = (target: AskTarget, language: PlanLanguage, hint = ''): string =>
|
|
72
|
+
ASK_LINES[language][target.kind](subjectKeyOf(target), scopeOf(target), hint)
|
|
67
73
|
|
|
68
74
|
const isAskable = (target: AskTarget): boolean =>
|
|
69
75
|
target.kind === ASK_KIND.question
|
|
@@ -114,7 +120,11 @@ export const askCoordinator = async (target: AskTarget, dependencies: AskDepende
|
|
|
114
120
|
if ('reason' in coordinator) return TEXTS.notAsked(coordinator.reason)
|
|
115
121
|
const failure = await laneSenderForAsync(dependencies.adapter, dependencies.run)(
|
|
116
122
|
coordinator.name,
|
|
117
|
-
askLine(
|
|
123
|
+
askLine(
|
|
124
|
+
target,
|
|
125
|
+
dependencies.language,
|
|
126
|
+
installedReferenceHintFor(dependencies.cwd ?? process.cwd(), REFERENCE.herdAsk),
|
|
127
|
+
),
|
|
118
128
|
)
|
|
119
129
|
return failure === null ? TEXTS.asked(coordinator.name, subjectOf(target)) : TEXTS.notAsked(failure)
|
|
120
130
|
}
|
package/src/plans/board-rows.ts
CHANGED
|
@@ -26,18 +26,23 @@ const newPartOf = (lane: SprintLane, step: PlanStep): PlanStep | null => {
|
|
|
26
26
|
return rest.phaseIds.length > 0 ? rest : null
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/**
|
|
29
|
+
/** Whether the lane is closed: the base says so, or the checkout marks it cleaned up before the mark is merged. */
|
|
30
|
+
const closedBy = (known: SprintLane, checkout: SprintLane | undefined): boolean =>
|
|
31
|
+
known.closed || checkout?.closed === true
|
|
32
|
+
|
|
33
|
+
/** The lane with the checkout's steps it does not have yet and its closed mark; the same object when nothing is new. */
|
|
30
34
|
const grownBy = (known: SprintLane, checkout: SprintLane | undefined): SprintLane => {
|
|
31
|
-
const grown: SprintLane = { ...known, steps: [...known.steps] }
|
|
35
|
+
const grown: SprintLane = { ...known, steps: [...known.steps], closed: closedBy(known, checkout) }
|
|
32
36
|
for (const step of checkout?.steps ?? []) {
|
|
33
37
|
const part = newPartOf(grown, step)
|
|
34
38
|
if (part !== null) grown.steps.push(part)
|
|
35
39
|
}
|
|
36
|
-
return grown.steps.length > known.steps.length ? grown : known
|
|
40
|
+
return grown.steps.length > known.steps.length || grown.closed !== known.closed ? grown : known
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
|
-
* The board at the base ref with the rows only the checkout has. Base lanes keep their order and their rows
|
|
44
|
+
* The board at the base ref with the rows only the checkout has. Base lanes keep their order and their rows, and are
|
|
45
|
+
* closed when the checkout marks them cleaned up, so the herd drops a lane before the mark reaches the base;
|
|
41
46
|
* a lane only the checkout names is appended; a step of a known lane is added when the base does not name its
|
|
42
47
|
* phases for that plan yet (identity: plan link and phase id), a row without a plan link when its label is new.
|
|
43
48
|
* Both sides come parsed, this function reads no text.
|
package/src/plans/click-hint.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { pullRequestNumberOfKey } from './pull-requests'
|
|
|
3
3
|
import { LINKS_KEY_PREFIX } from './row-focus'
|
|
4
4
|
import {
|
|
5
5
|
BACKLOG_KEY,
|
|
6
|
+
entryBlockOfKey,
|
|
6
7
|
finishedKey,
|
|
7
8
|
isBlockFolded,
|
|
9
|
+
isEntryBlockFolded,
|
|
8
10
|
isLaneOpen,
|
|
9
11
|
isLanesOpen,
|
|
10
12
|
isTaskRestKey,
|
|
@@ -55,6 +57,8 @@ const foldingHint = (key: string, state: Selection, agentOf: AgentOf): string |
|
|
|
55
57
|
const lane = laneOfKey(key)
|
|
56
58
|
if (lane !== null) return foldHint(isLaneOpen(state, lane, agentOf(lane)), lane)
|
|
57
59
|
if (key === LANES_KEY) return foldHint(isLanesOpen(state), TEXTS.lanesHeading)
|
|
60
|
+
const entrySource = entryBlockOfKey(key)
|
|
61
|
+
if (entrySource !== null) return foldHint(!isEntryBlockFolded(state, entrySource), entrySource)
|
|
58
62
|
const top = topBlockOfKey(key)
|
|
59
63
|
if (top !== null) return foldHint(!isBlockFolded(state, top), TOP_BLOCK_NAMES[top])
|
|
60
64
|
const open = state.expanded.has(key)
|
package/src/plans/command.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { laneStatusSourceFor } from '../terminal'
|
|
|
4
4
|
import { listHerdrAgents } from '../terminal/herdr'
|
|
5
5
|
import { startedKit } from '../version/started-kit'
|
|
6
6
|
import { boardFor, foundLanesOf } from './board-pick'
|
|
7
|
-
import {
|
|
7
|
+
import { ensurePlanPaneRun } from './ensure-panes'
|
|
8
8
|
import { mainCheckout, worktreeRoot } from './git'
|
|
9
9
|
import { fetchPullRequests } from './github'
|
|
10
10
|
import { claimOwnTerminal, startExclusive } from './herd-claim'
|
|
@@ -12,6 +12,7 @@ import { recallLanes, rememberLanes } from './herd-memory'
|
|
|
12
12
|
import { publishedKey } from './herd-state'
|
|
13
13
|
import { runLive } from './live'
|
|
14
14
|
import { parseOptions } from './options'
|
|
15
|
+
import { ENSURE_EXIT } from './plan-panes'
|
|
15
16
|
import { isSupervisedChild } from './restart-decision'
|
|
16
17
|
import { type PlansSettings, readSettings } from './settings'
|
|
17
18
|
import { loadSnapshot, type Source } from './snapshot'
|
|
@@ -55,12 +56,12 @@ export const run = async (args: string[], home: string = homedir()): Promise<num
|
|
|
55
56
|
foundLanesOf(root, settings, () => terminal.listAgents().map((agent) => agent.name)),
|
|
56
57
|
)
|
|
57
58
|
if (options.ensure) {
|
|
58
|
-
const lines =
|
|
59
|
+
const { lines, exitCode } =
|
|
59
60
|
settings.adapter === TERMINAL_ADAPTER.herdr
|
|
60
|
-
?
|
|
61
|
-
: ['the terminal adapter is not herdr: no panes to bring back']
|
|
61
|
+
? ensurePlanPaneRun(root, settings, picked.file)
|
|
62
|
+
: { lines: ['the terminal adapter is not herdr: no panes to bring back'], exitCode: ENSURE_EXIT.done }
|
|
62
63
|
for (const line of lines.length > 0 ? lines : ['every herd pane is running']) console.log(line)
|
|
63
|
-
return
|
|
64
|
+
return exitCode
|
|
64
65
|
}
|
|
65
66
|
const source: Source = { root, sprintFile: picked.file, options, settings, terminal, ...agentListOf(settings) }
|
|
66
67
|
if (options.once || !process.stdout.isTTY) await printOnceWithNotice(source, picked.notice)
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
agentPanesOf,
|
|
9
9
|
coordinatorLabelOf,
|
|
10
10
|
coordinatorPaneOf,
|
|
11
|
+
type EnsureExit,
|
|
12
|
+
ensureExitOf,
|
|
11
13
|
foregroundOf,
|
|
12
14
|
missingCoordinatorNote,
|
|
13
15
|
type PaneAction,
|
|
@@ -60,9 +62,14 @@ const labelCoordinator = (label: { pane: string; label: string } | null) => {
|
|
|
60
62
|
/**
|
|
61
63
|
* `herd --ensure`: brings back every missing herd pane beside the coordinator and each lane of the board, and
|
|
62
64
|
* leaves running ones alone, so it can run after every start. A lane gets its view once its agent runs. One line per
|
|
63
|
-
* action or skipped target, none when every view runs
|
|
65
|
+
* action or skipped target, none when every view runs, and the exit code (`ENSURE_EXIT`) that says whether the
|
|
66
|
+
* coordinator's pane was found. The coordinator's pane is labelled `🐾 Jack` on the way.
|
|
64
67
|
*/
|
|
65
|
-
export const
|
|
68
|
+
export const ensurePlanPaneRun = (
|
|
69
|
+
root: string,
|
|
70
|
+
settings: PlansSettings,
|
|
71
|
+
boardFile: string,
|
|
72
|
+
): { lines: string[]; exitCode: EnsureExit } => {
|
|
66
73
|
const agents = runHerdr(['agent', 'list'])
|
|
67
74
|
const listed = parseAgentList(agents)
|
|
68
75
|
const panes = panesWithForeground(agentPanesOf(agents))
|
|
@@ -84,5 +91,9 @@ export const ensurePlanPanes = (root: string, settings: PlansSettings, boardFile
|
|
|
84
91
|
command: (lane) => viewCommandOf(process.argv, lane),
|
|
85
92
|
missingCoordinator: missingCoordinatorNote(panes, root, coordinatorName),
|
|
86
93
|
})
|
|
87
|
-
return [...actions.map(apply), ...notes]
|
|
94
|
+
return { lines: [...actions.map(apply), ...notes], exitCode: ensureExitOf(panes, coordinator) }
|
|
88
95
|
}
|
|
96
|
+
|
|
97
|
+
/** The lines of `ensurePlanPaneRun`, for a caller that brings the panes back without an exit code (the watcher). */
|
|
98
|
+
export const ensurePlanPanes = (root: string, settings: PlansSettings, boardFile: string): string[] =>
|
|
99
|
+
ensurePlanPaneRun(root, settings, boardFile).lines
|
package/src/plans/git.ts
CHANGED
|
@@ -39,6 +39,11 @@ export const showAtRef = (root: string, ref: string, path: string): string | nul
|
|
|
39
39
|
return result.exitCode === 0 ? result.stdout.toString() : null
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** Whether `path` (from the repository root, without `..`) exists at `ref`. */
|
|
43
|
+
export const existsOnRef = (root: string, ref: string, path: string): boolean =>
|
|
44
|
+
Bun.spawnSync(['git', '-C', root, 'cat-file', '-e', `${ref}:${path}`], { stdout: 'ignore', stderr: 'ignore' })
|
|
45
|
+
.exitCode === 0
|
|
46
|
+
|
|
42
47
|
/** The commit `ref` points at, null when it does not exist. */
|
|
43
48
|
export const commitOf = (root: string, ref: string): string | null =>
|
|
44
49
|
git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`])
|
|
@@ -151,6 +156,15 @@ export const mainCheckout = (cwd: string): string => {
|
|
|
151
156
|
return dirname(commonDirectory)
|
|
152
157
|
}
|
|
153
158
|
|
|
159
|
+
/** `mainCheckout`, null outside a git checkout instead of git's error. */
|
|
160
|
+
export const mainCheckoutOrNull = (cwd: string): string | null => {
|
|
161
|
+
try {
|
|
162
|
+
return mainCheckout(cwd)
|
|
163
|
+
} catch {
|
|
164
|
+
return null
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
154
168
|
/** The top of the checkout `cwd` is in: the worktree itself, not the main checkout. */
|
|
155
169
|
export const worktreeRoot = (cwd: string): string => {
|
|
156
170
|
const top = git(cwd, ['rev-parse', '--show-toplevel'])
|
package/src/plans/github.ts
CHANGED
|
@@ -4,31 +4,40 @@ import { PULL_REQUEST_FIELDS, type PullRequest, parsePullRequests, pullRequestsB
|
|
|
4
4
|
/** Open pull requests by head branch, or none with the reason when `gh` fails. */
|
|
5
5
|
export type PullRequestState = { byBranch: Map<string, PullRequest[]>; errors: string[] }
|
|
6
6
|
|
|
7
|
+
/** What `gh` answered: stdout on success, else the reason. */
|
|
8
|
+
export type GhAnswer = { ok: true; stdout: string } | { ok: false; reason: string }
|
|
9
|
+
|
|
7
10
|
export const noPullRequests = (): PullRequestState => ({ byBranch: new Map(), errors: [] })
|
|
8
11
|
|
|
9
12
|
/** The GitHub host whose pull request links are trusted; `GH_HOST` names an Enterprise server. */
|
|
10
13
|
export const GITHUB_HOST = process.env.GH_HOST ?? 'github.com'
|
|
11
14
|
|
|
12
|
-
const runGh = async (
|
|
13
|
-
const child = Bun.spawn(['gh',
|
|
14
|
-
cwd: root,
|
|
15
|
-
stdout: 'pipe',
|
|
16
|
-
stderr: 'pipe',
|
|
17
|
-
})
|
|
15
|
+
const runGh = async (args: readonly string[], root: string): Promise<GhAnswer> => {
|
|
16
|
+
const child = Bun.spawn(['gh', ...args], { cwd: root, stdout: 'pipe', stderr: 'pipe' })
|
|
18
17
|
const [stdout, stderr, exitCode] = await Promise.all([
|
|
19
18
|
new Response(child.stdout).text(),
|
|
20
19
|
new Response(child.stderr).text(),
|
|
21
20
|
child.exited,
|
|
22
21
|
])
|
|
23
|
-
return { stdout, stderr
|
|
22
|
+
return exitCode === 0 ? { ok: true, stdout } : { ok: false, reason: stderr.trim() || `exit ${exitCode}` }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Runs `gh`; never rejects, also not when `gh` is not installed, and the reason is terminal-safe. */
|
|
26
|
+
const askGh = async (args: readonly string[], root: string): Promise<GhAnswer> => {
|
|
27
|
+
try {
|
|
28
|
+
const answer = await runGh(args, root)
|
|
29
|
+
return answer.ok ? answer : { ok: false, reason: errorText(answer.reason) }
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return { ok: false, reason: errorText(error) }
|
|
32
|
+
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
/** Open pull requests, or none with the reason; never rejects, also not when `gh` is not installed. */
|
|
27
36
|
export const fetchPullRequests = async (root: string): Promise<PullRequestState> => {
|
|
37
|
+
const answer = await askGh(['pr', 'list', '--state', 'open', '--limit', '100', '--json', PULL_REQUEST_FIELDS], root)
|
|
38
|
+
if (!answer.ok) return { byBranch: new Map(), errors: [`gh pr list: ${answer.reason}`] }
|
|
28
39
|
try {
|
|
29
|
-
|
|
30
|
-
if (exitCode !== 0) throw new Error(`gh pr list: ${stderr.trim() || `exit ${exitCode}`}`)
|
|
31
|
-
return { byBranch: pullRequestsByBranch(parsePullRequests(stdout, GITHUB_HOST)), errors: [] }
|
|
40
|
+
return { byBranch: pullRequestsByBranch(parsePullRequests(answer.stdout, GITHUB_HOST)), errors: [] }
|
|
32
41
|
} catch (error) {
|
|
33
42
|
return { byBranch: new Map(), errors: [errorText(error)] }
|
|
34
43
|
}
|