jackherd 1.9.0 → 1.10.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 +30 -0
- package/INSTALL.md +1 -1
- package/README.md +50 -32
- package/dist/{chunk-MCP4XJQH.js → chunk-5MQBCUQ5.js} +9 -4
- package/dist/config.d.ts +39 -4
- package/dist/config.js +67 -26
- package/dist/plan-format.d.ts +45 -6
- package/dist/plan-format.js +46 -6
- package/docs/workflow-dark.svg +67 -63
- package/docs/workflow.svg +67 -63
- package/herdr-plugin/herdr-plugin.toml +1 -1
- package/install.sh +1 -1
- package/kit/hooks/ask-rules.json +15 -0
- package/kit/hooks/hooks/ask-hint/decision.ts +82 -14
- package/kit/hooks/hooks/ask-hint/index.ts +15 -19
- package/kit/hooks/hooks/ask-hint/settings.ts +3 -18
- package/kit/hooks/hooks/git-guard/decision.ts +50 -102
- package/kit/hooks/hooks/merge-guard/always-ask.ts +63 -0
- package/kit/hooks/hooks/merge-guard/{plan-approval-settings.ts → board-settings.ts} +21 -67
- package/kit/hooks/hooks/merge-guard/check-free.ts +20 -0
- package/kit/hooks/hooks/merge-guard/decision.ts +127 -187
- package/kit/hooks/hooks/merge-guard/index.ts +6 -3
- package/kit/hooks/hooks/merge-guard/lane-plan.ts +79 -0
- package/kit/hooks/hooks/merge-guard/run.ts +59 -54
- package/kit/hooks/hooks/merge-guard/settings.ts +13 -1
- package/kit/hooks/hooks/merge-guard/standing-approval.ts +142 -0
- package/kit/hooks/hooks/open-question/index.ts +26 -0
- package/kit/hooks/hooks/open-question/record.ts +135 -0
- package/kit/hooks/hooks/open-question/run.ts +52 -0
- package/kit/hooks/hooks/open-question/store.ts +39 -0
- package/kit/hooks/hooks/sent-file/store.ts +3 -12
- package/kit/hooks/hooks/shared/config.ts +7 -0
- package/kit/hooks/hooks/shared/dialog-answers.ts +9 -9
- package/kit/hooks/hooks/shared/files.ts +7 -0
- package/kit/hooks/hooks/shared/lane.ts +1 -1
- package/kit/hooks/hooks/shared/newest-verdict.ts +10 -0
- package/kit/hooks/hooks/shared/private-directory.ts +56 -9
- package/kit/hooks/hooks/shared/program-position.ts +2 -75
- package/kit/hooks/hooks/shared/shell-aliases.ts +1 -71
- package/kit/hooks/hooks/{ask-hint → shared}/transcript.ts +37 -6
- package/kit/hooks/hooks/{merge-guard → shared}/xargs-program.ts +10 -8
- package/kit/hooks/hooks/task-hint/decision.ts +49 -0
- package/kit/hooks/hooks/task-hint/index.ts +79 -0
- package/kit/hooks/hooks/task-hint/run.ts +62 -0
- package/kit/hooks/hooks/task-hint/store.ts +51 -0
- package/kit/hooks/hooks.json +13 -5
- package/kit/review/agents/skill-review.md +34 -0
- package/kit/review/skills/pre-commit/SKILL.md +1 -1
- package/kit/workflow/skills/follow/SKILL.md +1 -8
- package/kit/workflow/skills/implement/SKILL.md +8 -6
- package/kit/workflow/skills/orchestrate/SKILL.md +210 -433
- package/kit/workflow/skills/orchestrate/handover/decision.ts +43 -8
- package/kit/workflow/skills/orchestrate/handover/index.ts +32 -4
- package/kit/workflow/skills/orchestrate/handover/standing-approval.ts +84 -0
- package/kit/workflow/skills/orchestrate/references/acceptance.md +15 -0
- package/kit/workflow/skills/orchestrate/references/close-lane.md +17 -0
- package/kit/workflow/skills/orchestrate/references/coordinator-handover.md +43 -17
- package/kit/workflow/skills/orchestrate/references/draft-review.md +19 -0
- package/kit/workflow/skills/orchestrate/references/events.md +86 -0
- package/kit/workflow/skills/orchestrate/references/herd.md +6 -6
- package/kit/workflow/skills/orchestrate/references/lane-handover.md +18 -0
- package/kit/workflow/skills/orchestrate/references/lane-session.md +25 -0
- package/kit/workflow/skills/orchestrate/references/lane-setup.md +37 -0
- package/kit/workflow/skills/orchestrate/references/plan-commit.md +22 -10
- package/kit/workflow/skills/orchestrate/references/sensitive-input.md +5 -7
- package/kit/workflow/skills/plan/SKILL.md +6 -5
- package/kit/workflow/skills/plan/references/template-English.md +4 -4
- package/kit/workflow/skills/plan/references/template-German.md +4 -4
- package/package.json +3 -1
- package/recipes/README.md +2 -1
- package/recipes/sources.md +1 -1
- package/schemas/jackherd.schema.json +59 -5
- package/src/check/agent-text-reviewers.ts +23 -0
- package/src/check/command.ts +2 -0
- package/src/check/plan-structure-check.ts +49 -2
- package/src/check/plan.ts +8 -1
- package/src/check/schema.ts +9 -0
- package/src/check/skill-budget-defaults.ts +55 -0
- package/src/check/skill-budgets.ts +185 -0
- package/src/cli.ts +1 -0
- package/src/config/auto-window.ts +8 -0
- package/src/config/link-kinds.ts +7 -1
- package/src/config/schema.ts +58 -24
- package/src/lane/close-board.ts +106 -0
- package/src/lane/close-check.ts +183 -0
- package/src/lane/close-command-line.ts +11 -0
- package/src/lane/close-command.ts +217 -0
- package/src/lane/close-options.ts +43 -0
- package/src/lane/close-survey.ts +83 -0
- package/src/lane/close.ts +141 -0
- package/src/lane/command.ts +13 -0
- package/src/lane-prompt/build.ts +74 -0
- package/src/lane-prompt/command.ts +87 -0
- package/src/lane-prompt/input.ts +116 -0
- package/src/lane-prompt/options.ts +68 -0
- package/src/lane-prompt/texts.ts +101 -0
- package/src/plan-format/clock.ts +8 -0
- package/src/plan-format/dependencies.ts +7 -4
- package/src/plan-format/index.ts +1 -0
- package/src/plan-format/short-names.ts +71 -0
- package/src/plan-format/waiting.ts +7 -2
- package/src/plans/appointment-rows.ts +59 -0
- package/src/plans/ask-coordinator.ts +77 -0
- package/src/plans/ask-target.ts +25 -0
- package/src/plans/child-stop.ts +51 -0
- package/src/plans/closable-records.ts +34 -0
- package/src/plans/command.ts +3 -2
- package/src/plans/fetch.ts +26 -3
- package/src/plans/git.ts +19 -5
- package/src/plans/herd-claim.ts +173 -0
- package/src/plans/herd-memory.ts +36 -25
- package/src/plans/lane-plans.ts +44 -13
- package/src/plans/lane-summary.ts +253 -45
- package/src/plans/layout-phase.ts +29 -7
- package/src/plans/layout-summary.ts +89 -18
- package/src/plans/layout.ts +262 -68
- package/src/plans/link-chips.ts +1 -0
- package/src/plans/live.ts +107 -20
- package/src/plans/phase-ids.ts +8 -0
- package/src/plans/phase-source.ts +15 -0
- package/src/plans/plan-cache.ts +28 -0
- package/src/plans/plan-heads.ts +54 -0
- package/src/plans/pull-requests.ts +17 -2
- package/src/plans/question-records.ts +48 -0
- package/src/plans/questions-read.ts +13 -0
- package/src/plans/read-cache.ts +8 -0
- package/src/plans/record-id.ts +4 -0
- package/src/plans/restart-decision.ts +13 -4
- package/src/plans/selection.ts +98 -18
- package/src/plans/sent-files-read.ts +6 -15
- package/src/plans/sent-files.ts +7 -14
- package/src/plans/settings.ts +2 -1
- package/src/plans/signalled-phase.ts +42 -0
- package/src/plans/signals-read.ts +12 -4
- package/src/plans/snapshot.ts +85 -62
- package/src/plans/sprint-export.ts +11 -11
- package/src/plans/sprint-page.ts +5 -5
- package/src/plans/subagent-phases.ts +95 -0
- package/src/plans/subagent-tasks.ts +51 -0
- package/src/plans/subagents-read.ts +66 -17
- package/src/plans/subagents.ts +64 -6
- package/src/plans/supervisor.ts +14 -4
- package/src/plans/symbols.ts +3 -0
- package/src/plans/task-name.ts +34 -0
- package/src/plans/texts.ts +23 -6
- package/src/plans/view.ts +17 -9
- package/src/plans/waiting-click.ts +192 -37
- package/src/plans/waiting-records.ts +39 -0
- package/src/plans/waiting-window.ts +8 -0
- package/src/preview/command.ts +25 -3
- package/src/shared/private-location.ts +89 -0
- package/src/shared/stat-cache.ts +48 -0
- package/src/sync/kit-source.ts +29 -10
- package/src/sync/kit.ts +2 -0
- package/src/sync/manifest.ts +2 -0
- package/src/sync/plan-ask-rules.ts +94 -0
- package/src/sync/plan-hooks.ts +2 -0
- package/src/sync/render.ts +3 -3
- package/src/sync/settings-hooks.ts +4 -1
- package/src/sync/sync-plan.ts +1 -0
- package/src/sync/sync.ts +24 -3
- package/src/task-signals/claude-read.ts +27 -10
- package/src/terminal/text.ts +8 -3
- package/src/version/skill-diff.ts +46 -0
- package/src/vocabulary/index.ts +16 -6
- package/src/waiting/command.ts +22 -7
- package/src/watch/appointments.ts +1 -2
- package/src/watch/asking-lanes.ts +40 -0
- package/src/watch/base-tip.ts +11 -0
- package/src/watch/command.ts +330 -105
- package/src/watch/heartbeat-progress.ts +6 -18
- package/src/watch/kit-update.ts +28 -9
- package/src/watch/lane-name.ts +6 -0
- package/src/watch/lane-progress.ts +40 -8
- package/src/watch/lane-report-file.ts +20 -5
- package/src/watch/lane-report.ts +32 -4
- package/src/watch/lane-sources.ts +31 -3
- package/src/watch/main-checkout.ts +34 -0
- package/src/watch/plan-badges-read.ts +13 -7
- package/src/watch/pull-requests.ts +6 -2
- package/src/watch/reference-paths.ts +87 -0
- package/src/watch/running-subagents.ts +43 -0
- package/src/watch/skill-change.ts +124 -32
- package/src/watch/source-change.ts +48 -0
- package/src/watch/sources.ts +6 -3
- package/src/watch/stream-output.ts +4 -3
- package/src/watch/task-parallel-auto.ts +208 -0
- package/src/watch/task-parallel-data-paths.ts +46 -0
- package/src/watch/task-parallel-input.ts +5 -15
- package/src/watch/task-parallel-read.ts +3 -1
- package/src/watch/task-parallel.ts +36 -7
- package/src/watch/task-signal-missing.ts +69 -0
- package/src/watch/task-signal-read.ts +29 -0
- package/src/watch/texts.ts +10 -0
- package/src/watch/update-available.ts +6 -3
- package/src/watch/watch-events.ts +23 -0
- package/src/watch/watcher-lock.ts +25 -29
- package/kit/hooks/hooks/merge-guard/plan-approval-record.ts +0 -23
- package/kit/hooks/hooks/merge-guard/plan-approval-sources.ts +0 -196
- package/kit/hooks/hooks/merge-guard/plan-approval.ts +0 -168
- package/kit/hooks/hooks/merge-guard/plan-growth.ts +0 -40
- package/kit/hooks/hooks/merge-guard/plan-pointers.ts +0 -194
- package/kit/hooks/hooks/shared/command-text-runners.ts +0 -71
- package/kit/hooks/hooks/shared/plan-open-phases.ts +0 -114
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type PhaseDependency, parseDependencyTable, writeSetOf } from '../plan-format/dependencies'
|
|
2
|
+
import { parseSprintLanes, phaseLabel, resolvePlanPath, type SprintLane } from '../plan-format/lanes'
|
|
3
|
+
import { parsePlanPhases } from '../plan-format/phases'
|
|
4
|
+
import { isPhaseFinished } from '../plan-format/progress'
|
|
5
|
+
import type { PlanLanguage } from '../vocabulary'
|
|
6
|
+
import type { LanePhase, LanePlan, LanePromptInput } from './build'
|
|
7
|
+
|
|
8
|
+
/** The lane to prompt, the hand-over file of a restart (null for a fresh start) and the plan language. */
|
|
9
|
+
export type LanePromptRequest = { lane: string; handover: string | null; language: PlanLanguage }
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The board's text, its directory from the repository root, which its plan links are relative to, and the path a
|
|
13
|
+
* refusal names it by.
|
|
14
|
+
*/
|
|
15
|
+
export type BoardSource = { text: string; directory: string; path: string }
|
|
16
|
+
|
|
17
|
+
/** A plan's text by its path from the repository root; null when it cannot be read. */
|
|
18
|
+
export type ReadPlan = (path: string) => string | null
|
|
19
|
+
|
|
20
|
+
export type LanePromptResult = { kind: 'prompt'; input: LanePromptInput } | { kind: 'refused'; reason: string }
|
|
21
|
+
|
|
22
|
+
type PlanSteps = { path: string; ids: string[] }
|
|
23
|
+
|
|
24
|
+
type Refusal = { reason: string }
|
|
25
|
+
|
|
26
|
+
type PlanOutcome = { plan: LanePlan } | Refusal
|
|
27
|
+
|
|
28
|
+
type PlansOutcome = { plans: LanePlan[] } | Refusal
|
|
29
|
+
|
|
30
|
+
const refused = (reason: string): LanePromptResult => ({ kind: 'refused', reason })
|
|
31
|
+
|
|
32
|
+
/** The lane's plans by path in board order, each with the phase ids its rows name, rows of one plan merged. */
|
|
33
|
+
const planStepsOf = (lane: SprintLane, directory: string): PlanSteps[] => {
|
|
34
|
+
const byPath = new Map<string, string[]>()
|
|
35
|
+
for (const step of lane.steps) {
|
|
36
|
+
if (step.planHref === null || step.phaseIds.length === 0) continue
|
|
37
|
+
const path = resolvePlanPath(directory, step.planHref)
|
|
38
|
+
byPath.set(path, [...new Set([...(byPath.get(path) ?? []), ...step.phaseIds])])
|
|
39
|
+
}
|
|
40
|
+
return [...byPath].map(([path, ids]) => ({ path, ids }))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The write set of the phase `id`; null without a row, for an unknown target or a cycle. */
|
|
44
|
+
const phaseWriteSet = (rows: readonly PhaseDependency[], id: string): string[] | null => {
|
|
45
|
+
const row = rows.find((candidate) => candidate.id === id)
|
|
46
|
+
return row ? writeSetOf(row, new Map(rows.map((candidate) => [candidate.id, candidate]))) : null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A plan's text on the lane branch (null without a worktree or a copy there) and in the main checkout. */
|
|
50
|
+
type PlanTexts = { lane: string | null; main: string | null }
|
|
51
|
+
|
|
52
|
+
const finishedIdsOf = (text: string | null, language: PlanLanguage): Set<string> =>
|
|
53
|
+
new Set(
|
|
54
|
+
text === null ? [] : parsePlanPhases(text, language).flatMap((phase) => (isPhaseFinished(phase) ? [phase.id] : [])),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The plan's open named phases, read from the lane branch when it has a copy, which holds the phases the lane wrote
|
|
59
|
+
* and the ticks it set; a phase finished in either copy is left out, so a lane branch behind the main checkout does not
|
|
60
|
+
* bring back what another lane finished.
|
|
61
|
+
*/
|
|
62
|
+
const lanePlanOf = (steps: PlanSteps, texts: PlanTexts, text: string, language: PlanLanguage): PlanOutcome => {
|
|
63
|
+
const phases = parsePlanPhases(text, language)
|
|
64
|
+
const named = steps.ids.map((id) => ({ id, phase: phases.find((phase) => phase.id === id) }))
|
|
65
|
+
const missing = named.find(({ phase }) => phase === undefined)
|
|
66
|
+
if (missing) return { reason: `${steps.path} has no phase ${phaseLabel(missing.id)}` }
|
|
67
|
+
const rows = parseDependencyTable(text, language) ?? []
|
|
68
|
+
const finishedInMain = finishedIdsOf(texts.main, language)
|
|
69
|
+
const open = named.filter(
|
|
70
|
+
({ id, phase }) => phase !== undefined && !isPhaseFinished(phase) && !finishedInMain.has(id),
|
|
71
|
+
)
|
|
72
|
+
const lanePhases: LanePhase[] = open.map(({ id }) => ({ id, writes: phaseWriteSet(rows, id) }))
|
|
73
|
+
return { plan: { path: steps.path, phases: lanePhases } }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const plansOf = (
|
|
77
|
+
steps: readonly PlanSteps[],
|
|
78
|
+
readers: { main: ReadPlan; lane: ReadPlan },
|
|
79
|
+
language: PlanLanguage,
|
|
80
|
+
): PlansOutcome => {
|
|
81
|
+
const plans: LanePlan[] = []
|
|
82
|
+
for (const step of steps) {
|
|
83
|
+
const texts = { lane: readers.lane(step.path), main: readers.main(step.path) }
|
|
84
|
+
const text = texts.lane ?? texts.main
|
|
85
|
+
if (text === null) return { reason: `cannot read the plan ${step.path}` }
|
|
86
|
+
const outcome = lanePlanOf(step, texts, text, language)
|
|
87
|
+
if ('reason' in outcome) return outcome
|
|
88
|
+
if (outcome.plan.phases.length > 0) plans.push(outcome.plan)
|
|
89
|
+
}
|
|
90
|
+
return { plans }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What the lane's prompt is built from: its open row of the board's lanes table (port, plans, phases), each named
|
|
95
|
+
* phase that is not finished, and the write set of each from its plan's dependency table. A plan is read from the lane
|
|
96
|
+
* branch (`readLanePlan`) when it has a copy, else from the main checkout (`readPlan`). Refused, with the reason,
|
|
97
|
+
* for a lane without a row, a closed lane, rows that name no phase, a plan that cannot be read or lacks a phase the
|
|
98
|
+
* row names, and a lane whose phases are all finished.
|
|
99
|
+
*/
|
|
100
|
+
export const lanePromptInputOf = (
|
|
101
|
+
request: LanePromptRequest,
|
|
102
|
+
board: BoardSource,
|
|
103
|
+
readPlan: ReadPlan,
|
|
104
|
+
readLanePlan: ReadPlan = () => null,
|
|
105
|
+
): LanePromptResult => {
|
|
106
|
+
const sprintLane = parseSprintLanes(board.text, request.language).find((candidate) => candidate.name === request.lane)
|
|
107
|
+
if (!sprintLane) return refused(`no row for lane ${request.lane} in ${board.path}`)
|
|
108
|
+
if (sprintLane.closed) return refused(`lane ${request.lane} is closed in ${board.path}`)
|
|
109
|
+
const steps = planStepsOf(sprintLane, board.directory)
|
|
110
|
+
if (steps.length === 0) return refused(`the row of lane ${request.lane} in ${board.path} links no plan with a phase`)
|
|
111
|
+
const found = plansOf(steps, { main: readPlan, lane: readLanePlan }, request.language)
|
|
112
|
+
if ('reason' in found) return refused(found.reason)
|
|
113
|
+
if (found.plans.length === 0) return refused(`every phase of lane ${request.lane} is finished`)
|
|
114
|
+
const { lane, handover, language } = request
|
|
115
|
+
return { kind: 'prompt', input: { language, lane, plans: found.plans, port: sprintLane.port, handover } }
|
|
116
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CLI_NAME } from '../version/release'
|
|
2
|
+
import { SAFE_LANE_NAME } from '../watch/lane-name'
|
|
3
|
+
|
|
4
|
+
/** What `jh lane prompt` was asked for; null where an option was left out. */
|
|
5
|
+
export type LanePromptOptions = { lane: string; boardPath: string | null; out: string | null; handover: string | null }
|
|
6
|
+
|
|
7
|
+
const VALUE_OPTIONS = ['--board', '--out', '--handover'] as const
|
|
8
|
+
|
|
9
|
+
type ValueOption = (typeof VALUE_OPTIONS)[number]
|
|
10
|
+
|
|
11
|
+
const SUBCOMMAND = 'prompt'
|
|
12
|
+
|
|
13
|
+
export const LANE_PROMPT_USAGE = `usage: ${CLI_NAME} lane prompt <lane> [--board <board.md>] [--out <file>] [--handover <file>]
|
|
14
|
+
|
|
15
|
+
Writes the prompt that starts the lane, from its row in the board and its plan, and prints the file's path.
|
|
16
|
+
--board <board.md> the board to read; without it the board is picked as for ${CLI_NAME} herd
|
|
17
|
+
--out <file> where to write the prompt; default .claude/handover/<lane>-prompt.md in the main checkout
|
|
18
|
+
--handover <file> a restart after a hand-over: the lane reads this file first and continues with its next step`
|
|
19
|
+
|
|
20
|
+
const usageError = (message: string): Error => new Error(`${message}\n${LANE_PROMPT_USAGE}`)
|
|
21
|
+
|
|
22
|
+
const isValueOption = (arg: string): arg is ValueOption => (VALUE_OPTIONS as readonly string[]).includes(arg)
|
|
23
|
+
|
|
24
|
+
const splitArguments = (args: readonly string[]): { values: Map<ValueOption, string>; words: string[] } => {
|
|
25
|
+
const values = new Map<ValueOption, string>()
|
|
26
|
+
const words: string[] = []
|
|
27
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
28
|
+
const arg = args[i]
|
|
29
|
+
if (!arg.startsWith('--')) {
|
|
30
|
+
words.push(arg)
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
if (!isValueOption(arg)) throw usageError(`unknown option ${arg}`)
|
|
34
|
+
const value = args[i + 1]
|
|
35
|
+
if (value === undefined || value.startsWith('--')) throw usageError(`${arg} needs a value`)
|
|
36
|
+
values.set(arg, value)
|
|
37
|
+
i += 1
|
|
38
|
+
}
|
|
39
|
+
return { values, words }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const laneOf = (words: readonly string[]): string => {
|
|
43
|
+
const [subcommand, ...lanes] = words
|
|
44
|
+
if (subcommand !== SUBCOMMAND)
|
|
45
|
+
throw usageError(subcommand ? `unknown subcommand ${subcommand}` : 'the subcommand is required')
|
|
46
|
+
if (lanes.length === 0) throw usageError('the lane is required')
|
|
47
|
+
if (lanes.length > 1) throw usageError(`one lane at most, got ${lanes.join(' ')}`)
|
|
48
|
+
if (!SAFE_LANE_NAME.test(lanes[0])) throw usageError(`${lanes[0]} is no lane name (letters, digits, . _ -)`)
|
|
49
|
+
return lanes[0]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The hand-over path as the prompt quotes it in backticks: one line without a backtick. */
|
|
53
|
+
const handoverOf = (value: string | undefined): string | null => {
|
|
54
|
+
if (value === undefined) return null
|
|
55
|
+
if (/[`\r\n]/.test(value)) throw usageError('--handover needs a path without backticks or line breaks')
|
|
56
|
+
return value
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Reads `prompt <lane> [--board …] [--out …] [--handover …]` in any order; throws on a wrong command line. */
|
|
60
|
+
export const parseLanePromptOptions = (args: readonly string[]): LanePromptOptions => {
|
|
61
|
+
const { values, words } = splitArguments(args)
|
|
62
|
+
return {
|
|
63
|
+
lane: laneOf(words),
|
|
64
|
+
boardPath: values.get('--board') ?? null,
|
|
65
|
+
out: values.get('--out') ?? null,
|
|
66
|
+
handover: handoverOf(values.get('--handover')),
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { PLAN_LANGUAGE, type PlanLanguage } from '../vocabulary'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The sentences of a lane prompt in one language, after `/orchestrate` § 1. The opening words and the column name of
|
|
5
|
+
* a write set come from the vocabulary; the report file keeps its `## Questions` heading in every language, since the
|
|
6
|
+
* watcher finds the section by that word.
|
|
7
|
+
*/
|
|
8
|
+
export type LanePromptTexts = {
|
|
9
|
+
answersTo: string
|
|
10
|
+
phasesIntro: string
|
|
11
|
+
noWrites: string
|
|
12
|
+
wholeRepository: string
|
|
13
|
+
editInside: string
|
|
14
|
+
writeTools: string
|
|
15
|
+
port: (port: number) => string
|
|
16
|
+
noPort: string
|
|
17
|
+
blocking: string
|
|
18
|
+
mustNot: string
|
|
19
|
+
commit: string
|
|
20
|
+
report: (reportPath: string) => string
|
|
21
|
+
textBlock: string
|
|
22
|
+
secret: string
|
|
23
|
+
askRule: string
|
|
24
|
+
approvalGate: string
|
|
25
|
+
helper: (helperName: string) => string
|
|
26
|
+
helperPurpose: string
|
|
27
|
+
start: string
|
|
28
|
+
restart: (handoverPath: string) => string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const LANE_PROMPT_TEXTS: Record<PlanLanguage, LanePromptTexts> = {
|
|
32
|
+
[PLAN_LANGUAGE.en]: {
|
|
33
|
+
answersTo: 'You answer to the coordinator, not to the user.',
|
|
34
|
+
phasesIntro: 'Your plan and phases:',
|
|
35
|
+
noWrites: 'no Writes set in the plan',
|
|
36
|
+
wholeRepository: 'the whole repository',
|
|
37
|
+
editInside:
|
|
38
|
+
'Nothing outside the Writes set of your phases is edited, except the task lines of your phases in the plan: tick a finished one right away, by an Edit of exactly that line.',
|
|
39
|
+
writeTools:
|
|
40
|
+
'Write code and tests with Write and Edit, never through a here-document or a script in Bash: such a call shows the reviewer no diff, and an unquoted or unreadable one can stop at a guard.',
|
|
41
|
+
port: (port) =>
|
|
42
|
+
`Port ${port}: the coordinator runs your dev server in its own pane; look at your visible changes there (\`/implement\` Step 4b) and never start a server in your own shell.`,
|
|
43
|
+
noPort:
|
|
44
|
+
'No port: this lane has no dev server of its own. Never start a server in your own shell; ask the coordinator when you need one.',
|
|
45
|
+
blocking:
|
|
46
|
+
'Mark every question of yours `blocking` or `not blocking`. A blocking one stops the step it decides; for a not blocking one leave a `TODO` at its spot and work on, building neither your recommendation nor another option as decided.',
|
|
47
|
+
mustNot:
|
|
48
|
+
'Without the user’s approval you push no database migration and write nothing against a shared environment (stage, production); you never run `git reset` or `git stash` on shared refs.',
|
|
49
|
+
commit: 'Ask before every commit (`/pre-commit`); no push, PR or merge without approval.',
|
|
50
|
+
report: (reportPath) =>
|
|
51
|
+
`The report at the end of each step goes to \`${reportPath}\` in the worktree, in the short form: one line of diff stat, one line per check with its numbers, open points, questions as a text block under the heading \`## Questions\` (whatever the report’s language: the watcher finds the section by that word and shows it whole); everything else is in the plan, by reference.`,
|
|
52
|
+
textBlock:
|
|
53
|
+
'Every question to the coordinator is a text block at the end of your turn, never a dialog (`AskUserQuestion`), also where a skill or a project rule asks for one, the commit confirmation of `/pre-commit` included: the question with the situation, the problem and what each option leads to, in everyday words (the user may not know your terms), the options, your recommendation, the evidence at `file:line`.',
|
|
54
|
+
secret:
|
|
55
|
+
'A value only the user knows (a secret, password, token or one-time code) never passes through you, your arguments, your output or a file you write: ask the coordinator for the step as a question.',
|
|
56
|
+
askRule:
|
|
57
|
+
'A tool that asks for approval on every call (an ask rule, such as a database query tool or a project CLI) gets as few calls as possible: bundle the steps into one call (one script, one query) instead of one call per step.',
|
|
58
|
+
approvalGate:
|
|
59
|
+
'A call that would open a permission dialog waits for the coordinator: the approval gate holds it and the coordinator asks the user. Denied with “approval pending”, retry the same call once the coordinator says it is approved; denied by the user, do not retry it.',
|
|
60
|
+
helper: (helperName) =>
|
|
61
|
+
`A helper agent in a pane of your own (a measurement, a probe session) is announced to the coordinator before it starts, as a question at the end of your turn: what it does, how long, and which temporary settings it uses. Once approved, name it \`${helperName}\` (\`herdr agent rename\`), so the watcher watches it with your lane, and close it yourself when it is done: \`/exit\`, then \`herdr pane close\`, and remove every temporary file it needed.`,
|
|
62
|
+
helperPurpose: '<purpose>',
|
|
63
|
+
start: 'Start: run `/implement` for your phases, in the order above.',
|
|
64
|
+
restart: (handoverPath) => `Start: read \`${handoverPath}\` first and continue with the next step it names.`,
|
|
65
|
+
},
|
|
66
|
+
[PLAN_LANGUAGE.de]: {
|
|
67
|
+
answersTo: 'Du antwortest dem Koordinator, nicht dem User.',
|
|
68
|
+
phasesIntro: 'Dein Plan und deine Phasen:',
|
|
69
|
+
noWrites: 'keine Schreibt-Menge im Plan',
|
|
70
|
+
wholeRepository: 'das ganze Repository',
|
|
71
|
+
editInside:
|
|
72
|
+
'Außerhalb der Schreibt-Menge deiner Phasen änderst du nichts, außer den Aufgabenzeilen deiner Phasen im Plan: eine erledigte hakst du sofort ab, per Edit auf genau diese Zeile.',
|
|
73
|
+
writeTools:
|
|
74
|
+
'Code und Tests schreibst du mit Write und Edit, nie per Heredoc oder Skript in Bash: ein solcher Aufruf zeigt dem Prüfer keinen Diff, und ein ungequoteter oder unlesbarer kann an einem Wächter hängen bleiben.',
|
|
75
|
+
port: (port) =>
|
|
76
|
+
`Port ${port}: Der Koordinator betreibt deinen Dev-Server in seinem eigenen Pane; deine sichtbaren Änderungen siehst du dort an (\`/implement\` Step 4b) und startest nie einen Server in deiner eigenen Shell.`,
|
|
77
|
+
noPort:
|
|
78
|
+
'Kein Port: Diese Spur hat keinen eigenen Dev-Server. Starte nie einen Server in deiner eigenen Shell; brauchst du einen, frag den Koordinator.',
|
|
79
|
+
blocking:
|
|
80
|
+
'Markiere jede deiner Fragen mit `blocking` oder `not blocking`. Eine blockierende hält den Schritt an, den sie entscheidet; bei einer nicht blockierenden lässt du an ihrer Stelle ein `TODO` und arbeitest weiter, ohne deine Empfehlung oder eine andere Option als entschieden zu bauen.',
|
|
81
|
+
mustNot:
|
|
82
|
+
'Ohne Freigabe des Users pushst du keine Datenbank-Migration und schreibst nichts gegen eine geteilte Umgebung (Stage, Produktion); `git reset` und `git stash` auf geteilten Refs führst du nie aus.',
|
|
83
|
+
commit: 'Vor jedem Commit fragst du (`/pre-commit`); kein Push, kein PR und kein Merge ohne Freigabe.',
|
|
84
|
+
report: (reportPath) =>
|
|
85
|
+
`Den Bericht am Ende jedes Schritts schreibst du nach \`${reportPath}\` im Worktree, in der Kurzform: eine Zeile Diff-Stat, eine Zeile je Check mit seinen Zahlen, offene Punkte, Fragen als Textblock unter der Überschrift \`## Questions\` (in jeder Berichtssprache: der Watcher findet den Abschnitt an diesem Wort und zeigt ihn ganz); alles andere steht im Plan, per Verweis.`,
|
|
86
|
+
textBlock:
|
|
87
|
+
'Jede Frage an den Koordinator ist ein Textblock am Ende deines Turns, nie ein Dialog (`AskUserQuestion`), auch wo ein Skill oder eine Projektregel einen verlangt, die Commit-Bestätigung von `/pre-commit` eingeschlossen: die Frage mit der Lage, dem Problem und wohin jede Option führt, in Alltagsworten (der User kennt deine Begriffe vielleicht nicht), die Optionen, deine Empfehlung, der Beleg als `datei:zeile`.',
|
|
88
|
+
secret:
|
|
89
|
+
'Ein Wert, den nur der User kennt (ein Geheimnis, Passwort, Token oder Einmalcode), läuft nie über dich, deine Argumente, deine Ausgabe oder eine Datei, die du schreibst: bitte den Koordinator mit einer Frage um diesen Schritt.',
|
|
90
|
+
askRule:
|
|
91
|
+
'Ein Werkzeug, das bei jedem Aufruf um Freigabe fragt (eine Ask-Regel, etwa ein Datenbank-Abfragewerkzeug oder eine Projekt-CLI), bekommt so wenige Aufrufe wie möglich: bündle die Schritte in einen Aufruf (ein Skript, eine Abfrage) statt eines Aufrufs je Schritt.',
|
|
92
|
+
approvalGate:
|
|
93
|
+
'Ein Aufruf, der einen Erlaubnis-Dialog öffnen würde, wartet auf den Koordinator: Das Approval-Gate hält ihn an, und der Koordinator fragt den User. Abgelehnt mit „approval pending“: denselben Aufruf wiederholen, sobald der Koordinator ihn als freigegeben meldet; vom User abgelehnt: nicht wiederholen.',
|
|
94
|
+
helper: (helperName) =>
|
|
95
|
+
`Einen Helfer-Agenten in einem eigenen Pane (eine Messung, eine Probesitzung) meldest du dem Koordinator an, bevor er startet, als Frage am Ende deines Turns: was er tut, wie lange, und welche temporären Einstellungen er nutzt. Nach der Freigabe benennst du ihn \`${helperName}\` (\`herdr agent rename\`), damit der Watcher ihn mit deiner Spur beobachtet, und schließt ihn selbst, wenn er fertig ist: \`/exit\`, dann \`herdr pane close\`, und entferne jede temporäre Datei, die er brauchte.`,
|
|
96
|
+
helperPurpose: '<zweck>',
|
|
97
|
+
start: 'Start: Führe `/implement` für deine Phasen aus, in der Reihenfolge oben.',
|
|
98
|
+
restart: (handoverPath) =>
|
|
99
|
+
`Start: Lies zuerst \`${handoverPath}\` und mach mit dem nächsten Schritt weiter, den sie nennt.`,
|
|
100
|
+
},
|
|
101
|
+
}
|
package/src/plan-format/clock.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export const MS_PER_MINUTE = 60_000
|
|
2
2
|
|
|
3
|
+
export const DAY_MS = 86_400_000
|
|
4
|
+
|
|
3
5
|
/** A day, month, hour or minute with a leading zero: `7` → `07`. */
|
|
4
6
|
export const twoDigits = (value: number): string => String(value).padStart(2, '0')
|
|
7
|
+
|
|
8
|
+
/** A time as the for-you rows show it: `DD.MM. HH:MM`. */
|
|
9
|
+
export const clockText = (at: number): string => {
|
|
10
|
+
const date = new Date(at)
|
|
11
|
+
return `${twoDigits(date.getDate())}.${twoDigits(date.getMonth() + 1)}. ${twoDigits(date.getHours())}:${twoDigits(date.getMinutes())}`
|
|
12
|
+
}
|
|
@@ -200,18 +200,21 @@ const longestChain = (chains: readonly string[][]): string[] =>
|
|
|
200
200
|
const mergeSets = (sets: readonly (string[] | null)[]): string[] | null =>
|
|
201
201
|
sets.some((set) => set === null) ? null : sets.flatMap((set) => set ?? [])
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
const writeSetOf = (
|
|
203
|
+
const writeSetWithin = (
|
|
205
204
|
row: PhaseDependency,
|
|
206
205
|
byId: ReadonlyMap<string, PhaseDependency>,
|
|
207
206
|
chain: readonly string[],
|
|
208
207
|
): string[] | null => {
|
|
209
208
|
if (chain.includes(row.id)) return null
|
|
210
209
|
const targets = row.writesLike.map((id) => byId.get(id))
|
|
211
|
-
const like = mergeSets(targets.map((target) => (target ?
|
|
210
|
+
const like = mergeSets(targets.map((target) => (target ? writeSetWithin(target, byId, [...chain, row.id]) : null)))
|
|
212
211
|
return like === null ? null : [...row.writes, ...like]
|
|
213
212
|
}
|
|
214
213
|
|
|
214
|
+
/** The paths a phase writes, those of every phase its `like` cell names included; null for an unknown target or a cycle. */
|
|
215
|
+
export const writeSetOf = (row: PhaseDependency, byId: ReadonlyMap<string, PhaseDependency>): string[] | null =>
|
|
216
|
+
writeSetWithin(row, byId, [])
|
|
217
|
+
|
|
215
218
|
const overlaps = (left: string, right: string): boolean =>
|
|
216
219
|
left === '' || right === '' || left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`)
|
|
217
220
|
|
|
@@ -228,7 +231,7 @@ const collides = (first: Candidate, second: Candidate): boolean =>
|
|
|
228
231
|
sharesMarker(first, second) || first.writes.some((path) => second.writes.some((other) => overlaps(path, other)))
|
|
229
232
|
|
|
230
233
|
const candidateOf = (row: PhaseDependency, byId: ReadonlyMap<string, PhaseDependency>): Candidate[] => {
|
|
231
|
-
const writes = writeSetOf(row, byId
|
|
234
|
+
const writes = writeSetOf(row, byId)
|
|
232
235
|
if (writes === null || writes.length === 0) return []
|
|
233
236
|
const releases = [...new Set([...row.releases, ...releasedByFiles(writes)])]
|
|
234
237
|
return [{ id: row.id, writes, serialMarkers: row.serialMarkers, releases }]
|
package/src/plan-format/index.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PlanLanguage } from '../vocabulary'
|
|
2
|
+
import { endsPhase, isOpenCheckboxLine, isReviewGateLine, type PhaseHeading, phaseHeadings } from './phases'
|
|
3
|
+
|
|
4
|
+
/** Characters a task's short name may have, so the herd shows it whole. */
|
|
5
|
+
export const SHORT_NAME_LIMIT = 40
|
|
6
|
+
|
|
7
|
+
/** Characters a phase title may have; the title is the phase's name. */
|
|
8
|
+
export const PHASE_TITLE_LIMIT = 50
|
|
9
|
+
|
|
10
|
+
export const SHORT_NAME_PROBLEM = { missing: 'missing', long: 'long' } as const
|
|
11
|
+
|
|
12
|
+
/** What is wrong with an open task's short name: none at all, or one of `length` characters over the limit. */
|
|
13
|
+
export type ShortNameProblem =
|
|
14
|
+
| { problem: typeof SHORT_NAME_PROBLEM.missing }
|
|
15
|
+
| { problem: typeof SHORT_NAME_PROBLEM.long; length: number }
|
|
16
|
+
|
|
17
|
+
/** An open task (1-based line) of phase `phase` whose short name is missing or too long. */
|
|
18
|
+
export type ShortNameFinding = { line: number; phase: string } & ShortNameProblem
|
|
19
|
+
|
|
20
|
+
/** A phase heading whose title has `length` characters, over the limit. */
|
|
21
|
+
export type LongPhaseTitle = PhaseHeading & { length: number }
|
|
22
|
+
|
|
23
|
+
/** `- [ ] **Name**: …`, the name in group 1. */
|
|
24
|
+
const SHORT_NAME = /^\s*[-*]\s+\[ \]\s+\*\*(.+?)\*\*:/
|
|
25
|
+
|
|
26
|
+
const characterCount = (text: string): number => [...text].length
|
|
27
|
+
|
|
28
|
+
const shortNameProblem = (line: string): ShortNameProblem | null => {
|
|
29
|
+
const name = line.match(SHORT_NAME)?.[1]
|
|
30
|
+
if (name === undefined) return { problem: SHORT_NAME_PROBLEM.missing }
|
|
31
|
+
const length = characterCount(name)
|
|
32
|
+
return length > SHORT_NAME_LIMIT ? { problem: SHORT_NAME_PROBLEM.long, length } : null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The open tasks a change wrote (a line not in `previousLines`) that do not start with `**Name**:` or whose name is
|
|
37
|
+
* longer than `SHORT_NAME_LIMIT`. Only tasks of a phase section before its review gate count: a gate item keeps its
|
|
38
|
+
* own form.
|
|
39
|
+
*/
|
|
40
|
+
export const shortNameFindings = (
|
|
41
|
+
markdown: string,
|
|
42
|
+
language: PlanLanguage,
|
|
43
|
+
previousLines: ReadonlySet<string>,
|
|
44
|
+
): ShortNameFinding[] => {
|
|
45
|
+
const headings = new Map(phaseHeadings(markdown, language).map((heading) => [heading.line, heading.id]))
|
|
46
|
+
const found: ShortNameFinding[] = []
|
|
47
|
+
let phase: string | null = null
|
|
48
|
+
for (const [index, line] of markdown.split('\n').entries()) {
|
|
49
|
+
const heading = headings.get(index + 1)
|
|
50
|
+
if (heading !== undefined) phase = heading
|
|
51
|
+
else if (endsPhase(line) || isReviewGateLine(line)) phase = null
|
|
52
|
+
else if (phase !== null && isOpenCheckboxLine(line) && !previousLines.has(line)) {
|
|
53
|
+
const problem = shortNameProblem(line)
|
|
54
|
+
if (problem) found.push({ line: index + 1, phase, ...problem })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return found
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The phase headings a change wrote whose title is longer than `PHASE_TITLE_LIMIT`. */
|
|
61
|
+
export const longPhaseTitles = (
|
|
62
|
+
markdown: string,
|
|
63
|
+
language: PlanLanguage,
|
|
64
|
+
previousLines: ReadonlySet<string>,
|
|
65
|
+
): LongPhaseTitle[] => {
|
|
66
|
+
const lines = markdown.split('\n')
|
|
67
|
+
return phaseHeadings(markdown, language)
|
|
68
|
+
.filter(({ line }) => !previousLines.has(lines[line - 1] ?? ''))
|
|
69
|
+
.map((heading) => ({ ...heading, length: characterCount(heading.title) }))
|
|
70
|
+
.filter(({ length }) => length > PHASE_TITLE_LIMIT)
|
|
71
|
+
}
|
|
@@ -2,6 +2,11 @@ import { type PlanLanguage, WAITING_VOCABULARY } from '../vocabulary'
|
|
|
2
2
|
import { firstTableWithHeader, sectionLines } from './markdown'
|
|
3
3
|
import { terminalSafe } from './terminal-text'
|
|
4
4
|
|
|
5
|
+
/** `file` for a file or an Artifact that was sent, `question` for a dialog that ended unanswered. */
|
|
6
|
+
export const WAITING_KIND = { file: 'file', question: 'question' } as const
|
|
7
|
+
|
|
8
|
+
export type WaitingKind = (typeof WAITING_KIND)[keyof typeof WAITING_KIND]
|
|
9
|
+
|
|
5
10
|
/** One row of the board's section of what waits on the user: when it began (as written), what it is, whether it is open. */
|
|
6
11
|
export type WaitingItem = {
|
|
7
12
|
since: string
|
|
@@ -9,8 +14,8 @@ export type WaitingItem = {
|
|
|
9
14
|
open: boolean
|
|
10
15
|
/** A `file:` address the item links to, for a sent file; absent for a row of the board. */
|
|
11
16
|
url?: string
|
|
12
|
-
/**
|
|
13
|
-
kind?:
|
|
17
|
+
/** Absent for a row of the board. */
|
|
18
|
+
kind?: WaitingKind
|
|
14
19
|
/** The id of the record that closes it (`jh waiting close`); not shown. */
|
|
15
20
|
id?: string
|
|
16
21
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { twoDigits } from '../plan-format/clock'
|
|
2
|
+
import { padVisible } from '../terminal/text'
|
|
3
|
+
import { textWidth } from '../terminal/width'
|
|
4
|
+
import type { PlanLanguage } from '../vocabulary'
|
|
5
|
+
import { type Appointment, readAppointmentTable } from '../watch/appointments'
|
|
6
|
+
import { shortTitle } from './task-name'
|
|
7
|
+
import type { BlockItem } from './waiting-click'
|
|
8
|
+
|
|
9
|
+
/** An open appointment as the herd shows it: `label` is the weekday and the time, `Mon 09:03` (the weekday is English whatever the board's language); `key` is the watcher's. */
|
|
10
|
+
export type AppointmentRow = { key: string; label: string; action: string }
|
|
11
|
+
|
|
12
|
+
/** The appointment block: the open rows, the earliest first. */
|
|
13
|
+
export type AppointmentBlock = { rows: AppointmentRow[] }
|
|
14
|
+
|
|
15
|
+
const APPOINTMENT_MARK = '◷'
|
|
16
|
+
|
|
17
|
+
const WEEKDAY_LOCALE = 'en-US'
|
|
18
|
+
|
|
19
|
+
const weekdayOf = (when: Date): string => new Intl.DateTimeFormat(WEEKDAY_LOCALE, { weekday: 'short' }).format(when)
|
|
20
|
+
|
|
21
|
+
const rowOf = ({ when, action, key }: Appointment): AppointmentRow => ({
|
|
22
|
+
key,
|
|
23
|
+
label: `${weekdayOf(when)} ${twoDigits(when.getHours())}:${twoDigits(when.getMinutes())}`,
|
|
24
|
+
action,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The open appointments of the board's section, read as the watcher reads them, the earliest first. A done row, a
|
|
29
|
+
* row whose time cannot be read and a board without the section give no row.
|
|
30
|
+
*/
|
|
31
|
+
export const appointmentRows = (board: string, language: PlanLanguage, now: Date): AppointmentRow[] =>
|
|
32
|
+
readAppointmentTable(board, language, now)
|
|
33
|
+
.appointments.filter(({ open }) => open)
|
|
34
|
+
.sort((left, right) => left.when.getTime() - right.when.getTime())
|
|
35
|
+
.map(rowOf)
|
|
36
|
+
|
|
37
|
+
/** The block of the board's open appointments, as the herd shows them. */
|
|
38
|
+
export const appointmentBlock = (board: string, language: PlanLanguage, now: Date): AppointmentBlock => ({
|
|
39
|
+
rows: appointmentRows(board, language, now),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const appointmentKey = ({ key }: AppointmentRow): string => `appointment>${key}`
|
|
43
|
+
|
|
44
|
+
/** The rows as the block draws them; a click on one only expands it, so they carry no address and no question. */
|
|
45
|
+
export const appointmentItems = (rows: readonly AppointmentRow[]): BlockItem[] => {
|
|
46
|
+
const timeWidth = Math.max(0, ...rows.map(({ label }) => textWidth(label)))
|
|
47
|
+
return rows.map((row) => ({
|
|
48
|
+
key: appointmentKey(row),
|
|
49
|
+
mark: APPOINTMENT_MARK,
|
|
50
|
+
lead: padVisible(row.label, timeWidth),
|
|
51
|
+
text: row.action,
|
|
52
|
+
title: shortTitle(row.action),
|
|
53
|
+
url: null,
|
|
54
|
+
ask: null,
|
|
55
|
+
}))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The keys of all rows, the shown ones and the `+<n>` rest alike: what the fold of the block remembers. */
|
|
59
|
+
export const appointmentKeys = (rows: readonly AppointmentRow[]): string[] => rows.map(appointmentKey)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TERMINAL_ADAPTER, type TerminalAdapter } from '../config'
|
|
2
|
+
import { resolveCoordinatorName } from '../context/coordinator-name'
|
|
3
|
+
import { laneSenderFor } from '../settled/send'
|
|
4
|
+
import { type HerdrRunner, parseAgentList } from '../terminal/herdr'
|
|
5
|
+
import { PLAN_LANGUAGE, type PlanLanguage } from '../vocabulary'
|
|
6
|
+
import { ASK_KIND, type AskTarget, boardRowKey } from './ask-target'
|
|
7
|
+
import { errorText } from './error-text'
|
|
8
|
+
import { isQuestionId } from './question-records'
|
|
9
|
+
import { TEXTS } from './texts'
|
|
10
|
+
|
|
11
|
+
/** What `askCoordinator` needs from the outside: the dialog language, the terminal, the repository and herdr. */
|
|
12
|
+
export type AskDependencies = {
|
|
13
|
+
language: PlanLanguage
|
|
14
|
+
adapter: TerminalAdapter
|
|
15
|
+
/** The repository's directory name, from which the coordinator's herdr name follows. */
|
|
16
|
+
repository: string
|
|
17
|
+
run: HerdrRunner
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type AskSentences = { question: (id: string) => string; boardRow: (key: string) => string }
|
|
21
|
+
|
|
22
|
+
const ASK_LINES: Record<PlanLanguage, AskSentences> = {
|
|
23
|
+
[PLAN_LANGUAGE.de]: {
|
|
24
|
+
question: (id) => `Stell mir die offene Frage ${id} jetzt (jh waiting).`,
|
|
25
|
+
boardRow: (key) => `Stell mir die offene Board-Zeile \`${key}\` jetzt (jh waiting).`,
|
|
26
|
+
},
|
|
27
|
+
[PLAN_LANGUAGE.en]: {
|
|
28
|
+
question: (id) => `Ask me the open question ${id} now (jh waiting).`,
|
|
29
|
+
boardRow: (key) => `Ask me the open board row \`${key}\` now (jh waiting).`,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The line sent to the coordinator: a fixed sentence that carries the id of a question, or the sanitised key of a
|
|
35
|
+
* board row (`boardRowKey`), and nothing else from the board or the question, so a prompt line cannot be steered by
|
|
36
|
+
* the file it reads. The caller checks the id with `isQuestionId`.
|
|
37
|
+
*/
|
|
38
|
+
export const askLine = (target: AskTarget, language: PlanLanguage): string =>
|
|
39
|
+
target.kind === ASK_KIND.question
|
|
40
|
+
? ASK_LINES[language].question(target.id)
|
|
41
|
+
: ASK_LINES[language].boardRow(boardRowKey(target.since, target.item))
|
|
42
|
+
|
|
43
|
+
const isAskable = (target: AskTarget): boolean =>
|
|
44
|
+
target.kind === ASK_KIND.question ? isQuestionId(target.id) : boardRowKey(target.since, target.item) !== ''
|
|
45
|
+
|
|
46
|
+
const subjectOf = (target: AskTarget): string =>
|
|
47
|
+
target.kind === ASK_KIND.question ? `question ${target.id}` : `board row ${boardRowKey(target.since, target.item)}`
|
|
48
|
+
|
|
49
|
+
const agentNamesOf = (run: HerdrRunner): string[] => parseAgentList(run(['agent', 'list'])).map(({ name }) => name)
|
|
50
|
+
|
|
51
|
+
/** The coordinator's herdr name, or why there is none to reach; without a terminal the sender gives the reason. */
|
|
52
|
+
const coordinatorOf = ({ adapter, repository, run }: AskDependencies): { name: string } | { reason: string } => {
|
|
53
|
+
if (adapter === TERMINAL_ADAPTER.none) return { name: resolveCoordinatorName(repository, []) }
|
|
54
|
+
try {
|
|
55
|
+
const names = agentNamesOf(run)
|
|
56
|
+
const name = resolveCoordinatorName(repository, names)
|
|
57
|
+
return names.includes(name) ? { name } : { reason: `no agent named ${name}` }
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return { reason: errorText(error) }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Asks the coordinator, by `herdr agent prompt`, to put the open question or board row `target` to the user. A
|
|
65
|
+
* coordinator that is working gets the line too: herdr queues it like a message in the middle of a turn. Returns the
|
|
66
|
+
* footer line: who was asked, or why nobody was.
|
|
67
|
+
*/
|
|
68
|
+
export const askCoordinator = (target: AskTarget, dependencies: AskDependencies): string => {
|
|
69
|
+
if (!isAskable(target)) return TEXTS.notAsked('nothing to ask')
|
|
70
|
+
const coordinator = coordinatorOf(dependencies)
|
|
71
|
+
if ('reason' in coordinator) return TEXTS.notAsked(coordinator.reason)
|
|
72
|
+
const failure = laneSenderFor(dependencies.adapter, dependencies.run)(
|
|
73
|
+
coordinator.name,
|
|
74
|
+
askLine(target, dependencies.language),
|
|
75
|
+
)
|
|
76
|
+
return failure === null ? TEXTS.asked(coordinator.name, subjectOf(target)) : TEXTS.notAsked(failure)
|
|
77
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ellipsize, terminalSafe } from '../plan-format/terminal-text'
|
|
2
|
+
|
|
3
|
+
/** What the coordinator can be asked to put to the user: an open dialog question, or an open row of the board. */
|
|
4
|
+
export const ASK_KIND = { question: 'question', boardRow: 'boardRow' } as const
|
|
5
|
+
|
|
6
|
+
export type AskTarget =
|
|
7
|
+
| { kind: typeof ASK_KIND.question; id: string }
|
|
8
|
+
| { kind: typeof ASK_KIND.boardRow; since: string; item: string }
|
|
9
|
+
|
|
10
|
+
/** The longest key a prompt line carries for a board row, the ellipsis included. */
|
|
11
|
+
export const MAX_ROW_KEY_LENGTH = 120
|
|
12
|
+
|
|
13
|
+
const ROW_KEY_SEPARATOR = ' · '
|
|
14
|
+
|
|
15
|
+
const safeCell = (text: string): string => terminalSafe(text.replace(/\s+/g, ' ')).replaceAll('`', "'").trim()
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The key of a board row as it goes into a prompt line: since and item on one line, free of control characters and
|
|
19
|
+
* backticks (the line quotes the key in backticks), cut to `MAX_ROW_KEY_LENGTH`. The text comes from the board, so
|
|
20
|
+
* it is never trusted as it is.
|
|
21
|
+
*/
|
|
22
|
+
export const boardRowKey = (since: string, item: string): string => {
|
|
23
|
+
const cells = [safeCell(since), safeCell(item)].filter((cell) => cell !== '')
|
|
24
|
+
return ellipsize(cells.join(ROW_KEY_SEPARATOR), MAX_ROW_KEY_LENGTH)
|
|
25
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Milliseconds a child gets to end after a signal before it is killed. */
|
|
2
|
+
export const GRACE_MS = 2000
|
|
3
|
+
|
|
4
|
+
export type StopperDeps = {
|
|
5
|
+
kill: (signal: NodeJS.Signals) => void
|
|
6
|
+
setTimer: (run: () => void, ms: number) => unknown
|
|
7
|
+
clearTimer: (handle: unknown) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const STOP_REQUEST = { forwarded: 'forwarded', killed: 'killed' } as const
|
|
11
|
+
|
|
12
|
+
export type StopRequest = (typeof STOP_REQUEST)[keyof typeof STOP_REQUEST]
|
|
13
|
+
|
|
14
|
+
export type Stopper = {
|
|
15
|
+
/** The first call forwards `signal` and arms the kill; any further call kills at once. */
|
|
16
|
+
request: (signal: NodeJS.Signals) => StopRequest
|
|
17
|
+
/** The child has ended: nothing is left to kill. */
|
|
18
|
+
ended: () => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stops one child: the signal goes to it, and a child that ignores it is killed once `GRACE_MS` have passed, so a
|
|
23
|
+
* supervisor never waits on a view that does not end.
|
|
24
|
+
*/
|
|
25
|
+
export const stopperOf = ({ kill, setTimer, clearTimer }: StopperDeps): Stopper => {
|
|
26
|
+
let timer: unknown
|
|
27
|
+
let requested = false
|
|
28
|
+
|
|
29
|
+
const send = (signal: NodeJS.Signals): void => {
|
|
30
|
+
try {
|
|
31
|
+
kill(signal)
|
|
32
|
+
} catch {
|
|
33
|
+
// the child is already gone
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
request: (signal) => {
|
|
39
|
+
if (requested) {
|
|
40
|
+
clearTimer(timer)
|
|
41
|
+
send('SIGKILL')
|
|
42
|
+
return STOP_REQUEST.killed
|
|
43
|
+
}
|
|
44
|
+
requested = true
|
|
45
|
+
send(signal)
|
|
46
|
+
timer = setTimer(() => send('SIGKILL'), GRACE_MS)
|
|
47
|
+
return STOP_REQUEST.forwarded
|
|
48
|
+
},
|
|
49
|
+
ended: () => clearTimer(timer),
|
|
50
|
+
}
|
|
51
|
+
}
|